diff --git a/.gitignore b/.gitignore index 7eefa4456..dfe7ac089 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ *.iml .idea/ -.gradle/ \ No newline at end of file +.gradle/ diff --git a/build.third_step0.gradle b/build.third_step0.gradle index 8fc464d7f..9b7bcd2cb 100644 --- a/build.third_step0.gradle +++ b/build.third_step0.gradle @@ -10,9 +10,9 @@ configurations.all { resolutionStrategy.cacheChangingModulesFor 0, 'seconds' } //源码版本 -sourceCompatibility=1.6 +sourceCompatibility=1.7 //构建的class版本 -targetCompatibility=1.6 +targetCompatibility=1.7 //解压lib下的jar到classes文件夹 @@ -43,8 +43,10 @@ def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf (java.io.File.s def branchName=buildDir.substring(buildDir.lastIndexOf (java.io.File.separator)+1) def srcDir="." +def MVN_BRANCH = branchVariable.toUpperCase() + // @branch - 分支信息 -def maven_version="${version}-FEATURE-SNAPSHOT" +def maven_version="${version}-${MVN_BRANCH}-SNAPSHOT" def jar_version = version configurations { @@ -53,8 +55,7 @@ configurations { } dependencies { - // @branch - 分支信息 - thirdjar "com.fr.third:fine-third:10.0-FEATURE-SNAPSHOT" + thirdjar "com.fr.third:fine-third-base:10.0-BASE-SNAPSHOT" sigar "com.fr.third:sigar:1.6.0" testCompile 'junit:junit:4.12' } diff --git a/build.third_step1.gradle b/build.third_step1.gradle index e545d8a7c..d035fd18d 100644 --- a/build.third_step1.gradle +++ b/build.third_step1.gradle @@ -6,9 +6,9 @@ tasks.withType(JavaCompile){ } //源码版本 -sourceCompatibility=1.6 +sourceCompatibility=1.7 //构建的class版本 -targetCompatibility=1.6 +targetCompatibility=1.7 def jarname="fine-third-10.0.jar" def classesDir='build/classes/1' @@ -32,6 +32,8 @@ sourceSets{ main{ java{ srcDirs=[ + "${srcDir}/fine-third-jdk11/src", + "${srcDir}/fine-objenesis/src", "${srcDir}/fine-jetbrains/src", "${srcDir}/fine-poi/src", "${srcDir}/fine-quartz/src", @@ -58,6 +60,7 @@ repositories{ FileTree files =fileTree(dir:'./',include:'build.*.gradle') def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf (java.io.File.separator)) def branchName=buildDir.substring(buildDir.lastIndexOf (java.io.File.separator)+1) +def MVN_BRANCH = branchVariable.toUpperCase() //指定依赖 dependencies{ @@ -65,7 +68,7 @@ dependencies{ compile fileTree(dir:"${srcDir}/fine-quartz/lib",include:'**/*.jar') compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar') // @branch - 分支信息 - compile "com.fr.third:fine-third:10.0-FEATURE-SNAPSHOT" + compile "com.fr.third:fine-third:10.0-${MVN_BRANCH}-SNAPSHOT" compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar') testCompile 'junit:junit:4.12' } @@ -85,6 +88,8 @@ def dataContent ={def dir -> task copyFiles(type:Copy,dependsOn:'compileJava'){ copy{ println "------------------------------------------------copyfiles" + with dataContent.call("${srcDir}/fine-third-jdk11/src") + with dataContent.call("${srcDir}/fine-objenesis/src") with dataContent.call("${srcDir}/fine-jetbrains/src") with dataContent.call("${srcDir}/fine-poi/src") with dataContent.call("${srcDir}/fine-quartz/src") diff --git a/build.third_step2.gradle b/build.third_step2.gradle index 576e44231..d65d684a4 100644 --- a/build.third_step2.gradle +++ b/build.third_step2.gradle @@ -46,6 +46,7 @@ repositories{ FileTree files =fileTree(dir:'./',include:'build.*.gradle') def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf (java.io.File.separator)) def branchName=buildDir.substring(buildDir.lastIndexOf (java.io.File.separator)+1) +def MVN_BRANCH = branchVariable.toUpperCase() //指定依赖 dependencies{ @@ -55,7 +56,7 @@ dependencies{ compile fileTree(dir:"${srcDir}/fine-antlr4/lib",include: '**/*.jar') compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar') // @branch - 分支信息 - compile "com.fr.third:fine-third:10.0-FEATURE-SNAPSHOT" + compile "com.fr.third:fine-third:10.0-${MVN_BRANCH}-SNAPSHOT" compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar') testCompile 'junit:junit:4.12' } diff --git a/build.third_step3.gradle b/build.third_step3.gradle index 4e80a9326..702132f17 100644 --- a/build.third_step3.gradle +++ b/build.third_step3.gradle @@ -6,9 +6,9 @@ tasks.withType(JavaCompile){ } //源码版本 -sourceCompatibility=1.6 +sourceCompatibility=1.7 //构建的class版本 -targetCompatibility=1.6 +targetCompatibility=1.7 def jarname="fine-third-10.0.jar" def classesDir='build/classes/3' @@ -45,13 +45,14 @@ repositories{ FileTree files =fileTree(dir:'./',include:'build.*.gradle') def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf (java.io.File.separator)) def branchName=buildDir.substring(buildDir.lastIndexOf (java.io.File.separator)+1) +def MVN_BRANCH = branchVariable.toUpperCase() //指定依赖 dependencies{ compile fileTree(dir:"${srcDir}/fine-jboss-logging/lib",include:'**/*.jar') compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar') // @branch - 分支信息 - compile "com.fr.third:fine-third:10.0-FEATURE-SNAPSHOT" + compile "com.fr.third:fine-third:10.0-${MVN_BRANCH}-SNAPSHOT" compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar') testCompile 'junit:junit:4.12' } diff --git a/build.third_step4.gradle b/build.third_step4.gradle index 46de47c24..650c69b0a 100644 --- a/build.third_step4.gradle +++ b/build.third_step4.gradle @@ -6,9 +6,9 @@ tasks.withType(JavaCompile){ } //源码版本 -sourceCompatibility=1.6 +sourceCompatibility=1.7 //构建的class版本 -targetCompatibility=1.6 +targetCompatibility=1.7 def jarname="fine-third-10.0.jar" def classesDir='build/classes/4' @@ -44,13 +44,14 @@ repositories{ FileTree files =fileTree(dir:'./',include:'build.*.gradle') def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf (java.io.File.separator)) def branchName=buildDir.substring(buildDir.lastIndexOf (java.io.File.separator)+1) +def MVN_BRANCH = branchVariable.toUpperCase() //指定依赖 dependencies{ compile fileTree(dir:"${srcDir}/fine-hibernate/lib",include:'**/*.jar') compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar') // @branch - 分支信息 - compile "com.fr.third:fine-third:10.0-FEATURE-SNAPSHOT" + compile "com.fr.third:fine-third:10.0-${MVN_BRANCH}-SNAPSHOT" compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar') testCompile 'junit:junit:4.12' } diff --git a/build.third_step5.gradle b/build.third_step5.gradle index d45e1b48e..dd8d80fdd 100644 --- a/build.third_step5.gradle +++ b/build.third_step5.gradle @@ -6,9 +6,9 @@ tasks.withType(JavaCompile){ } //源码版本 -sourceCompatibility=1.6 +sourceCompatibility=1.7 //构建的class版本 -targetCompatibility=1.6 +targetCompatibility=1.7 def jarname="fine-third-10.0.jar" def classesDir='build/classes/5' @@ -42,6 +42,7 @@ repositories{ FileTree files =fileTree(dir:'./',include:'build.*.gradle') def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf (java.io.File.separator)) def branchName=buildDir.substring(buildDir.lastIndexOf (java.io.File.separator)+1) +def MVN_BRANCH = branchVariable.toUpperCase() //指定依赖 dependencies{ @@ -49,7 +50,7 @@ dependencies{ compile fileTree(dir:"${srcDir}/fine-druid/lib",include:'**/*.jar') compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar') // @branch - 分支信息 - compile "com.fr.third:fine-third:10.0-FEATURE-SNAPSHOT" + compile "com.fr.third:fine-third:10.0-${MVN_BRANCH}-SNAPSHOT" compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar') testCompile 'junit:junit:4.12' } diff --git a/build.third_step6.gradle b/build.third_step6.gradle index de18cbab9..8ef6d50ae 100644 --- a/build.third_step6.gradle +++ b/build.third_step6.gradle @@ -6,9 +6,9 @@ tasks.withType(JavaCompile){ } //源码版本 -sourceCompatibility=1.6 +sourceCompatibility=1.7 //构建的class版本 -targetCompatibility=1.6 +targetCompatibility=1.7 def jarname="fine-third-10.0.jar" def classesDir='build/classes/6' @@ -68,6 +68,7 @@ repositories{ FileTree files =fileTree(dir:'./',include:'build*.gradle') def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf (java.io.File.separator)) def branchName=buildDir.substring(buildDir.lastIndexOf (java.io.File.separator)+1) +def MVN_BRANCH = branchVariable.toUpperCase() //指定依赖 dependencies{ @@ -83,7 +84,7 @@ dependencies{ compile fileTree(dir:"${srcDir}/fine-jgit/lib",include:'**/*.jar') compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar') // @branch - 分支信息 - compile "com.fr.third:fine-third:10.0-FEATURE-SNAPSHOT" + compile "com.fr.third:fine-third:10.0-${MVN_BRANCH}-SNAPSHOT" compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar') testCompile 'junit:junit:4.12' } diff --git a/fine-aspectj/src/com/fr/third/aspectj/apache/bcel/generic/TABLESWITCH.java b/fine-aspectj/src/com/fr/third/aspectj/apache/bcel/generic/TABLESWITCH.java index bf1936f64..b726d1851 100644 --- a/fine-aspectj/src/com/fr/third/aspectj/apache/bcel/generic/TABLESWITCH.java +++ b/fine-aspectj/src/com/fr/third/aspectj/apache/bcel/generic/TABLESWITCH.java @@ -53,20 +53,16 @@ */ package com.fr.third.aspectj.apache.bcel.generic; -import java.io.DataOutputStream; -import java.io.IOException; - -import com.fr.third.aspectj.apache.bcel.Constants; import com.fr.third.aspectj.apache.bcel.util.ByteSequence; -import com.sun.org.apache.bcel.internal.generic.SWITCH; +import java.io.DataOutputStream; +import java.io.IOException; /** * TABLESWITCH - Switch within given range of values, i.e., low..high * * @version $Id: TABLESWITCH.java,v 1.5 2008/08/28 00:05:29 aclement Exp $ * @author M. Dahm - * @see SWITCH */ public class TABLESWITCH extends InstructionSelect { diff --git a/fine-cglib/src/com/fr/third/net/sf/cglib/reflect/MethodDelegate.java b/fine-cglib/src/com/fr/third/net/sf/cglib/reflect/MethodDelegate.java index 51279a17d..6f0dc85d0 100644 --- a/fine-cglib/src/com/fr/third/net/sf/cglib/reflect/MethodDelegate.java +++ b/fine-cglib/src/com/fr/third/net/sf/cglib/reflect/MethodDelegate.java @@ -15,9 +15,6 @@ */ package com.fr.third.net.sf.cglib.reflect; -import java.lang.reflect.*; -import java.security.ProtectionDomain; - import com.fr.third.net.sf.cglib.core.AbstractClassGenerator; import com.fr.third.net.sf.cglib.core.ClassEmitter; import com.fr.third.net.sf.cglib.core.CodeEmitter; @@ -28,11 +25,12 @@ import com.fr.third.net.sf.cglib.core.MethodInfo; import com.fr.third.net.sf.cglib.core.ReflectUtils; import com.fr.third.net.sf.cglib.core.Signature; import com.fr.third.net.sf.cglib.core.TypeUtils; -import com.fr.third.net.sf.cglib.*; -import com.fr.third.net.sf.cglib.core.*; import com.fr.third.org.objectweb.asm.ClassVisitor; import com.fr.third.org.objectweb.asm.Type; +import java.lang.reflect.Method; +import java.security.ProtectionDomain; + // TODO: don't require exact match for return type /** diff --git a/fine-ehcache/src/com/fr/third/net/sf/ehcache/statistics/extended/ExtendedStatisticsImpl.java b/fine-ehcache/src/com/fr/third/net/sf/ehcache/statistics/extended/ExtendedStatisticsImpl.java index f02c4a84f..e168d0cd4 100644 --- a/fine-ehcache/src/com/fr/third/net/sf/ehcache/statistics/extended/ExtendedStatisticsImpl.java +++ b/fine-ehcache/src/com/fr/third/net/sf/ehcache/statistics/extended/ExtendedStatisticsImpl.java @@ -66,7 +66,7 @@ import static org.terracotta.context.query.QueryBuilder.queryBuilder; /** * The Class ExtendedStatisticsImpl. - * + * * @author cschanck */ public class ExtendedStatisticsImpl implements ExtendedStatistics { @@ -75,15 +75,15 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { private static final Logger LOGGER = LoggerFactory.getLogger(ExtendedStatisticsImpl.class); /** The standard pass throughs. */ - private final ConcurrentMap> standardPassThroughs = + private final ConcurrentMap> standardPassThroughs = new ConcurrentHashMap>(); /** The standard operations. */ - private final ConcurrentMap> standardOperations = + private final ConcurrentMap> standardOperations = new ConcurrentHashMap>(); /** The custom operations. */ - private final ConcurrentMap, CompoundOperationImpl> customOperations = + private final ConcurrentMap, CompoundOperationImpl> customOperations = new ConcurrentHashMap, CompoundOperationImpl>(); /** custom pass thru stats*/ @@ -155,7 +155,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /** * Instantiates a new extended statistics impl. - * + * * @param manager the manager * @param executor the executor * @param timeToDisable the time to disable @@ -265,7 +265,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#setTimeToDisable(long, java.util.concurrent.TimeUnit) */ @Override @@ -280,7 +280,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#setAlwaysOn(boolean) */ @Override @@ -305,7 +305,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#get() */ @Override @@ -315,7 +315,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#put() */ @Override @@ -375,7 +375,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#search() */ @Override @@ -385,7 +385,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#heapGet() */ @Override @@ -395,7 +395,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#heapPut() */ @Override @@ -405,7 +405,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#heapRemove() */ @Override @@ -415,7 +415,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#offheapGet() */ @Override @@ -425,7 +425,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#offheapPut() */ @Override @@ -435,7 +435,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#offheapRemove() */ @Override @@ -445,7 +445,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#diskGet() */ @Override @@ -455,7 +455,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#diskPut() */ @Override @@ -465,7 +465,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#diskRemove() */ @Override @@ -475,7 +475,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#xaCommit() */ @Override @@ -485,7 +485,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#xaRollback() */ @Override @@ -495,7 +495,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#xaRecovery() */ @Override @@ -505,7 +505,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#eviction() */ @Override @@ -515,7 +515,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#expiry() */ @Override @@ -525,7 +525,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#getCacheHitRatio() */ @Override @@ -535,7 +535,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#allGet() */ @Override @@ -545,7 +545,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#allMiss() */ @Override @@ -555,7 +555,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#allPut() */ @Override @@ -565,7 +565,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#heapAllPut() */ @Override @@ -575,7 +575,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#offHeapAllPut() */ @Override @@ -585,7 +585,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#diskAllPut() */ @Override @@ -595,7 +595,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#operations(java.lang.Class, java.lang.String, java.lang.String[]) */ @Override @@ -623,7 +623,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#getLocalHeapSize() */ @Override @@ -633,7 +633,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#getLocalHeapSizeInBytes() */ @Override @@ -643,7 +643,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#getLocalOffHeapSize() */ @Override @@ -653,7 +653,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#getLocalOffHeapSizeInBytes() */ @Override @@ -663,7 +663,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#getLocalDiskSize() */ @Override @@ -673,7 +673,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#getLocalDiskSizeInBytes() */ @Override @@ -683,7 +683,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#getRemoteSize() */ @Override @@ -693,7 +693,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#getSize() */ @Override @@ -703,7 +703,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#getWriterQueueLength() */ @Override @@ -713,7 +713,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /** * Gets the standard operation. - * + * * @param statistic the statistic * @return the standard operation */ @@ -740,7 +740,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /** * Gets the standard pass through. - * + * * @param statistic the statistic * @return the standard pass through */ @@ -766,13 +766,13 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /** * Find operation statistic. - * + * * @param manager the manager * @param statistic the statistic * @return the operation statistic */ private static OperationStatistic findOperationStatistic(StatisticsManager manager, StandardOperationStatistic statistic) { - Set> results = findOperationStatistic(manager, + Set> results = (Set>)findOperationStatistic(manager, statistic.context(), statistic.type(), statistic.operationName(), @@ -789,7 +789,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /** * Find pass through statistic. - * + * * @param manager the manager * @param statistic the statistic * @return the value statistic @@ -808,7 +808,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /** * Find operation statistic. - * + * * @param the generic type * @param manager the manager * @param contextQuery the context query @@ -843,7 +843,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /** * Find pass through statistic. - * + * * @param manager the manager * @param contextQuery the context query * @param name the name @@ -876,7 +876,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#clusterEvent() */ @Override @@ -886,7 +886,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#clusterEvent() */ @Override @@ -896,7 +896,7 @@ public class ExtendedStatisticsImpl implements ExtendedStatistics { /* * (non-Javadoc) - * + * * @see ExtendedStatistics#lastRejoinTimeStampInNanos() */ @Override diff --git a/fine-icu4j/src/com/fr/third/ibm/icu/text/RuleBasedBreakIterator.java b/fine-icu4j/src/com/fr/third/ibm/icu/text/RuleBasedBreakIterator.java index b202510ca..ce06a7f7f 100644 --- a/fine-icu4j/src/com/fr/third/ibm/icu/text/RuleBasedBreakIterator.java +++ b/fine-icu4j/src/com/fr/third/ibm/icu/text/RuleBasedBreakIterator.java @@ -17,6 +17,7 @@ import java.nio.ByteBuffer; import java.text.CharacterIterator; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.locks.ReentrantReadWriteLock; import com.fr.third.ibm.icu.impl.CharacterIteration; import com.fr.third.ibm.icu.impl.ICUBinary; @@ -43,8 +44,11 @@ public class RuleBasedBreakIterator extends BreakIterator { */ private RuleBasedBreakIterator() { fDictionaryCharCount = 0; - synchronized(gAllBreakEngines) { + try { + rLock.lock(); fBreakEngines = new ArrayList(gAllBreakEngines); + } finally { + rLock.unlock(); } } @@ -131,8 +135,11 @@ public class RuleBasedBreakIterator extends BreakIterator { if (fText != null) { result.fText = (CharacterIterator)(fText.clone()); } - synchronized (gAllBreakEngines) { + try { + rLock.lock(); result.fBreakEngines = new ArrayList(gAllBreakEngines); + } finally { + rLock.unlock(); } result.fLookAheadMatches = new LookAheadResults(); result.fBreakCache = result.new BreakCache(fBreakCache); @@ -294,10 +301,19 @@ public class RuleBasedBreakIterator extends BreakIterator { */ private static final List gAllBreakEngines; + private static final ReentrantReadWriteLock rwLock; + + private static final ReentrantReadWriteLock.ReadLock rLock; + + private static final ReentrantReadWriteLock.WriteLock wLock; + static { gUnhandledBreakEngine = new UnhandledBreakEngine(); gAllBreakEngines = new ArrayList(); gAllBreakEngines.add(gUnhandledBreakEngine); + rwLock = new ReentrantReadWriteLock(); + rLock = rwLock.readLock(); + wLock = rwLock.writeLock(); } /** @@ -663,7 +679,8 @@ public class RuleBasedBreakIterator extends BreakIterator { } } - synchronized (gAllBreakEngines) { + try { + wLock.lock(); // This break iterator's list of break engines didn't handle the character. // Check the global list, another break iterator may have instantiated the // desired engine. @@ -717,7 +734,10 @@ public class RuleBasedBreakIterator extends BreakIterator { fBreakEngines.add(eng); } return eng; - } // end synchronized(gAllBreakEngines) + // end synchronized(gAllBreakEngines) + } finally { + wLock.unlock(); + } } private static final int kMaxLookaheads = 8; diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/Row.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/Row.java index e6092dd96..a238628c1 100755 --- a/fine-itext-old/src/com/fr/third/com/lowagie/text/Row.java +++ b/fine-itext-old/src/com/fr/third/com/lowagie/text/Row.java @@ -93,7 +93,7 @@ public class Row implements Element { /** This is the array of Objects (Cell or Table). */ protected Object[] cells; - /** carl:ԼĴ룬ʲôṹ*/ + /** carl:反正自己改代码,不管什么结构了*/ protected int height = 0; /** This is the vertical alignment. */ diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/HTMLWorker.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/HTMLWorker.java index 1399c6d20..f1ea48571 100644 --- a/fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/HTMLWorker.java +++ b/fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/HTMLWorker.java @@ -72,14 +72,10 @@ import com.fr.third.com.lowagie.text.pdf.PdfPTable; import com.fr.third.com.lowagie.text.pdf.draw.LineSeparator; import com.fr.third.com.lowagie.text.xml.simpleparser.SimpleXMLDocHandler; import com.fr.third.com.lowagie.text.xml.simpleparser.SimpleXMLParser; -import sun.misc.BASE64Decoder; +import com.fr.third.sun.misc.BASE64Decoder; -import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.io.Reader; import java.util.ArrayList; import java.util.HashMap; diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/rtf/table/RtfRow.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/rtf/table/RtfRow.java index 1fb95f795..2f36fff2f 100755 --- a/fine-itext-old/src/com/fr/third/com/lowagie/text/rtf/table/RtfRow.java +++ b/fine-itext-old/src/com/fr/third/com/lowagie/text/rtf/table/RtfRow.java @@ -232,7 +232,7 @@ public class RtfRow extends RtfElement { this.cells = new ArrayList(); this.width = this.document.getDocumentHeader().getPageSetting().getPageWidth() - this.document.getDocumentHeader().getPageSetting().getMarginLeft() - this.document.getDocumentHeader().getPageSetting().getMarginRight(); this.width = (int) (this.width * this.parentTable.getTableWidthPercent() / 100); - // carl: height + // carl: height this.height = row.getHeight(); int cellRight = 0; diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/rtf/table/RtfTable.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/rtf/table/RtfTable.java index aaa3cb150..5a1b5e1cf 100755 --- a/fine-itext-old/src/com/fr/third/com/lowagie/text/rtf/table/RtfTable.java +++ b/fine-itext-old/src/com/fr/third/com/lowagie/text/rtf/table/RtfTable.java @@ -238,14 +238,14 @@ public class RtfTable extends RtfElement { result.write(RtfFont.FONT_SIZE); result.write(intToByteArray(this.offset)); } - // carl:УиΪС 1 + // carl:多出来的行,行高设为最小 1 result.write(RtfParagraph.PLAIN); // result.write("\\s".getBytes()); // result.write(intToByteArray(0)); result.write(RtfPhrase.LINE_SPACING); result.write(intToByteArray(0)); result.write(RtfParagraph.PLAIN); - // ǹؼ1 + // 这里是关键,把这破行设成1 result.write(RtfFont.FONT_SIZE); result.write(intToByteArray(2)); result.write(RtfParagraph.PARAGRAPH); @@ -258,14 +258,14 @@ public class RtfTable extends RtfElement { } result.write(RtfParagraph.PARAGRAPH_DEFAULTS); - // carl:УиΪС 1 + // carl:多出来的行,行高设为最小 1 result.write(RtfParagraph.PLAIN); // result.write("\\s".getBytes()); // result.write(intToByteArray(0)); result.write(RtfPhrase.LINE_SPACING); result.write(intToByteArray(0)); result.write(RtfParagraph.PLAIN); - // ǹؼ1 + // 这里是关键,把这破行设成1 result.write(RtfFont.FONT_SIZE); result.write(intToByteArray(2)); } diff --git a/fine-itext/src/com/fr/third/v2/lowagie/text/html/Markup.java b/fine-itext/src/com/fr/third/v2/lowagie/text/html/Markup.java index 763bbde5a..6a9cc97ff 100644 --- a/fine-itext/src/com/fr/third/v2/lowagie/text/html/Markup.java +++ b/fine-itext/src/com/fr/third/v2/lowagie/text/html/Markup.java @@ -209,6 +209,8 @@ public class Markup { /** the CSS tag for the visibility of objects */ public static final String CSS_KEY_VISIBILITY = "visibility"; + public static final String CSS_KEY_TEXTINDENT = "text-indent"; + // CSS values /** @@ -341,7 +343,7 @@ public class Markup { /** * New method contributed by: Lubos Strapko - * + * * @since 2.1.3 */ public static float parseLength(String string, float actualFontSize) { diff --git a/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java b/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java index 418bb954f..cf53266c4 100644 --- a/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java +++ b/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java @@ -374,14 +374,7 @@ public class FactoryProperties { if (key.equals(Markup.CSS_KEY_FONTFAMILY)) { h.put(ElementTags.FACE, prop.getProperty(key)); } else if (key.equals(Markup.CSS_KEY_FONTSIZE)) { - float actualFontSize = Markup.parseLength(cprops - .getProperty(ElementTags.SIZE), - Markup.DEFAULT_FONT_SIZE); - if (actualFontSize <= 0f) - actualFontSize = Markup.DEFAULT_FONT_SIZE; - h.put(ElementTags.SIZE, Float.toString(Markup.parseLength(prop - .getProperty(key), actualFontSize)) - + "pt"); + dealWithFontSizeOrTextIndent(h, cprops, prop, key); } else if (key.equals(Markup.CSS_KEY_FONTSTYLE)) { String ss = prop.getProperty(key).trim().toLowerCase(); if (ss.equals("italic") || ss.equals("oblique")) @@ -429,14 +422,34 @@ public class FactoryProperties { } else if (key.equals(Markup.CSS_KEY_BGCOLOR)) { String ss = prop.getProperty(key).trim().toLowerCase(); h.put("background", ss); - } - else{ - String ss = prop.getProperty(key).trim(); - h.put(key, ss); - } + } else if (key.equals(Markup.CSS_KEY_TEXTINDENT)) { + dealWithFontSizeOrTextIndent(h, cprops, prop, key); + } else { + String ss = prop.getProperty(key).trim(); + h.put(key, ss); + } } } + /** + * 处理下字号和文本缩进 + * + * @param h 当前标签内的属性Map + * @param cprops 一个list , 从左到右保存着父到子标签中的属性 + * @param prop 当前标签内的style 属性Map + * @param key 当前 prop 中的 k + */ + private static void dealWithFontSizeOrTextIndent(HashMap h, ChainedProperties cprops, Properties prop, String key) { + float actualFontSize = Markup.parseLength(cprops + .getProperty(ElementTags.SIZE), + Markup.DEFAULT_FONT_SIZE); + if (actualFontSize <= 0f) + actualFontSize = Markup.DEFAULT_FONT_SIZE; + h.put(key.equals(Markup.CSS_KEY_FONTSIZE) ? ElementTags.SIZE : key, Float.toString(Markup.parseLength(prop + .getProperty(key), actualFontSize)) + + "pt"); + } + public FontFactoryImp getFontImp() { return fontImp; } diff --git a/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java b/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java index ade85f5cf..5a4481ab7 100644 --- a/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java +++ b/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java @@ -58,8 +58,6 @@ import java.io.InputStream; import java.io.Reader; import java.util.ArrayList; import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; import java.util.Stack; import java.util.StringTokenizer; @@ -85,7 +83,7 @@ import com.fr.third.v2.lowagie.text.Paragraph; import com.fr.third.v2.lowagie.text.Phrase; import com.fr.third.v2.lowagie.text.pdf.PdfPTable; import com.fr.third.v2.lowagie.text.xml.simpleparser.SimpleXMLParser; -import sun.misc.BASE64Decoder; +import com.fr.third.sun.misc.BASE64Decoder; import javax.imageio.ImageIO; diff --git a/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java b/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java index 2ea2a07f1..5da1eb4ca 100644 --- a/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java +++ b/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java @@ -68,24 +68,25 @@ public class IncTable { private ArrayList cols; private ArrayList rowHeights = new ArrayList(); + private ArrayList relativeColWidths = new ArrayList(); /** Creates a new instance of IncTable */ public IncTable(HashMap props) { this.props.putAll(props); } - + public void addCol(PdfPCell cell) { if (cols == null) cols = new ArrayList(); cols.add(cell); } - + public void addCols(ArrayList ncols) { if (cols == null) cols = new ArrayList(ncols); else cols.addAll(ncols); } - + public void endRow(float rowHeight) { rowHeights.add(rowHeight); if (cols != null) { @@ -94,34 +95,39 @@ public class IncTable { cols = null; } } - + public ArrayList getRows() { return rows; } - + public PdfPTable buildTable() { if (rows.isEmpty()) return new PdfPTable(1); int ncol = 0; - ArrayList c0 = (ArrayList)rows.get(0); - ArrayList colWidths = new ArrayList(); + ArrayList c0 = (ArrayList) rows.get(0); + for (int k = 0; k < c0.size(); ++k) { - PdfPCell pCell = ((PdfPCell)c0.get(k)); - int cellCols = pCell.getColspan(); - ncol += cellCols; - if(cellCols > 1){ - for(int a = 0; a < cellCols ; a++){ - colWidths.add(pCell.getStyleWidth()/cellCols); - } - }else { - colWidths.add(pCell.getStyleWidth()); - } + ncol += ((PdfPCell) c0.get(k)).getColspan(); } + processColWidth(ncol); + PdfPTable table = new PdfPTable(ncol); try { TableProperties tableProperties = parseTableProperties(); table.setTableProperties(tableProperties); + + //相对宽度 + float[] floats = new float[relativeColWidths.size()]; + for (int a = 0; a < relativeColWidths.size(); a++) { + floats[a] = relativeColWidths.get(a); + } + try { + table.setWidths(floats); + } catch (Exception e) { + e.printStackTrace(); + } + String width = (String)props.get("width"); if (width == null) table.setWidthPercentage(100); @@ -130,18 +136,7 @@ public class IncTable { table.setWidthPercentage(CSSUtils.parseFloat(width)); else { //解析单元格宽度 - float totalWidth = CSSUtils.parseFloat(width); - float[] floats = new float[colWidths.size()]; - for (int a = 0; a < colWidths.size(); a++){ - floats[a] = colWidths.get(a); - } - //解析px数值 - table.setTotalWidth(totalWidth); - try { - table.setWidths(floats); - }catch (Exception e){ - e.printStackTrace(); - } + table.setTotalWidth(CSSUtils.parseFloat(width)); table.setLockedWidth(true); } } @@ -153,19 +148,66 @@ public class IncTable { } processRowHeight(table); - - }catch (Exception e){ e.printStackTrace(); } return table; } - public void processRowHeight(PdfPTable table){ - Float height = CSSUtils.parseFloat((String)props.get("height")); + /** + * 调整列宽,每列取最大值 + * + * @param colCount 列数 + */ + private void processColWidth(int colCount) { + if (null == rows || 0 == rows.size()) { + return; + } + //初始化一下 + for (int i = 0; i < colCount; i++) { + relativeColWidths.add(0f); + } + for (int rowIndex = 0; rowIndex < rows.size(); rowIndex++) { + ArrayList cols = (ArrayList) rows.get(rowIndex); + for (int colIndex = 0; colIndex < cols.size(); colIndex++) { + PdfPCell pCell = ((PdfPCell) cols.get(colIndex)); + + int cellCols = pCell.getColspan(); + float avgWidth = pCell.getStyleWidth() / cellCols; + for (int i = 0; i < cellCols && colIndex + i < colCount; i++) { + if (relativeColWidths.get(colIndex + i) < avgWidth) { + relativeColWidths.set(colIndex + i, avgWidth); + } + } + } + } + dealRelativeColWidthsWhenAllAreZero(relativeColWidths); + } + + /** + * 全部为0,则全部赋值1 + * + * @param relativeColWidths 相对宽度 + */ + private void dealRelativeColWidthsWhenAllAreZero(ArrayList relativeColWidths) { + if (0 == relativeColWidths.size()) { + return; + } + for (int i = 0; i < relativeColWidths.size(); i++) { + if (0 != relativeColWidths.get(i)) { + return; + } + } + for (int i = 0; i < relativeColWidths.size(); i++) { + relativeColWidths.set(i, 1f); + } + } + + public void processRowHeight(PdfPTable table) { + Float height = CSSUtils.parseFloat((String) props.get("height")); Float eachHeight = height / table.getRows().size(); //调整行高 - for(int a = 0; a < rowHeights.size(); a++){ + for (int a = 0; a < rowHeights.size(); a++) { table.getRow(a).setStyleHeight(Math.max(eachHeight, rowHeights.get(a))); } } diff --git a/fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java b/fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java index 09dce3311..f5b67439a 100644 --- a/fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java +++ b/fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java @@ -788,10 +788,11 @@ public class PdfChunk { public String toHtmlString() { StringBuffer htmlString = new StringBuffer(); - if(this.isImage()){ - htmlString.append(""); + if (this.isImage()) { + htmlString.append(""); return htmlString.toString(); - } //todo 需要添加其他样式属性 htmlString.append(" oldPacks, - Collection newPacks) { - oldPackLoop: for (PackFile oldPack : oldPacks) { + Collection newPacks) { + oldPackLoop: + for (PackFile oldPack : oldPacks) { String oldName = oldPack.getPackName(); // check whether an old pack file is also among the list of new // pack files. Then we must not delete it. diff --git a/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/InflatingBitSet.java b/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/InflatingBitSet.java index 096be5f33..ac1705f43 100755 --- a/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/InflatingBitSet.java +++ b/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/InflatingBitSet.java @@ -43,8 +43,8 @@ package com.fr.third.eclipse.jgit.internal.storage.file; -import com.googlecode.javaewah.EWAHCompressedBitmap; -import com.googlecode.javaewah.IntIterator; +import com.fr.third.googlecode.javaewah.EWAHCompressedBitmap; +import com.fr.third.googlecode.javaewah.IntIterator; /** * A wrapper around the EWAHCompressedBitmap optimized for the contains diff --git a/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/PackBitmapIndex.java b/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/PackBitmapIndex.java index 48c3c681f..ef5c5d15e 100755 --- a/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/PackBitmapIndex.java +++ b/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/PackBitmapIndex.java @@ -47,7 +47,7 @@ import com.fr.third.eclipse.jgit.errors.CorruptObjectException; import com.fr.third.eclipse.jgit.internal.JGitText; import com.fr.third.eclipse.jgit.lib.AnyObjectId; import com.fr.third.eclipse.jgit.lib.ObjectId; -import com.googlecode.javaewah.EWAHCompressedBitmap; +import com.fr.third.googlecode.javaewah.EWAHCompressedBitmap; import java.io.File; import java.io.FileInputStream; diff --git a/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/PackBitmapIndexBuilder.java b/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/PackBitmapIndexBuilder.java index fec58ad7a..aa6c9f3c3 100755 --- a/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/PackBitmapIndexBuilder.java +++ b/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/PackBitmapIndexBuilder.java @@ -50,7 +50,7 @@ import com.fr.third.eclipse.jgit.lib.Constants; import com.fr.third.eclipse.jgit.lib.ObjectId; import com.fr.third.eclipse.jgit.lib.ObjectIdOwnerMap; import com.fr.third.eclipse.jgit.util.BlockList; -import com.googlecode.javaewah.EWAHCompressedBitmap; +import com.fr.third.googlecode.javaewah.EWAHCompressedBitmap; import com.fr.third.eclipse.jgit.internal.storage.file.BitmapIndexImpl.CompressedBitmap; import com.fr.third.eclipse.jgit.lib.BitmapIndex.Bitmap; import com.fr.third.eclipse.jgit.lib.BitmapIndex.BitmapBuilder; diff --git a/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/PackBitmapIndexRemapper.java b/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/PackBitmapIndexRemapper.java index c896a5db5..20d5c79f6 100755 --- a/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/PackBitmapIndexRemapper.java +++ b/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/PackBitmapIndexRemapper.java @@ -47,8 +47,8 @@ import com.fr.third.eclipse.jgit.lib.AnyObjectId; import com.fr.third.eclipse.jgit.lib.BitmapIndex; import com.fr.third.eclipse.jgit.lib.ObjectId; import com.fr.third.eclipse.jgit.lib.ObjectIdOwnerMap; -import com.googlecode.javaewah.EWAHCompressedBitmap; -import com.googlecode.javaewah.IntIterator; +import com.fr.third.googlecode.javaewah.EWAHCompressedBitmap; +import com.fr.third.googlecode.javaewah.IntIterator; import com.fr.third.eclipse.jgit.internal.storage.file.BasePackBitmapIndex.StoredBitmap; import java.util.Collections; diff --git a/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/PackBitmapIndexV1.java b/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/PackBitmapIndexV1.java index f103996d7..b099c004c 100755 --- a/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/PackBitmapIndexV1.java +++ b/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/PackBitmapIndexV1.java @@ -50,7 +50,7 @@ import com.fr.third.eclipse.jgit.lib.ObjectId; import com.fr.third.eclipse.jgit.lib.ObjectIdOwnerMap; import com.fr.third.eclipse.jgit.util.IO; import com.fr.third.eclipse.jgit.util.NB; -import com.googlecode.javaewah.EWAHCompressedBitmap; +import com.fr.third.googlecode.javaewah.EWAHCompressedBitmap; import java.io.DataInput; import java.io.IOException; diff --git a/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/PackBitmapIndexWriterV1.java b/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/PackBitmapIndexWriterV1.java index 70c5d0457..13552f8f1 100755 --- a/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/PackBitmapIndexWriterV1.java +++ b/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/file/PackBitmapIndexWriterV1.java @@ -46,7 +46,7 @@ package com.fr.third.eclipse.jgit.internal.storage.file; import com.fr.third.eclipse.jgit.internal.JGitText; import com.fr.third.eclipse.jgit.lib.Constants; import com.fr.third.eclipse.jgit.util.io.SafeBufferedOutputStream; -import com.googlecode.javaewah.EWAHCompressedBitmap; +import com.fr.third.googlecode.javaewah.EWAHCompressedBitmap; import com.fr.third.eclipse.jgit.internal.storage.file.PackBitmapIndexBuilder.StoredEntry; import java.io.BufferedOutputStream; diff --git a/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/pack/PackWriterBitmapPreparer.java b/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/pack/PackWriterBitmapPreparer.java index 6f3d1fcd4..534d9c890 100755 --- a/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/pack/PackWriterBitmapPreparer.java +++ b/fine-jgit/src/com/fr/third/eclipse/jgit/internal/storage/pack/PackWriterBitmapPreparer.java @@ -60,7 +60,7 @@ import com.fr.third.eclipse.jgit.revwalk.RevCommit; import com.fr.third.eclipse.jgit.revwalk.RevObject; import com.fr.third.eclipse.jgit.revwalk.RevWalk; import com.fr.third.eclipse.jgit.util.BlockList; -import com.googlecode.javaewah.EWAHCompressedBitmap; +import com.fr.third.googlecode.javaewah.EWAHCompressedBitmap; import com.fr.third.eclipse.jgit.lib.BitmapIndex.BitmapBuilder; import java.io.IOException; diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/BitCounter.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/BitCounter.java new file mode 100644 index 000000000..85df35fe5 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/BitCounter.java @@ -0,0 +1,106 @@ +package com.fr.third.googlecode.javaewah; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ +/** + * BitCounter is a fake bitset data structure. Instead of storing the actual + * data, it only records the number of set bits. + * + * @since 0.4.0 + * @author David McIntosh + */ + +public final class BitCounter implements BitmapStorage { + + /** + * Virtually add words directly to the bitmap + * + * @param newdata + * the word + */ + @Override + public void add(final long newdata) { + this.oneBits += Long.bitCount(newdata); + return; + } + + /** + * virtually add several literal words. + * + * @param data + * the literal words + * @param start + * the starting point in the array + * @param number + * the number of literal words to add + */ + @Override + public void addStreamOfLiteralWords(long[] data, int start, int number) { + for (int i = start; i < start + number; i++) { + add(data[i]); + } + return; + } + + /** + * virtually add many zeroes or ones. + * + * @param v + * zeros or ones + * @param number + * how many to words add + */ + @Override +public void addStreamOfEmptyWords(boolean v, long number) { + if (v) { + this.oneBits += number * EWAHCompressedBitmap.wordinbits; + } + return; + } + + /** + * virtually add several negated literal words. + * + * @param data + * the literal words + * @param start + * the starting point in the array + * @param number + * the number of literal words to add + */ + // @Override : causes problems with Java 1.5 + @Override +public void addStreamOfNegatedLiteralWords(long[] data, int start, int number) { + for (int i = start; i < start + number; i++) { + add(~data[i]); + } + return; + } + + /** + * As you act on this class, it records the number of set (true) bits. + * + * @return number of set bits + */ + public int getCount() { + return this.oneBits; + } + + /** + * should directly set the sizeinbits field, but is effectively ignored in + * this class. + * + * @param bits + * number of bits + */ + // @Override : causes problems with Java 1.5 + @Override +public void setSizeInBits(int bits) { + // no action + } + + private int oneBits; + +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/BitmapStorage.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/BitmapStorage.java new file mode 100644 index 000000000..929b2b8b3 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/BitmapStorage.java @@ -0,0 +1,71 @@ +package com.fr.third.googlecode.javaewah; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ + +/** + * Low level bitset writing methods. + * + * @since 0.4.0 + * @author David McIntosh + */ +public interface BitmapStorage { + + /** + * Adding words directly to the bitmap (for expert use). + * + * This is normally how you add data to the array. So you add bits in streams + * of 8*8 bits. + * + * @param newdata + * the word + */ + public void add(final long newdata); + + /** + * if you have several literal words to copy over, this might be faster. + * + * @param data + * the literal words + * @param start + * the starting point in the array + * @param number + * the number of literal words to add + */ + public void addStreamOfLiteralWords(final long[] data, final int start, + final int number); + + /** + * For experts: You want to add many zeroes or ones? This is the method you + * use. + * + * @param v + * zeros or ones + * @param number + * how many to words add + */ + public void addStreamOfEmptyWords(final boolean v, final long number); + + /** + * Like "addStreamOfLiteralWords" but negates the words being added. + * + * @param data + * the literal words + * @param start + * the starting point in the array + * @param number + * the number of literal words to add + */ + public void addStreamOfNegatedLiteralWords(long[] data, final int start, + final int number); + + /** + * directly set the sizeinbits field + * + * @param bits + * number of bits + */ + public void setSizeInBits(final int bits); +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/BufferedIterator.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/BufferedIterator.java new file mode 100644 index 000000000..bf0e0c94a --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/BufferedIterator.java @@ -0,0 +1,151 @@ +package com.fr.third.googlecode.javaewah; + + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ +/** + * This class can be used to iterate over blocks of bitmap data. + * + * @author Daniel Lemire + * + */ +public class BufferedIterator implements IteratingRLW { + /** + * Instantiates a new iterating buffered running length word. + * + * @param iterator iterator + */ + public BufferedIterator(final CloneableIterator iterator) { + this.masteriterator = iterator; + if(this.masteriterator.hasNext()) { + this.iterator = this.masteriterator.next(); + this.brlw = new BufferedRunningLengthWord(this.iterator.next()); + this.literalWordStartPosition = this.iterator.literalWords() + this.brlw.literalwordoffset; + this.buffer = this.iterator.buffer(); + } + } + + + /** + * Discard first words, iterating to the next running length word if needed. + * + * @param x the number of words to be discarded + */ + @Override + public void discardFirstWords(long x) { + while (x > 0) { + if (this.brlw.RunningLength > x) { + this.brlw.RunningLength -= x; + return; + } + x -= this.brlw.RunningLength; + this.brlw.RunningLength = 0; + long toDiscard = x > this.brlw.NumberOfLiteralWords ? this.brlw.NumberOfLiteralWords : x; + + this.literalWordStartPosition += toDiscard; + this.brlw.NumberOfLiteralWords -= toDiscard; + x -= toDiscard; + if ((x > 0) || (this.brlw.size() == 0)) { + if (!this.next()) { + break; + } + } + } + } + /** + * Move to the next RunningLengthWord + * @return whether the move was possible + */ + @Override + public boolean next() { + if (!this.iterator.hasNext()) { + if(!reload()) { + this.brlw.NumberOfLiteralWords = 0; + this.brlw.RunningLength = 0; + return false; + } + } + this.brlw.reset(this.iterator.next()); + this.literalWordStartPosition = this.iterator.literalWords(); // + this.brlw.literalwordoffset ==0 + return true; + } + private boolean reload() { + if(!this.masteriterator.hasNext()) { + return false; + } + this.iterator = this.masteriterator.next(); + this.buffer = this.iterator.buffer(); + return true; + } + + + /** + * Get the nth literal word for the current running length word + * @param index zero based index + * @return the literal word + */ + @Override + public long getLiteralWordAt(int index) { + return this.buffer[this.literalWordStartPosition + index]; + } + + /** + * Gets the number of literal words for the current running length word. + * + * @return the number of literal words + */ + @Override + public int getNumberOfLiteralWords() { + return this.brlw.NumberOfLiteralWords; + } + + /** + * Gets the running bit. + * + * @return the running bit + */ + @Override + public boolean getRunningBit() { + return this.brlw.RunningBit; + } + + /** + * Gets the running length. + * + * @return the running length + */ + @Override + public long getRunningLength() { + return this.brlw.RunningLength; + } + + /** + * Size in uncompressed words of the current running length word. + * + * @return the size + */ + @Override + public long size() { + return this.brlw.size(); + } + + + @Override + public BufferedIterator clone() throws CloneNotSupportedException { + BufferedIterator answer = (BufferedIterator) super.clone(); + answer.brlw = this.brlw.clone(); + answer.buffer = this.buffer; + answer.iterator = this.iterator.clone(); + answer.literalWordStartPosition = this.literalWordStartPosition; + answer.masteriterator = this.masteriterator.clone(); + return answer; + } + + private BufferedRunningLengthWord brlw; + private long[] buffer; + private int literalWordStartPosition; + private EWAHIterator iterator; + private CloneableIterator masteriterator; + } \ No newline at end of file diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/BufferedRunningLengthWord.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/BufferedRunningLengthWord.java new file mode 100644 index 000000000..82afd2014 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/BufferedRunningLengthWord.java @@ -0,0 +1,175 @@ +package com.fr.third.googlecode.javaewah; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ + + + +/** + * Mostly for internal use. Similar to RunningLengthWord, but can + * be modified without access to the array, and has faster access. + * + * @author Daniel Lemire + * @since 0.1.0 + * + */ +public final class BufferedRunningLengthWord implements Cloneable { + + /** + * Instantiates a new buffered running length word. + * + * @param a the word + */ + public BufferedRunningLengthWord(final long a) { + this.NumberOfLiteralWords = (int) (a >>> (1 + RunningLengthWord.runninglengthbits)); + this.RunningBit = (a & 1) != 0; + this.RunningLength = (int) ((a >>> 1) & RunningLengthWord.largestrunninglengthcount); + } + + /** + * Instantiates a new buffered running length word. + * + * @param rlw the rlw + */ + public BufferedRunningLengthWord(final RunningLengthWord rlw) { + this(rlw.parent.buffer[rlw.position]); + } + + /** + * Discard first words. + * + * @param x the x + */ + public void discardFirstWords(long x) { + if (this.RunningLength >= x) { + this.RunningLength -= x; + return; + } + x -= this.RunningLength; + this.RunningLength = 0; + this.literalwordoffset += x; + this.NumberOfLiteralWords -= x; + } + + /** + * Gets the number of literal words. + * + * @return the number of literal words + */ + public int getNumberOfLiteralWords() { + return this.NumberOfLiteralWords; + } + + /** + * Gets the running bit. + * + * @return the running bit + */ + public boolean getRunningBit() { + return this.RunningBit; + } + + /** + * Gets the running length. + * + * @return the running length + */ + public long getRunningLength() { + return this.RunningLength; + } + + /** + * Reset the values using the provided word. + * + * @param a the word + */ + public void reset(final long a) { + this.NumberOfLiteralWords = (int) (a >>> (1 + RunningLengthWord.runninglengthbits)); + this.RunningBit = (a & 1) != 0; + this.RunningLength = (int) ((a >>> 1) & RunningLengthWord.largestrunninglengthcount); + this.literalwordoffset = 0; + } + + /** + * Reset the values of this running length word so that it has the same values + * as the other running length word. + * + * @param rlw the other running length word + */ + public void reset(final RunningLengthWord rlw) { + reset(rlw.parent.buffer[rlw.position]); + } + + /** + * Sets the number of literal words. + * + * @param number the new number of literal words + */ + public void setNumberOfLiteralWords(final int number) { + this.NumberOfLiteralWords = number; + } + + /** + * Sets the running bit. + * + * @param b the new running bit + */ + public void setRunningBit(final boolean b) { + this.RunningBit = b; + } + + /** + * Sets the running length. + * + * @param number the new running length + */ + public void setRunningLength(final long number) { + this.RunningLength = number; + } + + /** + * Size in uncompressed words. + * + * @return the long + */ + public long size() { + return this.RunningLength + this.NumberOfLiteralWords; + } + + /* + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "running bit = " + getRunningBit() + " running length = " + + getRunningLength() + " number of lit. words " + + getNumberOfLiteralWords(); + } + + @Override +public BufferedRunningLengthWord clone() throws CloneNotSupportedException { + BufferedRunningLengthWord answer = (BufferedRunningLengthWord) super.clone(); + answer.literalwordoffset = this.literalwordoffset; + answer.NumberOfLiteralWords = this.NumberOfLiteralWords; + answer.RunningBit = this.RunningBit; + answer.RunningLength = this.RunningLength; + return answer; + } + + + /** how many literal words have we read so far? */ + public int literalwordoffset = 0; + + /** The Number of literal words. */ + public int NumberOfLiteralWords; + + /** The Running bit. */ + public boolean RunningBit; + + /** The Running length. */ + public long RunningLength; + + +} \ No newline at end of file diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/CloneableIterator.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/CloneableIterator.java new file mode 100644 index 000000000..a17eded16 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/CloneableIterator.java @@ -0,0 +1,24 @@ +package com.fr.third.googlecode.javaewah; + +/** + * Like a standard Java iterator, except that you can clone it. + * + * @param the data type of the iterator + */ +public interface CloneableIterator extends Cloneable { + + /** + * @return whether there is more + */ + public boolean hasNext(); + /** + * @return the next element + */ + public E next(); + /** + * @return a copy + * @throws CloneNotSupportedException this should never happen in practice + */ + public CloneableIterator clone() throws CloneNotSupportedException; + +} \ No newline at end of file diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/EWAHCompressedBitmap.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/EWAHCompressedBitmap.java new file mode 100644 index 000000000..bc9397da9 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/EWAHCompressedBitmap.java @@ -0,0 +1,1631 @@ +package com.fr.third.googlecode.javaewah; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ + +import java.util.*; +import java.io.*; + + + +/** + *

+ * This implements the patent-free(1) EWAH scheme. Roughly speaking, it is a + * 64-bit variant of the BBC compression scheme used by Oracle for its bitmap + * indexes. + *

+ * + *

+ * The objective of this compression type is to provide some compression, while + * reducing as much as possible the CPU cycle usage. + *

+ * + * + *

+ * This implementation being 64-bit, it assumes a 64-bit CPU together with a + * 64-bit Java Virtual Machine. This same code on a 32-bit machine may not be as + * fast. + *

+ * + *

+ * There is also a 32-bit version of this code in the class + * javaewah32.EWAHCompressedBitmap32 + *

+ * + * @see com.googlecode.javaewah32.EWAHCompressedBitmap32 + * + *

+ * For more details, see the following paper: + *

+ * + *
    + *
  • Daniel Lemire, Owen Kaser, Kamel Aouiche, Sorting improves + * word-aligned bitmap indexes. Data & Knowledge Engineering 69 (1), pages + * 3-28, 2010. http://arxiv.org/abs/0901.3751
  • + *
+ * + *

+ * A 32-bit version of the compressed format was described by Wu et al. and + * named WBC: + *

+ * + *
    + *
  • K. Wu, E. J. Otoo, A. Shoshani, H. Nordberg, Notes on design and + * implementation of compressed bit vectors, Tech. Rep. LBNL/PUB-3161, + * Lawrence Berkeley National Laboratory, available from http://crd.lbl. + * gov/~kewu/ps/PUB-3161.html (2001).
  • + *
+ * + *

+ * Probably, the best prior art is the Oracle bitmap compression scheme + * (BBC): + *

+ *
    + *
  • G. Antoshenkov, Byte-Aligned Bitmap Compression, DCC'95, 1995.
  • + *
+ * + *

+ * 1- The authors do not know of any patent infringed by the following + * implementation. However, similar schemes, like WAH are covered by + * patents. + *

+ * + * @since 0.1.0 + */ +public final class EWAHCompressedBitmap implements Cloneable, Externalizable, + Iterable, BitmapStorage, LogicalElement { + + /** + * Creates an empty bitmap (no bit set to true). + */ + public EWAHCompressedBitmap() { + this.buffer = new long[defaultbuffersize]; + this.rlw = new RunningLengthWord(this, 0); + } + + /** + * Sets explicitly the buffer size (in 64-bit words). The initial memory usage + * will be "buffersize * 64". For large poorly compressible bitmaps, using + * large values may improve performance. + * + * @param buffersize + * number of 64-bit words reserved when the object is created) + */ + public EWAHCompressedBitmap(final int buffersize) { + this.buffer = new long[buffersize]; + this.rlw = new RunningLengthWord(this, 0); + } + + /** + * Adding words directly to the bitmap (for expert use). + * + * This is normally how you add data to the array. So you add bits in streams + * of 8*8 bits. + * + * Example: if you add 321, you are have added (in binary notation) + * 0b101000001, so you have effectively called set(0), set(6), set(8) + * in sequence. + * + * @param newdata + * the word + */ + @Override +public void add(final long newdata) { + add(newdata, wordinbits); + } + + /** + * Adding words directly to the bitmap (for expert use). + * + * @param newdata + * the word + * @param bitsthatmatter + * the number of significant bits (by default it should be 64) + */ + public void add(final long newdata, final int bitsthatmatter) { + this.sizeinbits += bitsthatmatter; + if (newdata == 0) { + addEmptyWord(false); + } else if (newdata == ~0l) { + addEmptyWord(true); + } else { + addLiteralWord(newdata); + } + } + + /** + * For internal use. + * + * @param v + * the boolean value + */ + private void addEmptyWord(final boolean v) { + final boolean noliteralword = (this.rlw.getNumberOfLiteralWords() == 0); + final long runlen = this.rlw.getRunningLength(); + if ((noliteralword) && (runlen == 0)) { + this.rlw.setRunningBit(v); + } + if ((noliteralword) && (this.rlw.getRunningBit() == v) + && (runlen < RunningLengthWord.largestrunninglengthcount)) { + this.rlw.setRunningLength(runlen + 1); + return; + } + push_back(0); + this.rlw.position = this.actualsizeinwords - 1; + this.rlw.setRunningBit(v); + this.rlw.setRunningLength(1); + return; + } + + /** + * For internal use. + * + * @param newdata + * the literal word + */ + private void addLiteralWord(final long newdata) { + final int numbersofar = this.rlw.getNumberOfLiteralWords(); + if (numbersofar >= RunningLengthWord.largestliteralcount) { + push_back(0); + this.rlw.position = this.actualsizeinwords - 1; + this.rlw.setNumberOfLiteralWords(1); + push_back(newdata); + } + this.rlw.setNumberOfLiteralWords(numbersofar + 1); + push_back(newdata); + } + + /** + * if you have several literal words to copy over, this might be faster. + * + * + * @param data + * the literal words + * @param start + * the starting point in the array + * @param number + * the number of literal words to add + */ + @Override +public void addStreamOfLiteralWords(final long[] data, final int start, + final int number) { + int leftovernumber = number; + while(leftovernumber > 0) { + final int NumberOfLiteralWords = this.rlw.getNumberOfLiteralWords(); + final int whatwecanadd = leftovernumber < RunningLengthWord.largestliteralcount + - NumberOfLiteralWords ? leftovernumber : RunningLengthWord.largestliteralcount + - NumberOfLiteralWords; + this.rlw.setNumberOfLiteralWords(NumberOfLiteralWords + whatwecanadd); + leftovernumber -= whatwecanadd; + push_back(data, start, whatwecanadd); + this.sizeinbits += whatwecanadd * wordinbits; + if (leftovernumber > 0) { + push_back(0); + this.rlw.position = this.actualsizeinwords - 1; + } + } + } + + /** + * For experts: You want to add many zeroes or ones? This is the method you + * use. + * + * @param v + * the boolean value + * @param number + * the number + */ + @Override +public void addStreamOfEmptyWords(final boolean v, long number) { + if (number == 0) + return; + this.sizeinbits += number * wordinbits; + if ((this.rlw.getRunningBit() != v) && (this.rlw.size() == 0)) { + this.rlw.setRunningBit(v); + } else if ((this.rlw.getNumberOfLiteralWords() != 0) + || (this.rlw.getRunningBit() != v)) { + push_back(0); + this.rlw.position = this.actualsizeinwords - 1; + if (v) + this.rlw.setRunningBit(v); + } + final long runlen = this.rlw.getRunningLength(); + final long whatwecanadd = number < RunningLengthWord.largestrunninglengthcount + - runlen ? number : RunningLengthWord.largestrunninglengthcount - runlen; + this.rlw.setRunningLength(runlen + whatwecanadd); + number -= whatwecanadd; + while (number >= RunningLengthWord.largestrunninglengthcount) { + push_back(0); + this.rlw.position = this.actualsizeinwords - 1; + if (v) + this.rlw.setRunningBit(v); + this.rlw.setRunningLength(RunningLengthWord.largestrunninglengthcount); + number -= RunningLengthWord.largestrunninglengthcount; + } + if (number > 0) { + push_back(0); + this.rlw.position = this.actualsizeinwords - 1; + if (v) + this.rlw.setRunningBit(v); + this.rlw.setRunningLength(number); + } + } + + /** + * Same as addStreamOfLiteralWords, but the words are negated. + * + * @param data + * the literal words + * @param start + * the starting point in the array + * @param number + * the number of literal words to add + */ + @Override + public void addStreamOfNegatedLiteralWords(final long[] data, + final int start, final int number) { + int leftovernumber = number; + while (leftovernumber > 0) { + final int NumberOfLiteralWords = this.rlw.getNumberOfLiteralWords(); + final int whatwecanadd = leftovernumber < RunningLengthWord.largestliteralcount + - NumberOfLiteralWords ? leftovernumber + : RunningLengthWord.largestliteralcount + - NumberOfLiteralWords; + this.rlw.setNumberOfLiteralWords(NumberOfLiteralWords + + whatwecanadd); + leftovernumber -= whatwecanadd; + negative_push_back(data, start, whatwecanadd); + this.sizeinbits += whatwecanadd * wordinbits; + if (leftovernumber > 0) { + push_back(0); + this.rlw.position = this.actualsizeinwords - 1; + } + } + } + + /** + * Returns a new compressed bitmap containing the bitwise AND values of the + * current bitmap with some other bitmap. + * + * The running time is proportional to the sum of the compressed sizes (as + * reported by sizeInBytes()). + * + * If you are not planning on adding to the resulting bitmap, you may call the trim() + * method to reduce memory usage. + * + * @since 0.4.3 + * @param a + * the other bitmap + * @return the EWAH compressed bitmap + */ + @Override +public EWAHCompressedBitmap and(final EWAHCompressedBitmap a) { + final EWAHCompressedBitmap container = new EWAHCompressedBitmap(); + container + .reserve(this.actualsizeinwords > a.actualsizeinwords ? this.actualsizeinwords + : a.actualsizeinwords); + andToContainer(a, container); + return container; + } + /** + * Computes new compressed bitmap containing the bitwise AND values of the + * current bitmap with some other bitmap. + * + * The running time is proportional to the sum of the compressed sizes (as + * reported by sizeInBytes()). + * + * @since 0.4.0 + * @param a + * the other bitmap + * @param container + * where we store the result + */ + public void andToContainer(final EWAHCompressedBitmap a, final BitmapStorage container) { + final EWAHIterator i = a.getEWAHIterator(); + final EWAHIterator j = getEWAHIterator(); + final IteratingBufferedRunningLengthWord rlwi = new IteratingBufferedRunningLengthWord(i); + final IteratingBufferedRunningLengthWord rlwj = new IteratingBufferedRunningLengthWord(j); + while ((rlwi.size()>0) && (rlwj.size()>0)) { + while ((rlwi.getRunningLength() > 0) || (rlwj.getRunningLength() > 0)) { + final boolean i_is_prey = rlwi.getRunningLength() < rlwj + .getRunningLength(); + final IteratingBufferedRunningLengthWord prey = i_is_prey ? rlwi : rlwj; + final IteratingBufferedRunningLengthWord predator = i_is_prey ? rlwj + : rlwi; + if (predator.getRunningBit() == false) { + container.addStreamOfEmptyWords(false, predator.getRunningLength()); + prey.discardFirstWords(predator.getRunningLength()); + predator.discardFirstWords(predator.getRunningLength()); + } else { + final long index = prey.discharge(container, predator.getRunningLength()); + container.addStreamOfEmptyWords(false, predator.getRunningLength() + - index); + predator.discardFirstWords(predator.getRunningLength()); + } + } + final int nbre_literal = Math.min(rlwi.getNumberOfLiteralWords(), + rlwj.getNumberOfLiteralWords()); + if (nbre_literal > 0) { + for (int k = 0; k < nbre_literal; ++k) + container.add(rlwi.getLiteralWordAt(k) & rlwj.getLiteralWordAt(k)); + rlwi.discardFirstWords(nbre_literal); + rlwj.discardFirstWords(nbre_literal); + } + } + if(adjustContainerSizeWhenAggregating) { + final boolean i_remains = rlwi.size()>0; + final IteratingBufferedRunningLengthWord remaining = i_remains ? rlwi : rlwj; + remaining.dischargeAsEmpty(container); + container.setSizeInBits(Math.max(sizeInBits(), a.sizeInBits())); + } + } + + + /** + * Returns the cardinality of the result of a bitwise AND of the values of the + * current bitmap with some other bitmap. Avoids needing to allocate an + * intermediate bitmap to hold the result of the OR. + * + * @since 0.4.0 + * @param a + * the other bitmap + * @return the cardinality + */ + public int andCardinality(final EWAHCompressedBitmap a) { + final BitCounter counter = new BitCounter(); + andToContainer(a, counter); + return counter.getCount(); + } + + /** + * Returns a new compressed bitmap containing the bitwise AND NOT values of + * the current bitmap with some other bitmap. + * + * The running time is proportional to the sum of the compressed sizes (as + * reported by sizeInBytes()). + * + * If you are not planning on adding to the resulting bitmap, you may call the trim() + * method to reduce memory usage. + * + * @param a + * the other bitmap + * @return the EWAH compressed bitmap + */ + @Override +public EWAHCompressedBitmap andNot(final EWAHCompressedBitmap a) { + final EWAHCompressedBitmap container = new EWAHCompressedBitmap(); + container + .reserve(this.actualsizeinwords > a.actualsizeinwords ? this.actualsizeinwords + : a.actualsizeinwords); + andNotToContainer(a, container); + return container; + } + + /** + * Returns a new compressed bitmap containing the bitwise AND NOT values of + * the current bitmap with some other bitmap. This method is expected to + * be faster than doing A.and(B.clone().not()). + * + * The running time is proportional to the sum of the compressed sizes (as + * reported by sizeInBytes()). + * + * @since 0.4.0 + * @param a the other bitmap + * @param container where to store the result + */ + public void andNotToContainer(final EWAHCompressedBitmap a, + final BitmapStorage container) { + final EWAHIterator i = getEWAHIterator(); + final EWAHIterator j = a.getEWAHIterator(); + final IteratingBufferedRunningLengthWord rlwi = new IteratingBufferedRunningLengthWord(i); + final IteratingBufferedRunningLengthWord rlwj = new IteratingBufferedRunningLengthWord(j); + while ((rlwi.size()>0) && (rlwj.size()>0)) { + while ((rlwi.getRunningLength() > 0) || (rlwj.getRunningLength() > 0)) { + final boolean i_is_prey = rlwi.getRunningLength() < rlwj + .getRunningLength(); + final IteratingBufferedRunningLengthWord prey = i_is_prey ? rlwi : rlwj; + final IteratingBufferedRunningLengthWord predator = i_is_prey ? rlwj + : rlwi; + if ( ((predator.getRunningBit() == true) && (i_is_prey)) + || ((predator.getRunningBit() == false) && (!i_is_prey))){ + container.addStreamOfEmptyWords(false, predator.getRunningLength()); + prey.discardFirstWords(predator.getRunningLength()); + predator.discardFirstWords(predator.getRunningLength()); + } else if (i_is_prey) { + long index = prey.discharge(container, predator.getRunningLength()); + container.addStreamOfEmptyWords(false, predator.getRunningLength() + - index); + predator.discardFirstWords(predator.getRunningLength()); + } else { + long index = prey.dischargeNegated(container, predator.getRunningLength()); + container.addStreamOfEmptyWords(true, predator.getRunningLength() + - index); + predator.discardFirstWords(predator.getRunningLength()); + } + } + final int nbre_literal = Math.min(rlwi.getNumberOfLiteralWords(), + rlwj.getNumberOfLiteralWords()); + if (nbre_literal > 0) { + for (int k = 0; k < nbre_literal; ++k) + container.add(rlwi.getLiteralWordAt(k) & (~rlwj.getLiteralWordAt(k))); + rlwi.discardFirstWords(nbre_literal); + rlwj.discardFirstWords(nbre_literal); + } + } + final boolean i_remains = rlwi.size()>0; + final IteratingBufferedRunningLengthWord remaining = i_remains ? rlwi : rlwj; + if(i_remains) + remaining.discharge(container); + else if(adjustContainerSizeWhenAggregating) + remaining.dischargeAsEmpty(container); + if(adjustContainerSizeWhenAggregating) + container.setSizeInBits(Math.max(sizeInBits(), a.sizeInBits())); + } + + /** + * Returns the cardinality of the result of a bitwise AND NOT of the values of + * the current bitmap with some other bitmap. Avoids needing to allocate an + * intermediate bitmap to hold the result of the OR. + * + * @since 0.4.0 + * @param a + * the other bitmap + * @return the cardinality + */ + public int andNotCardinality(final EWAHCompressedBitmap a) { + final BitCounter counter = new BitCounter(); + andNotToContainer(a, counter); + return counter.getCount(); + } + + /** + * reports the number of bits set to true. Running time is proportional to + * compressed size (as reported by sizeInBytes). + * + * @return the number of bits set to true + */ + public int cardinality() { + int counter = 0; + final EWAHIterator i = new EWAHIterator(this, this.actualsizeinwords); + while (i.hasNext()) { + RunningLengthWord localrlw = i.next(); + if (localrlw.getRunningBit()) { + counter += wordinbits * localrlw.getRunningLength(); + } + for (int j = 0; j < localrlw.getNumberOfLiteralWords(); ++j) { + counter += Long.bitCount(i.buffer()[i.literalWords() + j]); + } + } + return counter; + } + + /** + * Clear any set bits and set size in bits back to 0 + */ + public void clear() { + this.sizeinbits = 0; + this.actualsizeinwords = 1; + this.rlw.position = 0; + // buffer is not fully cleared but any new set operations should overwrite + // stale data + this.buffer[0] = 0; + } + + /* + * @see java.lang.Object#clone() + */ + @Override + public EWAHCompressedBitmap clone() throws CloneNotSupportedException { + final EWAHCompressedBitmap clone = (EWAHCompressedBitmap) super.clone(); + clone.buffer = this.buffer.clone(); + clone.rlw = new RunningLengthWord(clone, this.rlw.position); + clone.actualsizeinwords = this.actualsizeinwords; + clone.sizeinbits = this.sizeinbits; + return clone; + } + + /** + * Deserialize. + * + * @param in + * the DataInput stream + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public void deserialize(DataInput in) throws IOException { + this.sizeinbits = in.readInt(); + this.actualsizeinwords = in.readInt(); + if (this.buffer.length < this.actualsizeinwords) { + this.buffer = new long[this.actualsizeinwords]; + } + for (int k = 0; k < this.actualsizeinwords; ++k) + this.buffer[k] = in.readLong(); + this.rlw = new RunningLengthWord(this, in.readInt()); + } + + /** + * Check to see whether the two compressed bitmaps contain the same set bits. + * + * @see Object#equals(Object) + */ + @Override + public boolean equals(Object o) { + if (o instanceof EWAHCompressedBitmap) { + try { + this.xorToContainer((EWAHCompressedBitmap) o, new NonEmptyVirtualStorage()); + return true; + } catch (NonEmptyVirtualStorage.NonEmptyException e) { + return false; + } + } + return false; + } + + /** + * For experts: You want to add many zeroes or ones faster? + * + * This method does not update sizeinbits. + * + * @param v + * the boolean value + * @param number + * the number (must be greater than 0) + */ + private void fastaddStreamOfEmptyWords(final boolean v, long number) { + if ((this.rlw.getRunningBit() != v) && (this.rlw.size() == 0)) { + this.rlw.setRunningBit(v); + } else if ((this.rlw.getNumberOfLiteralWords() != 0) + || (this.rlw.getRunningBit() != v)) { + push_back(0); + this.rlw.position = this.actualsizeinwords - 1; + if (v) + this.rlw.setRunningBit(v); + } + + final long runlen = this.rlw.getRunningLength(); + final long whatwecanadd = number < RunningLengthWord.largestrunninglengthcount + - runlen ? number : RunningLengthWord.largestrunninglengthcount - runlen; + this.rlw.setRunningLength(runlen + whatwecanadd); + number -= whatwecanadd; + + while (number >= RunningLengthWord.largestrunninglengthcount) { + push_back(0); + this.rlw.position = this.actualsizeinwords - 1; + if (v) + this.rlw.setRunningBit(v); + this.rlw.setRunningLength(RunningLengthWord.largestrunninglengthcount); + number -= RunningLengthWord.largestrunninglengthcount; + } + if (number > 0) { + push_back(0); + this.rlw.position = this.actualsizeinwords - 1; + if (v) + this.rlw.setRunningBit(v); + this.rlw.setRunningLength(number); + } + } + + /** + * Gets an EWAHIterator over the data. This is a customized iterator which + * iterates over run length word. For experts only. + * + * @return the EWAHIterator + */ + public EWAHIterator getEWAHIterator() { + return new EWAHIterator(this, this.actualsizeinwords); + } + + /** + * @return the IteratingRLW iterator corresponding to this bitmap + */ + public IteratingRLW getIteratingRLW() { + return new IteratingBufferedRunningLengthWord(this); + } + /** + * get the locations of the true values as one vector. (may use more memory + * than iterator()) + * + * @return the positions + */ + public List getPositions() { + final ArrayList v = new ArrayList(); + final EWAHIterator i = new EWAHIterator(this, this.actualsizeinwords); + int pos = 0; + while (i.hasNext()) { + RunningLengthWord localrlw = i.next(); + if (localrlw.getRunningBit()) { + for (int j = 0; j < localrlw.getRunningLength(); ++j) { + for (int c = 0; c < wordinbits; ++c) + v.add(new Integer(pos++)); + } + } else { + pos += wordinbits * localrlw.getRunningLength(); + } + for (int j = 0; j < localrlw.getNumberOfLiteralWords(); ++j) { + long data = i.buffer()[i.literalWords() + j]; + while (data != 0) { + final int ntz = Long.numberOfTrailingZeros(data); + data ^= (1l << ntz); + v.add(new Integer(ntz + pos)); + } + pos += wordinbits; + } + } + while ((v.size() > 0) + && (v.get(v.size() - 1).intValue() >= this.sizeinbits)) + v.remove(v.size() - 1); + return v; + } + + /** + * Returns a customized hash code (based on Karp-Rabin). Naturally, if the + * bitmaps are equal, they will hash to the same value. + * + */ + @Override + public int hashCode() { + int karprabin = 0; + final int B = 31; + final EWAHIterator i = new EWAHIterator(this, this.actualsizeinwords); + while( i.hasNext() ) { + i.next(); + if (i.rlw.getRunningBit() == true) { + karprabin += B * karprabin + + (i.rlw.getRunningLength() & ((1l << 32) - 1)); + karprabin += B * karprabin + (i.rlw.getRunningLength() >>> 32); + } + for (int k = 0; k < i.rlw.getNumberOfLiteralWords(); ++k) { + karprabin += B * karprabin + (this.buffer[i.literalWords() + k] & ((1l << 32) - 1)); + karprabin += B * karprabin + (this.buffer[i.literalWords() + k] >>> 32); + } + } + return karprabin; + } + + /** + * Return true if the two EWAHCompressedBitmap have both at least one true bit + * in the same position. Equivalently, you could call "and" and check whether + * there is a set bit, but intersects will run faster if you don't need the + * result of the "and" operation. + * + * @since 0.3.2 + * @param a + * the other bitmap + * @return whether they intersect + */ + public boolean intersects(final EWAHCompressedBitmap a) { + NonEmptyVirtualStorage nevs = new NonEmptyVirtualStorage(); + try { + this.andToContainer(a, nevs); + } catch (NonEmptyVirtualStorage.NonEmptyException nee) { + return true; + } + return false; + } + + /** + * Iterator over the set bits (this is what most people will want to use to + * browse the content if they want an iterator). The location of the set bits + * is returned, in increasing order. + * + * @return the int iterator + */ + public IntIterator intIterator() { + return new IntIteratorImpl( + new EWAHIterator(this, this.actualsizeinwords)); + } + + /** + * iterate over the positions of the true values. This is similar to + * intIterator(), but it uses Java generics. + * + * @return the iterator + */ + @Override +public Iterator iterator() { + return new Iterator() { + @Override + public boolean hasNext() { + return this.under.hasNext(); + } + + @Override + public Integer next() { + return new Integer(this.under.next()); + } + + @Override + public void remove() { + throw new UnsupportedOperationException("bitsets do not support remove"); + } + + final private IntIterator under = intIterator(); + }; + } + + /** + * For internal use. + * + * @param data + * the array of words to be added + * @param start + * the starting point + * @param number + * the number of words to add + */ + private void negative_push_back(final long[] data, final int start, + final int number) { + while (this.actualsizeinwords + number >= this.buffer.length) { + final long oldbuffer[] = this.buffer; + if((this.actualsizeinwords + number) < 32768) + this.buffer = new long[ (this.actualsizeinwords + number) * 2]; + else if((this.actualsizeinwords + number) * 3 / 2 < this.actualsizeinwords + number) // overflow + this.buffer = new long[Integer.MAX_VALUE]; + else + this.buffer = new long[(this.actualsizeinwords + number) * 3 / 2]; + System.arraycopy(oldbuffer, 0, this.buffer, 0, oldbuffer.length); + this.rlw.parent.buffer = this.buffer; + } + for (int k = 0; k < number; ++k) + this.buffer[this.actualsizeinwords + k] = ~data[start + k]; + this.actualsizeinwords += number; + } + + /** + * Negate (bitwise) the current bitmap. To get a negated copy, do + * EWAHCompressedBitmap x= ((EWAHCompressedBitmap) mybitmap.clone()); x.not(); + * + * The running time is proportional to the compressed size (as reported by + * sizeInBytes()). + * + */ + @Override +public void not() { + final EWAHIterator i = new EWAHIterator(this, this.actualsizeinwords); + if (!i.hasNext()) + return; + + while (true) { + final RunningLengthWord rlw1 = i.next(); + rlw1.setRunningBit(!rlw1.getRunningBit()); + for (int j = 0; j < rlw1.getNumberOfLiteralWords(); ++j) { + i.buffer()[i.literalWords() + j] = ~i.buffer()[i.literalWords() + j]; + } + + if (!i.hasNext()) {// must potentially adjust the last literal word + final int usedbitsinlast = this.sizeinbits % wordinbits; + if (usedbitsinlast == 0) + return; + + if (rlw1.getNumberOfLiteralWords() == 0) { + if((rlw1.getRunningLength()>0) && (rlw1.getRunningBit())) { + rlw1.setRunningLength(rlw1.getRunningLength()-1); + this.addLiteralWord((~0l) >>> (wordinbits - usedbitsinlast)); + } + return; + } + i.buffer()[i.literalWords() + rlw1.getNumberOfLiteralWords() - 1] &= ((~0l) >>> (wordinbits - usedbitsinlast)); + return; + } + } + } + + /** + * Returns a new compressed bitmap containing the bitwise OR values of the + * current bitmap with some other bitmap. + * + * The running time is proportional to the sum of the compressed sizes (as + * reported by sizeInBytes()). + * + * If you are not planning on adding to the resulting bitmap, you may call the trim() + * method to reduce memory usage. + * + * @param a + * the other bitmap + * @return the EWAH compressed bitmap + */ + @Override +public EWAHCompressedBitmap or(final EWAHCompressedBitmap a) { + final EWAHCompressedBitmap container = new EWAHCompressedBitmap(); + container.reserve(this.actualsizeinwords + a.actualsizeinwords); + orToContainer(a, container); + return container; + } + + + + /** + * Computes the bitwise or between the current bitmap and the bitmap "a". + * Stores the result in the container. + * + * @since 0.4.0 + * @param a + * the other bitmap + * @param container + * where we store the result + */ + public void orToContainer(final EWAHCompressedBitmap a, final BitmapStorage container) { + final EWAHIterator i = a.getEWAHIterator(); + final EWAHIterator j = getEWAHIterator(); + final IteratingBufferedRunningLengthWord rlwi = new IteratingBufferedRunningLengthWord(i); + final IteratingBufferedRunningLengthWord rlwj = new IteratingBufferedRunningLengthWord(j); + while ((rlwi.size()>0) && (rlwj.size()>0)) { + while ((rlwi.getRunningLength() > 0) || (rlwj.getRunningLength() > 0)) { + final boolean i_is_prey = rlwi.getRunningLength() < rlwj + .getRunningLength(); + final IteratingBufferedRunningLengthWord prey = i_is_prey ? rlwi + : rlwj; + final IteratingBufferedRunningLengthWord predator = i_is_prey ? rlwj + : rlwi; + if (predator.getRunningBit() == true) { + container.addStreamOfEmptyWords(true, predator.getRunningLength()); + prey.discardFirstWords(predator.getRunningLength()); + predator.discardFirstWords(predator.getRunningLength()); + } else { + long index = prey.discharge(container, predator.getRunningLength()); + container.addStreamOfEmptyWords(false, predator.getRunningLength() + - index); + predator.discardFirstWords(predator.getRunningLength()); + } + } + final int nbre_literal = Math.min(rlwi.getNumberOfLiteralWords(), + rlwj.getNumberOfLiteralWords()); + if (nbre_literal > 0) { + for (int k = 0; k < nbre_literal; ++k) { + container.add(rlwi.getLiteralWordAt(k) | rlwj.getLiteralWordAt(k)); + } + rlwi.discardFirstWords(nbre_literal); + rlwj.discardFirstWords(nbre_literal); + } + } + final boolean i_remains = rlwi.size()>0; + final IteratingBufferedRunningLengthWord remaining = i_remains ? rlwi : rlwj; + remaining.discharge(container); + container.setSizeInBits(Math.max(sizeInBits(), a.sizeInBits())); + } + + /** + * Returns the cardinality of the result of a bitwise OR of the values of the + * current bitmap with some other bitmap. Avoids needing to allocate an + * intermediate bitmap to hold the result of the OR. + * + * @since 0.4.0 + * @param a + * the other bitmap + * @return the cardinality + */ + public int orCardinality(final EWAHCompressedBitmap a) { + final BitCounter counter = new BitCounter(); + orToContainer(a, counter); + return counter.getCount(); + } + + /** + * For internal use. + * + * @param data + * the word to be added + */ + private void push_back(final long data) { + if (this.actualsizeinwords == this.buffer.length) { + final long oldbuffer[] = this.buffer; + if(oldbuffer.length < 32768) + this.buffer = new long[ oldbuffer.length * 2]; + else if(oldbuffer.length * 3 / 2 < oldbuffer.length) // overflow + this.buffer = new long[Integer.MAX_VALUE]; + else + this.buffer = new long[oldbuffer.length * 3 / 2]; + System.arraycopy(oldbuffer, 0, this.buffer, 0, oldbuffer.length); + this.rlw.parent.buffer = this.buffer; + } + this.buffer[this.actualsizeinwords++] = data; + } + + /** + * For internal use. + * + * @param data + * the array of words to be added + * @param start + * the starting point + * @param number + * the number of words to add + */ + private void push_back(final long[] data, final int start, final int number) { + if (this.actualsizeinwords + number >= this.buffer.length) { + final long oldbuffer[] = this.buffer; + if(this.actualsizeinwords + number < 32768) + this.buffer = new long[(this.actualsizeinwords + number) * 2]; + else if ((this.actualsizeinwords + number) * 3 / 2 < this.actualsizeinwords + number) // overflow + this.buffer = new long[Integer.MAX_VALUE]; + else + this.buffer = new long[( this.actualsizeinwords + number) * 3 / 2]; + System.arraycopy(oldbuffer, 0, this.buffer, 0, oldbuffer.length); + this.rlw.parent.buffer = this.buffer; + } + System.arraycopy(data, start, this.buffer, this.actualsizeinwords, number); + this.actualsizeinwords += number; + } + + /* + * @see java.io.Externalizable#readExternal(java.io.ObjectInput) + */ + @Override +public void readExternal(ObjectInput in) throws IOException { + deserialize(in); + } + + /** + * For internal use (trading off memory for speed). + * + * @param size + * the number of words to allocate + * @return True if the operation was a success. + */ + private boolean reserve(final int size) { + if (size > this.buffer.length) { + final long oldbuffer[] = this.buffer; + this.buffer = new long[size]; + System.arraycopy(oldbuffer, 0, this.buffer, 0, oldbuffer.length); + this.rlw.parent.buffer = this.buffer; + return true; + } + return false; + } + + /** + * Serialize. + * + * @param out + * the DataOutput stream + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public void serialize(DataOutput out) throws IOException { + out.writeInt(this.sizeinbits); + out.writeInt(this.actualsizeinwords); + for (int k = 0; k < this.actualsizeinwords; ++k) + out.writeLong(this.buffer[k]); + out.writeInt(this.rlw.position); + } + + /** + * Report the size required to serialize this bitmap + * + * @return the size in bytes + */ + public int serializedSizeInBytes() { + return this.sizeInBytes() + 3 * 4; + } + + + /** + * Query the value of a single bit. Relying on this method when speed is + * needed is discouraged. The complexity is linear with the size of the + * bitmap. + * + * (This implementation is based on zhenjl's Go version of JavaEWAH.) + * + * @param i + * the bit we are interested in + * @return whether the bit is set to true + */ + public boolean get(final int i) { + if ((i < 0) || (i >= this.sizeinbits)) + return false; + int WordChecked = 0; + final IteratingRLW j = getIteratingRLW(); + final int wordi = i/wordinbits; + while (WordChecked <= wordi ) { + WordChecked += j.getRunningLength(); + if (wordi < WordChecked) { + return j.getRunningBit(); + } + if (wordi < WordChecked + j.getNumberOfLiteralWords()) { + final long w = j.getLiteralWordAt(wordi - WordChecked); + return (w & (1l << i)) != 0; + } + WordChecked += j.getNumberOfLiteralWords(); + j.next(); + } + return false; + } + + /** + * Set the bit at position i to true, the bits must be set in (strictly) increasing + * order. For example, set(15) and then set(7) will fail. You must do set(7) + * and then set(15). + * + * @param i + * the index + * @return true if the value was set (always true when i greater or equal to sizeInBits()). + * @throws IndexOutOfBoundsException + * if i is negative or greater than Integer.MAX_VALUE - 64 + */ + public boolean set(final int i) { + if ((i > Integer.MAX_VALUE - wordinbits) || (i < 0)) + throw new IndexOutOfBoundsException("Set values should be between 0 and " + + (Integer.MAX_VALUE - wordinbits)); + if (i < this.sizeinbits) + return false; + // distance in words: + final int dist = (i + wordinbits) / wordinbits + - (this.sizeinbits + wordinbits - 1) / wordinbits; + this.sizeinbits = i + 1; + if (dist > 0) {// easy + if (dist > 1) + fastaddStreamOfEmptyWords(false, dist - 1); + addLiteralWord(1l << (i % wordinbits)); + return true; + } + if (this.rlw.getNumberOfLiteralWords() == 0) { + this.rlw.setRunningLength(this.rlw.getRunningLength() - 1); + addLiteralWord(1l << (i % wordinbits)); + return true; + } + this.buffer[this.actualsizeinwords - 1] |= 1l << (i % wordinbits); + if (this.buffer[this.actualsizeinwords - 1] == ~0l) { + this.buffer[this.actualsizeinwords - 1] = 0; + --this.actualsizeinwords; + this.rlw.setNumberOfLiteralWords(this.rlw.getNumberOfLiteralWords() - 1); + // next we add one clean word + addEmptyWord(true); + } + return true; + } + + /** + * Set the size in bits. This does not change the compressed bitmap. + * + * @since 0.4.0 + */ + @Override +public void setSizeInBits(final int size) { + if((size+EWAHCompressedBitmap.wordinbits-1)/EWAHCompressedBitmap.wordinbits!= (this.sizeinbits+EWAHCompressedBitmap.wordinbits-1)/EWAHCompressedBitmap.wordinbits) + throw new RuntimeException("You can only reduce the size of the bitmap within the scope of the last word. To extend the bitmap, please call setSizeInbits(int,boolean)."); + this.sizeinbits = size; + } + + /** + * Change the reported size in bits of the *uncompressed* bitmap represented + * by this compressed bitmap. It may change the underlying compressed bitmap. + * It is not possible to reduce the sizeInBits, but + * it can be extended. The new bits are set to false or true depending on the + * value of defaultvalue. + * + * @param size + * the size in bits + * @param defaultvalue + * the default boolean value + * @return true if the update was possible + */ + public boolean setSizeInBits(final int size, final boolean defaultvalue) { + if (size < this.sizeinbits) + return false; + if (defaultvalue == false) + extendEmptyBits(this, this.sizeinbits, size); + else { + // next bit could be optimized + while (((this.sizeinbits % wordinbits) != 0) && (this.sizeinbits < size)) { + this.set(this.sizeinbits); + } + this.addStreamOfEmptyWords(defaultvalue, (size / wordinbits) + - this.sizeinbits / wordinbits); + // next bit could be optimized + while (this.sizeinbits < size) { + this.set(this.sizeinbits); + } + } + this.sizeinbits = size; + return true; + } + + /** + * Returns the size in bits of the *uncompressed* bitmap represented by this + * compressed bitmap. Initially, the sizeInBits is zero. It is extended + * automatically when you set bits to true. + * + * @return the size in bits + */ + @Override +public int sizeInBits() { + return this.sizeinbits; + } + + /** + * Report the *compressed* size of the bitmap (equivalent to memory usage, + * after accounting for some overhead). + * + * @return the size in bytes + */ + @Override +public int sizeInBytes() { + return this.actualsizeinwords * (wordinbits / 8); + } + + /** + * Populate an array of (sorted integers) corresponding to the location of the + * set bits. + * + * @return the array containing the location of the set bits + */ + public int[] toArray() { + int[] ans = new int[this.cardinality()]; + int inanspos = 0; + int pos = 0; + final EWAHIterator i = new EWAHIterator(this, this.actualsizeinwords); + while (i.hasNext()) { + RunningLengthWord localrlw = i.next(); + if (localrlw.getRunningBit()) { + for (int j = 0; j < localrlw.getRunningLength(); ++j) { + for (int c = 0; c < wordinbits; ++c) { + ans[inanspos++] = pos++; + } + } + } else { + pos += wordinbits * localrlw.getRunningLength(); + } + for (int j = 0; j < localrlw.getNumberOfLiteralWords(); ++j) { + long data = i.buffer()[i.literalWords() + j]; + if (!usetrailingzeros) { + for (int c = 0; c < wordinbits; ++c) { + if ((data & (1l << c)) != 0) + ans[inanspos++] = c + pos; + } + pos += wordinbits; + } else { + while (data != 0) { + final int ntz = Long.numberOfTrailingZeros(data); + data ^= (1l << ntz); + ans[inanspos++] = ntz + pos; + } + pos += wordinbits; + } + } + } + return ans; + + } + + /** + * A more detailed string describing the bitmap (useful for debugging). + * + * @return the string + */ + public String toDebugString() { + String ans = " EWAHCompressedBitmap, size in bits = " + this.sizeinbits + + " size in words = " + this.actualsizeinwords + "\n"; + final EWAHIterator i = new EWAHIterator(this, this.actualsizeinwords); + while (i.hasNext()) { + RunningLengthWord localrlw = i.next(); + if (localrlw.getRunningBit()) { + ans += localrlw.getRunningLength() + " 1x11\n"; + } else { + ans += localrlw.getRunningLength() + " 0x00\n"; + } + ans += localrlw.getNumberOfLiteralWords() + " dirties\n"; + for (int j = 0; j < localrlw.getNumberOfLiteralWords(); ++j) { + long data = i.buffer()[i.literalWords() + j]; + ans += "\t" + data + "\n"; + } + } + return ans; + } + + /** + * A string describing the bitmap. + * + * @return the string + */ + @Override + public String toString() { + StringBuffer answer = new StringBuffer(); + IntIterator i = this.intIterator(); + answer.append("{"); + if (i.hasNext()) + answer.append(i.next()); + while (i.hasNext()) { + answer.append(","); + answer.append(i.next()); + } + answer.append("}"); + return answer.toString(); + } + + /** + * swap the content of the bitmap with another. + * @param other bitmap to swap with + */ +public void swap(final EWAHCompressedBitmap other) { + long[] tmp = this.buffer; + this.buffer = other.buffer; + other.buffer = tmp; + + + int tmp2 = this.rlw.position; + this.rlw.position = other.rlw.position; + other.rlw.position = tmp2; + + int tmp3 = this.actualsizeinwords; + this.actualsizeinwords = other.actualsizeinwords; + other.actualsizeinwords = tmp3; + + int tmp4 = this.sizeinbits; + this.sizeinbits = other.sizeinbits; + other.sizeinbits = tmp4; + } + + /** + * Reduce the internal buffer to its minimal allowable size (given + * by this.actualsizeinwords). This can free memory. + */ + public void trim() { + this.buffer = Arrays.copyOf(this.buffer, this.actualsizeinwords); + } + + /* + * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput) + */ + @Override +public void writeExternal(ObjectOutput out) throws IOException { + serialize(out); + } + + /** + * Returns a new compressed bitmap containing the bitwise XOR values of the + * current bitmap with some other bitmap. + * + * The running time is proportional to the sum of the compressed sizes (as + * reported by sizeInBytes()). + * + * If you are not planning on adding to the resulting bitmap, you may call the trim() + * method to reduce memory usage. + * + * @param a + * the other bitmap + * @return the EWAH compressed bitmap + */ + @Override +public EWAHCompressedBitmap xor(final EWAHCompressedBitmap a) { + final EWAHCompressedBitmap container = new EWAHCompressedBitmap(); + container.reserve(this.actualsizeinwords + a.actualsizeinwords); + xorToContainer(a, container); + return container; + } + + /** + * Computes a new compressed bitmap containing the bitwise XOR values of the + * current bitmap with some other bitmap. + * + * The running time is proportional to the sum of the compressed sizes (as + * reported by sizeInBytes()). + * + * @since 0.4.0 + * @param a + * the other bitmap + * @param container + * where we store the result + */ + public void xorToContainer(final EWAHCompressedBitmap a, final BitmapStorage container) { + final EWAHIterator i = a.getEWAHIterator(); + final EWAHIterator j = getEWAHIterator(); + final IteratingBufferedRunningLengthWord rlwi = new IteratingBufferedRunningLengthWord(i); + final IteratingBufferedRunningLengthWord rlwj = new IteratingBufferedRunningLengthWord(j); + while ((rlwi.size()>0) && (rlwj.size()>0)) { + while ((rlwi.getRunningLength() > 0) || (rlwj.getRunningLength() > 0)) { + final boolean i_is_prey = rlwi.getRunningLength() < rlwj + .getRunningLength(); + final IteratingBufferedRunningLengthWord prey = i_is_prey ? rlwi : rlwj; + final IteratingBufferedRunningLengthWord predator = i_is_prey ? rlwj + : rlwi; + if (predator.getRunningBit() == false) { + long index = prey.discharge(container, predator.getRunningLength()); + container.addStreamOfEmptyWords(false, predator.getRunningLength() + - index); + predator.discardFirstWords(predator.getRunningLength()); + } else { + long index = prey.dischargeNegated(container, predator.getRunningLength()); + container.addStreamOfEmptyWords(true, predator.getRunningLength() + - index); + predator.discardFirstWords(predator.getRunningLength()); + } + } + final int nbre_literal = Math.min(rlwi.getNumberOfLiteralWords(), + rlwj.getNumberOfLiteralWords()); + if (nbre_literal > 0) { + for (int k = 0; k < nbre_literal; ++k) + container.add(rlwi.getLiteralWordAt(k) ^ rlwj.getLiteralWordAt(k)); + rlwi.discardFirstWords(nbre_literal); + rlwj.discardFirstWords(nbre_literal); + } + } + final boolean i_remains = rlwi.size()>0; + final IteratingBufferedRunningLengthWord remaining = i_remains ? rlwi : rlwj; + remaining.discharge(container); + container.setSizeInBits(Math.max(sizeInBits(), a.sizeInBits())); + } + + /** + * Returns the cardinality of the result of a bitwise XOR of the values of the + * current bitmap with some other bitmap. Avoids needing to allocate an + * intermediate bitmap to hold the result of the OR. + * + * @since 0.4.0 + * @param a + * the other bitmap + * @return the cardinality + */ + public int xorCardinality(final EWAHCompressedBitmap a) { + final BitCounter counter = new BitCounter(); + xorToContainer(a, counter); + return counter.getCount(); + } + + /** + * For internal use. Computes the bitwise and of the provided bitmaps and + * stores the result in the container. + * + * @param container + * where the result is stored + * @param bitmaps + * bitmaps to AND + * @since 0.4.3 + */ + public static void andWithContainer(final BitmapStorage container, + final EWAHCompressedBitmap... bitmaps) { + if(bitmaps.length == 1) throw new IllegalArgumentException("Need at least one bitmap"); + if(bitmaps.length == 2) { + bitmaps[0].andToContainer(bitmaps[1],container); + return; + } + EWAHCompressedBitmap answer = new EWAHCompressedBitmap(); + EWAHCompressedBitmap tmp = new EWAHCompressedBitmap(); + bitmaps[0].andToContainer(bitmaps[1], answer); + for(int k = 2; k < bitmaps.length - 1; ++k) { + answer.andToContainer(bitmaps[k], tmp); + tmp.swap(answer); + tmp.clear(); + } + answer.andToContainer(bitmaps[bitmaps.length - 1], container); + } + + /** + * Returns a new compressed bitmap containing the bitwise AND values of the + * provided bitmaps. + * + * It may or may not be faster than doing the aggregation two-by-two (A.and(B).and(C)). + * + * If only one bitmap is provided, it is returned as is. + * + * If you are not planning on adding to the resulting bitmap, you may call the trim() + * method to reduce memory usage. + * + * @since 0.4.3 + * @param bitmaps + * bitmaps to AND together + * @return result of the AND + */ + public static EWAHCompressedBitmap and(final EWAHCompressedBitmap... bitmaps) { + if(bitmaps.length == 1) return bitmaps[0]; + if(bitmaps.length == 2) return bitmaps[0].and(bitmaps[1]); + EWAHCompressedBitmap answer = new EWAHCompressedBitmap(); + EWAHCompressedBitmap tmp = new EWAHCompressedBitmap(); + bitmaps[0].andToContainer(bitmaps[1], answer); + for(int k = 2; k < bitmaps.length; ++k) { + answer.andToContainer(bitmaps[k], tmp); + tmp.swap(answer); + tmp.clear(); + } + return answer; + } + + /** + * Returns the cardinality of the result of a bitwise AND of the values of the + * provided bitmaps. Avoids needing to allocate an intermediate bitmap to hold + * the result of the AND. + * + * @since 0.4.3 + * @param bitmaps + * bitmaps to AND + * @return the cardinality + */ + public static int andCardinality(final EWAHCompressedBitmap... bitmaps) { + if(bitmaps.length == 1) return bitmaps[0].cardinality(); + final BitCounter counter = new BitCounter(); + andWithContainer(counter, bitmaps); + return counter.getCount(); + } + + /** + * Return a bitmap with the bit set to true at the given + * positions. The positions should be given in sorted order. + * + * (This is a convenience method.) + * + * @since 0.4.5 + * @param setbits list of set bit positions + * @return the bitmap + */ + public static EWAHCompressedBitmap bitmapOf(int ... setbits) { + EWAHCompressedBitmap a = new EWAHCompressedBitmap(); + for (int k : setbits) + a.set(k); + return a; + } + + + + + /** + * For internal use. This simply adds a stream of words made of zeroes so that + * we pad to the desired size. + * + * @param storage + * bitmap to extend + * @param currentSize + * current size (in bits) + * @param newSize + * new desired size (in bits) + * @since 0.4.3 + */ + private static void extendEmptyBits(final BitmapStorage storage, + final int currentSize, final int newSize) { + final int currentLeftover = currentSize % wordinbits; + final int finalLeftover = newSize % wordinbits; + storage.addStreamOfEmptyWords(false, (newSize / wordinbits) - currentSize + / wordinbits + (finalLeftover != 0 ? 1 : 0) + + (currentLeftover != 0 ? -1 : 0)); + } + + + /** + * Uses an adaptive technique to compute the logical OR. + * Mostly for internal use. + * + * @param container where the aggregate is written. + * @param bitmaps to be aggregated + */ + public static void orWithContainer(final BitmapStorage container, + final EWAHCompressedBitmap... bitmaps) { + if (bitmaps.length < 2) + throw new IllegalArgumentException("You should provide at least two bitmaps, provided "+bitmaps.length); + long size = 0L; + long sinbits = 0L; + for (EWAHCompressedBitmap b : bitmaps) { + size += b.sizeInBytes(); + if (sinbits < b.sizeInBits()) + sinbits = b.sizeInBits(); + } + if (size * 8 > sinbits) { + FastAggregation.bufferedorWithContainer(container, 65536, bitmaps); + } else { + FastAggregation.orToContainer(container, bitmaps); + } + } + + + /** + * Uses an adaptive technique to compute the logical XOR. + * Mostly for internal use. + * + * @param container where the aggregate is written. + * @param bitmaps to be aggregated + */ + public static void xorWithContainer(final BitmapStorage container, + final EWAHCompressedBitmap... bitmaps) { + if (bitmaps.length < 2) + throw new IllegalArgumentException("You should provide at least two bitmaps, provided "+bitmaps.length); + long size = 0L; + long sinbits = 0L; + for (EWAHCompressedBitmap b : bitmaps) { + size += b.sizeInBytes(); + if (sinbits < b.sizeInBits()) + sinbits = b.sizeInBits(); + } + if (size * 8 > sinbits) { + FastAggregation.bufferedxorWithContainer(container, 65536, bitmaps); + } else { + FastAggregation.xorToContainer(container, bitmaps); + } + } + /** + * Returns a new compressed bitmap containing the bitwise OR values of the + * provided bitmaps. This is typically faster than doing the aggregation + * two-by-two (A.or(B).or(C).or(D)). + * + * If only one bitmap is provided, it is returned as is. + * + * If you are not planning on adding to the resulting bitmap, you may call the trim() + * method to reduce memory usage. + * + * @since 0.4.0 + * @param bitmaps + * bitmaps to OR together + * @return result of the OR + */ + public static EWAHCompressedBitmap or(final EWAHCompressedBitmap... bitmaps) { + if(bitmaps.length == 1) + return bitmaps[0]; + final EWAHCompressedBitmap container = new EWAHCompressedBitmap(); + int largestSize = 0; + for (EWAHCompressedBitmap bitmap : bitmaps) { + largestSize = Math.max(bitmap.actualsizeinwords, largestSize); + } + container.reserve((int) (largestSize * 1.5)); + orWithContainer(container, bitmaps); + return container; + } + /** + * Returns a new compressed bitmap containing the bitwise XOR values of the + * provided bitmaps. This is typically faster than doing the aggregation + * two-by-two (A.xor(B).xor(C).xor(D)). + * + * If only one bitmap is provided, it is returned as is. + * + * If you are not planning on adding to the resulting bitmap, you may call the trim() + * method to reduce memory usage. + * + * @param bitmaps + * bitmaps to XOR together + * @return result of the XOR + */ + public static EWAHCompressedBitmap xor(final EWAHCompressedBitmap... bitmaps) { + if(bitmaps.length == 1) + return bitmaps[0]; + final EWAHCompressedBitmap container = new EWAHCompressedBitmap(); + int largestSize = 0; + for (EWAHCompressedBitmap bitmap : bitmaps) { + largestSize = Math.max(bitmap.actualsizeinwords, largestSize); + } + container.reserve((int) (largestSize * 1.5)); + xorWithContainer(container, bitmaps); + return container; + } + + /** + * Returns the cardinality of the result of a bitwise OR of the values of the + * provided bitmaps. Avoids needing to allocate an intermediate bitmap to hold + * the result of the OR. + * + * @since 0.4.0 + * @param bitmaps + * bitmaps to OR + * @return the cardinality + */ + public static int orCardinality(final EWAHCompressedBitmap... bitmaps) { + if(bitmaps.length == 1) return bitmaps[0].cardinality(); + final BitCounter counter = new BitCounter(); + orWithContainer(counter, bitmaps); + return counter.getCount(); + } + + /** The actual size in words. */ + int actualsizeinwords = 1; + + /** The buffer (array of 64-bit words) */ + long buffer[] = null; + + /** The current (last) running length word. */ + RunningLengthWord rlw = null; + + /** sizeinbits: number of bits in the (uncompressed) bitmap. */ + int sizeinbits = 0; + + /** + * The Constant defaultbuffersize: default memory allocation when the object + * is constructed. + */ + static final int defaultbuffersize = 4; + + /** optimization option **/ + public static final boolean usetrailingzeros = true; + + /** whether we adjust after some aggregation by adding in zeroes **/ + public static final boolean adjustContainerSizeWhenAggregating = true; + + /** The Constant wordinbits represents the number of bits in a long. */ + public static final int wordinbits = 64; + +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/EWAHIterator.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/EWAHIterator.java new file mode 100644 index 000000000..991698814 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/EWAHIterator.java @@ -0,0 +1,98 @@ +package com.fr.third.googlecode.javaewah; + + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ + +/** + * The class EWAHIterator represents a special type of + * efficient iterator iterating over (uncompressed) words of bits. + * It is not meant for end users. + * @author Daniel Lemire + * @since 0.1.0 + * + */ +public final class EWAHIterator implements Cloneable { + + /** + * Instantiates a new EWAH iterator. + * + * @param a the array of words + * @param sizeinwords the number of words that are significant in the array of words + */ + public EWAHIterator(final EWAHCompressedBitmap a, final int sizeinwords) { + this.rlw = new RunningLengthWord(a, 0); + this.size = sizeinwords; + this.pointer = 0; + } + + /** + * Allow expert developers to instantiate an EWAHIterator. + * + * @param bitmap we want to iterate over + * @return an iterator + */ + public static EWAHIterator getEWAHIterator(EWAHCompressedBitmap bitmap) { + return bitmap.getEWAHIterator(); + } + + + /** + * Access to the array of words + * + * @return the long[] + */ + public long[] buffer() { + return this.rlw.parent.buffer; + } + + /** + * Position of the literal words represented by this running length word. + * + * @return the int + */ + public int literalWords() { + return this.pointer - this.rlw.getNumberOfLiteralWords(); + } + + /** + * Checks for next. + * + * @return true, if successful + */ + public boolean hasNext() { + return this.pointer < this.size; + } + + /** + * Next running length word. + * + * @return the running length word + */ + public RunningLengthWord next() { + this.rlw.position = this.pointer; + this.pointer += this.rlw.getNumberOfLiteralWords() + 1; + return this.rlw; + } + + @Override + public EWAHIterator clone() throws CloneNotSupportedException { + EWAHIterator ans = (EWAHIterator) super.clone(); + ans.rlw = this.rlw.clone(); + ans.size = this.size; + ans.pointer = this.pointer; + return ans; + } + /** The pointer represent the location of the current running length + * word in the array of words (embedded in the rlw attribute). */ + int pointer; + + /** The current running length word. */ + RunningLengthWord rlw; + + /** The size in words. */ + int size; + +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/FastAggregation.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/FastAggregation.java new file mode 100644 index 000000000..80d378469 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/FastAggregation.java @@ -0,0 +1,436 @@ +package com.fr.third.googlecode.javaewah; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.PriorityQueue; + + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ + +/** + * Fast algorithms to aggregate many bitmaps. These algorithms are just given as + * reference. They may not be faster than the corresponding methods in the + * EWAHCompressedBitmap class. + * + * @author Daniel Lemire + * + */ +public class FastAggregation { + /** + * Compute the and aggregate using a temporary uncompressed bitmap. + * @param bitmaps the source bitmaps + * @param bufsize buffer size used during the computation in 64-bit words (per input bitmap) + * @return the or aggregate. + */ + public static EWAHCompressedBitmap bufferedand(final int bufsize, + final EWAHCompressedBitmap... bitmaps) { + EWAHCompressedBitmap answer = new EWAHCompressedBitmap(); + bufferedandWithContainer(answer,bufsize, bitmaps); + return answer; + } + /** + * Compute the and aggregate using a temporary uncompressed bitmap. + * + * @param container where the aggregate is written + * @param bufsize buffer size used during the computation in 64-bit words (per input bitmap) + * @param bitmaps the source bitmaps + */ + public static void bufferedandWithContainer(final BitmapStorage container,final int bufsize, + final EWAHCompressedBitmap... bitmaps) { + + java.util.LinkedList al = new java.util.LinkedList(); + for (EWAHCompressedBitmap bitmap : bitmaps) { + al.add(new IteratingBufferedRunningLengthWord(bitmap)); + } + + long[] hardbitmap = new long[bufsize*bitmaps.length]; + + for(IteratingRLW i : al) + if (i.size() == 0) { + al.clear(); + break; + } + + while (!al.isEmpty()) { + Arrays.fill(hardbitmap, ~0l); + long effective = Integer.MAX_VALUE; + for(IteratingRLW i : al) { + int eff = IteratorAggregation.inplaceand(hardbitmap, i); + if (eff < effective) + effective = eff; + } + for (int k = 0; k < effective; ++k) + container.add(hardbitmap[k]); + for(IteratingRLW i : al) + if (i.size() == 0) { + al.clear(); + break; + } + } + } + + /** + * Compute the or aggregate using a temporary uncompressed bitmap. + * @param bitmaps the source bitmaps + * @param bufsize buffer size used during the computation in 64-bit words + * @return the or aggregate. + */ + public static EWAHCompressedBitmap bufferedor(final int bufsize, + final EWAHCompressedBitmap... bitmaps) { + EWAHCompressedBitmap answer = new EWAHCompressedBitmap(); + bufferedorWithContainer(answer, bufsize, bitmaps); + return answer; + } + + /** + * Compute the or aggregate using a temporary uncompressed bitmap. + * + * @param container where the aggregate is written + * @param bufsize buffer size used during the computation in 64-bit words + * @param bitmaps the source bitmaps + */ + public static void bufferedorWithContainer(final BitmapStorage container, final int bufsize, + final EWAHCompressedBitmap... bitmaps) { + int range = 0; + EWAHCompressedBitmap[] sbitmaps = bitmaps.clone(); + Arrays.sort(sbitmaps, new Comparator() { + @Override + public int compare(EWAHCompressedBitmap a, EWAHCompressedBitmap b) { + return b.sizeinbits - a.sizeinbits; + } + }); + + java.util.ArrayList al = new java.util.ArrayList(); + for (EWAHCompressedBitmap bitmap : sbitmaps) { + if (bitmap.sizeinbits > range) + range = bitmap.sizeinbits; + al.add(new IteratingBufferedRunningLengthWord(bitmap)); + } + long[] hardbitmap = new long[bufsize]; + int maxr = al.size(); + while (maxr > 0) { + long effective = 0; + for (int k = 0; k < maxr; ++k) { + if (al.get(k).size() > 0) { + int eff = IteratorAggregation.inplaceor(hardbitmap, al.get(k)); + if (eff > effective) + effective = eff; + } else + maxr = k; + } + for (int k = 0; k < effective; ++k) + container.add(hardbitmap[k]); + Arrays.fill(hardbitmap, 0); + + } + container.setSizeInBits(range); + } + + /** + * Compute the xor aggregate using a temporary uncompressed bitmap. + * @param bitmaps the source bitmaps + * @param bufsize buffer size used during the computation in 64-bit words + * @return the xor aggregate. + */ + public static EWAHCompressedBitmap bufferedxor(final int bufsize, + final EWAHCompressedBitmap... bitmaps) { + EWAHCompressedBitmap answer = new EWAHCompressedBitmap(); + bufferedxorWithContainer(answer, bufsize,bitmaps); + return answer; + } + + + /** + * Compute the xor aggregate using a temporary uncompressed bitmap. + * + * @param container where the aggregate is written + * @param bufsize buffer size used during the computation in 64-bit words + * @param bitmaps the source bitmaps + */ + public static void bufferedxorWithContainer(final BitmapStorage container, final int bufsize, + final EWAHCompressedBitmap... bitmaps) { + int range = 0; + EWAHCompressedBitmap[] sbitmaps = bitmaps.clone(); + Arrays.sort(sbitmaps, new Comparator() { + @Override + public int compare(EWAHCompressedBitmap a, EWAHCompressedBitmap b) { + return b.sizeinbits - a.sizeinbits; + } + }); + + java.util.ArrayList al = new java.util.ArrayList(); + for (EWAHCompressedBitmap bitmap : sbitmaps) { + if (bitmap.sizeinbits > range) + range = bitmap.sizeinbits; + al.add(new IteratingBufferedRunningLengthWord(bitmap)); + } + long[] hardbitmap = new long[bufsize]; + int maxr = al.size(); + while (maxr > 0) { + long effective = 0; + for (int k = 0; k < maxr; ++k) { + if (al.get(k).size() > 0) { + int eff = IteratorAggregation.inplacexor(hardbitmap, al.get(k)); + if (eff > effective) + effective = eff; + } else + maxr = k; + } + for (int k = 0; k < effective; ++k) + container.add(hardbitmap[k]); + Arrays.fill(hardbitmap, 0); + } + container.setSizeInBits(range); + } + + /** + * Uses a priority queue to compute the or aggregate. + * @param a class extending LogicalElement (like a compressed bitmap) + * @param bitmaps + * bitmaps to be aggregated + * @return the or aggregate + */ + @SuppressWarnings({ "rawtypes", "unchecked" }) + public static T or(T... bitmaps) { + PriorityQueue pq = new PriorityQueue(bitmaps.length, + new Comparator() { + @Override + public int compare(T a, T b) { + return a.sizeInBytes() - b.sizeInBytes(); + } + }); + for (T x : bitmaps) { + pq.add(x); + } + while (pq.size() > 1) { + T x1 = pq.poll(); + T x2 = pq.poll(); + pq.add((T) x1.or(x2)); + } + return pq.poll(); + } + /** + * Uses a priority queue to compute the or aggregate. + * @param container where we write the result + * @param bitmaps to be aggregated + */ + public static void orToContainer(final BitmapStorage container, + final EWAHCompressedBitmap ... bitmaps) { + if(bitmaps.length < 2) throw new IllegalArgumentException("We need at least two bitmaps"); + PriorityQueue pq = new PriorityQueue(bitmaps.length, + new Comparator() { + @Override + public int compare(EWAHCompressedBitmap a, EWAHCompressedBitmap b) { + return a.sizeInBytes() - b.sizeInBytes(); + } + }); + for (EWAHCompressedBitmap x : bitmaps) { + pq.add(x); + } + while (pq.size() > 2) { + EWAHCompressedBitmap x1 = pq.poll(); + EWAHCompressedBitmap x2 = pq.poll(); + pq.add(x1.or(x2)); + } + pq.poll().orToContainer(pq.poll(), container); + } + + + /** + * Uses a priority queue to compute the xor aggregate. + * + * @param a class extending LogicalElement (like a compressed bitmap) + * @param bitmaps + * bitmaps to be aggregated + * @return the xor aggregate + */ + @SuppressWarnings({ "rawtypes", "unchecked" }) + public static T xor(T... bitmaps) { + PriorityQueue pq = new PriorityQueue(bitmaps.length, + new Comparator() { + + @Override + public int compare(T a, T b) { + return a.sizeInBytes() - b.sizeInBytes(); + } + }); + for (T x : bitmaps) + pq.add(x); + while (pq.size() > 1) { + T x1 = pq.poll(); + T x2 = pq.poll(); + pq.add((T) x1.xor(x2)); + } + return pq.poll(); + } + + /** + * Uses a priority queue to compute the xor aggregate. + * @param container where we write the result + * @param bitmaps to be aggregated + */ + public static void xorToContainer(final BitmapStorage container, + final EWAHCompressedBitmap ... bitmaps) { + if(bitmaps.length < 2) throw new IllegalArgumentException("We need at least two bitmaps"); + PriorityQueue pq = new PriorityQueue(bitmaps.length, + new Comparator() { + @Override + public int compare(EWAHCompressedBitmap a, EWAHCompressedBitmap b) { + return a.sizeInBytes() - b.sizeInBytes(); + } + }); + for (EWAHCompressedBitmap x : bitmaps) { + pq.add(x); + } + while (pq.size() > 2) { + EWAHCompressedBitmap x1 = pq.poll(); + EWAHCompressedBitmap x2 = pq.poll(); + pq.add(x1.xor(x2)); + } + pq.poll().xorToContainer(pq.poll(), container); + } + + /** + * For internal use. Computes the bitwise or of the provided bitmaps and + * stores the result in the container. (This used to be the default.) + * + * @deprecated use EWAHCompressedBitmap.or instead + * @since 0.4.0 + * @param container where store the result + * @param bitmaps to be aggregated + */ + @Deprecated + public static void legacy_orWithContainer(final BitmapStorage container, + final EWAHCompressedBitmap... bitmaps) { + if (bitmaps.length == 2) { + // should be more efficient + bitmaps[0].orToContainer(bitmaps[1], container); + return; + } + + // Sort the bitmaps in descending order by sizeinbits. We will exhaust the + // sorted bitmaps from right to left. + final EWAHCompressedBitmap[] sortedBitmaps = bitmaps.clone(); + Arrays.sort(sortedBitmaps, new Comparator() { + @Override + public int compare(EWAHCompressedBitmap a, EWAHCompressedBitmap b) { + return a.sizeinbits < b.sizeinbits ? 1 + : a.sizeinbits == b.sizeinbits ? 0 : -1; + } + }); + + final IteratingBufferedRunningLengthWord[] rlws = new IteratingBufferedRunningLengthWord[bitmaps.length]; + int maxAvailablePos = 0; + for (EWAHCompressedBitmap bitmap : sortedBitmaps) { + EWAHIterator iterator = bitmap.getEWAHIterator(); + if (iterator.hasNext()) { + rlws[maxAvailablePos++] = new IteratingBufferedRunningLengthWord( + iterator); + } + } + + if (maxAvailablePos == 0) { // this never happens... + container.setSizeInBits(0); + return; + } + + int maxSize = sortedBitmaps[0].sizeinbits; + + while (true) { + long maxOneRl = 0; + long minZeroRl = Long.MAX_VALUE; + long minSize = Long.MAX_VALUE; + int numEmptyRl = 0; + for (int i = 0; i < maxAvailablePos; i++) { + IteratingBufferedRunningLengthWord rlw = rlws[i]; + long size = rlw.size(); + if (size == 0) { + maxAvailablePos = i; + break; + } + minSize = Math.min(minSize, size); + + if (rlw.getRunningBit()) { + long rl = rlw.getRunningLength(); + maxOneRl = Math.max(maxOneRl, rl); + minZeroRl = 0; + if (rl == 0 && size > 0) { + numEmptyRl++; + } + } else { + long rl = rlw.getRunningLength(); + minZeroRl = Math.min(minZeroRl, rl); + if (rl == 0 && size > 0) { + numEmptyRl++; + } + } + } + + if (maxAvailablePos == 0) { + break; + } else if (maxAvailablePos == 1) { + // only one bitmap is left so just write the rest of it out + rlws[0].discharge(container); + break; + } + + if (maxOneRl > 0) { + container.addStreamOfEmptyWords(true, maxOneRl); + for (int i = 0; i < maxAvailablePos; i++) { + IteratingBufferedRunningLengthWord rlw = rlws[i]; + rlw.discardFirstWords(maxOneRl); + } + } else if (minZeroRl > 0) { + container.addStreamOfEmptyWords(false, minZeroRl); + for (int i = 0; i < maxAvailablePos; i++) { + IteratingBufferedRunningLengthWord rlw = rlws[i]; + rlw.discardFirstWords(minZeroRl); + } + } else { + int index = 0; + + if (numEmptyRl == 1) { + // if one rlw has literal words to process and the rest have a run of + // 0's we can write them out here + IteratingBufferedRunningLengthWord emptyRl = null; + long minNonEmptyRl = Long.MAX_VALUE; + for (int i = 0; i < maxAvailablePos; i++) { + IteratingBufferedRunningLengthWord rlw = rlws[i]; + long rl = rlw.getRunningLength(); + if (rl == 0) { + assert emptyRl == null; + emptyRl = rlw; + } else { + minNonEmptyRl = Math.min(minNonEmptyRl, rl); + } + } + long wordsToWrite = minNonEmptyRl > minSize ? minSize : minNonEmptyRl; + if (emptyRl != null) + emptyRl.writeLiteralWords((int) wordsToWrite, container); + index += wordsToWrite; + } + + while (index < minSize) { + long word = 0; + for (int i = 0; i < maxAvailablePos; i++) { + IteratingBufferedRunningLengthWord rlw = rlws[i]; + if (rlw.getRunningLength() <= index) { + word |= rlw.getLiteralWordAt(index - (int) rlw.getRunningLength()); + } + } + container.add(word); + index++; + } + for (int i = 0; i < maxAvailablePos; i++) { + IteratingBufferedRunningLengthWord rlw = rlws[i]; + rlw.discardFirstWords(minSize); + } + } + } + container.setSizeInBits(maxSize); + } + +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/IntIterator.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/IntIterator.java new file mode 100644 index 000000000..2aa5ef020 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/IntIterator.java @@ -0,0 +1,31 @@ +package com.fr.third.googlecode.javaewah; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ + +/** + * + * The IntIterator interface is used to iterate over a stream of integers. + * + * @author Daniel Lemire + * @since 0.2.0 + * + */ +public interface IntIterator { + + /** + * Is there more? + * + * @return true, if there is more, false otherwise + */ + public boolean hasNext(); + + /** + * Return the next integer + * + * @return the integer + */ + public int next(); +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/IntIteratorImpl.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/IntIteratorImpl.java new file mode 100644 index 000000000..0728ce643 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/IntIteratorImpl.java @@ -0,0 +1,87 @@ +package com.fr.third.googlecode.javaewah; + +/* + * Copyright 2012, Google Inc. + * Licensed under the Apache License, Version 2.0. + */ + +import static com.fr.third.googlecode.javaewah.EWAHCompressedBitmap.wordinbits; + +/** + * The IntIteratorImpl is the 64 bit implementation of the + * IntIterator interface, which efficiently returns the stream of integers + * represented by an EWAHIterator. + * + * @author Colby Ranger + * @since 0.5.6 + */ +final class IntIteratorImpl implements IntIterator { + + private final EWAHIterator ewahIter; + private final long[] ewahBuffer; + private int position; + private int runningLength; + private long word; + private int wordPosition; + private int wordLength; + private int literalPosition; + private boolean hasnext; + + IntIteratorImpl(EWAHIterator ewahIter) { + this.ewahIter = ewahIter; + this.ewahBuffer = ewahIter.buffer(); + this.hasnext = this.moveToNext(); + } + + public final boolean moveToNext() { + while (!runningHasNext() && !literalHasNext()) { + if (!this.ewahIter.hasNext()) { + return false; + } + setRunningLengthWord(this.ewahIter.next()); + } + return true; + } + + @Override +public boolean hasNext() { + return this.hasnext; + } + + @Override +public final int next() { + final int answer; + if (runningHasNext()) { + answer = this.position++; + } else { + final int bit = Long.numberOfTrailingZeros(this.word); + this.word ^= (1l << bit); + answer = this.literalPosition + bit; + } + this.hasnext = this.moveToNext(); + return answer; + } + + private final void setRunningLengthWord(RunningLengthWord rlw) { + this.runningLength = wordinbits * (int) rlw.getRunningLength() + this.position; + if (!rlw.getRunningBit()) { + this.position = this.runningLength; + } + + this.wordPosition = this.ewahIter.literalWords(); + this.wordLength = this.wordPosition + rlw.getNumberOfLiteralWords(); + } + + private final boolean runningHasNext() { + return this.position < this.runningLength; + } + + private final boolean literalHasNext() { + while (this.word == 0 && this.wordPosition < this.wordLength) { + this.word = this.ewahBuffer[this.wordPosition++]; + this.literalPosition = this.position; + this.position += wordinbits; + } + return this.word != 0; + } +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/IntIteratorOverIteratingRLW.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/IntIteratorOverIteratingRLW.java new file mode 100644 index 000000000..c4bf20f63 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/IntIteratorOverIteratingRLW.java @@ -0,0 +1,89 @@ +package com.fr.third.googlecode.javaewah; + +import static com.fr.third.googlecode.javaewah.EWAHCompressedBitmap.wordinbits; + + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ +/** + * Implementation of an IntIterator over an IteratingRLW. + * + * + */ +public class IntIteratorOverIteratingRLW implements IntIterator { + IteratingRLW parent; + private int position; + private int runningLength; + private long word; + private int wordPosition; + private int wordLength; + private int literalPosition; + private boolean hasnext; + + /** + * @param p iterator we wish to iterate over + */ + public IntIteratorOverIteratingRLW(final IteratingRLW p) { + this.parent = p; + this.position = 0; + setupForCurrentRunningLengthWord(); + this.hasnext = moveToNext(); + } + + /** + * @return whether we could find another set bit; don't move if there is an unprocessed value + */ + private final boolean moveToNext() { + while (!runningHasNext() && !literalHasNext()) { + if (this.parent.next()) + setupForCurrentRunningLengthWord(); + else return false; + } + return true; + } + + @Override + public boolean hasNext() { + return this.hasnext; + } + + @Override + public final int next() { + final int answer; + if (runningHasNext()) { + answer = this.position++; + } else { + final int bit = Long.numberOfTrailingZeros(this.word); + this.word ^= (1l << bit); + answer = this.literalPosition + bit; + } + this.hasnext = this.moveToNext(); + return answer; + } + + private final void setupForCurrentRunningLengthWord() { + this.runningLength = wordinbits * (int) this.parent.getRunningLength() + + this.position; + + if (!this.parent.getRunningBit()) { + this.position = this.runningLength; + } + this.wordPosition = 0; + this.wordLength = this.parent.getNumberOfLiteralWords(); + } + + private final boolean runningHasNext() { + return this.position < this.runningLength; + } + + private final boolean literalHasNext() { + while (this.word == 0 && this.wordPosition < this.wordLength) { + this.word = this.parent.getLiteralWordAt(this.wordPosition++); + this.literalPosition = this.position; + this.position += wordinbits; + } + return this.word != 0; + } +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/IteratingBufferedRunningLengthWord.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/IteratingBufferedRunningLengthWord.java new file mode 100644 index 000000000..bb8f2edc5 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/IteratingBufferedRunningLengthWord.java @@ -0,0 +1,276 @@ +package com.fr.third.googlecode.javaewah; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ +/** + * Mostly for internal use. Similar to BufferedRunningLengthWord, but automatically + * advances to the next BufferedRunningLengthWord as words are discarded. + * + * @since 0.4.0 + * @author David McIntosh + */ +public final class IteratingBufferedRunningLengthWord implements IteratingRLW, Cloneable{ + /** + * Instantiates a new iterating buffered running length word. + * + * @param iterator iterator + */ + public IteratingBufferedRunningLengthWord(final EWAHIterator iterator) { + this.iterator = iterator; + this.brlw = new BufferedRunningLengthWord(this.iterator.next()); + this.literalWordStartPosition = this.iterator.literalWords() + this.brlw.literalwordoffset; + this.buffer = this.iterator.buffer(); + } + + + + /** + * Instantiates a new iterating buffered running length word. + * @param bitmap over which we want to iterate + * + */ +public IteratingBufferedRunningLengthWord(final EWAHCompressedBitmap bitmap) { + this.iterator = EWAHIterator.getEWAHIterator(bitmap); + this.brlw = new BufferedRunningLengthWord(this.iterator.next()); + this.literalWordStartPosition = this.iterator.literalWords() + this.brlw.literalwordoffset; + this.buffer = this.iterator.buffer(); + } + + + + + /** + * Discard first words, iterating to the next running length word if needed. + * + * @param x the number of words to be discarded + */ + @Override +public void discardFirstWords(long x) { + while (x > 0) { + if (this.brlw.RunningLength > x) { + this.brlw.RunningLength -= x; + return; + } + x -= this.brlw.RunningLength; + this.brlw.RunningLength = 0; + long toDiscard = x > this.brlw.NumberOfLiteralWords ? this.brlw.NumberOfLiteralWords : x; + + this.literalWordStartPosition += toDiscard; + this.brlw.NumberOfLiteralWords -= toDiscard; + x -= toDiscard; + if ((x > 0) || (this.brlw.size() == 0)) { + if (!this.iterator.hasNext()) { + break; + } + this.brlw.reset(this.iterator.next()); + this.literalWordStartPosition = this.iterator.literalWords(); // + this.brlw.literalwordoffset ==0 + } + } + } + /** + * Move to the next RunningLengthWord + * @return whether the move was possible + */ + @Override +public boolean next() { + if (!this.iterator.hasNext()) { + this.brlw.NumberOfLiteralWords = 0; + this.brlw.RunningLength = 0; + return false; + } + this.brlw.reset(this.iterator.next()); + this.literalWordStartPosition = this.iterator.literalWords(); // + this.brlw.literalwordoffset ==0 + return true; + } + + /** + * Write out up to max words, returns how many were written + * @param container target for writes + * @param max maximal number of writes + * @return how many written + */ + public long discharge(BitmapStorage container, long max) { + long index = 0; + while ((index < max) && (size() > 0)) { + // first run + long pl = getRunningLength(); + if (index + pl > max) { + pl = max - index; + } + container.addStreamOfEmptyWords(getRunningBit(), pl); + index += pl; + int pd = getNumberOfLiteralWords(); + if (pd + index > max) { + pd = (int) (max - index); + } + writeLiteralWords(pd, container); + discardFirstWords(pl+pd); + index += pd; + } + return index; + } + + /** + * Write out up to max words (negated), returns how many were written + * @param container target for writes + * @param max maximal number of writes + * @return how many written + */ + public long dischargeNegated(BitmapStorage container, long max) { + long index = 0; + while ((index < max) && (size() > 0)) { + // first run + long pl = getRunningLength(); + if (index + pl > max) { + pl = max - index; + } + container.addStreamOfEmptyWords(!getRunningBit(), pl); + index += pl; + int pd = getNumberOfLiteralWords(); + if (pd + index > max) { + pd = (int) (max - index); + } + writeNegatedLiteralWords(pd, container); + discardFirstWords(pl+pd); + index += pd; + } + return index; + } + + + /** + * Write out the remain words, transforming them to zeroes. + * @param container target for writes + */ + public void dischargeAsEmpty(BitmapStorage container) { + while(size()>0) { + container.addStreamOfEmptyWords(false, size()); + discardFirstWords(size()); + } + } + + + + /** + * Write out the remaining words + * @param container target for writes + */ + public void discharge(BitmapStorage container) { + this.brlw.literalwordoffset = this.literalWordStartPosition - this.iterator.literalWords(); + discharge(this.brlw, this.iterator, container); + } + + /** + * Get the nth literal word for the current running length word + * @param index zero based index + * @return the literal word + */ + @Override +public long getLiteralWordAt(int index) { + return this.buffer[this.literalWordStartPosition + index]; + } + + /** + * Gets the number of literal words for the current running length word. + * + * @return the number of literal words + */ + @Override +public int getNumberOfLiteralWords() { + return this.brlw.NumberOfLiteralWords; + } + + /** + * Gets the running bit. + * + * @return the running bit + */ + @Override +public boolean getRunningBit() { + return this.brlw.RunningBit; + } + + /** + * Gets the running length. + * + * @return the running length + */ + @Override +public long getRunningLength() { + return this.brlw.RunningLength; + } + + /** + * Size in uncompressed words of the current running length word. + * + * @return the long + */ + @Override +public long size() { + return this.brlw.size(); + } + + /** + * write the first N literal words to the target bitmap. Does not discard the words or perform iteration. + * @param numWords number of words to be written + * @param container where we write + */ + public void writeLiteralWords(int numWords, BitmapStorage container) { + container.addStreamOfLiteralWords(this.buffer, this.literalWordStartPosition, numWords); + } + + /** + * write the first N literal words (negated) to the target bitmap. Does not discard the words or perform iteration. + * @param numWords number of words to be written + * @param container where we write + */ + public void writeNegatedLiteralWords(int numWords, BitmapStorage container) { + container.addStreamOfNegatedLiteralWords(this.buffer, this.literalWordStartPosition, numWords); + } + + /** + * For internal use. (One could use the non-static discharge method instead, + * but we expect them to be slower.) + * + * @param initialWord + * the initial word + * @param iterator + * the iterator + * @param container + * the container + */ + private static void discharge(final BufferedRunningLengthWord initialWord, + final EWAHIterator iterator, final BitmapStorage container) { + BufferedRunningLengthWord runningLengthWord = initialWord; + for (;;) { + final long runningLength = runningLengthWord.getRunningLength(); + container.addStreamOfEmptyWords(runningLengthWord.getRunningBit(), + runningLength); + container.addStreamOfLiteralWords(iterator.buffer(), iterator.literalWords() + + runningLengthWord.literalwordoffset, + runningLengthWord.getNumberOfLiteralWords()); + if (!iterator.hasNext()) + break; + runningLengthWord = new BufferedRunningLengthWord(iterator.next()); + } + } + + + @Override + public IteratingBufferedRunningLengthWord clone() throws CloneNotSupportedException { + IteratingBufferedRunningLengthWord answer = (IteratingBufferedRunningLengthWord) super.clone(); + answer.brlw = this.brlw.clone(); + answer.buffer = this.buffer; + answer.iterator = this.iterator.clone(); + answer.literalWordStartPosition = this.literalWordStartPosition; + return answer; + } + + + private BufferedRunningLengthWord brlw; + private long[] buffer; + private int literalWordStartPosition; + private EWAHIterator iterator; +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/IteratingRLW.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/IteratingRLW.java new file mode 100644 index 000000000..868b93c5e --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/IteratingRLW.java @@ -0,0 +1,49 @@ +package com.fr.third.googlecode.javaewah; + + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ + +/** + * High-level iterator over a compressed bitmap. + * + */ +public interface IteratingRLW { + /** + * @return whether there is more + */ + public boolean next() ; + /** + * @param index where the literal word is + * @return the literal word at the given index. + */ + public long getLiteralWordAt(int index); + /** + * @return the number of literal (non-fill) words + */ + public int getNumberOfLiteralWords() ; + /** + * @return the bit used for the fill bits + */ + public boolean getRunningBit() ; + /** + * @return sum of getRunningLength() and getNumberOfLiteralWords() + */ + public long size() ; + /** + * @return length of the run of fill words + */ + public long getRunningLength() ; + /** + * @param x the number of words to discard + */ + public void discardFirstWords(long x); + + /** + * @return a copy of the iterator + * @throws CloneNotSupportedException this should not be thrown in theory + */ + public IteratingRLW clone() throws CloneNotSupportedException; +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/IteratorAggregation.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/IteratorAggregation.java new file mode 100644 index 000000000..87386625a --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/IteratorAggregation.java @@ -0,0 +1,616 @@ +package com.fr.third.googlecode.javaewah; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedList; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ + +/** + * Set of helper functions to aggregate bitmaps. + * + */ +public class IteratorAggregation { + + /** + * @param x iterator to negate + * @return negated version of the iterator + */ + public static IteratingRLW not(final IteratingRLW x) { + return new IteratingRLW() { + + @Override + public boolean next() { + return x.next(); + } + + @Override + public long getLiteralWordAt(int index) { + return ~x.getLiteralWordAt(index); + } + + @Override + public int getNumberOfLiteralWords() { + return x.getNumberOfLiteralWords(); + } + + @Override + public boolean getRunningBit() { + return ! x.getRunningBit(); + } + + @Override + public long size() { + return x.size(); + } + + @Override + public long getRunningLength() { + return x.getRunningLength(); + } + + @Override + public void discardFirstWords(long y) { + x.discardFirstWords(y); + } + + @Override + public IteratingRLW clone() throws CloneNotSupportedException { + throw new CloneNotSupportedException(); + } + + + }; + } + + /** + * Aggregate the iterators using a bitmap buffer. + * + * @param al set of iterators to aggregate + * @return and aggregate + */ + public static IteratingRLW bufferedand(final IteratingRLW... al) { + return bufferedand(DEFAULTMAXBUFSIZE,al); + } + + /** + * Aggregate the iterators using a bitmap buffer. + * + * @param al set of iterators to aggregate + * @param bufsize size of the internal buffer used by the iterator in 64-bit words (per input iterator) + * @return and aggregate + */ + public static IteratingRLW bufferedand(final int bufsize, final IteratingRLW... al) { + if (al.length == 0) + throw new IllegalArgumentException("Need at least one iterator"); + if (al.length == 1) + return al[0]; + final LinkedList basell = new LinkedList(); + for (IteratingRLW i : al) + basell.add(i); + return new BufferedIterator(new BufferedAndIterator(basell,bufsize)); + } + + /** + * Aggregate the iterators using a bitmap buffer. + * + * @param al set of iterators to aggregate + * @return or aggregate + */ + public static IteratingRLW bufferedor(final IteratingRLW... al) { + return bufferedor(DEFAULTMAXBUFSIZE,al); + } + + + /** + * Aggregate the iterators using a bitmap buffer. + * + * @param al iterators to aggregate + * @param bufsize size of the internal buffer used by the iterator in 64-bit words + * @return or aggregate + */ + public static IteratingRLW bufferedor(final int bufsize, final IteratingRLW... al) { + if (al.length == 0) + throw new IllegalArgumentException("Need at least one iterator"); + if (al.length == 1) + return al[0]; + + final LinkedList basell = new LinkedList(); + for (IteratingRLW i : al) + basell.add(i); + return new BufferedIterator(new BufferedORIterator(basell,bufsize)); + } + + /** + * Aggregate the iterators using a bitmap buffer. + * + * @param al set of iterators to aggregate + * @return xor aggregate + */ + public static IteratingRLW bufferedxor(final IteratingRLW... al) { + return bufferedxor(DEFAULTMAXBUFSIZE,al); + } + + + /** + * Aggregate the iterators using a bitmap buffer. + * + * @param al iterators to aggregate + * @param bufsize size of the internal buffer used by the iterator in 64-bit words + * @return xor aggregate + */ + public static IteratingRLW bufferedxor(final int bufsize, final IteratingRLW... al) { + if (al.length == 0) + throw new IllegalArgumentException("Need at least one iterator"); + if (al.length == 1) + return al[0]; + + + final LinkedList basell = new LinkedList(); + for (IteratingRLW i : al) + basell.add(i); + + return new BufferedIterator(new BufferedXORIterator(basell, bufsize)); + } + + + /** + * Write out the content of the iterator, but as if it were all zeros. + * + * @param container + * where we write + * @param i + * the iterator + */ + protected static void dischargeAsEmpty(final BitmapStorage container, + final IteratingRLW i) { + while (i.size() > 0) { + container.addStreamOfEmptyWords(false, i.size()); + i.next(); + + } + } + + /** + * Write out up to max words, returns how many were written + * @param container target for writes + * @param i source of data + * @param max maximal number of writes + * @return how many written + */ + + protected static long discharge(final BitmapStorage container, IteratingRLW i, long max) { + long counter = 0; + while (i.size() > 0 && counter < max) { + long L1 = i.getRunningLength(); + if (L1 > 0) { + if (L1 + counter > max) + L1 = max - counter; + container.addStreamOfEmptyWords(i.getRunningBit(), L1); + counter += L1; + } + long L = i.getNumberOfLiteralWords(); + if(L + counter > max) L = max - counter; + for (int k = 0; k < L; ++k) { + container.add(i.getLiteralWordAt(k)); + } + counter += L; + i.discardFirstWords(L+L1); + } + return counter; + } + + + /** + * Write out up to max negated words, returns how many were written + * @param container target for writes + * @param i source of data + * @param max maximal number of writes + * @return how many written + */ + protected static long dischargeNegated(final BitmapStorage container, IteratingRLW i, long max) { + long counter = 0; + while (i.size() > 0 && counter < max) { + long L1 = i.getRunningLength(); + if (L1 > 0) { + if (L1 + counter > max) + L1 = max - counter; + container.addStreamOfEmptyWords(!i.getRunningBit(), L1); + counter += L1; + } + long L = i.getNumberOfLiteralWords(); + if(L + counter > max) L = max - counter; + for (int k = 0; k < L; ++k) { + container.add(~i.getLiteralWordAt(k)); + } + counter += L; + i.discardFirstWords(L+L1); + } + return counter; + } + + static void andToContainer(final BitmapStorage container, + int desiredrlwcount, final IteratingRLW rlwi, IteratingRLW rlwj) { + while ((rlwi.size()>0) && (rlwj.size()>0) && (desiredrlwcount-- >0) ) { + while ((rlwi.getRunningLength() > 0) || (rlwj.getRunningLength() > 0)) { + final boolean i_is_prey = rlwi.getRunningLength() < rlwj + .getRunningLength(); + final IteratingRLW prey = i_is_prey ? rlwi : rlwj; + final IteratingRLW predator = i_is_prey ? rlwj + : rlwi; + if (predator.getRunningBit() == false) { + container.addStreamOfEmptyWords(false, predator.getRunningLength()); + prey.discardFirstWords(predator.getRunningLength()); + predator.discardFirstWords(predator.getRunningLength()); + } else { + final long index = discharge(container, prey, predator.getRunningLength()); + container.addStreamOfEmptyWords(false, predator.getRunningLength() + - index); + predator.discardFirstWords(predator.getRunningLength()); + } + } + final int nbre_literal = Math.min(rlwi.getNumberOfLiteralWords(), + rlwj.getNumberOfLiteralWords()); + if (nbre_literal > 0) { + desiredrlwcount -= nbre_literal; + for (int k = 0; k < nbre_literal; ++k) + container.add(rlwi.getLiteralWordAt(k) & rlwj.getLiteralWordAt(k)); + rlwi.discardFirstWords(nbre_literal); + rlwj.discardFirstWords(nbre_literal); + } + } + } + + static void andToContainer(final BitmapStorage container, + final IteratingRLW rlwi, IteratingRLW rlwj) { + while ((rlwi.size()>0) && (rlwj.size()>0) ) { + while ((rlwi.getRunningLength() > 0) || (rlwj.getRunningLength() > 0)) { + final boolean i_is_prey = rlwi.getRunningLength() < rlwj + .getRunningLength(); + final IteratingRLW prey = i_is_prey ? rlwi : rlwj; + final IteratingRLW predator = i_is_prey ? rlwj + : rlwi; + if (predator.getRunningBit() == false) { + container.addStreamOfEmptyWords(false, predator.getRunningLength()); + prey.discardFirstWords(predator.getRunningLength()); + predator.discardFirstWords(predator.getRunningLength()); + } else { + final long index = discharge(container, prey, predator.getRunningLength()); + container.addStreamOfEmptyWords(false, predator.getRunningLength() + - index); + predator.discardFirstWords(predator.getRunningLength()); + } + } + final int nbre_literal = Math.min(rlwi.getNumberOfLiteralWords(), + rlwj.getNumberOfLiteralWords()); + if (nbre_literal > 0) { + for (int k = 0; k < nbre_literal; ++k) + container.add(rlwi.getLiteralWordAt(k) & rlwj.getLiteralWordAt(k)); + rlwi.discardFirstWords(nbre_literal); + rlwj.discardFirstWords(nbre_literal); + } + } + } + + + /** + * Compute the first few words of the XOR aggregate between two iterators. + * + * @param container where to write + * @param desiredrlwcount number of words to be written (max) + * @param rlwi first iterator to aggregate + * @param rlwj second iterator to aggregate + */ + public static void xorToContainer(final BitmapStorage container, + int desiredrlwcount, final IteratingRLW rlwi, final IteratingRLW rlwj) { + while ((rlwi.size()>0) && (rlwj.size()>0) && (desiredrlwcount-- >0) ) { + while ((rlwi.getRunningLength() > 0) || (rlwj.getRunningLength() > 0)) { + final boolean i_is_prey = rlwi.getRunningLength() < rlwj + .getRunningLength(); + final IteratingRLW prey = i_is_prey ? rlwi : rlwj; + final IteratingRLW predator = i_is_prey ? rlwj + : rlwi; + if (predator.getRunningBit() == false) { + long index = discharge(container, prey, predator.getRunningLength()); + container.addStreamOfEmptyWords(false, predator.getRunningLength() + - index); + predator.discardFirstWords(predator.getRunningLength()); + } else { + long index = dischargeNegated(container, prey, predator.getRunningLength()); + container.addStreamOfEmptyWords(true, predator.getRunningLength() + - index); + predator.discardFirstWords(predator.getRunningLength()); + } + } + final int nbre_literal = Math.min(rlwi.getNumberOfLiteralWords(), + rlwj.getNumberOfLiteralWords()); + if (nbre_literal > 0) { + desiredrlwcount -= nbre_literal; + for (int k = 0; k < nbre_literal; ++k) + container.add(rlwi.getLiteralWordAt(k) ^ rlwj.getLiteralWordAt(k)); + rlwi.discardFirstWords(nbre_literal); + rlwj.discardFirstWords(nbre_literal); + } + } + } + + protected static int inplaceor(long[] bitmap, + IteratingRLW i) { + + int pos = 0; + long s; + while ((s = i.size()) > 0) { + if (pos + s < bitmap.length) { + final int L = (int) i.getRunningLength(); + if (i.getRunningBit()) + Arrays.fill(bitmap, pos, pos + L, ~0l); + pos += L; + final int LR = i.getNumberOfLiteralWords(); + + for (int k = 0; k < LR; ++k) + bitmap[pos++] |= i.getLiteralWordAt(k); + if (!i.next()) { + return pos; + } + } else { + int howmany = bitmap.length - pos; + int L = (int) i.getRunningLength(); + + if (pos + L > bitmap.length) { + if (i.getRunningBit()) { + Arrays.fill(bitmap, pos, bitmap.length, ~0l); + } + i.discardFirstWords(howmany); + return bitmap.length; + } + if (i.getRunningBit()) + Arrays.fill(bitmap, pos, pos + L, ~0l); + pos += L; + for (int k = 0; pos < bitmap.length; ++k) + bitmap[pos++] |= i.getLiteralWordAt(k); + i.discardFirstWords(howmany); + return pos; + } + } + return pos; + } + + protected static int inplacexor(long[] bitmap, + IteratingRLW i) { + int pos = 0; + long s; + while ((s = i.size()) > 0) { + if (pos + s < bitmap.length) { + final int L = (int) i.getRunningLength(); + if (i.getRunningBit()) { + for(int k = pos ; k < pos + L; ++k) + bitmap[k] = ~bitmap[k]; + } + pos += L; + final int LR = i.getNumberOfLiteralWords(); + for (int k = 0; k < LR; ++k) + bitmap[pos++] ^= i.getLiteralWordAt(k); + if (!i.next()) { + return pos; + } + } else { + int howmany = bitmap.length - pos; + int L = (int) i.getRunningLength(); + if (pos + L > bitmap.length) { + if (i.getRunningBit()) { + for(int k = pos ; k < bitmap.length; ++k) + bitmap[k] = ~bitmap[k]; + } + i.discardFirstWords(howmany); + return bitmap.length; + } + if (i.getRunningBit()) + for(int k = pos ; k < pos + L; ++k) + bitmap[k] = ~bitmap[k]; + pos += L; + for (int k = 0; pos < bitmap.length; ++k) + bitmap[pos++] ^= i.getLiteralWordAt(k); + i.discardFirstWords(howmany); + return pos; + } + } + return pos; + } + protected static int inplaceand(long[] bitmap, + IteratingRLW i) { + int pos = 0; + long s; + while ((s = i.size()) > 0) { + if (pos + s < bitmap.length) { + final int L = (int) i.getRunningLength(); + if (!i.getRunningBit()) { + for(int k = pos ; k < pos + L; ++k) + bitmap[k] = 0; + } + pos += L; + final int LR = i.getNumberOfLiteralWords(); + for (int k = 0; k < LR; ++k) + bitmap[pos++] &= i.getLiteralWordAt(k); + if (!i.next()) { + return pos; + } + } else { + int howmany = bitmap.length - pos; + int L = (int) i.getRunningLength(); + if (pos + L > bitmap.length) { + if (!i.getRunningBit()) { + for(int k = pos ; k < bitmap.length; ++k) + bitmap[k] = 0; + } + i.discardFirstWords(howmany); + return bitmap.length; + } + if (!i.getRunningBit()) + for(int k = pos ; k < pos + L; ++k) + bitmap[k] = 0; + pos += L; + for (int k = 0; pos < bitmap.length; ++k) + bitmap[pos++] &= i.getLiteralWordAt(k); + i.discardFirstWords(howmany); + return pos; + } + } + return pos; + } + + /** + * An optimization option. Larger values may improve speed, but at + * the expense of memory. + */ + public final static int DEFAULTMAXBUFSIZE = 65536; +} +class BufferedORIterator implements CloneableIterator { + EWAHCompressedBitmap buffer = new EWAHCompressedBitmap(); + long[] hardbitmap; + LinkedList ll; + int buffersize; + + BufferedORIterator(LinkedList basell, int bufsize) { + this.ll = basell; + this.hardbitmap = new long[bufsize]; + } + + @Override + public BufferedXORIterator clone() throws CloneNotSupportedException { + BufferedXORIterator answer = (BufferedXORIterator) super.clone(); + answer.buffer = this.buffer.clone(); + answer.hardbitmap = this.hardbitmap.clone(); + answer.ll = (LinkedList) this.ll.clone(); + return answer; + } + + @Override + public boolean hasNext() { + return !this.ll.isEmpty(); + } + + @Override + public EWAHIterator next() { + this.buffer.clear(); + long effective = 0; + Iterator i = this.ll.iterator(); + while (i.hasNext()) { + IteratingRLW rlw = i.next(); + if (rlw.size() > 0) { + int eff = IteratorAggregation.inplaceor(this.hardbitmap, rlw); + if (eff > effective) + effective = eff; + } else + i.remove(); + } + for (int k = 0; k < effective; ++k) { + this.buffer.add(this.hardbitmap[k]); + } + + Arrays.fill(this.hardbitmap, 0); + return this.buffer.getEWAHIterator(); + } +} + +class BufferedXORIterator implements CloneableIterator { + EWAHCompressedBitmap buffer = new EWAHCompressedBitmap(); + long[] hardbitmap; + LinkedList ll; + int buffersize; + + BufferedXORIterator(LinkedList basell, int bufsize) { + this.ll = basell; + this.hardbitmap = new long[bufsize]; + } + + @Override + public BufferedXORIterator clone() throws CloneNotSupportedException { + BufferedXORIterator answer = (BufferedXORIterator) super.clone(); + answer.buffer = this.buffer.clone(); + answer.hardbitmap = this.hardbitmap.clone(); + answer.ll = (LinkedList) this.ll.clone(); + return answer; + } + + @Override + public boolean hasNext() { + return !this.ll.isEmpty(); + } + + @Override + public EWAHIterator next() { + this.buffer.clear(); + long effective = 0; + Iterator i = this.ll.iterator(); + while (i.hasNext()) { + IteratingRLW rlw = i.next(); + if (rlw.size() > 0) { + int eff = IteratorAggregation.inplacexor(this.hardbitmap, rlw); + if (eff > effective) + effective = eff; + } else + i.remove(); + } + for (int k = 0; k < effective; ++k) + this.buffer.add(this.hardbitmap[k]); + Arrays.fill(this.hardbitmap, 0); + return this.buffer.getEWAHIterator(); + } +} + + +class BufferedAndIterator implements CloneableIterator { + EWAHCompressedBitmap buffer = new EWAHCompressedBitmap(); + LinkedList ll; + int buffersize; + + public BufferedAndIterator(LinkedList basell, int bufsize) { + this.ll = basell; + this.buffersize = bufsize; + + } + + @Override + public boolean hasNext() { + return !this.ll.isEmpty(); + } + + @Override + public BufferedAndIterator clone() throws CloneNotSupportedException { + BufferedAndIterator answer = (BufferedAndIterator) super.clone(); + answer.buffer = this.buffer.clone(); + answer.ll = (LinkedList) this.ll.clone(); + return answer; + } + + @Override + public EWAHIterator next() { + this.buffer.clear(); + IteratorAggregation.andToContainer(this.buffer, this.buffersize * this.ll.size(), + this.ll.get(0), this.ll.get(1)); + if (this.ll.size() > 2) { + Iterator i = this.ll.iterator(); + i.next(); + i.next(); + EWAHCompressedBitmap tmpbuffer = new EWAHCompressedBitmap(); + while (i.hasNext() && this.buffer.sizeInBytes() > 0) { + IteratorAggregation.andToContainer(tmpbuffer, + this.buffer.getIteratingRLW(), i.next()); + this.buffer.swap(tmpbuffer); + tmpbuffer.clear(); + } + } + Iterator i = this.ll.iterator(); + while(i.hasNext()) { + if(i.next().size() == 0) { + this.ll.clear(); + break; + } + } + return this.buffer.getEWAHIterator(); + } + +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/IteratorUtil.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/IteratorUtil.java new file mode 100644 index 000000000..628ae46a8 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/IteratorUtil.java @@ -0,0 +1,132 @@ +package com.fr.third.googlecode.javaewah; + +import java.util.Iterator; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ +/** + * Convenience functions for working over iterators + * + */ +public class IteratorUtil { + + /** + * @param i iterator we wish to iterate over + * @return an iterator over the set bits corresponding to the iterator + */ + public static IntIterator toSetBitsIntIterator(final IteratingRLW i) { + return new IntIteratorOverIteratingRLW(i); + } + + /** + * @param i iterator we wish to iterate over + * @return an iterator over the set bits corresponding to the iterator + */ + public static Iterator toSetBitsIterator(final IteratingRLW i) { + return new Iterator() { + @Override + public boolean hasNext() { + return this.under.hasNext(); + } + + @Override + public Integer next() { + return new Integer(this.under.next()); + } + + @Override + public void remove() { + } + + final private IntIterator under = toSetBitsIntIterator(i); + }; + + } + + /** + * Generate a bitmap from an iterator + * + * @param i iterator we wish to materialize + * @param c where we write + */ + public static void materialize(final IteratingRLW i, final BitmapStorage c) { + while (true) { + if (i.getRunningLength() > 0) { + c.addStreamOfEmptyWords(i.getRunningBit(), i.getRunningLength()); + } + for (int k = 0; k < i.getNumberOfLiteralWords(); ++k) + c.add(i.getLiteralWordAt(k)); + if (!i.next()) + break; + } + } + + /** + * @param i iterator we wish to iterate over + * @return the cardinality (number of set bits) corresponding to the iterator + */ + public static int cardinality(final IteratingRLW i) { + int answer = 0; + while (true) { + if(i.getRunningBit()) answer += i.getRunningLength() * EWAHCompressedBitmap.wordinbits; + for (int k = 0; k < i.getNumberOfLiteralWords(); ++k) + answer += Long.bitCount(i.getLiteralWordAt(k)); + if(!i.next()) break; + } + return answer; + } + + /** + * @param x set of bitmaps + * @return an array of iterators corresponding to the array of bitmaps + */ + public static IteratingRLW[] toIterators(final EWAHCompressedBitmap... x) { + IteratingRLW[] X = new IteratingRLW[x.length]; + for (int k = 0; k < X.length; ++k) { + X[k] = new IteratingBufferedRunningLengthWord(x[k]); + } + return X; + } + /** + * Turn an iterator into a bitmap. + * + * @param i iterator we wish to materialize + * @param c where we write + * @param Max maximum number of words we wish to materialize + * @return how many words were actually materialized + */ + public static long materialize(final IteratingRLW i, final BitmapStorage c, long Max) { + final long origMax = Max; + while (true) { + if (i.getRunningLength() > 0) { + long L = i.getRunningLength(); + if(L > Max) L = Max; + c.addStreamOfEmptyWords(i.getRunningBit(), L); + Max -= L; + } + long L = i.getNumberOfLiteralWords(); + for (int k = 0; k < L; ++k) + c.add(i.getLiteralWordAt(k)); + if(Max>0) { + if (!i.next()) + break; + } + else break; + } + return origMax - Max; + } + /** + * Turn an iterator into a bitmap + * + * @param i iterator we wish to materialize + * @return materialized version of the iterator + */ + public static EWAHCompressedBitmap materialize(final IteratingRLW i) { + EWAHCompressedBitmap ewah = new EWAHCompressedBitmap(); + materialize(i, ewah); + return ewah; + } + +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/LogicalElement.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/LogicalElement.java new file mode 100644 index 000000000..b6300410c --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/LogicalElement.java @@ -0,0 +1,61 @@ +package com.fr.third.googlecode.javaewah; + +/** + * A prototypical model for bitmaps. Used by the + * class FastAggregation. Users should probably not + * be concerned by this class. + * + * @author Daniel Lemire + * @param the type of element (e.g., a bitmap class) + * + */ +public interface LogicalElement { + /** + * Compute the bitwise logical and + * @param le element + * @return the result of the operation + */ + public T and(T le); + + /** + * Compute the bitwise logical and not + * @param le element + * @return the result of the operation + */ + public T andNot(T le); + + /** + * Compute the bitwise logical not (in place) + */ + public void not(); + + + @SuppressWarnings({ "rawtypes", "javadoc" }) + /** + * Compute the bitwise logical or + * @param le another element + * @return the result of the operation + */ + public LogicalElement or(T le); + + /** + * How many logical bits does this element represent? + * + * @return the number of bits represented by this element + */ + public int sizeInBits(); + + /** + * Should report the storage requirement + * @return How many bytes + * @since 0.6.2 + */ + public int sizeInBytes(); + + /** + * Compute the bitwise logical Xor + * @param le element + * @return the results of the operation + */ + public T xor(T le); +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/NonEmptyVirtualStorage.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/NonEmptyVirtualStorage.java new file mode 100644 index 000000000..96ea6cfea --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/NonEmptyVirtualStorage.java @@ -0,0 +1,92 @@ +package com.fr.third.googlecode.javaewah; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ +/** + * This is a BitmapStorage that can be used to determine quickly if the result + * of an operation is non-trivial... that is, whether there will be at least on + * set bit. + * + * @since 0.4.2 + * @author Daniel Lemire and Veronika Zenz + * + */ +public class NonEmptyVirtualStorage implements BitmapStorage { + static class NonEmptyException extends RuntimeException { + private static final long serialVersionUID = 1L; + + /** + * Do not fill in the stack trace for this exception + * for performance reasons. + * + * @return this instance + * @see Throwable#fillInStackTrace() + */ + @Override + public synchronized Throwable fillInStackTrace() { + return this; + } + } + + private static final NonEmptyException nonEmptyException = new NonEmptyException(); + + /** + * If the word to be added is non-zero, a NonEmptyException exception is + * thrown. + * + * @see com.googlecode.javaewah.BitmapStorage#add(long) + */ + @Override +public void add(long newdata) { + if (newdata != 0) + throw nonEmptyException; + return; + } + + /** + * throws a NonEmptyException exception when number is greater than 0 + * + */ + @Override +public void addStreamOfLiteralWords(long[] data, int start, int number) { + if(number>0){ + throw nonEmptyException; + } + } + + /** + * If the boolean value is true and number is greater than 0, then it throws a NonEmptyException exception, + * otherwise, nothing happens. + * + * @see com.googlecode.javaewah.BitmapStorage#addStreamOfEmptyWords(boolean, long) + */ + @Override +public void addStreamOfEmptyWords(boolean v, long number) { + if (v && (number>0)) + throw nonEmptyException; + return; + } + + /** + * throws a NonEmptyException exception when number is greater than 0 + * + */ + @Override +public void addStreamOfNegatedLiteralWords(long[] data, int start, int number) { + if(number>0){ + throw nonEmptyException; + } + } + + /** + * Does nothing. + * + * @see com.googlecode.javaewah.BitmapStorage#setSizeInBits(int) + */ + @Override +public void setSizeInBits(int bits) { + } + +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/RunningLengthWord.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/RunningLengthWord.java new file mode 100644 index 000000000..969a78c48 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/RunningLengthWord.java @@ -0,0 +1,152 @@ +package com.fr.third.googlecode.javaewah; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ + +/** + * Mostly for internal use. + * + * @since 0.1.0 + * @author Daniel Lemire + */ +public final class RunningLengthWord implements Cloneable { + + /** + * Instantiates a new running length word. + * + * @param a + * an array of 64-bit words + * @param p + * position in the array where the running length word is + * located. + */ + RunningLengthWord(final EWAHCompressedBitmap a, final int p) { + this.parent = a; + this.position = p; + } + + /** + * Gets the number of literal words. + * + * @return the number of literal words + */ + public int getNumberOfLiteralWords() { + return (int) (this.parent.buffer[this.position] >>> (1 + runninglengthbits)); + } + + /** + * Gets the running bit. + * + * @return the running bit + */ + public boolean getRunningBit() { + return (this.parent.buffer[this.position] & 1) != 0; + } + + /** + * Gets the running length. + * + * @return the running length + */ + public long getRunningLength() { + return (this.parent.buffer[this.position] >>> 1) + & largestrunninglengthcount; + } + + /** + * Sets the number of literal words. + * + * @param number + * the new number of literal words + */ + public void setNumberOfLiteralWords(final long number) { + this.parent.buffer[this.position] |= notrunninglengthplusrunningbit; + this.parent.buffer[this.position] &= (number << (runninglengthbits + 1)) + | runninglengthplusrunningbit; + } + + /** + * Sets the running bit. + * + * @param b + * the new running bit + */ + public void setRunningBit(final boolean b) { + if (b) + this.parent.buffer[this.position] |= 1l; + else + this.parent.buffer[this.position] &= ~1l; + } + + /** + * Sets the running length. + * + * @param number + * the new running length + */ + public void setRunningLength(final long number) { + this.parent.buffer[this.position] |= shiftedlargestrunninglengthcount; + this.parent.buffer[this.position] &= (number << 1) + | notshiftedlargestrunninglengthcount; + } + + /** + * Return the size in uncompressed words represented by this running + * length word. + * + * @return the size + */ + public long size() { + return getRunningLength() + getNumberOfLiteralWords(); + } + + /* + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "running bit = " + getRunningBit() + + " running length = " + getRunningLength() + + " number of lit. words " + getNumberOfLiteralWords(); + } + + @Override + public RunningLengthWord clone() throws CloneNotSupportedException { + RunningLengthWord answer; + answer = (RunningLengthWord) super.clone(); + answer.parent = this.parent; + answer.position = this.position; + return answer; + } + + /** The array of words. */ + public EWAHCompressedBitmap parent; + + /** The position in array. */ + public int position; + + /** + * number of bits dedicated to marking of the running length of clean + * words + */ + public static final int runninglengthbits = 32; + + private static final int literalbits = 64 - 1 - runninglengthbits; + + /** largest number of literal words in a run. */ + public static final int largestliteralcount = (1 << literalbits) - 1; + + /** largest number of clean words in a run */ + public static final long largestrunninglengthcount = (1l << runninglengthbits) - 1; + + private static final long runninglengthplusrunningbit = (1l << (runninglengthbits + 1)) - 1; + + private static final long shiftedlargestrunninglengthcount = largestrunninglengthcount << 1; + + private static final long notrunninglengthplusrunningbit = ~runninglengthplusrunningbit; + + private static final long notshiftedlargestrunninglengthcount = ~shiftedlargestrunninglengthcount; + +} \ No newline at end of file diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/Benchmark.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/Benchmark.java new file mode 100644 index 000000000..e2ffb8fe4 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/Benchmark.java @@ -0,0 +1,284 @@ +package com.fr.third.googlecode.javaewah.benchmark; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ + +import java.text.DecimalFormat; +import java.util.Arrays; +import java.util.List; +import com.fr.third.googlecode.javaewah.EWAHCompressedBitmap; +import com.fr.third.googlecode.javaewah.FastAggregation; +import com.fr.third.googlecode.javaewah.IntIterator; +import com.fr.third.googlecode.javaewah.IteratingRLW; +import com.fr.third.googlecode.javaewah.IteratorAggregation; +import com.fr.third.googlecode.javaewah.IteratorUtil; + +/** + * This class is used to benchmark the performance EWAH. + * + * @author Daniel Lemire + */ +public class Benchmark { + + /** + * Compute the union between two sorted arrays + * @param set1 first sorted array + * @param set2 second sorted array + * @return merged array + */ + static public int[] unite2by2(final int[] set1, final int[] set2) { + int pos = 0; + int k1 = 0, k2 = 0; + if (0 == set1.length) + return Arrays.copyOf(set2, set2.length); + if (0 == set2.length) + return Arrays.copyOf(set1, set1.length); + int[] buffer = new int[set1.length + set2.length]; + while (true) { + if (set1[k1] < set2[k2]) { + buffer[pos++] = set1[k1]; + ++k1; + if (k1 >= set1.length) { + for (; k2 < set2.length; ++k2) + buffer[pos++] = set2[k2]; + break; + } + } else if (set1[k1] == set2[k2]) { + buffer[pos++] = set1[k1]; + ++k1; + ++k2; + if (k1 >= set1.length) { + for (; k2 < set2.length; ++k2) + buffer[pos++] = set2[k2]; + break; + } + if (k2 >= set2.length) { + for (; k1 < set1.length; ++k1) + buffer[pos++] = set1[k1]; + break; + } + } else {// if (set1[k1]>set2[k2]) { + buffer[pos++] = set2[k2]; + ++k2; + if (k2 >= set2.length) { + for (; k1 < set1.length; ++k1) + buffer[pos++] = set1[k1]; + break; + } + } + } + return Arrays.copyOf(buffer, pos); + } + + + @SuppressWarnings("javadoc") + public static void main(String args[]) { + //test(2, 24, 1); + test(100, 16, 1); + } + + @SuppressWarnings("javadoc") + public static void test(int N, int nbr, int repeat) { + DecimalFormat df = new DecimalFormat("0.###"); + ClusteredDataGenerator cdg = new ClusteredDataGenerator(); + for (int sparsity = 1; sparsity < 30 - nbr; sparsity += 2) { + long bogus = 0; + String line = ""; + long bef, aft; + line += sparsity; + int[][] data = new int[N][]; + int Max = (1 << (nbr + sparsity)); + System.out.println("# generating random data..."); + int[] inter = cdg.generateClustered(1 << (nbr/2), Max); + for (int k = 0; k < N; ++k) + data[k] = unite2by2(cdg.generateClustered(1 << nbr, Max),inter); + System.out.println("# generating random data... ok."); + // building + bef = System.currentTimeMillis(); + EWAHCompressedBitmap[] ewah = new EWAHCompressedBitmap[N]; + int size = 0; + for (int r = 0; r < repeat; ++r) { + size = 0; + for (int k = 0; k < N; ++k) { + ewah[k] = new EWAHCompressedBitmap(); + for (int x = 0; x < data[k].length; ++x) { + ewah[k].set(data[k][x]); + } + size += ewah[k].sizeInBytes(); + } + } + aft = System.currentTimeMillis(); + line += "\t" + size; + line += "\t" + df.format((aft - bef) / 1000.0); + // uncompressing + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + int[] array = ewah[k].toArray(); + bogus += array.length; + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + // uncompressing + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + int[] array = new int[ewah[k].cardinality()]; + int c = 0; + for (int x : ewah[k]) + array[c++] = x; + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + // uncompressing + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + List L = ewah[k].getPositions(); + int[] array = new int[L.size()]; + int c = 0; + for (int x : L) + array[c++] = x; + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + // uncompressing + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + IntIterator iter = ewah[k].intIterator(); + while (iter.hasNext()) { + bogus += iter.next(); + } + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + line += "\t\t\t"; + // logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap ewahor = ewah[0]; + for (int j = 1; j < k + 1; ++j) { + ewahor = ewahor.or(ewah[j]); + } + bogus += ewahor.sizeInBits(); + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + // fast logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap[] ewahcp = new EWAHCompressedBitmap[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j]; + } + EWAHCompressedBitmap ewahor = EWAHCompressedBitmap + .or(ewahcp); + bogus += ewahor.sizeInBits(); + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + + // fast logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap[] ewahcp = new EWAHCompressedBitmap[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j]; + } + EWAHCompressedBitmap ewahor = FastAggregation.or(ewahcp); + bogus += ewahor.sizeInBits(); + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + // fast logical or + // run sanity check + for (int k = 0; k < N; ++k) { + IteratingRLW[] ewahcp = new IteratingRLW[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j].getIteratingRLW(); + } + IteratingRLW ewahor = IteratorAggregation.bufferedor(ewahcp); + EWAHCompressedBitmap ewahorp = EWAHCompressedBitmap.or(Arrays.copyOf(ewah, k+1)); + EWAHCompressedBitmap mewahor = IteratorUtil.materialize(ewahor); + if(!ewahorp.equals(mewahor)) throw new RuntimeException("bug"); + } + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + IteratingRLW[] ewahcp = new IteratingRLW[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j].getIteratingRLW(); + } + IteratingRLW ewahor = IteratorAggregation.bufferedor(ewahcp); + bogus += IteratorUtil.materialize(ewahor).sizeInBits(); + } + aft = System.currentTimeMillis(); + + line += "\t" + df.format((aft - bef) / 1000.0); + line += "\t\t\t"; + // logical and + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap ewahand = ewah[0]; + for (int j = 1; j < k + 1; ++j) { + ewahand = ewahand.and(ewah[j]); + } + bogus += ewahand.sizeInBits(); + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + // fast logical and + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap[] ewahcp = new EWAHCompressedBitmap[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j]; + } + EWAHCompressedBitmap ewahand = EWAHCompressedBitmap + .and(ewahcp); + bogus += ewahand.sizeInBits(); + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + + for (int k = 0; k < N; ++k) { + IteratingRLW[] ewahcp = new IteratingRLW[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j].getIteratingRLW(); + } + IteratingRLW ewahand = IteratorAggregation.bufferedand(ewahcp); + EWAHCompressedBitmap ewahandp = EWAHCompressedBitmap.and(Arrays.copyOf(ewah, k+1)); + EWAHCompressedBitmap mewahand = IteratorUtil.materialize(ewahand); + if(!ewahandp.equals(mewahand)) throw new RuntimeException("bug"); + } + // fast logical and + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + IteratingRLW[] ewahcp = new IteratingRLW[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j].getIteratingRLW(); + } + IteratingRLW ewahand = IteratorAggregation.bufferedand(ewahcp); + bogus += IteratorUtil.materialize(ewahand).sizeInBits(); + } + aft = System.currentTimeMillis(); + + line += "\t" + df.format((aft - bef) / 1000.0); + + + System.out + .println("time for building, toArray(), Java iterator, intIterator,\t\t\t logical or (2-by-2), logical or (grouped), FastAggregation.or, iterator-based or, \t\t\t (2-by-2) and, logical and (grouped), iterator-based and"); + System.out.println(line); + System.out.println("# bogus =" + bogus); + } + } +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/Benchmark32.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/Benchmark32.java new file mode 100644 index 000000000..b221b911c --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/Benchmark32.java @@ -0,0 +1,212 @@ +package com.fr.third.googlecode.javaewah.benchmark; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ + +import java.text.DecimalFormat; +import java.util.List; +import com.fr.third.googlecode.javaewah32.EWAHCompressedBitmap32; +import com.fr.third.googlecode.javaewah.FastAggregation; +import com.fr.third.googlecode.javaewah.IntIterator; +import com.fr.third.googlecode.javaewah32.IteratingRLW32; +import com.fr.third.googlecode.javaewah32.IteratorAggregation32; +import com.fr.third.googlecode.javaewah32.IteratorUtil32; + +/** + * This class is used to benchmark the performance EWAH. + * + * @author Daniel Lemire + */ +public class Benchmark32 { + + @SuppressWarnings("javadoc") + public static void main(String args[]) { + test(100, 16, 1); +// test(2, 24, 1); + } + + @SuppressWarnings("javadoc") + public static void test(int N, int nbr, int repeat) { + DecimalFormat df = new DecimalFormat("0.###"); + ClusteredDataGenerator cdg = new ClusteredDataGenerator(); + for (int sparsity = 1; sparsity < 30 - nbr; sparsity += 2) { + long bogus = 0; + String line = ""; + long bef, aft; + line += sparsity; + int[][] data = new int[N][]; + int Max = (1 << (nbr + sparsity)); + System.out.println("# generating random data..."); + int[] inter = cdg.generateClustered(1 << (nbr/2), Max); + for (int k = 0; k < N; ++k) + data[k] = Benchmark.unite2by2(cdg.generateClustered(1 << nbr, Max),inter); + System.out.println("# generating random data... ok."); + // building + bef = System.currentTimeMillis(); + EWAHCompressedBitmap32[] ewah = new EWAHCompressedBitmap32[N]; + int size = 0; + for (int r = 0; r < repeat; ++r) { + size = 0; + for (int k = 0; k < N; ++k) { + ewah[k] = new EWAHCompressedBitmap32(); + for (int x = 0; x < data[k].length; ++x) { + ewah[k].set(data[k][x]); + } + size += ewah[k].sizeInBytes(); + } + } + aft = System.currentTimeMillis(); + line += "\t" + size; + line += "\t" + df.format((aft - bef) / 1000.0); + // uncompressing + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + int[] array = ewah[k].toArray(); + bogus += array.length; + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + // uncompressing + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + int[] array = new int[ewah[k].cardinality()]; + int c = 0; + for (int x : ewah[k]) + array[c++] = x; + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + // uncompressing + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + List L = ewah[k].getPositions(); + int[] array = new int[L.size()]; + int c = 0; + for (int x : L) + array[c++] = x; + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + // uncompressing + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + IntIterator iter = ewah[k].intIterator(); + while (iter.hasNext()) { + bogus += iter.next(); + } + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + line += "\t\t\t"; + // logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap32 ewahor = ewah[0]; + for (int j = 1; j < k + 1; ++j) { + ewahor = ewahor.or(ewah[j]); + } + bogus += ewahor.sizeInBits(); + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + // fast logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap32[] ewahcp = new EWAHCompressedBitmap32[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j]; + } + EWAHCompressedBitmap32 ewahor = EWAHCompressedBitmap32 + .or(ewahcp); + bogus += ewahor.sizeInBits(); + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + + // fast logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap32[] ewahcp = new EWAHCompressedBitmap32[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j]; + } + EWAHCompressedBitmap32 ewahor = FastAggregation.or(ewahcp); + bogus += ewahor.sizeInBits(); + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + // fast logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + IteratingRLW32[] ewahcp = new IteratingRLW32[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j].getIteratingRLW(); + } + IteratingRLW32 ewahor = IteratorAggregation32.bufferedor(ewahcp); + bogus += IteratorUtil32.materialize(ewahor).sizeInBits(); + } + aft = System.currentTimeMillis(); + + line += "\t" + df.format((aft - bef) / 1000.0); + line += "\t\t\t"; + // logical and + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap32 ewahand = ewah[0]; + for (int j = 1; j < k + 1; ++j) { + ewahand = ewahand.and(ewah[j]); + } + bogus += ewahand.sizeInBits(); + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + // fast logical and + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap32[] ewahcp = new EWAHCompressedBitmap32[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j]; + } + EWAHCompressedBitmap32 ewahand = EWAHCompressedBitmap32 + .and(ewahcp); + bogus += ewahand.sizeInBits(); + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + + + // fast logical and + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + IteratingRLW32[] ewahcp = new IteratingRLW32[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j].getIteratingRLW(); + } + IteratingRLW32 ewahand = IteratorAggregation32.bufferedand(ewahcp); + bogus += IteratorUtil32.materialize(ewahand).sizeInBits(); + } + aft = System.currentTimeMillis(); + + line += "\t" + df.format((aft - bef) / 1000.0); + + + System.out + .println("time for building, toArray(), Java iterator, intIterator,\t\t\t logical or (2-by-2), logical or (grouped), FastAggregation.or, iterator-based or, \t\t\t (2-by-2) and, logical and (grouped), iterator-based and"); + System.out.println(line); + System.out.println("# bogus =" + bogus); + } + } +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/BenchmarkIntersection.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/BenchmarkIntersection.java new file mode 100644 index 000000000..943c76bc6 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/BenchmarkIntersection.java @@ -0,0 +1,130 @@ +package com.fr.third.googlecode.javaewah.benchmark; + +import java.text.DecimalFormat; +import com.fr.third.googlecode.javaewah.*; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ +/** + * To benchmark the logical and (intersection) aggregate. + */ +public class BenchmarkIntersection { + + @SuppressWarnings("javadoc") + public static void main(String args[]) { + test(10, 18, 1); + } + + @SuppressWarnings({ "javadoc"}) + public static void test(int N, int nbr, int repeat) { + long bogus = 0; + + DecimalFormat df = new DecimalFormat("0.###"); + ClusteredDataGenerator cdg = new ClusteredDataGenerator(); + for (int sparsity = 1; sparsity < 30 - nbr; sparsity++) { + for (int times = 0; times < 2; ++times) { + String line = ""; + long bef, aft; + line += sparsity; + int[][] data = new int[N][]; + int Max = (1 << (nbr + sparsity)); + int[] inter = cdg.generateClustered(1 << (nbr/2), Max); + for (int k = 0; k < N; ++k) + data[k] = Benchmark.unite2by2(cdg.generateClustered(1 << nbr, Max),inter); + // building + EWAHCompressedBitmap[] ewah = new EWAHCompressedBitmap[N]; + for (int k = 0; k < N; ++k) { + ewah[k] = new EWAHCompressedBitmap(); + for (int x = 0; x < data[k].length; ++x) { + ewah[k].set(data[k][x]); + } + data[k] = null; + } + // sanity check + if (true) { + EWAHCompressedBitmap answer = ewah[0].and(ewah[1]); + for (int k = 2; k < ewah.length; ++k) + answer = answer.and(ewah[k]); + + EWAHCompressedBitmap ewahand = EWAHCompressedBitmap.and(ewah); + if (!answer.equals(ewahand)) + throw new RuntimeException( + "bug EWAHCompressedBitmap.and"); + EWAHCompressedBitmap ewahand2 = FastAggregation + .bufferedand(65536,ewah); + if (!ewahand.equals(ewahand2)) + throw new RuntimeException( + "bug FastAggregation.bufferedand "); + + } + + // logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap ewahor = ewah[0]; + for (int j = 1; j < k + 1; ++j) { + ewahor = ewahor.and(ewah[j]); + } + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + + // fast logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap[] ewahcp = new EWAHCompressedBitmap[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j]; + } + EWAHCompressedBitmap ewahor = EWAHCompressedBitmap + .and(ewahcp); + bogus += ewahor.sizeInBits(); + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + // fast logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap[] ewahcp = new EWAHCompressedBitmap[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j]; + } + EWAHCompressedBitmap ewahor = FastAggregation + .bufferedand(65536,ewahcp); + bogus += ewahor.sizeInBits(); + } + aft = System.currentTimeMillis(); + + line += "\t" + df.format((aft - bef) / 1000.0); + // fast logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + IteratingRLW[] ewahcp = new IteratingRLW[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = new IteratingBufferedRunningLengthWord( + ewah[j]); + } + IteratingRLW ewahor = IteratorAggregation.bufferedand(ewahcp); + int wordcounter = IteratorUtil.cardinality(ewahor); + bogus += wordcounter; + } + aft = System.currentTimeMillis(); + + line += "\t" + df.format((aft - bef) / 1000.0); + + System.out + .println("# times for: 2by2 EWAHCompressedBitmap.and bufferedand iterator-bufferedand"); + + System.out.println(line); + } + System.out.println("# bogus =" + bogus); + + } + } +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/BenchmarkIntersection32.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/BenchmarkIntersection32.java new file mode 100644 index 000000000..a36ba889b --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/BenchmarkIntersection32.java @@ -0,0 +1,130 @@ +package com.fr.third.googlecode.javaewah.benchmark; + +import java.text.DecimalFormat; +import com.fr.third.googlecode.javaewah32.*; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ +/** + * To benchmark the logical and (intersection) aggregate. + */ +public class BenchmarkIntersection32 { + + @SuppressWarnings("javadoc") + public static void main(String args[]) { + test(10, 18, 1); + } + + @SuppressWarnings({ "javadoc" }) + public static void test(int N, int nbr, int repeat) { + long bogus = 0; + + DecimalFormat df = new DecimalFormat("0.###"); + ClusteredDataGenerator cdg = new ClusteredDataGenerator(); + for (int sparsity = 1; sparsity < 30 - nbr; sparsity++) { + for (int times = 0; times < 2; ++times) { + String line = ""; + long bef, aft; + line += sparsity; + int[][] data = new int[N][]; + int Max = (1 << (nbr + sparsity)); + int[] inter = cdg.generateClustered(1 << (nbr/2), Max); + for (int k = 0; k < N; ++k) + data[k] = Benchmark.unite2by2(cdg.generateClustered(1 << nbr, Max),inter); + // building + EWAHCompressedBitmap32[] ewah = new EWAHCompressedBitmap32[N]; + for (int k = 0; k < N; ++k) { + ewah[k] = new EWAHCompressedBitmap32(); + for (int x = 0; x < data[k].length; ++x) { + ewah[k].set(data[k][x]); + } + data[k] = null; + } + // sanity check + if (true) { + EWAHCompressedBitmap32 answer = ewah[0].and(ewah[1]); + for (int k = 2; k < ewah.length; ++k) + answer = answer.and(ewah[k]); + + EWAHCompressedBitmap32 ewahand = EWAHCompressedBitmap32.and(ewah); + if (!answer.equals(ewahand)) + throw new RuntimeException( + "bug EWAHCompressedBitmap.and"); + EWAHCompressedBitmap32 ewahand2 = FastAggregation32 + .bufferedand(65536,ewah); + if (!ewahand.equals(ewahand2)) + throw new RuntimeException( + "bug FastAggregation.bufferedand "); + + } + + // logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap32 ewahor = ewah[0]; + for (int j = 1; j < k + 1; ++j) { + ewahor = ewahor.and(ewah[j]); + } + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + + // fast logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap32[] ewahcp = new EWAHCompressedBitmap32[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j]; + } + EWAHCompressedBitmap32 ewahor = EWAHCompressedBitmap32 + .and(ewahcp); + bogus += ewahor.sizeInBits(); + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + // fast logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap32[] ewahcp = new EWAHCompressedBitmap32[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j]; + } + EWAHCompressedBitmap32 ewahor = FastAggregation32 + .bufferedand(65536,ewahcp); + bogus += ewahor.sizeInBits(); + } + aft = System.currentTimeMillis(); + + line += "\t" + df.format((aft - bef) / 1000.0); + // fast logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + IteratingRLW32[] ewahcp = new IteratingRLW32[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = new IteratingBufferedRunningLengthWord32( + ewah[j]); + } + IteratingRLW32 ewahor = IteratorAggregation32.bufferedand(ewahcp); + int wordcounter = IteratorUtil32.cardinality(ewahor); + bogus += wordcounter; + } + aft = System.currentTimeMillis(); + + line += "\t" + df.format((aft - bef) / 1000.0); + + System.out + .println("# times for: 2by2 EWAHCompressedBitmap.and bufferedand iterator-bufferedand"); + + System.out.println(line); + } + System.out.println("# bogus =" + bogus); + + } + } +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/BenchmarkUnion.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/BenchmarkUnion.java new file mode 100644 index 000000000..55453bbe8 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/BenchmarkUnion.java @@ -0,0 +1,164 @@ +package com.fr.third.googlecode.javaewah.benchmark; + +import java.text.DecimalFormat; +import com.fr.third.googlecode.javaewah.*; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ +/** + * To benchmark the logical or (union) aggregate. + */ +public class BenchmarkUnion { + + @SuppressWarnings("javadoc") + public static void main(String args[]) { + test(10, 18, 1); + } + + @SuppressWarnings({ "javadoc", "deprecation" }) + public static void test(int N, int nbr, int repeat) { + long bogus = 0; + + DecimalFormat df = new DecimalFormat("0.###"); + ClusteredDataGenerator cdg = new ClusteredDataGenerator(); + for (int sparsity = 1; sparsity < 30 - nbr; sparsity++) { + for (int times = 0; times < 2; ++times) { + String line = ""; + long bef, aft; + line += sparsity; + int[][] data = new int[N][]; + int Max = (1 << (nbr + sparsity)); + for (int k = 0; k < N; ++k) + data[k] = cdg.generateClustered(1 << nbr, Max); + // building + EWAHCompressedBitmap[] ewah = new EWAHCompressedBitmap[N]; + for (int k = 0; k < N; ++k) { + ewah[k] = new EWAHCompressedBitmap(); + for (int x = 0; x < data[k].length; ++x) { + ewah[k].set(data[k][x]); + } + data[k] = null; + } + // sanity check + if (true) { + EWAHCompressedBitmap answer = ewah[0].or(ewah[1]); + for (int k = 2; k < ewah.length; ++k) + answer = answer.or(ewah[k]); + + EWAHCompressedBitmap ewahor = EWAHCompressedBitmap.or(ewah); + if (!answer.equals(ewahor)) + throw new RuntimeException( + "bug EWAHCompressedBitmap.or"); + EWAHCompressedBitmap ewahor3 = FastAggregation.or(ewah); + if (!ewahor.equals(ewahor3)) + throw new RuntimeException("bug FastAggregation.or"); + EWAHCompressedBitmap ewahor2 = FastAggregation + .bufferedor(65536,ewah); + if (!ewahor.equals(ewahor2)) + throw new RuntimeException( + "bug FastAggregation.bufferedor "); + + } + + // logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap ewahor = ewah[0]; + for (int j = 1; j < k + 1; ++j) { + ewahor = ewahor.or(ewah[j]); + } + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + + // fast logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap[] ewahcp = new EWAHCompressedBitmap[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j]; + } + EWAHCompressedBitmap ewahor = EWAHCompressedBitmap + .or(ewahcp); + bogus += ewahor.sizeInBits(); + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + + // fast logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap[] ewahcp = new EWAHCompressedBitmap[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j]; + } + EWAHCompressedBitmap ewahor = FastAggregation + .or(ewahcp); + bogus += ewahor.sizeInBits(); + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + + + // fast logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap[] ewahcp = new EWAHCompressedBitmap[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j]; + } + EWAHCompressedBitmap ewahor = FastAggregation + .bufferedor(65536,ewahcp); + bogus += ewahor.sizeInBits(); + } + aft = System.currentTimeMillis(); + + line += "\t" + df.format((aft - bef) / 1000.0); + // fast logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap[] ewahcp = new EWAHCompressedBitmap[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j]; + } + EWAHCompressedBitmap x = new EWAHCompressedBitmap(); + FastAggregation.legacy_orWithContainer(x, ewahcp); + bogus += x.sizeInBits(); + } + aft = System.currentTimeMillis(); + + line += "\t" + df.format((aft - bef) / 1000.0); + // fast logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + IteratingRLW[] ewahcp = new IteratingRLW[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = new IteratingBufferedRunningLengthWord( + ewah[j]); + } + IteratingRLW ewahor = IteratorAggregation.bufferedor(ewahcp); + int wordcounter = IteratorUtil.cardinality(ewahor); + bogus += wordcounter; + } + aft = System.currentTimeMillis(); + + line += "\t" + df.format((aft - bef) / 1000.0); + + System.out + .println("# times for: 2by2 EWAHCompressedBitmap.or FastAggregation.or experimentalor bufferedor legacygroupedor iterator-bufferedor"); + + System.out.println(line); + } + System.out.println("# bogus =" + bogus); + + } + } +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/BenchmarkUnion32.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/BenchmarkUnion32.java new file mode 100644 index 000000000..249354944 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/BenchmarkUnion32.java @@ -0,0 +1,165 @@ +package com.fr.third.googlecode.javaewah.benchmark; + +import java.text.DecimalFormat; + +import com.fr.third.googlecode.javaewah.FastAggregation; +import com.fr.third.googlecode.javaewah32.*; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ +/** + * To benchmark the logical or (union) aggregate. + */ +public class BenchmarkUnion32 { + + @SuppressWarnings("javadoc") + public static void main(String args[]) { + test(10, 18, 1); + } + + @SuppressWarnings({ "javadoc", "deprecation" }) + public static void test(int N, int nbr, int repeat) { + long bogus = 0; + + DecimalFormat df = new DecimalFormat("0.###"); + ClusteredDataGenerator cdg = new ClusteredDataGenerator(); + for (int sparsity = 1; sparsity < 30 - nbr; sparsity++) { + for (int times = 0; times < 2; ++times) { + String line = ""; + long bef, aft; + line += sparsity; + int[][] data = new int[N][]; + int Max = (1 << (nbr + sparsity)); + for (int k = 0; k < N; ++k) + data[k] = cdg.generateClustered(1 << nbr, Max); + // building + EWAHCompressedBitmap32[] ewah = new EWAHCompressedBitmap32[N]; + for (int k = 0; k < N; ++k) { + ewah[k] = new EWAHCompressedBitmap32(); + for (int x = 0; x < data[k].length; ++x) { + ewah[k].set(data[k][x]); + } + data[k] = null; + } + // sanity check + if(true){ + EWAHCompressedBitmap32 answer = ewah[0].or(ewah[1]); + for(int k = 2; k < ewah.length; ++k) + answer = answer.or(ewah[k]); + + EWAHCompressedBitmap32 ewahor = EWAHCompressedBitmap32 + .or(ewah); + if(!answer.equals(ewahor)) throw new RuntimeException("bug EWAHCompressedBitmap.or"); + EWAHCompressedBitmap32 ewahor3 = FastAggregation + .or(ewah); + if(!ewahor.equals(ewahor3)) throw new RuntimeException("bug FastAggregation.or"); + EWAHCompressedBitmap32 ewahor2 = FastAggregation32 + .bufferedor(65536,ewah); + if(!ewahor.equals(ewahor2)) throw new RuntimeException("bug FastAggregation.bufferedor "); + + } + + // logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap32 ewahor = ewah[0]; + for (int j = 1; j < k + 1; ++j) { + ewahor = ewahor.or(ewah[j]); + } + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + + + // fast logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap32[] ewahcp = new EWAHCompressedBitmap32[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j]; + } + EWAHCompressedBitmap32 ewahor = EWAHCompressedBitmap32 + .or(ewahcp); + bogus += ewahor.sizeInBits(); + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + + // fast logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap32[] ewahcp = new EWAHCompressedBitmap32[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j]; + } + EWAHCompressedBitmap32 ewahor = FastAggregation + .or(ewahcp); + bogus += ewahor.sizeInBits(); + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + + + // fast logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap32[] ewahcp = new EWAHCompressedBitmap32[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j]; + } + EWAHCompressedBitmap32 ewahor = FastAggregation32 + .bufferedor(65536,ewahcp); + bogus += ewahor.sizeInBits(); + } + aft = System.currentTimeMillis(); + + line += "\t" + df.format((aft - bef) / 1000.0); + // fast logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap32[] ewahcp = new EWAHCompressedBitmap32[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j]; + } + EWAHCompressedBitmap32 x = new EWAHCompressedBitmap32(); + FastAggregation32.legacy_orWithContainer(x, ewahcp); + bogus += x.sizeInBits(); + } + aft = System.currentTimeMillis(); + + line += "\t" + df.format((aft - bef) / 1000.0); + // fast logical or + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + IteratingRLW32[] ewahcp = new IteratingRLW32[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = new IteratingBufferedRunningLengthWord32(ewah[j]); + } + IteratingRLW32 ewahor = IteratorAggregation32 + .bufferedor(ewahcp); + int wordcounter = IteratorUtil32.cardinality(ewahor); + bogus += wordcounter; + } + aft = System.currentTimeMillis(); + + line += "\t" + df.format((aft - bef) / 1000.0); + + + System.out + .println("# times for: 2by2 EWAHCompressedBitmap.or FastAggregation.or experimentalor bufferedor legacygroupedor iterator-bufferedor"); + + System.out.println(line); + } + System.out.println("# bogus =" + bogus); + + } + } +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/BenchmarkXOR.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/BenchmarkXOR.java new file mode 100644 index 000000000..7f036d690 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/BenchmarkXOR.java @@ -0,0 +1,134 @@ +package com.fr.third.googlecode.javaewah.benchmark; + +import java.text.DecimalFormat; +import com.fr.third.googlecode.javaewah.*; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ +/** + * To benchmark the logical xor aggregate. + */ +public class BenchmarkXOR { + + @SuppressWarnings("javadoc") + public static void main(String args[]) { + //test(10, 18, 1); + test(2, 22, 1); + } + + @SuppressWarnings({ "javadoc" }) + public static void test(int N, int nbr, int repeat) { + long bogus = 0; + + DecimalFormat df = new DecimalFormat("0.###"); + ClusteredDataGenerator cdg = new ClusteredDataGenerator(); + for (int sparsity = 1; sparsity < 30 - nbr; sparsity++) { + for (int times = 0; times < 2; ++times) { + String line = ""; + long bef, aft; + line += sparsity; + int[][] data = new int[N][]; + int Max = (1 << (nbr + sparsity)); + for (int k = 0; k < N; ++k) + data[k] = cdg.generateClustered(1 << nbr, Max); + // building + EWAHCompressedBitmap[] ewah = new EWAHCompressedBitmap[N]; + for (int k = 0; k < N; ++k) { + ewah[k] = new EWAHCompressedBitmap(); + for (int x = 0; x < data[k].length; ++x) { + ewah[k].set(data[k][x]); + } + data[k] = null; + } + // sanity check + if (true) { + EWAHCompressedBitmap answer = ewah[0].xor(ewah[1]); + for (int k = 2; k < ewah.length; ++k) + answer = answer.xor(ewah[k]); + EWAHCompressedBitmap ewahor3 = FastAggregation.xor(ewah); + if (!answer.equals(ewahor3)) + throw new RuntimeException("bug FastAggregation.xor"); + EWAHCompressedBitmap ewahor2 = FastAggregation + .bufferedxor(65536,ewah); + if (!answer.equals(ewahor2)) + throw new RuntimeException( + "bug FastAggregation.bufferedxor "); + EWAHCompressedBitmap iwah = IteratorUtil.materialize(IteratorAggregation.bufferedxor(IteratorUtil.toIterators(ewah))); + if (!answer.equals(iwah)) + throw new RuntimeException( + "bug xor it "); + + + } + + // logical xor + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap ewahor = ewah[0]; + for (int j = 1; j < k + 1; ++j) { + ewahor = ewahor.xor(ewah[j]); + } + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + + // fast logical xor + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap[] ewahcp = new EWAHCompressedBitmap[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j]; + } + EWAHCompressedBitmap ewahor = FastAggregation + .xor(ewahcp); + bogus += ewahor.sizeInBits(); + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + + + // fast logical xor + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap[] ewahcp = new EWAHCompressedBitmap[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j]; + } + EWAHCompressedBitmap ewahor = FastAggregation + .bufferedxor(65536,ewahcp); + bogus += ewahor.sizeInBits(); + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + // fast logical xor + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + IteratingRLW[] ewahcp = new IteratingRLW[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = new IteratingBufferedRunningLengthWord( + ewah[j]); + } + IteratingRLW ewahor = IteratorAggregation.bufferedxor(ewahcp); + int wordcounter = IteratorUtil.cardinality(ewahor); + bogus += wordcounter; + } + aft = System.currentTimeMillis(); + + line += "\t" + df.format((aft - bef) / 1000.0); + + System.out + .println("# times for: 2by2 FastAggregation.xor bufferedxor iterator-based"); + + System.out.println(line); + } + System.out.println("# bogus =" + bogus); + + } + } +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/BenchmarkXOR32.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/BenchmarkXOR32.java new file mode 100644 index 000000000..4fb057fab --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/BenchmarkXOR32.java @@ -0,0 +1,137 @@ +package com.fr.third.googlecode.javaewah.benchmark; + +import java.text.DecimalFormat; + +import com.fr.third.googlecode.javaewah.FastAggregation; +import com.fr.third.googlecode.javaewah32.*; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ +/** + * To benchmark the logical xor aggregate. + */ +public class BenchmarkXOR32 { + + @SuppressWarnings("javadoc") + public static void main(String args[]) { + test(10, 18, 1); + //test(2, 22, 1); + } + + @SuppressWarnings({ "javadoc" }) + public static void test(int N, int nbr, int repeat) { + long bogus = 0; + + DecimalFormat df = new DecimalFormat("0.###"); + ClusteredDataGenerator cdg = new ClusteredDataGenerator(); + for (int sparsity = 1; sparsity < 30 - nbr; sparsity++) { + for (int times = 0; times < 2; ++times) { + String line = ""; + long bef, aft; + line += sparsity; + int[][] data = new int[N][]; + int Max = (1 << (nbr + sparsity)); + for (int k = 0; k < N; ++k) + data[k] = cdg.generateClustered(1 << nbr, Max); + // building + EWAHCompressedBitmap32[] ewah = new EWAHCompressedBitmap32[N]; + for (int k = 0; k < N; ++k) { + ewah[k] = new EWAHCompressedBitmap32(); + for (int x = 0; x < data[k].length; ++x) { + ewah[k].set(data[k][x]); + } + data[k] = null; + } + // sanity check + if (true) { + EWAHCompressedBitmap32 answer = ewah[0].xor(ewah[1]); + for (int k = 2; k < ewah.length; ++k) + answer = answer.xor(ewah[k]); + EWAHCompressedBitmap32 ewahor3 = FastAggregation.xor(ewah); + if (!answer.equals(ewahor3)) + throw new RuntimeException("bug FastAggregation.xor"); + EWAHCompressedBitmap32 ewahor2 = FastAggregation32 + .bufferedxor(65536,ewah); + if (!answer.equals(ewahor2)) + throw new RuntimeException( + "bug FastAggregation.bufferedxor "); + EWAHCompressedBitmap32 iwah = IteratorUtil32.materialize(IteratorAggregation32.bufferedxor(IteratorUtil32.toIterators(ewah))); + if (!answer.equals(iwah)) + throw new RuntimeException( + "bug xor it "); + + } + + // logical xor + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap32 ewahor = ewah[0]; + for (int j = 1; j < k + 1; ++j) { + ewahor = ewahor.xor(ewah[j]); + } + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + + // fast logical xor + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap32[] ewahcp = new EWAHCompressedBitmap32[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j]; + } + EWAHCompressedBitmap32 ewahor = FastAggregation + .xor(ewahcp); + bogus += ewahor.sizeInBits(); + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + + + // fast logical xor + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + EWAHCompressedBitmap32[] ewahcp = new EWAHCompressedBitmap32[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = ewah[j]; + } + EWAHCompressedBitmap32 ewahor = FastAggregation32 + .bufferedxor(65536,ewahcp); + bogus += ewahor.sizeInBits(); + } + aft = System.currentTimeMillis(); + line += "\t" + df.format((aft - bef) / 1000.0); + + // fast logical xor + bef = System.currentTimeMillis(); + for (int r = 0; r < repeat; ++r) + for (int k = 0; k < N; ++k) { + IteratingRLW32[] ewahcp = new IteratingRLW32[k + 1]; + for (int j = 0; j < k + 1; ++j) { + ewahcp[j] = new IteratingBufferedRunningLengthWord32( + ewah[j]); + } + IteratingRLW32 ewahor = IteratorAggregation32.bufferedxor(ewahcp); + int wordcounter = IteratorUtil32.cardinality(ewahor); + bogus += wordcounter; + } + aft = System.currentTimeMillis(); + + line += "\t" + df.format((aft - bef) / 1000.0); + + + System.out + .println("# times for: 2by2 FastAggregation.xor bufferedxor iterator-based"); + + System.out.println(line); + } + System.out.println("# bogus =" + bogus); + + } + } +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/ClusteredDataGenerator.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/ClusteredDataGenerator.java new file mode 100644 index 000000000..29078ca21 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/ClusteredDataGenerator.java @@ -0,0 +1,78 @@ +package com.fr.third.googlecode.javaewah.benchmark; + + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ + + +/** + * This class will generate lists of random integers with a "clustered" distribution. + * Reference: + * Anh VN, Moffat A. Index compression using 64-bit words. Software: Practice and Experience 2010; 40(2):131-147. + * + * @author Daniel Lemire + */ +public class ClusteredDataGenerator { + + /** + * + */ +public ClusteredDataGenerator() { + this.unidg = new UniformDataGenerator(); + } + + /** + * @param seed random seed + */ +public ClusteredDataGenerator(final int seed) { + this.unidg = new UniformDataGenerator(seed); +} + +/** + * generates randomly N distinct integers from 0 to Max. + * @param N number of integers + * @param Max maximum integer value + * @return a randomly generated array + */ + public int[] generateClustered(int N, int Max) { + int[] array = new int[N]; + fillClustered(array, 0, N, 0, Max); + return array; + } + + void fillClustered(int[] array, int offset, int length, int Min, int Max) { + final int range = Max - Min; + if ((range == length) || (length <= 10)) { + fillUniform(array, offset, length, Min, Max); + return; + } + final int cut = length / 2 + + ((range - length - 1 > 0) ? this.unidg.rand.nextInt(range - length - 1) : 0); + final double p = this.unidg.rand.nextDouble(); + if (p < 0.25) { + fillUniform(array, offset, length / 2, Min, Min + cut); + fillClustered(array, offset + length / 2, length - length / 2, Min + cut, + Max); + } else if (p < 0.5) { + fillClustered(array, offset, length / 2, Min, Min + cut); + fillUniform(array, offset + length / 2, length - length / 2, Min + cut, + Max); + } else { + fillClustered(array, offset, length / 2, Min, Min + cut); + fillClustered(array, offset + length / 2, length - length / 2, Min + cut, + Max); + } + } + + void fillUniform(int[] array, int offset, int length, int Min, int Max) { + int[] v = this.unidg.generateUniform(length, Max - Min); + for (int k = 0; k < v.length; ++k) + array[k + offset] = Min + v[k]; + } + + UniformDataGenerator unidg; + +} + diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/UniformDataGenerator.java b/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/UniformDataGenerator.java new file mode 100644 index 000000000..6c91ea67e --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah/benchmark/UniformDataGenerator.java @@ -0,0 +1,114 @@ +package com.fr.third.googlecode.javaewah.benchmark; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ + +import java.util.Arrays; +import java.util.BitSet; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Random; + +/** + * This class will generate "uniform" lists of random integers. + * + * @author Daniel Lemire + */ +public class UniformDataGenerator { + /** + * construct generator of random arrays. + */ + public UniformDataGenerator() { + this.rand = new Random(); + } + + /** + * @param seed random seed + */ + public UniformDataGenerator(final int seed) { + this.rand = new Random(seed); + } + + /** + * generates randomly N distinct integers from 0 to Max. + */ + int[] generateUniformHash(int N, int Max) { + if (N > Max) + throw new RuntimeException("not possible"); + int[] ans = new int[N]; + HashSet s = new HashSet(); + while (s.size() < N) + s.add(new Integer(this.rand.nextInt(Max))); + Iterator i = s.iterator(); + for (int k = 0; k < N; ++k) + ans[k] = i.next().intValue(); + Arrays.sort(ans); + return ans; + } + + /** + * output all integers from the range [0,Max) that are not + * in the array + */ + static int[] negate(int[] x, int Max) { + int[] ans = new int[Max - x.length]; + int i = 0; + int c = 0; + for (int j = 0; j < x.length; ++j) { + int v = x[j]; + for (; i < v; ++i) + ans[c++] = i; + ++i; + } + while (c < ans.length) + ans[c++] = i++; + return ans; + } + + + /** + * generates randomly N distinct integers from 0 to Max. + * @param N Number of integers to generate + * @param Max Maximum value of the integers + * @return array containing random integers + */ + public int[] generateUniform(int N, int Max) { + if(N * 2 > Max) { + return negate( generateUniform(Max - N, Max), Max ); + } + if (2048 * N > Max) + return generateUniformBitmap(N, Max); + return generateUniformHash(N, Max); + } + + /** + * generates randomly N distinct integers from 0 to Max using a bitmap. + * @param N Number of integers to generate + * @param Max Maximum value of the integers + * @return array containing random integers + */ + int[] generateUniformBitmap(int N, int Max) { + if (N > Max) + throw new RuntimeException("not possible"); + int[] ans = new int[N]; + BitSet bs = new BitSet(Max); + int cardinality = 0; + while (cardinality < N) { + int v = this.rand.nextInt(Max); + if (!bs.get(v)) { + bs.set(v); + cardinality++; + } + } + int pos = 0; + for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) { + ans[pos++] = i; + } + return ans; + } + + Random rand = new Random(); + +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah32/BitCounter32.java b/fine-jgit/src/com/fr/third/googlecode/javaewah32/BitCounter32.java new file mode 100644 index 000000000..53a9a0ee5 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah32/BitCounter32.java @@ -0,0 +1,102 @@ +package com.fr.third.googlecode.javaewah32; + + + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc. and Veronika Zenz + * Licensed under the Apache License, Version 2.0. + */ +/** + * BitCounter is a fake bitset data structure. Instead of storing the actual data, + * it only records the number of set bits. + * + * @since 0.5.0 + * @author Daniel Lemire and David McIntosh + */ + +public final class BitCounter32 implements BitmapStorage32 { + + /** + * Virtually add words directly to the bitmap + * + * @param newdata the word + */ + // @Override : causes problems with Java 1.5 + @Override +public void add(final int newdata) { + this.oneBits += Integer.bitCount(newdata); + } + + + /** + * virtually add several literal words. + * + * @param data the literal words + * @param start the starting point in the array + * @param number the number of literal words to add + */ + // @Override : causes problems with Java 1.5 + @Override +public void addStreamOfLiteralWords(int[] data, int start, int number) { + for(int i=start;i iterator) { + this.masteriterator = iterator; + if(this.masteriterator.hasNext()) { + this.iterator = this.masteriterator.next(); + this.brlw = new BufferedRunningLengthWord32(this.iterator.next()); + this.literalWordStartPosition = this.iterator.literalWords() + this.brlw.literalwordoffset; + this.buffer = this.iterator.buffer(); + } + } + + + /** + * Discard first words, iterating to the next running length word if needed. + * + * @param x the number of words to be discarded + */ + @Override + public void discardFirstWords(int x) { + while (x > 0) { + if (this.brlw.RunningLength > x) { + this.brlw.RunningLength -= x; + return; + } + x -= this.brlw.RunningLength; + this.brlw.RunningLength = 0; + int toDiscard = x > this.brlw.NumberOfLiteralWords ? this.brlw.NumberOfLiteralWords : x; + + this.literalWordStartPosition += toDiscard; + this.brlw.NumberOfLiteralWords -= toDiscard; + x -= toDiscard; + if ((x > 0) || (this.brlw.size() == 0)) { + if (!this.next()) { + break; + } + } + } + } + /** + * Move to the next RunningLengthWord + * @return whether the move was possible + */ + @Override + public boolean next() { + if (!this.iterator.hasNext()) { + if(!reload()) { + this.brlw.NumberOfLiteralWords = 0; + this.brlw.RunningLength = 0; + return false; + } + } + this.brlw.reset(this.iterator.next()); + this.literalWordStartPosition = this.iterator.literalWords(); // + this.brlw.literalwordoffset ==0 + return true; + } + private boolean reload() { + if(!this.masteriterator.hasNext()) { + return false; + } + this.iterator = this.masteriterator.next(); + this.buffer = this.iterator.buffer(); + return true; + } + + + /** + * Get the nth literal word for the current running length word + * @param index zero based index + * @return the literal word + */ + @Override + public int getLiteralWordAt(int index) { + return this.buffer[this.literalWordStartPosition + index]; + } + + /** + * Gets the number of literal words for the current running length word. + * + * @return the number of literal words + */ + @Override + public int getNumberOfLiteralWords() { + return this.brlw.NumberOfLiteralWords; + } + + /** + * Gets the running bit. + * + * @return the running bit + */ + @Override + public boolean getRunningBit() { + return this.brlw.RunningBit; + } + + /** + * Gets the running length. + * + * @return the running length + */ + @Override + public int getRunningLength() { + return this.brlw.RunningLength; + } + + /** + * Size in uncompressed words of the current running length word. + * + * @return the size + */ + @Override + public int size() { + return this.brlw.size(); + } + + @Override + public BufferedIterator32 clone() throws CloneNotSupportedException { + BufferedIterator32 answer = (BufferedIterator32) super.clone(); + answer.brlw = this.brlw.clone(); + answer.buffer = this.buffer; + answer.iterator = this.iterator.clone(); + answer.literalWordStartPosition = this.literalWordStartPosition; + answer.masteriterator = this.masteriterator.clone(); + return answer; + } + + private BufferedRunningLengthWord32 brlw; + private int[] buffer; + private int literalWordStartPosition; + private EWAHIterator32 iterator; + private CloneableIterator masteriterator; + } \ No newline at end of file diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah32/BufferedRunningLengthWord32.java b/fine-jgit/src/com/fr/third/googlecode/javaewah32/BufferedRunningLengthWord32.java new file mode 100644 index 000000000..80b665e81 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah32/BufferedRunningLengthWord32.java @@ -0,0 +1,174 @@ +package com.fr.third.googlecode.javaewah32; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ + + + +/** + * Mostly for internal use. Similar to RunningLengthWord, but can + * be modified without access to the array, and has faster access. + * + * @author Daniel Lemire + * @since 0.5.0 + * + */ +public final class BufferedRunningLengthWord32 implements Cloneable { + + /** + * Instantiates a new buffered running length word. + * + * @param a the word + */ + public BufferedRunningLengthWord32(final int a) { + this.NumberOfLiteralWords = (a >>> (1 + RunningLengthWord32.runninglengthbits)); + this.RunningBit = (a & 1) != 0; + this.RunningLength = ((a >>> 1) & RunningLengthWord32.largestrunninglengthcount); + } + + /** + * Instantiates a new buffered running length word. + * + * @param rlw the rlw + */ + public BufferedRunningLengthWord32(final RunningLengthWord32 rlw) { + this(rlw.parent.buffer[rlw.position]); + } + + /** + * Discard first words. + * + * @param x the number of words to be discarded + */ + public void discardFirstWords(int x) { + if (this.RunningLength >= x) { + this.RunningLength -= x; + return; + } + x -= this.RunningLength; + this.RunningLength = 0; + this.literalwordoffset += x; + this.NumberOfLiteralWords -= x; + } + + /** + * Gets the number of literal words. + * + * @return the number of literal words + */ + public int getNumberOfLiteralWords() { + return this.NumberOfLiteralWords; + } + + /** + * Gets the running bit. + * + * @return the running bit + */ + public boolean getRunningBit() { + return this.RunningBit; + } + + /** + * Gets the running length. + * + * @return the running length + */ + public int getRunningLength() { + return this.RunningLength; + } + + /** + * Reset the values using the provided word. + * + * @param a the word + */ + public void reset(final int a) { + this.NumberOfLiteralWords = (a >>> (1 + RunningLengthWord32.runninglengthbits)); + this.RunningBit = (a & 1) != 0; + this.RunningLength = ((a >>> 1) & RunningLengthWord32.largestrunninglengthcount); + this.literalwordoffset = 0; + } + + /** + * Reset the values of this running length word so that it has the same values + * as the other running length word. + * + * @param rlw the other running length word + */ + public void reset(final RunningLengthWord32 rlw) { + reset(rlw.parent.buffer[rlw.position]); + } + + /** + * Sets the number of literal words. + * + * @param number the new number of literal words + */ + public void setNumberOfLiteralWords(final int number) { + this.NumberOfLiteralWords = number; + } + + /** + * Sets the running bit. + * + * @param b the new running bit + */ + public void setRunningBit(final boolean b) { + this.RunningBit = b; + } + + /** + * Sets the running length. + * + * @param number the new running length + */ + public void setRunningLength(final int number) { + this.RunningLength = number; + } + + /** + * Size in uncompressed words. + * + * @return the int + */ + public int size() { + return this.RunningLength + this.NumberOfLiteralWords; + } + + /* + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "running bit = " + getRunningBit() + " running length = " + + getRunningLength() + " number of lit. words " + + getNumberOfLiteralWords(); + } + + @Override +public BufferedRunningLengthWord32 clone() throws CloneNotSupportedException { + BufferedRunningLengthWord32 answer = (BufferedRunningLengthWord32) super.clone(); + answer.literalwordoffset = this.literalwordoffset; + answer.NumberOfLiteralWords = this.NumberOfLiteralWords; + answer.RunningBit = this.RunningBit; + answer.RunningLength = this.RunningLength; + return answer; + } + + /** how many literal words have we read so far? */ + public int literalwordoffset = 0; + + /** The Number of literal words. */ + public int NumberOfLiteralWords; + + /** The Running bit. */ + public boolean RunningBit; + + /** The Running length. */ + public int RunningLength; + + +} \ No newline at end of file diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah32/EWAHCompressedBitmap32.java b/fine-jgit/src/com/fr/third/googlecode/javaewah32/EWAHCompressedBitmap32.java new file mode 100644 index 000000000..56259ffee --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah32/EWAHCompressedBitmap32.java @@ -0,0 +1,1608 @@ +package com.fr.third.googlecode.javaewah32; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ + +import java.util.*; +import java.io.*; + +import com.fr.third.googlecode.javaewah.IntIterator; +import com.fr.third.googlecode.javaewah.LogicalElement; + + +/** + *

+ * This implements the patent-free EWAH scheme. Roughly speaking, it is a 32-bit + * variant of the BBC compression scheme used by Oracle for its bitmap indexes. + *

+ * + *

+ * In contrast with the 64-bit EWAH scheme (javaewah.EWAHCompressedBitmap), you + * can expect this class to compress better, but to be slower at processing the + * data. In effect, there is a trade-off between memory usage and performances. + *

+ * + * @see com.fr.third.googlecode.javaewah.EWAHCompressedBitmap + * + *

+ * The objective of this compression type is to provide some compression, + * while reducing as much as possible the CPU cycle usage. + *

+ * + * + *

+ * For more details, see the following paper: + *

+ * + *
    + *
  • Daniel Lemire, Owen Kaser, Kamel Aouiche, Sorting improves + * word-aligned bitmap indexes. Data & Knowledge Engineering 69 (1), pages + * 3-28, 2010. http://arxiv.org/abs/0901.3751
  • + *
+ * + * @since 0.5.0 + */ +public final class EWAHCompressedBitmap32 implements Cloneable, Externalizable, + Iterable, BitmapStorage32, LogicalElement { + + /** + * Creates an empty bitmap (no bit set to true). + */ + public EWAHCompressedBitmap32() { + this.buffer = new int[defaultbuffersize]; + this.rlw = new RunningLengthWord32(this, 0); + } + + /** + * Sets explicitly the buffer size (in 32-bit words). The initial memory usage + * will be "buffersize * 32". For large poorly compressible bitmaps, using + * large values may improve performance. + * + * @param buffersize + * number of 32-bit words reserved when the object is created) + */ + public EWAHCompressedBitmap32(final int buffersize) { + this.buffer = new int[buffersize]; + this.rlw = new RunningLengthWord32(this, 0); + } + + /** + * Adding words directly to the bitmap (for expert use). + * + * This is normally how you add data to the array. So you add bits in streams + * of 4*8 bits. + * + * Example: if you add 321, you are have added (in binary notation) + * 0b101000001, so you have effectively called set(0), set(6), set(8) + * in sequence. + * + * @param newdata + * the word + */ + @Override +public void add(final int newdata) { + add(newdata, wordinbits); + } + + /** + * Adding words directly to the bitmap (for expert use). + * + * @param newdata + * the word + * @param bitsthatmatter + * the number of significant bits (by default it should be 32) + */ + public void add(final int newdata, final int bitsthatmatter) { + this.sizeinbits += bitsthatmatter; + if (newdata == 0) { + addEmptyWord(false); + } else if (newdata == ~0) { + addEmptyWord(true); + } else { + addLiteralWord(newdata); + } + } + + /** + * For internal use. + * + * @param v + * the boolean value + * @return the storage cost of the addition + */ + private int addEmptyWord(final boolean v) { + final boolean noliteralword = (this.rlw.getNumberOfLiteralWords() == 0); + final int runlen = this.rlw.getRunningLength(); + if ((noliteralword) && (runlen == 0)) { + this.rlw.setRunningBit(v); + } + if ((noliteralword) && (this.rlw.getRunningBit() == v) + && (runlen < RunningLengthWord32.largestrunninglengthcount)) { + this.rlw.setRunningLength(runlen + 1); + return 0; + } + push_back(0); + this.rlw.position = this.actualsizeinwords - 1; + this.rlw.setRunningBit(v); + this.rlw.setRunningLength(1); + return 1; + } + + /** + * For internal use. + * + * @param newdata + * the literal word + * @return the storage cost of the addition + */ + private int addLiteralWord(final int newdata) { + final int numbersofar = this.rlw.getNumberOfLiteralWords(); + if (numbersofar >= RunningLengthWord32.largestliteralcount) { + push_back(0); + this.rlw.position = this.actualsizeinwords - 1; + this.rlw.setNumberOfLiteralWords(1); + push_back(newdata); + return 2; + } + this.rlw.setNumberOfLiteralWords(numbersofar + 1); + push_back(newdata); + return 1; + } + + /** + * if you have several literal words to copy over, this might be faster. + * + * + * @param data + * the literal words + * @param start + * the starting point in the array + * @param number + * the number of literal words to add + */ + @Override +public void addStreamOfLiteralWords(final int[] data, final int start, + final int number) { + int leftovernumber = number; + while (leftovernumber > 0) { + final int NumberOfLiteralWords = this.rlw.getNumberOfLiteralWords(); + final int whatwecanadd = leftovernumber < RunningLengthWord32.largestliteralcount + - NumberOfLiteralWords ? leftovernumber + : RunningLengthWord32.largestliteralcount + - NumberOfLiteralWords; + this.rlw.setNumberOfLiteralWords(NumberOfLiteralWords + + whatwecanadd); + leftovernumber -= whatwecanadd; + push_back(data, start, whatwecanadd); + this.sizeinbits += whatwecanadd * wordinbits; + if (leftovernumber > 0) { + push_back(0); + this.rlw.position = this.actualsizeinwords - 1; + } + } + } + + /** + * For experts: You want to add many zeroes or ones? This is the method you + * use. + * + * @param v + * the boolean value + * @param number + * the number + */ + @Override +public void addStreamOfEmptyWords(final boolean v, int number) { + if (number == 0) + return; + this.sizeinbits += number * wordinbits; + if ((this.rlw.getRunningBit() != v) && (this.rlw.size() == 0)) { + this.rlw.setRunningBit(v); + } else if ((this.rlw.getNumberOfLiteralWords() != 0) + || (this.rlw.getRunningBit() != v)) { + push_back(0); + this.rlw.position = this.actualsizeinwords - 1; + if (v) + this.rlw.setRunningBit(v); + } + final int runlen = this.rlw.getRunningLength(); + final int whatwecanadd = number < RunningLengthWord32.largestrunninglengthcount + - runlen ? number : RunningLengthWord32.largestrunninglengthcount + - runlen; + this.rlw.setRunningLength(runlen + whatwecanadd); + number -= whatwecanadd; + while (number >= RunningLengthWord32.largestrunninglengthcount) { + push_back(0); + this.rlw.position = this.actualsizeinwords - 1; + if (v) + this.rlw.setRunningBit(v); + this.rlw.setRunningLength(RunningLengthWord32.largestrunninglengthcount); + number -= RunningLengthWord32.largestrunninglengthcount; + } + if (number > 0) { + push_back(0); + this.rlw.position = this.actualsizeinwords - 1; + if (v) + this.rlw.setRunningBit(v); + this.rlw.setRunningLength(number); + } + } + + /** + * Same as addStreamOfLiteralWords, but the words are negated. + * + * @param data + * the literal words + * @param start + * the starting point in the array + * @param number + * the number of literal words to add + */ + @Override +public void addStreamOfNegatedLiteralWords(final int[] data, final int start, + final int number) { + int leftovernumber = number; + while (leftovernumber > 0) { + final int NumberOfLiteralWords = this.rlw.getNumberOfLiteralWords(); + final int whatwecanadd = leftovernumber < RunningLengthWord32.largestliteralcount + - NumberOfLiteralWords ? leftovernumber + : RunningLengthWord32.largestliteralcount + - NumberOfLiteralWords; + this.rlw.setNumberOfLiteralWords(NumberOfLiteralWords + + whatwecanadd); + leftovernumber -= whatwecanadd; + negative_push_back(data, start, whatwecanadd); + this.sizeinbits += whatwecanadd * wordinbits; + if (leftovernumber > 0) { + push_back(0); + this.rlw.position = this.actualsizeinwords - 1; + } + } + } + + /** + * Returns a new compressed bitmap containing the bitwise AND values of the + * current bitmap with some other bitmap. + * + * The running time is proportional to the sum of the compressed sizes (as + * reported by sizeInBytes()). + * + * If you are not planning on adding to the resulting bitmap, you may call the trim() + * method to reduce memory usage. + * + * @param a + * the other bitmap + * @return the EWAH compressed bitmap + */ + @Override +public EWAHCompressedBitmap32 and(final EWAHCompressedBitmap32 a) { + final EWAHCompressedBitmap32 container = new EWAHCompressedBitmap32(); + container + .reserve(this.actualsizeinwords > a.actualsizeinwords ? this.actualsizeinwords + : a.actualsizeinwords); + andToContainer(a, container); + return container; + } + + /** + * Computes new compressed bitmap containing the bitwise AND values of the + * current bitmap with some other bitmap. + * + * The running time is proportional to the sum of the compressed sizes (as + * reported by sizeInBytes()). + * + * @param a + * the other bitmap + * @param container + * where we store the result + */ + /** + * Computes new compressed bitmap containing the bitwise AND values of the + * current bitmap with some other bitmap. + * + * The running time is proportional to the sum of the compressed sizes (as + * reported by sizeInBytes()). + * + * @since 0.4.0 + * @param a + * the other bitmap + * @param container + * where we store the result + */ + public void andToContainer(final EWAHCompressedBitmap32 a, final BitmapStorage32 container) { + final EWAHIterator32 i = a.getEWAHIterator(); + final EWAHIterator32 j = getEWAHIterator(); + final IteratingBufferedRunningLengthWord32 rlwi = new IteratingBufferedRunningLengthWord32(i); + final IteratingBufferedRunningLengthWord32 rlwj = new IteratingBufferedRunningLengthWord32(j); + while ((rlwi.size()>0) && (rlwj.size()>0)) { + while ((rlwi.getRunningLength() > 0) || (rlwj.getRunningLength() > 0)) { + final boolean i_is_prey = rlwi.getRunningLength() < rlwj + .getRunningLength(); + final IteratingBufferedRunningLengthWord32 prey = i_is_prey ? rlwi + : rlwj; + final IteratingBufferedRunningLengthWord32 predator = i_is_prey ? rlwj + : rlwi; + if (predator.getRunningBit() == false) { + container.addStreamOfEmptyWords(false, predator.getRunningLength()); + prey.discardFirstWords(predator.getRunningLength()); + predator.discardFirstWords(predator.getRunningLength()); + } else { + final int index = prey.discharge(container, predator.getRunningLength()); + container.addStreamOfEmptyWords(false, predator.getRunningLength() + - index); + predator.discardFirstWords(predator.getRunningLength()); + } + } + final int nbre_literal = Math.min(rlwi.getNumberOfLiteralWords(), + rlwj.getNumberOfLiteralWords()); + if (nbre_literal > 0) { + for (int k = 0; k < nbre_literal; ++k) + container.add(rlwi.getLiteralWordAt(k) & rlwj.getLiteralWordAt(k)); + rlwi.discardFirstWords(nbre_literal); + rlwj.discardFirstWords(nbre_literal); + } + } + if (adjustContainerSizeWhenAggregating) { + final boolean i_remains = rlwi.size() > 0; + final IteratingBufferedRunningLengthWord32 remaining = i_remains ? rlwi + : rlwj; + remaining.dischargeAsEmpty(container); + container.setSizeInBits(Math.max(sizeInBits(), a.sizeInBits())); + } + } + + + /** + * Returns the cardinality of the result of a bitwise AND of the values of the + * current bitmap with some other bitmap. Avoids needing to allocate an + * intermediate bitmap to hold the result of the OR. + * + * @param a + * the other bitmap + * @return the cardinality + */ + public int andCardinality(final EWAHCompressedBitmap32 a) { + final BitCounter32 counter = new BitCounter32(); + andToContainer(a, counter); + return counter.getCount(); + } + + /** + * Returns a new compressed bitmap containing the bitwise AND NOT values of + * the current bitmap with some other bitmap. + * + * The running time is proportional to the sum of the compressed sizes (as + * reported by sizeInBytes()). + * + * If you are not planning on adding to the resulting bitmap, you may call the trim() + * method to reduce memory usage. + * + * @param a + * the other bitmap + * @return the EWAH compressed bitmap + */ + @Override +public EWAHCompressedBitmap32 andNot(final EWAHCompressedBitmap32 a) { + final EWAHCompressedBitmap32 container = new EWAHCompressedBitmap32(); + container + .reserve(this.actualsizeinwords > a.actualsizeinwords ? this.actualsizeinwords + : a.actualsizeinwords); + andNotToContainer(a, container); + return container; + } + + /** + * Returns a new compressed bitmap containing the bitwise AND NOT values of + * the current bitmap with some other bitmap. + * + * The running time is proportional to the sum of the compressed sizes (as + * reported by sizeInBytes()). + * + * @param a the other bitmap + * @param container where we store the result + */ + public void andNotToContainer(final EWAHCompressedBitmap32 a, + final BitmapStorage32 container) { + final EWAHIterator32 i = getEWAHIterator(); + final EWAHIterator32 j = a.getEWAHIterator(); + final IteratingBufferedRunningLengthWord32 rlwi = new IteratingBufferedRunningLengthWord32(i); + final IteratingBufferedRunningLengthWord32 rlwj = new IteratingBufferedRunningLengthWord32(j); + while ((rlwi.size()>0) && (rlwj.size()>0)) { + while ((rlwi.getRunningLength() > 0) || (rlwj.getRunningLength() > 0)) { + final boolean i_is_prey = rlwi.getRunningLength() < rlwj + .getRunningLength(); + final IteratingBufferedRunningLengthWord32 prey = i_is_prey ? rlwi : rlwj; + final IteratingBufferedRunningLengthWord32 predator = i_is_prey ? rlwj + : rlwi; + if ( ((predator.getRunningBit() == true) && (i_is_prey)) + || ((predator.getRunningBit() == false) && (!i_is_prey))){ + container.addStreamOfEmptyWords(false, predator.getRunningLength()); + prey.discardFirstWords(predator.getRunningLength()); + predator.discardFirstWords(predator.getRunningLength()); + } else if (i_is_prey) { + int index = prey.discharge(container, predator.getRunningLength()); + container.addStreamOfEmptyWords(false, predator.getRunningLength() + - index); + predator.discardFirstWords(predator.getRunningLength()); + } else { + int index = prey.dischargeNegated(container, predator.getRunningLength()); + container.addStreamOfEmptyWords(true, predator.getRunningLength() + - index); + predator.discardFirstWords(predator.getRunningLength()); + } + } + final int nbre_literal = Math.min(rlwi.getNumberOfLiteralWords(), + rlwj.getNumberOfLiteralWords()); + if (nbre_literal > 0) { + for (int k = 0; k < nbre_literal; ++k) + container.add(rlwi.getLiteralWordAt(k) & (~rlwj.getLiteralWordAt(k))); + rlwi.discardFirstWords(nbre_literal); + rlwj.discardFirstWords(nbre_literal); + } + } + final boolean i_remains = rlwi.size()>0; + final IteratingBufferedRunningLengthWord32 remaining = i_remains ? rlwi : rlwj; + if(i_remains) + remaining.discharge(container); + else if (adjustContainerSizeWhenAggregating) + remaining.dischargeAsEmpty(container); + if (adjustContainerSizeWhenAggregating) + container.setSizeInBits(Math.max(sizeInBits(), a.sizeInBits())); + + } + + /** + * Returns the cardinality of the result of a bitwise AND NOT of the values of + * the current bitmap with some other bitmap. Avoids needing to allocate an + * intermediate bitmap to hold the result of the OR. + * + * @param a + * the other bitmap + * @return the cardinality + */ + public int andNotCardinality(final EWAHCompressedBitmap32 a) { + final BitCounter32 counter = new BitCounter32(); + andNotToContainer(a, counter); + return counter.getCount(); + } + + /** + * reports the number of bits set to true. Running time is proportional to + * compressed size (as reported by sizeInBytes). + * + * @return the number of bits set to true + */ + public int cardinality() { + int counter = 0; + final EWAHIterator32 i = new EWAHIterator32(this, + this.actualsizeinwords); + while (i.hasNext()) { + RunningLengthWord32 localrlw = i.next(); + if (localrlw.getRunningBit()) { + counter += wordinbits * localrlw.getRunningLength(); + } + for (int j = 0; j < localrlw.getNumberOfLiteralWords(); ++j) { + counter += Integer.bitCount(i.buffer()[i.literalWords() + j]); + } + } + return counter; + } + + /** + * Clear any set bits and set size in bits back to 0 + */ + public void clear() { + this.sizeinbits = 0; + this.actualsizeinwords = 1; + this.rlw.position = 0; + // buffer is not fully cleared but any new set operations should overwrite + // stale data + this.buffer[0] = 0; + } + + /* + * @see java.lang.Object#clone() + */ + @Override + public EWAHCompressedBitmap32 clone() throws CloneNotSupportedException { + final EWAHCompressedBitmap32 clone = (EWAHCompressedBitmap32) super.clone(); + clone.buffer = this.buffer.clone(); + clone.actualsizeinwords = this.actualsizeinwords; + clone.sizeinbits = this.sizeinbits; + return clone; + } + + /** + * Deserialize. + * + * @param in + * the DataInput stream + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public void deserialize(DataInput in) throws IOException { + this.sizeinbits = in.readInt(); + this.actualsizeinwords = in.readInt(); + if (this.buffer.length < this.actualsizeinwords) { + this.buffer = new int[this.actualsizeinwords]; + } + for (int k = 0; k < this.actualsizeinwords; ++k) + this.buffer[k] = in.readInt(); + this.rlw = new RunningLengthWord32(this, in.readInt()); + } + + /** + * Check to see whether the two compressed bitmaps contain the same set bits. + * + * @see Object#equals(Object) + */ + @Override + public boolean equals(Object o) { + if (o instanceof EWAHCompressedBitmap32) { + try { + this.xorToContainer((EWAHCompressedBitmap32) o, new NonEmptyVirtualStorage32()); + return true; + } catch (NonEmptyVirtualStorage32.NonEmptyException e) { + return false; + } + } + return false; + } + + /** + * For experts: You want to add many zeroes or ones faster? + * + * This method does not update sizeinbits. + * + * @param v + * the boolean value + * @param number + * the number (must be greater than 0) + */ + private void fastaddStreamOfEmptyWords(final boolean v, int number) { + if ((this.rlw.getRunningBit() != v) && (this.rlw.size() == 0)) { + this.rlw.setRunningBit(v); + } else if ((this.rlw.getNumberOfLiteralWords() != 0) + || (this.rlw.getRunningBit() != v)) { + push_back(0); + this.rlw.position = this.actualsizeinwords - 1; + if (v) + this.rlw.setRunningBit(v); + } + final int runlen = this.rlw.getRunningLength(); + final int whatwecanadd = number < RunningLengthWord32.largestrunninglengthcount + - runlen ? number : RunningLengthWord32.largestrunninglengthcount + - runlen; + this.rlw.setRunningLength(runlen + whatwecanadd); + number -= whatwecanadd; + while (number >= RunningLengthWord32.largestrunninglengthcount) { + push_back(0); + this.rlw.position = this.actualsizeinwords - 1; + if (v) + this.rlw.setRunningBit(v); + this.rlw.setRunningLength(RunningLengthWord32.largestrunninglengthcount); + number -= RunningLengthWord32.largestrunninglengthcount; + } + if (number > 0) { + push_back(0); + this.rlw.position = this.actualsizeinwords - 1; + if (v) + this.rlw.setRunningBit(v); + this.rlw.setRunningLength(number); + } + } + + /** + * Gets an EWAHIterator over the data. This is a customized iterator which + * iterates over run length word. For experts only. + * + * @return the EWAHIterator + */ + public EWAHIterator32 getEWAHIterator() { + return new EWAHIterator32(this, this.actualsizeinwords); + } + + /** + * @return the IteratingRLW iterator corresponding to this bitmap + */ + public IteratingRLW32 getIteratingRLW() { + return new IteratingBufferedRunningLengthWord32(this); + } + + /** + * get the locations of the true values as one vector. (may use more memory + * than iterator()) + * + * @return the positions + */ + public List getPositions() { + final ArrayList v = new ArrayList(); + final EWAHIterator32 i = new EWAHIterator32(this, + this.actualsizeinwords); + int pos = 0; + while (i.hasNext()) { + RunningLengthWord32 localrlw = i.next(); + if (localrlw.getRunningBit()) { + for (int j = 0; j < localrlw.getRunningLength(); ++j) { + for (int c = 0; c < wordinbits; ++c) + v.add(new Integer(pos++)); + } + } else { + pos += wordinbits * localrlw.getRunningLength(); + } + for (int j = 0; j < localrlw.getNumberOfLiteralWords(); ++j) { + int data = i.buffer()[i.literalWords() + j]; + while (data != 0) { + final int ntz = Integer.numberOfTrailingZeros(data); + data ^= (1 << ntz); + v.add(new Integer(ntz + pos)); + } + pos += wordinbits; + } + } + while ((v.size() > 0) + && (v.get(v.size() - 1).intValue() >= this.sizeinbits)) + v.remove(v.size() - 1); + return v; + } + + /** + * Returns a customized hash code (based on Karp-Rabin). Naturally, if the + * bitmaps are equal, they will hash to the same value. + * + */ + @Override + public int hashCode() { + int karprabin = 0; + final int B = 31; + final EWAHIterator32 i = new EWAHIterator32(this, + this.actualsizeinwords); + while( i.hasNext() ) { + i.next(); + if (i.rlw.getRunningBit() == true) { + karprabin += B * karprabin + i.rlw.getRunningLength(); + } + for (int k = 0; k < i.rlw.getNumberOfLiteralWords(); ++k) { + karprabin += B * karprabin + this.buffer[k + i.literalWords()]; + } + } + return karprabin; + } + + /** + * Return true if the two EWAHCompressedBitmap have both at least one true bit + * in the same position. Equivalently, you could call "and" and check whether + * there is a set bit, but intersects will run faster if you don't need the + * result of the "and" operation. + * + * @param a + * the other bitmap + * @return whether they intersect + */ + public boolean intersects(final EWAHCompressedBitmap32 a) { + NonEmptyVirtualStorage32 nevs = new NonEmptyVirtualStorage32(); + try { + this.andToContainer(a, nevs); + } catch (NonEmptyVirtualStorage32.NonEmptyException nee) { + return true; + } + return false; + } + + /** + * Iterator over the set bits (this is what most people will want to use to + * browse the content if they want an iterator). The location of the set bits + * is returned, in increasing order. + * + * @return the int iterator + */ + public IntIterator intIterator() { + return new IntIteratorImpl32( + new EWAHIterator32(this, this.actualsizeinwords)); + } + + /** + * iterate over the positions of the true values. This is similar to + * intIterator(), but it uses Java generics. + * + * @return the iterator + */ + @Override +public Iterator iterator() { + return new Iterator() { + @Override + public boolean hasNext() { + return this.under.hasNext(); + } + + @Override + public Integer next() { + return new Integer(this.under.next()); + } + + @Override + public void remove() { + throw new UnsupportedOperationException("bitsets do not support remove"); + } + + final private IntIterator under = intIterator(); + }; + } + + /** + * For internal use. + * + * @param data + * the array of words to be added + * @param start + * the starting point + * @param number + * the number of words to add + */ + private void negative_push_back(final int[] data, final int start, + final int number) { + while (this.actualsizeinwords + number >= this.buffer.length) { + final int oldbuffer[] = this.buffer; + if(this.actualsizeinwords + number < 32768) + this.buffer = new int[(this.actualsizeinwords + number) * 2]; + else if ((this.actualsizeinwords + number) * 3 / 2 < this.actualsizeinwords + number) + this.buffer = new int[Integer.MAX_VALUE]; + else + this.buffer = new int[(this.actualsizeinwords + number) * 3 / 2]; + System.arraycopy(oldbuffer, 0, this.buffer, 0, oldbuffer.length); + this.rlw.parent.buffer = this.buffer; + } + for (int k = 0; k < number; ++k) + this.buffer[this.actualsizeinwords + k] = ~data[start + k]; + this.actualsizeinwords += number; + } + + /** + * Negate (bitwise) the current bitmap. To get a negated copy, do + * EWAHCompressedBitmap x= ((EWAHCompressedBitmap) mybitmap.clone()); x.not(); + * + * The running time is proportional to the compressed size (as reported by + * sizeInBytes()). + * + */ + @Override +public void not() { + final EWAHIterator32 i = new EWAHIterator32(this, + this.actualsizeinwords); + if (!i.hasNext()) + return; + while (true) { + final RunningLengthWord32 rlw1 = i.next(); + rlw1.setRunningBit(!rlw1.getRunningBit()); + for (int j = 0; j < rlw1.getNumberOfLiteralWords(); ++j) { + i.buffer()[i.literalWords() + j] = ~i.buffer()[i.literalWords() + j]; + } + if (!i.hasNext()) {// must potentially adjust the last literal word + final int usedbitsinlast = this.sizeinbits % wordinbits; + if (usedbitsinlast == 0) + return; + + if (rlw1.getNumberOfLiteralWords() == 0) { + if((rlw1.getRunningLength()>0) && (rlw1.getRunningBit())) { + rlw1.setRunningLength(rlw1.getRunningLength()-1); + this.addLiteralWord((~0) >>> (wordinbits - usedbitsinlast)); + } + return; + } + i.buffer()[i.literalWords() + rlw1.getNumberOfLiteralWords() - 1] &= ((~0) >>> (wordinbits - usedbitsinlast)); + return; + } + + } + } + + + /** + * Returns a new compressed bitmap containing the bitwise OR values of the + * current bitmap with some other bitmap. + * + * The running time is proportional to the sum of the compressed sizes (as + * reported by sizeInBytes()). + * + * If you are not planning on adding to the resulting bitmap, you may call the trim() + * method to reduce memory usage. + * + * @param a + * the other bitmap + * @return the EWAH compressed bitmap + */ + @Override +public EWAHCompressedBitmap32 or(final EWAHCompressedBitmap32 a) { + final EWAHCompressedBitmap32 container = new EWAHCompressedBitmap32(); + container.reserve(this.actualsizeinwords + a.actualsizeinwords); + orToContainer(a, container); + return container; + } + + /** + * Computes the bitwise or between the current bitmap and the bitmap "a". + * Stores the result in the container. + * + * @param a + * the other bitmap + * @param container + * where we store the result + */ + public void orToContainer(final EWAHCompressedBitmap32 a, final BitmapStorage32 container) { + final EWAHIterator32 i = a.getEWAHIterator(); + final EWAHIterator32 j = getEWAHIterator(); + final IteratingBufferedRunningLengthWord32 rlwi = new IteratingBufferedRunningLengthWord32(i); + final IteratingBufferedRunningLengthWord32 rlwj = new IteratingBufferedRunningLengthWord32(j); + while ((rlwi.size()>0) && (rlwj.size()>0)) { + while ((rlwi.getRunningLength() > 0) || (rlwj.getRunningLength() > 0)) { + final boolean i_is_prey = rlwi.getRunningLength() < rlwj + .getRunningLength(); + final IteratingBufferedRunningLengthWord32 prey = i_is_prey ? rlwi + : rlwj; + final IteratingBufferedRunningLengthWord32 predator = i_is_prey ? rlwj + : rlwi; + if (predator.getRunningBit() == true) { + container.addStreamOfEmptyWords(true, predator.getRunningLength()); + prey.discardFirstWords(predator.getRunningLength()); + predator.discardFirstWords(predator.getRunningLength()); + } else { + int index = prey.discharge(container, predator.getRunningLength()); + container.addStreamOfEmptyWords(false, predator.getRunningLength() + - index); + predator.discardFirstWords(predator.getRunningLength()); + } + } + final int nbre_literal = Math.min(rlwi.getNumberOfLiteralWords(), + rlwj.getNumberOfLiteralWords()); + if (nbre_literal > 0) { + for (int k = 0; k < nbre_literal; ++k) { + container.add(rlwi.getLiteralWordAt(k) | rlwj.getLiteralWordAt(k)); + } + rlwi.discardFirstWords(nbre_literal); + rlwj.discardFirstWords(nbre_literal); + } + } + final boolean i_remains = rlwi.size()>0; + final IteratingBufferedRunningLengthWord32 remaining = i_remains ? rlwi : rlwj; + remaining.discharge(container); + container.setSizeInBits(Math.max(sizeInBits(), a.sizeInBits())); + } + /** + * Returns the cardinality of the result of a bitwise OR of the values of the + * current bitmap with some other bitmap. Avoids needing to allocate an + * intermediate bitmap to hold the result of the OR. + * + * @param a + * the other bitmap + * @return the cardinality + */ + public int orCardinality(final EWAHCompressedBitmap32 a) { + final BitCounter32 counter = new BitCounter32(); + orToContainer(a, counter); + return counter.getCount(); + } + + /** + * For internal use. + * + * @param data + * the word to be added + */ + private void push_back(final int data) { + if (this.actualsizeinwords == this.buffer.length) { + final int oldbuffer[] = this.buffer; + if(oldbuffer.length < 32768) + this.buffer = new int[oldbuffer.length * 2]; + else if (oldbuffer.length * 3 / 2 < oldbuffer.length) + this.buffer = new int[Integer.MAX_VALUE]; + else + this.buffer = new int[oldbuffer.length * 3 / 2]; + System.arraycopy(oldbuffer, 0, this.buffer, 0, oldbuffer.length); + this.rlw.parent.buffer = this.buffer; + } + this.buffer[this.actualsizeinwords++] = data; + } + + /** + * For internal use. + * + * @param data + * the array of words to be added + * @param start + * the starting point + * @param number + * the number of words to add + */ + private void push_back(final int[] data, final int start, final int number) { + if (this.actualsizeinwords + number >= this.buffer.length) { + final int oldbuffer[] = this.buffer; + if(this.actualsizeinwords + number < 32768) + this.buffer = new int[(this.actualsizeinwords + number) * 2]; + else if((this.actualsizeinwords + number) * 3 / 2 < this.actualsizeinwords + number) //overflow + this.buffer = new int[Integer.MAX_VALUE]; + else + this.buffer = new int[(this.actualsizeinwords + number) * 3 / 2]; + System.arraycopy(oldbuffer, 0, this.buffer, 0, oldbuffer.length); + this.rlw.parent.buffer = this.buffer; + } + System.arraycopy(data, start, this.buffer, this.actualsizeinwords, number); + this.actualsizeinwords += number; + } + + /* + * @see java.io.Externalizable#readExternal(java.io.ObjectInput) + */ + @Override +public void readExternal(ObjectInput in) throws IOException { + deserialize(in); + } + + /** + * For internal use (trading off memory for speed). + * + * @param size + * the number of words to allocate + * @return True if the operation was a success. + */ + private boolean reserve(final int size) { + if (size > this.buffer.length) { + final int oldbuffer[] = this.buffer; + this.buffer = new int[size]; + System.arraycopy(oldbuffer, 0, this.buffer, 0, oldbuffer.length); + this.rlw.parent.buffer = this.buffer; + return true; + } + return false; + } + + /** + * Serialize. + * + * @param out + * the DataOutput stream + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public void serialize(DataOutput out) throws IOException { + out.writeInt(this.sizeinbits); + out.writeInt(this.actualsizeinwords); + for (int k = 0; k < this.actualsizeinwords; ++k) + out.writeInt(this.buffer[k]); + out.writeInt(this.rlw.position); + } + + /** + * Report the size required to serialize this bitmap + * + * @return the size in bytes + */ + public int serializedSizeInBytes() { + return this.sizeInBytes() + 3 * 4; + } + + /** + * Query the value of a single bit. Relying on this method when speed is + * needed is discouraged. The complexity is linear with the size of the + * bitmap. + * + * (This implementation is based on zhenjl's Go version of JavaEWAH.) + * + * @param i + * the bit we are interested in + * @return whether the bit is set to true + */ + public boolean get(final int i) { + if ((i < 0) || (i >= this.sizeinbits)) + return false; + int WordChecked = 0; + final IteratingRLW32 j = getIteratingRLW(); + final int wordi = i / wordinbits; + while (WordChecked <= wordi) { + WordChecked += j.getRunningLength(); + if (wordi < WordChecked) { + return j.getRunningBit(); + } + if (wordi < WordChecked + j.getNumberOfLiteralWords()) { + final int w = j.getLiteralWordAt(wordi + - WordChecked); + return (w & (1 << i)) != 0; + } + WordChecked += j.getNumberOfLiteralWords(); + j.next(); + } + return false; + } + + /** + * Set the bit at position i to true, the bits must be set in (strictly) increasing + * order. For example, set(15) and then set(7) will fail. You must do set(7) + * and then set(15). + * + * @param i + * the index + * @return true if the value was set (always true when i is greater or equal to sizeInBits()). + * @throws IndexOutOfBoundsException + * if i is negative or greater than Integer.MAX_VALUE - 32 + */ + + public boolean set(final int i) { + if ((i > Integer.MAX_VALUE - wordinbits) || (i < 0)) + throw new IndexOutOfBoundsException("Set values should be between 0 and " + + (Integer.MAX_VALUE - wordinbits)); + if (i < this.sizeinbits) + return false; + // distance in words: + final int dist = (i + wordinbits) / wordinbits + - (this.sizeinbits + wordinbits - 1) / wordinbits; + this.sizeinbits = i + 1; + if (dist > 0) {// easy + if (dist > 1) + fastaddStreamOfEmptyWords(false, dist - 1); + addLiteralWord(1 << (i % wordinbits)); + return true; + } + if (this.rlw.getNumberOfLiteralWords() == 0) { + this.rlw.setRunningLength(this.rlw.getRunningLength() - 1); + addLiteralWord(1 << (i % wordinbits)); + return true; + } + this.buffer[this.actualsizeinwords - 1] |= 1 << (i % wordinbits); + if (this.buffer[this.actualsizeinwords - 1] == ~0) { + this.buffer[this.actualsizeinwords - 1] = 0; + --this.actualsizeinwords; + this.rlw.setNumberOfLiteralWords(this.rlw.getNumberOfLiteralWords() - 1); + // next we add one clean word + addEmptyWord(true); + } + return true; + } + + /** + * Set the size in bits. This does not change the compressed bitmap. + * + */ + @Override +public void setSizeInBits(final int size) { + if((size+EWAHCompressedBitmap32.wordinbits-1)/EWAHCompressedBitmap32.wordinbits!= (this.sizeinbits+EWAHCompressedBitmap32.wordinbits-1)/EWAHCompressedBitmap32.wordinbits) + throw new RuntimeException("You can only reduce the size of the bitmap within the scope of the last word. To extend the bitmap, please call setSizeInbits(int,boolean): "+size+" "+this.sizeinbits); + this.sizeinbits = size; + } + + /** + * Change the reported size in bits of the *uncompressed* bitmap represented + * by this compressed bitmap. It may change the underlying compressed bitmap. + * It is not possible to reduce the sizeInBits, but + * it can be extended. The new bits are set to false or true depending on the + * value of defaultvalue. + * + * @param size + * the size in bits + * @param defaultvalue + * the default boolean value + * @return true if the update was possible + */ + public boolean setSizeInBits(final int size, final boolean defaultvalue) { + if (size < this.sizeinbits) + return false; + if (defaultvalue == false) + extendEmptyBits(this, this.sizeinbits, size); + else { + // next bit could be optimized + while (((this.sizeinbits % wordinbits) != 0) && (this.sizeinbits < size)) { + this.set(this.sizeinbits); + } + this.addStreamOfEmptyWords(defaultvalue, (size / wordinbits) + - this.sizeinbits / wordinbits); + // next bit could be optimized + while (this.sizeinbits < size) { + this.set(this.sizeinbits); + } + } + this.sizeinbits = size; + return true; + } + + /** + * Returns the size in bits of the *uncompressed* bitmap represented by this + * compressed bitmap. Initially, the sizeInBits is zero. It is extended + * automatically when you set bits to true. + * + * @return the size in bits + */ + @Override +public int sizeInBits() { + return this.sizeinbits; + } + + /** + * Report the *compressed* size of the bitmap (equivalent to memory usage, + * after accounting for some overhead). + * + * @return the size in bytes + */ + @Override +public int sizeInBytes() { + return this.actualsizeinwords * (wordinbits / 8); + } + + /** + * Populate an array of (sorted integers) corresponding to the location of the + * set bits. + * + * @return the array containing the location of the set bits + */ + public int[] toArray() { + int[] ans = new int[this.cardinality()]; + int inanspos = 0; + int pos = 0; + final EWAHIterator32 i = new EWAHIterator32(this, + this.actualsizeinwords); + while (i.hasNext()) { + RunningLengthWord32 localrlw = i.next(); + if (localrlw.getRunningBit()) { + for (int j = 0; j < localrlw.getRunningLength(); ++j) { + for (int c = 0; c < wordinbits; ++c) { + ans[inanspos++] = pos++; + } + } + } else { + pos += wordinbits * localrlw.getRunningLength(); + } + for (int j = 0; j < localrlw.getNumberOfLiteralWords(); ++j) { + int data = i.buffer()[i.literalWords() + j]; + if (!usetrailingzeros) { + for (int c = 0; c < wordinbits; ++c) { + if ((data & (1 << c)) != 0) + ans[inanspos++] = c + pos; + } + pos += wordinbits; + } else { + while (data != 0) { + final int ntz = Integer.numberOfTrailingZeros(data); + data ^= (1l << ntz); + ans[inanspos++] = ntz + pos; + } + pos += wordinbits; + } + } + } + return ans; + + } + + /** + * A more detailed string describing the bitmap (useful for debugging). + * + * @return the string + */ + public String toDebugString() { + String ans = " EWAHCompressedBitmap, size in bits = " + this.sizeinbits + + " size in words = " + this.actualsizeinwords + "\n"; + final EWAHIterator32 i = new EWAHIterator32(this, + this.actualsizeinwords); + while (i.hasNext()) { + RunningLengthWord32 localrlw = i.next(); + if (localrlw.getRunningBit()) { + ans += localrlw.getRunningLength() + " 1x11\n"; + } else { + ans += localrlw.getRunningLength() + " 0x00\n"; + } + ans += localrlw.getNumberOfLiteralWords() + " dirties\n"; + for (int j = 0; j < localrlw.getNumberOfLiteralWords(); ++j) { + int data = i.buffer()[i.literalWords() + j]; + ans += "\t" + data + "\n"; + } + } + return ans; + } + + /** + * A string describing the bitmap. + * + * @return the string + */ + @Override + public String toString() { + StringBuffer answer = new StringBuffer(); + IntIterator i = this.intIterator(); + answer.append("{"); + if (i.hasNext()) + answer.append(i.next()); + while (i.hasNext()) { + answer.append(","); + answer.append(i.next()); + } + answer.append("}"); + return answer.toString(); + } + /** + * swap the content of the bitmap with another. + * + * @param other + * bitmap to swap with + */ + public void swap(final EWAHCompressedBitmap32 other) { + int[] tmp = this.buffer; + this.buffer = other.buffer; + other.buffer = tmp; + + int tmp2 = this.rlw.position; + this.rlw.position = other.rlw.position; + other.rlw.position = tmp2; + + int tmp3 = this.actualsizeinwords; + this.actualsizeinwords = other.actualsizeinwords; + other.actualsizeinwords = tmp3; + + int tmp4 = this.sizeinbits; + this.sizeinbits = other.sizeinbits; + other.sizeinbits = tmp4; + } + /** + * Reduce the internal buffer to its minimal allowable size (given + * by this.actualsizeinwords). This can free memory. + */ + public void trim() { + this.buffer = Arrays.copyOf(this.buffer, this.actualsizeinwords); + } + + /* + * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput) + */ + @Override +public void writeExternal(ObjectOutput out) throws IOException { + serialize(out); + } + + /** + * Returns a new compressed bitmap containing the bitwise XOR values of the + * current bitmap with some other bitmap. + * + * The running time is proportional to the sum of the compressed sizes (as + * reported by sizeInBytes()). + * + * If you are not planning on adding to the resulting bitmap, you may call the trim() + * method to reduce memory usage. + * + * @param a + * the other bitmap + * @return the EWAH compressed bitmap + */ + @Override +public EWAHCompressedBitmap32 xor(final EWAHCompressedBitmap32 a) { + final EWAHCompressedBitmap32 container = new EWAHCompressedBitmap32(); + container.reserve(this.actualsizeinwords + a.actualsizeinwords); + xorToContainer(a, container); + return container; + } + + /** + * Computes a new compressed bitmap containing the bitwise XOR values of the + * current bitmap with some other bitmap. + * + * The running time is proportional to the sum of the compressed sizes (as + * reported by sizeInBytes()). + * + * @param a + * the other bitmap + * @param container + * where we store the result + */ + public void xorToContainer(final EWAHCompressedBitmap32 a, + final BitmapStorage32 container) { + final EWAHIterator32 i = a.getEWAHIterator(); + final EWAHIterator32 j = getEWAHIterator(); + final IteratingBufferedRunningLengthWord32 rlwi = new IteratingBufferedRunningLengthWord32(i); + final IteratingBufferedRunningLengthWord32 rlwj = new IteratingBufferedRunningLengthWord32(j); + while ((rlwi.size()>0) && (rlwj.size()>0)) { + while ((rlwi.getRunningLength() > 0) || (rlwj.getRunningLength() > 0)) { + final boolean i_is_prey = rlwi.getRunningLength() < rlwj + .getRunningLength(); + final IteratingBufferedRunningLengthWord32 prey = i_is_prey ? rlwi : rlwj; + final IteratingBufferedRunningLengthWord32 predator = i_is_prey ? rlwj + : rlwi; + if (predator.getRunningBit() == false) { + int index = prey.discharge(container, predator.getRunningLength()); + container.addStreamOfEmptyWords(false, predator.getRunningLength() + - index); + predator.discardFirstWords(predator.getRunningLength()); + } else { + int index = prey.dischargeNegated(container, predator.getRunningLength()); + container.addStreamOfEmptyWords(true, predator.getRunningLength() + - index); + predator.discardFirstWords(predator.getRunningLength()); + } + } + final int nbre_literal = Math.min(rlwi.getNumberOfLiteralWords(), + rlwj.getNumberOfLiteralWords()); + if (nbre_literal > 0) { + for (int k = 0; k < nbre_literal; ++k) + container.add(rlwi.getLiteralWordAt(k) ^ rlwj.getLiteralWordAt(k)); + rlwi.discardFirstWords(nbre_literal); + rlwj.discardFirstWords(nbre_literal); + } + } + final boolean i_remains = rlwi.size()>0; + final IteratingBufferedRunningLengthWord32 remaining = i_remains ? rlwi : rlwj; + remaining.discharge(container); + container.setSizeInBits(Math.max(sizeInBits(), a.sizeInBits())); + } + + /** + * Returns the cardinality of the result of a bitwise XOR of the values of the + * current bitmap with some other bitmap. Avoids needing to allocate an + * intermediate bitmap to hold the result of the OR. + * + * @param a + * the other bitmap + * @return the cardinality + */ + public int xorCardinality(final EWAHCompressedBitmap32 a) { + final BitCounter32 counter = new BitCounter32(); + xorToContainer(a, counter); + return counter.getCount(); + } + + /** + * For internal use. Computes the bitwise and of the provided bitmaps and + * stores the result in the container. + * + * @param container + * where the result is stored + * @param bitmaps + * bitmaps to AND + */ + public static void andWithContainer(final BitmapStorage32 container, + final EWAHCompressedBitmap32... bitmaps) { + if(bitmaps.length == 1) throw new IllegalArgumentException("Need at least one bitmap"); + if(bitmaps.length == 2) { + bitmaps[0].andToContainer(bitmaps[1],container); + return; + } + EWAHCompressedBitmap32 answer = new EWAHCompressedBitmap32(); + EWAHCompressedBitmap32 tmp = new EWAHCompressedBitmap32(); + bitmaps[0].andToContainer(bitmaps[1], answer); + for(int k = 2; k < bitmaps.length - 1; ++k) { + answer.andToContainer(bitmaps[k], tmp); + tmp.swap(answer); + tmp.clear(); + } + answer.andToContainer(bitmaps[bitmaps.length - 1], container); + } + + /** + * Returns a new compressed bitmap containing the bitwise AND values of the + * provided bitmaps. + * + * It may or may not be faster than doing the aggregation two-by-two (A.and(B).and(C)). + * + * If only one bitmap is provided, it is returned as is. + * + * If you are not planning on adding to the resulting bitmap, you may call the trim() + * method to reduce memory usage. + * + * @param bitmaps + * bitmaps to AND together + * @return result of the AND + */ + public static EWAHCompressedBitmap32 and( + final EWAHCompressedBitmap32... bitmaps) { + if(bitmaps.length == 1) return bitmaps[0]; + if(bitmaps.length == 2) return bitmaps[0].and(bitmaps[1]); + EWAHCompressedBitmap32 answer = new EWAHCompressedBitmap32(); + EWAHCompressedBitmap32 tmp = new EWAHCompressedBitmap32(); + bitmaps[0].andToContainer(bitmaps[1], answer); + for(int k = 2; k < bitmaps.length; ++k) { + answer.andToContainer(bitmaps[k], tmp); + tmp.swap(answer); + tmp.clear(); + } + return answer; + } + + /** + * Returns the cardinality of the result of a bitwise AND of the values of the + * provided bitmaps. Avoids needing to allocate an intermediate bitmap to hold + * the result of the AND. + * + * @param bitmaps + * bitmaps to AND + * @return the cardinality + */ + public static int andCardinality(final EWAHCompressedBitmap32... bitmaps) { + if(bitmaps.length == 1) return bitmaps[0].cardinality(); + final BitCounter32 counter = new BitCounter32(); + andWithContainer(counter, bitmaps); + return counter.getCount(); + } + + + /** + * Return a bitmap with the bit set to true at the given + * positions. The positions should be given in sorted order. + * + * (This is a convenience method.) + * + * @since 0.4.5 + * @param setbits list of set bit positions + * @return the bitmap + */ + public static EWAHCompressedBitmap32 bitmapOf(int ... setbits) { + EWAHCompressedBitmap32 a = new EWAHCompressedBitmap32(); + for (int k : setbits) + a.set(k); + return a; + } + + + + + /** + * For internal use. This simply adds a stream of words made of zeroes so that + * we pad to the desired size. + * + * @param storage + * bitmap to extend + * @param currentSize + * current size (in bits) + * @param newSize + * new desired size (in bits) + */ + private static void extendEmptyBits(final BitmapStorage32 storage, + final int currentSize, final int newSize) { + final int currentLeftover = currentSize % wordinbits; + final int finalLeftover = newSize % wordinbits; + storage.addStreamOfEmptyWords(false, (newSize / wordinbits) - currentSize + / wordinbits + (finalLeftover != 0 ? 1 : 0) + + (currentLeftover != 0 ? -1 : 0)); + } + + /** + * For internal use. Computes the bitwise or of the provided bitmaps and + * stores the result in the container. + * @param container where store the result + * @param bitmaps to be aggregated + */ + public static void orWithContainer(final BitmapStorage32 container, + final EWAHCompressedBitmap32... bitmaps) { + if (bitmaps.length < 2) + throw new IllegalArgumentException("You should provide at least two bitmaps, provided "+bitmaps.length); + int size = 0; + int sinbits = 0; + for (EWAHCompressedBitmap32 b : bitmaps) { + size += b.sizeInBytes(); + if (sinbits < b.sizeInBits()) + sinbits = b.sizeInBits(); + } + if (size * 8 > sinbits) { + FastAggregation32.bufferedorWithContainer(container, 65536, bitmaps); + } else { + FastAggregation32.orToContainer(container, bitmaps); + } + } + + /** + * For internal use. Computes the bitwise xor of the provided bitmaps and + * stores the result in the container. + * @param container where store the result + * @param bitmaps to be aggregated + */ + public static void xorWithContainer(final BitmapStorage32 container, + final EWAHCompressedBitmap32... bitmaps) { + if (bitmaps.length < 2) + throw new IllegalArgumentException("You should provide at least two bitmaps, provided "+bitmaps.length); + int size = 0; + int sinbits = 0; + for (EWAHCompressedBitmap32 b : bitmaps) { + size += b.sizeInBytes(); + if (sinbits < b.sizeInBits()) + sinbits = b.sizeInBits(); + } + if (size * 8 > sinbits) { + FastAggregation32.bufferedxorWithContainer(container, 65536, bitmaps); + } else { + FastAggregation32.xorToContainer(container, bitmaps); + } + } + + /** + * Returns a new compressed bitmap containing the bitwise OR values of the + * provided bitmaps. This is typically faster than doing the aggregation + * two-by-two (A.or(B).or(C).or(D)). + * + * If only one bitmap is provided, it is returned as is. + * + * If you are not planning on adding to the resulting bitmap, you may call the trim() + * method to reduce memory usage. + * + * @param bitmaps + * bitmaps to OR together + * @return result of the OR + */ + public static EWAHCompressedBitmap32 or( + final EWAHCompressedBitmap32... bitmaps) { + if(bitmaps.length == 1) return bitmaps[0]; + final EWAHCompressedBitmap32 container = new EWAHCompressedBitmap32(); + int largestSize = 0; + for (EWAHCompressedBitmap32 bitmap : bitmaps) { + largestSize = Math.max(bitmap.actualsizeinwords, largestSize); + } + container.reserve((int) (largestSize * 1.5)); + orWithContainer(container, bitmaps); + return container; + } + + + /** + * Returns a new compressed bitmap containing the bitwise XOR values of the + * provided bitmaps. This is typically faster than doing the aggregation + * two-by-two (A.xor(B).xor(C).xor(D)). + * + * If only one bitmap is provided, it is returned as is. + * + * If you are not planning on adding to the resulting bitmap, you may call the trim() + * method to reduce memory usage. + * + * @param bitmaps + * bitmaps to XOR together + * @return result of the XOR + */ + public static EWAHCompressedBitmap32 xor( + final EWAHCompressedBitmap32... bitmaps) { + if(bitmaps.length == 1) return bitmaps[0]; + final EWAHCompressedBitmap32 container = new EWAHCompressedBitmap32(); + int largestSize = 0; + for (EWAHCompressedBitmap32 bitmap : bitmaps) { + largestSize = Math.max(bitmap.actualsizeinwords, largestSize); + } + container.reserve((int) (largestSize * 1.5)); + xorWithContainer(container, bitmaps); + return container; + } + + /** + * Returns the cardinality of the result of a bitwise OR of the values of the + * provided bitmaps. Avoids needing to allocate an intermediate bitmap to hold + * the result of the OR. + * + * @param bitmaps + * bitmaps to OR + * @return the cardinality + */ + public static int orCardinality(final EWAHCompressedBitmap32... bitmaps) { + if(bitmaps.length == 1) return bitmaps[0].cardinality(); + final BitCounter32 counter = new BitCounter32(); + orWithContainer(counter, bitmaps); + return counter.getCount(); + } + + /** The actual size in words. */ + int actualsizeinwords = 1; + + /** The buffer (array of 32-bit words) */ + int buffer[] = null; + + /** The current (last) running length word. */ + RunningLengthWord32 rlw = null; + + /** sizeinbits: number of bits in the (uncompressed) bitmap. */ + int sizeinbits = 0; + + /** + * The Constant defaultbuffersize: default memory allocation when the object + * is constructed. + */ + static final int defaultbuffersize = 4; + + /** optimization option **/ + public static final boolean usetrailingzeros = true; + + /** whether we adjust after some aggregation by adding in zeroes **/ + public static final boolean adjustContainerSizeWhenAggregating = true; + + /** The Constant wordinbits represents the number of bits in a int. */ + public static final int wordinbits = 32; + +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah32/EWAHIterator32.java b/fine-jgit/src/com/fr/third/googlecode/javaewah32/EWAHIterator32.java new file mode 100644 index 000000000..dee08341d --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah32/EWAHIterator32.java @@ -0,0 +1,98 @@ +package com.fr.third.googlecode.javaewah32; + + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ + +/** + * The class EWAHIterator represents a special type of + * efficient iterator iterating over (uncompressed) words of bits. + * + * @author Daniel Lemire + * @since 0.5.0 + * + */ +public final class EWAHIterator32 implements Cloneable { + + /** + * Instantiates a new eWAH iterator. + * + * @param a the array of words + * @param sizeinwords the number of words that are significant in the array of words + */ + public EWAHIterator32(final EWAHCompressedBitmap32 a, final int sizeinwords) { + this.rlw = new RunningLengthWord32(a, 0); + this.size = sizeinwords; + this.pointer = 0; + } + + /** + * Allow expert developers to instantiate an EWAHIterator. + * + * @param bitmap we want to iterate over + * @return an iterator + */ + public static EWAHIterator32 getEWAHIterator(EWAHCompressedBitmap32 bitmap) { + return bitmap.getEWAHIterator(); + } + + /** + * Access to the array of words + * + * @return the int[] + */ + public int[] buffer() { + return this.rlw.parent.buffer; + } + + /** + * Position of the literal words represented by this running length word. + * + * @return the int + */ + public int literalWords() { + return this.pointer - this.rlw.getNumberOfLiteralWords(); + } + + /** + * Checks for next. + * + * @return true, if successful + */ + public boolean hasNext() { + return this.pointer < this.size; + } + + /** + * Next running length word. + * + * @return the running length word + */ + public RunningLengthWord32 next() { + this.rlw.position = this.pointer; + this.pointer += this.rlw.getNumberOfLiteralWords() + 1; + return this.rlw; + } + + @Override + public EWAHIterator32 clone() throws CloneNotSupportedException { + EWAHIterator32 ans = (EWAHIterator32) super.clone(); + ans.rlw = this.rlw.clone(); + ans.size = this.size; + ans.pointer = this.pointer; + return ans; + } + + /** The pointer represent the location of the current running length + * word in the array of words (embedded in the rlw attribute). */ + int pointer; + + /** The current running length word. */ + RunningLengthWord32 rlw; + + /** The size in words. */ + int size; + +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah32/FastAggregation32.java b/fine-jgit/src/com/fr/third/googlecode/javaewah32/FastAggregation32.java new file mode 100644 index 000000000..7ecd45fcd --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah32/FastAggregation32.java @@ -0,0 +1,377 @@ +package com.fr.third.googlecode.javaewah32; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.PriorityQueue; + + +/** + * Fast algorithms to aggregate many bitmaps. These algorithms are just given as + * reference. They may not be faster than the corresponding methods in the + * EWAHCompressedBitmap class. + * + * @author Daniel Lemire + * + */ +public class FastAggregation32 { + + /** + * Compute the and aggregate using a temporary uncompressed bitmap. + * @param bitmaps the source bitmaps + * @param bufsize buffer size used during the computation in 64-bit words (per input bitmap) + * @return the or aggregate. + */ + public static EWAHCompressedBitmap32 bufferedand(final int bufsize, + final EWAHCompressedBitmap32... bitmaps) { + EWAHCompressedBitmap32 answer = new EWAHCompressedBitmap32(); + bufferedandWithContainer(answer,bufsize, bitmaps); + return answer; + } + /** + * Compute the and aggregate using a temporary uncompressed bitmap. + * + * @param container where the aggregate is written + * @param bufsize buffer size used during the computation in 64-bit words (per input bitmap) + * @param bitmaps the source bitmaps + */ + public static void bufferedandWithContainer(final BitmapStorage32 container,final int bufsize, + final EWAHCompressedBitmap32... bitmaps) { + + java.util.LinkedList al = new java.util.LinkedList(); + for (EWAHCompressedBitmap32 bitmap : bitmaps) { + al.add(new IteratingBufferedRunningLengthWord32(bitmap)); + } + int[] hardbitmap = new int[bufsize*bitmaps.length]; + + for(IteratingRLW32 i : al) + if (i.size() == 0) { + al.clear(); + break; + } + + while (!al.isEmpty()) { + Arrays.fill(hardbitmap, ~0); + int effective = Integer.MAX_VALUE; + for(IteratingRLW32 i : al) { + int eff = IteratorAggregation32.inplaceand(hardbitmap, i); + if (eff < effective) + effective = eff; + } + for (int k = 0; k < effective; ++k) + container.add(hardbitmap[k]); + for(IteratingRLW32 i : al) + if (i.size() == 0) { + al.clear(); + break; + } + } + } + + /** + * Compute the or aggregate using a temporary uncompressed bitmap. + * @param bitmaps the source bitmaps + * @param bufsize buffer size used during the computation in 64-bit words + * @return the or aggregate. + */ + public static EWAHCompressedBitmap32 bufferedor(final int bufsize, + final EWAHCompressedBitmap32... bitmaps) { + EWAHCompressedBitmap32 answer = new EWAHCompressedBitmap32(); + bufferedorWithContainer(answer, bufsize, bitmaps); + return answer; + } + + /** + * Compute the or aggregate using a temporary uncompressed bitmap. + * + * @param container where the aggregate is written + * @param bufsize buffer size used during the computation in 64-bit words + * @param bitmaps the source bitmaps + */ + public static void bufferedorWithContainer(final BitmapStorage32 container,final int bufsize, + final EWAHCompressedBitmap32... bitmaps) { + int range = 0; + EWAHCompressedBitmap32[] sbitmaps = bitmaps.clone(); + Arrays.sort(sbitmaps, new Comparator() { + @Override + public int compare(EWAHCompressedBitmap32 a, EWAHCompressedBitmap32 b) { + return b.sizeinbits - a.sizeinbits; + } + }); + + java.util.ArrayList al = new java.util.ArrayList(); + for (EWAHCompressedBitmap32 bitmap : sbitmaps) { + if (bitmap.sizeinbits > range) + range = bitmap.sizeinbits; + al.add(new IteratingBufferedRunningLengthWord32(bitmap)); + } + int[] hardbitmap = new int[bufsize]; + int maxr = al.size(); + while (maxr > 0) { + int effective = 0; + for (int k = 0; k < maxr; ++k) { + if (al.get(k).size() > 0) { + int eff = IteratorAggregation32.inplaceor(hardbitmap, al.get(k)); + if (eff > effective) + effective = eff; + } else + maxr = k; + } + for (int k = 0; k < effective; ++k) + container.add(hardbitmap[k]); + Arrays.fill(hardbitmap, 0); + + } + container.setSizeInBits(range); + } + + /** + * Compute the xor aggregate using a temporary uncompressed bitmap. + * @param bitmaps the source bitmaps + * @param bufsize buffer size used during the computation in 64-bit words + * @return the xor aggregate. + */ + public static EWAHCompressedBitmap32 bufferedxor(final int bufsize, + final EWAHCompressedBitmap32... bitmaps) { + EWAHCompressedBitmap32 answer = new EWAHCompressedBitmap32(); + bufferedxorWithContainer(answer, bufsize, bitmaps); + return answer; + } + + + /** + * Compute the xor aggregate using a temporary uncompressed bitmap. + * + * @param container where the aggregate is written + * @param bufsize buffer size used during the computation in 64-bit words + * @param bitmaps the source bitmaps + */ + public static void bufferedxorWithContainer(final BitmapStorage32 container,final int bufsize, + final EWAHCompressedBitmap32... bitmaps) { + int range = 0; + EWAHCompressedBitmap32[] sbitmaps = bitmaps.clone(); + Arrays.sort(sbitmaps, new Comparator() { + @Override + public int compare(EWAHCompressedBitmap32 a, EWAHCompressedBitmap32 b) { + return b.sizeinbits - a.sizeinbits; + } + }); + + java.util.ArrayList al = new java.util.ArrayList(); + for (EWAHCompressedBitmap32 bitmap : sbitmaps) { + if (bitmap.sizeinbits > range) + range = bitmap.sizeinbits; + al.add(new IteratingBufferedRunningLengthWord32(bitmap)); + } + int[] hardbitmap = new int[bufsize]; + int maxr = al.size(); + while (maxr > 0) { + int effective = 0; + for (int k = 0; k < maxr; ++k) { + if (al.get(k).size() > 0) { + int eff = IteratorAggregation32.inplacexor(hardbitmap, al.get(k)); + if (eff > effective) + effective = eff; + } else + maxr = k; + } + for (int k = 0; k < effective; ++k) + container.add(hardbitmap[k]); + Arrays.fill(hardbitmap, 0); + } + container.setSizeInBits(range); + } + + /** + * Uses a priority queue to compute the or aggregate. + * @param container where we write the result + * @param bitmaps to be aggregated + */ + public static void orToContainer(final BitmapStorage32 container, + final EWAHCompressedBitmap32 ... bitmaps) { + if(bitmaps.length < 2) throw new IllegalArgumentException("We need at least two bitmaps"); + PriorityQueue pq = new PriorityQueue(bitmaps.length, + new Comparator() { + @Override + public int compare(EWAHCompressedBitmap32 a, EWAHCompressedBitmap32 b) { + return a.sizeInBytes() - b.sizeInBytes(); + } + }); + for (EWAHCompressedBitmap32 x : bitmaps) { + pq.add(x); + } + while (pq.size() > 2) { + EWAHCompressedBitmap32 x1 = pq.poll(); + EWAHCompressedBitmap32 x2 = pq.poll(); + pq.add(x1.or(x2)); + } + pq.poll().orToContainer(pq.poll(), container); + } + + + /** + * Uses a priority queue to compute the xor aggregate. + * @param container where we write the result + * @param bitmaps to be aggregated + */ + public static void xorToContainer(final BitmapStorage32 container, + final EWAHCompressedBitmap32 ... bitmaps) { + if(bitmaps.length < 2) throw new IllegalArgumentException("We need at least two bitmaps"); + PriorityQueue pq = new PriorityQueue(bitmaps.length, + new Comparator() { + @Override + public int compare(EWAHCompressedBitmap32 a, EWAHCompressedBitmap32 b) { + return a.sizeInBytes() - b.sizeInBytes(); + } + }); + for (EWAHCompressedBitmap32 x : bitmaps) { + pq.add(x); + } + while (pq.size() > 2) { + EWAHCompressedBitmap32 x1 = pq.poll(); + EWAHCompressedBitmap32 x2 = pq.poll(); + pq.add(x1.xor(x2)); + } + pq.poll().xorToContainer(pq.poll(), container); + } + + /** + * For internal use. Computes the bitwise or of the provided bitmaps and + * stores the result in the container. (This used to be the default.) + * + * @deprecated use EWAHCompressedBitmap32.or instead + * @since 0.4.0 + * @param container where store the result + * @param bitmaps to be aggregated + */ + @Deprecated + public static void legacy_orWithContainer(final BitmapStorage32 container, + final EWAHCompressedBitmap32... bitmaps) { + if (bitmaps.length == 2) { + // should be more efficient + bitmaps[0].orToContainer(bitmaps[1], container); + return; + } + + // Sort the bitmaps in descending order by sizeinbits. We will exhaust the + // sorted bitmaps from right to left. + final EWAHCompressedBitmap32[] sortedBitmaps = bitmaps.clone(); + Arrays.sort(sortedBitmaps, new Comparator() { + @Override + public int compare(EWAHCompressedBitmap32 a, EWAHCompressedBitmap32 b) { + return a.sizeinbits < b.sizeinbits ? 1 + : a.sizeinbits == b.sizeinbits ? 0 : -1; + } + }); + + final IteratingBufferedRunningLengthWord32[] rlws = new IteratingBufferedRunningLengthWord32[bitmaps.length]; + int maxAvailablePos = 0; + for (EWAHCompressedBitmap32 bitmap : sortedBitmaps) { + EWAHIterator32 iterator = bitmap.getEWAHIterator(); + if (iterator.hasNext()) { + rlws[maxAvailablePos++] = new IteratingBufferedRunningLengthWord32( + iterator); + } + } + + if (maxAvailablePos == 0) { // this never happens... + container.setSizeInBits(0); + return; + } + + int maxSize = sortedBitmaps[0].sizeinbits; + + while (true) { + int maxOneRl = 0; + int minZeroRl = Integer.MAX_VALUE; + int minSize = Integer.MAX_VALUE; + int numEmptyRl = 0; + for (int i = 0; i < maxAvailablePos; i++) { + IteratingBufferedRunningLengthWord32 rlw = rlws[i]; + int size = rlw.size(); + if (size == 0) { + maxAvailablePos = i; + break; + } + minSize = Math.min(minSize, size); + + if (rlw.getRunningBit()) { + int rl = rlw.getRunningLength(); + maxOneRl = Math.max(maxOneRl, rl); + minZeroRl = 0; + if (rl == 0 && size > 0) { + numEmptyRl++; + } + } else { + int rl = rlw.getRunningLength(); + minZeroRl = Math.min(minZeroRl, rl); + if (rl == 0 && size > 0) { + numEmptyRl++; + } + } + } + + if (maxAvailablePos == 0) { + break; + } else if (maxAvailablePos == 1) { + // only one bitmap is left so just write the rest of it out + rlws[0].discharge(container); + break; + } + + if (maxOneRl > 0) { + container.addStreamOfEmptyWords(true, maxOneRl); + for (int i = 0; i < maxAvailablePos; i++) { + IteratingBufferedRunningLengthWord32 rlw = rlws[i]; + rlw.discardFirstWords(maxOneRl); + } + } else if (minZeroRl > 0) { + container.addStreamOfEmptyWords(false, minZeroRl); + for (int i = 0; i < maxAvailablePos; i++) { + IteratingBufferedRunningLengthWord32 rlw = rlws[i]; + rlw.discardFirstWords(minZeroRl); + } + } else { + int index = 0; + + if (numEmptyRl == 1) { + // if one rlw has literal words to process and the rest have a run of + // 0's we can write them out here + IteratingBufferedRunningLengthWord32 emptyRl = null; + int minNonEmptyRl = Integer.MAX_VALUE; + for (int i = 0; i < maxAvailablePos; i++) { + IteratingBufferedRunningLengthWord32 rlw = rlws[i]; + int rl = rlw.getRunningLength(); + if (rl == 0) { + assert emptyRl == null; + emptyRl = rlw; + } else { + minNonEmptyRl = Math.min(minNonEmptyRl, rl); + } + } + int wordsToWrite = minNonEmptyRl > minSize ? minSize : minNonEmptyRl; + if (emptyRl != null) + emptyRl.writeLiteralWords(wordsToWrite, container); + index += wordsToWrite; + } + + while (index < minSize) { + int word = 0; + for (int i = 0; i < maxAvailablePos; i++) { + IteratingBufferedRunningLengthWord32 rlw = rlws[i]; + if (rlw.getRunningLength() <= index) { + word |= rlw.getLiteralWordAt(index - rlw.getRunningLength()); + } + } + container.add(word); + index++; + } + for (int i = 0; i < maxAvailablePos; i++) { + IteratingBufferedRunningLengthWord32 rlw = rlws[i]; + rlw.discardFirstWords(minSize); + } + } + } + container.setSizeInBits(maxSize); + } + +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah32/IntIteratorImpl32.java b/fine-jgit/src/com/fr/third/googlecode/javaewah32/IntIteratorImpl32.java new file mode 100644 index 000000000..041b5d8ff --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah32/IntIteratorImpl32.java @@ -0,0 +1,90 @@ +package com.fr.third.googlecode.javaewah32; + +/* + * Copyright 2012, Google Inc. + * Licensed under the Apache License, Version 2.0. + */ + +import static com.fr.third.googlecode.javaewah32.EWAHCompressedBitmap32.wordinbits; + +import com.fr.third.googlecode.javaewah.IntIterator; + +/** + * The IntIteratorImpl32 is the 32 bit implementation of the IntIterator + * interface, which efficiently returns the stream of integers represented by an + * EWAHIterator32. + * + * @author Colby Ranger + * @since 0.5.6 + */ +final class IntIteratorImpl32 implements IntIterator { + + private final EWAHIterator32 ewahIter; + private final int[] ewahBuffer; + private int position; + private int runningLength; + private int word; + private int wordPosition; + private int wordLength; + private int literalPosition; + private boolean hasnext; + + IntIteratorImpl32(EWAHIterator32 ewahIter) { + this.ewahIter = ewahIter; + this.ewahBuffer = ewahIter.buffer(); + this.hasnext = this.moveToNext(); + } + + public final boolean moveToNext() { + while (!runningHasNext() && !literalHasNext()) { + if (!this.ewahIter.hasNext()) { + return false; + } + setRunningLengthWord(this.ewahIter.next()); + } + return true; + } + + @Override + public final boolean hasNext() { + return this.hasnext; + } + + @Override + public final int next() { + final int answer; + if (runningHasNext()) { + answer = this.position++; + } else { + final int bit = Long.numberOfTrailingZeros(this.word); + this.word ^= (1l << bit); + answer = this.literalPosition + bit; + } + this.hasnext = this.moveToNext(); + return answer; + } + + private final void setRunningLengthWord(RunningLengthWord32 rlw) { + this.runningLength = wordinbits * rlw.getRunningLength() + + this.position; + if (!rlw.getRunningBit()) { + this.position = this.runningLength; + } + + this.wordPosition = this.ewahIter.literalWords(); + this.wordLength = this.wordPosition + rlw.getNumberOfLiteralWords(); + } + + private final boolean runningHasNext() { + return this.position < this.runningLength; + } + + private final boolean literalHasNext() { + while (this.word == 0 && this.wordPosition < this.wordLength) { + this.word = this.ewahBuffer[this.wordPosition++]; + this.literalPosition = this.position; + this.position += wordinbits; + } + return this.word != 0; + } +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah32/IntIteratorOverIteratingRLW32.java b/fine-jgit/src/com/fr/third/googlecode/javaewah32/IntIteratorOverIteratingRLW32.java new file mode 100644 index 000000000..6ad8c47a2 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah32/IntIteratorOverIteratingRLW32.java @@ -0,0 +1,91 @@ +package com.fr.third.googlecode.javaewah32; + +import static com.fr.third.googlecode.javaewah.EWAHCompressedBitmap.wordinbits; + +import com.fr.third.googlecode.javaewah.IntIterator; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ +/** + * Implementation of an IntIterator over an IteratingRLW. + * + * + */ +public class IntIteratorOverIteratingRLW32 implements IntIterator { + IteratingRLW32 parent; + private int position; + private int runningLength; + private int word; + private int wordPosition; + private int wordLength; + private int literalPosition; + private boolean hasnext; + + /** + * @param p iterator we wish to iterate over + */ + public IntIteratorOverIteratingRLW32(final IteratingRLW32 p) { + this.parent = p; + this.position = 0; + setupForCurrentRunningLengthWord(); + this.hasnext = moveToNext(); + } + + /** + * @return whether we could find another set bit; don't move if there is an unprocessed value + */ + private final boolean moveToNext() { + while (!runningHasNext() && !literalHasNext()) { + if (this.parent.next()) + setupForCurrentRunningLengthWord(); + else return false; + } + return true; + } + + @Override + public boolean hasNext() { + return this.hasnext; + } + + @Override + public final int next() { + final int answer; + if (runningHasNext()) { + answer = this.position++; + } else { + final int bit = Long.numberOfTrailingZeros(this.word); + this.word ^= (1l << bit); + answer = this.literalPosition + bit; + } + this.hasnext = this.moveToNext(); + return answer; + } + + private final void setupForCurrentRunningLengthWord() { + this.runningLength = wordinbits * this.parent.getRunningLength() + + this.position; + + if (!this.parent.getRunningBit()) { + this.position = this.runningLength; + } + this.wordPosition = 0; + this.wordLength = this.parent.getNumberOfLiteralWords(); + } + + private final boolean runningHasNext() { + return this.position < this.runningLength; + } + + private final boolean literalHasNext() { + while (this.word == 0 && this.wordPosition < this.wordLength) { + this.word = this.parent.getLiteralWordAt(this.wordPosition++); + this.literalPosition = this.position; + this.position += wordinbits; + } + return this.word != 0; + } +} + diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah32/IteratingBufferedRunningLengthWord32.java b/fine-jgit/src/com/fr/third/googlecode/javaewah32/IteratingBufferedRunningLengthWord32.java new file mode 100644 index 000000000..f09906274 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah32/IteratingBufferedRunningLengthWord32.java @@ -0,0 +1,274 @@ +package com.fr.third.googlecode.javaewah32; + + + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ +/** + * Mostly for internal use. Similar to BufferedRunningLengthWord32, but automatically + * advances to the next BufferedRunningLengthWord32 as words are discarded. + * + * @since 0.5.0 + * @author Daniel Lemire and David McIntosh + */ +public final class IteratingBufferedRunningLengthWord32 implements IteratingRLW32, Cloneable { + /** + * Instantiates a new iterating buffered running length word. + * + * @param iterator iterator + */ + public IteratingBufferedRunningLengthWord32(final EWAHIterator32 iterator) { + this.iterator = iterator; + this.brlw = new BufferedRunningLengthWord32(this.iterator.next()); + this.literalWordStartPosition = this.iterator.literalWords() + this.brlw.literalwordoffset; + this.buffer = this.iterator.buffer(); + } + + + /** + * Instantiates a new iterating buffered running length word. + * @param bitmap over which we want to iterate + * + */ + public IteratingBufferedRunningLengthWord32(final EWAHCompressedBitmap32 bitmap) { + this(EWAHIterator32.getEWAHIterator(bitmap)); + } + + + /** + * Discard first words, iterating to the next running length word if needed. + * + * @param x the x + */ + @Override +public void discardFirstWords(int x) { + + while (x > 0) { + if (this.brlw.RunningLength > x) { + this.brlw.RunningLength -= x; + return; + } + x -= this.brlw.RunningLength; + this.brlw.RunningLength = 0; + int toDiscard = x > this.brlw.NumberOfLiteralWords ? this.brlw.NumberOfLiteralWords : x; + + this.literalWordStartPosition += toDiscard; + this.brlw.NumberOfLiteralWords -= toDiscard; + x -= toDiscard; + if ((x > 0) || (this.brlw.size() == 0)) { + if (!this.iterator.hasNext()) { + break; + } + this.brlw.reset(this.iterator.next()); + this.literalWordStartPosition = this.iterator.literalWords(); // + this.brlw.literalwordoffset == 0; + } + } + } + /** + * Write out up to max words, returns how many were written + * @param container target for writes + * @param max maximal number of writes + * @return how many written + */ + public int discharge(BitmapStorage32 container, int max) { + int index = 0; + while ((index < max) && (size() > 0)) { + // first run + int pl = getRunningLength(); + if (index + pl > max) { + pl = max - index; + } + container.addStreamOfEmptyWords(getRunningBit(), pl); + index += pl; + int pd = getNumberOfLiteralWords(); + if (pd + index > max) { + pd = max - index; + } + writeLiteralWords(pd, container); + discardFirstWords(pl+pd); + index += pd; + } + return index; + } + + /** + * Write out up to max words (negated), returns how many were written + * @param container target for writes + * @param max maximal number of writes + * @return how many written + */ + public int dischargeNegated(BitmapStorage32 container, int max) { + int index = 0; + while ((index < max) && (size() > 0)) { + // first run + int pl = getRunningLength(); + if (index + pl > max) { + pl = max - index; + } + container.addStreamOfEmptyWords(!getRunningBit(), pl); + index += pl; + int pd = getNumberOfLiteralWords(); + if (pd + index > max) { + pd = max - index; + } + writeNegatedLiteralWords(pd, container); + discardFirstWords(pl+pd); + index += pd; + } + return index; + } + + /** + * Move to the next RunningLengthWord + * @return whether the move was possible + */ + @Override +public boolean next() { + if (!this.iterator.hasNext()) { + this.brlw.NumberOfLiteralWords = 0; + this.brlw.RunningLength = 0; + return false; + } + this.brlw.reset(this.iterator.next()); + this.literalWordStartPosition = this.iterator.literalWords(); // + this.brlw.literalwordoffset ==0 + return true; + } + + /** + * Write out the remain words, transforming them to zeroes. + * @param container target for writes + */ + public void dischargeAsEmpty(BitmapStorage32 container) { + while(size()>0) { + container.addStreamOfEmptyWords(false, size()); + discardFirstWords(size()); + } + } + + /** + * Write out the remaining words + * @param container target for writes + */ + public void discharge(BitmapStorage32 container) { + // fix the offset + this.brlw.literalwordoffset = this.literalWordStartPosition - this.iterator.literalWords(); + discharge(this.brlw, this.iterator, container); + } + + /** + * Get the nth literal word for the current running length word + * @param index zero based index + * @return the literal word + */ + @Override +public int getLiteralWordAt(int index) { + return this.buffer[this.literalWordStartPosition + index]; + } + + /** + * Gets the number of literal words for the current running length word. + * + * @return the number of literal words + */ + @Override +public int getNumberOfLiteralWords() { + return this.brlw.NumberOfLiteralWords; + } + + /** + * Gets the running bit. + * + * @return the running bit + */ + @Override +public boolean getRunningBit() { + return this.brlw.RunningBit; + } + + /** + * Gets the running length. + * + * @return the running length + */ + @Override +public int getRunningLength() { + return this.brlw.RunningLength; + } + + /** + * Size in uncompressed words of the current running length word. + * + * @return the int + */ + @Override +public int size() { + return this.brlw.size(); + } + + /** + * write the first N literal words to the target bitmap. Does not discard the words or perform iteration. + * @param numWords number of words to be written + * @param container where we write the data + */ + public void writeLiteralWords(int numWords, BitmapStorage32 container) { + container.addStreamOfLiteralWords(this.buffer, this.literalWordStartPosition, numWords); + } + + + /** + * write the first N literal words (negated) to the target bitmap. Does not discard the words or perform iteration. + * @param numWords number of words to be written + * @param container where we write the data + */ + public void writeNegatedLiteralWords(int numWords, BitmapStorage32 container) { + container.addStreamOfNegatedLiteralWords(this.buffer, this.literalWordStartPosition, numWords); + } + + + /** + * For internal use. (One could use the non-static discharge method instead, + * but we expect them to be slower.) + * + * @param initialWord + * the initial word + * @param iterator + * the iterator + * @param container + * the container + */ + protected static void discharge( + final BufferedRunningLengthWord32 initialWord, + final EWAHIterator32 iterator, final BitmapStorage32 container) { + BufferedRunningLengthWord32 runningLengthWord = initialWord; + for (;;) { + final int runningLength = runningLengthWord.getRunningLength(); + container.addStreamOfEmptyWords(runningLengthWord.getRunningBit(), + runningLength); + container.addStreamOfLiteralWords(iterator.buffer(), iterator.literalWords() + + runningLengthWord.literalwordoffset, + runningLengthWord.getNumberOfLiteralWords()); + if (!iterator.hasNext()) + break; + runningLengthWord = new BufferedRunningLengthWord32(iterator.next()); + } + } + + + + @Override +public IteratingBufferedRunningLengthWord32 clone() throws CloneNotSupportedException { + IteratingBufferedRunningLengthWord32 answer = (IteratingBufferedRunningLengthWord32) super.clone(); + answer.brlw = this.brlw.clone(); + answer.buffer = this.buffer; + answer.iterator = this.iterator.clone(); + answer.literalWordStartPosition = this.literalWordStartPosition; + return answer; + } + + private BufferedRunningLengthWord32 brlw; + private int[] buffer; + private int literalWordStartPosition; + private EWAHIterator32 iterator; +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah32/IteratingRLW32.java b/fine-jgit/src/com/fr/third/googlecode/javaewah32/IteratingRLW32.java new file mode 100644 index 000000000..1ebeb2f62 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah32/IteratingRLW32.java @@ -0,0 +1,42 @@ +package com.fr.third.googlecode.javaewah32; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ + +/** + * High-level iterator over a compressed bitmap. + * + */ +public interface IteratingRLW32 { + /** + * @return whether there is more + */ + public boolean next() ; + /** + * @param index where the literal word is + * @return the literal word at the given index. + */ + public int getLiteralWordAt(int index); + /** + * @return the number of literal (non-fill) words + */ + public int getNumberOfLiteralWords() ; + /** + * @return the bit used for the fill bits + */ + public boolean getRunningBit() ; + /** + * @return sum of getRunningLength() and getNumberOfLiteralWords() + */ + public int size() ; + /** + * @return length of the run of fill words + */ + public int getRunningLength() ; + /** + * @param x the number of words to discard + */ + public void discardFirstWords(int x); +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah32/IteratorAggregation32.java b/fine-jgit/src/com/fr/third/googlecode/javaewah32/IteratorAggregation32.java new file mode 100644 index 000000000..cfd5a0adc --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah32/IteratorAggregation32.java @@ -0,0 +1,601 @@ +package com.fr.third.googlecode.javaewah32; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedList; + +import com.fr.third.googlecode.javaewah.CloneableIterator; + + + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ + +/** + * Set of helper functions to aggregate bitmaps. + * + */ +public class IteratorAggregation32 { + /** + * @param x iterator to negate + * @return negated version of the iterator + */ + public static IteratingRLW32 not(final IteratingRLW32 x) { + return new IteratingRLW32() { + + @Override + public boolean next() { + return x.next(); + } + + @Override + public int getLiteralWordAt(int index) { + return ~x.getLiteralWordAt(index); + } + + @Override + public int getNumberOfLiteralWords() { + return x.getNumberOfLiteralWords(); + } + + @Override + public boolean getRunningBit() { + return ! x.getRunningBit(); + } + + @Override + public int size() { + return x.size(); + } + + @Override + public int getRunningLength() { + return x.getRunningLength(); + } + + @Override + public void discardFirstWords(int y) { + x.discardFirstWords(y); + } + + }; + } + + /** + * Aggregate the iterators using a bitmap buffer. + * + * @param al iterators to aggregate + * @return and aggregate + */ + public static IteratingRLW32 bufferedand(final IteratingRLW32... al) { + return bufferedand (DEFAULTMAXBUFSIZE,al); + } + + /** + * Aggregate the iterators using a bitmap buffer. + * + * @param al iterators to aggregate + * @param bufsize size of the internal buffer used by the iterator in 64-bit words + * @return and aggregate + */ + public static IteratingRLW32 bufferedand(final int bufsize, final IteratingRLW32... al) { + if (al.length == 0) + throw new IllegalArgumentException("Need at least one iterator"); + if (al.length == 1) + return al[0]; + final LinkedList basell = new LinkedList(); + for (IteratingRLW32 i : al) + basell.add(i); + return new BufferedIterator32(new AndIt(basell,bufsize)); + } + + /** + * Aggregate the iterators using a bitmap buffer. + * + * @param al iterators to aggregate + * @return or aggregate + */ + public static IteratingRLW32 bufferedor(final IteratingRLW32... al) { + return bufferedor(DEFAULTMAXBUFSIZE,al); + } + + /** + * Aggregate the iterators using a bitmap buffer. + * + * @param al iterators to aggregate + * @param bufsize size of the internal buffer used by the iterator in 64-bit words + * @return or aggregate + */ + public static IteratingRLW32 bufferedor(final int bufsize, final IteratingRLW32... al) { + if (al.length == 0) + throw new IllegalArgumentException("Need at least one iterator"); + if (al.length == 1) + return al[0]; + + final LinkedList basell = new LinkedList(); + for (IteratingRLW32 i : al) + basell.add(i); + return new BufferedIterator32(new ORIt(basell,bufsize)); + } + + /** + * Aggregate the iterators using a bitmap buffer. + * + * @param al iterators to aggregate + * @return xor aggregate + */ + public static IteratingRLW32 bufferedxor(final IteratingRLW32... al) { + return bufferedxor (DEFAULTMAXBUFSIZE,al); + } + /** + * Aggregate the iterators using a bitmap buffer. + * + * @param al iterators to aggregate + * @param bufsize size of the internal buffer used by the iterator in 64-bit words + * @return xor aggregate + */ + public static IteratingRLW32 bufferedxor(final int bufsize, final IteratingRLW32... al) { + if (al.length == 0) + throw new IllegalArgumentException("Need at least one iterator"); + if (al.length == 1) + return al[0]; + + final LinkedList basell = new LinkedList(); + for (IteratingRLW32 i : al) + basell.add(i); + return new BufferedIterator32(new XORIt(basell,bufsize)); + } + /** + * Write out the content of the iterator, but as if it were all zeros. + * + * @param container + * where we write + * @param i + * the iterator + */ + protected static void dischargeAsEmpty(final BitmapStorage32 container, + final IteratingRLW32 i) { + while (i.size() > 0) { + container.addStreamOfEmptyWords(false, i.size()); + i.next(); + + } + } + + /** + * Write out up to max words, returns how many were written + * @param container target for writes + * @param i source of data + * @param max maximal number of writes + * @return how many written + */ + protected static int discharge(final BitmapStorage32 container, IteratingRLW32 i, int max) { + int counter = 0; + while (i.size() > 0 && counter < max) { + int L1 = i.getRunningLength(); + if (L1 > 0) { + if (L1 + counter > max) + L1 = max - counter; + container.addStreamOfEmptyWords(i.getRunningBit(), L1); + counter += L1; + } + int L = i.getNumberOfLiteralWords(); + if(L + counter > max) L = max - counter; + for (int k = 0; k < L; ++k) { + container.add(i.getLiteralWordAt(k)); + } + counter += L; + i.discardFirstWords(L+L1); + } + return counter; + } + + /** + * Write out up to max negated words, returns how many were written + * @param container target for writes + * @param i source of data + * @param max maximal number of writes + * @return how many written + */ + protected static int dischargeNegated(final BitmapStorage32 container, IteratingRLW32 i, int max) { + int counter = 0; + while (i.size() > 0 && counter < max) { + int L1 = i.getRunningLength(); + if (L1 > 0) { + if (L1 + counter > max) + L1 = max - counter; + container.addStreamOfEmptyWords(i.getRunningBit(), L1); + counter += L1; + } + int L = i.getNumberOfLiteralWords(); + if(L + counter > max) L = max - counter; + for (int k = 0; k < L; ++k) { + container.add(i.getLiteralWordAt(k)); + } + counter += L; + i.discardFirstWords(L+L1); + } + return counter; + } + + static void andToContainer(final BitmapStorage32 container, + int desiredrlwcount, final IteratingRLW32 rlwi, IteratingRLW32 rlwj) { + while ((rlwi.size()>0) && (rlwj.size()>0) && (desiredrlwcount-- >0) ) { + while ((rlwi.getRunningLength() > 0) || (rlwj.getRunningLength() > 0)) { + final boolean i_is_prey = rlwi.getRunningLength() < rlwj + .getRunningLength(); + final IteratingRLW32 prey = i_is_prey ? rlwi : rlwj; + final IteratingRLW32 predator = i_is_prey ? rlwj + : rlwi; + if (predator.getRunningBit() == false) { + container.addStreamOfEmptyWords(false, predator.getRunningLength()); + prey.discardFirstWords(predator.getRunningLength()); + predator.discardFirstWords(predator.getRunningLength()); + } else { + final int index = discharge(container, prey, predator.getRunningLength()); + container.addStreamOfEmptyWords(false, predator.getRunningLength() + - index); + predator.discardFirstWords(predator.getRunningLength()); + } + } + final int nbre_literal = Math.min(rlwi.getNumberOfLiteralWords(), + rlwj.getNumberOfLiteralWords()); + if (nbre_literal > 0) { + desiredrlwcount -= nbre_literal; + for (int k = 0; k < nbre_literal; ++k) + container.add(rlwi.getLiteralWordAt(k) & rlwj.getLiteralWordAt(k)); + rlwi.discardFirstWords(nbre_literal); + rlwj.discardFirstWords(nbre_literal); + } + } + } + + static void andToContainer(final BitmapStorage32 container, + final IteratingRLW32 rlwi, IteratingRLW32 rlwj) { + while ((rlwi.size()>0) && (rlwj.size()>0) ) { + while ((rlwi.getRunningLength() > 0) || (rlwj.getRunningLength() > 0)) { + final boolean i_is_prey = rlwi.getRunningLength() < rlwj + .getRunningLength(); + final IteratingRLW32 prey = i_is_prey ? rlwi : rlwj; + final IteratingRLW32 predator = i_is_prey ? rlwj + : rlwi; + if (predator.getRunningBit() == false) { + container.addStreamOfEmptyWords(false, predator.getRunningLength()); + prey.discardFirstWords(predator.getRunningLength()); + predator.discardFirstWords(predator.getRunningLength()); + } else { + final int index = discharge(container, prey, predator.getRunningLength()); + container.addStreamOfEmptyWords(false, predator.getRunningLength() + - index); + predator.discardFirstWords(predator.getRunningLength()); + } + } + final int nbre_literal = Math.min(rlwi.getNumberOfLiteralWords(), + rlwj.getNumberOfLiteralWords()); + if (nbre_literal > 0) { + for (int k = 0; k < nbre_literal; ++k) + container.add(rlwi.getLiteralWordAt(k) & rlwj.getLiteralWordAt(k)); + rlwi.discardFirstWords(nbre_literal); + rlwj.discardFirstWords(nbre_literal); + } + } + } + + + /** + * Compute the first few words of the XOR aggregate between two iterators. + * + * @param container where to write + * @param desiredrlwcount number of words to be written (max) + * @param rlwi first iterator to aggregate + * @param rlwj second iterator to aggregate + */ + public static void xorToContainer(final BitmapStorage32 container, + int desiredrlwcount, final IteratingRLW32 rlwi, IteratingRLW32 rlwj) { + while ((rlwi.size()>0) && (rlwj.size()>0) && (desiredrlwcount-- >0) ) { + while ((rlwi.getRunningLength() > 0) || (rlwj.getRunningLength() > 0)) { + final boolean i_is_prey = rlwi.getRunningLength() < rlwj + .getRunningLength(); + final IteratingRLW32 prey = i_is_prey ? rlwi : rlwj; + final IteratingRLW32 predator = i_is_prey ? rlwj + : rlwi; + if (predator.getRunningBit() == false) { + int index = discharge(container, prey, predator.getRunningLength()); + container.addStreamOfEmptyWords(false, predator.getRunningLength() + - index); + predator.discardFirstWords(predator.getRunningLength()); + } else { + int index = dischargeNegated(container, prey, predator.getRunningLength()); + container.addStreamOfEmptyWords(true, predator.getRunningLength() + - index); + predator.discardFirstWords(predator.getRunningLength()); + } + } + final int nbre_literal = Math.min(rlwi.getNumberOfLiteralWords(), + rlwj.getNumberOfLiteralWords()); + if (nbre_literal > 0) { + desiredrlwcount -= nbre_literal; + for (int k = 0; k < nbre_literal; ++k) + container.add(rlwi.getLiteralWordAt(k) ^ rlwj.getLiteralWordAt(k)); + rlwi.discardFirstWords(nbre_literal); + rlwj.discardFirstWords(nbre_literal); + } + } + } + + protected static int inplaceor(int[] bitmap, + IteratingRLW32 i) { + int pos = 0; + int s; + while ((s = i.size()) > 0) { + if (pos + s < bitmap.length) { + final int L = i.getRunningLength(); + if (i.getRunningBit()) + Arrays.fill(bitmap, pos, pos + L, ~0); + pos += L; + final int LR = i.getNumberOfLiteralWords(); + for (int k = 0; k < LR; ++k) + bitmap[pos++] |= i.getLiteralWordAt(k); + if (!i.next()) { + return pos; + } + } else { + int howmany = bitmap.length - pos; + int L = i.getRunningLength(); + if (pos + L > bitmap.length) { + if (i.getRunningBit()) { + Arrays.fill(bitmap, pos, bitmap.length, ~0); + } + i.discardFirstWords(howmany); + return bitmap.length; + } + if (i.getRunningBit()) + Arrays.fill(bitmap, pos, pos + L, ~0); + pos += L; + for (int k = 0; pos < bitmap.length; ++k) + bitmap[pos++] |= i.getLiteralWordAt(k); + i.discardFirstWords(howmany); + return pos; + } + } + return pos; + } + + + protected static int inplacexor(int[] bitmap, + IteratingRLW32 i) { + int pos = 0; + int s; + while ((s = i.size()) > 0) { + if (pos + s < bitmap.length) { + final int L = i.getRunningLength(); + if (i.getRunningBit()) { + for(int k = pos ; k < pos + L; ++k) + bitmap[k] = ~bitmap[k]; + } + pos += L; + final int LR = i.getNumberOfLiteralWords(); + for (int k = 0; k < LR; ++k) + bitmap[pos++] ^= i.getLiteralWordAt(k); + if (!i.next()) { + return pos; + } + } else { + int howmany = bitmap.length - pos; + int L = i.getRunningLength(); + if (pos + L > bitmap.length) { + if (i.getRunningBit()) { + for(int k = pos ; k < bitmap.length; ++k) + bitmap[k] = ~bitmap[k]; + } + i.discardFirstWords(howmany); + return bitmap.length; + } + if (i.getRunningBit()) + for(int k = pos ; k < pos + L; ++k) + bitmap[k] = ~bitmap[k]; + pos += L; + for (int k = 0; pos < bitmap.length; ++k) + bitmap[pos++] ^= i.getLiteralWordAt(k); + i.discardFirstWords(howmany); + return pos; + } + } + return pos; + } + protected static int inplaceand(int[] bitmap, + IteratingRLW32 i) { + int pos = 0; + int s; + while ((s = i.size()) > 0) { + if (pos + s < bitmap.length) { + final int L = i.getRunningLength(); + if (!i.getRunningBit()) { + for(int k = pos ; k < pos + L; ++k) + bitmap[k] = 0; + } + pos += L; + final int LR = i.getNumberOfLiteralWords(); + for (int k = 0; k < LR; ++k) + bitmap[pos++] &= i.getLiteralWordAt(k); + if (!i.next()) { + return pos; + } + } else { + int howmany = bitmap.length - pos; + int L = i.getRunningLength(); + if (pos + L > bitmap.length) { + if (!i.getRunningBit()) { + for(int k = pos ; k < bitmap.length; ++k) + bitmap[k] = 0; + } + i.discardFirstWords(howmany); + return bitmap.length; + } + if (!i.getRunningBit()) + for(int k = pos ; k < pos + L; ++k) + bitmap[k] = 0; + pos += L; + for (int k = 0; pos < bitmap.length; ++k) + bitmap[pos++] &= i.getLiteralWordAt(k); + i.discardFirstWords(howmany); + return pos; + } + } + return pos; + } + + /** + * An optimization option. Larger values may improve speed, but at + * the expense of memory. + */ + public final static int DEFAULTMAXBUFSIZE = 65536; + + +} + + +class ORIt implements CloneableIterator { + EWAHCompressedBitmap32 buffer = new EWAHCompressedBitmap32(); + int[] hardbitmap; + LinkedList ll; + + ORIt(LinkedList basell, final int bufsize) { + this.ll = basell; + this.hardbitmap = new int[bufsize]; + } + + @Override + public XORIt clone() throws CloneNotSupportedException { + XORIt answer = (XORIt) super.clone(); + answer.buffer = this.buffer.clone(); + answer.hardbitmap = this.hardbitmap.clone(); + answer.ll = (LinkedList) this.ll.clone(); + return answer; + } + + @Override + public boolean hasNext() { + return !this.ll.isEmpty(); + } + + @Override + public EWAHIterator32 next() { + this.buffer.clear(); + int effective = 0; + Iterator i = this.ll.iterator(); + while (i.hasNext()) { + IteratingRLW32 rlw = i.next(); + if (rlw.size() > 0) { + int eff = IteratorAggregation32.inplaceor(this.hardbitmap, rlw); + if (eff > effective) + effective = eff; + } else + i.remove(); + } + for (int k = 0; k < effective; ++k) + this.buffer.add(this.hardbitmap[k]); + Arrays.fill(this.hardbitmap, 0); + return this.buffer.getEWAHIterator(); + } +} + +class XORIt implements CloneableIterator { + EWAHCompressedBitmap32 buffer = new EWAHCompressedBitmap32(); + int[] hardbitmap; + LinkedList ll; + + XORIt(LinkedList basell, final int bufsize) { + this.ll = basell; + this.hardbitmap = new int[bufsize]; + + } + + @Override + public XORIt clone() throws CloneNotSupportedException { + XORIt answer = (XORIt) super.clone(); + answer.buffer = this.buffer.clone(); + answer.hardbitmap = this.hardbitmap.clone(); + answer.ll = (LinkedList) this.ll.clone(); + return answer; + } + + @Override + public boolean hasNext() { + return !this.ll.isEmpty(); + } + + @Override + public EWAHIterator32 next() { + this.buffer.clear(); + int effective = 0; + Iterator i = this.ll.iterator(); + while (i.hasNext()) { + IteratingRLW32 rlw = i.next(); + if (rlw.size() > 0) { + int eff = IteratorAggregation32.inplacexor(this.hardbitmap, rlw); + if (eff > effective) + effective = eff; + } else + i.remove(); + } + for (int k = 0; k < effective; ++k) + this.buffer.add(this.hardbitmap[k]); + Arrays.fill(this.hardbitmap, 0); + return this.buffer.getEWAHIterator(); + } +} + +class AndIt implements CloneableIterator { + EWAHCompressedBitmap32 buffer = new EWAHCompressedBitmap32(); + LinkedList ll; + int buffersize; + + public AndIt(LinkedList basell, final int bufsize) { + this.ll = basell; + this.buffersize = bufsize; + } + + @Override + public boolean hasNext() { + return !this.ll.isEmpty(); + } + + @Override + public AndIt clone() throws CloneNotSupportedException { + AndIt answer = (AndIt) super.clone(); + answer.buffer = this.buffer.clone(); + answer.ll = (LinkedList) this.ll.clone(); + return answer; + } + + @Override + public EWAHIterator32 next() { + this.buffer.clear(); + IteratorAggregation32.andToContainer(this.buffer, this.buffersize * this.ll.size(), + this.ll.get(0), this.ll.get(1)); + if (this.ll.size() > 2) { + Iterator i = this.ll.iterator(); + i.next(); + i.next(); + EWAHCompressedBitmap32 tmpbuffer = new EWAHCompressedBitmap32(); + while (i.hasNext() && this.buffer.sizeInBytes() > 0) { + IteratorAggregation32.andToContainer(tmpbuffer, + this.buffer.getIteratingRLW(), i.next()); + this.buffer.swap(tmpbuffer); + tmpbuffer.clear(); + } + } + Iterator i = this.ll.iterator(); + while(i.hasNext()) { + if(i.next().size() == 0) { + this.ll.clear(); + break; + } + } + return this.buffer.getEWAHIterator(); + } + +} \ No newline at end of file diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah32/IteratorUtil32.java b/fine-jgit/src/com/fr/third/googlecode/javaewah32/IteratorUtil32.java new file mode 100644 index 000000000..d8e415101 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah32/IteratorUtil32.java @@ -0,0 +1,135 @@ +package com.fr.third.googlecode.javaewah32; + +import java.util.Iterator; + +import com.fr.third.googlecode.javaewah.IntIterator; + + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ +/** + * Convenience functions for working over iterators + * + */ +public class IteratorUtil32 { + + /** + * @param i iterator we wish to iterate over + * @return an iterator over the set bits corresponding to the iterator + */ + public static IntIterator toSetBitsIntIterator(final IteratingRLW32 i) { + return new IntIteratorOverIteratingRLW32(i); + } + + /** + * @param i iterator we wish to iterate over + * @return an iterator over the set bits corresponding to the iterator + */ + public static Iterator toSetBitsIterator(final IteratingRLW32 i) { + return new Iterator() { + @Override + public boolean hasNext() { + return this.under.hasNext(); + } + + @Override + public Integer next() { + return new Integer(this.under.next()); + } + + @Override + public void remove() { + } + + final private IntIterator under = toSetBitsIntIterator(i); + }; + + } + + /** + * Turn an iterator into a bitmap + * @param i iterator we wish to materialize + * @param c where we write + */ + public static void materialize(final IteratingRLW32 i, final BitmapStorage32 c) { + while (true) { + if (i.getRunningLength() > 0) { + c.addStreamOfEmptyWords(i.getRunningBit(), i.getRunningLength()); + } + for (int k = 0; k < i.getNumberOfLiteralWords(); ++k) + c.add(i.getLiteralWordAt(k)); + if (!i.next()) + break; + } + } + + /** + * @param i iterator we wish to iterate over + * @return the cardinality (number of set bits) corresponding to the iterator + */ + public static int cardinality(final IteratingRLW32 i) { + int answer = 0; + while (true) { + if(i.getRunningBit()) answer += i.getRunningLength() * EWAHCompressedBitmap32.wordinbits; + for (int k = 0; k < i.getNumberOfLiteralWords(); ++k) + answer += Long.bitCount(i.getLiteralWordAt(k)); + if(!i.next()) break; + } + return answer; + } + + /** + * + * @param x set of bitmaps we wish to iterate over + * @return an array of iterators corresponding to the array of bitmaps + */ + public static IteratingRLW32[] toIterators(final EWAHCompressedBitmap32... x) { + IteratingRLW32[] X = new IteratingRLW32[x.length]; + for (int k = 0; k < X.length; ++k) { + X[k] = new IteratingBufferedRunningLengthWord32(x[k]); + } + return X; + } + /** + * Turn an iterator into a bitmap + * + * @param i iterator we wish to materialize + * @param c where we write + * @param Max maximum number of words to materialize + * @return how many words were actually materialized + */ + public static long materialize(final IteratingRLW32 i, final BitmapStorage32 c, int Max) { + final int origMax = Max; + while (true) { + if (i.getRunningLength() > 0) { + int L = i.getRunningLength(); + if(L > Max) L = Max; + c.addStreamOfEmptyWords(i.getRunningBit(), L); + Max -= L; + } + long L = i.getNumberOfLiteralWords(); + for (int k = 0; k < L; ++k) + c.add(i.getLiteralWordAt(k)); + if(Max>0) { + if (!i.next()) + break; + } + else break; + } + return origMax - Max; + } + /** + * Turn an iterator into a bitmap + * + * @param i iterator we wish to materialize + * @return materialized version of the iterator + */ + public static EWAHCompressedBitmap32 materialize(final IteratingRLW32 i) { + EWAHCompressedBitmap32 ewah = new EWAHCompressedBitmap32(); + materialize(i, ewah); + return ewah; + } + +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah32/NonEmptyVirtualStorage32.java b/fine-jgit/src/com/fr/third/googlecode/javaewah32/NonEmptyVirtualStorage32.java new file mode 100644 index 000000000..94e8bd96a --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah32/NonEmptyVirtualStorage32.java @@ -0,0 +1,87 @@ +package com.fr.third.googlecode.javaewah32; + + + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ +/** + * This is a BitmapStorage that can be used to determine quickly + * if the result of an operation is non-trivial... that is, whether + * there will be at least on set bit. + * + * @since 0.5.0 + * @author Daniel Lemire and Veronika Zenz + * + */ +public class NonEmptyVirtualStorage32 implements BitmapStorage32 { + static class NonEmptyException extends RuntimeException { + private static final long serialVersionUID = 1L; + + /** + * Do not fill in the stack trace for this exception + * for performance reasons. + * + * @return this instance + * @see Throwable#fillInStackTrace() + */ + @Override + public synchronized Throwable fillInStackTrace() { + return this; + } + } + + private static final NonEmptyException nonEmptyException = new NonEmptyException(); + + + /** + * If the word to be added is non-zero, a NonEmptyException exception is thrown. + */ + @Override +public void add(int newdata) { + if(newdata!=0) throw nonEmptyException; + } + + /** + * throws a NonEmptyException exception when number is greater than 0 + * + */ + @Override +public void addStreamOfLiteralWords(int[] data, int start, int number) { + if (number > 0){ + throw nonEmptyException; + } + } + + /** + * If the boolean value is true and number is greater than 0, then it throws a NonEmptyException exception, + * otherwise, nothing happens. + * + */ + @Override +public void addStreamOfEmptyWords(boolean v, int number) { + if(v && (number>0)) throw nonEmptyException; + } + + /** + * throws a NonEmptyException exception when number is greater than 0 + * + */ + @Override +public void addStreamOfNegatedLiteralWords(int[] data, int start, int number) { + if (number > 0){ + throw nonEmptyException; + } + } + + /** + * Does nothing. + * + * @see com.googlecode.javaewah.BitmapStorage#setSizeInBits(int) + */ + @Override +public void setSizeInBits(int bits) { + } + +} diff --git a/fine-jgit/src/com/fr/third/googlecode/javaewah32/RunningLengthWord32.java b/fine-jgit/src/com/fr/third/googlecode/javaewah32/RunningLengthWord32.java new file mode 100644 index 000000000..37f52ee83 --- /dev/null +++ b/fine-jgit/src/com/fr/third/googlecode/javaewah32/RunningLengthWord32.java @@ -0,0 +1,152 @@ +package com.fr.third.googlecode.javaewah32; + +/* + * Copyright 2009-2013, Daniel Lemire, Cliff Moon, David McIntosh, Robert Becho, Google Inc., Veronika Zenz and Owen Kaser + * Licensed under the Apache License, Version 2.0. + */ + +/** + * Mostly for internal use. + * + * @since 0.5.0 + * @author Daniel Lemire + */ +public final class RunningLengthWord32 implements Cloneable { + + /** + * Instantiates a new running length word. + * + * @param a + * an array of 32-bit words + * @param p + * position in the array where the running length word is + * located. + */ + RunningLengthWord32(final EWAHCompressedBitmap32 a, final int p) { + this.parent = a; + this.position = p; + } + + /** + * Gets the number of literal words. + * + * @return the number of literal words + */ + public int getNumberOfLiteralWords() { + return (this.parent.buffer[this.position] >>> (1 + runninglengthbits)); + } + + /** + * Gets the running bit. + * + * @return the running bit + */ + public boolean getRunningBit() { + return (this.parent.buffer[this.position] & 1) != 0; + } + + /** + * Gets the running length. + * + * @return the running length + */ + public int getRunningLength() { + return (this.parent.buffer[this.position] >>> 1) + & largestrunninglengthcount; + } + + /** + * Sets the number of literal words. + * + * @param number + * the new number of literal words + */ + public void setNumberOfLiteralWords(final int number) { + this.parent.buffer[this.position] |= notrunninglengthplusrunningbit; + this.parent.buffer[this.position] &= (number << (runninglengthbits + 1)) + | runninglengthplusrunningbit; + } + + /** + * Sets the running bit. + * + * @param b + * the new running bit + */ + public void setRunningBit(final boolean b) { + if (b) + this.parent.buffer[this.position] |= 1; + else + this.parent.buffer[this.position] &= ~1; + } + + /** + * Sets the running length. + * + * @param number + * the new running length + */ + public void setRunningLength(final int number) { + this.parent.buffer[this.position] |= shiftedlargestrunninglengthcount; + this.parent.buffer[this.position] &= (number << 1) + | notshiftedlargestrunninglengthcount; + } + + /** + * Return the size in uncompressed words represented by this running + * length word. + * + * @return the int + */ + public int size() { + return getRunningLength() + getNumberOfLiteralWords(); + } + + /* + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "running bit = " + getRunningBit() + + " running length = " + getRunningLength() + + " number of lit. words " + getNumberOfLiteralWords(); + } + + @Override + public RunningLengthWord32 clone() throws CloneNotSupportedException { + RunningLengthWord32 answer; + answer = (RunningLengthWord32) super.clone(); + answer.parent = this.parent; + answer.position = this.position; + return answer; + } + + /** The array of words. */ + public EWAHCompressedBitmap32 parent; + + /** The position in array. */ + public int position; + + /** + * number of bits dedicated to marking of the running length of clean + * words + */ + public static final int runninglengthbits = 16; + + private static final int literalbits = 32 - 1 - runninglengthbits; + + /** largest number of literal words in a run. */ + public static final int largestliteralcount = (1 << literalbits) - 1; + + /** largest number of clean words in a run */ + public static final int largestrunninglengthcount = (1 << runninglengthbits) - 1; + + private static final int runninglengthplusrunningbit = (1 << (runninglengthbits + 1)) - 1; + + private static final int shiftedlargestrunninglengthcount = largestrunninglengthcount << 1; + + private static final int notrunninglengthplusrunningbit = ~runninglengthplusrunningbit; + + private static final int notshiftedlargestrunninglengthcount = ~shiftedlargestrunninglengthcount; + +} \ No newline at end of file diff --git a/fine-jodd/src/com/fr/third/jodd/exception/ExceptionUtil.java b/fine-jodd/src/com/fr/third/jodd/exception/ExceptionUtil.java index 8ee74fe07..48d00afbc 100644 --- a/fine-jodd/src/com/fr/third/jodd/exception/ExceptionUtil.java +++ b/fine-jodd/src/com/fr/third/jodd/exception/ExceptionUtil.java @@ -255,7 +255,7 @@ public class ExceptionUtil { if (throwable instanceof RuntimeException) { throw (RuntimeException) throwable; } - Thread.currentThread().stop(throwable); + throw new UnsupportedOperationException(); } /** diff --git a/fine-kryo/src/com/fr/third/esotericsoftware/kryo/util/UnsafeUtil.java b/fine-kryo/src/com/fr/third/esotericsoftware/kryo/util/UnsafeUtil.java index 18be3eb24..3014b53ff 100644 --- a/fine-kryo/src/com/fr/third/esotericsoftware/kryo/util/UnsafeUtil.java +++ b/fine-kryo/src/com/fr/third/esotericsoftware/kryo/util/UnsafeUtil.java @@ -27,7 +27,7 @@ import java.util.Comparator; import java.util.List; import com.fr.third.esotericsoftware.minlog.Log; -import sun.misc.Cleaner; +import com.fr.third.sun.misc.Cleaner; import sun.misc.Unsafe; import sun.nio.ch.DirectBuffer; diff --git a/fine-kryo/src/com/fr/third/org/objenesis/Objenesis.java b/fine-objenesis/src/com/fr/third/org/objenesis/Objenesis.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/Objenesis.java rename to fine-objenesis/src/com/fr/third/org/objenesis/Objenesis.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/ObjenesisBase.java b/fine-objenesis/src/com/fr/third/org/objenesis/ObjenesisBase.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/ObjenesisBase.java rename to fine-objenesis/src/com/fr/third/org/objenesis/ObjenesisBase.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/ObjenesisException.java b/fine-objenesis/src/com/fr/third/org/objenesis/ObjenesisException.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/ObjenesisException.java rename to fine-objenesis/src/com/fr/third/org/objenesis/ObjenesisException.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/ObjenesisHelper.java b/fine-objenesis/src/com/fr/third/org/objenesis/ObjenesisHelper.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/ObjenesisHelper.java rename to fine-objenesis/src/com/fr/third/org/objenesis/ObjenesisHelper.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/ObjenesisSerializer.java b/fine-objenesis/src/com/fr/third/org/objenesis/ObjenesisSerializer.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/ObjenesisSerializer.java rename to fine-objenesis/src/com/fr/third/org/objenesis/ObjenesisSerializer.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/ObjenesisStd.java b/fine-objenesis/src/com/fr/third/org/objenesis/ObjenesisStd.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/ObjenesisStd.java rename to fine-objenesis/src/com/fr/third/org/objenesis/ObjenesisStd.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/ObjectInstantiator.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/ObjectInstantiator.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/ObjectInstantiator.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/ObjectInstantiator.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/SerializationInstantiatorHelper.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/SerializationInstantiatorHelper.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/SerializationInstantiatorHelper.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/SerializationInstantiatorHelper.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/android/Android10Instantiator.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/android/Android10Instantiator.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/android/Android10Instantiator.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/android/Android10Instantiator.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/android/Android17Instantiator.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/android/Android17Instantiator.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/android/Android17Instantiator.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/android/Android17Instantiator.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/android/Android18Instantiator.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/android/Android18Instantiator.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/android/Android18Instantiator.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/android/Android18Instantiator.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/android/AndroidSerializationInstantiator.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/android/AndroidSerializationInstantiator.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/android/AndroidSerializationInstantiator.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/android/AndroidSerializationInstantiator.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/annotations/Instantiator.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/annotations/Instantiator.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/annotations/Instantiator.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/annotations/Instantiator.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/annotations/Typology.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/annotations/Typology.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/annotations/Typology.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/annotations/Typology.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/AccessibleInstantiator.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/AccessibleInstantiator.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/AccessibleInstantiator.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/AccessibleInstantiator.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/ConstructorInstantiator.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/ConstructorInstantiator.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/ConstructorInstantiator.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/ConstructorInstantiator.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/FailingInstantiator.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/FailingInstantiator.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/FailingInstantiator.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/FailingInstantiator.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/NewInstanceInstantiator.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/NewInstanceInstantiator.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/NewInstanceInstantiator.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/NewInstanceInstantiator.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/NullInstantiator.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/NullInstantiator.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/NullInstantiator.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/NullInstantiator.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/ObjectInputStreamInstantiator.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/ObjectInputStreamInstantiator.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/ObjectInputStreamInstantiator.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/ObjectInputStreamInstantiator.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/ObjectStreamClassInstantiator.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/ObjectStreamClassInstantiator.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/ObjectStreamClassInstantiator.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/ObjectStreamClassInstantiator.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/ProxyingInstantiator.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/ProxyingInstantiator.java similarity index 99% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/ProxyingInstantiator.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/ProxyingInstantiator.java index 025dcfc74..490b06aeb 100644 --- a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/basic/ProxyingInstantiator.java +++ b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/basic/ProxyingInstantiator.java @@ -61,7 +61,7 @@ public class ProxyingInstantiator implements ObjectInstantiator { byte[] classBytes = writeExtendingClass(type, SUFFIX); try { - newType = ClassDefinitionUtils.defineClass(type.getName() + SUFFIX, classBytes, type.getClassLoader()); + newType = ClassDefinitionUtils.defineClass(type.getName() + SUFFIX, classBytes, type, type.getClassLoader()); } catch (Exception e) { throw new ObjenesisException(e); } diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/gcj/GCJInstantiator.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/gcj/GCJInstantiator.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/gcj/GCJInstantiator.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/gcj/GCJInstantiator.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/gcj/GCJInstantiatorBase.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/gcj/GCJInstantiatorBase.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/gcj/GCJInstantiatorBase.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/gcj/GCJInstantiatorBase.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/gcj/GCJSerializationInstantiator.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/gcj/GCJSerializationInstantiator.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/gcj/GCJSerializationInstantiator.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/gcj/GCJSerializationInstantiator.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/perc/PercInstantiator.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/perc/PercInstantiator.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/perc/PercInstantiator.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/perc/PercInstantiator.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/perc/PercSerializationInstantiator.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/perc/PercSerializationInstantiator.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/perc/PercSerializationInstantiator.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/perc/PercSerializationInstantiator.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/sun/MagicInstantiator.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/sun/MagicInstantiator.java similarity index 99% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/sun/MagicInstantiator.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/sun/MagicInstantiator.java index 33a9dec8a..531fbc840 100644 --- a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/sun/MagicInstantiator.java +++ b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/sun/MagicInstantiator.java @@ -95,7 +95,7 @@ public class MagicInstantiator implements ObjectInstantiator { byte[] classBytes = writeExtendingClass(type, className); try { - clazz = ClassDefinitionUtils.defineClass(className, classBytes, getClass().getClassLoader()); + clazz = ClassDefinitionUtils.defineClass(className, classBytes, type, getClass().getClassLoader()); } catch (Exception e) { throw new ObjenesisException(e); } diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/sun/SunReflectionFactoryHelper.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/sun/SunReflectionFactoryHelper.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/sun/SunReflectionFactoryHelper.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/sun/SunReflectionFactoryHelper.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/sun/SunReflectionFactoryInstantiator.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/sun/SunReflectionFactoryInstantiator.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/sun/SunReflectionFactoryInstantiator.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/sun/SunReflectionFactoryInstantiator.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/sun/SunReflectionFactorySerializationInstantiator.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/sun/SunReflectionFactorySerializationInstantiator.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/sun/SunReflectionFactorySerializationInstantiator.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/sun/SunReflectionFactorySerializationInstantiator.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/sun/UnsafeFactoryInstantiator.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/sun/UnsafeFactoryInstantiator.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/sun/UnsafeFactoryInstantiator.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/sun/UnsafeFactoryInstantiator.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/util/ClassDefinitionUtils.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/util/ClassDefinitionUtils.java similarity index 97% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/util/ClassDefinitionUtils.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/util/ClassDefinitionUtils.java index d7fdb79ce..fca50d9c1 100644 --- a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/util/ClassDefinitionUtils.java +++ b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/util/ClassDefinitionUtils.java @@ -90,9 +90,9 @@ public final class ClassDefinitionUtils { * @throws Exception whenever something goes wrong */ @SuppressWarnings("unchecked") - public static Class defineClass(String className, byte[] b, ClassLoader loader) + public static Class defineClass(String className, byte[] b, Class neighbor, ClassLoader loader) throws Exception { - Class c = (Class) UnsafeUtils.getUnsafe().defineClass(className, b, 0, b.length, loader, PROTECTION_DOMAIN); + Class c = (Class) DefineClassHelper.defineClass(className, b, 0, b.length, neighbor, loader, PROTECTION_DOMAIN); // Force static initializers to run. Class.forName(className, true, loader); return c; diff --git a/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/util/DefineClassHelper.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/util/DefineClassHelper.java new file mode 100644 index 000000000..6c2a4ebf7 --- /dev/null +++ b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/util/DefineClassHelper.java @@ -0,0 +1,149 @@ +/* + * Copyright 2006-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.fr.third.org.objenesis.instantiator.util; + +import com.fr.third.org.objenesis.ObjenesisException; +import com.fr.third.org.objenesis.strategy.PlatformDescription; +import sun.misc.Unsafe; + + + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.security.ProtectionDomain; + +/** + * Java 11+ removed sun.misc.Unsafe.defineClass. This class bridges the gap to work from Java 1.8 up to 11. + *

+ * It was inspired from javassist. + * + * @author Henri Tremblay + */ +public final class DefineClassHelper { + + private static abstract class Helper { + abstract Class defineClass(String name, byte[] b, int off, int len, Class neighbor, + ClassLoader loader, ProtectionDomain protectionDomain); + } + + private static class Java8 extends Helper { + + private final MethodHandle defineClass = defineClass(); + + private MethodHandle defineClass() { + MethodType mt = MethodType.methodType(Class.class, String.class, byte[].class, int.class, int.class, ClassLoader.class, ProtectionDomain.class); + MethodHandle m; + try { + m = MethodHandles.publicLookup().findVirtual(Unsafe.class, "defineClass", mt); + } catch(NoSuchMethodException | IllegalAccessException e) { + throw new ObjenesisException(e); + } + Unsafe unsafe = UnsafeUtils.getUnsafe(); + return m.bindTo(unsafe); + } + + @Override + Class defineClass(String className, byte[] b, int off, int len, Class neighbor, ClassLoader loader, ProtectionDomain protectionDomain) { + try { + return (Class) defineClass.invokeExact(className, b, off, len, loader, protectionDomain); + } catch (Throwable e) { + if(e instanceof Error) { + throw (Error) e; + } + if(e instanceof RuntimeException) { + throw (RuntimeException) e; + } + throw new ObjenesisException(e); + } + } + } + + private static class Java11 extends Helper { + + private final Class module = module(); + private final MethodHandles.Lookup lookup = MethodHandles.lookup(); + private final MethodHandle getModule = getModule(); + private final MethodHandle addReads = addReads(); + private final MethodHandle privateLookupIn = privateLookupIn(); + private final MethodHandle defineClass = defineClass(); + + private Class module() { + try { + return Class.forName("java.lang.Module"); + } catch (ClassNotFoundException e) { + throw new ObjenesisException(e); + } + } + + private MethodHandle getModule() { + try { + return lookup.findVirtual(Class.class, "getModule", MethodType.methodType(module)); + } catch (NoSuchMethodException | IllegalAccessException e) { + throw new ObjenesisException(e); + } + } + + private MethodHandle addReads() { + try { + return lookup.findVirtual(module, "addReads", MethodType.methodType(module, module)); + } catch (NoSuchMethodException | IllegalAccessException e) { + throw new ObjenesisException(e); + } + } + + private MethodHandle privateLookupIn() { + try { + return lookup.findStatic(MethodHandles.class, "privateLookupIn", MethodType.methodType(MethodHandles.Lookup.class, Class.class, MethodHandles.Lookup.class)); + } catch (NoSuchMethodException | IllegalAccessException e) { + throw new ObjenesisException(e); + } + } + + private MethodHandle defineClass() { + try { + return lookup.findVirtual(MethodHandles.Lookup.class, "defineClass", MethodType.methodType(Class.class, byte[].class)); + } catch (NoSuchMethodException | IllegalAccessException e) { + throw new ObjenesisException(e); + } + } + + @Override + Class defineClass(String className, byte[] b, int off, int len, Class neighbor, ClassLoader loader, ProtectionDomain protectionDomain) { + try { + Object module = getModule.invokeWithArguments(DefineClassHelper.class); + Object neighborModule = getModule.invokeWithArguments(neighbor); + addReads.invokeWithArguments(module, neighborModule); + MethodHandles.Lookup prvlookup = (MethodHandles.Lookup) privateLookupIn.invokeExact(neighbor, lookup); + return (Class) defineClass.invokeExact(prvlookup, b); + } catch (Throwable e) { + throw new ObjenesisException(neighbor.getName() + " has no permission to define the class", e); + } + } + } + + // Java 11+ removed sun.misc.Unsafe.defineClass, so we fallback to invoking defineClass on + // ClassLoader until we have an implementation that uses MethodHandles.Lookup.defineClass + private static final Helper privileged = PlatformDescription.isAfterJava11() ? + new Java11() : new Java8(); + + public static Class defineClass(String name, byte[] b, int off, int len, Class neighbor, + ClassLoader loader, ProtectionDomain protectionDomain) { + return privileged.defineClass(name, b, off, len, neighbor, loader, protectionDomain); + } + + private DefineClassHelper() {} +} \ No newline at end of file diff --git a/fine-kryo/src/com/fr/third/org/objenesis/instantiator/util/UnsafeUtils.java b/fine-objenesis/src/com/fr/third/org/objenesis/instantiator/util/UnsafeUtils.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/instantiator/util/UnsafeUtils.java rename to fine-objenesis/src/com/fr/third/org/objenesis/instantiator/util/UnsafeUtils.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/strategy/BaseInstantiatorStrategy.java b/fine-objenesis/src/com/fr/third/org/objenesis/strategy/BaseInstantiatorStrategy.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/strategy/BaseInstantiatorStrategy.java rename to fine-objenesis/src/com/fr/third/org/objenesis/strategy/BaseInstantiatorStrategy.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/strategy/InstantiatorStrategy.java b/fine-objenesis/src/com/fr/third/org/objenesis/strategy/InstantiatorStrategy.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/strategy/InstantiatorStrategy.java rename to fine-objenesis/src/com/fr/third/org/objenesis/strategy/InstantiatorStrategy.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/strategy/PlatformDescription.java b/fine-objenesis/src/com/fr/third/org/objenesis/strategy/PlatformDescription.java similarity index 89% rename from fine-kryo/src/com/fr/third/org/objenesis/strategy/PlatformDescription.java rename to fine-objenesis/src/com/fr/third/org/objenesis/strategy/PlatformDescription.java index a401fc320..b5c886e27 100644 --- a/fine-kryo/src/com/fr/third/org/objenesis/strategy/PlatformDescription.java +++ b/fine-objenesis/src/com/fr/third/org/objenesis/strategy/PlatformDescription.java @@ -134,6 +134,29 @@ public final class PlatformDescription { return bootClasspath != null && bootClasspath.toLowerCase().contains("core-oj.jar"); } + /** + * Tells if the current JVM is running Java 9 or above + * + * @return if the current JVM is Java 9 or above + */ + public static boolean isAfterJigsaw() { + String version = PlatformDescription.SPECIFICATION_VERSION; + return version.indexOf('.') < 0; // No dot means the version is 9, 10, 11, ... not 1.6, 1.7, 1.8 + } + + /** + * Tells if the current JVM is running Java 11 or above + * + * @return if the current JVM is Java 11 or above + */ + public static boolean isAfterJava11() { + if(!isAfterJigsaw()) { + return false; + } + int version = Integer.parseInt(PlatformDescription.SPECIFICATION_VERSION); + return version >= 11; + } + public static boolean isGoogleAppEngine() { return GAE_VERSION != null; } diff --git a/fine-kryo/src/com/fr/third/org/objenesis/strategy/SerializingInstantiatorStrategy.java b/fine-objenesis/src/com/fr/third/org/objenesis/strategy/SerializingInstantiatorStrategy.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/strategy/SerializingInstantiatorStrategy.java rename to fine-objenesis/src/com/fr/third/org/objenesis/strategy/SerializingInstantiatorStrategy.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/strategy/SingleInstantiatorStrategy.java b/fine-objenesis/src/com/fr/third/org/objenesis/strategy/SingleInstantiatorStrategy.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/strategy/SingleInstantiatorStrategy.java rename to fine-objenesis/src/com/fr/third/org/objenesis/strategy/SingleInstantiatorStrategy.java diff --git a/fine-kryo/src/com/fr/third/org/objenesis/strategy/StdInstantiatorStrategy.java b/fine-objenesis/src/com/fr/third/org/objenesis/strategy/StdInstantiatorStrategy.java similarity index 100% rename from fine-kryo/src/com/fr/third/org/objenesis/strategy/StdInstantiatorStrategy.java rename to fine-objenesis/src/com/fr/third/org/objenesis/strategy/StdInstantiatorStrategy.java diff --git a/fine-poi/src/com/fr/third/v2/org/apache/poi/POIXMLTypeLoader.java b/fine-poi/src/com/fr/third/v2/org/apache/poi/POIXMLTypeLoader.java index f9203a570..9776713d2 100644 --- a/fine-poi/src/com/fr/third/v2/org/apache/poi/POIXMLTypeLoader.java +++ b/fine-poi/src/com/fr/third/v2/org/apache/poi/POIXMLTypeLoader.java @@ -18,9 +18,11 @@ package com.fr.third.v2.org.apache.poi; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.Reader; +import java.io.StringReader; import java.net.URL; import java.util.Collections; import java.util.HashMap; @@ -28,6 +30,7 @@ import java.util.Map; import javax.xml.stream.XMLStreamReader; +import com.fr.third.v2.org.apache.poi.util.DocumentHelper; import com.fr.third.v2.org.apache.xmlbeans.SchemaType; import com.fr.third.v2.org.apache.xmlbeans.XmlBeans; import com.fr.third.v2.org.apache.xmlbeans.XmlException; @@ -35,19 +38,26 @@ import com.fr.third.v2.org.apache.xmlbeans.XmlObject; import com.fr.third.v2.org.apache.xmlbeans.XmlOptions; import com.fr.third.v2.org.apache.xmlbeans.xml.stream.XMLInputStream; import com.fr.third.v2.org.apache.xmlbeans.xml.stream.XMLStreamException; +import org.w3c.dom.Document; import org.w3c.dom.Node; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; @SuppressWarnings("deprecation") public class POIXMLTypeLoader { public static final XmlOptions DEFAULT_XML_OPTIONS; + static { DEFAULT_XML_OPTIONS = new XmlOptions(); DEFAULT_XML_OPTIONS.setSaveOuter(); DEFAULT_XML_OPTIONS.setUseDefaultNamespace(); DEFAULT_XML_OPTIONS.setSaveAggressiveNamespaces(); DEFAULT_XML_OPTIONS.setCharacterEncoding("UTF-8"); - DEFAULT_XML_OPTIONS.setLoadEntityBytesLimit(4096); + // Piccolo is disabled for POI builts, i.e. JAXP is used for parsing + // so only user code using XmlObject/XmlToken.Factory.parse + // directly can bypass the entity check, which is probably unlikely (... and not within our responsibility :)) + // DEFAULT_XML_OPTIONS.setLoadEntityBytesLimit(4096); Map map = new HashMap(); map.put("http://schemas.openxmlformats.org/drawingml/2006/main", "a"); @@ -66,10 +76,9 @@ public class POIXMLTypeLoader { map.put("urn:schemas-microsoft-com:vml", "v"); DEFAULT_XML_OPTIONS.setSaveSuggestedPrefixes(Collections.unmodifiableMap(map)); } - + private static XmlOptions getXmlOptions(XmlOptions options) { - XmlOptions opt = (options == null) ? DEFAULT_XML_OPTIONS : options; - return opt; + return options == null ? DEFAULT_XML_OPTIONS : options; } public static XmlObject newInstance(SchemaType type, XmlOptions options) { @@ -77,19 +86,38 @@ public class POIXMLTypeLoader { } public static XmlObject parse(String xmlText, SchemaType type, XmlOptions options) throws XmlException { - return XmlBeans.getContextTypeLoader().parse(xmlText, type, getXmlOptions(options)); + try { + return parse(new StringReader(xmlText), type, options); + } catch (IOException e) { + throw new XmlException("Unable to parse xml bean", e); + } } public static XmlObject parse(File file, SchemaType type, XmlOptions options) throws XmlException, IOException { - return XmlBeans.getContextTypeLoader().parse(file, type, getXmlOptions(options)); + InputStream is = new FileInputStream(file); + try { + return parse(is, type, options); + } finally { + is.close(); + } } public static XmlObject parse(URL file, SchemaType type, XmlOptions options) throws XmlException, IOException { - return XmlBeans.getContextTypeLoader().parse(file, type, getXmlOptions(options)); + InputStream is = file.openStream(); + try { + return parse(is, type, options); + } finally { + is.close(); + } } public static XmlObject parse(InputStream jiois, SchemaType type, XmlOptions options) throws XmlException, IOException { - return XmlBeans.getContextTypeLoader().parse(jiois, type, getXmlOptions(options)); + try { + Document doc = DocumentHelper.readDocument(jiois); + return XmlBeans.getContextTypeLoader().parse(doc.getDocumentElement(), type, getXmlOptions(options)); + } catch (SAXException e) { + throw new IOException("Unable to parse xml bean", e); + } } public static XmlObject parse(XMLStreamReader xsr, SchemaType type, XmlOptions options) throws XmlException { @@ -97,7 +125,12 @@ public class POIXMLTypeLoader { } public static XmlObject parse(Reader jior, SchemaType type, XmlOptions options) throws XmlException, IOException { - return XmlBeans.getContextTypeLoader().parse(jior, type, getXmlOptions(options)); + try { + Document doc = DocumentHelper.readDocument(new InputSource(jior)); + return XmlBeans.getContextTypeLoader().parse(doc.getDocumentElement(), type, getXmlOptions(options)); + } catch (SAXException e) { + throw new XmlException("Unable to parse xml bean", e); + } } public static XmlObject parse(Node node, SchemaType type, XmlOptions options) throws XmlException { @@ -107,8 +140,8 @@ public class POIXMLTypeLoader { public static XmlObject parse(XMLInputStream xis, SchemaType type, XmlOptions options) throws XmlException, XMLStreamException { return XmlBeans.getContextTypeLoader().parse(xis, type, getXmlOptions(options)); } - - public static XMLInputStream newValidatingXMLInputStream ( XMLInputStream xis, SchemaType type, XmlOptions options ) throws XmlException, XMLStreamException { + + public static XMLInputStream newValidatingXMLInputStream(XMLInputStream xis, SchemaType type, XmlOptions options) throws XmlException, XMLStreamException { return XmlBeans.getContextTypeLoader().newValidatingXMLInputStream(xis, type, getXmlOptions(options)); } } diff --git a/fine-poi/src/com/fr/third/v2/org/apache/poi/util/DocumentHelper.java b/fine-poi/src/com/fr/third/v2/org/apache/poi/util/DocumentHelper.java index f6d7b5bb1..d9bba2eb8 100644 --- a/fine-poi/src/com/fr/third/v2/org/apache/poi/util/DocumentHelper.java +++ b/fine-poi/src/com/fr/third/v2/org/apache/poi/util/DocumentHelper.java @@ -29,12 +29,55 @@ import javax.xml.stream.events.Namespace; import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.xml.sax.ErrorHandler; +import org.xml.sax.InputSource; import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; public final class DocumentHelper { private static POILogger logger = POILogFactory.getLogger(DocumentHelper.class); - private DocumentHelper() {} + private DocumentHelper() { + } + + private static class DocHelperErrorHandler implements ErrorHandler { + + public void warning(SAXParseException exception) throws SAXException { + printError(POILogger.WARN, exception); + } + + public void error(SAXParseException exception) throws SAXException { + printError(POILogger.ERROR, exception); + } + + public void fatalError(SAXParseException exception) throws SAXException { + printError(POILogger.FATAL, exception); + throw exception; + } + + /** + * Prints the error message. + */ + private void printError(int type, SAXParseException ex) { + StringBuilder sb = new StringBuilder(); + + String systemId = ex.getSystemId(); + if (systemId != null) { + int index = systemId.lastIndexOf('/'); + if (index != -1) + systemId = systemId.substring(index + 1); + sb.append(systemId); + } + sb.append(':'); + sb.append(ex.getLineNumber()); + sb.append(':'); + sb.append(ex.getColumnNumber()); + sb.append(": "); + sb.append(ex.getMessage()); + + logger.log(type, sb.toString(), ex); + } + } /** * Creates a new document builder, with sensible defaults @@ -43,6 +86,7 @@ public final class DocumentHelper { try { DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); documentBuilder.setEntityResolver(SAXHelper.IGNORING_ENTITY_RESOLVER); + documentBuilder.setErrorHandler(new DocHelperErrorHandler()); return documentBuilder; } catch (ParserConfigurationException e) { throw new IllegalStateException("cannot create a DocumentBuilder", e); @@ -50,6 +94,7 @@ public final class DocumentHelper { } private static final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + static { documentBuilderFactory.setNamespaceAware(true); documentBuilderFactory.setValidating(false); @@ -66,10 +111,10 @@ public final class DocumentHelper { logger.log(POILogger.WARN, "Cannot set SAX feature because outdated XML parser in classpath", feature, ame); } } - + private static void trySetXercesSecurityManager(DocumentBuilderFactory documentBuilderFactory) { // Try built-in JVM one first, standalone if not - for (String securityManagerClassName : new String[] { + for (String securityManagerClassName : new String[]{ "com.sun.org.apache.xerces.internal.util.SecurityManager", "org.apache.xerces.util.SecurityManager" }) { @@ -89,13 +134,25 @@ public final class DocumentHelper { /** * Parses the given stream via the default (sensible) * DocumentBuilder + * * @param inp Stream to read the XML data from - * @return the parsed Document + * @return the parsed Document */ public static Document readDocument(InputStream inp) throws IOException, SAXException { return newDocumentBuilder().parse(inp); } + /** + * Parses the given stream via the default (sensible) + * DocumentBuilder + * + * @param inp sax source to read the XML data from + * @return the parsed Document + */ + public static Document readDocument(InputSource inp) throws IOException, SAXException { + return newDocumentBuilder().parse(inp); + } + // must only be used to create empty documents, do not use it for parsing! private static final DocumentBuilder documentBuilderSingleton = newDocumentBuilder(); diff --git a/fine-quartz/src/com/fr/third/v2/org/quartz/jobs/ee/ejb/EJB3InvokerJob.java b/fine-quartz/src/com/fr/third/v2/org/quartz/jobs/ee/ejb/EJB3InvokerJob.java deleted file mode 100644 index b24a16182..000000000 --- a/fine-quartz/src/com/fr/third/v2/org/quartz/jobs/ee/ejb/EJB3InvokerJob.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.fr.third.v2.org.quartz.jobs.ee.ejb; - -import java.lang.reflect.InvocationTargetException; - -import javax.naming.InitialContext; -import javax.naming.NamingException; - -import com.fr.third.v2.org.quartz.JobDataMap; -import com.fr.third.v2.org.quartz.JobExecutionContext; -import com.fr.third.v2.org.quartz.JobExecutionException; - -/** - *

- * A Job that invokes a method on an EJB3. - *

- * - *

- * Expects the properties corresponding to the following keys to be in the - * JobDataMap when it executes: - *

    - *
  • EJB_JNDI_NAME_KEY- the JNDI name (location) of the EJB's - * home interface.
  • - *
  • EJB_METHOD_KEY- the name of the method to invoke on the EJB. - *
  • - *
  • EJB_ARGS_KEY- an Object[] of the args to pass to the method - * (optional, if left out, there are no arguments).
  • - *
  • EJB_ARG_TYPES_KEY- an Class[] of the types of the args to - * pass to the method (optional, if left out, the types will be derived by - * calling getClass() on each of the arguments).
  • - *
- *
- * The following keys can also be used at need: - *
    - *
  • INITIAL_CONTEXT_FACTORY - the context factory used to build - * the context.
  • - *
  • PROVIDER_URL - the name of the environment property for - * specifying configuration information for the service provider to use.
  • - *
- *

- * - *

- * The result of the EJB method invocation will be available to - * Job/TriggerListeners via - * {@link com.fr.third.v2.org.quartz.JobExecutionContext#getResult()}. - *

- * - * @author hhuynh - * @see {@link EJBInvokerJob} - */ -public class EJB3InvokerJob extends EJBInvokerJob { - - @Override - public void execute(JobExecutionContext context) - throws JobExecutionException { - JobDataMap dataMap = context.getMergedJobDataMap(); - - String ejb = dataMap.getString(EJB_JNDI_NAME_KEY); - String method = dataMap.getString(EJB_METHOD_KEY); - - Object[] arguments = (Object[]) dataMap.get(EJB_ARGS_KEY); - if (arguments == null) { - arguments = new Object[0]; - } - if (ejb == null) { - throw new JobExecutionException("must specify EJB_JNDI_NAME_KEY"); - } - if (method == null) { - throw new JobExecutionException("must specify EJB_METHOD_KEY"); - } - - InitialContext jndiContext = null; - Object value = null; - try { - try { - jndiContext = getInitialContext(dataMap); - value = jndiContext.lookup(ejb); - } catch (NamingException ne) { - throw new JobExecutionException(ne); - } - - Class[] argTypes = (Class[]) dataMap.get(EJB_ARG_TYPES_KEY); - if (argTypes == null) { - argTypes = new Class[arguments.length]; - for (int i = 0; i < arguments.length; i++) { - argTypes[i] = arguments[i].getClass(); - } - } - - try { - Object returnValue = value.getClass() - .getMethod(method, argTypes).invoke(value, arguments); - context.setResult(returnValue); - } catch (IllegalAccessException iae) { - throw new JobExecutionException(iae); - } catch (InvocationTargetException ite) { - throw new JobExecutionException(ite.getTargetException()); - } catch (NoSuchMethodException nsme) { - throw new JobExecutionException(nsme); - } - } finally { - if (jndiContext != null) { - try { - jndiContext.close(); - } catch (Exception e) { - // ignored - } - } - } - } -} diff --git a/fine-quartz/src/com/fr/third/v2/org/quartz/jobs/ee/ejb/EJBInvokerJob.java b/fine-quartz/src/com/fr/third/v2/org/quartz/jobs/ee/ejb/EJBInvokerJob.java deleted file mode 100644 index 68d5ba7a2..000000000 --- a/fine-quartz/src/com/fr/third/v2/org/quartz/jobs/ee/ejb/EJBInvokerJob.java +++ /dev/null @@ -1,277 +0,0 @@ -/* - * All content copyright Terracotta, Inc., unless otherwise indicated. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy - * of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - */ - -package com.fr.third.v2.org.quartz.jobs.ee.ejb; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.rmi.RemoteException; -import java.util.Hashtable; - -import javax.ejb.EJBHome; -import javax.ejb.EJBMetaData; -import javax.ejb.EJBObject; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import javax.rmi.PortableRemoteObject; - -import com.fr.third.v2.org.quartz.Job; -import com.fr.third.v2.org.quartz.JobDataMap; -import com.fr.third.v2.org.quartz.JobExecutionContext; -import com.fr.third.v2.org.quartz.JobExecutionException; - -/** - *

- * A Job that invokes a method on an EJB. - *

- * - *

- * Expects the properties corresponding to the following keys to be in the - * JobDataMap when it executes: - *

    - *
  • EJB_JNDI_NAME_KEY- the JNDI name (location) of the - * EJB's home interface.
  • - *
  • EJB_METHOD_KEY- the name of the method to invoke on the - * EJB.
  • - *
  • EJB_ARGS_KEY- an Object[] of the args to pass to the - * method (optional, if left out, there are no arguments).
  • - *
  • EJB_ARG_TYPES_KEY- an Class[] of the types of the args to - * pass to the method (optional, if left out, the types will be derived by - * calling getClass() on each of the arguments).
  • - *
- *
- * The following keys can also be used at need: - *
    - *
  • INITIAL_CONTEXT_FACTORY - the context factory used to - * build the context.
  • - *
  • PROVIDER_URL - the name of the environment property - * for specifying configuration information for the service provider to use. - *
  • - *
- *

- * - *

- * The result of the EJB method invocation will be available to - * Job/TriggerListeners via - * {@link com.fr.third.v2.org.quartz.JobExecutionContext#getResult()}. - *

- * - * @author Andrew Collins - * @author James House - * @author Joel Shellman - * @author Chris Bonham - */ -public class EJBInvokerJob implements Job { - - /* - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * - * Constants. - * - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - */ - - public static final String EJB_JNDI_NAME_KEY = "ejb"; - - public static final String EJB_METHOD_KEY = "method"; - - public static final String EJB_ARG_TYPES_KEY = "argTypes"; - - public static final String EJB_ARGS_KEY = "args"; - - public static final String INITIAL_CONTEXT_FACTORY = "java.naming.factory.initial"; - - public static final String PROVIDER_URL = "java.naming.provider.url"; - - public static final String PRINCIPAL = "java.naming.security.principal"; - - public static final String CREDENTIALS = "java.naming.security.credentials"; - - - /* - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * - * Constructors. - * - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - */ - - public EJBInvokerJob() { - // nothing - } - - /* - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * - * Interface. - * - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - */ - - public void execute(JobExecutionContext context) - throws JobExecutionException { - JobDataMap dataMap = context.getMergedJobDataMap(); - - String ejb = dataMap.getString(EJB_JNDI_NAME_KEY); - String method = dataMap.getString(EJB_METHOD_KEY); - Object[] arguments = (Object[]) dataMap.get(EJB_ARGS_KEY); - if (arguments == null) { - arguments = new Object[0]; - } - - if (ejb == null) { - // must specify remote home - throw new JobExecutionException(); - } - - InitialContext jndiContext = null; - - // get initial context - try { - jndiContext = getInitialContext(dataMap); - } catch (NamingException ne) { - throw new JobExecutionException(ne); - } - - try { - Object value = null; - - // locate home interface - try { - value = jndiContext.lookup(ejb); - } catch (NamingException ne) { - throw new JobExecutionException(ne); - } - - // get home interface - EJBHome ejbHome = (EJBHome) PortableRemoteObject.narrow(value, - EJBHome.class); - - // get meta data - EJBMetaData metaData = null; - - try { - metaData = ejbHome.getEJBMetaData(); - } catch (RemoteException re) { - throw new JobExecutionException(re); - } - - // get home interface class - Class homeClass = metaData.getHomeInterfaceClass(); - - // get remote interface class - Class remoteClass = metaData.getRemoteInterfaceClass(); - - // get home interface - ejbHome = (EJBHome) PortableRemoteObject.narrow(ejbHome, homeClass); - - Method methodCreate = null; - - try { - // create method 'create()' on home interface - methodCreate = homeClass.getMethod("create", ((Class[])null)); - } catch (NoSuchMethodException nsme) { - throw new JobExecutionException(nsme); - } - - // create remote object - EJBObject remoteObj = null; - - try { - // invoke 'create()' method on home interface - remoteObj = (EJBObject) methodCreate.invoke(ejbHome, ((Object[])null)); - } catch (IllegalAccessException iae) { - throw new JobExecutionException(iae); - } catch (InvocationTargetException ite) { - throw new JobExecutionException(ite); - } - - // execute user-specified method on remote object - Method methodExecute = null; - - try { - // create method signature - - Class[] argTypes = (Class[]) dataMap.get(EJB_ARG_TYPES_KEY); - if (argTypes == null) { - argTypes = new Class[arguments.length]; - for (int i = 0; i < arguments.length; i++) { - argTypes[i] = arguments[i].getClass(); - } - } - - // get method on remote object - methodExecute = remoteClass.getMethod(method, argTypes); - } catch (NoSuchMethodException nsme) { - throw new JobExecutionException(nsme); - } - - try { - // invoke user-specified method on remote object - Object returnObj = methodExecute.invoke(remoteObj, arguments); - - // Return any result in the JobExecutionContext so it will be - // available to Job/TriggerListeners - context.setResult(returnObj); - } catch (IllegalAccessException iae) { - throw new JobExecutionException(iae); - } catch (InvocationTargetException ite) { - throw new JobExecutionException(ite); - } - } finally { - // Don't close jndiContext until after method execution because - // WebLogic requires context to be open to keep the user credentials - // available. See JIRA Issue: QUARTZ-401 - if (jndiContext != null) { - try { - jndiContext.close(); - } catch (NamingException e) { - // Ignore any errors closing the initial context - } - } - } - } - - protected InitialContext getInitialContext(JobDataMap jobDataMap) - throws NamingException { - Hashtable params = new Hashtable(2); - - String initialContextFactory = - jobDataMap.getString(INITIAL_CONTEXT_FACTORY); - if (initialContextFactory != null) { - params.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory); - } - - String providerUrl = jobDataMap.getString(PROVIDER_URL); - if (providerUrl != null) { - params.put(Context.PROVIDER_URL, providerUrl); - } - - String principal = jobDataMap.getString(PRINCIPAL); - if ( principal != null ) { - params.put( Context.SECURITY_PRINCIPAL, principal ); - } - - String credentials = jobDataMap.getString(CREDENTIALS); - if ( credentials != null ) { - params.put( Context.SECURITY_CREDENTIALS, credentials ); - } - - return (params.size() == 0) ? new InitialContext() : new InitialContext(params); - } -} \ No newline at end of file diff --git a/fine-quartz/src/com/fr/third/v2/org/quartz/xml/XMLSchedulingDataProcessor.java b/fine-quartz/src/com/fr/third/v2/org/quartz/xml/XMLSchedulingDataProcessor.java index b70a3992d..8bd0e53fa 100644 --- a/fine-quartz/src/com/fr/third/v2/org/quartz/xml/XMLSchedulingDataProcessor.java +++ b/fine-quartz/src/com/fr/third/v2/org/quartz/xml/XMLSchedulingDataProcessor.java @@ -203,7 +203,7 @@ public class XMLSchedulingDataProcessor implements ErrorHandler { return XMLConstants.NULL_NS_URI; } - public Iterator getPrefixes(String namespaceURI) + public Iterator getPrefixes(String namespaceURI) { // This method isn't necessary for XPath processing. throw new UnsupportedOperationException(); diff --git a/fine-spring/src/com/fr/third/springframework/aop/framework/ObjenesisCglibAopProxy.java b/fine-spring/src/com/fr/third/springframework/aop/framework/ObjenesisCglibAopProxy.java index c26d3d1e5..3f8c40cde 100644 --- a/fine-spring/src/com/fr/third/springframework/aop/framework/ObjenesisCglibAopProxy.java +++ b/fine-spring/src/com/fr/third/springframework/aop/framework/ObjenesisCglibAopProxy.java @@ -16,8 +16,8 @@ package com.fr.third.springframework.aop.framework; -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.ObjenesisStd; +import com.fr.third.org.objenesis.ObjenesisException; +import com.fr.third.org.objenesis.ObjenesisStd; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.fr.third.springframework.cglib.proxy.Callback; diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/Objenesis.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/Objenesis.java deleted file mode 100644 index 402c72ea2..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/Objenesis.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis; - -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; - -/** - * Common interface to all kind of Objenesis objects - * - * @author Henri Tremblay - */ -public interface Objenesis { - - /** - * Will create a new object without any constructor being called - * - * @param Type instantiated - * @param clazz Class to instantiate - * @return New instance of clazz - */ - T newInstance(Class clazz); - - /** - * Will pick the best instantiator for the provided class. If you need to create a lot of - * instances from the same class, it is way more efficient to create them from the same - * ObjectInstantiator than calling {@link #newInstance(Class)}. - * - * @param Type to instantiate - * @param clazz Class to instantiate - * @return Instantiator dedicated to the class - */ - ObjectInstantiator getInstantiatorOf(Class clazz); -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisBase.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisBase.java deleted file mode 100644 index c34690c95..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisBase.java +++ /dev/null @@ -1,102 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis; - -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.strategy.InstantiatorStrategy; - -import java.util.concurrent.ConcurrentHashMap; - -/** - * Base class to extend if you want to have a class providing your own default strategy. Can also be - * instantiated directly. - * - * @author Henri Tremblay - */ -public class ObjenesisBase implements Objenesis { - - /** Strategy used by this Objenesi implementation to create classes */ - protected final InstantiatorStrategy strategy; - - /** Strategy cache. Key = Class, Value = InstantiatorStrategy */ - protected ConcurrentHashMap> cache; - - /** - * Constructor allowing to pick a strategy and using cache - * - * @param strategy Strategy to use - */ - public ObjenesisBase(InstantiatorStrategy strategy) { - this(strategy, true); - } - - /** - * Flexible constructor allowing to pick the strategy and if caching should be used - * - * @param strategy Strategy to use - * @param useCache If {@link ObjectInstantiator}s should be cached - */ - public ObjenesisBase(InstantiatorStrategy strategy, boolean useCache) { - if(strategy == null) { - throw new IllegalArgumentException("A strategy can't be null"); - } - this.strategy = strategy; - this.cache = useCache ? new ConcurrentHashMap>() : null; - } - - @Override - public String toString() { - return getClass().getName() + " using " + strategy.getClass().getName() - + (cache == null ? " without" : " with") + " caching"; - } - - /** - * Will create a new object without any constructor being called - * - * @param clazz Class to instantiate - * @return New instance of clazz - */ - public T newInstance(Class clazz) { - return getInstantiatorOf(clazz).newInstance(); - } - - /** - * Will pick the best instantiator for the provided class. If you need to create a lot of - * instances from the same class, it is way more efficient to create them from the same - * ObjectInstantiator than calling {@link #newInstance(Class)}. - * - * @param clazz Class to instantiate - * @return Instantiator dedicated to the class - */ - @SuppressWarnings("unchecked") - public ObjectInstantiator getInstantiatorOf(Class clazz) { - if(clazz.isPrimitive()) { - throw new IllegalArgumentException("Primitive types can't be instantiated in Java"); - } - if(cache == null) { - return strategy.newInstantiatorOf(clazz); - } - ObjectInstantiator instantiator = cache.get(clazz.getName()); - if(instantiator == null) { - ObjectInstantiator newInstantiator = strategy.newInstantiatorOf(clazz); - instantiator = cache.putIfAbsent(clazz.getName(), newInstantiator); - if(instantiator == null) { - instantiator = newInstantiator; - } - } - return (ObjectInstantiator) instantiator; - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisException.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisException.java deleted file mode 100644 index 682c45562..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisException.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis; - -/** - * Exception thrown by Objenesis. It wraps any instantiation exceptions. Note that this exception is - * runtime to prevent having to catch it. - * - * @author Henri Tremblay - */ -public class ObjenesisException extends RuntimeException { - - private static final long serialVersionUID = -2677230016262426968L; - - /** - * @param msg Error message - */ - public ObjenesisException(String msg) { - super(msg); - } - - /** - * @param cause Wrapped exception. The message will be the one of the cause. - */ - public ObjenesisException(Throwable cause) { - super(cause); - } - - /** - * @param msg Error message - * @param cause Wrapped exception - */ - public ObjenesisException(String msg, Throwable cause) { - super(msg, cause); - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisHelper.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisHelper.java deleted file mode 100644 index 3d0c81483..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisHelper.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis; - -import java.io.Serializable; - -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; - -/** - * Use Objenesis in a static way. It is strongly not recommended to use this class. - * - * @author Henri Tremblay - */ -public final class ObjenesisHelper { - - private static final Objenesis OBJENESIS_STD = new ObjenesisStd(); - - private static final Objenesis OBJENESIS_SERIALIZER = new ObjenesisSerializer(); - - private ObjenesisHelper() { - } - - /** - * Will create a new object without any constructor being called - * - * @param Type instantiated - * @param clazz Class to instantiate - * @return New instance of clazz - */ - public static T newInstance(Class clazz) { - return OBJENESIS_STD.newInstance(clazz); - } - - /** - * Will create an object just like it's done by ObjectInputStream.readObject (the default - * constructor of the first non serializable class will be called) - * - * @param Type instantiated - * @param clazz Class to instantiate - * @return New instance of clazz - */ - public static T newSerializableInstance(Class clazz) { - return (T) OBJENESIS_SERIALIZER.newInstance(clazz); - } - - /** - * Will pick the best instantiator for the provided class. If you need to create a lot of - * instances from the same class, it is way more efficient to create them from the same - * ObjectInstantiator than calling {@link #newInstance(Class)}. - * - * @param Type to instantiate - * @param clazz Class to instantiate - * @return Instantiator dedicated to the class - */ - public static ObjectInstantiator getInstantiatorOf(Class clazz) { - return OBJENESIS_STD.getInstantiatorOf(clazz); - } - - /** - * Same as {@link #getInstantiatorOf(Class)} but providing an instantiator emulating - * ObjectInputStream.readObject behavior. - * - * @see #newSerializableInstance(Class) - * @param Type to instantiate - * @param clazz Class to instantiate - * @return Instantiator dedicated to the class - */ - public static ObjectInstantiator getSerializableObjectInstantiatorOf(Class clazz) { - return OBJENESIS_SERIALIZER.getInstantiatorOf(clazz); - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisSerializer.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisSerializer.java deleted file mode 100644 index b300c9d15..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisSerializer.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis; - -import com.fr.third.springframework.aop.objenesis.strategy.SerializingInstantiatorStrategy; - -/** - * Objenesis implementation using the {@link SerializingInstantiatorStrategy}. - * - * @author Henri Tremblay - */ -public class ObjenesisSerializer extends ObjenesisBase { - - /** - * Default constructor using the {@link com.fr.third.springframework.aop.objenesis.strategy.SerializingInstantiatorStrategy} - */ - public ObjenesisSerializer() { - super(new SerializingInstantiatorStrategy()); - } - - /** - * Instance using the {@link com.fr.third.springframework.aop.objenesis.strategy.SerializingInstantiatorStrategy} with or without caching - * {@link com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator}s - * - * @param useCache If {@link com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator}s should be cached - */ - public ObjenesisSerializer(boolean useCache) { - super(new SerializingInstantiatorStrategy(), useCache); - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisStd.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisStd.java deleted file mode 100644 index e7c1d3493..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/ObjenesisStd.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis; - -import com.fr.third.springframework.aop.objenesis.strategy.StdInstantiatorStrategy; - -/** - * Objenesis implementation using the {@link com.fr.third.springframework.aop.objenesis.strategy.StdInstantiatorStrategy}. - * - * @author Henri Tremblay - */ -public class ObjenesisStd extends ObjenesisBase { - - /** - * Default constructor using the {@link com.fr.third.springframework.aop.objenesis.strategy.StdInstantiatorStrategy} - */ - public ObjenesisStd() { - super(new StdInstantiatorStrategy()); - } - - /** - * Instance using the {@link com.fr.third.springframework.aop.objenesis.strategy.StdInstantiatorStrategy} with or without - * caching {@link com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator}s - * - * @param useCache If {@link com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator}s should be cached - */ - public ObjenesisStd(boolean useCache) { - super(new StdInstantiatorStrategy(), useCache); - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/ObjectInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/ObjectInstantiator.java deleted file mode 100644 index c18b2fe1e..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/ObjectInstantiator.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator; - -/** - * Instantiates a new object. - * - * @author Leonardo Mesquita - */ -public interface ObjectInstantiator { - - /** - * Returns a new instance of an object. The returned object's class is defined by the - * implementation. - * - * @return A new instance of an object. - */ - T newInstance(); - -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/SerializationInstantiatorHelper.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/SerializationInstantiatorHelper.java deleted file mode 100644 index 515b69cbe..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/SerializationInstantiatorHelper.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator; - -import java.io.Serializable; - -/** - * Helper for common serialization-compatible instantiation functions - * - * @author Leonardo Mesquita - */ -public class SerializationInstantiatorHelper { - - /** - * Returns the first non-serializable superclass of a given class. According to Java Object - * Serialization Specification, objects read from a stream are initialized by calling an - * accessible no-arg constructor from the first non-serializable superclass in the object's - * hierarchy, allowing the state of non-serializable fields to be correctly initialized. - * - * @param Type to instantiate - * @param type Serializable class for which the first non-serializable superclass is to be found - * @return The first non-serializable superclass of 'type'. - * @see Serializable - */ - public static Class getNonSerializableSuperClass(Class type) { - Class result = type; - while(Serializable.class.isAssignableFrom(result)) { - result = result.getSuperclass(); - if(result == null) { - throw new Error("Bad class hierarchy: No non-serializable parents"); - } - } - return result; - - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/Android10Instantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/Android10Instantiator.java deleted file mode 100644 index 5795e702b..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/Android10Instantiator.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.android; - -import java.io.ObjectInputStream; -import java.lang.reflect.Method; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiator for Android API level 10 and lover which creates objects without driving their - * constructors, using internal methods on the Dalvik implementation of - * {@link ObjectInputStream}. - * - * @author Piotr 'Qertoip' Włodarek - */ -@Instantiator(Typology.STANDARD) -public class Android10Instantiator implements ObjectInstantiator { - private final Class type; - private final Method newStaticMethod; - - public Android10Instantiator(Class type) { - this.type = type; - newStaticMethod = getNewStaticMethod(); - } - - public T newInstance() { - try { - return type.cast(newStaticMethod.invoke(null, type, Object.class)); - } - catch(Exception e) { - throw new ObjenesisException(e); - } - } - - private static Method getNewStaticMethod() { - try { - Method newStaticMethod = ObjectInputStream.class.getDeclaredMethod( - "newInstance", Class.class, Class.class); - newStaticMethod.setAccessible(true); - return newStaticMethod; - } - catch(RuntimeException e) { - throw new ObjenesisException(e); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - } - -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/Android17Instantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/Android17Instantiator.java deleted file mode 100644 index 36d9b8b0c..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/Android17Instantiator.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.android; - -import java.io.ObjectStreamClass; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiator for Android API level 11 to 17 which creates objects without driving their - * constructors, using internal methods on the Dalvik implementation of {@link ObjectStreamClass}. - * - * @author Ian Parkinson (Google Inc.) - */ -@Instantiator(Typology.STANDARD) -public class Android17Instantiator implements ObjectInstantiator { - private final Class type; - private final Method newInstanceMethod; - private final Integer objectConstructorId; - - public Android17Instantiator(Class type) { - this.type = type; - newInstanceMethod = getNewInstanceMethod(); - objectConstructorId = findConstructorIdForJavaLangObjectConstructor(); - } - - public T newInstance() { - try { - return type.cast(newInstanceMethod.invoke(null, type, objectConstructorId)); - } - catch(Exception e) { - throw new ObjenesisException(e); - } - } - - private static Method getNewInstanceMethod() { - try { - Method newInstanceMethod = ObjectStreamClass.class.getDeclaredMethod( - "newInstance", Class.class, Integer.TYPE); - newInstanceMethod.setAccessible(true); - return newInstanceMethod; - } - catch(RuntimeException e) { - throw new ObjenesisException(e); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - } - - private static Integer findConstructorIdForJavaLangObjectConstructor() { - try { - Method newInstanceMethod = ObjectStreamClass.class.getDeclaredMethod( - "getConstructorId", Class.class); - newInstanceMethod.setAccessible(true); - - return (Integer) newInstanceMethod.invoke(null, Object.class); - } - catch(RuntimeException e) { - throw new ObjenesisException(e); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - catch(IllegalAccessException e) { - throw new ObjenesisException(e); - } - catch(InvocationTargetException e) { - throw new ObjenesisException(e); - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/Android18Instantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/Android18Instantiator.java deleted file mode 100644 index 81957ace2..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/Android18Instantiator.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.android; - -import java.io.ObjectStreamClass; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiator for Android API leve 18 and higher. Same as the version 17 but the - * newInstance now takes a long in parameter - * - * @author Henri Tremblay - */ -@Instantiator(Typology.STANDARD) -public class Android18Instantiator implements ObjectInstantiator { - private final Class type; - private final Method newInstanceMethod; - private final Long objectConstructorId; - - public Android18Instantiator(Class type) { - this.type = type; - newInstanceMethod = getNewInstanceMethod(); - objectConstructorId = findConstructorIdForJavaLangObjectConstructor(); - } - - public T newInstance() { - try { - return type.cast(newInstanceMethod.invoke(null, type, objectConstructorId)); - } - catch(Exception e) { - throw new ObjenesisException(e); - } - } - - private static Method getNewInstanceMethod() { - try { - Method newInstanceMethod = ObjectStreamClass.class.getDeclaredMethod("newInstance", - Class.class, Long.TYPE); - newInstanceMethod.setAccessible(true); - return newInstanceMethod; - } - catch(RuntimeException e) { - throw new ObjenesisException(e); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - } - - private static Long findConstructorIdForJavaLangObjectConstructor() { - try { - Method newInstanceMethod = ObjectStreamClass.class.getDeclaredMethod("getConstructorId", - Class.class); - newInstanceMethod.setAccessible(true); - - return (Long) newInstanceMethod.invoke(null, Object.class); - } - catch(RuntimeException e) { - throw new ObjenesisException(e); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - catch(IllegalAccessException e) { - throw new ObjenesisException(e); - } - catch(InvocationTargetException e) { - throw new ObjenesisException(e); - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/AndroidSerializationInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/AndroidSerializationInstantiator.java deleted file mode 100644 index 6dd9a25d2..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/android/AndroidSerializationInstantiator.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.android; - -import java.io.ObjectStreamClass; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * {@link ObjectInstantiator} for Android which creates objects using the constructor from the first - * non-serializable parent class constructor, using internal methods on the Dalvik implementation of - * {@link ObjectStreamClass}. - * - * @author Ian Parkinson (Google Inc.) - */ -@Instantiator(Typology.SERIALIZATION) -public class AndroidSerializationInstantiator implements ObjectInstantiator { - private final Class type; - private final ObjectStreamClass objectStreamClass; - private final Method newInstanceMethod; - - public AndroidSerializationInstantiator(Class type) { - this.type = type; - newInstanceMethod = getNewInstanceMethod(); - Method m = null; - try { - m = ObjectStreamClass.class.getMethod("lookupAny", Class.class); - } catch (NoSuchMethodException e) { - throw new ObjenesisException(e); - } - try { - objectStreamClass = (ObjectStreamClass) m.invoke(null, type); - } catch (IllegalAccessException e) { - throw new ObjenesisException(e); - } catch (InvocationTargetException e) { - throw new ObjenesisException(e); - } - } - - public T newInstance() { - try { - return type.cast(newInstanceMethod.invoke(objectStreamClass, type)); - } - catch(IllegalAccessException e) { - throw new ObjenesisException(e); - } - catch(IllegalArgumentException e) { - throw new ObjenesisException(e); - } - catch(InvocationTargetException e) { - throw new ObjenesisException(e); - } - } - - private static Method getNewInstanceMethod() { - try { - Method newInstanceMethod = ObjectStreamClass.class.getDeclaredMethod( - "newInstance", Class.class); - newInstanceMethod.setAccessible(true); - return newInstanceMethod; - } - catch(RuntimeException e) { - throw new ObjenesisException(e); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/annotations/Instantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/annotations/Instantiator.java deleted file mode 100644 index de8a7c8b0..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/annotations/Instantiator.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.annotations; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Denote that the class in an instantiator of a given type - * - * @author Henri Tremblay - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface Instantiator { - - /** - * @return type of instantiator - */ - Typology value(); -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/annotations/Typology.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/annotations/Typology.java deleted file mode 100644 index 2e2512768..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/annotations/Typology.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.annotations; - -/** - * Possible types of instantiator - * @author Henri Tremblay - */ -public enum Typology { - /** - * Mark an instantiator used for standard instantiation (not calling a constructor). - */ - STANDARD, - - /** - * Mark an instantiator used for serialization. - */ - SERIALIZATION, - - /** - * Mark an instantiator that doesn't behave like a {@link #STANDARD} nor a {@link #SERIALIZATION} (e.g. calls a constructor, fails - * all the time, etc.) - */ - NOT_COMPLIANT, - - /** - * No type specified on the instantiator class - */ - UNKNOWN -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/AccessibleInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/AccessibleInstantiator.java deleted file mode 100644 index 759538927..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/AccessibleInstantiator.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.basic; - -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiates a class by grabbing the no-args constructor, making it accessible and then calling - * Constructor.newInstance(). Although this still requires no-arg constructors, it can call - * non-public constructors (if the security manager allows it). - * - * @author Joe Walnes - * @see com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator - */ -@Instantiator(Typology.NOT_COMPLIANT) -public class AccessibleInstantiator extends ConstructorInstantiator { - - public AccessibleInstantiator(Class type) { - super(type); - if(constructor != null) { - constructor.setAccessible(true); - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ConstructorInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ConstructorInstantiator.java deleted file mode 100644 index 5a7fbb0dd..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ConstructorInstantiator.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.basic; - -import java.lang.reflect.Constructor; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiates a class by grabbing the no args constructor and calling Constructor.newInstance(). - * This can deal with default public constructors, but that's about it. - * - * @author Joe Walnes - * @param Type instantiated - * @see ObjectInstantiator - */ -@Instantiator(Typology.NOT_COMPLIANT) -public class ConstructorInstantiator implements ObjectInstantiator { - - protected Constructor constructor; - - public ConstructorInstantiator(Class type) { - try { - constructor = type.getDeclaredConstructor((Class[]) null); - } - catch(Exception e) { - throw new ObjenesisException(e); - } - } - - public T newInstance() { - try { - return constructor.newInstance((Object[]) null); - } - catch(Exception e) { - throw new ObjenesisException(e); - } - } - -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/FailingInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/FailingInstantiator.java deleted file mode 100644 index 9807425ed..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/FailingInstantiator.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.basic; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * The instantiator that always throws an exception. Mainly used for tests - * - * @author Henri Tremblay - */ -@Instantiator(Typology.NOT_COMPLIANT) -public class FailingInstantiator implements ObjectInstantiator { - - public FailingInstantiator(Class type) { - } - - /** - * @return Always throwing an exception - */ - public T newInstance() { - throw new ObjenesisException("Always failing"); - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/NewInstanceInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/NewInstanceInstantiator.java deleted file mode 100644 index d7e0c730d..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/NewInstanceInstantiator.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.basic; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * The simplest instantiator - simply calls Class.newInstance(). This can deal with default public - * constructors, but that's about it. - * - * @author Joe Walnes - * @see ObjectInstantiator - */ -@Instantiator(Typology.NOT_COMPLIANT) -public class NewInstanceInstantiator implements ObjectInstantiator { - - private final Class type; - - public NewInstanceInstantiator(Class type) { - this.type = type; - } - - public T newInstance() { - try { - return type.newInstance(); - } - catch(Exception e) { - throw new ObjenesisException(e); - } - } - -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/NullInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/NullInstantiator.java deleted file mode 100644 index 24960ab3c..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/NullInstantiator.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.basic; - -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * The instantiator that always return a null instance - * - * @author Henri Tremblay - */ -@Instantiator(Typology.NOT_COMPLIANT) -public class NullInstantiator implements ObjectInstantiator { - - public NullInstantiator(Class type) { - } - - /** - * @return Always null - */ - public T newInstance() { - return null; - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ObjectInputStreamInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ObjectInputStreamInstantiator.java deleted file mode 100644 index ee1aa4dc0..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ObjectInputStreamInstantiator.java +++ /dev/null @@ -1,186 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.basic; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.NotSerializableException; -import java.io.ObjectInputStream; -import java.io.ObjectStreamClass; -import java.io.ObjectStreamConstants; -import java.io.Serializable; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiates a class by using a dummy input stream that always feeds data for an empty object of - * the same kind. NOTE: This instantiator may not work properly if the class being instantiated - * defines a "readResolve" method, since it may return objects that have been returned previously - * (i.e., there's no guarantee that the returned object is a new one), or even objects from a - * completely different class. - * - * @author Leonardo Mesquita - * @see com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator - */ -@Instantiator(Typology.SERIALIZATION) -public class ObjectInputStreamInstantiator implements ObjectInstantiator { - private static class MockStream extends InputStream { - - private int pointer; - private byte[] data; - private int sequence; - private static final int[] NEXT = new int[] {1, 2, 2}; - private byte[][] buffers; - - private final byte[] FIRST_DATA; - private static byte[] HEADER; - private static byte[] REPEATING_DATA; - - static { - initialize(); - } - - private static void initialize() { - try { - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - DataOutputStream dout = new DataOutputStream(byteOut); - dout.writeShort(ObjectStreamConstants.STREAM_MAGIC); - dout.writeShort(ObjectStreamConstants.STREAM_VERSION); - HEADER = byteOut.toByteArray(); - - byteOut = new ByteArrayOutputStream(); - dout = new DataOutputStream(byteOut); - - dout.writeByte(ObjectStreamConstants.TC_OBJECT); - dout.writeByte(ObjectStreamConstants.TC_REFERENCE); - dout.writeInt(ObjectStreamConstants.baseWireHandle); - REPEATING_DATA = byteOut.toByteArray(); - } - catch(IOException e) { - throw new Error("IOException: " + e.getMessage()); - } - - } - - public MockStream(Class clazz) { - this.pointer = 0; - this.sequence = 0; - this.data = HEADER; - - // (byte) TC_OBJECT - // (byte) TC_CLASSDESC - // (short length) - // (byte * className.length) - // (long)serialVersionUID - // (byte) SC_SERIALIZABLE - // (short)0 - // TC_ENDBLOCKDATA - // TC_NULL - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - DataOutputStream dout = new DataOutputStream(byteOut); - try { - dout.writeByte(ObjectStreamConstants.TC_OBJECT); - dout.writeByte(ObjectStreamConstants.TC_CLASSDESC); - dout.writeUTF(clazz.getName()); - dout.writeLong(ObjectStreamClass.lookup(clazz).getSerialVersionUID()); - dout.writeByte(ObjectStreamConstants.SC_SERIALIZABLE); - dout.writeShort((short) 0); // Zero fields - dout.writeByte(ObjectStreamConstants.TC_ENDBLOCKDATA); - dout.writeByte(ObjectStreamConstants.TC_NULL); - } - catch(IOException e) { - throw new Error("IOException: " + e.getMessage()); - } - this.FIRST_DATA = byteOut.toByteArray(); - buffers = new byte[][] {HEADER, FIRST_DATA, REPEATING_DATA}; - } - - private void advanceBuffer() { - pointer = 0; - sequence = NEXT[sequence]; - data = buffers[sequence]; - } - - @Override - public int read() throws IOException { - int result = data[pointer++]; - if(pointer >= data.length) { - advanceBuffer(); - } - - return result; - } - - @Override - public int available() throws IOException { - return Integer.MAX_VALUE; - } - - @Override - public int read(byte[] b, int off, int len) throws IOException { - int left = len; - int remaining = data.length - pointer; - - while(remaining <= left) { - System.arraycopy(data, pointer, b, off, remaining); - off += remaining; - left -= remaining; - advanceBuffer(); - remaining = data.length - pointer; - } - if(left > 0) { - System.arraycopy(data, pointer, b, off, left); - pointer += left; - } - - return len; - } - } - - private ObjectInputStream inputStream; - - public ObjectInputStreamInstantiator(Class clazz) { - if(Serializable.class.isAssignableFrom(clazz)) { - try { - this.inputStream = new ObjectInputStream(new MockStream(clazz)); - } - catch(IOException e) { - throw new Error("IOException: " + e.getMessage()); - } - } - else { - throw new ObjenesisException(new NotSerializableException(clazz + " not serializable")); - } - } - - @SuppressWarnings("unchecked") - public T newInstance() { - try { - return (T) inputStream.readObject(); - } - catch(ClassNotFoundException e) { - throw new Error("ClassNotFoundException: " + e.getMessage()); - } - catch(Exception e) { - throw new ObjenesisException(e); - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ObjectStreamClassInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ObjectStreamClassInstantiator.java deleted file mode 100644 index 74d11c8f4..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ObjectStreamClassInstantiator.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.basic; - -import java.io.ObjectStreamClass; -import java.lang.reflect.Method; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiates a class by using reflection to make a call to private method - * ObjectStreamClass.newInstance, present in many JVM implementations. This instantiator will create - * classes in a way compatible with serialization, calling the first non-serializable superclass' - * no-arg constructor. - * - * @author Leonardo Mesquita - * @see ObjectInstantiator - * @see java.io.Serializable - */ -@Instantiator(Typology.SERIALIZATION) -public class ObjectStreamClassInstantiator implements ObjectInstantiator { - - private static Method newInstanceMethod; - - private static void initialize() { - if(newInstanceMethod == null) { - try { - newInstanceMethod = ObjectStreamClass.class.getDeclaredMethod("newInstance"); - newInstanceMethod.setAccessible(true); - } - catch(RuntimeException e) { - throw new ObjenesisException(e); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - } - } - - private final ObjectStreamClass objStreamClass; - - public ObjectStreamClassInstantiator(Class type) { - initialize(); - objStreamClass = ObjectStreamClass.lookup(type); - } - - @SuppressWarnings("unchecked") - public T newInstance() { - - try { - return (T) newInstanceMethod.invoke(objStreamClass); - } - catch(Exception e) { - throw new ObjenesisException(e); - } - - } - -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ProxyingInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ProxyingInstantiator.java deleted file mode 100644 index 30f55ae59..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/basic/ProxyingInstantiator.java +++ /dev/null @@ -1,193 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.basic; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; -import com.fr.third.springframework.aop.objenesis.instantiator.util.ClassDefinitionUtils; - -import static com.fr.third.springframework.aop.objenesis.instantiator.util.ClassDefinitionUtils.*; - -/** - * This instantiator creates a class by dynamically extending it. It will skip the call to the parent constructor - * in the bytecode. So that the constructor is indeed not called but you however instantiate a child class, not - * the actual class. The class loader will normally throw a {@code VerifyError} is you do that. However, using - * {@code -Xverify:none} should make it work - * - * @author Henri Tremblay - */ -@Instantiator(Typology.STANDARD) -public class ProxyingInstantiator implements ObjectInstantiator { - - private static final int INDEX_CLASS_THIS = 1; - private static final int INDEX_CLASS_SUPERCLASS = 2; - private static final int INDEX_UTF8_CONSTRUCTOR_NAME = 3; - private static final int INDEX_UTF8_CONSTRUCTOR_DESC = 4; - private static final int INDEX_UTF8_CODE_ATTRIBUTE = 5; - private static final int INDEX_UTF8_CLASS = 7; - private static final int INDEX_UTF8_SUPERCLASS = 8; - - private static int CONSTANT_POOL_COUNT = 9; - - private static final byte[] CODE = { OPS_aload_0, OPS_return}; - private static final int CODE_ATTRIBUTE_LENGTH = 12 + CODE.length; - - private static final String SUFFIX = "$$$Objenesis"; - - private static final String CONSTRUCTOR_NAME = ""; - private static final String CONSTRUCTOR_DESC = "()V"; - - private final Class newType; - - public ProxyingInstantiator(Class type) { - - byte[] classBytes = writeExtendingClass(type, SUFFIX); - - try { - newType = ClassDefinitionUtils.defineClass(type.getName() + SUFFIX, classBytes, type.getClassLoader()); - } catch (Exception e) { - throw new ObjenesisException(e); - } - } - - @SuppressWarnings("unchecked") - public T newInstance() { - try { - return (T) newType.newInstance(); - } catch (InstantiationException e) { - throw new ObjenesisException(e); - } catch (IllegalAccessException e) { - throw new ObjenesisException(e); - } - } - - /** - * Will generate the bytes for a class extending the type passed in parameter. This class will - * only have an empty default constructor - * - * @param type type to extend - * @param suffix the suffix appended to the class name to create the next extending class name - * @return the byte for the class - * @throws ObjenesisException is something goes wrong - */ - private static byte[] writeExtendingClass(Class type, String suffix) { - String parentClazz = classNameToInternalClassName(type.getName()); - String clazz = parentClazz + suffix; - - DataOutputStream in = null; - ByteArrayOutputStream bIn = new ByteArrayOutputStream(1000); // 1000 should be large enough to fit the entire class - try { - in = new DataOutputStream(bIn); - - in.write(MAGIC); - in.write(VERSION); - in.writeShort(CONSTANT_POOL_COUNT); - - // set all the constant pool here - - // 1. class - in.writeByte(CONSTANT_Class); - in.writeShort(INDEX_UTF8_CLASS); - - // 2. super class - in.writeByte(CONSTANT_Class); - in.writeShort(INDEX_UTF8_SUPERCLASS); - - // 3. default constructor name - in.writeByte(CONSTANT_Utf8); - in.writeUTF(CONSTRUCTOR_NAME); - - // 4. default constructor description - in.writeByte(CONSTANT_Utf8); - in.writeUTF(CONSTRUCTOR_DESC); - - // 5. Code - in.writeByte(CONSTANT_Utf8); - in.writeUTF("Code"); - - // 6. Class name - in.writeByte(CONSTANT_Utf8); - in.writeUTF("L" + clazz + ";"); - - // 7. Class name (again) - in.writeByte(CONSTANT_Utf8); - in.writeUTF(clazz); - - // 8. Superclass name - in.writeByte(CONSTANT_Utf8); - in.writeUTF(parentClazz); - - // end of constant pool - - // access flags: We want public, ACC_SUPER is always there - in.writeShort(ACC_PUBLIC | ACC_SUPER); - - // this class index in the constant pool - in.writeShort(INDEX_CLASS_THIS); - - // super class index in the constant pool - in.writeShort(INDEX_CLASS_SUPERCLASS); - - // interfaces implemented count (we have none) - in.writeShort(0); - - // fields count (we have none) - in.writeShort(0); - - // methods count (we have one: the default constructor) - in.writeShort(1); - - // default constructor method_info - in.writeShort(ACC_PUBLIC); - in.writeShort(INDEX_UTF8_CONSTRUCTOR_NAME); // index of the method name () - in.writeShort(INDEX_UTF8_CONSTRUCTOR_DESC); // index of the description - in.writeShort(1); // number of attributes: only one, the code - - // code attribute of the default constructor - in.writeShort(INDEX_UTF8_CODE_ATTRIBUTE); - in.writeInt(CODE_ATTRIBUTE_LENGTH); // attribute length - in.writeShort(1); // max_stack - in.writeShort(1); // max_locals - in.writeInt(CODE.length); // code length - in.write(CODE); - in.writeShort(0); // exception_table_length = 0 - in.writeShort(0); // attributes count = 0, no need to have LineNumberTable and LocalVariableTable - - // class attributes - in.writeShort(0); // none. No need to have a source file attribute - - - } catch (IOException e) { - throw new ObjenesisException(e); - } finally { - if(in != null) { - try { - in.close(); - } catch (IOException e) { - throw new ObjenesisException(e); - } - } - } - - return bIn.toByteArray(); - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/gcj/GCJInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/gcj/GCJInstantiator.java deleted file mode 100644 index 9a35db494..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/gcj/GCJInstantiator.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.gcj; - -import java.lang.reflect.InvocationTargetException; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiates a class by making a call to internal GCJ private methods. It is only supposed to - * work on GCJ JVMs. This instantiator will not call any constructors. - * - * @author Leonardo Mesquita - * @see com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator - */ -@Instantiator(Typology.STANDARD) -public class GCJInstantiator extends GCJInstantiatorBase { - public GCJInstantiator(Class type) { - super(type); - } - - @Override - public T newInstance() { - try { - return type.cast(newObjectMethod.invoke(dummyStream, type, Object.class)); - } - catch(RuntimeException e) { - throw new ObjenesisException(e); - } - catch(IllegalAccessException e) { - throw new ObjenesisException(e); - } - catch(InvocationTargetException e) { - throw new ObjenesisException(e); - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/gcj/GCJInstantiatorBase.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/gcj/GCJInstantiatorBase.java deleted file mode 100644 index 2390266f1..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/gcj/GCJInstantiatorBase.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.gcj; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.lang.reflect.Method; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; - -/** - * Base class for GCJ-based instantiators. It initializes reflection access to method - * ObjectInputStream.newObject, as well as creating a dummy ObjectInputStream to be used as the - * "this" argument for the method. - * - * @author Leonardo Mesquita - */ -public abstract class GCJInstantiatorBase implements ObjectInstantiator { - static Method newObjectMethod = null; - static ObjectInputStream dummyStream; - - private static class DummyStream extends ObjectInputStream { - public DummyStream() throws IOException { - } - } - - private static void initialize() { - if(newObjectMethod == null) { - try { - newObjectMethod = ObjectInputStream.class.getDeclaredMethod("newObject", new Class[] { - Class.class, Class.class}); - newObjectMethod.setAccessible(true); - dummyStream = new DummyStream(); - } - catch(RuntimeException e) { - throw new ObjenesisException(e); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - catch(IOException e) { - throw new ObjenesisException(e); - } - } - } - - protected final Class type; - - public GCJInstantiatorBase(Class type) { - this.type = type; - initialize(); - } - - public abstract T newInstance(); -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/gcj/GCJSerializationInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/gcj/GCJSerializationInstantiator.java deleted file mode 100644 index 16a4d70ad..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/gcj/GCJSerializationInstantiator.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.gcj; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.SerializationInstantiatorHelper; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiates a class by making a call to internal GCJ private methods. It is only supposed to - * work on GCJ JVMs. This instantiator will create classes in a way compatible with serialization, - * calling the first non-serializable superclass' no-arg constructor. - * - * @author Leonardo Mesquita - * @see com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator - */ -@Instantiator(Typology.SERIALIZATION) -public class GCJSerializationInstantiator extends GCJInstantiatorBase { - private Class superType; - - public GCJSerializationInstantiator(Class type) { - super(type); - this.superType = SerializationInstantiatorHelper.getNonSerializableSuperClass(type); - } - - @Override - public T newInstance() { - try { - return type.cast(newObjectMethod.invoke(dummyStream, type, superType)); - } - catch(Exception e) { - throw new ObjenesisException(e); - } - } - -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/perc/PercInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/perc/PercInstantiator.java deleted file mode 100644 index 894193b6a..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/perc/PercInstantiator.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.perc; - -import java.io.ObjectInputStream; -import java.lang.reflect.Method; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiates a class by making a call to internal Perc private methods. It is only supposed to - * work on Perc JVMs. This instantiator will not call any constructors. The code was provided by - * Aonix Perc support team. - * - * @author Henri Tremblay - * @see com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator - */ -@Instantiator(Typology.STANDARD) -public class PercInstantiator implements ObjectInstantiator { - - private final Method newInstanceMethod; - - private final Object[] typeArgs = new Object[] { null, Boolean.FALSE }; - - public PercInstantiator(Class type) { - - typeArgs[0] = type; - - try { - newInstanceMethod = ObjectInputStream.class.getDeclaredMethod("newInstance", Class.class, - Boolean.TYPE); - newInstanceMethod.setAccessible(true); - } - catch(RuntimeException e) { - throw new ObjenesisException(e); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - } - - @SuppressWarnings("unchecked") - public T newInstance() { - try { - return (T) newInstanceMethod.invoke(null, typeArgs); - } catch (Exception e) { - throw new ObjenesisException(e); - } - } - -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/perc/PercSerializationInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/perc/PercSerializationInstantiator.java deleted file mode 100644 index ea9ab3acd..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/perc/PercSerializationInstantiator.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.perc; - -import java.io.ObjectInputStream; -import java.io.Serializable; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiates a class by making a call to internal Perc private methods. It is only supposed to - * work on Perc JVMs. This instantiator will create classes in a way compatible with serialization, - * calling the first non-serializable superclass' no-arg constructor. - *

- * Based on code provided by Aonix but doesn't work right now - * - * @author Henri Tremblay - * @see com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator - */ -@Instantiator(Typology.SERIALIZATION) -public class PercSerializationInstantiator implements ObjectInstantiator { - - private Object[] typeArgs; - - private final Method newInstanceMethod; - - public PercSerializationInstantiator(Class type) { - - // Find the first unserializable parent class - Class unserializableType = type; - - while(Serializable.class.isAssignableFrom(unserializableType)) { - unserializableType = unserializableType.getSuperclass(); - } - - try { - // Get the special Perc method to call - Class percMethodClass = Class.forName("COM.newmonics.PercClassLoader.Method"); - - newInstanceMethod = ObjectInputStream.class.getDeclaredMethod("noArgConstruct", - new Class[] {Class.class, Object.class, percMethodClass}); - newInstanceMethod.setAccessible(true); - - // Create invoke params - Class percClassClass = Class.forName("COM.newmonics.PercClassLoader.PercClass"); - Method getPercClassMethod = percClassClass.getDeclaredMethod("getPercClass", Class.class); - Object someObject = getPercClassMethod.invoke(null, unserializableType); - Method findMethodMethod = someObject.getClass().getDeclaredMethod("findMethod", - new Class[] {String.class}); - Object percMethod = findMethodMethod.invoke(someObject, "()V"); - - typeArgs = new Object[] {unserializableType, type, percMethod}; - - } - catch(ClassNotFoundException e) { - throw new ObjenesisException(e); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - catch(InvocationTargetException e) { - throw new ObjenesisException(e); - } - catch(IllegalAccessException e) { - throw new ObjenesisException(e); - } - } - - @SuppressWarnings("unchecked") - public T newInstance() { - try { - return (T) newInstanceMethod.invoke(null, typeArgs); - } - catch(IllegalAccessException e) { - throw new ObjenesisException(e); - } - catch(InvocationTargetException e) { - throw new ObjenesisException(e); - } - } - -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/MagicInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/MagicInstantiator.java deleted file mode 100644 index 045716400..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/MagicInstantiator.java +++ /dev/null @@ -1,296 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.sun; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; -import com.fr.third.springframework.aop.objenesis.instantiator.util.ClassDefinitionUtils; - -import static com.fr.third.springframework.aop.objenesis.instantiator.util.ClassDefinitionUtils.*; - -/** - * This instantiator will correctly bypass the constructors by instantiating the class using the default - * constructor from Object. It will be allowed to do so by extending {@code MagicAccessorImpl} which prevents - * its children to be verified by the class loader - * - * @author Henri Tremblay - */ -@Instantiator(Typology.STANDARD) -public class MagicInstantiator implements ObjectInstantiator { - - private static final String MAGIC_ACCESSOR = getMagicClass(); - - private static final int INDEX_CLASS_THIS = 1; - private static final int INDEX_CLASS_SUPERCLASS = 2; - private static final int INDEX_UTF8_CONSTRUCTOR_NAME = 3; - private static final int INDEX_UTF8_CONSTRUCTOR_DESC = 4; - private static final int INDEX_UTF8_CODE_ATTRIBUTE = 5; - private static final int INDEX_UTF8_INSTANTIATOR_CLASS = 7; - private static final int INDEX_UTF8_SUPERCLASS = 8; - private static final int INDEX_CLASS_INTERFACE = 9; - private static final int INDEX_UTF8_INTERFACE = 10; - private static final int INDEX_UTF8_NEWINSTANCE_NAME = 11; - private static final int INDEX_UTF8_NEWINSTANCE_DESC = 12; - private static final int INDEX_METHODREF_OBJECT_CONSTRUCTOR = 13; - private static final int INDEX_CLASS_OBJECT = 14; - private static final int INDEX_UTF8_OBJECT = 15; - private static final int INDEX_NAMEANDTYPE_DEFAULT_CONSTRUCTOR = 16; - private static final int INDEX_CLASS_TYPE = 17; - private static final int INDEX_UTF8_TYPE = 18; - - private static int CONSTANT_POOL_COUNT = 19; - - private static final byte[] CONSTRUCTOR_CODE = { OPS_aload_0, OPS_invokespecial, 0, INDEX_METHODREF_OBJECT_CONSTRUCTOR, OPS_return}; - private static final int CONSTRUCTOR_CODE_ATTRIBUTE_LENGTH = 12 + CONSTRUCTOR_CODE.length; - - private static final byte[] NEWINSTANCE_CODE = { OPS_new, 0, INDEX_CLASS_TYPE, OPS_dup, OPS_invokespecial, 0, INDEX_METHODREF_OBJECT_CONSTRUCTOR, OPS_areturn}; - private static final int NEWINSTANCE_CODE_ATTRIBUTE_LENGTH = 12 + NEWINSTANCE_CODE.length; - - private static final String CONSTRUCTOR_NAME = ""; - private static final String CONSTRUCTOR_DESC = "()V"; - - private ObjectInstantiator instantiator; - - public MagicInstantiator(Class type) { - instantiator = newInstantiatorOf(type); - } - - /** - * Get the underlying instantiator. - * - * {@link MagicInstantiator} is a wrapper around another object - * which implements {@link ObjectInstantiator} interface. - * This method exposes that instantiator. - * - * @return the underlying instantiator - */ - public ObjectInstantiator getInstantiator() { - return instantiator; - } - - private ObjectInstantiator newInstantiatorOf(Class type) { - String suffix = type.getSimpleName(); - String className = getClass().getName() + "$$$" + suffix; - - Class> clazz = getExistingClass(getClass().getClassLoader(), className); - - if(clazz == null) { - byte[] classBytes = writeExtendingClass(type, className); - - try { - clazz = ClassDefinitionUtils.defineClass(className, classBytes, getClass().getClassLoader()); - } catch (Exception e) { - throw new ObjenesisException(e); - } - } - - try { - return clazz.newInstance(); - } catch (InstantiationException e) { - throw new ObjenesisException(e); - } catch (IllegalAccessException e) { - throw new ObjenesisException(e); - } - } - - /** - * Will generate the bytes for a class extending the type passed in parameter. This class will - * only have an empty default constructor - * - * @param type type to extend - * @param className name of the wrapped instantiator class - * @return the byte for the class - * @throws ObjenesisException is something goes wrong - */ - private byte[] writeExtendingClass(Class type, String className) { - String clazz = classNameToInternalClassName(className); - - DataOutputStream in = null; - ByteArrayOutputStream bIn = new ByteArrayOutputStream(1000); // 1000 should be large enough to fit the entire class - try { - in = new DataOutputStream(bIn); - - in.write(MAGIC); - in.write(VERSION); - in.writeShort(CONSTANT_POOL_COUNT); - - // set all the constant pool here - - // 1. class - in.writeByte(CONSTANT_Class); - in.writeShort(INDEX_UTF8_INSTANTIATOR_CLASS); - - // 2. super class - in.writeByte(CONSTANT_Class); - in.writeShort(INDEX_UTF8_SUPERCLASS); - - // 3. default constructor name - in.writeByte(CONSTANT_Utf8); - in.writeUTF(CONSTRUCTOR_NAME); - - // 4. default constructor description - in.writeByte(CONSTANT_Utf8); - in.writeUTF(CONSTRUCTOR_DESC); - - // 5. Code - in.writeByte(CONSTANT_Utf8); - in.writeUTF("Code"); - - // 6. Class name - in.writeByte(CONSTANT_Utf8); - in.writeUTF("L" + clazz + ";"); - - // 7. Class name (again) - in.writeByte(CONSTANT_Utf8); - in.writeUTF(clazz); - - // 8. Superclass name - in.writeByte(CONSTANT_Utf8); -// in.writeUTF("java/lang/Object"); - in.writeUTF(MAGIC_ACCESSOR); - - // 9. ObjectInstantiator interface - in.writeByte(CONSTANT_Class); - in.writeShort(INDEX_UTF8_INTERFACE); - - // 10. ObjectInstantiator name - in.writeByte(CONSTANT_Utf8); - in.writeUTF(ObjectInstantiator.class.getName().replace('.', '/')); - - // 11. newInstance name - in.writeByte(CONSTANT_Utf8); - in.writeUTF("newInstance"); - - // 12. newInstance desc - in.writeByte(CONSTANT_Utf8); - in.writeUTF("()Ljava/lang/Object;"); - - // 13. Methodref to the Object constructor - in.writeByte(CONSTANT_Methodref); - in.writeShort(INDEX_CLASS_OBJECT); - in.writeShort(INDEX_NAMEANDTYPE_DEFAULT_CONSTRUCTOR); - - // 14. Object class - in.writeByte(CONSTANT_Class); - in.writeShort(INDEX_UTF8_OBJECT); - - // 15. Object class name - in.writeByte(CONSTANT_Utf8); - in.writeUTF("java/lang/Object"); - - // 16. Default constructor name and type - in.writeByte(CONSTANT_NameAndType); - in.writeShort(INDEX_UTF8_CONSTRUCTOR_NAME); - in.writeShort(INDEX_UTF8_CONSTRUCTOR_DESC); - - // 17. Type to instantiate class - in.writeByte(CONSTANT_Class); - in.writeShort(INDEX_UTF8_TYPE); - - // 18. Type to instantiate name - in.writeByte(CONSTANT_Utf8); - in.writeUTF(classNameToInternalClassName(type.getName())); - - // end of constant pool - - // access flags: We want public, ACC_SUPER is always there - in.writeShort(ACC_PUBLIC | ACC_SUPER | ACC_FINAL); - - // this class index in the constant pool - in.writeShort(INDEX_CLASS_THIS); - - // super class index in the constant pool - in.writeShort(INDEX_CLASS_SUPERCLASS); - - // interfaces implemented count (we have none) - in.writeShort(1); - in.writeShort(INDEX_CLASS_INTERFACE); - - // fields count (we have none) - in.writeShort(0); - - // method count (we have two: the default constructor and newInstance) - in.writeShort(2); - - // default constructor method_info - in.writeShort(ACC_PUBLIC); - in.writeShort(INDEX_UTF8_CONSTRUCTOR_NAME); // index of the method name () - in.writeShort(INDEX_UTF8_CONSTRUCTOR_DESC); // index of the description - in.writeShort(1); // number of attributes: only one, the code - - // code attribute of the default constructor - in.writeShort(INDEX_UTF8_CODE_ATTRIBUTE); - in.writeInt(CONSTRUCTOR_CODE_ATTRIBUTE_LENGTH); // attribute length - in.writeShort(0); // max_stack - in.writeShort(1); // max_locals - in.writeInt(CONSTRUCTOR_CODE.length); // code length - in.write(CONSTRUCTOR_CODE); - in.writeShort(0); // exception_table_length = 0 - in.writeShort(0); // attributes count = 0, no need to have LineNumberTable and LocalVariableTable - - // newInstance method_info - in.writeShort(ACC_PUBLIC); - in.writeShort(INDEX_UTF8_NEWINSTANCE_NAME); // index of the method name (newInstance) - in.writeShort(INDEX_UTF8_NEWINSTANCE_DESC); // index of the description - in.writeShort(1); // number of attributes: only one, the code - - // code attribute of newInstance - in.writeShort(INDEX_UTF8_CODE_ATTRIBUTE); - in.writeInt(NEWINSTANCE_CODE_ATTRIBUTE_LENGTH); // attribute length - in.writeShort(2); // max_stack - in.writeShort(1); // max_locals - in.writeInt(NEWINSTANCE_CODE.length); // code length - in.write(NEWINSTANCE_CODE); - in.writeShort(0); // exception_table_length = 0 - in.writeShort(0); // attributes count = 0, no need to have LineNumberTable and LocalVariableTable - - // class attributes - in.writeShort(0); // none. No need to have a source file attribute - - } catch (IOException e) { - throw new ObjenesisException(e); - } finally { - if(in != null) { - try { - in.close(); - } catch (IOException e) { - throw new ObjenesisException(e); - } - } - } - - return bIn.toByteArray(); - } - - public T newInstance() { - return instantiator.newInstance(); - } - - private static String getMagicClass() { - try { - Class.forName("sun.reflect.MagicAccessorImpl", false, MagicInstantiator.class.getClassLoader()); - return "sun/reflect/MagicAccessorImpl"; - } catch (ClassNotFoundException e) { - return "jdk/internal/reflect/MagicAccessorImpl"; - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/SunReflectionFactoryHelper.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/SunReflectionFactoryHelper.java deleted file mode 100644 index 994c6a52a..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/SunReflectionFactoryHelper.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.sun; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; - - -/** - * Helper methods providing access to {@link sun.reflect.ReflectionFactory} via reflection, for use - * by the {@link ObjectInstantiator}s that use it. - * - * @author Henri Tremblay - */ -@SuppressWarnings("restriction") -class SunReflectionFactoryHelper { - - @SuppressWarnings("unchecked") - public static Constructor newConstructorForSerialization(Class type, - Constructor constructor) { - Class reflectionFactoryClass = getReflectionFactoryClass(); - Object reflectionFactory = createReflectionFactory(reflectionFactoryClass); - - Method newConstructorForSerializationMethod = getNewConstructorForSerializationMethod( - reflectionFactoryClass); - - try { - return (Constructor) newConstructorForSerializationMethod.invoke( - reflectionFactory, type, constructor); - } - catch(IllegalArgumentException e) { - throw new ObjenesisException(e); - } - catch(IllegalAccessException e) { - throw new ObjenesisException(e); - } - catch(InvocationTargetException e) { - throw new ObjenesisException(e); - } - } - - private static Class getReflectionFactoryClass() { - try { - return Class.forName("sun.reflect.ReflectionFactory"); - } - catch(ClassNotFoundException e) { - throw new ObjenesisException(e); - } - } - - private static Object createReflectionFactory(Class reflectionFactoryClass) { - try { - Method method = reflectionFactoryClass.getDeclaredMethod( - "getReflectionFactory"); - return method.invoke(null); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - catch(IllegalAccessException e) { - throw new ObjenesisException(e); - } - catch(IllegalArgumentException e) { - throw new ObjenesisException(e); - } - catch(InvocationTargetException e) { - throw new ObjenesisException(e); - } - } - - private static Method getNewConstructorForSerializationMethod(Class reflectionFactoryClass) { - try { - return reflectionFactoryClass.getDeclaredMethod( - "newConstructorForSerialization", Class.class, Constructor.class); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/SunReflectionFactoryInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/SunReflectionFactoryInstantiator.java deleted file mode 100644 index 761001115..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/SunReflectionFactoryInstantiator.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.sun; - -import java.lang.reflect.Constructor; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiates an object, WITHOUT calling it's constructor, using internal - * sun.reflect.ReflectionFactory - a class only available on JDK's that use Sun's 1.4 (or later) - * Java implementation. This is the best way to instantiate an object without any side effects - * caused by the constructor - however it is not available on every platform. - * - * @author Joe Walnes - * @see ObjectInstantiator - */ -@Instantiator(Typology.STANDARD) -public class SunReflectionFactoryInstantiator implements ObjectInstantiator { - - private final Constructor mungedConstructor; - - public SunReflectionFactoryInstantiator(Class type) { - Constructor javaLangObjectConstructor = getJavaLangObjectConstructor(); - mungedConstructor = SunReflectionFactoryHelper.newConstructorForSerialization( - type, javaLangObjectConstructor); - mungedConstructor.setAccessible(true); - } - - public T newInstance() { - try { - return mungedConstructor.newInstance((Object[]) null); - } - catch(Exception e) { - throw new ObjenesisException(e); - } - } - - private static Constructor getJavaLangObjectConstructor() { - try { - return Object.class.getConstructor((Class[]) null); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/SunReflectionFactorySerializationInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/SunReflectionFactorySerializationInstantiator.java deleted file mode 100644 index acb3463de..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/SunReflectionFactorySerializationInstantiator.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.sun; - -import java.io.NotSerializableException; -import java.lang.reflect.Constructor; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.SerializationInstantiatorHelper; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; - -/** - * Instantiates an object using internal sun.reflect.ReflectionFactory - a class only available on - * JDK's that use Sun's 1.4 (or later) Java implementation. This instantiator will create classes in - * a way compatible with serialization, calling the first non-serializable superclass' no-arg - * constructor. This is the best way to instantiate an object without any side effects caused by the - * constructor - however it is not available on every platform. - * - * @author Leonardo Mesquita - * @see ObjectInstantiator - */ -@Instantiator(Typology.SERIALIZATION) -public class SunReflectionFactorySerializationInstantiator implements ObjectInstantiator { - - private final Constructor mungedConstructor; - - public SunReflectionFactorySerializationInstantiator(Class type) { - Class nonSerializableAncestor = SerializationInstantiatorHelper - .getNonSerializableSuperClass(type); - - Constructor nonSerializableAncestorConstructor; - try { - nonSerializableAncestorConstructor = nonSerializableAncestor - .getDeclaredConstructor((Class[]) null); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(new NotSerializableException(type+" has no suitable superclass constructor")); - } - - mungedConstructor = SunReflectionFactoryHelper.newConstructorForSerialization( - type, nonSerializableAncestorConstructor); - mungedConstructor.setAccessible(true); - } - - public T newInstance() { - try { - return mungedConstructor.newInstance((Object[]) null); - } - catch(Exception e) { - throw new ObjenesisException(e); - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/UnsafeFactoryInstantiator.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/UnsafeFactoryInstantiator.java deleted file mode 100644 index 003902491..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/sun/UnsafeFactoryInstantiator.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.sun; - -import sun.misc.Unsafe; -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.annotations.Typology; -import com.fr.third.springframework.aop.objenesis.instantiator.util.UnsafeUtils; - -import java.lang.reflect.Field; - -/** - * Instantiates an object, WITHOUT calling it's constructor, using - * {@code sun.misc.Unsafe.allocateInstance()}. Unsafe and its methods are implemented by most - * modern JVMs. - * - * @author Henri Tremblay - * @see ObjectInstantiator - */ -@SuppressWarnings("restriction") -@Instantiator(Typology.STANDARD) -public class UnsafeFactoryInstantiator implements ObjectInstantiator { - - private final Unsafe unsafe; - private final Class type; - - public UnsafeFactoryInstantiator(Class type) { - this.unsafe = UnsafeUtils.getUnsafe(); // retrieve it to fail right away at instantiator creation if not there - this.type = type; - } - - public T newInstance() { - try { - return type.cast(unsafe.allocateInstance(type)); - } catch (InstantiationException e) { - throw new ObjenesisException(e); - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/util/ClassDefinitionUtils.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/util/ClassDefinitionUtils.java deleted file mode 100644 index 898fe4cc3..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/util/ClassDefinitionUtils.java +++ /dev/null @@ -1,195 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.util; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; - -import java.io.BufferedOutputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Field; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.ProtectionDomain; - -import sun.misc.Unsafe; - -/** - * Helper class for ProxyObjectInstantiator. We can see the details of a class specification - * here - * - * @author Henri Tremblay - */ -public final class ClassDefinitionUtils { - - public static final byte OPS_aload_0 = 42; - public static final byte OPS_invokespecial = -73; // has two bytes parameters - public static final byte OPS_return = -79; - public static final byte OPS_new = -69; - public static final byte OPS_dup = 89; - public static final byte OPS_areturn = -80; - - public static final int CONSTANT_Utf8 = 1; - public static final int CONSTANT_Integer = 3; - public static final int CONSTANT_Float = 4; - public static final int CONSTANT_Long = 5; - public static final int CONSTANT_Double = 6; - public static final int CONSTANT_Class = 7; - public static final int CONSTANT_String = 8; - public static final int CONSTANT_Fieldref = 9; - public static final int CONSTANT_Methodref = 10; - public static final int CONSTANT_InterfaceMethodref = 11; - public static final int CONSTANT_NameAndType = 12; - public static final int CONSTANT_MethodHandle = 15; - public static final int CONSTANT_MethodType = 16; - public static final int CONSTANT_InvokeDynamic = 18; - - public static final int ACC_PUBLIC = 0x0001; // Declared public; may be accessed from outside its package. - public static final int ACC_FINAL = 0x0010; // Declared final; no subclasses allowed. - public static final int ACC_SUPER = 0x0020; // Treat superclass methods specially when invoked by the invokespecial instruction. - public static final int ACC_INTERFACE = 0x0200; // Is an interface, not a class. - public static final int ACC_ABSTRACT = 0x0400; // Declared abstract; must not be instantiated. - public static final int ACC_SYNTHETIC = 0x1000; // Declared synthetic; not present in the source code. - public static final int ACC_ANNOTATION = 0x2000; // Declared as an annotation type. - public static final int ACC_ENUM = 0x4000; // Declared as an enum type. - - public static final byte[] MAGIC = { (byte) 0xca, (byte) 0xfe, (byte) 0xba, (byte) 0xbe }; - public static final byte[] VERSION = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x31 }; // minor_version, major_version (Java 5) - - private ClassDefinitionUtils() { } - -// private static Method DEFINE_CLASS; - private static final ProtectionDomain PROTECTION_DOMAIN; - - static { - PROTECTION_DOMAIN = AccessController.doPrivileged(new PrivilegedAction() { - public ProtectionDomain run() { - return ClassDefinitionUtils.class.getProtectionDomain(); - } - }); - } - - /** - * Define a class in the provided class loader from the array of bytes. Inspired by cglib - * ReflectUtils.defineClass - * - * @param type of the class returned - * @param className class name in the format com.fr.third.springframework.aop.objenesis.MyClass - * @param b bytes representing the class - * @param loader the class loader where the class will be loaded - * @return the newly loaded class - * @throws Exception whenever something goes wrong - */ - @SuppressWarnings("unchecked") - public static Class defineClass(String className, byte[] b, ClassLoader loader) - throws Exception { - Class c = (Class) UnsafeUtils.getUnsafe().defineClass(className, b, 0, b.length, loader, PROTECTION_DOMAIN); - // Force static initializers to run. - Class.forName(className, true, loader); - return c; - } - - /** - * Read the bytes of a class from the classpath - * - * @param className full class name including the package - * @return the bytes representing the class - * @throws IllegalArgumentException if the class is longer than 2500 bytes - * @throws IOException if we fail to read the class - */ - public static byte[] readClass(String className) throws IOException { - // convert to a resource - className = classNameToResource(className); - - byte[] b = new byte[2500]; // I'm assuming that I'm reading class that are not too big - - int length; - - InputStream in = ClassDefinitionUtils.class.getClassLoader().getResourceAsStream(className); - try { - length = in.read(b); - } - finally { - in.close(); - } - - if(length >= 2500) { - throw new IllegalArgumentException("The class is longer that 2500 bytes which is currently unsupported"); - } - - byte[] copy = new byte[length]; - System.arraycopy(b, 0, copy, 0, length); - return copy; - } - - /** - * Write all class bytes to a file. - * - * @param fileName file where the bytes will be written - * @param bytes bytes representing the class - * @throws IOException if we fail to write the class - */ - public static void writeClass(String fileName, byte[] bytes) throws IOException { - BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(fileName)); - try { - out.write(bytes); - } - finally { - out.close(); - } - } - - /** - * Will convert a class name to its name in the class definition format (e.g {@code com.fr.third.springframework.aop.objenesis.EmptyClass} - * becomes {@code org/objenesis/EmptyClass}) - * - * @param className full class name including the package - * @return the internal name - */ - public static String classNameToInternalClassName(String className) { - return className.replace('.', '/'); - } - - /** - * Will convert a class name to its class loader resource name (e.g {@code com.fr.third.springframework.aop.objenesis.EmptyClass} - * becomes {@code org/objenesis/EmptyClass.class}) - * - * @param className full class name including the package - * @return the resource name - */ - public static String classNameToResource(String className) { - return classNameToInternalClassName(className) + ".class"; - } - - /** - * Check if this class already exists in the class loader and return it if it does - * - * @param type of the class returned - * @param classLoader Class loader where to search the class - * @param className Class name with full path - * @return the class if it already exists or null - */ - @SuppressWarnings("unchecked") - public static Class getExistingClass(ClassLoader classLoader, String className) { - try { - return (Class) Class.forName(className, true, classLoader); - } - catch (ClassNotFoundException e) { - return null; - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/util/UnsafeUtils.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/util/UnsafeUtils.java deleted file mode 100644 index 091bb3ea5..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/instantiator/util/UnsafeUtils.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.instantiator.util; - -import java.lang.reflect.Field; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; - -import sun.misc.Unsafe; - -/** - * Helper class basically allowing to get access to {@code sun.misc.Unsafe} - * - * @author Henri Tremblay - */ -public final class UnsafeUtils { - - private static final Unsafe unsafe; - - static { - Field f; - try { - f = Unsafe.class.getDeclaredField("theUnsafe"); - } catch (NoSuchFieldException e) { - throw new ObjenesisException(e); - } - f.setAccessible(true); - try { - unsafe = (Unsafe) f.get(null); - } catch (IllegalAccessException e) { - throw new ObjenesisException(e); - } - } - - private UnsafeUtils() {} - - public static Unsafe getUnsafe() { - return unsafe; - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/BaseInstantiatorStrategy.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/BaseInstantiatorStrategy.java deleted file mode 100644 index 87826b5c4..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/BaseInstantiatorStrategy.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.strategy; - -/** - * Base {@link InstantiatorStrategy} class basically. Only implements {@link InstantiatorStrategy} - * - * @author Henri Tremblay - */ -public abstract class BaseInstantiatorStrategy implements InstantiatorStrategy { - -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/InstantiatorStrategy.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/InstantiatorStrategy.java deleted file mode 100644 index 75b4ccebe..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/InstantiatorStrategy.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.strategy; - -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; - -/** - * Defines a strategy to determine the best instantiator for a class. - * - * @author Henri Tremblay - */ -public interface InstantiatorStrategy { - - /** - * Create a dedicated instantiator for the given class - * - * @param Type to instantiate - * @param type Class that will be instantiated - * @return Dedicated instantiator - */ - ObjectInstantiator newInstantiatorOf(Class type); -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/PlatformDescription.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/PlatformDescription.java deleted file mode 100644 index 36a9f5623..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/PlatformDescription.java +++ /dev/null @@ -1,198 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.strategy; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; - -import java.lang.reflect.Field; - -/** - * List of constants describing the currently used platform. - * - * @author Henri Tremblay - */ -public final class PlatformDescription { - - /** JVM_NAME prefix for JRockit */ - public static final String JROCKIT = "BEA"; - - /** JVM_NAME prefix for GCJ */ - public static final String GNU = "GNU libgcj"; - - /** JVM_NAME prefix for Java HotSpot */ - public static final String HOTSPOT = "Java HotSpot"; - - /** - * JVM_NAME prefix for Java HotSpot - * - * @deprecated Use {@link #HOTSPOT} instead - */ - @Deprecated - public static final String SUN = HOTSPOT; - - /** JVM_NAME prefix for the OpenJDK */ - public static final String OPENJDK = "OpenJDK"; - - /** JVM_NAME prefix for Aonix PERC */ - public static final String PERC = "PERC"; - - /** JVM_NAME prefix for Dalvik/Android */ - public static final String DALVIK = "Dalvik"; - - /** Java specification version */ - public static final String SPECIFICATION_VERSION = System - .getProperty("java.specification.version"); - - /** JVM version */ - public static final String VM_VERSION = System.getProperty("java.runtime.version"); - - /** JVM version */ - public static final String VM_INFO = System.getProperty("java.vm.info"); - - /** VM vendor version */ - public static final String VENDOR_VERSION = System.getProperty("java.vm.version"); - - /** VM vendor name */ - public static final String VENDOR = System.getProperty("java.vm.vendor"); - - /** JVM name */ - public static final String JVM_NAME = System.getProperty("java.vm.name"); - - /** Android version. Will be 0 for none android platform */ - public static final int ANDROID_VERSION = getAndroidVersion(); - - /** Flag telling if this version of Android is based on the OpenJDK */ - public static final boolean IS_ANDROID_OPENJDK = getIsAndroidOpenJDK(); - - /** Google App Engine version or null is we are not on GAE */ - public static final String GAE_VERSION = getGaeRuntimeVersion(); - - /** - * Describes the platform. Outputs Java version and vendor. - * - * @return Description of the current platform - */ - public static String describePlatform() { - String desc = "Java " + SPECIFICATION_VERSION + " (" - + "VM vendor name=\"" + VENDOR + "\", " - + "VM vendor version=" + VENDOR_VERSION + ", " - + "JVM name=\"" + JVM_NAME + "\", " - + "JVM version=" + VM_VERSION + ", " - + "JVM info=" + VM_INFO; - - // Add the API level is it's an Android platform - int androidVersion = ANDROID_VERSION; - if(androidVersion != 0) { - desc += ", API level=" + ANDROID_VERSION; - } - desc += ")"; - - return desc; - } - - /** - * Check if the current JVM is of the type passed in parameter. Normally, this will be a constant - * from this class. We basically do - * System.getProperty("java.vm.name").startWith(name). - * - * @param name jvm name we are looking for - * @return if it's the requested JVM - */ - public static boolean isThisJVM(String name) { - return JVM_NAME.startsWith(name); - } - - /** - * Check if this JVM is an Android JVM based on OpenJDK. - * - * @return if it's an Android version based on the OpenJDK. Will return false if this JVM isn't an Android JVM at all - */ - public static boolean isAndroidOpenJDK() { - return IS_ANDROID_OPENJDK; - } - - private static boolean getIsAndroidOpenJDK() { - if(getAndroidVersion() == 0) { - return false; // Not android at all - } - // Sadly, Android N is still API 23. So we can't base ourselves on the API level to know if it is an OpenJDK - // version or not - String bootClasspath = System.getProperty("java.boot.class.path"); - return bootClasspath != null && bootClasspath.toLowerCase().contains("core-oj.jar"); - } - - public static boolean isGoogleAppEngine() { - return GAE_VERSION != null; - } - - private static String getGaeRuntimeVersion() { - return System.getProperty("com.google.appengine.runtime.version"); - } - - private static int getAndroidVersion() { - if(!isThisJVM(DALVIK)) { - return 0; - } - return getAndroidVersion0(); - } - - private static int getAndroidVersion0() { - Class clazz; - try { - clazz = Class.forName("android.os.Build$VERSION"); - } - catch(ClassNotFoundException e) { - throw new ObjenesisException(e); - } - Field field; - try { - field = clazz.getField("SDK_INT"); - } - catch(NoSuchFieldException e) { - // Might be a really old API (before 4), go for SDK - return getOldAndroidVersion(clazz); - } - int version; - try { - version = (Integer) field.get(null); - } - catch(IllegalAccessException e) { - throw new RuntimeException(e); - } - return version; - } - - private static int getOldAndroidVersion(Class versionClass) { - Field field; - try { - field = versionClass.getField("SDK"); - } - catch(NoSuchFieldException e) { - throw new ObjenesisException(e); - } - String version; - try { - version = (String) field.get(null); - } - catch(IllegalAccessException e) { - throw new RuntimeException(e); - } - return Integer.parseInt(version); - } - - private PlatformDescription() { - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/SerializingInstantiatorStrategy.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/SerializingInstantiatorStrategy.java deleted file mode 100644 index c11f19368..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/SerializingInstantiatorStrategy.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.strategy; - -import java.io.NotSerializableException; -import java.io.Serializable; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.android.AndroidSerializationInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.basic.ObjectInputStreamInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.basic.ObjectStreamClassInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.gcj.GCJSerializationInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.perc.PercSerializationInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.sun.SunReflectionFactorySerializationInstantiator; - -import static com.fr.third.springframework.aop.objenesis.strategy.PlatformDescription.*; - -/** - * Guess the best serializing instantiator for a given class. The returned instantiator will - * instantiate classes like the genuine java serialization framework (the constructor of the first - * not serializable class will be called). Currently, the selection doesn't depend on the class. It - * relies on the - *
    - *
  • JVM version
  • - *
  • JVM vendor
  • - *
  • JVM vendor version
  • - *
- * However, instantiators are stateful and so dedicated to their class. - * - * @author Henri Tremblay - * @see ObjectInstantiator - */ -public class SerializingInstantiatorStrategy extends BaseInstantiatorStrategy { - - /** - * Return an {@link ObjectInstantiator} allowing to create instance following the java - * serialization framework specifications. - * - * @param type Class to instantiate - * @return The ObjectInstantiator for the class - */ - public ObjectInstantiator newInstantiatorOf(Class type) { - if(!Serializable.class.isAssignableFrom(type)) { - throw new ObjenesisException(new NotSerializableException(type+" not serializable")); - } - if(JVM_NAME.startsWith(HOTSPOT) || PlatformDescription.isThisJVM(OPENJDK)) { - // Java 7 GAE was under a security manager so we use a degraded system - if(isGoogleAppEngine() && PlatformDescription.SPECIFICATION_VERSION.equals("1.7")) { - return new ObjectInputStreamInstantiator(type); - } - return new SunReflectionFactorySerializationInstantiator(type); - } - else if(JVM_NAME.startsWith(DALVIK)) { - if(PlatformDescription.isAndroidOpenJDK()) { - return new ObjectStreamClassInstantiator(type); - } - return new AndroidSerializationInstantiator(type); - } - else if(JVM_NAME.startsWith(GNU)) { - return new GCJSerializationInstantiator(type); - } - else if(JVM_NAME.startsWith(PERC)) { - return new PercSerializationInstantiator(type); - } - - return new SunReflectionFactorySerializationInstantiator(type); - } - -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/SingleInstantiatorStrategy.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/SingleInstantiatorStrategy.java deleted file mode 100644 index 3352fdac8..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/SingleInstantiatorStrategy.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.strategy; - -import com.fr.third.springframework.aop.objenesis.ObjenesisException; -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; - -/** - * Strategy returning only one instantiator type. Useful if you know on which JVM Objenesis - * will be used and want to specify it explicitly. - * - * @author Henri Tremblay - */ -public class SingleInstantiatorStrategy implements InstantiatorStrategy { - - private Constructor constructor; - - /** - * Create a strategy that will return always the same instantiator type. We assume this instantiator - * has one constructor taking the class to instantiate in parameter. - * - * @param the type we want to instantiate - * @param instantiator the instantiator type - */ - public > SingleInstantiatorStrategy(Class instantiator) { - try { - constructor = instantiator.getConstructor(Class.class); - } - catch(NoSuchMethodException e) { - throw new ObjenesisException(e); - } - } - - /** - * Return an instantiator for the wanted type and of the one and only type of instantiator returned by this - * class. - * - * @param the type we want to instantiate - * @param type Class to instantiate - * @return The ObjectInstantiator for the class - */ - @SuppressWarnings("unchecked") - public ObjectInstantiator newInstantiatorOf(Class type) { - try { - return (ObjectInstantiator) constructor.newInstance(type); - } catch (InstantiationException e) { - throw new ObjenesisException(e); - } catch (IllegalAccessException e) { - throw new ObjenesisException(e); - } catch (InvocationTargetException e) { - throw new ObjenesisException(e); - } - } -} diff --git a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/StdInstantiatorStrategy.java b/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/StdInstantiatorStrategy.java deleted file mode 100644 index 2e1f3680c..000000000 --- a/fine-spring/src/com/fr/third/springframework/aop/objenesis/strategy/StdInstantiatorStrategy.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Copyright 2006-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fr.third.springframework.aop.objenesis.strategy; - -import com.fr.third.springframework.aop.objenesis.instantiator.ObjectInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.android.Android10Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.android.Android17Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.android.Android18Instantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.basic.AccessibleInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.basic.ObjectInputStreamInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.gcj.GCJInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.perc.PercInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.sun.SunReflectionFactoryInstantiator; -import com.fr.third.springframework.aop.objenesis.instantiator.sun.UnsafeFactoryInstantiator; - -import java.io.Serializable; - -import static com.fr.third.springframework.aop.objenesis.strategy.PlatformDescription.*; - -/** - * Guess the best instantiator for a given class. The instantiator will instantiate the class - * without calling any constructor. Currently, the selection doesn't depend on the class. It relies - * on the - *
    - *
  • JVM version
  • - *
  • JVM vendor
  • - *
  • JVM vendor version
  • - *
- * However, instantiators are stateful and so dedicated to their class. - * - * @author Henri Tremblay - * @see ObjectInstantiator - */ -public class StdInstantiatorStrategy extends BaseInstantiatorStrategy { - - /** - * Return an {@link ObjectInstantiator} allowing to create instance without any constructor being - * called. - * - * @param type Class to instantiate - * @return The ObjectInstantiator for the class - */ - public ObjectInstantiator newInstantiatorOf(Class type) { - - if(PlatformDescription.isThisJVM(HOTSPOT) || PlatformDescription.isThisJVM(OPENJDK)) { - // Java 7 GAE was under a security manager so we use a degraded system - if(PlatformDescription.isGoogleAppEngine() && PlatformDescription.SPECIFICATION_VERSION.equals("1.7")) { - if(Serializable.class.isAssignableFrom(type)) { - return new ObjectInputStreamInstantiator(type); - } - return new AccessibleInstantiator(type); - } - // The UnsafeFactoryInstantiator would also work. But according to benchmarks, it is 2.5 - // times slower. So I prefer to use this one - return new SunReflectionFactoryInstantiator(type); - } - else if(PlatformDescription.isThisJVM(DALVIK)) { - if(PlatformDescription.isAndroidOpenJDK()) { - // Starting at Android N which is based on OpenJDK - return new UnsafeFactoryInstantiator(type); - } - if(ANDROID_VERSION <= 10) { - // Android 2.3 Gingerbread and lower - return new Android10Instantiator(type); - } - if(ANDROID_VERSION <= 17) { - // Android 3.0 Honeycomb to 4.2 Jelly Bean - return new Android17Instantiator(type); - } - // Android 4.3 until Android N - return new Android18Instantiator(type); - } - else if(PlatformDescription.isThisJVM(JROCKIT)) { - // JRockit is compliant with HotSpot - return new SunReflectionFactoryInstantiator(type); - } - else if(PlatformDescription.isThisJVM(GNU)) { - return new GCJInstantiator(type); - } - else if(PlatformDescription.isThisJVM(PERC)) { - return new PercInstantiator(type); - } - - // Fallback instantiator, should work with most modern JVM - return new UnsafeFactoryInstantiator(type); - - } -} diff --git a/fine-spring/src/com/fr/third/springframework/ejb/access/AbstractRemoteSlsbInvokerInterceptor.java b/fine-spring/src/com/fr/third/springframework/ejb/access/AbstractRemoteSlsbInvokerInterceptor.java index 6863de22e..96ddade3f 100644 --- a/fine-spring/src/com/fr/third/springframework/ejb/access/AbstractRemoteSlsbInvokerInterceptor.java +++ b/fine-spring/src/com/fr/third/springframework/ejb/access/AbstractRemoteSlsbInvokerInterceptor.java @@ -23,7 +23,6 @@ import java.rmi.RemoteException; import javax.ejb.EJBHome; import javax.ejb.EJBObject; import javax.naming.NamingException; -import javax.rmi.PortableRemoteObject; import org.aopalliance.intercept.MethodInvocation; @@ -88,28 +87,6 @@ public abstract class AbstractRemoteSlsbInvokerInterceptor extends AbstractSlsbI return this.refreshHomeOnConnectFailure; } - - /** - * This overridden lookup implementation performs a narrow operation - * after the JNDI lookup, provided that a home interface is specified. - * @see #setHomeInterface - * @see javax.rmi.PortableRemoteObject#narrow - */ - @Override - protected Object lookup() throws NamingException { - Object homeObject = super.lookup(); - if (this.homeInterface != null) { - try { - homeObject = PortableRemoteObject.narrow(homeObject, this.homeInterface); - } - catch (ClassCastException ex) { - throw new RemoteLookupFailureException( - "Could not narrow EJB home stub to home interface [" + this.homeInterface.getName() + "]", ex); - } - } - return homeObject; - } - /** * Check for EJB3-style home object that serves as EJB component directly. */ diff --git a/fine-spring/src/com/fr/third/springframework/remoting/rmi/JndiRmiClientInterceptor.java b/fine-spring/src/com/fr/third/springframework/remoting/rmi/JndiRmiClientInterceptor.java index 5d6440546..4bb758a0a 100644 --- a/fine-spring/src/com/fr/third/springframework/remoting/rmi/JndiRmiClientInterceptor.java +++ b/fine-spring/src/com/fr/third/springframework/remoting/rmi/JndiRmiClientInterceptor.java @@ -21,12 +21,9 @@ import java.lang.reflect.Method; import java.rmi.RemoteException; import javax.naming.Context; import javax.naming.NamingException; -import javax.rmi.PortableRemoteObject; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; -import org.omg.CORBA.OBJECT_NOT_EXIST; -import org.omg.CORBA.SystemException; import com.fr.third.springframework.aop.support.AopUtils; import com.fr.third.springframework.beans.factory.InitializingBean; @@ -41,8 +38,8 @@ import com.fr.third.springframework.remoting.support.RemoteInvocationFactory; import com.fr.third.springframework.util.ReflectionUtils; /** - * {@link org.aopalliance.intercept.MethodInterceptor} for accessing RMI services from JNDI. - * Typically used for RMI-IIOP (CORBA), but can also be used for EJB home objects + * {@link org.aopalliance.intercept.MethodInterceptor} for accessing RMI services + * from JNDI.Typically used for RMI-IIOP, but can also be used for EJB home objects * (for example, a Stateful Session Bean home). In contrast to a plain JNDI lookup, * this accessor also performs narrowing through PortableRemoteObject. * @@ -74,7 +71,6 @@ import com.fr.third.springframework.util.ReflectionUtils; * @see com.fr.third.springframework.remoting.RemoteAccessException * @see java.rmi.RemoteException * @see java.rmi.Remote - * @see javax.rmi.PortableRemoteObject#narrow */ public class JndiRmiClientInterceptor extends JndiObjectLocator implements MethodInterceptor, InitializingBean { @@ -227,17 +223,7 @@ public class JndiRmiClientInterceptor extends JndiObjectLocator implements Metho */ protected Object lookupStub() throws RemoteLookupFailureException { try { - Object stub = lookup(); - if (getServiceInterface() != null && !(stub instanceof RmiInvocationHandler)) { - try { - stub = PortableRemoteObject.narrow(stub, getServiceInterface()); - } - catch (ClassCastException ex) { - throw new RemoteLookupFailureException( - "Could not narrow RMI stub to service interface [" + getServiceInterface().getName() + "]", ex); - } - } - return stub; + return lookup(); } catch (NamingException ex) { throw new RemoteLookupFailureException("JNDI lookup for RMI service [" + getJndiName() + "] failed", ex); @@ -306,14 +292,6 @@ public class JndiRmiClientInterceptor extends JndiObjectLocator implements Metho throw ex; } } - catch (SystemException ex) { - if (isConnectFailure(ex)) { - return handleRemoteConnectFailure(invocation, ex); - } - else { - throw ex; - } - } finally { getJndiTemplate().releaseContext(ctx); } @@ -330,17 +308,6 @@ public class JndiRmiClientInterceptor extends JndiObjectLocator implements Metho return RmiClientInterceptorUtils.isConnectFailure(ex); } - /** - * Determine whether the given CORBA exception indicates a connect failure. - *

The default implementation checks for CORBA's - * {@link org.omg.CORBA.OBJECT_NOT_EXIST} exception. - * @param ex the RMI exception to check - * @return whether the exception should be treated as connect failure - */ - protected boolean isConnectFailure(SystemException ex) { - return (ex instanceof OBJECT_NOT_EXIST); - } - /** * Refresh the stub and retry the remote invocation if necessary. *

If not configured to refresh on connect failure, this method @@ -402,9 +369,6 @@ public class JndiRmiClientInterceptor extends JndiObjectLocator implements Metho catch (RemoteException ex) { throw convertRmiAccessException(ex, invocation.getMethod()); } - catch (SystemException ex) { - throw convertCorbaAccessException(ex, invocation.getMethod()); - } catch (InvocationTargetException ex) { throw ex.getTargetException(); } @@ -423,9 +387,6 @@ public class JndiRmiClientInterceptor extends JndiObjectLocator implements Metho if (targetEx instanceof RemoteException) { throw convertRmiAccessException((RemoteException) targetEx, invocation.getMethod()); } - else if (targetEx instanceof SystemException) { - throw convertCorbaAccessException((SystemException) targetEx, invocation.getMethod()); - } else { throw targetEx; } @@ -483,27 +444,4 @@ public class JndiRmiClientInterceptor extends JndiObjectLocator implements Metho return RmiClientInterceptorUtils.convertRmiAccessException(method, ex, isConnectFailure(ex), getJndiName()); } - /** - * Convert the given CORBA SystemException that happened during remote access - * to Spring's RemoteAccessException if the method signature does not declare - * RemoteException. Else, return the SystemException wrapped in a RemoteException. - * @param method the invoked method - * @param ex the RemoteException that happened - * @return the exception to be thrown to the caller - */ - private Exception convertCorbaAccessException(SystemException ex, Method method) { - if (ReflectionUtils.declaresException(method, RemoteException.class)) { - // A traditional RMI service: wrap CORBA exceptions in standard RemoteExceptions. - return new RemoteException("Failed to access CORBA service [" + getJndiName() + "]", ex); - } - else { - if (isConnectFailure(ex)) { - return new RemoteConnectFailureException("Could not connect to CORBA service [" + getJndiName() + "]", ex); - } - else { - return new RemoteAccessException("Could not access CORBA service [" + getJndiName() + "]", ex); - } - } - } - } diff --git a/fine-spring/src/com/fr/third/springframework/remoting/rmi/JndiRmiServiceExporter.java b/fine-spring/src/com/fr/third/springframework/remoting/rmi/JndiRmiServiceExporter.java index 5297f83f1..1ec5dfb68 100644 --- a/fine-spring/src/com/fr/third/springframework/remoting/rmi/JndiRmiServiceExporter.java +++ b/fine-spring/src/com/fr/third/springframework/remoting/rmi/JndiRmiServiceExporter.java @@ -22,7 +22,6 @@ import java.rmi.RemoteException; import java.util.Properties; import javax.naming.NamingException; -import javax.rmi.PortableRemoteObject; import com.fr.third.springframework.beans.factory.DisposableBean; import com.fr.third.springframework.beans.factory.InitializingBean; @@ -32,7 +31,6 @@ import com.fr.third.springframework.jndi.JndiTemplate; * Service exporter which binds RMI services to JNDI. * Typically used for RMI-IIOP (CORBA). * - *

Exports services via the {@link javax.rmi.PortableRemoteObject} class. * You need to run "rmic" with the "-iiop" option to generate corresponding * stubs and skeletons for each exported service. * @@ -64,7 +62,6 @@ import com.fr.third.springframework.jndi.JndiTemplate; * @see #setJndiName * @see JndiRmiClientInterceptor * @see JndiRmiProxyFactoryBean - * @see javax.rmi.PortableRemoteObject#exportObject */ public class JndiRmiServiceExporter extends RmiBasedExporter implements InitializingBean, DisposableBean { @@ -118,7 +115,6 @@ public class JndiRmiServiceExporter extends RmiBasedExporter implements Initiali // Initialize and cache exported object. this.exportedObject = getObjectToExport(); - PortableRemoteObject.exportObject(this.exportedObject); rebind(); } @@ -144,7 +140,6 @@ public class JndiRmiServiceExporter extends RmiBasedExporter implements Initiali logger.info("Unbinding RMI service from JNDI location [" + this.jndiName + "]"); } this.jndiTemplate.unbind(this.jndiName); - PortableRemoteObject.unexportObject(this.exportedObject); } } diff --git a/fine-spring/src/com/fr/third/springframework/remoting/rmi/RmiClientInterceptorUtils.java b/fine-spring/src/com/fr/third/springframework/remoting/rmi/RmiClientInterceptorUtils.java index 400c64e84..5c1fa0d61 100644 --- a/fine-spring/src/com/fr/third/springframework/remoting/rmi/RmiClientInterceptorUtils.java +++ b/fine-spring/src/com/fr/third/springframework/remoting/rmi/RmiClientInterceptorUtils.java @@ -29,10 +29,6 @@ import java.rmi.UnknownHostException; import org.aopalliance.intercept.MethodInvocation; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.omg.CORBA.COMM_FAILURE; -import org.omg.CORBA.CompletionStatus; -import org.omg.CORBA.NO_RESPONSE; -import org.omg.CORBA.SystemException; import com.fr.third.springframework.remoting.RemoteAccessException; import com.fr.third.springframework.remoting.RemoteConnectFailureException; @@ -184,8 +180,9 @@ public abstract class RmiClientInterceptorUtils { * @param ex the RMI exception to check */ private static boolean isCorbaConnectFailure(Throwable ex) { - return ((ex instanceof COMM_FAILURE || ex instanceof NO_RESPONSE) && - ((SystemException) ex).completed == CompletionStatus.COMPLETED_NO); + return (ex instanceof ConnectException || ex instanceof ConnectIOException || + ex instanceof UnknownHostException || ex instanceof NoSuchObjectException || + ex instanceof StubNotFoundException || ex.getCause() instanceof SocketException); } } diff --git a/fine-spring/src/com/fr/third/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java b/fine-spring/src/com/fr/third/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java index ce35a6e69..0920a2016 100644 --- a/fine-spring/src/com/fr/third/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java +++ b/fine-spring/src/com/fr/third/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java @@ -76,7 +76,6 @@ import com.fr.third.springframework.web.servlet.mvc.method.annotation.ExceptionH import com.fr.third.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; import com.fr.third.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; import com.fr.third.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; -import com.sun.prism.impl.BaseContext; /** * This is the main class providing the configuration behind the MVC Java config. diff --git a/fine-spring/src/com/fr/third/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java b/fine-spring/src/com/fr/third/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java index 3bc04abee..8944ad9b3 100644 --- a/fine-spring/src/com/fr/third/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java +++ b/fine-spring/src/com/fr/third/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java @@ -22,7 +22,7 @@ import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; -import com.fr.third.springframework.aop.objenesis.ObjenesisStd; +import com.fr.third.org.objenesis.ObjenesisStd; import org.aopalliance.intercept.MethodInterceptor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/fine-third-jdk11/src/com/fr/third/sun/misc/BASE64Decoder.java b/fine-third-jdk11/src/com/fr/third/sun/misc/BASE64Decoder.java new file mode 100644 index 000000000..8c261d23d --- /dev/null +++ b/fine-third-jdk11/src/com/fr/third/sun/misc/BASE64Decoder.java @@ -0,0 +1,96 @@ +package com.fr.third.sun.misc; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.PushbackInputStream; + +/** + * @author zhouping + * @version 10.0 + * Created by zhouping on 2019/10/28 + */ +public class BASE64Decoder extends CharacterDecoder { + private static final char[] pem_array = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'}; + private static final byte[] pem_convert_array = new byte[256]; + byte[] decode_buffer = new byte[4]; + + public BASE64Decoder() { + } + + protected int bytesPerAtom() { + return 4; + } + + protected int bytesPerLine() { + return 72; + } + + protected void decodeAtom(PushbackInputStream var1, OutputStream var2, int var3) throws IOException { + byte var5 = -1; + byte var6 = -1; + byte var7 = -1; + byte var8 = -1; + if (var3 < 2) { + throw new CEFormatException("BASE64Decoder: Not enough bytes for an atom."); + } else { + int var4; + do { + var4 = var1.read(); + if (var4 == -1) { + throw new CEStreamExhausted(); + } + } while(var4 == 10 || var4 == 13); + + this.decode_buffer[0] = (byte)var4; + var4 = this.readFully(var1, this.decode_buffer, 1, var3 - 1); + if (var4 == -1) { + throw new CEStreamExhausted(); + } else { + if (var3 > 3 && this.decode_buffer[3] == 61) { + var3 = 3; + } + + if (var3 > 2 && this.decode_buffer[2] == 61) { + var3 = 2; + } + + switch(var3) { + case 4: + var8 = pem_convert_array[this.decode_buffer[3] & 255]; + case 3: + var7 = pem_convert_array[this.decode_buffer[2] & 255]; + case 2: + var6 = pem_convert_array[this.decode_buffer[1] & 255]; + var5 = pem_convert_array[this.decode_buffer[0] & 255]; + default: + switch(var3) { + case 2: + var2.write((byte)(var5 << 2 & 252 | var6 >>> 4 & 3)); + break; + case 3: + var2.write((byte)(var5 << 2 & 252 | var6 >>> 4 & 3)); + var2.write((byte)(var6 << 4 & 240 | var7 >>> 2 & 15)); + break; + case 4: + var2.write((byte)(var5 << 2 & 252 | var6 >>> 4 & 3)); + var2.write((byte)(var6 << 4 & 240 | var7 >>> 2 & 15)); + var2.write((byte)(var7 << 6 & 192 | var8 & 63)); + } + + } + } + } + } + + static { + int var0; + for(var0 = 0; var0 < 255; ++var0) { + pem_convert_array[var0] = -1; + } + + for(var0 = 0; var0 < pem_array.length; ++var0) { + pem_convert_array[pem_array[var0]] = (byte)var0; + } + + } +} \ No newline at end of file diff --git a/fine-third-jdk11/src/com/fr/third/sun/misc/BASE64Encoder.java b/fine-third-jdk11/src/com/fr/third/sun/misc/BASE64Encoder.java new file mode 100644 index 000000000..8942cc796 --- /dev/null +++ b/fine-third-jdk11/src/com/fr/third/sun/misc/BASE64Encoder.java @@ -0,0 +1,62 @@ +package com.fr.third.sun.misc; + +import java.io.IOException; +import java.io.OutputStream; + +/** + * @author zhouping + * @version 10.0 + * Created by zhouping on 2019/10/28 + */ +public class BASE64Encoder extends CharacterEncoder { + + private static final char[] pem_array = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'}; + + public BASE64Encoder() { + + } + + protected int bytesPerAtom() { + + return 3; + } + + protected int bytesPerLine() { + + return 57; + } + + protected void encodeAtom(OutputStream var1, byte[] var2, int var3, int var4) throws IOException { + + byte var5; + if (var4 == 1) { + var5 = var2[var3]; + byte var6 = 0; + boolean var7 = false; + var1.write(pem_array[var5 >>> 2 & 63]); + var1.write(pem_array[(var5 << 4 & 48) + (var6 >>> 4 & 15)]); + var1.write(61); + var1.write(61); + } else { + byte var8; + if (var4 == 2) { + var5 = var2[var3]; + var8 = var2[var3 + 1]; + byte var9 = 0; + var1.write(pem_array[var5 >>> 2 & 63]); + var1.write(pem_array[(var5 << 4 & 48) + (var8 >>> 4 & 15)]); + var1.write(pem_array[(var8 << 2 & 60) + (var9 >>> 6 & 3)]); + var1.write(61); + } else { + var5 = var2[var3]; + var8 = var2[var3 + 1]; + byte var10 = var2[var3 + 2]; + var1.write(pem_array[var5 >>> 2 & 63]); + var1.write(pem_array[(var5 << 4 & 48) + (var8 >>> 4 & 15)]); + var1.write(pem_array[(var8 << 2 & 60) + (var10 >>> 6 & 3)]); + var1.write(pem_array[var10 & 63]); + } + } + + } +} \ No newline at end of file diff --git a/fine-third-jdk11/src/com/fr/third/sun/misc/CEFormatException.java b/fine-third-jdk11/src/com/fr/third/sun/misc/CEFormatException.java new file mode 100644 index 000000000..947c6bf8a --- /dev/null +++ b/fine-third-jdk11/src/com/fr/third/sun/misc/CEFormatException.java @@ -0,0 +1,16 @@ +package com.fr.third.sun.misc; + +import java.io.IOException; + +/** + * @author zhouping + * @version 10.0 + * Created by zhouping on 2019/10/28 + */ +public class CEFormatException extends IOException { + + public CEFormatException(String var1) { + + super(var1); + } +} \ No newline at end of file diff --git a/fine-third-jdk11/src/com/fr/third/sun/misc/CEStreamExhausted.java b/fine-third-jdk11/src/com/fr/third/sun/misc/CEStreamExhausted.java new file mode 100644 index 000000000..c02f142dd --- /dev/null +++ b/fine-third-jdk11/src/com/fr/third/sun/misc/CEStreamExhausted.java @@ -0,0 +1,15 @@ +package com.fr.third.sun.misc; + +import java.io.IOException; + +/** + * @author zhouping + * @version 10.0 + * Created by zhouping on 2019/10/28 + */ +public class CEStreamExhausted extends IOException { + + public CEStreamExhausted() { + + } +} \ No newline at end of file diff --git a/fine-third-jdk11/src/com/fr/third/sun/misc/CharacterDecoder.java b/fine-third-jdk11/src/com/fr/third/sun/misc/CharacterDecoder.java new file mode 100644 index 000000000..fe8d50066 --- /dev/null +++ b/fine-third-jdk11/src/com/fr/third/sun/misc/CharacterDecoder.java @@ -0,0 +1,107 @@ +package com.fr.third.sun.misc; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PushbackInputStream; +import java.nio.ByteBuffer; + +/** + * @author zhouping + * @version 10.0 + * Created by zhouping on 2019/10/28 + */ +public abstract class CharacterDecoder { + public CharacterDecoder() { + } + + protected abstract int bytesPerAtom(); + + protected abstract int bytesPerLine(); + + protected void decodeBufferPrefix(PushbackInputStream var1, OutputStream var2) throws IOException { + } + + protected void decodeBufferSuffix(PushbackInputStream var1, OutputStream var2) throws IOException { + } + + protected int decodeLinePrefix(PushbackInputStream var1, OutputStream var2) throws IOException { + return this.bytesPerLine(); + } + + protected void decodeLineSuffix(PushbackInputStream var1, OutputStream var2) throws IOException { + } + + protected void decodeAtom(PushbackInputStream var1, OutputStream var2, int var3) throws IOException { + throw new CEStreamExhausted(); + } + + protected int readFully(InputStream var1, byte[] var2, int var3, int var4) throws IOException { + for(int var5 = 0; var5 < var4; ++var5) { + int var6 = var1.read(); + if (var6 == -1) { + return var5 == 0 ? -1 : var5; + } + + var2[var5 + var3] = (byte)var6; + } + + return var4; + } + + public void decodeBuffer(InputStream var1, OutputStream var2) throws IOException { + int var4 = 0; + PushbackInputStream var5 = new PushbackInputStream(var1); + this.decodeBufferPrefix(var5, var2); + + while(true) { + try { + int var6 = this.decodeLinePrefix(var5, var2); + + int var3; + for(var3 = 0; var3 + this.bytesPerAtom() < var6; var3 += this.bytesPerAtom()) { + this.decodeAtom(var5, var2, this.bytesPerAtom()); + var4 += this.bytesPerAtom(); + } + + if (var3 + this.bytesPerAtom() == var6) { + this.decodeAtom(var5, var2, this.bytesPerAtom()); + var4 += this.bytesPerAtom(); + } else { + this.decodeAtom(var5, var2, var6 - var3); + var4 += var6 - var3; + } + + this.decodeLineSuffix(var5, var2); + } catch (CEStreamExhausted var8) { + this.decodeBufferSuffix(var5, var2); + return; + } + } + } + + public byte[] decodeBuffer(String var1) throws IOException { + byte[] var2 = new byte[var1.length()]; + var1.getBytes(0, var1.length(), var2, 0); + ByteArrayInputStream var3 = new ByteArrayInputStream(var2); + ByteArrayOutputStream var4 = new ByteArrayOutputStream(); + this.decodeBuffer(var3, var4); + return var4.toByteArray(); + } + + public byte[] decodeBuffer(InputStream var1) throws IOException { + ByteArrayOutputStream var2 = new ByteArrayOutputStream(); + this.decodeBuffer(var1, var2); + return var2.toByteArray(); + } + + public ByteBuffer decodeBufferToByteBuffer(String var1) throws IOException { + return ByteBuffer.wrap(this.decodeBuffer(var1)); + } + + public ByteBuffer decodeBufferToByteBuffer(InputStream var1) throws IOException { + return ByteBuffer.wrap(this.decodeBuffer(var1)); + } +} \ No newline at end of file diff --git a/fine-third-jdk11/src/com/fr/third/sun/misc/CharacterEncoder.java b/fine-third-jdk11/src/com/fr/third/sun/misc/CharacterEncoder.java new file mode 100644 index 000000000..41c77ede0 --- /dev/null +++ b/fine-third-jdk11/src/com/fr/third/sun/misc/CharacterEncoder.java @@ -0,0 +1,186 @@ +package com.fr.third.sun.misc; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintStream; +import java.nio.ByteBuffer; + +/** + * @author zhouping + * @version 10.0 + * Created by zhouping on 2019/10/28 + */ +public abstract class CharacterEncoder { + protected PrintStream pStream; + + public CharacterEncoder() { + } + + protected abstract int bytesPerAtom(); + + protected abstract int bytesPerLine(); + + protected void encodeBufferPrefix(OutputStream var1) throws IOException { + this.pStream = new PrintStream(var1); + } + + protected void encodeBufferSuffix(OutputStream var1) throws IOException { + } + + protected void encodeLinePrefix(OutputStream var1, int var2) throws IOException { + } + + protected void encodeLineSuffix(OutputStream var1) throws IOException { + this.pStream.println(); + } + + protected abstract void encodeAtom(OutputStream var1, byte[] var2, int var3, int var4) throws IOException; + + protected int readFully(InputStream var1, byte[] var2) throws IOException { + for (int var3 = 0; var3 < var2.length; ++var3) { + int var4 = var1.read(); + if (var4 == -1) { + return var3; + } + + var2[var3] = (byte) var4; + } + + return var2.length; + } + + public void encode(InputStream var1, OutputStream var2) throws IOException { + byte[] var5 = new byte[this.bytesPerLine()]; + this.encodeBufferPrefix(var2); + + while (true) { + int var4 = this.readFully(var1, var5); + if (var4 == 0) { + break; + } + + this.encodeLinePrefix(var2, var4); + + for (int var3 = 0; var3 < var4; var3 += this.bytesPerAtom()) { + if (var3 + this.bytesPerAtom() <= var4) { + this.encodeAtom(var2, var5, var3, this.bytesPerAtom()); + } else { + this.encodeAtom(var2, var5, var3, var4 - var3); + } + } + + if (var4 < this.bytesPerLine()) { + break; + } + + this.encodeLineSuffix(var2); + } + + this.encodeBufferSuffix(var2); + } + + public void encode(byte[] var1, OutputStream var2) throws IOException { + ByteArrayInputStream var3 = new ByteArrayInputStream(var1); + this.encode((InputStream) var3, var2); + } + + public String encode(byte[] var1) { + ByteArrayOutputStream var2 = new ByteArrayOutputStream(); + ByteArrayInputStream var3 = new ByteArrayInputStream(var1); + String var4 = null; + + try { + this.encode((InputStream) var3, var2); + var4 = var2.toString("8859_1"); + return var4; + } catch (Exception var6) { + throw new Error("CharacterEncoder.encode internal error"); + } + } + + private byte[] getBytes(ByteBuffer var1) { + byte[] var2 = null; + if (var1.hasArray()) { + byte[] var3 = var1.array(); + if (var3.length == var1.capacity() && var3.length == var1.remaining()) { + var2 = var3; + var1.position(var1.limit()); + } + } + + if (var2 == null) { + var2 = new byte[var1.remaining()]; + var1.get(var2); + } + + return var2; + } + + public void encode(ByteBuffer var1, OutputStream var2) throws IOException { + byte[] var3 = this.getBytes(var1); + this.encode(var3, var2); + } + + public String encode(ByteBuffer var1) { + byte[] var2 = this.getBytes(var1); + return this.encode(var2); + } + + public void encodeBuffer(InputStream var1, OutputStream var2) throws IOException { + byte[] var5 = new byte[this.bytesPerLine()]; + this.encodeBufferPrefix(var2); + + int var4; + do { + var4 = this.readFully(var1, var5); + if (var4 == 0) { + break; + } + + this.encodeLinePrefix(var2, var4); + + for (int var3 = 0; var3 < var4; var3 += this.bytesPerAtom()) { + if (var3 + this.bytesPerAtom() <= var4) { + this.encodeAtom(var2, var5, var3, this.bytesPerAtom()); + } else { + this.encodeAtom(var2, var5, var3, var4 - var3); + } + } + + this.encodeLineSuffix(var2); + } while (var4 >= this.bytesPerLine()); + + this.encodeBufferSuffix(var2); + } + + public void encodeBuffer(byte[] var1, OutputStream var2) throws IOException { + ByteArrayInputStream var3 = new ByteArrayInputStream(var1); + this.encodeBuffer((InputStream) var3, var2); + } + + public String encodeBuffer(byte[] var1) { + ByteArrayOutputStream var2 = new ByteArrayOutputStream(); + ByteArrayInputStream var3 = new ByteArrayInputStream(var1); + + try { + this.encodeBuffer((InputStream) var3, var2); + } catch (Exception var5) { + throw new Error("CharacterEncoder.encodeBuffer internal error"); + } + + return var2.toString(); + } + + public void encodeBuffer(ByteBuffer var1, OutputStream var2) throws IOException { + byte[] var3 = this.getBytes(var1); + this.encodeBuffer(var3, var2); + } + + public String encodeBuffer(ByteBuffer var1) { + byte[] var2 = this.getBytes(var1); + return this.encodeBuffer(var2); + } +} \ No newline at end of file diff --git a/fine-third-jdk11/src/com/fr/third/sun/misc/Cleaner.java b/fine-third-jdk11/src/com/fr/third/sun/misc/Cleaner.java new file mode 100644 index 000000000..75b154185 --- /dev/null +++ b/fine-third-jdk11/src/com/fr/third/sun/misc/Cleaner.java @@ -0,0 +1,84 @@ +package com.fr.third.sun.misc; + +import java.lang.ref.PhantomReference; +import java.lang.ref.ReferenceQueue; +import java.security.AccessController; +import java.security.PrivilegedAction; + +/** + * @author zhouping + * @version 10.0 + * Created by zhouping on 2019/10/29 + */ +public class Cleaner extends PhantomReference { + private static final ReferenceQueue dummyQueue = new ReferenceQueue(); + private static Cleaner first = null; + private Cleaner next = null; + private Cleaner prev = null; + private final Runnable thunk; + + private static synchronized Cleaner add(Cleaner var0) { + if (first != null) { + var0.next = first; + first.prev = var0; + } + + first = var0; + return var0; + } + + private static synchronized boolean remove(Cleaner var0) { + if (var0.next == var0) { + return false; + } else { + if (first == var0) { + if (var0.next != null) { + first = var0.next; + } else { + first = var0.prev; + } + } + + if (var0.next != null) { + var0.next.prev = var0.prev; + } + + if (var0.prev != null) { + var0.prev.next = var0.next; + } + + var0.next = var0; + var0.prev = var0; + return true; + } + } + + private Cleaner(Object var1, Runnable var2) { + super(var1, dummyQueue); + this.thunk = var2; + } + + public static Cleaner create(Object var0, Runnable var1) { + return var1 == null ? null : add(new Cleaner(var0, var1)); + } + + public void clean() { + if (remove(this)) { + try { + this.thunk.run(); + } catch (final Throwable var2) { + AccessController.doPrivileged(new PrivilegedAction() { + public Void run() { + if (System.err != null) { + (new Error("Cleaner terminated abnormally", var2)).printStackTrace(); + } + + System.exit(1); + return null; + } + }); + } + + } + } +} diff --git a/fine-third-jdk11/src/com/sun/activation/registries/LogSupport.java b/fine-third-jdk11/src/com/sun/activation/registries/LogSupport.java new file mode 100644 index 000000000..1ccdb3529 --- /dev/null +++ b/fine-third-jdk11/src/com/sun/activation/registries/LogSupport.java @@ -0,0 +1,85 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package com.sun.activation.registries; + +import java.io.*; +import java.util.logging.*; + +/** + * Logging related methods. + */ +public class LogSupport { + private static boolean debug = false; + private static Logger logger; + private static final Level level = Level.FINE; + + static { + try { + debug = Boolean.getBoolean("javax.activation.debug"); + } catch (Throwable t) { + // ignore any errors + } + logger = Logger.getLogger("javax.activation"); + } + + /** + * Constructor. + */ + private LogSupport() { + // private constructor, can't create instances + } + + public static void log(String msg) { + if (debug) + System.out.println(msg); + logger.log(level, msg); + } + + public static void log(String msg, Throwable t) { + if (debug) + System.out.println(msg + "; Exception: " + t); + logger.log(level, msg, t); + } + + public static boolean isLoggable() { + return debug || logger.isLoggable(level); + } +} diff --git a/fine-third-jdk11/src/com/sun/activation/registries/MailcapFile.java b/fine-third-jdk11/src/com/sun/activation/registries/MailcapFile.java new file mode 100644 index 000000000..3553968e9 --- /dev/null +++ b/fine-third-jdk11/src/com/sun/activation/registries/MailcapFile.java @@ -0,0 +1,578 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package com.sun.activation.registries; + +import java.io.*; +import java.util.*; + +public class MailcapFile { + + /** + * A Map indexed by MIME type (string) that references + * a Map of commands for each type. The comand Map + * is indexed by the command name and references a List of + * class names (strings) for each command. + */ + private Map type_hash = new HashMap(); + + /** + * Another Map like above, but for fallback entries. + */ + private Map fallback_hash = new HashMap(); + + /** + * A Map indexed by MIME type (string) that references + * a List of native commands (string) corresponding to the type. + */ + private Map native_commands = new HashMap(); + + private static boolean addReverse = false; + + static { + try { + addReverse = Boolean.getBoolean("javax.activation.addreverse"); + } catch (Throwable t) { + // ignore any errors + } + } + + /** + * The constructor that takes a filename as an argument. + * + * @param new_fname The file name of the mailcap file. + */ + public MailcapFile(String new_fname) throws IOException { + if (LogSupport.isLoggable()) + LogSupport.log("new MailcapFile: file " + new_fname); + FileReader reader = null; + try { + reader = new FileReader(new_fname); + parse(new BufferedReader(reader)); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException ex) { } + } + } + } + + /** + * The constructor that takes an input stream as an argument. + * + * @param is the input stream + */ + public MailcapFile(InputStream is) throws IOException { + if (LogSupport.isLoggable()) + LogSupport.log("new MailcapFile: InputStream"); + parse(new BufferedReader(new InputStreamReader(is, "iso-8859-1"))); + } + + /** + * Mailcap file default constructor. + */ + public MailcapFile() { + if (LogSupport.isLoggable()) + LogSupport.log("new MailcapFile: default"); + } + + /** + * Get the Map of MailcapEntries based on the MIME type. + * + *

+ * Semantics: First check for the literal mime type, + * if that fails looks for wildcard /\* and return that. Return the + * list of all that hit. + */ + public Map getMailcapList(String mime_type) { + Map search_result = null; + Map wildcard_result = null; + + // first try the literal + search_result = (Map)type_hash.get(mime_type); + + // ok, now try the wildcard + int separator = mime_type.indexOf('/'); + String subtype = mime_type.substring(separator + 1); + if (!subtype.equals("*")) { + String type = mime_type.substring(0, separator + 1) + "*"; + wildcard_result = (Map)type_hash.get(type); + + if (wildcard_result != null) { // damn, we have to merge!!! + if (search_result != null) + search_result = + mergeResults(search_result, wildcard_result); + else + search_result = wildcard_result; + } + } + return search_result; + } + + /** + * Get the Map of fallback MailcapEntries based on the MIME type. + * + *

+ * Semantics: First check for the literal mime type, + * if that fails looks for wildcard /\* and return that. Return the + * list of all that hit. + */ + public Map getMailcapFallbackList(String mime_type) { + Map search_result = null; + Map wildcard_result = null; + + // first try the literal + search_result = (Map)fallback_hash.get(mime_type); + + // ok, now try the wildcard + int separator = mime_type.indexOf('/'); + String subtype = mime_type.substring(separator + 1); + if (!subtype.equals("*")) { + String type = mime_type.substring(0, separator + 1) + "*"; + wildcard_result = (Map)fallback_hash.get(type); + + if (wildcard_result != null) { // damn, we have to merge!!! + if (search_result != null) + search_result = + mergeResults(search_result, wildcard_result); + else + search_result = wildcard_result; + } + } + return search_result; + } + + /** + * Return all the MIME types known to this mailcap file. + */ + public String[] getMimeTypes() { + Set types = new HashSet(type_hash.keySet()); + types.addAll(fallback_hash.keySet()); + types.addAll(native_commands.keySet()); + String[] mts = new String[types.size()]; + mts = (String[])types.toArray(mts); + return mts; + } + + /** + * Return all the native comands for the given MIME type. + */ + public String[] getNativeCommands(String mime_type) { + String[] cmds = null; + List v = + (List)native_commands.get(mime_type.toLowerCase(Locale.ENGLISH)); + if (v != null) { + cmds = new String[v.size()]; + cmds = (String[])v.toArray(cmds); + } + return cmds; + } + + /** + * Merge the first hash into the second. + * This merge will only effect the hashtable that is + * returned, we don't want to touch the one passed in since + * its integrity must be maintained. + */ + private Map mergeResults(Map first, Map second) { + Iterator verb_enum = second.keySet().iterator(); + Map clonedHash = new HashMap(first); + + // iterate through the verbs in the second map + while (verb_enum.hasNext()) { + String verb = (String)verb_enum.next(); + List cmdVector = (List)clonedHash.get(verb); + if (cmdVector == null) { + clonedHash.put(verb, second.get(verb)); + } else { + // merge the two + List oldV = (List)second.get(verb); + cmdVector = new ArrayList(cmdVector); + cmdVector.addAll(oldV); + clonedHash.put(verb, cmdVector); + } + } + return clonedHash; + } + + /** + * appendToMailcap: Append to this Mailcap DB, use the mailcap + * format: + * Comment == "# comment string + * Entry == "mimetype; javabeanclass + * + * Example: + * # this is a comment + * image/gif jaf.viewers.ImageViewer + */ + public void appendToMailcap(String mail_cap) { + if (LogSupport.isLoggable()) + LogSupport.log("appendToMailcap: " + mail_cap); + try { + parse(new StringReader(mail_cap)); + } catch (IOException ex) { + // can't happen + } + } + + /** + * parse file into a hash table of MC Type Entry Obj + */ + private void parse(Reader reader) throws IOException { + BufferedReader buf_reader = new BufferedReader(reader); + String line = null; + String continued = null; + + while ((line = buf_reader.readLine()) != null) { + // LogSupport.log("parsing line: " + line); + + line = line.trim(); + + try { + if (line.charAt(0) == '#') + continue; + if (line.charAt(line.length() - 1) == '\\') { + if (continued != null) + continued += line.substring(0, line.length() - 1); + else + continued = line.substring(0, line.length() - 1); + } else if (continued != null) { + // handle the two strings + continued = continued + line; + // LogSupport.log("parse: " + continued); + try { + parseLine(continued); + } catch (MailcapParseException e) { + //e.printStackTrace(); + } + continued = null; + } + else { + // LogSupport.log("parse: " + line); + try { + parseLine(line); + // LogSupport.log("hash.size = " + type_hash.size()); + } catch (MailcapParseException e) { + //e.printStackTrace(); + } + } + } catch (StringIndexOutOfBoundsException e) {} + } + } + + /** + * A routine to parse individual entries in a Mailcap file. + * + * Note that this routine does not handle line continuations. + * They should have been handled prior to calling this routine. + */ + protected void parseLine(String mailcapEntry) + throws MailcapParseException, IOException { + MailcapTokenizer tokenizer = new MailcapTokenizer(mailcapEntry); + tokenizer.setIsAutoquoting(false); + + if (LogSupport.isLoggable()) + LogSupport.log("parse: " + mailcapEntry); + // parse the primary type + int currentToken = tokenizer.nextToken(); + if (currentToken != MailcapTokenizer.STRING_TOKEN) { + reportParseError(MailcapTokenizer.STRING_TOKEN, currentToken, + tokenizer.getCurrentTokenValue()); + } + String primaryType = + tokenizer.getCurrentTokenValue().toLowerCase(Locale.ENGLISH); + String subType = "*"; + + // parse the '/' between primary and sub + // if it's not present that's ok, we just don't have a subtype + currentToken = tokenizer.nextToken(); + if ((currentToken != MailcapTokenizer.SLASH_TOKEN) && + (currentToken != MailcapTokenizer.SEMICOLON_TOKEN)) { + reportParseError(MailcapTokenizer.SLASH_TOKEN, + MailcapTokenizer.SEMICOLON_TOKEN, currentToken, + tokenizer.getCurrentTokenValue()); + } + + // only need to look for a sub type if we got a '/' + if (currentToken == MailcapTokenizer.SLASH_TOKEN) { + // parse the sub type + currentToken = tokenizer.nextToken(); + if (currentToken != MailcapTokenizer.STRING_TOKEN) { + reportParseError(MailcapTokenizer.STRING_TOKEN, + currentToken, tokenizer.getCurrentTokenValue()); + } + subType = + tokenizer.getCurrentTokenValue().toLowerCase(Locale.ENGLISH); + + // get the next token to simplify the next step + currentToken = tokenizer.nextToken(); + } + + String mimeType = primaryType + "/" + subType; + + if (LogSupport.isLoggable()) + LogSupport.log(" Type: " + mimeType); + + // now setup the commands hashtable + Map commands = new LinkedHashMap(); // keep commands in order found + + // parse the ';' that separates the type from the parameters + if (currentToken != MailcapTokenizer.SEMICOLON_TOKEN) { + reportParseError(MailcapTokenizer.SEMICOLON_TOKEN, + currentToken, tokenizer.getCurrentTokenValue()); + } + // eat it + + // parse the required view command + tokenizer.setIsAutoquoting(true); + currentToken = tokenizer.nextToken(); + tokenizer.setIsAutoquoting(false); + if ((currentToken != MailcapTokenizer.STRING_TOKEN) && + (currentToken != MailcapTokenizer.SEMICOLON_TOKEN)) { + reportParseError(MailcapTokenizer.STRING_TOKEN, + MailcapTokenizer.SEMICOLON_TOKEN, currentToken, + tokenizer.getCurrentTokenValue()); + } + + if (currentToken == MailcapTokenizer.STRING_TOKEN) { + // have a native comand, save the entire mailcap entry + //String nativeCommand = tokenizer.getCurrentTokenValue(); + List v = (List)native_commands.get(mimeType); + if (v == null) { + v = new ArrayList(); + v.add(mailcapEntry); + native_commands.put(mimeType, v); + } else { + // XXX - check for duplicates? + v.add(mailcapEntry); + } + } + + // only have to get the next token if the current one isn't a ';' + if (currentToken != MailcapTokenizer.SEMICOLON_TOKEN) { + currentToken = tokenizer.nextToken(); + } + + // look for a ';' which will indicate whether + // a parameter list is present or not + if (currentToken == MailcapTokenizer.SEMICOLON_TOKEN) { + boolean isFallback = false; + do { + // eat the ';' + + // parse the parameter name + currentToken = tokenizer.nextToken(); + if (currentToken != MailcapTokenizer.STRING_TOKEN) { + reportParseError(MailcapTokenizer.STRING_TOKEN, + currentToken, tokenizer.getCurrentTokenValue()); + } + String paramName = tokenizer.getCurrentTokenValue(). + toLowerCase(Locale.ENGLISH); + + // parse the '=' which separates the name from the value + currentToken = tokenizer.nextToken(); + if ((currentToken != MailcapTokenizer.EQUALS_TOKEN) && + (currentToken != MailcapTokenizer.SEMICOLON_TOKEN) && + (currentToken != MailcapTokenizer.EOI_TOKEN)) { + reportParseError(MailcapTokenizer.EQUALS_TOKEN, + MailcapTokenizer.SEMICOLON_TOKEN, + MailcapTokenizer.EOI_TOKEN, + currentToken, tokenizer.getCurrentTokenValue()); + } + + // we only have a useful command if it is named + if (currentToken == MailcapTokenizer.EQUALS_TOKEN) { + // eat it + + // parse the parameter value (which is autoquoted) + tokenizer.setIsAutoquoting(true); + currentToken = tokenizer.nextToken(); + tokenizer.setIsAutoquoting(false); + if (currentToken != MailcapTokenizer.STRING_TOKEN) { + reportParseError(MailcapTokenizer.STRING_TOKEN, + currentToken, tokenizer.getCurrentTokenValue()); + } + String paramValue = + tokenizer.getCurrentTokenValue(); + + // add the class to the list iff it is one we care about + if (paramName.startsWith("x-java-")) { + String commandName = paramName.substring(7); + // 7 == "x-java-".length + + if (commandName.equals("fallback-entry") && + paramValue.equalsIgnoreCase("true")) { + isFallback = true; + } else { + + // setup the class entry list + if (LogSupport.isLoggable()) + LogSupport.log(" Command: " + commandName + + ", Class: " + paramValue); + List classes = (List)commands.get(commandName); + if (classes == null) { + classes = new ArrayList(); + commands.put(commandName, classes); + } + if (addReverse) + classes.add(0, paramValue); + else + classes.add(paramValue); + } + } + + // set up the next iteration + currentToken = tokenizer.nextToken(); + } + } while (currentToken == MailcapTokenizer.SEMICOLON_TOKEN); + + Map masterHash = isFallback ? fallback_hash : type_hash; + Map curcommands = + (Map)masterHash.get(mimeType); + if (curcommands == null) { + masterHash.put(mimeType, commands); + } else { + if (LogSupport.isLoggable()) + LogSupport.log("Merging commands for type " + mimeType); + // have to merge current and new commands + // first, merge list of classes for commands already known + Iterator cn = curcommands.keySet().iterator(); + while (cn.hasNext()) { + String cmdName = (String)cn.next(); + List ccv = (List)curcommands.get(cmdName); + List cv = (List)commands.get(cmdName); + if (cv == null) + continue; + // add everything in cv to ccv, if it's not already there + Iterator cvn = cv.iterator(); + while (cvn.hasNext()) { + String clazz = (String)cvn.next(); + if (!ccv.contains(clazz)) + if (addReverse) + ccv.add(0, clazz); + else + ccv.add(clazz); + } + } + // now, add commands not previously known + cn = commands.keySet().iterator(); + while (cn.hasNext()) { + String cmdName = (String)cn.next(); + if (curcommands.containsKey(cmdName)) + continue; + List cv = (List)commands.get(cmdName); + curcommands.put(cmdName, cv); + } + } + } else if (currentToken != MailcapTokenizer.EOI_TOKEN) { + reportParseError(MailcapTokenizer.EOI_TOKEN, + MailcapTokenizer.SEMICOLON_TOKEN, + currentToken, tokenizer.getCurrentTokenValue()); + } + } + + protected static void reportParseError(int expectedToken, int actualToken, + String actualTokenValue) throws MailcapParseException { + throw new MailcapParseException("Encountered a " + + MailcapTokenizer.nameForToken(actualToken) + " token (" + + actualTokenValue + ") while expecting a " + + MailcapTokenizer.nameForToken(expectedToken) + " token."); + } + + protected static void reportParseError(int expectedToken, + int otherExpectedToken, int actualToken, String actualTokenValue) + throws MailcapParseException { + throw new MailcapParseException("Encountered a " + + MailcapTokenizer.nameForToken(actualToken) + " token (" + + actualTokenValue + ") while expecting a " + + MailcapTokenizer.nameForToken(expectedToken) + " or a " + + MailcapTokenizer.nameForToken(otherExpectedToken) + " token."); + } + + protected static void reportParseError(int expectedToken, + int otherExpectedToken, int anotherExpectedToken, int actualToken, + String actualTokenValue) throws MailcapParseException { + if (LogSupport.isLoggable()) + LogSupport.log("PARSE ERROR: " + "Encountered a " + + MailcapTokenizer.nameForToken(actualToken) + " token (" + + actualTokenValue + ") while expecting a " + + MailcapTokenizer.nameForToken(expectedToken) + ", a " + + MailcapTokenizer.nameForToken(otherExpectedToken) + ", or a " + + MailcapTokenizer.nameForToken(anotherExpectedToken) + " token."); + throw new MailcapParseException("Encountered a " + + MailcapTokenizer.nameForToken(actualToken) + " token (" + + actualTokenValue + ") while expecting a " + + MailcapTokenizer.nameForToken(expectedToken) + ", a " + + MailcapTokenizer.nameForToken(otherExpectedToken) + ", or a " + + MailcapTokenizer.nameForToken(anotherExpectedToken) + " token."); + } + + /** for debugging + public static void main(String[] args) throws Exception { + Map masterHash = new HashMap(); + for (int i = 0; i < args.length; ++i) { + System.out.println("Entry " + i + ": " + args[i]); + parseLine(args[i], masterHash); + } + + Enumeration types = masterHash.keys(); + while (types.hasMoreElements()) { + String key = (String)types.nextElement(); + System.out.println("MIME Type: " + key); + + Map commandHash = (Map)masterHash.get(key); + Enumeration commands = commandHash.keys(); + while (commands.hasMoreElements()) { + String command = (String)commands.nextElement(); + System.out.println(" Command: " + command); + + Vector classes = (Vector)commandHash.get(command); + for (int i = 0; i < classes.size(); ++i) { + System.out.println(" Class: " + + (String)classes.elementAt(i)); + } + } + + System.out.println(""); + } + } + */ +} diff --git a/fine-third-jdk11/src/com/sun/activation/registries/MailcapParseException.java b/fine-third-jdk11/src/com/sun/activation/registries/MailcapParseException.java new file mode 100644 index 000000000..eca133ba4 --- /dev/null +++ b/fine-third-jdk11/src/com/sun/activation/registries/MailcapParseException.java @@ -0,0 +1,55 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package com.sun.activation.registries; + +/** + * A class to encapsulate Mailcap parsing related exceptions + */ +public class MailcapParseException extends Exception { + + public MailcapParseException() { + super(); + } + + public MailcapParseException(String inInfo) { + super(inInfo); + } +} diff --git a/fine-third-jdk11/src/com/sun/activation/registries/MailcapTokenizer.java b/fine-third-jdk11/src/com/sun/activation/registries/MailcapTokenizer.java new file mode 100644 index 000000000..96435687a --- /dev/null +++ b/fine-third-jdk11/src/com/sun/activation/registries/MailcapTokenizer.java @@ -0,0 +1,337 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package com.sun.activation.registries; + +/** + * A tokenizer for strings in the form of "foo/bar; prop1=val1; ... ". + * Useful for parsing MIME content types. + */ +public class MailcapTokenizer { + + public static final int UNKNOWN_TOKEN = 0; + public static final int START_TOKEN = 1; + public static final int STRING_TOKEN = 2; + public static final int EOI_TOKEN = 5; + public static final int SLASH_TOKEN = '/'; + public static final int SEMICOLON_TOKEN = ';'; + public static final int EQUALS_TOKEN = '='; + + /** + * Constructor + * + * @parameter inputString the string to tokenize + */ + public MailcapTokenizer(String inputString) { + data = inputString; + dataIndex = 0; + dataLength = inputString.length(); + + currentToken = START_TOKEN; + currentTokenValue = ""; + + isAutoquoting = false; + autoquoteChar = ';'; + } + + /** + * Set whether auto-quoting is on or off. + * + * Auto-quoting means that all characters after the first + * non-whitespace, non-control character up to the auto-quote + * terminator character or EOI (minus any whitespace immediatley + * preceeding it) is considered a token. + * + * This is required for handling command strings in a mailcap entry. + */ + public void setIsAutoquoting(boolean value) { + isAutoquoting = value; + } + + /** + * Retrieve current token. + * + * @returns The current token value + */ + public int getCurrentToken() { + return currentToken; + } + + /* + * Get a String that describes the given token. + */ + public static String nameForToken(int token) { + String name = "really unknown"; + + switch(token) { + case UNKNOWN_TOKEN: + name = "unknown"; + break; + case START_TOKEN: + name = "start"; + break; + case STRING_TOKEN: + name = "string"; + break; + case EOI_TOKEN: + name = "EOI"; + break; + case SLASH_TOKEN: + name = "'/'"; + break; + case SEMICOLON_TOKEN: + name = "';'"; + break; + case EQUALS_TOKEN: + name = "'='"; + break; + } + + return name; + } + + /* + * Retrieve current token value. + * + * @returns A String containing the current token value + */ + public String getCurrentTokenValue() { + return currentTokenValue; + } + + /* + * Process the next token. + * + * @returns the next token + */ + public int nextToken() { + if (dataIndex < dataLength) { + // skip white space + while ((dataIndex < dataLength) && + (isWhiteSpaceChar(data.charAt(dataIndex)))) { + ++dataIndex; + } + + if (dataIndex < dataLength) { + // examine the current character and see what kind of token we have + char c = data.charAt(dataIndex); + if (isAutoquoting) { + if (c == ';' || c == '=') { + currentToken = c; + currentTokenValue = new Character(c).toString(); + ++dataIndex; + } else { + processAutoquoteToken(); + } + } else { + if (isStringTokenChar(c)) { + processStringToken(); + } else if ((c == '/') || (c == ';') || (c == '=')) { + currentToken = c; + currentTokenValue = new Character(c).toString(); + ++dataIndex; + } else { + currentToken = UNKNOWN_TOKEN; + currentTokenValue = new Character(c).toString(); + ++dataIndex; + } + } + } else { + currentToken = EOI_TOKEN; + currentTokenValue = null; + } + } else { + currentToken = EOI_TOKEN; + currentTokenValue = null; + } + + return currentToken; + } + + private void processStringToken() { + // capture the initial index + int initialIndex = dataIndex; + + // skip to 1st non string token character + while ((dataIndex < dataLength) && + isStringTokenChar(data.charAt(dataIndex))) { + ++dataIndex; + } + + currentToken = STRING_TOKEN; + currentTokenValue = data.substring(initialIndex, dataIndex); + } + + private void processAutoquoteToken() { + // capture the initial index + int initialIndex = dataIndex; + + // now skip to the 1st non-escaped autoquote termination character + // XXX - doesn't actually consider escaping + boolean foundTerminator = false; + while ((dataIndex < dataLength) && !foundTerminator) { + char c = data.charAt(dataIndex); + if (c != autoquoteChar) { + ++dataIndex; + } else { + foundTerminator = true; + } + } + + currentToken = STRING_TOKEN; + currentTokenValue = + fixEscapeSequences(data.substring(initialIndex, dataIndex)); + } + + private static boolean isSpecialChar(char c) { + boolean lAnswer = false; + + switch(c) { + case '(': + case ')': + case '<': + case '>': + case '@': + case ',': + case ';': + case ':': + case '\\': + case '"': + case '/': + case '[': + case ']': + case '?': + case '=': + lAnswer = true; + break; + } + + return lAnswer; + } + + private static boolean isControlChar(char c) { + return Character.isISOControl(c); + } + + private static boolean isWhiteSpaceChar(char c) { + return Character.isWhitespace(c); + } + + private static boolean isStringTokenChar(char c) { + return !isSpecialChar(c) && !isControlChar(c) && !isWhiteSpaceChar(c); + } + + private static String fixEscapeSequences(String inputString) { + int inputLength = inputString.length(); + StringBuffer buffer = new StringBuffer(); + buffer.ensureCapacity(inputLength); + + for (int i = 0; i < inputLength; ++i) { + char currentChar = inputString.charAt(i); + if (currentChar != '\\') { + buffer.append(currentChar); + } else { + if (i < inputLength - 1) { + char nextChar = inputString.charAt(i + 1); + buffer.append(nextChar); + + // force a skip over the next character too + ++i; + } else { + buffer.append(currentChar); + } + } + } + + return buffer.toString(); + } + + private String data; + private int dataIndex; + private int dataLength; + private int currentToken; + private String currentTokenValue; + private boolean isAutoquoting; + private char autoquoteChar; + + /* + public static void main(String[] args) { + for (int i = 0; i < args.length; ++i) { + MailcapTokenizer tokenizer = new MailcapTokenizer(args[i]); + + System.out.println("Original: |" + args[i] + "|"); + + int currentToken = tokenizer.nextToken(); + while (currentToken != EOI_TOKEN) { + switch(currentToken) { + case UNKNOWN_TOKEN: + System.out.println(" Unknown Token: |" + tokenizer.getCurrentTokenValue() + "|"); + break; + case START_TOKEN: + System.out.println(" Start Token: |" + tokenizer.getCurrentTokenValue() + "|"); + break; + case STRING_TOKEN: + System.out.println(" String Token: |" + tokenizer.getCurrentTokenValue() + "|"); + break; + case EOI_TOKEN: + System.out.println(" EOI Token: |" + tokenizer.getCurrentTokenValue() + "|"); + break; + case SLASH_TOKEN: + System.out.println(" Slash Token: |" + tokenizer.getCurrentTokenValue() + "|"); + break; + case SEMICOLON_TOKEN: + System.out.println(" Semicolon Token: |" + tokenizer.getCurrentTokenValue() + "|"); + break; + case EQUALS_TOKEN: + System.out.println(" Equals Token: |" + tokenizer.getCurrentTokenValue() + "|"); + break; + default: + System.out.println(" Really Unknown Token: |" + tokenizer.getCurrentTokenValue() + "|"); + break; + } + + currentToken = tokenizer.nextToken(); + } + + System.out.println(""); + } + } + */ +} diff --git a/fine-third-jdk11/src/com/sun/activation/registries/MimeTypeEntry.java b/fine-third-jdk11/src/com/sun/activation/registries/MimeTypeEntry.java new file mode 100644 index 000000000..67149360e --- /dev/null +++ b/fine-third-jdk11/src/com/sun/activation/registries/MimeTypeEntry.java @@ -0,0 +1,65 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package com.sun.activation.registries; + +import java.lang.*; + +public class MimeTypeEntry { + private String type; + private String extension; + + public MimeTypeEntry(String mime_type, String file_ext) { + type = mime_type; + extension = file_ext; + } + + public String getMIMEType() { + return type; + } + + public String getFileExtension() { + return extension; + } + + public String toString() { + return "MIMETypeEntry: " + type + ", " + extension; + } +} diff --git a/fine-third-jdk11/src/com/sun/activation/registries/MimeTypeFile.java b/fine-third-jdk11/src/com/sun/activation/registries/MimeTypeFile.java new file mode 100644 index 000000000..43bf32755 --- /dev/null +++ b/fine-third-jdk11/src/com/sun/activation/registries/MimeTypeFile.java @@ -0,0 +1,332 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package com.sun.activation.registries; + +import java.io.*; +import java.util.*; + +public class MimeTypeFile { + private String fname = null; + private Hashtable type_hash = new Hashtable(); + + /** + * The construtor that takes a filename as an argument. + * + * @param new_fname The file name of the mime types file. + */ + public MimeTypeFile(String new_fname) throws IOException { + File mime_file = null; + FileReader fr = null; + + fname = new_fname; // remember the file name + + mime_file = new File(fname); // get a file object + + fr = new FileReader(mime_file); + + try { + parse(new BufferedReader(fr)); + } finally { + try { + fr.close(); // close it + } catch (IOException e) { + // ignore it + } + } + } + + public MimeTypeFile(InputStream is) throws IOException { + parse(new BufferedReader(new InputStreamReader(is, "iso-8859-1"))); + } + + /** + * Creates an empty DB. + */ + public MimeTypeFile() { + } + + /** + * get the MimeTypeEntry based on the file extension + */ + public MimeTypeEntry getMimeTypeEntry(String file_ext) { + return (MimeTypeEntry)type_hash.get((Object)file_ext); + } + + /** + * Get the MIME type string corresponding to the file extension. + */ + public String getMIMETypeString(String file_ext) { + MimeTypeEntry entry = this.getMimeTypeEntry(file_ext); + + if (entry != null) + return entry.getMIMEType(); + else + return null; + } + + /** + * Appends string of entries to the types registry, must be valid + * .mime.types format. + * A mime.types entry is one of two forms: + * + * type/subtype ext1 ext2 ... + * or + * type=type/subtype desc="description of type" exts=ext1,ext2,... + * + * Example: + * # this is a test + * audio/basic au + * text/plain txt text + * type=application/postscript exts=ps,eps + */ + public void appendToRegistry(String mime_types) { + try { + parse(new BufferedReader(new StringReader(mime_types))); + } catch (IOException ex) { + // can't happen + } + } + + /** + * Parse a stream of mime.types entries. + */ + private void parse(BufferedReader buf_reader) throws IOException { + String line = null, prev = null; + + while ((line = buf_reader.readLine()) != null) { + if (prev == null) + prev = line; + else + prev += line; + int end = prev.length(); + if (prev.length() > 0 && prev.charAt(end - 1) == '\\') { + prev = prev.substring(0, end - 1); + continue; + } + this.parseEntry(prev); + prev = null; + } + if (prev != null) + this.parseEntry(prev); + } + + /** + * Parse single mime.types entry. + */ + private void parseEntry(String line) { + String mime_type = null; + String file_ext = null; + line = line.trim(); + + if (line.length() == 0) // empty line... + return; // BAIL! + + // check to see if this is a comment line? + if (line.charAt(0) == '#') + return; // then we are done! + + // is it a new format line or old format? + if (line.indexOf('=') > 0) { + // new format + LineTokenizer lt = new LineTokenizer(line); + while (lt.hasMoreTokens()) { + String name = lt.nextToken(); + String value = null; + if (lt.hasMoreTokens() && lt.nextToken().equals("=") && + lt.hasMoreTokens()) + value = lt.nextToken(); + if (value == null) { + if (LogSupport.isLoggable()) + LogSupport.log("Bad .mime.types entry: " + line); + return; + } + if (name.equals("type")) + mime_type = value; + else if (name.equals("exts")) { + StringTokenizer st = new StringTokenizer(value, ","); + while (st.hasMoreTokens()) { + file_ext = st.nextToken(); + MimeTypeEntry entry = + new MimeTypeEntry(mime_type, file_ext); + type_hash.put(file_ext, entry); + if (LogSupport.isLoggable()) + LogSupport.log("Added: " + entry.toString()); + } + } + } + } else { + // old format + // count the tokens + StringTokenizer strtok = new StringTokenizer(line); + int num_tok = strtok.countTokens(); + + if (num_tok == 0) // empty line + return; + + mime_type = strtok.nextToken(); // get the MIME type + + while (strtok.hasMoreTokens()) { + MimeTypeEntry entry = null; + + file_ext = strtok.nextToken(); + entry = new MimeTypeEntry(mime_type, file_ext); + type_hash.put(file_ext, entry); + if (LogSupport.isLoggable()) + LogSupport.log("Added: " + entry.toString()); + } + } + } + + // for debugging + /* + public static void main(String[] argv) throws Exception { + MimeTypeFile mf = new MimeTypeFile(argv[0]); + System.out.println("ext " + argv[1] + " type " + + mf.getMIMETypeString(argv[1])); + System.exit(0); + } + */ +} + +class LineTokenizer { + private int currentPosition; + private int maxPosition; + private String str; + private Vector stack = new Vector(); + private static final String singles = "="; // single character tokens + + /** + * Constructs a tokenizer for the specified string. + *

+ * + * @param str a string to be parsed. + */ + public LineTokenizer(String str) { + currentPosition = 0; + this.str = str; + maxPosition = str.length(); + } + + /** + * Skips white space. + */ + private void skipWhiteSpace() { + while ((currentPosition < maxPosition) && + Character.isWhitespace(str.charAt(currentPosition))) { + currentPosition++; + } + } + + /** + * Tests if there are more tokens available from this tokenizer's string. + * + * @return true if there are more tokens available from this + * tokenizer's string; false otherwise. + */ + public boolean hasMoreTokens() { + if (stack.size() > 0) + return true; + skipWhiteSpace(); + return (currentPosition < maxPosition); + } + + /** + * Returns the next token from this tokenizer. + * + * @return the next token from this tokenizer. + * @exception NoSuchElementException if there are no more tokens in this + * tokenizer's string. + */ + public String nextToken() { + int size = stack.size(); + if (size > 0) { + String t = (String)stack.elementAt(size - 1); + stack.removeElementAt(size - 1); + return t; + } + skipWhiteSpace(); + + if (currentPosition >= maxPosition) { + throw new NoSuchElementException(); + } + + int start = currentPosition; + char c = str.charAt(start); + if (c == '"') { + currentPosition++; + boolean filter = false; + while (currentPosition < maxPosition) { + c = str.charAt(currentPosition++); + if (c == '\\') { + currentPosition++; + filter = true; + } else if (c == '"') { + String s; + + if (filter) { + StringBuffer sb = new StringBuffer(); + for (int i = start + 1; i < currentPosition - 1; i++) { + c = str.charAt(i); + if (c != '\\') + sb.append(c); + } + s = sb.toString(); + } else + s = str.substring(start + 1, currentPosition - 1); + return s; + } + } + } else if (singles.indexOf(c) >= 0) { + currentPosition++; + } else { + while ((currentPosition < maxPosition) && + singles.indexOf(str.charAt(currentPosition)) < 0 && + !Character.isWhitespace(str.charAt(currentPosition))) { + currentPosition++; + } + } + return str.substring(start, currentPosition); + } + + public void pushToken(String token) { + stack.addElement(token); + } +} diff --git a/fine-third-jdk11/src/com/sun/activation/viewers/ImageViewer.java b/fine-third-jdk11/src/com/sun/activation/viewers/ImageViewer.java new file mode 100644 index 000000000..eea8adde7 --- /dev/null +++ b/fine-third-jdk11/src/com/sun/activation/viewers/ImageViewer.java @@ -0,0 +1,138 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package com.sun.activation.viewers; + +import java.awt.*; +import java.io.*; +import java.beans.*; +import javax.activation.*; + +public class ImageViewer extends Panel implements CommandObject { + // UI Vars... + private ImageViewerCanvas canvas = null; + + // File Vars + // private InputStream data_ins = null; + private Image image = null; + private DataHandler _dh = null; + + private boolean DEBUG = false; + /** + * Constructor + */ + public ImageViewer(){ + + // create the ImageViewerCanvas + canvas = new ImageViewerCanvas(); + add(canvas); + } + /** + * Set the DataHandler for this CommandObject + * @param DataHandler the DataHandler + */ + public void setCommandContext(String verb, DataHandler dh) throws IOException{ + _dh = dh; + this.setInputStream( _dh.getInputStream() ); + } + //-------------------------------------------------------------------- + + /** + * Set the data stream, component to assume it is ready to + * be read. + */ + private void setInputStream(InputStream ins) throws IOException { + MediaTracker mt = new MediaTracker(this); + int bytes_read = 0; + byte data[] = new byte[1024]; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + while((bytes_read = ins.read(data)) >0) + baos.write(data, 0, bytes_read); + ins.close(); + + // convert the buffer into an image + image = getToolkit().createImage(baos.toByteArray()); + + mt.addImage(image, 0); + + try { + mt.waitForID(0); + mt.waitForAll(); + if(mt.statusID(0, true ) != MediaTracker.COMPLETE){ + System.out.println("Error occured in image loading = " + + mt.getErrorsID(0)); + + } + + } + catch(InterruptedException e) { + throw new IOException("Error reading image data"); + } + + canvas.setImage(image); + if(DEBUG) + System.out.println("calling invalidate"); + + } + //-------------------------------------------------------------------- + public void addNotify(){ + super.addNotify(); // call the real one first... + this.invalidate(); + this.validate(); + this.doLayout(); + } + //-------------------------------------------------------------------- + public Dimension getPreferredSize(){ + return canvas.getPreferredSize(); + } + +} + + + + + + + + + + + diff --git a/fine-third-jdk11/src/com/sun/activation/viewers/ImageViewerCanvas.java b/fine-third-jdk11/src/com/sun/activation/viewers/ImageViewerCanvas.java new file mode 100644 index 000000000..54f897c12 --- /dev/null +++ b/fine-third-jdk11/src/com/sun/activation/viewers/ImageViewerCanvas.java @@ -0,0 +1,95 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package com.sun.activation.viewers; + +import java.awt.*; + +public class ImageViewerCanvas extends Canvas +{ + private Image canvas_image = null; + + /** + * The constructor + */ + public ImageViewerCanvas() + { + + } + + /** + * set the image + */ + public void setImage(Image new_image) + { + canvas_image = new_image; + this.invalidate(); + this.repaint(); + } + + /** + * getPreferredSize + */ + public Dimension getPreferredSize() + { + Dimension d = null; + + if(canvas_image == null) + { + d = new Dimension(200, 200); + } + else + d = new Dimension(canvas_image.getWidth(this), + canvas_image.getHeight(this)); + + return d; + } + /** + * paint method + */ + public void paint(Graphics g) + { + + if(canvas_image != null) + g.drawImage(canvas_image, 0, 0, this); + + } + +} diff --git a/fine-third-jdk11/src/com/sun/activation/viewers/TextEditor.java b/fine-third-jdk11/src/com/sun/activation/viewers/TextEditor.java new file mode 100644 index 000000000..66a153faa --- /dev/null +++ b/fine-third-jdk11/src/com/sun/activation/viewers/TextEditor.java @@ -0,0 +1,203 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package com.sun.activation.viewers; + +import java.awt.*; +import java.awt.event.*; +import java.io.*; +import java.beans.*; +import javax.activation.*; + +public class TextEditor extends Panel implements CommandObject, + ActionListener { + // UI Vars... + private TextArea text_area = null; + private GridBagLayout panel_gb = null; + private Panel button_panel = null; + private Button save_button = null; + // File Vars + private File text_file = null; + private String text_buffer = null; + private InputStream data_ins = null; + private FileInputStream fis = null; + + private DataHandler _dh = null; + private boolean DEBUG = false; + /** + * Constructor + */ + public TextEditor() { + panel_gb = new GridBagLayout(); + setLayout(panel_gb); + + button_panel = new Panel(); + // button_panel.setBackground(Color.white); + button_panel.setLayout( new FlowLayout() ); + save_button = new Button("SAVE"); + button_panel.add(save_button); + addGridComponent(this, + button_panel, + panel_gb, + 0,0, + 1,1, + 1,0); + + // create the text area + text_area = new TextArea("This is text",24, 80, + TextArea.SCROLLBARS_VERTICAL_ONLY ); + // text_area.setBackground(Color.lightGray); + text_area.setEditable( true ); + + addGridComponent(this, + text_area, + panel_gb, + 0,1, + 1,2, + 1,1); + + // add listeners + save_button.addActionListener( this ); + + } + + //////////////////////////////////////////////////////////////////////// + /** + * adds a component to our gridbag layout + */ + private void addGridComponent(Container cont, + Component comp, + GridBagLayout mygb, + int gridx, + int gridy, + int gridw, + int gridh, + int weightx, + int weighty) { + GridBagConstraints c = new GridBagConstraints(); + c.gridx = gridx; + c.gridy = gridy; + c.gridwidth = gridw; + c.gridheight = gridh; + c.fill = GridBagConstraints.BOTH; + c.weighty = weighty; + c.weightx = weightx; + c.anchor = GridBagConstraints.CENTER; + mygb.setConstraints(comp, c); + cont.add(comp); + } + + //-------------------------------------------------------------------- + public void setCommandContext(String verb, DataHandler dh) throws IOException { + _dh = dh; + this.setInputStream( _dh.getInputStream() ); + + } + //-------------------------------------------------------------------- + + /** + * set the data stream, component to assume it is ready to + * be read. + */ + public void setInputStream(InputStream ins) throws IOException { + + byte data[] = new byte[1024]; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + int bytes_read = 0; + // check that we can actually read + + while((bytes_read = ins.read(data)) >0) + baos.write(data, 0, bytes_read); + ins.close(); + + + // convert the buffer into a string + // popuplate the buffer + text_buffer = baos.toString(); + + // place in the text area + text_area.setText(text_buffer); + } + /////////////////////////////////////////////////////////////////////// + private void performSaveOperation(){ + OutputStream fos = null; + try { + fos = _dh.getOutputStream(); + } catch (Exception e) {} + + String buffer = text_area.getText(); + + // make sure we got one + if(fos == null) { + System.out.println("Invalid outputstream in TextEditor!"); + System.out.println("not saving!"); + return; + } + + try { + fos.write( buffer.getBytes() ); + fos.flush(); // flush it! + fos.close(); // close it! + } catch(IOException e) + { + System.out.println("TextEditor Save Operation failed with: " + e); + } + + } + //-------------------------------------------------------------------- + public void addNotify() { + super.addNotify(); + invalidate(); + } + //-------------------------------------------------------------------- + public Dimension getPreferredSize() { + return text_area.getMinimumSize(24, 80); + } + ///////////////////////////////////////////////////////////////////// + // for ActionListener + public void actionPerformed(ActionEvent evt){ + if(evt.getSource() == save_button) { // save button pressed! + + // Save ourselves + this.performSaveOperation(); + } + } + +} diff --git a/fine-third-jdk11/src/com/sun/activation/viewers/TextViewer.java b/fine-third-jdk11/src/com/sun/activation/viewers/TextViewer.java new file mode 100644 index 000000000..6019fc795 --- /dev/null +++ b/fine-third-jdk11/src/com/sun/activation/viewers/TextViewer.java @@ -0,0 +1,118 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package com.sun.activation.viewers; + +import java.awt.*; +import java.io.*; +import java.beans.*; +import javax.activation.*; + +public class TextViewer extends Panel implements CommandObject { + // UI Vars... + private TextArea text_area = null; + + // File Vars + private File text_file = null; + private String text_buffer = null; + + private DataHandler _dh = null; + private boolean DEBUG = false; + /** + * Constructor + */ + public TextViewer() { + setLayout( new GridLayout(1,1)); + // create the text area + text_area = new TextArea("", 24, 80, + TextArea.SCROLLBARS_VERTICAL_ONLY ); + text_area.setEditable( false ); + + add(text_area); + } + + //-------------------------------------------------------------------- + public void setCommandContext(String verb, DataHandler dh) throws IOException { + _dh = dh; + this.setInputStream( _dh.getInputStream() ); + } + //-------------------------------------------------------------------- + + /** + * set the data stream, component to assume it is ready to + * be read. + */ + public void setInputStream(InputStream ins) throws IOException { + + int bytes_read = 0; + // check that we can actually read + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + byte data[] = new byte[1024]; + + while((bytes_read = ins.read(data)) >0) + baos.write(data, 0, bytes_read); + + ins.close(); + + // convert the buffer into a string + // popuplate the buffer + text_buffer = baos.toString(); + + // place in the text area + text_area.setText(text_buffer); + + } + //-------------------------------------------------------------------- + public void addNotify() { + super.addNotify(); + invalidate(); + } + //-------------------------------------------------------------------- + public Dimension getPreferredSize() { + return text_area.getMinimumSize(24, 80); + } + +} + + + + + + diff --git a/fine-third-jdk11/src/javax/activation/ActivationDataFlavor.java b/fine-third-jdk11/src/javax/activation/ActivationDataFlavor.java new file mode 100644 index 000000000..e1b456e5d --- /dev/null +++ b/fine-third-jdk11/src/javax/activation/ActivationDataFlavor.java @@ -0,0 +1,263 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.activation; + +import java.awt.datatransfer.DataFlavor; +import java.io.IOException; +import javax.activation.MimeType; + +/** + * The ActivationDataFlavor class is a special subclass of + * java.awt.datatransfer.DataFlavor. It allows the JAF to + * set all three values stored by the DataFlavor class via a new + * constructor. It also contains improved MIME parsing in the equals + * method. Except for the improved parsing, its semantics are + * identical to that of the JDK's DataFlavor class. + */ + +public class ActivationDataFlavor extends DataFlavor { + + /* + * Raison d'etre: + * + * The DataFlavor class included in JDK 1.1 has several limitations + * including piss poor MIME type parsing, and the limitation of + * only supporting serialized objects and InputStreams as + * representation objects. This class 'fixes' that. + */ + + // I think for now I'll keep copies of all the variables and + // then later I may choose try to better coexist with the base + // class *sigh* + private String mimeType = null; + private MimeType mimeObject = null; + private String humanPresentableName = null; + private Class representationClass = null; + + /** + * Construct a DataFlavor that represents an arbitrary + * Java object. This constructor is an extension of the + * JDK's DataFlavor in that it allows the explicit setting + * of all three DataFlavor attributes. + *

+ * The returned DataFlavor will have the following characteristics: + *

+ * representationClass = representationClass
+ * mimeType = mimeType
+ * humanName = humanName + *

+ * + * @param representationClass the class used in this DataFlavor + * @param mimeType the MIME type of the data represented by this class + * @param humanPresentableName the human presentable name of the flavor + */ + public ActivationDataFlavor(Class representationClass, + String mimeType, String humanPresentableName) { + super(mimeType, humanPresentableName); // need to call super + + // init private variables: + this.mimeType = mimeType; + this.humanPresentableName = humanPresentableName; + this.representationClass = representationClass; + } + + /** + * Construct a DataFlavor that represents a MimeType. + *

+ * The returned DataFlavor will have the following characteristics: + *

+ * If the mimeType is "application/x-java-serialized-object; + * class=", the result is the same as calling new + * DataFlavor(Class.forName()) as above. + *

+ * otherwise: + *

+ * representationClass = InputStream

+ * mimeType = mimeType

+ * + * @param representationClass the class used in this DataFlavor + * @param humanPresentableName the human presentable name of the flavor + */ + public ActivationDataFlavor(Class representationClass, + String humanPresentableName) { + super(representationClass, humanPresentableName); + this.mimeType = super.getMimeType(); + this.representationClass = representationClass; + this.humanPresentableName = humanPresentableName; + } + + /** + * Construct a DataFlavor that represents a MimeType. + *

+ * The returned DataFlavor will have the following characteristics: + *

+ * If the mimeType is "application/x-java-serialized-object; class=", + * the result is the same as calling new DataFlavor(Class.forName()) as + * above, otherwise: + *

+ * representationClass = InputStream

+ * mimeType = mimeType + * + * @param mimeType the MIME type of the data represented by this class + * @param humanPresentableName the human presentable name of the flavor + */ + public ActivationDataFlavor(String mimeType, String humanPresentableName) { + super(mimeType, humanPresentableName); + this.mimeType = mimeType; + try { + this.representationClass = Class.forName("java.io.InputStream"); + } catch (ClassNotFoundException ex) { + // XXX - should never happen, ignore it + } + this.humanPresentableName = humanPresentableName; + } + + /** + * Return the MIME type for this DataFlavor. + * + * @return the MIME type + */ + public String getMimeType() { + return mimeType; + } + + /** + * Return the representation class. + * + * @return the representation class + */ + public Class getRepresentationClass() { + return representationClass; + } + + /** + * Return the Human Presentable name. + * + * @return the human presentable name + */ + public String getHumanPresentableName() { + return humanPresentableName; + } + + /** + * Set the human presentable name. + * + * @param humanPresentableName the name to set + */ + public void setHumanPresentableName(String humanPresentableName) { + this.humanPresentableName = humanPresentableName; + } + + /** + * Compares the DataFlavor passed in with this DataFlavor; calls + * the isMimeTypeEqual method. + * + * @param dataFlavor the DataFlavor to compare with + * @return true if the MIME type and representation class + * are the same + */ + public boolean equals(DataFlavor dataFlavor) { + return (isMimeTypeEqual(dataFlavor) && + dataFlavor.getRepresentationClass() == representationClass); + } + + /** + * Is the string representation of the MIME type passed in equivalent + * to the MIME type of this DataFlavor.

+ * + * ActivationDataFlavor delegates the comparison of MIME types to + * the MimeType class included as part of the JavaBeans Activation + * Framework. This provides a more robust comparison than is normally + * available in the DataFlavor class. + * + * @param mimeType the MIME type + * @return true if the same MIME type + */ + public boolean isMimeTypeEqual(String mimeType) { + MimeType mt = null; + try { + if (mimeObject == null) + mimeObject = new MimeType(this.mimeType); + mt = new MimeType(mimeType); + } catch (MimeTypeParseException e) { + // something didn't parse, do a crude comparison + return this.mimeType.equalsIgnoreCase(mimeType); + } + + return mimeObject.match(mt); + } + + /** + * Called on DataFlavor for every MIME Type parameter to allow DataFlavor + * subclasses to handle special parameters like the text/plain charset + * parameters, whose values are case insensitive. (MIME type parameter + * values are supposed to be case sensitive). + *

+ * This method is called for each parameter name/value pair and should + * return the normalized representation of the parameterValue. + * This method is never invoked by this implementation. + * + * @param parameterName the parameter name + * @param parameterValue the parameter value + * @return the normalized parameter value + * @deprecated + */ + protected String normalizeMimeTypeParameter(String parameterName, + String parameterValue) { + return parameterValue; + } + + /** + * Called for each MIME type string to give DataFlavor subtypes the + * opportunity to change how the normalization of MIME types is + * accomplished. + * One possible use would be to add default parameter/value pairs in cases + * where none are present in the MIME type string passed in. + * This method is never invoked by this implementation. + * + * @param mimeType the MIME type + * @return the normalized MIME type + * @deprecated + */ + protected String normalizeMimeType(String mimeType) { + return mimeType; + } +} diff --git a/fine-third-jdk11/src/javax/activation/CommandInfo.java b/fine-third-jdk11/src/javax/activation/CommandInfo.java new file mode 100644 index 000000000..0297938cf --- /dev/null +++ b/fine-third-jdk11/src/javax/activation/CommandInfo.java @@ -0,0 +1,245 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.activation; + +import java.io.*; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; + +/** + * The CommandInfo class is used by CommandMap implementations to + * describe the results of command requests. It provides the requestor + * with both the verb requested, as well as an instance of the + * bean. There is also a method that will return the name of the + * class that implements the command but it is not guaranteed to + * return a valid value. The reason for this is to allow CommandMap + * implmentations that subclass CommandInfo to provide special + * behavior. For example a CommandMap could dynamically generate + * JavaBeans. In this case, it might not be possible to create an + * object with all the correct state information solely from the class + * name. + */ + +public class CommandInfo { + private String verb; + private String className; + + /** + * The Constructor for CommandInfo. + * @param verb The command verb this CommandInfo decribes. + * @param className The command's fully qualified class name. + */ + public CommandInfo(String verb, String className) { + this.verb = verb; + this.className = className; + } + + /** + * Return the command verb. + * + * @return the command verb. + */ + public String getCommandName() { + return verb; + } + + /** + * Return the command's class name. This method MAY return null in + * cases where a CommandMap subclassed CommandInfo for its + * own purposes. In other words, it might not be possible to + * create the correct state in the command by merely knowing + * its class name. DO NOT DEPEND ON THIS METHOD RETURNING + * A VALID VALUE! + * + * @return The class name of the command, or null + */ + public String getCommandClass() { + return className; + } + + /** + * Return the instantiated JavaBean component. + *

+ * If the current runtime environment supports + * {@link java.beans.Beans#instantiate Beans.instantiate}, + * use it to instantiate the JavaBeans component. Otherwise, use + * {@link java.lang.Class#forName Class.forName}. + *

+ * The component class needs to be public. + * On Java SE 9 and newer, if the component class is in a named module, + * it needs to be in an exported package. + *

+ * If the bean implements the javax.activation.CommandObject + * interface, call its setCommandContext method. + *

+ * If the DataHandler parameter is null, then the bean is + * instantiated with no data. NOTE: this may be useful + * if for some reason the DataHandler that is passed in + * throws IOExceptions when this method attempts to + * access its InputStream. It will allow the caller to + * retrieve a reference to the bean if it can be + * instantiated. + *

+ * If the bean does NOT implement the CommandObject interface, + * this method will check if it implements the + * java.io.Externalizable interface. If it does, the bean's + * readExternal method will be called if an InputStream + * can be acquired from the DataHandler.

+ * + * @param dh The DataHandler that describes the data to be + * passed to the command. + * @param loader The ClassLoader to be used to instantiate the bean. + * @return The bean + * @exception IOException for failures reading data + * @exception ClassNotFoundException if command object class can't + * be found + * @see java.beans.Beans#instantiate + * @see javax.activation.CommandObject + */ + public Object getCommandObject(DataHandler dh, ClassLoader loader) + throws IOException, ClassNotFoundException { + Object new_bean = null; + + // try to instantiate the bean + new_bean = Beans.instantiate(loader, className); + + // if we got one and it is a CommandObject + if (new_bean != null) { + if (new_bean instanceof CommandObject) { + ((CommandObject)new_bean).setCommandContext(verb, dh); + } else if (new_bean instanceof Externalizable) { + if (dh != null) { + InputStream is = dh.getInputStream(); + if (is != null) { + ((Externalizable)new_bean).readExternal( + new ObjectInputStream(is)); + } + } + } + } + + return new_bean; + } + + /** + * Helper class to invoke Beans.instantiate reflectively or the equivalent + * with core reflection when module java.desktop is not readable. + */ + private static final class Beans { + static final Method instantiateMethod; + + static { + Method m; + try { + Class c = Class.forName("java.beans.Beans"); + m = c.getDeclaredMethod("instantiate", ClassLoader.class, String.class); + } catch (ClassNotFoundException e) { + m = null; + } catch (NoSuchMethodException e) { + m = null; + } + instantiateMethod = m; + } + + /** + * Equivalent to invoking java.beans.Beans.instantiate(loader, cn) + */ + static Object instantiate(ClassLoader loader, String cn) + throws IOException, ClassNotFoundException { + + Exception exception; + + if (instantiateMethod != null) { + + // invoke Beans.instantiate + try { + return instantiateMethod.invoke(null, loader, cn); + } catch (InvocationTargetException e) { + exception = e; + } catch (IllegalAccessException e) { + exception = e; + } + + } else { + + SecurityManager security = System.getSecurityManager(); + if (security != null) { + // if it's ok with the SecurityManager, it's ok with me. + String cname = cn.replace('/', '.'); + if (cname.startsWith("[")) { + int b = cname.lastIndexOf('[') + 2; + if (b > 1 && b < cname.length()) { + cname = cname.substring(b); + } + } + int i = cname.lastIndexOf('.'); + if (i != -1) { + security.checkPackageAccess(cname.substring(0, i)); + } + } + + // Beans.instantiate specified to use SCL when loader is null + if (loader == null) { + loader = (ClassLoader) + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + ClassLoader cl = null; + try { + cl = ClassLoader.getSystemClassLoader(); + } catch (SecurityException ex) { } + return cl; + } + }); + } + Class beanClass = Class.forName(cn, true, loader); + try { + return beanClass.newInstance(); + } catch (Exception ex) { + throw new ClassNotFoundException(beanClass + ": " + ex, ex); + } + + } + return null; + } + } +} diff --git a/fine-third-jdk11/src/javax/activation/CommandMap.java b/fine-third-jdk11/src/javax/activation/CommandMap.java new file mode 100644 index 000000000..f51064cb0 --- /dev/null +++ b/fine-third-jdk11/src/javax/activation/CommandMap.java @@ -0,0 +1,249 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.activation; + +import java.util.Map; +import java.util.WeakHashMap; + + +/** + * The CommandMap class provides an interface to a registry of + * command objects available in the system. + * Developers are expected to either use the CommandMap + * implementation included with this package (MailcapCommandMap) or + * develop their own. Note that some of the methods in this class are + * abstract. + */ +public abstract class CommandMap { + private static CommandMap defaultCommandMap = null; + private static Map map = + new WeakHashMap(); + + + /** + * Get the default CommandMap. + * + *

    + *
  • In cases where a CommandMap instance has been previously set + * to some value (via setDefaultCommandMap) + * return the CommandMap. + *
  • + * In cases where no CommandMap has been set, the CommandMap + * creates an instance of MailcapCommandMap and + * set that to the default, returning its value. + * + *
+ * + * @return the CommandMap + */ + public static synchronized CommandMap getDefaultCommandMap() { + if (defaultCommandMap != null) + return defaultCommandMap; + + // fetch per-thread-context-class-loader default + ClassLoader tccl = SecuritySupport.getContextClassLoader(); + CommandMap def = map.get(tccl); + if (def == null) { + def = new MailcapCommandMap(); + map.put(tccl, def); + } + return def; + } + + /** + * Set the default CommandMap. Reset the CommandMap to the default by + * calling this method with null. + * + * @param commandMap The new default CommandMap. + * @exception SecurityException if the caller doesn't have permission + * to change the default + */ + public static synchronized void setDefaultCommandMap(CommandMap commandMap) { + SecurityManager security = System.getSecurityManager(); + if (security != null) { + try { + // if it's ok with the SecurityManager, it's ok with me... + security.checkSetFactory(); + } catch (SecurityException ex) { + // otherwise, we also allow it if this code and the + // factory come from the same (non-system) class loader (e.g., + // the JAF classes were loaded with the applet classes). + ClassLoader cl = CommandMap.class.getClassLoader(); + if (cl == null || cl.getParent() == null || + cl != commandMap.getClass().getClassLoader()) { + throw ex; + } + } + } + // remove any per-thread-context-class-loader CommandMap + map.remove(SecuritySupport.getContextClassLoader()); + defaultCommandMap = commandMap; + } + + /** + * Get the preferred command list from a MIME Type. The actual semantics + * are determined by the implementation of the CommandMap. + * + * @param mimeType the MIME type + * @return the CommandInfo classes that represent the command Beans. + */ + abstract public CommandInfo[] getPreferredCommands(String mimeType); + + /** + * Get the preferred command list from a MIME Type. The actual semantics + * are determined by the implementation of the CommandMap.

+ * + * The DataSource provides extra information, such as + * the file name, that a CommandMap implementation may use to further + * refine the list of commands that are returned. The implementation + * in this class simply calls the getPreferredCommands + * method that ignores this argument. + * + * @param mimeType the MIME type + * @param ds a DataSource for the data + * @return the CommandInfo classes that represent the command Beans. + * @since JAF 1.1 + */ + public CommandInfo[] getPreferredCommands(String mimeType, DataSource ds) { + return getPreferredCommands(mimeType); + } + + /** + * Get all the available commands for this type. This method + * should return all the possible commands for this MIME type. + * + * @param mimeType the MIME type + * @return the CommandInfo objects representing all the commands. + */ + abstract public CommandInfo[] getAllCommands(String mimeType); + + /** + * Get all the available commands for this type. This method + * should return all the possible commands for this MIME type.

+ * + * The DataSource provides extra information, such as + * the file name, that a CommandMap implementation may use to further + * refine the list of commands that are returned. The implementation + * in this class simply calls the getAllCommands + * method that ignores this argument. + * + * @param mimeType the MIME type + * @param ds a DataSource for the data + * @return the CommandInfo objects representing all the commands. + * @since JAF 1.1 + */ + public CommandInfo[] getAllCommands(String mimeType, DataSource ds) { + return getAllCommands(mimeType); + } + + /** + * Get the default command corresponding to the MIME type. + * + * @param mimeType the MIME type + * @param cmdName the command name + * @return the CommandInfo corresponding to the command. + */ + abstract public CommandInfo getCommand(String mimeType, String cmdName); + + /** + * Get the default command corresponding to the MIME type.

+ * + * The DataSource provides extra information, such as + * the file name, that a CommandMap implementation may use to further + * refine the command that is chosen. The implementation + * in this class simply calls the getCommand + * method that ignores this argument. + * + * @param mimeType the MIME type + * @param cmdName the command name + * @param ds a DataSource for the data + * @return the CommandInfo corresponding to the command. + * @since JAF 1.1 + */ + public CommandInfo getCommand(String mimeType, String cmdName, + DataSource ds) { + return getCommand(mimeType, cmdName); + } + + /** + * Locate a DataContentHandler that corresponds to the MIME type. + * The mechanism and semantics for determining this are determined + * by the implementation of the particular CommandMap. + * + * @param mimeType the MIME type + * @return the DataContentHandler for the MIME type + */ + abstract public DataContentHandler createDataContentHandler(String + mimeType); + + /** + * Locate a DataContentHandler that corresponds to the MIME type. + * The mechanism and semantics for determining this are determined + * by the implementation of the particular CommandMap.

+ * + * The DataSource provides extra information, such as + * the file name, that a CommandMap implementation may use to further + * refine the choice of DataContentHandler. The implementation + * in this class simply calls the createDataContentHandler + * method that ignores this argument. + * + * @param mimeType the MIME type + * @param ds a DataSource for the data + * @return the DataContentHandler for the MIME type + * @since JAF 1.1 + */ + public DataContentHandler createDataContentHandler(String mimeType, + DataSource ds) { + return createDataContentHandler(mimeType); + } + + /** + * Get all the MIME types known to this command map. + * If the command map doesn't support this operation, + * null is returned. + * + * @return array of MIME types as strings, or null if not supported + * @since JAF 1.1 + */ + public String[] getMimeTypes() { + return null; + } +} diff --git a/fine-third-jdk11/src/javax/activation/CommandObject.java b/fine-third-jdk11/src/javax/activation/CommandObject.java new file mode 100644 index 000000000..f37f687ff --- /dev/null +++ b/fine-third-jdk11/src/javax/activation/CommandObject.java @@ -0,0 +1,68 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.activation; + +import java.io.IOException; + +/** + * JavaBeans components that are Activation Framework aware implement + * this interface to find out which command verb they're being asked + * to perform, and to obtain the DataHandler representing the + * data they should operate on. JavaBeans that don't implement + * this interface may be used as well. Such commands may obtain + * the data using the Externalizable interface, or using an + * application-specific method. + */ +public interface CommandObject { + + /** + * Initialize the Command with the verb it is requested to handle + * and the DataHandler that describes the data it will + * operate on. NOTE: it is acceptable for the caller + * to pass null as the value for DataHandler. + * + * @param verb The Command Verb this object refers to. + * @param dh The DataHandler. + * @exception IOException for failures accessing data + */ + public void setCommandContext(String verb, DataHandler dh) + throws IOException; +} diff --git a/fine-third-jdk11/src/javax/activation/DataContentHandler.java b/fine-third-jdk11/src/javax/activation/DataContentHandler.java new file mode 100644 index 000000000..78c01cace --- /dev/null +++ b/fine-third-jdk11/src/javax/activation/DataContentHandler.java @@ -0,0 +1,114 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.activation; + +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.io.InputStream; +import java.io.IOException; +import java.io.OutputStream; +import javax.activation.DataSource; + +/** + * The DataContentHandler interface is implemented by objects that can + * be used to extend the capabilities of the DataHandler's implementation + * of the Transferable interface. Through DataContentHandlers + * the framework can be extended to convert streams in to objects, and + * to write objects to streams.

+ * + * Applications don't generally call the methods in DataContentHandlers + * directly. Instead, an application calls the equivalent methods in + * DataHandler. The DataHandler will attempt to find an appropriate + * DataContentHandler that corresponds to its MIME type using the + * current DataContentHandlerFactory. The DataHandler then calls + * through to the methods in the DataContentHandler. + */ + +public interface DataContentHandler { + /** + * Returns an array of DataFlavor objects indicating the flavors the + * data can be provided in. The array should be ordered according to + * preference for providing the data (from most richly descriptive to + * least descriptive). + * + * @return The DataFlavors. + */ + public DataFlavor[] getTransferDataFlavors(); + + /** + * Returns an object which represents the data to be transferred. + * The class of the object returned is defined by the representation class + * of the flavor. + * + * @param df The DataFlavor representing the requested type. + * @param ds The DataSource representing the data to be converted. + * @return The constructed Object. + * @exception UnsupportedFlavorException if the handler doesn't + * support the requested flavor + * @exception IOException if the data can't be accessed + */ + public Object getTransferData(DataFlavor df, DataSource ds) + throws UnsupportedFlavorException, IOException; + + /** + * Return an object representing the data in its most preferred form. + * Generally this will be the form described by the first DataFlavor + * returned by the getTransferDataFlavors method. + * + * @param ds The DataSource representing the data to be converted. + * @return The constructed Object. + * @exception IOException if the data can't be accessed + */ + public Object getContent(DataSource ds) throws IOException; + + /** + * Convert the object to a byte stream of the specified MIME type + * and write it to the output stream. + * + * @param obj The object to be converted. + * @param mimeType The requested MIME type of the resulting byte stream. + * @param os The output stream into which to write the converted + * byte stream. + * @exception IOException errors writing to the stream + */ + public void writeTo(Object obj, String mimeType, OutputStream os) + throws IOException; +} diff --git a/fine-third-jdk11/src/javax/activation/DataContentHandlerFactory.java b/fine-third-jdk11/src/javax/activation/DataContentHandlerFactory.java new file mode 100644 index 000000000..3e60d3e9b --- /dev/null +++ b/fine-third-jdk11/src/javax/activation/DataContentHandlerFactory.java @@ -0,0 +1,61 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.activation; + +/** + * This interface defines a factory for DataContentHandlers. An + * implementation of this interface should map a MIME type into an + * instance of DataContentHandler. The design pattern for classes implementing + * this interface is the same as for the ContentHandler mechanism used in + * java.net.URL. + */ + +public interface DataContentHandlerFactory { + + /** + * Creates a new DataContentHandler object for the MIME type. + * + * @param mimeType the MIME type to create the DataContentHandler for. + * @return The new DataContentHandler, or null + * if none are found. + */ + public DataContentHandler createDataContentHandler(String mimeType); +} diff --git a/fine-third-jdk11/src/javax/activation/DataHandler.java b/fine-third-jdk11/src/javax/activation/DataHandler.java new file mode 100644 index 000000000..4f38c5292 --- /dev/null +++ b/fine-third-jdk11/src/javax/activation/DataHandler.java @@ -0,0 +1,912 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.activation; + +import java.io.InputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; +import java.io.OutputStreamWriter; +import java.net.URL; +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.UnsupportedFlavorException; + +/** + * The DataHandler class provides a consistent interface to data + * available in many different sources and formats. + * It manages simple stream to string conversions and related operations + * using DataContentHandlers. + * It provides access to commands that can operate on the data. + * The commands are found using a CommandMap.

+ * + * DataHandler and the Transferable Interface

+ * DataHandler implements the Transferable interface so that data can + * be used in AWT data transfer operations, such as cut and paste and + * drag and drop. The implementation of the Transferable interface + * relies on the availability of an installed DataContentHandler + * object corresponding to the MIME type of the data represented in + * the specific instance of the DataHandler.

+ * + * DataHandler and CommandMaps

+ * The DataHandler keeps track of the current CommandMap that it uses to + * service requests for commands (getCommand, + * getAllCommands, getPreferredCommands). + * Each instance of a DataHandler may have a CommandMap associated with + * it using the setCommandMap method. If a CommandMap was + * not set, DataHandler calls the getDefaultCommandMap + * method in CommandMap and uses the value it returns. See + * CommandMap for more information.

+ * + * DataHandler and URLs

+ * The current DataHandler implementation creates a private + * instance of URLDataSource when it is constructed with a URL. + * + * @see javax.activation.CommandMap + * @see javax.activation.DataContentHandler + * @see javax.activation.DataSource + * @see javax.activation.URLDataSource + */ + +public class DataHandler implements Transferable { + + // Use the datasource to indicate whether we were started via the + // DataSource constructor or the object constructor. + private DataSource dataSource = null; + private DataSource objDataSource = null; + + // The Object and mimetype from the constructor (if passed in). + // object remains null if it was instantiated with a + // DataSource. + private Object object = null; + private String objectMimeType = null; + + // Keep track of the CommandMap + private CommandMap currentCommandMap = null; + + // our transfer flavors + private static final DataFlavor emptyFlavors[] = new DataFlavor[0]; + private DataFlavor transferFlavors[] = emptyFlavors; + + // our DataContentHandler + private DataContentHandler dataContentHandler = null; + private DataContentHandler factoryDCH = null; + + // our DataContentHandlerFactory + private static DataContentHandlerFactory factory = null; + private DataContentHandlerFactory oldFactory = null; + // the short representation of the ContentType (sans params) + private String shortType = null; + + /** + * Create a DataHandler instance referencing the + * specified DataSource. The data exists in a byte stream form. + * The DataSource will provide an InputStream to access the data. + * + * @param ds the DataSource + */ + public DataHandler(DataSource ds) { + // save a reference to the incoming DS + dataSource = ds; + oldFactory = factory; // keep track of the factory + } + + /** + * Create a DataHandler instance representing an object + * of this MIME type. This constructor is + * used when the application already has an in-memory representation + * of the data in the form of a Java Object. + * + * @param obj the Java Object + * @param mimeType the MIME type of the object + */ + public DataHandler(Object obj, String mimeType) { + object = obj; + objectMimeType = mimeType; + oldFactory = factory; // keep track of the factory + } + + /** + * Create a DataHandler instance referencing a URL. + * The DataHandler internally creates a URLDataSource + * instance to represent the URL. + * + * @param url a URL object + */ + public DataHandler(URL url) { + dataSource = new URLDataSource(url); + oldFactory = factory; // keep track of the factory + } + + /** + * Return the CommandMap for this instance of DataHandler. + */ + private synchronized CommandMap getCommandMap() { + if (currentCommandMap != null) + return currentCommandMap; + else + return CommandMap.getDefaultCommandMap(); + } + + /** + * Return the DataSource associated with this instance + * of DataHandler. + *

+ * For DataHandlers that have been instantiated with a DataSource, + * this method returns the DataSource that was used to create the + * DataHandler object. In other cases the DataHandler + * constructs a DataSource from the data used to construct + * the DataHandler. DataSources created for DataHandlers not + * instantiated with a DataSource are cached for performance + * reasons. + * + * @return a valid DataSource object for this DataHandler + */ + public DataSource getDataSource() { + if (dataSource == null) { + // create one on the fly + if (objDataSource == null) + objDataSource = new DataHandlerDataSource(this); + return objDataSource; + } + return dataSource; + } + + /** + * Return the name of the data object. If this DataHandler + * was created with a DataSource, this method calls through + * to the DataSource.getName method, otherwise it + * returns null. + * + * @return the name of the object + */ + public String getName() { + if (dataSource != null) + return dataSource.getName(); + else + return null; + } + + /** + * Return the MIME type of this object as retrieved from + * the source object. Note that this is the full + * type with parameters. + * + * @return the MIME type + */ + public String getContentType() { + if (dataSource != null) // data source case + return dataSource.getContentType(); + else + return objectMimeType; // obj/type case + } + + /** + * Get the InputStream for this object.

+ * + * For DataHandlers instantiated with a DataSource, the DataHandler + * calls the DataSource.getInputStream method and + * returns the result to the caller. + *

+ * For DataHandlers instantiated with an Object, the DataHandler + * first attempts to find a DataContentHandler for the Object. If + * the DataHandler can not find a DataContentHandler for this MIME + * type, it throws an UnsupportedDataTypeException. If it is + * successful, it creates a pipe and a thread. The thread uses the + * DataContentHandler's writeTo method to write the + * stream data into one end of the pipe. The other end of the pipe + * is returned to the caller. Because a thread is created to copy + * the data, IOExceptions that may occur during the copy can not be + * propagated back to the caller. The result is an empty stream.

+ * + * @return the InputStream representing this data + * @exception IOException if an I/O error occurs + * + * @see javax.activation.DataContentHandler#writeTo + * @see javax.activation.UnsupportedDataTypeException + */ + public InputStream getInputStream() throws IOException { + InputStream ins = null; + + if (dataSource != null) { + ins = dataSource.getInputStream(); + } else { + DataContentHandler dch = getDataContentHandler(); + // we won't even try if we can't get a dch + if (dch == null) + throw new UnsupportedDataTypeException( + "no DCH for MIME type " + getBaseType()); + + if (dch instanceof ObjectDataContentHandler) { + if (((ObjectDataContentHandler)dch).getDCH() == null) + throw new UnsupportedDataTypeException( + "no object DCH for MIME type " + getBaseType()); + } + // there is none but the default^^^^^^^^^^^^^^^^ + final DataContentHandler fdch = dch; + + // from bill s. + // ce n'est pas une pipe! + // + // NOTE: This block of code needs to throw exceptions, but + // can't because it is in another thread!!! ARG! + // + final PipedOutputStream pos = new PipedOutputStream(); + PipedInputStream pin = new PipedInputStream(pos); + new Thread( + new Runnable() { + public void run() { + try { + fdch.writeTo(object, objectMimeType, pos); + } catch (IOException e) { + + } finally { + try { + pos.close(); + } catch (IOException ie) { } + } + } + }, + "DataHandler.getInputStream").start(); + ins = pin; + } + + return ins; + } + + /** + * Write the data to an OutputStream.

+ * + * If the DataHandler was created with a DataSource, writeTo + * retrieves the InputStream and copies the bytes from the + * InputStream to the OutputStream passed in. + *

+ * If the DataHandler was created with an object, writeTo + * retrieves the DataContentHandler for the object's type. + * If the DataContentHandler was found, it calls the + * writeTo method on the DataContentHandler. + * + * @param os the OutputStream to write to + * @exception IOException if an I/O error occurs + */ + public void writeTo(OutputStream os) throws IOException { + // for the DataSource case + if (dataSource != null) { + InputStream is = null; + byte data[] = new byte[8*1024]; + int bytes_read; + + is = dataSource.getInputStream(); + + try { + while ((bytes_read = is.read(data)) > 0) { + os.write(data, 0, bytes_read); + } + } finally { + is.close(); + is = null; + } + } else { // for the Object case + DataContentHandler dch = getDataContentHandler(); + dch.writeTo(object, objectMimeType, os); + } + } + + /** + * Get an OutputStream for this DataHandler to allow overwriting + * the underlying data. + * If the DataHandler was created with a DataSource, the + * DataSource's getOutputStream method is called. + * Otherwise, null is returned. + * + * @return the OutputStream + * @exception IOException for failures creating the OutputStream + * + * @see javax.activation.DataSource#getOutputStream + * @see javax.activation.URLDataSource + */ + public OutputStream getOutputStream() throws IOException { + if (dataSource != null) + return dataSource.getOutputStream(); + else + return null; + } + + /** + * Return the DataFlavors in which this data is available.

+ * + * Returns an array of DataFlavor objects indicating the flavors + * the data can be provided in. The array is usually ordered + * according to preference for providing the data, from most + * richly descriptive to least richly descriptive.

+ * + * The DataHandler attempts to find a DataContentHandler that + * corresponds to the MIME type of the data. If one is located, + * the DataHandler calls the DataContentHandler's + * getTransferDataFlavors method.

+ * + * If a DataContentHandler can not be located, and if the + * DataHandler was created with a DataSource (or URL), one + * DataFlavor is returned that represents this object's MIME type + * and the java.io.InputStream class. If the + * DataHandler was created with an object and a MIME type, + * getTransferDataFlavors returns one DataFlavor that represents + * this object's MIME type and the object's class. + * + * @return an array of data flavors in which this data can be transferred + * @see javax.activation.DataContentHandler#getTransferDataFlavors + */ + public synchronized DataFlavor[] getTransferDataFlavors() { + if (factory != oldFactory) // if the factory has changed, clear cache + transferFlavors = emptyFlavors; + + // if it's not set, set it... + if (transferFlavors == emptyFlavors) + transferFlavors = getDataContentHandler().getTransferDataFlavors(); + if (transferFlavors == emptyFlavors) + return transferFlavors; // no need to clone an empty array + else + return transferFlavors.clone(); + } + + /** + * Returns whether the specified data flavor is supported + * for this object.

+ * + * This method iterates through the DataFlavors returned from + * getTransferDataFlavors, comparing each with + * the specified flavor. + * + * @param flavor the requested flavor for the data + * @return true if the data flavor is supported + * @see javax.activation.DataHandler#getTransferDataFlavors + */ + public boolean isDataFlavorSupported(DataFlavor flavor) { + DataFlavor[] lFlavors = getTransferDataFlavors(); + + for (int i = 0; i < lFlavors.length; i++) { + if (lFlavors[i].equals(flavor)) + return true; + } + return false; + } + + /** + * Returns an object that represents the data to be + * transferred. The class of the object returned is defined by the + * representation class of the data flavor.

+ * + * For DataHandler's created with DataSources or URLs:

+ * + * The DataHandler attempts to locate a DataContentHandler + * for this MIME type. If one is found, the passed in DataFlavor + * and the type of the data are passed to its getTransferData + * method. If the DataHandler fails to locate a DataContentHandler + * and the flavor specifies this object's MIME type and the + * java.io.InputStream class, this object's InputStream + * is returned. + * Otherwise it throws an UnsupportedFlavorException.

+ * + * For DataHandler's created with Objects:

+ * + * The DataHandler attempts to locate a DataContentHandler + * for this MIME type. If one is found, the passed in DataFlavor + * and the type of the data are passed to its getTransferData + * method. If the DataHandler fails to locate a DataContentHandler + * and the flavor specifies this object's MIME type and its class, + * this DataHandler's referenced object is returned. + * Otherwise it throws an UnsupportedFlavorException. + * + * @param flavor the requested flavor for the data + * @return the object + * @exception UnsupportedFlavorException if the data could not be + * converted to the requested flavor + * @exception IOException if an I/O error occurs + * @see javax.activation.ActivationDataFlavor + */ + public Object getTransferData(DataFlavor flavor) + throws UnsupportedFlavorException, IOException { + return getDataContentHandler().getTransferData(flavor, dataSource); + } + + /** + * Set the CommandMap for use by this DataHandler. + * Setting it to null causes the CommandMap to revert + * to the CommandMap returned by the + * CommandMap.getDefaultCommandMap method. + * Changing the CommandMap, or setting it to null, + * clears out any data cached from the previous CommandMap. + * + * @param commandMap the CommandMap to use in this DataHandler + * + * @see javax.activation.CommandMap#setDefaultCommandMap + */ + public synchronized void setCommandMap(CommandMap commandMap) { + if (commandMap != currentCommandMap || commandMap == null) { + // clear cached values... + transferFlavors = emptyFlavors; + dataContentHandler = null; + + currentCommandMap = commandMap; + } + } + + /** + * Return the preferred commands for this type of data. + * This method calls the getPreferredCommands method + * in the CommandMap associated with this instance of DataHandler. + * This method returns an array that represents a subset of + * available commands. In cases where multiple commands for the + * MIME type represented by this DataHandler are present, the + * installed CommandMap chooses the appropriate commands. + * + * @return the CommandInfo objects representing the preferred commands + * + * @see javax.activation.CommandMap#getPreferredCommands + */ + public CommandInfo[] getPreferredCommands() { + if (dataSource != null) + return getCommandMap().getPreferredCommands(getBaseType(), + dataSource); + else + return getCommandMap().getPreferredCommands(getBaseType()); + } + + /** + * Return all the commands for this type of data. + * This method returns an array containing all commands + * for the type of data represented by this DataHandler. The + * MIME type for the underlying data represented by this DataHandler + * is used to call through to the getAllCommands method + * of the CommandMap associated with this DataHandler. + * + * @return the CommandInfo objects representing all the commands + * + * @see javax.activation.CommandMap#getAllCommands + */ + public CommandInfo[] getAllCommands() { + if (dataSource != null) + return getCommandMap().getAllCommands(getBaseType(), dataSource); + else + return getCommandMap().getAllCommands(getBaseType()); + } + + /** + * Get the command cmdName. Use the search semantics as + * defined by the CommandMap installed in this DataHandler. The + * MIME type for the underlying data represented by this DataHandler + * is used to call through to the getCommand method + * of the CommandMap associated with this DataHandler. + * + * @param cmdName the command name + * @return the CommandInfo corresponding to the command + * + * @see javax.activation.CommandMap#getCommand + */ + public CommandInfo getCommand(String cmdName) { + if (dataSource != null) + return getCommandMap().getCommand(getBaseType(), cmdName, + dataSource); + else + return getCommandMap().getCommand(getBaseType(), cmdName); + } + + /** + * Return the data in its preferred Object form.

+ * + * If the DataHandler was instantiated with an object, return + * the object.

+ * + * If the DataHandler was instantiated with a DataSource, + * this method uses a DataContentHandler to return the content + * object for the data represented by this DataHandler. If no + * DataContentHandler can be found for the + * the type of this data, the DataHandler returns an + * InputStream for the data. + * + * @return the content. + * @exception IOException if an IOException occurs during + * this operation. + */ + public Object getContent() throws IOException { + if (object != null) + return object; + else + return getDataContentHandler().getContent(getDataSource()); + } + + /** + * A convenience method that takes a CommandInfo object + * and instantiates the corresponding command, usually + * a JavaBean component. + *

+ * This method calls the CommandInfo's getCommandObject + * method with the ClassLoader used to load + * the javax.activation.DataHandler class itself. + * + * @param cmdinfo the CommandInfo corresponding to a command + * @return the instantiated command object + */ + public Object getBean(CommandInfo cmdinfo) { + Object bean = null; + + try { + // make the bean + ClassLoader cld = null; + // First try the "application's" class loader. + cld = SecuritySupport.getContextClassLoader(); + if (cld == null) + cld = this.getClass().getClassLoader(); + bean = cmdinfo.getCommandObject(this, cld); + } catch (IOException e) { + } catch (ClassNotFoundException e) { } + + return bean; + } + + /** + * Get the DataContentHandler for this DataHandler:

+ * + * If a DataContentHandlerFactory is set, use it. + * Otherwise look for an object to serve DCH in the + * following order:

+ * + * 1) if a factory is set, use it

+ * 2) if a CommandMap is set, use it

+ * 3) use the default CommandMap

+ * + * In any case, wrap the real DataContentHandler with one of our own + * to handle any missing cases, fill in defaults, and to ensure that + * we always have a non-null DataContentHandler. + * + * @return the requested DataContentHandler + */ + private synchronized DataContentHandler getDataContentHandler() { + + // make sure the factory didn't change + if (factory != oldFactory) { + oldFactory = factory; + factoryDCH = null; + dataContentHandler = null; + transferFlavors = emptyFlavors; + } + + if (dataContentHandler != null) + return dataContentHandler; + + String simpleMT = getBaseType(); + + if (factoryDCH == null && factory != null) + factoryDCH = factory.createDataContentHandler(simpleMT); + + if (factoryDCH != null) + dataContentHandler = factoryDCH; + + if (dataContentHandler == null) { + if (dataSource != null) + dataContentHandler = getCommandMap(). + createDataContentHandler(simpleMT, dataSource); + else + dataContentHandler = getCommandMap(). + createDataContentHandler(simpleMT); + } + + // getDataContentHandler always uses these 'wrapper' handlers + // to make sure it returns SOMETHING meaningful... + if (dataSource != null) + dataContentHandler = new DataSourceDataContentHandler( + dataContentHandler, + dataSource); + else + dataContentHandler = new ObjectDataContentHandler( + dataContentHandler, + object, + objectMimeType); + return dataContentHandler; + } + + /** + * Use the MimeType class to extract the MIME type/subtype, + * ignoring the parameters. The type is cached. + */ + private synchronized String getBaseType() { + if (shortType == null) { + String ct = getContentType(); + try { + MimeType mt = new MimeType(ct); + shortType = mt.getBaseType(); + } catch (MimeTypeParseException e) { + shortType = ct; + } + } + return shortType; + } + + /** + * Sets the DataContentHandlerFactory. The DataContentHandlerFactory + * is called first to find DataContentHandlers. + * The DataContentHandlerFactory can only be set once. + *

+ * If the DataContentHandlerFactory has already been set, + * this method throws an Error. + * + * @param newFactory the DataContentHandlerFactory + * @exception Error if the factory has already been defined. + * + * @see javax.activation.DataContentHandlerFactory + */ + public static synchronized void setDataContentHandlerFactory( + DataContentHandlerFactory newFactory) { + if (factory != null) + throw new Error("DataContentHandlerFactory already defined"); + + SecurityManager security = System.getSecurityManager(); + if (security != null) { + try { + // if it's ok with the SecurityManager, it's ok with me... + security.checkSetFactory(); + } catch (SecurityException ex) { + // otherwise, we also allow it if this code and the + // factory come from the same class loader (e.g., + // the JAF classes were loaded with the applet classes). + if (DataHandler.class.getClassLoader() != + newFactory.getClass().getClassLoader()) + throw ex; + } + } + factory = newFactory; + } +} + +/** + * The DataHanderDataSource class implements the + * DataSource interface when the DataHandler is constructed + * with an Object and a mimeType string. + */ +class DataHandlerDataSource implements DataSource { + DataHandler dataHandler = null; + + /** + * The constructor. + */ + public DataHandlerDataSource(DataHandler dh) { + this.dataHandler = dh; + } + + /** + * Returns an InputStream representing this object. + * @return the InputStream + */ + public InputStream getInputStream() throws IOException { + return dataHandler.getInputStream(); + } + + /** + * Returns the OutputStream for this object. + * @return the OutputStream + */ + public OutputStream getOutputStream() throws IOException { + return dataHandler.getOutputStream(); + } + + /** + * Returns the MIME type of the data represented by this object. + * @return the MIME type + */ + public String getContentType() { + return dataHandler.getContentType(); + } + + /** + * Returns the name of this object. + * @return the name of this object + */ + public String getName() { + return dataHandler.getName(); // what else would it be? + } +} + +/* + * DataSourceDataContentHandler + * + * This is a private DataContentHandler that wraps the real + * DataContentHandler in the case where the DataHandler was instantiated + * with a DataSource. + */ +class DataSourceDataContentHandler implements DataContentHandler { + private DataSource ds = null; + private DataFlavor transferFlavors[] = null; + private DataContentHandler dch = null; + + /** + * The constructor. + */ + public DataSourceDataContentHandler(DataContentHandler dch, DataSource ds) { + this.ds = ds; + this.dch = dch; + } + + /** + * Return the DataFlavors for this DataContentHandler. + * @return the DataFlavors + */ + public DataFlavor[] getTransferDataFlavors() { + + if (transferFlavors == null) { + if (dch != null) { // is there a dch? + transferFlavors = dch.getTransferDataFlavors(); + } else { + transferFlavors = new DataFlavor[1]; + transferFlavors[0] = + new ActivationDataFlavor(ds.getContentType(), + ds.getContentType()); + } + } + return transferFlavors; + } + + /** + * Return the Transfer Data of type DataFlavor from InputStream. + * @param df the DataFlavor + * @param ds the DataSource + * @return the constructed Object + */ + public Object getTransferData(DataFlavor df, DataSource ds) throws + UnsupportedFlavorException, IOException { + + if (dch != null) + return dch.getTransferData(df, ds); + else if (df.equals(getTransferDataFlavors()[0])) // only have one now + return ds.getInputStream(); + else + throw new UnsupportedFlavorException(df); + } + + public Object getContent(DataSource ds) throws IOException { + + if (dch != null) + return dch.getContent(ds); + else + return ds.getInputStream(); + } + + /** + * Write the object to the output stream. + */ + public void writeTo(Object obj, String mimeType, OutputStream os) + throws IOException { + if (dch != null) + dch.writeTo(obj, mimeType, os); + else + throw new UnsupportedDataTypeException( + "no DCH for content type " + ds.getContentType()); + } +} + +/* + * ObjectDataContentHandler + * + * This is a private DataContentHandler that wraps the real + * DataContentHandler in the case where the DataHandler was instantiated + * with an object. + */ +class ObjectDataContentHandler implements DataContentHandler { + private DataFlavor transferFlavors[] = null; + private Object obj; + private String mimeType; + private DataContentHandler dch = null; + + /** + * The constructor. + */ + public ObjectDataContentHandler(DataContentHandler dch, + Object obj, String mimeType) { + this.obj = obj; + this.mimeType = mimeType; + this.dch = dch; + } + + /** + * Return the DataContentHandler for this object. + * Used only by the DataHandler class. + */ + public DataContentHandler getDCH() { + return dch; + } + + /** + * Return the DataFlavors for this DataContentHandler. + * @return the DataFlavors + */ + public synchronized DataFlavor[] getTransferDataFlavors() { + if (transferFlavors == null) { + if (dch != null) { + transferFlavors = dch.getTransferDataFlavors(); + } else { + transferFlavors = new DataFlavor[1]; + transferFlavors[0] = new ActivationDataFlavor(obj.getClass(), + mimeType, mimeType); + } + } + return transferFlavors; + } + + /** + * Return the Transfer Data of type DataFlavor from InputStream. + * @param df the DataFlavor + * @param ds the DataSource + * @return the constructed Object + */ + public Object getTransferData(DataFlavor df, DataSource ds) + throws UnsupportedFlavorException, IOException { + + if (dch != null) + return dch.getTransferData(df, ds); + else if (df.equals(getTransferDataFlavors()[0])) // only have one now + return obj; + else + throw new UnsupportedFlavorException(df); + + } + + public Object getContent(DataSource ds) { + return obj; + } + + /** + * Write the object to the output stream. + */ + public void writeTo(Object obj, String mimeType, OutputStream os) + throws IOException { + if (dch != null) + dch.writeTo(obj, mimeType, os); + else if (obj instanceof byte[]) + os.write((byte[])obj); + else if (obj instanceof String) { + OutputStreamWriter osw = new OutputStreamWriter(os); + osw.write((String)obj); + osw.flush(); + } else + throw new UnsupportedDataTypeException( + "no object DCH for MIME type " + this.mimeType); + } +} diff --git a/fine-third-jdk11/src/javax/activation/DataSource.java b/fine-third-jdk11/src/javax/activation/DataSource.java new file mode 100644 index 000000000..51745b562 --- /dev/null +++ b/fine-third-jdk11/src/javax/activation/DataSource.java @@ -0,0 +1,101 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.activation; + +import java.io.InputStream; +import java.io.OutputStream; +import java.io.IOException; + +/** + * The DataSource interface provides the JavaBeans Activation Framework + * with an abstraction of an arbitrary collection of data. It + * provides a type for that data as well as access + * to it in the form of InputStreams and + * OutputStreams where appropriate. + */ + +public interface DataSource { + + /** + * This method returns an InputStream representing + * the data and throws the appropriate exception if it can + * not do so. Note that a new InputStream object must be + * returned each time this method is called, and the stream must be + * positioned at the beginning of the data. + * + * @return an InputStream + * @exception IOException for failures creating the InputStream + */ + public InputStream getInputStream() throws IOException; + + /** + * This method returns an OutputStream where the + * data can be written and throws the appropriate exception if it can + * not do so. Note that a new OutputStream object must + * be returned each time this method is called, and the stream must + * be positioned at the location the data is to be written. + * + * @return an OutputStream + * @exception IOException for failures creating the OutputStream + */ + public OutputStream getOutputStream() throws IOException; + + /** + * This method returns the MIME type of the data in the form of a + * string. It should always return a valid type. It is suggested + * that getContentType return "application/octet-stream" if the + * DataSource implementation can not determine the data type. + * + * @return the MIME Type + */ + public String getContentType(); + + /** + * Return the name of this object where the name of the object + * is dependant on the nature of the underlying objects. DataSources + * encapsulating files may choose to return the filename of the object. + * (Typically this would be the last component of the filename, not an + * entire pathname.) + * + * @return the name of the object. + */ + public String getName(); +} diff --git a/fine-third-jdk11/src/javax/activation/FileDataSource.java b/fine-third-jdk11/src/javax/activation/FileDataSource.java new file mode 100644 index 000000000..caf1c2b32 --- /dev/null +++ b/fine-third-jdk11/src/javax/activation/FileDataSource.java @@ -0,0 +1,171 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.activation; + +import java.io.InputStream; +import java.io.OutputStream; +import java.io.File; +import java.io.FileDescriptor; +import java.io.FileNotFoundException; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import com.sun.activation.registries.MimeTypeFile; + +/** + * The FileDataSource class implements a simple DataSource object + * that encapsulates a file. It provides data typing services via + * a FileTypeMap object.

+ * + * FileDataSource Typing Semantics

+ * + * The FileDataSource class delegates data typing of files + * to an object subclassed from the FileTypeMap class. + * The setFileTypeMap method can be used to explicitly + * set the FileTypeMap for an instance of FileDataSource. If no + * FileTypeMap is set, the FileDataSource will call the FileTypeMap's + * getDefaultFileTypeMap method to get the System's default FileTypeMap. + * + * @see javax.activation.DataSource + * @see javax.activation.FileTypeMap + * @see javax.activation.MimetypesFileTypeMap + */ +public class FileDataSource implements DataSource { + + // keep track of original 'ref' passed in, non-null + // one indicated which was passed in: + private File _file = null; + private FileTypeMap typeMap = null; + + /** + * Creates a FileDataSource from a File object. Note: + * The file will not actually be opened until a method is + * called that requires the file to be opened. + * + * @param file the file + */ + public FileDataSource(File file) { + _file = file; // save the file Object... + } + + /** + * Creates a FileDataSource from + * the specified path name. Note: + * The file will not actually be opened until a method is + * called that requires the file to be opened. + * + * @param name the system-dependent file name. + */ + public FileDataSource(String name) { + this(new File(name)); // use the file constructor + } + + /** + * This method will return an InputStream representing the + * the data and will throw an IOException if it can + * not do so. This method will return a new + * instance of InputStream with each invocation. + * + * @return an InputStream + */ + public InputStream getInputStream() throws IOException { + return new FileInputStream(_file); + } + + /** + * This method will return an OutputStream representing the + * the data and will throw an IOException if it can + * not do so. This method will return a new instance of + * OutputStream with each invocation. + * + * @return an OutputStream + */ + public OutputStream getOutputStream() throws IOException { + return new FileOutputStream(_file); + } + + /** + * This method returns the MIME type of the data in the form of a + * string. This method uses the currently installed FileTypeMap. If + * there is no FileTypeMap explictly set, the FileDataSource will + * call the getDefaultFileTypeMap method on + * FileTypeMap to acquire a default FileTypeMap. Note: By + * default, the FileTypeMap used will be a MimetypesFileTypeMap. + * + * @return the MIME Type + * @see javax.activation.FileTypeMap#getDefaultFileTypeMap + */ + public String getContentType() { + // check to see if the type map is null? + if (typeMap == null) + return FileTypeMap.getDefaultFileTypeMap().getContentType(_file); + else + return typeMap.getContentType(_file); + } + + /** + * Return the name of this object. The FileDataSource + * will return the file name of the object. + * + * @return the name of the object. + * @see javax.activation.DataSource + */ + public String getName() { + return _file.getName(); + } + + /** + * Return the File object that corresponds to this FileDataSource. + * @return the File object for the file represented by this object. + */ + public File getFile() { + return _file; + } + + /** + * Set the FileTypeMap to use with this FileDataSource + * + * @param map The FileTypeMap for this object. + */ + public void setFileTypeMap(FileTypeMap map) { + typeMap = map; + } +} diff --git a/fine-third-jdk11/src/javax/activation/FileTypeMap.java b/fine-third-jdk11/src/javax/activation/FileTypeMap.java new file mode 100644 index 000000000..74b26381e --- /dev/null +++ b/fine-third-jdk11/src/javax/activation/FileTypeMap.java @@ -0,0 +1,145 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.activation; + +import java.io.File; +import java.util.Map; +import java.util.WeakHashMap; + +/** + * The FileTypeMap is an abstract class that provides a data typing + * interface for files. Implementations of this class will + * implement the getContentType methods which will derive a content + * type from a file name or a File object. FileTypeMaps could use any + * scheme to determine the data type, from examining the file extension + * of a file (like the MimetypesFileTypeMap) to opening the file and + * trying to derive its type from the contents of the file. The + * FileDataSource class uses the default FileTypeMap (a MimetypesFileTypeMap + * unless changed) to determine the content type of files. + * + * @see javax.activation.FileTypeMap + * @see javax.activation.FileDataSource + * @see javax.activation.MimetypesFileTypeMap + */ + +public abstract class FileTypeMap { + + private static FileTypeMap defaultMap = null; + private static Map map = + new WeakHashMap(); + + /** + * The default constructor. + */ + public FileTypeMap() { + super(); + } + + /** + * Return the type of the file object. This method should + * always return a valid MIME type. + * + * @param file A file to be typed. + * @return The content type. + */ + abstract public String getContentType(File file); + + /** + * Return the type of the file passed in. This method should + * always return a valid MIME type. + * + * @param filename the pathname of the file. + * @return The content type. + */ + abstract public String getContentType(String filename); + + /** + * Sets the default FileTypeMap for the system. This instance + * will be returned to callers of getDefaultFileTypeMap. + * + * @param fileTypeMap The FileTypeMap. + * @exception SecurityException if the caller doesn't have permission + * to change the default + */ + public static synchronized void setDefaultFileTypeMap(FileTypeMap fileTypeMap) { + SecurityManager security = System.getSecurityManager(); + if (security != null) { + try { + // if it's ok with the SecurityManager, it's ok with me... + security.checkSetFactory(); + } catch (SecurityException ex) { + // otherwise, we also allow it if this code and the + // factory come from the same (non-system) class loader (e.g., + // the JAF classes were loaded with the applet classes). + ClassLoader cl = FileTypeMap.class.getClassLoader(); + if (cl == null || cl.getParent() == null || + cl != fileTypeMap.getClass().getClassLoader()) + throw ex; + } + } + // remove any per-thread-context-class-loader FileTypeMap + map.remove(SecuritySupport.getContextClassLoader()); + defaultMap = fileTypeMap; + } + + /** + * Return the default FileTypeMap for the system. + * If setDefaultFileTypeMap was called, return + * that instance, otherwise return an instance of + * MimetypesFileTypeMap. + * + * @return The default FileTypeMap + * @see javax.activation.FileTypeMap#setDefaultFileTypeMap + */ + public static synchronized FileTypeMap getDefaultFileTypeMap() { + if (defaultMap != null) + return defaultMap; + + // fetch per-thread-context-class-loader default + ClassLoader tccl = SecuritySupport.getContextClassLoader(); + FileTypeMap def = map.get(tccl); + if (def == null) { + def = new MimetypesFileTypeMap(); + map.put(tccl, def); + } + return def; + } +} diff --git a/fine-third-jdk11/src/javax/activation/MailcapCommandMap.java b/fine-third-jdk11/src/javax/activation/MailcapCommandMap.java new file mode 100644 index 000000000..c7c85083d --- /dev/null +++ b/fine-third-jdk11/src/javax/activation/MailcapCommandMap.java @@ -0,0 +1,737 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.activation; + +import java.util.*; +import java.io.*; +import java.net.*; +import java.security.AccessController; +import java.security.PrivilegedAction; +import com.sun.activation.registries.MailcapFile; +import com.sun.activation.registries.LogSupport; + +/** + * MailcapCommandMap extends the CommandMap + * abstract class. It implements a CommandMap whose configuration + * is based on mailcap files + * (RFC 1524). + * The MailcapCommandMap can be configured both programmatically + * and via configuration files. + *

+ * Mailcap file search order:

+ * The MailcapCommandMap looks in various places in the user's + * system for mailcap file entries. When requests are made + * to search for commands in the MailcapCommandMap, it searches + * mailcap files in the following order: + *

    + *
  1. Programatically added entries to the MailcapCommandMap instance. + *
  2. The file .mailcap in the user's home directory. + *
  3. The file mailcap in the Java runtime. + *
  4. The file or resources named META-INF/mailcap. + *
  5. The file or resource named META-INF/mailcap.default + * (usually found only in the activation.jar file). + *
+ *

+ * (The current implementation looks for the mailcap file + * in the Java runtime in the directory java.home/conf + * if it exists, and otherwise in the directory + * java.home/lib, where java.home is the value + * of the "java.home" System property. Note that the "conf" directory was + * introduced in JDK 9.) + *

+ * Mailcap file format:

+ * + * Mailcap files must conform to the mailcap + * file specification (RFC 1524, A User Agent Configuration Mechanism + * For Multimedia Mail Format Information). + * The file format consists of entries corresponding to + * particular MIME types. In general, the specification + * specifies applications for clients to use when they + * themselves cannot operate on the specified MIME type. The + * MailcapCommandMap extends this specification by using a parameter mechanism + * in mailcap files that allows JavaBeans(tm) components to be specified as + * corresponding to particular commands for a MIME type.

+ * + * When a mailcap file is + * parsed, the MailcapCommandMap recognizes certain parameter signatures, + * specifically those parameter names that begin with x-java-. + * The MailcapCommandMap uses this signature to find + * command entries for inclusion into its registries. + * Parameter names with the form x-java-<name> + * are read by the MailcapCommandMap as identifying a command + * with the name name. When the name is + * content-handler the MailcapCommandMap recognizes the class + * signified by this parameter as a DataContentHandler. + * All other commands are handled generically regardless of command + * name. The command implementation is specified by a fully qualified + * class name of a JavaBean(tm) component. For example; a command for viewing + * some data can be specified as: x-java-view=com.foo.ViewBean.

+ * + * When the command name is fallback-entry, the value of + * the command may be true or false. An + * entry for a MIME type that includes a parameter of + * x-java-fallback-entry=true defines fallback commands + * for that MIME type that will only be used if no non-fallback entry + * can be found. For example, an entry of the form text/*; ; + * x-java-fallback-entry=true; x-java-view=com.sun.TextViewer + * specifies a view command to be used for any text MIME type. This + * view command would only be used if a non-fallback view command for + * the MIME type could not be found.

+ * + * MailcapCommandMap aware mailcap files have the + * following general form:

+ * + * # Comments begin with a '#' and continue to the end of the line.
+ * <mime type>; ; <parameter list>
+ * # Where a parameter list consists of one or more parameters,
+ * # where parameters look like: x-java-view=com.sun.TextViewer
+ * # and a parameter list looks like:
+ * text/plain; ; x-java-view=com.sun.TextViewer; x-java-edit=com.sun.TextEdit + *
+ * # Note that mailcap entries that do not contain 'x-java' parameters
+ * # and comply to RFC 1524 are simply ignored:
+ * image/gif; /usr/dt/bin/sdtimage %s
+ * + *
+ *

+ * + * @author Bart Calder + * @author Bill Shannon + */ + +public class MailcapCommandMap extends CommandMap { + /* + * We manage a collection of databases, searched in order. + */ + private MailcapFile[] DB; + private static final int PROG = 0; // programmatically added entries + + private static final String confDir; + + static { + String dir = null; + try { + dir = (String)AccessController.doPrivileged( + new PrivilegedAction() { + public Object run() { + String home = System.getProperty("java.home"); + String newdir = home + File.separator + "conf"; + File conf = new File(newdir); + if (conf.exists()) + return newdir + File.separator; + else + return home + File.separator + "lib" + File.separator; + } + }); + } catch (Exception ex) { + // ignore any exceptions + } + confDir = dir; + } + + /** + * The default Constructor. + */ + public MailcapCommandMap() { + super(); + List dbv = new ArrayList(5); // usually 5 or less databases + MailcapFile mf = null; + dbv.add(null); // place holder for PROG entry + + LogSupport.log("MailcapCommandMap: load HOME"); + try { + String user_home = System.getProperty("user.home"); + + if (user_home != null) { + String path = user_home + File.separator + ".mailcap"; + mf = loadFile(path); + if (mf != null) + dbv.add(mf); + } + } catch (SecurityException ex) {} + + LogSupport.log("MailcapCommandMap: load SYS"); + try { + // check system's home + if (confDir != null) { + mf = loadFile(confDir + "mailcap"); + if (mf != null) + dbv.add(mf); + } + } catch (SecurityException ex) {} + + LogSupport.log("MailcapCommandMap: load JAR"); + // load from the app's jar file + loadAllResources(dbv, "META-INF/mailcap"); + + LogSupport.log("MailcapCommandMap: load DEF"); + mf = loadResource("/META-INF/mailcap.default"); + + if (mf != null) + dbv.add(mf); + + DB = new MailcapFile[dbv.size()]; + DB = (MailcapFile[])dbv.toArray(DB); + } + + /** + * Load from the named resource. + */ + private MailcapFile loadResource(String name) { + InputStream clis = null; + try { + clis = SecuritySupport.getResourceAsStream(this.getClass(), name); + if (clis != null) { + MailcapFile mf = new MailcapFile(clis); + if (LogSupport.isLoggable()) + LogSupport.log("MailcapCommandMap: successfully loaded " + + "mailcap file: " + name); + return mf; + } else { + if (LogSupport.isLoggable()) + LogSupport.log("MailcapCommandMap: not loading " + + "mailcap file: " + name); + } + } catch (IOException e) { + if (LogSupport.isLoggable()) + LogSupport.log("MailcapCommandMap: can't load " + name, e); + } catch (SecurityException sex) { + if (LogSupport.isLoggable()) + LogSupport.log("MailcapCommandMap: can't load " + name, sex); + } finally { + try { + if (clis != null) + clis.close(); + } catch (IOException ex) { } // ignore it + } + return null; + } + + /** + * Load all of the named resource. + */ + private void loadAllResources(List v, String name) { + boolean anyLoaded = false; + try { + URL[] urls; + ClassLoader cld = null; + // First try the "application's" class loader. + cld = SecuritySupport.getContextClassLoader(); + if (cld == null) + cld = this.getClass().getClassLoader(); + if (cld != null) + urls = SecuritySupport.getResources(cld, name); + else + urls = SecuritySupport.getSystemResources(name); + if (urls != null) { + if (LogSupport.isLoggable()) + LogSupport.log("MailcapCommandMap: getResources"); + for (int i = 0; i < urls.length; i++) { + URL url = urls[i]; + InputStream clis = null; + if (LogSupport.isLoggable()) + LogSupport.log("MailcapCommandMap: URL " + url); + try { + clis = SecuritySupport.openStream(url); + if (clis != null) { + v.add(new MailcapFile(clis)); + anyLoaded = true; + if (LogSupport.isLoggable()) + LogSupport.log("MailcapCommandMap: " + + "successfully loaded " + + "mailcap file from URL: " + + url); + } else { + if (LogSupport.isLoggable()) + LogSupport.log("MailcapCommandMap: " + + "not loading mailcap " + + "file from URL: " + url); + } + } catch (IOException ioex) { + if (LogSupport.isLoggable()) + LogSupport.log("MailcapCommandMap: can't load " + + url, ioex); + } catch (SecurityException sex) { + if (LogSupport.isLoggable()) + LogSupport.log("MailcapCommandMap: can't load " + + url, sex); + } finally { + try { + if (clis != null) + clis.close(); + } catch (IOException cex) { } + } + } + } + } catch (Exception ex) { + if (LogSupport.isLoggable()) + LogSupport.log("MailcapCommandMap: can't load " + name, ex); + } + + // if failed to load anything, fall back to old technique, just in case + if (!anyLoaded) { + if (LogSupport.isLoggable()) + LogSupport.log("MailcapCommandMap: !anyLoaded"); + MailcapFile mf = loadResource("/" + name); + if (mf != null) + v.add(mf); + } + } + + /** + * Load from the named file. + */ + private MailcapFile loadFile(String name) { + MailcapFile mtf = null; + + try { + mtf = new MailcapFile(name); + } catch (IOException e) { + // e.printStackTrace(); + } + return mtf; + } + + /** + * Constructor that allows the caller to specify the path + * of a mailcap file. + * + * @param fileName The name of the mailcap file to open + * @exception IOException if the file can't be accessed + */ + public MailcapCommandMap(String fileName) throws IOException { + this(); + + if (LogSupport.isLoggable()) + LogSupport.log("MailcapCommandMap: load PROG from " + fileName); + if (DB[PROG] == null) { + DB[PROG] = new MailcapFile(fileName); + } + } + + + /** + * Constructor that allows the caller to specify an InputStream + * containing a mailcap file. + * + * @param is InputStream of the mailcap file to open + */ + public MailcapCommandMap(InputStream is) { + this(); + + LogSupport.log("MailcapCommandMap: load PROG"); + if (DB[PROG] == null) { + try { + DB[PROG] = new MailcapFile(is); + } catch (IOException ex) { + // XXX - should throw it + } + } + } + + /** + * Get the preferred command list for a MIME Type. The MailcapCommandMap + * searches the mailcap files as described above under + * Mailcap file search order.

+ * + * The result of the search is a proper subset of available + * commands in all mailcap files known to this instance of + * MailcapCommandMap. The first entry for a particular command + * is considered the preferred command. + * + * @param mimeType the MIME type + * @return the CommandInfo objects representing the preferred commands. + */ + public synchronized CommandInfo[] getPreferredCommands(String mimeType) { + List cmdList = new ArrayList(); + if (mimeType != null) + mimeType = mimeType.toLowerCase(Locale.ENGLISH); + + for (int i = 0; i < DB.length; i++) { + if (DB[i] == null) + continue; + Map cmdMap = DB[i].getMailcapList(mimeType); + if (cmdMap != null) + appendPrefCmdsToList(cmdMap, cmdList); + } + + // now add the fallback commands + for (int i = 0; i < DB.length; i++) { + if (DB[i] == null) + continue; + Map cmdMap = DB[i].getMailcapFallbackList(mimeType); + if (cmdMap != null) + appendPrefCmdsToList(cmdMap, cmdList); + } + + CommandInfo[] cmdInfos = new CommandInfo[cmdList.size()]; + cmdInfos = (CommandInfo[])cmdList.toArray(cmdInfos); + + return cmdInfos; + } + + /** + * Put the commands that are in the hash table, into the list. + */ + private void appendPrefCmdsToList(Map cmdHash, List cmdList) { + Iterator verb_enum = cmdHash.keySet().iterator(); + + while (verb_enum.hasNext()) { + String verb = (String)verb_enum.next(); + if (!checkForVerb(cmdList, verb)) { + List cmdList2 = (List)cmdHash.get(verb); // get the list + String className = (String)cmdList2.get(0); + cmdList.add(new CommandInfo(verb, className)); + } + } + } + + /** + * Check the cmdList to see if this command exists, return + * true if the verb is there. + */ + private boolean checkForVerb(List cmdList, String verb) { + Iterator ee = cmdList.iterator(); + while (ee.hasNext()) { + String enum_verb = + (String)((CommandInfo)ee.next()).getCommandName(); + if (enum_verb.equals(verb)) + return true; + } + return false; + } + + /** + * Get all the available commands in all mailcap files known to + * this instance of MailcapCommandMap for this MIME type. + * + * @param mimeType the MIME type + * @return the CommandInfo objects representing all the commands. + */ + public synchronized CommandInfo[] getAllCommands(String mimeType) { + List cmdList = new ArrayList(); + if (mimeType != null) + mimeType = mimeType.toLowerCase(Locale.ENGLISH); + + for (int i = 0; i < DB.length; i++) { + if (DB[i] == null) + continue; + Map cmdMap = DB[i].getMailcapList(mimeType); + if (cmdMap != null) + appendCmdsToList(cmdMap, cmdList); + } + + // now add the fallback commands + for (int i = 0; i < DB.length; i++) { + if (DB[i] == null) + continue; + Map cmdMap = DB[i].getMailcapFallbackList(mimeType); + if (cmdMap != null) + appendCmdsToList(cmdMap, cmdList); + } + + CommandInfo[] cmdInfos = new CommandInfo[cmdList.size()]; + cmdInfos = (CommandInfo[])cmdList.toArray(cmdInfos); + + return cmdInfos; + } + + /** + * Put the commands that are in the hash table, into the list. + */ + private void appendCmdsToList(Map typeHash, List cmdList) { + Iterator verb_enum = typeHash.keySet().iterator(); + + while (verb_enum.hasNext()) { + String verb = (String)verb_enum.next(); + List cmdList2 = (List)typeHash.get(verb); + Iterator cmd_enum = ((List)cmdList2).iterator(); + + while (cmd_enum.hasNext()) { + String cmd = (String)cmd_enum.next(); + cmdList.add(new CommandInfo(verb, cmd)); + // cmdList.add(0, new CommandInfo(verb, cmd)); + } + } + } + + /** + * Get the command corresponding to cmdName for the MIME type. + * + * @param mimeType the MIME type + * @param cmdName the command name + * @return the CommandInfo object corresponding to the command. + */ + public synchronized CommandInfo getCommand(String mimeType, + String cmdName) { + if (mimeType != null) + mimeType = mimeType.toLowerCase(Locale.ENGLISH); + + for (int i = 0; i < DB.length; i++) { + if (DB[i] == null) + continue; + Map cmdMap = DB[i].getMailcapList(mimeType); + if (cmdMap != null) { + // get the cmd list for the cmd + List v = (List)cmdMap.get(cmdName); + if (v != null) { + String cmdClassName = (String)v.get(0); + + if (cmdClassName != null) + return new CommandInfo(cmdName, cmdClassName); + } + } + } + + // now try the fallback list + for (int i = 0; i < DB.length; i++) { + if (DB[i] == null) + continue; + Map cmdMap = DB[i].getMailcapFallbackList(mimeType); + if (cmdMap != null) { + // get the cmd list for the cmd + List v = (List)cmdMap.get(cmdName); + if (v != null) { + String cmdClassName = (String)v.get(0); + + if (cmdClassName != null) + return new CommandInfo(cmdName, cmdClassName); + } + } + } + return null; + } + + /** + * Add entries to the registry. Programmatically + * added entries are searched before other entries.

+ * + * The string that is passed in should be in mailcap + * format. + * + * @param mail_cap a correctly formatted mailcap string + */ + public synchronized void addMailcap(String mail_cap) { + // check to see if one exists + LogSupport.log("MailcapCommandMap: add to PROG"); + if (DB[PROG] == null) + DB[PROG] = new MailcapFile(); + + DB[PROG].appendToMailcap(mail_cap); + } + + /** + * Return the DataContentHandler for the specified MIME type. + * + * @param mimeType the MIME type + * @return the DataContentHandler + */ + public synchronized DataContentHandler createDataContentHandler( + String mimeType) { + if (LogSupport.isLoggable()) + LogSupport.log( + "MailcapCommandMap: createDataContentHandler for " + mimeType); + if (mimeType != null) + mimeType = mimeType.toLowerCase(Locale.ENGLISH); + + for (int i = 0; i < DB.length; i++) { + if (DB[i] == null) + continue; + if (LogSupport.isLoggable()) + LogSupport.log(" search DB #" + i); + Map cmdMap = DB[i].getMailcapList(mimeType); + if (cmdMap != null) { + List v = (List)cmdMap.get("content-handler"); + if (v != null) { + String name = (String)v.get(0); + DataContentHandler dch = getDataContentHandler(name); + if (dch != null) + return dch; + } + } + } + + // now try the fallback entries + for (int i = 0; i < DB.length; i++) { + if (DB[i] == null) + continue; + if (LogSupport.isLoggable()) + LogSupport.log(" search fallback DB #" + i); + Map cmdMap = DB[i].getMailcapFallbackList(mimeType); + if (cmdMap != null) { + List v = (List)cmdMap.get("content-handler"); + if (v != null) { + String name = (String)v.get(0); + DataContentHandler dch = getDataContentHandler(name); + if (dch != null) + return dch; + } + } + } + return null; + } + + private DataContentHandler getDataContentHandler(String name) { + if (LogSupport.isLoggable()) + LogSupport.log(" got content-handler"); + if (LogSupport.isLoggable()) + LogSupport.log(" class " + name); + try { + ClassLoader cld = null; + // First try the "application's" class loader. + cld = SecuritySupport.getContextClassLoader(); + if (cld == null) + cld = this.getClass().getClassLoader(); + Class cl = null; + try { + cl = cld.loadClass(name); + } catch (Exception ex) { + // if anything goes wrong, do it the old way + cl = Class.forName(name); + } + if (cl != null) // XXX - always true? + return (DataContentHandler)cl.newInstance(); + } catch (IllegalAccessException e) { + if (LogSupport.isLoggable()) + LogSupport.log("Can't load DCH " + name, e); + } catch (ClassNotFoundException e) { + if (LogSupport.isLoggable()) + LogSupport.log("Can't load DCH " + name, e); + } catch (InstantiationException e) { + if (LogSupport.isLoggable()) + LogSupport.log("Can't load DCH " + name, e); + } + return null; + } + + /** + * Get all the MIME types known to this command map. + * + * @return array of MIME types as strings + * @since JAF 1.1 + */ + public synchronized String[] getMimeTypes() { + List mtList = new ArrayList(); + + for (int i = 0; i < DB.length; i++) { + if (DB[i] == null) + continue; + String[] ts = DB[i].getMimeTypes(); + if (ts != null) { + for (int j = 0; j < ts.length; j++) { + // eliminate duplicates + if (!mtList.contains(ts[j])) + mtList.add(ts[j]); + } + } + } + + String[] mts = new String[mtList.size()]; + mts = (String[])mtList.toArray(mts); + + return mts; + } + + /** + * Get the native commands for the given MIME type. + * Returns an array of strings where each string is + * an entire mailcap file entry. The application + * will need to parse the entry to extract the actual + * command as well as any attributes it needs. See + * RFC 1524 + * for details of the mailcap entry syntax. Only mailcap + * entries that specify a view command for the specified + * MIME type are returned. + * + * @param mimeType the MIME type + * @return array of native command entries + * @since JAF 1.1 + */ + public synchronized String[] getNativeCommands(String mimeType) { + List cmdList = new ArrayList(); + if (mimeType != null) + mimeType = mimeType.toLowerCase(Locale.ENGLISH); + + for (int i = 0; i < DB.length; i++) { + if (DB[i] == null) + continue; + String[] cmds = DB[i].getNativeCommands(mimeType); + if (cmds != null) { + for (int j = 0; j < cmds.length; j++) { + // eliminate duplicates + if (!cmdList.contains(cmds[j])) + cmdList.add(cmds[j]); + } + } + } + + String[] cmds = new String[cmdList.size()]; + cmds = (String[])cmdList.toArray(cmds); + + return cmds; + } + + /** + * for debugging... + * + public static void main(String[] argv) throws Exception { + MailcapCommandMap map = new MailcapCommandMap(); + CommandInfo[] cmdInfo; + + cmdInfo = map.getPreferredCommands(argv[0]); + System.out.println("Preferred Commands:"); + for (int i = 0; i < cmdInfo.length; i++) + System.out.println("Command " + cmdInfo[i].getCommandName() + " [" + + cmdInfo[i].getCommandClass() + "]"); + cmdInfo = map.getAllCommands(argv[0]); + System.out.println(); + System.out.println("All Commands:"); + for (int i = 0; i < cmdInfo.length; i++) + System.out.println("Command " + cmdInfo[i].getCommandName() + " [" + + cmdInfo[i].getCommandClass() + "]"); + DataContentHandler dch = map.createDataContentHandler(argv[0]); + if (dch != null) + System.out.println("DataContentHandler " + + dch.getClass().toString()); + System.exit(0); + } + */ +} diff --git a/fine-third-jdk11/src/javax/activation/MimeType.java b/fine-third-jdk11/src/javax/activation/MimeType.java new file mode 100644 index 000000000..bed48a816 --- /dev/null +++ b/fine-third-jdk11/src/javax/activation/MimeType.java @@ -0,0 +1,359 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.activation; + +import java.io.*; +import java.util.Locale; + +/** + * A Multipurpose Internet Mail Extension (MIME) type, as defined + * in RFC 2045 and 2046. + */ +public class MimeType implements Externalizable { + + private String primaryType; + private String subType; + private MimeTypeParameterList parameters; + + /** + * A string that holds all the special chars. + */ + private static final String TSPECIALS = "()<>@,;:/[]?=\\\""; + + /** + * Default constructor. + */ + public MimeType() { + primaryType = "application"; + subType = "*"; + parameters = new MimeTypeParameterList(); + } + + /** + * Constructor that builds a MimeType from a String. + * + * @param rawdata the MIME type string + * @exception MimeTypeParseException if the MIME type can't be parsed + */ + public MimeType(String rawdata) throws MimeTypeParseException { + parse(rawdata); + } + + /** + * Constructor that builds a MimeType with the given primary and sub type + * but has an empty parameter list. + * + * @param primary the primary MIME type + * @param sub the MIME sub-type + * @exception MimeTypeParseException if the primary type or subtype + * is not a valid token + */ + public MimeType(String primary, String sub) throws MimeTypeParseException { + // check to see if primary is valid + if (isValidToken(primary)) { + primaryType = primary.toLowerCase(Locale.ENGLISH); + } else { + throw new MimeTypeParseException("Primary type is invalid."); + } + + // check to see if sub is valid + if (isValidToken(sub)) { + subType = sub.toLowerCase(Locale.ENGLISH); + } else { + throw new MimeTypeParseException("Sub type is invalid."); + } + + parameters = new MimeTypeParameterList(); + } + + /** + * A routine for parsing the MIME type out of a String. + */ + private void parse(String rawdata) throws MimeTypeParseException { + int slashIndex = rawdata.indexOf('/'); + int semIndex = rawdata.indexOf(';'); + if ((slashIndex < 0) && (semIndex < 0)) { + // neither character is present, so treat it + // as an error + throw new MimeTypeParseException("Unable to find a sub type."); + } else if ((slashIndex < 0) && (semIndex >= 0)) { + // we have a ';' (and therefore a parameter list), + // but no '/' indicating a sub type is present + throw new MimeTypeParseException("Unable to find a sub type."); + } else if ((slashIndex >= 0) && (semIndex < 0)) { + // we have a primary and sub type but no parameter list + primaryType = rawdata.substring(0, slashIndex).trim(). + toLowerCase(Locale.ENGLISH); + subType = rawdata.substring(slashIndex + 1).trim(). + toLowerCase(Locale.ENGLISH); + parameters = new MimeTypeParameterList(); + } else if (slashIndex < semIndex) { + // we have all three items in the proper sequence + primaryType = rawdata.substring(0, slashIndex).trim(). + toLowerCase(Locale.ENGLISH); + subType = rawdata.substring(slashIndex + 1, semIndex).trim(). + toLowerCase(Locale.ENGLISH); + parameters = new MimeTypeParameterList(rawdata.substring(semIndex)); + } else { + // we have a ';' lexically before a '/' which means we + // have a primary type and a parameter list but no sub type + throw new MimeTypeParseException("Unable to find a sub type."); + } + + // now validate the primary and sub types + + // check to see if primary is valid + if (!isValidToken(primaryType)) + throw new MimeTypeParseException("Primary type is invalid."); + + // check to see if sub is valid + if (!isValidToken(subType)) + throw new MimeTypeParseException("Sub type is invalid."); + } + + /** + * Retrieve the primary type of this object. + * + * @return the primary MIME type + */ + public String getPrimaryType() { + return primaryType; + } + + /** + * Set the primary type for this object to the given String. + * + * @param primary the primary MIME type + * @exception MimeTypeParseException if the primary type + * is not a valid token + */ + public void setPrimaryType(String primary) throws MimeTypeParseException { + // check to see if primary is valid + if (!isValidToken(primaryType)) + throw new MimeTypeParseException("Primary type is invalid."); + primaryType = primary.toLowerCase(Locale.ENGLISH); + } + + /** + * Retrieve the subtype of this object. + * + * @return the MIME subtype + */ + public String getSubType() { + return subType; + } + + /** + * Set the subtype for this object to the given String. + * + * @param sub the MIME subtype + * @exception MimeTypeParseException if the subtype + * is not a valid token + */ + public void setSubType(String sub) throws MimeTypeParseException { + // check to see if sub is valid + if (!isValidToken(subType)) + throw new MimeTypeParseException("Sub type is invalid."); + subType = sub.toLowerCase(Locale.ENGLISH); + } + + /** + * Retrieve this object's parameter list. + * + * @return a MimeTypeParameterList object representing the parameters + */ + public MimeTypeParameterList getParameters() { + return parameters; + } + + /** + * Retrieve the value associated with the given name, or null if there + * is no current association. + * + * @param name the parameter name + * @return the paramter's value + */ + public String getParameter(String name) { + return parameters.get(name); + } + + /** + * Set the value to be associated with the given name, replacing + * any previous association. + * + * @param name the parameter name + * @param value the paramter's value + */ + public void setParameter(String name, String value) { + parameters.set(name, value); + } + + /** + * Remove any value associated with the given name. + * + * @param name the parameter name + */ + public void removeParameter(String name) { + parameters.remove(name); + } + + /** + * Return the String representation of this object. + */ + public String toString() { + return getBaseType() + parameters.toString(); + } + + /** + * Return a String representation of this object + * without the parameter list. + * + * @return the MIME type and sub-type + */ + public String getBaseType() { + return primaryType + "/" + subType; + } + + /** + * Determine if the primary and sub type of this object is + * the same as what is in the given type. + * + * @param type the MimeType object to compare with + * @return true if they match + */ + public boolean match(MimeType type) { + return primaryType.equals(type.getPrimaryType()) + && (subType.equals("*") + || type.getSubType().equals("*") + || (subType.equals(type.getSubType()))); + } + + /** + * Determine if the primary and sub type of this object is + * the same as the content type described in rawdata. + * + * @param rawdata the MIME type string to compare with + * @return true if they match + * @exception MimeTypeParseException if the MIME type can't be parsed + */ + public boolean match(String rawdata) throws MimeTypeParseException { + return match(new MimeType(rawdata)); + } + + /** + * The object implements the writeExternal method to save its contents + * by calling the methods of DataOutput for its primitive values or + * calling the writeObject method of ObjectOutput for objects, strings + * and arrays. + * + * @param out the ObjectOutput object to write to + * @exception IOException Includes any I/O exceptions that may occur + */ + public void writeExternal(ObjectOutput out) throws IOException { + out.writeUTF(toString()); + out.flush(); + } + + /** + * The object implements the readExternal method to restore its + * contents by calling the methods of DataInput for primitive + * types and readObject for objects, strings and arrays. The + * readExternal method must read the values in the same sequence + * and with the same types as were written by writeExternal. + * + * @param in the ObjectInput object to read from + * @exception ClassNotFoundException If the class for an object being + * restored cannot be found. + */ + public void readExternal(ObjectInput in) + throws IOException, ClassNotFoundException { + try { + parse(in.readUTF()); + } catch (MimeTypeParseException e) { + throw new IOException(e.toString()); + } + } + + // below here be scary parsing related things + + /** + * Determine whether or not a given character belongs to a legal token. + */ + private static boolean isTokenChar(char c) { + return ((c > 040) && (c < 0177)) && (TSPECIALS.indexOf(c) < 0); + } + + /** + * Determine whether or not a given string is a legal token. + */ + private boolean isValidToken(String s) { + int len = s.length(); + if (len > 0) { + for (int i = 0; i < len; ++i) { + char c = s.charAt(i); + if (!isTokenChar(c)) { + return false; + } + } + return true; + } else { + return false; + } + } + + /** + * A simple parser test, + * for debugging... + * + public static void main(String[] args) + throws MimeTypeParseException, IOException { + for (int i = 0; i < args.length; ++i) { + System.out.println("Original: " + args[i]); + + MimeType type = new MimeType(args[i]); + + System.out.println("Short: " + type.getBaseType()); + System.out.println("Parsed: " + type.toString()); + System.out.println(); + } + } + */ +} diff --git a/fine-third-jdk11/src/javax/activation/MimeTypeParameterList.java b/fine-third-jdk11/src/javax/activation/MimeTypeParameterList.java new file mode 100644 index 000000000..4f4926b84 --- /dev/null +++ b/fine-third-jdk11/src/javax/activation/MimeTypeParameterList.java @@ -0,0 +1,354 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.activation; + +import java.util.Hashtable; +import java.util.Enumeration; +import java.util.Locale; + +/** + * A parameter list of a MimeType + * as defined in RFC 2045 and 2046. The Primary type of the + * object must already be stripped off. + * + * @see javax.activation.MimeType + */ +public class MimeTypeParameterList { + private Hashtable parameters; + + /** + * A string that holds all the special chars. + */ + private static final String TSPECIALS = "()<>@,;:/[]?=\\\""; + + + /** + * Default constructor. + */ + public MimeTypeParameterList() { + parameters = new Hashtable(); + } + + /** + * Constructs a new MimeTypeParameterList with the passed in data. + * + * @param parameterList an RFC 2045, 2046 compliant parameter list. + * @exception MimeTypeParseException if the MIME type can't be parsed + */ + public MimeTypeParameterList(String parameterList) + throws MimeTypeParseException { + parameters = new Hashtable(); + + // now parse rawdata + parse(parameterList); + } + + /** + * A routine for parsing the parameter list out of a String. + * + * @param parameterList an RFC 2045, 2046 compliant parameter list. + * @exception MimeTypeParseException if the MIME type can't be parsed + */ + protected void parse(String parameterList) throws MimeTypeParseException { + if (parameterList == null) + return; + + int length = parameterList.length(); + if (length <= 0) + return; + + int i; + char c; + for (i = skipWhiteSpace(parameterList, 0); + i < length && (c = parameterList.charAt(i)) == ';'; + i = skipWhiteSpace(parameterList, i)) { + int lastIndex; + String name; + String value; + + // eat the ';' + i++; + + // now parse the parameter name + + // skip whitespace + i = skipWhiteSpace(parameterList, i); + + // tolerate trailing semicolon, even though it violates the spec + if (i >= length) + return; + + // find the end of the token char run + lastIndex = i; + while ((i < length) && isTokenChar(parameterList.charAt(i))) + i++; + + name = parameterList.substring(lastIndex, i). + toLowerCase(Locale.ENGLISH); + + // now parse the '=' that separates the name from the value + i = skipWhiteSpace(parameterList, i); + + if (i >= length || parameterList.charAt(i) != '=') + throw new MimeTypeParseException( + "Couldn't find the '=' that separates a " + + "parameter name from its value."); + + // eat it and parse the parameter value + i++; + i = skipWhiteSpace(parameterList, i); + + if (i >= length) + throw new MimeTypeParseException( + "Couldn't find a value for parameter named " + name); + + // now find out whether or not we have a quoted value + c = parameterList.charAt(i); + if (c == '"') { + // yup it's quoted so eat it and capture the quoted string + i++; + if (i >= length) + throw new MimeTypeParseException( + "Encountered unterminated quoted parameter value."); + + lastIndex = i; + + // find the next unescaped quote + while (i < length) { + c = parameterList.charAt(i); + if (c == '"') + break; + if (c == '\\') { + // found an escape sequence + // so skip this and the + // next character + i++; + } + i++; + } + if (c != '"') + throw new MimeTypeParseException( + "Encountered unterminated quoted parameter value."); + + value = unquote(parameterList.substring(lastIndex, i)); + // eat the quote + i++; + } else if (isTokenChar(c)) { + // nope it's an ordinary token so it + // ends with a non-token char + lastIndex = i; + while (i < length && isTokenChar(parameterList.charAt(i))) + i++; + value = parameterList.substring(lastIndex, i); + } else { + // it ain't a value + throw new MimeTypeParseException( + "Unexpected character encountered at index " + i); + } + + // now put the data into the hashtable + parameters.put(name, value); + } + if (i < length) { + throw new MimeTypeParseException( + "More characters encountered in input than expected."); + } + } + + /** + * Return the number of name-value pairs in this list. + * + * @return the number of parameters + */ + public int size() { + return parameters.size(); + } + + /** + * Determine whether or not this list is empty. + * + * @return true if there are no parameters + */ + public boolean isEmpty() { + return parameters.isEmpty(); + } + + /** + * Retrieve the value associated with the given name, or null if there + * is no current association. + * + * @param name the parameter name + * @return the parameter's value + */ + public String get(String name) { + return (String)parameters.get(name.trim().toLowerCase(Locale.ENGLISH)); + } + + /** + * Set the value to be associated with the given name, replacing + * any previous association. + * + * @param name the parameter name + * @param value the parameter's value + */ + public void set(String name, String value) { + parameters.put(name.trim().toLowerCase(Locale.ENGLISH), value); + } + + /** + * Remove any value associated with the given name. + * + * @param name the parameter name + */ + public void remove(String name) { + parameters.remove(name.trim().toLowerCase(Locale.ENGLISH)); + } + + /** + * Retrieve an enumeration of all the names in this list. + * + * @return an enumeration of all parameter names + */ + public Enumeration getNames() { + return parameters.keys(); + } + + /** + * Return a string representation of this object. + */ + public String toString() { + StringBuffer buffer = new StringBuffer(); + buffer.ensureCapacity(parameters.size() * 16); + // heuristic: 8 characters per field + + Enumeration keys = parameters.keys(); + while (keys.hasMoreElements()) { + String key = (String)keys.nextElement(); + buffer.append("; "); + buffer.append(key); + buffer.append('='); + buffer.append(quote((String)parameters.get(key))); + } + + return buffer.toString(); + } + + // below here be scary parsing related things + + /** + * Determine whether or not a given character belongs to a legal token. + */ + private static boolean isTokenChar(char c) { + return ((c > 040) && (c < 0177)) && (TSPECIALS.indexOf(c) < 0); + } + + /** + * return the index of the first non white space character in + * rawdata at or after index i. + */ + private static int skipWhiteSpace(String rawdata, int i) { + int length = rawdata.length(); + while ((i < length) && Character.isWhitespace(rawdata.charAt(i))) + i++; + return i; + } + + /** + * A routine that knows how and when to quote and escape the given value. + */ + private static String quote(String value) { + boolean needsQuotes = false; + + // check to see if we actually have to quote this thing + int length = value.length(); + for (int i = 0; (i < length) && !needsQuotes; i++) { + needsQuotes = !isTokenChar(value.charAt(i)); + } + + if (needsQuotes) { + StringBuffer buffer = new StringBuffer(); + buffer.ensureCapacity((int)(length * 1.5)); + + // add the initial quote + buffer.append('"'); + + // add the properly escaped text + for (int i = 0; i < length; ++i) { + char c = value.charAt(i); + if ((c == '\\') || (c == '"')) + buffer.append('\\'); + buffer.append(c); + } + + // add the closing quote + buffer.append('"'); + + return buffer.toString(); + } else { + return value; + } + } + + /** + * A routine that knows how to strip the quotes and + * escape sequences from the given value. + */ + private static String unquote(String value) { + int valueLength = value.length(); + StringBuffer buffer = new StringBuffer(); + buffer.ensureCapacity(valueLength); + + boolean escaped = false; + for (int i = 0; i < valueLength; ++i) { + char currentChar = value.charAt(i); + if (!escaped && (currentChar != '\\')) { + buffer.append(currentChar); + } else if (escaped) { + buffer.append(currentChar); + escaped = false; + } else { + escaped = true; + } + } + + return buffer.toString(); + } +} diff --git a/fine-third-jdk11/src/javax/activation/MimeTypeParseException.java b/fine-third-jdk11/src/javax/activation/MimeTypeParseException.java new file mode 100644 index 000000000..d17f76003 --- /dev/null +++ b/fine-third-jdk11/src/javax/activation/MimeTypeParseException.java @@ -0,0 +1,63 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.activation; + +/** + * A class to encapsulate MimeType parsing related exceptions. + */ +public class MimeTypeParseException extends Exception { + + /** + * Constructs a MimeTypeParseException with no specified detail message. + */ + public MimeTypeParseException() { + super(); + } + + /** + * Constructs a MimeTypeParseException with the specified detail message. + * + * @param s the detail message. + */ + public MimeTypeParseException(String s) { + super(s); + } +} diff --git a/fine-third-jdk11/src/javax/activation/MimetypesFileTypeMap.java b/fine-third-jdk11/src/javax/activation/MimetypesFileTypeMap.java new file mode 100644 index 000000000..77d7ee902 --- /dev/null +++ b/fine-third-jdk11/src/javax/activation/MimetypesFileTypeMap.java @@ -0,0 +1,373 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.activation; + +import java.io.*; +import java.net.*; +import java.util.*; +import java.security.AccessController; +import java.security.PrivilegedAction; +import com.sun.activation.registries.MimeTypeFile; +import com.sun.activation.registries.LogSupport; + +/** + * This class extends FileTypeMap and provides data typing of files + * via their file extension. It uses the .mime.types format.

+ * + * MIME types file search order:

+ * The MimetypesFileTypeMap looks in various places in the user's + * system for MIME types file entries. When requests are made + * to search for MIME types in the MimetypesFileTypeMap, it searches + * MIME types files in the following order: + *

    + *
  1. Programmatically added entries to the MimetypesFileTypeMap instance. + *
  2. The file .mime.types in the user's home directory. + *
  3. The file mime.types in the Java runtime. + *
  4. The file or resources named META-INF/mime.types. + *
  5. The file or resource named META-INF/mimetypes.default + * (usually found only in the activation.jar file). + *
+ *

+ * (The current implementation looks for the mime.types file + * in the Java runtime in the directory java.home/conf + * if it exists, and otherwise in the directory + * java.home/lib, where java.home is the value + * of the "java.home" System property. Note that the "conf" directory was + * introduced in JDK 9.) + *

+ * MIME types file format:

+ * + * + * # comments begin with a '#'
+ * # the format is <mime type> <space separated file extensions>
+ * # for example:
+ * text/plain txt text TXT
+ * # this would map file.txt, file.text, and file.TXT to
+ * # the mime type "text/plain"
+ *
+ * + * @author Bart Calder + * @author Bill Shannon + */ +public class MimetypesFileTypeMap extends FileTypeMap { + /* + * We manage a collection of databases, searched in order. + */ + private MimeTypeFile[] DB; + private static final int PROG = 0; // programmatically added entries + + private static final String defaultType = "application/octet-stream"; + + private static final String confDir; + + static { + String dir = null; + try { + dir = (String)AccessController.doPrivileged( + new PrivilegedAction() { + public Object run() { + String home = System.getProperty("java.home"); + String newdir = home + File.separator + "conf"; + File conf = new File(newdir); + if (conf.exists()) + return newdir + File.separator; + else + return home + File.separator + "lib" + File.separator; + } + }); + } catch (Exception ex) { + // ignore any exceptions + } + confDir = dir; + } + + /** + * The default constructor. + */ + public MimetypesFileTypeMap() { + Vector dbv = new Vector(5); // usually 5 or less databases + MimeTypeFile mf = null; + dbv.addElement(null); // place holder for PROG entry + + LogSupport.log("MimetypesFileTypeMap: load HOME"); + try { + String user_home = System.getProperty("user.home"); + + if (user_home != null) { + String path = user_home + File.separator + ".mime.types"; + mf = loadFile(path); + if (mf != null) + dbv.addElement(mf); + } + } catch (SecurityException ex) {} + + LogSupport.log("MimetypesFileTypeMap: load SYS"); + try { + // check system's home + if (confDir != null) { + mf = loadFile(confDir + "mime.types"); + if (mf != null) + dbv.addElement(mf); + } + } catch (SecurityException ex) {} + + LogSupport.log("MimetypesFileTypeMap: load JAR"); + // load from the app's jar file + loadAllResources(dbv, "META-INF/mime.types"); + + LogSupport.log("MimetypesFileTypeMap: load DEF"); + mf = loadResource("/META-INF/mimetypes.default"); + + if (mf != null) + dbv.addElement(mf); + + DB = new MimeTypeFile[dbv.size()]; + dbv.copyInto(DB); + } + + /** + * Load from the named resource. + */ + private MimeTypeFile loadResource(String name) { + InputStream clis = null; + try { + clis = SecuritySupport.getResourceAsStream(this.getClass(), name); + if (clis != null) { + MimeTypeFile mf = new MimeTypeFile(clis); + if (LogSupport.isLoggable()) + LogSupport.log("MimetypesFileTypeMap: successfully " + + "loaded mime types file: " + name); + return mf; + } else { + if (LogSupport.isLoggable()) + LogSupport.log("MimetypesFileTypeMap: not loading " + + "mime types file: " + name); + } + } catch (IOException e) { + if (LogSupport.isLoggable()) + LogSupport.log("MimetypesFileTypeMap: can't load " + name, e); + } catch (SecurityException sex) { + if (LogSupport.isLoggable()) + LogSupport.log("MimetypesFileTypeMap: can't load " + name, sex); + } finally { + try { + if (clis != null) + clis.close(); + } catch (IOException ex) { } // ignore it + } + return null; + } + + /** + * Load all of the named resource. + */ + private void loadAllResources(Vector v, String name) { + boolean anyLoaded = false; + try { + URL[] urls; + ClassLoader cld = null; + // First try the "application's" class loader. + cld = SecuritySupport.getContextClassLoader(); + if (cld == null) + cld = this.getClass().getClassLoader(); + if (cld != null) + urls = SecuritySupport.getResources(cld, name); + else + urls = SecuritySupport.getSystemResources(name); + if (urls != null) { + if (LogSupport.isLoggable()) + LogSupport.log("MimetypesFileTypeMap: getResources"); + for (int i = 0; i < urls.length; i++) { + URL url = urls[i]; + InputStream clis = null; + if (LogSupport.isLoggable()) + LogSupport.log("MimetypesFileTypeMap: URL " + url); + try { + clis = SecuritySupport.openStream(url); + if (clis != null) { + v.addElement(new MimeTypeFile(clis)); + anyLoaded = true; + if (LogSupport.isLoggable()) + LogSupport.log("MimetypesFileTypeMap: " + + "successfully loaded " + + "mime types from URL: " + url); + } else { + if (LogSupport.isLoggable()) + LogSupport.log("MimetypesFileTypeMap: " + + "not loading " + + "mime types from URL: " + url); + } + } catch (IOException ioex) { + if (LogSupport.isLoggable()) + LogSupport.log("MimetypesFileTypeMap: can't load " + + url, ioex); + } catch (SecurityException sex) { + if (LogSupport.isLoggable()) + LogSupport.log("MimetypesFileTypeMap: can't load " + + url, sex); + } finally { + try { + if (clis != null) + clis.close(); + } catch (IOException cex) { } + } + } + } + } catch (Exception ex) { + if (LogSupport.isLoggable()) + LogSupport.log("MimetypesFileTypeMap: can't load " + name, ex); + } + + // if failed to load anything, fall back to old technique, just in case + if (!anyLoaded) { + LogSupport.log("MimetypesFileTypeMap: !anyLoaded"); + MimeTypeFile mf = loadResource("/" + name); + if (mf != null) + v.addElement(mf); + } + } + + /** + * Load the named file. + */ + private MimeTypeFile loadFile(String name) { + MimeTypeFile mtf = null; + + try { + mtf = new MimeTypeFile(name); + } catch (IOException e) { + // e.printStackTrace(); + } + return mtf; + } + + /** + * Construct a MimetypesFileTypeMap with programmatic entries + * added from the named file. + * + * @param mimeTypeFileName the file name + * @exception IOException for errors reading the file + */ + public MimetypesFileTypeMap(String mimeTypeFileName) throws IOException { + this(); + DB[PROG] = new MimeTypeFile(mimeTypeFileName); + } + + /** + * Construct a MimetypesFileTypeMap with programmatic entries + * added from the InputStream. + * + * @param is the input stream to read from + */ + public MimetypesFileTypeMap(InputStream is) { + this(); + try { + DB[PROG] = new MimeTypeFile(is); + } catch (IOException ex) { + // XXX - really should throw it + } + } + + /** + * Prepend the MIME type values to the registry. + * + * @param mime_types A .mime.types formatted string of entries. + */ + public synchronized void addMimeTypes(String mime_types) { + // check to see if we have created the registry + if (DB[PROG] == null) + DB[PROG] = new MimeTypeFile(); // make one + + DB[PROG].appendToRegistry(mime_types); + } + + /** + * Return the MIME type of the file object. + * The implementation in this class calls + * getContentType(f.getName()). + * + * @param f the file + * @return the file's MIME type + */ + public String getContentType(File f) { + return this.getContentType(f.getName()); + } + + /** + * Return the MIME type based on the specified file name. + * The MIME type entries are searched as described above under + * MIME types file search order. + * If no entry is found, the type "application/octet-stream" is returned. + * + * @param filename the file name + * @return the file's MIME type + */ + public synchronized String getContentType(String filename) { + int dot_pos = filename.lastIndexOf("."); // period index + + if (dot_pos < 0) + return defaultType; + + String file_ext = filename.substring(dot_pos + 1); + if (file_ext.length() == 0) + return defaultType; + + for (int i = 0; i < DB.length; i++) { + if (DB[i] == null) + continue; + String result = DB[i].getMIMETypeString(file_ext); + if (result != null) + return result; + } + return defaultType; + } + + /** + * for debugging... + * + public static void main(String[] argv) throws Exception { + MimetypesFileTypeMap map = new MimetypesFileTypeMap(); + System.out.println("File " + argv[0] + " has MIME type " + + map.getContentType(argv[0])); + System.exit(0); + } + */ +} diff --git a/fine-third-jdk11/src/javax/activation/SecuritySupport.java b/fine-third-jdk11/src/javax/activation/SecuritySupport.java new file mode 100644 index 000000000..cf6943e43 --- /dev/null +++ b/fine-third-jdk11/src/javax/activation/SecuritySupport.java @@ -0,0 +1,144 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.activation; + +import java.security.*; +import java.net.*; +import java.io.*; +import java.util.*; + +/** + * Security related methods that only work on J2SE 1.2 and newer. + */ +class SecuritySupport { + + private SecuritySupport() { + // private constructor, can't create an instance + } + + public static ClassLoader getContextClassLoader() { + return (ClassLoader) + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + ClassLoader cl = null; + try { + cl = Thread.currentThread().getContextClassLoader(); + } catch (SecurityException ex) { } + return cl; + } + }); + } + + public static InputStream getResourceAsStream(final Class c, + final String name) throws IOException { + try { + return (InputStream) + AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws IOException { + return c.getResourceAsStream(name); + } + }); + } catch (PrivilegedActionException e) { + throw (IOException)e.getException(); + } + } + + public static URL[] getResources(final ClassLoader cl, final String name) { + return (URL[]) + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + URL[] ret = null; + try { + List v = new ArrayList(); + Enumeration e = cl.getResources(name); + while (e != null && e.hasMoreElements()) { + URL url = (URL)e.nextElement(); + if (url != null) + v.add(url); + } + if (v.size() > 0) { + ret = new URL[v.size()]; + ret = (URL[])v.toArray(ret); + } + } catch (IOException ioex) { + } catch (SecurityException ex) { } + return ret; + } + }); + } + + public static URL[] getSystemResources(final String name) { + return (URL[]) + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + URL[] ret = null; + try { + List v = new ArrayList(); + Enumeration e = ClassLoader.getSystemResources(name); + while (e != null && e.hasMoreElements()) { + URL url = (URL)e.nextElement(); + if (url != null) + v.add(url); + } + if (v.size() > 0) { + ret = new URL[v.size()]; + ret = (URL[])v.toArray(ret); + } + } catch (IOException ioex) { + } catch (SecurityException ex) { } + return ret; + } + }); + } + + public static InputStream openStream(final URL url) throws IOException { + try { + return (InputStream) + AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws IOException { + return url.openStream(); + } + }); + } catch (PrivilegedActionException e) { + throw (IOException)e.getException(); + } + } +} diff --git a/fine-third-jdk11/src/javax/activation/URLDataSource.java b/fine-third-jdk11/src/javax/activation/URLDataSource.java new file mode 100644 index 000000000..f5b937e7a --- /dev/null +++ b/fine-third-jdk11/src/javax/activation/URLDataSource.java @@ -0,0 +1,150 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.activation; + +import java.net.URL; +import java.net.URLConnection; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.IOException; + +/** + * The URLDataSource class provides an object that wraps a URL + * object in a DataSource interface. URLDataSource simplifies the handling + * of data described by URLs within the JavaBeans Activation Framework + * because this class can be used to create new DataHandlers. NOTE: The + * DataHandler object creates a URLDataSource internally, + * when it is constructed with a URL. + * + * @see javax.activation.DataSource + * @see javax.activation.DataHandler + */ +public class URLDataSource implements DataSource { + private URL url = null; + private URLConnection url_conn = null; + + /** + * URLDataSource constructor. The URLDataSource class will + * not open a connection to the URL until a method requiring it + * to do so is called. + * + * @param url The URL to be encapsulated in this object. + */ + public URLDataSource(URL url) { + this.url = url; + } + + /** + * Returns the value of the URL content-type header field. + * It calls the URL's URLConnection.getContentType method + * after retrieving a URLConnection object. + * Note: this method attempts to call the openConnection + * method on the URL. If this method fails, or if a content type is not + * returned from the URLConnection, getContentType returns + * "application/octet-stream" as the content type. + * + * @return the content type. + */ + public String getContentType() { + String type = null; + + try { + if (url_conn == null) + url_conn = url.openConnection(); + } catch (IOException e) { } + + if (url_conn != null) + type = url_conn.getContentType(); + + if (type == null) + type = "application/octet-stream"; + + return type; + } + + /** + * Calls the getFile method on the URL used to + * instantiate the object. + * + * @return the result of calling the URL's getFile method. + */ + public String getName() { + return url.getFile(); + } + + /** + * The getInputStream method from the URL. Calls the + * openStream method on the URL. + * + * @return the InputStream. + */ + public InputStream getInputStream() throws IOException { + return url.openStream(); + } + + /** + * The getOutputStream method from the URL. First an attempt is + * made to get the URLConnection object for the URL. If that + * succeeds, the getOutputStream method on the URLConnection + * is returned. + * + * @return the OutputStream. + */ + public OutputStream getOutputStream() throws IOException { + // get the url connection if it is available + url_conn = url.openConnection(); + + if (url_conn != null) { + url_conn.setDoOutput(true); + return url_conn.getOutputStream(); + } else + return null; + } + + /** + * Return the URL used to create this DataSource. + * + * @return The URL. + */ + public URL getURL() { + return url; + } +} diff --git a/fine-third-jdk11/src/javax/activation/UnsupportedDataTypeException.java b/fine-third-jdk11/src/javax/activation/UnsupportedDataTypeException.java new file mode 100644 index 000000000..6358d6d0d --- /dev/null +++ b/fine-third-jdk11/src/javax/activation/UnsupportedDataTypeException.java @@ -0,0 +1,70 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.activation; + +import java.io.IOException; + +/** + * Signals that the requested operation does not support the + * requested data type. + * + * @see javax.activation.DataHandler + */ + +public class UnsupportedDataTypeException extends IOException { + /** + * Constructs an UnsupportedDataTypeException with no detail + * message. + */ + public UnsupportedDataTypeException() { + super(); + } + + /** + * Constructs an UnsupportedDataTypeException with the specified + * message. + * + * @param s The detail message. + */ + public UnsupportedDataTypeException(String s) { + super(s); + } +} diff --git a/fine-third-jdk11/src/javax/activation/package.html b/fine-third-jdk11/src/javax/activation/package.html new file mode 100644 index 000000000..8392470f2 --- /dev/null +++ b/fine-third-jdk11/src/javax/activation/package.html @@ -0,0 +1,53 @@ + + + + + + + + +The JavaBeans(TM) Activation Framework is used by the JavaMail(TM) +API to manage MIME data. + + + diff --git a/fine-third-jdk11/src/javax/annotation/Generated.java b/fine-third-jdk11/src/javax/annotation/Generated.java new file mode 100644 index 000000000..f14d31038 --- /dev/null +++ b/fine-third-jdk11/src/javax/annotation/Generated.java @@ -0,0 +1,91 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2018 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.annotation; +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +/** + * The Generated annotation is used to mark source code + * that has been generated. + * It can also be used to differentiate user written code from generated code + * in a single file. + *

The value element must have the name of the + * code generator. The recommended convention is to use the fully qualified + * name of the code generator in the value field, + * for example com.company.package.classname.

+ *

The date element is used to indicate the date the + * source was generated. + * The date element must follow the ISO 8601 standard. + * For example, the date element could have the + * value 2001-07-04T12:08:56.235-0700, + * which represents 2001-07-04 12:08:56 local time in the U.S. Pacific + * time zone.

+ *

The comment element is a place holder for any comments + * that the code generator may want to include in the generated code.

+ * + * @since 1.6, Common Annotations 1.0 + */ + +@Documented +@Retention(SOURCE) +@Target({PACKAGE, TYPE, ANNOTATION_TYPE, METHOD, CONSTRUCTOR, FIELD, + LOCAL_VARIABLE, PARAMETER}) +public @interface Generated { + /** + * The value element must have the name of the code generator. + * The recommended convention is to use the fully qualified name of the + * code generator. For example: com.acme.generator.CodeGen. + */ + String[] value(); + + /** + * Date when the source was generated. + */ + String date() default ""; + + /** + * A place holder for any comments that the code generator may want to + * include in the generated code. + */ + String comments() default ""; +} + diff --git a/fine-third-jdk11/src/javax/annotation/ManagedBean.java b/fine-third-jdk11/src/javax/annotation/ManagedBean.java new file mode 100644 index 000000000..30c10d319 --- /dev/null +++ b/fine-third-jdk11/src/javax/annotation/ManagedBean.java @@ -0,0 +1,70 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2009-2018 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.annotation; + +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +/** + * The ManagedBean annotation marks a POJO (Plain Old Java Object) + * as a ManagedBean. A ManagedBean supports a small set of basic services + * such as resource injection, lifecycle callbacks and interceptors. + * + * @since Common Annotations 1.1 + */ +@Target(TYPE) +@Retention(RUNTIME) +public @interface ManagedBean { + /** + * The name of the Managed Bean. Managed Bean names must be unique within a + * Java EE module. For each named Managed Bean, Java EE containers must make + * available the following entries in JNDI, using the same naming scheme used + * for EJB components. + *

+ * In the application namespace:

+ * java:app/<module-name>/<bean-name>

+ * In the module namespace of the module containing the Managed Bean: + *

java:module/<bean-name> + * + */ + public String value() default ""; +} diff --git a/fine-third-jdk11/src/javax/annotation/PostConstruct.java b/fine-third-jdk11/src/javax/annotation/PostConstruct.java new file mode 100644 index 000000000..3be69531e --- /dev/null +++ b/fine-third-jdk11/src/javax/annotation/PostConstruct.java @@ -0,0 +1,97 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2018 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.annotation; + +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +/** + * The PostConstruct annotation is used on a method that + * needs to be executed after dependency injection is done to perform + * any initialization. This method must be invoked before the class + * is put into service. This annotation must be supported on all classes + * that support dependency injection. The method annotated with + * PostConstruct must be invoked even if the class does + * not request any resources to be injected. Only one + * method in a given class can be annotated with this annotation. + * The method on which the PostConstruct annotation is + * applied must fulfill all of the following criteria: + *

    + *
  • The method must not have any parameters except in the case of + * interceptors in which case it takes an InvocationContext + * object as defined by the Interceptors specification.
  • + *
  • The method defined on an interceptor class or superclass of an + * interceptor class must have one of the following signatures: + *

    + * void <METHOD>(InvocationContext) + *

    + * Object <METHOD>(InvocationContext) throws Exception + *

    + * Note: A PostConstruct interceptor method must not throw application + * exceptions, but it may be declared to throw checked exceptions including + * the java.lang.Exception if the same interceptor method interposes on + * business or timeout methods in addition to lifecycle events. If a + * PostConstruct interceptor method returns a value, it is ignored by + * the container. + *

  • + *
  • The method defined on a non-interceptor class must have the + * following signature: + *

    + * void <METHOD>() + *

  • + *
  • The method on which the PostConstruct annotation + * is applied may be public, protected, package private or private.
  • + *
  • The method must not be static except for the application client.
  • + *
  • The method should not be final.
  • + *
  • If the method throws an unchecked exception the class must not be put into + * service except in the case where the exception is handled by an + * interceptor.
+ * + * @see javax.annotation.PreDestroy + * @see javax.annotation.Resource + * @since 1.6, Common Annotations 1.0 + */ +@Documented +@Retention (RUNTIME) +@Target(METHOD) +public @interface PostConstruct { +} diff --git a/fine-third-jdk11/src/javax/annotation/PreDestroy.java b/fine-third-jdk11/src/javax/annotation/PreDestroy.java new file mode 100644 index 000000000..c7c113ef0 --- /dev/null +++ b/fine-third-jdk11/src/javax/annotation/PreDestroy.java @@ -0,0 +1,97 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2018 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.annotation; + +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +/** + * The PreDestroy annotation is used on a method as a + * callback notification to signal that the instance is in the + * process of being removed by the container. The method annotated + * with PreDestroy is typically used to + * release resources that it has been holding. This annotation must be + * supported by all container-managed objects that support the use of + * the PostConstruct annotation except the Java EE application + * client. The method on which the PreDestroy annotation + * is applied must fulfill all of the following criteria: + *
    + *
  • The method must not have any parameters except in the case of + * interceptors in which case it takes an InvocationContext + * object as defined by the Interceptors specification.
  • + *
  • The method defined on an interceptor class or superclass of an + * interceptor class must have one of the following signatures: + *

    + * void <METHOD>(InvocationContext) + *

    + * Object <METHOD>(InvocationContext) throws Exception + *

    + * Note: A PreDestroy interceptor method must not throw application + * exceptions, but it may be declared to throw checked exceptions including + * the java.lang.Exception if the same interceptor method interposes on + * business or timeout methods in addition to lifecycle events. If a + * PreDestroy interceptor method returns a value, it is ignored by + * the container. + *

  • + *
  • The method defined on a non-interceptor class must have the + * following signature: + *

    + * void <METHOD>() + *

  • + *
  • The method on which PreDestroy is applied may be public, protected, + * package private or private.
  • + *
  • The method must not be static.
  • + *
  • The method should not be final.
  • + *
  • If the method throws an unchecked exception it is ignored by + * the container.
  • + *
+ * + * @see javax.annotation.PostConstruct + * @see javax.annotation.Resource + * @since 1.6, Common Annotations 1.0 + */ + +@Documented +@Retention (RUNTIME) +@Target(METHOD) +public @interface PreDestroy { +} diff --git a/fine-third-jdk11/src/javax/annotation/Priority.java b/fine-third-jdk11/src/javax/annotation/Priority.java new file mode 100644 index 000000000..21fac05a7 --- /dev/null +++ b/fine-third-jdk11/src/javax/annotation/Priority.java @@ -0,0 +1,74 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2018 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.annotation; + +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +/** + * The Priority annotation can be applied to classes + * or parameters to indicate in what order they should be used. + * The effect of using the Priority annotation in + * any particular instance is defined by other specifications that + * define the use of a specific class. + *

+ * For example, the Interceptors specification defines the use of + * priorities on interceptors to control the order in which + * interceptors are called.

+ *

+ * Priority values should generally be non-negative, with negative values + * reserved for special meanings such as "undefined" or "not specified". + * A specification that defines use of the Priority annotation may define + * the range of allowed priorities and any priority values with special + * meaning.

+ * + * @since Common Annotations 1.2 + */ +@Target({TYPE,PARAMETER}) +@Retention(RUNTIME) +@Documented +public @interface Priority { + /** + * The priority value. + */ + int value(); +} diff --git a/fine-third-jdk11/src/javax/annotation/Resource.java b/fine-third-jdk11/src/javax/annotation/Resource.java new file mode 100644 index 000000000..1ce583b63 --- /dev/null +++ b/fine-third-jdk11/src/javax/annotation/Resource.java @@ -0,0 +1,143 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2018 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.annotation; + +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +/** + * The Resource annotation marks a resource that is needed + * by the application. This annotation may be applied to an + * application component class, or to fields or methods of the + * component class. When the annotation is applied to a + * field or method, the container will inject an instance + * of the requested resource into the application component + * when the component is initialized. If the annotation is + * applied to the component class, the annotation declares a + * resource that the application will look up at runtime. + *

+ * Even though this annotation is not marked Inherited, deployment + * tools are required to examine all superclasses of any component + * class to discover all uses of this annotation in all superclasses. + * All such annotation instances specify resources that are needed + * by the application component. Note that this annotation may + * appear on private fields and methods of superclasses; the container + * is required to perform injection in these cases as well.

+ * + * @since 1.6, Common Annotations 1.0 + */ +@Target({TYPE, FIELD, METHOD}) +@Retention(RUNTIME) +@Repeatable(Resources.class) +public @interface Resource { + /** + * The JNDI name of the resource. For field annotations, + * the default is the field name. For method annotations, + * the default is the JavaBeans property name corresponding + * to the method. For class annotations, there is no default + * and this must be specified. + */ + String name() default ""; + + /** + * The name of the resource that the reference points to. It can + * link to any compatible resource using the global JNDI names. + * + * @since 1.7, Common Annotations 1.1 + */ + + String lookup() default ""; + + /** + * The Java type of the resource. For field annotations, + * the default is the type of the field. For method annotations, + * the default is the type of the JavaBeans property. + * For class annotations, there is no default and this must be + * specified. + */ + Class type() default java.lang.Object.class; + + /** + * The two possible authentication types for a resource. + */ + enum AuthenticationType { + CONTAINER, + APPLICATION + } + + /** + * The authentication type to use for this resource. + * This may be specified for resources representing a + * connection factory of any supported type, and must + * not be specified for resources of other types. + */ + AuthenticationType authenticationType() default AuthenticationType.CONTAINER; + + /** + * Indicates whether this resource can be shared between + * this component and other components. + * This may be specified for resources representing a + * connection factory of any supported type, and must + * not be specified for resources of other types. + */ + boolean shareable() default true; + + /** + * A product-specific name that this resource should be mapped to. + * The mappedName element provides for mapping the + * resource reference to the name of a resource known to the + * applicaiton server. The mapped name could be of any form. + *

Application servers are not required to support any particular + * form or type of mapped name, nor the ability to use mapped names. + * The mapped name is product-dependent and often installation-dependent. + * No use of a mapped name is portable.

+ */ + String mappedName() default ""; + + /** + * Description of this resource. The description is expected + * to be in the default language of the system on which the + * application is deployed. The description can be presented + * to the Deployer to help in choosing the correct resource. + */ + String description() default ""; +} diff --git a/fine-third-jdk11/src/javax/annotation/Resources.java b/fine-third-jdk11/src/javax/annotation/Resources.java new file mode 100644 index 000000000..19ecdcdeb --- /dev/null +++ b/fine-third-jdk11/src/javax/annotation/Resources.java @@ -0,0 +1,61 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2018 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.annotation; +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +/** + * This class is used to allow multiple resources declarations. + * + * @see javax.annotation.Resource + * @since 1.6, Common Annotations 1.0 + */ + +@Documented +@Retention(RUNTIME) +@Target(TYPE) +public @interface Resources { + /** + * Array used for multiple resource declarations. + */ + Resource[] value(); +} diff --git a/fine-third-jdk11/src/javax/annotation/package.html b/fine-third-jdk11/src/javax/annotation/package.html new file mode 100644 index 000000000..ccf7a00ea --- /dev/null +++ b/fine-third-jdk11/src/javax/annotation/package.html @@ -0,0 +1,47 @@ + + + + + This package defines the common annotations. + + diff --git a/fine-third-jdk11/src/javax/annotation/security/DeclareRoles.java b/fine-third-jdk11/src/javax/annotation/security/DeclareRoles.java new file mode 100644 index 000000000..6d51f1f48 --- /dev/null +++ b/fine-third-jdk11/src/javax/annotation/security/DeclareRoles.java @@ -0,0 +1,61 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2018 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.annotation.security; +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +/** + * Used by application to declare security roles. It can be + * specified on a class. The value of the DeclareRoles + * annotation is a list of security role names. + * + * @since Common Annotations 1.0 + */ +@Documented +@Retention (RUNTIME) +@Target(TYPE) +public @interface DeclareRoles { + /** + * List of security role names. + */ + String[] value(); +} diff --git a/fine-third-jdk11/src/javax/annotation/security/DenyAll.java b/fine-third-jdk11/src/javax/annotation/security/DenyAll.java new file mode 100644 index 000000000..c0aa5db54 --- /dev/null +++ b/fine-third-jdk11/src/javax/annotation/security/DenyAll.java @@ -0,0 +1,58 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2018 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.annotation.security; +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +/** + * Specifies that no security roles are allowed to invoke the specified + * method(s). + * + * @see javax.annotation.security.RolesAllowed + * @see javax.annotation.security.PermitAll + * @since Common Annotations 1.0 + */ +@Documented +@Retention (RUNTIME) +@Target({TYPE, METHOD}) +public @interface DenyAll { +} diff --git a/fine-third-jdk11/src/javax/annotation/security/PermitAll.java b/fine-third-jdk11/src/javax/annotation/security/PermitAll.java new file mode 100644 index 000000000..f4ad071e5 --- /dev/null +++ b/fine-third-jdk11/src/javax/annotation/security/PermitAll.java @@ -0,0 +1,66 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2018 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.annotation.security; +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +/** + * Specifies that all security roles are allowed to invoke the specified + * method(s) — i.e., that the specified method(s) are "unchecked". + * It can be specified on a class or on methods. Specifying it on the class + * means that it applies to all methods of the class. If specified at the + * method level, it only affects that method. If the RolesAllowed + * annotation is specified at the class level and this annotation is + * applied at the method level, the PermitAll + * annotation overrides the RolesAllowed annotation for + * the specified method. + * + * @see javax.annotation.security.RolesAllowed + * @see javax.annotation.security.DenyAll + * + * @since Common Annotations 1.0 + */ +@Documented +@Retention (RUNTIME) +@Target({TYPE, METHOD}) +public @interface PermitAll { +} diff --git a/fine-third-jdk11/src/javax/annotation/security/RolesAllowed.java b/fine-third-jdk11/src/javax/annotation/security/RolesAllowed.java new file mode 100644 index 000000000..74ffb29f9 --- /dev/null +++ b/fine-third-jdk11/src/javax/annotation/security/RolesAllowed.java @@ -0,0 +1,66 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2018 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.annotation.security; +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +/** + * Specifies the list of security roles permitted to access method(s) in an + * application. The value of the RolesAllowed annotation + * is a list of security role names. + * This annotation can be specified on a class or on method(s). Specifying it + * at a class level means that it applies to all the methods in the class. + * Specifying it on a method means that it is applicable to that method only. + * If applied at both the class and methods level, the method value overrides + * the class value if the two conflict. + * + * @since Common Annotations 1.0 + */ +@Documented +@Retention (RUNTIME) +@Target({TYPE, METHOD}) +public @interface RolesAllowed { + /** + * List of roles that are permitted access. + */ + String[] value(); +} diff --git a/fine-third-jdk11/src/javax/annotation/security/RunAs.java b/fine-third-jdk11/src/javax/annotation/security/RunAs.java new file mode 100644 index 000000000..e31f7e6e6 --- /dev/null +++ b/fine-third-jdk11/src/javax/annotation/security/RunAs.java @@ -0,0 +1,62 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2018 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.annotation.security; +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +/** + * Defines the identity of the application during execution. + * This allows developers to execute an application under a particular role. + * The role must map to the user / group information in the container's + * security realm. Its value is the name of a security role. + * + * @since Common Annotations 1.0 + */ +@Documented +@Retention (RUNTIME) +@Target(TYPE) +public @interface RunAs { + /** + * Name of a security role. + */ + String value(); +} diff --git a/fine-third-jdk11/src/javax/annotation/security/package.html b/fine-third-jdk11/src/javax/annotation/security/package.html new file mode 100644 index 000000000..5a195df8a --- /dev/null +++ b/fine-third-jdk11/src/javax/annotation/security/package.html @@ -0,0 +1,47 @@ + + + + + This package contains the security common annotations. + + diff --git a/fine-third-jdk11/src/javax/annotation/sql/DataSourceDefinition.java b/fine-third-jdk11/src/javax/annotation/sql/DataSourceDefinition.java new file mode 100644 index 000000000..bb3d68ad5 --- /dev/null +++ b/fine-third-jdk11/src/javax/annotation/sql/DataSourceDefinition.java @@ -0,0 +1,337 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2009-2018 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.annotation.sql; + +import java.lang.annotation.*; +import java.lang.annotation.Target; +import java.lang.annotation.Retention; +import java.lang.annotation.ElementType; +import java.lang.annotation.RetentionPolicy; + +/** + * Annotation used to define a container DataSource to + * be registered with JNDI. The DataSource may be configured by + * setting the annotation elements for commonly used DataSource + * properties. Additional standard and vendor-specific properties may be + * specified using the properties element. + *

+ * + * The data source will be registered under the name specified in the + * name element. It may be defined to be in any valid + * Java EE namespace, which will determine the accessibility of + * the data source from other components. + *

+ * A JDBC driver implementation class of the appropriate type, either + * DataSource, ConnectionPoolDataSource, or + * XADataSource, must be indicated by the className + * element. The availability of the driver class will be assumed at runtime. + *

+ * DataSource properties should not be specified more than once. If + * the url annotation element contains a DataSource property that was also + * specified using the corresponding annotation element or was specified in + * the properties annotation element, the precedence order is undefined + * and implementation specific: + *

+ *

+ *   @DataSourceDefinition(name="java:global/MyApp/MyDataSource",
+ *      className="org.apache.derby.jdbc.ClientDataSource",
+ *      url="jdbc:derby://localhost:1527/myDB;user=bill",
+ *      user="lance",
+ *      password="secret",
+ *      databaseName="testDB",
+ *      serverName="luckydog"
+ *   )// DO NOT DO THIS!!!
+ * 
+ *

+ * In the above example, the databaseName, user + * and serverName properties were specified as part of the + * url property and using the corresponding + * annotation elements. This should be avoided. + *

+ * If the properties annotation element is used and contains a + * DataSource property that was also specified using the corresponding + * annotation element, the annotation element value takes precedence. + * For example: + *

+ *

+ *   @DataSourceDefinition(name="java:global/MyApp/MyDataSource",
+ *      className="org.apache.derby.jdbc.ClientDataSource",
+ *      user="lance",
+ *      password="secret",
+ *      databaseName="testDB",
+ *      serverName="luckydog",
+ *       properties= {"databaseName=myDB", "databaseProp=doThis"}
+ *   )// DO NOT DO THIS!!!
+ * 
+ *

+ * This would result in the following values being used when configuring + * the DataSource: + *

    + *
  • serverName=luckydog
  • + *
  • portNumber=1527
  • + *
  • databaseName=testDB
  • + *
  • user=lance
  • + *
  • password=secret
  • + *
  • databaseProp=doThis
  • + *
+ *

+ * Vendors are not required to support properties that do not normally + * apply to a specific data source type. For example, specifying the + * transactional property to be true but supplying + * a value for className that implements a data source class + * other than XADataSource may not be supported. + *

+ * Vendor-specific properties may be combined with or used to + * override standard data source properties defined using this annotation. + *

+ * DataSource properties that are specified and are not supported + * in a given configuration or cannot be mapped to a vendor specific + * configuration property may be ignored. + *

+ * Examples: + *
+ *

+ *   @DataSourceDefinition(name="java:global/MyApp/MyDataSource",
+ *      className="com.foobar.MyDataSource",
+ *      portNumber=6689,
+ *      serverName="myserver.com",
+ *      user="lance",
+ *      password="secret"
+ *   )
+ * 
+ * 
+ *

+ * Using a URL: + *
+ *

+ *  @DataSourceDefinition(name="java:global/MyApp/MyDataSource",
+ *    className="org.apache.derby.jdbc.ClientDataSource",
+ *    url="jdbc:derby://localhost:1527/myDB",
+ *    user="lance",
+ *    password="secret"
+ * )
+ * 
+ *

+ * An example lookup of the DataSource from an EJB: + *

+ * @Stateless
+ * public class MyStatelessEJB {
+ *   @Resource(lookup="java:global/MyApp/myDataSource")
+ *    DataSource myDB;
+ *      ...
+ * }
+ * 
+ *

+ * @see javax.sql.DataSource + * @see javax.sql.XADataSource + * @see javax.sql.ConnectionPoolDataSource + * @since Common Annotations 1.1 + */ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(DataSourceDefinitions.class) +public @interface DataSourceDefinition { + + /** + * JNDI name by which the data source will be registered. + * @since 1.1 + */ + String name(); + + /** + * Name of a DataSource class that implements + * javax.sql.DataSource or javax.sql.XADataSource + * or javax.sql.ConnectionPoolDataSource. + * @since 1.1 + */ + String className(); + + /** + * Description of this data source + * @since 1.1 + */ + String description() default ""; + + /** + * A JDBC URL. If the url annotation element contains a + * DataSource property that was also specified using the corresponding + * annotation element, the precedence order is undefined and + * implementation specific. + * @since 1.1 + */ + String url() default ""; + + /** + * User name to use for connection authentication. + * @since 1.1 + */ + String user() default ""; + + /** + * Password to use for connection authentication. + * @since 1.1 + */ + String password() default ""; + + /** + * Name of a database on a server. + * @since 1.1 + */ + String databaseName() default ""; + + /** + * Port number where a server is listening for requests. + * @since 1.1 + */ + int portNumber() default -1; + + /** + * Database server name. + * @since 1.1 + */ + String serverName() default "localhost"; + + /** + * Isolation level for connections. The Isolation level + * must be one of the following: + *

+ *

    + *
  • Connection.TRANSACTION_NONE, + *
  • Connection.TRANSACTION_READ_ UNCOMMITTED, + *
  • Connection.TRANSACTION_READ_COMMITTED, + *
  • Connection.TRANSACTION_REPEATABLE_READ, + *
  • Connection.TRANSACTION_SERIALIZABLE + *
+ *

+ * Default is vendor-specific. + * @since 1.1 + */ + int isolationLevel() default -1; + + /** + * Set to false if connections should not participate + * in transactions. + *

+ * Default is to enlist in a transaction when one is active or becomes + * active. + * @since 1.1 + */ + boolean transactional() default true; + + /** + * Number of connections that should be created when a connection pool + * is initialized. + *

+ * Default is vendor-specific + * @since 1.1 + */ + int initialPoolSize() default -1; + + /** + * Maximum number of connections that should be concurrently allocated for a + * connection pool. + *

+ * Default is vendor-specific. + * @since 1.1 + */ + int maxPoolSize() default -1; + + /** + * Minimum number of connections that should be allocated for a + * connection pool. + *

+ * Default is vendor-specific. + * @since 1.1 + */ + int minPoolSize() default -1; + + /** + * The number of seconds that a physical connection + * should remain unused in the pool before the + * connection is closed for a connection pool. + *

+ * Default is vendor-specific + * @since 1.1 + */ + int maxIdleTime() default -1; + + /** + * The total number of statements that a connection pool should keep open. + * A value of 0 indicates that the caching of statements is disabled for + * a connection pool. + *

+ * Default is vendor-specific + * @since 1.1 + */ + int maxStatements() default -1; + /** + * Used to specify vendor-specific properties and less commonly + * used DataSource properties such as: + *

+ *

    + *
  • dataSourceName + *
  • networkProtocol + *
  • propertyCycle + *
  • roleName + *
+ *

+ * Properties are specified using the format: + * propertyName=propertyValue with one property per array element. + *

+ * If a DataSource property is specified in the properties + * element and the annotation element for the property is also + * specified, the annotation element value takes precedence. + * @since 1.1 + */ + String[] properties() default {}; + + + /** + * Sets the maximum time in seconds that this data source will wait while + * attempting to connect to a database. A value of zero specifies that + * the timeout is the default system timeout if there is one; otherwise, + * it specifies that there is no timeout. + *

+ * Default is vendor-specific. + * @since 1.1 + */ + int loginTimeout() default 0; +} diff --git a/fine-third-jdk11/src/javax/annotation/sql/DataSourceDefinitions.java b/fine-third-jdk11/src/javax/annotation/sql/DataSourceDefinitions.java new file mode 100644 index 000000000..fbd9d9ae7 --- /dev/null +++ b/fine-third-jdk11/src/javax/annotation/sql/DataSourceDefinitions.java @@ -0,0 +1,59 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2009-2018 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.annotation.sql; + +import java.lang.annotation.Target; +import java.lang.annotation.Retention; +import java.lang.annotation.ElementType; +import java.lang.annotation.RetentionPolicy; + +/** + * Declares one or more DataSourceDefinition annotations. + * + * @see javax.annotation.sql.DataSourceDefinition + * @since Common Annotations 1.1 + */ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +public @interface DataSourceDefinitions { + DataSourceDefinition[] value (); + +} diff --git a/fine-ehcache/src/javax/jms/BytesMessage.java b/fine-third-jdk11/src/javax/jms/BytesMessage.java similarity index 100% rename from fine-ehcache/src/javax/jms/BytesMessage.java rename to fine-third-jdk11/src/javax/jms/BytesMessage.java diff --git a/fine-ehcache/src/javax/jms/Connection.java b/fine-third-jdk11/src/javax/jms/Connection.java similarity index 100% rename from fine-ehcache/src/javax/jms/Connection.java rename to fine-third-jdk11/src/javax/jms/Connection.java diff --git a/fine-ehcache/src/javax/jms/ConnectionConsumer.java b/fine-third-jdk11/src/javax/jms/ConnectionConsumer.java similarity index 100% rename from fine-ehcache/src/javax/jms/ConnectionConsumer.java rename to fine-third-jdk11/src/javax/jms/ConnectionConsumer.java diff --git a/fine-ehcache/src/javax/jms/ConnectionFactory.java b/fine-third-jdk11/src/javax/jms/ConnectionFactory.java similarity index 100% rename from fine-ehcache/src/javax/jms/ConnectionFactory.java rename to fine-third-jdk11/src/javax/jms/ConnectionFactory.java diff --git a/fine-ehcache/src/javax/jms/ConnectionMetaData.java b/fine-third-jdk11/src/javax/jms/ConnectionMetaData.java similarity index 100% rename from fine-ehcache/src/javax/jms/ConnectionMetaData.java rename to fine-third-jdk11/src/javax/jms/ConnectionMetaData.java diff --git a/fine-ehcache/src/javax/jms/DeliveryMode.java b/fine-third-jdk11/src/javax/jms/DeliveryMode.java similarity index 100% rename from fine-ehcache/src/javax/jms/DeliveryMode.java rename to fine-third-jdk11/src/javax/jms/DeliveryMode.java diff --git a/fine-ehcache/src/javax/jms/Destination.java b/fine-third-jdk11/src/javax/jms/Destination.java similarity index 100% rename from fine-ehcache/src/javax/jms/Destination.java rename to fine-third-jdk11/src/javax/jms/Destination.java diff --git a/fine-ehcache/src/javax/jms/ExceptionListener.java b/fine-third-jdk11/src/javax/jms/ExceptionListener.java similarity index 100% rename from fine-ehcache/src/javax/jms/ExceptionListener.java rename to fine-third-jdk11/src/javax/jms/ExceptionListener.java diff --git a/fine-ehcache/src/javax/jms/IllegalStateException.java b/fine-third-jdk11/src/javax/jms/IllegalStateException.java similarity index 100% rename from fine-ehcache/src/javax/jms/IllegalStateException.java rename to fine-third-jdk11/src/javax/jms/IllegalStateException.java diff --git a/fine-ehcache/src/javax/jms/InvalidClientIDException.java b/fine-third-jdk11/src/javax/jms/InvalidClientIDException.java similarity index 100% rename from fine-ehcache/src/javax/jms/InvalidClientIDException.java rename to fine-third-jdk11/src/javax/jms/InvalidClientIDException.java diff --git a/fine-ehcache/src/javax/jms/InvalidDestinationException.java b/fine-third-jdk11/src/javax/jms/InvalidDestinationException.java similarity index 100% rename from fine-ehcache/src/javax/jms/InvalidDestinationException.java rename to fine-third-jdk11/src/javax/jms/InvalidDestinationException.java diff --git a/fine-ehcache/src/javax/jms/InvalidSelectorException.java b/fine-third-jdk11/src/javax/jms/InvalidSelectorException.java similarity index 100% rename from fine-ehcache/src/javax/jms/InvalidSelectorException.java rename to fine-third-jdk11/src/javax/jms/InvalidSelectorException.java diff --git a/fine-ehcache/src/javax/jms/JMSException.java b/fine-third-jdk11/src/javax/jms/JMSException.java similarity index 100% rename from fine-ehcache/src/javax/jms/JMSException.java rename to fine-third-jdk11/src/javax/jms/JMSException.java diff --git a/fine-ehcache/src/javax/jms/JMSSecurityException.java b/fine-third-jdk11/src/javax/jms/JMSSecurityException.java similarity index 100% rename from fine-ehcache/src/javax/jms/JMSSecurityException.java rename to fine-third-jdk11/src/javax/jms/JMSSecurityException.java diff --git a/fine-ehcache/src/javax/jms/MapMessage.java b/fine-third-jdk11/src/javax/jms/MapMessage.java similarity index 100% rename from fine-ehcache/src/javax/jms/MapMessage.java rename to fine-third-jdk11/src/javax/jms/MapMessage.java diff --git a/fine-ehcache/src/javax/jms/Message.java b/fine-third-jdk11/src/javax/jms/Message.java similarity index 100% rename from fine-ehcache/src/javax/jms/Message.java rename to fine-third-jdk11/src/javax/jms/Message.java diff --git a/fine-ehcache/src/javax/jms/MessageConsumer.java b/fine-third-jdk11/src/javax/jms/MessageConsumer.java similarity index 100% rename from fine-ehcache/src/javax/jms/MessageConsumer.java rename to fine-third-jdk11/src/javax/jms/MessageConsumer.java diff --git a/fine-ehcache/src/javax/jms/MessageEOFException.java b/fine-third-jdk11/src/javax/jms/MessageEOFException.java similarity index 100% rename from fine-ehcache/src/javax/jms/MessageEOFException.java rename to fine-third-jdk11/src/javax/jms/MessageEOFException.java diff --git a/fine-ehcache/src/javax/jms/MessageFormatException.java b/fine-third-jdk11/src/javax/jms/MessageFormatException.java similarity index 100% rename from fine-ehcache/src/javax/jms/MessageFormatException.java rename to fine-third-jdk11/src/javax/jms/MessageFormatException.java diff --git a/fine-ehcache/src/javax/jms/MessageListener.java b/fine-third-jdk11/src/javax/jms/MessageListener.java similarity index 100% rename from fine-ehcache/src/javax/jms/MessageListener.java rename to fine-third-jdk11/src/javax/jms/MessageListener.java diff --git a/fine-ehcache/src/javax/jms/MessageNotReadableException.java b/fine-third-jdk11/src/javax/jms/MessageNotReadableException.java similarity index 100% rename from fine-ehcache/src/javax/jms/MessageNotReadableException.java rename to fine-third-jdk11/src/javax/jms/MessageNotReadableException.java diff --git a/fine-ehcache/src/javax/jms/MessageNotWriteableException.java b/fine-third-jdk11/src/javax/jms/MessageNotWriteableException.java similarity index 100% rename from fine-ehcache/src/javax/jms/MessageNotWriteableException.java rename to fine-third-jdk11/src/javax/jms/MessageNotWriteableException.java diff --git a/fine-ehcache/src/javax/jms/MessageProducer.java b/fine-third-jdk11/src/javax/jms/MessageProducer.java similarity index 100% rename from fine-ehcache/src/javax/jms/MessageProducer.java rename to fine-third-jdk11/src/javax/jms/MessageProducer.java diff --git a/fine-ehcache/src/javax/jms/ObjectMessage.java b/fine-third-jdk11/src/javax/jms/ObjectMessage.java similarity index 100% rename from fine-ehcache/src/javax/jms/ObjectMessage.java rename to fine-third-jdk11/src/javax/jms/ObjectMessage.java diff --git a/fine-ehcache/src/javax/jms/Queue.java b/fine-third-jdk11/src/javax/jms/Queue.java similarity index 100% rename from fine-ehcache/src/javax/jms/Queue.java rename to fine-third-jdk11/src/javax/jms/Queue.java diff --git a/fine-ehcache/src/javax/jms/QueueBrowser.java b/fine-third-jdk11/src/javax/jms/QueueBrowser.java similarity index 100% rename from fine-ehcache/src/javax/jms/QueueBrowser.java rename to fine-third-jdk11/src/javax/jms/QueueBrowser.java diff --git a/fine-ehcache/src/javax/jms/QueueConnection.java b/fine-third-jdk11/src/javax/jms/QueueConnection.java similarity index 100% rename from fine-ehcache/src/javax/jms/QueueConnection.java rename to fine-third-jdk11/src/javax/jms/QueueConnection.java diff --git a/fine-ehcache/src/javax/jms/QueueConnectionFactory.java b/fine-third-jdk11/src/javax/jms/QueueConnectionFactory.java similarity index 100% rename from fine-ehcache/src/javax/jms/QueueConnectionFactory.java rename to fine-third-jdk11/src/javax/jms/QueueConnectionFactory.java diff --git a/fine-ehcache/src/javax/jms/QueueReceiver.java b/fine-third-jdk11/src/javax/jms/QueueReceiver.java similarity index 100% rename from fine-ehcache/src/javax/jms/QueueReceiver.java rename to fine-third-jdk11/src/javax/jms/QueueReceiver.java diff --git a/fine-ehcache/src/javax/jms/QueueRequestor.java b/fine-third-jdk11/src/javax/jms/QueueRequestor.java similarity index 100% rename from fine-ehcache/src/javax/jms/QueueRequestor.java rename to fine-third-jdk11/src/javax/jms/QueueRequestor.java diff --git a/fine-ehcache/src/javax/jms/QueueSender.java b/fine-third-jdk11/src/javax/jms/QueueSender.java similarity index 100% rename from fine-ehcache/src/javax/jms/QueueSender.java rename to fine-third-jdk11/src/javax/jms/QueueSender.java diff --git a/fine-ehcache/src/javax/jms/QueueSession.java b/fine-third-jdk11/src/javax/jms/QueueSession.java similarity index 100% rename from fine-ehcache/src/javax/jms/QueueSession.java rename to fine-third-jdk11/src/javax/jms/QueueSession.java diff --git a/fine-ehcache/src/javax/jms/ResourceAllocationException.java b/fine-third-jdk11/src/javax/jms/ResourceAllocationException.java similarity index 100% rename from fine-ehcache/src/javax/jms/ResourceAllocationException.java rename to fine-third-jdk11/src/javax/jms/ResourceAllocationException.java diff --git a/fine-ehcache/src/javax/jms/ServerSession.java b/fine-third-jdk11/src/javax/jms/ServerSession.java similarity index 100% rename from fine-ehcache/src/javax/jms/ServerSession.java rename to fine-third-jdk11/src/javax/jms/ServerSession.java diff --git a/fine-ehcache/src/javax/jms/ServerSessionPool.java b/fine-third-jdk11/src/javax/jms/ServerSessionPool.java similarity index 100% rename from fine-ehcache/src/javax/jms/ServerSessionPool.java rename to fine-third-jdk11/src/javax/jms/ServerSessionPool.java diff --git a/fine-ehcache/src/javax/jms/Session.java b/fine-third-jdk11/src/javax/jms/Session.java similarity index 100% rename from fine-ehcache/src/javax/jms/Session.java rename to fine-third-jdk11/src/javax/jms/Session.java diff --git a/fine-ehcache/src/javax/jms/StreamMessage.java b/fine-third-jdk11/src/javax/jms/StreamMessage.java similarity index 100% rename from fine-ehcache/src/javax/jms/StreamMessage.java rename to fine-third-jdk11/src/javax/jms/StreamMessage.java diff --git a/fine-ehcache/src/javax/jms/TemporaryQueue.java b/fine-third-jdk11/src/javax/jms/TemporaryQueue.java similarity index 100% rename from fine-ehcache/src/javax/jms/TemporaryQueue.java rename to fine-third-jdk11/src/javax/jms/TemporaryQueue.java diff --git a/fine-ehcache/src/javax/jms/TemporaryTopic.java b/fine-third-jdk11/src/javax/jms/TemporaryTopic.java similarity index 100% rename from fine-ehcache/src/javax/jms/TemporaryTopic.java rename to fine-third-jdk11/src/javax/jms/TemporaryTopic.java diff --git a/fine-ehcache/src/javax/jms/TextMessage.java b/fine-third-jdk11/src/javax/jms/TextMessage.java similarity index 100% rename from fine-ehcache/src/javax/jms/TextMessage.java rename to fine-third-jdk11/src/javax/jms/TextMessage.java diff --git a/fine-ehcache/src/javax/jms/Topic.java b/fine-third-jdk11/src/javax/jms/Topic.java similarity index 100% rename from fine-ehcache/src/javax/jms/Topic.java rename to fine-third-jdk11/src/javax/jms/Topic.java diff --git a/fine-ehcache/src/javax/jms/TopicConnection.java b/fine-third-jdk11/src/javax/jms/TopicConnection.java similarity index 100% rename from fine-ehcache/src/javax/jms/TopicConnection.java rename to fine-third-jdk11/src/javax/jms/TopicConnection.java diff --git a/fine-ehcache/src/javax/jms/TopicConnectionFactory.java b/fine-third-jdk11/src/javax/jms/TopicConnectionFactory.java similarity index 100% rename from fine-ehcache/src/javax/jms/TopicConnectionFactory.java rename to fine-third-jdk11/src/javax/jms/TopicConnectionFactory.java diff --git a/fine-ehcache/src/javax/jms/TopicPublisher.java b/fine-third-jdk11/src/javax/jms/TopicPublisher.java similarity index 100% rename from fine-ehcache/src/javax/jms/TopicPublisher.java rename to fine-third-jdk11/src/javax/jms/TopicPublisher.java diff --git a/fine-ehcache/src/javax/jms/TopicRequestor.java b/fine-third-jdk11/src/javax/jms/TopicRequestor.java similarity index 100% rename from fine-ehcache/src/javax/jms/TopicRequestor.java rename to fine-third-jdk11/src/javax/jms/TopicRequestor.java diff --git a/fine-ehcache/src/javax/jms/TopicSession.java b/fine-third-jdk11/src/javax/jms/TopicSession.java similarity index 100% rename from fine-ehcache/src/javax/jms/TopicSession.java rename to fine-third-jdk11/src/javax/jms/TopicSession.java diff --git a/fine-ehcache/src/javax/jms/TopicSubscriber.java b/fine-third-jdk11/src/javax/jms/TopicSubscriber.java similarity index 100% rename from fine-ehcache/src/javax/jms/TopicSubscriber.java rename to fine-third-jdk11/src/javax/jms/TopicSubscriber.java diff --git a/fine-ehcache/src/javax/jms/TransactionInProgressException.java b/fine-third-jdk11/src/javax/jms/TransactionInProgressException.java similarity index 100% rename from fine-ehcache/src/javax/jms/TransactionInProgressException.java rename to fine-third-jdk11/src/javax/jms/TransactionInProgressException.java diff --git a/fine-ehcache/src/javax/jms/TransactionRolledBackException.java b/fine-third-jdk11/src/javax/jms/TransactionRolledBackException.java similarity index 100% rename from fine-ehcache/src/javax/jms/TransactionRolledBackException.java rename to fine-third-jdk11/src/javax/jms/TransactionRolledBackException.java diff --git a/fine-ehcache/src/javax/jms/XAConnection.java b/fine-third-jdk11/src/javax/jms/XAConnection.java similarity index 100% rename from fine-ehcache/src/javax/jms/XAConnection.java rename to fine-third-jdk11/src/javax/jms/XAConnection.java diff --git a/fine-ehcache/src/javax/jms/XAConnectionFactory.java b/fine-third-jdk11/src/javax/jms/XAConnectionFactory.java similarity index 100% rename from fine-ehcache/src/javax/jms/XAConnectionFactory.java rename to fine-third-jdk11/src/javax/jms/XAConnectionFactory.java diff --git a/fine-ehcache/src/javax/jms/XAQueueConnection.java b/fine-third-jdk11/src/javax/jms/XAQueueConnection.java similarity index 100% rename from fine-ehcache/src/javax/jms/XAQueueConnection.java rename to fine-third-jdk11/src/javax/jms/XAQueueConnection.java diff --git a/fine-ehcache/src/javax/jms/XAQueueConnectionFactory.java b/fine-third-jdk11/src/javax/jms/XAQueueConnectionFactory.java similarity index 100% rename from fine-ehcache/src/javax/jms/XAQueueConnectionFactory.java rename to fine-third-jdk11/src/javax/jms/XAQueueConnectionFactory.java diff --git a/fine-ehcache/src/javax/jms/XAQueueSession.java b/fine-third-jdk11/src/javax/jms/XAQueueSession.java similarity index 100% rename from fine-ehcache/src/javax/jms/XAQueueSession.java rename to fine-third-jdk11/src/javax/jms/XAQueueSession.java diff --git a/fine-ehcache/src/javax/jms/XASession.java b/fine-third-jdk11/src/javax/jms/XASession.java similarity index 100% rename from fine-ehcache/src/javax/jms/XASession.java rename to fine-third-jdk11/src/javax/jms/XASession.java diff --git a/fine-ehcache/src/javax/jms/XATopicConnection.java b/fine-third-jdk11/src/javax/jms/XATopicConnection.java similarity index 100% rename from fine-ehcache/src/javax/jms/XATopicConnection.java rename to fine-third-jdk11/src/javax/jms/XATopicConnection.java diff --git a/fine-ehcache/src/javax/jms/XATopicConnectionFactory.java b/fine-third-jdk11/src/javax/jms/XATopicConnectionFactory.java similarity index 100% rename from fine-ehcache/src/javax/jms/XATopicConnectionFactory.java rename to fine-third-jdk11/src/javax/jms/XATopicConnectionFactory.java diff --git a/fine-ehcache/src/javax/jms/XATopicSession.java b/fine-third-jdk11/src/javax/jms/XATopicSession.java similarity index 100% rename from fine-ehcache/src/javax/jms/XATopicSession.java rename to fine-third-jdk11/src/javax/jms/XATopicSession.java diff --git a/fine-third-jdk11/src/javax/jws/HandlerChain.java b/fine-third-jdk11/src/javax/jws/HandlerChain.java new file mode 100644 index 000000000..f90462d64 --- /dev/null +++ b/fine-third-jdk11/src/javax/jws/HandlerChain.java @@ -0,0 +1,41 @@ +package javax.jws; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; + +/** + * Associates the Web Service with an externally defined handler chain. This annotation is typically used in scenarios + * where embedding the handler configuration directly in the Java source is not appropriate; for example, where the + * handler configuration needs to be shared across multiple Web Services, or where the handler chain consists of + * handlers for multiple transports. + * + * It is an error to combine this annotation with the @SOAPMessageHandlers annotation. + * + * @author Copyright (c) 2004 by BEA Systems, Inc. All Rights Reserved. + * + * @since 1.6 + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = {ElementType.TYPE, ElementType.METHOD, ElementType.FIELD}) +public @interface HandlerChain { + + /** + * Location of the handler chain file. + *

+ * The location supports 2 formats: + *

    + *
  1. An absolute java.net.URL in externalForm (ex: http://myhandlers.foo.com/handlerfile1.xml). + *
  2. A relative path from the source file or class file (ex: bar/handlerfile1.xml). + *
+ */ + String file(); + + /** + * Name of the handler chain in the configuration file + * + * @deprecated As of JSR-181 2.0 with no replacement. + */ + @Deprecated String name() default ""; +}; diff --git a/fine-third-jdk11/src/javax/jws/Oneway.java b/fine-third-jdk11/src/javax/jws/Oneway.java new file mode 100644 index 000000000..7ff38d323 --- /dev/null +++ b/fine-third-jdk11/src/javax/jws/Oneway.java @@ -0,0 +1,21 @@ +package javax.jws; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; + +/** + * Indicates that the given @WebMethod has only an input message and no output. Typically, a oneway method returns + * the thread of control to the calling application prior to executing the actual business method. A 181 processor + * should report an error if an operation marked @Oneway has a return value or Holder parameters, or declares any + * checked exceptions. + * + * @author Copyright (c) 2004 by BEA Systems, Inc. All Rights Reserved. + * + * @since 1.6 + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = {ElementType.METHOD}) +public @interface Oneway { +} diff --git a/fine-third-jdk11/src/javax/jws/WebMethod.java b/fine-third-jdk11/src/javax/jws/WebMethod.java new file mode 100644 index 000000000..92813b5a2 --- /dev/null +++ b/fine-third-jdk11/src/javax/jws/WebMethod.java @@ -0,0 +1,48 @@ +package javax.jws; + +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * Customizes a method that is exposed as a Web Service operation. + * The associated method must be public and its parameters return value, + * and exceptions must follow the rules defined in JAX-RPC 1.1, section 5. + * + * The method is not required to throw java.rmi.RemoteException. + * + * @author Copyright (c) 2004 by BEA Systems, Inc. All Rights Reserved. + * + * @since 1.6 + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD}) +public @interface WebMethod { + + /** + * Name of the wsdl:operation matching this method. + * + * @specdefault Name of the Java method. + */ + String operationName() default ""; + + /** + * The action for this operation. + *

+ * For SOAP bindings, this determines the value of the soap action. + */ + String action() default ""; + + /** + * Marks a method to NOT be exposed as a web method. + *

+ * Used to stop an inherited method from being exposed as part of this web service. + * If this element is specified, other elements MUST NOT be specified for the @WebMethod. + *

+ * This member-value is not allowed on endpoint interfaces. + * + * @since 2.0 + */ + boolean exclude() default false; +}; diff --git a/fine-third-jdk11/src/javax/jws/WebParam.java b/fine-third-jdk11/src/javax/jws/WebParam.java new file mode 100644 index 000000000..46dd4eceb --- /dev/null +++ b/fine-third-jdk11/src/javax/jws/WebParam.java @@ -0,0 +1,87 @@ +package javax.jws; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; + +/** + * Customizes the mapping of an individual parameter to a Web Service message part and XML element. + * + * @author Copyright (c) 2004 by BEA Systems, Inc. All Rights Reserved. + * + * @since 1.6 + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = {ElementType.PARAMETER}) +public @interface WebParam { + + /** + * The direction in which the parameter flows + */ + public enum Mode { + IN, + OUT, + INOUT + }; + + /** + * Name of the parameter. + *

+ * If the operation is rpc style and @WebParam.partName has not been specified, this is name of the wsdl:part + * representing the parameter. + *
+ * If the operation is document style or the parameter maps to a header, this is the local name of the XML element + * representing the parameter. + *

+ * A name MUST be specified if the operation is document style, the parameter style is BARE, and the mode is OUT + * or INOUT. + * + * @specdefault + * If the operation is document style and the parameter style is BARE, {@code @WebMethod.operationName}.
+ * Otherwise, argN, where N represents the index of the parameter in the method signature (starting at arg0). + */ + String name() default ""; + + /** + * The name of the wsdl:part representing this parameter. + *

+ * This is only used if the operation is rpc style or if the operation is document style and the parameter style + * is BARE. + * + * @specdefault {@code @WebParam.name} + * + * @since 2.0 + */ + String partName() default ""; + + /** + * The XML namespace for the parameter. + *

+ * Only used if the operation is document style or the paramater maps to a header. + * If the target namespace is set to "", this represents the empty namespace. + * + * @specdefault + * If the operation is document style, the parameter style is WRAPPED, and the parameter does not map to a + * header, the empty namespace.
+ * Otherwise, the targetNamespace for the Web Service. + */ + String targetNamespace() default ""; + + /** + * The direction in which the parameter is flowing (One of IN, OUT, or INOUT). + *

+ * The OUT and INOUT modes may only be specified for parameter types that conform to the definition of Holder types + * (JAX-WS 2.0 [5], section 2.3.3). Parameters that are Holder Types MUST be OUT or INOUT. + * + * @specdefault + * INOUT if a Holder type.
+ * IN if not a Holder type. + */ + Mode mode() default Mode.IN; + + /** + * If true, the parameter is pulled from a message header rather then the message body. + */ + boolean header() default false; +}; diff --git a/fine-third-jdk11/src/javax/jws/WebResult.java b/fine-third-jdk11/src/javax/jws/WebResult.java new file mode 100644 index 000000000..b8735dbd2 --- /dev/null +++ b/fine-third-jdk11/src/javax/jws/WebResult.java @@ -0,0 +1,66 @@ +package javax.jws; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; + +/** + * Customizes the mapping of the return value to a WSDL part and XML element. + * + * @author Copyright (c) 2004 by BEA Systems, Inc. All Rights Reserved. + * + * @since 1.6 + */ +@Retention(value = RetentionPolicy.RUNTIME) + @Target(value = {ElementType.METHOD}) + public @interface WebResult +{ + + /** + * Name of return value. + *

+ * If the operation is rpc style and @WebResult.partName has not been specified, this is the name of the wsdl:part + * representing the return value. + *
+ * If the operation is document style or the return value maps to a header, this is the local name of the XML + * element representing the return value. + * + * @specdefault + * If the operation is document style and the parameter style is BARE, {@code @WebParam.operationName}+"Response".
+ * Otherwise, "return." + */ + String name() default ""; + + /** + * The name of the wsdl:part representing this return value. + *

+ * This is only used if the operation is rpc style, or if the operation is document style and the parameter style + * is BARE. + * + * @specdefault {@code @WebResult.name} + * + * @since 2.0 + */ + String partName() default ""; + + /** + * The XML namespace for the return value. + *

+ * Only used if the operation is document style or the return value maps to a header. + * If the target namespace is set to ��, this represents the empty namespace. + * + * @specdefault + * If the operation is document style, the parameter style is WRAPPED, and the return value does not map to a + * header, the empty namespace.
+ * Otherwise, the targetNamespace for the Web Service. + */ + String targetNamespace() default ""; + + /** + * If true, the result is pulled from a message header rather then the message body. + * + * @since 2.0 + */ + boolean header() default false; +} diff --git a/fine-third-jdk11/src/javax/jws/WebService.java b/fine-third-jdk11/src/javax/jws/WebService.java new file mode 100644 index 000000000..ac49a07c5 --- /dev/null +++ b/fine-third-jdk11/src/javax/jws/WebService.java @@ -0,0 +1,97 @@ +package javax.jws; + +import java.lang.annotation.Target; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.ElementType; + +/** + * Marks a Java class as implementing a Web Service, or a Java interface as defining a Web Service interface. + * + * @author Copyright (c) 2004 by BEA Systems, Inc. All Rights Reserved. + * + * @since 1.6 + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = {ElementType.TYPE}) +public @interface WebService { + + /** + * The name of the Web Service. + *

+ * Used as the name of the wsdl:portType when mapped to WSDL 1.1. + * + * @specdefault The simple name of the Java class or interface. + */ + String name() default ""; + + /** + * If the @WebService.targetNamespace annotation is on a service endpoint interface, the targetNamespace is used + * for the namespace for the wsdl:portType (and associated XML elements). + *

+ * If the @WebService.targetNamespace annotation is on a service implementation bean that does NOT reference a + * service endpoint interface (through the endpointInterface attribute), the targetNamespace is used for both the + * wsdl:portType and the wsdl:service (and associated XML elements). + *

+ * If the @WebService.targetNamespace annotation is on a service implementation bean that does reference a service + * endpoint interface (through the endpointInterface attribute), the targetNamespace is used for only the + * wsdl:service (and associated XML elements). + * + * @specdefault Implementation-defined, as described in JAX-WS 2.0 [5], section 3.2. + */ + String targetNamespace() default ""; + + /** + * The service name of the Web Service. + *

+ * Used as the name of the wsdl:service when mapped to WSDL 1.1. + *

+ * This member-value is not allowed on endpoint interfaces. + * + * @specdefault The simple name of the Java class + Service". + */ + String serviceName() default ""; + + /** + * The port name of the Web Service. + *

+ * Used as the name of the wsdl:port when mapped to WSDL 1.1. + *

+ * This member-value is not allowed on endpoint interfaces. + * + * @specdefault {@code @WebService.name}+Port. + * + * @since 2.0 + */ + String portName() default ""; + + /** + * The location of a pre-defined WSDL describing the service. + *

+ * The wsdlLocation is a URL (relative or absolute) that refers to a pre-existing WSDL file. The presence of a + * wsdlLocation value indicates that the service implementation bean is implementing a pre-defined WSDL contract. + * The JSR-181 tool MUST provide feedback if the service implementation bean is inconsistent with the portType and + * bindings declared in this WSDL. Note that a single WSDL file might contain multiple portTypes and multiple + * bindings. The annotations on the service implementation bean determine the specific portType and bindings that + * correspond to the Web Service. + */ + String wsdlLocation() default ""; + + /** + * The complete name of the service endpoint interface defining the service�s abstract Web Service contract. + *

+ * This annotation allows the developer to separate the interface contract from the implementation. If this + * annotation is present, the service endpoint interface is used to determine the abstract WSDL contract (portType + * and bindings). The service endpoint interface MAY include JSR-181 annotations to customize the mapping from + * Java to WSDL. + *
+ * The service implementation bean MAY implement the service endpoint interface, but is not REQUIRED to do so. + *
+ * If this member-value is not present, the Web Service contract is generated from annotations on the service + * implementation bean. If a service endpoint interface is required by the target environment, it will be + * generated into an implementation-defined package with an implementation- defined name + *

+ * This member-value is not allowed on endpoint interfaces. + */ + String endpointInterface() default ""; +}; diff --git a/fine-third-jdk11/src/javax/jws/javaee_web_services_metadata_handler_2_0.xsd b/fine-third-jdk11/src/javax/jws/javaee_web_services_metadata_handler_2_0.xsd new file mode 100644 index 000000000..1ec629906 --- /dev/null +++ b/fine-third-jdk11/src/javax/jws/javaee_web_services_metadata_handler_2_0.xsd @@ -0,0 +1,77 @@ + + + + + + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + + Copyright (c) 2007-2017 Oracle and/or its affiliates. All rights reserved. + + The contents of this file are subject to the terms of either the GNU + General Public License Version 2 only ("GPL") or the Common Development + and Distribution License("CDDL") (collectively, the "License"). You + may not use this file except in compliance with the License. You can + obtain a copy of the License at + https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html + or packager/legal/LICENSE.txt. See the License for the specific + language governing permissions and limitations under the License. + + When distributing the software, include this License Header Notice in each + file and include the License file at packager/legal/LICENSE.txt. + + GPL Classpath Exception: + Oracle designates this particular file as subject to the "Classpath" + exception as provided by Oracle in the GPL Version 2 section of the License + file that accompanied this code. + + Modifications: + If applicable, add the following below the License Header, with the fields + enclosed by brackets [] replaced by your own identifying information: + "Portions Copyright [year] [name of copyright owner]" + + Contributor(s): + If you wish your version of this file to be governed by only the CDDL or + only the GPL Version 2, indicate your decision by adding "[Contributor] + elects to include this software in this distribution under the [CDDL or GPL + Version 2] license." If you don't indicate a single choice of license, a + recipient has the option to distribute your version of this file under + either the CDDL, the GPL Version 2 or to extend the choice of license to + its licensees as provided above. However, if you add GPL Version 2 code + and therefore, elected the GPL Version 2 license, then the option applies + only if the new code is made subject to such option by the copyright + holder. + + + + + + + javaee_web_services_metadata_handler.xsd v2.0.1 11/09/2007 + + + + + + + + + + The handler-chains element is the root element for defining + handlerchains. + + The Web Services Metadata for the Java Platform (JSR-181), Version 2.0 + specification defines the @javax.jws.HandlerChain annotation + that refers to an XML descriptor conforming to this schema. + + + + + + diff --git a/fine-third-jdk11/src/javax/jws/package.html b/fine-third-jdk11/src/javax/jws/package.html new file mode 100644 index 000000000..e54857e1f --- /dev/null +++ b/fine-third-jdk11/src/javax/jws/package.html @@ -0,0 +1,52 @@ + + + + + + + + +This package defines annotations for light-weight web services programming model. + + + diff --git a/fine-third-jdk11/src/javax/jws/soap/InitParam.java b/fine-third-jdk11/src/javax/jws/soap/InitParam.java new file mode 100644 index 000000000..7a93d2582 --- /dev/null +++ b/fine-third-jdk11/src/javax/jws/soap/InitParam.java @@ -0,0 +1,24 @@ +package javax.jws.soap; + +/** + * An initialization parameter + * + * @deprecated As of JSR-181 2.0 with no replacement. + * + * @author Copyright (c) 2004 by BEA Systems, Inc. All Rights Reserved. + * + * @since 1.6 + */ +@Deprecated public @interface InitParam { + + /** + * Name of the initialization parameter + */ + String name(); + + /** + * Value of the initialization parameter + */ + String value(); +}; + diff --git a/fine-third-jdk11/src/javax/jws/soap/SOAPBinding.java b/fine-third-jdk11/src/javax/jws/soap/SOAPBinding.java new file mode 100644 index 000000000..31298a45a --- /dev/null +++ b/fine-third-jdk11/src/javax/jws/soap/SOAPBinding.java @@ -0,0 +1,58 @@ +package javax.jws.soap; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; + +/** + * Specifies the mapping of the Web Service onto the SOAP message protocol. + * + * @author Copyright (c) 2004 by BEA Systems, Inc. All Rights Reserved. + * + * @since 1.6, JAX-WS 2.0 + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = {ElementType.TYPE, ElementType.METHOD}) +public @interface SOAPBinding { + + /** + * The SOAP binding style + */ + public enum Style { + DOCUMENT, + RPC + }; + + /** + * The SOAP binding use + */ + public enum Use { + LITERAL, + ENCODED + }; + + /** + * The style of mapping parameters onto SOAP messages + */ + public enum ParameterStyle { + BARE, + WRAPPED + } + + /** + * Defines the encoding style for messages send to and from the Web Service. + */ + Style style() default Style.DOCUMENT; + + /** + * Defines the formatting style for messages sent to and from the Web Service. + */ + Use use() default Use.LITERAL; + + /** + * Determines whether method parameters represent the entire message body, or whether the parameters are elements + * wrapped inside a top-level element named after the operation + */ + ParameterStyle parameterStyle() default ParameterStyle.WRAPPED; +} diff --git a/fine-third-jdk11/src/javax/jws/soap/SOAPMessageHandler.java b/fine-third-jdk11/src/javax/jws/soap/SOAPMessageHandler.java new file mode 100644 index 000000000..b77c85d24 --- /dev/null +++ b/fine-third-jdk11/src/javax/jws/soap/SOAPMessageHandler.java @@ -0,0 +1,42 @@ +package javax.jws.soap; + +/** + * A single SOAP message handler + * + * @deprecated As of JSR-181 2.0 with no replacement. + * + * @author Copyright (c) 2004 by BEA Systems, Inc. All Rights Reserved. + * + * @since 1.6 + */ +@Deprecated public @interface SOAPMessageHandler { + + /** + * Name of the handler. Defaults to the name of the handler class. + */ + String name() default ""; + + /** + * Name of the handler class. + */ + String className(); + + /** + * Array of name/value pairs that should be passed to the handler during initialization. + */ + InitParam[] initParams() default {}; + + /** + * List of SOAP roles/actors implemented by the handler + */ + String[] roles() default {}; + + /** + * List of SOAP headers processed by the handler. Each element in this array contains a QName which defines the + * header element processed by the handler. The QNames are specified using the string notation described in the + * documentation for javax.xml.namespace.QName.valueOf(String qNameAsString) + */ + String[] headers() default {}; +}; + + diff --git a/fine-third-jdk11/src/javax/jws/soap/SOAPMessageHandlers.java b/fine-third-jdk11/src/javax/jws/soap/SOAPMessageHandlers.java new file mode 100644 index 000000000..cee7e2426 --- /dev/null +++ b/fine-third-jdk11/src/javax/jws/soap/SOAPMessageHandlers.java @@ -0,0 +1,26 @@ +package javax.jws.soap; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; + +/** + * Specifies a list of SOAP protocol handlers that run before and after business methods on the Web Service. These + * handlers are called in response to SOAP messages targeting the service. + *

+ * The @SOAPMessageHandlers annotation is an array of SOAPMessageHandler types. The handlers are run in the order in + * which they appear in the annotation, starting with the first handler in the array. + * + * @deprecated As of JSR-181 2.0 with no replacement. + * + * @author Copyright (c) 2004 by BEA Systems, Inc. All Rights Reserved. + * + * @since 1.6 + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = {ElementType.TYPE}) +@Deprecated public @interface SOAPMessageHandlers { + + SOAPMessageHandler[] value(); +}; diff --git a/fine-third-jdk11/src/javax/jws/soap/package.html b/fine-third-jdk11/src/javax/jws/soap/package.html new file mode 100644 index 000000000..4b6c26368 --- /dev/null +++ b/fine-third-jdk11/src/javax/jws/soap/package.html @@ -0,0 +1,52 @@ + + + + + + + + +This packages defines annotations for SOAP binding definition within light-weight web services programming model. + + + diff --git a/fine-third-jdk11/src/javax/xml/bind/Binder.java b/fine-third-jdk11/src/javax/xml/bind/Binder.java new file mode 100644 index 000000000..551fdb655 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/Binder.java @@ -0,0 +1,436 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +import org.w3c.dom.Node; + +import javax.xml.validation.Schema; + +/** + * Enable synchronization between XML infoset nodes and JAXB objects + * representing same XML document. + * + *

+ * An instance of this class maintains the association between XML nodes of + * an infoset preserving view and a JAXB representation of an XML document. + * Navigation between the two views is provided by the methods + * {@link #getXMLNode(Object)} and {@link #getJAXBNode(Object)}. + * + *

+ * Modifications can be made to either the infoset preserving view or the + * JAXB representation of the document while the other view remains + * unmodified. The binder is able to synchronize the changes made in the + * modified view back into the other view using the appropriate + * Binder update methods, {@link #updateXML(Object, Object)} or + * {@link #updateJAXB(Object)}. + * + *

+ * A typical usage scenario is the following: + *

    + *
  • load XML document into an XML infoset representation
  • + *
  • {@link #unmarshal(Object)} XML infoset view to JAXB view. + * (Note to conserve resources, it is possible to only unmarshal a + * subtree of the XML infoset view to the JAXB view.)
  • + *
  • application access/updates JAXB view of XML document.
  • + *
  • {@link #updateXML(Object)} synchronizes modifications to JAXB view + * back into the XML infoset view. Update operation preserves as + * much of original XML infoset as possible (i.e. comments, PI, ...)
  • + *
+ * + *

+ * A Binder instance is created using the factory method + * {@link JAXBContext#createBinder()} or {@link JAXBContext#createBinder(Class)}. + * + *

+ * The template parameter, XmlNode, is the + * root interface/class for the XML infoset preserving representation. + * A Binder implementation is required to minimally support + * an XmlNode value of org.w3c.dom.Node.class. + * A Binder implementation can support alternative XML infoset + * preserving representations. + * + * @author + * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) + * Joseph Fialli + * + * @since 1.6, JAXB 2.0 + */ +public abstract class Binder { + /** + * Unmarshal XML infoset view to a JAXB object tree. + * + *

+ * This method is similar to {@link Unmarshaller#unmarshal(Node)} + * with the addition of maintaining the association between XML nodes + * and the produced JAXB objects, enabling future update operations, + * {@link #updateXML(Object, Object)} or {@link #updateJAXB(Object)}. + * + *

+ * When {@link #getSchema()} is non-null, xmlNode + * and its descendants is validated during this operation. + * + *

+ * This method throws {@link UnmarshalException} when the Binder's + * {@link JAXBContext} does not have a mapping for the XML element name + * or the type, specifiable via {@code @xsi:type}, of {@code xmlNode} + * to a JAXB mapped class. The method {@link #unmarshal(Object, Class)} + * enables an application to specify the JAXB mapped class that + * the {@code xmlNode} should be mapped to. + * + * @param xmlNode + * the document/element to unmarshal XML data from. + * + * @return + * the newly created root object of the JAXB object tree. + * + * @throws JAXBException + * If any unexpected errors occur while unmarshalling + * @throws UnmarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Binder} is unable to perform the XML to Java + * binding. + * @throws IllegalArgumentException + * If the node parameter is null + */ + public abstract Object unmarshal( XmlNode xmlNode ) throws JAXBException; + + /** + * Unmarshal XML root element by provided {@code declaredType} + * to a JAXB object tree. + * + *

+ * Implements Unmarshal by Declared Type + * + *

+ * This method is similar to {@link Unmarshaller#unmarshal(Node, Class)} + * with the addition of maintaining the association between XML nodes + * and the produced JAXB objects, enabling future update operations, + * {@link #updateXML(Object, Object)} or {@link #updateJAXB(Object)}. + * + *

+ * When {@link #getSchema()} is non-null, xmlNode + * and its descendants is validated during this operation. + * + * @param xmlNode + * the document/element to unmarshal XML data from. + * @param declaredType + * appropriate JAXB mapped class to hold {@code node}'s XML data. + * + * @return + * JAXB Element representation + * of {@code node} + * + * @throws JAXBException + * If any unexpected errors occur while unmarshalling + * @throws UnmarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Binder} is unable to perform the XML to Java + * binding. + * @throws IllegalArgumentException + * If any of the input parameters are null + * @since 1.6, JAXB 2.0 + */ + public abstract JAXBElement + unmarshal( XmlNode xmlNode, Class declaredType ) + throws JAXBException; + + /** + * Marshal a JAXB object tree to a new XML document. + * + *

+ * This method is similar to {@link Marshaller#marshal(Object, Node)} + * with the addition of maintaining the association between JAXB objects + * and the produced XML nodes, + * enabling future update operations such as + * {@link #updateXML(Object, Object)} or {@link #updateJAXB(Object)}. + * + *

+ * When {@link #getSchema()} is non-null, the marshalled + * xml content is validated during this operation. + * + * @param jaxbObject + * The content tree to be marshalled. + * @param xmlNode + * The parameter must be a Node that accepts children. + * + * @throws JAXBException + * If any unexpected problem occurs during the marshalling. + * @throws MarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Binder} is unable to marshal {@code jaxbObject} (or any + * object reachable from {@code jaxbObject}). + * + * @throws IllegalArgumentException + * If any of the method parameters are null + */ + public abstract void marshal( Object jaxbObject, XmlNode xmlNode ) throws JAXBException; + + /** + * Gets the XML element associated with the given JAXB object. + * + *

+ * Once a JAXB object tree is associated with an XML fragment, + * this method enables navigation between the two trees. + * + *

+ * An association between an XML element and a JAXB object is + * established by the bind methods and the update methods. + * Note that this association is partial; not all XML elements + * have associated JAXB objects, and not all JAXB objects have + * associated XML elements. + * + * @param jaxbObject An instance that is reachable from a prior + * call to a bind or update method that returned + * a JAXB object tree. + * + * @return + * null if the specified JAXB object is not known to this + * {@link Binder}, or if it is not associated with an + * XML element. + * + * @throws IllegalArgumentException + * If the jaxbObject parameter is null + */ + public abstract XmlNode getXMLNode( Object jaxbObject ); + + /** + * Gets the JAXB object associated with the given XML element. + * + *

+ * Once a JAXB object tree is associated with an XML fragment, + * this method enables navigation between the two trees. + * + *

+ * An association between an XML element and a JAXB object is + * established by the unmarshal, marshal and update methods. + * Note that this association is partial; not all XML elements + * have associated JAXB objects, and not all JAXB objects have + * associated XML elements. + * + * @return + * null if the specified XML node is not known to this + * {@link Binder}, or if it is not associated with a + * JAXB object. + * + * @throws IllegalArgumentException + * If the node parameter is null + */ + public abstract Object getJAXBNode( XmlNode xmlNode ); + + /** + * Takes an JAXB object and updates + * its associated XML node and its descendants. + * + *

+ * This is a convenience method of: + *

+     * updateXML( jaxbObject, getXMLNode(jaxbObject));
+     * 
+ * + * @throws JAXBException + * If any unexpected problem occurs updating corresponding XML content. + * @throws IllegalArgumentException + * If the jaxbObject parameter is null + */ + public abstract XmlNode updateXML( Object jaxbObject ) throws JAXBException; + + /** + * Changes in JAXB object tree are updated in its associated XML parse tree. + * + *

+ * This operation can be thought of as an "in-place" marshalling. + * The difference is that instead of creating a whole new XML tree, + * this operation updates an existing tree while trying to preserve + * the XML as much as possible. + * + *

+ * For example, unknown elements/attributes in XML that were not bound + * to JAXB will be left untouched (whereas a marshalling operation + * would create a new tree that doesn't contain any of those.) + * + *

+ * As a side-effect, this operation updates the association between + * XML nodes and JAXB objects. + * + * @param jaxbObject root of potentially modified JAXB object tree + * @param xmlNode root of update target XML parse tree + * + * @return + * Returns the updated XML node. Typically, this is the same + * node you passed in as xmlNode, but it maybe + * a different object, for example when the tag name of the object + * has changed. + * + * @throws JAXBException + * If any unexpected problem occurs updating corresponding XML content. + * @throws IllegalArgumentException + * If any of the input parameters are null + */ + public abstract XmlNode updateXML( Object jaxbObject, XmlNode xmlNode ) throws JAXBException; + + /** + * Takes an XML node and updates its associated JAXB object and its descendants. + * + *

+ * This operation can be thought of as an "in-place" unmarshalling. + * The difference is that instead of creating a whole new JAXB tree, + * this operation updates an existing tree, reusing as much JAXB objects + * as possible. + * + *

+ * As a side-effect, this operation updates the association between + * XML nodes and JAXB objects. + * + * @return + * Returns the updated JAXB object. Typically, this is the same + * object that was returned from earlier + * {@link #marshal(Object,Object)} or + * {@link #updateJAXB(Object)} method invocation, + * but it maybe + * a different object, for example when the name of the XML + * element has changed. + * + * @throws JAXBException + * If any unexpected problem occurs updating corresponding JAXB mapped content. + * @throws IllegalArgumentException + * If node parameter is null + */ + public abstract Object updateJAXB( XmlNode xmlNode ) throws JAXBException; + + + /** + * Specifies whether marshal, unmarshal and update methods + * performs validation on their XML content. + * + * @param schema set to null to disable validation. + * + * @see Unmarshaller#setSchema(Schema) + */ + public abstract void setSchema( Schema schema ); + + /** + * Gets the last {@link Schema} object (including null) set by the + * {@link #setSchema(Schema)} method. + * + * @return the Schema object for validation or null if not present + */ + public abstract Schema getSchema(); + + /** + * Allow an application to register a {@code ValidationEventHandler}. + *

+ * The {@code ValidationEventHandler} will be called by the JAXB Provider + * if any validation errors are encountered during calls to any of the + * Binder unmarshal, marshal and update methods. + * + *

+ * Calling this method with a null parameter will cause the Binder + * to revert back to the default default event handler. + * + * @param handler the validation event handler + * @throws JAXBException if an error was encountered while setting the + * event handler + */ + public abstract void setEventHandler( ValidationEventHandler handler ) throws JAXBException; + + /** + * Return the current event handler or the default event handler if one + * hasn't been set. + * + * @return the current ValidationEventHandler or the default event handler + * if it hasn't been set + * @throws JAXBException if an error was encountered while getting the + * current event handler + */ + public abstract ValidationEventHandler getEventHandler() throws JAXBException; + + /** + * + * Set the particular property in the underlying implementation of + * {@code Binder}. This method can only be used to set one of + * the standard JAXB defined unmarshal/marshal properties + * or a provider specific property for binder, unmarshal or marshal. + * Attempting to set an undefined property will result in + * a PropertyException being thrown. See + * Supported Unmarshal Properties + * and + * Supported Marshal Properties. + * + * @param name the name of the property to be set. This value can either + * be specified using one of the constant fields or a user + * supplied string. + * @param value the value of the property to be set + * + * @throws PropertyException when there is an error processing the given + * property or value + * @throws IllegalArgumentException + * If the name parameter is null + */ + abstract public void setProperty( String name, Object value ) throws PropertyException; + + + /** + * Get the particular property in the underlying implementation of + * {@code Binder}. This method can only + * be used to get one of + * the standard JAXB defined unmarshal/marshal properties + * or a provider specific property for binder, unmarshal or marshal. + * Attempting to get an undefined property will result in + * a PropertyException being thrown. See + * Supported Unmarshal Properties + * and + * Supported Marshal Properties. + * + * @param name the name of the property to retrieve + * @return the value of the requested property + * + * @throws PropertyException + * when there is an error retrieving the given property or value + * property name + * @throws IllegalArgumentException + * If the name parameter is null + */ + abstract public Object getProperty( String name ) throws PropertyException; + +} diff --git a/fine-third-jdk11/src/javax/xml/bind/ContextFinder.java b/fine-third-jdk11/src/javax/xml/bind/ContextFinder.java new file mode 100644 index 000000000..97769a9cc --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/ContextFinder.java @@ -0,0 +1,672 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2018 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.Map; +import java.util.Properties; +import java.util.StringTokenizer; +import java.util.logging.ConsoleHandler; +import java.util.logging.Level; +import java.util.logging.Logger; + + +/** + * This class is package private and therefore is not exposed as part of the + * JAXB API. + * + * This code is designed to implement the JAXB 1.0 spec pluggability feature + * + * @author

  • Ryan Shoemaker, Sun Microsystems, Inc.
+ * @see JAXBContext + */ +class ContextFinder { + + /** + * When JAXB is in J2SE, rt.jar has to have a JAXB implementation. + * However, rt.jar cannot have META-INF/services/javax.xml.bind.JAXBContext + * because if it has, it will take precedence over any file that applications have + * in their jar files. + * + *

+ * When the user bundles his own JAXB implementation, we'd like to use it, and we + * want the platform default to be used only when there's no other JAXB provider. + * + *

+ * For this reason, we have to hard-code the class name into the API. + */ + private static final String PLATFORM_DEFAULT_FACTORY_CLASS = "com.sun.xml.internal.bind.v2.ContextFactory"; + + // previous value of JAXBContext.JAXB_CONTEXT_FACTORY, using also this to ensure backwards compatibility + private static final String JAXB_CONTEXT_FACTORY_DEPRECATED = "javax.xml.bind.context.factory"; + + private static final Logger logger; + + static { + logger = Logger.getLogger("javax.xml.bind"); + try { + if (AccessController.doPrivileged(new GetPropertyAction("jaxb.debug")) != null) { + // disconnect the logger from a bigger framework (if any) + // and take the matters into our own hands + logger.setUseParentHandlers(false); + logger.setLevel(Level.ALL); + ConsoleHandler handler = new ConsoleHandler(); + handler.setLevel(Level.ALL); + logger.addHandler(handler); + } else { + // don't change the setting of this logger + // to honor what other frameworks + // have done on configurations. + } + } catch (Throwable t) { + // just to be extra safe. in particular System.getProperty may throw + // SecurityException. + } + } + + private static ServiceLoaderUtil.ExceptionHandler EXCEPTION_HANDLER = + new ServiceLoaderUtil.ExceptionHandler() { + @Override + public JAXBException createException(Throwable throwable, String message) { + return new JAXBException(message, throwable); + } + }; + + /** + * If the {@link InvocationTargetException} wraps an exception that shouldn't be wrapped, + * throw the wrapped exception. Otherwise returns exception to be wrapped for further processing. + */ + private static Throwable handleInvocationTargetException(InvocationTargetException x) throws JAXBException { + Throwable t = x.getTargetException(); + if (t != null) { + if (t instanceof JAXBException) + // one of our exceptions, just re-throw + throw (JAXBException) t; + if (t instanceof RuntimeException) + // avoid wrapping exceptions unnecessarily + throw (RuntimeException) t; + if (t instanceof Error) + throw (Error) t; + return t; + } + return x; + } + + + /** + * Determine if two types (JAXBContext in this case) will generate a ClassCastException. + * + * For example, (targetType)originalType + * + * @param originalType + * The Class object of the type being cast + * @param targetType + * The Class object of the type that is being cast to + * @return JAXBException to be thrown. + */ + private static JAXBException handleClassCastException(Class originalType, Class targetType) { + final URL targetTypeURL = which(targetType); + + return new JAXBException(Messages.format(Messages.ILLEGAL_CAST, + // we don't care where the impl class is, we want to know where JAXBContext lives in the impl + // class' ClassLoader + getClassClassLoader(originalType).getResource("javax/xml/bind/JAXBContext.class"), + targetTypeURL)); + } + + /** + * Create an instance of a class using the specified ClassLoader + */ + static JAXBContext newInstance(String contextPath, + Class[] contextPathClasses, + String className, + ClassLoader classLoader, + Map properties) throws JAXBException { + + try { + Class spFactory = ServiceLoaderUtil.safeLoadClass(className, PLATFORM_DEFAULT_FACTORY_CLASS, classLoader); + return newInstance(contextPath, contextPathClasses, spFactory, classLoader, properties); + } catch (ClassNotFoundException x) { + throw new JAXBException(Messages.format(Messages.DEFAULT_PROVIDER_NOT_FOUND), x); + + } catch (RuntimeException | JAXBException x) { + // avoid wrapping RuntimeException to JAXBException, + // because it indicates a bug in this code. + // JAXBException re-thrown as is + throw x; + } catch (Exception x) { + // can't catch JAXBException because the method is hidden behind + // reflection. Root element collisions detected in the call to + // createContext() are reported as JAXBExceptions - just re-throw it + // some other type of exception - just wrap it + throw new JAXBException(Messages.format(Messages.COULD_NOT_INSTANTIATE, className, x), x); + } + } + + static JAXBContext newInstance(String contextPath, + Class[] contextPathClasses, + Class spFactory, + ClassLoader classLoader, + Map properties) throws JAXBException { + + try { + + ModuleUtil.delegateAddOpensToImplModule(contextPathClasses, spFactory); + + /* + * javax.xml.bind.context.factory points to a class which has a + * static method called 'createContext' that + * returns a javax.xml.JAXBContext. + */ + + Object context = null; + + // first check the method that takes Map as the third parameter. + // this is added in 2.0. + try { + Method m = spFactory.getMethod("createContext", String.class, ClassLoader.class, Map.class); + // any failure in invoking this method would be considered fatal + Object obj = instantiateProviderIfNecessary(spFactory); + context = m.invoke(obj, contextPath, classLoader, properties); + } catch (NoSuchMethodException ignored) { + // it's not an error for the provider not to have this method. + } + + if (context == null) { + // try the old method that doesn't take properties. compatible with 1.0. + // it is an error for an implementation not to have both forms of the createContext method. + Method m = spFactory.getMethod("createContext", String.class, ClassLoader.class); + Object obj = instantiateProviderIfNecessary(spFactory); + // any failure in invoking this method would be considered fatal + context = m.invoke(obj, contextPath, classLoader); + } + + if (!(context instanceof JAXBContext)) { + // the cast would fail, so generate an exception with a nice message + throw handleClassCastException(context.getClass(), JAXBContext.class); + } + + return (JAXBContext) context; + } catch (InvocationTargetException x) { + // throw if it is exception not to be wrapped + // otherwise, wrap with a JAXBException + Throwable e = handleInvocationTargetException(x); + throw new JAXBException(Messages.format(Messages.COULD_NOT_INSTANTIATE, spFactory, e), e); + + } catch (Exception x) { + // can't catch JAXBException because the method is hidden behind + // reflection. Root element collisions detected in the call to + // createContext() are reported as JAXBExceptions - just re-throw it + // some other type of exception - just wrap it + throw new JAXBException(Messages.format(Messages.COULD_NOT_INSTANTIATE, spFactory, x), x); + } + } + + private static Object instantiateProviderIfNecessary(final Class implClass) throws JAXBException { + try { + if (JAXBContextFactory.class.isAssignableFrom(implClass)) { + return AccessController.doPrivileged(new PrivilegedExceptionAction() { + @Override + public Object run() throws Exception { + return implClass.newInstance(); + } + }); + } + return null; + } catch (PrivilegedActionException x) { + Throwable e = (x.getCause() == null) ? x : x.getCause(); + throw new JAXBException(Messages.format(Messages.COULD_NOT_INSTANTIATE, implClass, e), e); + } + } + + /** + * Create an instance of a class using the thread context ClassLoader + */ + static JAXBContext newInstance(Class[] classes, Map properties, String className) throws JAXBException { + + Class spi; + try { + spi = ServiceLoaderUtil.safeLoadClass(className, PLATFORM_DEFAULT_FACTORY_CLASS, getContextClassLoader()); + } catch (ClassNotFoundException e) { + throw new JAXBException(Messages.format(Messages.DEFAULT_PROVIDER_NOT_FOUND), e); + } + + if (logger.isLoggable(Level.FINE)) { + // extra check to avoid costly which operation if not logged + logger.log(Level.FINE, "loaded {0} from {1}", new Object[]{className, which(spi)}); + } + + return newInstance(classes, properties, spi); + } + + static JAXBContext newInstance(Class[] classes, + Map properties, + Class spFactory) throws JAXBException { + try { + ModuleUtil.delegateAddOpensToImplModule(classes, spFactory); + + Method m = spFactory.getMethod("createContext", Class[].class, Map.class); + Object obj = instantiateProviderIfNecessary(spFactory); + Object context = m.invoke(obj, classes, properties); + if (!(context instanceof JAXBContext)) { + // the cast would fail, so generate an exception with a nice message + throw handleClassCastException(context.getClass(), JAXBContext.class); + } + return (JAXBContext) context; + + } catch (NoSuchMethodException | IllegalAccessException e) { + throw new JAXBException(e); + } catch (InvocationTargetException e) { + // throw if it is exception not to be wrapped + // otherwise, wrap with a JAXBException + Throwable x = handleInvocationTargetException(e); + + throw new JAXBException(x); + } + } + + static JAXBContext find(String factoryId, + String contextPath, + ClassLoader classLoader, + Map properties) throws JAXBException { + + if (contextPath == null || contextPath.isEmpty()) { + // no context is specified + throw new JAXBException(Messages.format(Messages.NO_PACKAGE_IN_CONTEXTPATH)); + } + + //ModuleUtil is mr-jar class, scans context path for jaxb classes on jdk9 and higher + Class[] contextPathClasses = ModuleUtil.getClassesFromContextPath(contextPath, classLoader); + + //first try with classloader#getResource + String factoryClassName = jaxbProperties(contextPath, classLoader, factoryId); + if (factoryClassName == null && contextPathClasses != null) { + //try with class#getResource + factoryClassName = jaxbProperties(contextPathClasses, factoryId); + } + + if (factoryClassName != null) { + return newInstance(contextPath, contextPathClasses, factoryClassName, classLoader, properties); + } + + + String factoryName = classNameFromSystemProperties(); + if (factoryName != null) return newInstance(contextPath, contextPathClasses, factoryName, classLoader, properties); + + JAXBContextFactory obj = ServiceLoaderUtil.firstByServiceLoader( + JAXBContextFactory.class, logger, EXCEPTION_HANDLER); + + if (obj != null) { + ModuleUtil.delegateAddOpensToImplModule(contextPathClasses, obj.getClass()); + return obj.createContext(contextPath, classLoader, properties); + } + + // to ensure backwards compatibility + factoryName = firstByServiceLoaderDeprecated(JAXBContext.class, classLoader); + if (factoryName != null) return newInstance(contextPath, contextPathClasses, factoryName, classLoader, properties); + + Class ctxFactory = (Class) ServiceLoaderUtil.lookupUsingOSGiServiceLoader( + "javax.xml.bind.JAXBContext", logger); + + if (ctxFactory != null) { + return newInstance(contextPath, contextPathClasses, ctxFactory, classLoader, properties); + } + + // else no provider found + logger.fine("Trying to create the platform default provider"); + return newInstance(contextPath, contextPathClasses, PLATFORM_DEFAULT_FACTORY_CLASS, classLoader, properties); + } + + static JAXBContext find(Class[] classes, Map properties) throws JAXBException { + + // search for jaxb.properties in the class loader of each class first + logger.fine("Searching jaxb.properties"); + for (final Class c : classes) { + // this classloader is used only to load jaxb.properties, so doing this should be safe. + // this is possible for primitives, arrays, and classes that are + // loaded by poorly implemented ClassLoaders + if (c.getPackage() == null) continue; + + // TODO: do we want to optimize away searching the same package? org.Foo, org.Bar, com.Baz + // classes from the same package might come from different class loades, so it might be a bad idea + // TODO: it's easier to look things up from the class + // c.getResourceAsStream("jaxb.properties"); + + URL jaxbPropertiesUrl = getResourceUrl(c, "jaxb.properties"); + + if (jaxbPropertiesUrl != null) { + + String factoryClassName = + classNameFromPackageProperties( + jaxbPropertiesUrl, + JAXBContext.JAXB_CONTEXT_FACTORY, JAXB_CONTEXT_FACTORY_DEPRECATED); + + return newInstance(classes, properties, factoryClassName); + } + + } + + String factoryClassName = classNameFromSystemProperties(); + if (factoryClassName != null) return newInstance(classes, properties, factoryClassName); + + JAXBContextFactory factory = + ServiceLoaderUtil.firstByServiceLoader(JAXBContextFactory.class, logger, EXCEPTION_HANDLER); + + if (factory != null) { + ModuleUtil.delegateAddOpensToImplModule(classes, factory.getClass()); + return factory.createContext(classes, properties); + } + + // to ensure backwards compatibility + String className = firstByServiceLoaderDeprecated(JAXBContext.class, getContextClassLoader()); + if (className != null) return newInstance(classes, properties, className); + + logger.fine("Trying to create the platform default provider"); + Class ctxFactoryClass = + (Class) ServiceLoaderUtil.lookupUsingOSGiServiceLoader("javax.xml.bind.JAXBContext", logger); + + if (ctxFactoryClass != null) { + return newInstance(classes, properties, ctxFactoryClass); + } + + // else no provider found + logger.fine("Trying to create the platform default provider"); + return newInstance(classes, properties, PLATFORM_DEFAULT_FACTORY_CLASS); + } + + + /** + * first factoryId should be the preferred one, + * more of those can be provided to support backwards compatibility + */ + private static String classNameFromPackageProperties(URL packagePropertiesUrl, + String ... factoryIds) throws JAXBException { + + logger.log(Level.FINE, "Trying to locate {0}", packagePropertiesUrl.toString()); + Properties props = loadJAXBProperties(packagePropertiesUrl); + for(String factoryId : factoryIds) { + if (props.containsKey(factoryId)) { + return props.getProperty(factoryId); + } + } + //Factory key not found + String propertiesUrl = packagePropertiesUrl.toExternalForm(); + String packageName = propertiesUrl.substring(0, propertiesUrl.indexOf("/jaxb.properties")); + throw new JAXBException(Messages.format(Messages.MISSING_PROPERTY, packageName, factoryIds[0])); + } + + private static String classNameFromSystemProperties() throws JAXBException { + + String factoryClassName = getSystemProperty(JAXBContext.JAXB_CONTEXT_FACTORY); + if (factoryClassName != null) { + return factoryClassName; + } + // leave this here to assure compatibility + factoryClassName = getDeprecatedSystemProperty(JAXB_CONTEXT_FACTORY_DEPRECATED); + if (factoryClassName != null) { + return factoryClassName; + } + // leave this here to assure compatibility + factoryClassName = getDeprecatedSystemProperty(JAXBContext.class.getName()); + if (factoryClassName != null) { + return factoryClassName; + } + return null; + } + + private static String getDeprecatedSystemProperty(String property) { + String value = getSystemProperty(property); + if (value != null) { + logger.log(Level.WARNING, "Using non-standard property: {0}. Property {1} should be used instead.", + new Object[] {property, JAXBContext.JAXB_CONTEXT_FACTORY}); + } + return value; + } + + private static String getSystemProperty(String property) { + logger.log(Level.FINE, "Checking system property {0}", property); + String value = AccessController.doPrivileged(new GetPropertyAction(property)); + if (value != null) { + logger.log(Level.FINE, " found {0}", value); + } else { + logger.log(Level.FINE, " not found"); + } + return value; + } + + private static Properties loadJAXBProperties(URL url) throws JAXBException { + + try { + Properties props; + logger.log(Level.FINE, "loading props from {0}", url); + props = new Properties(); + InputStream is = url.openStream(); + props.load(is); + is.close(); + return props; + } catch (IOException ioe) { + logger.log(Level.FINE, "Unable to load " + url.toString(), ioe); + throw new JAXBException(ioe.toString(), ioe); + } + } + + /** + * If run on JPMS package containing resource must be open unconditionally. + * + * @param classLoader classloader to load resource with + * @param resourceName qualified name of the resource + * @return resource url if found + */ + private static URL getResourceUrl(ClassLoader classLoader, String resourceName) { + URL url; + if (classLoader == null) + url = ClassLoader.getSystemResource(resourceName); + else + url = classLoader.getResource(resourceName); + return url; + } + + private static URL getResourceUrl(Class clazz, String resourceName) { + return clazz.getResource(resourceName); + } + + + /** + * Search the given ClassLoader for an instance of the specified class and + * return a string representation of the URL that points to the resource. + * + * @param clazz + * The class to search for + * @param loader + * The ClassLoader to search. If this parameter is null, then the + * system class loader will be searched + * @return + * the URL for the class or null if it wasn't found + */ + static URL which(Class clazz, ClassLoader loader) { + + String classnameAsResource = clazz.getName().replace('.', '/') + ".class"; + + if (loader == null) { + loader = getSystemClassLoader(); + } + + return loader.getResource(classnameAsResource); + } + + /** + * Get the URL for the Class from it's ClassLoader. + * + * Convenience method for {@link #which(Class, ClassLoader)}. + * + * Equivalent to calling: which(clazz, clazz.getClassLoader()) + * + * @param clazz + * The class to search for + * @return + * the URL for the class or null if it wasn't found + */ + static URL which(Class clazz) { + return which(clazz, getClassClassLoader(clazz)); + } + + @SuppressWarnings("unchecked") + private static ClassLoader getContextClassLoader() { + if (System.getSecurityManager() == null) { + return Thread.currentThread().getContextClassLoader(); + } else { + return (ClassLoader) java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction() { + @Override + public java.lang.Object run() { + return Thread.currentThread().getContextClassLoader(); + } + }); + } + } + + @SuppressWarnings("unchecked") + private static ClassLoader getClassClassLoader(final Class c) { + if (System.getSecurityManager() == null) { + return c.getClassLoader(); + } else { + return (ClassLoader) java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction() { + @Override + public java.lang.Object run() { + return c.getClassLoader(); + } + }); + } + } + + private static ClassLoader getSystemClassLoader() { + if (System.getSecurityManager() == null) { + return ClassLoader.getSystemClassLoader(); + } else { + return (ClassLoader) java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction() { + @Override + public java.lang.Object run() { + return ClassLoader.getSystemClassLoader(); + } + }); + } + } + + // ServiceLoaderUtil.firstByServiceLoaderDeprecated should be used instead. + @Deprecated + static String firstByServiceLoaderDeprecated(Class spiClass, + ClassLoader classLoader) throws JAXBException { + + final String jaxbContextFQCN = spiClass.getName(); + + logger.fine("Searching META-INF/services"); + + // search META-INF services next + BufferedReader r = null; + final String resource = "META-INF/services/" + jaxbContextFQCN; + try { + final InputStream resourceStream = + (classLoader == null) ? + ClassLoader.getSystemResourceAsStream(resource) : + classLoader.getResourceAsStream(resource); + + if (resourceStream != null) { + r = new BufferedReader(new InputStreamReader(resourceStream, "UTF-8")); + String factoryClassName = r.readLine(); + if (factoryClassName != null) { + factoryClassName = factoryClassName.trim(); + } + r.close(); + logger.log(Level.FINE, "Configured factorty class:{0}", factoryClassName); + return factoryClassName; + } else { + logger.log(Level.FINE, "Unable to load:{0}", resource); + return null; + } + } catch (IOException e) { + throw new JAXBException(e); + } finally { + try { + if (r != null) { + r.close(); + } + } catch (IOException ex) { + logger.log(Level.SEVERE, "Unable to close resource: " + resource, ex); + } + } + } + + private static String jaxbProperties(String contextPath, ClassLoader classLoader, String factoryId) throws JAXBException { + String[] packages = contextPath.split(":"); + + for (String pkg : packages) { + String pkgUrl = pkg.replace('.', '/'); + URL jaxbPropertiesUrl = getResourceUrl(classLoader, pkgUrl + "/jaxb.properties"); + if (jaxbPropertiesUrl != null) { + return classNameFromPackageProperties(jaxbPropertiesUrl, + factoryId, JAXB_CONTEXT_FACTORY_DEPRECATED); + } + } + return null; + } + + private static String jaxbProperties(Class[] classesFromContextPath, String factoryId) throws JAXBException { + for (Class c : classesFromContextPath) { + URL jaxbPropertiesUrl = getResourceUrl(c, "jaxb.properties"); + if (jaxbPropertiesUrl != null) { + return classNameFromPackageProperties(jaxbPropertiesUrl, factoryId, JAXB_CONTEXT_FACTORY_DEPRECATED); + } + } + return null; + } + +} diff --git a/fine-third-jdk11/src/javax/xml/bind/DataBindingException.java b/fine-third-jdk11/src/javax/xml/bind/DataBindingException.java new file mode 100644 index 000000000..eabc6547d --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/DataBindingException.java @@ -0,0 +1,62 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2006-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +/** + * Exception that represents a failure in a JAXB operation. + * + *

+ * This exception differs from {@link JAXBException} in that + * this is an unchecked exception, while {@code JAXBException} + * is a checked exception. + * + * @see JAXB + * @since 1.6, JAXB 2.1 + */ +public class DataBindingException extends RuntimeException { + public DataBindingException(String message, Throwable cause) { + super(message, cause); + } + + public DataBindingException(Throwable cause) { + super(cause); + } +} diff --git a/fine-third-jdk11/src/javax/xml/bind/DatatypeConverter.java b/fine-third-jdk11/src/javax/xml/bind/DatatypeConverter.java new file mode 100644 index 000000000..bb871fe0f --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/DatatypeConverter.java @@ -0,0 +1,710 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +import javax.xml.namespace.NamespaceContext; + +/** + *

+ * The javaType binding declaration can be used to customize the binding of + * an XML schema datatype to a Java datatype. Customizations can involve + * writing a parse and print method for parsing and printing lexical + * representations of a XML schema datatype respectively. However, writing + * parse and print methods requires knowledge of the lexical representations ( + * XML Schema Part2: Datatypes + * specification ) and hence may be difficult to write. + *

+ *

+ * This class makes it easier to write parse and print methods. It defines + * static parse and print methods that provide access to a JAXB provider's + * implementation of parse and print methods. These methods are invoked by + * custom parse and print methods. For example, the binding of xsd:dateTime + * to a long can be customized using parse and print methods as follows: + *

+ *
+ *    // Customized parse method 
+ *    public long myParseCal( String dateTimeString ) {
+ *        java.util.Calendar cal = DatatypeConverter.parseDateTime(dateTimeString);
+ *        long longval = convert_calendar_to_long(cal); //application specific
+ *        return longval;
+ *    }
+ *     
+ *    // Customized print method
+ *    public String myPrintCal( Long longval ) {
+ *        java.util.Calendar cal = convert_long_to_calendar(longval) ; //application specific
+ *        String dateTimeString = DatatypeConverter.printDateTime(cal);
+ *        return dateTimeString;
+ *    }
+ *    
+ *
+ *

+ * There is a static parse and print method corresponding to each parse and + * print method respectively in the {@link DatatypeConverterInterface + * DatatypeConverterInterface}. + *

+ * The static methods defined in the class can also be used to specify + * a parse or a print method in a javaType binding declaration. + *

+ *

+ * JAXB Providers are required to call the + * {@link #setDatatypeConverter(DatatypeConverterInterface) + * setDatatypeConverter} api at some point before the first marshal or unmarshal + * operation (perhaps during the call to JAXBContext.newInstance). This step is + * necessary to configure the converter that should be used to perform the + * print and parse functionality. + *

+ * + *

+ * A print method for a XML schema datatype can output any lexical + * representation that is valid with respect to the XML schema datatype. + * If an error is encountered during conversion, then an IllegalArgumentException, + * or a subclass of IllegalArgumentException must be thrown by the method. + *

+ * + * @author
  • Sekhar Vajjhala, Sun Microsystems, Inc.
  • Joe Fialli, Sun Microsystems Inc.
  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • Ryan Shoemaker,Sun Microsystems Inc.
+ * @see DatatypeConverterInterface + * @see ParseConversionEvent + * @see PrintConversionEvent + * @since 1.6, JAXB 1.0 + */ + +final public class DatatypeConverter { + + // delegate to this instance of DatatypeConverter + private static volatile DatatypeConverterInterface theConverter = null; + + private final static JAXBPermission SET_DATATYPE_CONVERTER_PERMISSION = + new JAXBPermission("setDatatypeConverter"); + + private DatatypeConverter() { + // private constructor + } + + /** + * This method is for JAXB provider use only. + *

+ * JAXB Providers are required to call this method at some point before + * allowing any of the JAXB client marshal or unmarshal operations to + * occur. This is necessary to configure the datatype converter that + * should be used to perform the print and parse conversions. + * + *

+ * Calling this api repeatedly will have no effect - the + * DatatypeConverterInterface instance passed into the first invocation is + * the one that will be used from then on. + * + * @param converter an instance of a class that implements the + * DatatypeConverterInterface class - this parameter must not be null. + * @throws IllegalArgumentException if the parameter is null + * @throws SecurityException + * If the {@link SecurityManager} in charge denies the access to + * set the datatype converter. + * @see JAXBPermission + */ + public static void setDatatypeConverter( DatatypeConverterInterface converter ) { + if( converter == null ) { + throw new IllegalArgumentException( + Messages.format( Messages.CONVERTER_MUST_NOT_BE_NULL ) ); + } else if( theConverter == null ) { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) + sm.checkPermission(SET_DATATYPE_CONVERTER_PERMISSION); + theConverter = converter; + } + } + + private static synchronized void initConverter() { + theConverter = new DatatypeConverterImpl(); + } + + /** + *

+ * Convert the lexical XSD string argument into a String value. + * @param lexicalXSDString + * A string containing a lexical representation of + * xsd:string. + * @return + * A String value represented by the string argument. + */ + public static String parseString( String lexicalXSDString ) { + if (theConverter == null) initConverter(); + return theConverter.parseString( lexicalXSDString ); + } + + /** + *

+ * Convert the string argument into a BigInteger value. + * @param lexicalXSDInteger + * A string containing a lexical representation of + * xsd:integer. + * @return + * A BigInteger value represented by the string argument. + * @throws NumberFormatException lexicalXSDInteger is not a valid string representation of a {@link java.math.BigInteger} value. + */ + public static java.math.BigInteger parseInteger( String lexicalXSDInteger ) { + if (theConverter == null) initConverter(); + return theConverter.parseInteger( lexicalXSDInteger ); + } + + /** + *

+ * Convert the string argument into an int value. + * @param lexicalXSDInt + * A string containing a lexical representation of + * xsd:int. + * @return + * A int value represented by the string argument. + * @throws NumberFormatException lexicalXSDInt is not a valid string representation of an int value. + */ + public static int parseInt( String lexicalXSDInt ) { + if (theConverter == null) initConverter(); + return theConverter.parseInt( lexicalXSDInt ); + } + + /** + *

+ * Converts the string argument into a long value. + * @param lexicalXSDLong + * A string containing lexical representation of + * xsd:long. + * @return + * A long value represented by the string argument. + * @throws NumberFormatException lexicalXSDLong is not a valid string representation of a long value. + */ + public static long parseLong( String lexicalXSDLong ) { + if (theConverter == null) initConverter(); + return theConverter.parseLong( lexicalXSDLong ); + } + + /** + *

+ * Converts the string argument into a short value. + * @param lexicalXSDShort + * A string containing lexical representation of + * xsd:short. + * @return + * A short value represented by the string argument. + * @throws NumberFormatException lexicalXSDShort is not a valid string representation of a short value. + */ + public static short parseShort( String lexicalXSDShort ) { + if (theConverter == null) initConverter(); + return theConverter.parseShort( lexicalXSDShort ); + } + + /** + *

+ * Converts the string argument into a BigDecimal value. + * @param lexicalXSDDecimal + * A string containing lexical representation of + * xsd:decimal. + * @return + * A BigDecimal value represented by the string argument. + * @throws NumberFormatException lexicalXSDDecimal is not a valid string representation of {@link java.math.BigDecimal}. + */ + public static java.math.BigDecimal parseDecimal( String lexicalXSDDecimal ) { + if (theConverter == null) initConverter(); + return theConverter.parseDecimal( lexicalXSDDecimal ); + } + + /** + *

+ * Converts the string argument into a float value. + * @param lexicalXSDFloat + * A string containing lexical representation of + * xsd:float. + * @return + * A float value represented by the string argument. + * @throws NumberFormatException lexicalXSDFloat is not a valid string representation of a float value. + */ + public static float parseFloat( String lexicalXSDFloat ) { + if (theConverter == null) initConverter(); + return theConverter.parseFloat( lexicalXSDFloat ); + } + + /** + *

+ * Converts the string argument into a double value. + * @param lexicalXSDDouble + * A string containing lexical representation of + * xsd:double. + * @return + * A double value represented by the string argument. + * @throws NumberFormatException lexicalXSDDouble is not a valid string representation of a double value. + */ + public static double parseDouble( String lexicalXSDDouble ) { + if (theConverter == null) initConverter(); + return theConverter.parseDouble( lexicalXSDDouble ); + } + + /** + *

+ * Converts the string argument into a boolean value. + * @param lexicalXSDBoolean + * A string containing lexical representation of + * xsd:boolean. + * @return + * A boolean value represented by the string argument. + * @throws IllegalArgumentException if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:boolean. + */ + public static boolean parseBoolean( String lexicalXSDBoolean ) { + if (theConverter == null) initConverter(); + return theConverter.parseBoolean( lexicalXSDBoolean ); + } + + /** + *

+ * Converts the string argument into a byte value. + * @param lexicalXSDByte + * A string containing lexical representation of + * xsd:byte. + * @return + * A byte value represented by the string argument. + * @throws IllegalArgumentException if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:byte. + */ + public static byte parseByte( String lexicalXSDByte ) { + if (theConverter == null) initConverter(); + return theConverter.parseByte( lexicalXSDByte ); + } + + /** + *

+ * Converts the string argument into a byte value. + * + *

+ * String parameter {@code lexicalXSDQname} must conform to lexical value space specifed at + * XML Schema Part 2:Datatypes specification:QNames + * + * @param lexicalXSDQName + * A string containing lexical representation of xsd:QName. + * @param nsc + * A namespace context for interpreting a prefix within a QName. + * @return + * A QName value represented by the string argument. + * @throws IllegalArgumentException if string parameter does not conform to XML Schema Part 2 specification or + * if namespace prefix of {@code lexicalXSDQname} is not bound to a URI in NamespaceContext {@code nsc}. + */ + public static javax.xml.namespace.QName parseQName( String lexicalXSDQName, + NamespaceContext nsc) { + if (theConverter == null) initConverter(); + return theConverter.parseQName( lexicalXSDQName, nsc ); + } + + /** + *

+ * Converts the string argument into a Calendar value. + * @param lexicalXSDDateTime + * A string containing lexical representation of + * xsd:datetime. + * @return + * A Calendar object represented by the string argument. + * @throws IllegalArgumentException if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:dateTime. + */ + public static java.util.Calendar parseDateTime( String lexicalXSDDateTime ) { + if (theConverter == null) initConverter(); + return theConverter.parseDateTime( lexicalXSDDateTime ); + } + + /** + *

+ * Converts the string argument into an array of bytes. + * @param lexicalXSDBase64Binary + * A string containing lexical representation + * of xsd:base64Binary. + * @return + * An array of bytes represented by the string argument. + * @throws IllegalArgumentException if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:base64Binary + */ + public static byte[] parseBase64Binary( String lexicalXSDBase64Binary ) { + if (theConverter == null) initConverter(); + return theConverter.parseBase64Binary( lexicalXSDBase64Binary ); + } + + /** + *

+ * Converts the string argument into an array of bytes. + * @param lexicalXSDHexBinary + * A string containing lexical representation of + * xsd:hexBinary. + * @return + * An array of bytes represented by the string argument. + * @throws IllegalArgumentException if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:hexBinary. + */ + public static byte[] parseHexBinary( String lexicalXSDHexBinary ) { + if (theConverter == null) initConverter(); + return theConverter.parseHexBinary( lexicalXSDHexBinary ); + } + + /** + *

+ * Converts the string argument into a long value. + * @param lexicalXSDUnsignedInt + * A string containing lexical representation + * of xsd:unsignedInt. + * @return + * A long value represented by the string argument. + * @throws NumberFormatException if string parameter can not be parsed into a {@code long} value. + */ + public static long parseUnsignedInt( String lexicalXSDUnsignedInt ) { + if (theConverter == null) initConverter(); + return theConverter.parseUnsignedInt( lexicalXSDUnsignedInt ); + } + + /** + *

+ * Converts the string argument into an int value. + * @param lexicalXSDUnsignedShort + * A string containing lexical + * representation of xsd:unsignedShort. + * @return + * An int value represented by the string argument. + * @throws NumberFormatException if string parameter can not be parsed into an {@code int} value. + */ + public static int parseUnsignedShort( String lexicalXSDUnsignedShort ) { + if (theConverter == null) initConverter(); + return theConverter.parseUnsignedShort( lexicalXSDUnsignedShort ); + } + + /** + *

+ * Converts the string argument into a Calendar value. + * @param lexicalXSDTime + * A string containing lexical representation of + * xsd:time. + * @return + * A Calendar value represented by the string argument. + * @throws IllegalArgumentException if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:Time. + */ + public static java.util.Calendar parseTime( String lexicalXSDTime ) { + if (theConverter == null) initConverter(); + return theConverter.parseTime( lexicalXSDTime ); + } + /** + *

+ * Converts the string argument into a Calendar value. + * @param lexicalXSDDate + * A string containing lexical representation of + * xsd:Date. + * @return + * A Calendar value represented by the string argument. + * @throws IllegalArgumentException if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:Date. + */ + public static java.util.Calendar parseDate( String lexicalXSDDate ) { + if (theConverter == null) initConverter(); + return theConverter.parseDate( lexicalXSDDate ); + } + + /** + *

+ * Return a string containing the lexical representation of the + * simple type. + * @param lexicalXSDAnySimpleType + * A string containing lexical + * representation of the simple type. + * @return + * A string containing the lexical representation of the + * simple type. + */ + public static String parseAnySimpleType( String lexicalXSDAnySimpleType ) { + if (theConverter == null) initConverter(); + return theConverter.parseAnySimpleType( lexicalXSDAnySimpleType ); + } + /** + *

+ * Converts the string argument into a string. + * @param val + * A string value. + * @return + * A string containing a lexical representation of xsd:string. + */ + // also indicate the print methods produce a lexical + // representation for given Java datatypes. + + public static String printString( String val ) { + if (theConverter == null) initConverter(); + return theConverter.printString( val ); + } + + /** + *

+ * Converts a BigInteger value into a string. + * @param val + * A BigInteger value + * @return + * A string containing a lexical representation of xsd:integer + * @throws IllegalArgumentException {@code val} is null. + */ + public static String printInteger( java.math.BigInteger val ) { + if (theConverter == null) initConverter(); + return theConverter.printInteger( val ); + } + + /** + *

+ * Converts an int value into a string. + * @param val + * An int value + * @return + * A string containing a lexical representation of xsd:int + */ + public static String printInt( int val ) { + if (theConverter == null) initConverter(); + return theConverter.printInt( val ); + } + + /** + *

+ * Converts A long value into a string. + * @param val + * A long value + * @return + * A string containing a lexical representation of xsd:long + */ + public static String printLong( long val ) { + if (theConverter == null) initConverter(); + return theConverter.printLong( val ); + } + + /** + *

+ * Converts a short value into a string. + * @param val + * A short value + * @return + * A string containing a lexical representation of xsd:short + */ + public static String printShort( short val ) { + if (theConverter == null) initConverter(); + return theConverter.printShort( val ); + } + + /** + *

+ * Converts a BigDecimal value into a string. + * @param val + * A BigDecimal value + * @return + * A string containing a lexical representation of xsd:decimal + * @throws IllegalArgumentException {@code val} is null. + */ + public static String printDecimal( java.math.BigDecimal val ) { + if (theConverter == null) initConverter(); + return theConverter.printDecimal( val ); + } + + /** + *

+ * Converts a float value into a string. + * @param val + * A float value + * @return + * A string containing a lexical representation of xsd:float + */ + public static String printFloat( float val ) { + if (theConverter == null) initConverter(); + return theConverter.printFloat( val ); + } + + /** + *

+ * Converts a double value into a string. + * @param val + * A double value + * @return + * A string containing a lexical representation of xsd:double + */ + public static String printDouble( double val ) { + if (theConverter == null) initConverter(); + return theConverter.printDouble( val ); + } + + /** + *

+ * Converts a boolean value into a string. + * @param val + * A boolean value + * @return + * A string containing a lexical representation of xsd:boolean + */ + public static String printBoolean( boolean val ) { + if (theConverter == null) initConverter(); + return theConverter.printBoolean( val ); + } + + /** + *

+ * Converts a byte value into a string. + * @param val + * A byte value + * @return + * A string containing a lexical representation of xsd:byte + */ + public static String printByte( byte val ) { + if (theConverter == null) initConverter(); + return theConverter.printByte( val ); + } + + /** + *

+ * Converts a QName instance into a string. + * @param val + * A QName value + * @param nsc + * A namespace context for interpreting a prefix within a QName. + * @return + * A string containing a lexical representation of QName + * @throws IllegalArgumentException if {@code val} is null or + * if {@code nsc} is non-null or {@code nsc.getPrefix(nsprefixFromVal)} is null. + */ + public static String printQName( javax.xml.namespace.QName val, + NamespaceContext nsc ) { + if (theConverter == null) initConverter(); + return theConverter.printQName( val, nsc ); + } + + /** + *

+ * Converts a Calendar value into a string. + * @param val + * A Calendar value + * @return + * A string containing a lexical representation of xsd:dateTime + * @throws IllegalArgumentException if {@code val} is null. + */ + public static String printDateTime( java.util.Calendar val ) { + if (theConverter == null) initConverter(); + return theConverter.printDateTime( val ); + } + + /** + *

+ * Converts an array of bytes into a string. + * @param val + * An array of bytes + * @return + * A string containing a lexical representation of xsd:base64Binary + * @throws IllegalArgumentException if {@code val} is null. + */ + public static String printBase64Binary( byte[] val ) { + if (theConverter == null) initConverter(); + return theConverter.printBase64Binary( val ); + } + + /** + *

+ * Converts an array of bytes into a string. + * @param val + * An array of bytes + * @return + * A string containing a lexical representation of xsd:hexBinary + * @throws IllegalArgumentException if {@code val} is null. + */ + public static String printHexBinary( byte[] val ) { + if (theConverter == null) initConverter(); + return theConverter.printHexBinary( val ); + } + + /** + *

+ * Converts a long value into a string. + * @param val + * A long value + * @return + * A string containing a lexical representation of xsd:unsignedInt + */ + public static String printUnsignedInt( long val ) { + if (theConverter == null) initConverter(); + return theConverter.printUnsignedInt( val ); + } + + /** + *

+ * Converts an int value into a string. + * @param val + * An int value + * @return + * A string containing a lexical representation of xsd:unsignedShort + */ + public static String printUnsignedShort( int val ) { + if (theConverter == null) initConverter(); + return theConverter.printUnsignedShort( val ); + } + + /** + *

+ * Converts a Calendar value into a string. + * @param val + * A Calendar value + * @return + * A string containing a lexical representation of xsd:time + * @throws IllegalArgumentException if {@code val} is null. + */ + public static String printTime( java.util.Calendar val ) { + if (theConverter == null) initConverter(); + return theConverter.printTime( val ); + } + + /** + *

+ * Converts a Calendar value into a string. + * @param val + * A Calendar value + * @return + * A string containing a lexical representation of xsd:date + * @throws IllegalArgumentException if {@code val} is null. + */ + public static String printDate( java.util.Calendar val ) { + if (theConverter == null) initConverter(); + return theConverter.printDate( val ); + } + + /** + *

+ * Converts a string value into a string. + * @param val + * A string value + * @return + * A string containing a lexical representation of xsd:AnySimpleType + */ + public static String printAnySimpleType( String val ) { + if (theConverter == null) initConverter(); + return theConverter.printAnySimpleType( val ); + } +} diff --git a/fine-third-jdk11/src/javax/xml/bind/DatatypeConverterImpl.java b/fine-third-jdk11/src/javax/xml/bind/DatatypeConverterImpl.java new file mode 100644 index 000000000..8ef52127a --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/DatatypeConverterImpl.java @@ -0,0 +1,1057 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2007-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.TimeZone; + +import javax.xml.namespace.QName; +import javax.xml.namespace.NamespaceContext; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.DatatypeConfigurationException; + +/** + * This class is the JAXB RI's default implementation of the + * {@link DatatypeConverterInterface}. + * + *

+ * When client applications specify the use of the static print/parse + * methods in {@link DatatypeConverter}, it will delegate + * to this class. + * + *

+ * This class is responsible for whitespace normalization. + * + * @author

  • Ryan Shoemaker, Sun Microsystems, Inc.
+ * @since JAXB 2.1 + */ +final class DatatypeConverterImpl implements DatatypeConverterInterface { + + /** + * To avoid re-creating instances, we cache one instance. + */ + public static final DatatypeConverterInterface theInstance = new DatatypeConverterImpl(); + + protected DatatypeConverterImpl() { + } + + public String parseString(String lexicalXSDString) { + return lexicalXSDString; + } + + public BigInteger parseInteger(String lexicalXSDInteger) { + return _parseInteger(lexicalXSDInteger); + } + + public static BigInteger _parseInteger(CharSequence s) { + return new BigInteger(removeOptionalPlus(WhiteSpaceProcessor.trim(s)).toString()); + } + + public String printInteger(BigInteger val) { + return _printInteger(val); + } + + public static String _printInteger(BigInteger val) { + return val.toString(); + } + + public int parseInt(String s) { + return _parseInt(s); + } + + /** + * Faster but less robust String->int conversion. + * + * Note that: + *
    + *
  1. XML Schema allows '+', but {@link Integer#valueOf(String)} is not. + *
  2. XML Schema allows leading and trailing (but not in-between) whitespaces. + * {@link Integer#valueOf(String)} doesn't allow any. + *
+ */ + public static int _parseInt(CharSequence s) { + int len = s.length(); + int sign = 1; + + int r = 0; + + for (int i = 0; i < len; i++) { + char ch = s.charAt(i); + if (WhiteSpaceProcessor.isWhiteSpace(ch)) { + // skip whitespace + } else if ('0' <= ch && ch <= '9') { + r = r * 10 + (ch - '0'); + } else if (ch == '-') { + sign = -1; + } else if (ch == '+') { + // noop + } else { + throw new NumberFormatException("Not a number: " + s); + } + } + + return r * sign; + } + + public long parseLong(String lexicalXSLong) { + return _parseLong(lexicalXSLong); + } + + public static long _parseLong(CharSequence s) { + return Long.parseLong(removeOptionalPlus(WhiteSpaceProcessor.trim(s)).toString()); + } + + public short parseShort(String lexicalXSDShort) { + return _parseShort(lexicalXSDShort); + } + + public static short _parseShort(CharSequence s) { + return (short) _parseInt(s); + } + + public String printShort(short val) { + return _printShort(val); + } + + public static String _printShort(short val) { + return String.valueOf(val); + } + + public BigDecimal parseDecimal(String content) { + return _parseDecimal(content); + } + + public static BigDecimal _parseDecimal(CharSequence content) { + content = WhiteSpaceProcessor.trim(content); + + if (content.length() <= 0) { + return null; + } + + return new BigDecimal(content.toString()); + + // from purely XML Schema perspective, + // this implementation has a problem, since + // in xs:decimal "1.0" and "1" is equal whereas the above + // code will return different values for those two forms. + // + // the code was originally using com.sun.msv.datatype.xsd.NumberType.load, + // but a profiling showed that the process of normalizing "1.0" into "1" + // could take non-trivial time. + // + // also, from the user's point of view, one might be surprised if + // 1 (not 1.0) is returned from "1.000" + } + + public float parseFloat(String lexicalXSDFloat) { + return _parseFloat(lexicalXSDFloat); + } + + public static float _parseFloat(CharSequence _val) { + String s = WhiteSpaceProcessor.trim(_val).toString(); + /* Incompatibilities of XML Schema's float "xfloat" and Java's float "jfloat" + + * jfloat.valueOf ignores leading and trailing whitespaces, + whereas this is not allowed in xfloat. + * jfloat.valueOf allows "float type suffix" (f, F) to be + appended after float literal (e.g., 1.52e-2f), whereare + this is not the case of xfloat. + + gray zone + --------- + * jfloat allows ".523". And there is no clear statement that mentions + this case in xfloat. Although probably this is allowed. + * + */ + + if (s.equals("NaN")) { + return Float.NaN; + } + if (s.equals("INF")) { + return Float.POSITIVE_INFINITY; + } + if (s.equals("-INF")) { + return Float.NEGATIVE_INFINITY; + } + + if (s.length() == 0 + || !isDigitOrPeriodOrSign(s.charAt(0)) + || !isDigitOrPeriodOrSign(s.charAt(s.length() - 1))) { + throw new NumberFormatException(); + } + + // these screening process is necessary due to the wobble of Float.valueOf method + return Float.parseFloat(s); + } + + public String printFloat(float v) { + return _printFloat(v); + } + + public static String _printFloat(float v) { + if (Float.isNaN(v)) { + return "NaN"; + } + if (v == Float.POSITIVE_INFINITY) { + return "INF"; + } + if (v == Float.NEGATIVE_INFINITY) { + return "-INF"; + } + return String.valueOf(v); + } + + public double parseDouble(String lexicalXSDDouble) { + return _parseDouble(lexicalXSDDouble); + } + + public static double _parseDouble(CharSequence _val) { + String val = WhiteSpaceProcessor.trim(_val).toString(); + + if (val.equals("NaN")) { + return Double.NaN; + } + if (val.equals("INF")) { + return Double.POSITIVE_INFINITY; + } + if (val.equals("-INF")) { + return Double.NEGATIVE_INFINITY; + } + + if (val.length() == 0 + || !isDigitOrPeriodOrSign(val.charAt(0)) + || !isDigitOrPeriodOrSign(val.charAt(val.length() - 1))) { + throw new NumberFormatException(val); + } + + + // these screening process is necessary due to the wobble of Float.valueOf method + return Double.parseDouble(val); + } + + public boolean parseBoolean(String lexicalXSDBoolean) { + Boolean b = _parseBoolean(lexicalXSDBoolean); + return (b == null) ? false : b.booleanValue(); + } + + public static Boolean _parseBoolean(CharSequence literal) { + if (literal == null) { + return null; + } + + int i = 0; + int len = literal.length(); + char ch; + boolean value = false; + + if (literal.length() <= 0) { + return null; + } + + do { + ch = literal.charAt(i++); + } while (WhiteSpaceProcessor.isWhiteSpace(ch) && i < len); + + int strIndex = 0; + + switch (ch) { + case '1': + value = true; + break; + case '0': + value = false; + break; + case 't': + String strTrue = "rue"; + do { + ch = literal.charAt(i++); + } while ((strTrue.charAt(strIndex++) == ch) && i < len && strIndex < 3); + + if (strIndex == 3) { + value = true; + } else { + return false; + } +// throw new IllegalArgumentException("String \"" + literal + "\" is not valid boolean value."); + + break; + case 'f': + String strFalse = "alse"; + do { + ch = literal.charAt(i++); + } while ((strFalse.charAt(strIndex++) == ch) && i < len && strIndex < 4); + + + if (strIndex == 4) { + value = false; + } else { + return false; + } +// throw new IllegalArgumentException("String \"" + literal + "\" is not valid boolean value."); + + break; + } + + if (i < len) { + do { + ch = literal.charAt(i++); + } while (WhiteSpaceProcessor.isWhiteSpace(ch) && i < len); + } + + if (i == len) { + return value; + } else { + return null; + } +// throw new IllegalArgumentException("String \"" + literal + "\" is not valid boolean value."); + } + + public String printBoolean(boolean val) { + return val ? "true" : "false"; + } + + public static String _printBoolean(boolean val) { + return val ? "true" : "false"; + } + + public byte parseByte(String lexicalXSDByte) { + return _parseByte(lexicalXSDByte); + } + + public static byte _parseByte(CharSequence literal) { + return (byte) _parseInt(literal); + } + + public String printByte(byte val) { + return _printByte(val); + } + + public static String _printByte(byte val) { + return String.valueOf(val); + } + + public QName parseQName(String lexicalXSDQName, NamespaceContext nsc) { + return _parseQName(lexicalXSDQName, nsc); + } + + /** + * @return null if fails to convert. + */ + public static QName _parseQName(CharSequence text, NamespaceContext nsc) { + int length = text.length(); + + // trim whitespace + int start = 0; + while (start < length && WhiteSpaceProcessor.isWhiteSpace(text.charAt(start))) { + start++; + } + + int end = length; + while (end > start && WhiteSpaceProcessor.isWhiteSpace(text.charAt(end - 1))) { + end--; + } + + if (end == start) { + throw new IllegalArgumentException("input is empty"); + } + + + String uri; + String localPart; + String prefix; + + // search ':' + int idx = start + 1; // no point in searching the first char. that's not valid. + while (idx < end && text.charAt(idx) != ':') { + idx++; + } + + if (idx == end) { + uri = nsc.getNamespaceURI(""); + localPart = text.subSequence(start, end).toString(); + prefix = ""; + } else { + // Prefix exists, check everything + prefix = text.subSequence(start, idx).toString(); + localPart = text.subSequence(idx + 1, end).toString(); + uri = nsc.getNamespaceURI(prefix); + // uri can never be null according to javadoc, + // but some users reported that there are implementations that return null. + if (uri == null || uri.length() == 0) // crap. the NamespaceContext interface is broken. + // error: unbound prefix + { + throw new IllegalArgumentException("prefix " + prefix + " is not bound to a namespace"); + } + } + + return new QName(uri, localPart, prefix); + } + + public Calendar parseDateTime(String lexicalXSDDateTime) { + return _parseDateTime(lexicalXSDDateTime); + } + + public static GregorianCalendar _parseDateTime(CharSequence s) { + String val = WhiteSpaceProcessor.trim(s).toString(); + return datatypeFactory.newXMLGregorianCalendar(val).toGregorianCalendar(); + } + + public String printDateTime(Calendar val) { + return _printDateTime(val); + } + + public static String _printDateTime(Calendar val) { + return CalendarFormatter.doFormat("%Y-%M-%DT%h:%m:%s%z", val); + } + + public byte[] parseBase64Binary(String lexicalXSDBase64Binary) { + return _parseBase64Binary(lexicalXSDBase64Binary); + } + + public byte[] parseHexBinary(String s) { + final int len = s.length(); + + // "111" is not a valid hex encoding. + if (len % 2 != 0) { + throw new IllegalArgumentException("hexBinary needs to be even-length: " + s); + } + + byte[] out = new byte[len / 2]; + + for (int i = 0; i < len; i += 2) { + int h = hexToBin(s.charAt(i)); + int l = hexToBin(s.charAt(i + 1)); + if (h == -1 || l == -1) { + throw new IllegalArgumentException("contains illegal character for hexBinary: " + s); + } + + out[i / 2] = (byte) (h * 16 + l); + } + + return out; + } + + private static int hexToBin(char ch) { + if ('0' <= ch && ch <= '9') { + return ch - '0'; + } + if ('A' <= ch && ch <= 'F') { + return ch - 'A' + 10; + } + if ('a' <= ch && ch <= 'f') { + return ch - 'a' + 10; + } + return -1; + } + private static final char[] hexCode = "0123456789ABCDEF".toCharArray(); + + public String printHexBinary(byte[] data) { + StringBuilder r = new StringBuilder(data.length * 2); + for (byte b : data) { + r.append(hexCode[(b >> 4) & 0xF]); + r.append(hexCode[(b & 0xF)]); + } + return r.toString(); + } + + public long parseUnsignedInt(String lexicalXSDUnsignedInt) { + return _parseLong(lexicalXSDUnsignedInt); + } + + public String printUnsignedInt(long val) { + return _printLong(val); + } + + public int parseUnsignedShort(String lexicalXSDUnsignedShort) { + return _parseInt(lexicalXSDUnsignedShort); + } + + public Calendar parseTime(String lexicalXSDTime) { + return datatypeFactory.newXMLGregorianCalendar(lexicalXSDTime).toGregorianCalendar(); + } + + public String printTime(Calendar val) { + return CalendarFormatter.doFormat("%h:%m:%s%z", val); + } + + public Calendar parseDate(String lexicalXSDDate) { + return datatypeFactory.newXMLGregorianCalendar(lexicalXSDDate).toGregorianCalendar(); + } + + public String printDate(Calendar val) { + return _printDate(val); + } + + public static String _printDate(Calendar val) { + return CalendarFormatter.doFormat((new StringBuilder("%Y-%M-%D").append("%z")).toString(),val); + } + + public String parseAnySimpleType(String lexicalXSDAnySimpleType) { + return lexicalXSDAnySimpleType; +// return (String)SimpleURType.theInstance._createValue( lexicalXSDAnySimpleType, null ); + } + + public String printString(String val) { +// return StringType.theInstance.convertToLexicalValue( val, null ); + return val; + } + + public String printInt(int val) { + return _printInt(val); + } + + public static String _printInt(int val) { + return String.valueOf(val); + } + + public String printLong(long val) { + return _printLong(val); + } + + public static String _printLong(long val) { + return String.valueOf(val); + } + + public String printDecimal(BigDecimal val) { + return _printDecimal(val); + } + + public static String _printDecimal(BigDecimal val) { + return val.toPlainString(); + } + + public String printDouble(double v) { + return _printDouble(v); + } + + public static String _printDouble(double v) { + if (Double.isNaN(v)) { + return "NaN"; + } + if (v == Double.POSITIVE_INFINITY) { + return "INF"; + } + if (v == Double.NEGATIVE_INFINITY) { + return "-INF"; + } + return String.valueOf(v); + } + + public String printQName(QName val, NamespaceContext nsc) { + return _printQName(val, nsc); + } + + public static String _printQName(QName val, NamespaceContext nsc) { + // Double-check + String qname; + String prefix = nsc.getPrefix(val.getNamespaceURI()); + String localPart = val.getLocalPart(); + + if (prefix == null || prefix.length() == 0) { // be defensive + qname = localPart; + } else { + qname = prefix + ':' + localPart; + } + + return qname; + } + + public String printBase64Binary(byte[] val) { + return _printBase64Binary(val); + } + + public String printUnsignedShort(int val) { + return String.valueOf(val); + } + + public String printAnySimpleType(String val) { + return val; + } + + /** + * Just return the string passed as a parameter but + * installs an instance of this class as the DatatypeConverter + * implementation. Used from static fixed value initializers. + */ + public static String installHook(String s) { + DatatypeConverter.setDatatypeConverter(theInstance); + return s; + } +// base64 decoder + private static final byte[] decodeMap = initDecodeMap(); + private static final byte PADDING = 127; + + private static byte[] initDecodeMap() { + byte[] map = new byte[128]; + int i; + for (i = 0; i < 128; i++) { + map[i] = -1; + } + + for (i = 'A'; i <= 'Z'; i++) { + map[i] = (byte) (i - 'A'); + } + for (i = 'a'; i <= 'z'; i++) { + map[i] = (byte) (i - 'a' + 26); + } + for (i = '0'; i <= '9'; i++) { + map[i] = (byte) (i - '0' + 52); + } + map['+'] = 62; + map['/'] = 63; + map['='] = PADDING; + + return map; + } + + /** + * computes the length of binary data speculatively. + * + *

+ * Our requirement is to create byte[] of the exact length to store the binary data. + * If we do this in a straight-forward way, it takes two passes over the data. + * Experiments show that this is a non-trivial overhead (35% or so is spent on + * the first pass in calculating the length.) + * + *

+ * So the approach here is that we compute the length speculatively, without looking + * at the whole contents. The obtained speculative value is never less than the + * actual length of the binary data, but it may be bigger. So if the speculation + * goes wrong, we'll pay the cost of reallocation and buffer copying. + * + *

+ * If the base64 text is tightly packed with no indentation nor illegal char + * (like what most web services produce), then the speculation of this method + * will be correct, so we get the performance benefit. + */ + private static int guessLength(String text) { + final int len = text.length(); + + // compute the tail '=' chars + int j = len - 1; + for (; j >= 0; j--) { + byte code = decodeMap[text.charAt(j)]; + if (code == PADDING) { + continue; + } + if (code == -1) // most likely this base64 text is indented. go with the upper bound + { + return text.length() / 4 * 3; + } + break; + } + + j++; // text.charAt(j) is now at some base64 char, so +1 to make it the size + int padSize = len - j; + if (padSize > 2) // something is wrong with base64. be safe and go with the upper bound + { + return text.length() / 4 * 3; + } + + // so far this base64 looks like it's unindented tightly packed base64. + // take a chance and create an array with the expected size + return text.length() / 4 * 3 - padSize; + } + + /** + * @param text + * base64Binary data is likely to be long, and decoding requires + * each character to be accessed twice (once for counting length, another + * for decoding.) + * + * A benchmark showed that taking {@link String} is faster, presumably + * because JIT can inline a lot of string access (with data of 1K chars, it was twice as fast) + */ + public static byte[] _parseBase64Binary(String text) { + final int buflen = guessLength(text); + final byte[] out = new byte[buflen]; + int o = 0; + + final int len = text.length(); + int i; + + final byte[] quadruplet = new byte[4]; + int q = 0; + + // convert each quadruplet to three bytes. + for (i = 0; i < len; i++) { + char ch = text.charAt(i); + byte v = decodeMap[ch]; + + if (v != -1) { + quadruplet[q++] = v; + } + + if (q == 4) { + // quadruplet is now filled. + out[o++] = (byte) ((quadruplet[0] << 2) | (quadruplet[1] >> 4)); + if (quadruplet[2] != PADDING) { + out[o++] = (byte) ((quadruplet[1] << 4) | (quadruplet[2] >> 2)); + } + if (quadruplet[3] != PADDING) { + out[o++] = (byte) ((quadruplet[2] << 6) | (quadruplet[3])); + } + q = 0; + } + } + + if (buflen == o) // speculation worked out to be OK + { + return out; + } + + // we overestimated, so need to create a new buffer + byte[] nb = new byte[o]; + System.arraycopy(out, 0, nb, 0, o); + return nb; + } + private static final char[] encodeMap = initEncodeMap(); + + private static char[] initEncodeMap() { + char[] map = new char[64]; + int i; + for (i = 0; i < 26; i++) { + map[i] = (char) ('A' + i); + } + for (i = 26; i < 52; i++) { + map[i] = (char) ('a' + (i - 26)); + } + for (i = 52; i < 62; i++) { + map[i] = (char) ('0' + (i - 52)); + } + map[62] = '+'; + map[63] = '/'; + + return map; + } + + public static char encode(int i) { + return encodeMap[i & 0x3F]; + } + + public static byte encodeByte(int i) { + return (byte) encodeMap[i & 0x3F]; + } + + public static String _printBase64Binary(byte[] input) { + return _printBase64Binary(input, 0, input.length); + } + + public static String _printBase64Binary(byte[] input, int offset, int len) { + char[] buf = new char[((len + 2) / 3) * 4]; + int ptr = _printBase64Binary(input, offset, len, buf, 0); + assert ptr == buf.length; + return new String(buf); + } + + /** + * Encodes a byte array into a char array by doing base64 encoding. + * + * The caller must supply a big enough buffer. + * + * @return + * the value of {@code ptr+((len+2)/3)*4}, which is the new offset + * in the output buffer where the further bytes should be placed. + */ + public static int _printBase64Binary(byte[] input, int offset, int len, char[] buf, int ptr) { + // encode elements until only 1 or 2 elements are left to encode + int remaining = len; + int i; + for (i = offset;remaining >= 3; remaining -= 3, i += 3) { + buf[ptr++] = encode(input[i] >> 2); + buf[ptr++] = encode( + ((input[i] & 0x3) << 4) + | ((input[i + 1] >> 4) & 0xF)); + buf[ptr++] = encode( + ((input[i + 1] & 0xF) << 2) + | ((input[i + 2] >> 6) & 0x3)); + buf[ptr++] = encode(input[i + 2] & 0x3F); + } + // encode when exactly 1 element (left) to encode + if (remaining == 1) { + buf[ptr++] = encode(input[i] >> 2); + buf[ptr++] = encode(((input[i]) & 0x3) << 4); + buf[ptr++] = '='; + buf[ptr++] = '='; + } + // encode when exactly 2 elements (left) to encode + if (remaining == 2) { + buf[ptr++] = encode(input[i] >> 2); + buf[ptr++] = encode(((input[i] & 0x3) << 4) + | ((input[i + 1] >> 4) & 0xF)); + buf[ptr++] = encode((input[i + 1] & 0xF) << 2); + buf[ptr++] = '='; + } + return ptr; + } + + /** + * Encodes a byte array into another byte array by first doing base64 encoding + * then encoding the result in ASCII. + * + * The caller must supply a big enough buffer. + * + * @return + * the value of {@code ptr+((len+2)/3)*4}, which is the new offset + * in the output buffer where the further bytes should be placed. + */ + public static int _printBase64Binary(byte[] input, int offset, int len, byte[] out, int ptr) { + byte[] buf = out; + int remaining = len; + int i; + for (i=offset; remaining >= 3; remaining -= 3, i += 3 ) { + buf[ptr++] = encodeByte(input[i]>>2); + buf[ptr++] = encodeByte( + ((input[i]&0x3)<<4) | + ((input[i+1]>>4)&0xF)); + buf[ptr++] = encodeByte( + ((input[i+1]&0xF)<<2)| + ((input[i+2]>>6)&0x3)); + buf[ptr++] = encodeByte(input[i+2]&0x3F); + } + // encode when exactly 1 element (left) to encode + if (remaining == 1) { + buf[ptr++] = encodeByte(input[i]>>2); + buf[ptr++] = encodeByte(((input[i])&0x3)<<4); + buf[ptr++] = '='; + buf[ptr++] = '='; + } + // encode when exactly 2 elements (left) to encode + if (remaining == 2) { + buf[ptr++] = encodeByte(input[i]>>2); + buf[ptr++] = encodeByte( + ((input[i]&0x3)<<4) | + ((input[i+1]>>4)&0xF)); + buf[ptr++] = encodeByte((input[i+1]&0xF)<<2); + buf[ptr++] = '='; + } + + return ptr; + } + + private static CharSequence removeOptionalPlus(CharSequence s) { + int len = s.length(); + + if (len <= 1 || s.charAt(0) != '+') { + return s; + } + + s = s.subSequence(1, len); + char ch = s.charAt(0); + if ('0' <= ch && ch <= '9') { + return s; + } + if ('.' == ch) { + return s; + } + + throw new NumberFormatException(); + } + + private static boolean isDigitOrPeriodOrSign(char ch) { + if ('0' <= ch && ch <= '9') { + return true; + } + if (ch == '+' || ch == '-' || ch == '.') { + return true; + } + return false; + } + private static final DatatypeFactory datatypeFactory; + + static { + try { + datatypeFactory = DatatypeFactory.newInstance(); + } catch (DatatypeConfigurationException e) { + throw new Error(e); + } + } + + private static final class CalendarFormatter { + + public static String doFormat(String format, Calendar cal) throws IllegalArgumentException { + int fidx = 0; + int flen = format.length(); + StringBuilder buf = new StringBuilder(); + + while (fidx < flen) { + char fch = format.charAt(fidx++); + + if (fch != '%') { // not a meta character + buf.append(fch); + continue; + } + + // seen meta character. we don't do error check against the format + switch (format.charAt(fidx++)) { + case 'Y': // year + formatYear(cal, buf); + break; + + case 'M': // month + formatMonth(cal, buf); + break; + + case 'D': // days + formatDays(cal, buf); + break; + + case 'h': // hours + formatHours(cal, buf); + break; + + case 'm': // minutes + formatMinutes(cal, buf); + break; + + case 's': // parse seconds. + formatSeconds(cal, buf); + break; + + case 'z': // time zone + formatTimeZone(cal, buf); + break; + + default: + // illegal meta character. impossible. + throw new InternalError(); + } + } + + return buf.toString(); + } + + private static void formatYear(Calendar cal, StringBuilder buf) { + int year = cal.get(Calendar.YEAR); + + String s; + if (year <= 0) // negative value + { + s = Integer.toString(1 - year); + } else // positive value + { + s = Integer.toString(year); + } + + while (s.length() < 4) { + s = '0' + s; + } + if (year <= 0) { + s = '-' + s; + } + + buf.append(s); + } + + private static void formatMonth(Calendar cal, StringBuilder buf) { + formatTwoDigits(cal.get(Calendar.MONTH) + 1, buf); + } + + private static void formatDays(Calendar cal, StringBuilder buf) { + formatTwoDigits(cal.get(Calendar.DAY_OF_MONTH), buf); + } + + private static void formatHours(Calendar cal, StringBuilder buf) { + formatTwoDigits(cal.get(Calendar.HOUR_OF_DAY), buf); + } + + private static void formatMinutes(Calendar cal, StringBuilder buf) { + formatTwoDigits(cal.get(Calendar.MINUTE), buf); + } + + private static void formatSeconds(Calendar cal, StringBuilder buf) { + formatTwoDigits(cal.get(Calendar.SECOND), buf); + if (cal.isSet(Calendar.MILLISECOND)) { // milliseconds + int n = cal.get(Calendar.MILLISECOND); + if (n != 0) { + String ms = Integer.toString(n); + while (ms.length() < 3) { + ms = '0' + ms; // left 0 paddings. + } + buf.append('.'); + buf.append(ms); + } + } + } + + /** formats time zone specifier. */ + private static void formatTimeZone(Calendar cal, StringBuilder buf) { + TimeZone tz = cal.getTimeZone(); + + if (tz == null) { + return; + } + + // otherwise print out normally. + int offset = tz.getOffset(cal.getTime().getTime()); + + if (offset == 0) { + buf.append('Z'); + return; + } + + if (offset >= 0) { + buf.append('+'); + } else { + buf.append('-'); + offset *= -1; + } + + offset /= 60 * 1000; // offset is in milli-seconds + + formatTwoDigits(offset / 60, buf); + buf.append(':'); + formatTwoDigits(offset % 60, buf); + } + + /** formats Integer into two-character-wide string. */ + private static void formatTwoDigits(int n, StringBuilder buf) { + // n is always non-negative. + if (n < 10) { + buf.append('0'); + } + buf.append(n); + } + } +} diff --git a/fine-third-jdk11/src/javax/xml/bind/DatatypeConverterInterface.java b/fine-third-jdk11/src/javax/xml/bind/DatatypeConverterInterface.java new file mode 100644 index 000000000..0a301b4e6 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/DatatypeConverterInterface.java @@ -0,0 +1,499 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +/** + *

+ * The DatatypeConverterInterface is for JAXB provider use only. A + * JAXB provider must supply a class that implements this interface. + * JAXB Providers are required to call the + * {@link DatatypeConverter#setDatatypeConverter(DatatypeConverterInterface) + * DatatypeConverter.setDatatypeConverter} api at + * some point before the first marshal or unmarshal operation (perhaps during + * the call to JAXBContext.newInstance). This step is necessary to configure + * the converter that should be used to perform the print and parse + * functionality. Calling this api repeatedly will have no effect - the + * DatatypeConverter instance passed into the first invocation is the one that + * will be used from then on. + * + *

+ * This interface defines the parse and print methods. There is one + * parse and print method for each XML schema datatype specified in the + * the default binding Table 5-1 in the JAXB specification. + * + *

+ * The parse and print methods defined here are invoked by the static parse + * and print methods defined in the {@link DatatypeConverter DatatypeConverter} + * class. + * + *

+ * A parse method for a XML schema datatype must be capable of converting any + * lexical representation of the XML schema datatype ( specified by the + * XML Schema Part2: Datatypes + * specification into a value in the value space of the XML schema datatype. + * If an error is encountered during conversion, then an IllegalArgumentException + * or a subclass of IllegalArgumentException must be thrown by the method. + * + *

+ * A print method for a XML schema datatype can output any lexical + * representation that is valid with respect to the XML schema datatype. + * If an error is encountered during conversion, then an IllegalArgumentException, + * or a subclass of IllegalArgumentException must be thrown by the method. + * + *

+ * The prefix xsd: is used to refer to XML schema datatypes + * XML Schema Part2: Datatypes + * specification. + * + * @author

    + *
  • Sekhar Vajjhala, Sun Microsystems, Inc.
  • + *
  • Joe Fialli, Sun Microsystems Inc.
  • + *
  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • + *
  • Ryan Shoemaker,Sun Microsystems Inc.
  • + *
+ * @see DatatypeConverter + * @see ParseConversionEvent + * @see PrintConversionEvent + * @since 1.6, JAXB 1.0 + */ + +public interface DatatypeConverterInterface { + /** + * Convert the string argument into a string. + * @param lexicalXSDString + * A lexical representation of the XML Schema datatype xsd:string + * @return + * A string that is the same as the input string. + */ + public String parseString( String lexicalXSDString ); + + /** + * Convert the string argument into a BigInteger value. + * @param lexicalXSDInteger + * A string containing a lexical representation of + * xsd:integer. + * @return + * A BigInteger value represented by the string argument. + * @throws NumberFormatException {@code lexicalXSDInteger} is not a valid string representation of a {@link java.math.BigInteger} value. + */ + public java.math.BigInteger parseInteger( String lexicalXSDInteger ); + + /** + * Convert the string argument into an int value. + * @param lexicalXSDInt + * A string containing a lexical representation of + * xsd:int. + * @return + * An int value represented byte the string argument. + * @throws NumberFormatException {@code lexicalXSDInt} is not a valid string representation of an {@code int} value. + */ + public int parseInt( String lexicalXSDInt ); + + /** + * Converts the string argument into a long value. + * @param lexicalXSDLong + * A string containing lexical representation of + * xsd:long. + * @return + * A long value represented by the string argument. + * @throws NumberFormatException {@code lexicalXSDLong} is not a valid string representation of a {@code long} value. + */ + public long parseLong( String lexicalXSDLong ); + + /** + * Converts the string argument into a short value. + * @param lexicalXSDShort + * A string containing lexical representation of + * xsd:short. + * @return + * A short value represented by the string argument. + * @throws NumberFormatException {@code lexicalXSDShort} is not a valid string representation of a {@code short} value. + */ + public short parseShort( String lexicalXSDShort ); + + /** + * Converts the string argument into a BigDecimal value. + * @param lexicalXSDDecimal + * A string containing lexical representation of + * xsd:decimal. + * @return + * A BigDecimal value represented by the string argument. + * @throws NumberFormatException {@code lexicalXSDDecimal} is not a valid string representation of {@link java.math.BigDecimal}. + */ + public java.math.BigDecimal parseDecimal( String lexicalXSDDecimal ); + + /** + * Converts the string argument into a float value. + * @param lexicalXSDFloat + * A string containing lexical representation of + * xsd:float. + * @return + * A float value represented by the string argument. + * @throws NumberFormatException {@code lexicalXSDFloat} is not a valid string representation of a {@code float} value. + */ + public float parseFloat( String lexicalXSDFloat ); + + /** + * Converts the string argument into a double value. + * @param lexicalXSDDouble + * A string containing lexical representation of + * xsd:double. + * @return + * A double value represented by the string argument. + * @throws NumberFormatException {@code lexicalXSDDouble} is not a valid string representation of a {@code double} value. + */ + public double parseDouble( String lexicalXSDDouble ); + + /** + * Converts the string argument into a boolean value. + * @param lexicalXSDBoolean + * A string containing lexical representation of + * xsd:boolean. + * @return + * A boolean value represented by the string argument. + * @throws IllegalArgumentException if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:boolean. + */ + public boolean parseBoolean( String lexicalXSDBoolean ); + + /** + * Converts the string argument into a byte value. + * @param lexicalXSDByte + * A string containing lexical representation of + * xsd:byte. + * @return + * A byte value represented by the string argument. + * @throws NumberFormatException {@code lexicalXSDByte} does not contain a parseable byte. + * @throws IllegalArgumentException if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:byte. + */ + public byte parseByte( String lexicalXSDByte ); + + /** + * Converts the string argument into a QName value. + * + *

+ * String parameter {@code lexicalXSDQname} must conform to lexical value space specifed at + * XML Schema Part 2:Datatypes specification:QNames + * + * @param lexicalXSDQName + * A string containing lexical representation of xsd:QName. + * @param nsc + * A namespace context for interpreting a prefix within a QName. + * @return + * A QName value represented by the string argument. + * @throws IllegalArgumentException if string parameter does not conform to XML Schema Part 2 specification or + * if namespace prefix of {@code lexicalXSDQname} is not bound to a URI in NamespaceContext {@code nsc}. + */ + public javax.xml.namespace.QName parseQName( String lexicalXSDQName, + javax.xml.namespace.NamespaceContext nsc); + + /** + * Converts the string argument into a Calendar value. + * @param lexicalXSDDateTime + * A string containing lexical representation of + * xsd:datetime. + * @return + * A Calendar object represented by the string argument. + * @throws IllegalArgumentException if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:dateTime. + */ + public java.util.Calendar parseDateTime( String lexicalXSDDateTime ); + + /** + * Converts the string argument into an array of bytes. + * @param lexicalXSDBase64Binary + * A string containing lexical representation + * of xsd:base64Binary. + * @return + * An array of bytes represented by the string argument. + * @throws IllegalArgumentException if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:base64Binary + */ + public byte[] parseBase64Binary( String lexicalXSDBase64Binary ); + + /** + * Converts the string argument into an array of bytes. + * @param lexicalXSDHexBinary + * A string containing lexical representation of + * xsd:hexBinary. + * @return + * An array of bytes represented by the string argument. + * @throws IllegalArgumentException if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:hexBinary. + */ + public byte[] parseHexBinary( String lexicalXSDHexBinary ); + + /** + * Converts the string argument into a long value. + * @param lexicalXSDUnsignedInt + * A string containing lexical representation + * of xsd:unsignedInt. + * @return + * A long value represented by the string argument. + * @throws NumberFormatException if string parameter can not be parsed into a {@code long} value. + */ + public long parseUnsignedInt( String lexicalXSDUnsignedInt ); + + /** + * Converts the string argument into an int value. + * @param lexicalXSDUnsignedShort + * A string containing lexical + * representation of xsd:unsignedShort. + * @return + * An int value represented by the string argument. + * @throws NumberFormatException if string parameter can not be parsed into an {@code int} value. + */ + public int parseUnsignedShort( String lexicalXSDUnsignedShort ); + + /** + * Converts the string argument into a Calendar value. + * @param lexicalXSDTime + * A string containing lexical representation of + * xsd:Time. + * @return + * A Calendar value represented by the string argument. + * @throws IllegalArgumentException if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:Time. + */ + public java.util.Calendar parseTime( String lexicalXSDTime ); + + /** + * Converts the string argument into a Calendar value. + * @param lexicalXSDDate + * A string containing lexical representation of + * xsd:Date. + * @return + * A Calendar value represented by the string argument. + * @throws IllegalArgumentException if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:Date. + */ + public java.util.Calendar parseDate( String lexicalXSDDate ); + + /** + * Return a string containing the lexical representation of the + * simple type. + * @param lexicalXSDAnySimpleType + * A string containing lexical + * representation of the simple type. + * @return + * A string containing the lexical representation of the + * simple type. + */ + public String parseAnySimpleType( String lexicalXSDAnySimpleType ); + + /** + * Converts the string argument into a string. + * @param val + * A string value. + * @return + * A string containing a lexical representation of xsd:string + */ + public String printString( String val ); + + /** + * Converts a BigInteger value into a string. + * @param val + * A BigInteger value + * @return + * A string containing a lexical representation of xsd:integer + * @throws IllegalArgumentException {@code val} is null. + */ + public String printInteger( java.math.BigInteger val ); + + /** + * Converts an int value into a string. + * @param val + * An int value + * @return + * A string containing a lexical representation of xsd:int + */ + public String printInt( int val ); + + + /** + * Converts a long value into a string. + * @param val + * A long value + * @return + * A string containing a lexical representation of xsd:long + */ + public String printLong( long val ); + + /** + * Converts a short value into a string. + * @param val + * A short value + * @return + * A string containing a lexical representation of xsd:short + */ + public String printShort( short val ); + + /** + * Converts a BigDecimal value into a string. + * @param val + * A BigDecimal value + * @return + * A string containing a lexical representation of xsd:decimal + * @throws IllegalArgumentException {@code val} is null. + */ + public String printDecimal( java.math.BigDecimal val ); + + /** + * Converts a float value into a string. + * @param val + * A float value + * @return + * A string containing a lexical representation of xsd:float + */ + public String printFloat( float val ); + + /** + * Converts a double value into a string. + * @param val + * A double value + * @return + * A string containing a lexical representation of xsd:double + */ + public String printDouble( double val ); + + /** + * Converts a boolean value into a string. + * @param val + * A boolean value + * @return + * A string containing a lexical representation of xsd:boolean + */ + public String printBoolean( boolean val ); + + /** + * Converts a byte value into a string. + * @param val + * A byte value + * @return + * A string containing a lexical representation of xsd:byte + */ + public String printByte( byte val ); + + /** + * Converts a QName instance into a string. + * @param val + * A QName value + * @param nsc + * A namespace context for interpreting a prefix within a QName. + * @return + * A string containing a lexical representation of QName + * @throws IllegalArgumentException if {@code val} is null or + * if {@code nsc} is non-null or {@code nsc.getPrefix(nsprefixFromVal)} is null. + */ + public String printQName( javax.xml.namespace.QName val, + javax.xml.namespace.NamespaceContext nsc ); + + /** + * Converts a Calendar value into a string. + * @param val + * A Calendar value + * @return + * A string containing a lexical representation of xsd:dateTime + * @throws IllegalArgumentException if {@code val} is null. + */ + public String printDateTime( java.util.Calendar val ); + + /** + * Converts an array of bytes into a string. + * @param val + * an array of bytes + * @return + * A string containing a lexical representation of xsd:base64Binary + * @throws IllegalArgumentException if {@code val} is null. + */ + public String printBase64Binary( byte[] val ); + + /** + * Converts an array of bytes into a string. + * @param val + * an array of bytes + * @return + * A string containing a lexical representation of xsd:hexBinary + * @throws IllegalArgumentException if {@code val} is null. + */ + public String printHexBinary( byte[] val ); + + /** + * Converts a long value into a string. + * @param val + * A long value + * @return + * A string containing a lexical representation of xsd:unsignedInt + */ + public String printUnsignedInt( long val ); + + /** + * Converts an int value into a string. + * @param val + * An int value + * @return + * A string containing a lexical representation of xsd:unsignedShort + */ + public String printUnsignedShort( int val ); + + /** + * Converts a Calendar value into a string. + * @param val + * A Calendar value + * @return + * A string containing a lexical representation of xsd:time + * @throws IllegalArgumentException if {@code val} is null. + */ + public String printTime( java.util.Calendar val ); + + /** + * Converts a Calendar value into a string. + * @param val + * A Calendar value + * @return + * A string containing a lexical representation of xsd:date + * @throws IllegalArgumentException if {@code val} is null. + */ + public String printDate( java.util.Calendar val ); + + /** + * Converts a string value into a string. + * @param val + * A string value + * @return + * A string containing a lexical representation of xsd:AnySimpleType + */ + public String printAnySimpleType( String val ); +} diff --git a/fine-third-jdk11/src/javax/xml/bind/Element.java b/fine-third-jdk11/src/javax/xml/bind/Element.java new file mode 100644 index 000000000..7671b2abb --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/Element.java @@ -0,0 +1,57 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +/** + * This is an element marker interface. + * + * Under certain circumstances, it is necessary for the binding compiler to + * generate derived java content classes that implement this interface. In + * those cases, client applications must supply element instances rather than + * types of elements. For more detail, see section 5.7 "Element Declaration" + * and 5.7.1 "Bind to Java Element Interface" of the specification. + * + * @author

  • Ryan Shoemaker, Sun Microsystems, Inc.
  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • Joe Fialli, Sun Microsystems, Inc.
+ * @since 1.6, JAXB 1.0 + */ + +public interface Element { +} diff --git a/fine-third-jdk11/src/javax/xml/bind/GetPropertyAction.java b/fine-third-jdk11/src/javax/xml/bind/GetPropertyAction.java new file mode 100644 index 000000000..064f0d4f8 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/GetPropertyAction.java @@ -0,0 +1,59 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2006-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +import java.security.PrivilegedAction; + +/** + * {@link PrivilegedAction} that gets the system property value. + * @author Kohsuke Kawaguchi + */ +final class GetPropertyAction implements PrivilegedAction { + private final String propertyName; + + public GetPropertyAction(String propertyName) { + this.propertyName = propertyName; + } + + public String run() { + return System.getProperty(propertyName); + } +} diff --git a/fine-third-jdk11/src/javax/xml/bind/JAXB.java b/fine-third-jdk11/src/javax/xml/bind/JAXB.java new file mode 100644 index 000000000..196060b68 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/JAXB.java @@ -0,0 +1,644 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2006-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.namespace.QName; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import java.beans.Introspector; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Reader; +import java.io.Writer; +import java.lang.ref.WeakReference; +import java.net.HttpURLConnection; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLConnection; + +/** + * Class that defines convenience methods for common, simple use of JAXB. + * + *

+ * Methods defined in this class are convenience methods that combine several basic operations + * in the {@link JAXBContext}, {@link Unmarshaller}, and {@link Marshaller}. + * + * They are designed + * to be the prefered methods for developers new to JAXB. They have + * the following characterstics: + * + *

    + *
  1. Generally speaking, the performance is not necessarily optimal. + * It is expected that people who need to write performance + * critical code will use the rest of the JAXB API directly. + *
  2. Errors that happen during the processing is wrapped into + * {@link DataBindingException} (which will have {@link JAXBException} + * as its {@link Throwable#getCause() cause}. It is expected that + * people who prefer the checked exception would use + * the rest of the JAXB API directly. + *
+ * + *

+ * In addition, the {@code unmarshal} methods have the following characteristic: + * + *

    + *
  1. Schema validation is not performed on the input XML. + * The processing will try to continue even if there + * are errors in the XML, as much as possible. Only as + * the last resort, this method fails with {@link DataBindingException}. + *
+ * + *

+ * Similarly, the {@code marshal} methods have the following characteristic: + *

    + *
  1. The processing will try to continue even if the Java object tree + * does not meet the validity requirement. Only as + * the last resort, this method fails with {@link DataBindingException}. + *
+ * + * + *

+ * All the methods on this class require non-null arguments to all parameters. + * The {@code unmarshal} methods either fail with an exception or return + * a non-null value. + * + * @author Kohsuke Kawaguchi + * @since 1.6, JAXB 2.1 + */ +public final class JAXB { + /** + * No instanciation is allowed. + */ + private JAXB() {} + + /** + * To improve the performance, we'll cache the last {@link JAXBContext} used. + */ + private static final class Cache { + final Class type; + final JAXBContext context; + + public Cache(Class type) throws JAXBException { + this.type = type; + this.context = JAXBContext.newInstance(type); + } + } + + /** + * Cache. We don't want to prevent the {@link Cache#type} from GC-ed, + * hence {@link WeakReference}. + */ + private static volatile WeakReference cache; + + /** + * Obtains the {@link JAXBContext} from the given type, + * by using the cache if possible. + * + *

+ * We don't use locks to control access to {@link #cache}, but this code + * should be thread-safe thanks to the immutable {@link Cache} and {@code volatile}. + */ + private static JAXBContext getContext(Class type) throws JAXBException { + WeakReference c = cache; + if(c!=null) { + Cache d = c.get(); + if(d!=null && d.type==type) + return d.context; + } + + // overwrite the cache + Cache d = new Cache(type); + cache = new WeakReference(d); + + return d.context; + } + + /** + * Reads in a Java object tree from the given XML input. + * + * @param xml + * Reads the entire file as XML. + */ + public static T unmarshal( File xml, Class type ) { + try { + JAXBElement item = getContext(type).createUnmarshaller().unmarshal(new StreamSource(xml), type); + return item.getValue(); + } catch (JAXBException e) { + throw new DataBindingException(e); + } + } + + /** + * Reads in a Java object tree from the given XML input. + * + * @param xml + * The resource pointed by the URL is read in its entirety. + */ + public static T unmarshal( URL xml, Class type ) { + try { + JAXBElement item = getContext(type).createUnmarshaller().unmarshal(toSource(xml), type); + return item.getValue(); + } catch (JAXBException e) { + throw new DataBindingException(e); + } catch (IOException e) { + throw new DataBindingException(e); + } + } + + /** + * Reads in a Java object tree from the given XML input. + * + * @param xml + * The URI is {@link URI#toURL() turned into URL} and then + * follows the handling of {@code URL}. + */ + public static T unmarshal( URI xml, Class type ) { + try { + JAXBElement item = getContext(type).createUnmarshaller().unmarshal(toSource(xml), type); + return item.getValue(); + } catch (JAXBException e) { + throw new DataBindingException(e); + } catch (IOException e) { + throw new DataBindingException(e); + } + } + + /** + * Reads in a Java object tree from the given XML input. + * + * @param xml + * The string is first interpreted as an absolute {@code URI}. + * If it's not {@link URI#isAbsolute() a valid absolute URI}, + * then it's interpreted as a {@code File} + */ + public static T unmarshal( String xml, Class type ) { + try { + JAXBElement item = getContext(type).createUnmarshaller().unmarshal(toSource(xml), type); + return item.getValue(); + } catch (JAXBException e) { + throw new DataBindingException(e); + } catch (IOException e) { + throw new DataBindingException(e); + } + } + + /** + * Reads in a Java object tree from the given XML input. + * + * @param xml + * The entire stream is read as an XML infoset. + * Upon a successful completion, the stream will be closed by this method. + */ + public static T unmarshal( InputStream xml, Class type ) { + try { + JAXBElement item = getContext(type).createUnmarshaller().unmarshal(toSource(xml), type); + return item.getValue(); + } catch (JAXBException e) { + throw new DataBindingException(e); + } catch (IOException e) { + throw new DataBindingException(e); + } + } + + /** + * Reads in a Java object tree from the given XML input. + * + * @param xml + * The character stream is read as an XML infoset. + * The encoding declaration in the XML will be ignored. + * Upon a successful completion, the stream will be closed by this method. + */ + public static T unmarshal( Reader xml, Class type ) { + try { + JAXBElement item = getContext(type).createUnmarshaller().unmarshal(toSource(xml), type); + return item.getValue(); + } catch (JAXBException e) { + throw new DataBindingException(e); + } catch (IOException e) { + throw new DataBindingException(e); + } + } + + /** + * Reads in a Java object tree from the given XML input. + * + * @param xml + * The XML infoset that the {@link Source} represents is read. + */ + public static T unmarshal( Source xml, Class type ) { + try { + JAXBElement item = getContext(type).createUnmarshaller().unmarshal(toSource(xml), type); + return item.getValue(); + } catch (JAXBException e) { + throw new DataBindingException(e); + } catch (IOException e) { + throw new DataBindingException(e); + } + } + + + + /** + * Creates {@link Source} from various XML representation. + * See {@link #unmarshal} for the conversion rules. + */ + private static Source toSource(Object xml) throws IOException { + if(xml==null) + throw new IllegalArgumentException("no XML is given"); + + if (xml instanceof String) { + try { + xml=new URI((String)xml); + } catch (URISyntaxException e) { + xml=new File((String)xml); + } + } + if (xml instanceof File) { + File file = (File) xml; + return new StreamSource(file); + } + if (xml instanceof URI) { + URI uri = (URI) xml; + xml=uri.toURL(); + } + if (xml instanceof URL) { + URL url = (URL) xml; + return new StreamSource(url.toExternalForm()); + } + if (xml instanceof InputStream) { + InputStream in = (InputStream) xml; + return new StreamSource(in); + } + if (xml instanceof Reader) { + Reader r = (Reader) xml; + return new StreamSource(r); + } + if (xml instanceof Source) { + return (Source) xml; + } + throw new IllegalArgumentException("I don't understand how to handle "+xml.getClass()); + } + + /** + * Writes a Java object tree to XML and store it to the specified location. + * + * @param jaxbObject + * The Java object to be marshalled into XML. If this object is + * a {@link JAXBElement}, it will provide the root tag name and + * the body. If this object has {@link XmlRootElement} + * on its class definition, that will be used as the root tag name + * and the given object will provide the body. Otherwise, + * the root tag name is {@link Introspector#decapitalize(String) infered} from + * {@link Class#getSimpleName() the short class name}. + * This parameter must not be null. + * + * @param xml + * XML will be written to this file. If it already exists, + * it will be overwritten. + * + * @throws DataBindingException + * If the operation fails, such as due to I/O error, unbindable classes. + */ + public static void marshal( Object jaxbObject, File xml ) { + _marshal(jaxbObject,xml); + } + + /** + * Writes a Java object tree to XML and store it to the specified location. + * + * @param jaxbObject + * The Java object to be marshalled into XML. If this object is + * a {@link JAXBElement}, it will provide the root tag name and + * the body. If this object has {@link XmlRootElement} + * on its class definition, that will be used as the root tag name + * and the given object will provide the body. Otherwise, + * the root tag name is {@link Introspector#decapitalize(String) infered} from + * {@link Class#getSimpleName() the short class name}. + * This parameter must not be null. + * + * @param xml + * The XML will be {@link URLConnection#getOutputStream() sent} to the + * resource pointed by this URL. Note that not all {@code URL}s support + * such operation, and exact semantics depends on the {@code URL} + * implementations. In case of {@link HttpURLConnection HTTP URLs}, + * this will perform HTTP POST. + * + * @throws DataBindingException + * If the operation fails, such as due to I/O error, unbindable classes. + */ + public static void marshal( Object jaxbObject, URL xml ) { + _marshal(jaxbObject,xml); + } + + /** + * Writes a Java object tree to XML and store it to the specified location. + * + * @param jaxbObject + * The Java object to be marshalled into XML. If this object is + * a {@link JAXBElement}, it will provide the root tag name and + * the body. If this object has {@link XmlRootElement} + * on its class definition, that will be used as the root tag name + * and the given object will provide the body. Otherwise, + * the root tag name is {@link Introspector#decapitalize(String) infered} from + * {@link Class#getSimpleName() the short class name}. + * This parameter must not be null. + * + * @param xml + * The URI is {@link URI#toURL() turned into URL} and then + * follows the handling of {@code URL}. See above. + * + * @throws DataBindingException + * If the operation fails, such as due to I/O error, unbindable classes. + */ + public static void marshal( Object jaxbObject, URI xml ) { + _marshal(jaxbObject,xml); + } + + /** + * Writes a Java object tree to XML and store it to the specified location. + * + * @param jaxbObject + * The Java object to be marshalled into XML. If this object is + * a {@link JAXBElement}, it will provide the root tag name and + * the body. If this object has {@link XmlRootElement} + * on its class definition, that will be used as the root tag name + * and the given object will provide the body. Otherwise, + * the root tag name is {@link Introspector#decapitalize(String) infered} from + * {@link Class#getSimpleName() the short class name}. + * This parameter must not be null. + * + * @param xml + * The string is first interpreted as an absolute {@code URI}. + * If it's not {@link URI#isAbsolute() a valid absolute URI}, + * then it's interpreted as a {@code File} + * + * @throws DataBindingException + * If the operation fails, such as due to I/O error, unbindable classes. + */ + public static void marshal( Object jaxbObject, String xml ) { + _marshal(jaxbObject,xml); + } + + /** + * Writes a Java object tree to XML and store it to the specified location. + * + * @param jaxbObject + * The Java object to be marshalled into XML. If this object is + * a {@link JAXBElement}, it will provide the root tag name and + * the body. If this object has {@link XmlRootElement} + * on its class definition, that will be used as the root tag name + * and the given object will provide the body. Otherwise, + * the root tag name is {@link Introspector#decapitalize(String) infered} from + * {@link Class#getSimpleName() the short class name}. + * This parameter must not be null. + * + * @param xml + * The XML will be sent to the given {@link OutputStream}. + * Upon a successful completion, the stream will be closed by this method. + * + * @throws DataBindingException + * If the operation fails, such as due to I/O error, unbindable classes. + */ + public static void marshal( Object jaxbObject, OutputStream xml ) { + _marshal(jaxbObject,xml); + } + + /** + * Writes a Java object tree to XML and store it to the specified location. + * + * @param jaxbObject + * The Java object to be marshalled into XML. If this object is + * a {@link JAXBElement}, it will provide the root tag name and + * the body. If this object has {@link XmlRootElement} + * on its class definition, that will be used as the root tag name + * and the given object will provide the body. Otherwise, + * the root tag name is {@link Introspector#decapitalize(String) infered} from + * {@link Class#getSimpleName() the short class name}. + * This parameter must not be null. + * + * @param xml + * The XML will be sent as a character stream to the given {@link Writer}. + * Upon a successful completion, the stream will be closed by this method. + * + * @throws DataBindingException + * If the operation fails, such as due to I/O error, unbindable classes. + */ + public static void marshal( Object jaxbObject, Writer xml ) { + _marshal(jaxbObject,xml); + } + + /** + * Writes a Java object tree to XML and store it to the specified location. + * + * @param jaxbObject + * The Java object to be marshalled into XML. If this object is + * a {@link JAXBElement}, it will provide the root tag name and + * the body. If this object has {@link XmlRootElement} + * on its class definition, that will be used as the root tag name + * and the given object will provide the body. Otherwise, + * the root tag name is {@link Introspector#decapitalize(String) infered} from + * {@link Class#getSimpleName() the short class name}. + * This parameter must not be null. + * + * @param xml + * The XML will be sent to the {@link Result} object. + * + * @throws DataBindingException + * If the operation fails, such as due to I/O error, unbindable classes. + */ + public static void marshal( Object jaxbObject, Result xml ) { + _marshal(jaxbObject,xml); + } + + /** + * Writes a Java object tree to XML and store it to the specified location. + * + *

+ * This method is a convenience method that combines several basic operations + * in the {@link JAXBContext} and {@link Marshaller}. This method is designed + * to be the prefered method for developers new to JAXB. This method + * has the following characterstics: + * + *

    + *
  1. Generally speaking, the performance is not necessarily optimal. + * It is expected that those people who need to write performance + * critical code will use the rest of the JAXB API directly. + *
  2. Errors that happen during the processing is wrapped into + * {@link DataBindingException} (which will have {@link JAXBException} + * as its {@link Throwable#getCause() cause}. It is expected that + * those people who prefer the checked exception would use + * the rest of the JAXB API directly. + *
+ * + * @param jaxbObject + * The Java object to be marshalled into XML. If this object is + * a {@link JAXBElement}, it will provide the root tag name and + * the body. If this object has {@link XmlRootElement} + * on its class definition, that will be used as the root tag name + * and the given object will provide the body. Otherwise, + * the root tag name is {@link Introspector#decapitalize(String) infered} from + * {@link Class#getSimpleName() the short class name}. + * This parameter must not be null. + * + * @param xml + * Represents the receiver of XML. Objects of the following types are allowed. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
TypeOperation
{@link File}XML will be written to this file. If it already exists, + * it will be overwritten.
{@link URL}The XML will be {@link URLConnection#getOutputStream() sent} to the + * resource pointed by this URL. Note that not all {@code URL}s support + * such operation, and exact semantics depends on the {@code URL} + * implementations. In case of {@link HttpURLConnection HTTP URLs}, + * this will perform HTTP POST.
{@link URI}The URI is {@link URI#toURL() turned into URL} and then + * follows the handling of {@code URL}. See above.
{@link String}The string is first interpreted as an absolute {@code URI}. + * If it's not {@link URI#isAbsolute() a valid absolute URI}, + * then it's interpreted as a {@code File}
{@link OutputStream}The XML will be sent to the given {@link OutputStream}. + * Upon a successful completion, the stream will be closed by this method.
{@link Writer}The XML will be sent as a character stream to the given {@link Writer}. + * Upon a successful completion, the stream will be closed by this method.
{@link Result}The XML will be sent to the {@link Result} object.
+ * + * @throws DataBindingException + * If the operation fails, such as due to I/O error, unbindable classes. + */ + private static void _marshal( Object jaxbObject, Object xml ) { + try { + JAXBContext context; + + if(jaxbObject instanceof JAXBElement) { + context = getContext(((JAXBElement)jaxbObject).getDeclaredType()); + } else { + Class clazz = jaxbObject.getClass(); + XmlRootElement r = clazz.getAnnotation(XmlRootElement.class); + context = getContext(clazz); + if(r==null) { + // we need to infer the name + jaxbObject = new JAXBElement(new QName(inferName(clazz)),clazz,jaxbObject); + } + } + + Marshaller m = context.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true); + m.marshal(jaxbObject, toResult(xml)); + } catch (JAXBException e) { + throw new DataBindingException(e); + } catch (IOException e) { + throw new DataBindingException(e); + } + } + + private static String inferName(Class clazz) { + return Introspector.decapitalize(clazz.getSimpleName()); + } + + /** + * Creates {@link Result} from various XML representation. + * See {@link #_marshal(Object,Object)} for the conversion rules. + */ + private static Result toResult(Object xml) throws IOException { + if(xml==null) + throw new IllegalArgumentException("no XML is given"); + + if (xml instanceof String) { + try { + xml=new URI((String)xml); + } catch (URISyntaxException e) { + xml=new File((String)xml); + } + } + if (xml instanceof File) { + File file = (File) xml; + return new StreamResult(file); + } + if (xml instanceof URI) { + URI uri = (URI) xml; + xml=uri.toURL(); + } + if (xml instanceof URL) { + URL url = (URL) xml; + URLConnection con = url.openConnection(); + con.setDoOutput(true); + con.setDoInput(false); + con.connect(); + return new StreamResult(con.getOutputStream()); + } + if (xml instanceof OutputStream) { + OutputStream os = (OutputStream) xml; + return new StreamResult(os); + } + if (xml instanceof Writer) { + Writer w = (Writer)xml; + return new StreamResult(w); + } + if (xml instanceof Result) { + return (Result) xml; + } + throw new IllegalArgumentException("I don't understand how to handle "+xml.getClass()); + } + +} diff --git a/fine-third-jdk11/src/javax/xml/bind/JAXBContext.java b/fine-third-jdk11/src/javax/xml/bind/JAXBContext.java new file mode 100644 index 000000000..34d084e12 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/JAXBContext.java @@ -0,0 +1,849 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +import org.w3c.dom.Node; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Collections; +import java.util.Map; +import java.util.Properties; + +/** + * The {@code JAXBContext} class provides the client's entry point to the + * JAXB API. It provides an abstraction for managing the XML/Java binding + * information necessary to implement the JAXB binding framework operations: + * unmarshal, marshal and validate. + * + *

A client application normally obtains new instances of this class using + * one of these two styles for newInstance methods, although there are other + * specialized forms of the method available: + * + *

    + *
  • {@link #newInstance(String, ClassLoader) JAXBContext.newInstance( "com.acme.foo:com.acme.bar" )}
    + * The JAXBContext instance is initialized from a list of colon + * separated Java package names. Each java package contains + * JAXB mapped classes, schema-derived classes and/or user annotated + * classes. Additionally, the java package may contain JAXB package annotations + * that must be processed. (see JLS, Section 7.4.1 "Named Packages"). + *
  • + *
  • {@link #newInstance(Class...) JAXBContext.newInstance( com.acme.foo.Foo.class )}
    + * The JAXBContext instance is initialized with class(es) + * passed as parameter(s) and classes that are statically reachable from + * these class(es). See {@link #newInstance(Class...)} for details. + *
  • + *
+ * + *

+ * The following JAXB 1.0 requirement is only required for schema to + * java interface/implementation binding. It does not apply to JAXB annotated + * classes. JAXB Providers must generate a {@code jaxb.properties} file in + * each package containing schema derived classes. The property file must + * contain a property named {@code javax.xml.bind.context.factory} whose + * value is the name of the class that implements the {@code createContext} + * APIs. + * + *

+ * The class supplied by the provider does not have to be assignable to + * {@code javax.xml.bind.JAXBContext}, it simply has to provide a class that + * implements the {@code createContext} APIs. + * + *

+ * In addition, the provider must call the + * {@link DatatypeConverter#setDatatypeConverter(DatatypeConverterInterface) + * DatatypeConverter.setDatatypeConverter} api prior to any client + * invocations of the marshal and unmarshal methods. This is necessary to + * configure the datatype converter that will be used during these operations. + * + * + *

Unmarshalling

+ *

+ * The {@link Unmarshaller} class provides the client application the ability + * to convert XML data into a tree of Java content objects. + * The unmarshal method allows for + * any global XML element declared in the schema to be unmarshalled as + * the root of an instance document. + * Additionally, the unmarshal method allows for an unrecognized root element that + * has an xsi:type attribute's value that references a type definition declared in + * the schema to be unmarshalled as the root of an instance document. + * The {@code JAXBContext} object + * allows the merging of global elements and type definitions across a set of schemas (listed + * in the {@code contextPath}). Since each schema in the schema set can belong + * to distinct namespaces, the unification of schemas to an unmarshalling + * context must be namespace independent. This means that a client + * application is able to unmarshal XML documents that are instances of + * any of the schemas listed in the {@code contextPath}. For example: + * + *

+ *      JAXBContext jc = JAXBContext.newInstance( "com.acme.foo:com.acme.bar" );
+ *      Unmarshaller u = jc.createUnmarshaller();
+ *      FooObject fooObj = (FooObject)u.unmarshal( new File( "foo.xml" ) ); // ok
+ *      BarObject barObj = (BarObject)u.unmarshal( new File( "bar.xml" ) ); // ok
+ *      BazObject bazObj = (BazObject)u.unmarshal( new File( "baz.xml" ) ); // error, "com.acme.baz" not in contextPath
+ * 
+ * + *

+ * The client application may also generate Java content trees explicitly rather + * than unmarshalling existing XML data. For all JAXB-annotated value classes, + * an application can create content using constructors. + * For schema-derived interface/implementation classes and for the + * creation of elements that are not bound to a JAXB-annotated + * class, an application needs to have access and knowledge about each of + * the schema derived {@code ObjectFactory} classes that exist in each of + * java packages contained in the {@code contextPath}. For each schema + * derived java class, there is a static factory method that produces objects + * of that type. For example, + * assume that after compiling a schema, you have a package {@code com.acme.foo} + * that contains a schema derived interface named {@code PurchaseOrder}. In + * order to create objects of that type, the client application would use the + * factory method like this: + * + *

+ *       com.acme.foo.PurchaseOrder po =
+ *           com.acme.foo.ObjectFactory.createPurchaseOrder();
+ * 
+ * + *

+ * Once the client application has an instance of the the schema derived object, + * it can use the mutator methods to set content on it. + * + *

+ * For more information on the generated {@code ObjectFactory} classes, see + * Section 4.2 Java Package of the specification. + * + *

+ * The provider must generate a class in each + * package that contains all of the necessary object factory methods for that + * package named ObjectFactory as well as the static + * {@code newInstance( javaContentInterface )} method + * + *

Marshalling

+ *

+ * The {@link Marshaller} class provides the client application the ability + * to convert a Java content tree back into XML data. There is no difference + * between marshalling a content tree that is created manually using the factory + * methods and marshalling a content tree that is the result an {@code unmarshal} + * operation. Clients can marshal a java content tree back to XML data + * to a {@code java.io.OutputStream} or a {@code java.io.Writer}. The + * marshalling process can alternatively produce SAX2 event streams to a + * registered {@code ContentHandler} or produce a DOM Node object. + * Client applications have control over the output encoding as well as + * whether or not to marshal the XML data as a complete document or + * as a fragment. + * + *

+ * Here is a simple example that unmarshals an XML document and then marshals + * it back out: + * + *

+ *        JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
+ *
+ *        // unmarshal from foo.xml
+ *        Unmarshaller u = jc.createUnmarshaller();
+ *        FooObject fooObj = (FooObject)u.unmarshal( new File( "foo.xml" ) );
+ *
+ *        // marshal to System.out
+ *        Marshaller m = jc.createMarshaller();
+ *        m.marshal( fooObj, System.out );
+ * 
+ * + * + *

Validation

+ *

+ * Validation has been changed significantly since JAXB 1.0. The {@link Validator} + * class has been deprecated and made optional. This means that you are advised + * not to use this class and, in fact, it may not even be available depending on + * your JAXB provider. JAXB 1.0 client applications that rely on {@code Validator} + * will still work properly when deployed with the JAXB 1.0 runtime system. + * + * In JAXB 2.0, the {@link Unmarshaller} has included convenince methods that expose + * the JAXP 1.3 {@link javax.xml.validation} framework. Please refer to the + * {@link Unmarshaller#setSchema(javax.xml.validation.Schema)} API for more + * information. + * + * + *

JAXB Runtime Binding Framework Compatibility

+ *

+ * The following JAXB 1.0 restriction only applies to binding schema to + * interfaces/implementation classes. + * Since this binding does not require a common runtime system, a JAXB + * client application must not attempt to mix runtime objects ({@code JAXBContext, + * Marshaller}, etc. ) from different providers. This does not + * mean that the client application isn't portable, it simply means that a + * client has to use a runtime system provided by the same provider that was + * used to compile the schema. + * + * + *

Discovery of JAXB implementation

+ *

+ * To create an instance of {@link JAXBContext}, one of {@code JAXBContext.newInstance(...)} methods is invoked. After + * JAX-B implementation is discovered, call is delegated to appropriate provider's method {@code createContext(...)} + * passing parameters from the original call. + *

+ * JAX-B implementation discovery happens each time {@code JAXBContext.newInstance} is invoked. If there is no user + * specific configuration provided, default JAX-B provider must be returned. + *

+ * Implementation discovery consists of following steps: + * + *

    + * + *
  1. + * Packages/classes explicitly passed in to the {@link #newInstance} method are processed in the order they are + * specified, until {@code jaxb.properties} file is looked up in its package, by using the associated classloader — + * this is {@link Class#getClassLoader() the owner class loader} for a {@link Class} argument, and for a package + * the specified {@link ClassLoader}. + * + *

    + * If such a resource is discovered, it is {@link Properties#load(InputStream) loaded} as a property file, and + * the value of the {@link #JAXB_CONTEXT_FACTORY} key will be assumed to be the provider factory class. If no value + * found, {@code "javax.xml.bind.context.factory"} is used as a key for backwards compatibility reasons. This class is + * then loaded by the associated class loader discussed above. + * + *

    + * This phase of the look up allows some packages to force the use of a certain JAXB implementation. + * (For example, perhaps the schema compiler has generated some vendor extension in the code.) + * + *

    + * This configuration method is deprecated. + * + *

  2. + * If the system property {@link #JAXB_CONTEXT_FACTORY} exists, then its value is assumed to be the provider + * factory class. If no such property exists, properties {@code "javax.xml.bind.context.factory"} and + * {@code "javax.xml.bind.JAXBContext"} are checked too (in this order), for backwards compatibility reasons. This phase + * of the look up enables per-JVM override of the JAXB implementation. + * + *
  3. + * Provider of {@link javax.xml.bind.JAXBContextFactory} is loaded using the service-provider loading + * facilities, defined by the {@link java.util.ServiceLoader} class, to attempt + * to locate and load an implementation of the service using the {@linkplain + * java.util.ServiceLoader#load(java.lang.Class) default loading mechanism}: the service-provider loading facility + * will use the {@linkplain java.lang.Thread#getContextClassLoader() current thread's context class loader} + * to attempt to load the context factory. If the context class loader is null, the + * {@linkplain ClassLoader#getSystemClassLoader() system class loader} will be used. + *
    + * In case of {@link java.util.ServiceConfigurationError service + * configuration error} a {@link javax.xml.bind.JAXBException} will be thrown. + * + *
  4. + * Look for resource {@code /META-INF/services/javax.xml.bind.JAXBContext} using provided class loader. + * Methods without class loader parameter use {@code Thread.currentThread().getContextClassLoader()}. + * If such a resource exists, its content is assumed to be the provider factory class. + * + * This configuration method is deprecated. + * + *
  5. + * Finally, if all the steps above fail, then the rest of the look up is unspecified. That said, + * the recommended behavior is to simply look for some hard-coded platform default JAXB implementation. + * This phase of the look up is so that Java SE can have its own JAXB implementation as the last resort. + *
+ * + *

+ * Once the provider factory class is discovered, context creation is delegated to one of its + * {@code createContext(...)} methods. + * + * For backward compatibility reasons, there are two ways how to implement provider factory class: + *

    + *
  1. the class is implementation of {@link javax.xml.bind.JAXBContextFactory}. It must also implement no-arg + * constructor. If discovered in other step then 3, new instance using no-arg constructor is created first. + * After that, appropriate instance method is invoked on this instance. + *
  2. the class is not implementation of interface above and then it is mandated to implement the following + * static method signatures: + *
    + *
    + * public static JAXBContext createContext(
    + *                                      String contextPath,
    + *                                      ClassLoader classLoader,
    + *                                      Map<String,Object> properties ) throws JAXBException
    + *
    + * public static JAXBContext createContext(
    + *                                      Class[] classes,
    + *                                      Map<String,Object> properties ) throws JAXBException
    + * 
    + * In this scenario, appropriate static method is used instead of instance method. This approach is incompatible + * with {@link java.util.ServiceLoader} so it can't be used with step 3. + *
+ *

+ * There is no difference in behavior of given method {@code createContext(...)} regardless of whether it uses approach + * 1 (JAXBContextFactory) or 2 (no interface, static methods). + * + * @apiNote + * Service discovery method using resource {@code /META-INF/services/javax.xml.bind.JAXBContext} (described in step 4) + * is supported only to allow backwards compatibility, it is strongly recommended to migrate to standard + * {@link java.util.ServiceLoader} mechanism (described in step 3). The difference here is the resource name, which + * doesn't match service's type name. + *

+ * Also using providers implementing interface {@link JAXBContextFactory} is preferred over using ones defining + * static methods, same as {@link JAXBContext#JAXB_CONTEXT_FACTORY} property is preferred over property + * {@code "javax.xml.bind.context.factory"} + * + * @implNote + * Within the last step, if Glassfish AS environment detected, its specific service loader is used to find factory class. + * + * @author

  • Ryan Shoemaker, Sun Microsystems, Inc.
  • + *
  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • + *
  • Joe Fialli, Sun Microsystems, Inc.
+ * + * @see Marshaller + * @see Unmarshaller + * @see S 7.4.1 "Named Packages" + * in Java Language Specification + * + * @since 1.6, JAXB 1.0 + */ +public abstract class JAXBContext { + + /** + * The name of the property that contains the name of the class capable + * of creating new {@code JAXBContext} objects. + */ + public static final String JAXB_CONTEXT_FACTORY = "javax.xml.bind.JAXBContextFactory"; + + protected JAXBContext() { + } + + + /** + * Create a new instance of a {@code JAXBContext} class. + * + *

+ * This is a convenience method to invoke the + * {@link #newInstance(String,ClassLoader)} method with + * the context class loader of the current thread. + * + * @throws JAXBException if an error was encountered while creating the + * {@code JAXBContext} such as + *

    + *
  1. failure to locate either ObjectFactory.class or jaxb.index in the packages
  2. + *
  3. an ambiguity among global elements contained in the contextPath
  4. + *
  5. failure to locate a value for the context factory provider property
  6. + *
  7. mixing schema derived packages from different providers on the same contextPath
  8. + *
  9. packages are not open to {@code java.xml.bind} module
  10. + *
+ */ + public static JAXBContext newInstance( String contextPath ) + throws JAXBException { + + //return newInstance( contextPath, JAXBContext.class.getClassLoader() ); + return newInstance( contextPath, getContextClassLoader()); + } + + /** + * Create a new instance of a {@code JAXBContext} class. + * + *

+ * The client application must supply a context path which is a list of + * colon (':', \u005Cu003A) separated java package names that contain + * schema-derived classes and/or fully qualified JAXB-annotated classes. + * Schema-derived + * code is registered with the JAXBContext by the + * ObjectFactory.class generated per package. + * Alternatively than being listed in the context path, programmer + * annotated JAXB mapped classes can be listed in a + * {@code jaxb.index} resource file, format described below. + * Note that a java package can contain both schema-derived classes and + * user annotated JAXB classes. Additionally, the java package may + * contain JAXB package annotations that must be processed. (see JLS, + * Section 7.4.1 "Named Packages"). + *

+ * + *

+ * Every package listed on the contextPath must meet one or both of the + * following conditions otherwise a {@code JAXBException} will be thrown: + *

+ *
    + *
  1. it must contain ObjectFactory.class
  2. + *
  3. it must contain jaxb.index
  4. + *
+ * + *

+ * Format for jaxb.index + *

+ * The file contains a newline-separated list of class names. + * Space and tab characters, as well as blank + * lines, are ignored. The comment character + * is '#' (0x23); on each line all characters following the first comment + * character are ignored. The file must be encoded in UTF-8. Classes that + * are reachable, as defined in {@link #newInstance(Class...)}, from the + * listed classes are also registered with JAXBContext. + *

+ * Constraints on class name occuring in a {@code jaxb.index} file are: + *

    + *
  • Must not end with ".class".
  • + *
  • Class names are resolved relative to package containing + * {@code jaxb.index} file. Only classes occuring directly in package + * containing {@code jaxb.index} file are allowed.
  • + *
  • Fully qualified class names are not allowed. + * A qualified class name,relative to current package, + * is only allowed to specify a nested or inner class.
  • + *
+ * + *

+ * To maintain compatibility with JAXB 1.0 schema to java + * interface/implementation binding, enabled by schema customization + * {@code }, + * the JAXB provider will ensure that each package on the context path + * has a {@code jaxb.properties} file which contains a value for the + * {@code javax.xml.bind.context.factory} property and that all values + * resolve to the same provider. This requirement does not apply to + * JAXB annotated classes. + * + *

+ * If there are any global XML element name collisions across the various + * packages listed on the {@code contextPath}, a {@code JAXBException} + * will be thrown. + * + *

+ * Mixing generated interface/impl bindings from multiple JAXB Providers + * in the same context path may result in a {@code JAXBException} + * being thrown. + * + *

+ * The steps involved in discovering the JAXB implementation is discussed in the class javadoc. + * + * @param contextPath + * List of java package names that contain schema + * derived class and/or java to schema (JAXB-annotated) + * mapped classes. + * Packages in {@code contextPath} that are in named modules must be + * {@linkplain java.lang.Module#isOpen open} to at least the {@code java.xml.bind} module. + * @param classLoader + * This class loader will be used to locate the implementation + * classes. + * + * @return a new instance of a {@code JAXBContext} + * @throws JAXBException if an error was encountered while creating the + * {@code JAXBContext} such as + *

    + *
  1. failure to locate either ObjectFactory.class or jaxb.index in the packages
  2. + *
  3. an ambiguity among global elements contained in the contextPath
  4. + *
  5. failure to locate a value for the context factory provider property
  6. + *
  7. mixing schema derived packages from different providers on the same contextPath
  8. + *
  9. packages are not open to {@code java.xml.bind} module
  10. + *
+ */ + public static JAXBContext newInstance( String contextPath, ClassLoader classLoader ) throws JAXBException { + + return newInstance(contextPath,classLoader,Collections.emptyMap()); + } + + /** + * Create a new instance of a {@code JAXBContext} class. + * + *

+ * This is mostly the same as {@link JAXBContext#newInstance(String, ClassLoader)}, + * but this version allows you to pass in provider-specific properties to configure + * the instantiation of {@link JAXBContext}. + * + *

+ * The interpretation of properties is up to implementations. Implementations must + * throw {@code JAXBException} if it finds properties that it doesn't understand. + * + * @param contextPath + * List of java package names that contain schema + * derived class and/or java to schema (JAXB-annotated) + * mapped classes. + * Packages in {@code contextPath} that are in named modules must be + * {@linkplain java.lang.Module#isOpen open} to at least the {@code java.xml.bind} module. + * @param classLoader + * This class loader will be used to locate the implementation classes. + * @param properties + * provider-specific properties. Can be null, which means the same thing as passing + * in an empty map. + * + * @return a new instance of a {@code JAXBContext} + * @throws JAXBException if an error was encountered while creating the + * {@code JAXBContext} such as + *

    + *
  1. failure to locate either ObjectFactory.class or jaxb.index in the packages
  2. + *
  3. an ambiguity among global elements contained in the contextPath
  4. + *
  5. failure to locate a value for the context factory provider property
  6. + *
  7. mixing schema derived packages from different providers on the same contextPath
  8. + *
  9. packages are not open to {@code java.xml.bind} module
  10. + *
+ * @since 1.6, JAXB 2.0 + */ + public static JAXBContext newInstance( String contextPath, + ClassLoader classLoader, + Map properties ) throws JAXBException { + + return ContextFinder.find( + /* The default property name according to the JAXB spec */ + JAXB_CONTEXT_FACTORY, + + /* the context path supplied by the client app */ + contextPath, + + /* class loader to be used */ + classLoader, + properties ); + } + +// TODO: resurrect this once we introduce external annotations +// /** +// * Create a new instance of a {@code JAXBContext} class. +// * +// *

+// * The client application must supply a list of classes that the new +// * context object needs to recognize. +// * +// * Not only the new context will recognize all the classes specified, +// * but it will also recognize any classes that are directly/indirectly +// * referenced statically from the specified classes. +// * +// * For example, in the following Java code, if you do +// * {@code newInstance(Foo.class)}, the newly created {@link JAXBContext} +// * will recognize both {@code Foo} and {@code Bar}, but not {@code Zot}: +// *

+//     * class Foo {
+//     *      Bar b;
+//     * }
+//     * class Bar { int x; }
+//     * class Zot extends Bar { int y; }
+//     * 
+// * +// * Therefore, a typical client application only needs to specify the +// * top-level classes, but it needs to be careful. +// * +// * TODO: if we are to define other mechanisms, refer to them. +// * +// * @param externalBindings +// * list of external binding files. Can be null or empty if none is used. +// * when specified, those files determine how the classes are bound. +// * +// * @param classesToBeBound +// * list of java classes to be recognized by the new {@link JAXBContext}. +// * Can be empty, in which case a {@link JAXBContext} that only knows about +// * spec-defined classes will be returned. +// * +// * @return +// * A new instance of a {@code JAXBContext}. +// * +// * @throws JAXBException +// * if an error was encountered while creating the +// * {@code JAXBContext}, such as (but not limited to): +// *
    +// *
  1. No JAXB implementation was discovered +// *
  2. Classes use JAXB annotations incorrectly +// *
  3. Classes have colliding annotations (i.e., two classes with the same type name) +// *
  4. Specified external bindings are incorrect +// *
  5. The JAXB implementation was unable to locate +// * provider-specific out-of-band information (such as additional +// * files generated at the development time.) +// *
+// * +// * @throws IllegalArgumentException +// * if the parameter contains {@code null} (i.e., {@code newInstance(null);}) +// * +// * @since JAXB 2.0 +// */ +// public static JAXBContext newInstance( Source[] externalBindings, Class... classesToBeBound ) +// throws JAXBException { +// +// // empty class list is not an error, because the context will still include +// // spec-specified classes like String and Integer. +// // if(classesToBeBound.length==0) +// // throw new IllegalArgumentException(); +// +// // but it is an error to have nulls in it. +// for( int i=classesToBeBound.length-1; i>=0; i-- ) +// if(classesToBeBound[i]==null) +// throw new IllegalArgumentException(); +// +// return ContextFinder.find(externalBindings,classesToBeBound); +// } + + /** + * Create a new instance of a {@code JAXBContext} class. + * + *

+ * The client application must supply a list of classes that the new + * context object needs to recognize. + * + * Not only the new context will recognize all the classes specified, + * but it will also recognize any classes that are directly/indirectly + * referenced statically from the specified classes. Subclasses of + * referenced classes nor {@code @XmlTransient} referenced classes + * are not registered with JAXBContext. + * + * For example, in the following Java code, if you do + * {@code newInstance(Foo.class)}, the newly created {@link JAXBContext} + * will recognize both {@code Foo} and {@code Bar}, but not {@code Zot} or {@code FooBar}: + *

+     * class Foo {
+     *      @XmlTransient FooBar c;
+     *      Bar b;
+     * }
+     * class Bar { int x; }
+     * class Zot extends Bar { int y; }
+     * class FooBar { }
+     * 
+ * + * Therefore, a typical client application only needs to specify the + * top-level classes, but it needs to be careful. + * + *

+ * Note that for each java package registered with JAXBContext, + * when the optional package annotations exist, they must be processed. + * (see JLS, Section 7.4.1 "Named Packages"). + * + *

+ * The steps involved in discovering the JAXB implementation is discussed in the class javadoc. + * + * @param classesToBeBound + * List of java classes to be recognized by the new {@link JAXBContext}. + * Classes in {@code classesToBeBound} that are in named modules must be in a package + * that is {@linkplain java.lang.Module#isOpen open} to at least the {@code java.xml.bind} module. + * Can be empty, in which case a {@link JAXBContext} that only knows about + * spec-defined classes will be returned. + * + * @return + * A new instance of a {@code JAXBContext}. + * + * @throws JAXBException + * if an error was encountered while creating the + * {@code JAXBContext}, such as (but not limited to): + *

    + *
  1. No JAXB implementation was discovered + *
  2. Classes use JAXB annotations incorrectly + *
  3. Classes have colliding annotations (i.e., two classes with the same type name) + *
  4. The JAXB implementation was unable to locate + * provider-specific out-of-band information (such as additional + * files generated at the development time.) + *
  5. {@code classesToBeBound} are not open to {@code java.xml.bind} module + *
+ * + * @throws IllegalArgumentException + * if the parameter contains {@code null} (i.e., {@code newInstance(null);}) + * + * @since 1.6, JAXB 2.0 + */ + public static JAXBContext newInstance( Class ... classesToBeBound ) + throws JAXBException { + + return newInstance(classesToBeBound,Collections.emptyMap()); + } + + /** + * Create a new instance of a {@code JAXBContext} class. + * + *

+ * An overloading of {@link JAXBContext#newInstance(Class...)} + * to configure 'properties' for this instantiation of {@link JAXBContext}. + * + *

+ * The interpretation of properties is up to implementations. Implementations must + * throw {@code JAXBException} if it finds properties that it doesn't understand. + * + * @param classesToBeBound + * List of java classes to be recognized by the new {@link JAXBContext}. + * Classes in {@code classesToBeBound} that are in named modules must be in a package + * that is {@linkplain java.lang.Module#isOpen open} to at least the {@code java.xml.bind} module. + * Can be empty, in which case a {@link JAXBContext} that only knows about + * spec-defined classes will be returned. + * @param properties + * provider-specific properties. Can be null, which means the same thing as passing + * in an empty map. + * + * @return + * A new instance of a {@code JAXBContext}. + * + * @throws JAXBException + * if an error was encountered while creating the + * {@code JAXBContext}, such as (but not limited to): + *

    + *
  1. No JAXB implementation was discovered + *
  2. Classes use JAXB annotations incorrectly + *
  3. Classes have colliding annotations (i.e., two classes with the same type name) + *
  4. The JAXB implementation was unable to locate + * provider-specific out-of-band information (such as additional + * files generated at the development time.) + *
  5. {@code classesToBeBound} are not open to {@code java.xml.bind} module + *
+ * + * @throws IllegalArgumentException + * if the parameter contains {@code null} (i.e., {@code newInstance(null,someMap);}) + * + * @since 1.6, JAXB 2.0 + */ + public static JAXBContext newInstance( Class[] classesToBeBound, Map properties ) + throws JAXBException { + + if (classesToBeBound == null) { + throw new IllegalArgumentException(); + } + + // but it is an error to have nulls in it. + for (int i = classesToBeBound.length - 1; i >= 0; i--) { + if (classesToBeBound[i] == null) { + throw new IllegalArgumentException(); + } + } + + return ContextFinder.find(classesToBeBound,properties); + } + + /** + * Create an {@code Unmarshaller} object that can be used to convert XML + * data into a java content tree. + * + * @return an {@code Unmarshaller} object + * + * @throws JAXBException if an error was encountered while creating the + * {@code Unmarshaller} object + */ + public abstract Unmarshaller createUnmarshaller() throws JAXBException; + + + /** + * Create a {@code Marshaller} object that can be used to convert a + * java content tree into XML data. + * + * @return a {@code Marshaller} object + * + * @throws JAXBException if an error was encountered while creating the + * {@code Marshaller} object + */ + public abstract Marshaller createMarshaller() throws JAXBException; + + + /** + * {@link Validator} has been made optional and deprecated in JAXB 2.0. Please + * refer to the javadoc for {@link Validator} for more detail. + *

+ * Create a {@code Validator} object that can be used to validate a + * java content tree against its source schema. + * + * @return a {@code Validator} object + * + * @throws JAXBException if an error was encountered while creating the + * {@code Validator} object + * @deprecated since JAXB2.0 + */ + @Deprecated + public abstract Validator createValidator() throws JAXBException; + + /** + * Creates a {@code Binder} object that can be used for + * associative/in-place unmarshalling/marshalling. + * + * @param domType select the DOM API to use by passing in its DOM Node class. + * + * @return always a new valid {@code Binder} object. + * + * @throws UnsupportedOperationException + * if DOM API corresponding to {@code domType} is not supported by + * the implementation. + * + * @since 1.6, JAXB 2.0 + */ + public Binder createBinder(Class domType) { + // to make JAXB 1.0 implementations work, this method must not be + // abstract + throw new UnsupportedOperationException(); + } + + /** + * Creates a {@code Binder} for W3C DOM. + * + * @return always a new valid {@code Binder} object. + * + * @since 1.6, JAXB 2.0 + */ + public Binder createBinder() { + return createBinder(Node.class); + } + + /** + * Creates a {@code JAXBIntrospector} object that can be used to + * introspect JAXB objects. + * + * @return + * always return a non-null valid {@code JAXBIntrospector} object. + * + * @throws UnsupportedOperationException + * Calling this method on JAXB 1.0 implementations will throw + * an UnsupportedOperationException. + * + * @since 1.6, JAXB 2.0 + */ + public JAXBIntrospector createJAXBIntrospector() { + // to make JAXB 1.0 implementations work, this method must not be + // abstract + throw new UnsupportedOperationException(); + } + + /** + * Generates the schema documents for this context. + * + * @param outputResolver + * this object controls the output to which schemas + * will be sent. + * + * @throws IOException + * if {@link SchemaOutputResolver} throws an {@link IOException}. + * + * @throws UnsupportedOperationException + * Calling this method on JAXB 1.0 implementations will throw + * an UnsupportedOperationException. + * + * @since 1.6, JAXB 2.0 + */ + public void generateSchema(SchemaOutputResolver outputResolver) throws IOException { + // to make JAXB 1.0 implementations work, this method must not be + // abstract + throw new UnsupportedOperationException(); + } + + private static ClassLoader getContextClassLoader() { + if (System.getSecurityManager() == null) { + return Thread.currentThread().getContextClassLoader(); + } else { + return java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction() { + public ClassLoader run() { + return Thread.currentThread().getContextClassLoader(); + } + }); + } + } + +} diff --git a/fine-third-jdk11/src/javax/xml/bind/JAXBContextFactory.java b/fine-third-jdk11/src/javax/xml/bind/JAXBContextFactory.java new file mode 100644 index 000000000..d921134fa --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/JAXBContextFactory.java @@ -0,0 +1,133 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2015-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +import java.util.Map; + +/** + *

Factory that creates new JAXBContext instances. + * + * JAXBContextFactory can be located using {@link java.util.ServiceLoader#load(Class)} + * + * @since 9, JAXB 2.3 + */ +public interface JAXBContextFactory { + + /** + *

+ * Create a new instance of a {@code JAXBContext} class. + * + *

+ * For semantics see {@link javax.xml.bind.JAXBContext#newInstance(Class[], java.util.Map)} + * + * @param classesToBeBound + * List of java classes to be recognized by the new {@link JAXBContext}. + * Classes in {@code classesToBeBound} that are in named modules must be in a package + * that is {@linkplain java.lang.Module#isOpen open} to at least the {@code java.xml.bind} module. + * Can be empty, in which case a {@link JAXBContext} that only knows about + * spec-defined classes will be returned. + * @param properties + * provider-specific properties. Can be null, which means the same thing as passing + * in an empty map. + * + * @return + * A new instance of a {@code JAXBContext}. + * + * @throws JAXBException + * if an error was encountered while creating the + * {@code JAXBContext}, such as (but not limited to): + *

    + *
  1. No JAXB implementation was discovered + *
  2. Classes use JAXB annotations incorrectly + *
  3. Classes have colliding annotations (i.e., two classes with the same type name) + *
  4. The JAXB implementation was unable to locate + * provider-specific out-of-band information (such as additional + * files generated at the development time.) + *
  5. {@code classesToBeBound} are not open to {@code java.xml.bind} module + *
+ * + * @throws IllegalArgumentException + * if the parameter contains {@code null} (i.e., {@code newInstance(null,someMap);}) + * + * @since 9, JAXB 2.3 + */ + JAXBContext createContext(Class[] classesToBeBound, + Map properties ) throws JAXBException; + + /** + *

+ * Create a new instance of a {@code JAXBContext} class. + * + *

+ * For semantics see {@link javax.xml.bind.JAXBContext#newInstance(String, ClassLoader, java.util.Map)} + * + *

+ * The interpretation of properties is up to implementations. Implementations must + * throw {@code JAXBException} if it finds properties that it doesn't understand. + * + * @param contextPath + * List of java package names that contain schema derived classes. + * Classes in {@code classesToBeBound} that are in named modules must be in a package + * that is {@linkplain java.lang.Module#isOpen open} to at least the {@code java.xml.bind} module. + * @param classLoader + * This class loader will be used to locate the implementation classes. + * @param properties + * provider-specific properties. Can be null, which means the same thing as passing + * in an empty map. + * + * @return a new instance of a {@code JAXBContext} + * @throws JAXBException if an error was encountered while creating the + * {@code JAXBContext} such as + *

    + *
  1. failure to locate either ObjectFactory.class or jaxb.index in the packages
  2. + *
  3. an ambiguity among global elements contained in the contextPath
  4. + *
  5. failure to locate a value for the context factory provider property
  6. + *
  7. mixing schema derived packages from different providers on the same contextPath
  8. + *
  9. packages are not open to {@code java.xml.bind} module
  10. + *
+ * + * @since 9, JAXB 2.3 + */ + JAXBContext createContext(String contextPath, + ClassLoader classLoader, + Map properties ) throws JAXBException; + +} diff --git a/fine-third-jdk11/src/javax/xml/bind/JAXBElement.java b/fine-third-jdk11/src/javax/xml/bind/JAXBElement.java new file mode 100644 index 000000000..82134314a --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/JAXBElement.java @@ -0,0 +1,233 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +import javax.xml.namespace.QName; +import java.io.Serializable; + +/** + *

JAXB representation of an Xml Element.

+ * + *

This class represents information about an Xml Element from both the element + * declaration within a schema and the element instance value within an xml document + * with the following properties + *

    + *
  • element's xml tag {@code name}
  • + *
  • {@code value} represents the element instance's atttribute(s) and content model
  • + *
  • element declaration's {@code declaredType} ({@code xs:element @type} attribute)
  • + *
  • {@code scope} of element declaration
  • + *
  • boolean {@code nil} property. (element instance's {@code xsi:nil} attribute)
  • + *
+ * + *

The {@code declaredType} and {@code scope} property are the + * JAXB class binding for the xml type definition. + *

+ * + *

{@code Scope} is either {@link GlobalScope} or the Java class representing the + * complex type definition containing the schema element declaration. + *

+ * + *

There is a property constraint that if {@code value} is {@code null}, + * then {@code nil} must be {@code true}. The converse is not true to enable + * representing a nil element with attribute(s). If {@code nil} is true, it is possible + * that {@code value} is non-null so it can hold the value of the attributes + * associated with a nil element. + *

+ * + * @author Kohsuke Kawaguchi, Joe Fialli + * @since 1.6, JAXB 2.0 + */ + +public class JAXBElement implements Serializable { + + /** xml element tag name */ + final protected QName name; + + /** Java datatype binding for xml element declaration's type. */ + final protected Class declaredType; + + /** Scope of xml element declaration representing this xml element instance. + * Can be one of the following values: + * - {@link GlobalScope} for global xml element declaration. + * - local element declaration has a scope set to the Java class + * representation of complex type defintion containing + * xml element declaration. + */ + final protected Class scope; + + /** xml element value. + Represents content model and attributes of an xml element instance. */ + protected T value; + + /** true iff the xml element instance has xsi:nil="true". */ + protected boolean nil = false; + + /** + * Designates global scope for an xml element. + */ + public static final class GlobalScope {} + + /** + *

Construct an xml element instance.

+ * + * @param name Java binding of xml element tag name + * @param declaredType Java binding of xml element declaration's type + * @param scope + * Java binding of scope of xml element declaration. + * Passing null is the same as passing {@code GlobalScope.class} + * @param value + * Java instance representing xml element's value. + * @see #getScope() + * @see #isTypeSubstituted() + */ + public JAXBElement(QName name, + Class declaredType, + Class scope, + T value) { + if(declaredType==null || name==null) + throw new IllegalArgumentException(); + this.declaredType = declaredType; + if(scope==null) scope = GlobalScope.class; + this.scope = scope; + this.name = name; + setValue(value); + } + + /** + * Construct an xml element instance. + * + * This is just a convenience method for {@code new JAXBElement(name,declaredType,GlobalScope.class,value)} + */ + public JAXBElement(QName name, Class declaredType, T value ) { + this(name,declaredType,GlobalScope.class,value); + } + + /** + * Returns the Java binding of the xml element declaration's type attribute. + */ + public Class getDeclaredType() { + return declaredType; + } + + /** + * Returns the xml element tag name. + */ + public QName getName() { + return name; + } + + /** + *

Set the content model and attributes of this xml element.

+ * + *

When this property is set to {@code null}, {@code isNil()} must by {@code true}. + * Details of constraint are described at {@link #isNil()}.

+ * + * @see #isTypeSubstituted() + */ + public void setValue(T t) { + this.value = t; + } + + /** + *

Return the content model and attribute values for this element.

+ * + *

See {@link #isNil()} for a description of a property constraint when + * this value is {@code null}

+ */ + public T getValue() { + return value; + } + + /** + * Returns scope of xml element declaration. + * + * @see #isGlobalScope() + * @return {@code GlobalScope.class} if this element is of global scope. + */ + public Class getScope() { + return scope; + } + + /** + *

Returns {@code true} iff this element instance content model + * is nil.

+ * + *

This property always returns {@code true} when {@link #getValue()} is null. + * Note that the converse is not true, when this property is {@code true}, + * {@link #getValue()} can contain a non-null value for attribute(s). It is + * valid for a nil xml element to have attribute(s).

+ */ + public boolean isNil() { + return (value == null) || nil; + } + + /** + *

Set whether this element has nil content.

+ * + * @see #isNil() + */ + public void setNil(boolean value) { + this.nil = value; + } + + /* Convenience methods + * (Not necessary but they do unambiguously conceptualize + * the rationale behind this class' fields.) + */ + + /** + * Returns true iff this xml element declaration is global. + */ + public boolean isGlobalScope() { + return this.scope == GlobalScope.class; + } + + /** + * Returns true iff this xml element instance's value has a different + * type than xml element declaration's declared type. + */ + public boolean isTypeSubstituted() { + if(value==null) return false; + return value.getClass() != declaredType; + } + + private static final long serialVersionUID = 1L; +} diff --git a/fine-third-jdk11/src/javax/xml/bind/JAXBException.java b/fine-third-jdk11/src/javax/xml/bind/JAXBException.java new file mode 100644 index 000000000..6b541ff7c --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/JAXBException.java @@ -0,0 +1,199 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +import java.io.PrintWriter; + +/** + * This is the root exception class for all JAXB exceptions. + * + * @author
  • Ryan Shoemaker, Sun Microsystems, Inc.
+ * @see JAXBContext + * @see Marshaller + * @see Unmarshaller + * @since 1.6, JAXB 1.0 + */ +public class JAXBException extends Exception { + + /** + * Vendor specific error code + * + */ + private String errorCode; + + /** + * Exception reference + * + */ + private volatile Throwable linkedException; + + static final long serialVersionUID = -5621384651494307979L; + + /** + * Construct a JAXBException with the specified detail message. The + * errorCode and linkedException will default to null. + * + * @param message a description of the exception + */ + public JAXBException(String message) { + this( message, null, null ); + } + + /** + * Construct a JAXBException with the specified detail message and vendor + * specific errorCode. The linkedException will default to null. + * + * @param message a description of the exception + * @param errorCode a string specifying the vendor specific error code + */ + public JAXBException(String message, String errorCode) { + this( message, errorCode, null ); + } + + /** + * Construct a JAXBException with a linkedException. The detail message and + * vendor specific errorCode will default to null. + * + * @param exception the linked exception + */ + public JAXBException(Throwable exception) { + this( null, null, exception ); + } + + /** + * Construct a JAXBException with the specified detail message and + * linkedException. The errorCode will default to null. + * + * @param message a description of the exception + * @param exception the linked exception + */ + public JAXBException(String message, Throwable exception) { + this( message, null, exception ); + } + + /** + * Construct a JAXBException with the specified detail message, vendor + * specific errorCode, and linkedException. + * + * @param message a description of the exception + * @param errorCode a string specifying the vendor specific error code + * @param exception the linked exception + */ + public JAXBException(String message, String errorCode, Throwable exception) { + super( message ); + this.errorCode = errorCode; + this.linkedException = exception; + } + + /** + * Get the vendor specific error code + * + * @return a string specifying the vendor specific error code + */ + public String getErrorCode() { + return this.errorCode; + } + + /** + * Get the linked exception + * + * @return the linked Exception, null if none exists + */ + public Throwable getLinkedException() { + return linkedException; + } + + /** + * Add a linked Exception. + * + * @param exception the linked Exception (A null value is permitted and + * indicates that the linked exception does not exist or + * is unknown). + */ + public void setLinkedException( Throwable exception ) { + this.linkedException = exception; + } + + /** + * Returns a short description of this JAXBException. + * + */ + public String toString() { + return linkedException == null ? + super.toString() : + super.toString() + "\n - with linked exception:\n[" + + linkedException.toString()+ "]"; + } + + /** + * Prints this JAXBException and its stack trace (including the stack trace + * of the linkedException if it is non-null) to the PrintStream. + * + * @param s PrintStream to use for output + */ + public void printStackTrace( java.io.PrintStream s ) { + super.printStackTrace(s); + } + + /** + * Prints this JAXBException and its stack trace (including the stack trace + * of the linkedException if it is non-null) to {@code System.err}. + * + */ + public void printStackTrace() { + super.printStackTrace(); + } + + /** + * Prints this JAXBException and its stack trace (including the stack trace + * of the linkedException if it is non-null) to the PrintWriter. + * + * @param s PrintWriter to use for output + */ + public void printStackTrace(PrintWriter s) { + super.printStackTrace(s); + } + + @Override + public Throwable getCause() { + return linkedException; + } +} diff --git a/fine-third-jdk11/src/javax/xml/bind/JAXBIntrospector.java b/fine-third-jdk11/src/javax/xml/bind/JAXBIntrospector.java new file mode 100644 index 000000000..a95bfe005 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/JAXBIntrospector.java @@ -0,0 +1,107 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; +import javax.xml.namespace.QName; + +/** + * Provide access to JAXB xml binding data for a JAXB object. + * + *

+ * Intially, the intent of this class is to just conceptualize how + * a JAXB application developer can access xml binding information, + * independent if binding model is java to schema or schema to java. + * Since accessing the XML element name related to a JAXB element is + * a highly requested feature, demonstrate access to this + * binding information. + * + * The factory method to get a JAXBIntrospector instance is + * {@link JAXBContext#createJAXBIntrospector()}. + * + * @see JAXBContext#createJAXBIntrospector() + * @since 1.6, JAXB 2.0 + */ +public abstract class JAXBIntrospector { + + /** + *

Return true if object represents a JAXB element.

+ *

Parameter object is a JAXB element for following cases: + *

    + *
  1. It is an instance of javax.xml.bind.JAXBElement.
  2. + *
  3. The class of object is annotated with + * @XmlRootElement. + *
  4. + *
+ * + * @see #getElementName(Object) + */ + public abstract boolean isElement(Object object); + + /** + *

Get xml element qname for jaxbElement.

+ * + * @param jaxbElement is an object that {@link #isElement(Object)} returned true. + * + * @return xml element qname associated with jaxbElement; + * null if jaxbElement is not a JAXB Element. + */ + public abstract QName getElementName(Object jaxbElement); + + /** + *

Get the element value of a JAXB element.

+ * + *

Convenience method to abstract whether working with either + * a javax.xml.bind.JAXBElement instance or an instance of + * {@code @XmlRootElement} annotated Java class.

+ * + * @param jaxbElement object that #isElement(Object) returns true. + * + * @return The element value of the jaxbElement. + */ + public static Object getValue(Object jaxbElement) { + if (jaxbElement instanceof JAXBElement) { + return ((JAXBElement)jaxbElement).getValue(); + } else { + // assume that class of this instance is + // annotated with @XmlRootElement. + return jaxbElement; + } + } +} diff --git a/fine-third-jdk11/src/javax/xml/bind/JAXBPermission.java b/fine-third-jdk11/src/javax/xml/bind/JAXBPermission.java new file mode 100644 index 000000000..058e17d91 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/JAXBPermission.java @@ -0,0 +1,112 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2007-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +import java.security.BasicPermission; + +/** + * This class is for JAXB permissions. A {@code JAXBPermission} + * contains a name (also referred to as a "target name") but + * no actions list; you either have the named permission + * or you don't. + * + *

+ * The target name is the name of the JAXB permission (see below). + * + *

+ * The following table lists all the possible {@code JAXBPermission} target names, + * and for each provides a description of what the permission allows + * and a discussion of the risks of granting code the permission. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Permission target name, what the permission allows, and associated risks"
Permission Target NameWhat the Permission AllowsRisks of Allowing this Permission
setDatatypeConverter + * Allows the code to set VM-wide {@link DatatypeConverterInterface} + * via {@link DatatypeConverter#setDatatypeConverter(DatatypeConverterInterface) the setDatatypeConverter method} + * that all the methods on {@link DatatypeConverter} uses. + * + * Malicious code can set {@link DatatypeConverterInterface}, which has + * VM-wide singleton semantics, before a genuine JAXB implementation sets one. + * This allows malicious code to gain access to objects that it may otherwise + * not have access to, such as {@link java.awt.Frame#getFrames()} that belongs to + * another application running in the same JVM. + *
+ * + * @see java.security.BasicPermission + * @see java.security.Permission + * @see java.security.Permissions + * @see java.security.PermissionCollection + * @see java.lang.SecurityManager + * + * @author Joe Fialli + * @since 1.7, JAXB 2.2 + */ + +/* code was borrowed originally from java.lang.RuntimePermission. */ +public final class JAXBPermission extends BasicPermission { + /** + * Creates a new JAXBPermission with the specified name. + * + * @param name + * The name of the JAXBPermission. As of 2.2 only "setDatatypeConverter" + * is defined. + */ + public JAXBPermission(String name) { + super(name); + } + + private static final long serialVersionUID = 1L; +} diff --git a/fine-third-jdk11/src/javax/xml/bind/MarshalException.java b/fine-third-jdk11/src/javax/xml/bind/MarshalException.java new file mode 100644 index 000000000..9d8475990 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/MarshalException.java @@ -0,0 +1,116 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +/** + * This exception indicates that an error has occurred while performing + * a marshal operation that the provider is unable to recover from. + * + *

+ * The {@code ValidationEventHandler} can cause this exception to be thrown + * during the marshal operations. See + * {@link ValidationEventHandler#handleEvent(ValidationEvent) + * ValidationEventHandler.handleEvent(ValidationEvent)}. + * + * @author

  • Ryan Shoemaker, Sun Microsystems, Inc.
+ * @see JAXBException + * @see Marshaller + * @since 1.6, JAXB 1.0 + */ +public class MarshalException extends JAXBException { + + /** + * Construct a MarshalException with the specified detail message. The + * errorCode and linkedException will default to null. + * + * @param message a description of the exception + */ + public MarshalException( String message ) { + this( message, null, null ); + } + + /** + * Construct a MarshalException with the specified detail message and vendor + * specific errorCode. The linkedException will default to null. + * + * @param message a description of the exception + * @param errorCode a string specifying the vendor specific error code + */ + public MarshalException( String message, String errorCode ) { + this( message, errorCode, null ); + } + + /** + * Construct a MarshalException with a linkedException. The detail message and + * vendor specific errorCode will default to null. + * + * @param exception the linked exception + */ + public MarshalException( Throwable exception ) { + this( null, null, exception ); + } + + /** + * Construct a MarshalException with the specified detail message and + * linkedException. The errorCode will default to null. + * + * @param message a description of the exception + * @param exception the linked exception + */ + public MarshalException( String message, Throwable exception ) { + this( message, null, exception ); + } + + /** + * Construct a MarshalException with the specified detail message, vendor + * specific errorCode, and linkedException. + * + * @param message a description of the exception + * @param errorCode a string specifying the vendor specific error code + * @param exception the linked exception + */ + public MarshalException( String message, String errorCode, Throwable exception ) { + super( message, errorCode, exception ); + } + +} + + diff --git a/fine-third-jdk11/src/javax/xml/bind/Marshaller.java b/fine-third-jdk11/src/javax/xml/bind/Marshaller.java new file mode 100644 index 000000000..037e71eac --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/Marshaller.java @@ -0,0 +1,841 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.adapters.XmlAdapter; +import javax.xml.bind.attachment.AttachmentMarshaller; +import javax.xml.validation.Schema; +import java.io.File; + +/** + *

+ * The {@code Marshaller} class is responsible for governing the process + * of serializing Java content trees back into XML data. It provides the basic + * marshalling methods: + * + *

+ * Assume the following setup code for all following code fragments: + *

+ *
+ *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
+ *       Unmarshaller u = jc.createUnmarshaller();
+ *       Object element = u.unmarshal( new File( "foo.xml" ) );
+ *       Marshaller m = jc.createMarshaller();
+ *    
+ *
+ * + *

+ * Marshalling to a File: + *

+ *
+ *       OutputStream os = new FileOutputStream( "nosferatu.xml" );
+ *       m.marshal( element, os );
+ *    
+ *
+ * + *

+ * Marshalling to a SAX ContentHandler: + *

+ *
+ *       // assume MyContentHandler instanceof ContentHandler
+ *       m.marshal( element, new MyContentHandler() );  
+ *    
+ *
+ * + *

+ * Marshalling to a DOM Node: + *

+ *
+ *       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ *       dbf.setNamespaceAware(true);
+ *       DocumentBuilder db = dbf.newDocumentBuilder();
+ *       Document doc = db.newDocument();
+ *
+ *       m.marshal( element, doc );
+ *    
+ *
+ * + *

+ * Marshalling to a java.io.OutputStream: + *

+ *
+ *       m.marshal( element, System.out );
+ *    
+ *
+ * + *

+ * Marshalling to a java.io.Writer: + *

+ *
+ *       m.marshal( element, new PrintWriter( System.out ) );
+ *    
+ *
+ * + *

+ * Marshalling to a javax.xml.transform.SAXResult: + *

+ *
+ *       // assume MyContentHandler instanceof ContentHandler
+ *       SAXResult result = new SAXResult( new MyContentHandler() );
+ *
+ *       m.marshal( element, result );
+ *    
+ *
+ * + *

+ * Marshalling to a javax.xml.transform.DOMResult: + *

+ *
+ *       DOMResult result = new DOMResult();
+ *       
+ *       m.marshal( element, result );
+ *    
+ *
+ * + *

+ * Marshalling to a javax.xml.transform.StreamResult: + *

+ *
+ *       StreamResult result = new StreamResult( System.out );
+ * 
+ *       m.marshal( element, result );
+ *    
+ *
+ * + *

+ * Marshalling to a javax.xml.stream.XMLStreamWriter: + *

+ *
+ *       XMLStreamWriter xmlStreamWriter = 
+ *           XMLOutputFactory.newInstance().createXMLStreamWriter( ... );
+ * 
+ *       m.marshal( element, xmlStreamWriter );
+ *    
+ *
+ * + *

+ * Marshalling to a javax.xml.stream.XMLEventWriter: + *

+ *
+ *       XMLEventWriter xmlEventWriter = 
+ *           XMLOutputFactory.newInstance().createXMLEventWriter( ... );
+ * 
+ *       m.marshal( element, xmlEventWriter );
+ *    
+ *
+ * + *

+ * + * Marshalling content tree rooted by a JAXB element
+ *

+ * The first parameter of the overloaded + * {@code Marshaller.marshal(java.lang.Object, ...)} methods must be a + * JAXB element as computed by + * {@link JAXBIntrospector#isElement(java.lang.Object)}; + * otherwise, a {@code Marshaller.marshal} method must throw a + * {@link MarshalException}. There exist two mechanisms + * to enable marshalling an instance that is not a JAXB element. + * One method is to wrap the instance as a value of a {@link JAXBElement}, + * and pass the wrapper element as the first parameter to + * a {@code Marshaller.marshal} method. For java to schema binding, it + * is also possible to simply annotate the instance's class with + * @{@link XmlRootElement}. + *
+ * + *

+ * Encoding
+ *

+ * By default, the Marshaller will use UTF-8 encoding when generating XML data + * to a {@code java.io.OutputStream}, or a {@code java.io.Writer}. Use the + * {@link #setProperty(String,Object) setProperty} API to change the output + * encoding used during these marshal operations. Client applications are + * expected to supply a valid character encoding name as defined in the + * W3C XML 1.0 + * Recommendation and supported by your Java Platform. + *
+ * + *

+ * Validation and Well-Formedness
+ *

+ *

+ * Client applications are not required to validate the Java content tree prior + * to calling any of the marshal API's. Furthermore, there is no requirement + * that the Java content tree be valid with respect to its original schema in + * order to marshal it back into XML data. Different JAXB Providers will + * support marshalling invalid Java content trees at varying levels, however + * all JAXB Providers must be able to marshal a valid content tree back to + * XML data. A JAXB Provider must throw a {@code MarshalException} when it + * is unable to complete the marshal operation due to invalid content. Some + * JAXB Providers will fully allow marshalling invalid content, others will fail + * on the first validation error. + *

+ * Even when schema validation is not explictly enabled for the marshal operation, + * it is possible that certain types of validation events will be detected + * during the operation. Validation events will be reported to the registered + * event handler. If the client application has not registered an event handler + * prior to invoking one of the marshal API's, then events will be delivered to + * a default event handler which will terminate the marshal operation after + * encountering the first error or fatal error. Note that for JAXB 2.0 and + * later versions, {@link javax.xml.bind.helpers.DefaultValidationEventHandler} is + * no longer used. + * + *

+ * + *

+ * + * Supported Properties
+ *

+ *

+ * All JAXB Providers are required to support the following set of properties. + * Some providers may support additional properties. + *

+ *
{@code jaxb.encoding} - value must be a java.lang.String
+ *
The output encoding to use when marshalling the XML data. The + * Marshaller will use "UTF-8" by default if this property is not + * specified.
+ *
{@code jaxb.formatted.output} - value must be a java.lang.Boolean
+ *
This property controls whether or not the Marshaller will format + * the resulting XML data with line breaks and indentation. A + * true value for this property indicates human readable indented + * xml data, while a false value indicates unformatted xml data. + * The Marshaller will default to false (unformatted) if this + * property is not specified.
+ *
{@code jaxb.schemaLocation} - value must be a java.lang.String
+ *
This property allows the client application to specify an + * xsi:schemaLocation attribute in the generated XML data. The format of + * the schemaLocation attribute value is discussed in an easy to + * understand, non-normative form in + * Section 5.6 + * of the W3C XML Schema Part 0: Primer and specified in + * + * Section 2.6 of the W3C XML Schema Part 1: Structures.
+ *
{@code jaxb.noNamespaceSchemaLocation} - value must be a java.lang.String
+ *
This property allows the client application to specify an + * xsi:noNamespaceSchemaLocation attribute in the generated XML + * data. The format of the schemaLocation attribute value is discussed in + * an easy to understand, non-normative form in + * Section 5.6 + * of the W3C XML Schema Part 0: Primer and specified in + * + * Section 2.6 of the W3C XML Schema Part 1: Structures.
+ *
{@code jaxb.fragment} - value must be a java.lang.Boolean
+ *
This property determines whether or not document level events will be + * generated by the Marshaller. If the property is not specified, the + * default is {@code false}. This property has different implications depending + * on which marshal api you are using - when this property is set to true:
+ *
    + *
  • {@link #marshal(Object,org.xml.sax.ContentHandler) marshal(Object,ContentHandler)} - the Marshaller won't + * invoke {@link org.xml.sax.ContentHandler#startDocument()} and + * {@link org.xml.sax.ContentHandler#endDocument()}.
  • + *
  • {@link #marshal(Object,org.w3c.dom.Node) marshal(Object,Node)} - the property has no effect on this + * API.
  • + *
  • {@link #marshal(Object,java.io.OutputStream) marshal(Object,OutputStream)} - the Marshaller won't + * generate an xml declaration.
  • + *
  • {@link #marshal(Object,java.io.Writer) marshal(Object,Writer)} - the Marshaller won't + * generate an xml declaration.
  • + *
  • {@link #marshal(Object,javax.xml.transform.Result) marshal(Object,Result)} - depends on the kind of + * Result object, see semantics for Node, ContentHandler, and Stream APIs
  • + *
  • {@link #marshal(Object,javax.xml.stream.XMLEventWriter) marshal(Object,XMLEventWriter)} - the + * Marshaller will not generate {@link javax.xml.stream.events.XMLEvent#START_DOCUMENT} and + * {@link javax.xml.stream.events.XMLEvent#END_DOCUMENT} events.
  • + *
  • {@link #marshal(Object,javax.xml.stream.XMLStreamWriter) marshal(Object,XMLStreamWriter)} - the + * Marshaller will not generate {@link javax.xml.stream.events.XMLEvent#START_DOCUMENT} and + * {@link javax.xml.stream.events.XMLEvent#END_DOCUMENT} events.
  • + *
+ *
+ *
+ *
+ * + *

+ * + * Marshal Event Callbacks
+ *

+ * "The {@link Marshaller} provides two styles of callback mechanisms + * that allow application specific processing during key points in the + * unmarshalling process. In 'class defined' event callbacks, application + * specific code placed in JAXB mapped classes is triggered during + * marshalling. 'External listeners' allow for centralized processing + * of marshal events in one callback method rather than by type event callbacks. + * + *

+ * Class defined event callback methods allow any JAXB mapped class to specify + * its own specific callback methods by defining methods with the following method signatures: + *

+ *
+ *   // Invoked by Marshaller after it has created an instance of this object.
+ *   boolean beforeMarshal(Marshaller);
+ * 
+ *   // Invoked by Marshaller after it has marshalled all properties of this object.
+ *   void afterMarshal(Marshaller);
+ * 
+ *
+ * The class defined event callback methods should be used when the callback method requires + * access to non-public methods and/or fields of the class. + *

+ * The external listener callback mechanism enables the registration of a {@link Listener} + * instance with a {@link Marshaller#setListener(Listener)}. The external listener receives all callback events, + * allowing for more centralized processing than per class defined callback methods. + *

+ * The 'class defined' and external listener event callback methods are independent of each other, + * both can be called for one event. The invocation ordering when both listener callback methods exist is + * defined in {@link Listener#beforeMarshal(Object)} and {@link Listener#afterMarshal(Object)}. + *

+ * An event callback method throwing an exception terminates the current marshal process. + *

+ * + * @author
  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • Ryan Shoemaker, Sun Microsystems, Inc.
  • Joe Fialli, Sun Microsystems, Inc.
+ * @see JAXBContext + * @see Validator + * @see Unmarshaller + * @since 1.6, JAXB 1.0 + */ +public interface Marshaller { + + /** + * The name of the property used to specify the output encoding in + * the marshalled XML data. + */ + public static final String JAXB_ENCODING = + "jaxb.encoding"; + + /** + * The name of the property used to specify whether or not the marshalled + * XML data is formatted with linefeeds and indentation. + */ + public static final String JAXB_FORMATTED_OUTPUT = + "jaxb.formatted.output"; + + /** + * The name of the property used to specify the xsi:schemaLocation + * attribute value to place in the marshalled XML output. + */ + public static final String JAXB_SCHEMA_LOCATION = + "jaxb.schemaLocation"; + + /** + * The name of the property used to specify the + * xsi:noNamespaceSchemaLocation attribute value to place in the marshalled + * XML output. + */ + public static final String JAXB_NO_NAMESPACE_SCHEMA_LOCATION = + "jaxb.noNamespaceSchemaLocation"; + + /** + * The name of the property used to specify whether or not the marshaller + * will generate document level events (ie calling startDocument or endDocument). + */ + public static final String JAXB_FRAGMENT = + "jaxb.fragment"; + + /** + * Marshal the content tree rooted at {@code jaxbElement} into the specified + * {@code javax.xml.transform.Result}. + * + *

+ * All JAXB Providers must at least support + * {@link javax.xml.transform.dom.DOMResult}, + * {@link javax.xml.transform.sax.SAXResult}, and + * {@link javax.xml.transform.stream.StreamResult}. It can + * support other derived classes of {@code Result} as well. + * + * @param jaxbElement + * The root of content tree to be marshalled. + * @param result + * XML will be sent to this Result + * + * @throws JAXBException + * If any unexpected problem occurs during the marshalling. + * @throws MarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Marshaller} is unable to marshal {@code jaxbElement} (or any + * object reachable from {@code jaxbElement}). See + * Marshalling a JAXB element. + * @throws IllegalArgumentException + * If any of the method parameters are null + */ + public void marshal( Object jaxbElement, javax.xml.transform.Result result ) + throws JAXBException; + + /** + * Marshal the content tree rooted at {@code jaxbElement} into an output stream. + * + * @param jaxbElement + * The root of content tree to be marshalled. + * @param os + * XML will be added to this stream. + * + * @throws JAXBException + * If any unexpected problem occurs during the marshalling. + * @throws MarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Marshaller} is unable to marshal {@code jaxbElement} (or any + * object reachable from {@code jaxbElement}). See + * Marshalling a JAXB element. + * @throws IllegalArgumentException + * If any of the method parameters are null + */ + public void marshal( Object jaxbElement, java.io.OutputStream os ) + throws JAXBException; + + /** + * Marshal the content tree rooted at {@code jaxbElement} into a file. + * + * @param jaxbElement + * The root of content tree to be marshalled. + * @param output + * File to be written. If this file already exists, it will be overwritten. + * + * @throws JAXBException + * If any unexpected problem occurs during the marshalling. + * @throws MarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Marshaller} is unable to marshal {@code jaxbElement} (or any + * object reachable from {@code jaxbElement}). See + * Marshalling a JAXB element. + * @throws IllegalArgumentException + * If any of the method parameters are null + * @since 1.6, JAXB 2.1 + */ + public void marshal( Object jaxbElement, File output ) + throws JAXBException; + + /** + * Marshal the content tree rooted at {@code jaxbElement} into a Writer. + * + * @param jaxbElement + * The root of content tree to be marshalled. + * @param writer + * XML will be sent to this writer. + * + * @throws JAXBException + * If any unexpected problem occurs during the marshalling. + * @throws MarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Marshaller} is unable to marshal {@code jaxbElement} (or any + * object reachable from {@code jaxbElement}). See + * Marshalling a JAXB element. + * @throws IllegalArgumentException + * If any of the method parameters are null + */ + public void marshal( Object jaxbElement, java.io.Writer writer ) + throws JAXBException; + + /** + * Marshal the content tree rooted at {@code jaxbElement} into SAX2 events. + * + * @param jaxbElement + * The root of content tree to be marshalled. + * @param handler + * XML will be sent to this handler as SAX2 events. + * + * @throws JAXBException + * If any unexpected problem occurs during the marshalling. + * @throws MarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Marshaller} is unable to marshal {@code jaxbElement} (or any + * object reachable from {@code jaxbElement}). See + * Marshalling a JAXB element. + * @throws IllegalArgumentException + * If any of the method parameters are null + */ + public void marshal( Object jaxbElement, org.xml.sax.ContentHandler handler ) + throws JAXBException; + + /** + * Marshal the content tree rooted at {@code jaxbElement} into a DOM tree. + * + * @param jaxbElement + * The content tree to be marshalled. + * @param node + * DOM nodes will be added as children of this node. + * This parameter must be a Node that accepts children + * ({@link org.w3c.dom.Document}, + * {@link org.w3c.dom.DocumentFragment}, or + * {@link org.w3c.dom.Element}) + * + * @throws JAXBException + * If any unexpected problem occurs during the marshalling. + * @throws MarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Marshaller} is unable to marshal {@code jaxbElement} (or any + * object reachable from {@code jaxbElement}). See + * Marshalling a JAXB element. + * @throws IllegalArgumentException + * If any of the method parameters are null + */ + public void marshal( Object jaxbElement, org.w3c.dom.Node node ) + throws JAXBException; + + /** + * Marshal the content tree rooted at {@code jaxbElement} into a + * {@link javax.xml.stream.XMLStreamWriter}. + * + * @param jaxbElement + * The content tree to be marshalled. + * @param writer + * XML will be sent to this writer. + * + * @throws JAXBException + * If any unexpected problem occurs during the marshalling. + * @throws MarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Marshaller} is unable to marshal {@code jaxbElement} (or any + * object reachable from {@code jaxbElement}). See + * Marshalling a JAXB element. + * @throws IllegalArgumentException + * If any of the method parameters are null + * @since 1.6, JAXB 2.0 + */ + public void marshal( Object jaxbElement, javax.xml.stream.XMLStreamWriter writer ) + throws JAXBException; + + /** + * Marshal the content tree rooted at {@code jaxbElement} into a + * {@link javax.xml.stream.XMLEventWriter}. + * + * @param jaxbElement + * The content tree rooted at jaxbElement to be marshalled. + * @param writer + * XML will be sent to this writer. + * + * @throws JAXBException + * If any unexpected problem occurs during the marshalling. + * @throws MarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Marshaller} is unable to marshal {@code jaxbElement} (or any + * object reachable from {@code jaxbElement}). See + * Marshalling a JAXB element. + * @throws IllegalArgumentException + * If any of the method parameters are null + * @since 1.6, JAXB 2.0 + */ + public void marshal( Object jaxbElement, javax.xml.stream.XMLEventWriter writer ) + throws JAXBException; + + /** + * Get a DOM tree view of the content tree(Optional). + * + * If the returned DOM tree is updated, these changes are also + * visible in the content tree. + * Use {@link #marshal(Object, org.w3c.dom.Node)} to force + * a deep copy of the content tree to a DOM representation. + * + * @param contentTree - JAXB Java representation of XML content + * + * @return the DOM tree view of the contentTree + * + * @throws UnsupportedOperationException + * If the JAXB provider implementation does not support a + * DOM view of the content tree + * + * @throws IllegalArgumentException + * If any of the method parameters are null + * + * @throws JAXBException + * If any unexpected problem occurs + * + */ + public org.w3c.dom.Node getNode( java.lang.Object contentTree ) + throws JAXBException; + + /** + * Set the particular property in the underlying implementation of + * {@code Marshaller}. This method can only be used to set one of + * the standard JAXB defined properties above or a provider specific + * property. Attempting to set an undefined property will result in + * a PropertyException being thrown. See + * Supported Properties. + * + * @param name the name of the property to be set. This value can either + * be specified using one of the constant fields or a user + * supplied string. + * @param value the value of the property to be set + * + * @throws PropertyException when there is an error processing the given + * property or value + * @throws IllegalArgumentException + * If the name parameter is null + */ + public void setProperty( String name, Object value ) + throws PropertyException; + + /** + * Get the particular property in the underlying implementation of + * {@code Marshaller}. This method can only be used to get one of + * the standard JAXB defined properties above or a provider specific + * property. Attempting to get an undefined property will result in + * a PropertyException being thrown. See + * Supported Properties. + * + * @param name the name of the property to retrieve + * @return the value of the requested property + * + * @throws PropertyException + * when there is an error retrieving the given property or value + * property name + * @throws IllegalArgumentException + * If the name parameter is null + */ + public Object getProperty( String name ) throws PropertyException; + + /** + * Allow an application to register a validation event handler. + *

+ * The validation event handler will be called by the JAXB Provider if any + * validation errors are encountered during calls to any of the marshal + * API's. If the client application does not register a validation event + * handler before invoking one of the marshal methods, then validation + * events will be handled by the default event handler which will terminate + * the marshal operation after the first error or fatal error is encountered. + *

+ * Calling this method with a null parameter will cause the Marshaller + * to revert back to the default default event handler. + * + * @param handler the validation event handler + * @throws JAXBException if an error was encountered while setting the + * event handler + */ + public void setEventHandler( ValidationEventHandler handler ) + throws JAXBException; + + /** + * Return the current event handler or the default event handler if one + * hasn't been set. + * + * @return the current ValidationEventHandler or the default event handler + * if it hasn't been set + * @throws JAXBException if an error was encountered while getting the + * current event handler + */ + public ValidationEventHandler getEventHandler() + throws JAXBException; + + + + /** + * Associates a configured instance of {@link XmlAdapter} with this marshaller. + * + *

+ * This is a convenience method that invokes {@code setAdapter(adapter.getClass(),adapter);}. + * + * @see #setAdapter(Class,XmlAdapter) + * @throws IllegalArgumentException + * if the adapter parameter is null. + * @throws UnsupportedOperationException + * if invoked agains a JAXB 1.0 implementation. + * @since 1.6, JAXB 2.0 + */ + public void setAdapter( XmlAdapter adapter ); + + /** + * Associates a configured instance of {@link XmlAdapter} with this marshaller. + * + *

+ * Every marshaller internally maintains a + * {@link java.util.Map}<{@link Class},{@link XmlAdapter}>, + * which it uses for marshalling classes whose fields/methods are annotated + * with {@link javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter}. + * + *

+ * This method allows applications to use a configured instance of {@link XmlAdapter}. + * When an instance of an adapter is not given, a marshaller will create + * one by invoking its default constructor. + * + * @param type + * The type of the adapter. The specified instance will be used when + * {@link javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter#value()} + * refers to this type. + * @param adapter + * The instance of the adapter to be used. If null, it will un-register + * the current adapter set for this type. + * @throws IllegalArgumentException + * if the type parameter is null. + * @throws UnsupportedOperationException + * if invoked agains a JAXB 1.0 implementation. + * @since 1.6, JAXB 2.0 + */ + public void setAdapter( Class type, A adapter ); + + /** + * Gets the adapter associated with the specified type. + * + * This is the reverse operation of the {@link #setAdapter} method. + * + * @throws IllegalArgumentException + * if the type parameter is null. + * @throws UnsupportedOperationException + * if invoked agains a JAXB 1.0 implementation. + * @since 1.6, JAXB 2.0 + */ + public A getAdapter( Class type ); + + + /** + *

Associate a context that enables binary data within an XML document + * to be transmitted as XML-binary optimized attachment. + * The attachment is referenced from the XML document content model + * by content-id URIs(cid) references stored within the xml document. + * + * @throws IllegalStateException if attempt to concurrently call this + * method during a marshal operation. + */ + void setAttachmentMarshaller(AttachmentMarshaller am); + + AttachmentMarshaller getAttachmentMarshaller(); + + /** + * Specify the JAXP 1.3 {@link javax.xml.validation.Schema Schema} + * object that should be used to validate subsequent marshal operations + * against. Passing null into this method will disable validation. + * + *

+ * This method allows the caller to validate the marshalled XML as it's marshalled. + * + *

+ * Initially this property is set to {@code null}. + * + * @param schema Schema object to validate marshal operations against or null to disable validation + * @throws UnsupportedOperationException could be thrown if this method is + * invoked on an Marshaller created from a JAXBContext referencing + * JAXB 1.0 mapped classes + * @since 1.6, JAXB 2.0 + */ + public void setSchema( Schema schema ); + + /** + * Get the JAXP 1.3 {@link javax.xml.validation.Schema Schema} object + * being used to perform marshal-time validation. If there is no + * Schema set on the marshaller, then this method will return null + * indicating that marshal-time validation will not be performed. + * + * @return the Schema object being used to perform marshal-time + * validation or null if not present. + * @throws UnsupportedOperationException could be thrown if this method is + * invoked on an Marshaller created from a JAXBContext referencing + * JAXB 1.0 mapped classes + * @since 1.6, JAXB 2.0 + */ + public Schema getSchema(); + + /** + *

+ * Register an instance of an implementation of this class with a {@link Marshaller} to externally listen + * for marshal events. + *

+ *

+ * This class enables pre and post processing of each marshalled object. + * The event callbacks are called when marshalling from an instance that maps to an xml element or + * complex type definition. The event callbacks are not called when marshalling from an instance of a + * Java datatype that represents a simple type definition. + *

+ *

+ * External listener is one of two different mechanisms for defining marshal event callbacks. + * See Marshal Event Callbacks for an overview. + * + * @see Marshaller#setListener(Listener) + * @see Marshaller#getListener() + * @since 1.6, JAXB 2.0 + */ + public static abstract class Listener { + /** + *

+ * Callback method invoked before marshalling from {@code source} to XML. + *

+ *

+ * This method is invoked just before marshalling process starts to marshal {@code source}. + * Note that if the class of {@code source} defines its own {@code beforeMarshal} method, + * the class specific callback method is invoked just before this method is invoked. + * + * @param source instance of JAXB mapped class prior to marshalling from it. + */ + public void beforeMarshal(Object source) { + } + + /** + *

+ * Callback method invoked after marshalling {@code source} to XML. + *

+ *

+ * This method is invoked after {@code source} and all its descendants have been marshalled. + * Note that if the class of {@code source} defines its own {@code afterMarshal} method, + * the class specific callback method is invoked just before this method is invoked. + * + * @param source instance of JAXB mapped class after marshalling it. + */ + public void afterMarshal(Object source) { + } + } + + /** + *

+ * Register marshal event callback {@link Listener} with this {@link Marshaller}. + * + *

+ * There is only one Listener per Marshaller. Setting a Listener replaces the previous set Listener. + * One can unregister current Listener by setting listener to {@code null}. + * + * @param listener an instance of a class that implements {@link Listener} + * @since 1.6, JAXB 2.0 + */ + public void setListener(Listener listener); + + /** + *

Return {@link Listener} registered with this {@link Marshaller}. + * + * @return registered {@link Listener} or {@code null} + * if no Listener is registered with this Marshaller. + * @since 1.6, JAXB 2.0 + */ + public Listener getListener(); +} + + + + diff --git a/fine-third-jdk11/src/javax/xml/bind/Messages.java b/fine-third-jdk11/src/javax/xml/bind/Messages.java new file mode 100644 index 000000000..eb07dfb9e --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/Messages.java @@ -0,0 +1,115 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +import java.text.MessageFormat; +import java.util.ResourceBundle; + +/** + * Formats error messages. + */ +class Messages +{ + static String format( String property ) { + return format( property, null ); + } + + static String format( String property, Object arg1 ) { + return format( property, new Object[]{arg1} ); + } + + static String format( String property, Object arg1, Object arg2 ) { + return format( property, new Object[]{arg1,arg2} ); + } + + static String format( String property, Object arg1, Object arg2, Object arg3 ) { + return format( property, new Object[]{arg1,arg2,arg3} ); + } + + // add more if necessary. + + /** Loads a string resource and formats it with specified arguments. */ + static String format( String property, Object[] args ) { + String text = ResourceBundle.getBundle(Messages.class.getName()).getString(property); + return MessageFormat.format(text,args); + } + +// +// +// Message resources +// +// + static final String PROVIDER_NOT_FOUND = // 1 arg + "ContextFinder.ProviderNotFound"; + + static final String DEFAULT_PROVIDER_NOT_FOUND = // 0 args + "ContextFinder.DefaultProviderNotFound"; + + static final String COULD_NOT_INSTANTIATE = // 2 args + "ContextFinder.CouldNotInstantiate"; + + static final String CANT_FIND_PROPERTIES_FILE = // 1 arg + "ContextFinder.CantFindPropertiesFile"; + + static final String CANT_MIX_PROVIDERS = // 0 args + "ContextFinder.CantMixProviders"; + + static final String MISSING_PROPERTY = // 2 args + "ContextFinder.MissingProperty"; + + static final String NO_PACKAGE_IN_CONTEXTPATH = // 0 args + "ContextFinder.NoPackageInContextPath"; + + static final String NAME_VALUE = // 2 args + "PropertyException.NameValue"; + + static final String CONVERTER_MUST_NOT_BE_NULL = // 0 args + "DatatypeConverter.ConverterMustNotBeNull"; + + static final String ILLEGAL_CAST = // 2 args + "JAXBContext.IllegalCast"; + + static final String ERROR_LOAD_CLASS = // 2 args + "ContextFinder.ErrorLoadClass"; + + static final String JAXB_CLASSES_NOT_OPEN = // 1 arg + "JAXBClasses.notOpen"; +} diff --git a/fine-third-jdk11/src/javax/xml/bind/ModuleUtil.java b/fine-third-jdk11/src/javax/xml/bind/ModuleUtil.java new file mode 100644 index 000000000..099f18bb5 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/ModuleUtil.java @@ -0,0 +1,78 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ +package javax.xml.bind; + +import java.io.IOException; + +/** + * Intended to be overridden on JDK9, with JEP 238 multi-release class copy. + * Contains only stubs for methods needed on JDK9 runtime. + * + * @author Roman Grigoriadi + */ +class ModuleUtil { + + /** + * Resolves classes from context path. + * Only one class per package is needed to access its {@link java.lang.Module} + */ + static Class[] getClassesFromContextPath(String contextPath, ClassLoader classLoader) throws JAXBException { + return null; + } + + /** + * Find first class in package by {@code jaxb.index} file. + */ + static Class findFirstByJaxbIndex(String pkg, ClassLoader classLoader) throws IOException, JAXBException { + return null; + } + + /** + * Implementation may be defined in other module than {@code java.xml.bind}. In that case openness + * {@linkplain java.lang.Module#isOpen open} of classes should be delegated to implementation module. + * + * @param classes used to resolve module for {@linkplain java.lang.Module#addOpens(String, java.lang.Module)} + * @param factorySPI used to resolve {@link java.lang.Module} of the implementation. + */ + static void delegateAddOpensToImplModule(Class[] classes, Class factorySPI) { + //stub + } + +} diff --git a/fine-third-jdk11/src/javax/xml/bind/NotIdentifiableEvent.java b/fine-third-jdk11/src/javax/xml/bind/NotIdentifiableEvent.java new file mode 100644 index 000000000..985dad95e --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/NotIdentifiableEvent.java @@ -0,0 +1,54 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +/** + * This event indicates that a problem was encountered resolving an ID/IDREF. + * + * + * @author

  • Ryan Shoemaker, Sun Microsystems, Inc.
  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • Joe Fialli, Sun Microsystems, Inc.
+ * @see Validator + * @see ValidationEventHandler + * @since 1.6, JAXB 1.0 + */ +public interface NotIdentifiableEvent extends ValidationEvent { + +} diff --git a/fine-third-jdk11/src/javax/xml/bind/ParseConversionEvent.java b/fine-third-jdk11/src/javax/xml/bind/ParseConversionEvent.java new file mode 100644 index 000000000..2f9821727 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/ParseConversionEvent.java @@ -0,0 +1,55 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +/** + * This event indicates that a problem was encountered while converting a + * string from the XML data into a value of the target Java data type. + * + * @author
  • Ryan Shoemaker, Sun Microsystems, Inc.
  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • Joe Fialli, Sun Microsystems, Inc.
+ * @see ValidationEvent + * @see ValidationEventHandler + * @see Unmarshaller + * @since 1.6, JAXB 1.0 + */ +public interface ParseConversionEvent extends ValidationEvent { + +} diff --git a/fine-third-jdk11/src/javax/xml/bind/PrintConversionEvent.java b/fine-third-jdk11/src/javax/xml/bind/PrintConversionEvent.java new file mode 100644 index 000000000..af9a72c6e --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/PrintConversionEvent.java @@ -0,0 +1,55 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +/** + * This event indicates that a problem was encountered while converting data + * from the Java content tree into its lexical representation. + * + * @author
  • Ryan Shoemaker, Sun Microsystems, Inc.
  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • Joe Fialli, Sun Microsystems, Inc.
+ * @see ValidationEvent + * @see ValidationEventHandler + * @see Marshaller + * @since 1.6, JAXB 1.0 + */ +public interface PrintConversionEvent extends ValidationEvent { + +} diff --git a/fine-third-jdk11/src/javax/xml/bind/PropertyException.java b/fine-third-jdk11/src/javax/xml/bind/PropertyException.java new file mode 100644 index 000000000..97dc99942 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/PropertyException.java @@ -0,0 +1,128 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + + + +/** + * This exception indicates that an error was encountered while getting or + * setting a property. + * + * @author
  • Ryan Shoemaker, Sun Microsystems, Inc.
  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • Joe Fialli, Sun Microsystems, Inc.
+ * @see JAXBContext + * @see Validator + * @see Unmarshaller + * @since 1.6, JAXB 1.0 + */ +public class PropertyException extends JAXBException { + + /** + * Construct a PropertyException with the specified detail message. The + * errorCode and linkedException will default to null. + * + * @param message a description of the exception + */ + public PropertyException(String message) { + super(message); + } + + /** + * Construct a PropertyException with the specified detail message and + * vendor specific errorCode. The linkedException will default to null. + * + * @param message a description of the exception + * @param errorCode a string specifying the vendor specific error code + */ + public PropertyException(String message, String errorCode) { + super(message, errorCode); + } + + /** + * Construct a PropertyException with a linkedException. The detail + * message and vendor specific errorCode will default to null. + * + * @param exception the linked exception + */ + public PropertyException(Throwable exception) { + super(exception); + } + + /** + * Construct a PropertyException with the specified detail message and + * linkedException. The errorCode will default to null. + * + * @param message a description of the exception + * @param exception the linked exception + */ + public PropertyException(String message, Throwable exception) { + super(message, exception); + } + + /** + * Construct a PropertyException with the specified detail message, vendor + * specific errorCode, and linkedException. + * + * @param message a description of the exception + * @param errorCode a string specifying the vendor specific error code + * @param exception the linked exception + */ + public PropertyException( + String message, + String errorCode, + Throwable exception) { + super(message, errorCode, exception); + } + + /** + * Construct a PropertyException whose message field is set based on the + * name of the property and value.toString(). + * + * @param name the name of the property related to this exception + * @param value the value of the property related to this exception + */ + public PropertyException(String name, Object value) { + super( Messages.format( Messages.NAME_VALUE, + name, + value.toString() ) ); + } + + +} diff --git a/fine-third-jdk11/src/javax/xml/bind/SchemaOutputResolver.java b/fine-third-jdk11/src/javax/xml/bind/SchemaOutputResolver.java new file mode 100644 index 000000000..73c329aa7 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/SchemaOutputResolver.java @@ -0,0 +1,98 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +import javax.xml.transform.Result; +import java.io.IOException; + +/** + * Controls where a JAXB implementation puts the generates + * schema files. + * + *

+ * An implementation of this abstract class has to be provided by the calling + * application to generate schemas. + * + *

+ * This is a class, not an interface so as to allow future versions to evolve + * without breaking the compatibility. + * + * @author + * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) + * @since 1.6 + */ +public abstract class SchemaOutputResolver { + /** + * Decides where the schema file (of the given namespace URI) + * will be written, and return it as a {@link Result} object. + * + *

+ * This method is called only once for any given namespace. + * IOW, all the components in one namespace is always written + * into the same schema document. + * + * @param namespaceUri + * The namespace URI that the schema declares. + * Can be the empty string, but never be null. + * @param suggestedFileName + * A JAXB implementation generates an unique file name (like "schema1.xsd") + * for the convenience of the callee. This name can be + * used for the file name of the schema, or the callee can just + * ignore this name and come up with its own name. + * This is just a hint. + * + * @return + * a {@link Result} object that encapsulates the actual destination + * of the schema. + * + * If the {@link Result} object has a system ID, it must be an + * absolute system ID. Those system IDs are relativized by the caller and used + * for {@literal } statements. + * + * If the {@link Result} object does not have a system ID, a schema + * for the namespace URI is generated but it won't be explicitly + * {@literal }ed from other schemas. + * + * If {@code null} is returned, the schema generation for this + * namespace URI will be skipped. + */ + public abstract Result createOutput( String namespaceUri, String suggestedFileName ) throws IOException; +} diff --git a/fine-third-jdk11/src/javax/xml/bind/ServiceLoaderUtil.java b/fine-third-jdk11/src/javax/xml/bind/ServiceLoaderUtil.java new file mode 100644 index 000000000..f5bc4d54b --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/ServiceLoaderUtil.java @@ -0,0 +1,172 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2015-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Iterator; +import java.util.ServiceLoader; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Shared ServiceLoader/FactoryFinder Utils shared among SAAJ, JAXB and JAXWS + * - this class must be duplicated to all those projects, but it's + * basically generic code and we want to have it everywhere same. + * + * @author Miroslav.Kos@oracle.com + */ +class ServiceLoaderUtil { + + private static final String OSGI_SERVICE_LOADER_CLASS_NAME = "org.glassfish.hk2.osgiresourcelocator.ServiceLoader"; + private static final String OSGI_SERVICE_LOADER_METHOD_NAME = "lookupProviderClasses"; + + static P firstByServiceLoader(Class

spiClass, + Logger logger, + ExceptionHandler handler) throws T { + // service discovery + try { + ServiceLoader

serviceLoader = ServiceLoader.load(spiClass); + + for (P impl : serviceLoader) { + logger.fine("ServiceProvider loading Facility used; returning object [" + + impl.getClass().getName() + "]"); + + return impl; + } + } catch (Throwable t) { + throw handler.createException(t, "Error while searching for service [" + spiClass.getName() + "]"); + } + return null; + } + + static Object lookupUsingOSGiServiceLoader(String factoryId, Logger logger) { + + try { + // Use reflection to avoid having any dependendcy on ServiceLoader class + Class serviceClass = Class.forName(factoryId); + Class target = Class.forName(OSGI_SERVICE_LOADER_CLASS_NAME); + Method m = target.getMethod(OSGI_SERVICE_LOADER_METHOD_NAME, Class.class); + Iterator iter = ((Iterable) m.invoke(null, serviceClass)).iterator(); + if (iter.hasNext()) { + Object next = iter.next(); + logger.fine("Found implementation using OSGi facility; returning object [" + + next.getClass().getName() + "]."); + return next; + } else { + return null; + } + } catch (IllegalAccessException | + InvocationTargetException | + ClassNotFoundException | + NoSuchMethodException ignored) { + + logger.log(Level.FINE, "Unable to find from OSGi: [" + factoryId + "]", ignored); + return null; + } + } + + static void checkPackageAccess(String className) { + // make sure that the current thread has an access to the package of the given name. + SecurityManager s = System.getSecurityManager(); + if (s != null) { + int i = className.lastIndexOf('.'); + if (i != -1) { + s.checkPackageAccess(className.substring(0, i)); + } + } + } + + static Class nullSafeLoadClass(String className, ClassLoader classLoader) throws ClassNotFoundException { + if (classLoader == null) { + return Class.forName(className); + } else { + return classLoader.loadClass(className); + } + } + + // Returns instance of required class. It checks package access (security) + // unless it is defaultClassname. It means if you are trying to instantiate + // default implementation (fallback), pass the class name to both first and second parameter. + static Object newInstance(String className, + String defaultImplClassName, + final ExceptionHandler handler) throws T { + try { + return safeLoadClass(className, defaultImplClassName, contextClassLoader(handler)).newInstance(); + } catch (ClassNotFoundException x) { + throw handler.createException(x, "Provider " + className + " not found"); + } catch (Exception x) { + throw handler.createException(x, "Provider " + className + " could not be instantiated: " + x); + } + } + + static Class safeLoadClass(String className, + String defaultImplClassName, + ClassLoader classLoader) throws ClassNotFoundException { + + try { + checkPackageAccess(className); + } catch (SecurityException se) { + // anyone can access the platform default factory class without permission + if (defaultImplClassName != null && defaultImplClassName.equals(className)) { + return Class.forName(className); + } + // not platform default implementation ... + throw se; + } + return nullSafeLoadClass(className, classLoader); + } + + static ClassLoader contextClassLoader(ExceptionHandler exceptionHandler) throws Exception { + try { + return Thread.currentThread().getContextClassLoader(); + } catch (Exception x) { + throw exceptionHandler.createException(x, x.toString()); + } + } + + static abstract class ExceptionHandler { + + public abstract T createException(Throwable throwable, String message); + + } + +} diff --git a/fine-third-jdk11/src/javax/xml/bind/TypeConstraintException.java b/fine-third-jdk11/src/javax/xml/bind/TypeConstraintException.java new file mode 100644 index 000000000..26d6557eb --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/TypeConstraintException.java @@ -0,0 +1,199 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +/** + * This exception indicates that a violation of a dynamically checked type + * constraint was detected. + * + *

+ * This exception can be thrown by the generated setter methods of the schema + * derived Java content classes. However, since fail-fast validation is + * an optional feature for JAXB Providers to support, not all setter methods + * will throw this exception when a type constraint is violated. + * + *

+ * If this exception is throw while invoking a fail-fast setter, the value of + * the property is guaranteed to remain unchanged, as if the setter were never + * called. + * + * @author

  • Ryan Shoemaker, Sun Microsystems, Inc.
  • Joe Fialli, Sun Microsystems, Inc.
+ * @see ValidationEvent + * @since 1.6, JAXB 1.0 + */ + +public class TypeConstraintException extends java.lang.RuntimeException { + + /** + * Vendor specific error code + * + */ + private String errorCode; + + /** + * Exception reference + * + */ + private volatile Throwable linkedException; + + static final long serialVersionUID = -3059799699420143848L; + + /** + * Construct a TypeConstraintException with the specified detail message. The + * errorCode and linkedException will default to null. + * + * @param message a description of the exception + */ + public TypeConstraintException(String message) { + this( message, null, null ); + } + + /** + * Construct a TypeConstraintException with the specified detail message and vendor + * specific errorCode. The linkedException will default to null. + * + * @param message a description of the exception + * @param errorCode a string specifying the vendor specific error code + */ + public TypeConstraintException(String message, String errorCode) { + this( message, errorCode, null ); + } + + /** + * Construct a TypeConstraintException with a linkedException. The detail message and + * vendor specific errorCode will default to null. + * + * @param exception the linked exception + */ + public TypeConstraintException(Throwable exception) { + this( null, null, exception ); + } + + /** + * Construct a TypeConstraintException with the specified detail message and + * linkedException. The errorCode will default to null. + * + * @param message a description of the exception + * @param exception the linked exception + */ + public TypeConstraintException(String message, Throwable exception) { + this( message, null, exception ); + } + + /** + * Construct a TypeConstraintException with the specified detail message, + * vendor specific errorCode, and linkedException. + * + * @param message a description of the exception + * @param errorCode a string specifying the vendor specific error code + * @param exception the linked exception + */ + public TypeConstraintException(String message, String errorCode, Throwable exception) { + super( message ); + this.errorCode = errorCode; + this.linkedException = exception; + } + + /** + * Get the vendor specific error code + * + * @return a string specifying the vendor specific error code + */ + public String getErrorCode() { + return this.errorCode; + } + + /** + * Get the linked exception + * + * @return the linked Exception, null if none exists + */ + public Throwable getLinkedException() { + return linkedException; + } + + /** + * Add a linked Exception. + * + * @param exception the linked Exception (A null value is permitted and + * indicates that the linked exception does not exist or + * is unknown). + */ + public void setLinkedException( Throwable exception ) { + this.linkedException = exception; + } + + /** + * Returns a short description of this TypeConstraintException. + * + */ + public String toString() { + return linkedException == null ? + super.toString() : + super.toString() + "\n - with linked exception:\n[" + + linkedException.toString()+ "]"; + } + + /** + * Prints this TypeConstraintException and its stack trace (including the stack trace + * of the linkedException if it is non-null) to the PrintStream. + * + * @param s PrintStream to use for output + */ + public void printStackTrace( java.io.PrintStream s ) { + if( linkedException != null ) { + linkedException.printStackTrace(s); + s.println("--------------- linked to ------------------"); + } + + super.printStackTrace(s); + } + + /** + * Prints this TypeConstraintException and its stack trace (including the stack trace + * of the linkedException if it is non-null) to {@code System.err}. + * + */ + public void printStackTrace() { + printStackTrace(System.err); + } + +} diff --git a/fine-third-jdk11/src/javax/xml/bind/UnmarshalException.java b/fine-third-jdk11/src/javax/xml/bind/UnmarshalException.java new file mode 100644 index 000000000..08a5f86a6 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/UnmarshalException.java @@ -0,0 +1,118 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +/** + * This exception indicates that an error has occurred while performing + * an unmarshal operation that prevents the JAXB Provider from completing + * the operation. + * + *

+ * The {@code ValidationEventHandler} can cause this exception to be thrown + * during the unmarshal operations. See + * {@link ValidationEventHandler#handleEvent(ValidationEvent) + * ValidationEventHandler.handleEvent(ValidationEvent)}. + * + * @author

  • Ryan Shoemaker, Sun Microsystems, Inc.
+ * @see JAXBException + * @see Unmarshaller + * @see ValidationEventHandler + * @since 1.6, JAXB 1.0 + */ +public class UnmarshalException extends JAXBException { + + /** + * Construct an UnmarshalException with the specified detail message. The + * errorCode and linkedException will default to null. + * + * @param message a description of the exception + */ + public UnmarshalException( String message ) { + this( message, null, null ); + } + + /** + * Construct an UnmarshalException with the specified detail message and vendor + * specific errorCode. The linkedException will default to null. + * + * @param message a description of the exception + * @param errorCode a string specifying the vendor specific error code + */ + public UnmarshalException( String message, String errorCode ) { + this( message, errorCode, null ); + } + + /** + * Construct an UnmarshalException with a linkedException. The detail message and + * vendor specific errorCode will default to null. + * + * @param exception the linked exception + */ + public UnmarshalException( Throwable exception ) { + this( null, null, exception ); + } + + /** + * Construct an UnmarshalException with the specified detail message and + * linkedException. The errorCode will default to null. + * + * @param message a description of the exception + * @param exception the linked exception + */ + public UnmarshalException( String message, Throwable exception ) { + this( message, null, exception ); + } + + /** + * Construct an UnmarshalException with the specified detail message, vendor + * specific errorCode, and linkedException. + * + * @param message a description of the exception + * @param errorCode a string specifying the vendor specific error code + * @param exception the linked exception + */ + public UnmarshalException( String message, String errorCode, Throwable exception ) { + super( message, errorCode, exception ); + } + +} + + diff --git a/fine-third-jdk11/src/javax/xml/bind/Unmarshaller.java b/fine-third-jdk11/src/javax/xml/bind/Unmarshaller.java new file mode 100644 index 000000000..f706f7418 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/Unmarshaller.java @@ -0,0 +1,1154 @@ + +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +import javax.xml.bind.annotation.adapters.XmlAdapter; +import javax.xml.bind.attachment.AttachmentUnmarshaller; +import javax.xml.validation.Schema; +import java.io.Reader; + +/** + * The {@code Unmarshaller} class governs the process of deserializing XML + * data into newly created Java content trees, optionally validating the XML + * data as it is unmarshalled. It provides an overloading of unmarshal methods + * for many different input kinds. + * + *

+ * Unmarshalling from a File: + *

+ *
+ *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
+ *       Unmarshaller u = jc.createUnmarshaller();
+ *       Object o = u.unmarshal( new File( "nosferatu.xml" ) );
+ *    
+ *
+ * + * + *

+ * Unmarshalling from an InputStream: + *

+ *
+ *       InputStream is = new FileInputStream( "nosferatu.xml" );
+ *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
+ *       Unmarshaller u = jc.createUnmarshaller();
+ *       Object o = u.unmarshal( is );
+ *    
+ *
+ * + *

+ * Unmarshalling from a URL: + *

+ *
+ *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
+ *       Unmarshaller u = jc.createUnmarshaller();
+ *       URL url = new URL( "http://beaker.east/nosferatu.xml" );
+ *       Object o = u.unmarshal( url );
+ *    
+ *
+ * + *

+ * Unmarshalling from a StringBuffer using a + * {@code javax.xml.transform.stream.StreamSource}: + *

+ *
{@code
+ *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
+ *       Unmarshaller u = jc.createUnmarshaller();
+ *       StringBuffer xmlStr = new StringBuffer( "..." );
+ *       Object o = u.unmarshal( new StreamSource( new StringReader( xmlStr.toString() ) ) );
+ *    }
+ *
+ * + *

+ * Unmarshalling from a {@code org.w3c.dom.Node}: + *

+ *
+ *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
+ *       Unmarshaller u = jc.createUnmarshaller();
+ * 
+ *       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ *       dbf.setNamespaceAware(true);
+ *       DocumentBuilder db = dbf.newDocumentBuilder();
+ *       Document doc = db.parse(new File( "nosferatu.xml"));
+
+ *       Object o = u.unmarshal( doc );
+ *    
+ *
+ * + *

+ * Unmarshalling from a {@code javax.xml.transform.sax.SAXSource} using a + * client specified validating SAX2.0 parser: + *

+ *
+ *       // configure a validating SAX2.0 parser (Xerces2)
+ *       static final String JAXP_SCHEMA_LANGUAGE =
+ *           "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
+ *       static final String JAXP_SCHEMA_LOCATION =
+ *           "http://java.sun.com/xml/jaxp/properties/schemaSource";
+ *       static final String W3C_XML_SCHEMA =
+ *           "http://www.w3.org/2001/XMLSchema";
+ *
+ *       System.setProperty( "javax.xml.parsers.SAXParserFactory",
+ *                           "org.apache.xerces.jaxp.SAXParserFactoryImpl" );
+ *
+ *       SAXParserFactory spf = SAXParserFactory.newInstance();
+ *       spf.setNamespaceAware(true);
+ *       spf.setValidating(true);
+ *       SAXParser saxParser = spf.newSAXParser();
+ *       
+ *       try {
+ *           saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
+ *           saxParser.setProperty(JAXP_SCHEMA_LOCATION, "http://....");
+ *       } catch (SAXNotRecognizedException x) {
+ *           // exception handling omitted
+ *       }
+ *
+ *       XMLReader xmlReader = saxParser.getXMLReader();
+ *       SAXSource source = 
+ *           new SAXSource( xmlReader, new InputSource( "http://..." ) );
+ *
+ *       // Setup JAXB to unmarshal
+ *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
+ *       Unmarshaller u = jc.createUnmarshaller();
+ *       ValidationEventCollector vec = new ValidationEventCollector();
+ *       u.setEventHandler( vec );
+ *       
+ *       // turn off the JAXB provider's default validation mechanism to 
+ *       // avoid duplicate validation
+ *       u.setValidating( false )
+ *
+ *       // unmarshal
+ *       Object o = u.unmarshal( source );
+ *
+ *       // check for events
+ *       if( vec.hasEvents() ) {
+ *          // iterate over events
+ *       }
+ *    
+ *
+ * + *

+ * Unmarshalling from a StAX XMLStreamReader: + *

+ *
+ *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
+ *       Unmarshaller u = jc.createUnmarshaller();
+ * 
+ *       javax.xml.stream.XMLStreamReader xmlStreamReader = 
+ *           javax.xml.stream.XMLInputFactory().newInstance().createXMLStreamReader( ... );
+ * 
+ *       Object o = u.unmarshal( xmlStreamReader );
+ *    
+ *
+ * + *

+ * Unmarshalling from a StAX XMLEventReader: + *

+ *
+ *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
+ *       Unmarshaller u = jc.createUnmarshaller();
+ * 
+ *       javax.xml.stream.XMLEventReader xmlEventReader = 
+ *           javax.xml.stream.XMLInputFactory().newInstance().createXMLEventReader( ... );
+ * 
+ *       Object o = u.unmarshal( xmlEventReader );
+ *    
+ *
+ * + *

+ * + * Unmarshalling XML Data
+ *

+ * Unmarshalling can deserialize XML data that represents either an entire XML document + * or a subtree of an XML document. Typically, it is sufficient to use the + * unmarshalling methods described by + * Unmarshal root element that is declared globally. + * These unmarshal methods utilize {@link JAXBContext}'s mapping of global XML element + * declarations and type definitions to JAXB mapped classes to initiate the + * unmarshalling of the root element of XML data. When the {@link JAXBContext}'s + * mappings are not sufficient to unmarshal the root element of XML data, + * the application can assist the unmarshalling process by using the + * unmarshal by declaredType methods. + * These methods are useful for unmarshalling XML data where + * the root element corresponds to a local element declaration in the schema. + *
+ * + *
+ * An unmarshal method never returns null. If the unmarshal process is unable to unmarshal + * the root of XML content to a JAXB mapped object, a fatal error is reported that + * terminates processing by throwing JAXBException. + *
+ * + *

+ * + * Unmarshal a root element that is globally declared
+ *

+ * The unmarshal methods that do not have an {@code declaredType} parameter use + * {@link JAXBContext} to unmarshal the root element of an XML data. The {@link JAXBContext} + * instance is the one that was used to create this {@code Unmarshaller}. The {@link JAXBContext} + * instance maintains a mapping of globally declared XML element and type definition names to + * JAXB mapped classes. The unmarshal method checks if {@link JAXBContext} has a mapping + * from the root element's XML name and/or {@code @xsi:type} to a JAXB mapped class. If it does, it umarshalls the + * XML data using the appropriate JAXB mapped class. Note that when the root element name is unknown and the root + * element has an {@code @xsi:type}, the XML data is unmarshalled + * using that JAXB mapped class as the value of a {@link JAXBElement}. + * When the {@link JAXBContext} object does not have a mapping for the root element's name + * nor its {@code @xsi:type}, if it exists, + * then the unmarshal operation will abort immediately by throwing a {@link UnmarshalException + * UnmarshalException}. This exception scenario can be worked around by using the unmarshal by + * declaredType methods described in the next subsection. + *
+ * + *

+ * + * Unmarshal by Declared Type
+ *

+ * The unmarshal methods with a {@code declaredType} parameter enable an + * application to deserialize a root element of XML data, even when + * there is no mapping in {@link JAXBContext} of the root element's XML name. + * The unmarshaller unmarshals the root element using the application provided + * mapping specified as the {@code declaredType} parameter. + * Note that even when the root element's element name is mapped by {@link JAXBContext}, + * the {@code declaredType} parameter overrides that mapping for + * deserializing the root element when using these unmarshal methods. + * Additionally, when the root element of XML data has an {@code xsi:type} attribute and + * that attribute's value references a type definition that is mapped + * to a JAXB mapped class by {@link JAXBContext}, that the root + * element's {@code xsi:type} attribute takes + * precedence over the unmarshal methods {@code declaredType} parameter. + * These methods always return a {@code JAXBElement} + * instance. The table below shows how the properties of the returned JAXBElement + * instance are set. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Unmarshal By Declared Type returned JAXBElement
JAXBElement PropertyValue
name{@code xml element name}
value{@code instanceof declaredType}
declaredTypeunmarshal method {@code declaredType} parameter
scope{@code null} (actual scope is unknown)
+ *
+ * + *

+ * The following is an example of + * unmarshal by declaredType method. + *

+ * Unmarshal by declaredType from a {@code org.w3c.dom.Node}: + *

+ *
{@code 
+ *       Schema fragment for example
+ *       
+ *          ...<\xs:complexType>
+ *          
+ *          
+ *              
+ *                 
+ *                    
+ *                    
+ *                    ...
+ *                 
+ *              
+ *          
+ *       
+ *
+ *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
+ *       Unmarshaller u = jc.createUnmarshaller();
+ * 
+ *       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ *       dbf.setNamespaceAware(true);
+ *       DocumentBuilder db = dbf.newDocumentBuilder();
+ *       Document doc = db.parse(new File( "nosferatu.xml"));
+ *       Element  fooSubtree = ...; // traverse DOM till reach xml element foo, constrained by a 
+ *                                  // local element declaration in schema.
+ * 
+ *       // FooType is the JAXB mapping of the type of local element declaration foo.
+ *       JAXBElement foo = u.unmarshal( fooSubtree, FooType.class);
+ *    }
+ *
+ * + *

+ * Support for SAX2.0 Compliant Parsers
+ *

+ * A client application has the ability to select the SAX2.0 compliant parser + * of their choice. If a SAX parser is not selected, then the JAXB Provider's + * default parser will be used. Even though the JAXB Provider's default parser + * is not required to be SAX2.0 compliant, all providers are required to allow + * a client application to specify their own SAX2.0 parser. Some providers may + * require the client application to specify the SAX2.0 parser at schema compile + * time. See {@link #unmarshal(javax.xml.transform.Source) unmarshal(Source)} + * for more detail. + *
+ * + *

+ * Validation and Well-Formedness
+ *

+ *

+ * A client application can enable or disable JAXP 1.3 validation + * mechanism via the {@code setSchema(javax.xml.validation.Schema)} API. + * Sophisticated clients can specify their own validating SAX 2.0 compliant + * parser and bypass the JAXP 1.3 validation mechanism using the + * {@link #unmarshal(javax.xml.transform.Source) unmarshal(Source)} API. + * + *

+ * Since unmarshalling invalid XML content is defined in JAXB 2.0, + * the Unmarshaller default validation event handler was made more lenient + * than in JAXB 1.0. When schema-derived code generated + * by JAXB 1.0 binding compiler is registered with {@link JAXBContext}, + * the default unmarshal validation handler is + * {@link javax.xml.bind.helpers.DefaultValidationEventHandler} and it + * terminates the marshal operation after encountering either a fatal error or an error. + * For a JAXB 2.0 client application, there is no explicitly defined default + * validation handler and the default event handling only + * terminates the unmarshal operation after encountering a fatal error. + * + *

+ * + *

+ * + * Supported Properties
+ *

+ *

+ * There currently are not any properties required to be supported by all + * JAXB Providers on Unmarshaller. However, some providers may support + * their own set of provider specific properties. + *

+ * + *

+ * + * Unmarshal Event Callbacks
+ *

+ * The {@link Unmarshaller} provides two styles of callback mechanisms + * that allow application specific processing during key points in the + * unmarshalling process. In 'class defined' event callbacks, application + * specific code placed in JAXB mapped classes is triggered during + * unmarshalling. 'External listeners' allow for centralized processing + * of unmarshal events in one callback method rather than by type event callbacks. + *

+ * 'Class defined' event callback methods allow any JAXB mapped class to specify + * its own specific callback methods by defining methods with the following method signature: + *

+ *
+ *   // This method is called immediately after the object is created and before the unmarshalling of this 
+ *   // object begins. The callback provides an opportunity to initialize JavaBean properties prior to unmarshalling.
+ *   void beforeUnmarshal(Unmarshaller, Object parent);
+ * 
+ *   //This method is called after all the properties (except IDREF) are unmarshalled for this object, 
+ *   //but before this object is set to the parent object.
+ *   void afterUnmarshal(Unmarshaller, Object parent);
+ * 
+ *
+ * The class defined callback methods should be used when the callback method requires + * access to non-public methods and/or fields of the class. + *

+ * The external listener callback mechanism enables the registration of a {@link Listener} + * instance with an {@link Unmarshaller#setListener(Listener)}. The external listener receives all callback events, + * allowing for more centralized processing than per class defined callback methods. The external listener + * receives events when unmarshalling process is marshalling to a JAXB element or to JAXB mapped class. + *

+ * The 'class defined' and external listener event callback methods are independent of each other, + * both can be called for one event. The invocation ordering when both listener callback methods exist is + * defined in {@link Listener#beforeUnmarshal(Object, Object)} and {@link Listener#afterUnmarshal(Object, Object)}. +*

+ * An event callback method throwing an exception terminates the current unmarshal process. + * + *

+ * + * @author
  • Ryan Shoemaker, Sun Microsystems, Inc.
  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • Joe Fialli, Sun Microsystems, Inc.
+ * @see JAXBContext + * @see Marshaller + * @see Validator + * @since 1.6, JAXB 1.0 + */ +public interface Unmarshaller { + + /** + * Unmarshal XML data from the specified file and return the resulting + * content tree. + * + *

+ * Implements Unmarshal Global Root Element. + * + * @param f the file to unmarshal XML data from + * @return the newly created root object of the java content tree + * + * @throws JAXBException + * If any unexpected errors occur while unmarshalling + * @throws UnmarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Unmarshaller} is unable to perform the XML to Java + * binding. See Unmarshalling XML Data + * @throws IllegalArgumentException + * If the file parameter is null + */ + public Object unmarshal( java.io.File f ) throws JAXBException; + + /** + * Unmarshal XML data from the specified InputStream and return the + * resulting content tree. Validation event location information may + * be incomplete when using this form of the unmarshal API. + * + *

+ * Implements Unmarshal Global Root Element. + * + * @param is the InputStream to unmarshal XML data from + * @return the newly created root object of the java content tree + * + * @throws JAXBException + * If any unexpected errors occur while unmarshalling + * @throws UnmarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Unmarshaller} is unable to perform the XML to Java + * binding. See Unmarshalling XML Data + * @throws IllegalArgumentException + * If the InputStream parameter is null + */ + public Object unmarshal( java.io.InputStream is ) throws JAXBException; + + /** + * Unmarshal XML data from the specified Reader and return the + * resulting content tree. Validation event location information may + * be incomplete when using this form of the unmarshal API, + * because a Reader does not provide the system ID. + * + *

+ * Implements Unmarshal Global Root Element. + * + * @param reader the Reader to unmarshal XML data from + * @return the newly created root object of the java content tree + * + * @throws JAXBException + * If any unexpected errors occur while unmarshalling + * @throws UnmarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Unmarshaller} is unable to perform the XML to Java + * binding. See Unmarshalling XML Data + * @throws IllegalArgumentException + * If the InputStream parameter is null + * @since 1.6, JAXB 2.0 + */ + public Object unmarshal( Reader reader ) throws JAXBException; + + /** + * Unmarshal XML data from the specified URL and return the resulting + * content tree. + * + *

+ * Implements Unmarshal Global Root Element. + * + * @param url the url to unmarshal XML data from + * @return the newly created root object of the java content tree + * + * @throws JAXBException + * If any unexpected errors occur while unmarshalling + * @throws UnmarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Unmarshaller} is unable to perform the XML to Java + * binding. See Unmarshalling XML Data + * @throws IllegalArgumentException + * If the URL parameter is null + */ + public Object unmarshal( java.net.URL url ) throws JAXBException; + + /** + * Unmarshal XML data from the specified SAX InputSource and return the + * resulting content tree. + * + *

+ * Implements Unmarshal Global Root Element. + * + * @param source the input source to unmarshal XML data from + * @return the newly created root object of the java content tree + * + * @throws JAXBException + * If any unexpected errors occur while unmarshalling + * @throws UnmarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Unmarshaller} is unable to perform the XML to Java + * binding. See Unmarshalling XML Data + * @throws IllegalArgumentException + * If the InputSource parameter is null + */ + public Object unmarshal( org.xml.sax.InputSource source ) throws JAXBException; + + /** + * Unmarshal global XML data from the specified DOM tree and return the resulting + * content tree. + * + *

+ * Implements Unmarshal Global Root Element. + * + * @param node + * the document/element to unmarshal XML data from. + * The caller must support at least Document and Element. + * @return the newly created root object of the java content tree + * + * @throws JAXBException + * If any unexpected errors occur while unmarshalling + * @throws UnmarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Unmarshaller} is unable to perform the XML to Java + * binding. See Unmarshalling XML Data + * @throws IllegalArgumentException + * If the Node parameter is null + * @see #unmarshal(org.w3c.dom.Node, Class) + */ + public Object unmarshal( org.w3c.dom.Node node ) throws JAXBException; + + /** + * Unmarshal XML data by JAXB mapped {@code declaredType} + * and return the resulting content tree. + * + *

+ * Implements Unmarshal by Declared Type + * + * @param node + * the document/element to unmarshal XML data from. + * The caller must support at least Document and Element. + * @param declaredType + * appropriate JAXB mapped class to hold {@code node}'s XML data. + * + * @return JAXB Element representation of {@code node} + * + * @throws JAXBException + * If any unexpected errors occur while unmarshalling + * @throws UnmarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Unmarshaller} is unable to perform the XML to Java + * binding. See Unmarshalling XML Data + * @throws IllegalArgumentException + * If any parameter is null + * @since 1.6, JAXB 2.0 + */ + public JAXBElement unmarshal( org.w3c.dom.Node node, Class declaredType ) throws JAXBException; + + /** + * Unmarshal XML data from the specified XML Source and return the + * resulting content tree. + * + *

+ * Implements Unmarshal Global Root Element. + * + *

+ * + * SAX 2.0 Parser Pluggability + *

+ * A client application can choose not to use the default parser mechanism + * supplied with their JAXB provider. Any SAX 2.0 compliant parser can be + * substituted for the JAXB provider's default mechanism. To do so, the + * client application must properly configure a {@code SAXSource} containing + * an {@code XMLReader} implemented by the SAX 2.0 parser provider. If the + * {@code XMLReader} has an {@code org.xml.sax.ErrorHandler} registered + * on it, it will be replaced by the JAXB Provider so that validation errors + * can be reported via the {@code ValidationEventHandler} mechanism of + * JAXB. If the {@code SAXSource} does not contain an {@code XMLReader}, + * then the JAXB provider's default parser mechanism will be used. + *

+ * This parser replacement mechanism can also be used to replace the JAXB + * provider's unmarshal-time validation engine. The client application + * must properly configure their SAX 2.0 compliant parser to perform + * validation (as shown in the example above). Any {@code SAXParserExceptions} + * encountered by the parser during the unmarshal operation will be + * processed by the JAXB provider and converted into JAXB + * {@code ValidationEvent} objects which will be reported back to the + * client via the {@code ValidationEventHandler} registered with the + * {@code Unmarshaller}. Note: specifying a substitute validating + * SAX 2.0 parser for unmarshalling does not necessarily replace the + * validation engine used by the JAXB provider for performing on-demand + * validation. + *

+ * The only way for a client application to specify an alternate parser + * mechanism to be used during unmarshal is via the + * {@code unmarshal(SAXSource)} API. All other forms of the unmarshal + * method (File, URL, Node, etc) will use the JAXB provider's default + * parser and validator mechanisms. + * + * @param source the XML Source to unmarshal XML data from (providers are + * only required to support SAXSource, DOMSource, and StreamSource) + * @return the newly created root object of the java content tree + * + * @throws JAXBException + * If any unexpected errors occur while unmarshalling + * @throws UnmarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Unmarshaller} is unable to perform the XML to Java + * binding. See Unmarshalling XML Data + * @throws IllegalArgumentException + * If the Source parameter is null + * @see #unmarshal(javax.xml.transform.Source, Class) + */ + public Object unmarshal( javax.xml.transform.Source source ) + throws JAXBException; + + + /** + * Unmarshal XML data from the specified XML Source by {@code declaredType} and return the + * resulting content tree. + * + *

+ * Implements Unmarshal by Declared Type + * + *

+ * See SAX 2.0 Parser Pluggability + * + * @param source the XML Source to unmarshal XML data from (providers are + * only required to support SAXSource, DOMSource, and StreamSource) + * @param declaredType + * appropriate JAXB mapped class to hold {@code source}'s xml root element + * @return Java content rooted by JAXB Element + * + * @throws JAXBException + * If any unexpected errors occur while unmarshalling + * @throws UnmarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Unmarshaller} is unable to perform the XML to Java + * binding. See Unmarshalling XML Data + * @throws IllegalArgumentException + * If any parameter is null + * @since 1.6, JAXB 2.0 + */ + public JAXBElement unmarshal( javax.xml.transform.Source source, Class declaredType ) + throws JAXBException; + + /** + * Unmarshal XML data from the specified pull parser and return the + * resulting content tree. + * + *

+ * Implements Unmarshal Global Root Element. + * + *

+ * This method assumes that the parser is on a START_DOCUMENT or + * START_ELEMENT event. Unmarshalling will be done from this + * start event to the corresponding end event. If this method + * returns successfully, the {@code reader} will be pointing at + * the token right after the end event. + * + * @param reader + * The parser to be read. + * @return + * the newly created root object of the java content tree. + * + * @throws JAXBException + * If any unexpected errors occur while unmarshalling + * @throws UnmarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Unmarshaller} is unable to perform the XML to Java + * binding. See Unmarshalling XML Data + * @throws IllegalArgumentException + * If the {@code reader} parameter is null + * @throws IllegalStateException + * If {@code reader} is not pointing to a START_DOCUMENT or + * START_ELEMENT event. + * @since 1.6, JAXB 2.0 + * @see #unmarshal(javax.xml.stream.XMLStreamReader, Class) + */ + public Object unmarshal( javax.xml.stream.XMLStreamReader reader ) + throws JAXBException; + + /** + * Unmarshal root element to JAXB mapped {@code declaredType} + * and return the resulting content tree. + * + *

+ * This method implements unmarshal by declaredType. + *

+ * This method assumes that the parser is on a START_DOCUMENT or + * START_ELEMENT event. Unmarshalling will be done from this + * start event to the corresponding end event. If this method + * returns successfully, the {@code reader} will be pointing at + * the token right after the end event. + * + * @param reader + * The parser to be read. + * @param declaredType + * appropriate JAXB mapped class to hold {@code reader}'s START_ELEMENT XML data. + * + * @return content tree rooted by JAXB Element representation + * + * @throws JAXBException + * If any unexpected errors occur while unmarshalling + * @throws UnmarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Unmarshaller} is unable to perform the XML to Java + * binding. See Unmarshalling XML Data + * @throws IllegalArgumentException + * If any parameter is null + * @since 1.6, JAXB 2.0 + */ + public JAXBElement unmarshal( javax.xml.stream.XMLStreamReader reader, Class declaredType ) throws JAXBException; + + /** + * Unmarshal XML data from the specified pull parser and return the + * resulting content tree. + * + *

+ * This method is an Unmarshal Global Root method. + * + *

+ * This method assumes that the parser is on a START_DOCUMENT or + * START_ELEMENT event. Unmarshalling will be done from this + * start event to the corresponding end event. If this method + * returns successfully, the {@code reader} will be pointing at + * the token right after the end event. + * + * @param reader + * The parser to be read. + * @return + * the newly created root object of the java content tree. + * + * @throws JAXBException + * If any unexpected errors occur while unmarshalling + * @throws UnmarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Unmarshaller} is unable to perform the XML to Java + * binding. See Unmarshalling XML Data + * @throws IllegalArgumentException + * If the {@code reader} parameter is null + * @throws IllegalStateException + * If {@code reader} is not pointing to a START_DOCUMENT or + * START_ELEMENT event. + * @since 1.6, JAXB 2.0 + * @see #unmarshal(javax.xml.stream.XMLEventReader, Class) + */ + public Object unmarshal( javax.xml.stream.XMLEventReader reader ) + throws JAXBException; + + /** + * Unmarshal root element to JAXB mapped {@code declaredType} + * and return the resulting content tree. + * + *

+ * This method implements unmarshal by declaredType. + * + *

+ * This method assumes that the parser is on a START_DOCUMENT or + * START_ELEMENT event. Unmarshalling will be done from this + * start event to the corresponding end event. If this method + * returns successfully, the {@code reader} will be pointing at + * the token right after the end event. + * + * @param reader + * The parser to be read. + * @param declaredType + * appropriate JAXB mapped class to hold {@code reader}'s START_ELEMENT XML data. + * + * @return content tree rooted by JAXB Element representation + * + * @throws JAXBException + * If any unexpected errors occur while unmarshalling + * @throws UnmarshalException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Unmarshaller} is unable to perform the XML to Java + * binding. See Unmarshalling XML Data + * @throws IllegalArgumentException + * If any parameter is null + * @since 1.6, JAXB 2.0 + */ + public JAXBElement unmarshal( javax.xml.stream.XMLEventReader reader, Class declaredType ) throws JAXBException; + + /** + * Get an unmarshaller handler object that can be used as a component in + * an XML pipeline. + * + *

+ * The JAXB Provider can return the same handler object for multiple + * invocations of this method. In other words, this method does not + * necessarily create a new instance of {@code UnmarshallerHandler}. If the + * application needs to use more than one {@code UnmarshallerHandler}, it + * should create more than one {@code Unmarshaller}. + * + * @return the unmarshaller handler object + * @see UnmarshallerHandler + */ + public UnmarshallerHandler getUnmarshallerHandler(); + + /** + * Specifies whether or not the default validation mechanism of the + * {@code Unmarshaller} should validate during unmarshal operations. + * By default, the {@code Unmarshaller} does not validate. + *

+ * This method may only be invoked before or after calling one of the + * unmarshal methods. + *

+ * This method only controls the JAXB Provider's default unmarshal-time + * validation mechanism - it has no impact on clients that specify their + * own validating SAX 2.0 compliant parser. Clients that specify their + * own unmarshal-time validation mechanism may wish to turn off the JAXB + * Provider's default validation mechanism via this API to avoid "double + * validation". + *

+ * This method is deprecated as of JAXB 2.0 - please use the new + * {@link #setSchema(javax.xml.validation.Schema)} API. + * + * @param validating true if the Unmarshaller should validate during + * unmarshal, false otherwise + * @throws JAXBException if an error occurred while enabling or disabling + * validation at unmarshal time + * @throws UnsupportedOperationException could be thrown if this method is + * invoked on an Unmarshaller created from a JAXBContext referencing + * JAXB 2.0 mapped classes + * @deprecated since JAXB2.0, please see {@link #setSchema(javax.xml.validation.Schema)} + */ + public void setValidating( boolean validating ) + throws JAXBException; + + /** + * Indicates whether or not the {@code Unmarshaller} is configured to + * validate during unmarshal operations. + *

+ * This API returns the state of the JAXB Provider's default unmarshal-time + * validation mechanism. + *

+ * This method is deprecated as of JAXB 2.0 - please use the new + * {@link #getSchema()} API. + * + * @return true if the Unmarshaller is configured to validate during + * unmarshal operations, false otherwise + * @throws JAXBException if an error occurs while retrieving the validating + * flag + * @throws UnsupportedOperationException could be thrown if this method is + * invoked on an Unmarshaller created from a JAXBContext referencing + * JAXB 2.0 mapped classes + * @deprecated since JAXB2.0, please see {@link #getSchema()} + */ + public boolean isValidating() + throws JAXBException; + + /** + * Allow an application to register a {@code ValidationEventHandler}. + *

+ * The {@code ValidationEventHandler} will be called by the JAXB Provider + * if any validation errors are encountered during calls to any of the + * unmarshal methods. If the client application does not register a + * {@code ValidationEventHandler} before invoking the unmarshal methods, + * then {@code ValidationEvents} will be handled by the default event + * handler which will terminate the unmarshal operation after the first + * error or fatal error is encountered. + *

+ * Calling this method with a null parameter will cause the Unmarshaller + * to revert back to the default event handler. + * + * @param handler the validation event handler + * @throws JAXBException if an error was encountered while setting the + * event handler + */ + public void setEventHandler( ValidationEventHandler handler ) + throws JAXBException; + + /** + * Return the current event handler or the default event handler if one + * hasn't been set. + * + * @return the current ValidationEventHandler or the default event handler + * if it hasn't been set + * @throws JAXBException if an error was encountered while getting the + * current event handler + */ + public ValidationEventHandler getEventHandler() + throws JAXBException; + + /** + * Set the particular property in the underlying implementation of + * {@code Unmarshaller}. This method can only be used to set one of + * the standard JAXB defined properties above or a provider specific + * property. Attempting to set an undefined property will result in + * a PropertyException being thrown. See + * Supported Properties. + * + * @param name the name of the property to be set. This value can either + * be specified using one of the constant fields or a user + * supplied string. + * @param value the value of the property to be set + * + * @throws PropertyException when there is an error processing the given + * property or value + * @throws IllegalArgumentException + * If the name parameter is null + */ + public void setProperty( String name, Object value ) + throws PropertyException; + + /** + * Get the particular property in the underlying implementation of + * {@code Unmarshaller}. This method can only be used to get one of + * the standard JAXB defined properties above or a provider specific + * property. Attempting to get an undefined property will result in + * a PropertyException being thrown. See + * Supported Properties. + * + * @param name the name of the property to retrieve + * @return the value of the requested property + * + * @throws PropertyException + * when there is an error retrieving the given property or value + * property name + * @throws IllegalArgumentException + * If the name parameter is null + */ + public Object getProperty( String name ) throws PropertyException; + + /** + * Specify the JAXP 1.3 {@link javax.xml.validation.Schema Schema} + * object that should be used to validate subsequent unmarshal operations + * against. Passing null into this method will disable validation. + *

+ * This method replaces the deprecated {@link #setValidating(boolean) setValidating(boolean)} + * API. + * + *

+ * Initially this property is set to {@code null}. + * + * @param schema Schema object to validate unmarshal operations against or null to disable validation + * @throws UnsupportedOperationException could be thrown if this method is + * invoked on an Unmarshaller created from a JAXBContext referencing + * JAXB 1.0 mapped classes + * @since 1.6, JAXB 2.0 + */ + public void setSchema( javax.xml.validation.Schema schema ); + + /** + * Get the JAXP 1.3 {@link javax.xml.validation.Schema Schema} object + * being used to perform unmarshal-time validation. If there is no + * Schema set on the unmarshaller, then this method will return null + * indicating that unmarshal-time validation will not be performed. + *

+ * This method provides replacement functionality for the deprecated + * {@link #isValidating()} API as well as access to the Schema object. + * To determine if the Unmarshaller has validation enabled, simply + * test the return type for null: + *

{@code
+     *   boolean isValidating = u.getSchema()!=null;
+     * }
+ * + * @return the Schema object being used to perform unmarshal-time + * validation or null if not present + * @throws UnsupportedOperationException could be thrown if this method is + * invoked on an Unmarshaller created from a JAXBContext referencing + * JAXB 1.0 mapped classes + * @since 1.6, JAXB 2.0 + */ + public javax.xml.validation.Schema getSchema(); + + /** + * Associates a configured instance of {@link XmlAdapter} with this unmarshaller. + * + *

+ * This is a convenience method that invokes {@code setAdapter(adapter.getClass(),adapter);}. + * + * @see #setAdapter(Class,XmlAdapter) + * @throws IllegalArgumentException + * if the adapter parameter is null. + * @throws UnsupportedOperationException + * if invoked agains a JAXB 1.0 implementation. + * @since 1.6, JAXB 2.0 + */ + public void setAdapter( XmlAdapter adapter ); + + /** + * Associates a configured instance of {@link XmlAdapter} with this unmarshaller. + * + *

+ * Every unmarshaller internally maintains a + * {@link java.util.Map}<{@link Class},{@link XmlAdapter}>, + * which it uses for unmarshalling classes whose fields/methods are annotated + * with {@link javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter}. + * + *

+ * This method allows applications to use a configured instance of {@link XmlAdapter}. + * When an instance of an adapter is not given, an unmarshaller will create + * one by invoking its default constructor. + * + * @param type + * The type of the adapter. The specified instance will be used when + * {@link javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter#value()} + * refers to this type. + * @param adapter + * The instance of the adapter to be used. If null, it will un-register + * the current adapter set for this type. + * @throws IllegalArgumentException + * if the type parameter is null. + * @throws UnsupportedOperationException + * if invoked agains a JAXB 1.0 implementation. + * @since 1.6, JAXB 2.0 + */ + public void setAdapter( Class type, A adapter ); + + /** + * Gets the adapter associated with the specified type. + * + * This is the reverse operation of the {@link #setAdapter} method. + * + * @throws IllegalArgumentException + * if the type parameter is null. + * @throws UnsupportedOperationException + * if invoked agains a JAXB 1.0 implementation. + * @since 1.6, JAXB 2.0 + */ + public A getAdapter( Class type ); + + /** + *

Associate a context that resolves cid's, content-id URIs, to + * binary data passed as attachments.

+ *

Unmarshal time validation, enabled via {@link #setSchema(Schema)}, + * must be supported even when unmarshaller is performing XOP processing. + *

+ * + * @throws IllegalStateException if attempt to concurrently call this + * method during a unmarshal operation. + */ + void setAttachmentUnmarshaller(AttachmentUnmarshaller au); + + AttachmentUnmarshaller getAttachmentUnmarshaller(); + + /** + *

+ * Register an instance of an implementation of this class with {@link Unmarshaller} to externally listen + * for unmarshal events. + *

+ *

+ * This class enables pre and post processing of an instance of a JAXB mapped class + * as XML data is unmarshalled into it. The event callbacks are called when unmarshalling + * XML content into a JAXBElement instance or a JAXB mapped class that represents a complex type definition. + * The event callbacks are not called when unmarshalling to an instance of a + * Java datatype that represents a simple type definition. + *

+ *

+ * External listener is one of two different mechanisms for defining unmarshal event callbacks. + * See Unmarshal Event Callbacks for an overview. + *

+ * (@link #setListener(Listener)} + * (@link #getListener()} + * + * @since 1.6, JAXB 2.0 + */ + public static abstract class Listener { + /** + *

+ * Callback method invoked before unmarshalling into {@code target}. + *

+ *

+ * This method is invoked immediately after {@code target} was created and + * before the unmarshalling of this object begins. Note that + * if the class of {@code target} defines its own {@code beforeUnmarshal} method, + * the class specific callback method is invoked before this method is invoked. + * + * @param target non-null instance of JAXB mapped class prior to unmarshalling into it. + * @param parent instance of JAXB mapped class that will eventually reference {@code target}. + * {@code null} when {@code target} is root element. + */ + public void beforeUnmarshal(Object target, Object parent) { + } + + /** + *

+ * Callback method invoked after unmarshalling XML data into {@code target}. + *

+ *

+ * This method is invoked after all the properties (except IDREF) + * are unmarshalled into {@code target}, + * but before {@code target} is set into its {@code parent} object. + * Note that if the class of {@code target} defines its own {@code afterUnmarshal} method, + * the class specific callback method is invoked before this method is invoked. + * + * @param target non-null instance of JAXB mapped class prior to unmarshalling into it. + * @param parent instance of JAXB mapped class that will reference {@code target}. + * {@code null} when {@code target} is root element. + */ + public void afterUnmarshal(Object target, Object parent) { + } + } + + /** + *

+ * Register unmarshal event callback {@link Listener} with this {@link Unmarshaller}. + * + *

+ * There is only one Listener per Unmarshaller. Setting a Listener replaces the previous set Listener. + * One can unregister current Listener by setting listener to {@code null}. + * + * @param listener provides unmarshal event callbacks for this {@link Unmarshaller} + * @since 1.6, JAXB 2.0 + */ + public void setListener(Listener listener); + + /** + *

Return {@link Listener} registered with this {@link Unmarshaller}. + * + * @return registered {@link Listener} or {@code null} + * if no Listener is registered with this Unmarshaller. + * @since 1.6, JAXB 2.0 + */ + public Listener getListener(); +} diff --git a/fine-third-jdk11/src/javax/xml/bind/UnmarshallerHandler.java b/fine-third-jdk11/src/javax/xml/bind/UnmarshallerHandler.java new file mode 100644 index 000000000..d9ed481bd --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/UnmarshallerHandler.java @@ -0,0 +1,98 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +import org.xml.sax.ContentHandler; + +/** + * Unmarshaller implemented as SAX ContentHandler. + * + *

+ * Applications can use this interface to use their JAXB provider as a component + * in an XML pipeline. For example: + * + *

+ *       JAXBContext context = JAXBContext.newInstance( "org.acme.foo" );
+ *
+ *       Unmarshaller unmarshaller = context.createUnmarshaller();
+ * 
+ *       UnmarshallerHandler unmarshallerHandler = unmarshaller.getUnmarshallerHandler();
+ *
+ *       SAXParserFactory spf = SAXParserFactory.newInstance();
+ *       spf.setNamespaceAware( true );
+ * 
+ *       XMLReader xmlReader = spf.newSAXParser().getXMLReader();
+ *       xmlReader.setContentHandler( unmarshallerHandler );
+ *       xmlReader.parse(new InputSource( new FileInputStream( XML_FILE ) ) );
+ *
+ *       MyObject myObject= (MyObject)unmarshallerHandler.getResult();                          
+ * 
+ * + *

+ * This interface is reusable: even if the user fails to unmarshal + * an object, s/he can still start a new round of unmarshalling. + * + * @author

  • Kohsuke KAWAGUCHI, Sun Microsystems, Inc.
+ * @see Unmarshaller#getUnmarshallerHandler() + * @since 1.6, JAXB 1.0 + */ +public interface UnmarshallerHandler extends ContentHandler +{ + /** + * Obtains the unmarshalled result. + * + * This method can be called only after this handler + * receives the endDocument SAX event. + * + * @exception IllegalStateException + * if this method is called before this handler + * receives the endDocument event. + * + * @exception JAXBException + * if there is any unmarshalling error. + * Note that the implementation is allowed to throw SAXException + * during the parsing when it finds an error. + * + * @return + * always return a non-null valid object which was unmarshalled. + */ + Object getResult() throws JAXBException, IllegalStateException; +} diff --git a/fine-third-jdk11/src/javax/xml/bind/ValidationEvent.java b/fine-third-jdk11/src/javax/xml/bind/ValidationEvent.java new file mode 100644 index 000000000..ec025e11a --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/ValidationEvent.java @@ -0,0 +1,107 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +/** + * This event indicates that a problem was encountered while validating the + * incoming XML data during an unmarshal operation, while performing + * on-demand validation of the Java content tree, or while marshalling the + * Java content tree back to XML data. + * + * @author
  • Ryan Shoemaker, Sun Microsystems, Inc.
  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • Joe Fialli, Sun Microsystems, Inc.
+ * @see Validator + * @see ValidationEventHandler + * @since 1.6, JAXB 1.0 + */ +public interface ValidationEvent { + + /** + * Conditions that are not errors or fatal errors as defined by the + * XML 1.0 recommendation + */ + public static final int WARNING = 0; + + /** + * Conditions that correspond to the definition of "error" in section + * 1.2 of the W3C XML 1.0 Recommendation + */ + public static final int ERROR = 1; + + /** + * Conditions that correspond to the definition of "fatal error" in section + * 1.2 of the W3C XML 1.0 Recommendation + */ + public static final int FATAL_ERROR = 2; + + /** + * Retrieve the severity code for this warning/error. + * + *

+ * Must be one of {@code ValidationEvent.WARNING}, + * {@code ValidationEvent.ERROR}, or {@code ValidationEvent.FATAL_ERROR}. + * + * @return the severity code for this warning/error + */ + public int getSeverity(); + + /** + * Retrieve the text message for this warning/error. + * + * @return the text message for this warning/error or null if one wasn't set + */ + public String getMessage(); + + /** + * Retrieve the linked exception for this warning/error. + * + * @return the linked exception for this warning/error or null if one + * wasn't set + */ + public Throwable getLinkedException(); + + /** + * Retrieve the locator for this warning/error. + * + * @return the locator that indicates where the warning/error occurred + */ + public ValidationEventLocator getLocator(); + +} diff --git a/fine-third-jdk11/src/javax/xml/bind/ValidationEventHandler.java b/fine-third-jdk11/src/javax/xml/bind/ValidationEventHandler.java new file mode 100644 index 000000000..bfda9dd07 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/ValidationEventHandler.java @@ -0,0 +1,112 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +/** + * A basic event handler interface for validation errors. + * + *

+ * If an application needs to implement customized event handling, it must + * implement this interface and then register it with either the + * {@link Unmarshaller#setEventHandler(ValidationEventHandler) Unmarshaller}, + * the {@link Validator#setEventHandler(ValidationEventHandler) Validator}, or + * the {@link Marshaller#setEventHandler(ValidationEventHandler) Marshaller}. + * The JAXB Provider will then report validation errors and warnings encountered + * during the unmarshal, marshal, and validate operations to these event + * handlers. + * + *

+ * If the {@code handleEvent} method throws an unchecked runtime exception, + * the JAXB Provider must treat that as if the method returned false, effectively + * terminating whatever operation was in progress at the time (unmarshal, + * validate, or marshal). + * + *

+ * Modifying the Java content tree within your event handler is undefined + * by the specification and may result in unexpected behaviour. + * + *

+ * Failing to return false from the {@code handleEvent} method after + * encountering a fatal error is undefined by the specification and may result + * in unexpected behavior. + * + *

+ * Default Event Handler + *

+ * See: Validator javadocs + *
+ * + * @author
  • Ryan Shoemaker, Sun Microsystems, Inc.
  • + *
  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • + *
  • Joe Fialli, Sun Microsystems, Inc.
+ * @see Unmarshaller + * @see Validator + * @see Marshaller + * @see ValidationEvent + * @see javax.xml.bind.util.ValidationEventCollector + * @since 1.6, JAXB 1.0 + */ +public interface ValidationEventHandler { + /** + * Receive notification of a validation warning or error. + * + * The ValidationEvent will have a + * {@link ValidationEventLocator ValidationEventLocator} embedded in it that + * indicates where the error or warning occurred. + * + *

+ * If an unchecked runtime exception is thrown from this method, the JAXB + * provider will treat it as if the method returned false and interrupt + * the current unmarshal, validate, or marshal operation. + * + * @param event the encapsulated validation event information. It is a + * provider error if this parameter is null. + * @return true if the JAXB Provider should attempt to continue the current + * unmarshal, validate, or marshal operation after handling this + * warning/error, false if the provider should terminate the current + * operation with the appropriate {@code UnmarshalException}, + * {@code ValidationException}, or {@code MarshalException}. + * @throws IllegalArgumentException if the event object is null. + */ + public boolean handleEvent( ValidationEvent event ); + +} + diff --git a/fine-third-jdk11/src/javax/xml/bind/ValidationEventLocator.java b/fine-third-jdk11/src/javax/xml/bind/ValidationEventLocator.java new file mode 100644 index 000000000..f64dfadb6 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/ValidationEventLocator.java @@ -0,0 +1,107 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +/** + * Encapsulate the location of a ValidationEvent. + * + *

+ * The {@code ValidationEventLocator} indicates where the {@code ValidationEvent} + * occurred. Different fields will be set depending on the type of + * validation that was being performed when the error or warning was detected. + * For example, on-demand validation would produce locators that contained + * references to objects in the Java content tree while unmarshal-time + * validation would produce locators containing information appropriate to the + * source of the XML data (file, url, Node, etc). + * + * @author

  • Ryan Shoemaker, Sun Microsystems, Inc.
  • + *
  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • + *
  • Joe Fialli, Sun Microsystems, Inc.
+ * @see Validator + * @see ValidationEvent + * @since 1.6, JAXB 1.0 + */ +public interface ValidationEventLocator { + + /** + * Return the name of the XML source as a URL if available + * + * @return the name of the XML source as a URL or null if unavailable + */ + public java.net.URL getURL(); + + /** + * Return the byte offset if available + * + * @return the byte offset into the input source or -1 if unavailable + */ + public int getOffset(); + + /** + * Return the line number if available + * + * @return the line number or -1 if unavailable + */ + public int getLineNumber(); + + /** + * Return the column number if available + * + * @return the column number or -1 if unavailable + */ + public int getColumnNumber(); + + /** + * Return a reference to the object in the Java content tree if available + * + * @return a reference to the object in the Java content tree or null if + * unavailable + */ + public java.lang.Object getObject(); + + /** + * Return a reference to the DOM Node if available + * + * @return a reference to the DOM Node or null if unavailable + */ + public org.w3c.dom.Node getNode(); + +} diff --git a/fine-third-jdk11/src/javax/xml/bind/ValidationException.java b/fine-third-jdk11/src/javax/xml/bind/ValidationException.java new file mode 100644 index 000000000..a4990cb3e --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/ValidationException.java @@ -0,0 +1,114 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +/** + * This exception indicates that an error has occurred while performing + * a validate operation. + * + *

+ * The {@code ValidationEventHandler} can cause this exception to be thrown + * during the validate operations. See + * {@link ValidationEventHandler#handleEvent(ValidationEvent) + * ValidationEventHandler.handleEvent(ValidationEvent)}. + * + * @author

  • Ryan Shoemaker, Sun Microsystems, Inc.
+ * @see JAXBException + * @see Validator + * @since 1.6, JAXB 1.0 + */ +public class ValidationException extends JAXBException { + + /** + * Construct an ValidationException with the specified detail message. The + * errorCode and linkedException will default to null. + * + * @param message a description of the exception + */ + public ValidationException(String message) { + this( message, null, null ); + } + + /** + * Construct an ValidationException with the specified detail message and vendor + * specific errorCode. The linkedException will default to null. + * + * @param message a description of the exception + * @param errorCode a string specifying the vendor specific error code + */ + public ValidationException(String message, String errorCode) { + this( message, errorCode, null ); + } + + /** + * Construct an ValidationException with a linkedException. The detail message and + * vendor specific errorCode will default to null. + * + * @param exception the linked exception + */ + public ValidationException(Throwable exception) { + this( null, null, exception ); + } + + /** + * Construct an ValidationException with the specified detail message and + * linkedException. The errorCode will default to null. + * + * @param message a description of the exception + * @param exception the linked exception + */ + public ValidationException(String message, Throwable exception) { + this( message, null, exception ); + } + + /** + * Construct an ValidationException with the specified detail message, vendor + * specific errorCode, and linkedException. + * + * @param message a description of the exception + * @param errorCode a string specifying the vendor specific error code + * @param exception the linked exception + */ + public ValidationException(String message, String errorCode, Throwable exception) { + super( message, errorCode, exception ); + } + +} diff --git a/fine-third-jdk11/src/javax/xml/bind/Validator.java b/fine-third-jdk11/src/javax/xml/bind/Validator.java new file mode 100644 index 000000000..4a0756d2a --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/Validator.java @@ -0,0 +1,300 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +/** + * As of JAXB 2.0, this class is deprecated and optional. + *

+ * The {@code Validator} class is responsible for controlling the validation + * of content trees during runtime. + * + *

+ * + * Three Forms of Validation
+ *

+ *
+ *
Unmarshal-Time Validation
+ *
This form of validation enables a client application to receive + * information about validation errors and warnings detected while + * unmarshalling XML data into a Java content tree and is completely + * orthogonal to the other types of validation. To enable or disable + * it, see the javadoc for + * {@link Unmarshaller#setValidating(boolean) Unmarshaller.setValidating}. + * All JAXB 1.0 Providers are required to support this operation. + *
+ * + *
On-Demand Validation
+ *
This form of validation enables a client application to receive + * information about validation errors and warnings detected in the + * Java content tree. At any point, client applications can call + * the {@link Validator#validate(Object) Validator.validate} method + * on the Java content tree (or any sub-tree of it). All JAXB 1.0 + * Providers are required to support this operation. + *
+ * + *
Fail-Fast Validation
+ *
This form of validation enables a client application to receive + * immediate feedback about modifications to the Java content tree + * that violate type constraints on Java Properties as defined in + * the specification. JAXB Providers are not required support + * this type of validation. Of the JAXB Providers that do support + * this type of validation, some may require you to decide at schema + * compile time whether or not a client application will be allowed + * to request fail-fast validation at runtime. + *
+ *
+ *
+ * + *

+ * The {@code Validator} class is responsible for managing On-Demand Validation. + * The {@code Unmarshaller} class is responsible for managing Unmarshal-Time + * Validation during the unmarshal operations. Although there is no formal + * method of enabling validation during the marshal operations, the + * {@code Marshaller} may detect errors, which will be reported to the + * {@code ValidationEventHandler} registered on it. + * + *

+ * + * Using the Default EventHandler
+ *

+ * If the client application does not set an event handler on their + * {@code Validator}, {@code Unmarshaller}, or {@code Marshaller} prior to + * calling the validate, unmarshal, or marshal methods, then a default event + * handler will receive notification of any errors or warnings encountered. + * The default event handler will cause the current operation to halt after + * encountering the first error or fatal error (but will attempt to continue + * after receiving warnings). + *
+ * + *

+ * + * Handling Validation Events
+ *

+ * There are three ways to handle events encountered during the unmarshal, + * validate, and marshal operations: + *
+ *
Use the default event handler
+ *
The default event handler will be used if you do not specify one + * via the {@code setEventHandler} API's on {@code Validator}, + * {@code Unmarshaller}, or {@code Marshaller}. + *
+ * + *
Implement and register a custom event handler
+ *
Client applications that require sophisticated event processing + * can implement the {@code ValidationEventHandler} interface and + * register it with the {@code Unmarshaller} and/or + * {@code Validator}. + *
+ * + *
Use the {@link javax.xml.bind.util.ValidationEventCollector ValidationEventCollector} + * utility
+ *
For convenience, a specialized event handler is provided that + * simply collects any {@code ValidationEvent} objects created + * during the unmarshal, validate, and marshal operations and + * returns them to the client application as a + * {@code java.util.Collection}. + *
+ *
+ *
+ * + *

+ * Validation and Well-Formedness
+ *

+ *

+ * Validation events are handled differently depending on how the client + * application is configured to process them as described in the previous + * section. However, there are certain cases where a JAXB Provider indicates + * that it is no longer able to reliably detect and report errors. In these + * cases, the JAXB Provider will set the severity of the ValidationEvent to + * FATAL_ERROR to indicate that the unmarshal, validate, or marshal operations + * should be terminated. The default event handler and + * {@code ValidationEventCollector} utility class must terminate processing + * after being notified of a fatal error. Client applications that supply their + * own {@code ValidationEventHandler} should also terminate processing after + * being notified of a fatal error. If not, unexpected behaviour may occur. + *

+ * + *

+ * + * Supported Properties
+ *

+ *

+ * There currently are not any properties required to be supported by all + * JAXB Providers on Validator. However, some providers may support + * their own set of provider specific properties. + *

+ * + * + * @author
  • Ryan Shoemaker, Sun Microsystems, Inc.
  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • Joe Fialli, Sun Microsystems, Inc.
+ * @see JAXBContext + * @see Unmarshaller + * @see ValidationEventHandler + * @see ValidationEvent + * @see javax.xml.bind.util.ValidationEventCollector + * @since 1.6, JAXB 1.0 + * @deprecated since JAXB 2.0 + */ +public interface Validator { + + /** + * Allow an application to register a validation event handler. + *

+ * The validation event handler will be called by the JAXB Provider if any + * validation errors are encountered during calls to + * {@link #validate(Object) validate}. If the client application does not + * register a validation event handler before invoking the validate method, + * then validation events will be handled by the default event handler which + * will terminate the validate operation after the first error or fatal error + * is encountered. + *

+ * Calling this method with a null parameter will cause the Validator + * to revert back to the default default event handler. + * + * @param handler the validation event handler + * @throws JAXBException if an error was encountered while setting the + * event handler + * @deprecated since JAXB2.0 + */ + public void setEventHandler( ValidationEventHandler handler ) + throws JAXBException; + + /** + * Return the current event handler or the default event handler if one + * hasn't been set. + * + * @return the current ValidationEventHandler or the default event handler + * if it hasn't been set + * @throws JAXBException if an error was encountered while getting the + * current event handler + * @deprecated since JAXB2.0 + */ + public ValidationEventHandler getEventHandler() + throws JAXBException; + + /** + * Validate the Java content tree starting at {@code subrootObj}. + *

+ * Client applications can use this method to validate Java content trees + * on-demand at runtime. This method can be used to validate any arbitrary + * subtree of the Java content tree. Global constraint checking will not + * be performed as part of this operation (i.e. ID/IDREF constraints). + * + * @param subrootObj the obj to begin validation at + * @throws JAXBException if any unexpected problem occurs during validation + * @throws ValidationException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Validator} is unable to validate the content tree rooted + * at {@code subrootObj} + * @throws IllegalArgumentException + * If the subrootObj parameter is null + * @return true if the subtree rooted at {@code subrootObj} is valid, false + * otherwise + * @deprecated since JAXB2.0 + */ + public boolean validate( Object subrootObj ) throws JAXBException; + + /** + * Validate the Java content tree rooted at {@code rootObj}. + *

+ * Client applications can use this method to validate Java content trees + * on-demand at runtime. This method is used to validate an entire Java + * content tree. Global constraint checking will be performed as + * part of this operation (i.e. ID/IDREF constraints). + * + * @param rootObj the root obj to begin validation at + * @throws JAXBException if any unexpected problem occurs during validation + * @throws ValidationException + * If the {@link ValidationEventHandler ValidationEventHandler} + * returns false from its {@code handleEvent} method or the + * {@code Validator} is unable to validate the content tree rooted + * at {@code rootObj} + * @throws IllegalArgumentException + * If the rootObj parameter is null + * @return true if the tree rooted at {@code rootObj} is valid, false + * otherwise + * @deprecated since JAXB2.0 + */ + public boolean validateRoot( Object rootObj ) throws JAXBException; + + /** + * Set the particular property in the underlying implementation of + * {@code Validator}. This method can only be used to set one of + * the standard JAXB defined properties above or a provider specific + * property. Attempting to set an undefined property will result in + * a PropertyException being thrown. See + * Supported Properties. + * + * @param name the name of the property to be set. This value can either + * be specified using one of the constant fields or a user + * supplied string. + * @param value the value of the property to be set + * + * @throws PropertyException when there is an error processing the given + * property or value + * @throws IllegalArgumentException + * If the name parameter is null + * @deprecated since JAXB2.0 + */ + public void setProperty( String name, Object value ) + throws PropertyException; + + /** + * Get the particular property in the underlying implementation of + * {@code Validator}. This method can only be used to get one of + * the standard JAXB defined properties above or a provider specific + * property. Attempting to get an undefined property will result in + * a PropertyException being thrown. See + * Supported Properties. + * + * @param name the name of the property to retrieve + * @return the value of the requested property + * + * @throws PropertyException + * when there is an error retrieving the given property or value + * property name + * @throws IllegalArgumentException + * If the name parameter is null + * @deprecated since JAXB2.0 + */ + public Object getProperty( String name ) throws PropertyException; + +} diff --git a/fine-third-jdk11/src/javax/xml/bind/WhiteSpaceProcessor.java b/fine-third-jdk11/src/javax/xml/bind/WhiteSpaceProcessor.java new file mode 100644 index 000000000..7fc96ced4 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/WhiteSpaceProcessor.java @@ -0,0 +1,213 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2007-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind; + +/** + * Processes white space normalization. + * + * @since 1.0 + */ +abstract class WhiteSpaceProcessor { + +// benchmarking (see test/src/ReplaceTest.java in the CVS Attic) +// showed that this code is slower than the current code. +// +// public static String replace(String text) { +// final int len = text.length(); +// StringBuffer result = new StringBuffer(len); +// +// for (int i = 0; i < len; i++) { +// char ch = text.charAt(i); +// if (isWhiteSpace(ch)) +// result.append(' '); +// else +// result.append(ch); +// } +// +// return result.toString(); +// } + + public static String replace(String text) { + return replace( (CharSequence)text ).toString(); + } + + /** + * @since 2.0 + */ + public static CharSequence replace(CharSequence text) { + int i=text.length()-1; + + // look for the first whitespace char. + while( i>=0 && !isWhiteSpaceExceptSpace(text.charAt(i)) ) + i--; + + if( i<0 ) + // no such whitespace. replace(text)==text. + return text; + + // we now know that we need to modify the text. + // allocate a char array to do it. + StringBuilder buf = new StringBuilder(text); + + buf.setCharAt(i--,' '); + for( ; i>=0; i-- ) + if( isWhiteSpaceExceptSpace(buf.charAt(i))) + buf.setCharAt(i,' '); + + return new String(buf); + } + + /** + * Equivalent of {@link String#trim()}. + * @since 2.0 + */ + public static CharSequence trim(CharSequence text) { + int len = text.length(); + int start = 0; + + while( startstart && isWhiteSpace(text.charAt(end)) ) + end--; + + if(start==0 && end==len-1) + return text; // no change + else + return text.subSequence(start,end+1); + } + + public static String collapse(String text) { + return collapse( (CharSequence)text ).toString(); + } + + /** + * This is usually the biggest processing bottleneck. + * + * @since 2.0 + */ + public static CharSequence collapse(CharSequence text) { + int len = text.length(); + + // most of the texts are already in the collapsed form. + // so look for the first whitespace in the hope that we will + // never see it. + int s=0; + while(s 0 && result.charAt(len - 1) == ' ') + result.setLength(len - 1); + // whitespaces are already collapsed, + // so all we have to do is to remove the last one character + // if it's a whitespace. + + return result; + } + + /** + * Returns true if the specified string is all whitespace. + */ + public static final boolean isWhiteSpace(CharSequence s) { + for( int i=s.length()-1; i>=0; i-- ) + if(!isWhiteSpace(s.charAt(i))) + return false; + return true; + } + + /** returns true if the specified char is a white space character. */ + public static final boolean isWhiteSpace(char ch) { + // most of the characters are non-control characters. + // so check that first to quickly return false for most of the cases. + if( ch>0x20 ) return false; + + // other than we have to do four comparisons. + return ch == 0x9 || ch == 0xA || ch == 0xD || ch == 0x20; + } + + /** + * Returns true if the specified char is a white space character + * but not 0x20. + */ + protected static final boolean isWhiteSpaceExceptSpace(char ch) { + // most of the characters are non-control characters. + // so check that first to quickly return false for most of the cases. + if( ch>=0x20 ) return false; + + // other than we have to do four comparisons. + return ch == 0x9 || ch == 0xA || ch == 0xD; + } +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/DomHandler.java b/fine-third-jdk11/src/javax/xml/bind/annotation/DomHandler.java new file mode 100644 index 000000000..6bb0bfe50 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/DomHandler.java @@ -0,0 +1,134 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import javax.xml.bind.ValidationEventHandler; +import javax.xml.transform.Result; +import javax.xml.transform.Source; + +/** + * Converts an element (and its descendants) + * from/to DOM (or similar) representation. + * + *

+ * Implementations of this interface will be used in conjunction with + * {@link XmlAnyElement} annotation to map an element of XML into a representation + * of infoset such as W3C DOM. + * + *

+ * Implementations hide how a portion of XML is converted into/from such + * DOM-like representation, allowing JAXB providers to work with arbitrary + * such library. + * + *

+ * This interface is intended to be implemented by library writers + * and consumed by JAXB providers. None of those methods are intended to + * be called from applications. + * + * @author Kohsuke Kawaguchi + * @since 1.6, JAXB 2.0 + */ +public interface DomHandler { + /** + * When a JAXB provider needs to unmarshal a part of a document into an + * infoset representation, it first calls this method to create a + * {@link Result} object. + * + *

+ * A JAXB provider will then send a portion of the XML + * into the given result. Such a portion always form a subtree + * of the whole XML document rooted at an element. + * + * @param errorHandler + * if any error happens between the invocation of this method + * and the invocation of {@link #getElement(Result)}, they + * must be reported to this handler. + * + * The caller must provide a non-null error handler. + * + * The {@link Result} object created from this method + * may hold a reference to this error handler. + * + * @return + * null if the operation fails. The error must have been reported + * to the error handler. + */ + ResultT createUnmarshaller( ValidationEventHandler errorHandler ); + + /** + * Once the portion is sent to the {@link Result}. This method is called + * by a JAXB provider to obtain the unmarshalled element representation. + * + *

+ * Multiple invocations of this method may return different objects. + * This method can be invoked only when the whole sub-tree are fed + * to the {@link Result} object. + * + * @param rt + * The {@link Result} object created by {@link #createUnmarshaller(ValidationEventHandler)}. + * + * @return + * null if the operation fails. The error must have been reported + * to the error handler. + */ + ElementT getElement(ResultT rt); + + /** + * This method is called when a JAXB provider needs to marshal an element + * to XML. + * + *

+ * If non-null, the returned {@link Source} must contain a whole document + * rooted at one element, which will then be weaved into a bigger document + * that the JAXB provider is marshalling. + * + * @param errorHandler + * Receives any errors happened during the process of converting + * an element into a {@link Source}. + * + * The caller must provide a non-null error handler. + * + * @return + * null if there was an error. The error should have been reported + * to the handler. + */ + Source marshal( ElementT n, ValidationEventHandler errorHandler ); +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/W3CDomHandler.java b/fine-third-jdk11/src/javax/xml/bind/annotation/W3CDomHandler.java new file mode 100644 index 000000000..b3a0b8ccf --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/W3CDomHandler.java @@ -0,0 +1,124 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import org.w3c.dom.Document; +import org.w3c.dom.DocumentFragment; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import javax.xml.bind.ValidationEventHandler; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.transform.Source; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.dom.DOMSource; + +/** + * {@link DomHandler} implementation for W3C DOM (org.w3c.dom package.) + * + * @author Kohsuke Kawaguchi + * @since 1.6, JAXB 2.0 + */ +public class W3CDomHandler implements DomHandler { + + private DocumentBuilder builder; + + /** + * Default constructor. + * + * It is up to a JAXB provider to decide which DOM implementation + * to use or how that is configured. + */ + public W3CDomHandler() { + this.builder = null; + } + + /** + * Constructor that allows applications to specify which DOM implementation + * to be used. + * + * @param builder + * must not be null. JAXB uses this {@link DocumentBuilder} to create + * a new element. + */ + public W3CDomHandler(DocumentBuilder builder) { + if(builder==null) + throw new IllegalArgumentException(); + this.builder = builder; + } + + public DocumentBuilder getBuilder() { + return builder; + } + + public void setBuilder(DocumentBuilder builder) { + this.builder = builder; + } + + public DOMResult createUnmarshaller(ValidationEventHandler errorHandler) { + if(builder==null) + return new DOMResult(); + else + return new DOMResult(builder.newDocument()); + } + + public Element getElement(DOMResult r) { + // JAXP spec is ambiguous about what really happens in this case, + // so work defensively + Node n = r.getNode(); + if( n instanceof Document ) { + return ((Document)n).getDocumentElement(); + } + if( n instanceof Element ) + return (Element)n; + if( n instanceof DocumentFragment ) + return (Element)n.getChildNodes().item(0); + + // if the result object contains something strange, + // it is not a user problem, but it is a JAXB provider's problem. + // That's why we throw a runtime exception. + throw new IllegalStateException(n.toString()); + } + + public Source marshal(Element element, ValidationEventHandler errorHandler) { + return new DOMSource(element); + } +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAccessOrder.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAccessOrder.java new file mode 100644 index 000000000..7c91f4fec --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAccessOrder.java @@ -0,0 +1,64 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +/** + * Used by XmlAccessorOrder to control the ordering of properties and + * fields in a JAXB bound class. + * + * @author Sekhar Vajjhala, Sun Microsystems, Inc. + * @since 1.6, JAXB 2.0 + * @see XmlAccessorOrder + */ + +public enum XmlAccessOrder { + /** + * The ordering of fields and properties in a class is undefined. + */ + UNDEFINED, + /** + * The ordering of fields and properties in a class is in + * alphabetical order as determined by the + * method java.lang.String.compareTo(String anotherString). + */ + ALPHABETICAL +} + diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAccessType.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAccessType.java new file mode 100644 index 000000000..ba3cfd414 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAccessType.java @@ -0,0 +1,86 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + + + +/** + * Used by XmlAccessorType to control serialization of fields or + * properties. + * + * @author Sekhar Vajjhala, Sun Microsystems, Inc. + * @since 1.6, JAXB 2.0 + * @see XmlAccessorType + */ + +public enum XmlAccessType { + /** + * Every getter/setter pair in a JAXB-bound class will be automatically + * bound to XML, unless annotated by {@link XmlTransient}. + * + * Fields are bound to XML only when they are explicitly annotated + * by some of the JAXB annotations. + */ + PROPERTY, + /** + * Every non static, non transient field in a JAXB-bound class will be automatically + * bound to XML, unless annotated by {@link XmlTransient}. + * + * Getter/setter pairs are bound to XML only when they are explicitly annotated + * by some of the JAXB annotations. + */ + FIELD, + /** + * Every public getter/setter pair and every public field will be + * automatically bound to XML, unless annotated by {@link XmlTransient}. + * + * Fields or getter/setter pairs that are private, protected, or + * defaulted to package-only access are bound to XML only when they are + * explicitly annotated by the appropriate JAXB annotations. + */ + PUBLIC_MEMBER, + /** + * None of the fields or properties is bound to XML unless they + * are specifically annotated with some of the JAXB annotations. + */ + NONE +} + diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAccessorOrder.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAccessorOrder.java new file mode 100644 index 000000000..c3d599635 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAccessorOrder.java @@ -0,0 +1,95 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.lang.annotation.Target; +import java.lang.annotation.Retention; +import java.lang.annotation.Inherited; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +/** + *

Controls the ordering of fields and properties in a class.

+ * + *

Usage

+ * + *

{@code @XmlAccessorOrder} annotation can be used with the following + * program elements:

+ * + *
    + *
  • package
  • + *
  • a top level class
  • + *
+ * + *

See "Package Specification" in {@code javax.xml.bind} package javadoc for + * additional common information.

+ * + *

The effective {@link XmlAccessOrder} on a class is determined + * as follows: + * + *

    + *
  • If there is a {@code @XmlAccessorOrder} on a class, then + * it is used.
  • + *
  • Otherwise, if a {@code @XmlAccessorOrder} exists on one of + * its super classes, then it is inherited (by the virtue of + * {@link Inherited}) + *
  • Otherwise, the {@code @XmlAccessorOrder} on the package + * of the class is used, if it's there. + *
  • Otherwise {@link XmlAccessOrder#UNDEFINED}. + *
+ * + *

This annotation can be used with the following annotations: + * {@link XmlType}, {@link XmlRootElement}, {@link XmlAccessorType}, + * {@link XmlSchema}, {@link XmlSchemaType}, {@link XmlSchemaTypes}, + * , {@link XmlJavaTypeAdapter}. It can also be used with the + * following annotations at the package level: {@link XmlJavaTypeAdapter}. + * + * @author Sekhar Vajjhala, Sun Microsystems, Inc. + * @since 1.6, JAXB 2.0 + * @see XmlAccessOrder + */ + +@Inherited @Retention(RUNTIME) @Target({PACKAGE, TYPE}) +public @interface XmlAccessorOrder { + XmlAccessOrder value() default XmlAccessOrder.UNDEFINED; +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAccessorType.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAccessorType.java new file mode 100644 index 000000000..fc5f106fa --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAccessorType.java @@ -0,0 +1,115 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.lang.annotation.Target; +import java.lang.annotation.Retention; +import java.lang.annotation.Inherited; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +/** + *

Controls whether fields or Javabean properties are serialized by default.

+ * + *

Usage

+ * + *

{@code @XmlAccessorType} annotation can be used with the following program elements:

+ * + *
    + *
  • package
  • + *
  • a top level class
  • + *
+ * + *

See "Package Specification" in javax.xml.bind.package javadoc for + * additional common information.

+ * + *

This annotation provides control over the default serialization + * of properties and fields in a class. + * + *

The annotation {@code @XmlAccessorType} on a package applies to + * all classes in the package. The following inheritance + * semantics apply: + * + *

    + *
  • If there is a {@code @XmlAccessorType} on a class, then it + * is used.
  • + *
  • Otherwise, if a {@code @XmlAccessorType} exists on one of + * its super classes, then it is inherited. + *
  • Otherwise, the {@code @XmlAccessorType} on a package is + * inherited. + *
+ *

Defaulting Rules:

+ * + *

By default, if {@code @XmlAccessorType} on a package is absent, + * then the following package level annotation is assumed.

+ *
+ *   @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
+ * 
+ *

By default, if {@code @XmlAccessorType} on a class is absent, + * and none of its super classes is annotated with + * {@code @XmlAccessorType}, then the following default on the class + * is assumed:

+ *
+ *   @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
+ * 
+ *

This annotation can be used with the following annotations: + * {@link XmlType}, {@link XmlRootElement}, {@link XmlAccessorOrder}, + * {@link XmlSchema}, {@link XmlSchemaType}, {@link XmlSchemaTypes}, + * , {@link XmlJavaTypeAdapter}. It can also be used with the + * following annotations at the package level: {@link XmlJavaTypeAdapter}. + * + * @author Sekhar Vajjhala, Sun Microsystems, Inc. + * @since 1.6, JAXB 2.0 + * @see XmlAccessType + */ + +@Inherited @Retention(RUNTIME) @Target({PACKAGE, TYPE}) +public @interface XmlAccessorType { + + /** + * Specifies whether fields or properties are serialized. + * + * @see XmlAccessType + */ + XmlAccessType value() default XmlAccessType.PUBLIC_MEMBER; +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAnyAttribute.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAnyAttribute.java new file mode 100644 index 000000000..dda60dd2a --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAnyAttribute.java @@ -0,0 +1,89 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import javax.xml.namespace.QName; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import java.util.Map; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; + +/** + *

+ * Maps a JavaBean property to a map of wildcard attributes. + * + *

Usage

+ *

+ * The {@code @XmlAnyAttribute} annotation can be used with the + * following program elements: + *

    + *
  • JavaBean property
  • + *
  • non static, non transient field
  • + *
+ * + *

See "Package Specification" in javax.xml.bind.package javadoc for + * additional common information.

+ * + * The usage is subject to the following constraints: + *
    + *
  • At most one field or property in a class can be annotated + * with {@code @XmlAnyAttribute}.
  • + *
  • The type of the property or the field must {@code java.util.Map}
  • + *
+ * + *

+ * While processing attributes to be unmarshalled into a value class, + * each attribute that is not statically associated with another + * JavaBean property, via {@link XmlAttribute}, is entered into the + * wildcard attribute map represented by + * {@link Map}<{@link QName},{@link Object}>. The attribute QName is the + * map's key. The key's value is the String value of the attribute. + * + * @author Kohsuke Kawaguchi, Sun Microsystems, Inc. + * @since 1.6, JAXB 2.0 + */ +@Retention(RUNTIME) +@Target({FIELD,METHOD}) +public @interface XmlAnyAttribute { +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAnyElement.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAnyElement.java new file mode 100644 index 000000000..fe8f13f68 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAnyElement.java @@ -0,0 +1,302 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import org.w3c.dom.Element; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import java.util.List; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * Maps a JavaBean property to XML infoset representation and/or JAXB element. + * + *

+ * This annotation serves as a "catch-all" property while unmarshalling + * xml content into a instance of a JAXB annotated class. It typically + * annotates a multi-valued JavaBean property, but it can occur on + * single value JavaBean property. During unmarshalling, each xml element + * that does not match a static @XmlElement or @XmlElementRef + * annotation for the other JavaBean properties on the class, is added to this + * "catch-all" property. + * + *

Usages:

+ *
+ * @XmlAnyElement
+ * public {@link Element}[] others;
+ * 
+ * // Collection of {@link Element} or JAXB elements.
+ * @XmlAnyElement(lax="true")
+ * public {@link Object}[] others;
+ *
+ * @XmlAnyElement
+ * private List<{@link Element}> nodes;
+ *
+ * @XmlAnyElement
+ * private {@link Element} node;
+ * 
+ * + *

Restriction usage constraints

+ *

+ * This annotation is mutually exclusive with + * {@link XmlElement}, {@link XmlAttribute}, {@link XmlValue}, + * {@link XmlElements}, {@link XmlID}, and {@link XmlIDREF}. + * + *

+ * There can be only one {@link XmlAnyElement} annotated JavaBean property + * in a class and its super classes. + * + *

Relationship to other annotations

+ *

+ * This annotation can be used with {@link XmlJavaTypeAdapter}, so that users + * can map their own data structure to DOM, which in turn can be composed + * into XML. + * + *

+ * This annotation can be used with {@link XmlMixed} like this: + *

+ * // List of java.lang.String or DOM nodes.
+ * @XmlAnyElement @XmlMixed
+ * List<Object> others;
+ * 
+ * + * + *

Schema To Java example

+ * + * The following schema would produce the following Java class: + *
{@code
+ * 
+ *   
+ *     
+ *     
+ *     
+ *   
+ * 
+ * }
+ * + *
+ * class Foo {
+ *   int a;
+ *   int b;
+ *   @{@link XmlAnyElement}
+ *   List<Element> any;
+ * }
+ * 
+ * + * It can unmarshal instances like + * + *
{@code
+ * 
+ *   1
+ *     // this will be bound to DOM, because unmarshalling is orderless
+ *   3
+ *   
+ *   5     // this will be bound to DOM, because the annotation doesn't remember namespaces.
+ * 
+ * }
+ * + * + * + * The following schema would produce the following Java class: + *
{@code
+ * 
+ *   
+ *   
+ *     
+ *       
+ *       
+ *     
+ *   
+ * 
+ * }
+ * + *
+ * class Bar extends Foo {
+ *   int c;
+ *   // Foo.getAny() also represents wildcard content for type definition bar.
+ * }
+ * 
+ * + * + * It can unmarshal instances like + * + *
{@code
+ * 
+ *   1
+ *     // this will be bound to DOM, because unmarshalling is orderless
+ *   3
+ *   
+ *   5     // this now goes to Bar.c
+ *     // this will go to Foo.any
+ * 
+ * }
+ * + * + * + * + *

Using {@link XmlAnyElement} with {@link XmlElementRef}

+ *

+ * The {@link XmlAnyElement} annotation can be used with {@link XmlElementRef}s to + * designate additional elements that can participate in the content tree. + * + *

+ * The following schema would produce the following Java class: + *

{@code
+ * 
+ *   
+ *     
+ *     
+ *     
+ *   
+ * 
+ * }
+ * + *
+ * class Foo {
+ *   @{@link XmlAnyElement}(lax="true")
+ *   @{@link XmlElementRefs}({
+ *     @{@link XmlElementRef}(name="a", type="JAXBElement.class")
+ *     @{@link XmlElementRef}(name="b", type="JAXBElement.class")
+ *   })
+ *   {@link List}<{@link Object}> others;
+ * }
+ *
+ * @XmlRegistry
+ * class ObjectFactory {
+ *   ...
+ *   @XmlElementDecl(name = "a", namespace = "", scope = Foo.class)
+ *   {@link JAXBElement}<Integer> createFooA( Integer i ) { ... }
+ *
+ *   @XmlElementDecl(name = "b", namespace = "", scope = Foo.class)
+ *   {@link JAXBElement}<Integer> createFooB( Integer i ) { ... }
+ * 
+ * + * It can unmarshal instances like + * + *
+ *{@code }
+ *{@code   1}     // this will unmarshal to a {@link JAXBElement} instance whose value is 1.
+ *{@code   }  // this will unmarshal to a DOM {@link Element}.
+ *{@code   3}     // this will unmarshal to a {@link JAXBElement} instance whose value is 1.
+ *{@code }
+ * 
+ * + * + * + * + *

W3C XML Schema "lax" wildcard emulation

+ * The lax element of the annotation enables the emulation of the "lax" wildcard semantics. + * For example, when the Java source code is annotated like this: + *
+ * @{@link XmlRootElement}
+ * class Foo {
+ *   @XmlAnyElement(lax=true)
+ *   public {@link Object}[] others;
+ * }
+ * 
+ * then the following document will unmarshal like this: + *
{@code
+ * 
+ *   
+ *   
+ * 
+ *
+ * Foo foo = unmarshal();
+ * // 1 for 'unknown', another for 'foo'
+ * assert foo.others.length==2;
+ * // 'unknown' unmarshals to a DOM element
+ * assert foo.others[0] instanceof Element;
+ * // because of lax=true, the 'foo' element eagerly
+ * // unmarshals to a Foo object.
+ * assert foo.others[1] instanceof Foo;
+ * }
+ * + * @author Kohsuke Kawaguchi + * @since 1.6, JAXB 2.0 + */ +@Retention(RUNTIME) +@Target({FIELD,METHOD}) +public @interface XmlAnyElement { + + /** + * Controls the unmarshaller behavior when it sees elements + * known to the current {@link JAXBContext}. + * + *

When false

+ *

+ * If false, all the elements that match the property will be unmarshalled + * to DOM, and the property will only contain DOM elements. + * + *

When true

+ *

+ * If true, when an element matches a property marked with {@link XmlAnyElement} + * is known to {@link JAXBContext} (for example, there's a class with + * {@link XmlRootElement} that has the same tag name, or there's + * {@link XmlElementDecl} that has the same tag name), + * the unmarshaller will eagerly unmarshal this element to the JAXB object, + * instead of unmarshalling it to DOM. Additionally, if the element is + * unknown but it has a known xsi:type, the unmarshaller eagerly unmarshals + * the element to a {@link JAXBElement}, with the unknown element name and + * the JAXBElement value is set to an instance of the JAXB mapping of the + * known xsi:type. + * + *

+ * As a result, after the unmarshalling, the property can become heterogeneous; + * it can have both DOM nodes and some JAXB objects at the same time. + * + *

+ * This can be used to emulate the "lax" wildcard semantics of the W3C XML Schema. + */ + boolean lax() default false; + + /** + * Specifies the {@link DomHandler} which is responsible for actually + * converting XML from/to a DOM-like data structure. + */ + Class value() default W3CDomHandler.class; +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAttachmentRef.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAttachmentRef.java new file mode 100644 index 000000000..803a616af --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAttachmentRef.java @@ -0,0 +1,89 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import javax.activation.DataHandler; +import static java.lang.annotation.ElementType.*; +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import java.lang.annotation.Target; + +/** + * Marks a field/property that its XML form is a uri reference to mime content. + * The mime content is optimally stored out-of-line as an attachment. + * + * A field/property must always map to the {@link DataHandler} class. + * + *

Usage

+ *
+ * @{@link XmlRootElement}
+ * class Foo {
+ *   @{@link XmlAttachmentRef}
+ *   @{@link XmlAttribute}
+ *   {@link DataHandler} data;
+ *
+ *   @{@link XmlAttachmentRef}
+ *   @{@link XmlElement}
+ *   {@link DataHandler} body;
+ * }
+ * 
+ * The above code maps to the following XML: + *
{@code
+ * 
+ *   
+ *     
+ *       
+ *     
+ *     
+ *   
+ * 
+ * }
+ * + *

+ * The above binding supports WS-I AP 1.0 WS-I Attachments Profile Version 1.0. + * + * @author Kohsuke Kawaguchi + * @since 1.6, JAXB 2.0 + */ +@Retention(RUNTIME) +@Target({FIELD,METHOD,PARAMETER}) +public @interface XmlAttachmentRef { +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAttribute.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAttribute.java new file mode 100644 index 000000000..6aca38563 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlAttribute.java @@ -0,0 +1,168 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +/** + *

+ * Maps a JavaBean property to a XML attribute. + * + *

Usage

+ *

+ * The {@code @XmlAttribute} annotation can be used with the + * following program elements: + *

    + *
  • JavaBean property
  • + *
  • field
  • + *
+ * + *

A static final field is mapped to a XML fixed attribute. + * + *

See "Package Specification" in javax.xml.bind.package javadoc for + * additional common information.

+ * + * The usage is subject to the following constraints: + *
    + *
  • If type of the field or the property is a collection + * type, then the collection item type must be mapped to schema + * simple type. + *
    + *     // Examples
    + *     @XmlAttribute List<Integer> items; //legal
    + *     @XmlAttribute List<Bar> foo; // illegal if Bar does not map to a schema simple type
    + * 
    + *
  • + *
  • If the type of the field or the property is a non + * collection type, then the type of the property or field + * must map to a simple schema type. + *
    + *     // Examples
    + *     @XmlAttribute int foo; // legal
    + *     @XmlAttribute Foo foo; // illegal if Foo does not map to a schema simple type
    + * 
    + *
  • + *
  • This annotation can be used with the following annotations: + * {@link XmlID}, + * {@link XmlIDREF}, + * {@link XmlList}, + * {@link XmlSchemaType}, + * {@link XmlValue}, + * {@link XmlAttachmentRef}, + * {@link XmlMimeType}, + * {@link XmlInlineBinaryData}, + * {@link javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter}.
  • + *
+ * + *

Example 1: Map a JavaBean property to an XML attribute.

+ *
+ *     //Example: Code fragment
+ *     public class USPrice { 
+ *         @XmlAttribute
+ *         public java.math.BigDecimal getPrice() {...} ;
+ *         public void setPrice(java.math.BigDecimal ) {...};
+ *     }
+ * {@code
+ * 
+ *     
+ *     
+ *       
+ *       
+ *       
+ *     
+ * }
+ * + *

Example 2: Map a JavaBean property to an XML attribute with anonymous type.

+ * See Example 7 in @{@link XmlType}. + * + *

Example 3: Map a JavaBean collection property to an XML attribute.

+ *
+ *     // Example: Code fragment
+ *     class Foo {
+ *         ...
+ *         @XmlAttribute List<Integer> items;
+ *     } 
+ * {@code
+ * 
+ *     
+ *     
+ *     	 ...
+ *       
+ *         
+ *           
+ *         
+ *     
+ *
+ * }
+ * @author Sekhar Vajjhala, Sun Microsystems, Inc. + * @see XmlType + * @since 1.6, JAXB 2.0 + */ + +@Retention(RUNTIME) @Target({FIELD, METHOD}) +public @interface XmlAttribute { + /** + * Name of the XML Schema attribute. By default, the XML Schema + * attribute name is derived from the JavaBean property name. + * + */ + String name() default "##default"; + + /** + * Specifies if the XML Schema attribute is optional or + * required. If true, then the JavaBean property is mapped to a + * XML Schema attribute that is required. Otherwise it is mapped + * to a XML Schema attribute that is optional. + * + */ + boolean required() default false; + + /** + * Specifies the XML target namespace of the XML Schema + * attribute. + * + */ + String namespace() default "##default" ; +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlElement.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlElement.java new file mode 100644 index 000000000..100fe97b2 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlElement.java @@ -0,0 +1,222 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.*; + +/** + * Maps a JavaBean property to a XML element derived from property name. + * + *

Usage + *

+ * {@code @XmlElement} annotation can be used with the following program + * elements: + *

    + *
  • a JavaBean property
  • + *
  • non static, non transient field
  • + *
  • within {@link XmlElements} + *
+ * + * The usage is subject to the following constraints: + *
    + *
  • This annotation can be used with following annotations: + * {@link XmlID}, + * {@link XmlIDREF}, + * {@link XmlList}, + * {@link XmlSchemaType}, + * {@link XmlValue}, + * {@link XmlAttachmentRef}, + * {@link XmlMimeType}, + * {@link XmlInlineBinaryData}, + * {@link XmlElementWrapper}, + * {@link XmlJavaTypeAdapter}
  • + *
  • if the type of JavaBean property is a collection type of + * array, an indexed property, or a parameterized list, and + * this annotation is used with {@link XmlElements} then, + * {@code @XmlElement.type()} must be DEFAULT.class since the + * collection item type is already known.
  • + *
+ * + *

+ * A JavaBean property, when annotated with @XmlElement annotation + * is mapped to a local element in the XML Schema complex type to + * which the containing class is mapped. + * + *

+ * Example 1: Map a public non static non final field to local + * element + *

+ *     //Example: Code fragment
+ *     public class USPrice {
+ *        {@literal @}XmlElement(name="itemprice")
+ *         public java.math.BigDecimal price;
+ *     }
+ * {@code
+ *
+ *     
+ *     
+ *       
+ *         
+ *       
+ *     
+ *   }
+ *

+ * + * Example 2: Map a field to a nillable element. + *

+ *     //Example: Code fragment
+ *     public class USPrice {
+ *        {@literal @}XmlElement(nillable=true)
+ *         public java.math.BigDecimal price;
+ *     }
+ * {@code
+ *
+ *     
+ *     
+ *       
+ *         
+ *       
+ *     
+ *   }
+ *

+ * Example 3: Map a field to a nillable, required element. + *

+ *     //Example: Code fragment
+ *     public class USPrice {
+ *        {@literal @}XmlElement(nillable=true, required=true)
+ *         public java.math.BigDecimal price;
+ *     }
+ * {@code
+ *
+ *     
+ *     
+ *       
+ *         
+ *       
+ *     
+ *   }
+ * + *

Example 4: Map a JavaBean property to an XML element + * with anonymous type.

+ *

+ * See Example 6 in @{@link XmlType}. + * + * @author Sekhar Vajjhala, Sun Microsystems, Inc. + * @since 1.6, JAXB 2.0 + */ + +@Retention(RUNTIME) @Target({FIELD, METHOD, PARAMETER}) +public @interface XmlElement { + /** + * Name of the XML Schema element. + *

If the value is "##default", then element name is derived from the + * JavaBean property name. + */ + String name() default "##default"; + + /** + * Customize the element declaration to be nillable. + *

If nillable() is true, then the JavaBean property is + * mapped to a XML Schema nillable element declaration. + */ + boolean nillable() default false; + + /** + * Customize the element declaration to be required. + *

If required() is true, then Javabean property is mapped to + * an XML schema element declaration with minOccurs="1". + * maxOccurs is "1" for a single valued property and "unbounded" + * for a multivalued property. + *

If required() is false, then the Javabean property is mapped + * to XML Schema element declaration with minOccurs="0". + * maxOccurs is "1" for a single valued property and "unbounded" + * for a multivalued property. + */ + + boolean required() default false; + + /** + * XML target namespace of the XML Schema element. + *

+ * If the value is "##default", then the namespace is determined + * as follows: + *

    + *
  1. + * If the enclosing package has {@link XmlSchema} annotation, + * and its {@link XmlSchema#elementFormDefault() elementFormDefault} + * is {@link XmlNsForm#QUALIFIED QUALIFIED}, then the namespace of + * the enclosing class. + * + *
  2. + * Otherwise {@literal ''} (which produces unqualified element in the default + * namespace. + *
+ */ + String namespace() default "##default"; + + /** + * Default value of this element. + * + *

+ * The

'\u0000'
value specified as a default of this annotation element + * is used as a poor-man's substitute for null to allow implementations + * to recognize the 'no default value' state. + */ + String defaultValue() default "\u0000"; + + /** + * The Java class being referenced. + */ + Class type() default DEFAULT.class; + + /** + * Used in {@link XmlElement#type()} to + * signal that the type be inferred from the signature + * of the property. + */ + static final class DEFAULT {} +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlElementDecl.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlElementDecl.java new file mode 100644 index 000000000..acc8895a1 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlElementDecl.java @@ -0,0 +1,232 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.ElementType.METHOD; + +/** + * Maps a factory method to a XML element. + * + *

Usage

+ * + * The annotation creates a mapping between an XML schema element + * declaration and a element factory method that returns a + * JAXBElement instance representing the element + * declaration. Typically, the element factory method is generated + * (and annotated) from a schema into the ObjectFactory class in a + * Java package that represents the binding of the element + * declaration's target namespace. Thus, while the annotation syntax + * allows @XmlElementDecl to be used on any method, semantically + * its use is restricted to annotation of element factory method. + * + * The usage is subject to the following constraints: + * + *
    + *
  • The class containing the element factory method annotated + * with @XmlElementDecl must be marked with {@link + * XmlRegistry}.
  • + *
  • The element factory method must take one parameter + * assignable to {@link Object}.
  • + *
+ * + *

Example 1: Annotation on a factory method + *

+ *     // Example: code fragment
+ *     @XmlRegistry
+ *     class ObjectFactory {
+ *         @XmlElementDecl(name="foo")
+ *         JAXBElement<String> createFoo(String s) { ... }
+ *     }
+ * 
+ *
 {@code
+ * 
+ *     
+ *     string
+ *
+ *     // Example: code fragment corresponding to XML input
+ *     JAXBElement o =
+ *     (JAXBElement)unmarshaller.unmarshal(aboveDocument);
+ *     // print JAXBElement instance to show values
+ *     System.out.println(o.getName());   // prints  "{}foo"
+ *     System.out.println(o.getValue());  // prints  "string"
+ *     System.out.println(o.getValue().getClass()); // prints "java.lang.String"
+ *
+ *     
+ *     
+ * }
+ * + *

Example 2: Element declaration with non local scope + *

+ * The following example illustrates the use of scope annotation + * parameter in binding of element declaration in schema derived + * code. + *

+ * The following example may be replaced in a future revision of + * this javadoc. + * + *

{@code
+ *     
+ *     
+ *       
+ *         
+ *           
+ *           
+ *         
+ *       
+ *       
+ *     
+ * }
+ *
+ *     // Example: expected default binding
+ *     class Pea {
+ *         @XmlElementRefs({
+ *             @XmlElementRef(name="foo",type=JAXBElement.class)
+ *             @XmlElementRef(name="bar",type=JAXBElement.class)
+ *         })
+ *         List<JAXBElement<String>> fooOrBar;
+ *     }
+ * 
+ *     @XmlRegistry
+ *     class ObjectFactory {
+ *         @XmlElementDecl(scope=Pea.class,name="foo")
+ *         JAXBElement<String> createPeaFoo(String s);
+ * 
+ *         @XmlElementDecl(scope=Pea.class,name="bar")
+ *         JAXBElement<String> createPeaBar(String s);
+ * 
+ *         @XmlElementDecl(name="foo")
+ *         JAXBElement<Integer> createFoo(Integer i);
+ *     }
+ * 
+ * 
+ * Without scope createFoo and createPeaFoo would become ambiguous + * since both of them map to a XML schema element with the same local + * name "foo". + * + * @see XmlRegistry + * @since 1.6, JAXB 2.0 + */ +@Retention(RUNTIME) +@Target({METHOD}) +public @interface XmlElementDecl { + /** + * scope of the mapping. + * + *

+ * If this is not {@link XmlElementDecl.GLOBAL}, then this element + * declaration mapping is only active within the specified class. + */ + Class scope() default GLOBAL.class; + + /** + * namespace name of the XML element. + *

+ * If the value is "##default", then the value is the namespace + * name for the package of the class containing this factory method. + * + * @see #name() + */ + String namespace() default "##default"; + + /** + * local name of the XML element. + * + *

+ * Note to reviewers: There is no default name; since + * the annotation is on a factory method, it is not clear that the + * method name can be derived from the factory method name. + * @see #namespace() + */ + String name(); + + /** + * namespace name of a substitution group's head XML element. + *

+ * This specifies the namespace name of the XML element whose local + * name is specified by {@code substitutionHeadName()}. + *

+ * If {@code susbtitutionHeadName()} is "", then this + * value can only be "##default". But the value is ignored since + * since this element is not part of susbtitution group when the + * value of {@code susbstitutionHeadName()} is "". + *

+ * If {@code susbtitutionHeadName()} is not "" and the value is + * "##default", then the namespace name is the namespace name to + * which the package of the containing class, marked with {@link + * XmlRegistry }, is mapped. + *

+ * If {@code susbtitutionHeadName()} is not "" and the value is + * not "##default", then the value is the namespace name. + * + * @see #substitutionHeadName() + */ + String substitutionHeadNamespace() default "##default"; + + /** + * XML local name of a substitution group's head element. + *

+ * If the value is "", then this element is not part of any + * substitution group. + * + * @see #substitutionHeadNamespace() + */ + String substitutionHeadName() default ""; + + /** + * Default value of this element. + * + *

+ * The

'\u0000'
value specified as a default of this annotation element + * is used as a poor-man's substitute for null to allow implementations + * to recognize the 'no default value' state. + */ + String defaultValue() default "\u0000"; + + /** + * Used in {@link XmlElementDecl#scope()} to + * signal that the declaration is in the global scope. + */ + public final class GLOBAL {} +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlElementRef.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlElementRef.java new file mode 100644 index 000000000..52355e505 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlElementRef.java @@ -0,0 +1,306 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; + +/** + *

+ * Maps a JavaBean property to a XML element derived from property's type. + *

+ * Usage + *

+ * {@code @XmlElementRef} annotation can be used with a + * JavaBean property or from within {@link XmlElementRefs} + *

+ * This annotation dynamically associates an XML element name with the JavaBean + * property. When a JavaBean property is annotated with {@link + * XmlElement}, the XML element name is statically derived from the + * JavaBean property name. However, when this annotation is used, the + * XML element name is derived from the instance of the type of the + * JavaBean property at runtime. + * + *

XML Schema substitution group support

+ * XML Schema allows a XML document author to use XML element names + * that were not statically specified in the content model of a + * schema using substitution groups. Schema derived code provides + * support for substitution groups using an element property, + * (section 5.5.5, "Element Property" of JAXB 2.0 specification). An + * element property method signature is of the form: + *
{@code
+ *     public void setTerm(JAXBElement);
+ *     public JAXBElement getTerm();
+ * }
+ *

+ * An element factory method annotated with {@link XmlElementDecl} is + * used to create a {@code JAXBElement} instance, containing an XML + * element name. The presence of {@code @XmlElementRef} annotation on an + * element property indicates that the element name from {@code JAXBElement} + * instance be used instead of deriving an XML element name from the + * JavaBean property name. + * + *

+ * The usage is subject to the following constraints: + *

    + *
  • If the collection item type (for collection property) or + * property type (for single valued property) is + * {@link javax.xml.bind.JAXBElement}, then + * {@code @XmlElementRef.name()} and {@code @XmlElementRef.namespace()} must + * point an element factory method with an @XmlElementDecl + * annotation in a class annotated with @XmlRegistry (usually + * ObjectFactory class generated by the schema compiler) : + *
      + *
    • @XmlElementDecl.name() must equal @XmlElementRef.name()
    • + *
    • @XmlElementDecl.namespace() must equal @XmlElementRef.namespace().
    • + *
    + *
  • + *
  • If the collection item type (for collection property) or + * property type (for single valued property) is not + * {@link javax.xml.bind.JAXBElement}, then the type referenced by the + * property or field must be annotated with {@link XmlRootElement}.
  • + *
  • This annotation can be used with the following annotations: + * {@link XmlElementWrapper}, {@link XmlJavaTypeAdapter}. + *
+ * + *

See "Package Specification" in javax.xml.bind.package javadoc for + * additional common information.

+ * + *

Example 1: Ant Task Example

+ * The following Java class hierarchy models an Ant build + * script. An Ant task corresponds to a class in the class + * hierarchy. The XML element name of an Ant task is indicated by the + * @XmlRootElement annotation on its corresponding class. + *
+ *     @XmlRootElement(name="target")
+ *     class Target {
+ *         // The presence of @XmlElementRef indicates that the XML
+ *         // element name will be derived from the @XmlRootElement 
+ *         // annotation on the type (for e.g. "jar" for JarTask). 
+ *         @XmlElementRef
+ *         List<Task> tasks;
+ *     }
+ *
+ *     abstract class Task {
+ *     }
+ *
+ *     @XmlRootElement(name="jar")
+ *     class JarTask extends Task {
+ *         ...
+ *     }
+ *
+ *     @XmlRootElement(name="javac")
+ *     class JavacTask extends Task {
+ *         ...
+ *     }
+ * {@code
+ * 
+ *     
+ *     
+ *     
+ *       
+ *         
+ *           
+ *           
+ *         
+ *       
+ *     
+ *
+ * }
+ *

+ * Thus the following code fragment: + *

+ *     Target target = new Target();
+ *     target.tasks.add(new JarTask());
+ *     target.tasks.add(new JavacTask());
+ *     marshal(target);
+ * 
+ * will produce the following XML output: + *
{@code
+ *     
+ *       
+ *         ....
+ *       
+ *       
+ *         ....
+ *       
+ *     
+ * }
+ *

+ * It is not an error to have a class that extends {@code Task} + * that doesn't have {@link XmlRootElement}. But they can't show up in an + * XML instance (because they don't have XML element names). + * + *

Example 2: XML Schema Susbstitution group support + *

The following example shows the annotations for XML Schema + * substitution groups. The annotations and the ObjectFactory are + * derived from the schema. + * + *

+ *     @XmlElement
+ *     class Math {
+ *         //  The value of {@link #type()}is 
+ *         //  JAXBElement.class , which indicates the XML
+ *         //  element name ObjectFactory - in general a class marked
+ *         //  with @XmlRegistry. (See ObjectFactory below)
+ *         //  
+ *         //  The {@link #name()} is "operator", a pointer to a
+ *         // factory method annotated with a
+ *         //  {@link XmlElementDecl} with the name "operator". Since
+ *         //  "operator" is the head of a substitution group that
+ *         //  contains elements "add" and "sub" elements, "operator"
+ *         //  element can be substituted in an instance document by
+ *         //  elements "add" or "sub". At runtime, JAXBElement
+ *         //  instance contains the element name that has been
+ *         //  substituted in the XML document.
+ *         // 
+ *         @XmlElementRef(type=JAXBElement.class,name="operator")
+ *         JAXBElement<? extends Operator> term;
+ *     }
+ *
+ *     @XmlRegistry
+ *     class ObjectFactory {
+ *         @XmlElementDecl(name="operator")
+ *         JAXBElement<Operator> createOperator(Operator o) {...}
+ *         @XmlElementDecl(name="add",substitutionHeadName="operator")
+ *         JAXBElement<Operator> createAdd(Operator o) {...}
+ *         @XmlElementDecl(name="sub",substitutionHeadName="operator")
+ *         JAXBElement<Operator> createSub(Operator o) {...}
+ *     }
+ *
+ *     class Operator {
+ *         ...
+ *     }
+ * 
+ *

+ * Thus, the following code fragment + *

+ *     Math m = new Math();
+ *     m.term = new ObjectFactory().createAdd(new Operator());
+ *     marshal(m);
+ * 
+ * will produce the following XML output: + *
{@code
+ *     
+ *       ...
+ *     
+ * }
+ * + * + * @author
  • Kohsuke Kawaguchi, Sun Microsystems,Inc.
  • Sekhar Vajjhala, Sun Microsystems, Inc.
+ * @see XmlElementRefs + * @since 1.6, JAXB 2.0 + */ +@Retention(RUNTIME) +@Target({FIELD,METHOD}) +public @interface XmlElementRef { + /** + * The Java type being referenced. + *

+ * If the value is DEFAULT.class, the type is inferred from the + * the type of the JavaBean property. + */ + Class type() default DEFAULT.class; + + /** + * This parameter and {@link #name()} are used to determine the + * XML element for the JavaBean property. + * + *

If {@code type()} is {@code JAXBElement.class} , then + * {@code namespace()} and {@code name()} + * point to a factory method with {@link XmlElementDecl}. The XML + * element name is the element name from the factory method's + * {@link XmlElementDecl} annotation or if an element from its + * substitution group (of which it is a head element) has been + * substituted in the XML document, then the element name is from the + * {@link XmlElementDecl} on the substituted element. + * + *

If {@link #type()} is not {@code JAXBElement.class}, then + * the XML element name is the XML element name statically + * associated with the type using the annotation {@link + * XmlRootElement} on the type. If the type is not annotated with + * an {@link XmlElementDecl}, then it is an error. + * + *

If {@code type()} is not {@code JAXBElement.class}, then + * this value must be "". + * + */ + String namespace() default ""; + /** + * + * @see #namespace() + */ + String name() default "##default"; + + /** + * Used in {@link XmlElementRef#type()} to + * signal that the type be inferred from the signature + * of the property. + */ + static final class DEFAULT {} + + /** + * Customize the element declaration to be required. + *

+ * If required() is true, then Javabean property is mapped to + * an XML schema element declaration with minOccurs="1". + * maxOccurs is "1" for a single valued property and "unbounded" + * for a multivalued property. + * + *

+ * If required() is false, then the Javabean property is mapped + * to XML Schema element declaration with minOccurs="0". + * maxOccurs is "1" for a single valued property and "unbounded" + * for a multivalued property. + * + *

+ * For compatibility with JAXB 2.1, this property defaults to {@code true}, + * despite the fact that {@link XmlElement#required()} defaults to false. + * + * @since 1.7, JAXB 2.2 + */ + boolean required() default true; +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlElementRefs.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlElementRefs.java new file mode 100644 index 000000000..9edfb4a17 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlElementRefs.java @@ -0,0 +1,74 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * Marks a property that refers to classes with {@link XmlElement} + * or JAXBElement. + * + *

+ * Compared to an element property (property with {@link XmlElement} + * annotation), a reference property has a different substitution semantics. + * When a sub-class is assigned to a property, an element property produces + * the same tag name with @xsi:type, whereas a reference property produces + * a different tag name (the tag name that's on the the sub-class.) + * + *

This annotation can be used with the following annotations: + * {@link XmlJavaTypeAdapter}, {@link XmlElementWrapper}. + * + * @author

  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • Sekhar Vajjhala, Sun Microsystems, Inc.
+ * + * @see XmlElementWrapper + * @see XmlElementRef + * @since 1.6, JAXB 2.0 + */ +@Retention(RUNTIME) +@Target({FIELD,METHOD}) +public @interface XmlElementRefs { + XmlElementRef[] value(); +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlElementWrapper.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlElementWrapper.java new file mode 100644 index 000000000..bd887b9e2 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlElementWrapper.java @@ -0,0 +1,160 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Generates a wrapper element around XML representation. + * + * This is primarily intended to be used to produce a wrapper + * XML element around collections. The annotation therefore supports + * two forms of serialization shown below. + * + *
{@code
+ *    //Example: code fragment
+ *      int[] names;
+ *
+ *    // XML Serialization Form 1 (Unwrapped collection)
+ *     ... 
+ *     ... 
+ * 
+ *    // XML Serialization Form 2 ( Wrapped collection )
+ *    
+ *        value-of-item 
+ *        value-of-item 
+ *       ....
+ *    
+ * }
+ * + *

The two serialized XML forms allow a null collection to be + * represented either by absence or presence of an element with a + * nillable attribute. + * + *

Usage

+ *

+ * The {@code @XmlElementWrapper} annotation can be used with the + * following program elements: + *

    + *
  • JavaBean property
  • + *
  • non static, non transient field
  • + *
+ * + *

The usage is subject to the following constraints: + *

    + *
  • The property must be a collection property
  • + *
  • This annotation can be used with the following annotations: + * {@link XmlElement}, + * {@link XmlElements}, + * {@link XmlElementRef}, + * {@link XmlElementRefs}, + * {@link XmlJavaTypeAdapter}.
  • + *
+ * + *

See "Package Specification" in javax.xml.bind.package javadoc for + * additional common information.

+ * + * @author
  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • Sekhar Vajjhala, Sun Microsystems, Inc.
+ * @see XmlElement + * @see XmlElements + * @see XmlElementRef + * @see XmlElementRefs + * @since 1.6, JAXB 2.0 + * + */ + +@Retention(RUNTIME) @Target({FIELD, METHOD}) +public @interface XmlElementWrapper { + /** + * Name of the XML wrapper element. By default, the XML wrapper + * element name is derived from the JavaBean property name. + */ + String name() default "##default"; + + /** + * XML target namespace of the XML wrapper element. + *

+ * If the value is "##default", then the namespace is determined + * as follows: + *

    + *
  1. + * If the enclosing package has {@link XmlSchema} annotation, + * and its {@link XmlSchema#elementFormDefault() elementFormDefault} + * is {@link XmlNsForm#QUALIFIED QUALIFIED}, then the namespace of + * the enclosing class. + * + *
  2. + * Otherwise "" (which produces unqualified element in the default + * namespace. + *
+ */ + String namespace() default "##default"; + + /** + * If true, the absence of the collection is represented by + * using {@code xsi:nil='true'}. Otherwise, it is represented by + * the absence of the element. + */ + boolean nillable() default false; + + /** + * Customize the wrapper element declaration to be required. + * + *

+ * If required() is true, then the corresponding generated + * XML schema element declaration will have {@code minOccurs="1"}, + * to indicate that the wrapper element is always expected. + * + *

+ * Note that this only affects the schema generation, and + * not the unmarshalling or marshalling capability. This is + * simply a mechanism to let users express their application constraints + * better. + * + * @since 1.6, JAXB 2.1 + */ + boolean required() default false; +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlElements.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlElements.java new file mode 100644 index 000000000..ae1099d24 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlElements.java @@ -0,0 +1,195 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + *

+ * A container for multiple @{@link XmlElement} annotations. + * + * Multiple annotations of the same type are not allowed on a program + * element. This annotation therefore serves as a container annotation + * for multiple @XmlElements as follows: + * + *

+ * @XmlElements({ @XmlElement(...),@XmlElement(...) })
+ * 
+ * + *

The {@code @XmlElements} annotation can be used with the + * following program elements:

+ *
    + *
  • a JavaBean property
  • + *
  • non static, non transient field
  • + *
+ * + * This annotation is intended for annotation a JavaBean collection + * property (e.g. List). + * + *

Usage

+ * + *

The usage is subject to the following constraints: + *

    + *
  • This annotation can be used with the following + * annotations: @{@link XmlIDREF}, @{@link XmlElementWrapper}.
  • + *
  • If @XmlIDREF is also specified on the JavaBean property, + * then each @XmlElement.type() must contain a JavaBean + * property annotated with {@code @XmlID}.
  • + *
+ * + *

See "Package Specification" in javax.xml.bind.package javadoc for + * additional common information.

+ * + *
+ * + *

Example 1: Map to a list of elements

+ *
+ *    
+ *    // Mapped code fragment
+ *    public class Foo {
+ *        @XmlElements(
+ *            @XmlElement(name="A", type=Integer.class),
+ *            @XmlElement(name="B", type=Float.class)
+ *         )
+ *         public List items;
+ *    }
+ * {@code
+ * 
+ *    
+ *    ...
+ *     1 
+ *     2.5 
+ *    ...
+ *
+ *    
+ *    
+ *      
+ *        
+ *          
+ *          
+ *        
+ *      
+ *    
+ *
+ * }
+ * + *

Example 2: Map to a list of elements wrapped with another element + *

+ *
+ * 
+ *    // Mapped code fragment
+ *    public class Foo {
+ *        @XmlElementWrapper(name="bar")
+ *        @XmlElements(
+ *            @XmlElement(name="A", type=Integer.class),
+ *            @XmlElement(name="B", type=Float.class)
+ *        }
+ *        public List items;
+ *    }
+ * {@code
+ * 
+ *    
+ *    
+ *      
+ *        
+ *          
+ *            
+ *              
+ *              
+ *            
+ *          
+ *        
+ *      
+ *    
+ * }
+ * + *

Example 3: Change element name based on type using an adapter. + *

+ *
+ *    class Foo {
+ *       @XmlJavaTypeAdapter(QtoPAdapter.class)
+ *       @XmlElements({
+ *           @XmlElement(name="A",type=PX.class),
+ *           @XmlElement(name="B",type=PY.class)
+ *       })
+ *       Q bar;
+ *    }
+ * 
+ *    @XmlType abstract class P {...}
+ *    @XmlType(name="PX") class PX extends P {...}
+ *    @XmlType(name="PY") class PY extends P {...}
+ * {@code
+ * 
+ *    
+ *    
+ *      
+ *        
+ *          
+ *            
+ *              
+ *              
+ *            
+ *          
+ *        
+ *      
+ *    
+ * }
+ * + * @author
  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • Sekhar Vajjhala, Sun Microsystems, Inc.
+ * @see XmlElement + * @see XmlElementRef + * @see XmlElementRefs + * @see XmlJavaTypeAdapter + * @since 1.6, JAXB 2.0 + */ +@Retention(RUNTIME) @Target({FIELD,METHOD}) +public @interface XmlElements { + /** + * Collection of @{@link XmlElement} annotations + */ + XmlElement[] value(); +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlEnum.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlEnum.java new file mode 100644 index 000000000..199c878e1 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlEnum.java @@ -0,0 +1,90 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import static java.lang.annotation.ElementType.TYPE; +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import java.lang.annotation.Target; + +/** + *

+ * Maps an enum type {@link Enum} to XML representation. + * + *

This annotation, together with {@link XmlEnumValue} provides a + * mapping of enum type to XML representation. + * + *

Usage

+ *

+ * The {@code @XmlEnum} annotation can be used with the + * following program elements: + *

    + *
  • enum type
  • + *
+ * + *

The usage is subject to the following constraints: + *

    + *
  • This annotation can be used the following other annotations: + * {@link XmlType}, + * {@link XmlRootElement}
  • + *
+ *

See "Package Specification" in javax.xml.bind.package javadoc for + * additional common information

+ * + *

An enum type is mapped to a schema simple type with enumeration + * facets. The schema type is derived from the Java type to which + * {@code @XmlEnum.value()}. Each enum constant {@code @XmlEnumValue} + * must have a valid lexical representation for the type + * {@code @XmlEnum.value()}. + * + *

Examples: See examples in {@link XmlEnumValue} + * + * @since 1.6, JAXB 2.0 + */ + +@Retention(RUNTIME) @Target({TYPE}) +public @interface XmlEnum { + /** + * Java type that is mapped to a XML simple type. + * + */ + Class value() default String.class; +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlEnumValue.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlEnumValue.java new file mode 100644 index 000000000..99f879936 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlEnumValue.java @@ -0,0 +1,141 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.ElementType.FIELD; + +/** + * Maps an enum constant in {@link Enum} type to XML representation. + * + *

Usage

+ * + *

The {@code @XmlEnumValue} annotation can be used with the + * following program elements: + *

    + *
  • enum constant
  • + *
+ * + *

See "Package Specification" in javax.xml.bind.package javadoc for + * additional common information.

+ * + *

This annotation, together with {@link XmlEnum} provides a + * mapping of enum type to XML representation. + * + *

An enum type is mapped to a schema simple type with enumeration + * facets. The schema type is derived from the Java type specified in + * {@code @XmlEnum.value()}. Each enum constant {@code @XmlEnumValue} + * must have a valid lexical representation for the type + * {@code @XmlEnum.value()} + * + *

In the absence of this annotation, {@link Enum#name()} is used + * as the XML representation. + * + *

Example 1: Map enum constant name {@literal ->} enumeration facet

+ *
+ *     //Example: Code fragment
+ *     @XmlEnum(String.class)
+ *     public enum Card { CLUBS, DIAMONDS, HEARTS, SPADES }
+ * {@code
+ * 
+ *     
+ *     
+ *       
+ *         
+ *         
+ *         
+ *         
+ *     
+ * }
+ * + *

Example 2: Map enum constant name(value) {@literal ->} enumeration facet

+ *
+ *     //Example: code fragment
+ *     @XmlType
+ *     @XmlEnum(Integer.class)
+ *     public enum Coin { 
+ *         @XmlEnumValue("1") PENNY(1),
+ *         @XmlEnumValue("5") NICKEL(5),
+ *         @XmlEnumValue("10") DIME(10),
+ *         @XmlEnumValue("25") QUARTER(25) }
+ * {@code
+ * 
+ *     
+ *     
+ *       
+ *         
+ *         
+ *         
+ *         
+ *       
+ *     
+ * }
+ * + *

Example 3: Map enum constant name {@literal ->} enumeration facet

+ * + *
+ *     //Code fragment
+ *     @XmlType
+ *     @XmlEnum(Integer.class)
+ *     public enum Code {
+ *         @XmlEnumValue("1") ONE,
+ *         @XmlEnumValue("2") TWO;
+ *     }
+ * {@code
+ * 
+ *     
+ *     
+ *       
+ *         
+ *         
+ *       
+ *     
+ * }
+ * + * @since 1.6, JAXB 2.0 + */ +@Retention(RUNTIME) +@Target({FIELD}) +public @interface XmlEnumValue { + String value(); +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlID.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlID.java new file mode 100644 index 000000000..f8e6fa7ad --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlID.java @@ -0,0 +1,113 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import java.lang.annotation.Target; +import java.lang.annotation.Retention; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +/** + *

+ * Maps a JavaBean property to XML ID. + * + *

+ * To preserve referential integrity of an object graph across XML + * serialization followed by a XML deserialization, requires an object + * reference to be marshalled by reference or containment + * appropriately. Annotations {@code @XmlID} and {@code @XmlIDREF} + * together allow a customized mapping of a JavaBean property's + * type by containment or reference. + * + *

Usage

+ * The {@code @XmlID} annotation can be used with the following + * program elements: + *
    + *
  • a JavaBean property
  • + *
  • non static, non transient field
  • + *
+ * + *

See "Package Specification" in javax.xml.bind.package javadoc for + * additional common information.

+ * + * The usage is subject to the following constraints: + *
    + *
  • At most one field or property in a class can be annotated + * with {@code @XmlID}.
  • + *
  • The JavaBean property's type must be {@code java.lang.String}.
  • + *
  • The only other mapping annotations that can be used + * with {@code @XmlID} + * are: {@code @XmlElement} and {@code @XmlAttribute}.
  • + *
+ * + *

Example: Map a JavaBean property's type to {@code xs:ID}

+ *
+ *    // Example: code fragment
+ *    public class Customer {
+ *        @XmlAttribute
+ *        @XmlID
+ *        public String getCustomerID();
+ *        public void setCustomerID(String id);
+ *        .... other properties not shown 
+ *    }
+ * {@code
+ * 
+ *    
+ *    
+ *      
+ *        
+ *          ....
+ *        
+ *        
+ *      
+ *    
+ * }
+ * + * @author Sekhar Vajjhala, Sun Microsystems, Inc. + * @see XmlIDREF + * @since 1.6, JAXB 2.0 + */ + +@Retention(RUNTIME) @Target({FIELD, METHOD}) +public @interface XmlID { } + + + diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlIDREF.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlIDREF.java new file mode 100644 index 000000000..972b96209 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlIDREF.java @@ -0,0 +1,269 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import java.lang.annotation.Target; +import java.lang.annotation.Retention; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +/** + *

+ * Maps a JavaBean property to XML IDREF. + * + *

+ * To preserve referential integrity of an object graph across XML + * serialization followed by a XML deserialization, requires an object + * reference to be marshaled by reference or containment + * appropriately. Annotations {@code @XmlID} and {@code @XmlIDREF} + * together allow a customized mapping of a JavaBean property's + * type by containment or reference. + * + *

Usage

+ * The {@code @XmlIDREF} annotation can be used with the following + * program elements: + *
    + *
  • a JavaBean property
  • + *
  • non static, non transient field
  • + *
+ * + *

See "Package Specification" in javax.xml.bind.package javadoc for + * additional common information.

+ * + *

The usage is subject to the following constraints: + *

    + * + *
  • If the type of the field or property is a collection type, + * then the collection item type must contain a property or + * field annotated with {@code @XmlID}.
  • + *
  • If the field or property is single valued, then the type of + * the property or field must contain a property or field + * annotated with {@code @XmlID}. + *

    Note: If the collection item type or the type of the + * property (for non collection type) is java.lang.Object, then + * the instance must contain a property/field annotated with + * {@code @XmlID} attribute. + *

  • + *
  • This annotation can be used with the following annotations: + * {@link XmlElement}, {@link XmlAttribute}, {@link XmlList}, + * and {@link XmlElements}.
  • + * + *
+ *

Example: Map a JavaBean property to {@code xs:IDREF} + * (i.e. by reference rather than by containment)

+ *
+ *
+ *   //EXAMPLE: Code fragment
+ *   public class Shipping {
+ *       @XmlIDREF public Customer getCustomer();
+ *       public void setCustomer(Customer customer);
+ *       ....
+ *    }
+ * {@code
+ * 
+ *   
+ *   
+ *     
+ *       
+ *         
+ *         ....
+ *       
+ *     
+ *   
+ *
+ * }
+ * + * + *

Example 2: The following is a complete example of + * containment versus reference. + * + *

+ *    // By default, Customer maps to complex type {@code xs:Customer}
+ *    public class Customer {
+ *        
+ *        // map JavaBean property type to {@code xs:ID}
+ *        @XmlID public String getCustomerID();
+ *        public void setCustomerID(String id);
+ *
+ *        // .... other properties not shown 
+ *    }
+ *
+ *
+ *   // By default, Invoice maps to a complex type {@code xs:Invoice}
+ *   public class Invoice {
+ *    
+ *       // map by reference
+ *       @XmlIDREF public Customer getCustomer();       
+ *       public void setCustomer(Customer customer);
+ *
+ *      // .... other properties not shown here
+ *   }
+ *
+ *   // By default, Shipping maps to complex type {@code xs:Shipping}
+ *   public class Shipping {
+ *
+ *       // map by reference
+ *       @XmlIDREF public Customer getCustomer();       
+ *       public void setCustomer(Customer customer);
+ *   }
+ *
+ *   // at least one class must reference Customer by containment;
+ *   // Customer instances won't be marshalled.
+ *   @XmlElement(name="CustomerData")
+ *   public class CustomerData {
+ *       // map reference to Customer by containment by default.
+ *       public Customer getCustomer();
+ *
+ *       // maps reference to Shipping by containment by default. 
+ *       public Shipping getShipping();     
+ *
+ *       // maps reference to Invoice by containment by default. 
+ *       public Invoice getInvoice();     
+ *   }
+ * {@code
+ * 
+ *   
+ *
+ *   
+ *     
+ *       
+ *         
+ *         ....
+ *       
+ *     
+ *   
+ *
+ *   
+ *     
+ *       
+ *         
+ *         ....
+ *       
+ *     
+ *   
+ *
+ *   
+ *     
+ *       
+ *         ....
+ *       
+ *       
+ *     
+ *   
+ *
+ *   
+ *     
+ *       
+ *         
+ *         
+ *         
+ *       
+ *     
+ *   
+ *
+ *   
+ *
+ *   
+ *    
+ *       
+ *           ....
+ *       
+ *
+ *       
+ *           ....
+ *       
+ *         
+ *       
+ *           ....
+ *       
+ *   
+ *
+ * }
+ * + *

Example 3: Mapping List to repeating element of type IDREF + *

+ *     // Code fragment
+ *     public class Shipping {
+ *         @XmlIDREF
+ *         @XmlElement(name="Alice")
+ *             public List customers;
+ *     }
+ * {@code
+ * 
+ *     
+ *     
+ *       
+ *         
+ *           
+ *         
+ *       
+ *     
+ * }
+ * + *

Example 4: Mapping a List to a list of elements of type IDREF. + *

+ *     //Code fragment
+ *     public class Shipping {
+ *         @XmlIDREF
+ *         @XmlElements(
+ *             @XmlElement(name="Alice", type="Customer.class")
+ *              @XmlElement(name="John", type="InternationalCustomer.class")
+ *         public List customers;
+ *     }
+ * {@code
+ * 
+ *     
+ *     
+ *       
+ *         
+ *           
+ *           
+ *         
+ *       
+ *     
+ * }
+ * @author Sekhar Vajjhala, Sun Microsystems, Inc. + * @see XmlID + * @since 1.6, JAXB 2.0 + */ + +@Retention(RUNTIME) @Target({FIELD, METHOD}) +public @interface XmlIDREF {} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlInlineBinaryData.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlInlineBinaryData.java new file mode 100644 index 000000000..7e699d16b --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlInlineBinaryData.java @@ -0,0 +1,76 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import javax.xml.transform.Source; +import javax.xml.bind.attachment.AttachmentMarshaller; +import javax.activation.DataHandler; + +/** + * Disable consideration of XOP encoding for datatypes that are bound to + * base64-encoded binary data in XML. + * + *

+ * When XOP encoding is enabled as described in {@link AttachmentMarshaller#isXOPPackage()}, + * this annotation disables datatypes such as {@link java.awt.Image} or {@link Source} + * or {@code byte[]} that are bound to base64-encoded binary from being considered for + * XOP encoding. If a JAXB property is annotated with this annotation or if + * the JAXB property's base type is annotated with this annotation, + * neither + * {@link AttachmentMarshaller#addMtomAttachment(DataHandler, String, String)} + * nor + * {@link AttachmentMarshaller#addMtomAttachment(byte[], int, int, String, String, String)} is + * ever called for the property. The binary data will always be inlined. + * + * @author Joseph Fialli + * @since 1.6, JAXB 2.0 + */ +@Retention(RUNTIME) +@Target({FIELD,METHOD,TYPE}) +public @interface XmlInlineBinaryData { +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlList.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlList.java new file mode 100644 index 000000000..83f1a6418 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlList.java @@ -0,0 +1,126 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; + +/** + * Used to map a property to a list simple type. + * + *

Usage

+ *

+ * The {@code @XmlList} annotation can be used with the + * following program elements: + *

    + *
  • JavaBean property
  • + *
  • field
  • + *
+ * + *

+ * When a collection property is annotated just with @XmlElement, + * each item in the collection will be wrapped by an element. + * For example, + * + *

+ * @XmlRootElement
+ * class Foo {
+ *     @XmlElement
+ *     List<String> data;
+ * }
+ * 
+ * + * would produce XML like this: + * + *
{@code
+ * 
+ *   abc
+ *   def
+ * 
+ * }
+ * + * @XmlList annotation, on the other hand, allows multiple values to be + * represented as whitespace-separated tokens in a single element. For example, + * + *
+ * @XmlRootElement
+ * class Foo {
+ *     @XmlElement
+ *     @XmlList
+ *     List<String> data;
+ * }
+ * 
+ * + * the above code will produce XML like this: + * + *
{@code
+ * 
+ *   abc def
+ * 
+ * }
+ * + *

This annotation can be used with the following annotations: + * {@link XmlElement}, + * {@link XmlAttribute}, + * {@link XmlValue}, + * {@link XmlIDREF}. + *

    + *
  • The use of {@code @XmlList} with {@link XmlValue} while + * allowed, is redundant since {@link XmlList} maps a + * collection type to a simple schema type that derives by + * list just as {@link XmlValue} would.
  • + * + *
  • The use of {@code @XmlList} with {@link XmlAttribute} while + * allowed, is redundant since {@link XmlList} maps a + * collection type to a simple schema type that derives by + * list just as {@link XmlAttribute} would.
  • + *
+ * + * @author
  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • Sekhar Vajjhala, Sun Microsystems, Inc.
+ * @since 1.6, JAXB 2.0 + */ +@Retention(RUNTIME) @Target({FIELD,METHOD,PARAMETER}) +public @interface XmlList { +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlMimeType.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlMimeType.java new file mode 100644 index 000000000..d18a08a64 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlMimeType.java @@ -0,0 +1,75 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; + +import javax.xml.transform.Source; + +/** + * Associates the MIME type that controls the XML representation of the property. + * + *

+ * This annotation is used in conjunction with datatypes such as + * {@link java.awt.Image} or {@link Source} that are bound to base64-encoded binary in XML. + * + *

+ * If a property that has this annotation has a sibling property bound to + * the xmime:contentType attribute, and if in the instance the property has a value, + * the value of the attribute takes precedence and that will control the marshalling. + * + * @author Kohsuke Kawaguchi + * @since 1.6, JAXB 2.0 + */ +@Retention(RUNTIME) +@Target({FIELD,METHOD,PARAMETER}) +public @interface XmlMimeType { + /** + * The textual representation of the MIME type, + * such as "image/jpeg" "image/*", "text/xml; charset=iso-8859-1" and so on. + */ + String value(); +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlMixed.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlMixed.java new file mode 100644 index 000000000..e2a7a1063 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlMixed.java @@ -0,0 +1,148 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; + +import org.w3c.dom.Element; +import javax.xml.bind.JAXBElement; + +/** + *

+ * Annotate a JavaBean multi-valued property to support mixed content. + * + *

+ * The usage is subject to the following constraints: + *

    + *
  • can be used with @XmlElementRef, @XmlElementRefs or @XmlAnyElement
  • + *
+ *

+ * The following can be inserted into @XmlMixed annotated multi-valued property + *

    + *
  • XML text information items are added as values of java.lang.String.
  • + *
  • Children element information items are added as instances of + * {@link JAXBElement} or instances with a class that is annotated with + * @XmlRootElement.
  • + *
  • Unknown content that is not be bound to a JAXB mapped class is inserted + * as {@link Element}. (Assumes property annotated with @XmlAnyElement)
  • + *
+ * + * Below is an example of binding and creation of mixed content. + *
{@code
+ * 
+ *  
+ *  
+ *    
+ *	
+ *	
+ *	
+ *	
+ *    
+ *  
+ *  
+ * 
+ * // Schema-derived Java code: 
+ * // (Only annotations relevant to mixed content are shown below, 
+ * //  others are omitted.)
+ * import java.math.BigInteger;
+ * public class ObjectFactory {
+ * 	// element instance factories
+ * 	JAXBElement createLetterBody(LetterBody value);
+ * 	JAXBElement     createLetterBodyName(String value);
+ * 	JAXBElement createLetterBodyQuantity(BigInteger value);
+ * 	JAXBElement     createLetterBodyProductName(String value);
+ *      // type instance factory
+ * 	LetterBody createLetterBody();
+ * }
+ * }
+ *
+ * public class LetterBody {
+ * 	// Mixed content can contain instances of Element classes
+ * 	// Name, Quantity and ProductName. Text data is represented as
+ *	// java.util.String for text.
+ *	@XmlMixed 
+ * 	@XmlElementRefs({
+ *		@XmlElementRef(name="productName", type=JAXBElement.class),
+ *		@XmlElementRef(name="quantity", type=JAXBElement.class),
+ *		@XmlElementRef(name="name", type=JAXBElement.class)})
+ *	List getContent(){...}
+ * }
+ * 
+ * The following is an XML instance document with mixed content + *
{@code
+ * 
+ * Dear Mr.Robert Smith
+ * Your order of 1 Baby
+ * Monitor shipped from our warehouse. ....
+ * 
+ * }
+ * that can be constructed using following JAXB API calls. + *
{@code
+ * LetterBody lb = ObjectFactory.createLetterBody();
+ * JAXBElement lbe = ObjectFactory.createLetterBody(lb);
+ * List gcl = lb.getContent();  //add mixed content to general content property.
+ * gcl.add("Dear Mr.");  // add text information item as a String.
+ * 
+ * // add child element information item
+ * gcl.add(ObjectFactory.createLetterBodyName("Robert Smith"));
+ * gcl.add("Your order of "); // add text information item as a String
+ * 
+ * // add children element information items
+ * gcl.add(ObjectFactory.
+ * 	 		createLetterBodyQuantity(new BigInteger("1")));
+ * gcl.add(ObjectFactory.createLetterBodyProductName("Baby Monitor"));
+ * gcl.add("shipped from our warehouse");  // add text information item
+ * }
+ * + *

See "Package Specification" in javax.xml.bind.package javadoc for + * additional common information.

+ * @author Kohsuke Kawaguchi + * @since 1.6, JAXB 2.0 + */ +@Retention(RUNTIME) +@Target({FIELD,METHOD}) +public @interface XmlMixed { +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlNs.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlNs.java new file mode 100644 index 000000000..cef84556b --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlNs.java @@ -0,0 +1,76 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import java.lang.annotation.Target; + +/** + *

+ * Associates a namespace prefix with a XML namespace URI. + * + *

Usage

+ *

{@code @XmlNs} annotation is intended for use from other + * program annotations. + * + *

See "Package Specification" in javax.xml.bind.package javadoc for + * additional common information.

+ * + *

Example:See {@code XmlSchema} annotation type for an example. + * @author Sekhar Vajjhala, Sun Microsystems, Inc. + * @since 1.6, JAXB 2.0 + */ + +@Retention(RUNTIME) @Target({}) +public @interface XmlNs { + /** + * Namespace prefix + */ + String prefix(); + + /** + * Namespace URI + */ + String namespaceURI(); +} + + diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlNsForm.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlNsForm.java new file mode 100644 index 000000000..53e4e63fc --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlNsForm.java @@ -0,0 +1,86 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +/** + * Enumeration of XML Schema namespace qualifications. + * + *

See "Package Specification" in javax.xml.bind.package javadoc for + * additional common information.

+ * + *

Usage + *

+ * The namespace qualification values are used in the annotations + * defined in this packge. The enumeration values are mapped as follows: + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Mapping of enumeration values
Enum ValueXML Schema Value
UNQUALIFIEDunqualified
QUALIFIEDqualified
UNSETnamespace qualification attribute is absent from the + * XML Schema fragment
+ * + * @author Sekhar Vajjhala, Sun Microsystems, Inc. + * @since 1.6, JAXB 2.0 + */ +public enum XmlNsForm {UNQUALIFIED, QUALIFIED, UNSET} + + + diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlRegistry.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlRegistry.java new file mode 100644 index 000000000..1be7fb7e7 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlRegistry.java @@ -0,0 +1,58 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * Marks a class that has {@link XmlElementDecl}s. + * + * @author

  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • Sekhar Vajjhala, Sun Microsystems, Inc.
+ * @since 1.6, JAXB 2.0 + * @see XmlElementDecl + */ +@Retention(RUNTIME) +@Target({TYPE}) +public @interface XmlRegistry { +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlRootElement.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlRootElement.java new file mode 100644 index 000000000..00d04ccca --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlRootElement.java @@ -0,0 +1,201 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.ElementType.TYPE; + +/** + * Maps a class or an enum type to an XML element. + * + *

Usage

+ *

+ * The @XmlRootElement annotation can be used with the following program + * elements: + *

    + *
  • a top level class
  • + *
  • an enum type
  • + *
+ * + *

See "Package Specification" in javax.xml.bind.package javadoc for + * additional common information.

+ * + *

+ * When a top level class or an enum type is annotated with the + * @XmlRootElement annotation, then its value is represented + * as XML element in an XML document. + * + *

This annotation can be used with the following annotations: + * {@link XmlType}, {@link XmlEnum}, {@link XmlAccessorType}, + * {@link XmlAccessorOrder}. + *

+ + *

+ * Example 1: Associate an element with XML Schema type + *

+ *     // Example: Code fragment
+ *     @XmlRootElement
+ *     class Point {
+ *        int x;
+ *        int y;
+ *        Point(int _x,int _y) {x=_x;y=_y;}
+ *     }
+ * 
+ * + *
+ *     //Example: Code fragment corresponding to XML output
+ *     marshal( new Point(3,5), System.out);
+ * 
+ * + *
{@code
+ * 
+ *     
+ *     
+ *        3 
+ *        5 
+ *     
+ * }
+ * + * The annotation causes an global element declaration to be produced + * in the schema. The global element declaration is associated with + * the XML schema type to which the class is mapped. + * + *
{@code
+ * 
+ *     
+ *     
+ *     
+ *       
+ *         
+ *         
+ *       
+ *     
+ * }
+ * + *

+ * + * Example 2: Orthogonality to type inheritance + * + *

+ * An element declaration annotated on a type is not inherited by its + * derived types. The following example shows this. + *

+ *     // Example: Code fragment
+ *     @XmlRootElement
+ *     class Point3D extends Point {
+ *         int z;
+ *         Point3D(int _x,int _y,int _z) {super(_x,_y);z=_z;}
+ *     }
+ *
+ *     //Example: Code fragment corresponding to XML output * 
+ *     marshal( new Point3D(3,5,0), System.out );
+ * {@code
+ * 
+ *     
+ *     
+ *     
+ *       3
+ *       5
+ *       0
+ *     
+ *
+ *     
+ *     
+ *     
+ *       
+ *         
+ *           
+ *             
+ *           
+ *         
+ *       
+ *     
+ * }
+ * + * Example 3: Associate a global element with XML Schema type + * to which the class is mapped. + *
+ *     //Example: Code fragment
+ *     @XmlRootElement(name="PriceElement")
+ *     public class USPrice {
+ *         @XmlElement
+ *         public java.math.BigDecimal price;
+ *     }
+ * {@code
+ * 
+ *     
+ *     
+ *     
+ *       
+ *         
+ *       
+ *     
+ * }
+ * + * @author Sekhar Vajjhala, Sun Microsystems, Inc. + * @since 1.6, JAXB 2.0 + */ +@Retention(RUNTIME) +@Target({TYPE}) +public @interface XmlRootElement { + /** + * namespace name of the XML element. + *

+ * If the value is "##default", then the XML namespace name is derived + * from the package of the class ( {@link XmlSchema} ). If the + * package is unnamed, then the XML namespace is the default empty + * namespace. + */ + String namespace() default "##default"; + + /** + * local name of the XML element. + *

+ * If the value is "##default", then the name is derived from the + * class name. + * + */ + String name() default "##default"; + +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlSchema.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlSchema.java new file mode 100644 index 000000000..a8d45d864 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlSchema.java @@ -0,0 +1,223 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +/** + *

Maps a package name to a XML namespace.

+ * + *

Usage

+ *

+ * The XmlSchema annotation can be used with the following program + * elements: + *

    + *
  • package
  • + *
+ * + *

+ * This is a package level annotation and follows the recommendations + * and restrictions contained in JSR 175, section III, "Annotations". + * Thus the usage is subject to the following constraints and + * recommendations. + *

    + *
  • There can only be one package declaration as noted in JSR + * 175, section III, "Annotations".
  • + *
  • JSR 175 recommends package-info.java for package level + * annotations. JAXB Providers that follow this recommendation + * will allow the package level annotations to be defined in + * package-info.java. + *
+ * + *

Example 1: Customize name of XML namespace to which + * package is mapped.

+ * + *
+ *    @javax.xml.bind.annotation.XmlSchema (
+ *      namespace = "http://www.example.com/MYPO1"
+ *    )
+ * {@code   
+ * 
+ *    
+ *    
+ *    
+ * }
+ * + *

Example 2: Customize namespace prefix, namespace URI + * mapping

+ * + *
+ *    // Package level annotation
+ *    @javax.xml.bind.annotation.XmlSchema (
+ *      xmlns = { 
+ *        @javax.xml.bind.annotation.XmlNs(prefix = "po", 
+ *                   namespaceURI="http://www.example.com/myPO1"),
+ *
+ *        @javax.xml.bind.annotation.XmlNs(prefix="xs",
+ *                   namespaceURI="http://www.w3.org/2001/XMLSchema")
+ *      }
+ *    )
+ * {@code
+ * 
+ *    
+ *    
+ * 
+ * }
+ * + *

Example 3: Customize elementFormDefault

+ *
+ *    @javax.xml.bind.annotation.XmlSchema (
+ *      elementFormDefault=XmlNsForm.UNQUALIFIED
+ *      ...
+ *    )
+ * {@code
+ * 
+ *    
+ *    
+ * 
+ * }
+ + * @author Sekhar Vajjhala, Sun Microsystems, Inc. + * @since 1.6, JAXB 2.0 + */ + +@Retention(RUNTIME) @Target(PACKAGE) +public @interface XmlSchema { + + /** + * Customize the namespace URI, prefix associations. By default, + * the namespace prefixes for a XML namespace are generated by a + * JAXB Provider in an implementation dependent way. + */ + XmlNs[] xmlns() default {}; + + /** + * Name of the XML namespace. + */ + String namespace() default ""; + + /** + * Namespace qualification for elements. By default, element + * default attribute will be absent from the XML Schema fragment. + */ + XmlNsForm elementFormDefault() default XmlNsForm.UNSET; + + /** + * Namespace qualification for attributes. By default, + * attributesFormDefault will be absent from the XML Schema fragment. + */ + XmlNsForm attributeFormDefault() default XmlNsForm.UNSET; + + /** + * Indicates that this namespace (specified by {@link #namespace()}) + * has a schema already available exeternally, available at this location. + * + *

+ * This instructs the JAXB schema generators to simply refer to + * the pointed schema, as opposed to generating components into the schema. + * This schema is assumed to match what would be otherwise produced + * by the schema generator (same element names, same type names...) + * + *

+ * This feature is intended to be used when a set of the Java classes + * is originally generated from an existing schema, hand-written to + * match externally defined schema, or the generated schema is modified + * manually. + * + *

+ * Value could be any absolute URI, like {@code http://example.org/some.xsd}. + * It is also possible to specify the empty string, to indicate + * that the schema is externally available but the location is + * unspecified (and thus it's the responsibility of the reader of the generate + * schema to locate it.) Finally, the default value of this property + * {@code "##generate"} indicates that the schema generator is going + * to generate components for this namespace (as it did in JAXB 2.0.) + * + *

+ * Multiple {@link XmlSchema} annotations on multiple packages are allowed + * to govern the same {@link #namespace()}. In such case, all of them + * must have the same {@link #location()} values. + * + * + *

Note to implementor

+ *

+ * More precisely, the value must be either {@code ""}, {@code "##generate"}, or + * + * a valid lexical representation of {@code xs:anyURI} that begins + * with {@code :}. + * + *

+ * A schema generator is expected to generate a corresponding + * {@code } (or + * no {@code schemaLocation} attribute at all if the empty string is specified.) + * However, the schema generator is allowed to use a different value in + * the {@code schemaLocation} attribute (including not generating + * such attribute), for example so that the user can specify a local + * copy of the resource through the command line interface. + * + * @since 1.6, JAXB 2.1 + */ + String location() default NO_LOCATION; + + /** + * The default value of the {@link #location()} attribute, + * which indicates that the schema generator will generate + * components in this namespace. + */ + // the actual value is chosen because ## is not a valid + // sequence in xs:anyURI. + static final String NO_LOCATION = "##generate"; +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlSchemaType.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlSchemaType.java new file mode 100644 index 000000000..5e29041bd --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlSchemaType.java @@ -0,0 +1,127 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PACKAGE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * Maps a Java type to a simple schema built-in type. + * + *

Usage

+ *

+ * {@code @XmlSchemaType} annotation can be used with the following program + * elements: + *

    + *
  • a JavaBean property
  • + *
  • field
  • + *
  • package
  • + *
+ * + *

{@code @XmlSchemaType} annotation defined for Java type + * applies to all references to the Java type from a property/field. + * A {@code @XmlSchemaType} annotation specified on the + * property/field overrides the {@code @XmlSchemaType} annotation + * specified at the package level. + * + *

This annotation can be used with the following annotations: + * {@link XmlElement}, {@link XmlAttribute}. + *

+ * Example 1: Customize mapping of XMLGregorianCalendar on the + * field. + * + *

+ *     //Example: Code fragment
+ *     public class USPrice {
+ *         @XmlElement
+ *         @XmlSchemaType(name="date")
+ *         public XMLGregorianCalendar date;
+ *     }
+ * {@code
+ * 
+ *     
+ *     
+ *       
+ *         
+ *       
+ *     
+ * }
+ * + *

Example 2: Customize mapping of XMLGregorianCalendar at package + * level

+ *
+ *     package foo;
+ *     @javax.xml.bind.annotation.XmlSchemaType(
+ *          name="date", type=javax.xml.datatype.XMLGregorianCalendar.class)
+ *     }
+ * 
+ * + * @since 1.6, JAXB 2.0 + */ + +@Retention(RUNTIME) @Target({FIELD,METHOD,PACKAGE}) +public @interface XmlSchemaType { + String name(); + String namespace() default "http://www.w3.org/2001/XMLSchema"; + /** + * If this annotation is used at the package level, then value of + * the type() must be specified. + */ + + Class type() default DEFAULT.class; + + /** + * Used in {@link XmlSchemaType#type()} to + * signal that the type be inferred from the signature + * of the property. + */ + + static final class DEFAULT {} + +} + + + diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlSchemaTypes.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlSchemaTypes.java new file mode 100644 index 000000000..ada5b5c65 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlSchemaTypes.java @@ -0,0 +1,76 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.ElementType.PACKAGE; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + *

+ * A container for multiple @{@link XmlSchemaType} annotations. + * + *

Multiple annotations of the same type are not allowed on a program + * element. This annotation therefore serves as a container annotation + * for multiple @XmlSchemaType annotations as follows: + * + *

+ * @XmlSchemaTypes({ @XmlSchemaType(...), @XmlSchemaType(...) })
+ * 
+ *

The {@code @XmlSchemaTypes} annnotation can be used to + * define {@link XmlSchemaType} for different types at the + * package level. + * + *

See "Package Specification" in javax.xml.bind.package javadoc for + * additional common information.

+ * + * @author
  • Sekhar Vajjhala, Sun Microsystems, Inc.
+ * @see XmlSchemaType + * @since 1.6, JAXB 2.0 + */ +@Retention(RUNTIME) @Target({PACKAGE}) +public @interface XmlSchemaTypes { + /** + * Collection of @{@link XmlSchemaType} annotations + */ + XmlSchemaType[] value(); +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlSeeAlso.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlSeeAlso.java new file mode 100644 index 000000000..a743baa13 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlSeeAlso.java @@ -0,0 +1,94 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2006-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import javax.xml.bind.JAXBContext; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import java.lang.annotation.Target; + +/** + * Instructs JAXB to also bind other classes when binding this class. + * + *

+ * Java makes it impractical/impossible to list all sub-classes of + * a given class. This often gets in a way of JAXB users, as it JAXB + * cannot automatically list up the classes that need to be known + * to {@link JAXBContext}. + * + *

+ * For example, with the following class definitions: + * + *

+ * class Animal {}
+ * class Dog extends Animal {}
+ * class Cat extends Animal {}
+ * 
+ * + *

+ * The user would be required to create {@link JAXBContext} as + * {@code JAXBContext.newInstance(Dog.class,Cat.class)} + * ({@code Animal} will be automatically picked up since {@code Dog} + * and {@code Cat} refers to it.) + * + *

+ * {@link XmlSeeAlso} annotation would allow you to write: + *

+ * @XmlSeeAlso({Dog.class,Cat.class})
+ * class Animal {}
+ * class Dog extends Animal {}
+ * class Cat extends Animal {}
+ * 
+ * + *

+ * This would allow you to do {@code JAXBContext.newInstance(Animal.class)}. + * By the help of this annotation, JAXB implementations will be able to + * correctly bind {@code Dog} and {@code Cat}. + * + * @author Kohsuke Kawaguchi + * @since 1.6, JAXB 2.1 + */ +@Target({ElementType.TYPE}) +@Retention(RUNTIME) +public @interface XmlSeeAlso { + Class[] value(); +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlTransient.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlTransient.java new file mode 100644 index 000000000..614131b8a --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlTransient.java @@ -0,0 +1,112 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import java.lang.annotation.Target; +import java.lang.annotation.Retention; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +/** + *

+ * Prevents the mapping of a JavaBean property/type to XML representation. + *

+ * The {@code @XmlTransient} annotation is useful for resolving name + * collisions between a JavaBean property name and a field name or + * preventing the mapping of a field/property. A name collision can + * occur when the decapitalized JavaBean property name and a field + * name are the same. If the JavaBean property refers to the field, + * then the name collision can be resolved by preventing the + * mapping of either the field or the JavaBean property using the + * {@code @XmlTransient} annotation. + * + *

+ * When placed on a class, it indicates that the class shouldn't be mapped + * to XML by itself. Properties on such class will be mapped to XML along + * with its derived classes, as if the class is inlined. + * + *

Usage

+ *

The {@code @XmlTransient} annotation can be used with the following + * program elements: + *

    + *
  • a JavaBean property
  • + *
  • field
  • + *
  • class
  • + *
+ * + *

{@code @XmlTransient} is mutually exclusive with all other + * JAXB defined annotations.

+ * + *

See "Package Specification" in javax.xml.bind.package javadoc for + * additional common information.

+ * + *

Example: Resolve name collision between JavaBean property and + * field name

+ * + *
+ *   // Example: Code fragment
+ *   public class USAddress {
+ *
+ *       // The field name "name" collides with the property name 
+ *       // obtained by bean decapitalization of getName() below
+ *       @XmlTransient public String name;
+ *
+ *       String getName() {..};
+ *       String setName() {..};
+ *   }
+ *
+ * {@code   
+ * 
+ *   
+ *   
+ *     
+ *       
+ *     
+ *   
+ * }
+ * + * @author Sekhar Vajjhala, Sun Microsystems, Inc. + * @since 1.6, JAXB 2.0 + */ + +@Retention(RUNTIME) @Target({FIELD, METHOD, TYPE}) +public @interface XmlTransient {} + diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlType.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlType.java new file mode 100644 index 000000000..3f03355d0 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlType.java @@ -0,0 +1,473 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import static java.lang.annotation.ElementType.TYPE; +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import java.lang.annotation.Target; + +/** + *

+ * Maps a class or an enum type to a XML Schema type. + * + *

Usage

+ *

The {@code @XmlType} annnotation can be used with the following program + * elements: + *

    + *
  • a top level class
  • + *
  • an enum type
  • + *
+ * + *

See "Package Specification" in javax.xml.bind.package javadoc for + * additional common information.

+ * + *

Mapping a Class

+ *

+ * A class maps to a XML Schema type. A class is a data container for + * values represented by properties and fields. A schema type is a + * data container for values represented by schema components within a + * schema type's content model (e.g. model groups, attributes etc). + *

To be mapped, a class must either have a public no-arg + * constructor or a static no-arg factory method. The static factory + * method can be specified in {@code factoryMethod()} and + * {@code factoryClass()} annotation elements. The static factory + * method or the no-arg constructor is used during unmarshalling to + * create an instance of this class. If both are present, the static + * factory method overrides the no-arg constructor. + *

+ * A class maps to either a XML Schema complex type or a XML Schema simple + * type. The XML Schema type is derived based on the + * mapping of JavaBean properties and fields contained within the + * class. The schema type to which the class is mapped can either be + * named or anonymous. A class can be mapped to an anonymous schema + * type by annotating the class with {@code @XmlType(name="")}. + *

+ * Either a global element, local element or a local attribute can be + * associated with an anonymous type as follows: + *

    + *
  • global element: A global element of an anonymous + * type can be derived by annotating the class with @{@link + * XmlRootElement}. See Example 3 below.
  • + * + *
  • local element: A JavaBean property that references + * a class annotated with @XmlType(name="") and is mapped to the + * element associated with the anonymous type. See Example 4 + * below.
  • + * + *
  • attribute: A JavaBean property that references + * a class annotated with @XmlType(name="") and is mapped to the + * attribute associated with the anonymous type. See Example 5 below.
  • + *
+ * Mapping to XML Schema Complex Type + *
    + *
  • If class is annotated with {@code @XmlType(name="") }, it + * is mapped to an anonymous type otherwise, the class name maps + * to a complex type name. The {@code XmlName()} annotation element + * can be used to customize the name.
  • + * + *
  • Properties and fields that are mapped to elements are mapped to a + * content model within a complex type. The annotation element + * {@code propOrder()} can be used to customize the content model to be + * {@code xs:all} or {@code xs:sequence}. It is used for specifying + * the order of XML elements in {@code xs:sequence}.
  • + * + *
  • Properties and fields can be mapped to attributes within the + * complex type.
  • + * + *
  • The targetnamespace of the XML Schema type can be customized + * using the annotation element {@code namespace()}.
  • + *
+ * + *

+ * Mapping class to XML Schema simple type + *

+ * A class can be mapped to a XML Schema simple type using the + * {@code @XmlValue} annotation. For additional details and examples, + * see @{@link XmlValue} annotation type. + *

+ * The following table shows the mapping of the class to a XML Schema + * complex type or simple type. The notational symbols used in the table are: + *

    + *
  • {@literal ->} : represents a mapping
  • + *
  • [x]+ : one or more occurrences of x
  • + *
  • [ {@code @XmlValue} property ]: JavaBean property annotated with + * {@code @XmlValue}
  • + *
  • X : don't care + *
+ *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
TargetpropOrderClassBodyComplexTypeSimpleType
Class{}[property]+ {@literal ->} elementscomplexcontent
xs:all
Classnon empty[property]+ {@literal ->} elementscomplexcontent
xs:sequence
ClassXno property {@literal ->} elementcomplexcontent
empty sequence
ClassX1 [{@code @XmlValue} property] {@literal &&}
[property]+ {@literal ->} attributes
simplecontent
ClassX1 [{@code @XmlValue} property] {@literal &&}
no properties {@literal ->} attribute
simpletype
+ *
+ * + *

Mapping an enum type

+ * + * An enum type maps to a XML schema simple type with enumeration + * facets. The following annotation elements are ignored since they + * are not meaningful: {@code propOrder()} , {@code factoryMethod()} , + * {@code factoryClass()} . + * + *

Usage with other annotations

+ *

This annotation can be used with the following annotations: + * {@link XmlRootElement}, {@link XmlAccessorOrder}, {@link XmlAccessorType}, + * {@link XmlEnum}. However, {@link + * XmlAccessorOrder} and {@link XmlAccessorType} are ignored when this + * annotation is used on an enum type. + * + *

Example 1: Map a class to a complex type with + * xs:sequence with a customized ordering of JavaBean properties. + *

+ * + *
+ *   @XmlType(propOrder={"street", "city" , "state", "zip", "name" })
+ *   public class USAddress {
+ *     String getName() {..};
+ *     void setName(String) {..};
+ * 
+ *     String getStreet() {..};
+ *     void setStreet(String) {..};
+ *
+ *     String getCity() {..}; 
+ *     void setCity(String) {..};
+ * 
+ *     String getState() {..};
+ *     void setState(String) {..};
+ *
+ *     java.math.BigDecimal getZip() {..};
+ *     void setZip(java.math.BigDecimal) {..};
+ *   }
+ * {@code
+ * 
+ *   
+ *   
+ *     
+ *       
+ *       
+ *       
+ *       
+ *       
+ *     
+ *   
+ * }
+ *

Example 2: Map a class to a complex type with + * xs:all

+ *
+ * @XmlType(propOrder={})
+ * public class USAddress { ...}
+ * {@code
+ * 
+ * 
+ * 
+ *   
+ *     
+ *     
+ *     
+ *     
+ *     
+ *   
+ * 
+ *}
+ *

Example 3: Map a class to a global element with an + * anonymous type. + *

+ *
+ *   @XmlRootElement
+ *   @XmlType(name="")
+ *   public class USAddress { ...}
+ * {@code
+ * 
+ *   
+ *   
+ *     
+ *       
+ *         
+ *         
+ *         
+ *         
+ *         
+ *       
+ *     
+ *   
+ * }
+ * + *

Example 4: Map a property to a local element with + * anonymous type. + *

+ *   //Example: Code fragment
+ *   public class Invoice {
+ *       USAddress addr;
+ *           ...
+ *       }
+ *
+ *   @XmlType(name="")
+ *   public class USAddress { ... }
+ *   } 
+ * {@code
+ * 
+ *   
+ *   
+ *     
+ *       
+ *         
+ *           
+ *           
+ *           
+ *           
+ *           
+ *         
+ *       ...
+ *     
+ *   
+ * }
+ * + *

Example 5: Map a property to an attribute with + * anonymous type. + * + *

+ *
+ *     //Example: Code fragment
+ *     public class Item {
+ *         public String name;
+ *         @XmlAttribute 
+ *         public USPrice price;
+ *     }
+ *    
+ *     // map class to anonymous simple type. 
+ *     @XmlType(name="")
+ *     public class USPrice { 
+ *         @XmlValue
+ *         public java.math.BigDecimal price;
+ *     }
+ * {@code
+ * 
+ *     
+ *     
+ *       
+ *         
+ *         
+ *           
+ *             
+ *           
+ *         
+ *       
+ *     
+ * }
+ * + *

Example 6: Define a factoryClass and factoryMethod + * + *

 
+ *      @XmlType(name="USAddressType", factoryClass=USAddressFactory.class,
+ *      factoryMethod="getUSAddress")
+ *      public class USAddress {
+ *
+ *          private String city;
+ *          private String name;
+ *          private String state;
+ *          private String street;
+ *          private int    zip;
+ *
+ *      public USAddress(String name, String street, String city, 
+ *          String state, int zip) {
+ *          this.name = name;
+ *          this.street = street;
+ *          this.city = city;
+ *          this.state = state;
+ *          this.zip = zip;
+ *      }
+ *  }
+ *
+ *  public class USAddressFactory {
+ *      public static USAddress getUSAddress(){
+ *       return new USAddress("Mark Baker", "23 Elm St", 
+ *          "Dayton", "OH", 90952);
+ *  }
+ *
+ * 
+ * + *

Example 7: Define factoryMethod and use the default factoryClass + * + *

+ *      @XmlType(name="USAddressType", factoryMethod="getNewInstance")
+ *      public class USAddress {
+ *
+ *          private String city;
+ *          private String name;
+ *          private String state;
+ *          private String street;
+ *          private int    zip;
+ *
+ *          private USAddress() {}
+ *
+ *          public static USAddress getNewInstance(){
+ *              return new USAddress();
+ *          }
+ *      }
+ * 
+ * + * @author Sekhar Vajjhala, Sun Microsystems, Inc. + * @see XmlElement + * @see XmlAttribute + * @see XmlValue + * @see XmlSchema + * @since 1.6, JAXB 2.0 + */ + +@Retention(RUNTIME) @Target({TYPE}) +public @interface XmlType { + /** + * Name of the XML Schema type which the class is mapped. + */ + String name() default "##default" ; + + /** + * Specifies the order for XML Schema elements when class is + * mapped to a XML Schema complex type. + * + *

Refer to the table for how the propOrder affects the + * mapping of class

+ * + *

The propOrder is a list of names of JavaBean properties in + * the class. Each name in the list is the name of a Java + * identifier of the JavaBean property. The order in which + * JavaBean properties are listed is the order of XML Schema + * elements to which the JavaBean properties are mapped.

+ *

All of the JavaBean properties being mapped to XML Schema elements + * must be listed. + *

A JavaBean property or field listed in propOrder must not + * be transient or annotated with {@code @XmlTransient}. + *

The default ordering of JavaBean properties is determined + * by @{@link XmlAccessorOrder}. + */ + String[] propOrder() default {""}; + + /** + * Name of the target namespace of the XML Schema type. By + * default, this is the target namespace to which the package + * containing the class is mapped. + */ + String namespace() default "##default" ; + + /** + * Class containing a no-arg factory method for creating an + * instance of this class. The default is this class. + * + *

If {@code factoryClass} is DEFAULT.class and + * {@code factoryMethod} is "", then there is no static factory + * method. + * + *

If {@code factoryClass} is DEFAULT.class and + * {@code factoryMethod} is not "", then + * {@code factoryMethod} is the name of a static factory method + * in this class. + * + *

If {@code factoryClass} is not DEFAULT.class, then + * {@code factoryMethod} must not be "" and must be the name of + * a static factory method specified in {@code factoryClass}. + */ + Class factoryClass() default DEFAULT.class; + + /** + * Used in {@link XmlType#factoryClass()} to + * signal that either factory mehod is not used or + * that it's in the class with this {@link XmlType} itself. + */ + static final class DEFAULT {} + + /** + * Name of a no-arg factory method in the class specified in + * {@code factoryClass} factoryClass(). + * + */ + String factoryMethod() default ""; +} + + diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/XmlValue.java b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlValue.java new file mode 100644 index 000000000..f3a9f794d --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/XmlValue.java @@ -0,0 +1,146 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation; + +import java.lang.annotation.Target; +import java.lang.annotation.Retention; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +/** + *

+ * Enables mapping a class to a XML Schema complex type with a + * simpleContent or a XML Schema simple type. + *

+ * + *

+ * Usage: + *

+ * The {@code @XmlValue} annotation can be used with the following program + * elements: + *

    + *
  • a JavaBean property.
  • + *
  • non static, non transient field.
  • + *
+ * + *

See "Package Specification" in javax.xml.bind.package javadoc for + * additional common information.

+ * + * The usage is subject to the following usage constraints: + *
    + *
  • At most one field or property can be annotated with the + * {@code @XmlValue} annotation.
  • + * + *
  • {@code @XmlValue} can be used with the following + * annotations: {@link XmlList}. However this is redundant since + * {@link XmlList} maps a type to a simple schema type that derives by + * list just as {@link XmlValue} would.
  • + * + *
  • If the type of the field or property is a collection type, + * then the collection item type must map to a simple schema + * type.
  • + * + *
  • If the type of the field or property is not a collection + * type, then the type must map to a XML Schema simple type.
  • + * + *
+ *

+ * If the annotated JavaBean property is the sole class member being + * mapped to XML Schema construct, then the class is mapped to a + * simple type. + * + * If there are additional JavaBean properties (other than the + * JavaBean property annotated with {@code @XmlValue} annotation) + * that are mapped to XML attributes, then the class is mapped to a + * complex type with simpleContent. + *

+ * + *

Example 1: Map a class to XML Schema simpleType

+ * + *
+ * 
+ *     // Example 1: Code fragment
+ *     public class USPrice {
+ *         @XmlValue
+ *         public java.math.BigDecimal price;
+ *     }
+ * {@code
+ * 
+ *     
+ *     
+ *       
+ *     
+ *
+ * }
+ * + *

Example 2: Map a class to XML Schema complexType with + * with simpleContent.

+ * + *
+ *
+ *   // Example 2: Code fragment
+ *   public class InternationalPrice {
+ *       @XmlValue
+ *       public java.math.BigDecimal price;
+ * 
+ *       @XmlAttribute
+ *       public String currency;
+ *   }
+ * {@code
+ * 
+ *   
+ *   
+ *     
+ *       
+ *         
+ *       
+ *     
+ *   
+ *
+ * }
+ * + * @author Sekhar Vajjhala, Sun Microsystems, Inc. + * @see XmlType + * @since 1.6, JAXB 2.0 + */ + +@Retention(RUNTIME) @Target({FIELD, METHOD}) +public @interface XmlValue {} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/adapters/CollapsedStringAdapter.java b/fine-third-jdk11/src/javax/xml/bind/annotation/adapters/CollapsedStringAdapter.java new file mode 100644 index 000000000..36612c38f --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/adapters/CollapsedStringAdapter.java @@ -0,0 +1,134 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation.adapters; + + + +/** + * Built-in {@link XmlAdapter} to handle {@code xs:token} and its derived types. + * + *

+ * This adapter removes leading and trailing whitespaces, then truncate any + * sequence of tab, CR, LF, and SP by a single whitespace character ' '. + * + * @author Kohsuke Kawaguchi + * @since 1.6, JAXB 2.0 + */ +public class CollapsedStringAdapter extends XmlAdapter { + /** + * Removes leading and trailing whitespaces of the string + * given as the parameter, then truncate any + * sequence of tab, CR, LF, and SP by a single whitespace character ' '. + */ + public String unmarshal(String text) { + if(text==null) return null; // be defensive + + int len = text.length(); + + // most of the texts are already in the collapsed form. + // so look for the first whitespace in the hope that we will + // never see it. + int s=0; + while(s 0 && result.charAt(len - 1) == ' ') + result.setLength(len - 1); + // whitespaces are already collapsed, + // so all we have to do is to remove the last one character + // if it's a whitespace. + + return result.toString(); + } + + /** + * No-op. + * + * Just return the same string given as the parameter. + */ + public String marshal(String s) { + return s; + } + + + /** returns true if the specified char is a white space character. */ + protected static boolean isWhiteSpace(char ch) { + // most of the characters are non-control characters. + // so check that first to quickly return false for most of the cases. + if( ch>0x20 ) return false; + + // other than we have to do four comparisons. + return ch == 0x9 || ch == 0xA || ch == 0xD || ch == 0x20; + } +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/adapters/HexBinaryAdapter.java b/fine-third-jdk11/src/javax/xml/bind/annotation/adapters/HexBinaryAdapter.java new file mode 100644 index 000000000..3a6d9db6f --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/adapters/HexBinaryAdapter.java @@ -0,0 +1,64 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation.adapters; + +import javax.xml.bind.DatatypeConverter; + +/** + * {@link XmlAdapter} for {@code xs:hexBinary}. + * + *

+ * This {@link XmlAdapter} binds {@code byte[]} to the hexBinary representation in XML. + * + * @author Kohsuke Kawaguchi + * @since 1.6, JAXB 2.0 + */ +public final class HexBinaryAdapter extends XmlAdapter { + public byte[] unmarshal(String s) { + if(s==null) return null; + return DatatypeConverter.parseHexBinary(s); + } + + public String marshal(byte[] bytes) { + if(bytes==null) return null; + return DatatypeConverter.printHexBinary(bytes); + } +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/adapters/NormalizedStringAdapter.java b/fine-third-jdk11/src/javax/xml/bind/annotation/adapters/NormalizedStringAdapter.java new file mode 100644 index 000000000..c865354f0 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/adapters/NormalizedStringAdapter.java @@ -0,0 +1,107 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation.adapters; + + + +/** + * {@link XmlAdapter} to handle {@code xs:normalizedString}. + * + *

+ * Replaces any tab, CR, and LF by a whitespace character ' ', + * as specified in the whitespace facet 'replace' + * + * @author Kohsuke Kawaguchi, Martin Grebac + * @since 1.6, JAXB 2.0 + */ +public final class NormalizedStringAdapter extends XmlAdapter { + /** + * Replace any tab, CR, and LF by a whitespace character ' ', + * as specified in the whitespace facet 'replace' + */ + public String unmarshal(String text) { + if(text==null) return null; // be defensive + + int i=text.length()-1; + + // look for the first whitespace char. + while( i>=0 && !isWhiteSpaceExceptSpace(text.charAt(i)) ) + i--; + + if( i<0 ) + // no such whitespace. replace(text)==text. + return text; + + // we now know that we need to modify the text. + // allocate a char array to do it. + char[] buf = text.toCharArray(); + + buf[i--] = ' '; + for( ; i>=0; i-- ) + if( isWhiteSpaceExceptSpace(buf[i])) + buf[i] = ' '; + + return new String(buf); + } + + /** + * No-op. + * + * Just return the same string given as the parameter. + */ + public String marshal(String s) { + return s; + } + + + /** + * Returns true if the specified char is a white space character + * but not 0x20. + */ + protected static boolean isWhiteSpaceExceptSpace(char ch) { + // most of the characters are non-control characters. + // so check that first to quickly return false for most of the cases. + if( ch>=0x20 ) return false; + + // other than we have to do four comparisons. + return ch == 0x9 || ch == 0xA || ch == 0xD; + } +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/adapters/XmlAdapter.java b/fine-third-jdk11/src/javax/xml/bind/annotation/adapters/XmlAdapter.java new file mode 100644 index 000000000..f08f9b567 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/adapters/XmlAdapter.java @@ -0,0 +1,208 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation.adapters; + +/** + * Adapts a Java type for custom marshaling. + * + *

Usage:

+ * + *

+ * Some Java types do not map naturally to an XML representation, for + * example {@code HashMap} or other non JavaBean classes. Conversely, + * an XML representation may map to a Java type but an application may + * choose to access the XML representation using another Java + * type. For example, the schema to Java binding rules bind + * xs:DateTime by default to XmlGregorianCalendar. But an application + * may desire to bind xs:DateTime to a custom type, + * MyXmlGregorianCalendar, for example. In both cases, there is a + * mismatch between bound type , used by an application to + * access XML content and the value type, that is mapped to an + * XML representation. + * + *

+ * This abstract class defines methods for adapting a bound type to a value + * type or vice versa. The methods are invoked by the JAXB binding + * framework during marshaling and unmarshalling: + * + *

    + *
  • XmlAdapter.marshal(...): During marshalling, JAXB + * binding framework invokes XmlAdapter.marshal(..) to adapt a + * bound type to value type, which is then marshaled to XML + * representation.
  • + * + *
  • XmlAdapter.unmarshal(...): During unmarshalling, + * JAXB binding framework first unmarshals XML representation + * to a value type and then invokes XmlAdapter.unmarshal(..) to + * adapt the value type to a bound type.
  • + *
+ * + * Writing an adapter therefore involves the following steps: + * + *
    + *
  • Write an adapter that implements this abstract class.
  • + *
  • Install the adapter using the annotation {@link + * XmlJavaTypeAdapter}
  • + *
+ * + *

Example: Customized mapping of {@code HashMap}

+ *

The following example illustrates the use of + * {@code @XmlAdapter} and {@code @XmlJavaTypeAdapter} to + * customize the mapping of a {@code HashMap}. + * + *

Step 1: Determine the desired XML representation for HashMap. + * + *

{@code
+ *     
+ *         this is a value
+ *         this is another value
+ *         ...
+ *     
+ * }
+ * + *

Step 2: Determine the schema definition that the + * desired XML representation shown above should follow. + * + *

{@code
+ *     
+ *     
+ *       
+ *         
+ *       
+ *     
+ *
+ *     
+ *       
+ *         
+ *           
+ *         
+ *       
+ *     
+ *
+ * }
+ * + *

Step 3: Write value types that can generate the above + * schema definition. + * + *

+ *     public class MyHashMapType {
+ *         List<MyHashMapEntryType> entry;
+ *     }
+ *
+ *     public class MyHashMapEntryType {
+ *         @XmlAttribute
+ *         public Integer key; 
+ *
+ *         @XmlValue
+ *         public String value;
+ *     }
+ * 
+ * + *

Step 4: Write the adapter that adapts the value type, + * MyHashMapType to a bound type, HashMap, used by the application. + * + *

{@code
+ *     public final class MyHashMapAdapter extends
+ *                        XmlAdapter { ... }
+ *      
+ * }
+ * + *

Step 5: Use the adapter. + * + *

+ *     public class Foo {
+ *         @XmlJavaTypeAdapter(MyHashMapAdapter.class)
+ *         HashMap hashmap;
+ *         ...
+ *     }
+ * 
+ * + * The above code fragment will map to the following schema: + * + *
{@code
+ *     
+ *       
+ *         
+ *       
+ *     
+ * }
+ * + * @param + * The type that JAXB doesn't know how to handle. An adapter is written + * to allow this type to be used as an in-memory representation through + * the {@code ValueType}. + * @param + * The type that JAXB knows how to handle out of the box. + * + * @author
  • Sekhar Vajjhala, Sun Microsystems Inc.
  • Kohsuke Kawaguchi, Sun Microsystems Inc.
+ * @see XmlJavaTypeAdapter + * @since 1.6, JAXB 2.0 + */ +public abstract class XmlAdapter { + + /** + * Do-nothing constructor for the derived classes. + */ + protected XmlAdapter() {} + + /** + * Convert a value type to a bound type. + * + * @param v + * The value to be converted. Can be null. + * @throws Exception + * if there's an error during the conversion. The caller is responsible for + * reporting the error to the user through {@link javax.xml.bind.ValidationEventHandler}. + */ + public abstract BoundType unmarshal(ValueType v) throws Exception; + + /** + * Convert a bound type to a value type. + * + * @param v + * The value to be convereted. Can be null. + * @throws Exception + * if there's an error during the conversion. The caller is responsible for + * reporting the error to the user through {@link javax.xml.bind.ValidationEventHandler}. + */ + public abstract ValueType marshal(BoundType v) throws Exception; +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/adapters/XmlJavaTypeAdapter.java b/fine-third-jdk11/src/javax/xml/bind/annotation/adapters/XmlJavaTypeAdapter.java new file mode 100644 index 000000000..5e650ca41 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/adapters/XmlJavaTypeAdapter.java @@ -0,0 +1,131 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation.adapters; + +import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlElementRefs; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlSchema; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlSchemaTypes; +import java.lang.annotation.Target; +import java.lang.annotation.Retention; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.PACKAGE; + + +/** + * Use an adapter that implements {@link XmlAdapter} for custom marshaling. + * + *

Usage:

+ * + *

The {@code @XmlJavaTypeAdapter} annotation can be used with the + * following program elements: + *

    + *
  • a JavaBean property
  • + *
  • field
  • + *
  • parameter
  • + *
  • package
  • + *
  • from within {@link XmlJavaTypeAdapters}
  • + *
+ * + *

When {@code @XmlJavaTypeAdapter} annotation is defined on a + * class, it applies to all references to the class. + *

When {@code @XmlJavaTypeAdapter} annotation is defined at the + * package level it applies to all references from within the package + * to {@code @XmlJavaTypeAdapter.type()}. + *

When {@code @XmlJavaTypeAdapter} annotation is defined on the + * field, property or parameter, then the annotation applies to the + * field, property or the parameter only. + *

A {@code @XmlJavaTypeAdapter} annotation on a field, property + * or parameter overrides the {@code @XmlJavaTypeAdapter} annotation + * associated with the class being referenced by the field, property + * or parameter. + *

A {@code @XmlJavaTypeAdapter} annotation on a class overrides + * the {@code @XmlJavaTypeAdapter} annotation specified at the + * package level for that class. + * + *

This annotation can be used with the following other annotations: + * {@link XmlElement}, {@link XmlAttribute}, {@link XmlElementRef}, + * {@link XmlElementRefs}, {@link XmlAnyElement}. This can also be + * used at the package level with the following annotations: + * {@link XmlAccessorType}, {@link XmlSchema}, {@link XmlSchemaType}, + * {@link XmlSchemaTypes}. + * + *

Example: See example in {@link XmlAdapter} + * + * @author

  • Sekhar Vajjhala, Sun Microsystems Inc.
  • Kohsuke Kawaguchi, Sun Microsystems Inc.
+ * @since 1.6, JAXB 2.0 + * @see XmlAdapter + */ + +@Retention(RUNTIME) @Target({PACKAGE,FIELD,METHOD,TYPE,PARAMETER}) +public @interface XmlJavaTypeAdapter { + /** + * Points to the class that converts a value type to a bound type or vice versa. + * See {@link XmlAdapter} for more details. + */ + Class value(); + + /** + * If this annotation is used at the package level, then value of + * the type() must be specified. + */ + + Class type() default DEFAULT.class; + + /** + * Used in {@link XmlJavaTypeAdapter#type()} to + * signal that the type be inferred from the signature + * of the field, property, parameter or the class. + */ + + static final class DEFAULT {} + +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/adapters/XmlJavaTypeAdapters.java b/fine-third-jdk11/src/javax/xml/bind/annotation/adapters/XmlJavaTypeAdapters.java new file mode 100644 index 000000000..2e5fb4713 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/adapters/XmlJavaTypeAdapters.java @@ -0,0 +1,77 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.annotation.adapters; + +import static java.lang.annotation.ElementType.PACKAGE; +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import java.lang.annotation.Target; + +/** + *

+ * A container for multiple @{@link XmlJavaTypeAdapter} annotations. + * + *

Multiple annotations of the same type are not allowed on a program + * element. This annotation therefore serves as a container annotation + * for multiple @XmlJavaTypeAdapter as follows: + * + *

+ * @XmlJavaTypeAdapters ({ @XmlJavaTypeAdapter(...),@XmlJavaTypeAdapter(...) })
+ * 
+ * + *

The {@code @XmlJavaTypeAdapters} annotation is useful for + * defining {@link XmlJavaTypeAdapter} annotations for different types + * at the package level. + * + *

See "Package Specification" in javax.xml.bind.package javadoc for + * additional common information.

+ * + * @author
  • Sekhar Vajjhala, Sun Microsystems, Inc.
+ * @see XmlJavaTypeAdapter + * @since 1.6, JAXB 2.0 + */ +@Retention(RUNTIME) @Target({PACKAGE}) +public @interface XmlJavaTypeAdapters { + /** + * Collection of @{@link XmlJavaTypeAdapter} annotations + */ + XmlJavaTypeAdapter[] value(); +} diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/adapters/package-info.java b/fine-third-jdk11/src/javax/xml/bind/annotation/adapters/package-info.java new file mode 100644 index 000000000..ae94d5b04 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/adapters/package-info.java @@ -0,0 +1,61 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +/** + * {@link javax.xml.bind.annotation.adapters.XmlAdapter} and its spec-defined + * sub-classes to allow arbitrary Java classes to be used with JAXB. + * + *

Package Specification

+ * + * + * + *

Related Documentation

+ * + * For overviews, tutorials, examples, guides, and tool documentation, + * please see: + * + * + * @see JAXB Website + */ +package javax.xml.bind.annotation.adapters; diff --git a/fine-third-jdk11/src/javax/xml/bind/annotation/package-info.java b/fine-third-jdk11/src/javax/xml/bind/annotation/package-info.java new file mode 100644 index 000000000..ea206f197 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/annotation/package-info.java @@ -0,0 +1,203 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +/** + * Defines annotations for customizing Java program elements to XML Schema mapping. + *

+ *

Package Specification

+ *

The following table shows the JAXB mapping annotations + * that can be associated with each program element.

+ *

+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Program ElementJAXB annotation
Package + * + *
Class + * + *
Enum type + * + *
JavaBean Property/field + * + *
Parameter + * + *
+ *

Terminology

+ *

+ * JavaBean property and field: For the purposes of + * mapping, there is no semantic difference between a field and + * a JavaBean property. Thus, an annotation that can be applied + * to a JavaBean property can always be applied to a + * field. Hence in the Javadoc documentation, for brevity, the + * term JavaBean property or property is used to mean either JavaBean + * property or a field. Where required, both are explicitly + * mentioned. + *

+ * top level class: For the purpose of mapping, there is + * no semantic difference between a top level class and a + * static nested class. Thus, an annotation that can be applied + * to a top level class, can always be applied to a nested + * static class. Hence in the Javadoc documentation, for + * brevity, the term "top level class" or just class is used to + * mean either a top level class or a nested static + * class. + *

+ * mapping annotation:A JAXB 2.0 defined program + * annotation based on the JSR 175 programming annotation + * facility. + *

Common Usage Constraints

+ *

The following usage constraints are defined here since + * they apply to more than annotation: + *

    + *
  • For a property, a given annotation can be applied to + * either read or write property but not both.
  • + *
  • A property name must be different from any other + * property name in any of the super classes of the + * class being mapped.
  • + *
  • A mapped field name or the decapitalized name of a + * mapped property must be unique within a class.
  • + *
+ *

Notations

+ * Namespace prefixes + *

The following namespace prefixes are used in the XML Schema + * fragments in this package. + *

+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
PrefixNamespaceNotes
xshttp://www.w3.org/2001/XMLSchemaNamespace of XML Schema namespace
refhttp://ws-i.org/profiles/basic/1.1/xsdNamespace for swaref schema component
xsihttp://www.w3.org/2001/XMLSchema-instanceXML Schema namespace for instances
+ * + * @since 1.6, JAXB 2.0 + */ +package javax.xml.bind.annotation; diff --git a/fine-third-jdk11/src/javax/xml/bind/attachment/AttachmentMarshaller.java b/fine-third-jdk11/src/javax/xml/bind/attachment/AttachmentMarshaller.java new file mode 100644 index 000000000..8127bcb15 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/attachment/AttachmentMarshaller.java @@ -0,0 +1,215 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.attachment; + +import javax.activation.DataHandler; +import javax.xml.bind.Marshaller; + +/** + *

Enable JAXB marshalling to optimize storage of binary data. + * + *

This API enables an efficient cooperative creation of optimized + * binary data formats between a JAXB marshalling process and a MIME-based package + * processor. A JAXB implementation marshals the root body of a MIME-based package, + * delegating the creation of referenceable MIME parts to + * the MIME-based package processor that implements this abstraction. + * + *

XOP processing is enabled when {@link #isXOPPackage()} is true. + * See {@link #addMtomAttachment(DataHandler, String, String)} for details. + * + * + *

WS-I Attachment Profile 1.0 is supported by + * {@link #addSwaRefAttachment(DataHandler)} being called by the + * marshaller for each JAXB property related to + * {http://ws-i.org/profiles/basic/1.1/xsd}swaRef. + * + * + * @author Marc Hadley + * @author Kohsuke Kawaguchi + * @author Joseph Fialli + * @since 1.6, JAXB 2.0 + * + * @see Marshaller#setAttachmentMarshaller(AttachmentMarshaller) + * + * @see XML-binary Optimized Packaging + * @see WS-I Attachments Profile Version 1.0. + */ +public abstract class AttachmentMarshaller { + + /** + *

Consider MIME content {@code data} for optimized binary storage as an attachment. + * + *

+ * This method is called by JAXB marshal process when {@link #isXOPPackage()} is + * {@code true}, for each element whose datatype is "base64Binary", as described in + * Step 3 in + * Creating XOP Packages. + * + *

+ * The method implementor determines whether {@code data} shall be attached separately + * or inlined as base64Binary data. If the implementation chooses to optimize the storage + * of the binary data as a MIME part, it is responsible for attaching {@code data} to the + * MIME-based package, and then assigning an unique content-id, cid, that identifies + * the MIME part within the MIME message. This method returns the cid, + * which enables the JAXB marshaller to marshal a XOP element that refers to that cid in place + * of marshalling the binary data. When the method returns null, the JAXB marshaller + * inlines {@code data} as base64binary data. + * + *

+ * The caller of this method is required to meet the following constraint. + * If the element infoset item containing {@code data} has the attribute + * {@code xmime:contentType} or if the JAXB property/field representing + * {@code data} is annotated with a known MIME type, + * {@code data.getContentType()} should be set to that MIME type. + * + *

+ * The {@code elementNamespace} and {@code elementLocalName} + * parameters provide the + * context that contains the binary data. This information could + * be used by the MIME-based package processor to determine if the + * binary data should be inlined or optimized as an attachment. + * + * @param data + * represents the data to be attached. Must be non-null. + * @param elementNamespace + * the namespace URI of the element that encloses the base64Binary data. + * Can be empty but never null. + * @param elementLocalName + * The local name of the element. Always a non-null valid string. + * + * @return + * a valid content-id URI (see RFC 2387) that identifies the attachment containing {@code data}. + * Otherwise, null if the attachment was not added and should instead be inlined in the message. + * + * @see XML-binary Optimized Packaging + * @see Describing Media Content of Binary Data in XML + */ + public abstract String addMtomAttachment(DataHandler data, String elementNamespace, String elementLocalName); + + /** + *

Consider binary {@code data} for optimized binary storage as an attachment. + * + *

Since content type is not known, the attachment's MIME content type must be set to "application/octet-stream". + * + *

+ * The {@code elementNamespace} and {@code elementLocalName} + * parameters provide the + * context that contains the binary data. This information could + * be used by the MIME-based package processor to determine if the + * binary data should be inlined or optimized as an attachment. + * + * @param data + * represents the data to be attached. Must be non-null. The actual data region is + * specified by {@code (data,offset,length)} tuple. + * + * @param offset + * The offset within the array of the first byte to be read; + * must be non-negative and no larger than array.length + * + * @param length + * The number of bytes to be read from the given array; + * must be non-negative and no larger than array.length + * + * @param mimeType + * If the data has an associated MIME type known to JAXB, that is passed + * as this parameter. If none is known, "application/octet-stream". + * This parameter may never be null. + * + * @param elementNamespace + * the namespace URI of the element that encloses the base64Binary data. + * Can be empty but never null. + * + * @param elementLocalName + * The local name of the element. Always a non-null valid string. + * + * @return content-id URI, cid, to the attachment containing + * {@code data} or null if data should be inlined. + * + * @see #addMtomAttachment(DataHandler, String, String) + */ + public abstract String addMtomAttachment(byte[] data, int offset, int length, String mimeType, String elementNamespace, String elementLocalName); + + /** + *

Read-only property that returns true if JAXB marshaller should enable XOP creation. + * + *

This value must not change during the marshalling process. When this + * value is true, the {@code addMtomAttachment(...)} method + * is invoked when the appropriate binary datatypes are encountered by + * the marshal process. + * + *

Marshaller.marshal() must throw IllegalStateException if this value is {@code true} + * and the XML content to be marshalled violates Step 1 in + * Creating XOP Pacakges + * http://www.w3.org/TR/2005/REC-xop10-20050125/#creating_xop_packages. + * "Ensure the Original XML Infoset contains no element information item with a + * [namespace name] of "http://www.w3.org/2004/08/xop/include" and a [local name] of Include" + * + *

When this method returns true and during the marshal process + * at least one call to {@code addMtomAttachment(...)} returns + * a content-id, the MIME-based package processor must label the + * root part with the application/xop+xml media type as described in + * Step 5 of + * Creating XOP Pacakges. + * + * @return true when MIME context is a XOP Package. + */ + public boolean isXOPPackage() { return false; } + + /** + *

Add MIME {@code data} as an attachment and return attachment's content-id, cid. + * + *

+ * This method is called by JAXB marshal process for each element/attribute typed as + * {http://ws-i.org/profiles/basic/1.1/xsd}swaRef. The MIME-based package processor + * implementing this method is responsible for attaching the specified data to a + * MIME attachment, and generating a content-id, cid, that uniquely identifies the attachment + * within the MIME-based package. + * + *

Caller inserts the returned content-id, cid, into the XML content being marshalled. + * + * @param data + * represents the data to be attached. Must be non-null. + * @return + * must be a valid URI used as cid. Must satisfy Conformance Requirement R2928 from + * WS-I Attachments Profile Version 1.0. + */ + public abstract String addSwaRefAttachment(DataHandler data); +} diff --git a/fine-third-jdk11/src/javax/xml/bind/attachment/AttachmentUnmarshaller.java b/fine-third-jdk11/src/javax/xml/bind/attachment/AttachmentUnmarshaller.java new file mode 100644 index 000000000..b71807230 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/attachment/AttachmentUnmarshaller.java @@ -0,0 +1,155 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.attachment; + +import javax.activation.DataHandler; + +/** + *

Enables JAXB unmarshalling of a root document containing optimized binary data formats.

+ * + *

This API enables an efficient cooperative processing of optimized + * binary data formats between a JAXB 2.0 implementation and MIME-based package + * processor (MTOM/XOP and WS-I AP 1.0). JAXB unmarshals the body of a package, delegating the + * understanding of the packaging format being used to a MIME-based + * package processor that implements this abstract class.

+ * + *

This abstract class identifies if a package requires XOP processing, {@link #isXOPPackage()} + * and provides retrieval of binary content stored as attachments by content-id.

+ * + *

Identifying the content-id, cid, to pass to {@code getAttachment*(String cid)}

+ * + * + * @author Marc Hadley + * @author Kohsuke Kawaguchi + * @author Joseph Fialli + * + * @since 1.6, JAXB 2.0 + * + * @see javax.xml.bind.Unmarshaller#setAttachmentUnmarshaller(AttachmentUnmarshaller) + * + * @see XML-binary Optimized Packaging + * @see WS-I Attachments Profile Version 1.0. + * @see Describing Media Content of Binary Data in XML + */ +public abstract class AttachmentUnmarshaller { + /** + *

Lookup MIME content by content-id, {@code cid}, and return as a {@link DataHandler}.

+ * + *

The returned {@code DataHandler} instance must be configured + * to meet the following required mapping constaint. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Required Mappings between MIME and Java Types
MIME TypeJava Type
{@code DataHandler.getContentType()}{@code instanceof DataHandler.getContent()}
image/gifjava.awt.Image
image/jpegjava.awt.Image
text/xml or application/xmljavax.xml.transform.Source
+ * Note that it is allowable to support additional mappings. + * + * @param cid It is expected to be a valid lexical form of the XML Schema + * {@code xs:anyURI} datatype. If {@link #isXOPPackage()}{@code ==true}, + * it must be a valid URI per the {@code cid:} URI scheme (see RFC 2387) + * + * @return + * a {@link DataHandler} that represents the MIME attachment. + * + * @throws IllegalArgumentException if the attachment for the given cid is not found. + */ + public abstract DataHandler getAttachmentAsDataHandler(String cid); + + /** + *

Retrieve the attachment identified by content-id, {@code cid}, as a {@code byte[]}. + * + * @param cid It is expected to be a valid lexical form of the XML Schema + * {@code xs:anyURI} datatype. If {@link #isXOPPackage()}{@code ==true}, + * it must be a valid URI per the {@code cid:} URI scheme (see RFC 2387) + * + * @return byte[] representation of attachment identified by cid. + * + * @throws IllegalArgumentException if the attachment for the given cid is not found. + */ + public abstract byte[] getAttachmentAsByteArray(String cid); + + /** + *

Read-only property that returns true if JAXB unmarshaller needs to perform XOP processing.

+ * + *

This method returns {@code true} when the constraints specified + * in Identifying XOP Documents are met. + * This value must not change during the unmarshalling process.

+ * + * @return true when MIME context is a XOP Document. + */ + public boolean isXOPPackage() { return false; } +} + + diff --git a/fine-third-jdk11/src/javax/xml/bind/attachment/package-info.java b/fine-third-jdk11/src/javax/xml/bind/attachment/package-info.java new file mode 100644 index 000000000..a38dacaf3 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/attachment/package-info.java @@ -0,0 +1,74 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +/** + * This package is implemented by a MIME-based package processor that + * enables the interpretation and creation of optimized binary data + * within an MIME-based package format. + *

+ *

+ * Soap MTOM[1], XOP([2][3]) and WS-I AP[4] standardize approaches to + * optimized transmission of binary datatypes as an attachment. + * To optimally support these standards within a message passing + * environment, this package enables an integrated solution between + * a MIME-based package processor and JAXB unmarshall/marshal processes. + *

+ *

Package Specification

+ *

+ *

+ *

+ *

Related Standards

+ *

+ *

+ * + * @see [1]SOAP Message Transmission Optimization Mechanism + * @see [2]XML-binary Optimized Packaging + * @see [3]WS-I Attachments Profile Version 1.0. + * @see [4]Describing Media Content of Binary Data in XML + * @since JAXB 2.0 + */ +package javax.xml.bind.attachment; \ No newline at end of file diff --git a/fine-third-jdk11/src/javax/xml/bind/helpers/AbstractMarshallerImpl.java b/fine-third-jdk11/src/javax/xml/bind/helpers/AbstractMarshallerImpl.java new file mode 100644 index 000000000..16570c8b0 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/helpers/AbstractMarshallerImpl.java @@ -0,0 +1,510 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.helpers; + +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.PropertyException; +import javax.xml.bind.ValidationEventHandler; +import javax.xml.bind.annotation.adapters.XmlAdapter; +import javax.xml.bind.attachment.AttachmentMarshaller; +import javax.xml.stream.XMLEventWriter; +import javax.xml.stream.XMLStreamWriter; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.sax.SAXResult; +import javax.xml.transform.stream.StreamResult; +import javax.xml.validation.Schema; +import java.io.UnsupportedEncodingException; +import java.io.File; +import java.io.OutputStream; +import java.io.FileOutputStream; +import java.io.BufferedOutputStream; +import java.io.IOException; +// J2SE1.4 feature +// import java.nio.charset.Charset; +// import java.nio.charset.UnsupportedCharsetException; + +/** + * Partial default {@code Marshaller} implementation. + * + *

+ * This class provides a partial default implementation for the + * {@link javax.xml.bind.Marshaller} interface. + * + *

+ * The only methods that a JAXB Provider has to implement are + * {@link Marshaller#marshal(Object, javax.xml.transform.Result) marshal(Object, javax.xml.transform.Result)}, + * {@link Marshaller#marshal(Object, javax.xml.transform.Result) marshal(Object, javax.xml.stream.XMLStreamWriter)}, and + * {@link Marshaller#marshal(Object, javax.xml.transform.Result) marshal(Object, javax.xml.stream.XMLEventWriter)}. + * + * @author

  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
+ * @see javax.xml.bind.Marshaller + * @since 1.6, JAXB 1.0 + */ +public abstract class AbstractMarshallerImpl implements Marshaller +{ + /** handler that will be used to process errors and warnings during marshal */ + private ValidationEventHandler eventHandler = + new DefaultValidationEventHandler(); + + //J2SE1.4 feature + //private Charset encoding = null; + + /** store the value of the encoding property. */ + private String encoding = "UTF-8"; + + /** store the value of the schemaLocation property. */ + private String schemaLocation = null; + + /** store the value of the noNamespaceSchemaLocation property. */ + private String noNSSchemaLocation = null; + + /** store the value of the formattedOutput property. */ + private boolean formattedOutput = false; + + /** store the value of the fragment property. */ + private boolean fragment = false; + + public final void marshal( Object obj, java.io.OutputStream os ) + throws JAXBException { + + checkNotNull( obj, "obj", os, "os" ); + marshal( obj, new StreamResult(os) ); + } + + public void marshal(Object jaxbElement, File output) throws JAXBException { + checkNotNull(jaxbElement, "jaxbElement", output, "output" ); + try { + OutputStream os = new BufferedOutputStream(new FileOutputStream(output)); + try { + marshal( jaxbElement, new StreamResult(os) ); + } finally { + os.close(); + } + } catch (IOException e) { + throw new JAXBException(e); + } + } + + public final void marshal( Object obj, java.io.Writer w ) + throws JAXBException { + + checkNotNull( obj, "obj", w, "writer" ); + marshal( obj, new StreamResult(w) ); + } + + public final void marshal( Object obj, org.xml.sax.ContentHandler handler ) + throws JAXBException { + + checkNotNull( obj, "obj", handler, "handler" ); + marshal( obj, new SAXResult(handler) ); + } + + public final void marshal( Object obj, org.w3c.dom.Node node ) + throws JAXBException { + + checkNotNull( obj, "obj", node, "node" ); + marshal( obj, new DOMResult(node) ); + } + + /** + * By default, the getNode method is unsupported and throw + * an {@link java.lang.UnsupportedOperationException}. + * + * Implementations that choose to support this method must + * override this method. + */ + public org.w3c.dom.Node getNode( Object obj ) throws JAXBException { + + checkNotNull( obj, "obj", Boolean.TRUE, "foo" ); + + throw new UnsupportedOperationException(); + } + + /** + * Convenience method for getting the current output encoding. + * + * @return the current encoding or "UTF-8" if it hasn't been set. + */ + protected String getEncoding() { + return encoding; + } + + /** + * Convenience method for setting the output encoding. + * + * @param encoding a valid encoding as specified in the Marshaller class + * documentation + */ + protected void setEncoding( String encoding ) { + this.encoding = encoding; + } + + /** + * Convenience method for getting the current schemaLocation. + * + * @return the current schemaLocation or null if it hasn't been set + */ + protected String getSchemaLocation() { + return schemaLocation; + } + + /** + * Convenience method for setting the schemaLocation. + * + * @param location the schemaLocation value + */ + protected void setSchemaLocation( String location ) { + schemaLocation = location; + } + + /** + * Convenience method for getting the current noNamespaceSchemaLocation. + * + * @return the current noNamespaceSchemaLocation or null if it hasn't + * been set + */ + protected String getNoNSSchemaLocation() { + return noNSSchemaLocation; + } + + /** + * Convenience method for setting the noNamespaceSchemaLocation. + * + * @param location the noNamespaceSchemaLocation value + */ + protected void setNoNSSchemaLocation( String location ) { + noNSSchemaLocation = location; + } + + /** + * Convenience method for getting the formatted output flag. + * + * @return the current value of the formatted output flag or false if + * it hasn't been set. + */ + protected boolean isFormattedOutput() { + return formattedOutput; + } + + /** + * Convenience method for setting the formatted output flag. + * + * @param v value of the formatted output flag. + */ + protected void setFormattedOutput( boolean v ) { + formattedOutput = v; + } + + + /** + * Convenience method for getting the fragment flag. + * + * @return the current value of the fragment flag or false if + * it hasn't been set. + */ + protected boolean isFragment() { + return fragment; + } + + /** + * Convenience method for setting the fragment flag. + * + * @param v value of the fragment flag. + */ + protected void setFragment( boolean v ) { + fragment = v; + } + + + static String[] aliases = { + "UTF-8", "UTF8", + "UTF-16", "Unicode", + "UTF-16BE", "UnicodeBigUnmarked", + "UTF-16LE", "UnicodeLittleUnmarked", + "US-ASCII", "ASCII", + "TIS-620", "TIS620", + + // taken from the project-X parser + "ISO-10646-UCS-2", "Unicode", + + "EBCDIC-CP-US", "cp037", + "EBCDIC-CP-CA", "cp037", + "EBCDIC-CP-NL", "cp037", + "EBCDIC-CP-WT", "cp037", + + "EBCDIC-CP-DK", "cp277", + "EBCDIC-CP-NO", "cp277", + "EBCDIC-CP-FI", "cp278", + "EBCDIC-CP-SE", "cp278", + + "EBCDIC-CP-IT", "cp280", + "EBCDIC-CP-ES", "cp284", + "EBCDIC-CP-GB", "cp285", + "EBCDIC-CP-FR", "cp297", + + "EBCDIC-CP-AR1", "cp420", + "EBCDIC-CP-HE", "cp424", + "EBCDIC-CP-BE", "cp500", + "EBCDIC-CP-CH", "cp500", + + "EBCDIC-CP-ROECE", "cp870", + "EBCDIC-CP-YU", "cp870", + "EBCDIC-CP-IS", "cp871", + "EBCDIC-CP-AR2", "cp918", + + // IANA also defines two that JDK 1.2 doesn't handle: + // EBCDIC-CP-GR --> CP423 + // EBCDIC-CP-TR --> CP905 + }; + + /** + * Gets the corresponding Java encoding name from an IANA name. + * + * This method is a helper method for the derived class to convert + * encoding names. + * + * @exception UnsupportedEncodingException + * If this implementation couldn't find the Java encoding name. + */ + protected String getJavaEncoding( String encoding ) throws UnsupportedEncodingException { + try { + "1".getBytes(encoding); + return encoding; + } catch( UnsupportedEncodingException e ) { + // try known alias + for( int i=0; i void setAdapter(Class type, A adapter) { + throw new UnsupportedOperationException(); + } + + public A getAdapter(Class type) { + throw new UnsupportedOperationException(); + } + + public void setAttachmentMarshaller(AttachmentMarshaller am) { + throw new UnsupportedOperationException(); + } + + public AttachmentMarshaller getAttachmentMarshaller() { + throw new UnsupportedOperationException(); + } + + public void setListener(Listener listener) { + throw new UnsupportedOperationException(); + } + + public Listener getListener() { + throw new UnsupportedOperationException(); + } +} diff --git a/fine-third-jdk11/src/javax/xml/bind/helpers/AbstractUnmarshallerImpl.java b/fine-third-jdk11/src/javax/xml/bind/helpers/AbstractUnmarshallerImpl.java new file mode 100644 index 000000000..e0a85e39a --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/helpers/AbstractUnmarshallerImpl.java @@ -0,0 +1,440 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.helpers; + +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; +import org.w3c.dom.Node; + +import javax.xml.bind.JAXBException; +import javax.xml.bind.PropertyException; +import javax.xml.bind.UnmarshalException; +import javax.xml.bind.Unmarshaller; +import javax.xml.bind.ValidationEventHandler; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.adapters.XmlAdapter; +import javax.xml.bind.attachment.AttachmentUnmarshaller; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParserFactory; +import javax.xml.stream.XMLEventReader; +import javax.xml.stream.XMLStreamReader; +import javax.xml.transform.Source; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import java.io.*; +import java.net.URL; + +/** + * Partial default {@code Unmarshaller} implementation. + * + *

+ * This class provides a partial default implementation for the + * {@link javax.xml.bind.Unmarshaller}interface. + * + *

+ * A JAXB Provider has to implement five methods (getUnmarshallerHandler, + * unmarshal(Node), unmarshal(XMLReader,InputSource), + * unmarshal(XMLStreamReader), and unmarshal(XMLEventReader). + * + * @author

    + *
  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • + *
+ * @see javax.xml.bind.Unmarshaller + * @since 1.6, JAXB 1.0 + */ +public abstract class AbstractUnmarshallerImpl implements Unmarshaller +{ + /** handler that will be used to process errors and warnings during unmarshal */ + private ValidationEventHandler eventHandler = + new DefaultValidationEventHandler(); + + /** whether or not the unmarshaller will validate */ + protected boolean validating = false; + + /** + * XMLReader that will be used to parse a document. + */ + private XMLReader reader = null; + + /** + * Obtains a configured XMLReader. + * + * This method is used when the client-specified + * {@link SAXSource} object doesn't have XMLReader. + * + * {@link Unmarshaller} is not re-entrant, so we will + * only use one instance of XMLReader. + */ + protected XMLReader getXMLReader() throws JAXBException { + if(reader==null) { + try { + SAXParserFactory parserFactory; + parserFactory = SAXParserFactory.newInstance(); + parserFactory.setNamespaceAware(true); + // there is no point in asking a validation because + // there is no guarantee that the document will come with + // a proper schemaLocation. + parserFactory.setValidating(false); + reader = parserFactory.newSAXParser().getXMLReader(); + } catch( ParserConfigurationException e ) { + throw new JAXBException(e); + } catch( SAXException e ) { + throw new JAXBException(e); + } + } + return reader; + } + + public Object unmarshal( Source source ) throws JAXBException { + if( source == null ) { + throw new IllegalArgumentException( + Messages.format( Messages.MUST_NOT_BE_NULL, "source" ) ); + } + + if(source instanceof SAXSource) + return unmarshal( (SAXSource)source ); + if(source instanceof StreamSource) + return unmarshal( streamSourceToInputSource((StreamSource)source)); + if(source instanceof DOMSource) + return unmarshal( ((DOMSource)source).getNode() ); + + // we don't handle other types of Source + throw new IllegalArgumentException(); + } + + // use the client specified XMLReader contained in the SAXSource. + private Object unmarshal( SAXSource source ) throws JAXBException { + + XMLReader r = source.getXMLReader(); + if( r == null ) + r = getXMLReader(); + + return unmarshal( r, source.getInputSource() ); + } + + /** + * Unmarshals an object by using the specified XMLReader and the InputSource. + * + * The callee should call the setErrorHandler method of the XMLReader + * so that errors are passed to the client-specified ValidationEventHandler. + */ + protected abstract Object unmarshal( XMLReader reader, InputSource source ) throws JAXBException; + + public final Object unmarshal( InputSource source ) throws JAXBException { + if( source == null ) { + throw new IllegalArgumentException( + Messages.format( Messages.MUST_NOT_BE_NULL, "source" ) ); + } + + return unmarshal( getXMLReader(), source ); + } + + + private Object unmarshal( String url ) throws JAXBException { + return unmarshal( new InputSource(url) ); + } + + public final Object unmarshal( URL url ) throws JAXBException { + if( url == null ) { + throw new IllegalArgumentException( + Messages.format( Messages.MUST_NOT_BE_NULL, "url" ) ); + } + + return unmarshal( url.toExternalForm() ); + } + + public final Object unmarshal( File f ) throws JAXBException { + if( f == null ) { + throw new IllegalArgumentException( + Messages.format( Messages.MUST_NOT_BE_NULL, "file" ) ); + } + + try { + return unmarshal(new BufferedInputStream(new FileInputStream(f))); + } catch( FileNotFoundException e ) { + throw new IllegalArgumentException(e.getMessage()); + } + } + + public final Object unmarshal( java.io.InputStream is ) + throws JAXBException { + + if( is == null ) { + throw new IllegalArgumentException( + Messages.format( Messages.MUST_NOT_BE_NULL, "is" ) ); + } + + InputSource isrc = new InputSource( is ); + return unmarshal( isrc ); + } + + public final Object unmarshal( Reader reader ) throws JAXBException { + if( reader == null ) { + throw new IllegalArgumentException( + Messages.format( Messages.MUST_NOT_BE_NULL, "reader" ) ); + } + + InputSource isrc = new InputSource( reader ); + return unmarshal( isrc ); + } + + + private static InputSource streamSourceToInputSource( StreamSource ss ) { + InputSource is = new InputSource(); + is.setSystemId( ss.getSystemId() ); + is.setByteStream( ss.getInputStream() ); + is.setCharacterStream( ss.getReader() ); + + return is; + } + + + /** + * Indicates whether or not the Unmarshaller is configured to validate + * during unmarshal operations. + *

+ * Note: I named this method isValidating() to stay in-line + * with JAXP, as opposed to naming it getValidating(). + * + * @return true if the Unmarshaller is configured to validate during + * unmarshal operations, false otherwise + * @throws JAXBException if an error occurs while retrieving the validating + * flag + */ + public boolean isValidating() throws JAXBException { + return validating; + } + + /** + * Allow an application to register a validation event handler. + *

+ * The validation event handler will be called by the JAXB Provider if any + * validation errors are encountered during calls to any of the + * {@code unmarshal} methods. If the client application does not register + * a validation event handler before invoking the unmarshal methods, then + * all validation events will be silently ignored and may result in + * unexpected behaviour. + * + * @param handler the validation event handler + * @throws JAXBException if an error was encountered while setting the + * event handler + */ + public void setEventHandler(ValidationEventHandler handler) + throws JAXBException { + + if( handler == null ) { + eventHandler = new DefaultValidationEventHandler(); + } else { + eventHandler = handler; + } + } + + /** + * Specifies whether or not the Unmarshaller should validate during + * unmarshal operations. By default, the {@code Unmarshaller} does + * not validate. + *

+ * This method may only be invoked before or after calling one of the + * unmarshal methods. + * + * @param validating true if the Unmarshaller should validate during + * unmarshal, false otherwise + * @throws JAXBException if an error occurred while enabling or disabling + * validation at unmarshal time + */ + public void setValidating(boolean validating) throws JAXBException { + this.validating = validating; + } + + /** + * Return the current event handler or the default event handler if one + * hasn't been set. + * + * @return the current ValidationEventHandler or the default event handler + * if it hasn't been set + * @throws JAXBException if an error was encountered while getting the + * current event handler + */ + public ValidationEventHandler getEventHandler() throws JAXBException { + return eventHandler; + } + + + /** + * Creates an UnmarshalException from a SAXException. + * + * This is an utility method provided for the derived classes. + * + *

+ * When a provider-implemented ContentHandler wants to throw a + * JAXBException, it needs to wrap the exception by a SAXException. + * If the unmarshaller implementation blindly wrap SAXException + * by JAXBException, such an exception will be a JAXBException + * wrapped by a SAXException wrapped by another JAXBException. + * This is silly. + * + *

+ * This method checks the nested exception of SAXException + * and reduce those excessive wrapping. + * + * @return the resulting UnmarshalException + */ + protected UnmarshalException createUnmarshalException( SAXException e ) { + // check the nested exception to see if it's an UnmarshalException + Exception nested = e.getException(); + if(nested instanceof UnmarshalException) + return (UnmarshalException)nested; + + if(nested instanceof RuntimeException) + // typically this is an unexpected exception, + // just throw it rather than wrap it, so that the full stack + // trace can be displayed. + throw (RuntimeException)nested; + + + // otherwise simply wrap it + if(nested!=null) + return new UnmarshalException(nested); + else + return new UnmarshalException(e); + } + + /** + * Default implementation of the setProperty method always + * throws PropertyException since there are no required + * properties. If a provider needs to handle additional + * properties, it should override this method in a derived class. + */ + public void setProperty( String name, Object value ) + throws PropertyException { + + if( name == null ) { + throw new IllegalArgumentException( + Messages.format( Messages.MUST_NOT_BE_NULL, "name" ) ); + } + + throw new PropertyException(name, value); + } + + /** + * Default implementation of the getProperty method always + * throws PropertyException since there are no required + * properties. If a provider needs to handle additional + * properties, it should override this method in a derived class. + */ + public Object getProperty( String name ) + throws PropertyException { + + if( name == null ) { + throw new IllegalArgumentException( + Messages.format( Messages.MUST_NOT_BE_NULL, "name" ) ); + } + + throw new PropertyException(name); + } + + public Object unmarshal(XMLEventReader reader) throws JAXBException { + + throw new UnsupportedOperationException(); + } + + public Object unmarshal(XMLStreamReader reader) throws JAXBException { + + throw new UnsupportedOperationException(); + } + + public JAXBElement unmarshal(Node node, Class expectedType) throws JAXBException { + throw new UnsupportedOperationException(); + } + + public JAXBElement unmarshal(Source source, Class expectedType) throws JAXBException { + throw new UnsupportedOperationException(); + } + + public JAXBElement unmarshal(XMLStreamReader reader, Class expectedType) throws JAXBException { + throw new UnsupportedOperationException(); + } + + public JAXBElement unmarshal(XMLEventReader reader, Class expectedType) throws JAXBException { + throw new UnsupportedOperationException(); + } + + public void setSchema(Schema schema) { + throw new UnsupportedOperationException(); + } + + public Schema getSchema() { + throw new UnsupportedOperationException(); + } + + public void setAdapter(XmlAdapter adapter) { + if(adapter==null) + throw new IllegalArgumentException(); + setAdapter((Class)adapter.getClass(),adapter); + } + + public void setAdapter(Class type, A adapter) { + throw new UnsupportedOperationException(); + } + + public A getAdapter(Class type) { + throw new UnsupportedOperationException(); + } + + public void setAttachmentUnmarshaller(AttachmentUnmarshaller au) { + throw new UnsupportedOperationException(); + } + + public AttachmentUnmarshaller getAttachmentUnmarshaller() { + throw new UnsupportedOperationException(); + } + + public void setListener(Listener listener) { + throw new UnsupportedOperationException(); + } + + public Listener getListener() { + throw new UnsupportedOperationException(); + } +} diff --git a/fine-third-jdk11/src/javax/xml/bind/helpers/DefaultValidationEventHandler.java b/fine-third-jdk11/src/javax/xml/bind/helpers/DefaultValidationEventHandler.java new file mode 100644 index 000000000..a56b21cef --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/helpers/DefaultValidationEventHandler.java @@ -0,0 +1,147 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.helpers; + +import org.w3c.dom.Node; + +import javax.xml.bind.ValidationEvent; +import javax.xml.bind.ValidationEventHandler; +import javax.xml.bind.ValidationEventLocator; +import java.net.URL; + +/** + *

+ * JAXB 1.0 only default validation event handler. This is the default + * handler for all objects created from a JAXBContext that is managing + * schema-derived code generated by a JAXB 1.0 binding compiler. + * + *

+ * This handler causes the unmarshal and validate operations to fail on the first + * error or fatal error. + * + *

+ * This handler is not the default handler for JAXB mapped classes following + * JAXB 2.0 or later versions. Default validation event handling has changed + * and is specified in {@link javax.xml.bind.Unmarshaller} and + * {@link javax.xml.bind.Marshaller}. + * + * @author

+ * @see javax.xml.bind.Unmarshaller + * @see javax.xml.bind.Validator + * @see javax.xml.bind.ValidationEventHandler + * @since 1.6, JAXB 1.0 + */ +public class DefaultValidationEventHandler implements ValidationEventHandler { + + public boolean handleEvent( ValidationEvent event ) { + + if( event == null ) { + throw new IllegalArgumentException(); + } + + // calculate the severity prefix and return value + String severity = null; + boolean retVal = false; + switch ( event.getSeverity() ) { + case ValidationEvent.WARNING: + severity = Messages.format( Messages.WARNING ); + retVal = true; // continue after warnings + break; + case ValidationEvent.ERROR: + severity = Messages.format( Messages.ERROR ); + retVal = false; // terminate after errors + break; + case ValidationEvent.FATAL_ERROR: + severity = Messages.format( Messages.FATAL_ERROR ); + retVal = false; // terminate after fatal errors + break; + default: + assert false : + Messages.format( Messages.UNRECOGNIZED_SEVERITY, + event.getSeverity() ); + } + + // calculate the location message + String location = getLocation( event ); + + System.out.println( + Messages.format( Messages.SEVERITY_MESSAGE, + severity, + event.getMessage(), + location ) ); + + // fail on the first error or fatal error + return retVal; + } + + /** + * Calculate a location message for the event + * + */ + private String getLocation(ValidationEvent event) { + StringBuffer msg = new StringBuffer(); + + ValidationEventLocator locator = event.getLocator(); + + if( locator != null ) { + + URL url = locator.getURL(); + Object obj = locator.getObject(); + Node node = locator.getNode(); + int line = locator.getLineNumber(); + + if( url!=null || line!=-1 ) { + msg.append( "line " + line ); + if( url!=null ) + msg.append( " of " + url ); + } else if( obj != null ) { + msg.append( " obj: " + obj.toString() ); + } else if( node != null ) { + msg.append( " node: " + node.toString() ); + } + } else { + msg.append( Messages.format( Messages.LOCATION_UNAVAILABLE ) ); + } + + return msg.toString(); + } +} + diff --git a/fine-third-jdk11/src/javax/xml/bind/helpers/Messages.java b/fine-third-jdk11/src/javax/xml/bind/helpers/Messages.java new file mode 100644 index 000000000..1597fc1f5 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/helpers/Messages.java @@ -0,0 +1,112 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.helpers; + +import java.text.MessageFormat; +import java.util.ResourceBundle; + +/** + * Formats error messages. + */ +class Messages +{ + static String format( String property ) { + return format( property, null ); + } + + static String format( String property, Object arg1 ) { + return format( property, new Object[]{arg1} ); + } + + static String format( String property, Object arg1, Object arg2 ) { + return format( property, new Object[]{arg1,arg2} ); + } + + static String format( String property, Object arg1, Object arg2, Object arg3 ) { + return format( property, new Object[]{arg1,arg2,arg3} ); + } + + // add more if necessary. + + /** Loads a string resource and formats it with specified arguments. */ + static String format( String property, Object[] args ) { + String text = ResourceBundle.getBundle(Messages.class.getName()).getString(property); + return MessageFormat.format(text,args); + } + +// +// +// Message resources +// +// + static final String INPUTSTREAM_NOT_NULL = // 0 args + "AbstractUnmarshallerImpl.ISNotNull"; + + static final String MUST_BE_BOOLEAN = // 1 arg + "AbstractMarshallerImpl.MustBeBoolean"; + + static final String MUST_BE_STRING = // 1 arg + "AbstractMarshallerImpl.MustBeString"; + + static final String SEVERITY_MESSAGE = // 3 args + "DefaultValidationEventHandler.SeverityMessage"; + + static final String LOCATION_UNAVAILABLE = // 0 args + "DefaultValidationEventHandler.LocationUnavailable"; + + static final String UNRECOGNIZED_SEVERITY = // 1 arg + "DefaultValidationEventHandler.UnrecognizedSeverity"; + + static final String WARNING = // 0 args + "DefaultValidationEventHandler.Warning"; + + static final String ERROR = // 0 args + "DefaultValidationEventHandler.Error"; + + static final String FATAL_ERROR = // 0 args + "DefaultValidationEventHandler.FatalError"; + + static final String ILLEGAL_SEVERITY = // 0 args + "ValidationEventImpl.IllegalSeverity"; + + static final String MUST_NOT_BE_NULL = // 1 arg + "Shared.MustNotBeNull"; +} diff --git a/fine-third-jdk11/src/javax/xml/bind/helpers/NotIdentifiableEventImpl.java b/fine-third-jdk11/src/javax/xml/bind/helpers/NotIdentifiableEventImpl.java new file mode 100644 index 000000000..e0cf60492 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/helpers/NotIdentifiableEventImpl.java @@ -0,0 +1,100 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.helpers; + +import javax.xml.bind.ValidationEventLocator; + +/** + * Default implementation of the NotIdentifiableEvent interface. + * + *

+ * JAXB providers are allowed to use whatever class that implements + * the ValidationEvent interface. This class is just provided for a + * convenience. + * + * @author

  • Ryan Shoemaker, Sun Microsystems, Inc.
+ * @see javax.xml.bind.NotIdentifiableEvent + * @see javax.xml.bind.Validator + * @see javax.xml.bind.ValidationEventHandler + * @see javax.xml.bind.ValidationEvent + * @see javax.xml.bind.ValidationEventLocator + * @since 1.6, JAXB 1.0 + */ +public class NotIdentifiableEventImpl + extends ValidationEventImpl + implements javax.xml.bind.NotIdentifiableEvent { + + /** + * Create a new NotIdentifiableEventImpl. + * + * @param _severity The severity value for this event. Must be one of + * ValidationEvent.WARNING, ValidationEvent.ERROR, or + * ValidationEvent.FATAL_ERROR + * @param _message The text message for this event - may be null. + * @param _locator The locator object for this event - may be null. + * @throws IllegalArgumentException if an illegal severity field is supplied + */ + public NotIdentifiableEventImpl( int _severity, String _message, + ValidationEventLocator _locator) { + + super(_severity, _message, _locator); + } + + /** + * Create a new NotIdentifiableEventImpl. + * + * @param _severity The severity value for this event. Must be one of + * ValidationEvent.WARNING, ValidationEvent.ERROR, or + * ValidationEvent.FATAL_ERROR + * @param _message The text message for this event - may be null. + * @param _locator The locator object for this event - may be null. + * @param _linkedException An optional linked exception that may provide + * additional information about the event - may be null. + * @throws IllegalArgumentException if an illegal severity field is supplied + */ + public NotIdentifiableEventImpl( int _severity, String _message, + ValidationEventLocator _locator, + Throwable _linkedException) { + + super(_severity, _message, _locator, _linkedException); + } + +} diff --git a/fine-third-jdk11/src/javax/xml/bind/helpers/ParseConversionEventImpl.java b/fine-third-jdk11/src/javax/xml/bind/helpers/ParseConversionEventImpl.java new file mode 100644 index 000000000..3aabb897b --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/helpers/ParseConversionEventImpl.java @@ -0,0 +1,101 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.helpers; + +import javax.xml.bind.ParseConversionEvent; +import javax.xml.bind.ValidationEventLocator; + +/** + * Default implementation of the ParseConversionEvent interface. + * + *

+ * JAXB providers are allowed to use whatever class that implements + * the ValidationEvent interface. This class is just provided for a + * convenience. + * + * @author

  • Ryan Shoemaker, Sun Microsystems, Inc.
+ * @see javax.xml.bind.ParseConversionEvent + * @see javax.xml.bind.Validator + * @see javax.xml.bind.ValidationEventHandler + * @see javax.xml.bind.ValidationEvent + * @see javax.xml.bind.ValidationEventLocator + * @since 1.6, JAXB 1.0 + */ +public class ParseConversionEventImpl + extends ValidationEventImpl + implements ParseConversionEvent { + + /** + * Create a new ParseConversionEventImpl. + * + * @param _severity The severity value for this event. Must be one of + * ValidationEvent.WARNING, ValidationEvent.ERROR, or + * ValidationEvent.FATAL_ERROR + * @param _message The text message for this event - may be null. + * @param _locator The locator object for this event - may be null. + * @throws IllegalArgumentException if an illegal severity field is supplied + */ + public ParseConversionEventImpl( int _severity, String _message, + ValidationEventLocator _locator) { + + super(_severity, _message, _locator); + } + + /** + * Create a new ParseConversionEventImpl. + * + * @param _severity The severity value for this event. Must be one of + * ValidationEvent.WARNING, ValidationEvent.ERROR, or + * ValidationEvent.FATAL_ERROR + * @param _message The text message for this event - may be null. + * @param _locator The locator object for this event - may be null. + * @param _linkedException An optional linked exception that may provide + * additional information about the event - may be null. + * @throws IllegalArgumentException if an illegal severity field is supplied + */ + public ParseConversionEventImpl( int _severity, String _message, + ValidationEventLocator _locator, + Throwable _linkedException) { + + super(_severity, _message, _locator, _linkedException); + } + +} diff --git a/fine-third-jdk11/src/javax/xml/bind/helpers/PrintConversionEventImpl.java b/fine-third-jdk11/src/javax/xml/bind/helpers/PrintConversionEventImpl.java new file mode 100644 index 000000000..cdfe1b031 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/helpers/PrintConversionEventImpl.java @@ -0,0 +1,101 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.helpers; + +import javax.xml.bind.PrintConversionEvent; +import javax.xml.bind.ValidationEventLocator; + +/** + * Default implementation of the PrintConversionEvent interface. + * + *

+ * JAXB providers are allowed to use whatever class that implements + * the ValidationEvent interface. This class is just provided for a + * convenience. + * + * @author

  • Ryan Shoemaker, Sun Microsystems, Inc.
+ * @see javax.xml.bind.PrintConversionEvent + * @see javax.xml.bind.Validator + * @see javax.xml.bind.ValidationEventHandler + * @see javax.xml.bind.ValidationEvent + * @see javax.xml.bind.ValidationEventLocator + * @since 1.6, JAXB 1.0 + */ +public class PrintConversionEventImpl + extends ValidationEventImpl + implements PrintConversionEvent { + + /** + * Create a new PrintConversionEventImpl. + * + * @param _severity The severity value for this event. Must be one of + * ValidationEvent.WARNING, ValidationEvent.ERROR, or + * ValidationEvent.FATAL_ERROR + * @param _message The text message for this event - may be null. + * @param _locator The locator object for this event - may be null. + * @throws IllegalArgumentException if an illegal severity field is supplied + */ + public PrintConversionEventImpl( int _severity, String _message, + ValidationEventLocator _locator) { + + super(_severity, _message, _locator); + } + + /** + * Create a new PrintConversionEventImpl. + * + * @param _severity The severity value for this event. Must be one of + * ValidationEvent.WARNING, ValidationEvent.ERROR, or + * ValidationEvent.FATAL_ERROR + * @param _message The text message for this event - may be null. + * @param _locator The locator object for this event - may be null. + * @param _linkedException An optional linked exception that may provide + * additional information about the event - may be null. + * @throws IllegalArgumentException if an illegal severity field is supplied + */ + public PrintConversionEventImpl( int _severity, String _message, + ValidationEventLocator _locator, + Throwable _linkedException) { + + super(_severity, _message, _locator, _linkedException); + } + +} diff --git a/fine-third-jdk11/src/javax/xml/bind/helpers/ValidationEventImpl.java b/fine-third-jdk11/src/javax/xml/bind/helpers/ValidationEventImpl.java new file mode 100644 index 000000000..0b9605f27 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/helpers/ValidationEventImpl.java @@ -0,0 +1,190 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.helpers; + +import java.text.MessageFormat; + +import javax.xml.bind.ValidationEvent; +import javax.xml.bind.ValidationEventLocator; + +/** + * Default implementation of the ValidationEvent interface. + * + *

+ * JAXB providers are allowed to use whatever class that implements + * the ValidationEvent interface. This class is just provided for a + * convenience. + * + * @author

  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
+ * @see javax.xml.bind.Validator + * @see javax.xml.bind.ValidationEventHandler + * @see javax.xml.bind.ValidationEvent + * @see javax.xml.bind.ValidationEventLocator + * @since 1.6, JAXB 1.0 + */ +public class ValidationEventImpl implements ValidationEvent +{ + + /** + * Create a new ValidationEventImpl. + * + * @param _severity The severity value for this event. Must be one of + * ValidationEvent.WARNING, ValidationEvent.ERROR, or + * ValidationEvent.FATAL_ERROR + * @param _message The text message for this event - may be null. + * @param _locator The locator object for this event - may be null. + * @throws IllegalArgumentException if an illegal severity field is supplied + */ + public ValidationEventImpl( int _severity, String _message, + ValidationEventLocator _locator ) { + + this(_severity,_message,_locator,null); + } + + /** + * Create a new ValidationEventImpl. + * + * @param _severity The severity value for this event. Must be one of + * ValidationEvent.WARNING, ValidationEvent.ERROR, or + * ValidationEvent.FATAL_ERROR + * @param _message The text message for this event - may be null. + * @param _locator The locator object for this event - may be null. + * @param _linkedException An optional linked exception that may provide + * additional information about the event - may be null. + * @throws IllegalArgumentException if an illegal severity field is supplied + */ + public ValidationEventImpl( int _severity, String _message, + ValidationEventLocator _locator, + Throwable _linkedException ) { + + setSeverity( _severity ); + this.message = _message; + this.locator = _locator; + this.linkedException = _linkedException; + } + + private int severity; + private String message; + private Throwable linkedException; + private ValidationEventLocator locator; + + public int getSeverity() { + return severity; + } + + + /** + * Set the severity field of this event. + * + * @param _severity Must be one of ValidationEvent.WARNING, + * ValidationEvent.ERROR, or ValidationEvent.FATAL_ERROR. + * @throws IllegalArgumentException if an illegal severity field is supplied + */ + public void setSeverity( int _severity ) { + + if( _severity != ValidationEvent.WARNING && + _severity != ValidationEvent.ERROR && + _severity != ValidationEvent.FATAL_ERROR ) { + throw new IllegalArgumentException( + Messages.format( Messages.ILLEGAL_SEVERITY ) ); + } + + this.severity = _severity; + } + + public String getMessage() { + return message; + } + /** + * Set the message field of this event. + * + * @param _message String message - may be null. + */ + public void setMessage( String _message ) { + this.message = _message; + } + + public Throwable getLinkedException() { + return linkedException; + } + /** + * Set the linked exception field of this event. + * + * @param _linkedException Optional linked exception - may be null. + */ + public void setLinkedException( Throwable _linkedException ) { + this.linkedException = _linkedException; + } + + public ValidationEventLocator getLocator() { + return locator; + } + /** + * Set the locator object for this event. + * + * @param _locator The locator - may be null. + */ + public void setLocator( ValidationEventLocator _locator ) { + this.locator = _locator; + } + + /** + * Returns a string representation of this object in a format + * helpful to debugging. + * + * @see Object#equals(Object) + */ + public String toString() { + String s; + switch(getSeverity()) { + case WARNING: s="WARNING";break; + case ERROR: s="ERROR";break; + case FATAL_ERROR: s="FATAL_ERROR";break; + default: s=String.valueOf(getSeverity());break; + } + return MessageFormat.format("[severity={0},message={1},locator={2}]", + new Object[]{ + s, + getMessage(), + getLocator() + }); + } +} diff --git a/fine-third-jdk11/src/javax/xml/bind/helpers/ValidationEventLocatorImpl.java b/fine-third-jdk11/src/javax/xml/bind/helpers/ValidationEventLocatorImpl.java new file mode 100644 index 000000000..20aabe12c --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/helpers/ValidationEventLocatorImpl.java @@ -0,0 +1,288 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.helpers; + +import java.net.URL; +import java.net.MalformedURLException; +import java.text.MessageFormat; + +import javax.xml.bind.ValidationEventLocator; +import org.w3c.dom.Node; +import org.xml.sax.Locator; +import org.xml.sax.SAXParseException; + +/** + * Default implementation of the ValidationEventLocator interface. + * + *

+ * JAXB providers are allowed to use whatever class that implements + * the ValidationEventLocator interface. This class is just provided for a + * convenience. + * + * @author

  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
+ * @see javax.xml.bind.Validator + * @see javax.xml.bind.ValidationEventHandler + * @see javax.xml.bind.ValidationEvent + * @see javax.xml.bind.ValidationEventLocator + * @since 1.6, JAXB 1.0 + */ +public class ValidationEventLocatorImpl implements ValidationEventLocator +{ + /** + * Creates an object with all fields unavailable. + */ + public ValidationEventLocatorImpl() { + } + + /** + * Constructs an object from an org.xml.sax.Locator. + * + * The object's ColumnNumber, LineNumber, and URL become available from the + * values returned by the locator's getColumnNumber(), getLineNumber(), and + * getSystemId() methods respectively. Node, Object, and Offset are not + * available. + * + * @param loc the SAX Locator object that will be used to populate this + * event locator. + * @throws IllegalArgumentException if the Locator is null + */ + public ValidationEventLocatorImpl( Locator loc ) { + if( loc == null ) { + throw new IllegalArgumentException( + Messages.format( Messages.MUST_NOT_BE_NULL, "loc" ) ); + } + + this.url = toURL(loc.getSystemId()); + this.columnNumber = loc.getColumnNumber(); + this.lineNumber = loc.getLineNumber(); + } + + /** + * Constructs an object from the location information of a SAXParseException. + * + * The object's ColumnNumber, LineNumber, and URL become available from the + * values returned by the locator's getColumnNumber(), getLineNumber(), and + * getSystemId() methods respectively. Node, Object, and Offset are not + * available. + * + * @param e the SAXParseException object that will be used to populate this + * event locator. + * @throws IllegalArgumentException if the SAXParseException is null + */ + public ValidationEventLocatorImpl( SAXParseException e ) { + if( e == null ) { + throw new IllegalArgumentException( + Messages.format( Messages.MUST_NOT_BE_NULL, "e" ) ); + } + + this.url = toURL(e.getSystemId()); + this.columnNumber = e.getColumnNumber(); + this.lineNumber = e.getLineNumber(); + } + + /** + * Constructs an object that points to a DOM Node. + * + * The object's Node becomes available. ColumnNumber, LineNumber, Object, + * Offset, and URL are not available. + * + * @param _node the DOM Node object that will be used to populate this + * event locator. + * @throws IllegalArgumentException if the Node is null + */ + public ValidationEventLocatorImpl(Node _node) { + if( _node == null ) { + throw new IllegalArgumentException( + Messages.format( Messages.MUST_NOT_BE_NULL, "_node" ) ); + } + + this.node = _node; + } + + /** + * Constructs an object that points to a JAXB content object. + * + * The object's Object becomes available. ColumnNumber, LineNumber, Node, + * Offset, and URL are not available. + * + * @param _object the Object that will be used to populate this + * event locator. + * @throws IllegalArgumentException if the Object is null + */ + public ValidationEventLocatorImpl(Object _object) { + if( _object == null ) { + throw new IllegalArgumentException( + Messages.format( Messages.MUST_NOT_BE_NULL, "_object" ) ); + } + + this.object = _object; + } + + /** Converts a system ID to an URL object. */ + private static URL toURL( String systemId ) { + try { + return new URL(systemId); + } catch( MalformedURLException e ) { + // TODO: how should we handle system id here? + return null; // for now + } + } + + private URL url = null; + private int offset = -1; + private int lineNumber = -1; + private int columnNumber = -1; + private Object object = null; + private Node node = null; + + + /** + * @see javax.xml.bind.ValidationEventLocator#getURL() + */ + public URL getURL() { + return url; + } + + /** + * Set the URL field on this event locator. Null values are allowed. + * + * @param _url the url + */ + public void setURL( URL _url ) { + this.url = _url; + } + + /** + * @see javax.xml.bind.ValidationEventLocator#getOffset() + */ + public int getOffset() { + return offset; + } + + /** + * Set the offset field on this event locator. + * + * @param _offset the offset + */ + public void setOffset( int _offset ) { + this.offset = _offset; + } + + /** + * @see javax.xml.bind.ValidationEventLocator#getLineNumber() + */ + public int getLineNumber() { + return lineNumber; + } + + /** + * Set the lineNumber field on this event locator. + * + * @param _lineNumber the line number + */ + public void setLineNumber( int _lineNumber ) { + this.lineNumber = _lineNumber; + } + + /** + * @see javax.xml.bind.ValidationEventLocator#getColumnNumber() + */ + public int getColumnNumber() { + return columnNumber; + } + + /** + * Set the columnNumber field on this event locator. + * + * @param _columnNumber the column number + */ + public void setColumnNumber( int _columnNumber ) { + this.columnNumber = _columnNumber; + } + + /** + * @see javax.xml.bind.ValidationEventLocator#getObject() + */ + public Object getObject() { + return object; + } + + /** + * Set the Object field on this event locator. Null values are allowed. + * + * @param _object the java content object + */ + public void setObject( Object _object ) { + this.object = _object; + } + + /** + * @see javax.xml.bind.ValidationEventLocator#getNode() + */ + public Node getNode() { + return node; + } + + /** + * Set the Node field on this event locator. Null values are allowed. + * + * @param _node the Node + */ + public void setNode( Node _node ) { + this.node = _node; + } + + /** + * Returns a string representation of this object in a format + * helpful to debugging. + * + * @see Object#equals(Object) + */ + public String toString() { + return MessageFormat.format("[node={0},object={1},url={2},line={3},col={4},offset={5}]", + getNode(), + getObject(), + getURL(), + String.valueOf(getLineNumber()), + String.valueOf(getColumnNumber()), + String.valueOf(getOffset())); + } +} diff --git a/fine-third-jdk11/src/javax/xml/bind/helpers/package-info.java b/fine-third-jdk11/src/javax/xml/bind/helpers/package-info.java new file mode 100644 index 000000000..49f595381 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/helpers/package-info.java @@ -0,0 +1,65 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +/** + * JAXB Provider Use Only: Provides partial default implementations for + * some of the javax.xml.bind interfaces. + * + *

+ * JAXB Providers can extend these classes and implement the abstract + * methods. + * + *

Package Specification

+ * + *
+ * + *

Related Documentation

+ *

+ * For overviews, tutorials, examples, guides, and tool documentation, + * please see: + *

+ * + * @see JAXB Website + */ +package javax.xml.bind.helpers; diff --git a/fine-third-jdk11/src/javax/xml/bind/package-info.java b/fine-third-jdk11/src/javax/xml/bind/package-info.java new file mode 100644 index 000000000..2d90f9627 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/package-info.java @@ -0,0 +1,66 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +/** + * Provides a runtime binding framework for client applications including + * unmarshalling, marshalling, and validation capabilities. + *

+ *

+ * JAXBContext is the client-entry point to the runtime binding + * framework. + *

+ *

+ *

Package Specification

+ *

+ *

+ *

+ *

Related Documentation

+ *

+ * For overviews, tutorials, examples, guides, and tool documentation, + * please see: + *

+ * + * @see JAXB Website + */ +package javax.xml.bind; \ No newline at end of file diff --git a/fine-third-jdk11/src/javax/xml/bind/util/JAXBResult.java b/fine-third-jdk11/src/javax/xml/bind/util/JAXBResult.java new file mode 100644 index 000000000..1c6063db4 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/util/JAXBResult.java @@ -0,0 +1,166 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.util; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import javax.xml.bind.UnmarshallerHandler; +import javax.xml.transform.sax.SAXResult; + +/** + * JAXP {@link javax.xml.transform.Result} implementation + * that unmarshals a JAXB object. + * + *

+ * This utility class is useful to combine JAXB with + * other Java/XML technologies. + * + *

+ * The following example shows how to use JAXB to unmarshal a document + * resulting from an XSLT transformation. + * + *

+ *
+ *       JAXBResult result = new JAXBResult(
+ *         JAXBContext.newInstance("org.acme.foo") );
+ *       
+ *       // set up XSLT transformation
+ *       TransformerFactory tf = TransformerFactory.newInstance();
+ *       Transformer t = tf.newTransformer(new StreamSource("test.xsl"));
+ *       
+ *       // run transformation
+ *       t.transform(new StreamSource("document.xml"),result);
+ * 
+ *       // obtain the unmarshalled content tree
+ *       Object o = result.getResult();
+ *    
+ *
+ * + *

+ * The fact that JAXBResult derives from SAXResult is an implementation + * detail. Thus in general applications are strongly discouraged from + * accessing methods defined on SAXResult. + * + *

+ * In particular it shall never attempt to call the setHandler, + * setLexicalHandler, and setSystemId methods. + * + * @author + * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) + * @since 1.6 + */ +public class JAXBResult extends SAXResult { + + /** + * Creates a new instance that uses the specified + * JAXBContext to unmarshal. + * + * @param context The JAXBContext that will be used to create the + * necessary Unmarshaller. This parameter must not be null. + * @exception JAXBException if an error is encountered while creating the + * JAXBResult or if the context parameter is null. + */ + public JAXBResult( JAXBContext context ) throws JAXBException { + this( ( context == null ) ? assertionFailed() : context.createUnmarshaller() ); + } + + /** + * Creates a new instance that uses the specified + * Unmarshaller to unmarshal an object. + * + *

+ * This JAXBResult object will use the specified Unmarshaller + * instance. It is the caller's responsibility not to use the + * same Unmarshaller for other purposes while it is being + * used by this object. + * + *

+ * The primary purpose of this method is to allow the client + * to configure Unmarshaller. Unless you know what you are doing, + * it's easier and safer to pass a JAXBContext. + * + * @param _unmarshaller the unmarshaller. This parameter must not be null. + * @throws JAXBException if an error is encountered while creating the + * JAXBResult or the Unmarshaller parameter is null. + */ + public JAXBResult( Unmarshaller _unmarshaller ) throws JAXBException { + if( _unmarshaller == null ) + throw new JAXBException( + Messages.format( Messages.RESULT_NULL_UNMARSHALLER ) ); + + this.unmarshallerHandler = _unmarshaller.getUnmarshallerHandler(); + + super.setHandler(unmarshallerHandler); + } + + /** + * Unmarshaller that will be used to unmarshal + * the input documents. + */ + private final UnmarshallerHandler unmarshallerHandler; + + /** + * Gets the unmarshalled object created by the transformation. + * + * @return + * Always return a non-null object. + * + * @exception IllegalStateException + * if this method is called before an object is unmarshalled. + * + * @exception JAXBException + * if there is any unmarshalling error. + * Note that the implementation is allowed to throw SAXException + * during the parsing when it finds an error. + */ + public Object getResult() throws JAXBException { + return unmarshallerHandler.getResult(); + } + + /** + * Hook to throw exception from the middle of a contructor chained call + * to this + */ + private static Unmarshaller assertionFailed() throws JAXBException { + throw new JAXBException( Messages.format( Messages.RESULT_NULL_CONTEXT ) ); + } +} diff --git a/fine-third-jdk11/src/javax/xml/bind/util/JAXBSource.java b/fine-third-jdk11/src/javax/xml/bind/util/JAXBSource.java new file mode 100644 index 000000000..c6f9eb2bc --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/util/JAXBSource.java @@ -0,0 +1,288 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.util; + +import org.xml.sax.ContentHandler; +import org.xml.sax.DTDHandler; +import org.xml.sax.EntityResolver; +import org.xml.sax.ErrorHandler; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.SAXParseException; +import org.xml.sax.XMLReader; +import org.xml.sax.ext.LexicalHandler; +import org.xml.sax.helpers.XMLFilterImpl; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.transform.sax.SAXSource; +import org.xml.sax.XMLFilter; + +/** + * JAXP {@link javax.xml.transform.Source} implementation + * that marshals a JAXB-generated object. + * + *

+ * This utility class is useful to combine JAXB with + * other Java/XML technologies. + * + *

+ * The following example shows how to use JAXB to marshal a document + * for transformation by XSLT. + * + *

+ *
+ *       MyObject o = // get JAXB content tree
+ *       
+ *       // jaxbContext is a JAXBContext object from which 'o' is created.
+ *       JAXBSource source = new JAXBSource( jaxbContext, o );
+ *       
+ *       // set up XSLT transformation
+ *       TransformerFactory tf = TransformerFactory.newInstance();
+ *       Transformer t = tf.newTransformer(new StreamSource("test.xsl"));
+ *       
+ *       // run transformation
+ *       t.transform(source,new StreamResult(System.out));
+ *    
+ *
+ * + *

+ * The fact that JAXBSource derives from SAXSource is an implementation + * detail. Thus in general applications are strongly discouraged from + * accessing methods defined on SAXSource. In particular, + * the setXMLReader and setInputSource methods shall never be called. + * The XMLReader object obtained by the getXMLReader method shall + * be used only for parsing the InputSource object returned by + * the getInputSource method. + * + *

+ * Similarly the InputSource object obtained by the getInputSource + * method shall be used only for being parsed by the XMLReader object + * returned by the getXMLReader. + * + * @author + * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) + * @since 1.6 + */ +public class JAXBSource extends SAXSource { + + /** + * Creates a new {@link javax.xml.transform.Source} for the given content object. + * + * @param context + * JAXBContext that was used to create + * contentObject. This context is used + * to create a new instance of marshaller and must not be null. + * @param contentObject + * An instance of a JAXB-generated class, which will be + * used as a {@link javax.xml.transform.Source} (by marshalling it into XML). It must + * not be null. + * @throws JAXBException if an error is encountered while creating the + * JAXBSource or if either of the parameters are null. + */ + public JAXBSource( JAXBContext context, Object contentObject ) + throws JAXBException { + + this( + ( context == null ) ? + assertionFailed( Messages.format( Messages.SOURCE_NULL_CONTEXT ) ) : + context.createMarshaller(), + + ( contentObject == null ) ? + assertionFailed( Messages.format( Messages.SOURCE_NULL_CONTENT ) ) : + contentObject); + } + + /** + * Creates a new {@link javax.xml.transform.Source} for the given content object. + * + * @param marshaller + * A marshaller instance that will be used to marshal + * contentObject into XML. This must be + * created from a JAXBContext that was used to build + * contentObject and must not be null. + * @param contentObject + * An instance of a JAXB-generated class, which will be + * used as a {@link javax.xml.transform.Source} (by marshalling it into XML). It must + * not be null. + * @throws JAXBException if an error is encountered while creating the + * JAXBSource or if either of the parameters are null. + */ + public JAXBSource( Marshaller marshaller, Object contentObject ) + throws JAXBException { + + if( marshaller == null ) + throw new JAXBException( + Messages.format( Messages.SOURCE_NULL_MARSHALLER ) ); + + if( contentObject == null ) + throw new JAXBException( + Messages.format( Messages.SOURCE_NULL_CONTENT ) ); + + this.marshaller = marshaller; + this.contentObject = contentObject; + + super.setXMLReader(pseudoParser); + // pass a dummy InputSource. We don't care + super.setInputSource(new InputSource()); + } + + private final Marshaller marshaller; + private final Object contentObject; + + // this object will pretend as an XMLReader. + // no matter what parameter is specified to the parse method, + // it just parse the contentObject. + private final XMLReader pseudoParser = new XMLReader() { + public boolean getFeature(String name) throws SAXNotRecognizedException { + if(name.equals("http://xml.org/sax/features/namespaces")) + return true; + if(name.equals("http://xml.org/sax/features/namespace-prefixes")) + return false; + throw new SAXNotRecognizedException(name); + } + + public void setFeature(String name, boolean value) throws SAXNotRecognizedException { + if(name.equals("http://xml.org/sax/features/namespaces") && value) + return; + if(name.equals("http://xml.org/sax/features/namespace-prefixes") && !value) + return; + throw new SAXNotRecognizedException(name); + } + + public Object getProperty(String name) throws SAXNotRecognizedException { + if( "http://xml.org/sax/properties/lexical-handler".equals(name) ) { + return lexicalHandler; + } + throw new SAXNotRecognizedException(name); + } + + public void setProperty(String name, Object value) throws SAXNotRecognizedException { + if( "http://xml.org/sax/properties/lexical-handler".equals(name) ) { + this.lexicalHandler = (LexicalHandler)value; + return; + } + throw new SAXNotRecognizedException(name); + } + + private LexicalHandler lexicalHandler; + + // we will store this value but never use it by ourselves. + private EntityResolver entityResolver; + public void setEntityResolver(EntityResolver resolver) { + this.entityResolver = resolver; + } + public EntityResolver getEntityResolver() { + return entityResolver; + } + + private DTDHandler dtdHandler; + public void setDTDHandler(DTDHandler handler) { + this.dtdHandler = handler; + } + public DTDHandler getDTDHandler() { + return dtdHandler; + } + + // SAX allows ContentHandler to be changed during the parsing, + // but JAXB doesn't. So this repeater will sit between those + // two components. + private XMLFilter repeater = new XMLFilterImpl(); + + public void setContentHandler(ContentHandler handler) { + repeater.setContentHandler(handler); + } + public ContentHandler getContentHandler() { + return repeater.getContentHandler(); + } + + private ErrorHandler errorHandler; + public void setErrorHandler(ErrorHandler handler) { + this.errorHandler = handler; + } + public ErrorHandler getErrorHandler() { + return errorHandler; + } + + public void parse(InputSource input) throws SAXException { + parse(); + } + + public void parse(String systemId) throws SAXException { + parse(); + } + + public void parse() throws SAXException { + // parses a content object by using the given marshaller + // SAX events will be sent to the repeater, and the repeater + // will further forward it to an appropriate component. + try { + marshaller.marshal( contentObject, (XMLFilterImpl)repeater ); + } catch( JAXBException e ) { + // wrap it to a SAXException + SAXParseException se = + new SAXParseException( e.getMessage(), + null, null, -1, -1, e ); + + // if the consumer sets an error handler, it is our responsibility + // to notify it. + if(errorHandler!=null) + errorHandler.fatalError(se); + + // this is a fatal error. Even if the error handler + // returns, we will abort anyway. + throw se; + } + } + }; + + /** + * Hook to throw exception from the middle of a contructor chained call + * to this + */ + private static Marshaller assertionFailed( String message ) + throws JAXBException { + + throw new JAXBException( message ); + } +} diff --git a/fine-third-jdk11/src/javax/xml/bind/util/Messages.java b/fine-third-jdk11/src/javax/xml/bind/util/Messages.java new file mode 100644 index 000000000..aca02bde3 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/util/Messages.java @@ -0,0 +1,98 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.util; + +import java.text.MessageFormat; +import java.util.ResourceBundle; + +/** + * Formats error messages. + */ +class Messages +{ + static String format( String property ) { + return format( property, null ); + } + + static String format( String property, Object arg1 ) { + return format( property, new Object[]{arg1} ); + } + + static String format( String property, Object arg1, Object arg2 ) { + return format( property, new Object[]{arg1,arg2} ); + } + + static String format( String property, Object arg1, Object arg2, Object arg3 ) { + return format( property, new Object[]{arg1,arg2,arg3} ); + } + + // add more if necessary. + + /** Loads a string resource and formats it with specified arguments. */ + static String format( String property, Object[] args ) { + String text = ResourceBundle.getBundle(Messages.class.getName()).getString(property); + return MessageFormat.format(text,args); + } + +// +// +// Message resources +// +// + static final String UNRECOGNIZED_SEVERITY = // 1 arg + "ValidationEventCollector.UnrecognizedSeverity"; + + static final String RESULT_NULL_CONTEXT = // 0 args + "JAXBResult.NullContext"; + + static final String RESULT_NULL_UNMARSHALLER = // 0 arg + "JAXBResult.NullUnmarshaller"; + + static final String SOURCE_NULL_CONTEXT = // 0 args + "JAXBSource.NullContext"; + + static final String SOURCE_NULL_CONTENT = // 0 arg + "JAXBSource.NullContent"; + + static final String SOURCE_NULL_MARSHALLER = // 0 arg + "JAXBSource.NullMarshaller"; + +} diff --git a/fine-third-jdk11/src/javax/xml/bind/util/ValidationEventCollector.java b/fine-third-jdk11/src/javax/xml/bind/util/ValidationEventCollector.java new file mode 100644 index 000000000..07fe60431 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/util/ValidationEventCollector.java @@ -0,0 +1,128 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.bind.util; + +import javax.xml.bind.ValidationEvent; +import javax.xml.bind.ValidationEventHandler; +import java.util.ArrayList; +import java.util.List; + +/** + * {@link javax.xml.bind.ValidationEventHandler ValidationEventHandler} + * implementation that collects all events. + * + *

+ * To use this class, create a new instance and pass it to the setEventHandler + * method of the Validator, Unmarshaller, Marshaller class. After the call to + * validate or unmarshal completes, call the getEvents method to retrieve all + * the reported errors and warnings. + * + * @author

  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • Ryan Shoemaker, Sun Microsystems, Inc.
  • Joe Fialli, Sun Microsystems, Inc.
+ * @see javax.xml.bind.Validator + * @see javax.xml.bind.ValidationEventHandler + * @see javax.xml.bind.ValidationEvent + * @see javax.xml.bind.ValidationEventLocator + * @since 1.6, JAXB 1.0 + */ +public class ValidationEventCollector implements ValidationEventHandler +{ + private final List events = new ArrayList(); + + /** + * Return an array of ValidationEvent objects containing a copy of each of + * the collected errors and warnings. + * + * @return + * a copy of all the collected errors and warnings or an empty array + * if there weren't any + */ + public ValidationEvent[] getEvents() { + return events.toArray(new ValidationEvent[events.size()]); + } + + /** + * Clear all collected errors and warnings. + */ + public void reset() { + events.clear(); + } + + /** + * Returns true if this event collector contains at least one + * ValidationEvent. + * + * @return true if this event collector contains at least one + * ValidationEvent, false otherwise + */ + public boolean hasEvents() { + return !events.isEmpty(); + } + + public boolean handleEvent( ValidationEvent event ) { + events.add(event); + + boolean retVal = true; + switch( event.getSeverity() ) { + case ValidationEvent.WARNING: + retVal = true; // continue validation + break; + case ValidationEvent.ERROR: + retVal = true; // continue validation + break; + case ValidationEvent.FATAL_ERROR: + retVal = false; // halt validation + break; + default: + _assert( false, + Messages.format( Messages.UNRECOGNIZED_SEVERITY, + event.getSeverity() ) ); + break; + } + + return retVal; + } + + private static void _assert( boolean b, String msg ) { + if( !b ) { + throw new InternalError( msg ); + } + } +} diff --git a/fine-third-jdk11/src/javax/xml/bind/util/package-info.java b/fine-third-jdk11/src/javax/xml/bind/util/package-info.java new file mode 100644 index 000000000..9a056bed7 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/bind/util/package-info.java @@ -0,0 +1,60 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2003-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +/** + * Useful client utility classes. + * + *

Package Specification

+ * + * + * + *

Related Documentation

+ *

+ * For overviews, tutorials, examples, guides, and tool documentation, + * please see: + *

+ * + * @see JAXB Website + */ +package javax.xml.bind.util; diff --git a/fine-third-jdk11/src/javax/xml/soap/AttachmentPart.java b/fine-third-jdk11/src/javax/xml/soap/AttachmentPart.java new file mode 100644 index 000000000..df449298f --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/AttachmentPart.java @@ -0,0 +1,541 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +import java.io.InputStream; +import java.util.Iterator; + +import javax.activation.DataHandler; + +/** + * A single attachment to a {@code SOAPMessage} object. A {@code SOAPMessage} + * object may contain zero, one, or many {@code AttachmentPart} objects. + * Each {@code AttachmentPart} object consists of two parts, + * application-specific content and associated MIME headers. The + * MIME headers consists of name/value pairs that can be used to + * identify and describe the content. + *

+ * An {@code AttachmentPart} object must conform to certain standards. + *

    + *
  1. It must conform to + * MIME [RFC2045] standards + *
  2. It MUST contain content + *
  3. The header portion MUST include the following header: + *
      + *
    • {@code Content-Type}
      + * This header identifies the type of data in the content of an + * {@code AttachmentPart} object and MUST conform to [RFC2045]. + * The following is an example of a Content-Type header: + *
      + *       Content-Type:  application/xml
      + *       
      + * The following line of code, in which {@code ap} is an + * {@code AttachmentPart} object, sets the header shown in + * the previous example. + *
      + *       ap.setMimeHeader("Content-Type", "application/xml");
      + *       
      + *
    + *
+ *

+ * There are no restrictions on the content portion of an {@code + * AttachmentPart} object. The content may be anything from a + * simple plain text object to a complex XML document or image file. + * + *

+ * An {@code AttachmentPart} object is created with the method + * {@code SOAPMessage.createAttachmentPart}. After setting its MIME headers, + * the {@code AttachmentPart} object is added to the message + * that created it with the method {@code SOAPMessage.addAttachmentPart}. + * + *

+ * The following code fragment, in which {@code m} is a + * {@code SOAPMessage} object and {@code contentStringl} is a + * {@code String}, creates an instance of {@code AttachmentPart}, + * sets the {@code AttachmentPart} object with some content and + * header information, and adds the {@code AttachmentPart} object to + * the {@code SOAPMessage} object. + *

+ *     AttachmentPart ap1 = m.createAttachmentPart();
+ *     ap1.setContent(contentString1, "text/plain");
+ *     m.addAttachmentPart(ap1);
+ * 
+ * + * + *

+ * The following code fragment creates and adds a second + * {@code AttachmentPart} instance to the same message. {@code jpegData} + * is a binary byte buffer representing the jpeg file. + *

+ *     AttachmentPart ap2 = m.createAttachmentPart();
+ *     byte[] jpegData =  ...;
+ *     ap2.setContent(new ByteArrayInputStream(jpegData), "image/jpeg");
+ *     m.addAttachmentPart(ap2);
+ * 
+ *

+ * The {@code getContent} method retrieves the contents and header from + * an {@code AttachmentPart} object. Depending on the + * {@code DataContentHandler} objects present, the returned + * {@code Object} can either be a typed Java object corresponding + * to the MIME type or an {@code InputStream} object that contains the + * content as bytes. + *

+ *     String content1 = ap1.getContent();
+ *     java.io.InputStream content2 = ap2.getContent();
+ * 
+ * + * The method {@code clearContent} removes all the content from an + * {@code AttachmentPart} object but does not affect its header information. + *
+ *     ap1.clearContent();
+ * 
+ * + * @since 1.6 + */ + +public abstract class AttachmentPart { + /** + * Returns the number of bytes in this {@code AttachmentPart} + * object. + * + * @return the size of this {@code AttachmentPart} object in bytes + * or -1 if the size cannot be determined + * @exception SOAPException if the content of this attachment is + * corrupted of if there was an exception while trying + * to determine the size. + */ + public abstract int getSize() throws SOAPException; + + /** + * Clears out the content of this {@code AttachmentPart} object. + * The MIME header portion is left untouched. + */ + public abstract void clearContent(); + + /** + * Gets the content of this {@code AttachmentPart} object as a Java + * object. The type of the returned Java object depends on (1) the + * {@code DataContentHandler} object that is used to interpret the bytes + * and (2) the {@code Content-Type} given in the header. + *

+ * For the MIME content types "text/plain", "text/html" and "text/xml", the + * {@code DataContentHandler} object does the conversions to and + * from the Java types corresponding to the MIME types. + * For other MIME types,the {@code DataContentHandler} object + * can return an {@code InputStream} object that contains the content data + * as raw bytes. + *

+ * A SAAJ-compliant implementation must, as a minimum, return a + * {@code java.lang.String} object corresponding to any content + * stream with a {@code Content-Type} value of + * {@code text/plain}, a + * {@code javax.xml.transform.stream.StreamSource} object corresponding to a + * content stream with a {@code Content-Type} value of + * {@code text/xml}, a {@code java.awt.Image} object + * corresponding to a content stream with a + * {@code Content-Type} value of {@code image/gif} or + * {@code image/jpeg}. For those content types that an + * installed {@code DataContentHandler} object does not understand, the + * {@code DataContentHandler} object is required to return a + * {@code java.io.InputStream} object with the raw bytes. + * + * @return a Java object with the content of this {@code AttachmentPart} + * object + * + * @exception SOAPException if there is no content set into this + * {@code AttachmentPart} object or if there was a data + * transformation error + */ + public abstract Object getContent() throws SOAPException; + + /** + * Gets the content of this {@code AttachmentPart} object as an + * InputStream as if a call had been made to {@code getContent} and no + * {@code DataContentHandler} had been registered for the + * {@code content-type} of this {@code AttachmentPart}. + *

+ * Note that reading from the returned InputStream would result in consuming + * the data in the stream. It is the responsibility of the caller to reset + * the InputStream appropriately before calling a Subsequent API. If a copy + * of the raw attachment content is required then the {@link #getRawContentBytes} API + * should be used instead. + * + * @return an {@code InputStream} from which the raw data contained by + * the {@code AttachmentPart} can be accessed. + * + * @throws SOAPException if there is no content set into this + * {@code AttachmentPart} object or if there was a data + * transformation error. + * + * @since 1.6, SAAJ 1.3 + * @see #getRawContentBytes + */ + public abstract InputStream getRawContent() throws SOAPException; + + /** + * Gets the content of this {@code AttachmentPart} object as a + * byte[] array as if a call had been made to {@code getContent} and no + * {@code DataContentHandler} had been registered for the + * {@code content-type} of this {@code AttachmentPart}. + * + * @return a {@code byte[]} array containing the raw data of the + * {@code AttachmentPart}. + * + * @throws SOAPException if there is no content set into this + * {@code AttachmentPart} object or if there was a data + * transformation error. + * + * @since 1.6, SAAJ 1.3 + */ + public abstract byte[] getRawContentBytes() throws SOAPException; + + /** + * Returns an {@code InputStream} which can be used to obtain the + * content of {@code AttachmentPart} as Base64 encoded + * character data, this method would base64 encode the raw bytes + * of the attachment and return. + * + * @return an {@code InputStream} from which the Base64 encoded + * {@code AttachmentPart} can be read. + * + * @throws SOAPException if there is no content set into this + * {@code AttachmentPart} object or if there was a data + * transformation error. + * + * @since 1.6, SAAJ 1.3 + */ + public abstract InputStream getBase64Content() throws SOAPException; + + /** + * Sets the content of this attachment part to that of the given + * {@code Object} and sets the value of the {@code Content-Type} + * header to the given type. The type of the + * {@code Object} should correspond to the value given for the + * {@code Content-Type}. This depends on the particular + * set of {@code DataContentHandler} objects in use. + * + * + * @param object the Java object that makes up the content for + * this attachment part + * @param contentType the MIME string that specifies the type of + * the content + * + * @exception IllegalArgumentException may be thrown if the contentType + * does not match the type of the content object, or if there + * was no {@code DataContentHandler} object for this + * content object + * + * @see #getContent + */ + public abstract void setContent(Object object, String contentType); + + /** + * Sets the content of this attachment part to that contained by the + * {@code InputStream} {@code content} and sets the value of the + * {@code Content-Type} header to the value contained in + * {@code contentType}. + *

+ * A subsequent call to getSize() may not be an exact measure + * of the content size. + * + * @param content the raw data to add to the attachment part + * @param contentType the value to set into the {@code Content-Type} + * header + * + * @exception SOAPException if an there is an error in setting the content + * @exception NullPointerException if {@code content} is null + * @since 1.6, SAAJ 1.3 + */ + public abstract void setRawContent(InputStream content, String contentType) throws SOAPException; + + /** + * Sets the content of this attachment part to that contained by the + * {@code byte[]} array {@code content} and sets the value of the + * {@code Content-Type} header to the value contained in + * {@code contentType}. + * + * @param content the raw data to add to the attachment part + * @param contentType the value to set into the {@code Content-Type} + * header + * @param offset the offset in the byte array of the content + * @param len the number of bytes that form the content + * + * @exception SOAPException if an there is an error in setting the content + * or content is null + * @since 1.6, SAAJ 1.3 + */ + public abstract void setRawContentBytes( + byte[] content, int offset, int len, String contentType) + throws SOAPException; + + + /** + * Sets the content of this attachment part from the Base64 source + * {@code InputStream} and sets the value of the + * {@code Content-Type} header to the value contained in + * {@code contentType}, This method would first decode the base64 + * input and write the resulting raw bytes to the attachment. + *

+ * A subsequent call to getSize() may not be an exact measure + * of the content size. + * + * @param content the base64 encoded data to add to the attachment part + * @param contentType the value to set into the {@code Content-Type} + * header + * + * @exception SOAPException if an there is an error in setting the content + * @exception NullPointerException if {@code content} is null + * + * @since 1.6, SAAJ 1.3 + */ + public abstract void setBase64Content( + InputStream content, String contentType) throws SOAPException; + + + /** + * Gets the {@code DataHandler} object for this {@code AttachmentPart} + * object. + * + * @return the {@code DataHandler} object associated with this + * {@code AttachmentPart} object + * + * @exception SOAPException if there is no data in + * this {@code AttachmentPart} object + */ + public abstract DataHandler getDataHandler() + throws SOAPException; + + /** + * Sets the given {@code DataHandler} object as the data handler + * for this {@code AttachmentPart} object. Typically, on an incoming + * message, the data handler is automatically set. When + * a message is being created and populated with content, the + * {@code setDataHandler} method can be used to get data from + * various data sources into the message. + * + * @param dataHandler the {@code DataHandler} object to be set + * + * @exception IllegalArgumentException if there was a problem with + * the specified {@code DataHandler} object + */ + public abstract void setDataHandler(DataHandler dataHandler); + + + /** + * Gets the value of the MIME header whose name is "Content-ID". + * + * @return a {@code String} giving the value of the + * "Content-ID" header or {@code null} if there + * is none + * @see #setContentId + */ + public String getContentId() { + String[] values = getMimeHeader("Content-ID"); + if (values != null && values.length > 0) + return values[0]; + return null; + } + + /** + * Gets the value of the MIME header whose name is "Content-Location". + * + * @return a {@code String} giving the value of the + * "Content-Location" header or {@code null} if there + * is none + */ + public String getContentLocation() { + String[] values = getMimeHeader("Content-Location"); + if (values != null && values.length > 0) + return values[0]; + return null; + } + + /** + * Gets the value of the MIME header whose name is "Content-Type". + * + * @return a {@code String} giving the value of the + * "Content-Type" header or {@code null} if there + * is none + */ + public String getContentType() { + String[] values = getMimeHeader("Content-Type"); + if (values != null && values.length > 0) + return values[0]; + return null; + } + + /** + * Sets the MIME header whose name is "Content-ID" with the given value. + * + * @param contentId a {@code String} giving the value of the + * "Content-ID" header + * + * @exception IllegalArgumentException if there was a problem with + * the specified {@code contentId} value + * @see #getContentId + */ + public void setContentId(String contentId) + { + setMimeHeader("Content-ID", contentId); + } + + + /** + * Sets the MIME header whose name is "Content-Location" with the given value. + * + * + * @param contentLocation a {@code String} giving the value of the + * "Content-Location" header + * @exception IllegalArgumentException if there was a problem with + * the specified content location + */ + public void setContentLocation(String contentLocation) + { + setMimeHeader("Content-Location", contentLocation); + } + + /** + * Sets the MIME header whose name is "Content-Type" with the given value. + * + * @param contentType a {@code String} giving the value of the + * "Content-Type" header + * + * @exception IllegalArgumentException if there was a problem with + * the specified content type + */ + public void setContentType(String contentType) + { + setMimeHeader("Content-Type", contentType); + } + + /** + * Removes all MIME headers that match the given name. + * + * @param header the string name of the MIME header/s to + * be removed + */ + public abstract void removeMimeHeader(String header); + + /** + * Removes all the MIME header entries. + */ + public abstract void removeAllMimeHeaders(); + + + /** + * Gets all the values of the header identified by the given + * {@code String}. + * + * @param name the name of the header; example: "Content-Type" + * @return a {@code String} array giving the value for the + * specified header + * @see #setMimeHeader + */ + public abstract String[] getMimeHeader(String name); + + + /** + * Changes the first header entry that matches the given name + * to the given value, adding a new header if no existing header + * matches. This method also removes all matching headers but the first.

+ * + * Note that RFC822 headers can only contain US-ASCII characters. + * + * @param name a {@code String} giving the name of the header + * for which to search + * @param value a {@code String} giving the value to be set for + * the header whose name matches the given name + * + * @exception IllegalArgumentException if there was a problem with + * the specified mime header name or value + */ + public abstract void setMimeHeader(String name, String value); + + + /** + * Adds a MIME header with the specified name and value to this + * {@code AttachmentPart} object. + *

+ * Note that RFC822 headers can contain only US-ASCII characters. + * + * @param name a {@code String} giving the name of the header + * to be added + * @param value a {@code String} giving the value of the header + * to be added + * + * @exception IllegalArgumentException if there was a problem with + * the specified mime header name or value + */ + public abstract void addMimeHeader(String name, String value); + + /** + * Retrieves all the headers for this {@code AttachmentPart} object + * as an iterator over the {@code MimeHeader} objects. + * + * @return an {@code Iterator} object with all of the Mime + * headers for this {@code AttachmentPart} object + */ + public abstract Iterator getAllMimeHeaders(); + + /** + * Retrieves all {@code MimeHeader} objects that match a name in + * the given array. + * + * @param names a {@code String} array with the name(s) of the + * MIME headers to be returned + * @return all of the MIME headers that match one of the names in the + * given array as an {@code Iterator} object + */ + public abstract Iterator getMatchingMimeHeaders(String[] names); + + /** + * Retrieves all {@code MimeHeader} objects whose name does + * not match a name in the given array. + * + * @param names a {@code String} array with the name(s) of the + * MIME headers not to be returned + * @return all of the MIME headers in this {@code AttachmentPart} object + * except those that match one of the names in the + * given array. The nonmatching MIME headers are returned as an + * {@code Iterator} object. + */ + public abstract Iterator getNonMatchingMimeHeaders(String[] names); +} diff --git a/fine-third-jdk11/src/javax/xml/soap/Detail.java b/fine-third-jdk11/src/javax/xml/soap/Detail.java new file mode 100644 index 000000000..a7ce9b66f --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/Detail.java @@ -0,0 +1,122 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +import java.util.Iterator; + +import javax.xml.namespace.QName; + +/** + * A container for {@code DetailEntry} objects. {@code DetailEntry} + * objects give detailed error information that is application-specific and + * related to the {@code SOAPBody} object that contains it. + *

+ * A {@code Detail} object, which is part of a {@code SOAPFault} + * object, can be retrieved using the method {@code SOAPFault.getDetail}. + * The {@code Detail} interface provides two methods. One creates a new + * {@code DetailEntry} object and also automatically adds it to + * the {@code Detail} object. The second method gets a list of the + * {@code DetailEntry} objects contained in a {@code Detail} + * object. + *

+ * The following code fragment, in which sf is a {@code SOAPFault} + * object, gets its {@code Detail} object (d), adds a new + * {@code DetailEntry} object to d, and then gets a list of all the + * {@code DetailEntry} objects in d. The code also creates a + * {@code Name} object to pass to the method {@code addDetailEntry}. + * The variable se, used to create the {@code Name} object, + * is a {@code SOAPEnvelope} object. + *

{@code
+ *    Detail d = sf.getDetail();
+ *    Name name = se.createName("GetLastTradePrice", "WOMBAT",
+ *                                "http://www.wombat.org/trader");
+ *    d.addDetailEntry(name);
+ *    Iterator it = d.getDetailEntries();
+ * }
+ * + * @since 1.6 + */ +public interface Detail extends SOAPFaultElement { + + /** + * Creates a new {@code DetailEntry} object with the given + * name and adds it to this {@code Detail} object. + * + * @param name a {@code Name} object identifying the + * new {@code DetailEntry} object + * + * @return the new {@code DetailEntry} object that was + * created + * + * @exception SOAPException thrown when there is a problem in adding a + * DetailEntry object to this Detail object. + * + * @see Detail#addDetailEntry(QName qname) + */ + public DetailEntry addDetailEntry(Name name) throws SOAPException; + + /** + * Creates a new {@code DetailEntry} object with the given + * QName and adds it to this {@code Detail} object. This method + * is the preferred over the one using Name. + * + * @param qname a {@code QName} object identifying the + * new {@code DetailEntry} object + * + * @return the new {@code DetailEntry} object that was + * created + * + * @exception SOAPException thrown when there is a problem in adding a + * DetailEntry object to this Detail object. + * + * @see Detail#addDetailEntry(Name name) + * @since 1.6, SAAJ 1.3 + */ + public DetailEntry addDetailEntry(QName qname) throws SOAPException; + + /** + * Gets an Iterator over all of the {@code DetailEntry}s in this {@code Detail} object. + * + * @return an {@code Iterator} object over the {@code DetailEntry} + * objects in this {@code Detail} object + */ + public Iterator getDetailEntries(); +} diff --git a/fine-third-jdk11/src/javax/xml/soap/DetailEntry.java b/fine-third-jdk11/src/javax/xml/soap/DetailEntry.java new file mode 100644 index 000000000..b34d3ee89 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/DetailEntry.java @@ -0,0 +1,53 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +/** + * The content for a {@code Detail} object, giving details for + * a {@code SOAPFault} object. A {@code DetailEntry} object, + * which carries information about errors related to the {@code SOAPBody} + * object that contains it, is application-specific. + * + * @since 1.6 + */ +public interface DetailEntry extends SOAPElement { + +} diff --git a/fine-third-jdk11/src/javax/xml/soap/FactoryFinder.java b/fine-third-jdk11/src/javax/xml/soap/FactoryFinder.java new file mode 100644 index 000000000..d6dc39bbf --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/FactoryFinder.java @@ -0,0 +1,283 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; + + +class FactoryFinder { + + private static final Logger logger = Logger.getLogger("javax.xml.soap"); + + private static final ServiceLoaderUtil.ExceptionHandler EXCEPTION_HANDLER = + new ServiceLoaderUtil.ExceptionHandler() { + @Override + public SOAPException createException(Throwable throwable, String message) { + return new SOAPException(message, throwable); + } + }; + + /** + * Finds the implementation {@code Class} object for the given + * factory type. If it fails and {@code tryFallback} is {@code true} + * finds the {@code Class} object for the given default class name. + * The arguments supplied must be used in order + * Note the default class name may be needed even if fallback + * is not to be attempted in order to check if requested type is fallback. + *

+ * This method is package private so that this code can be shared. + * + * @return the {@code Class} object of the specified message factory; + * may not be {@code null} + * + * @param factoryClass factory abstract class or interface to be found + * @param deprecatedFactoryId deprecated name of a factory; it is used for types + * where class name is different from a name + * being searched (in previous spec). + * @param defaultClassName the implementation class name, which is + * to be used only if nothing else + * is found; {@code null} to indicate + * that there is no default class name + * @param tryFallback whether to try the default class as a + * fallback + * @exception SOAPException if there is a SOAP error + */ + @SuppressWarnings("unchecked") + static T find(Class factoryClass, + String defaultClassName, + boolean tryFallback, String deprecatedFactoryId) throws SOAPException { + + ClassLoader tccl = ServiceLoaderUtil.contextClassLoader(EXCEPTION_HANDLER); + String factoryId = factoryClass.getName(); + + // Use the system property first + String className = fromSystemProperty(factoryId, deprecatedFactoryId); + if (className != null) { + Object result = newInstance(className, defaultClassName, tccl); + if (result != null) { + return (T) result; + } + } + + // try to read from $java.home/lib/jaxm.properties + className = fromJDKProperties(factoryId, deprecatedFactoryId); + if (className != null) { + Object result = newInstance(className, defaultClassName, tccl); + if (result != null) { + return (T) result; + } + } + + // standard services: java.util.ServiceLoader + T factory = ServiceLoaderUtil.firstByServiceLoader( + factoryClass, + logger, + EXCEPTION_HANDLER); + if (factory != null) { + return factory; + } + + // try to find services in CLASSPATH + className = fromMetaInfServices(deprecatedFactoryId, tccl); + if (className != null) { + logger.log(Level.WARNING, + "Using deprecated META-INF/services mechanism with non-standard property: {0}. " + + "Property {1} should be used instead.", + new Object[]{deprecatedFactoryId, factoryId}); + Object result = newInstance(className, defaultClassName, tccl); + if (result != null) { + return (T) result; + } + } + + // If not found and fallback should not be tried, return a null result. + if (!tryFallback) + return null; + + // We didn't find the class through the usual means so try the default + // (built in) factory if specified. + if (defaultClassName == null) { + throw new SOAPException( + "Provider for " + factoryId + " cannot be found", null); + } + return (T) newInstance(defaultClassName, defaultClassName, tccl); + } + + // in most cases there is no deprecated factory id + static T find(Class factoryClass, + String defaultClassName, + boolean tryFallback) throws SOAPException { + return find(factoryClass, defaultClassName, tryFallback, null); + } + + private static Object newInstance(String className, String defaultClassName, ClassLoader tccl) throws SOAPException { + return ServiceLoaderUtil.newInstance( + className, + defaultClassName, + tccl, + EXCEPTION_HANDLER); + } + + // used only for deprecatedFactoryId; + // proper factoryId searched by java.util.ServiceLoader + private static String fromMetaInfServices(String deprecatedFactoryId, ClassLoader tccl) { + String serviceId = "META-INF/services/" + deprecatedFactoryId; + logger.log(Level.FINE, "Checking deprecated {0} resource", serviceId); + + try (InputStream is = + tccl == null ? + ClassLoader.getSystemResourceAsStream(serviceId) + : + tccl.getResourceAsStream(serviceId)) { + + if (is != null) { + String factoryClassName; + try (InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8); + BufferedReader rd = new BufferedReader(isr)) { + factoryClassName = rd.readLine(); + } + + logFound(factoryClassName); + if (factoryClassName != null && !"".equals(factoryClassName)) { + return factoryClassName; + } + } + + } catch (IOException e) { + // keep original behavior + } + return null; + } + + private static String fromJDKProperties(String factoryId, String deprecatedFactoryId) { + Path path = null; + try { + String JAVA_HOME = getSystemProperty("java.home"); + path = Paths.get(JAVA_HOME, "conf", "jaxm.properties"); + logger.log(Level.FINE, "Checking configuration in {0}", path); + + // to ensure backwards compatibility + if (!Files.exists(path)) { + path = Paths.get(JAVA_HOME, "lib", "jaxm.properties"); + } + + logger.log(Level.FINE, "Checking configuration in {0}", path); + if (Files.exists(path)) { + Properties props = new Properties(); + try (InputStream inputStream = Files.newInputStream(path)) { + props.load(inputStream); + } + + // standard property + logger.log(Level.FINE, "Checking property {0}", factoryId); + String factoryClassName = props.getProperty(factoryId); + logFound(factoryClassName); + if (factoryClassName != null) { + return factoryClassName; + } + + // deprecated property + if (deprecatedFactoryId != null) { + logger.log(Level.FINE, "Checking deprecated property {0}", deprecatedFactoryId); + factoryClassName = props.getProperty(deprecatedFactoryId); + logFound(factoryClassName); + if (factoryClassName != null) { + logger.log(Level.WARNING, + "Using non-standard property: {0}. Property {1} should be used instead.", + new Object[]{deprecatedFactoryId, factoryId}); + return factoryClassName; + } + } + } + } catch (Exception ignored) { + logger.log(Level.SEVERE, "Error reading SAAJ configuration from [" + path + + "] file. Check it is accessible and has correct format.", ignored); + } + return null; + } + + private static String fromSystemProperty(String factoryId, String deprecatedFactoryId) { + String systemProp = getSystemProperty(factoryId); + if (systemProp != null) { + return systemProp; + } + if (deprecatedFactoryId != null) { + systemProp = getSystemProperty(deprecatedFactoryId); + if (systemProp != null) { + logger.log(Level.WARNING, + "Using non-standard property: {0}. Property {1} should be used instead.", + new Object[] {deprecatedFactoryId, factoryId}); + return systemProp; + } + } + return null; + } + + private static String getSystemProperty(final String property) { + logger.log(Level.FINE, "Checking system property {0}", property); + String value = AccessController.doPrivileged(new PrivilegedAction() { + @Override + public String run() { + return System.getProperty(property); + } + }); + logFound(value); + return value; + } + + private static void logFound(String value) { + if (value != null) { + logger.log(Level.FINE, " found {0}", value); + } else { + logger.log(Level.FINE, " not found"); + } + } + +} diff --git a/fine-third-jdk11/src/javax/xml/soap/MessageFactory.java b/fine-third-jdk11/src/javax/xml/soap/MessageFactory.java new file mode 100644 index 000000000..c7ccee498 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/MessageFactory.java @@ -0,0 +1,204 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + + +import java.io.IOException; +import java.io.InputStream; + +/** + * A factory for creating {@code SOAPMessage} objects. + *

+ * A SAAJ client can create a {@code MessageFactory} object + * using the method {@code newInstance}, as shown in the following + * lines of code. + *

{@code
+ *       MessageFactory mf = MessageFactory.newInstance();
+ *       MessageFactory mf12 = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+ * }
+ *

+ * All {@code MessageFactory} objects, regardless of how they are + * created, will produce {@code SOAPMessage} objects that + * have the following elements by default: + *

    + *
  • A {@code SOAPPart} object + *
  • A {@code SOAPEnvelope} object + *
  • A {@code SOAPBody} object + *
  • A {@code SOAPHeader} object + *
+ * In some cases, specialized MessageFactory objects may be obtained that produce messages + * prepopulated with additional entries in the {@code SOAPHeader} object and the + * {@code SOAPBody} object. + * The content of a new {@code SOAPMessage} object depends on which of the two + * {@code MessageFactory} methods is used to create it. + *
    + *
  • {@code createMessage()}
    + * This is the method clients would normally use to create a request message. + *
  • {@code createMessage(MimeHeaders, java.io.InputStream)} -- message has + * content from the {@code InputStream} object and headers from the + * {@code MimeHeaders} object
    + * This method can be used internally by a service implementation to + * create a message that is a response to a request. + *
+ * + * @since 1.6 + */ +public abstract class MessageFactory { + + private static final String DEFAULT_MESSAGE_FACTORY + = "com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl"; + + /** + * Creates a new {@code MessageFactory} object that is an instance + * of the default implementation (SOAP 1.1). + * + * This method uses the lookup procedure specified in {@link javax.xml.soap} to locate and load the + * {@link javax.xml.soap.MessageFactory} class. + * + * @return a new instance of a {@code MessageFactory} + * + * @exception SOAPException if there was an error in creating the + * default implementation of the + * {@code MessageFactory}. + * @see SAAJMetaFactory + */ + public static MessageFactory newInstance() throws SOAPException { + + + try { + MessageFactory factory = (MessageFactory) FactoryFinder.find( + MessageFactory.class, + DEFAULT_MESSAGE_FACTORY, + false); + + if (factory != null) { + return factory; + } + return newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); + + } catch (Exception ex) { + throw new SOAPException( + "Unable to create message factory for SOAP: " + +ex.getMessage()); + } + + } + + /** + * Creates a new {@code MessageFactory} object that is an instance + * of the specified implementation. May be a dynamic message factory, + * a SOAP 1.1 message factory, or a SOAP 1.2 message factory. A dynamic + * message factory creates messages based on the MIME headers specified + * as arguments to the {@code createMessage} method. + * + * This method uses the SAAJMetaFactory to locate the implementation class + * and create the MessageFactory instance. + * + * @return a new instance of a {@code MessageFactory} + * + * @param protocol a string constant representing the class of the + * specified message factory implementation. May be + * either {@code DYNAMIC_SOAP_PROTOCOL}, + * {@code DEFAULT_SOAP_PROTOCOL} (which is the same + * as) {@code SOAP_1_1_PROTOCOL}, or + * {@code SOAP_1_2_PROTOCOL}. + * + * @exception SOAPException if there was an error in creating the + * specified implementation of {@code MessageFactory}. + * @see SAAJMetaFactory + * @since 1.6, SAAJ 1.3 + */ + public static MessageFactory newInstance(String protocol) throws SOAPException { + return SAAJMetaFactory.getInstance().newMessageFactory(protocol); + } + + /** + * Creates a new {@code SOAPMessage} object with the default + * {@code SOAPPart}, {@code SOAPEnvelope}, {@code SOAPBody}, + * and {@code SOAPHeader} objects. Profile-specific message factories + * can choose to prepopulate the {@code SOAPMessage} object with + * profile-specific headers. + *

+ * Content can be added to this message's {@code SOAPPart} object, and + * the message can be sent "as is" when a message containing only a SOAP part + * is sufficient. Otherwise, the {@code SOAPMessage} object needs + * to create one or more {@code AttachmentPart} objects and + * add them to itself. Any content that is not in XML format must be + * in an {@code AttachmentPart} object. + * + * @return a new {@code SOAPMessage} object + * @exception SOAPException if a SOAP error occurs + * @exception UnsupportedOperationException if the protocol of this + * {@code MessageFactory} instance is {@code DYNAMIC_SOAP_PROTOCOL} + */ + public abstract SOAPMessage createMessage() + throws SOAPException; + + /** + * Internalizes the contents of the given {@code InputStream} object into a + * new {@code SOAPMessage} object and returns the {@code SOAPMessage} + * object. + * + * @param in the {@code InputStream} object that contains the data + * for a message + * @param headers the transport-specific headers passed to the + * message in a transport-independent fashion for creation of the + * message + * @return a new {@code SOAPMessage} object containing the data from + * the given {@code InputStream} object + * + * @exception IOException if there is a problem in reading data from + * the input stream + * + * @exception SOAPException may be thrown if the message is invalid + * + * @exception IllegalArgumentException if the {@code MessageFactory} + * requires one or more MIME headers to be present in the + * {@code headers} parameter and they are missing. + * {@code MessageFactory} implementations for + * {@code SOAP_1_1_PROTOCOL} or + * {@code SOAP_1_2_PROTOCOL} must not throw + * {@code IllegalArgumentException} for this reason. + */ + public abstract SOAPMessage createMessage(MimeHeaders headers, + InputStream in) + throws IOException, SOAPException; +} diff --git a/fine-third-jdk11/src/javax/xml/soap/MimeHeader.java b/fine-third-jdk11/src/javax/xml/soap/MimeHeader.java new file mode 100644 index 000000000..d3a4a5ff9 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/MimeHeader.java @@ -0,0 +1,86 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + + +/** + * An object that stores a MIME header name and its value. One or more + * {@code MimeHeader} objects may be contained in a {@code MimeHeaders} + * object. + * + * @see MimeHeaders + * @since 1.6 + */ +public class MimeHeader { + + private String name; + private String value; + + /** + * Constructs a {@code MimeHeader} object initialized with the given + * name and value. + * + * @param name a {@code String} giving the name of the header + * @param value a {@code String} giving the value of the header + */ + public MimeHeader(String name, String value) { + this.name = name; + this.value = value; + } + + /** + * Returns the name of this {@code MimeHeader} object. + * + * @return the name of the header as a {@code String} + */ + public String getName() { + return name; + } + + /** + * Returns the value of this {@code MimeHeader} object. + * + * @return the value of the header as a {@code String} + */ + public String getValue() { + return value; + } +} diff --git a/fine-third-jdk11/src/javax/xml/soap/MimeHeaders.java b/fine-third-jdk11/src/javax/xml/soap/MimeHeaders.java new file mode 100644 index 000000000..576dee2dd --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/MimeHeaders.java @@ -0,0 +1,288 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +import java.util.Iterator; +import java.util.Vector; + +/** + * A container for {@code MimeHeader} objects, which represent + * the MIME headers present in a MIME part of a message. + * + *

This class is used primarily when an application wants to + * retrieve specific attachments based on certain MIME headers and + * values. This class will most likely be used by implementations of + * {@code AttachmentPart} and other MIME dependent parts of the SAAJ + * API. + * @see SOAPMessage#getAttachments + * @see AttachmentPart + * @since 1.6 + */ +public class MimeHeaders { + private Vector headers; + + /** + * Constructs a default {@code MimeHeaders} object initialized with + * an empty {@code Vector} object. + */ + public MimeHeaders() { + headers = new Vector<>(); + } + + /** + * Returns all of the values for the specified header as an array of + * {@code String} objects. + * + * @param name the name of the header for which values will be returned + * @return a {@code String} array with all of the values for the + * specified header + * @see #setHeader + */ + public String[] getHeader(String name) { + Vector values = new Vector<>(); + + for(int i = 0; i < headers.size(); i++) { + MimeHeader hdr = headers.elementAt(i); + if (hdr.getName().equalsIgnoreCase(name) + && hdr.getValue() != null) + values.addElement(hdr.getValue()); + } + + if (values.size() == 0) + return null; + + String r[] = new String[values.size()]; + values.copyInto(r); + return r; + } + + /** + * Replaces the current value of the first header entry whose name matches + * the given name with the given value, adding a new header if no existing header + * name matches. This method also removes all matching headers after the first one. + *

+ * Note that RFC822 headers can contain only US-ASCII characters. + * + * @param name a {@code String} with the name of the header for + * which to search + * @param value a {@code String} with the value that will replace the + * current value of the specified header + * + * @exception IllegalArgumentException if there was a problem in the + * mime header name or the value being set + * @see #getHeader + */ + public void setHeader(String name, String value) + { + boolean found = false; + + if ((name == null) || name.equals("")) + throw new IllegalArgumentException("Illegal MimeHeader name"); + + for(int i = 0; i < headers.size(); i++) { + MimeHeader hdr = headers.elementAt(i); + if (hdr.getName().equalsIgnoreCase(name)) { + if (!found) { + headers.setElementAt(new MimeHeader(hdr.getName(), + value), i); + found = true; + } + else + headers.removeElementAt(i--); + } + } + + if (!found) + addHeader(name, value); + } + + /** + * Adds a {@code MimeHeader} object with the specified name and value + * to this {@code MimeHeaders} object's list of headers. + *

+ * Note that RFC822 headers can contain only US-ASCII characters. + * + * @param name a {@code String} with the name of the header to + * be added + * @param value a {@code String} with the value of the header to + * be added + * + * @exception IllegalArgumentException if there was a problem in the + * mime header name or value being added + */ + public void addHeader(String name, String value) + { + if ((name == null) || name.equals("")) + throw new IllegalArgumentException("Illegal MimeHeader name"); + + int pos = headers.size(); + + for(int i = pos - 1 ; i >= 0; i--) { + MimeHeader hdr = headers.elementAt(i); + if (hdr.getName().equalsIgnoreCase(name)) { + headers.insertElementAt(new MimeHeader(name, value), + i+1); + return; + } + } + headers.addElement(new MimeHeader(name, value)); + } + + /** + * Remove all {@code MimeHeader} objects whose name matches the + * given name. + * + * @param name a {@code String} with the name of the header for + * which to search + */ + public void removeHeader(String name) { + for(int i = 0; i < headers.size(); i++) { + MimeHeader hdr = headers.elementAt(i); + if (hdr.getName().equalsIgnoreCase(name)) + headers.removeElementAt(i--); + } + } + + /** + * Removes all the header entries from this {@code MimeHeaders} object. + */ + public void removeAllHeaders() { + headers.removeAllElements(); + } + + + /** + * Returns all the {@code MimeHeader}s in this {@code MimeHeaders} object. + * + * @return an {@code Iterator} object over this {@code MimeHeaders} + * object's list of {@code MimeHeader} objects + */ + public Iterator getAllHeaders() { + return headers.iterator(); + } + + static class MatchingIterator implements Iterator { + private final boolean match; + private final Iterator iterator; + private final String[] names; + private MimeHeader nextHeader; + + MatchingIterator(String[] names, boolean match, Iterator i) { + this.match = match; + this.names = names; + this.iterator = i; + } + + private MimeHeader nextMatch() { + next: + while (iterator.hasNext()) { + MimeHeader hdr = iterator.next(); + + if (names == null) + return match ? null : hdr; + + for(int i = 0; i < names.length; i++) + if (hdr.getName().equalsIgnoreCase(names[i])) + if (match) + return hdr; + else + continue next; + if (!match) + return hdr; + } + return null; + } + + + @Override + public boolean hasNext() { + if (nextHeader == null) + nextHeader = nextMatch(); + return nextHeader != null; + } + + @Override + public MimeHeader next() { + // hasNext should've prefetched the header for us, + // return it. + if (nextHeader != null) { + MimeHeader ret = nextHeader; + nextHeader = null; + return ret; + } + if (hasNext()) + return nextHeader; + return null; + } + + @Override + public void remove() { + iterator.remove(); + } + } + + + /** + * Returns all the {@code MimeHeader} objects whose name matches + * a name in the given array of names. + * + * @param names an array of {@code String} objects with the names + * for which to search + * @return an {@code Iterator} object over the {@code MimeHeader} + * objects whose name matches one of the names in the given list + */ + public Iterator getMatchingHeaders(String[] names) { + return new MatchingIterator(names, true, headers.iterator()); + } + + /** + * Returns all of the {@code MimeHeader} objects whose name does not + * match a name in the given array of names. + * + * @param names an array of {@code String} objects with the names + * for which to search + * @return an {@code Iterator} object over the {@code MimeHeader} + * objects whose name does not match one of the names in the given list + */ + public Iterator getNonMatchingHeaders(String[] names) { + return new MatchingIterator(names, false, headers.iterator()); + } +} diff --git a/fine-third-jdk11/src/javax/xml/soap/Name.java b/fine-third-jdk11/src/javax/xml/soap/Name.java new file mode 100644 index 000000000..fd2447dca --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/Name.java @@ -0,0 +1,124 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +/** + * A representation of an XML name. This interface provides methods for + * getting the local and namespace-qualified names and also for getting the + * prefix associated with the namespace for the name. It is also possible + * to get the URI of the namespace. + *

+ * The following is an example of a namespace declaration in an element. + * {@code } + * ("xmlns" stands for "XML namespace".) + * The following + * shows what the methods in the {@code Name} interface will return. + *

    + *
  • {@code getQualifiedName} will return "prefix:LocalName" = + * "WOMBAT:GetLastTradePrice" + *
  • {@code getURI} will return "http://www.wombat.org/trader" + *
  • {@code getLocalName} will return "GetLastTracePrice" + *
  • {@code getPrefix} will return "WOMBAT" + *
+ *

+ * XML namespaces are used to disambiguate SOAP identifiers from + * application-specific identifiers. + *

+ * {@code Name} objects are created using the method + * {@code SOAPEnvelope.createName}, which has two versions. + * One method creates {@code Name} objects with + * a local name, a namespace prefix, and a namespace URI. + * and the second creates {@code Name} objects with just a local name. + * The following line of + * code, in which se is a {@code SOAPEnvelope} object, creates a new + * {@code Name} object with all three. + *

{@code
+ *     Name name = se.createName("GetLastTradePrice", "WOMBAT",
+ *                                "http://www.wombat.org/trader");
+ * }
+ * The following line of code gives an example of how a {@code Name} object + * can be used. The variable element is a {@code SOAPElement} object. + * This code creates a new {@code SOAPElement} object with the given name and + * adds it to element. + *
{@code
+ *     element.addChildElement(name);
+ * }
+ *

+ * The {@code Name} interface may be deprecated in a future release of SAAJ + * in favor of {@code javax.xml.namespace.QName} + * @see SOAPEnvelope#createName(String, String, String) SOAPEnvelope.createName + * @see SOAPFactory#createName(String, String, String) SOAPFactory.createName + * @since 1.6 + */ +public interface Name { + /** + * Gets the local name part of the XML name that this {@code Name} + * object represents. + * + * @return a string giving the local name + */ + String getLocalName(); + + /** + * Gets the namespace-qualified name of the XML name that this + * {@code Name} object represents. + * + * @return the namespace-qualified name as a string + */ + String getQualifiedName(); + + /** + * Returns the prefix that was specified when this {@code Name} object + * was initialized. This prefix is associated with the namespace for the XML + * name that this {@code Name} object represents. + * + * @return the prefix as a string + */ + String getPrefix(); + + /** + * Returns the URI of the namespace for the XML + * name that this {@code Name} object represents. + * + * @return the URI as a string + */ + String getURI(); +} diff --git a/fine-third-jdk11/src/javax/xml/soap/Node.java b/fine-third-jdk11/src/javax/xml/soap/Node.java new file mode 100644 index 000000000..8a4d99e96 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/Node.java @@ -0,0 +1,130 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +/** + * A representation of a node (element) in an XML document. + * This interface extends the standard DOM Node interface with methods for + * getting and setting the value of a node, for + * getting and setting the parent of a node, and for removing a node. + * + * @since 1.6 + */ +public interface Node extends org.w3c.dom.Node { + /** + * Returns the value of this node if this is a {@code Text} node or the + * value of the immediate child of this node otherwise. + * If there is an immediate child of this {@code Node} that it is a + * {@code Text} node then it's value will be returned. If there is + * more than one {@code Text} node then the value of the first + * {@code Text} Node will be returned. + * Otherwise {@code null} is returned. + * + * @return a {@code String} with the text of this node if this is a + * {@code Text} node or the text contained by the first + * immediate child of this {@code Node} object that is a + * {@code Text} object if such a child exists; + * {@code null} otherwise. + */ + public String getValue(); + + /** + * If this is a Text node then this method will set its value, + * otherwise it sets the value of the immediate (Text) child of this node. + * The value of the immediate child of this node can be set only if, there is + * one child node and that node is a {@code Text} node, or if + * there are no children in which case a child {@code Text} node will be + * created. + * + * @param value {@code value} to set on the {@code Text} node + * @exception IllegalStateException if the node is not a {@code Text} + * node and either has more than one child node or has a child + * node that is not a {@code Text} node. + * + * @since 1.6, SAAJ 1.2 + */ + public void setValue(String value); + + /** + * Sets the parent of this {@code Node} object to the given + * {@code SOAPElement} object. + * + * @param parent the {@code SOAPElement} object to be set as + * the parent of this {@code Node} object + * + * @exception SOAPException if there is a problem in setting the + * parent to the given element + * @see #getParentElement + */ + public void setParentElement(SOAPElement parent) throws SOAPException; + + /** + * Returns the parent element of this {@code Node} object. + * This method can throw an {@code UnsupportedOperationException} + * if the tree is not kept in memory. + * + * @return the {@code SOAPElement} object that is the parent of + * this {@code Node} object or {@code null} if this + * {@code Node} object is root + * + * @exception UnsupportedOperationException if the whole tree is not + * kept in memory + * @see #setParentElement + */ + public SOAPElement getParentElement(); + + /** + * Removes this {@code Node} object from the tree. + */ + public void detachNode(); + + /** + * Notifies the implementation that this {@code Node} + * object is no longer being used by the application and that the + * implementation is free to reuse this object for nodes that may + * be created later. + *

+ * Calling the method {@code recycleNode} implies that the method + * {@code detachNode} has been called previously. + */ + public void recycleNode(); + +} diff --git a/fine-third-jdk11/src/javax/xml/soap/SAAJMetaFactory.java b/fine-third-jdk11/src/javax/xml/soap/SAAJMetaFactory.java new file mode 100644 index 000000000..cffb52b50 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/SAAJMetaFactory.java @@ -0,0 +1,147 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +/** +* The access point for the implementation classes of the factories defined in the +* SAAJ API. The {@code newInstance} methods defined on factories {@link SOAPFactory} and +* {@link MessageFactory} in SAAJ 1.4 defer to instances of this class to do the actual object creation. +* The implementations of {@code newInstance()} methods (in {@link SOAPFactory} and {@link MessageFactory}) +* that existed in SAAJ 1.2 have been updated to also delegate to the SAAJMetaFactory when the SAAJ 1.2 +* defined lookup fails to locate the Factory implementation class name. +* +*

+* SAAJMetaFactory is a service provider interface and it uses similar lookup mechanism as other SAAJ factories +* to get actual instance: +* +*

    +*
  • If a system property with name {@code javax.xml.soap.SAAJMetaFactory} exists then its value is assumed +* to be the fully qualified name of the implementation class. This phase of the look up enables per-JVM +* override of the SAAJ implementation. +*
  • If a system property with name {@code javax.xml.soap.MetaFactory} exists then its value is assumed +* to be the fully qualified name of the implementation class. This property, defined by previous specifications + * (up to 1.3), is still supported, but it is strongly recommended to migrate to new property + * {@code javax.xml.soap.SAAJMetaFactory}. +*
  • Use the configuration file "jaxm.properties". The file is in standard {@link java.util.Properties} format +* and typically located in the {@code conf} directory of the Java installation. It contains the fully qualified +* name of the implementation class with key {@code javax.xml.soap.SAAJMetaFactory}. If no such property is defined, + * again, property with key {@code javax.xml.soap.MetaFactory} is used. It is strongly recommended to migrate to + * new property {@code javax.xml.soap.SAAJMetaFactory}. +*
  • Use the service-provider loading facilities, defined by the {@link java.util.ServiceLoader} class, +* to attempt to locate and load an implementation of the service using the {@linkplain +* java.util.ServiceLoader#load(java.lang.Class) default loading mechanism}. +*
  • Finally, if all the steps above fail, platform default implementation is used. +*
+* +*

+* There are no public methods on this +* class. +* +* @author SAAJ RI Development Team +* @since 1.6, SAAJ 1.3 +*/ +public abstract class SAAJMetaFactory { + + private static final String META_FACTORY_DEPRECATED_CLASS_PROPERTY = + "javax.xml.soap.MetaFactory"; + + private static final String DEFAULT_META_FACTORY_CLASS = + "com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl"; + + /** + * Creates a new instance of a concrete {@code SAAJMetaFactory} object. + * The SAAJMetaFactory is an SPI, it pulls the creation of the other factories together into a + * single place. Changing out the SAAJMetaFactory has the effect of changing out the entire SAAJ + * implementation. Service providers provide the name of their {@code SAAJMetaFactory} + * implementation. + * + * This method uses the lookup procedure specified in {@link javax.xml.soap} to locate and load the + * {@link javax.xml.soap.SAAJMetaFactory} class. + * + * @return a concrete {@code SAAJMetaFactory} object + * @exception SOAPException if there is an error in creating the {@code SAAJMetaFactory} + */ + static SAAJMetaFactory getInstance() throws SOAPException { + try { + return FactoryFinder.find( + SAAJMetaFactory.class, + DEFAULT_META_FACTORY_CLASS, + true, + META_FACTORY_DEPRECATED_CLASS_PROPERTY); + + } catch (Exception e) { + throw new SOAPException( + "Unable to create SAAJ meta-factory: " + e.getMessage()); + } + } + + protected SAAJMetaFactory() { } + + /** + * Creates a {@code MessageFactory} object for + * the given {@code String} protocol. + * + * @param protocol a {@code String} indicating the protocol + * @return a {@link MessageFactory}, not null + * @exception SOAPException if there is an error in creating the + * MessageFactory + * @see SOAPConstants#SOAP_1_1_PROTOCOL + * @see SOAPConstants#SOAP_1_2_PROTOCOL + * @see SOAPConstants#DYNAMIC_SOAP_PROTOCOL + */ + protected abstract MessageFactory newMessageFactory(String protocol) + throws SOAPException; + + /** + * Creates a {@code SOAPFactory} object for + * the given {@code String} protocol. + * + * @param protocol a {@code String} indicating the protocol + * @return a {@link SOAPFactory}, not null + * @exception SOAPException if there is an error in creating the + * SOAPFactory + * @see SOAPConstants#SOAP_1_1_PROTOCOL + * @see SOAPConstants#SOAP_1_2_PROTOCOL + * @see SOAPConstants#DYNAMIC_SOAP_PROTOCOL + */ + protected abstract SOAPFactory newSOAPFactory(String protocol) + throws SOAPException; +} diff --git a/fine-third-jdk11/src/javax/xml/soap/SAAJResult.java b/fine-third-jdk11/src/javax/xml/soap/SAAJResult.java new file mode 100644 index 000000000..e7ee2ca04 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/SAAJResult.java @@ -0,0 +1,148 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +import javax.xml.transform.dom.DOMResult; + +/** + * Acts as a holder for the results of a JAXP transformation or a JAXB + * marshalling, in the form of a SAAJ tree. These results should be accessed + * by using the {@link #getResult()} method. The {@link DOMResult#getNode()} + * method should be avoided in almost all cases. + * + * @author XWS-Security Development Team + * + * @since 1.6, SAAJ 1.3 + */ +public class SAAJResult extends DOMResult { + + /** + * Creates a {@code SAAJResult} that will present results in the form + * of a SAAJ tree that supports the default (SOAP 1.1) protocol. + *

+ * This kind of {@code SAAJResult} is meant for use in situations where the + * results will be used as a parameter to a method that takes a parameter + * whose type, such as {@code SOAPElement}, is drawn from the SAAJ + * API. When used in a transformation, the results are populated into the + * {@code SOAPPart} of a {@code SOAPMessage} that is created internally. + * The {@code SOAPPart} returned by {@link DOMResult#getNode()} + * is not guaranteed to be well-formed. + * + * @throws SOAPException if there is a problem creating a {@code SOAPMessage} + * + * @since 1.6, SAAJ 1.3 + */ + public SAAJResult() throws SOAPException { + this(MessageFactory.newInstance().createMessage()); + } + + /** + * Creates a {@code SAAJResult} that will present results in the form + * of a SAAJ tree that supports the specified protocol. The + * {@code DYNAMIC_SOAP_PROTOCOL} is ambiguous in this context and will + * cause this constructor to throw an {@code UnsupportedOperationException}. + *

+ * This kind of {@code SAAJResult} is meant for use in situations where the + * results will be used as a parameter to a method that takes a parameter + * whose type, such as {@code SOAPElement}, is drawn from the SAAJ + * API. When used in a transformation the results are populated into the + * {@code SOAPPart} of a {@code SOAPMessage} that is created + * internally. The {@code SOAPPart} returned by {@link DOMResult#getNode()} + * is not guaranteed to be well-formed. + * + * @param protocol the name of the SOAP protocol that the resulting SAAJ + * tree should support + * + * @throws SOAPException if a {@code SOAPMessage} supporting the + * specified protocol cannot be created + * + * @since 1.6, SAAJ 1.3 + */ + public SAAJResult(String protocol) throws SOAPException { + this(MessageFactory.newInstance(protocol).createMessage()); + } + + /** + * Creates a {@code SAAJResult} that will write the results into the + * {@code SOAPPart} of the supplied {@code SOAPMessage}. + * In the normal case these results will be written using DOM APIs and, + * as a result, the finished {@code SOAPPart} will not be guaranteed + * to be well-formed unless the data used to create it is also well formed. + * When used in a transformation the validity of the {@code SOAPMessage} + * after the transformation can be guaranteed only by means outside SAAJ + * specification. + * + * @param message the message whose {@code SOAPPart} will be + * populated as a result of some transformation or + * marshalling operation + * + * @since 1.6, SAAJ 1.3 + */ + public SAAJResult(SOAPMessage message) { + super(message.getSOAPPart()); + } + + /** + * Creates a {@code SAAJResult} that will write the results as a + * child node of the {@code SOAPElement} specified. In the normal + * case these results will be written using DOM APIs and as a result may + * invalidate the structure of the SAAJ tree. This kind of + * {@code SAAJResult} should only be used when the validity of the + * incoming data can be guaranteed by means outside of the SAAJ + * specification. + * + * @param rootNode the root to which the results will be appended + * + * @since 1.6, SAAJ 1.3 + */ + public SAAJResult(SOAPElement rootNode) { + super(rootNode); + } + + + /** + * @return the resulting Tree that was created under the specified root Node. + * @since 1.6, SAAJ 1.3 + */ + public javax.xml.soap.Node getResult() { + return (javax.xml.soap.Node)super.getNode().getFirstChild(); + } +} diff --git a/fine-third-jdk11/src/javax/xml/soap/SOAPBody.java b/fine-third-jdk11/src/javax/xml/soap/SOAPBody.java new file mode 100644 index 000000000..7403017c6 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/SOAPBody.java @@ -0,0 +1,313 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +import java.util.Locale; + +import org.w3c.dom.Document; + +import javax.xml.namespace.QName; + +/** + * An object that represents the contents of the SOAP body + * element in a SOAP message. A SOAP body element consists of XML data + * that affects the way the application-specific content is processed. + *

+ * A {@code SOAPBody} object contains {@code SOAPBodyElement} + * objects, which have the content for the SOAP body. + * A {@code SOAPFault} object, which carries status and/or + * error information, is an example of a {@code SOAPBodyElement} object. + * + * @see SOAPFault + * @since 1.6 + */ +public interface SOAPBody extends SOAPElement { + + /** + * Creates a new {@code SOAPFault} object and adds it to + * this {@code SOAPBody} object. The new {@code SOAPFault} will + * have default values set for the mandatory child elements. The type of + * the {@code SOAPFault} will be a SOAP 1.1 or a SOAP 1.2 {@code SOAPFault} + * depending on the {@code protocol} specified while creating the + * {@code MessageFactory} instance. + *

+ * A {@code SOAPBody} may contain at most one {@code SOAPFault} + * child element. + * + * @return the new {@code SOAPFault} object + * @exception SOAPException if there is a SOAP error + */ + public SOAPFault addFault() throws SOAPException; + + + /** + * Creates a new {@code SOAPFault} object and adds it to + * this {@code SOAPBody} object. The type of the + * {@code SOAPFault} will be a SOAP 1.1 or a SOAP 1.2 + * {@code SOAPFault} depending on the {@code protocol} + * specified while creating the {@code MessageFactory} instance. + *

+ * For SOAP 1.2 the {@code faultCode} parameter is the value of the + * Fault/Code/Value element and the {@code faultString} parameter + * is the value of the Fault/Reason/Text element. For SOAP 1.1 + * the {@code faultCode} parameter is the value of the {@code faultcode} + * element and the {@code faultString} parameter is the value of the {@code faultstring} + * element. + *

+ * A {@code SOAPBody} may contain at most one {@code SOAPFault} + * child element. + * + * @param faultCode a {@code Name} object giving the fault + * code to be set; must be one of the fault codes defined in the Version + * of SOAP specification in use + * @param faultString a {@code String} giving an explanation of + * the fault + * @param locale a {@link java.util.Locale} object indicating + * the native language of the {@code faultString} + * @return the new {@code SOAPFault} object + * @exception SOAPException if there is a SOAP error + * @see SOAPFault#setFaultCode + * @see SOAPFault#setFaultString + * @since 1.6, SAAJ 1.2 + */ + public SOAPFault addFault(Name faultCode, String faultString, Locale locale) throws SOAPException; + + /** + * Creates a new {@code SOAPFault} object and adds it to this + * {@code SOAPBody} object. The type of the {@code SOAPFault} + * will be a SOAP 1.1 or a SOAP 1.2 {@code SOAPFault} depending on + * the {@code protocol} specified while creating the {@code MessageFactory} + * instance. + *

+ * For SOAP 1.2 the {@code faultCode} parameter is the value of the + * Fault/Code/Value element and the {@code faultString} parameter + * is the value of the Fault/Reason/Text element. For SOAP 1.1 + * the {@code faultCode} parameter is the value of the {@code faultcode} + * element and the {@code faultString} parameter is the value of the {@code faultstring} + * element. + *

+ * A {@code SOAPBody} may contain at most one {@code SOAPFault} + * child element. + * + * @param faultCode + * a {@code QName} object giving the fault code to be + * set; must be one of the fault codes defined in the version + * of SOAP specification in use. + * @param faultString + * a {@code String} giving an explanation of the fault + * @param locale + * a {@link java.util.Locale Locale} object indicating the + * native language of the {@code faultString} + * @return the new {@code SOAPFault} object + * @exception SOAPException + * if there is a SOAP error + * @see SOAPFault#setFaultCode + * @see SOAPFault#setFaultString + * @see SOAPBody#addFault(Name faultCode, String faultString, Locale locale) + * + * @since 1.6, SAAJ 1.3 + */ + public SOAPFault addFault(QName faultCode, String faultString, Locale locale) + throws SOAPException; + + /** + * Creates a new {@code SOAPFault} object and adds it to this + * {@code SOAPBody} object. The type of the {@code SOAPFault} + * will be a SOAP 1.1 or a SOAP 1.2 {@code SOAPFault} depending on + * the {@code protocol} specified while creating the {@code MessageFactory} + * instance. + *

+ * For SOAP 1.2 the {@code faultCode} parameter is the value of the + * Fault/Code/Value element and the {@code faultString} parameter + * is the value of the Fault/Reason/Text element. For SOAP 1.1 + * the {@code faultCode} parameter is the value of the faultcode + * element and the {@code faultString} parameter is the value of the faultstring + * element. + *

+ * In case of a SOAP 1.2 fault, the default value for the mandatory {@code xml:lang} + * attribute on the Fault/Reason/Text element will be set to + * {@code java.util.Locale.getDefault()} + *

+ * A {@code SOAPBody} may contain at most one {@code SOAPFault} + * child element. + * + * @param faultCode + * a {@code Name} object giving the fault code to be set; + * must be one of the fault codes defined in the version of SOAP + * specification in use + * @param faultString + * a {@code String} giving an explanation of the fault + * @return the new {@code SOAPFault} object + * @exception SOAPException + * if there is a SOAP error + * @see SOAPFault#setFaultCode + * @see SOAPFault#setFaultString + * @since 1.6, SAAJ 1.2 + */ + public SOAPFault addFault(Name faultCode, String faultString) + throws SOAPException; + + /** + * Creates a new {@code SOAPFault} object and adds it to this {@code SOAPBody} + * object. The type of the {@code SOAPFault} + * will be a SOAP 1.1 or a SOAP 1.2 {@code SOAPFault} depending on + * the {@code protocol} specified while creating the {@code MessageFactory} + * instance. + *

+ * For SOAP 1.2 the {@code faultCode} parameter is the value of the + * Fault/Code/Value element and the {@code faultString} parameter + * is the value of the Fault/Reason/Text element. For SOAP 1.1 + * the {@code faultCode} parameter is the value of the faultcode + * element and the {@code faultString} parameter is the value of the faultstring + * element. + *

+ * In case of a SOAP 1.2 fault, the default value for the mandatory {@code xml:lang} + * attribute on the Fault/Reason/Text element will be set to + * {@code java.util.Locale.getDefault()} + *

+ * A {@code SOAPBody} may contain at most one {@code SOAPFault} + * child element + * + * @param faultCode + * a {@code QName} object giving the fault code to be + * set; must be one of the fault codes defined in the version + * of SOAP specification in use + * @param faultString + * a {@code String} giving an explanation of the fault + * @return the new {@code SOAPFault} object + * @exception SOAPException + * if there is a SOAP error + * @see SOAPFault#setFaultCode + * @see SOAPFault#setFaultString + * @see SOAPBody#addFault(Name faultCode, String faultString) + * @since 1.6, SAAJ 1.3 + */ + public SOAPFault addFault(QName faultCode, String faultString) + throws SOAPException; + + /** + * Indicates whether a {@code SOAPFault} object exists in this + * {@code SOAPBody} object. + * + * @return {@code true} if a {@code SOAPFault} object exists + * in this {@code SOAPBody} object; {@code false} + * otherwise + */ + public boolean hasFault(); + + /** + * Returns the {@code SOAPFault} object in this {@code SOAPBody} + * object. + * + * @return the {@code SOAPFault} object in this {@code SOAPBody} + * object if present, null otherwise. + */ + public SOAPFault getFault(); + + /** + * Creates a new {@code SOAPBodyElement} object with the specified + * name and adds it to this {@code SOAPBody} object. + * + * @param name + * a {@code Name} object with the name for the new {@code SOAPBodyElement} + * object + * @return the new {@code SOAPBodyElement} object + * @exception SOAPException + * if a SOAP error occurs + * @see SOAPBody#addBodyElement(javax.xml.namespace.QName) + */ + public SOAPBodyElement addBodyElement(Name name) throws SOAPException; + + + /** + * Creates a new {@code SOAPBodyElement} object with the specified + * QName and adds it to this {@code SOAPBody} object. + * + * @param qname + * a {@code QName} object with the qname for the new + * {@code SOAPBodyElement} object + * @return the new {@code SOAPBodyElement} object + * @exception SOAPException + * if a SOAP error occurs + * @see SOAPBody#addBodyElement(Name) + * @since 1.6, SAAJ 1.3 + */ + public SOAPBodyElement addBodyElement(QName qname) throws SOAPException; + + /** + * Adds the root node of the DOM {@link org.w3c.dom.Document} + * to this {@code SOAPBody} object. + *

+ * Calling this method invalidates the {@code document} parameter. + * The client application should discard all references to this {@code Document} + * and its contents upon calling {@code addDocument}. The behavior + * of an application that continues to use such references is undefined. + * + * @param document + * the {@code Document} object whose root node will be + * added to this {@code SOAPBody}. + * @return the {@code SOAPBodyElement} that represents the root node + * that was added. + * @exception SOAPException + * if the {@code Document} cannot be added + * @since 1.6, SAAJ 1.2 + */ + public SOAPBodyElement addDocument(org.w3c.dom.Document document) + throws SOAPException; + + /** + * Creates a new DOM {@link org.w3c.dom.Document} and sets + * the first child of this {@code SOAPBody} as it's document + * element. The child {@code SOAPElement} is removed as part of the + * process. + * + * @return the {@link org.w3c.dom.Document} representation + * of the {@code SOAPBody} content. + * + * @exception SOAPException + * if there is not exactly one child {@code SOAPElement} of the + * {@code SOAPBody}. + * + * @since 1.6, SAAJ 1.3 + */ + public org.w3c.dom.Document extractContentAsDocument() + throws SOAPException; +} diff --git a/fine-third-jdk11/src/javax/xml/soap/SOAPBodyElement.java b/fine-third-jdk11/src/javax/xml/soap/SOAPBodyElement.java new file mode 100644 index 000000000..acda37df6 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/SOAPBodyElement.java @@ -0,0 +1,60 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +/** + * A {@code SOAPBodyElement} object represents the contents in + * a {@code SOAPBody} object. The {@code SOAPFault} interface + * is a {@code SOAPBodyElement} object that has been defined. + *

+ * A new {@code SOAPBodyElement} object can be created and added + * to a {@code SOAPBody} object with the {@code SOAPBody} + * method {@code addBodyElement}. In the following line of code, + * {@code sb} is a {@code SOAPBody} object, and + * {@code myName} is a {@code Name} object. + *

{@code
+ *    SOAPBodyElement sbe = sb.addBodyElement(myName);
+ * }
+ * + * @since 1.6 + */ +public interface SOAPBodyElement extends SOAPElement { +} diff --git a/fine-third-jdk11/src/javax/xml/soap/SOAPConnection.java b/fine-third-jdk11/src/javax/xml/soap/SOAPConnection.java new file mode 100644 index 000000000..9478ae6ec --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/SOAPConnection.java @@ -0,0 +1,112 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + + +/** + * A point-to-point connection that a client can use for sending messages + * directly to a remote party (represented by a URL, for instance). + *

+ * The SOAPConnection class is optional. Some implementations may + * not implement this interface in which case the call to + * {@code SOAPConnectionFactory.newInstance()} (see below) will + * throw an {@code UnsupportedOperationException}. + *

+ * A client can obtain a {@code SOAPConnection} object using a + * {@link SOAPConnectionFactory} object as in the following example: + *

{@code
+ *      SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();
+ *      SOAPConnection con = factory.createConnection();
+ * }
+ * A {@code SOAPConnection} object can be used to send messages + * directly to a URL following the request/response paradigm. That is, + * messages are sent using the method {@code call}, which sends the + * message and then waits until it gets a reply. + * + * @since 1.6 + */ +public abstract class SOAPConnection { + + /** + * Sends the given message to the specified endpoint and blocks until + * it has returned the response. + * + * @param request the {@code SOAPMessage} object to be sent + * @param to an {@code Object} that identifies + * where the message should be sent. It is required to + * support Objects of type + * {@code java.lang.String}, + * {@code java.net.URL}, and when JAXM is present + * {@code javax.xml.messaging.URLEndpoint} + * + * @return the {@code SOAPMessage} object that is the response to the + * message that was sent + * @throws SOAPException if there is a SOAP error + */ + public abstract SOAPMessage call(SOAPMessage request, + Object to) throws SOAPException; + + /** + * Gets a message from a specific endpoint and blocks until it receives, + * + * @param to an {@code Object} that identifies where + * the request should be sent. Objects of type + * {@code java.lang.String} and + * {@code java.net.URL} must be supported. + * + * @return the {@code SOAPMessage} object that is the response to the + * get message request + * @throws SOAPException if there is a SOAP error + * @since 1.6, SAAJ 1.3 + */ + public SOAPMessage get(Object to) + throws SOAPException { + throw new UnsupportedOperationException("All subclasses of SOAPConnection must override get()"); + } + + /** + * Closes this {@code SOAPConnection} object. + * + * @throws SOAPException if there is a SOAP error + */ + public abstract void close() + throws SOAPException; +} diff --git a/fine-third-jdk11/src/javax/xml/soap/SOAPConnectionFactory.java b/fine-third-jdk11/src/javax/xml/soap/SOAPConnectionFactory.java new file mode 100644 index 000000000..3dac31864 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/SOAPConnectionFactory.java @@ -0,0 +1,102 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +/** + * A factory for creating {@code SOAPConnection} objects. Implementation of this class + * is optional. If {@code SOAPConnectionFactory.newInstance()} throws an + * UnsupportedOperationException then the implementation does not support the + * SAAJ communication infrastructure. Otherwise {@link SOAPConnection} objects + * can be created by calling {@code createConnection()} on the newly + * created {@code SOAPConnectionFactory} object. + * + * @since 1.6 + */ +public abstract class SOAPConnectionFactory { + + /** + * A constant representing the default value for a {@code SOAPConnection} + * object. The default is the point-to-point SOAP connection. + */ + private static final String DEFAULT_SOAP_CONNECTION_FACTORY + = "com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnectionFactory"; + + /** + * Creates an instance of the default + * {@code SOAPConnectionFactory} object. + * + * This method uses the lookup procedure specified in {@link javax.xml.soap} to locate and load the + * {@link javax.xml.soap.SOAPConnectionFactory} class. + * + * @return a new instance of a default + * {@code SOAPConnectionFactory} object + * + * @exception SOAPException if there was an error creating the + * {@code SOAPConnectionFactory} + * + * @exception UnsupportedOperationException if newInstance is not + * supported. + */ + public static SOAPConnectionFactory newInstance() + throws SOAPException, UnsupportedOperationException + { + try { + return FactoryFinder.find( + SOAPConnectionFactory.class, + DEFAULT_SOAP_CONNECTION_FACTORY, + true); + } catch (Exception ex) { + throw new SOAPException("Unable to create SOAP connection factory: " + +ex.getMessage()); + } + } + + /** + * Create a new {@code SOAPConnection}. + * + * @return the new {@code SOAPConnection} object. + * + * @exception SOAPException if there was an exception creating the + * {@code SOAPConnection} object. + */ + public abstract SOAPConnection createConnection() + throws SOAPException; +} diff --git a/fine-third-jdk11/src/javax/xml/soap/SOAPConstants.java b/fine-third-jdk11/src/javax/xml/soap/SOAPConstants.java new file mode 100644 index 000000000..ebb56ebc8 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/SOAPConstants.java @@ -0,0 +1,218 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +import javax.xml.namespace.QName; + +/** + * The definition of constants pertaining to the SOAP protocol. + * + * @since 1.6 + */ +public interface SOAPConstants { + /** + * Used to create {@code MessageFactory} instances that create + * {@code SOAPMessages} whose concrete type is based on the + * {@code Content-Type} MIME header passed to the + * {@code createMessage} method. If no {@code Content-Type} + * header is passed then the {@code createMessage} may throw an + * {@code IllegalArgumentException} or, in the case of the no + * argument version of {@code createMessage}, an + * {@code UnsupportedOperationException}. + * + * @since 1.6, SAAJ 1.3 + */ + public static final String DYNAMIC_SOAP_PROTOCOL = "Dynamic Protocol"; + + /** + * Used to create {@code MessageFactory} instances that create + * {@code SOAPMessages} whose behavior supports the SOAP 1.1 specification. + * + * @since 1.6, SAAJ 1.3 + */ + public static final String SOAP_1_1_PROTOCOL = "SOAP 1.1 Protocol"; + + /** + * Used to create {@code MessageFactory} instances that create + * {@code SOAPMessages} whose behavior supports the SOAP 1.2 + * specification + * + * @since 1.6, SAAJ 1.3 + */ + public static final String SOAP_1_2_PROTOCOL = "SOAP 1.2 Protocol"; + + /** + * The default protocol: SOAP 1.1 for backwards compatibility. + * + * @since 1.6, SAAJ 1.3 + */ + public static final String DEFAULT_SOAP_PROTOCOL = SOAP_1_1_PROTOCOL; + + /** + * The namespace identifier for the SOAP 1.1 envelope. + * @since 1.6, SAAJ 1.3 + */ + public static final String + URI_NS_SOAP_1_1_ENVELOPE = "http://schemas.xmlsoap.org/soap/envelope/"; + /** + * The namespace identifier for the SOAP 1.2 envelope. + * @since 1.6, SAAJ 1.3 + */ + public static final String + URI_NS_SOAP_1_2_ENVELOPE = "http://www.w3.org/2003/05/soap-envelope"; + + /** + * The namespace identifier for the SOAP 1.1 envelope, All SOAPElements in this + * namespace are defined by the SOAP 1.1 specification. + */ + public static final String + URI_NS_SOAP_ENVELOPE = URI_NS_SOAP_1_1_ENVELOPE; + + /** + * The namespace identifier for the SOAP 1.1 encoding. + * An attribute named {@code encodingStyle} in the + * {@code URI_NS_SOAP_ENVELOPE} namespace and set to the value + * {@code URI_NS_SOAP_ENCODING} can be added to an element to indicate + * that it is encoded using the rules in section 5 of the SOAP 1.1 + * specification. + */ + public static final String + URI_NS_SOAP_ENCODING = "http://schemas.xmlsoap.org/soap/encoding/"; + + /** + * The namespace identifier for the SOAP 1.2 encoding. + * @since 1.6, SAAJ 1.3 + */ + public static final String + URI_NS_SOAP_1_2_ENCODING = "http://www.w3.org/2003/05/soap-encoding"; + + /** + * The media type of the {@code Content-Type} MIME header in SOAP 1.1. + * @since 1.6, SAAJ 1.3 + */ + public static final String + SOAP_1_1_CONTENT_TYPE = "text/xml"; + + /** + * The media type of the {@code Content-Type} MIME header in SOAP 1.2. + * @since 1.6, SAAJ 1.3 + */ + public static final String + SOAP_1_2_CONTENT_TYPE = "application/soap+xml"; + + /** + * The URI identifying the next application processing a SOAP request as the intended + * actor for a SOAP 1.1 header entry (see section 4.2.2 of the SOAP 1.1 specification). + *

+ * This value can be passed to + * {@link SOAPHeader#examineMustUnderstandHeaderElements(String)}, + * {@link SOAPHeader#examineHeaderElements(String)} and + * {@link SOAPHeader#extractHeaderElements(String)} + */ + public static final String + URI_SOAP_ACTOR_NEXT = "http://schemas.xmlsoap.org/soap/actor/next"; + + /** + * The URI identifying the next application processing a SOAP request as the intended + * role for a SOAP 1.2 header entry (see section 2.2 of part 1 of the SOAP 1.2 + * specification). + * @since 1.6, SAAJ 1.3 + */ + public static final String + URI_SOAP_1_2_ROLE_NEXT = URI_NS_SOAP_1_2_ENVELOPE + "/role/next"; + + /** + * The URI specifying the role None in SOAP 1.2. + * @since 1.6, SAAJ 1.3 + */ + public static final String + URI_SOAP_1_2_ROLE_NONE = URI_NS_SOAP_1_2_ENVELOPE + "/role/none"; + + /** + * The URI identifying the ultimate receiver of the SOAP 1.2 message. + * @since 1.6, SAAJ 1.3 + */ + public static final String + URI_SOAP_1_2_ROLE_ULTIMATE_RECEIVER = + URI_NS_SOAP_1_2_ENVELOPE + "/role/ultimateReceiver"; + + /** + * The default namespace prefix for http://www.w3.org/2003/05/soap-envelope + * @since 1.6, SAAJ 1.3 + */ + public static final String SOAP_ENV_PREFIX = "env"; + + /** + * SOAP 1.2 VersionMismatch Fault + * @since 1.6, SAAJ 1.3 + */ + public static final QName SOAP_VERSIONMISMATCH_FAULT = + new QName(URI_NS_SOAP_1_2_ENVELOPE, "VersionMismatch", SOAP_ENV_PREFIX); + + /** + * SOAP 1.2 MustUnderstand Fault + * @since 1.6, SAAJ 1.3 + */ + public static final QName SOAP_MUSTUNDERSTAND_FAULT = + new QName(URI_NS_SOAP_1_2_ENVELOPE, "MustUnderstand", SOAP_ENV_PREFIX); + + /** + * SOAP 1.2 DataEncodingUnknown Fault + * @since 1.6, SAAJ 1.3 + */ + public static final QName SOAP_DATAENCODINGUNKNOWN_FAULT = + new QName(URI_NS_SOAP_1_2_ENVELOPE, "DataEncodingUnknown", SOAP_ENV_PREFIX); + + /** + * SOAP 1.2 Sender Fault + * @since 1.6, SAAJ 1.3 + */ + public static final QName SOAP_SENDER_FAULT = + new QName(URI_NS_SOAP_1_2_ENVELOPE, "Sender", SOAP_ENV_PREFIX); + + /** + * SOAP 1.2 Receiver Fault + * @since 1.6, SAAJ 1.3 + */ + public static final QName SOAP_RECEIVER_FAULT = + new QName(URI_NS_SOAP_1_2_ENVELOPE, "Receiver", SOAP_ENV_PREFIX); + +} diff --git a/fine-third-jdk11/src/javax/xml/soap/SOAPElement.java b/fine-third-jdk11/src/javax/xml/soap/SOAPElement.java new file mode 100644 index 000000000..b88a5395c --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/SOAPElement.java @@ -0,0 +1,540 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +import java.util.Iterator; + +import javax.xml.namespace.QName; + +/** + * An object representing an element of a SOAP message that is allowed but not + * specifically prescribed by a SOAP specification. This interface serves as the + * base interface for those objects that are specifically prescribed by a SOAP + * specification. + *

+ * Methods in this interface that are required to return SAAJ specific objects + * may "silently" replace nodes in the tree as required to successfully return + * objects of the correct type. See {@link #getChildElements()} and + * {@link javax.xml.soap} for details. + * + * @since 1.6 + */ +public interface SOAPElement extends Node, org.w3c.dom.Element { + + /** + * Creates a new {@code SOAPElement} object initialized with the + * given {@code Name} object and adds the new element to this + * {@code SOAPElement} object. + *

+ * This method may be deprecated in a future release of SAAJ in favor of + * addChildElement(javax.xml.namespace.QName) + * + * @param name a {@code Name} object with the XML name for the + * new element + * + * @return the new {@code SOAPElement} object that was created + * @exception SOAPException if there is an error in creating the + * {@code SOAPElement} object + * @see SOAPElement#addChildElement(javax.xml.namespace.QName) + */ + public SOAPElement addChildElement(Name name) throws SOAPException; + + /** + * Creates a new {@code SOAPElement} object initialized with the given + * {@code QName} object and adds the new element to this {@code SOAPElement} + * object. The namespace, localname and prefix of the new + * {@code SOAPElement} are all taken from the {@code qname} argument. + * + * @param qname a {@code QName} object with the XML name for the + * new element + * + * @return the new {@code SOAPElement} object that was created + * @exception SOAPException if there is an error in creating the + * {@code SOAPElement} object + * @see SOAPElement#addChildElement(Name) + * @since 1.6, SAAJ 1.3 + */ + public SOAPElement addChildElement(QName qname) throws SOAPException; + + /** + * Creates a new {@code SOAPElement} object initialized with the + * specified local name and adds the new element to this + * {@code SOAPElement} object. + * The new {@code SOAPElement} inherits any in-scope default namespace. + * + * @param localName a {@code String} giving the local name for + * the element + * @return the new {@code SOAPElement} object that was created + * @exception SOAPException if there is an error in creating the + * {@code SOAPElement} object + */ + public SOAPElement addChildElement(String localName) throws SOAPException; + + /** + * Creates a new {@code SOAPElement} object initialized with the + * specified local name and prefix and adds the new element to this + * {@code SOAPElement} object. + * + * @param localName a {@code String} giving the local name for + * the new element + * @param prefix a {@code String} giving the namespace prefix for + * the new element + * + * @return the new {@code SOAPElement} object that was created + * @exception SOAPException if the {@code prefix} is not valid in the + * context of this {@code SOAPElement} or if there is an error in creating the + * {@code SOAPElement} object + */ + public SOAPElement addChildElement(String localName, String prefix) + throws SOAPException; + + /** + * Creates a new {@code SOAPElement} object initialized with the + * specified local name, prefix, and URI and adds the new element to this + * {@code SOAPElement} object. + * + * @param localName a {@code String} giving the local name for + * the new element + * @param prefix a {@code String} giving the namespace prefix for + * the new element + * @param uri a {@code String} giving the URI of the namespace + * to which the new element belongs + * + * @return the new {@code SOAPElement} object that was created + * @exception SOAPException if there is an error in creating the + * {@code SOAPElement} object + */ + public SOAPElement addChildElement(String localName, String prefix, + String uri) + throws SOAPException; + + /** + * Add a {@code SOAPElement} as a child of this + * {@code SOAPElement} instance. The {@code SOAPElement} + * is expected to be created by a + * {@code SOAPFactory}. Callers should not rely on the + * element instance being added as is into the XML + * tree. Implementations could end up copying the content + * of the {@code SOAPElement} passed into an instance of + * a different {@code SOAPElement} implementation. For + * instance if {@code addChildElement()} is called on a + * {@code SOAPHeader}, {@code element} will be copied + * into an instance of a {@code SOAPHeaderElement}. + * + *

The fragment rooted in {@code element} is either added + * as a whole or not at all, if there was an error. + * + *

The fragment rooted in {@code element} cannot contain + * elements named "Envelope", "Header" or "Body" and in the SOAP + * namespace. Any namespace prefixes present in the fragment + * should be fully resolved using appropriate namespace + * declarations within the fragment itself. + * + * @param element the {@code SOAPElement} to be added as a + * new child + * + * @exception SOAPException if there was an error in adding this + * element as a child + * + * @return an instance representing the new SOAP element that was + * actually added to the tree. + */ + public SOAPElement addChildElement(SOAPElement element) + throws SOAPException; + + /** + * Detaches all children of this {@code SOAPElement}. + *

+ * This method is useful for rolling back the construction of partially + * completed {@code SOAPHeaders} and {@code SOAPBodys} in + * preparation for sending a fault when an error condition is detected. It + * is also useful for recycling portions of a document within a SOAP + * message. + * + * @since 1.6, SAAJ 1.2 + */ + public abstract void removeContents(); + + /** + * Creates a new {@code Text} object initialized with the given + * {@code String} and adds it to this {@code SOAPElement} object. + * + * @param text a {@code String} object with the textual content to be added + * + * @return the {@code SOAPElement} object into which + * the new {@code Text} object was inserted + * @exception SOAPException if there is an error in creating the + * new {@code Text} object or if it is not legal to + * attach it as a child to this + * {@code SOAPElement} + */ + public SOAPElement addTextNode(String text) throws SOAPException; + + /** + * Adds an attribute with the specified name and value to this + * {@code SOAPElement} object. + * + * @param name a {@code Name} object with the name of the attribute + * @param value a {@code String} giving the value of the attribute + * @return the {@code SOAPElement} object into which the attribute was + * inserted + * + * @exception SOAPException if there is an error in creating the + * Attribute, or it is invalid to set + an attribute with {@code Name} + {@code name} on this SOAPElement. + * @see SOAPElement#addAttribute(javax.xml.namespace.QName, String) + */ + public SOAPElement addAttribute(Name name, String value) + throws SOAPException; + + /** + * Adds an attribute with the specified name and value to this + * {@code SOAPElement} object. + * + * @param qname a {@code QName} object with the name of the attribute + * @param value a {@code String} giving the value of the attribute + * @return the {@code SOAPElement} object into which the attribute was + * inserted + * + * @exception SOAPException if there is an error in creating the + * Attribute, or it is invalid to set + an attribute with {@code QName} + {@code qname} on this SOAPElement. + * @see SOAPElement#addAttribute(Name, String) + * @since 1.6, SAAJ 1.3 + */ + public SOAPElement addAttribute(QName qname, String value) + throws SOAPException; + + /** + * Adds a namespace declaration with the specified prefix and URI to this + * {@code SOAPElement} object. + * + * @param prefix a {@code String} giving the prefix of the namespace + * @param uri a {@code String} giving the uri of the namespace + * @return the {@code SOAPElement} object into which this + * namespace declaration was inserted. + * + * @exception SOAPException if there is an error in creating the + * namespace + */ + public SOAPElement addNamespaceDeclaration(String prefix, String uri) + throws SOAPException; + + /** + * Returns the value of the attribute with the specified name. + * + * @param name a {@code Name} object with the name of the attribute + * @return a {@code String} giving the value of the specified + * attribute, Null if there is no such attribute + * @see SOAPElement#getAttributeValue(javax.xml.namespace.QName) + */ + public String getAttributeValue(Name name); + + /** + * Returns the value of the attribute with the specified qname. + * + * @param qname a {@code QName} object with the qname of the attribute + * @return a {@code String} giving the value of the specified + * attribute, Null if there is no such attribute + * @see SOAPElement#getAttributeValue(Name) + * @since 1.6, SAAJ 1.3 + */ + public String getAttributeValue(QName qname); + + /** + * Returns an {@code Iterator} over all of the attribute + * {@code Name} objects in this + * {@code SOAPElement} object. The iterator can be used to get + * the attribute names, which can then be passed to the method + * {@code getAttributeValue} to retrieve the value of each + * attribute. + * + * @see SOAPElement#getAllAttributesAsQNames() + * @return an iterator over the names of the attributes + */ + public Iterator getAllAttributes(); + + /** + * Returns an {@code Iterator} over all of the attributes + * in this {@code SOAPElement} as {@code QName} objects. + * The iterator can be used to get the attribute QName, which can then + * be passed to the method {@code getAttributeValue} to retrieve + * the value of each attribute. + * + * @return an iterator over the QNames of the attributes + * @see SOAPElement#getAllAttributes() + * @since 1.6, SAAJ 1.3 + */ + public Iterator getAllAttributesAsQNames(); + + + /** + * Returns the URI of the namespace that has the given prefix. + * + * @param prefix a {@code String} giving the prefix of the namespace + * for which to search + * @return a {@code String} with the uri of the namespace that has + * the given prefix + */ + public String getNamespaceURI(String prefix); + + /** + * Returns an {@code Iterator} over the namespace prefix + * {@code String}s declared by this element. The prefixes returned by + * this iterator can be passed to the method + * {@code getNamespaceURI} to retrieve the URI of each namespace. + * + * @return an iterator over the namespace prefixes in this + * {@code SOAPElement} object + */ + public Iterator getNamespacePrefixes(); + + /** + * Returns an {@code Iterator} over the namespace prefix + * {@code String}s visible to this element. The prefixes returned by + * this iterator can be passed to the method + * {@code getNamespaceURI} to retrieve the URI of each namespace. + * + * @return an iterator over the namespace prefixes are within scope of this + * {@code SOAPElement} object + * + * @since 1.6, SAAJ 1.2 + */ + public Iterator getVisibleNamespacePrefixes(); + + /** + * Creates a {@code QName} whose namespace URI is the one associated + * with the parameter, {@code prefix}, in the context of this + * {@code SOAPElement}. The remaining elements of the new + * {@code QName} are taken directly from the parameters, + * {@code localName} and {@code prefix}. + * + * @param localName + * a {@code String} containing the local part of the name. + * @param prefix + * a {@code String} containing the prefix for the name. + * + * @return a {@code QName} with the specified {@code localName} + * and {@code prefix}, and with a namespace that is associated + * with the {@code prefix} in the context of this + * {@code SOAPElement}. This namespace will be the same as + * the one that would be returned by + * {@link #getNamespaceURI(String)} if it were given + * {@code prefix} as it's parameter. + * + * @exception SOAPException if the {@code QName} cannot be created. + * + * @since 1.6, SAAJ 1.3 + */ + public QName createQName(String localName, String prefix) + throws SOAPException; + /** + * Returns the name of this {@code SOAPElement} object. + * + * @return a {@code Name} object with the name of this + * {@code SOAPElement} object + */ + public Name getElementName(); + + /** + * Returns the qname of this {@code SOAPElement} object. + * + * @return a {@code QName} object with the qname of this + * {@code SOAPElement} object + * @see SOAPElement#getElementName() + * @since 1.6, SAAJ 1.3 + */ + public QName getElementQName(); + + /** + * Changes the name of this {@code Element} to {@code newName} if + * possible. SOAP Defined elements such as SOAPEnvelope, SOAPHeader, SOAPBody + * etc. cannot have their names changed using this method. Any attempt to do + * so will result in a SOAPException being thrown. + *

+ * Callers should not rely on the element instance being renamed as is. + * Implementations could end up copying the content of the + * {@code SOAPElement} to a renamed instance. + * + * @param newName the new name for the {@code Element}. + * + * @exception SOAPException if changing the name of this {@code Element} + * is not allowed. + * @return The renamed Node + * + * @since 1.6, SAAJ 1.3 + */ + public SOAPElement setElementQName(QName newName) throws SOAPException; + + /** + * Removes the attribute with the specified name. + * + * @param name the {@code Name} object with the name of the + * attribute to be removed + * @return {@code true} if the attribute was + * removed successfully; {@code false} if it was not + * @see SOAPElement#removeAttribute(javax.xml.namespace.QName) + */ + public boolean removeAttribute(Name name); + + /** + * Removes the attribute with the specified qname. + * + * @param qname the {@code QName} object with the qname of the + * attribute to be removed + * @return {@code true} if the attribute was + * removed successfully; {@code false} if it was not + * @see SOAPElement#removeAttribute(Name) + * @since 1.6, SAAJ 1.3 + */ + public boolean removeAttribute(QName qname); + + /** + * Removes the namespace declaration corresponding to the given prefix. + * + * @param prefix a {@code String} giving the prefix for which + * to search + * @return {@code true} if the namespace declaration was + * removed successfully; {@code false} if it was not + */ + public boolean removeNamespaceDeclaration(String prefix); + + /** + * Returns an {@code Iterator} over all the immediate child + * {@link Node}s of this element. This includes {@code javax.xml.soap.Text} + * objects as well as {@code SOAPElement} objects. + *

+ * Calling this method must cause child {@code Element}, + * {@code SOAPElement} and {@code org.w3c.dom.Text} nodes to be + * replaced by {@code SOAPElement}, {@code SOAPHeaderElement}, + * {@code SOAPBodyElement} or {@code javax.xml.soap.Text} nodes as + * appropriate for the type of this parent node. As a result the calling + * application must treat any existing references to these child nodes that + * have been obtained through DOM APIs as invalid and either discard them or + * refresh them with the values returned by this {@code Iterator}. This + * behavior can be avoided by calling the equivalent DOM APIs. See + * {@link javax.xml.soap} + * for more details. + * + * @return an iterator with the content of this {@code SOAPElement} + * object + */ + public Iterator getChildElements(); + + /** + * Returns an {@code Iterator} over all the immediate child + * {@link Node}s of this element with the specified name. All of these + * children will be {@code SOAPElement} nodes. + *

+ * Calling this method must cause child {@code Element}, + * {@code SOAPElement} and {@code org.w3c.dom.Text} nodes to be + * replaced by {@code SOAPElement}, {@code SOAPHeaderElement}, + * {@code SOAPBodyElement} or {@code javax.xml.soap.Text} nodes as + * appropriate for the type of this parent node. As a result the calling + * application must treat any existing references to these child nodes that + * have been obtained through DOM APIs as invalid and either discard them or + * refresh them with the values returned by this {@code Iterator}. This + * behavior can be avoided by calling the equivalent DOM APIs. See + * {@link javax.xml.soap} + * for more details. + * + * @param name a {@code Name} object with the name of the child + * elements to be returned + * + * @return an {@code Iterator} object over all the elements + * in this {@code SOAPElement} object with the + * specified name + * @see SOAPElement#getChildElements(javax.xml.namespace.QName) + */ + public Iterator getChildElements(Name name); + + /** + * Returns an {@code Iterator} over all the immediate child + * {@link Node}s of this element with the specified qname. All of these + * children will be {@code SOAPElement} nodes. + *

+ * Calling this method must cause child {@code Element}, + * {@code SOAPElement} and {@code org.w3c.dom.Text} nodes to be + * replaced by {@code SOAPElement}, {@code SOAPHeaderElement}, + * {@code SOAPBodyElement} or {@code javax.xml.soap.Text} nodes as + * appropriate for the type of this parent node. As a result the calling + * application must treat any existing references to these child nodes that + * have been obtained through DOM APIs as invalid and either discard them or + * refresh them with the values returned by this {@code Iterator}. This + * behavior can be avoided by calling the equivalent DOM APIs. See + * {@link javax.xml.soap} + * for more details. + * + * @param qname a {@code QName} object with the qname of the child + * elements to be returned + * + * @return an {@code Iterator} object over all the elements + * in this {@code SOAPElement} object with the + * specified qname + * @see SOAPElement#getChildElements(Name) + * @since 1.6, SAAJ 1.3 + */ + public Iterator getChildElements(QName qname); + + /** + * Sets the encoding style for this {@code SOAPElement} object + * to one specified. + * + * @param encodingStyle a {@code String} giving the encoding style + * + * @exception IllegalArgumentException if there was a problem in the + * encoding style being set. + * @exception SOAPException if setting the encodingStyle is invalid for this SOAPElement. + * @see #getEncodingStyle + */ + public void setEncodingStyle(String encodingStyle) + throws SOAPException; + /** + * Returns the encoding style for this {@code SOAPElement} object. + * + * @return a {@code String} giving the encoding style + * + * @see #setEncodingStyle + */ + public String getEncodingStyle(); +} diff --git a/fine-third-jdk11/src/javax/xml/soap/SOAPElementFactory.java b/fine-third-jdk11/src/javax/xml/soap/SOAPElementFactory.java new file mode 100644 index 000000000..bf5cb9f19 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/SOAPElementFactory.java @@ -0,0 +1,156 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +/** + * {@code SOAPElementFactory} is a factory for XML fragments that + * will eventually end up in the SOAP part. These fragments + * can be inserted as children of the {@code SOAPHeader} or + * {@code SOAPBody} or {@code SOAPEnvelope}. + * + *

Elements created using this factory do not have the properties + * of an element that lives inside a SOAP header document. These + * elements are copied into the XML document tree when they are + * inserted. + * @deprecated - Use {@code javax.xml.soap.SOAPFactory} for creating SOAPElements. + * @see javax.xml.soap.SOAPFactory + * @since 1.6 + */ +public class SOAPElementFactory { + + private SOAPFactory soapFactory; + + private SOAPElementFactory(SOAPFactory soapFactory) { + this.soapFactory = soapFactory; + } + + /** + * Create a {@code SOAPElement} object initialized with the + * given {@code Name} object. + * + * @param name a {@code Name} object with the XML name for + * the new element + * + * @return the new {@code SOAPElement} object that was + * created + * + * @exception SOAPException if there is an error in creating the + * {@code SOAPElement} object + * + * @deprecated Use + * javax.xml.soap.SOAPFactory.createElement(javax.xml.soap.Name) + * instead + * + * @see javax.xml.soap.SOAPFactory#createElement(javax.xml.soap.Name) + * @see javax.xml.soap.SOAPFactory#createElement(javax.xml.namespace.QName) + */ + public SOAPElement create(Name name) throws SOAPException { + return soapFactory.createElement(name); + } + + /** + * Create a {@code SOAPElement} object initialized with the + * given local name. + * + * @param localName a {@code String} giving the local name for + * the new element + * + * @return the new {@code SOAPElement} object that was + * created + * + * @exception SOAPException if there is an error in creating the + * {@code SOAPElement} object + * + * @deprecated Use + * javax.xml.soap.SOAPFactory.createElement(String localName) instead + * + * @see javax.xml.soap.SOAPFactory#createElement(java.lang.String) + */ + public SOAPElement create(String localName) throws SOAPException { + return soapFactory.createElement(localName); + } + + /** + * Create a new {@code SOAPElement} object with the given + * local name, prefix and uri. + * + * @param localName a {@code String} giving the local name + * for the new element + * @param prefix the prefix for this {@code SOAPElement} + * @param uri a {@code String} giving the URI of the + * namespace to which the new element belongs + * + * @return the new {@code SOAPElement} object that was + * created + * + * @exception SOAPException if there is an error in creating the + * {@code SOAPElement} object + * + * @deprecated Use + * javax.xml.soap.SOAPFactory.createElement(String localName, + * String prefix, + * String uri) + * instead + * + * @see javax.xml.soap.SOAPFactory#createElement(java.lang.String, java.lang.String, java.lang.String) + */ + public SOAPElement create(String localName, String prefix, String uri) + throws SOAPException { + return soapFactory.createElement(localName, prefix, uri); + } + + /** + * Creates a new instance of {@code SOAPElementFactory}. + * + * @return a new instance of a {@code SOAPElementFactory} + * + * @exception SOAPException if there was an error creating the + * default {@code SOAPElementFactory} + */ + public static SOAPElementFactory newInstance() throws SOAPException { + try { + return new SOAPElementFactory(SOAPFactory.newInstance()); + } catch (Exception ex) { + throw new SOAPException( + "Unable to create SOAP Element Factory: " + ex.getMessage()); + } + } +} diff --git a/fine-third-jdk11/src/javax/xml/soap/SOAPEnvelope.java b/fine-third-jdk11/src/javax/xml/soap/SOAPEnvelope.java new file mode 100644 index 000000000..a9bafbe09 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/SOAPEnvelope.java @@ -0,0 +1,217 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + + +/** + * The container for the SOAPHeader and SOAPBody portions of a + * {@code SOAPPart} object. By default, a {@code SOAPMessage} + * object is created with a {@code SOAPPart} object that has a + * {@code SOAPEnvelope} object. The {@code SOAPEnvelope} object + * by default has an empty {@code SOAPBody} object and an empty + * {@code SOAPHeader} object. The {@code SOAPBody} object is + * required, and the {@code SOAPHeader} object, though + * optional, is used in the majority of cases. If the + * {@code SOAPHeader} object is not needed, it can be deleted, + * which is shown later. + *

+ * A client can access the {@code SOAPHeader} and {@code SOAPBody} + * objects by calling the methods {@code SOAPEnvelope.getHeader} and + * {@code SOAPEnvelope.getBody}. The + * following lines of code use these two methods after starting with + * the {@code SOAPMessage} + * object message to get the {@code SOAPPart} object sp, + * which is then used to get the {@code SOAPEnvelope} object se. + * + *

{@code
+ *     SOAPPart sp = message.getSOAPPart();
+ *     SOAPEnvelope se = sp.getEnvelope();
+ *     SOAPHeader sh = se.getHeader();
+ *     SOAPBody sb = se.getBody();
+ * }
+ *

+ * It is possible to change the body or header of a {@code SOAPEnvelope} + * object by retrieving the current one, deleting it, and then adding + * a new body or header. The {@code javax.xml.soap.Node} method + * {@code deleteNode} deletes the XML element (node) on which it is + * called. For example, the following line of code deletes the + * {@code SOAPBody} object that is retrieved by the method {@code getBody}. + *

{@code
+ *      se.getBody().detachNode();
+ * }
+ * To create a {@code SOAPHeader} object to replace the one that was removed, + * a client uses + * the method {@code SOAPEnvelope.addHeader}, which creates a new header and + * adds it to the {@code SOAPEnvelope} object. Similarly, the method + * {@code addBody} creates a new {@code SOAPBody} object and adds + * it to the {@code SOAPEnvelope} object. The following code fragment + * retrieves the current header, removes it, and adds a new one. Then + * it retrieves the current body, removes it, and adds a new one. + * + *
{@code
+ *     SOAPPart sp = message.getSOAPPart();
+ *     SOAPEnvelope se = sp.getEnvelope();
+ *     se.getHeader().detachNode();
+ *     SOAPHeader sh = se.addHeader();
+ *     se.getBody().detachNode();
+ *     SOAPBody sb = se.addBody();
+ * }
+ * It is an error to add a {@code SOAPBody} or {@code SOAPHeader} + * object if one already exists. + *

+ * The {@code SOAPEnvelope} interface provides three methods for creating + * {@code Name} objects. One method creates {@code Name} objects with + * a local name, a namespace prefix, and a namesapce URI. The second method creates + * {@code Name} objects with a local name and a namespace prefix, and the third + * creates {@code Name} objects with just a local name. The following line of + * code, in which se is a {@code SOAPEnvelope} object, creates a new + * {@code Name} object with all three. + *

{@code
+ *     Name name = se.createName("GetLastTradePrice", "WOMBAT",
+ *                                "http://www.wombat.org/trader");
+ * }
+ * + * @since 1.6 + */ +public interface SOAPEnvelope extends SOAPElement { + + /** + * Creates a new {@code Name} object initialized with the + * given local name, namespace prefix, and namespace URI. + *

+ * This factory method creates {@code Name} objects for use in + * the SOAP/XML document. + * + * @param localName a {@code String} giving the local name + * @param prefix a {@code String} giving the prefix of the namespace + * @param uri a {@code String} giving the URI of the namespace + * @return a {@code Name} object initialized with the given + * local name, namespace prefix, and namespace URI + * @throws SOAPException if there is a SOAP error + */ + public abstract Name createName(String localName, String prefix, + String uri) + throws SOAPException; + + /** + * Creates a new {@code Name} object initialized with the + * given local name. + *

+ * This factory method creates {@code Name} objects for use in + * the SOAP/XML document. + * + * @param localName a {@code String} giving the local name + * @return a {@code Name} object initialized with the given + * local name + * @throws SOAPException if there is a SOAP error + */ + public abstract Name createName(String localName) + throws SOAPException; + + /** + * Returns the {@code SOAPHeader} object for + * this {@code SOAPEnvelope} object. + *

+ * A new {@code SOAPMessage} object is by default created with a + * {@code SOAPEnvelope} object that contains an empty + * {@code SOAPHeader} object. As a result, the method + * {@code getHeader} will always return a {@code SOAPHeader} + * object unless the header has been removed and a new one has not + * been added. + * + * @return the {@code SOAPHeader} object or {@code null} if + * there is none + * @exception SOAPException if there is a problem obtaining the + * {@code SOAPHeader} object + */ + public SOAPHeader getHeader() throws SOAPException; + + /** + * Returns the {@code SOAPBody} object associated with this + * {@code SOAPEnvelope} object. + *

+ * A new {@code SOAPMessage} object is by default created with a + * {@code SOAPEnvelope} object that contains an empty + * {@code SOAPBody} object. As a result, the method + * {@code getBody} will always return a {@code SOAPBody} + * object unless the body has been removed and a new one has not + * been added. + * + * @return the {@code SOAPBody} object for this + * {@code SOAPEnvelope} object or {@code null} + * if there is none + * @exception SOAPException if there is a problem obtaining the + * {@code SOAPBody} object + */ + public SOAPBody getBody() throws SOAPException; + /** + * Creates a {@code SOAPHeader} object and sets it as the + * {@code SOAPHeader} object for this {@code SOAPEnvelope} + * object. + *

+ * It is illegal to add a header when the envelope already + * contains a header. Therefore, this method should be called + * only after the existing header has been removed. + * + * @return the new {@code SOAPHeader} object + * + * @exception SOAPException if this + * {@code SOAPEnvelope} object already contains a + * valid {@code SOAPHeader} object + */ + public SOAPHeader addHeader() throws SOAPException; + /** + * Creates a {@code SOAPBody} object and sets it as the + * {@code SOAPBody} object for this {@code SOAPEnvelope} + * object. + *

+ * It is illegal to add a body when the envelope already + * contains a body. Therefore, this method should be called + * only after the existing body has been removed. + * + * @return the new {@code SOAPBody} object + * + * @exception SOAPException if this + * {@code SOAPEnvelope} object already contains a + * valid {@code SOAPBody} object + */ + public SOAPBody addBody() throws SOAPException; +} diff --git a/fine-third-jdk11/src/javax/xml/soap/SOAPException.java b/fine-third-jdk11/src/javax/xml/soap/SOAPException.java new file mode 100644 index 000000000..375f950d8 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/SOAPException.java @@ -0,0 +1,186 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +/** + * An exception that signals that a SOAP exception has occurred. A + * {@code SOAPException} object may contain a {@code String} + * that gives the reason for the exception, an embedded + * {@code Throwable} object, or both. This class provides methods + * for retrieving reason messages and for retrieving the embedded + * {@code Throwable} object. + * + *

Typical reasons for throwing a {@code SOAPException} + * object are problems such as difficulty setting a header, not being + * able to send a message, and not being able to get a connection with + * the provider. Reasons for embedding a {@code Throwable} + * object include problems such as input/output errors or a parsing + * problem, such as an error in parsing a header. + * + * @since 1.6 + */ +public class SOAPException extends Exception { + private Throwable cause; + + /** + * Constructs a {@code SOAPException} object with no + * reason or embedded {@code Throwable} object. + */ + public SOAPException() { + super(); + this.cause = null; + } + + /** + * Constructs a {@code SOAPException} object with the given + * {@code String} as the reason for the exception being thrown. + * + * @param reason a description of what caused the exception + */ + public SOAPException(String reason) { + super(reason); + this.cause = null; + } + + /** + * Constructs a {@code SOAPException} object with the given + * {@code String} as the reason for the exception being thrown + * and the given {@code Throwable} object as an embedded + * exception. + * + * @param reason a description of what caused the exception + * @param cause a {@code Throwable} object that is to + * be embedded in this {@code SOAPException} object + */ + public SOAPException(String reason, Throwable cause) { + super(reason); + initCause(cause); + } + + /** + * Constructs a {@code SOAPException} object initialized + * with the given {@code Throwable} object. + * + * @param cause a {@code Throwable} object that is to + * be embedded in this {@code SOAPException} object + */ + public SOAPException(Throwable cause) { + super(cause.toString()); + initCause(cause); + } + + /** + * Returns the detail message for this {@code SOAPException} + * object. + *

+ * If there is an embedded {@code Throwable} object, and if the + * {@code SOAPException} object has no detail message of its + * own, this method will return the detail message from the embedded + * {@code Throwable} object. + * + * @return the error or warning message for this + * {@code SOAPException} or, if it has none, the + * message of the embedded {@code Throwable} object, + * if there is one + */ + @Override + public String getMessage() { + String message = super.getMessage(); + if (message == null && cause != null) { + return cause.getMessage(); + } else { + return message; + } + } + + /** + * Returns the {@code Throwable} object embedded in this + * {@code SOAPException} if there is one. Otherwise, this method + * returns {@code null}. + * + * @return the embedded {@code Throwable} object or {@code null} + * if there is none + */ + + @Override + public Throwable getCause() { + return cause; + } + + /** + * Initializes the {@code cause} field of this {@code SOAPException} + * object with the given {@code Throwable} object. + *

+ * This method can be called at most once. It is generally called from + * within the constructor or immediately after the constructor has + * returned a new {@code SOAPException} object. + * If this {@code SOAPException} object was created with the + * constructor {@link #SOAPException(Throwable)} or + * {@link #SOAPException(String,Throwable)}, meaning that its + * {@code cause} field already has a value, this method cannot be + * called even once. + * + * @param cause the {@code Throwable} object that caused this + * {@code SOAPException} object to be thrown. The value of this + * parameter is saved for later retrieval by the + * {@link #getCause()} method. A {@code null} value is + * permitted and indicates that the cause is nonexistent or + * unknown. + * @return a reference to this {@code SOAPException} instance + * @throws IllegalArgumentException if {@code cause} is this + * {@code Throwable} object. (A {@code Throwable} object + * cannot be its own cause.) + * @throws IllegalStateException if the cause for this {@code SOAPException} object + * has already been initialized + */ + @Override + public synchronized Throwable initCause(Throwable cause) { + if (this.cause != null) { + throw new IllegalStateException("Can't override cause"); + } + if (cause == this) { + throw new IllegalArgumentException("Self-causation not permitted"); + } + this.cause = cause; + + return this; + } +} diff --git a/fine-third-jdk11/src/javax/xml/soap/SOAPFactory.java b/fine-third-jdk11/src/javax/xml/soap/SOAPFactory.java new file mode 100644 index 000000000..c2442a96e --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/SOAPFactory.java @@ -0,0 +1,305 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +import javax.xml.namespace.QName; + +import org.w3c.dom.Element; + +/** + * {@code SOAPFactory} is a factory for creating various objects + * that exist in the SOAP XML tree. + + * {@code SOAPFactory} can be + * used to create XML fragments that will eventually end up in the + * SOAP part. These fragments can be inserted as children of the + * {@link SOAPHeaderElement} or {@link SOAPBodyElement} or + * {@link SOAPEnvelope} or other {@link SOAPElement} objects. + * + * {@code SOAPFactory} also has methods to create + * {@code javax.xml.soap.Detail} objects as well as + * {@code java.xml.soap.Name} objects. + * + * @since 1.6 + */ +public abstract class SOAPFactory { + + /** + * Class name of default {@code SOAPFactory} implementation. + */ + private static final String DEFAULT_SOAP_FACTORY + = "com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPFactory1_1Impl"; + + /** + * Creates a {@code SOAPElement} object from an existing DOM + * {@code Element}. If the DOM {@code Element} that is passed in + * as an argument is already a {@code SOAPElement} then this method + * must return it unmodified without any further work. Otherwise, a new + * {@code SOAPElement} is created and a deep copy is made of the + * {@code domElement} argument. The concrete type of the return value + * will depend on the name of the {@code domElement} argument. If any + * part of the tree rooted in {@code domElement} violates SOAP rules, a + * {@code SOAPException} will be thrown. + * + * @param domElement the {@code Element} to be copied. + * + * @return a new {@code SOAPElement} that is a copy of {@code domElement}. + * + * @exception SOAPException if there is an error in creating the + * {@code SOAPElement} object + * + * @since 1.6, SAAJ 1.3 + */ + public SOAPElement createElement(Element domElement) throws SOAPException { + throw new UnsupportedOperationException("createElement(org.w3c.dom.Element) must be overridden by all subclasses of SOAPFactory."); + } + + /** + * Creates a {@code SOAPElement} object initialized with the + * given {@code Name} object. The concrete type of the return value + * will depend on the name given to the new {@code SOAPElement}. For + * instance, a new {@code SOAPElement} with the name + * "{http://www.w3.org/2003/05/soap-envelope}Envelope" would cause a + * {@code SOAPEnvelope} that supports SOAP 1.2 behavior to be created. + * + * @param name a {@code Name} object with the XML name for + * the new element + * + * @return the new {@code SOAPElement} object that was + * created + * + * @exception SOAPException if there is an error in creating the + * {@code SOAPElement} object + * @see SOAPFactory#createElement(javax.xml.namespace.QName) + */ + public abstract SOAPElement createElement(Name name) throws SOAPException; + + /** + * Creates a {@code SOAPElement} object initialized with the + * given {@code QName} object. The concrete type of the return value + * will depend on the name given to the new {@code SOAPElement}. For + * instance, a new {@code SOAPElement} with the name + * "{http://www.w3.org/2003/05/soap-envelope}Envelope" would cause a + * {@code SOAPEnvelope} that supports SOAP 1.2 behavior to be created. + * + * @param qname a {@code QName} object with the XML name for + * the new element + * + * @return the new {@code SOAPElement} object that was + * created + * + * @exception SOAPException if there is an error in creating the + * {@code SOAPElement} object + * @see SOAPFactory#createElement(Name) + * @since 1.6, SAAJ 1.3 + */ + public SOAPElement createElement(QName qname) throws SOAPException { + throw new UnsupportedOperationException("createElement(QName) must be overridden by all subclasses of SOAPFactory."); + } + + /** + * Creates a {@code SOAPElement} object initialized with the + * given local name. + * + * @param localName a {@code String} giving the local name for + * the new element + * + * @return the new {@code SOAPElement} object that was + * created + * + * @exception SOAPException if there is an error in creating the + * {@code SOAPElement} object + */ + public abstract SOAPElement createElement(String localName) + throws SOAPException; + + + /** + * Creates a new {@code SOAPElement} object with the given + * local name, prefix and uri. The concrete type of the return value + * will depend on the name given to the new {@code SOAPElement}. For + * instance, a new {@code SOAPElement} with the name + * "{http://www.w3.org/2003/05/soap-envelope}Envelope" would cause a + * {@code SOAPEnvelope} that supports SOAP 1.2 behavior to be created. + * + * @param localName a {@code String} giving the local name + * for the new element + * @param prefix the prefix for this {@code SOAPElement} + * @param uri a {@code String} giving the URI of the + * namespace to which the new element belongs + * @return the new {@code SOAPElement} object that was + * created + * + * @exception SOAPException if there is an error in creating the + * {@code SOAPElement} object + */ + public abstract SOAPElement createElement( + String localName, + String prefix, + String uri) + throws SOAPException; + + /** + * Creates a new {@code Detail} object which serves as a container + * for {@code DetailEntry} objects. + *

+ * This factory method creates {@code Detail} objects for use in + * situations where it is not practical to use the {@code SOAPFault} + * abstraction. + * + * @return a {@code Detail} object + * @throws SOAPException if there is a SOAP error + * @throws UnsupportedOperationException if the protocol specified + * for the SOAPFactory was {@code DYNAMIC_SOAP_PROTOCOL} + */ + public abstract Detail createDetail() throws SOAPException; + + /** + *Creates a new {@code SOAPFault} object initialized with the given {@code reasonText} + * and {@code faultCode} + *@param reasonText the ReasonText/FaultString for the fault + *@param faultCode the FaultCode for the fault + *@return a {@code SOAPFault} object + *@throws SOAPException if there is a SOAP error + *@since 1.6, SAAJ 1.3 + */ + public abstract SOAPFault createFault(String reasonText, QName faultCode) throws SOAPException; + + /** + *Creates a new default {@code SOAPFault} object + *@return a {@code SOAPFault} object + *@throws SOAPException if there is a SOAP error + *@since 1.6, SAAJ 1.3 + */ + public abstract SOAPFault createFault() throws SOAPException; + + /** + * Creates a new {@code Name} object initialized with the + * given local name, namespace prefix, and namespace URI. + *

+ * This factory method creates {@code Name} objects for use in + * situations where it is not practical to use the {@code SOAPEnvelope} + * abstraction. + * + * @param localName a {@code String} giving the local name + * @param prefix a {@code String} giving the prefix of the namespace + * @param uri a {@code String} giving the URI of the namespace + * @return a {@code Name} object initialized with the given + * local name, namespace prefix, and namespace URI + * @throws SOAPException if there is a SOAP error + */ + public abstract Name createName( + String localName, + String prefix, + String uri) + throws SOAPException; + + /** + * Creates a new {@code Name} object initialized with the + * given local name. + *

+ * This factory method creates {@code Name} objects for use in + * situations where it is not practical to use the {@code SOAPEnvelope} + * abstraction. + * + * @param localName a {@code String} giving the local name + * @return a {@code Name} object initialized with the given + * local name + * @throws SOAPException if there is a SOAP error + */ + public abstract Name createName(String localName) throws SOAPException; + + /** + * Creates a new {@code SOAPFactory} object that is an instance of + * the default implementation (SOAP 1.1). + * + * This method uses the lookup procedure specified in {@link javax.xml.soap} to locate and load the + * {@link javax.xml.soap.SOAPFactory} class. + * + * @return a new instance of a {@code SOAPFactory} + * + * @exception SOAPException if there was an error creating the + * default {@code SOAPFactory} + * @see SAAJMetaFactory + */ + public static SOAPFactory newInstance() + throws SOAPException + { + try { + SOAPFactory factory = FactoryFinder.find( + SOAPFactory.class, + DEFAULT_SOAP_FACTORY, + false); + if (factory != null) return factory; + + // leave it on SAAJMetaFactory + return newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); + } catch (Exception ex) { + throw new SOAPException( + "Unable to create SOAP Factory: " + ex.getMessage()); + } + + } + + /** + * Creates a new {@code SOAPFactory} object that is an instance of + * the specified implementation, this method uses the SAAJMetaFactory to + * locate the implementation class and create the SOAPFactory instance. + * + * @return a new instance of a {@code SOAPFactory} + * + * @param protocol a string constant representing the protocol of the + * specified SOAP factory implementation. May be + * either {@code DYNAMIC_SOAP_PROTOCOL}, + * {@code DEFAULT_SOAP_PROTOCOL} (which is the same + * as) {@code SOAP_1_1_PROTOCOL}, or + * {@code SOAP_1_2_PROTOCOL}. + * + * @exception SOAPException if there was an error creating the + * specified {@code SOAPFactory} + * @see SAAJMetaFactory + * @since 1.6, SAAJ 1.3 + */ + public static SOAPFactory newInstance(String protocol) + throws SOAPException { + return SAAJMetaFactory.getInstance().newSOAPFactory(protocol); + } +} diff --git a/fine-third-jdk11/src/javax/xml/soap/SOAPFault.java b/fine-third-jdk11/src/javax/xml/soap/SOAPFault.java new file mode 100644 index 000000000..d483cedf4 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/SOAPFault.java @@ -0,0 +1,530 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +import java.util.Iterator; +import java.util.Locale; + +import javax.xml.namespace.QName; + +/** + * An element in the {@code SOAPBody} object that contains + * error and/or status information. This information may relate to + * errors in the {@code SOAPMessage} object or to problems + * that are not related to the content in the message itself. Problems + * not related to the message itself are generally errors in + * processing, such as the inability to communicate with an upstream + * server. + *

+ * Depending on the {@code protocol} specified while creating the + * {@code MessageFactory} instance, a {@code SOAPFault} has + * sub-elements as defined in the SOAP 1.1/SOAP 1.2 specification. + * + * @since 1.6 + */ +public interface SOAPFault extends SOAPBodyElement { + + /** + * Sets this {@code SOAPFault} object with the given fault code. + * + *

Fault codes, which give information about the fault, are defined + * in the SOAP 1.1 specification. A fault code is mandatory and must + * be of type {@code Name}. This method provides a convenient + * way to set a fault code. For example, + * + *

{@code
+     * SOAPEnvelope se = ...;
+     * // Create a qualified name in the SOAP namespace with a localName
+     * // of "Client". Note that prefix parameter is optional and is null
+     * // here which causes the implementation to use an appropriate prefix.
+     * Name qname = se.createName("Client", null,
+     *                            SOAPConstants.URI_NS_SOAP_ENVELOPE);
+     * SOAPFault fault = ...;
+     * fault.setFaultCode(qname);
+     * }
+ * It is preferable to use this method over {@link #setFaultCode(String)}. + * + * @param faultCodeQName a {@code Name} object giving the fault + * code to be set. It must be namespace qualified. + * @see #getFaultCodeAsName + * + * @exception SOAPException if there was an error in adding the + * faultcode element to the underlying XML tree. + * + * @since 1.6, SAAJ 1.2 + */ + public void setFaultCode(Name faultCodeQName) throws SOAPException; + + /** + * Sets this {@code SOAPFault} object with the given fault code. + * + * It is preferable to use this method over {@link #setFaultCode(Name)}. + * + * @param faultCodeQName a {@code QName} object giving the fault + * code to be set. It must be namespace qualified. + * @see #getFaultCodeAsQName + * + * @exception SOAPException if there was an error in adding the + * {@code faultcode} element to the underlying XML tree. + * + * @see #setFaultCode(Name) + * @see #getFaultCodeAsQName() + * + * @since 1.6, SAAJ 1.3 + */ + public void setFaultCode(QName faultCodeQName) throws SOAPException; + + /** + * Sets this {@code SOAPFault} object with the give fault code. + *

+ * Fault codes, which given information about the fault, are defined in + * the SOAP 1.1 specification. This element is mandatory in SOAP 1.1. + * Because the fault code is required to be a QName it is preferable to + * use the {@link #setFaultCode(Name)} form of this method. + * + * @param faultCode a {@code String} giving the fault code to be set. + * It must be of the form "prefix:localName" where the prefix has + * been defined in a namespace declaration. + * @see #setFaultCode(Name) + * @see #getFaultCode + * @see SOAPElement#addNamespaceDeclaration + * + * @exception SOAPException if there was an error in adding the + * {@code faultCode} to the underlying XML tree. + */ + public void setFaultCode(String faultCode) throws SOAPException; + + /** + * Gets the mandatory SOAP 1.1 fault code for this + * {@code SOAPFault} object as a SAAJ {@code Name} object. + * The SOAP 1.1 specification requires the value of the "faultcode" + * element to be of type QName. This method returns the content of the + * element as a QName in the form of a SAAJ Name object. This method + * should be used instead of the {@code getFaultCode} method since + * it allows applications to easily access the namespace name without + * additional parsing. + * + * @return a {@code Name} representing the faultcode + * @see #setFaultCode(Name) + * + * @since 1.6, SAAJ 1.2 + */ + public Name getFaultCodeAsName(); + + + /** + * Gets the fault code for this + * {@code SOAPFault} object as a {@code QName} object. + * + * @return a {@code QName} representing the faultcode + * + * @see #setFaultCode(QName) + * + * @since 1.6, SAAJ 1.3 + */ + public QName getFaultCodeAsQName(); + + /** + * Gets the Subcodes for this {@code SOAPFault} as an iterator over + * {@code QNames}. + * + * @return an {@code Iterator} that accesses a sequence of + * {@code QNames}. This {@code Iterator} should not support + * the optional {@code remove} method. The order in which the + * Subcodes are returned reflects the hierarchy of Subcodes present + * in the fault from top to bottom. + * + * @exception UnsupportedOperationException if this message does not + * support the SOAP 1.2 concept of Subcode. + * + * @since 1.6, SAAJ 1.3 + */ + public Iterator getFaultSubcodes(); + + /** + * Removes any Subcodes that may be contained by this + * {@code SOAPFault}. Subsequent calls to + * {@code getFaultSubcodes} will return an empty iterator until a call + * to {@code appendFaultSubcode} is made. + * + * @exception UnsupportedOperationException if this message does not + * support the SOAP 1.2 concept of Subcode. + * + * @since 1.6, SAAJ 1.3 + */ + public void removeAllFaultSubcodes(); + + /** + * Adds a Subcode to the end of the sequence of Subcodes contained by this + * {@code SOAPFault}. Subcodes, which were introduced in SOAP 1.2, are + * represented by a recursive sequence of subelements rooted in the + * mandatory Code subelement of a SOAP Fault. + * + * @param subcode a QName containing the Value of the Subcode. + * + * @exception SOAPException if there was an error in setting the Subcode + * @exception UnsupportedOperationException if this message does not + * support the SOAP 1.2 concept of Subcode. + * + * @since 1.6, SAAJ 1.3 + */ + public void appendFaultSubcode(QName subcode) throws SOAPException; + + /** + * Gets the fault code for this {@code SOAPFault} object. + * + * @return a {@code String} with the fault code + * @see #getFaultCodeAsName + * @see #setFaultCode + */ + public String getFaultCode(); + + /** + * Sets this {@code SOAPFault} object with the given fault actor. + *

+ * The fault actor is the recipient in the message path who caused the + * fault to happen. + *

+ * If this {@code SOAPFault} supports SOAP 1.2 then this call is + * equivalent to {@link #setFaultRole(String)} + * + * @param faultActor a {@code String} identifying the actor that + * caused this {@code SOAPFault} object + * @see #getFaultActor + * + * @exception SOAPException if there was an error in adding the + * {@code faultActor} to the underlying XML tree. + */ + public void setFaultActor(String faultActor) throws SOAPException; + + /** + * Gets the fault actor for this {@code SOAPFault} object. + *

+ * If this {@code SOAPFault} supports SOAP 1.2 then this call is + * equivalent to {@link #getFaultRole()} + * + * @return a {@code String} giving the actor in the message path + * that caused this {@code SOAPFault} object + * @see #setFaultActor + */ + public String getFaultActor(); + + /** + * Sets the fault string for this {@code SOAPFault} object + * to the given string. + *

+ * If this + * {@code SOAPFault} is part of a message that supports SOAP 1.2 then + * this call is equivalent to: + *

{@code
+     *      addFaultReasonText(faultString, Locale.getDefault());
+     * }
+ * + * @param faultString a {@code String} giving an explanation of + * the fault + * @see #getFaultString + * + * @exception SOAPException if there was an error in adding the + * {@code faultString} to the underlying XML tree. + */ + public void setFaultString(String faultString) throws SOAPException; + + /** + * Sets the fault string for this {@code SOAPFault} object + * to the given string and localized to the given locale. + *

+ * If this + * {@code SOAPFault} is part of a message that supports SOAP 1.2 then + * this call is equivalent to: + *

{@code
+     *      addFaultReasonText(faultString, locale);
+     * }
+ * + * @param faultString a {@code String} giving an explanation of + * the fault + * @param locale a {@link java.util.Locale Locale} object indicating + * the native language of the {@code faultString} + * @see #getFaultString + * + * @exception SOAPException if there was an error in adding the + * {@code faultString} to the underlying XML tree. + * + * @since 1.6, SAAJ 1.2 + */ + public void setFaultString(String faultString, Locale locale) + throws SOAPException; + + /** + * Gets the fault string for this {@code SOAPFault} object. + *

+ * If this + * {@code SOAPFault} is part of a message that supports SOAP 1.2 then + * this call is equivalent to: + *

{@code
+     *    String reason = null;
+     *    try {
+     *        reason = (String) getFaultReasonTexts().next();
+     *    } catch (SOAPException e) {}
+     *    return reason;
+     * }
+ * + * @return a {@code String} giving an explanation of + * the fault + * @see #setFaultString(String) + * @see #setFaultString(String, Locale) + */ + public String getFaultString(); + + /** + * Gets the locale of the fault string for this {@code SOAPFault} + * object. + *

+ * If this + * {@code SOAPFault} is part of a message that supports SOAP 1.2 then + * this call is equivalent to: + *

{@code
+     *    Locale locale = null;
+     *    try {
+     *        locale = (Locale) getFaultReasonLocales().next();
+     *    } catch (SOAPException e) {}
+     *    return locale;
+     * }
+ * + * @return a {@code Locale} object indicating the native language of + * the fault string or {@code null} if no locale was specified + * @see #setFaultString(String, Locale) + * + * @since 1.6, SAAJ 1.2 + */ + public Locale getFaultStringLocale(); + + /** + * Returns true if this {@code SOAPFault} has a {@code Detail} + * subelement and false otherwise. Equivalent to + * {@code (getDetail()!=null)}. + * + * @return true if this {@code SOAPFault} has a {@code Detail} + * subelement and false otherwise. + * + * @since 1.6, SAAJ 1.3 + */ + public boolean hasDetail(); + + /** + * Returns the optional detail element for this {@code SOAPFault} + * object. + *

+ * A {@code Detail} object carries application-specific error + * information, the scope of the error information is restricted to + * faults in the {@code SOAPBodyElement} objects if this is a + * SOAP 1.1 Fault. + * + * @return a {@code Detail} object with application-specific + * error information if present, null otherwise + */ + public Detail getDetail(); + + /** + * Creates an optional {@code Detail} object and sets it as the + * {@code Detail} object for this {@code SOAPFault} + * object. + *

+ * It is illegal to add a detail when the fault already + * contains a detail. Therefore, this method should be called + * only after the existing detail has been removed. + * + * @return the new {@code Detail} object + * + * @exception SOAPException if this + * {@code SOAPFault} object already contains a + * valid {@code Detail} object + */ + public Detail addDetail() throws SOAPException; + + /** + * Returns an {@code Iterator} over a distinct sequence of + * {@code Locale}s for which there are associated Reason Text items. + * Any of these {@code Locale}s can be used in a call to + * {@code getFaultReasonText} in order to obtain a localized version + * of the Reason Text string. + * + * @return an {@code Iterator} over a sequence of {@code Locale} + * objects for which there are associated Reason Text items. + * + * @exception SOAPException if there was an error in retrieving + * the fault Reason locales. + * @exception UnsupportedOperationException if this message does not + * support the SOAP 1.2 concept of Fault Reason. + * + * @since 1.6, SAAJ 1.3 + */ + public Iterator getFaultReasonLocales() throws SOAPException; + + /** + * Returns an {@code Iterator} over a sequence of + * {@code String} objects containing all of the Reason Text items for + * this {@code SOAPFault}. + * + * @return an {@code Iterator} over env:Fault/env:Reason/env:Text items. + * + * @exception SOAPException if there was an error in retrieving + * the fault Reason texts. + * @exception UnsupportedOperationException if this message does not + * support the SOAP 1.2 concept of Fault Reason. + * + * @since 1.6, SAAJ 1.3 + */ + public Iterator getFaultReasonTexts() throws SOAPException; + + /** + * Returns the Reason Text associated with the given {@code Locale}. + * If more than one such Reason Text exists the first matching Text is + * returned + * + * @param locale -- the {@code Locale} for which a localized + * Reason Text is desired + * + * @return the Reason Text associated with {@code locale} + * + * @see #getFaultString + * + * @exception SOAPException if there was an error in retrieving + * the fault Reason text for the specified locale . + * @exception UnsupportedOperationException if this message does not + * support the SOAP 1.2 concept of Fault Reason. + * + * @since 1.6, SAAJ 1.3 + */ + public String getFaultReasonText(Locale locale) throws SOAPException; + + /** + * Appends or replaces a Reason Text item containing the specified + * text message and an xml:lang derived from + * {@code locale}. If a Reason Text item with this + * xml:lang already exists its text value will be replaced + * with {@code text}. + * The {@code locale} parameter should not be {@code null} + *

+ * Code sample: + * + *

{@code
+     * SOAPFault fault = ...;
+     * fault.addFaultReasonText("Version Mismatch", Locale.ENGLISH);
+     * }
+ * + * @param text -- reason message string + * @param locale -- Locale object representing the locale of the message + * + * @exception SOAPException if there was an error in adding the Reason text + * or the {@code locale} passed was {@code null}. + * @exception UnsupportedOperationException if this message does not + * support the SOAP 1.2 concept of Fault Reason. + * + * @since 1.6, SAAJ 1.3 + */ + public void addFaultReasonText(String text, java.util.Locale locale) + throws SOAPException; + + /** + * Returns the optional Node element value for this + * {@code SOAPFault} object. The Node element is + * optional in SOAP 1.2. + * + * @return Content of the env:Fault/env:Node element as a String + * or {@code null} if none + * + * @exception UnsupportedOperationException if this message does not + * support the SOAP 1.2 concept of Fault Node. + * + * @since 1.6, SAAJ 1.3 + */ + public String getFaultNode(); + + /** + * Creates or replaces any existing Node element value for + * this {@code SOAPFault} object. The Node element + * is optional in SOAP 1.2. + * + * @param uri the URI of the Node + * + * @exception SOAPException if there was an error in setting the + * Node for this {@code SOAPFault} object. + * @exception UnsupportedOperationException if this message does not + * support the SOAP 1.2 concept of Fault Node. + * + * + * @since 1.6, SAAJ 1.3 + */ + public void setFaultNode(String uri) throws SOAPException; + + /** + * Returns the optional Role element value for this + * {@code SOAPFault} object. The Role element is + * optional in SOAP 1.2. + * + * @return Content of the env:Fault/env:Role element as a String + * or {@code null} if none + * + * @exception UnsupportedOperationException if this message does not + * support the SOAP 1.2 concept of Fault Role. + * + * @since 1.6, SAAJ 1.3 + */ + public String getFaultRole(); + + /** + * Creates or replaces any existing Role element value for + * this {@code SOAPFault} object. The Role element + * is optional in SOAP 1.2. + * + * @param uri the URI of the Role + * + * @exception SOAPException if there was an error in setting the + * Role for this {@code SOAPFault} object. + * + * @exception UnsupportedOperationException if this message does not + * support the SOAP 1.2 concept of Fault Role. + * + * @since 1.6, SAAJ 1.3 + */ + public void setFaultRole(String uri) throws SOAPException; + +} diff --git a/fine-third-jdk11/src/javax/xml/soap/SOAPFaultElement.java b/fine-third-jdk11/src/javax/xml/soap/SOAPFaultElement.java new file mode 100644 index 000000000..511974159 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/SOAPFaultElement.java @@ -0,0 +1,54 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +/** + * A representation of the contents in + * a {@code SOAPFault} object. The {@code Detail} interface + * is a {@code SOAPFaultElement}. + *

+ * Content is added to a {@code SOAPFaultElement} using the + * {@code SOAPElement} method {@code addTextNode}. + * + * @since 1.6 + */ +public interface SOAPFaultElement extends SOAPElement { +} diff --git a/fine-third-jdk11/src/javax/xml/soap/SOAPHeader.java b/fine-third-jdk11/src/javax/xml/soap/SOAPHeader.java new file mode 100644 index 000000000..cdc7fb9df --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/SOAPHeader.java @@ -0,0 +1,278 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +import java.util.Iterator; + +import javax.xml.namespace.QName; + +/** + * A representation of the SOAP header + * element. A SOAP header element consists of XML data that affects + * the way the application-specific content is processed by the message + * provider. For example, transaction semantics, authentication information, + * and so on, can be specified as the content of a {@code SOAPHeader} + * object. + *

+ * A {@code SOAPEnvelope} object contains an empty + * {@code SOAPHeader} object by default. If the {@code SOAPHeader} + * object, which is optional, is not needed, it can be retrieved and deleted + * with the following line of code. The variable se is a + * {@code SOAPEnvelope} object. + *

{@code
+ *      se.getHeader().detachNode();
+ * }
+ * + * A {@code SOAPHeader} object is created with the {@code SOAPEnvelope} + * method {@code addHeader}. This method, which creates a new header and adds it + * to the envelope, may be called only after the existing header has been removed. + * + *
{@code
+ *      se.getHeader().detachNode();
+ *      SOAPHeader sh = se.addHeader();
+ * }
+ *

+ * A {@code SOAPHeader} object can have only {@code SOAPHeaderElement} + * objects as its immediate children. The method {@code addHeaderElement} + * creates a new {@code HeaderElement} object and adds it to the + * {@code SOAPHeader} object. In the following line of code, the + * argument to the method {@code addHeaderElement} is a {@code Name} + * object that is the name for the new {@code HeaderElement} object. + *

{@code
+ *      SOAPHeaderElement shElement = sh.addHeaderElement(name);
+ * }
+ * + * @see SOAPHeaderElement + * @since 1.6 + */ +public interface SOAPHeader extends SOAPElement { + /** + * Creates a new {@code SOAPHeaderElement} object initialized with the + * specified name and adds it to this {@code SOAPHeader} object. + * + * @param name a {@code Name} object with the name of the new + * {@code SOAPHeaderElement} object + * @return the new {@code SOAPHeaderElement} object that was + * inserted into this {@code SOAPHeader} object + * @exception SOAPException if a SOAP error occurs + * @see SOAPHeader#addHeaderElement(javax.xml.namespace.QName) + */ + public SOAPHeaderElement addHeaderElement(Name name) + throws SOAPException; + + /** + * Creates a new {@code SOAPHeaderElement} object initialized with the + * specified qname and adds it to this {@code SOAPHeader} object. + * + * @param qname a {@code QName} object with the qname of the new + * {@code SOAPHeaderElement} object + * @return the new {@code SOAPHeaderElement} object that was + * inserted into this {@code SOAPHeader} object + * @exception SOAPException if a SOAP error occurs + * @see SOAPHeader#addHeaderElement(Name) + * @since 1.6, SAAJ 1.3 + */ + public SOAPHeaderElement addHeaderElement(QName qname) + throws SOAPException; + + /** + * Returns an {@code Iterator} over all the {@code SOAPHeaderElement} objects + * in this {@code SOAPHeader} object + * that have the specified actor and that have a MustUnderstand attribute + * whose value is equivalent to {@code true}. + *

+ * In SOAP 1.2 the env:actor attribute is replaced by the env:role + * attribute, but with essentially the same semantics. + * + * @param actor a {@code String} giving the URI of the {@code actor} / {@code role} + * for which to search + * @return an {@code Iterator} object over all the + * {@code SOAPHeaderElement} objects that contain the specified + * {@code actor} / {@code role} and are marked as MustUnderstand + * @see #examineHeaderElements + * @see #extractHeaderElements + * @see SOAPConstants#URI_SOAP_ACTOR_NEXT + * + * @since 1.6, SAAJ 1.2 + */ + public Iterator examineMustUnderstandHeaderElements(String actor); + + /** + * Returns an {@code Iterator} over all the {@code SOAPHeaderElement} objects + * in this {@code SOAPHeader} object + * that have the specified actor. + * + * An actor is a global attribute that indicates the intermediate + * parties that should process a message before it reaches its ultimate + * receiver. An actor receives the message and processes it before sending + * it on to the next actor. The default actor is the ultimate intended + * recipient for the message, so if no actor attribute is included in a + * {@code SOAPHeader} object, it is sent to the ultimate receiver + * along with the message body. + *

+ * In SOAP 1.2 the env:actor attribute is replaced by the env:role + * attribute, but with essentially the same semantics. + * + * @param actor a {@code String} giving the URI of the {@code actor} / {@code role} + * for which to search + * @return an {@code Iterator} object over all the + * {@code SOAPHeaderElement} objects that contain the specified + * {@code actor} / {@code role} + * @see #extractHeaderElements + * @see SOAPConstants#URI_SOAP_ACTOR_NEXT + */ + public Iterator examineHeaderElements(String actor); + + /** + * Returns an {@code Iterator} over all the {@code SOAPHeaderElement} objects + * in this {@code SOAPHeader} object + * that have the specified actor and detaches them + * from this {@code SOAPHeader} object. + *

+ * This method allows an actor to process the parts of the + * {@code SOAPHeader} object that apply to it and to remove + * them before passing the message on to the next actor. + *

+ * In SOAP 1.2 the env:actor attribute is replaced by the env:role + * attribute, but with essentially the same semantics. + * + * @param actor a {@code String} giving the URI of the {@code actor} / {@code role} + * for which to search + * @return an {@code Iterator} object over all the + * {@code SOAPHeaderElement} objects that contain the specified + * {@code actor} / {@code role} + * + * @see #examineHeaderElements + * @see SOAPConstants#URI_SOAP_ACTOR_NEXT + */ + public Iterator extractHeaderElements(String actor); + + /** + * Creates a new NotUnderstood {@code SOAPHeaderElement} object initialized + * with the specified name and adds it to this {@code SOAPHeader} object. + * This operation is supported only by SOAP 1.2. + * + * @param name a {@code QName} object with the name of the + * {@code SOAPHeaderElement} object that was not understood. + * @return the new {@code SOAPHeaderElement} object that was + * inserted into this {@code SOAPHeader} object + * @exception SOAPException if a SOAP error occurs. + * @exception UnsupportedOperationException if this is a SOAP 1.1 Header. + * @since 1.6, SAAJ 1.3 + */ + public SOAPHeaderElement addNotUnderstoodHeaderElement(QName name) + throws SOAPException; + + /** + * Creates a new Upgrade {@code SOAPHeaderElement} object initialized + * with the specified List of supported SOAP URIs and adds it to this + * {@code SOAPHeader} object. + * This operation is supported on both SOAP 1.1 and SOAP 1.2 header. + * + * @param supportedSOAPURIs an {@code Iterator} object with the URIs of SOAP + * versions supported. + * @return the new {@code SOAPHeaderElement} object that was + * inserted into this {@code SOAPHeader} object + * @exception SOAPException if a SOAP error occurs. + * @since 1.6, SAAJ 1.3 + */ + public SOAPHeaderElement addUpgradeHeaderElement(Iterator supportedSOAPURIs) + throws SOAPException; + + /** + * Creates a new Upgrade {@code SOAPHeaderElement} object initialized + * with the specified array of supported SOAP URIs and adds it to this + * {@code SOAPHeader} object. + * This operation is supported on both SOAP 1.1 and SOAP 1.2 header. + * + * @param supportedSoapUris an array of the URIs of SOAP versions supported. + * @return the new {@code SOAPHeaderElement} object that was + * inserted into this {@code SOAPHeader} object + * @exception SOAPException if a SOAP error occurs. + * @since 1.6, SAAJ 1.3 + */ + public SOAPHeaderElement addUpgradeHeaderElement(String[] supportedSoapUris) + throws SOAPException; + + /** + * Creates a new Upgrade {@code SOAPHeaderElement} object initialized + * with the specified supported SOAP URI and adds it to this + * {@code SOAPHeader} object. + * This operation is supported on both SOAP 1.1 and SOAP 1.2 header. + * + * @param supportedSoapUri the URI of SOAP the version that is supported. + * @return the new {@code SOAPHeaderElement} object that was + * inserted into this {@code SOAPHeader} object + * @exception SOAPException if a SOAP error occurs. + * @since 1.6, SAAJ 1.3 + */ + public SOAPHeaderElement addUpgradeHeaderElement(String supportedSoapUri) + throws SOAPException; + + /** + * Returns an {@code Iterator} over all the {@code SOAPHeaderElement} objects + * in this {@code SOAPHeader} object. + * + * @return an {@code Iterator} object over all the + * {@code SOAPHeaderElement} objects contained by this + * {@code SOAPHeader} + * @see #extractAllHeaderElements + * + * @since 1.6, SAAJ 1.2 + */ + public Iterator examineAllHeaderElements(); + + /** + * Returns an {@code Iterator} over all the {@code SOAPHeaderElement} objects + * in this {@code SOAPHeader} object and detaches them + * from this {@code SOAPHeader} object. + * + * @return an {@code Iterator} object over all the + * {@code SOAPHeaderElement} objects contained by this + * {@code SOAPHeader} + * + * @see #examineAllHeaderElements + * + * @since 1.6, SAAJ 1.2 + */ + public Iterator extractAllHeaderElements(); + +} diff --git a/fine-third-jdk11/src/javax/xml/soap/SOAPHeaderElement.java b/fine-third-jdk11/src/javax/xml/soap/SOAPHeaderElement.java new file mode 100644 index 000000000..c63403a80 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/SOAPHeaderElement.java @@ -0,0 +1,183 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +/** + * An object representing the contents in the SOAP header part of the + * SOAP envelope. + * The immediate children of a {@code SOAPHeader} object can + * be represented only as {@code SOAPHeaderElement} objects. + *

+ * A {@code SOAPHeaderElement} object can have other + * {@code SOAPElement} objects as its children. + * + * @since 1.6 + */ +public interface SOAPHeaderElement extends SOAPElement { + + /** + * Sets the actor associated with this {@code SOAPHeaderElement} + * object to the specified actor. The default value of an actor is: + * {@code SOAPConstants.URI_SOAP_ACTOR_NEXT} + *

+ * If this {@code SOAPHeaderElement} supports SOAP 1.2 then this call is + * equivalent to {@link #setRole(String)} + * + * @param actorURI a {@code String} giving the URI of the actor + * to set + * + * @exception IllegalArgumentException if there is a problem in + * setting the actor. + * + * @see #getActor + */ + public void setActor(String actorURI); + + /** + * Sets the {@code Role} associated with this {@code SOAPHeaderElement} + * object to the specified {@code Role}. + * + * @param uri the URI of the {@code Role} + * + * @throws SOAPException if there is an error in setting the role + * + * @exception UnsupportedOperationException if this message does not + * support the SOAP 1.2 concept of Fault Role. + * + * @since 1.6, SAAJ 1.3 + */ + public void setRole(String uri) throws SOAPException; + + /** + * Returns the uri of the actor attribute of this + * {@code SOAPHeaderElement}. + *

+ * If this {@code SOAPHeaderElement} supports SOAP 1.2 then this call is + * equivalent to {@link #getRole()} + * @return a {@code String} giving the URI of the actor + * @see #setActor + */ + public String getActor(); + + /** + * Returns the value of the Role attribute of this + * {@code SOAPHeaderElement}. + * + * @return a {@code String} giving the URI of the {@code Role} + * + * @exception UnsupportedOperationException if this message does not + * support the SOAP 1.2 concept of Fault Role. + * + * @since 1.6, SAAJ 1.3 + */ + public String getRole(); + + /** + * Sets the mustUnderstand attribute for this {@code SOAPHeaderElement} + * object to be either true or false. + *

+ * If the mustUnderstand attribute is on, the actor who receives the + * {@code SOAPHeaderElement} must process it correctly. This + * ensures, for example, that if the {@code SOAPHeaderElement} + * object modifies the message, that the message is being modified correctly. + * + * @param mustUnderstand {@code true} to set the mustUnderstand + * attribute to true; {@code false} to set it to false + * + * @exception IllegalArgumentException if there is a problem in + * setting the mustUnderstand attribute + * @see #getMustUnderstand + * @see #setRelay + */ + public void setMustUnderstand(boolean mustUnderstand); + + /** + * Returns the boolean value of the mustUnderstand attribute for this + * {@code SOAPHeaderElement}. + * + * @return {@code true} if the mustUnderstand attribute of this + * {@code SOAPHeaderElement} object is turned on; {@code false} + * otherwise + */ + public boolean getMustUnderstand(); + + /** + * Sets the relay attribute for this {@code SOAPHeaderElement} to be + * either true or false. + *

+ * The SOAP relay attribute is set to true to indicate that the SOAP header + * block must be relayed by any node that is targeted by the header block + * but not actually process it. This attribute is ignored on header blocks + * whose mustUnderstand attribute is set to true or that are targeted at + * the ultimate reciever (which is the default). The default value of this + * attribute is {@code false}. + * + * @param relay the new value of the relay attribute + * + * @exception SOAPException if there is a problem in setting the + * relay attribute. + * @exception UnsupportedOperationException if this message does not + * support the SOAP 1.2 concept of Relay attribute. + * + * @see #setMustUnderstand + * @see #getRelay + * + * @since 1.6, SAAJ 1.3 + */ + public void setRelay(boolean relay) throws SOAPException; + + /** + * Returns the boolean value of the relay attribute for this + * {@code SOAPHeaderElement} + * + * @return {@code true} if the relay attribute is turned on; + * {@code false} otherwise + * + * @exception UnsupportedOperationException if this message does not + * support the SOAP 1.2 concept of Relay attribute. + * + * @see #getMustUnderstand + * @see #setRelay + * + * @since 1.6, SAAJ 1.3 + */ + public boolean getRelay(); +} diff --git a/fine-third-jdk11/src/javax/xml/soap/SOAPMessage.java b/fine-third-jdk11/src/javax/xml/soap/SOAPMessage.java new file mode 100644 index 000000000..4fef939af --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/SOAPMessage.java @@ -0,0 +1,470 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; +import java.io.OutputStream; +import java.io.IOException; + +import java.util.Iterator; + +import javax.activation.DataHandler; + +/** + * The root class for all SOAP messages. As transmitted on the "wire", a SOAP + * message is an XML document or a MIME message whose first body part is an + * XML/SOAP document. + *

+ * A {@code SOAPMessage} object consists of a SOAP part and optionally + * one or more attachment parts. The SOAP part for a {@code SOAPMessage} + * object is a {@code SOAPPart} object, which contains information used + * for message routing and identification, and which can contain + * application-specific content. All data in the SOAP Part of a message must be + * in XML format. + *

+ * A new {@code SOAPMessage} object contains the following by default: + *

    + *
  • A {@code SOAPPart} object + *
  • A {@code SOAPEnvelope} object + *
  • A {@code SOAPBody} object + *
  • A {@code SOAPHeader} object + *
+ * The SOAP part of a message can be retrieved by calling the method {@code SOAPMessage.getSOAPPart()}. + * The {@code SOAPEnvelope} object is retrieved from the {@code SOAPPart} + * object, and the {@code SOAPEnvelope} object is used to retrieve the + * {@code SOAPBody} and {@code SOAPHeader} objects. + * + *
{@code
+ *     SOAPPart sp = message.getSOAPPart();
+ *     SOAPEnvelope se = sp.getEnvelope();
+ *     SOAPBody sb = se.getBody();
+ *     SOAPHeader sh = se.getHeader();
+ * }
+ * + *

+ * In addition to the mandatory {@code SOAPPart} object, a {@code SOAPMessage} + * object may contain zero or more {@code AttachmentPart} objects, each + * of which contains application-specific data. The {@code SOAPMessage} + * interface provides methods for creating {@code AttachmentPart} + * objects and also for adding them to a {@code SOAPMessage} object. A + * party that has received a {@code SOAPMessage} object can examine its + * contents by retrieving individual attachment parts. + *

+ * Unlike the rest of a SOAP message, an attachment is not required to be in + * XML format and can therefore be anything from simple text to an image file. + * Consequently, any message content that is not in XML format must be in an + * {@code AttachmentPart} object. + *

+ * A {@code MessageFactory} object may create {@code SOAPMessage} + * objects with behavior that is specialized to a particular implementation or + * application of SAAJ. For instance, a {@code MessageFactory} object + * may produce {@code SOAPMessage} objects that conform to a particular + * Profile such as ebXML. In this case a {@code MessageFactory} object + * might produce {@code SOAPMessage} objects that are initialized with + * ebXML headers. + *

+ * In order to ensure backward source compatibility, methods that are added to + * this class after version 1.1 of the SAAJ specification are all concrete + * instead of abstract and they all have default implementations. Unless + * otherwise noted in the JavaDocs for those methods the default + * implementations simply throw an {@code UnsupportedOperationException} + * and the SAAJ implementation code must override them with methods that + * provide the specified behavior. Legacy client code does not have this + * restriction, however, so long as there is no claim made that it conforms to + * some later version of the specification than it was originally written for. + * A legacy class that extends the SOAPMessage class can be compiled and/or run + * against succeeding versions of the SAAJ API without modification. If such a + * class was correctly implemented then it will continue to behave correctly + * relative to the version of the specification against which it was written. + * + * @see MessageFactory + * @see AttachmentPart + * @since 1.6 + */ +public abstract class SOAPMessage { + + /** + * Specifies the character type encoding for the SOAP Message. Valid values + * include "utf-8" and "utf-16". See vendor documentation for additional + * supported values. The default is "utf-8". + * + * @see SOAPMessage#setProperty(String, Object) SOAPMessage.setProperty + * @since 1.6, SAAJ 1.2 + */ + public static final String CHARACTER_SET_ENCODING = + "javax.xml.soap.character-set-encoding"; + + /** + * Specifies whether the SOAP Message will contain an XML declaration when + * it is sent. The only valid values are "true" and "false". The default is + * "false". + * + * @see SOAPMessage#setProperty(String, Object) SOAPMessage.setProperty + * @since 1.6, SAAJ 1.2 + */ + public static final String WRITE_XML_DECLARATION = + "javax.xml.soap.write-xml-declaration"; + + /** + * Sets the description of this {@code SOAPMessage} object's + * content with the given description. + * + * @param description a {@code String} describing the content of this + * message + * @see #getContentDescription + */ + public abstract void setContentDescription(String description); + + /** + * Retrieves a description of this {@code SOAPMessage} object's + * content. + * + * @return a {@code String} describing the content of this + * message or {@code null} if no description has been set + * @see #setContentDescription + */ + public abstract String getContentDescription(); + + /** + * Gets the SOAP part of this {@code SOAPMessage} object. + *

+ * {@code SOAPMessage} object contains one or more attachments, the + * SOAP Part must be the first MIME body part in the message. + * + * @return the {@code SOAPPart} object for this {@code SOAPMessage} + * object + */ + public abstract SOAPPart getSOAPPart(); + + /** + * Gets the SOAP Body contained in this {@code SOAPMessage} object. + * + * @return the {@code SOAPBody} object contained by this {@code SOAPMessage} + * object + * @throws SOAPException if the SOAP Body does not exist or cannot be retrieved + * @since 1.6, SAAJ 1.2 + */ + public SOAPBody getSOAPBody() throws SOAPException { + throw new UnsupportedOperationException("getSOAPBody must be overridden by all subclasses of SOAPMessage"); + } + + /** + * Gets the SOAP Header contained in this {@code SOAPMessage} object. + * + * @return the {@code SOAPHeader} object contained + * by this {@code SOAPMessage} object + * @exception SOAPException + * if the SOAP Header does not exist or cannot be retrieved + * @since 1.6, SAAJ 1.2 + */ + public SOAPHeader getSOAPHeader() throws SOAPException { + throw new UnsupportedOperationException("getSOAPHeader must be overridden by all subclasses of SOAPMessage"); + } + + /** + * Removes all {@code AttachmentPart} objects that have been added + * to this {@code SOAPMessage} object. + *

+ * This method does not touch the SOAP part. + */ + public abstract void removeAllAttachments(); + + /** + * Gets a count of the number of attachments in this message. This count + * does not include the SOAP part. + * + * @return the number of {@code AttachmentPart} objects that are + * part of this {@code SOAPMessage} object + */ + public abstract int countAttachments(); + + /** + * Retrieves all the {@code AttachmentPart} objects that are part of + * this {@code SOAPMessage} object. + * + * @return an iterator over all the attachments in this message + */ + public abstract Iterator getAttachments(); + + /** + * Retrieves all the {@code AttachmentPart} objects that have header + * entries that match the specified headers. Note that a returned + * attachment could have headers in addition to those specified. + * + * @param headers a {@code MimeHeaders} object containing the MIME + * headers for which to search + * @return an iterator over all attachments that have a header that matches + * one of the given headers + */ + public abstract Iterator getAttachments(MimeHeaders headers); + + /** + * Removes all the {@code AttachmentPart} objects that have header + * entries that match the specified headers. Note that the removed + * attachment could have headers in addition to those specified. + * + * @param headers + * a {@code MimeHeaders} object containing the MIME + * headers for which to search + * @since 1.6, SAAJ 1.3 + */ + public abstract void removeAttachments(MimeHeaders headers); + + + /** + * Returns an {@code AttachmentPart} object that is associated with an + * attachment that is referenced by this {@code SOAPElement} or + * {@code null} if no such attachment exists. References can be made + * via an {@code href} attribute as described in + * SOAP Messages with Attachments, + * or via a single {@code Text} child node containing a URI as + * described in the WS-I Attachments Profile 1.0 for elements of schema + * type ref:swaRef. + * These two mechanisms must be supported. + * The support for references via {@code href} attribute also implies that + * this method should also be supported on an element that is an + * xop:Include element ( + * XOP). + * other reference mechanisms may be supported by individual + * implementations of this standard. Contact your vendor for details. + * + * @param element The {@code SOAPElement} containing the reference to an Attachment + * @return the referenced {@code AttachmentPart} or null if no such + * {@code AttachmentPart} exists or no reference can be + * found in this {@code SOAPElement}. + * @throws SOAPException if there is an error in the attempt to access the + * attachment + * + * @since 1.6, SAAJ 1.3 + */ + public abstract AttachmentPart getAttachment(SOAPElement element) throws SOAPException; + + + /** + * Adds the given {@code AttachmentPart} object to this {@code SOAPMessage} + * object. An {@code AttachmentPart} object must be created before + * it can be added to a message. + * + * @param attachmentPart + * an {@code attachmentPart} object that is to become part + * of this {@code SOAPMessage} object + * @exception IllegalArgumentException + * if there was a problem with the specified {@code attachmentPart} + * object + */ + public abstract void addAttachmentPart(AttachmentPart attachmentPart); + + /** + * Creates a new empty {@code AttachmentPart} object. Note that the + * method {@code addAttachmentPart} must be called with this new + * {@code AttachmentPart} object as the parameter in order for it to + * become an attachment to this {@code SOAPMessage} object. + * + * @return a new {@code AttachmentPart} object that can be populated + * and added to this {@code SOAPMessage} object + */ + public abstract AttachmentPart createAttachmentPart(); + + /** + * Creates an {@code AttachmentPart} object and populates it using + * the given {@code DataHandler} object. + * + * @param dataHandler + * the {@code javax.activation.DataHandler} object that + * will generate the content for this {@code SOAPMessage} + * object + * @return a new {@code AttachmentPart} object that contains data + * generated by the given {@code DataHandler} object + * @exception IllegalArgumentException + * if there was a problem with the specified {@code DataHandler} + * object + * @see javax.activation.DataHandler + * @see javax.activation.DataContentHandler + */ + public AttachmentPart createAttachmentPart(DataHandler dataHandler) { + AttachmentPart attachment = createAttachmentPart(); + attachment.setDataHandler(dataHandler); + return attachment; + } + + /** + * Returns all the transport-specific MIME headers for this {@code SOAPMessage} + * object in a transport-independent fashion. + * + * @return a {@code MimeHeaders} object containing the {@code MimeHeader} + * objects + */ + public abstract MimeHeaders getMimeHeaders(); + + /** + * Creates an {@code AttachmentPart} object and populates it with + * the specified data of the specified content type. The type of the + * {@code Object} should correspond to the value given for the + * {@code Content-Type}. + * + * @param content + * an {@code Object} containing the content for the + * {@code AttachmentPart} object to be created + * @param contentType + * a {@code String} object giving the type of content; + * examples are "text/xml", "text/plain", and "image/jpeg" + * @return a new {@code AttachmentPart} object that contains the + * given data + * @exception IllegalArgumentException + * may be thrown if the contentType does not match the type + * of the content object, or if there was no + * {@code DataContentHandler} object for the given + * content object + * @see javax.activation.DataHandler + * @see javax.activation.DataContentHandler + */ + public AttachmentPart createAttachmentPart( + Object content, + String contentType) { + AttachmentPart attachment = createAttachmentPart(); + attachment.setContent(content, contentType); + return attachment; + } + + /** + * Updates this {@code SOAPMessage} object with all the changes that + * have been made to it. This method is called automatically when + * {@link SOAPMessage#writeTo(OutputStream)} is called. However, if + * changes are made to a message that was received or to one that has + * already been sent, the method {@code saveChanges} needs to be + * called explicitly in order to save the changes. The method {@code saveChanges} + * also generates any changes that can be read back (for example, a + * MessageId in profiles that support a message id). All MIME headers in a + * message that is created for sending purposes are guaranteed to have + * valid values only after {@code saveChanges} has been called. + *

+ * In addition, this method marks the point at which the data from all + * constituent {@code AttachmentPart} objects are pulled into the + * message. + * + * @exception SOAPException if there was a problem saving + * changes to this message. + */ + public abstract void saveChanges() throws SOAPException; + + /** + * Indicates whether this {@code SOAPMessage} object needs to have + * the method {@code saveChanges} called on it. + * + * @return {@code true} if {@code saveChanges} needs to be + * called; {@code false} otherwise. + */ + public abstract boolean saveRequired(); + + /** + * Writes this {@code SOAPMessage} object to the given output + * stream. The externalization format is as defined by the SOAP 1.1 with + * Attachments specification. + *

+ * If there are no attachments, just an XML stream is written out. For + * those messages that have attachments, {@code writeTo} writes a + * MIME-encoded byte stream. + *

+ * Note that this method does not write the transport-specific MIME Headers + * of the Message + * + * @param out + * the {@code OutputStream} object to which this {@code SOAPMessage} + * object will be written + * @exception IOException + * if an I/O error occurs + * @exception SOAPException + * if there was a problem in externalizing this SOAP message + */ + public abstract void writeTo(OutputStream out) + throws SOAPException, IOException; + + /** + * Associates the specified value with the specified property. If there was + * already a value associated with this property, the old value is + * replaced. + *

+ * The valid property names include + * {@link SOAPMessage#WRITE_XML_DECLARATION} and + * {@link SOAPMessage#CHARACTER_SET_ENCODING}. All of these standard SAAJ + * properties are prefixed by "javax.xml.soap". Vendors may also add + * implementation specific properties. These properties must be prefixed + * with package names that are unique to the vendor. + *

+ * Setting the property {@code WRITE_XML_DECLARATION} to {@code "true"} + * will cause an XML Declaration to be written out at the start of the SOAP + * message. The default value of "false" suppresses this declaration. + *

+ * The property {@code CHARACTER_SET_ENCODING} defaults to the value + * {@code "utf-8"} which causes the SOAP message to be encoded using + * UTF-8. Setting {@code CHARACTER_SET_ENCODING} to {@code "utf-16"} + * causes the SOAP message to be encoded using UTF-16. + *

+ * Some implementations may allow encodings in addition to UTF-8 and + * UTF-16. Refer to your vendor's documentation for details. + * + * @param property + * the property with which the specified value is to be + * associated. + * @param value + * the value to be associated with the specified property + * @exception SOAPException + * if the property name is not recognized. + * @since 1.6, SAAJ 1.2 + */ + public void setProperty(String property, Object value) + throws SOAPException { + throw new UnsupportedOperationException("setProperty must be overridden by all subclasses of SOAPMessage"); + } + + /** + * Retrieves value of the specified property. + * + * @param property + * the name of the property to retrieve + * @return the value associated with the named property or {@code null} + * if no such property exists. + * @exception SOAPException + * if the property name is not recognized. + * @since 1.6, SAAJ 1.2 + */ + public Object getProperty(String property) throws SOAPException { + throw new UnsupportedOperationException("getProperty must be overridden by all subclasses of SOAPMessage"); + } +} diff --git a/fine-third-jdk11/src/javax/xml/soap/SOAPPart.java b/fine-third-jdk11/src/javax/xml/soap/SOAPPart.java new file mode 100644 index 000000000..5d314fb95 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/SOAPPart.java @@ -0,0 +1,281 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +import java.util.Iterator; + +import javax.xml.transform.Source; + +/** + * The container for the SOAP-specific portion of a {@code SOAPMessage} + * object. All messages are required to have a SOAP part, so when a + * {@code SOAPMessage} object is created, it will automatically + * have a {@code SOAPPart} object. + *

+ * A {@code SOAPPart} object is a MIME part and has the MIME headers + * Content-Id, Content-Location, and Content-Type. Because the value of + * Content-Type must be "text/xml", a {@code SOAPPart} object automatically + * has a MIME header of Content-Type with its value set to "text/xml". + * The value must be "text/xml" because content in the SOAP part of a + * message must be in XML format. Content that is not of type "text/xml" + * must be in an {@code AttachmentPart} object rather than in the + * {@code SOAPPart} object. + *

+ * When a message is sent, its SOAP part must have the MIME header Content-Type + * set to "text/xml". Or, from the other perspective, the SOAP part of any + * message that is received must have the MIME header Content-Type with a + * value of "text/xml". + *

+ * A client can access the {@code SOAPPart} object of a + * {@code SOAPMessage} object by + * calling the method {@code SOAPMessage.getSOAPPart}. The + * following line of code, in which {@code message} is a + * {@code SOAPMessage} object, retrieves the SOAP part of a message. + *

{@code
+ *   SOAPPart soapPart = message.getSOAPPart();
+ * }
+ *

+ * A {@code SOAPPart} object contains a {@code SOAPEnvelope} object, + * which in turn contains a {@code SOAPBody} object and a + * {@code SOAPHeader} object. + * The {@code SOAPPart} method {@code getEnvelope} can be used + * to retrieve the {@code SOAPEnvelope} object. + * + * @since 1.6 + */ +public abstract class SOAPPart implements org.w3c.dom.Document, Node { + + /** + * Gets the {@code SOAPEnvelope} object associated with this + * {@code SOAPPart} object. Once the SOAP envelope is obtained, it + * can be used to get its contents. + * + * @return the {@code SOAPEnvelope} object for this + * {@code SOAPPart} object + * @exception SOAPException if there is a SOAP error + */ + public abstract SOAPEnvelope getEnvelope() throws SOAPException; + + /** + * Retrieves the value of the MIME header whose name is "Content-Id". + * + * @return a {@code String} giving the value of the MIME header + * named "Content-Id" + * @see #setContentId + */ + public String getContentId() { + String[] values = getMimeHeader("Content-Id"); + if (values != null && values.length > 0) + return values[0]; + return null; + } + + /** + * Retrieves the value of the MIME header whose name is "Content-Location". + * + * @return a {@code String} giving the value of the MIME header whose + * name is "Content-Location" + * @see #setContentLocation + */ + public String getContentLocation() { + String[] values = getMimeHeader("Content-Location"); + if (values != null && values.length > 0) + return values[0]; + return null; + } + + /** + * Sets the value of the MIME header named "Content-Id" + * to the given {@code String}. + * + * @param contentId a {@code String} giving the value of the MIME + * header "Content-Id" + * + * @exception IllegalArgumentException if there is a problem in + * setting the content id + * @see #getContentId + */ + public void setContentId(String contentId) + { + setMimeHeader("Content-Id", contentId); + } + /** + * Sets the value of the MIME header "Content-Location" + * to the given {@code String}. + * + * @param contentLocation a {@code String} giving the value + * of the MIME + * header "Content-Location" + * @exception IllegalArgumentException if there is a problem in + * setting the content location. + * @see #getContentLocation + */ + public void setContentLocation(String contentLocation) + { + setMimeHeader("Content-Location", contentLocation); + } + /** + * Removes all MIME headers that match the given name. + * + * @param header a {@code String} giving the name of the MIME header(s) to + * be removed + */ + public abstract void removeMimeHeader(String header); + + /** + * Removes all the {@code MimeHeader} objects for this + * {@code SOAPEnvelope} object. + */ + public abstract void removeAllMimeHeaders(); + + /** + * Gets all the values of the {@code MimeHeader} object + * in this {@code SOAPPart} object that + * is identified by the given {@code String}. + * + * @param name the name of the header; example: "Content-Type" + * @return a {@code String} array giving all the values for the + * specified header + * @see #setMimeHeader + */ + public abstract String[] getMimeHeader(String name); + + /** + * Changes the first header entry that matches the given header name + * so that its value is the given value, adding a new header with the + * given name and value if no + * existing header is a match. If there is a match, this method clears + * all existing values for the first header that matches and sets the + * given value instead. If more than one header has + * the given name, this method removes all of the matching headers after + * the first one. + *

+ * Note that RFC822 headers can contain only US-ASCII characters. + * + * @param name a {@code String} giving the header name + * for which to search + * @param value a {@code String} giving the value to be set. + * This value will be substituted for the current value(s) + * of the first header that is a match if there is one. + * If there is no match, this value will be the value for + * a new {@code MimeHeader} object. + * + * @exception IllegalArgumentException if there was a problem with + * the specified mime header name or value + * @see #getMimeHeader + */ + public abstract void setMimeHeader(String name, String value); + + /** + * Creates a {@code MimeHeader} object with the specified + * name and value and adds it to this {@code SOAPPart} object. + * If a {@code MimeHeader} with the specified name already + * exists, this method adds the specified value to the already + * existing value(s). + *

+ * Note that RFC822 headers can contain only US-ASCII characters. + * + * @param name a {@code String} giving the header name + * @param value a {@code String} giving the value to be set + * or added + * @exception IllegalArgumentException if there was a problem with + * the specified mime header name or value + */ + public abstract void addMimeHeader(String name, String value); + + /** + * Retrieves all the headers for this {@code SOAPPart} object + * as an iterator over the {@code MimeHeader} objects. + * + * @return an {@code Iterator} object with all of the Mime + * headers for this {@code SOAPPart} object + */ + public abstract Iterator getAllMimeHeaders(); + + /** + * Retrieves all {@code MimeHeader} objects that match a name in + * the given array. + * + * @param names a {@code String} array with the name(s) of the + * MIME headers to be returned + * @return all of the MIME headers that match one of the names in the + * given array, returned as an {@code Iterator} object + */ + public abstract Iterator getMatchingMimeHeaders(String[] names); + + /** + * Retrieves all {@code MimeHeader} objects whose name does + * not match a name in the given array. + * + * @param names a {@code String} array with the name(s) of the + * MIME headers not to be returned + * @return all of the MIME headers in this {@code SOAPPart} object + * except those that match one of the names in the + * given array. The nonmatching MIME headers are returned as an + * {@code Iterator} object. + */ + public abstract Iterator getNonMatchingMimeHeaders(String[] names); + + /** + * Sets the content of the {@code SOAPEnvelope} object with the data + * from the given {@code Source} object. This {@code Source} + * must contain a valid SOAP document. + * + * @param source the {@code javax.xml.transform.Source} object with the + * data to be set + * + * @exception SOAPException if there is a problem in setting the source + * @see #getContent + */ + public abstract void setContent(Source source) throws SOAPException; + + /** + * Returns the content of the SOAPEnvelope as a JAXP {@code Source} + * object. + * + * @return the content as a {@code javax.xml.transform.Source} object + * + * @exception SOAPException if the implementation cannot convert + * the specified {@code Source} object + * @see #setContent + */ + public abstract Source getContent() throws SOAPException; +} diff --git a/fine-third-jdk11/src/javax/xml/soap/ServiceLoaderUtil.java b/fine-third-jdk11/src/javax/xml/soap/ServiceLoaderUtil.java new file mode 100644 index 000000000..97f950d1a --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/ServiceLoaderUtil.java @@ -0,0 +1,139 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2016-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +import java.util.ServiceLoader; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Shared ServiceLoader/FactoryFinder Utils shared among SAAJ, JAXB and JAXWS + * Class duplicated to all those projects. + * + * @author Miroslav.Kos@oracle.com + */ +class ServiceLoaderUtil { + + static P firstByServiceLoader(Class

spiClass, + Logger logger, + ExceptionHandler handler) throws T { + logger.log(Level.FINE, "Using java.util.ServiceLoader to find {0}", spiClass.getName()); + // service discovery + try { + ServiceLoader

serviceLoader = ServiceLoader.load(spiClass); + + for (P impl : serviceLoader) { + logger.log(Level.FINE, "ServiceProvider loading Facility used; returning object [{0}]", impl.getClass().getName()); + + return impl; + } + } catch (Throwable t) { + throw handler.createException(t, "Error while searching for service [" + spiClass.getName() + "]"); + } + return null; + } + + static void checkPackageAccess(String className) { + // make sure that the current thread has an access to the package of the given name. + SecurityManager s = System.getSecurityManager(); + if (s != null) { + int i = className.lastIndexOf('.'); + if (i != -1) { + s.checkPackageAccess(className.substring(0, i)); + } + } + } + + static Class nullSafeLoadClass(String className, ClassLoader classLoader) throws ClassNotFoundException { + if (classLoader == null) { + return Class.forName(className); + } else { + return classLoader.loadClass(className); + } + } + + // Returns instance of required class. It checks package access (security) + // unless it is defaultClassname. It means if you are trying to instantiate + // default implementation (fallback), pass the class name to both first and second parameter. + static Object newInstance(String className, + String defaultImplClassName, ClassLoader classLoader, + final ExceptionHandler handler) throws T { + try { + return safeLoadClass(className, defaultImplClassName, classLoader).newInstance(); + } catch (ClassNotFoundException x) { + throw handler.createException(x, "Provider " + className + " not found"); + } catch (Exception x) { + throw handler.createException(x, "Provider " + className + " could not be instantiated: " + x); + } + } + + static Class safeLoadClass(String className, + String defaultImplClassName, + ClassLoader classLoader) throws ClassNotFoundException { + + try { + checkPackageAccess(className); + } catch (SecurityException se) { + // anyone can access the platform default factory class without permission + if (defaultImplClassName != null && defaultImplClassName.equals(className)) { + return Class.forName(className); + } + // not platform default implementation ... + throw se; + } + return nullSafeLoadClass(className, classLoader); + } + + static ClassLoader contextClassLoader(ExceptionHandler exceptionHandler) throws T { + try { + return Thread.currentThread().getContextClassLoader(); + } catch (Exception x) { + throw exceptionHandler.createException(x, x.toString()); + } + } + + static abstract class ExceptionHandler { + + public abstract T createException(Throwable throwable, String message); + + } + +} diff --git a/fine-third-jdk11/src/javax/xml/soap/Text.java b/fine-third-jdk11/src/javax/xml/soap/Text.java new file mode 100644 index 000000000..451d8e249 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/Text.java @@ -0,0 +1,58 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2004-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.soap; + +/** + * A representation of a node whose value is text. A {@code Text} object + * may represent text that is content or text that is a comment. + * + * @since 1.6 + */ +public interface Text extends Node, org.w3c.dom.Text { + + /** + * Retrieves whether this {@code Text} object represents a comment. + * + * @return {@code true} if this {@code Text} object is a + * comment; {@code false} otherwise + */ + public boolean isComment(); +} diff --git a/fine-third-jdk11/src/javax/xml/soap/package-info.java b/fine-third-jdk11/src/javax/xml/soap/package-info.java new file mode 100644 index 000000000..8a816a35f --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/soap/package-info.java @@ -0,0 +1,121 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +/** + * Provides the API for creating and building SOAP messages. This package + * is defined in the SOAP with Attachments API for Java™ (SAAJ) 1.4 specification. + * + *

The API in the javax.xml.soap package allows you to do the following: + * + *

    + *
  • create a point-to-point connection to a specified endpoint + *
  • create a SOAP message + *
  • create an XML fragment + *
  • add content to the header of a SOAP message + *
  • add content to the body of a SOAP message + *
  • create attachment parts and add content to them + *
  • access/add/modify parts of a SOAP message + *
  • create/add/modify SOAP fault information + *
  • extract content from a SOAP message + *
  • send a SOAP request-response message + *
+ * + *

+ * In addition the APIs in the javax.xml.soap package extend + * their counterparts in the org.w3c.dom package. This means that + * the SOAPPart of a SOAPMessage is also a DOM Level + * 2 Document, and can be manipulated as such by applications, + * tools and libraries that use DOM (see http://www.w3.org/DOM/ for more information). + * It is important to note that, while it is possible to use DOM APIs to add + * ordinary DOM nodes to a SAAJ tree, the SAAJ APIs are still required to return + * SAAJ types when examining or manipulating the tree. In order to accomplish + * this the SAAJ APIs (specifically {@link javax.xml.soap.SOAPElement#getChildElements()}) + * are allowed to silently replace objects that are incorrectly typed relative + * to SAAJ requirements with equivalent objects of the required type. These + * replacements must never cause the logical structure of the tree to change, + * so from the perspective of the DOM APIs the tree will remain unchanged. However, + * the physical composition of the tree will have changed so that references + * to the nodes that were replaced will refer to nodes that are no longer a + * part of the tree. The SAAJ APIs are not allowed to make these replacements + * if they are not required so the replacement objects will never subsequently + * be silently replaced by future calls to the SAAJ API. + *

+ * What this means in practical terms is that an application that starts to use + * SAAJ APIs on a tree after manipulating it using DOM APIs must assume that the + * tree has been translated into an all SAAJ tree and that any references to objects + * within the tree that were obtained using DOM APIs are no longer valid. Switching + * from SAAJ APIs to DOM APIs is not allowed to cause invalid references and + * neither is using SAAJ APIs exclusively. It is only switching from using DOM + * APIs on a particular SAAJ tree to using SAAJ APIs that causes the risk of + * invalid references. + * + *

Discovery of SAAJ implementation

+ *

+ * There are several factories defined in the SAAJ API to discover and load specific implementation: + * + *

    + *
  • {@link javax.xml.soap.SOAPFactory} + *
  • {@link javax.xml.soap.MessageFactory} + *
  • {@link javax.xml.soap.SOAPConnectionFactory} + *
  • {@link javax.xml.soap.SAAJMetaFactory} + *
+ * + * First three define {@code newInstance()} method which uses a common lookup procedure to determine + * the implementation class: + * + *
    + *
  • Checks if a system property with the same name as the factory class is set (e.g. + * {@code javax.xml.soap.SOAPFactory}). If such property exists then its value is assumed to be the fully qualified + * name of the implementation class. This phase of the look up enables per-JVM override of the SAAJ implementation. + *
  • Use the configuration file "jaxm.properties". The file is in standard + * {@link java.util.Properties} format and typically located in the + * {@code conf} directory of the Java installation. It contains the fully qualified + * name of the implementation class with the key being the system property + * defined above. + *
  • Use the service-provider loading facilities, defined by the {@link java.util.ServiceLoader} class, + * to attempt to locate and load an implementation of the service using the {@linkplain + * java.util.ServiceLoader#load(java.lang.Class) default loading mechanism}. + *
  • Finally, if all the steps above fail, {@link javax.xml.soap.SAAJMetaFactory} instance is used + * to locate specific implementation (for {@link javax.xml.soap.MessageFactory} and {@link javax.xml.soap.SOAPFactory}) + * or platform default implementation is used ({@link javax.xml.soap.SOAPConnectionFactory}). + * Whenever {@link javax.xml.soap.SAAJMetaFactory} is used, its lookup procedure to get actual instance is performed. + *
+ */ +package javax.xml.soap; diff --git a/fine-third-jdk11/src/javax/xml/ws/Action.java b/fine-third-jdk11/src/javax/xml/ws/Action.java new file mode 100644 index 000000000..1a1370ac3 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/Action.java @@ -0,0 +1,169 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * The {@code Action} annotation allows explicit association of a + * WS-Addressing {@code Action} message addressing property with + * {@code input}, {@code output}, and + * {@code fault} messages of the mapped WSDL operation. + *

+ * This annotation can be specified on each method of a service endpoint interface. + * For such a method, the mapped operation in the generated WSDL's + * {@code wsam:Action} attribute on the WSDL {@code input}, + * {@code output} and {@code fault} messages of the WSDL {@code operation} + * is based upon which attributes of the {@code Action} annotation have been specified. + * For the exact computation of {@code wsam:Action} values for the messages, refer + * to the algorithm in the JAX-WS specification. + *

+ * Example 1: Specify explicit values for {@code Action} message addressing property + * for {@code input} and {@code output} messages. + * + *

+ * {@literal @}WebService(targetNamespace="http://example.com/numbers")
+ *  public class AddNumbersImpl {
+ *     {@literal @}Action(
+ *          input="http://example.com/inputAction",
+ *          output="http://example.com/outputAction")
+ *      public int addNumbers(int number1, int number2) {
+ *          return number1 + number2;
+ *      }
+ *  }
+ * 
+ * + * The generated WSDL looks like: + *
 {@code
+ *   
+ *     ...
+ *     
+ *       
+ *         wsam:Action="http://example.com/inputAction"/>
+ *         wsam:Action="http://example.com/outputAction"/>
+ *       
+ *     
+ *     ...
+ *   
+ * }
+ * 
+ * + *

+ * Example 2: Specify explicit value for {@code Action} message addressing property + * for only the {@code input} message. The {@code wsam:Action} values for the + * WSDL {@code output} message are computed using the algorithm in the JAX-WS specification. + * + *

+ * {@literal @}WebService(targetNamespace="http://example.com/numbers")
+ *  public class AddNumbersImpl {
+ *     {@literal @}Action(input="http://example.com/inputAction")
+ *      public int addNumbers(int number1, int number2) {
+ *          return number1 + number2;
+ *      }
+ *  }
+ * 
+ * + * The generated WSDL looks like: + *
 {@code
+ *   
+ *     ...
+ *     
+ *       
+ *         wsam:Action="http://example.com/inputAction"/>
+ *         wsam:Action="http://example.com/numbers/AddNumbersPortType/AddNumbersResponse"/>
+ *       
+ *     
+ *     ...
+ *   
+ * }
+ * + * It is legitimate to specify an explicit value for {@code Action} message addressing property for + * {@code output} message only. In this case, {@code wsam:Action} value for the + * WSDL {@code input} message is computed using the algorithm in the JAX-WS specification. + * + *

+ * Example 3: See {@link FaultAction} annotation for an example of + * how to specify an explicit value for {@code Action} message addressing property for the + * {@code fault} message. + * + * @see FaultAction + * + * @since 1.6, JAX-WS 2.1 + */ + +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface Action { + /** + * Explicit value of the WS-Addressing {@code Action} message addressing property for the {@code input} + * message of the operation. + * + * @return {@code Action} message addressing property for the {@code input} message + */ + String input() default ""; + + /** + * Explicit value of the WS-Addressing {@code Action} message addressing property for the {@code output} + * message of the operation. + * + * @return {@code Action} message addressing property for the {@code output} message + */ + String output() default ""; + + /** + * Explicit value of the WS-Addressing {@code Action} message addressing property for the {@code fault} + * message(s) of the operation. Each exception that is mapped to a fault and requires an explicit WS-Addressing + * {@code Action} message addressing property, needs to be specified as a value in this property + * using {@link FaultAction} annotation. + * + * @return {@code Action} message addressing property for the {@code fault} message(s) + */ + FaultAction[] fault() default { }; +} diff --git a/fine-third-jdk11/src/javax/xml/ws/AsyncHandler.java b/fine-third-jdk11/src/javax/xml/ws/AsyncHandler.java new file mode 100644 index 000000000..485c05a9b --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/AsyncHandler.java @@ -0,0 +1,58 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +/** The {@code AsyncHandler} interface is implemented by + * clients that wish to receive callback notification of the completion of + * service endpoint operations invoked asynchronously. + * + * @param The type of the message or payload + * @since 1.6, JAX-WS 2.0 +**/ +public interface AsyncHandler { + + /** Called when the response to an asynchronous operation is available. + * + * @param res The response to the operation invocation. + * + **/ + void handleResponse(Response res); +} diff --git a/fine-third-jdk11/src/javax/xml/ws/Binding.java b/fine-third-jdk11/src/javax/xml/ws/Binding.java new file mode 100644 index 000000000..41e3b370a --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/Binding.java @@ -0,0 +1,82 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + + +/** The {@code Binding} interface is the base interface + * for JAX-WS protocol bindings. + * + * @since 1.6, JAX-WS 2.0 +**/ +public interface Binding { + + /** + * Gets a copy of the handler chain for a protocol binding instance. + * If the returned chain is modified a call to {@code setHandlerChain} + * is required to configure the binding instance with the new chain. + * + * @return {@code java.util.List} Handler chain + */ + public java.util.List getHandlerChain(); + + /** + * Sets the handler chain for the protocol binding instance. + * + * @param chain A List of handler configuration entries + * @throws WebServiceException On an error in the configuration of + * the handler chain + * @throws java.lang.UnsupportedOperationException If this + * operation is not supported. This may be done to + * avoid any overriding of a pre-configured handler + * chain. + */ + public void setHandlerChain(java.util.List chain); + + /** + * Get the URI for this binding instance. + * + * @return String The binding identifier for the port. + * Never returns {@code null} + * + * @since 1.6, JAX-WS 2.1 + */ + String getBindingID(); +} diff --git a/fine-third-jdk11/src/javax/xml/ws/BindingProvider.java b/fine-third-jdk11/src/javax/xml/ws/BindingProvider.java new file mode 100644 index 000000000..21fa473df --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/BindingProvider.java @@ -0,0 +1,198 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import java.util.Map; +import javax.xml.ws.wsaddressing.W3CEndpointReference; + +/** + * The {@code BindingProvider} interface provides access to the + * protocol binding and associated context objects for request and + * response message processing. + * + * @since 1.6, JAX-WS 2.0 + * + * @see javax.xml.ws.Binding + **/ +public interface BindingProvider { + /** + * Standard property: User name for authentication. + *

Type: {@code java.lang.String} + **/ + public static final String USERNAME_PROPERTY = + "javax.xml.ws.security.auth.username"; + + /** + * Standard property: Password for authentication. + *

Type: {@code java.lang.String} + **/ + public static final String PASSWORD_PROPERTY = + "javax.xml.ws.security.auth.password"; + + /** + * Standard property: Target service endpoint address. The + * URI scheme for the endpoint address specification MUST + * correspond to the protocol/transport binding for the + * binding in use. + *

Type: {@code java.lang.String} + **/ + public static final String ENDPOINT_ADDRESS_PROPERTY = + "javax.xml.ws.service.endpoint.address"; + + /** + * Standard property: This boolean property is used by a service + * client to indicate whether or not it wants to participate in + * a session with a service endpoint. If this property is set to + * {@code true}, the service client indicates that it wants the session + * to be maintained. If set to {@code false}, the session is not maintained. + * The default value for this property is {@code false}. + *

Type: {@code java.lang.Boolean} + **/ + public static final String SESSION_MAINTAIN_PROPERTY = + "javax.xml.ws.session.maintain"; + + /** + * Standard property for SOAPAction. This boolean property + * indicates whether or not the value of the + * {@code javax.xml.ws.soap.http.soapaction.uri} property + * is used for the value of the SOAPAction. The + * default value of this property is {@code false} indicating + * that the + * {@code javax.xml.ws.soap.http.soapaction.uri} property + * is not used for the value of the SOAPAction, however, + * if WS-Addressing is enabled, the default value is + * {@code true}. + * + *

Type: {@code java.lang.Boolean} + **/ + public static final String SOAPACTION_USE_PROPERTY = + "javax.xml.ws.soap.http.soapaction.use"; + + /** + * Standard property for SOAPAction. Indicates the SOAPAction + * URI if the {@code javax.xml.ws.soap.http.soapaction.use} + * property is set to {@code true}. If WS-Addressing + * is enabled, this value will also be used for the value of the + * WS-Addressing Action header. If this property is not set, + * the default SOAPAction and WS-Addressing Action will be sent. + * + *

Type: {@code java.lang.String} + **/ + public static final String SOAPACTION_URI_PROPERTY = + "javax.xml.ws.soap.http.soapaction.uri"; + + /** + * Get the context that is used to initialize the message context + * for request messages. + * + * Modifications to the request context do not affect the message context of + * either synchronous or asynchronous operations that have already been + * started. + * + * @return The context that is used in processing request messages. + **/ + Map getRequestContext(); + + /** + * Get the context that resulted from processing a response message. + * + * The returned context is for the most recently completed synchronous + * operation. Subsequent synchronous operation invocations overwrite the + * response context. Asynchronous operations return their response context + * via the Response interface. + * + * @return The context that resulted from processing the latest + * response messages. + **/ + Map getResponseContext(); + + /** + * Get the Binding for this binding provider. + * + * @return The Binding for this binding provider. + **/ + Binding getBinding(); + + + + /** + * Returns the {@code EndpointReference} associated with + * this {@code BindingProvider} instance. + *

+ * If the Binding for this {@code bindingProvider} is + * either SOAP1.1/HTTP or SOAP1.2/HTTP, then a + * {@code W3CEndpointReference} MUST be returned. + * + * @return EndpointReference of the target endpoint associated with this + * {@code BindingProvider} instance. + * + * @throws java.lang.UnsupportedOperationException If this + * {@code BindingProvider} uses the XML/HTTP binding. + * + * @see W3CEndpointReference + * + * @since 1.6, JAX-WS 2.1 + */ + public EndpointReference getEndpointReference(); + + + /** + * Returns the {@code EndpointReference} associated with + * this {@code BindingProvider} instance. The instance + * returned will be of type {@code clazz}. + * + * @param the type of {@code EndpointReference} + * @param clazz Specifies the type of {@code EndpointReference} + * that MUST be returned. + + * @return EndpointReference of the target endpoint associated with this + * {@code BindingProvider} instance. MUST be of type + * {@code clazz}. + + * @throws WebServiceException If the Class {@code clazz} + * is not supported by this implementation. + * @throws java.lang.UnsupportedOperationException If this + * {@code BindingProvider} uses the XML/HTTP binding. + * + * @since 1.6, JAX-WS 2.1 + */ + public T getEndpointReference(Class clazz); +} diff --git a/fine-third-jdk11/src/javax/xml/ws/BindingType.java b/fine-third-jdk11/src/javax/xml/ws/BindingType.java new file mode 100644 index 000000000..b4e31f873 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/BindingType.java @@ -0,0 +1,78 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import java.lang.annotation.Documented; +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import javax.xml.ws.http.HTTPBinding; +import javax.xml.ws.soap.SOAPBinding; + +/** + * The {@code BindingType} annotation is used to + * specify the binding to use for a web service + * endpoint implementation class. + *

+ * This annotation may be overridden programmatically or via + * deployment descriptors, depending on the platform in use. + * + * @since 1.6, JAX-WS 2.0 + * + **/ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface BindingType { + /** + * A binding identifier (a URI). If not specified, the default is the SOAP 1.1 / HTTP binding.
+ * See the {@link SOAPBinding} and {@link HTTPBinding} + * for the definition of the standard binding identifiers. + * + * @return A binding identifier (a URI) + * @see javax.xml.ws.Binding + * @see javax.xml.ws.soap.SOAPBinding#SOAP11HTTP_BINDING + * @see javax.xml.ws.soap.SOAPBinding#SOAP12HTTP_BINDING + * @see javax.xml.ws.http.HTTPBinding#HTTP_BINDING + */ + String value() default "" ; +} diff --git a/fine-third-jdk11/src/javax/xml/ws/Dispatch.java b/fine-third-jdk11/src/javax/xml/ws/Dispatch.java new file mode 100644 index 000000000..e9e7400f6 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/Dispatch.java @@ -0,0 +1,133 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import java.util.concurrent.Future; + + +/** The {@code Dispatch} interface provides support + * for the dynamic invocation of a service endpoint operations. The + * {@code javax.xml.ws.Service} + * class acts as a factory for the creation of {@code Dispatch} + * instances. + * + * @param The type of the message or payload + * @since 1.6, JAX-WS 2.0 +**/ +public interface Dispatch extends BindingProvider { + + /** Invoke a service operation synchronously. + * + * The client is responsible for ensuring that the {@code msg} object + * when marshalled is formed according to the requirements of the protocol + * binding in use. + * + * @param msg An object that will form the message or payload of + * the message used to invoke the operation. + * @return The response message or message payload to the + * operation invocation. + * @throws WebServiceException If a fault occurs during communication with + * the service + * @throws WebServiceException If there is any error in the configuration of + * the {@code Dispatch} instance + **/ + public T invoke(T msg); + + /** Invoke a service operation asynchronously. The + * method returns without waiting for the response to the operation + * invocation, the results of the operation are obtained by polling the + * returned {@code Response}. + *

+ * The client is responsible for ensuring that the {@code msg} object + * when marshalled is formed according to the requirements of the protocol + * binding in use. + * + * @param msg An object that will form the message or payload of + * the message used to invoke the operation. + * @return The response message or message payload to the + * operation invocation. + * @throws WebServiceException If there is any error in the configuration of + * the {@code Dispatch} instance + **/ + public Response invokeAsync(T msg); + + /** Invoke a service operation asynchronously. The + * method returns without waiting for the response to the operation + * invocation, the results of the operation are communicated to the client + * via the passed in {@code handler}. + *

+ * The client is responsible for ensuring that the {@code msg} object + * when marshalled is formed according to the requirements of the protocol + * binding in use. + * + * @param msg An object that will form the message or payload of + * the message used to invoke the operation. + * @param handler The handler object that will receive the + * response to the operation invocation. + * @return A {@code Future} object that may be used to check the status + * of the operation invocation. This object MUST NOT be used to try to + * obtain the results of the operation - the object returned from + * {@code Future.get()} is implementation dependent + * and any use of it will result in non-portable behaviour. + * @throws WebServiceException If there is any error in the configuration of + * the {@code Dispatch} instance + **/ + public Future invokeAsync(T msg, AsyncHandler handler); + + /** Invokes a service operation using the one-way + * interaction mode. The operation invocation is logically non-blocking, + * subject to the capabilities of the underlying protocol, no results + * are returned. When + * the protocol in use is SOAP/HTTP, this method MUST block until + * an HTTP response code has been received or an error occurs. + *

+ * The client is responsible for ensuring that the {@code msg} object + * when marshalled is formed according to the requirements of the protocol + * binding in use. + * + * @param msg An object that will form the message or payload of + * the message used to invoke the operation. + * @throws WebServiceException If there is any error in the configuration of + * the {@code Dispatch} instance or if an error occurs during the + * invocation. + **/ + public void invokeOneWay(T msg); +} diff --git a/fine-third-jdk11/src/javax/xml/ws/Endpoint.java b/fine-third-jdk11/src/javax/xml/ws/Endpoint.java new file mode 100644 index 000000000..4b05d6892 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/Endpoint.java @@ -0,0 +1,510 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import java.util.List; +import java.util.Map; +import javax.xml.ws.spi.Provider; +import javax.xml.ws.spi.http.HttpContext; +import javax.xml.ws.wsaddressing.W3CEndpointReference; +import org.w3c.dom.Element; + + +/** + * A Web service endpoint. + * + *

Endpoints are created using the static methods defined in this + * class. An endpoint is always tied to one {@code Binding} + * and one implementor, both set at endpoint creation time. + * + *

An endpoint is either in a published or an unpublished state. + * The {@code publish} methods can be used to start publishing + * an endpoint, at which point it starts accepting incoming requests. + * Conversely, the {@code stop} method can be used to stop + * accepting incoming requests and take the endpoint down. + * Once stopped, an endpoint cannot be published again. + * + *

An {@code Executor} may be set on the endpoint in order + * to gain better control over the threads used to dispatch incoming + * requests. For instance, thread pooling with certain parameters + * can be enabled by creating a {@code ThreadPoolExecutor} and + * registering it with the endpoint. + * + *

Handler chains can be set using the contained {@code Binding}. + * + *

An endpoint may have a list of metadata documents, such as WSDL + * and XMLSchema documents, bound to it. At publishing time, the + * JAX-WS implementation will try to reuse as much of that metadata + * as possible instead of generating new ones based on the annotations + * present on the implementor. + * + * @since 1.6, JAX-WS 2.0 + * + * @see javax.xml.ws.Binding + * @see javax.xml.ws.BindingType + * @see javax.xml.ws.soap.SOAPBinding + * @see java.util.concurrent.Executor + * + **/ +public abstract class Endpoint { + + /** Standard property: name of WSDL service. + *

Type: javax.xml.namespace.QName + **/ + public static final String WSDL_SERVICE = "javax.xml.ws.wsdl.service"; + + /** Standard property: name of WSDL port. + *

Type: javax.xml.namespace.QName + **/ + public static final String WSDL_PORT = "javax.xml.ws.wsdl.port"; + + /** + * Creates an endpoint with the specified implementor object. If there is + * a binding specified via a BindingType annotation then it MUST be used else + * a default of SOAP 1.1 / HTTP binding MUST be used. + *

+ * The newly created endpoint may be published by calling + * one of the {@link javax.xml.ws.Endpoint#publish(String)} and + * {@link javax.xml.ws.Endpoint#publish(Object)} methods. + * + * + * @param implementor The endpoint implementor. + * + * @return The newly created endpoint. + * + **/ + public static Endpoint create(Object implementor) { + return create(null, implementor); + } + + /** + * Creates an endpoint with the specified implementor object and web + * service features. If there is a binding specified via a BindingType + * annotation then it MUST be used else a default of SOAP 1.1 / HTTP + * binding MUST be used. + *

+ * The newly created endpoint may be published by calling + * one of the {@link javax.xml.ws.Endpoint#publish(String)} and + * {@link javax.xml.ws.Endpoint#publish(Object)} methods. + * + * + * @param implementor The endpoint implementor. + * @param features A list of WebServiceFeature to configure on the + * endpoint. Supported features not in the {@code features + * } parameter will have their default values. + * + * + * @return The newly created endpoint. + * @since 1.7, JAX-WS 2.2 + * + */ + public static Endpoint create(Object implementor, WebServiceFeature ... features) { + return create(null, implementor, features); + } + + /** + * Creates an endpoint with the specified binding type and + * implementor object. + *

+ * The newly created endpoint may be published by calling + * one of the {@link javax.xml.ws.Endpoint#publish(String)} and + * {@link javax.xml.ws.Endpoint#publish(Object)} methods. + * + * @param bindingId A URI specifying the binding to use. If the bindingID is + * {@code null} and no binding is specified via a BindingType + * annotation then a default SOAP 1.1 / HTTP binding MUST be used. + * + * @param implementor The endpoint implementor. + * + * @return The newly created endpoint. + * + **/ + public static Endpoint create(String bindingId, Object implementor) { + return Provider.provider().createEndpoint(bindingId, implementor); + } + + /** + * Creates an endpoint with the specified binding type, + * implementor object, and web service features. + *

+ * The newly created endpoint may be published by calling + * one of the {@link javax.xml.ws.Endpoint#publish(String)} and + * {@link javax.xml.ws.Endpoint#publish(Object)} methods. + * + * @param bindingId A URI specifying the binding to use. If the bindingID is + * {@code null} and no binding is specified via a BindingType + * annotation then a default SOAP 1.1 / HTTP binding MUST be used. + * + * @param implementor The endpoint implementor. + * + * @param features A list of WebServiceFeature to configure on the + * endpoint. Supported features not in the {@code features + * } parameter will have their default values. + * + * @return The newly created endpoint. + * @since 1.7, JAX-WS 2.2 + */ + public static Endpoint create(String bindingId, Object implementor, WebServiceFeature ... features) { + return Provider.provider().createEndpoint(bindingId, implementor, features); + } + + /** + * Returns the binding for this endpoint. + * + * @return The binding for this endpoint + **/ + public abstract Binding getBinding(); + + /** + * Returns the implementation object for this endpoint. + * + * @return The implementor for this endpoint + **/ + public abstract Object getImplementor(); + + /** + * Publishes this endpoint at the given address. + * The necessary server infrastructure will be created and + * configured by the JAX-WS implementation using some default configuration. + * In order to get more control over the server configuration, please + * use the {@link javax.xml.ws.Endpoint#publish(Object)} method instead. + * + * @param address A URI specifying the address to use. The address + * MUST be compatible with the binding specified at the + * time the endpoint was created. + * + * @throws java.lang.IllegalArgumentException + * If the provided address URI is not usable + * in conjunction with the endpoint's binding. + * + * @throws java.lang.IllegalStateException + * If the endpoint has been published already or it has been stopped. + * + * @throws java.lang.SecurityException + * If a {@code java.lang.SecurityManger} + * is being used and the application doesn't have the + * {@code WebServicePermission("publishEndpoint")} permission. + **/ + public abstract void publish(String address); + + /** + * Creates and publishes an endpoint for the specified implementor + * object at the given address. + *

+ * The necessary server infrastructure will be created and + * configured by the JAX-WS implementation using some default configuration. + * + * In order to get more control over the server configuration, please + * use the {@link javax.xml.ws.Endpoint#create(String,Object)} and + * {@link javax.xml.ws.Endpoint#publish(Object)} methods instead. + * + * @param address A URI specifying the address and transport/protocol + * to use. A http: URI MUST result in the SOAP 1.1/HTTP + * binding being used. Implementations may support other + * URI schemes. + * @param implementor The endpoint implementor. + * + * @return The newly created endpoint. + * + * @throws java.lang.SecurityException + * If a {@code java.lang.SecurityManger} + * is being used and the application doesn't have the + * {@code WebServicePermission("publishEndpoint")} permission. + * + **/ + public static Endpoint publish(String address, Object implementor) { + return Provider.provider().createAndPublishEndpoint(address, implementor); + } + + /** + * Creates and publishes an endpoint for the specified implementor + * object at the given address. The created endpoint is configured + * with the web service features. + *

+ * The necessary server infrastructure will be created and + * configured by the JAX-WS implementation using some default configuration. + * + * In order to get more control over the server configuration, please + * use the {@link javax.xml.ws.Endpoint#create(String,Object)} and + * {@link javax.xml.ws.Endpoint#publish(Object)} methods instead. + * + * @param address A URI specifying the address and transport/protocol + * to use. A http: URI MUST result in the SOAP 1.1/HTTP + * binding being used. Implementations may support other + * URI schemes. + * @param implementor The endpoint implementor. + * @param features A list of WebServiceFeature to configure on the + * endpoint. Supported features not in the {@code features + * } parameter will have their default values. + * @return The newly created endpoint. + * + * @throws java.lang.SecurityException + * If a {@code java.lang.SecurityManger} + * is being used and the application doesn't have the + * {@code WebServicePermission("publishEndpoint")} permission. + * @since 1.7, JAX-WS 2.2 + */ + public static Endpoint publish(String address, Object implementor, WebServiceFeature ... features) { + return Provider.provider().createAndPublishEndpoint(address, implementor, features); + } + + /** + * Publishes this endpoint at the provided server context. + * A server context encapsulates the server infrastructure + * and addressing information for a particular transport. + * For a call to this method to succeed, the server context + * passed as an argument to it MUST be compatible with the + * endpoint's binding. + * + * @param serverContext An object representing a server + * context to be used for publishing the endpoint. + * + * @throws java.lang.IllegalArgumentException + * If the provided server context is not + * supported by the implementation or turns + * out to be unusable in conjunction with the + * endpoint's binding. + * + * @throws java.lang.IllegalStateException + * If the endpoint has been published already or it has been stopped. + * + * @throws java.lang.SecurityException + * If a {@code java.lang.SecurityManger} + * is being used and the application doesn't have the + * {@code WebServicePermission("publishEndpoint")} permission. + **/ + public abstract void publish(Object serverContext); + + /** + * Publishes this endpoint at the provided server context. + * A server context encapsulates the server infrastructure + * and addressing information for a particular transport. + * For a call to this method to succeed, the server context + * passed as an argument to it MUST be compatible with the + * endpoint's binding. + * + *

+ * This is meant for container developers to publish the + * the endpoints portably and not intended for the end + * developers. + * + * + * @param serverContext An object representing a server + * context to be used for publishing the endpoint. + * + * @throws java.lang.IllegalArgumentException + * If the provided server context is not + * supported by the implementation or turns + * out to be unusable in conjunction with the + * endpoint's binding. + * + * @throws java.lang.IllegalStateException + * If the endpoint has been published already or it has been stopped. + * + * @throws java.lang.SecurityException + * If a {@code java.lang.SecurityManger} + * is being used and the application doesn't have the + * {@code WebServicePermission("publishEndpoint")} permission. + * @since 1.7, JAX-WS 2.2 + */ + public void publish(HttpContext serverContext) { + throw new UnsupportedOperationException("JAX-WS 2.2 implementation must override this default behaviour."); + } + + /** + * Stops publishing this endpoint. + * + * If the endpoint is not in a published state, this method + * has no effect. + * + **/ + public abstract void stop(); + + /** + * Returns true if the endpoint is in the published state. + * + * @return {@code true} if the endpoint is in the published state. + **/ + public abstract boolean isPublished(); + + /** + * Returns a list of metadata documents for the service. + * + * @return {@code List} A list of metadata documents for the service + **/ + public abstract List getMetadata(); + + /** + * Sets the metadata for this endpoint. + * + * @param metadata A list of XML document sources containing + * metadata information for the endpoint (e.g. + * WSDL or XML Schema documents) + * + * @throws java.lang.IllegalStateException If the endpoint + * has already been published. + **/ + public abstract void setMetadata(List metadata); + + /** + * Returns the executor for this {@code Endpoint}instance. + * + * The executor is used to dispatch an incoming request to + * the implementor object. + * + * @return The {@code java.util.concurrent.Executor} to be + * used to dispatch a request. + * + * @see java.util.concurrent.Executor + **/ + public abstract java.util.concurrent.Executor getExecutor(); + + /** + * Sets the executor for this {@code Endpoint} instance. + * + * The executor is used to dispatch an incoming request to + * the implementor object. + * + * If this {@code Endpoint} is published using the + * {@code publish(Object)} method and the specified server + * context defines its own threading behavior, the executor + * may be ignored. + * + * @param executor The {@code java.util.concurrent.Executor} + * to be used to dispatch a request. + * + * @throws SecurityException If the instance does not support + * setting an executor for security reasons (e.g. the + * necessary permissions are missing). + * + * @see java.util.concurrent.Executor + **/ + public abstract void setExecutor(java.util.concurrent.Executor executor); + + /** + * Returns the property bag for this {@code Endpoint} instance. + * + * @return Map<String,Object> The property bag + * associated with this instance. + **/ + public abstract Map getProperties(); + + /** + * Sets the property bag for this {@code Endpoint} instance. + * + * @param properties The property bag associated with + * this instance. + **/ + public abstract void setProperties(Map properties); + + /** + * Returns the {@code EndpointReference} associated with + * this {@code Endpoint} instance. + *

+ * If the Binding for this {@code bindingProvider} is + * either SOAP1.1/HTTP or SOAP1.2/HTTP, then a + * {@code W3CEndpointReference} MUST be returned. + * + * @param referenceParameters Reference parameters to be associated with the + * returned {@code EndpointReference} instance. + * @return EndpointReference of this {@code Endpoint} instance. + * If the returned {@code EndpointReference} is of type + * {@code W3CEndpointReference} then it MUST contain the + * the specified {@code referenceParameters}. + + * @throws WebServiceException If any error in the creation of + * the {@code EndpointReference} or if the {@code Endpoint} is + * not in the published state. + * @throws UnsupportedOperationException If this {@code BindingProvider} + * uses the XML/HTTP binding. + * + * @see W3CEndpointReference + * + * @since 1.6, JAX-WS 2.1 + **/ + public abstract EndpointReference getEndpointReference(Element... referenceParameters); + + /** + * Returns the {@code EndpointReference} associated with + * this {@code Endpoint} instance. + * + * @param The type of EndpointReference. + * @param clazz Specifies the type of EndpointReference that MUST be returned. + * @param referenceParameters Reference parameters to be associated with the + * returned {@code EndpointReference} instance. + * @return EndpointReference of type {@code clazz} of this + * {@code Endpoint} instance. + * If the returned {@code EndpointReference} is of type + * {@code W3CEndpointReference} then it MUST contain the + * the specified {@code referenceParameters}. + + * @throws WebServiceException If any error in the creation of + * the {@code EndpointReference} or if the {@code Endpoint} is + * not in the published state or if the {@code clazz} is not a supported + * {@code EndpointReference} type. + * @throws UnsupportedOperationException If this {@code BindingProvider} + * uses the XML/HTTP binding. + * + * + * @since 1.6, JAX-WS 2.1 + **/ + public abstract T getEndpointReference(Class clazz, + Element... referenceParameters); + + /** + * By setting a {@code EndpointContext}, JAX-WS runtime knows about + * addresses of other endpoints in an application. If multiple endpoints + * share different ports of a WSDL, then the multiple port addresses + * are patched when the WSDL is accessed. + * + *

+ * This needs to be set before publishing the endpoints. + * + * @param ctxt that is shared for multiple endpoints + * @throws java.lang.IllegalStateException + * If the endpoint has been published already or it has been stopped. + * + * @since 1.7, JAX-WS 2.2 + */ + public void setEndpointContext(EndpointContext ctxt) { + throw new UnsupportedOperationException("JAX-WS 2.2 implementation must override this default behaviour."); + } +} diff --git a/fine-third-jdk11/src/javax/xml/ws/EndpointContext.java b/fine-third-jdk11/src/javax/xml/ws/EndpointContext.java new file mode 100644 index 000000000..5c710cdb9 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/EndpointContext.java @@ -0,0 +1,73 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2009-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import java.util.Set; + +/** + * {@code EndpointContext} allows multiple endpoints in an application + * to share any information. For example, servlet application's war may + * contain multiple endpoints and these endpoints can get addresses of each + * other by sharing this context. If multiple endpoints share different + * ports of a WSDL, then the multiple port addresses can be patched + * when the WSDL is accessed. It also allows all endpoints to share any + * other runtime information. + * + *

+ * This needs to be set by using {@link Endpoint#setEndpointContext} + * before {@link Endpoint#publish} methods. + * + * @author Jitendra Kotamraju + * @since 1.7, JAX-WS 2.2 + */ +public abstract class EndpointContext { + + /** + * This gives list of endpoints in an application. For e.g in + * servlet container, a war file may contain multiple endpoints. + * In case of http, these endpoints are hosted on the same http + * server. + * + * @return list of all endpoints in an application + */ + public abstract Set getEndpoints(); + +} diff --git a/fine-third-jdk11/src/javax/xml/ws/EndpointReference.java b/fine-third-jdk11/src/javax/xml/ws/EndpointReference.java new file mode 100644 index 000000000..73026939e --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/EndpointReference.java @@ -0,0 +1,215 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import javax.xml.bind.annotation.XmlTransient; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamResult; +import javax.xml.ws.spi.Provider; +import javax.xml.ws.wsaddressing.W3CEndpointReference; +import java.io.StringWriter; + +/** + * This class represents an WS-Addressing EndpointReference + * which is a remote reference to a web service endpoint. + * See + * Web Services Addressing 1.0 - Core + * for more information on WS-Addressing EndpointReferences. + *

+ * This class is immutable as the typical web service developer + * need not be concerned with its contents. The web service + * developer should use this class strictly as a mechanism to + * reference a remote web service endpoint. See the {@link Service} APIs + * that clients can use to that utilize an {@code EndpointReference}. + * See the {@link javax.xml.ws.Endpoint}, and + * {@link javax.xml.ws.BindingProvider} APIs on how + * {@code EndpointReferences} can be created for published + * endpoints. + *

+ * Concrete implementations of this class will represent + * an {@code EndpointReference} for a particular version of Addressing. + * For example the {@link W3CEndpointReference} is for use + * with W3C Web Services Addressing 1.0 - Core Recommendation. + * If JAX-WS implementors need to support different versions + * of addressing, they should write their own + * {@code EndpointReference} subclass for that version. + * This will allow a JAX-WS implementation to create + * a vendor specific {@code EndpointReferences} that the + * vendor can use to flag a different version of + * addressing. + *

+ * Web service developers that wish to pass or return + * {@code EndpointReference} in Java methods in an + * SEI should use + * concrete instances of an {@code EndpointReference} such + * as the {@code W3CEndpointReference}. This way the + * schema mapped from the SEI will be more descriptive of the + * type of endpoint reference being passed. + *

+ * JAX-WS implementors are expected to extract the XML infoset + * from an {@code EndpointReferece} using the + * {@link EndpointReference#writeTo} + * method. + *

+ * JAXB will bind this class to xs:anyType. If a better binding + * is desired, web services developers should use a concrete + * subclass such as {@link W3CEndpointReference}. + * + * @see W3CEndpointReference + * @see Service + * @since 1.6, JAX-WS 2.1 + */ +@XmlTransient // to treat this class like Object as far as databinding is concerned (proposed JAXB 2.1 feature) +public abstract class EndpointReference { + // + //Default constructor to be only called by derived types. + // + + /** + * Default constructor. + */ + protected EndpointReference(){} + + /** + * Factory method to read an EndpointReference from the infoset contained in + * {@code eprInfoset}. This method delegates to the vendor specific + * implementation of the {@link javax.xml.ws.spi.Provider#readEndpointReference} method. + * + * @param eprInfoset The {@code EndpointReference} infoset to be unmarshalled + * + * @return the EndpointReference unmarshalled from {@code eprInfoset} + * never {@code null} + * @throws WebServiceException + * if an error occurs while creating the + * {@code EndpointReference} from the {@code eprInfoset} + * @throws java.lang.IllegalArgumentException + * if the {@code null} {@code eprInfoset} value is given. + */ + public static EndpointReference readFrom(Source eprInfoset) { + return Provider.provider().readEndpointReference(eprInfoset); + } + + /** + * write this {@code EndpointReference} to the specified infoset format + * + * @param result for writing infoset + * @throws WebServiceException + * if there is an error writing the + * {@code EndpointReference} to the specified {@code result}. + * + * @throws java.lang.IllegalArgumentException + * If the {@code null} {@code result} value is given. + */ + public abstract void writeTo(Result result); + + + /** + * The {@code getPort} method returns a proxy. If there + * are any reference parameters in the + * {@code EndpointReference} instance, then those reference + * parameters MUST appear as SOAP headers, indicating them to be + * reference parameters, on all messages sent to the endpoint. + * The parameter {@code serviceEndpointInterface} specifies + * the service endpoint interface that is supported by the + * returned proxy. + * The {@code EndpointReference} instance specifies the + * endpoint that will be invoked by the returned proxy. + * In the implementation of this method, the JAX-WS + * runtime system takes the responsibility of selecting a protocol + * binding (and a port) and configuring the proxy accordingly from + * the WSDL Metadata from this {@code EndpointReference} or from + * annotations on the {@code serviceEndpointInterface}. For this method + * to successfully return a proxy, WSDL metadata MUST be available and the + * {@code EndpointReference} instance MUST contain an implementation understood + * {@code serviceName} metadata. + *

+ * Because this port is not created from a {@code Service} object, handlers + * will not automatically be configured, and the {@code HandlerResolver} + * and {@code Executor} cannot be get or set for this port. The + * {@code BindingProvider().getBinding().setHandlerChain()} + * method can be used to manually configure handlers for this port. + * + * + * @param Service endpoint interface + * @param serviceEndpointInterface Service endpoint interface + * @param features An array of {@code WebServiceFeatures} to configure on the + * proxy. Supported features not in the {@code features + * } parameter will have their default values. + * @return Object Proxy instance that supports the + * specified service endpoint interface + * @throws WebServiceException + *

    + *
  • If there is an error during creation + * of the proxy + *
  • If there is any missing WSDL metadata + * as required by this method + *
  • If this + * {@code endpointReference} + * is invalid + *
  • If an illegal + * {@code serviceEndpointInterface} + * is specified + *
  • If a feature is enabled that is not compatible with + * this port or is unsupported. + *
+ * + * @see java.lang.reflect.Proxy + * @see WebServiceFeature + **/ + public T getPort(Class serviceEndpointInterface, + WebServiceFeature... features) { + return Provider.provider().getPort(this, serviceEndpointInterface, + features); + } + + /** + * Displays EPR infoset for debugging convenience. + * + * @return a string representation of the object + */ + @Override + public String toString() { + StringWriter w = new StringWriter(); + writeTo(new StreamResult(w)); + return w.toString(); + } +} diff --git a/fine-third-jdk11/src/javax/xml/ws/FaultAction.java b/fine-third-jdk11/src/javax/xml/ws/FaultAction.java new file mode 100644 index 000000000..cac35514e --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/FaultAction.java @@ -0,0 +1,183 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * The {@code FaultAction} annotation is used inside an {@link Action} + * annotation to allow an explicit association of a WS-Addressing + * {@code Action} message addressing property with the {@code fault} + * messages of the WSDL operation mapped from the exception class. + *

+ * The {@code wsam:Action} attribute value in the {@code fault} + * message in the generated WSDL operation mapped for {@code className} + * class is equal to the corresponding value in the {@code FaultAction}. + * For the exact computation of {@code wsam:Action} values for the + * fault messages, refer to the algorithm in the JAX-WS specification. + * + *

+ * Example 1: Specify explicit values for {@code Action} message addressing + * property for the {@code input}, {@code output} and {@code fault} message + * if the Java method throws only one service specific exception. + * + *

+ * {@literal @}WebService(targetNamespace="http://example.com/numbers")
+ *  public class AddNumbersImpl {
+ *    {@literal @}Action(
+ *         fault = {
+ *             {@literal @}FaultAction(className=AddNumbersException.class, value="http://example.com/faultAction")
+ *         })
+ *     public int addNumbers(int number1, int number2)
+ *         throws AddNumbersException {
+ *         return number1 + number2;
+ *     }
+ * }
+ * 
+ * + * The generated WSDL looks like: + * + *
 {@code
+ *   
+ *     ...
+ *     
+ *       
+ *         ...
+ *         wsam:Action="http://example.com/faultAction"{@code />
+ *       
+ *     
+ *     ...
+ *    }
+ * 
+ * + *

+ * Example 2: Here is an example that shows if the explicit value for {@code Action} + * message addressing property for the service specific exception is not present. + * + *

+ * {@literal @}WebService(targetNamespace="http://example.com/numbers")
+ *  public class AddNumbersImpl {
+ *     public int addNumbers(int number1, int number2)
+ *         throws AddNumbersException {
+ *         return number1 + number2;
+ *     }
+ *  }
+ * 
+ * + * The generated WSDL looks like: + * + *
{@code
+ *   
+ *     ...
+ *     
+ *       
+ *         ...
+ *         wsam:Action="http://example.com/numbers/AddNumbersPortType/AddNumbers/Fault/AddNumbersException"{@code />
+ *       
+ *     
+ *     ...
+ *   
+ * }
+ * + *

+ * Example 3: Here is an example that shows how to specify explicit values for {@code Action} + * message addressing property if the Java method throws more than one service specific exception. + * + *

+ * {@literal @}WebService(targetNamespace="http://example.com/numbers")
+ *  public class AddNumbersImpl {
+ *    {@literal @}Action(
+ *         fault = {
+ *             {@literal @}FaultAction(className=AddNumbersException.class, value="http://example.com/addFaultAction"),
+ *             {@literal @}FaultAction(className=TooBigNumbersException.class, value="http://example.com/toobigFaultAction")
+ *         })
+ *     public int addNumbers(int number1, int number2)
+ *         throws AddNumbersException, TooBigNumbersException {
+ *         return number1 + number2;
+ *     }
+ *  }
+ * 
+ * + * The generated WSDL looks like: + * + *
 {@code
+ *   
+ *     ...
+ *     
+ *       
+ *         ...
+ *         wsam:Action="http://example.com/addFaultAction"{@code />
+ *         wsam:Action="http://example.com/toobigFaultAction"{@code />
+ *       
+ *     
+ *     ...
+ *   
+ * }
+ * + * @since 1.6, JAX-WS 2.1 + */ + +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface FaultAction { + /** + * Name of the exception class. + * + * @return the name of the exception class + */ + Class className(); + + /** + * Value of WS-Addressing {@code Action} message addressing property for the exception. + * + * @return WS-Addressing {@code Action} message addressing property for the exception + */ + String value() default ""; +} diff --git a/fine-third-jdk11/src/javax/xml/ws/Holder.java b/fine-third-jdk11/src/javax/xml/ws/Holder.java new file mode 100644 index 000000000..bc2a32364 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/Holder.java @@ -0,0 +1,74 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import java.io.Serializable; + +/** + * Holds a value of type {@code T}. + * + * @param Type of the value in the holder. + * @since 1.6, JAX-WS 2.0 + */ +public final class Holder implements Serializable { + + private static final long serialVersionUID = 2623699057546497185L; + + /** + * The value contained in the holder. + */ + public T value; + + /** + * Creates a new holder with a {@code null} value. + */ + public Holder() { + } + + /** + * Create a new holder with the specified value. + * + * @param value The value to be stored in the holder. + */ + public Holder(T value) { + this.value = value; + } +} diff --git a/fine-third-jdk11/src/javax/xml/ws/LogicalMessage.java b/fine-third-jdk11/src/javax/xml/ws/LogicalMessage.java new file mode 100644 index 000000000..f68b2e7ad --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/LogicalMessage.java @@ -0,0 +1,107 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import javax.xml.transform.Source; +import javax.xml.bind.JAXBContext; + +/** The {@code LogicalMessage} interface represents a + * protocol agnostic XML message and contains methods that + * provide access to the payload of the message. + * + * @since 1.6, JAX-WS 2.0 +**/ +public interface LogicalMessage { + + /** Gets the message payload as an XML source, may be called + * multiple times on the same LogicalMessage instance, always + * returns a new {@code Source} that may be used to retrieve the entire + * message payload. + * + *

If the returned {@code Source} is an instance of + * {@code DOMSource}, then + * modifications to the encapsulated DOM tree change the message + * payload in-place, there is no need to susequently call + * {@code setPayload}. Other types of {@code Source} provide only + * read access to the message payload. + * + * @return The contained message payload; returns {@code null} if no + * payload is present in this message. + **/ + public Source getPayload(); + + /** Sets the message payload + * + * @param payload message payload + * @throws WebServiceException If any error during the setting + * of the payload in this message + * @throws java.lang.UnsupportedOperationException If this + * operation is not supported + **/ + public void setPayload(Source payload); + + /** Gets the message payload as a JAXB object. Note that there is no + * connection between the returned object and the message payload, + * changes to the payload require calling {@code setPayload}. + * + * @param context The JAXBContext that should be used to unmarshall + * the message payload + * @return The contained message payload; returns {@code null} if no + * payload is present in this message + * @throws WebServiceException If an error occurs when using a supplied + * JAXBContext to unmarshall the payload. The cause of + * the WebServiceException is the original JAXBException. + **/ + public Object getPayload(JAXBContext context); + + /** Sets the message payload + * + * @param payload message payload + * @param context The JAXBContext that should be used to marshall + * the payload + * @throws java.lang.UnsupportedOperationException If this + * operation is not supported + * @throws WebServiceException If an error occurs when using the supplied + * JAXBContext to marshall the payload. The cause of + * the WebServiceException is the original JAXBException. + **/ + public void setPayload(Object payload, JAXBContext context); +} diff --git a/fine-third-jdk11/src/javax/xml/ws/ProtocolException.java b/fine-third-jdk11/src/javax/xml/ws/ProtocolException.java new file mode 100644 index 000000000..a0bcffb58 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/ProtocolException.java @@ -0,0 +1,103 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +/** The {@code ProtocolException} class is a + * base class for exceptions related to a specific protocol binding. Subclasses + * are used to communicate protocol level fault information to clients and may + * be used on the server to control the protocol specific fault representation. + * + * @since 1.6, JAX-WS 2.0 +**/ +public class ProtocolException extends WebServiceException { + /** + * Constructs a new protocol exception with {@code null} as its detail message. The + * cause is not initialized, and may subsequently be initialized by a call + * to {@code Throwable.initCause(java.lang.Throwable)}. + */ + public ProtocolException() { + super(); + } + + /** + * Constructs a new protocol exception with the specified detail message. + * The cause is not initialized, and may subsequently be initialized by a + * call to {@code Throwable.initCause(java.lang.Throwable)}. + * + * @param message the detail message. The detail message is saved for later + * retrieval by the Throwable.getMessage() method. + */ + public ProtocolException(String message) { + super(message); + } + + /** + * Constructs a new runtime exception with the specified detail message and + * cause. + * + * Note that the detail message associated with cause is not automatically + * incorporated in this runtime exception's detail message. + * + * @param message the detail message (which is saved for later retrieval by + * the Throwable.getMessage() method). + * @param cause the cause (which is saved for later retrieval by the + * {@code Throwable.getCause()} method). (A {@code null} value is permitted, and indicates + * that the cause is nonexistent or unknown.) + */ + public ProtocolException(String message, Throwable cause) { + super(message, cause); + } + + /** + * Constructs a new runtime exception with the specified cause and a detail + * message of {@code (cause==null ? null : cause.toString())} (which typically + * contains the class and detail message of cause). This constructor is + * useful for runtime exceptions that are little more than wrappers for + * other throwables. + * + * @param cause the cause (which is saved for later retrieval by the + * {@code Throwable.getCause()} method). (A {@code null} value is permitted, and indicates + * that the cause is nonexistent or unknown.) + */ + public ProtocolException(Throwable cause) { + super(cause); + } +} diff --git a/fine-third-jdk11/src/javax/xml/ws/Provider.java b/fine-third-jdk11/src/javax/xml/ws/Provider.java new file mode 100644 index 000000000..9ff37facc --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/Provider.java @@ -0,0 +1,79 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +/** + *

Service endpoints may implement the {@code Provider} + * interface as a dynamic alternative to an SEI. + * + *

Implementations are required to support {@code Provider}, + * {@code Provider} and + * {@code Provider}, depending on the binding + * in use and the service mode. + * + *

The {@code ServiceMode} annotation can be used to control whether + * the {@code Provider} instance will receive entire protocol messages + * or just message payloads. + * + * @param The type of the request + * @since 1.6, JAX-WS 2.0 + * + * @see javax.xml.transform.Source + * @see javax.xml.soap.SOAPMessage + * @see javax.xml.ws.ServiceMode +**/ +public interface Provider { + + /** Invokes an operation according to the contents of the request + * message. + * + * @param request The request message or message payload. + * @return The response message or message payload. May be {@code null} if + there is no response. + * @throws WebServiceException If there is an error processing request. + * The cause of the {@code WebServiceException} may be set to a subclass + * of {@code ProtocolException} to control the protocol level + * representation of the exception. + * @see javax.xml.ws.handler.MessageContext + * @see javax.xml.ws.ProtocolException + **/ + public T invoke(T request); +} diff --git a/fine-third-jdk11/src/javax/xml/ws/RequestWrapper.java b/fine-third-jdk11/src/javax/xml/ws/RequestWrapper.java new file mode 100644 index 000000000..eed7f4b46 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/RequestWrapper.java @@ -0,0 +1,92 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import java.lang.annotation.Documented; +import java.lang.annotation.Target; +import java.lang.annotation.Retention; +import java.lang.annotation.ElementType; +import java.lang.annotation.RetentionPolicy; + +/** + * Used to annotate methods in the Service Endpoint Interface with the request + * wrapper bean to be used at runtime. The default value of the {@code localName} is + * the {@code operationName}, as defined in {@code WebMethod} annotation and the + * {@code targetNamespace} is the target namespace of the SEI. + *

When starting from Java this annotation is used resolve + * overloading conflicts in document literal mode. Only the {@code className} + * is required in this case. + * + * @since 1.6, JAX-WS 2.0 + **/ + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface RequestWrapper { + /** + * Element's local name. + * @return local name + */ + public String localName() default ""; + + /** + * Element's namespace name. + * @return target namespace name + */ + public String targetNamespace() default ""; + + /** + * Request wrapper bean name. + * @return bean name + */ + public String className() default ""; + + /** + * wsdl:part name for the wrapper part + * + * @return wsdl:part name + * @since 1.7, JAX-WS 2.2 + */ + public String partName() default ""; + +} + diff --git a/fine-third-jdk11/src/javax/xml/ws/RespectBinding.java b/fine-third-jdk11/src/javax/xml/ws/RespectBinding.java new file mode 100644 index 000000000..9aeca81a7 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/RespectBinding.java @@ -0,0 +1,85 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import java.lang.annotation.Documented; +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import javax.xml.ws.spi.WebServiceFeatureAnnotation; + + +/** + * This feature clarifies the use of the {@code wsdl:binding} + * in a JAX-WS runtime. + *

+ * This annotation MUST only be used in conjunction the + * {@code javax.jws.WebService}, {@link WebServiceProvider}, + * {@link WebServiceRef} annotations. + * When used with the {@code javax.jws.WebService} annotation this + * annotation MUST only be used on the service endpoint implementation + * class. + * When used with a {@code WebServiceRef} annotation, this annotation + * MUST only be used when a proxy instance is created. The injected SEI + * proxy, and endpoint MUST honor the values of the {@code RespectBinding} + * annotation. + *

+ * + * This annotation's behaviour is defined by the corresponding feature + * {@link RespectBindingFeature}. + * + * @see RespectBindingFeature + * + * @since 1.6, JAX-WS 2.1 + */ +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@WebServiceFeatureAnnotation(id=RespectBindingFeature.ID,bean=RespectBindingFeature.class) +public @interface RespectBinding { + /** + * Specifies if this feature is enabled or disabled. + * + * @return {@code true} if this feature is enabled, {@code false} otherwise + */ + boolean enabled() default true; +} diff --git a/fine-third-jdk11/src/javax/xml/ws/RespectBindingFeature.java b/fine-third-jdk11/src/javax/xml/ws/RespectBindingFeature.java new file mode 100644 index 000000000..9c68628c5 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/RespectBindingFeature.java @@ -0,0 +1,132 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import javax.xml.ws.soap.AddressingFeature; + +/** + * This feature clarifies the use of the {@code wsdl:binding} + * in a JAX-WS runtime. + * + * This feature can be used during the creation of SEI proxy, and + * {@link Dispatch} instances on the client side and {@link Endpoint} + * instances on the server side. This feature cannot be used for {@link Service} + * instance creation on the client side. + *

+ * This feature is only useful with web services that have an + * associated WSDL. Enabling this feature requires that a JAX-WS + * implementation inspect the {@code wsdl:binding} for an + * endpoint at runtime to make sure that all {@code wsdl:extensions} + * that have the {@code required} attribute set to {@code true} + * are understood and are being used. + *

+ * The following describes the affects of this feature with respect + * to be enabled or disabled: + *

    + *
  • ENABLED: In this Mode, a JAX-WS runtime MUST assure that all + * required {@code wsdl:binding} extensions(including policies) are + * either understood and used by the runtime, or explicitly disabled by the + * web service application. A web service can disable a particular + * extension if there is a corresponding {@link WebServiceFeature} or annotation. + * Similarly, a web service client can disable + * particular extension using the corresponding {@code WebServiceFeature} while + * creating a proxy or Dispatch instance. + * The runtime MUST also make sure that binding of + * SEI parameters/return values respect the {@code wsdl:binding}. + * With this feature enabled, if a required ({@code wsdl:required="true"}) + * {@code wsdl:binding} extension is in the WSDL and it is not + * supported by a JAX-WS runtime and it has not + * been explicitly turned off by the web service developer, then + * that JAX-WS runtime MUST behave appropriately based on whether it is + * on the client or server: + *
      + *
    • Client: runtime MUST throw a + * {@link WebServiceException} no sooner than when one of the methods + * above is invoked but no later than the first invocation of an endpoint + * operation. + *
    • Server: throw a {@link WebServiceException} and the endpoint MUST fail to deploy + *
    + * + *
  • DISABLED: In this Mode, an implementation may choose whether + * to inspect the {@code wsdl:binding} or not and to what degree + * the {@code wsdl:binding} will be inspected. For example, + * one implementation may choose to behave as if this feature is enabled, + * another implementation may only choose to verify the SEI's + * parameter/return type bindings. + *
+ * + * @see AddressingFeature + * + * @since 1.6, JAX-WS 2.1 + */ +public final class RespectBindingFeature extends WebServiceFeature { + /** + * + * Constant value identifying the RespectBindingFeature + */ + public static final String ID = "javax.xml.ws.RespectBindingFeature"; + + + /** + * Creates an {@code RespectBindingFeature}. + * The instance created will be enabled. + */ + public RespectBindingFeature() { + this.enabled = true; + } + + /** + * Creates an RespectBindingFeature + * + * @param enabled specifies whether this feature should + * be enabled or not. + */ + public RespectBindingFeature(boolean enabled) { + this.enabled = enabled; + } + + /** + * {@inheritDoc} + */ + public String getID() { + return ID; + } +} diff --git a/fine-third-jdk11/src/javax/xml/ws/Response.java b/fine-third-jdk11/src/javax/xml/ws/Response.java new file mode 100644 index 000000000..52c2527e2 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/Response.java @@ -0,0 +1,68 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import java.util.Map; +import java.util.concurrent.Future; + +/** The {@code Response} interface provides methods used to obtain the + * payload and context of a message sent in response to an operation + * invocation. + * + *

For asynchronous operation invocations it provides additional methods + * to check the status of the request. The {@code get(...)} methods may + * throw the standard + * set of exceptions and their cause may be a {@code RemoteException} or a + * {@link WebServiceException} that represents the error that occurred during the + * asynchronous method invocation.

+ * + * @param The type of the response + * @since 1.6, JAX-WS 2.0 +**/ +public interface Response extends Future { + /** Gets the contained response context. + * + * @return The contained response context. May be {@code null} if a + * response is not yet available. + * + **/ + Map getContext(); +} diff --git a/fine-third-jdk11/src/javax/xml/ws/ResponseWrapper.java b/fine-third-jdk11/src/javax/xml/ws/ResponseWrapper.java new file mode 100644 index 000000000..cfc49f7a3 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/ResponseWrapper.java @@ -0,0 +1,92 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import java.lang.annotation.Documented; +import java.lang.annotation.Target; +import java.lang.annotation.Retention; +import java.lang.annotation.ElementType; +import java.lang.annotation.RetentionPolicy; +/** + * Used to annotate methods in the Service Endpoint Interface with the response + * wrapper bean to be used at runtime. The default value of the {@code localName} is + * the {@code operationName} as defined in {@code WebMethod} annotation appended with + * {@code Response} and the {@code targetNamespace} is the target namespace of the SEI. + *

When starting from Java this annotation is used resolve + * overloading conflicts in document literal mode. Only the {@code className} + * is required in this case. + * + * @since 1.6, JAX-WS 2.0 +**/ + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface ResponseWrapper { + + /** + * Element's local name. + * @return local name + */ + public String localName() default ""; + + /** + * Element's namespace name. + * @return target namespace name + */ + public String targetNamespace() default ""; + + /** + * Response wrapper bean name. + * @return bean name + */ + public String className() default ""; + + /** + * wsdl:part name for the wrapper part + * + * @return wsdl:part name + * @since 1.7, JAX-WS 2.2 + */ + public String partName() default ""; + +} + diff --git a/fine-third-jdk11/src/javax/xml/ws/Service.java b/fine-third-jdk11/src/javax/xml/ws/Service.java new file mode 100644 index 000000000..29b125ab3 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/Service.java @@ -0,0 +1,824 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import javax.xml.namespace.QName; +import java.util.Iterator; +import javax.xml.ws.handler.HandlerResolver; +import javax.xml.bind.JAXBContext; +import javax.xml.ws.spi.ServiceDelegate; +import javax.xml.ws.spi.Provider; + +/** + * {@code Service} objects provide the client view of a Web service. + *

{@code Service} acts as a factory of the following: + *

    + *
  • Proxies for a target service endpoint.
  • + *
  • Instances of {@link javax.xml.ws.Dispatch} for + * dynamic message-oriented invocation of a remote + * operation. + *
  • + *
+ * + *

The ports available on a service can be enumerated using the + * {@code getPorts} method. Alternatively, you can pass a + * service endpoint interface to the unary {@code getPort} method + * and let the runtime select a compatible port. + * + *

Handler chains for all the objects created by a {@code Service} + * can be set by means of a {@code HandlerResolver}. + * + *

An {@code Executor} may be set on the service in order + * to gain better control over the threads used to dispatch asynchronous + * callbacks. For instance, thread pooling with certain parameters + * can be enabled by creating a {@code ThreadPoolExecutor} and + * registering it with the service. + * + * @since 1.6, JAX-WS 2.0 + * + * @see javax.xml.ws.spi.Provider + * @see javax.xml.ws.handler.HandlerResolver + * @see java.util.concurrent.Executor + **/ +public class Service { + + private ServiceDelegate delegate; + /** + * The orientation of a dynamic client or service. {@code MESSAGE} provides + * access to entire protocol message, {@code PAYLOAD} to protocol message + * payload only. + **/ + public enum Mode { + + /** + * Message mode. + */ + MESSAGE, + + /** + * Payload mode. + */ + PAYLOAD } + + /** + * Creates a {@code Service}. + * + * The specified WSDL document location and service qualified name MUST + * uniquely identify a {@code wsdl:service} element. + * + * @param wsdlDocumentLocation {@code URL} for the WSDL document location + * for the service + * @param serviceName {@code QName} for the service + */ + protected Service(java.net.URL wsdlDocumentLocation, QName serviceName) { + delegate = Provider.provider().createServiceDelegate(wsdlDocumentLocation, + serviceName, + this.getClass()); + } + + /** + * Creates a {@code Service}. The created instance is + * configured with the web service features. + * + * The specified WSDL document location and service qualified name MUST + * uniquely identify a {@code wsdl:service} element. + * + * @param wsdlDocumentLocation {@code URL} for the WSDL document location + * for the service + * @param serviceName {@code QName} for the service + * @param features Web Service features that must be configured on + * the service. If the provider doesn't understand a feature, + * it must throw a WebServiceException. + */ + protected Service(java.net.URL wsdlDocumentLocation, QName serviceName, WebServiceFeature ... features) { + delegate = Provider.provider().createServiceDelegate(wsdlDocumentLocation, + serviceName, + this.getClass(), features); + } + + + /** + * The {@code getPort} method returns a proxy. A service client + * uses this proxy to invoke operations on the target + * service endpoint. The {@code serviceEndpointInterface} + * specifies the service endpoint interface that is supported by + * the created dynamic proxy instance. + * + * @param Service endpoint interface. + * @param portName Qualified name of the service endpoint in + * the WSDL service description. + * @param serviceEndpointInterface Service endpoint interface + * supported by the dynamic proxy instance. + * @return Object Proxy instance that + * supports the specified service endpoint + * interface. + * @throws WebServiceException This exception is thrown in the + * following cases: + *

    + *
  • If there is an error in creation of + * the proxy. + *
  • If there is any missing WSDL metadata + * as required by this method. + *
  • If an illegal + * {@code serviceEndpointInterface} + * or {@code portName} is specified. + *
+ * @see java.lang.reflect.Proxy + * @see java.lang.reflect.InvocationHandler + **/ + public T getPort(QName portName, + Class serviceEndpointInterface) { + return delegate.getPort(portName, serviceEndpointInterface); + } + + /** + * The {@code getPort} method returns a proxy. A service client + * uses this proxy to invoke operations on the target + * service endpoint. The {@code serviceEndpointInterface} + * specifies the service endpoint interface that is supported by + * the created dynamic proxy instance. + * + * @param Service endpoint interface. + * @param portName Qualified name of the service endpoint in + * the WSDL service description. + * @param serviceEndpointInterface Service endpoint interface + * supported by the dynamic proxy instance. + * @param features A list of WebServiceFeatures to configure on the + * proxy. Supported features not in the {@code features + * } parameter will have their default values. + * @return Object Proxy instance that + * supports the specified service endpoint + * interface. + * @throws WebServiceException This exception is thrown in the + * following cases: + *
    + *
  • If there is an error in creation of + * the proxy. + *
  • If there is any missing WSDL metadata + * as required by this method. + *
  • If an illegal + * {@code serviceEndpointInterface} + * or {@code portName} is specified. + *
  • If a feature is enabled that is not compatible + * with this port or is unsupported. + *
+ * @see java.lang.reflect.Proxy + * @see java.lang.reflect.InvocationHandler + * @see WebServiceFeature + * + * @since 1.6, JAX-WS 2.1 + **/ + public T getPort(QName portName, + Class serviceEndpointInterface, WebServiceFeature... features) { + return delegate.getPort(portName, serviceEndpointInterface, features); + } + + + /** + * The {@code getPort} method returns a proxy. The parameter + * {@code serviceEndpointInterface} specifies the service + * endpoint interface that is supported by the returned proxy. + * In the implementation of this method, the JAX-WS + * runtime system takes the responsibility of selecting a protocol + * binding (and a port) and configuring the proxy accordingly. + * The returned proxy should not be reconfigured by the client. + * + * @param Service endpoint interface. + * @param serviceEndpointInterface Service endpoint interface. + * @return Object instance that supports the + * specified service endpoint interface. + * @throws WebServiceException + *
    + *
  • If there is an error during creation + * of the proxy. + *
  • If there is any missing WSDL metadata + * as required by this method. + *
  • If an illegal + * {@code serviceEndpointInterface} + * is specified. + *
+ **/ + public T getPort(Class serviceEndpointInterface) { + return delegate.getPort(serviceEndpointInterface); + } + + + /** + * The {@code getPort} method returns a proxy. The parameter + * {@code serviceEndpointInterface} specifies the service + * endpoint interface that is supported by the returned proxy. + * In the implementation of this method, the JAX-WS + * runtime system takes the responsibility of selecting a protocol + * binding (and a port) and configuring the proxy accordingly. + * The returned proxy should not be reconfigured by the client. + * + * @param Service endpoint interface. + * @param serviceEndpointInterface Service endpoint interface. + * @param features A list of WebServiceFeatures to configure on the + * proxy. Supported features not in the {@code features + * } parameter will have their default values. + * @return Object instance that supports the + * specified service endpoint interface. + * @throws WebServiceException + *
    + *
  • If there is an error during creation + * of the proxy. + *
  • If there is any missing WSDL metadata + * as required by this method. + *
  • If an illegal + * {@code serviceEndpointInterface} + * is specified. + *
  • If a feature is enabled that is not compatible + * with this port or is unsupported. + *
+ * + * @see WebServiceFeature + * + * @since 1.6, JAX-WS 2.1 + **/ + public T getPort(Class serviceEndpointInterface, + WebServiceFeature... features) { + return delegate.getPort(serviceEndpointInterface, features); + } + + + /** + * The {@code getPort} method returns a proxy. + * The parameter {@code endpointReference} specifies the + * endpoint that will be invoked by the returned proxy. If there + * are any reference parameters in the + * {@code endpointReference}, then those reference + * parameters MUST appear as SOAP headers, indicating them to be + * reference parameters, on all messages sent to the endpoint. + * The {@code endpointReference's} address MUST be used + * for invocations on the endpoint. + * The parameter {@code serviceEndpointInterface} specifies + * the service endpoint interface that is supported by the + * returned proxy. + * In the implementation of this method, the JAX-WS + * runtime system takes the responsibility of selecting a protocol + * binding (and a port) and configuring the proxy accordingly from + * the WSDL associated with this {@code Service} instance or + * from the metadata from the {@code endpointReference}. + * If this {@code Service} instance has a WSDL and + * the {@code endpointReference} metadata + * also has a WSDL, then the WSDL from this instance MUST be used. + * If this {@code Service} instance does not have a WSDL and + * the {@code endpointReference} does have a WSDL, then the + * WSDL from the {@code endpointReference} MAY be used. + * The returned proxy should not be reconfigured by the client. + * If this {@code Service} instance has a known proxy + * port that matches the information contained in + * the WSDL, + * then that proxy is returned, otherwise a WebServiceException + * is thrown. + *

+ * Calling this method has the same behavior as the following + *

+     * {@code port = service.getPort(portName, serviceEndpointInterface);}
+     * 
+ * where the {@code portName} is retrieved from the + * metadata of the {@code endpointReference} or from the + * {@code serviceEndpointInterface} and the WSDL + * associated with this {@code Service} instance. + * + * @param Service endpoint interface. + * @param endpointReference The {@code EndpointReference} + * for the target service endpoint that will be invoked by the + * returned proxy. + * @param serviceEndpointInterface Service endpoint interface. + * @param features A list of {@code WebServiceFeatures} to configure on the + * proxy. Supported features not in the {@code features + * } parameter will have their default values. + * @return Object Proxy instance that supports the + * specified service endpoint interface. + * @throws WebServiceException + *
    + *
  • If there is an error during creation + * of the proxy. + *
  • If there is any missing WSDL metadata + * as required by this method. + *
  • If the {@code endpointReference} metadata does + * not match the {@code serviceName} of this + * {@code Service} instance. + *
  • If a {@code portName} cannot be extracted + * from the WSDL or {@code endpointReference} metadata. + *
  • If an invalid + * {@code endpointReference} + * is specified. + *
  • If an invalid + * {@code serviceEndpointInterface} + * is specified. + *
  • If a feature is enabled that is not compatible + * with this port or is unsupported. + *
+ * + * @since 1.6, JAX-WS 2.1 + **/ + public T getPort(EndpointReference endpointReference, + Class serviceEndpointInterface, WebServiceFeature... features) { + return delegate.getPort(endpointReference, serviceEndpointInterface, features); + } + + /** + * Creates a new port for the service. Ports created in this way contain + * no WSDL port type information and can only be used for creating + * {@code Dispatch}instances. + * + * @param portName Qualified name for the target service endpoint. + * @param bindingId A String identifier of a binding. + * @param endpointAddress Address of the target service endpoint as a URI. + * @throws WebServiceException If any error in the creation of + * the port. + * + * @see javax.xml.ws.soap.SOAPBinding#SOAP11HTTP_BINDING + * @see javax.xml.ws.soap.SOAPBinding#SOAP12HTTP_BINDING + * @see javax.xml.ws.http.HTTPBinding#HTTP_BINDING + **/ + public void addPort(QName portName, String bindingId, String endpointAddress) { + delegate.addPort(portName, bindingId, endpointAddress); + } + + + /** + * Creates a {@code Dispatch} instance for use with objects of + * the client's choosing. + * + * @param The type of the message or payload + * @param portName Qualified name for the target service endpoint + * @param type The class of object used for messages or message + * payloads. Implementations are required to support + * {@code javax.xml.transform.Source}, {@code javax.xml.soap.SOAPMessage} + * and {@code javax.activation.DataSource}, depending on + * the binding in use. + * @param mode Controls whether the created dispatch instance is message + * or payload oriented, i.e. whether the client will work with complete + * protocol messages or message payloads. E.g. when using the SOAP + * protocol, this parameter controls whether the client will work with + * SOAP messages or the contents of a SOAP body. Mode MUST be MESSAGE + * when type is SOAPMessage. + * + * @return Dispatch instance. + * @throws WebServiceException If any error in the creation of + * the {@code Dispatch} object. + * + * @see javax.xml.transform.Source + * @see javax.xml.soap.SOAPMessage + **/ + public Dispatch createDispatch(QName portName, Class type, Mode mode) { + return delegate.createDispatch(portName, type, mode); + } + + + /** + * Creates a {@code Dispatch} instance for use with objects of + * the client's choosing. + * + * @param The type of the message or payload + * @param portName Qualified name for the target service endpoint + * @param type The class of object used for messages or message + * payloads. Implementations are required to support + * {@code javax.xml.transform.Source} and {@code javax.xml.soap.SOAPMessage}. + * @param mode Controls whether the created dispatch instance is message + * or payload oriented, i.e. whether the client will work with complete + * protocol messages or message payloads. E.g. when using the SOAP + * protocol, this parameter controls whether the client will work with + * SOAP messages or the contents of a SOAP body. Mode MUST be {@code MESSAGE} + * when type is {@code SOAPMessage}. + * @param features A list of {@code WebServiceFeatures} to configure on the + * proxy. Supported features not in the {@code features + * } parameter will have their default values. + * + * @return Dispatch instance. + * @throws WebServiceException If any error in the creation of + * the {@code Dispatch} object or if a + * feature is enabled that is not compatible with + * this port or is unsupported. + * + * @see javax.xml.transform.Source + * @see javax.xml.soap.SOAPMessage + * @see WebServiceFeature + * + * @since 1.6, JAX-WS 2.1 + **/ + public Dispatch createDispatch(QName portName, Class type, + Service.Mode mode, WebServiceFeature... features) { + return delegate.createDispatch(portName, type, mode, features); + } + + + /** + * Creates a {@code Dispatch} instance for use with objects of + * the client's choosing. If there + * are any reference parameters in the + * {@code endpointReference}, then those reference + * parameters MUST appear as SOAP headers, indicating them to be + * reference parameters, on all messages sent to the endpoint. + * The {@code endpointReference's} address MUST be used + * for invocations on the endpoint. + * In the implementation of this method, the JAX-WS + * runtime system takes the responsibility of selecting a protocol + * binding (and a port) and configuring the dispatch accordingly from + * the WSDL associated with this {@code Service} instance or + * from the metadata from the {@code endpointReference}. + * If this {@code Service} instance has a WSDL and + * the {@code endpointReference} + * also has a WSDL in its metadata, then the WSDL from this instance MUST be used. + * If this {@code Service} instance does not have a WSDL and + * the {@code endpointReference} does have a WSDL, then the + * WSDL from the {@code endpointReference} MAY be used. + * An implementation MUST be able to retrieve the {@code portName} from the + * {@code endpointReference} metadata. + *

+ * This method behaves the same as calling + *

+     * {@code dispatch = service.createDispatch(portName, type, mode, features);}
+     * 
+ * where the {@code portName} is retrieved from the + * WSDL or {@code EndpointReference} metadata. + * + * @param The type of the message or payload + * @param endpointReference The {@code EndpointReference} + * for the target service endpoint that will be invoked by the + * returned {@code Dispatch} object. + * @param type The class of object used to messages or message + * payloads. Implementations are required to support + * {@code javax.xml.transform.Source} and {@code javax.xml.soap.SOAPMessage}. + * @param mode Controls whether the created dispatch instance is message + * or payload oriented, i.e. whether the client will work with complete + * protocol messages or message payloads. E.g. when using the SOAP + * protocol, this parameter controls whether the client will work with + * SOAP messages or the contents of a SOAP body. Mode MUST be {@code MESSAGE} + * when type is {@code SOAPMessage}. + * @param features An array of {@code WebServiceFeatures} to configure on the + * proxy. Supported features not in the {@code features + * } parameter will have their default values. + * + * @return Dispatch instance + * @throws WebServiceException + *
    + *
  • If there is any missing WSDL metadata + * as required by this method. + *
  • If the {@code endpointReference} metadata does + * not match the {@code serviceName} or {@code portName} + * of a WSDL associated + * with this {@code Service} instance. + *
  • If the {@code portName} cannot be determined + * from the {@code EndpointReference} metadata. + *
  • If any error in the creation of + * the {@code Dispatch} object. + *
  • If a feature is enabled that is not + * compatible with this port or is unsupported. + *
+ * + * @see javax.xml.transform.Source + * @see javax.xml.soap.SOAPMessage + * @see WebServiceFeature + * + * @since 1.6, JAX-WS 2.1 + **/ + public Dispatch createDispatch(EndpointReference endpointReference, + Class type, Service.Mode mode, + WebServiceFeature... features) { + return delegate.createDispatch(endpointReference, type, mode, features); + } + + /** + * Creates a {@code Dispatch} instance for use with JAXB + * generated objects. + * + * @param portName Qualified name for the target service endpoint + * @param context The JAXB context used to marshall and unmarshall + * messages or message payloads. + * @param mode Controls whether the created dispatch instance is message + * or payload oriented, i.e. whether the client will work with complete + * protocol messages or message payloads. E.g. when using the SOAP + * protocol, this parameter controls whether the client will work with + * SOAP messages or the contents of a SOAP body. + * + * @return Dispatch instance. + * @throws WebServiceException If any error in the creation of + * the {@code Dispatch} object. + * + * @see javax.xml.bind.JAXBContext + **/ + public Dispatch createDispatch(QName portName, JAXBContext context, + Mode mode) { + return delegate.createDispatch(portName, context, mode); + } + + + /** + * Creates a {@code Dispatch} instance for use with JAXB + * generated objects. + * + * @param portName Qualified name for the target service endpoint + * @param context The JAXB context used to marshall and unmarshall + * messages or message payloads. + * @param mode Controls whether the created dispatch instance is message + * or payload oriented, i.e. whether the client will work with complete + * protocol messages or message payloads. E.g. when using the SOAP + * protocol, this parameter controls whether the client will work with + * SOAP messages or the contents of a SOAP body. + * @param features A list of {@code WebServiceFeatures} to configure on the + * proxy. Supported features not in the {@code features + * } parameter will have their default values. + * + * @return Dispatch instance. + * @throws WebServiceException If any error in the creation of + * the {@code Dispatch} object or if a + * feature is enabled that is not compatible with + * this port or is unsupported. + * + * @see javax.xml.bind.JAXBContext + * @see WebServiceFeature + * + * @since 1.6, JAX-WS 2.1 + **/ + public Dispatch createDispatch(QName portName, + JAXBContext context, Service.Mode mode, WebServiceFeature... features) { + return delegate.createDispatch(portName, context, mode, features); + } + + + /** + * Creates a {@code Dispatch} instance for use with JAXB + * generated objects. If there + * are any reference parameters in the + * {@code endpointReference}, then those reference + * parameters MUST appear as SOAP headers, indicating them to be + * reference parameters, on all messages sent to the endpoint. + * The {@code endpointReference's} address MUST be used + * for invocations on the endpoint. + * In the implementation of this method, the JAX-WS + * runtime system takes the responsibility of selecting a protocol + * binding (and a port) and configuring the dispatch accordingly from + * the WSDL associated with this {@code Service} instance or + * from the metadata from the {@code endpointReference}. + * If this {@code Service} instance has a WSDL and + * the {@code endpointReference} + * also has a WSDL in its metadata, then the WSDL from this instance + * MUST be used. + * If this {@code Service} instance does not have a WSDL and + * the {@code endpointReference} does have a WSDL, then the + * WSDL from the {@code endpointReference} MAY be used. + * An implementation MUST be able to retrieve the {@code portName} from the + * {@code endpointReference} metadata. + *

+ * This method behavies the same as calling + *

+     * {@code dispatch = service.createDispatch(portName, context, mode, features);}
+     * 
+ * where the {@code portName} is retrieved from the + * WSDL or {@code endpointReference} metadata. + * + * @param endpointReference The {@code EndpointReference} + * for the target service endpoint that will be invoked by the + * returned {@code Dispatch} object. + * @param context The JAXB context used to marshall and unmarshall + * messages or message payloads. + * @param mode Controls whether the created dispatch instance is message + * or payload oriented, i.e. whether the client will work with complete + * protocol messages or message payloads. E.g. when using the SOAP + * protocol, this parameter controls whether the client will work with + * SOAP messages or the contents of a SOAP body. + * @param features An array of {@code WebServiceFeatures} to configure on the + * proxy. Supported features not in the {@code features + * } parameter will have their default values. + * + * @return Dispatch instance + * @throws WebServiceException + *
    + *
  • If there is any missing WSDL metadata + * as required by this method. + *
  • If the {@code endpointReference} metadata does + * not match the {@code serviceName} or {@code portName} + * of a WSDL associated + * with this {@code Service} instance. + *
  • If the {@code portName} cannot be determined + * from the {@code EndpointReference} metadata. + *
  • If any error in the creation of + * the {@code Dispatch} object. + *
  • if a feature is enabled that is not + * compatible with this port or is unsupported. + *
+ * + * @see javax.xml.bind.JAXBContext + * @see WebServiceFeature + * + * @since 1.6, JAX-WS 2.1 + **/ + public Dispatch createDispatch(EndpointReference endpointReference, + JAXBContext context, Service.Mode mode, + WebServiceFeature... features) { + return delegate.createDispatch(endpointReference, context, mode, features); + } + + /** + * Gets the name of this service. + * @return Qualified name of this service + **/ + public QName getServiceName() { + return delegate.getServiceName(); + } + + /** + * Returns an {@code Iterator} for the list of + * {@code QName}s of service endpoints grouped by this + * service + * + * @return Returns {@code java.util.Iterator} with elements + * of type {@code javax.xml.namespace.QName}. + * @throws WebServiceException If this Service class does not + * have access to the required WSDL metadata. + **/ + public Iterator getPorts() { + return delegate.getPorts(); + } + + /** + * Gets the location of the WSDL document for this Service. + * + * @return URL for the location of the WSDL document for + * this service. + **/ + public java.net.URL getWSDLDocumentLocation() { + return delegate.getWSDLDocumentLocation(); + } + + /** + * Returns the configured handler resolver. + * + * @return HandlerResolver The {@code HandlerResolver} being + * used by this {@code Service} instance, or {@code null} + * if there isn't one. + **/ + public HandlerResolver getHandlerResolver() { + return delegate.getHandlerResolver(); + } + + /** + * Sets the {@code HandlerResolver} for this {@code Service} + * instance. + *

+ * The handler resolver, if present, will be called once for each + * proxy or dispatch instance that is created, and the handler chain + * returned by the resolver will be set on the instance. + * + * @param handlerResolver The {@code HandlerResolver} to use + * for all subsequently created proxy/dispatch objects. + * + * @see javax.xml.ws.handler.HandlerResolver + **/ + public void setHandlerResolver(HandlerResolver handlerResolver) { + delegate.setHandlerResolver(handlerResolver); + } + + /** + * Returns the executor for this {@code Service}instance. + * + * The executor is used for all asynchronous invocations that + * require callbacks. + * + * @return The {@code java.util.concurrent.Executor} to be + * used to invoke a callback. + * + * @see java.util.concurrent.Executor + **/ + public java.util.concurrent.Executor getExecutor() { + return delegate.getExecutor(); + } + + /** + * Sets the executor for this {@code Service} instance. + * + * The executor is used for all asynchronous invocations that + * require callbacks. + * + * @param executor The {@code java.util.concurrent.Executor} + * to be used to invoke a callback. + * + * @throws SecurityException If the instance does not support + * setting an executor for security reasons (e.g. the + * necessary permissions are missing). + * + * @see java.util.concurrent.Executor + **/ + public void setExecutor(java.util.concurrent.Executor executor) { + delegate.setExecutor(executor); + } + + /** + * Creates a {@code Service} instance. + * + * The specified WSDL document location and service qualified name MUST + * uniquely identify a {@code wsdl:service} element. + * + * @param wsdlDocumentLocation {@code URL} for the WSDL document location + * for the service + * @param serviceName {@code QName} for the service + * @return Service instance + * @throws WebServiceException If any error in creation of the + * specified service. + **/ + public static Service create( + java.net.URL wsdlDocumentLocation, + QName serviceName) { + return new Service(wsdlDocumentLocation, serviceName); + } + + /** + * Creates a {@code Service} instance. The created instance is + * configured with the web service features. + * + * The specified WSDL document location and service qualified name MUST + * uniquely identify a {@code wsdl:service} element. + * + * @param wsdlDocumentLocation {@code URL} for the WSDL document location + * for the service + * @param serviceName {@code QName} for the service + * @param features Web Service features that must be configured on + * the service. If the provider doesn't understand a feature, + * it must throw a WebServiceException. + * @return Service instance configured with requested web service features + * @throws WebServiceException If any error in creation of the + * specified service. + * @since 1.7, JAX-WS 2.2 + **/ + public static Service create( + java.net.URL wsdlDocumentLocation, + QName serviceName, WebServiceFeature ... features) { + return new Service(wsdlDocumentLocation, serviceName, features); + } + + /** + * Creates a {@code Service} instance. + * + * @param serviceName {@code QName} for the service + * @return Service instance + * @throws WebServiceException If any error in creation of the + * specified service + */ + public static Service create(QName serviceName) { + return new Service(null, serviceName); + } + + /** + * Creates a {@code Service} instance. The created instance is + * configured with the web service features. + * + * @param serviceName {@code QName} for the service + * @param features Web Service features that must be configured on + * the service. If the provider doesn't understand a feature, + * it must throw a WebServiceException. + * @return Service instance configured with requested web service features + * @throws WebServiceException If any error in creation of the + * specified service + * + * @since 1.7, JAX-WS 2.2 + */ + public static Service create(QName serviceName, WebServiceFeature ... features) { + return new Service(null, serviceName, features); + } +} + + + diff --git a/fine-third-jdk11/src/javax/xml/ws/ServiceMode.java b/fine-third-jdk11/src/javax/xml/ws/ServiceMode.java new file mode 100644 index 000000000..2622bece7 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/ServiceMode.java @@ -0,0 +1,70 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import java.lang.annotation.Documented; +import java.lang.annotation.Target; +import java.lang.annotation.Retention; +import java.lang.annotation.ElementType; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Inherited; + +/** + * Used to indicate whether a {@link Provider} implementation wishes to work + * with entire protocol messages or just with protocol message payloads. + * + * @since 1.6, JAX-WS 2.0 +**/ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Inherited +@Documented +public @interface ServiceMode { + /** + * Service mode. {@code PAYLOAD} indicates that the {@code Provider} implementation + * wishes to work with protocol message payloads only. {@code MESSAGE} indicates + * that the {@code Provider} implementation wishes to work with entire protocol + * messages. + * + * @return Service mode. + **/ + public Service.Mode value() default Service.Mode.PAYLOAD; +} diff --git a/fine-third-jdk11/src/javax/xml/ws/WebEndpoint.java b/fine-third-jdk11/src/javax/xml/ws/WebEndpoint.java new file mode 100644 index 000000000..9a149cde5 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/WebEndpoint.java @@ -0,0 +1,73 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import java.lang.annotation.Documented; +import java.lang.annotation.Target; +import java.lang.annotation.Retention; +import java.lang.annotation.ElementType; +import java.lang.annotation.RetentionPolicy; + +/** + * Used to annotate the getPortName() + * methods of a generated service interface. + * + *

The information specified in this annotation is sufficient + * to uniquely identify a {@code wsdl:port} element + * inside a {@code wsdl:service}. The latter is + * determined based on the value of the {@code WebServiceClient} + * annotation on the generated service interface itself. + * + * @since 1.6, JAX-WS 2.0 + * + * @see javax.xml.ws.WebServiceClient +**/ +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface WebEndpoint { + /** + * The local name of the endpoint. + * + * @return ocal name of the endpoint + **/ + String name() default ""; +} diff --git a/fine-third-jdk11/src/javax/xml/ws/WebFault.java b/fine-third-jdk11/src/javax/xml/ws/WebFault.java new file mode 100644 index 000000000..4d92d8d1d --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/WebFault.java @@ -0,0 +1,89 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import java.lang.annotation.Documented; +import java.lang.annotation.Target; +import java.lang.annotation.Retention; +import java.lang.annotation.ElementType; +import java.lang.annotation.RetentionPolicy; + +/** + * Used to annotate service specific exception classes to customize + * to the local and namespace name of the fault element and the name + * of the fault bean. + * + * @since 1.6, JAX-WS 2.0 +**/ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface WebFault { + /** + * Element's local name. + * + * @return loxL name + */ + public String name() default ""; + + /** + * Element's namespace name. + * + * @return target namespace name + */ + public String targetNamespace() default ""; + + /** + * Fault bean name. + * + * @return bean name + */ + public String faultBean() default ""; + + /** + * wsdl:Message's name. Default name is the exception's class name. + * + * @return wsdl:Message's name + * @since 1.7, JAX-WS 2.2 + */ + public String messageName() default ""; + +} diff --git a/fine-third-jdk11/src/javax/xml/ws/WebServiceClient.java b/fine-third-jdk11/src/javax/xml/ws/WebServiceClient.java new file mode 100644 index 000000000..635a86440 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/WebServiceClient.java @@ -0,0 +1,84 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import java.lang.annotation.Documented; +import java.lang.annotation.Target; +import java.lang.annotation.Retention; +import java.lang.annotation.ElementType; +import java.lang.annotation.RetentionPolicy; + +/** + * Used to annotate a generated service interface. + * + *

The information specified in this annotation is sufficient + * to uniquely identify a {@code wsdl:service} + * element inside a WSDL document. This {@code wsdl:service} + * element represents the Web service for which the generated + * service interface provides a client view. + * + * @since 1.6, JAX-WS 2.0 +**/ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface WebServiceClient { + /** + * The local name of the Web service. + * + * @return local name + */ + String name() default ""; + + /** + * The namespace for the Web service. + * + * @return target namespace name + */ + String targetNamespace() default ""; + + /** + * The location of the WSDL document for the service (a URL). + * + * @return location of the WSDL document (a URL) + */ + String wsdlLocation() default ""; +} diff --git a/fine-third-jdk11/src/javax/xml/ws/WebServiceContext.java b/fine-third-jdk11/src/javax/xml/ws/WebServiceContext.java new file mode 100644 index 000000000..65515df91 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/WebServiceContext.java @@ -0,0 +1,167 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import java.security.Principal; +import javax.xml.ws.handler.MessageContext; +import javax.xml.ws.wsaddressing.W3CEndpointReference; +import org.w3c.dom.Element; + + +/** + * A {@code WebServiceContext} makes it possible for + * a web service endpoint implementation class to access + * message context and security information relative to + * a request being served. + * + * Typically a {@code WebServiceContext} is injected + * into an endpoint implementation class using the + * {@code Resource} annotation. + * + * @since 1.6, JAX-WS 2.0 + * + * @see javax.annotation.Resource + **/ +public interface WebServiceContext { + + /** + * Returns the {@code MessageContext} for the request being served + * at the time this method is called. Only properties with + * APPLICATION scope will be visible to the application. + * + * @return MessageContext The message context. + * + * @throws IllegalStateException This exception is thrown + * if the method is called while no request is + * being serviced. + * + * @see javax.xml.ws.handler.MessageContext + * @see javax.xml.ws.handler.MessageContext.Scope + * @see java.lang.IllegalStateException + **/ + public MessageContext getMessageContext(); + + /** + * Returns the Principal that identifies the sender + * of the request currently being serviced. If the + * sender has not been authenticated, the method + * returns {@code null}. + * + * @return Principal The principal object. + * + * @throws IllegalStateException This exception is thrown + * if the method is called while no request is + * being serviced. + * + * @see java.security.Principal + * @see java.lang.IllegalStateException + **/ + public Principal getUserPrincipal(); + + /** + * Returns a boolean indicating whether the + * authenticated user is included in the specified + * logical role. If the user has not been + * authenticated, the method returns {@code false}. + * + * @param role A {@code String} specifying the name of the role + * + * @return a {@code boolean} indicating whether + * the sender of the request belongs to a given role + * + * @throws IllegalStateException This exception is thrown + * if the method is called while no request is + * being serviced. + **/ + public boolean isUserInRole(String role); + + /** + * Returns the {@code EndpointReference} for this + * endpoint. + *

+ * If the {@link Binding} for this {@code bindingProvider} is + * either SOAP1.1/HTTP or SOAP1.2/HTTP, then a + * {@code W3CEndpointReference} MUST be returned. + * + * @param referenceParameters Reference parameters to be associated with the + * returned {@code EndpointReference} instance. + * @return EndpointReference of the endpoint associated with this + * {@code WebServiceContext}. + * If the returned {@code EndpointReference} is of type + * {@code W3CEndpointReference} then it MUST contain the + * the specified {@code referenceParameters}. + * + * @throws IllegalStateException This exception is thrown + * if the method is called while no request is + * being serviced. + * + * @see W3CEndpointReference + * + * @since 1.6, JAX-WS 2.1 + */ + public EndpointReference getEndpointReference(Element... referenceParameters); + + /** + * Returns the {@code EndpointReference} associated with + * this endpoint. + * + * @param The type of {@code EndpointReference}. + * @param clazz The type of {@code EndpointReference} that + * MUST be returned. + * @param referenceParameters Reference parameters to be associated with the + * returned {@code EndpointReference} instance. + * @return EndpointReference of type {@code clazz} of the endpoint + * associated with this {@code WebServiceContext} instance. + * If the returned {@code EndpointReference} is of type + * {@code W3CEndpointReference} then it MUST contain the + * the specified {@code referenceParameters}. + * + * @throws IllegalStateException This exception is thrown + * if the method is called while no request is + * being serviced. + * @throws WebServiceException If the {@code clazz} type of + * {@code EndpointReference} is not supported. + * + * @since 1.6, JAX-WS 2.1 + **/ + public T getEndpointReference(Class clazz, + Element... referenceParameters); +} diff --git a/fine-third-jdk11/src/javax/xml/ws/WebServiceException.java b/fine-third-jdk11/src/javax/xml/ws/WebServiceException.java new file mode 100644 index 000000000..4feff9d5e --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/WebServiceException.java @@ -0,0 +1,95 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +/** The {@code WebServiceException} class is the base + * exception class for all JAX-WS API runtime exceptions. + * + * @since 1.6, JAX-WS 2.0 +**/ + +public class WebServiceException extends java.lang.RuntimeException { + + /** Constructs a new exception with {@code null} as its + * detail message. The cause is not initialized. + **/ + public WebServiceException() { + super(); + } + + /** Constructs a new exception with the specified detail + * message. The cause is not initialized. + * @param message The detail message which is later + * retrieved using the getMessage method + **/ + public WebServiceException(String message) { + super(message); + } + + /** Constructs a new exception with the specified detail + * message and cause. + * + * @param message The detail message which is later retrieved + * using the getMessage method + * @param cause The cause which is saved for the later + * retrieval throw by the getCause method + **/ + public WebServiceException(String message, Throwable cause) { + super(message,cause); + } + + /** Constructs a new WebServiceException with the specified cause + * and a detail message of + * {@code (cause==null ? null : cause.toString())} + * (which typically contains the + * class and detail message of {@code cause}). + * + * @param cause The cause which is saved for the later + * retrieval throw by the getCause method. + * (A {@code null} value is permitted, and + * indicates that the cause is nonexistent or + * unknown.) + **/ + public WebServiceException(Throwable cause) { + super(cause); + } + +} diff --git a/fine-third-jdk11/src/javax/xml/ws/WebServiceFeature.java b/fine-third-jdk11/src/javax/xml/ws/WebServiceFeature.java new file mode 100644 index 000000000..eecf33d69 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/WebServiceFeature.java @@ -0,0 +1,97 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + + +/** + * A WebServiceFeature is used to represent a feature that can be + * enabled or disabled for a web service. + *

+ * The JAX-WS specification will define some standard features and + * JAX-WS implementors are free to define additional features if + * necessary. Vendor specific features may not be portable so + * caution should be used when using them. Each Feature definition + * MUST define a {@code public static final String ID} + * that can be used in the Feature annotation to refer + * to the feature. This ID MUST be unique across all features + * of all vendors. When defining a vendor specific feature ID, + * use a vendor specific namespace in the ID string. + * + * @see javax.xml.ws.RespectBindingFeature + * @see javax.xml.ws.soap.AddressingFeature + * @see javax.xml.ws.soap.MTOMFeature + * + * @since 1.6, JAX-WS 2.1 + */ +public abstract class WebServiceFeature { + /** + * Each Feature definition MUST define a public static final + * String ID that can be used in the Feature annotation to refer + * to the feature. + */ + // public static final String ID = "some unique feature Identifier"; + + /** + * Get the unique identifier for this WebServiceFeature. + * + * @return the unique identifier for this feature. + */ + public abstract String getID(); + + /** + * Specifies if the feature is enabled or disabled + */ + protected boolean enabled = false; + + /** + * Default constructor. + */ + protected WebServiceFeature() {} + + /** + * Returns {@code true} if this feature is enabled. + * + * @return {@code true} if and only if the feature is enabled . + */ + public boolean isEnabled() { + return enabled; + } +} diff --git a/fine-third-jdk11/src/javax/xml/ws/WebServicePermission.java b/fine-third-jdk11/src/javax/xml/ws/WebServicePermission.java new file mode 100644 index 000000000..ae829693b --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/WebServicePermission.java @@ -0,0 +1,99 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import java.security.BasicPermission; + +/** + * This class defines web service permissions. + *

+ * Web service Permissions are identified by name (also referred to as + * a "target name") alone. There are no actions associated + * with them. + *

+ * The following permission target name is defined: + *

+ *
publishEndpoint + *
+ * The {@code publishEndpoint} permission allows publishing a + * web service endpoint using the {@code publish} methods + * defined by the {@code javax.xml.ws.Endpoint} class. + *

+ * Granting {@code publishEndpoint} allows the application to be + * exposed as a network service. Depending on the security of the runtime and + * the security of the application, this may introduce a security hole that + * is remotely exploitable. + * + * @see javax.xml.ws.Endpoint + * @see java.security.BasicPermission + * @see java.security.Permission + * @see java.security.Permissions + * @see java.lang.SecurityManager + * @see java.net.SocketPermission + * @since 1.6 + */ +public final class WebServicePermission extends BasicPermission { + + private static final long serialVersionUID = -146474640053770988L; + + /** + * Creates a new permission with the specified name. + * + * @param name the name of the {@code WebServicePermission} + */ + public WebServicePermission(String name) { + super(name); + } + + /** + * Creates a new permission with the specified name and actions. + * + * The {@code actions} parameter is currently unused and + * it should be {@code null}. + * + * @param name the name of the {@code WebServicePermission} + * @param actions should be {@code null} + */ + public WebServicePermission(String name, String actions) { + super(name, actions); + } + +} diff --git a/fine-third-jdk11/src/javax/xml/ws/WebServiceProvider.java b/fine-third-jdk11/src/javax/xml/ws/WebServiceProvider.java new file mode 100644 index 000000000..f54713fed --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/WebServiceProvider.java @@ -0,0 +1,85 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import java.lang.annotation.Documented; +import java.lang.annotation.Target; +import java.lang.annotation.Retention; +import java.lang.annotation.ElementType; +import java.lang.annotation.RetentionPolicy; +/** + * Used to annotate a Provider implementation class. + * + * @since 1.6, JAX-WS 2.0 + * @see javax.xml.ws.Provider + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface WebServiceProvider { + /** + * Location of the WSDL description for the service. + * + * @return location of the WSDL description + */ + String wsdlLocation() default ""; + + /** + * Service name. + * + * @return service name + */ + String serviceName() default ""; + + /** + * Target namespace for the service + * + * @return target namespace + */ + String targetNamespace() default ""; + + /** + * Port name. + * + * @return port name + */ + String portName() default ""; +} diff --git a/fine-third-jdk11/src/javax/xml/ws/WebServiceRef.java b/fine-third-jdk11/src/javax/xml/ws/WebServiceRef.java new file mode 100644 index 000000000..29c206c32 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/WebServiceRef.java @@ -0,0 +1,179 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import javax.xml.ws.soap.Addressing; +import javax.xml.ws.spi.WebServiceFeatureAnnotation; +import java.lang.annotation.Documented; +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import javax.annotation.Resource; + +/** + * The {@code WebServiceRef} annotation is used to + * define a reference to a web service and + * (optionally) an injection target for it. + * It can be used to inject both service and proxy + * instances. These injected references are not thread safe. + * If the references are accessed by multiple threads, + * usual synchronization techinques can be used to + * support multiple threads. + * + *

+ * Web service references are resources in the Java EE 5 sense. + * The annotations (for example, {@link Addressing}) annotated with + * meta-annotation {@link WebServiceFeatureAnnotation} + * can be used in conjunction with {@code WebServiceRef}. + * The created reference MUST be configured with annotation's web service + * feature. + * + *

+ * For example, in the code below, the injected + * {@code StockQuoteProvider} proxy MUST + * have WS-Addressing enabled as specifed by the + * {@link Addressing} + * annotation. + * + *


+ *    public class MyClient {
+ *       {@literal @}Addressing
+ *       {@literal @}WebServiceRef(StockQuoteService.class)
+ *       private StockQuoteProvider stockQuoteProvider;
+ *       ...
+ *    }
+ * 
+ * + *

+ * If a JAX-WS implementation encounters an unsupported or unrecognized + * annotation annotated with the {@code WebServiceFeatureAnnotation} + * that is specified with {@code WebServiceRef}, an ERROR MUST be given. + * + * @see Resource + * @see WebServiceFeatureAnnotation + * + * @since 1.6, JAX-WS 2.0 + * + **/ + +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Repeatable(WebServiceRefs.class) +public @interface WebServiceRef { + /** + * The JNDI name of the resource. For field annotations, + * the default is the field name. For method annotations, + * the default is the JavaBeans property name corresponding + * to the method. For class annotations, there is no default + * and this MUST be specified. + * + * The JNDI name can be absolute(with any logical namespace) or relative + * to JNDI {@code java:comp/env} namespace. + * + * @return absolute or relative JNDI name + */ + String name() default ""; + + /** + * The Java type of the resource. For field annotations, + * the default is the type of the field. For method annotations, + * the default is the type of the JavaBeans property. + * For class annotations, there is no default and this MUST be + * specified. + * + * @return type of the resource + */ + Class type() default Object.class; + + /** + * A product specific name that this resource should be mapped to. + * The name of this resource, as defined by the {@code name} + * element or defaulted, is a name that is local to the application + * component using the resource. (When a relative JNDI name + * is specified, then it's a name in the JNDI + * {@code java:comp/env} namespace.) Many application servers + * provide a way to map these local names to names of resources + * known to the application server. This mapped name is often a + * global JNDI name, but may be a name of any form. + *

+ * Application servers are not required to support any particular + * form or type of mapped name, nor the ability to use mapped names. + * The mapped name is product-dependent and often installation-dependent. + * No use of a mapped name is portable. + * + * @return product specific resource name + */ + String mappedName() default ""; + + /** + * The service class, always a type extending + * {@code javax.xml.ws.Service}. This element MUST be specified + * whenever the type of the reference is a service endpoint interface. + * + * @return the service class extending {@code javax.xml.ws.Service} + */ + // 2.1 has Class value() default Object.class; + // Fixing this raw Class type correctly in 2.2 API. This shouldn't cause + // any compatibility issues for applications. + Class value() default Service.class; + + /** + * A URL pointing to the WSDL document for the web service. + * If not specified, the WSDL location specified by annotations + * on the resource type is used instead. + * + * @return a URL pointing to the WSDL document + */ + String wsdlLocation() default ""; + + /** + * A portable JNDI lookup name that resolves to the target + * web service reference. + * + * @return portable JNDI lookup name + * @since 1.7, JAX-WS 2.2 + */ + String lookup() default ""; + +} diff --git a/fine-third-jdk11/src/javax/xml/ws/WebServiceRefs.java b/fine-third-jdk11/src/javax/xml/ws/WebServiceRefs.java new file mode 100644 index 000000000..b99e9537c --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/WebServiceRefs.java @@ -0,0 +1,100 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws; + +import java.lang.annotation.Documented; +import java.lang.annotation.Target; +import java.lang.annotation.Retention; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +/** + * The {@code WebServiceRefs} annotation allows + * multiple web service references to be declared at the + * class level. + * + *

+ * It can be used to inject both service and proxy + * instances. These injected references are not thread safe. + * If the references are accessed by multiple threads, + * usual synchronization techniques can be used to + * support multiple threads. + * + *

+ * There is no way to associate web service features with + * the injected instances. If an instance needs to be + * configured with web service features, use @WebServiceRef + * to inject the resource along with its features. + * + *

+ * Example: The {@code StockQuoteProvider} + * proxy instance, and the {@code StockQuoteService} service + * instance are injected using @WebServiceRefs. + * + *


+ *    {@literal @}WebServiceRefs({{@literal @}WebServiceRef(name="service/stockquoteservice", value=StockQuoteService.class),
+ *                     {@literal @}WebServiceRef(name="service/stockquoteprovider", type=StockQuoteProvider.class, value=StockQuoteService.class})
+ *    public class MyClient {
+ *        void init() {
+ *            Context ic = new InitialContext();
+ *            StockQuoteService service = (StockQuoteService) ic.lookup("java:comp/env/service/stockquoteservice");
+ *            StockQuoteProvider port = (StockQuoteProvider) ic.lookup("java:comp/env/service/stockquoteprovider");
+ *            ...
+ *       }
+ *       ...
+ *    }
+ * 
+ * + * @see WebServiceRef + * @since 1.6, JAX-WS 2.0 + */ + +@Documented +@Retention(RUNTIME) +@Target(TYPE) +public @interface WebServiceRefs { + /** + * Array used for multiple web service reference declarations. + * + * @return multiple web service reference declarations + */ + WebServiceRef[] value(); +} diff --git a/fine-third-jdk11/src/javax/xml/ws/handler/Handler.java b/fine-third-jdk11/src/javax/xml/ws/handler/Handler.java new file mode 100644 index 000000000..abfa3320f --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/handler/Handler.java @@ -0,0 +1,102 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.handler; + +import javax.xml.ws.ProtocolException; + +/** The {@code Handler} interface + * is the base interface for JAX-WS handlers. + * + * @param message context + * @since 1.6, JAX-WS 2.0 +**/ +public interface Handler { + + /** The {@code handleMessage} method is invoked for normal processing + * of inbound and outbound messages. Refer to the description of the handler + * framework in the JAX-WS specification for full details. + * + * @param context the message context. + * @return An indication of whether handler processing should continue for + * the current message + *
    + *
  • Return {@code true} to continue + * processing.
  • + *
  • Return {@code false} to block + * processing.
  • + *
+ * @throws RuntimeException Causes the JAX-WS runtime to cease + * handler processing and generate a fault. + * @throws ProtocolException Causes the JAX-WS runtime to switch to + * fault message processing. + **/ + public boolean handleMessage(C context); + + /** The {@code handleFault} method is invoked for fault message + * processing. Refer to the description of the handler + * framework in the JAX-WS specification for full details. + * + * @param context the message context + * @return An indication of whether handler fault processing should continue + * for the current message + *
    + *
  • Return {@code true} to continue + * processing.
  • + *
  • Return {@code false} to block + * processing.
  • + *
+ * @throws RuntimeException Causes the JAX-WS runtime to cease + * handler fault processing and dispatch the fault. + * @throws ProtocolException Causes the JAX-WS runtime to cease + * handler fault processing and dispatch the fault. + **/ + public boolean handleFault(C context); + + /** + * Called at the conclusion of a message exchange pattern just prior to + * the JAX-WS runtime dispatching a message, fault or exception. Refer to + * the description of the handler + * framework in the JAX-WS specification for full details. + * + * @param context the message context + **/ + public void close(MessageContext context); +} diff --git a/fine-third-jdk11/src/javax/xml/ws/handler/HandlerResolver.java b/fine-third-jdk11/src/javax/xml/ws/handler/HandlerResolver.java new file mode 100644 index 000000000..be3ed7860 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/handler/HandlerResolver.java @@ -0,0 +1,68 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.handler; + +/** + * {@code HandlerResolver} is an interface implemented + * by an application to get control over the handler chain + * set on proxy/dispatch objects at the time of their creation. + *

+ * A {@code HandlerResolver} may be set on a {@code Service} + * using the {@code setHandlerResolver} method. + *

+ * When the runtime invokes a {@code HandlerResolver}, it will + * pass it a {@code PortInfo} object containing information + * about the port that the proxy/dispatch object will be accessing. + * + * @see javax.xml.ws.Service#setHandlerResolver + * + * @since 1.6, JAX-WS 2.0 +**/ +public interface HandlerResolver { + + /** + * Gets the handler chain for the specified port. + * + * @param portInfo Contains information about the port being accessed. + * @return {@code java.util.List} chain + **/ + public java.util.List getHandlerChain(PortInfo portInfo); +} diff --git a/fine-third-jdk11/src/javax/xml/ws/handler/LogicalHandler.java b/fine-third-jdk11/src/javax/xml/ws/handler/LogicalHandler.java new file mode 100644 index 000000000..5902887a9 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/handler/LogicalHandler.java @@ -0,0 +1,50 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.handler; + +/** The {@code LogicalHandler} extends + * Handler to provide typesafety for the message context parameter. + * + * @param message context + * @since 1.6, JAX-WS 2.0 +**/ +public interface LogicalHandler extends Handler { +} diff --git a/fine-third-jdk11/src/javax/xml/ws/handler/LogicalMessageContext.java b/fine-third-jdk11/src/javax/xml/ws/handler/LogicalMessageContext.java new file mode 100644 index 000000000..5d19e8dcc --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/handler/LogicalMessageContext.java @@ -0,0 +1,61 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.handler; + +import javax.xml.ws.LogicalMessage; + +/** The {@code LogicalMessageContext} interface extends + * {@code MessageContext} to + * provide access to a the contained message as a protocol neutral + * LogicalMessage + * + * @since 1.6, JAX-WS 2.0 +**/ +public interface LogicalMessageContext + extends MessageContext { + + /** Gets the message from this message context + * + * @return The contained message; returns {@code null} if no + * message is present in this message context + **/ + public LogicalMessage getMessage(); +} diff --git a/fine-third-jdk11/src/javax/xml/ws/handler/MessageContext.java b/fine-third-jdk11/src/javax/xml/ws/handler/MessageContext.java new file mode 100644 index 000000000..8891e2ad3 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/handler/MessageContext.java @@ -0,0 +1,230 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.handler; +import java.util.Map; + +/** + * The interface {@code MessageContext} abstracts the message + * context that is processed by a handler in the {@code handle} + * method. + * + *

The {@code MessageContext} interface provides methods to + * manage a property set. {@code MessageContext} properties + * enable handlers in a handler chain to share processing related + * state. + * + * @since 1.6, JAX-WS 2.0 + */ +public interface MessageContext extends Map { + + /** + * Standard property: message direction, {@code true} for + * outbound messages, {@code false} for inbound. + *

Type: boolean + */ + public static final String MESSAGE_OUTBOUND_PROPERTY = + "javax.xml.ws.handler.message.outbound"; + + /** + * Standard property: Map of attachments to a message for the inbound + * message, key is the MIME Content-ID, value is a DataHandler. + *

Type: {@code java.util.Map} + */ + public static final String INBOUND_MESSAGE_ATTACHMENTS = + "javax.xml.ws.binding.attachments.inbound"; + + /** + * Standard property: Map of attachments to a message for the outbound + * message, key is the MIME Content-ID, value is a DataHandler. + *

Type: {@code java.util.Map} + */ + public static final String OUTBOUND_MESSAGE_ATTACHMENTS = + "javax.xml.ws.binding.attachments.outbound"; + + /** + * Standard property: input source for WSDL document. + *

Type: org.xml.sax.InputSource + */ + public static final String WSDL_DESCRIPTION = + "javax.xml.ws.wsdl.description"; + + /** + * Standard property: name of WSDL service. + *

Type: javax.xml.namespace.QName + */ + public static final String WSDL_SERVICE = + "javax.xml.ws.wsdl.service"; + + /** + * Standard property: name of WSDL port. + *

Type: javax.xml.namespace.QName + */ + public static final String WSDL_PORT = + "javax.xml.ws.wsdl.port"; + + /** + * Standard property: name of wsdl interface (2.0) or port type (1.1). + *

Type: javax.xml.namespace.QName + */ + public static final String WSDL_INTERFACE = + "javax.xml.ws.wsdl.interface"; + + /** + * Standard property: name of WSDL operation. + *

Type: javax.xml.namespace.QName + */ + public static final String WSDL_OPERATION = + "javax.xml.ws.wsdl.operation"; + + /** + * Standard property: HTTP response status code. + *

Type: java.lang.Integer + */ + public static final String HTTP_RESPONSE_CODE = + "javax.xml.ws.http.response.code"; + + /** + * Standard property: HTTP request headers. + *

Type: {@code java.util.Map>} + */ + public static final String HTTP_REQUEST_HEADERS = + "javax.xml.ws.http.request.headers"; + + /** + * Standard property: HTTP response headers. + *

Type: {@code java.util.Map>} + */ + public static final String HTTP_RESPONSE_HEADERS = + "javax.xml.ws.http.response.headers"; + + /** + * Standard property: HTTP request method. + *

Type: java.lang.String + */ + public static final String HTTP_REQUEST_METHOD = + "javax.xml.ws.http.request.method"; + + /** + * Standard property: servlet request object. + *

Type: javax.servlet.http.HttpServletRequest + */ + public static final String SERVLET_REQUEST = + "javax.xml.ws.servlet.request"; + + /** + * Standard property: servlet response object. + *

Type: javax.servlet.http.HttpServletResponse + */ + public static final String SERVLET_RESPONSE = + "javax.xml.ws.servlet.response"; + + /** + * Standard property: servlet context object. + *

Type: javax.servlet.ServletContext + */ + public static final String SERVLET_CONTEXT = + "javax.xml.ws.servlet.context"; + + /** + * Standard property: Query string for request. + *

Type: String + **/ + public static final String QUERY_STRING = + "javax.xml.ws.http.request.querystring"; + + /** + * Standard property: Request Path Info + *

Type: String + */ + public static final String PATH_INFO = + "javax.xml.ws.http.request.pathinfo"; + + /** + * Standard property: WS Addressing Reference Parameters. + * The list MUST include all SOAP headers marked with the + * wsa:IsReferenceParameter="true" attribute. + *

Type: {@code List} + * + * @since 1.6, JAX-WS 2.1 + */ + public static final String REFERENCE_PARAMETERS = + "javax.xml.ws.reference.parameters"; + + /** + * Property scope. Properties scoped as {@code APPLICATION} are + * visible to handlers, + * client applications and service endpoints; properties scoped as + * {@code HANDLER} + * are only normally visible to handlers. + */ + public enum Scope { + + /** + * Application visibility. + */ + APPLICATION, + + /** + * Handler visibility. + */ + HANDLER}; + + /** + * Sets the scope of a property. + * + * @param name Name of the property associated with the + * {@code MessageContext} + * @param scope Desired scope of the property + * @throws java.lang.IllegalArgumentException if an illegal + * property name is specified + */ + public void setScope(String name, Scope scope); + + /** + * Gets the scope of a property. + * + * @param name Name of the property + * @return Scope of the property + * @throws java.lang.IllegalArgumentException if a non-existant + * property name is specified + */ + public Scope getScope(String name); +} diff --git a/fine-third-jdk11/src/javax/xml/ws/handler/PortInfo.java b/fine-third-jdk11/src/javax/xml/ws/handler/PortInfo.java new file mode 100644 index 000000000..3f0862e9c --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/handler/PortInfo.java @@ -0,0 +1,81 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.handler; + +import javax.xml.namespace.QName; + +/** + * The {@code PortInfo} interface is used by a + * {@code HandlerResolver} to query information about + * the port it is being asked to create a handler chain for. + *

+ * This interface is never implemented by an application, + * only by a JAX-WS implementation. + * + * @since 1.6, JAX-WS 2.0 +**/ +public interface PortInfo { + + /** + * Gets the qualified name of the WSDL service name containing + * the port being accessed. + * + * @return javax.xml.namespace.QName The qualified name of the WSDL service. + **/ + public QName getServiceName(); + + /** + * Gets the qualified name of the WSDL port being accessed. + * + * @return javax.xml.namespace.QName The qualified name of the WSDL port. + **/ + public QName getPortName(); + + /** + * Gets the URI identifying the binding used by the port being accessed. + * + * @return String The binding identifier for the port. + * + * @see javax.xml.ws.Binding + **/ + public String getBindingID(); + +} diff --git a/fine-third-jdk11/src/javax/xml/ws/handler/package-info.java b/fine-third-jdk11/src/javax/xml/ws/handler/package-info.java new file mode 100644 index 000000000..8bcb5104d --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/handler/package-info.java @@ -0,0 +1,44 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +/** + * This package defines APIs for message handlers. + */ +package javax.xml.ws.handler; diff --git a/fine-third-jdk11/src/javax/xml/ws/handler/soap/SOAPHandler.java b/fine-third-jdk11/src/javax/xml/ws/handler/soap/SOAPHandler.java new file mode 100644 index 000000000..529e8c061 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/handler/soap/SOAPHandler.java @@ -0,0 +1,65 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.handler.soap; + +import javax.xml.namespace.QName; +import javax.xml.ws.handler.Handler; +import java.util.Set; + +/** The {@code SOAPHandler} class extends {@code Handler} + * to provide typesafety for the message context parameter and add a method + * to obtain access to the headers that may be processed by the handler. + * + * @param message context + * @since 1.6, JAX-WS 2.0 +**/ +public interface SOAPHandler + extends Handler { + + /** Gets the header blocks that can be processed by this Handler + * instance. + * + * @return Set of {@code QNames} of header blocks processed by this + * handler instance. {@code QName} is the qualified + * name of the outermost element of the Header block. + **/ + Set getHeaders(); +} diff --git a/fine-third-jdk11/src/javax/xml/ws/handler/soap/SOAPMessageContext.java b/fine-third-jdk11/src/javax/xml/ws/handler/soap/SOAPMessageContext.java new file mode 100644 index 000000000..0afdc79ed --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/handler/soap/SOAPMessageContext.java @@ -0,0 +1,114 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.handler.soap; + +import javax.xml.soap.SOAPMessage; +import javax.xml.bind.JAXBContext; +import javax.xml.namespace.QName; +import java.util.Set; + +/** The interface {@code SOAPMessageContext} + * provides access to the SOAP message for either RPC request or + * response. The {@code javax.xml.soap.SOAPMessage} specifies + * the standard Java API for the representation of a SOAP 1.1 message + * with attachments. + * + * @see javax.xml.soap.SOAPMessage + * + * @since 1.6, JAX-WS 2.0 +**/ +public interface SOAPMessageContext + extends javax.xml.ws.handler.MessageContext { + + /** Gets the {@code SOAPMessage} from this message context. Modifications + * to the returned {@code SOAPMessage} change the message in-place, there + * is no need to subsequently call {@code setMessage}. + * + * @return Returns the {@code SOAPMessage}; returns {@code null} if no + * {@code SOAPMessage} is present in this message context + **/ + public SOAPMessage getMessage(); + + /** Sets the SOAPMessage in this message context + * + * @param message SOAP message + * @throws javax.xml.ws.WebServiceException If any error during the setting + * of the {@code SOAPMessage} in this message context + * @throws java.lang.UnsupportedOperationException If this + * operation is not supported + **/ + public void setMessage(SOAPMessage message); + + /** Gets headers that have a particular qualified name from the message in the + * message context. Note that a SOAP message can contain multiple headers + * with the same qualified name. + * + * @param header The XML qualified name of the SOAP header(s). + * @param context The JAXBContext that should be used to unmarshall the + * header + * @param allRoles If {@code true} then returns headers for all SOAP + * roles, if {@code false} then only returns headers targetted + * at the roles currently being played by this SOAP node, see + * {@code getRoles}. + * @return An array of unmarshalled headers; returns an empty array if no + * message is present in this message context or no headers match + * the supplied qualified name. + * @throws javax.xml.ws.WebServiceException If an error occurs when using the supplied + * {@code JAXBContext} to unmarshall. The cause of + * the {@code WebServiceException} is the original {@code JAXBException}. + **/ + public Object[] getHeaders(QName header, JAXBContext context, + boolean allRoles); + + /** Gets the SOAP actor roles associated with an execution + * of the handler chain. + * Note that SOAP actor roles apply to the SOAP node and + * are managed using {@link javax.xml.ws.soap.SOAPBinding#setRoles} and + * {@link javax.xml.ws.soap.SOAPBinding#getRoles}. {@code Handler} instances in + * the handler chain use this information about the SOAP actor + * roles to process the SOAP header blocks. Note that the + * SOAP actor roles are invariant during the processing of + * SOAP message through the handler chain. + * + * @return Array of {@code String} for SOAP actor roles + **/ + public Set getRoles(); +} diff --git a/fine-third-jdk11/src/javax/xml/ws/handler/soap/package-info.java b/fine-third-jdk11/src/javax/xml/ws/handler/soap/package-info.java new file mode 100644 index 000000000..b57ef1c7f --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/handler/soap/package-info.java @@ -0,0 +1,44 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +/** + * This package defines APIs for SOAP message handlers. + */ +package javax.xml.ws.handler.soap; diff --git a/fine-third-jdk11/src/javax/xml/ws/http/HTTPBinding.java b/fine-third-jdk11/src/javax/xml/ws/http/HTTPBinding.java new file mode 100644 index 000000000..36d3d5899 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/http/HTTPBinding.java @@ -0,0 +1,57 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.http; + + +import javax.xml.ws.Binding; + +/** The {@code HTTPBinding} interface is an + * abstraction for the XML/HTTP binding. + * + * @since 1.6, JAX-WS 2.0 +**/ +public interface HTTPBinding extends Binding { + + /** + * A constant representing the identity of the XML/HTTP binding. + */ + public static final String HTTP_BINDING = "http://www.w3.org/2004/08/wsdl/http"; +} diff --git a/fine-third-jdk11/src/javax/xml/ws/http/HTTPException.java b/fine-third-jdk11/src/javax/xml/ws/http/HTTPException.java new file mode 100644 index 000000000..232a14087 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/http/HTTPException.java @@ -0,0 +1,71 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.http; + + +/** The {@code HTTPException} exception represents a + * XML/HTTP fault. + * + *

Since there is no standard format for faults or exceptions + * in XML/HTTP messaging, only the HTTP status code is captured. + * + * @since 1.6, JAX-WS 2.0 +**/ +public class HTTPException extends javax.xml.ws.ProtocolException { + + private int statusCode; + + /** Constructor for the HTTPException + * @param statusCode {@code int} for the HTTP status code + **/ + public HTTPException(int statusCode) { + super(); + this.statusCode = statusCode; + } + + /** Gets the HTTP status code. + * + * @return HTTP status code + **/ + public int getStatusCode() { + return statusCode; + } +} diff --git a/fine-third-jdk11/src/javax/xml/ws/http/package-info.java b/fine-third-jdk11/src/javax/xml/ws/http/package-info.java new file mode 100644 index 000000000..4c9e8f7ab --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/http/package-info.java @@ -0,0 +1,44 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +/** + * This package defines APIs specific to the HTTP binding. + */ +package javax.xml.ws.http; diff --git a/fine-third-jdk11/src/javax/xml/ws/package-info.java b/fine-third-jdk11/src/javax/xml/ws/package-info.java new file mode 100644 index 000000000..35667f6f8 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/package-info.java @@ -0,0 +1,44 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2007-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +/** + * This package contains the core JAX-WS APIs. + */ +package javax.xml.ws; diff --git a/fine-third-jdk11/src/javax/xml/ws/soap/Addressing.java b/fine-third-jdk11/src/javax/xml/ws/soap/Addressing.java new file mode 100644 index 000000000..c777e6d60 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/soap/Addressing.java @@ -0,0 +1,131 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.soap; + +import java.lang.annotation.Documented; +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.xml.ws.WebServiceRef; +import javax.xml.ws.WebServiceProvider; +import javax.xml.ws.soap.AddressingFeature.Responses; +import javax.xml.ws.spi.WebServiceFeatureAnnotation; + +/** + * This annotation represents the use of WS-Addressing with either + * the SOAP 1.1/HTTP or SOAP 1.2/HTTP binding. Using this annotation + * with any other binding is undefined. + *

+ * This annotation MUST only be used in conjunction with the + * {@code javax.jws.WebService}, {@link WebServiceProvider}, + * and {@link WebServiceRef} annotations. + * When used with a {@code javax.jws.WebService} annotation, this + * annotation MUST only be used on the service endpoint implementation + * class. + * When used with a {@code WebServiceRef} annotation, this annotation + * MUST only be used when a proxy instance is created. The injected SEI + * proxy, and endpoint MUST honor the values of the {@code Addressing} + * annotation. + *

+ * This annotation's behaviour is defined by the corresponding feature + * {@link AddressingFeature}. + * + * @since 1.6, JAX-WS 2.1 + */ +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@WebServiceFeatureAnnotation(id=AddressingFeature.ID,bean=AddressingFeature.class) +public @interface Addressing { + /** + * Specifies if this feature is enabled or disabled. If enabled, it means + * the endpoint supports WS-Addressing but does not require its use. + * Corresponding + * + * 3.1.1 Addressing Assertion must be generated in the generated WSDL. + * + * @return {@code true} if endpoint supports WS-Addressing, {@code false} otherwise + */ + boolean enabled() default true; + + /** + * If addressing is enabled, this property determines whether the endpoint + * requires WS-Addressing. If required is true, the endpoint requires + * WS-Addressing and WS-Addressing headers MUST + * be present on incoming messages. A corresponding + * + * 3.1.1 Addressing Assertion must be generated in the WSDL. + * + * @return {@code true} if endpoint requires WS-Addressing, {@code false} otherwise + */ + boolean required() default false; + + /** + * If addressing is enabled, this property determines whether endpoint + * requires the use of anonymous responses, or non-anonymous responses, + * or all. + * + *

+ * {@link Responses#ALL} supports all response types and this is the + * default value. + * + *

+ * {@link Responses#ANONYMOUS} requires the use of only anonymous + * responses. It will result into wsam:AnonymousResponses nested assertion + * as specified in + * + * 3.1.2 AnonymousResponses Assertion in the generated WSDL. + * + *

+ * {@link Responses#NON_ANONYMOUS} requires the use of only non-anonymous + * responses. It will result into + * wsam:NonAnonymousResponses nested assertion as specified in + * + * 3.1.3 NonAnonymousResponses Assertion in the generated WSDL. + * + * @return supported response types + * @since 1.7, JAX-WS 2.2 + */ + Responses responses() default Responses.ALL; + +} diff --git a/fine-third-jdk11/src/javax/xml/ws/soap/AddressingFeature.java b/fine-third-jdk11/src/javax/xml/ws/soap/AddressingFeature.java new file mode 100644 index 000000000..2683315de --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/soap/AddressingFeature.java @@ -0,0 +1,291 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.soap; + +import javax.xml.ws.WebServiceFeature; +import javax.xml.ws.Endpoint; +import javax.xml.ws.Service; + +/** + * AddressingFeature represents the use of WS-Addressing with either + * the SOAP 1.1/HTTP or SOAP 1.2/HTTP binding. Using this feature + * with any other binding is undefined. + *

+ * This feature can be used during the creation of SEI proxy, and + * {@link javax.xml.ws.Dispatch} instances on the client side and {@link Endpoint} + * instances on the server side. This feature cannot be used for {@link Service} + * instance creation on the client side. + *

+ * The following describes the effects of this feature with respect + * to be enabled or disabled: + *

    + *
  • ENABLED: In this Mode, WS-Addressing will be enabled. It means + * the endpoint supports WS-Addressing but does not require its use. + * A sender could send messages with WS-Addressing headers or without + * WS-Addressing headers. But a receiver MUST consume both types of + * messages. + *
  • DISABLED: In this Mode, WS-Addressing will be disabled. + * At runtime, WS-Addressing headers MUST NOT be used by a sender or + * receiver. + *
+ *

+ * If the feature is enabled, the {@code required} property determines + * whether the endpoint requires WS-Addressing. If it is set true, + * WS-Addressing headers MUST be present on incoming and outgoing messages. + * By default the {@code required} property is {@code false}. + * + *

+ * If the web service developer has not explicitly enabled this feature, + * WSDL's wsam:Addressing policy assertion is used to find + * the use of WS-Addressing. By using the feature explicitly, an application + * overrides WSDL's indication of the use of WS-Addressing. In some cases, + * this is really required. For example, if an application has implemented + * WS-Addressing itself, it can use this feature to disable addressing. That + * means a JAX-WS implementation doesn't consume or produce WS-Addressing + * headers. + * + *

+ * If addressing is enabled, a corresponding wsam:Addressing policy assertion + * must be generated in the WSDL as per + * + * 3.1 WS-Policy Assertions + * + *

+ * Example 1: Possible Policy Assertion in the generated WSDL for + * {@code @Addressing} + *

 {@code
+ *   
+ *     
+ *    }
+ * 
+ * + *

+ * Example 2: Possible Policy Assertion in the generated WSDL for + * {@code @Addressing(required=true)} + *

 {@code
+ *   
+ *     
+ *    }
+ * 
+ * + *

+ * Example 3: Possible Policy Assertion in the generated WSDL for + * {@code @Addressing(required=true, responses=Responses.ANONYMOUS)} + *

 {@code
+ *   
+ *      
+ *        
+ *      
+ *    }
+ * 
+ * + *

+ * See + * Web Services Addressing - Core, + * + * Web Services Addressing 1.0 - SOAP Binding, + * and + * Web Services Addressing 1.0 - Metadata + * for more information on WS-Addressing. + * + * @see Addressing + * @since 1.6, JAX-WS 2.1 + */ + +public final class AddressingFeature extends WebServiceFeature { + /** + * Constant value identifying the AddressingFeature + */ + public static final String ID = "http://www.w3.org/2005/08/addressing/module"; + + /** + * If addressing is enabled, this property determines whether the endpoint + * requires WS-Addressing. If required is true, WS-Addressing headers MUST + * be present on incoming and outgoing messages. + */ + // should be private final, keeping original modifier due to backwards compatibility + protected boolean required; + + /** + * If addressing is enabled, this property determines if endpoint requires + * the use of only anonymous responses, or only non-anonymous responses, or all. + * + *

+ * {@link Responses#ALL} supports all response types and this is the default + * value. + * + *

+ * {@link Responses#ANONYMOUS} requires the use of only anonymous + * responses. It will result into wsam:AnonymousResponses nested assertion + * as specified in + * + * 3.1.2 AnonymousResponses Assertion in the generated WSDL. + * + *

+ * {@link Responses#NON_ANONYMOUS} requires the use of only non-anonymous + * responses. It will result into + * wsam:NonAnonymousResponses nested assertion as specified in + * + * 3.1.3 NonAnonymousResponses Assertion in the generated WSDL. + * + * @since 1.7, JAX-WS 2.2 + */ + public enum Responses { + /** + * Specifies the use of only anonymous + * responses. It will result into wsam:AnonymousResponses nested assertion + * as specified in + * + * 3.1.2 AnonymousResponses Assertion in the generated WSDL. + */ + ANONYMOUS, + + /** + * Specifies the use of only non-anonymous + * responses. It will result into + * wsam:NonAnonymousResponses nested assertion as specified in + * + * 3.1.3 NonAnonymousResponses Assertion in the generated WSDL. + */ + NON_ANONYMOUS, + + /** + * Supports all response types and this is the default + */ + ALL + } + + private final Responses responses; + + /** + * Creates and configures an {@code AddressingFeature} with the + * use of addressing requirements. The created feature enables + * ws-addressing i.e. supports ws-addressing but doesn't require + * its use. It is also configured to accept all the response types. + */ + public AddressingFeature() { + this(true, false, Responses.ALL); + } + + /** + * Creates and configures an {@code AddressingFeature} with the + * use of addressing requirements. If {@code enabled} is true, + * it enables ws-addressing i.e. supports ws-addressing but doesn't + * require its use. It also configures to accept all the response types. + * + * @param enabled true enables ws-addressing i.e.ws-addressing + * is supported but doesn't require its use + */ + public AddressingFeature(boolean enabled) { + this(enabled, false, Responses.ALL); + } + + /** + * Creates and configures an {@code AddressingFeature} with the + * use of addressing requirements. If {@code enabled} and + * {@code required} are true, it enables ws-addressing and + * requires its use. It also configures to accept all the response types. + * + * @param enabled true enables ws-addressing i.e.ws-addressing + * is supported but doesn't require its use + * @param required true means requires the use of ws-addressing . + */ + public AddressingFeature(boolean enabled, boolean required) { + this(enabled, required, Responses.ALL); + } + + /** + * Creates and configures an {@code AddressingFeature} with the + * use of addressing requirements. If {@code enabled} and + * {@code required} are true, it enables ws-addressing and + * requires its use. Also, the response types can be configured using + * {@code responses} parameter. + * + * @param enabled true enables ws-addressing i.e.ws-addressing + * is supported but doesn't require its use + * @param required true means requires the use of ws-addressing . + * @param responses specifies what type of responses are required + * + * @since 1.7, JAX-WS 2.2 + */ + public AddressingFeature(boolean enabled, boolean required, Responses responses) { + this.enabled = enabled; + this.required = required; + this.responses = responses; + } + + /** + * {@inheritDoc} + */ + public String getID() { + return ID; + } + + /** + * If addressing is enabled, this property determines whether the endpoint + * requires WS-Addressing. If required is true, WS-Addressing headers MUST + * be present on incoming and outgoing messages. + * + * @return the current required value + */ + public boolean isRequired() { + return required; + } + + /** + * If addressing is enabled, this property determines whether endpoint + * requires the use of anonymous responses, or non-anonymous responses, + * or all responses. + * + * @return {@link Responses#ALL} when endpoint supports all types of + * responses, + * {@link Responses#ANONYMOUS} when endpoint requires the use of + * only anonymous responses, + * {@link Responses#NON_ANONYMOUS} when endpoint requires the use + * of only non-anonymous responses + * + * @since 1.7, JAX-WS 2.2 + */ + public Responses getResponses() { + return responses; + } + +} diff --git a/fine-third-jdk11/src/javax/xml/ws/soap/MTOM.java b/fine-third-jdk11/src/javax/xml/ws/soap/MTOM.java new file mode 100644 index 000000000..6ad38a5c6 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/soap/MTOM.java @@ -0,0 +1,94 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.soap; + +import java.lang.annotation.Documented; +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.xml.ws.spi.WebServiceFeatureAnnotation; +import javax.xml.ws.WebServiceRef; +import javax.xml.ws.WebServiceProvider; + +/** + * This feature represents the use of MTOM with a + * web service. + *

+ * This annotation MUST only be used in conjunction the + * {@code javax.jws.WebService}, {@link WebServiceProvider}, + * {@link WebServiceRef} annotations. + * When used with the {@code javax.jws.WebService} annotation this + * annotation MUST only be used on the service endpoint implementation + * class. + * When used with a {@code WebServiceRef} annotation, this annotation + * MUST only be used when a proxy instance is created. The injected SEI + * proxy, and endpoint MUST honor the values of the {@code MTOM} + * annotation. + *

+ * + * This annotation's behaviour is defined by the corresponding feature + * {@link MTOMFeature}. + * + * @since 1.6, JAX-WS 2.1 + */ +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@WebServiceFeatureAnnotation(id=MTOMFeature.ID,bean=MTOMFeature.class) +public @interface MTOM { + /** + * Specifies if this feature is enabled or disabled. + * + * @return {@code true} if MTOM is supported, {@code false} otherwise + */ + boolean enabled() default true; + + /** + * Property for MTOM threshold value. When MTOM is enabled, binary data above this + * size in bytes will be XOP encoded or sent as attachment. The value of this property + * MUST always be {@literal >=} 0. Default value is 0. + * + * @return MTOM threshold in bytes + */ + int threshold() default 0; +} diff --git a/fine-third-jdk11/src/javax/xml/ws/soap/MTOMFeature.java b/fine-third-jdk11/src/javax/xml/ws/soap/MTOMFeature.java new file mode 100644 index 000000000..322c26eec --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/soap/MTOMFeature.java @@ -0,0 +1,159 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.soap; + +import javax.xml.ws.WebServiceFeature; +import javax.xml.ws.WebServiceException; +import javax.xml.ws.Endpoint; +import javax.xml.ws.Service; + +/** + * This feature represents the use of MTOM with a + * web service. + * + * This feature can be used during the creation of SEI proxy, and + * {@link javax.xml.ws.Dispatch} instances on the client side and {@link Endpoint} + * instances on the server side. This feature cannot be used for {@link Service} + * instance creation on the client side. + * + *

+ * The following describes the affects of this feature with respect + * to being enabled or disabled: + *

    + *
  • ENABLED: In this Mode, MTOM will be enabled. A receiver MUST accept + * both a non-optimized and an optimized message, and a sender MAY send an + * optimized message, or a non-optimized message. The heuristics used by a + * sender to determine whether to use optimization or not are + * implementation-specific. + *
  • DISABLED: In this Mode, MTOM will be disabled + *
+ *

+ * The {@link #threshold} property can be used to set the threshold + * value used to determine when binary data should be XOP encoded. + * + * @since 1.6, JAX-WS 2.1 + */ +public final class MTOMFeature extends WebServiceFeature { + /** + * Constant value identifying the MTOMFeature + */ + public static final String ID = "http://www.w3.org/2004/08/soap/features/http-optimization"; + + + /** + * Property for MTOM threshold value. This property serves as a hint when + * MTOM is enabled, binary data above this size in bytes SHOULD be sent + * as attachment. + * The value of this property MUST always be {@literal >=} 0. Default value is 0. + */ + // should be changed to private final, keeping original modifier to keep backwards compatibility + protected int threshold; + + + /** + * Create an {@code MTOMFeature}. + * The instance created will be enabled. + */ + public MTOMFeature() { + this.enabled = true; + this.threshold = 0; + } + + /** + * Creates a {@code MTOMFeature}. + * + * @param enabled specifies if this feature should be enabled or not + */ + public MTOMFeature(boolean enabled) { + this.enabled = enabled; + this.threshold = 0; + } + + + /** + * Creates a {@code MTOMFeature}. + * The instance created will be enabled. + * + * @param threshold the size in bytes that binary data SHOULD be before + * being sent as an attachment. + * + * @throws WebServiceException if threshold is {@literal <} 0 + */ + public MTOMFeature(int threshold) { + if (threshold < 0) + throw new WebServiceException("MTOMFeature.threshold must be >= 0, actual value: "+threshold); + this.enabled = true; + this.threshold = threshold; + } + + /** + * Creates a {@code MTOMFeature}. + * + * @param enabled specifies if this feature should be enabled or not + * @param threshold the size in bytes that binary data SHOULD be before + * being sent as an attachment. + * + * @throws WebServiceException if threshold is {@literal <} 0 + */ + public MTOMFeature(boolean enabled, int threshold) { + if (threshold < 0) + throw new WebServiceException("MTOMFeature.threshold must be >= 0, actual value: "+threshold); + this.enabled = enabled; + this.threshold = threshold; + } + + /** + * {@inheritDoc} + */ + public String getID() { + return ID; + } + + /** + * Gets the threshold value used to determine when binary data + * should be sent as an attachment. + * + * @return the current threshold size in bytes + */ + public int getThreshold() { + return threshold; + } +} diff --git a/fine-third-jdk11/src/javax/xml/ws/soap/SOAPBinding.java b/fine-third-jdk11/src/javax/xml/ws/soap/SOAPBinding.java new file mode 100644 index 000000000..a59f25e51 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/soap/SOAPBinding.java @@ -0,0 +1,125 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.soap; + + +import java.util.Set; +import javax.xml.ws.Binding; +import javax.xml.soap.SOAPFactory; +import javax.xml.soap.MessageFactory; + +/** The {@code SOAPBinding} interface is an abstraction for + * the SOAP binding. + * + * @since 1.6, JAX-WS 2.0 +**/ +public interface SOAPBinding extends Binding { + + /** + * A constant representing the identity of the SOAP 1.1 over HTTP binding. + */ + public static final String SOAP11HTTP_BINDING = "http://schemas.xmlsoap.org/wsdl/soap/http"; + + /** + * A constant representing the identity of the SOAP 1.2 over HTTP binding. + */ + public static final String SOAP12HTTP_BINDING = "http://www.w3.org/2003/05/soap/bindings/HTTP/"; + + /** + * A constant representing the identity of the SOAP 1.1 over HTTP binding + * with MTOM enabled by default. + */ + public static final String SOAP11HTTP_MTOM_BINDING = "http://schemas.xmlsoap.org/wsdl/soap/http?mtom=true"; + + /** + * A constant representing the identity of the SOAP 1.2 over HTTP binding + * with MTOM enabled by default. + */ + public static final String SOAP12HTTP_MTOM_BINDING = "http://www.w3.org/2003/05/soap/bindings/HTTP/?mtom=true"; + + + /** Gets the roles played by the SOAP binding instance. + * + * @return {@code Set} The set of roles played by the binding instance. + **/ + public Set getRoles(); + + /** Sets the roles played by the SOAP binding instance. + * + * @param roles The set of roles played by the binding instance. + * @throws javax.xml.ws.WebServiceException On an error in the configuration of + * the list of roles. + **/ + public void setRoles(Set roles); + + /** + * Returns {@code true} if the use of MTOM is enabled. + * + * @return {@code true} if and only if the use of MTOM is enabled. + **/ + + public boolean isMTOMEnabled(); + + /** + * Enables or disables use of MTOM. + * + * @param flag A {@code boolean} specifying whether the use of MTOM should + * be enabled or disabled. + * @throws javax.xml.ws.WebServiceException If the specified setting is not supported + * by this binding instance. + * + **/ + public void setMTOMEnabled(boolean flag); + + /** + * Gets the SAAJ {@code SOAPFactory} instance used by this SOAP binding. + * + * @return SOAPFactory instance used by this SOAP binding. + **/ + public SOAPFactory getSOAPFactory(); + + /** + * Gets the SAAJ {@code MessageFactory} instance used by this SOAP binding. + * + * @return MessageFactory instance used by this SOAP binding. + **/ + public MessageFactory getMessageFactory(); +} diff --git a/fine-third-jdk11/src/javax/xml/ws/soap/SOAPFaultException.java b/fine-third-jdk11/src/javax/xml/ws/soap/SOAPFaultException.java new file mode 100644 index 000000000..63848b1df --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/soap/SOAPFaultException.java @@ -0,0 +1,90 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.soap; + +import javax.xml.soap.SOAPFault; + +/** The {@code SOAPFaultException} exception represents a + * SOAP 1.1 or 1.2 fault. + * + *

A {@code SOAPFaultException} wraps a SAAJ {@code SOAPFault} + * that manages the SOAP-specific representation of faults. + * The {@code createFault} method of + * {@code javax.xml.soap.SOAPFactory} may be used to create an instance + * of {@code javax.xml.soap.SOAPFault} for use with the + * constructor. {@code SOAPBinding} contains an accessor for the + * {@code SOAPFactory} used by the binding instance. + * + *

Note that the value of {@code getFault} is the only part of the + * exception used when searializing a SOAP fault. + * + *

Refer to the SOAP specification for a complete + * description of SOAP faults. + * + * @see javax.xml.soap.SOAPFault + * @see javax.xml.ws.soap.SOAPBinding#getSOAPFactory + * @see javax.xml.ws.ProtocolException + * + * @since 1.6, JAX-WS 2.0 + **/ +public class SOAPFaultException extends javax.xml.ws.ProtocolException { + + private SOAPFault fault; + + /** Constructor for SOAPFaultException + * @param fault {@code SOAPFault} representing the fault + * + * @see javax.xml.soap.SOAPFactory#createFault + **/ + public SOAPFaultException(SOAPFault fault) { + super(fault.getFaultString()); + this.fault = fault; + } + + /** Gets the embedded {@code SOAPFault} instance. + * + * @return {@code javax.xml.soap.SOAPFault} SOAP + * fault element + **/ + public javax.xml.soap.SOAPFault getFault() { + return this.fault; + } +} diff --git a/fine-third-jdk11/src/javax/xml/ws/soap/package-info.java b/fine-third-jdk11/src/javax/xml/ws/soap/package-info.java new file mode 100644 index 000000000..4d77cf895 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/soap/package-info.java @@ -0,0 +1,44 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +/** + * This package defines APIs specific to the SOAP binding. + */ +package javax.xml.ws.soap; diff --git a/fine-third-jdk11/src/javax/xml/ws/spi/FactoryFinder.java b/fine-third-jdk11/src/javax/xml/ws/spi/FactoryFinder.java new file mode 100644 index 000000000..18ef54a65 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/spi/FactoryFinder.java @@ -0,0 +1,185 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.spi; + +import java.io.*; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.xml.ws.WebServiceException; + +class FactoryFinder { + + private static final Logger logger = Logger.getLogger("javax.xml.ws"); + + private static final ServiceLoaderUtil.ExceptionHandler EXCEPTION_HANDLER = + new ServiceLoaderUtil.ExceptionHandler() { + @Override + public WebServiceException createException(Throwable throwable, String message) { + return new WebServiceException(message, throwable); + } + }; + + /** + * Finds the implementation {@code Class} object for the given + * factory name, or if that fails, finds the {@code Class} object + * for the given fallback class name. The arguments supplied MUST be + * used in order. If using the first argument is successful, the second + * one will not be used. + *

+ * This method is package private so that this code can be shared. + * + * @return the {@code Class} object of the specified message factory; + * may not be {@code null} + * + * @param factoryClass the name of the factory to find, which is + * a system property + * @param fallbackClassName the implementation class name, which is + * to be used only if nothing else + * is found; {@code null} to indicate that + * there is no fallback class name + * @exception WebServiceException if there is an error + */ + @SuppressWarnings("unchecked") + static T find(Class factoryClass, String fallbackClassName) { + ClassLoader classLoader = ServiceLoaderUtil.contextClassLoader(EXCEPTION_HANDLER); + + T provider = ServiceLoaderUtil.firstByServiceLoader(factoryClass, logger, EXCEPTION_HANDLER); + if (provider != null) return provider; + + String factoryId = factoryClass.getName(); + + // try to read from $java.home/lib/jaxws.properties + provider = (T) fromJDKProperties(factoryId, fallbackClassName, classLoader); + if (provider != null) return provider; + + // Use the system property + provider = (T) fromSystemProperty(factoryId, fallbackClassName, classLoader); + if (provider != null) return provider; + + // handling Glassfish (platform specific default) + if (isOsgi()) { + return (T) lookupUsingOSGiServiceLoader(factoryId); + } + + if (fallbackClassName == null) { + throw new WebServiceException( + "Provider for " + factoryId + " cannot be found", null); + } + + return (T) ServiceLoaderUtil.newInstance(fallbackClassName, + fallbackClassName, classLoader, EXCEPTION_HANDLER); + } + + private static Object fromSystemProperty(String factoryId, + String fallbackClassName, + ClassLoader classLoader) { + try { + String systemProp = System.getProperty(factoryId); + if (systemProp != null) { + return ServiceLoaderUtil.newInstance(systemProp, + fallbackClassName, classLoader, EXCEPTION_HANDLER); + } + } catch (SecurityException ignored) { + } + return null; + } + + private static Object fromJDKProperties(String factoryId, + String fallbackClassName, + ClassLoader classLoader) { + Path path = null; + try { + String JAVA_HOME = System.getProperty("java.home"); + path = Paths.get(JAVA_HOME, "conf", "jaxws.properties"); + + // to ensure backwards compatibility + if (!Files.exists(path)) { + path = Paths.get(JAVA_HOME, "lib", "jaxws.properties"); + } + + if (Files.exists(path)) { + Properties props = new Properties(); + try (InputStream inStream = Files.newInputStream(path)) { + props.load(inStream); + } + String factoryClassName = props.getProperty(factoryId); + return ServiceLoaderUtil.newInstance(factoryClassName, + fallbackClassName, classLoader, EXCEPTION_HANDLER); + } + } catch (Exception ignored) { + logger.log(Level.SEVERE, "Error reading JAX-WS configuration from [" + path + + "] file. Check it is accessible and has correct format.", ignored); + } + return null; + } + + private static final String OSGI_SERVICE_LOADER_CLASS_NAME = "org.glassfish.hk2.osgiresourcelocator.ServiceLoader"; + + private static boolean isOsgi() { + try { + Class.forName(OSGI_SERVICE_LOADER_CLASS_NAME); + return true; + } catch (ClassNotFoundException ignored) { + } + return false; + } + + private static Object lookupUsingOSGiServiceLoader(String factoryId) { + try { + // Use reflection to avoid having any dependendcy on ServiceLoader class + Class serviceClass = Class.forName(factoryId); + Class[] args = new Class[]{serviceClass}; + Class target = Class.forName(OSGI_SERVICE_LOADER_CLASS_NAME); + java.lang.reflect.Method m = target.getMethod("lookupProviderInstances", Class.class); + java.util.Iterator iter = ((Iterable) m.invoke(null, (Object[]) args)).iterator(); + return iter.hasNext() ? iter.next() : null; + } catch (Exception ignored) { + // log and continue + return null; + } + } + +} diff --git a/fine-third-jdk11/src/javax/xml/ws/spi/Invoker.java b/fine-third-jdk11/src/javax/xml/ws/spi/Invoker.java new file mode 100644 index 000000000..cccb5275d --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/spi/Invoker.java @@ -0,0 +1,106 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2009-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.spi; + +import javax.xml.ws.WebServiceContext; +import javax.xml.ws.WebServiceFeature; +import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; + +/** + * Invoker hides the detail of calling into application endpoint + * implementation. Container hands over an implementation of Invoker + * to JAX-WS runtime, and jax-ws runtime calls {@link #invoke} + * for a web service invocation. Finally, Invoker does the actual + * invocation of web service on endpoint instance. + * + * Container also injects the provided {@code WebServiceContext} and takes + * care of invoking {@code javax.annotation.PostConstruct} methods, + * if present, on the endpoint implementation. + * + * @see Provider#createEndpoint(String, Class, Invoker, WebServiceFeature...) + * @author Jitendra Kotamraju + * @since 1.7, JAX-WS 2.2 + */ + +public abstract class Invoker { + + /** + * JAX-WS runtimes calls this method to ask container to inject + * WebServiceContext on the endpoint instance. The + * {@code WebServiceContext} object uses thread-local information + * to return the correct information during the actual endpoint invocation + * regardless of how many threads are concurrently being used to serve + * requests. + * + * @param webServiceContext a holder for MessageContext + * @throws IllegalAccessException if the injection done + * by reflection API throws this exception + * @throws IllegalArgumentException if the injection done + * by reflection API throws this exception + * @throws InvocationTargetException if the injection done + * by reflection API throws this exception + */ + public abstract void inject(WebServiceContext webServiceContext) + throws IllegalAccessException, IllegalArgumentException, InvocationTargetException; + + /** + * JAX-WS runtime calls this method to do the actual web service + * invocation on endpoint instance. The injected + * {@code WebServiceContext.getMessageContext()} gives the correct + * information for this invocation. + * + * @param m Method to be invoked on the service + * @param args Method arguments + * @return return value of the method + * @throws IllegalAccessException if the invocation done + * by reflection API throws this exception + * @throws IllegalArgumentException if the invocation done + * by reflection API throws this exception + * @throws InvocationTargetException if the invocation done + * by reflection API throws this exception + + * @see Method#invoke + */ + public abstract Object invoke(Method m, Object... args) + throws IllegalAccessException, IllegalArgumentException, InvocationTargetException; + +} diff --git a/fine-third-jdk11/src/javax/xml/ws/spi/Provider.java b/fine-third-jdk11/src/javax/xml/ws/spi/Provider.java new file mode 100644 index 000000000..6b693d050 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/spi/Provider.java @@ -0,0 +1,454 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.spi; + +import java.util.List; +import java.util.Map; +import javax.xml.namespace.QName; +import javax.xml.ws.*; +import javax.xml.ws.wsaddressing.W3CEndpointReference; + +import org.w3c.dom.Element; + +/** + * Service provider for {@code ServiceDelegate} and + * {@code Endpoint} objects. + * + * @since 1.6, JAX-WS 2.0 + */ +public abstract class Provider { + + /** + * A constant representing the name of the default + * {@code Provider} implementation class. + **/ + // Using two strings so that package renaming doesn't change it + private static final String DEFAULT_JAXWSPROVIDER = + "com.sun"+".xml.internal.ws.spi.ProviderImpl"; + + /** + * Creates a new instance of Provider + */ + protected Provider() { + } + + /** + * + * Creates a new provider object. + *

+ * The algorithm used to locate the provider subclass to use consists + * of the following steps: + *

    + *
  • Use the service-provider loading facilities, defined by the {@link java.util.ServiceLoader} class, + * to attempt to locate and load an implementation of {@link javax.xml.ws.spi.Provider} service using + * the {@linkplain java.util.ServiceLoader#load(java.lang.Class) default loading mechanism}. + *
  • Use the configuration file "jaxws.properties". The file is in standard + * {@link java.util.Properties} format and typically located in the + * {@code conf} directory of the Java installation. It contains the fully qualified + * name of the implementation class with the key {@code javax.xml.ws.spi.Provider}. + *
  • If a system property with the name {@code javax.xml.ws.spi.Provider} + * is defined, then its value is used as the name of the implementation class. + *
  • Finally, a platform default implementation is used. + *
+ * + * @return provider object + */ + public static Provider provider() { + try { + return FactoryFinder.find(Provider.class, DEFAULT_JAXWSPROVIDER); + } catch (WebServiceException ex) { + throw ex; + } catch (Exception ex) { + throw new WebServiceException("Unable to createEndpointReference Provider", ex); + } + } + + /** + * Creates a service delegate object. + * + * @param wsdlDocumentLocation A URL pointing to the WSDL document + * for the service, or {@code null} if there isn't one. + * @param serviceName The qualified name of the service. + * @param serviceClass The service class, which MUST be either + * {@code javax.xml.ws.Service} or a subclass thereof. + * @return The newly created service delegate. + */ + public abstract ServiceDelegate createServiceDelegate( + java.net.URL wsdlDocumentLocation, + QName serviceName, Class serviceClass); + + /** + * Creates a service delegate object. + * + * @param wsdlDocumentLocation A URL pointing to the WSDL document + * for the service, or {@code null} if there isn't one. + * @param serviceName The qualified name of the service. + * @param serviceClass The service class, which MUST be either + * {@code javax.xml.ws.Service} or a subclass thereof. + * @param features Web Service features that must be configured on + * the service. If the provider doesn't understand a feature, + * it must throw a WebServiceException. + * @return The newly created service delegate. + * + * @since 1.7, JAX-WS 2.2 + */ + public ServiceDelegate createServiceDelegate( + java.net.URL wsdlDocumentLocation, + QName serviceName, Class serviceClass, WebServiceFeature ... features) { + throw new UnsupportedOperationException("JAX-WS 2.2 implementation must override this default behaviour."); + } + + /** + * + * Creates an endpoint object with the provided binding and implementation + * object. + * + * @param bindingId A URI specifying the desired binding (e.g. SOAP/HTTP) + * @param implementor A service implementation object to which + * incoming requests will be dispatched. The corresponding + * class MUST be annotated with all the necessary Web service + * annotations. + * @return The newly created endpoint. + */ + public abstract Endpoint createEndpoint(String bindingId, + Object implementor); + + /** + * Creates and publishes an endpoint object with the specified + * address and implementation object. + * + * @param address A URI specifying the address and transport/protocol + * to use. A http: URI MUST result in the SOAP 1.1/HTTP + * binding being used. Implementations may support other + * URI schemes. + * @param implementor A service implementation object to which + * incoming requests will be dispatched. The corresponding + * class MUST be annotated with all the necessary Web service + * annotations. + * @return The newly created endpoint. + */ + public abstract Endpoint createAndPublishEndpoint(String address, + Object implementor); + + /** + * read an EndpointReference from the infoset contained in + * {@code eprInfoset}. + * + * @param eprInfoset infoset for EndpointReference + * + * @return the {@code EndpointReference} unmarshalled from + * {@code eprInfoset}. This method never returns {@code null}. + * + * @throws WebServiceException If there is an error creating the + * {@code EndpointReference} from the specified {@code eprInfoset}. + * + * @throws NullPointerException If the {@code null} + * {@code eprInfoset} value is given. + * + * @since 1.6, JAX-WS 2.1 + **/ + public abstract EndpointReference readEndpointReference(javax.xml.transform.Source eprInfoset); + + + /** + * The getPort method returns a proxy. If there + * are any reference parameters in the + * {@code endpointReference}, then those reference + * parameters MUST appear as SOAP headers, indicating them to be + * reference parameters, on all messages sent to the endpoint. + * The parameter {@code serviceEndpointInterface} specifies + * the service endpoint interface that is supported by the + * returned proxy. + * The parameter {@code endpointReference} specifies the + * endpoint that will be invoked by the returned proxy. + * In the implementation of this method, the JAX-WS + * runtime system takes the responsibility of selecting a protocol + * binding (and a port) and configuring the proxy accordingly from + * the WSDL metadata of the + * {@code serviceEndpointInterface} and the {@code EndpointReference}. + * For this method + * to successfully return a proxy, WSDL metadata MUST be available and the + * {@code endpointReference} MUST contain an implementation understood + * {@code serviceName} metadata. + * + * + * @param Service endpoint interface + * @param endpointReference the EndpointReference that will + * be invoked by the returned proxy. + * @param serviceEndpointInterface Service endpoint interface + * @param features A list of WebServiceFeatures to configure on the + * proxy. Supported features not in the {@code features + * } parameter will have their default values. + * @return Object Proxy instance that supports the + * specified service endpoint interface + * @throws WebServiceException + *
    + *
  • If there is an error during creation + * of the proxy + *
  • If there is any missing WSDL metadata + * as required by this method} + *
  • If this + * {@code endpointReference} + * is illegal + *
  • If an illegal + * {@code serviceEndpointInterface} + * is specified + *
  • If a feature is enabled that is not compatible with + * this port or is unsupported. + *
+ * + * @see WebServiceFeature + * + * @since 1.6, JAX-WS 2.1 + **/ + public abstract T getPort(EndpointReference endpointReference, + Class serviceEndpointInterface, + WebServiceFeature... features); + + /** + * Factory method to create a {@code W3CEndpointReference}. + * + *

+ * This method can be used to create a {@code W3CEndpointReference} + * for any endpoint by specifying the {@code address} property along + * with any other desired properties. This method + * can also be used to create a {@code W3CEndpointReference} for + * an endpoint that is published by the same Java EE application. + * To do so the {@code address} property can be provided or this + * method can automatically determine the {@code address} of + * an endpoint that is published by the same Java EE application and is + * identified by the {@code serviceName} and + * {@code portName} properties. If the {@code address} is + * {@code null} and the {@code serviceName} and + * {@code portName} do not identify an endpoint published by the + * same Java EE application, a + * {@code javax.lang.IllegalStateException} MUST be thrown. + * + * @param address Specifies the address of the target endpoint + * @param serviceName Qualified name of the service in the WSDL. + * @param portName Qualified name of the endpoint in the WSDL. + * @param metadata A list of elements that should be added to the + * {@code W3CEndpointReference} instances {@code wsa:metadata} + * element. + * @param wsdlDocumentLocation URL for the WSDL document location for + * the service. + * @param referenceParameters Reference parameters to be associated + * with the returned {@code EndpointReference} instance. + * + * @return the {@code W3CEndpointReference} created from + * {@code serviceName}, {@code portName}, + * {@code metadata}, {@code wsdlDocumentLocation} + * and {@code referenceParameters}. This method + * never returns {@code null}. + * + * @throws java.lang.IllegalStateException + *

    + *
  • If the {@code address}, {@code serviceName} and + * {@code portName} are all {@code null}. + *
  • If the {@code serviceName} service is {@code null} and the + * {@code portName} is NOT {@code null}. + *
  • If the {@code address} property is {@code null} and + * the {@code serviceName} and {@code portName} do not + * specify a valid endpoint published by the same Java EE + * application. + *
  • If the {@code serviceName}is NOT {@code null} + * and is not present in the specified WSDL. + *
  • If the {@code portName} port is not {@code null} and it + * is not present in {@code serviceName} service in the WSDL. + *
  • If the {@code wsdlDocumentLocation} is NOT {@code null} + * and does not represent a valid WSDL. + *
+ * @throws WebServiceException If an error occurs while creating the + * {@code W3CEndpointReference}. + * + * @since 1.6, JAX-WS 2.1 + */ + public abstract W3CEndpointReference createW3CEndpointReference(String address, QName serviceName, QName portName, + List metadata, String wsdlDocumentLocation, List referenceParameters); + + + /** + * Factory method to create a {@code W3CEndpointReference}. + * Using this method, a {@code W3CEndpointReference} instance + * can be created with extension elements, and attributes. + * {@code Provider} implementations must override the default + * implementation. + * + *

+ * This method can be used to create a {@code W3CEndpointReference} + * for any endpoint by specifying the {@code address} property along + * with any other desired properties. This method + * can also be used to create a {@code W3CEndpointReference} for + * an endpoint that is published by the same Java EE application. + * To do so the {@code address} property can be provided or this + * method can automatically determine the {@code address} of + * an endpoint that is published by the same Java EE application and is + * identified by the {@code serviceName} and + * {@code portName} propeties. If the {@code address} is + * {@code null} and the {@code serviceName} and + * {@code portName} do not identify an endpoint published by the + * same Java EE application, a + * {@code javax.lang.IllegalStateException} MUST be thrown. + * + * @param address Specifies the address of the target endpoint + * @param interfaceName the {@code wsam:InterfaceName} element in the + * {@code wsa:Metadata} element. + * @param serviceName Qualified name of the service in the WSDL. + * @param portName Qualified name of the endpoint in the WSDL. + * @param metadata A list of elements that should be added to the + * {@code W3CEndpointReference} instances {@code wsa:metadata} + * element. + * @param wsdlDocumentLocation URL for the WSDL document location for + * the service. + * @param referenceParameters Reference parameters to be associated + * with the returned {@code EndpointReference} instance. + * @param elements extension elements to be associated + * with the returned {@code EndpointReference} instance. + * @param attributes extension attributes to be associated + * with the returned {@code EndpointReference} instance. + * + * @return the {@code W3CEndpointReference} created from + * {@code serviceName}, {@code portName}, + * {@code metadata}, {@code wsdlDocumentLocation} + * and {@code referenceParameters}. This method + * never returns {@code null}. + * + * @throws java.lang.IllegalStateException + *

    + *
  • If the {@code address}, {@code serviceName} and + * {@code portName} are all {@code null}. + *
  • If the {@code serviceName} service is {@code null} and the + * {@code portName} is NOT {@code null}. + *
  • If the {@code address} property is {@code null} and + * the {@code serviceName} and {@code portName} do not + * specify a valid endpoint published by the same Java EE + * application. + *
  • If the {@code serviceName}is NOT {@code null} + * and is not present in the specified WSDL. + *
  • If the {@code portName} port is not {@code null} and it + * is not present in {@code serviceName} service in the WSDL. + *
  • If the {@code wsdlDocumentLocation} is NOT {@code null} + * and does not represent a valid WSDL. + *
  • If the {@code wsdlDocumentLocation} is NOT {@code null} but + * wsdli:wsdlLocation's namespace name cannot be got from the available + * metadata. + *
+ * @throws WebServiceException If an error occurs while creating the + * {@code W3CEndpointReference}. + * @since 1.7, JAX-WS 2.2 + */ + public W3CEndpointReference createW3CEndpointReference(String address, + QName interfaceName, QName serviceName, QName portName, + List metadata, String wsdlDocumentLocation, List referenceParameters, + List elements, Map attributes) { + throw new UnsupportedOperationException("JAX-WS 2.2 implementation must override this default behaviour."); + } + + /** + * Creates and publishes an endpoint object with the specified + * address, implementation object and web service features. + * {@code Provider} implementations must override the + * default implementation. + * + * @param address A URI specifying the address and transport/protocol + * to use. A http: URI MUST result in the SOAP 1.1/HTTP + * binding being used. Implementations may support other + * URI schemes. + * @param implementor A service implementation object to which + * incoming requests will be dispatched. The corresponding + * class MUST be annotated with all the necessary Web service + * annotations. + * @param features A list of WebServiceFeatures to configure on the + * endpoint. Supported features not in the {@code features} + * parameter will have their default values. + * @return The newly created endpoint. + * @since 1.7, JAX-WS 2.2 + */ + public Endpoint createAndPublishEndpoint(String address, + Object implementor, WebServiceFeature ... features) { + throw new UnsupportedOperationException("JAX-WS 2.2 implementation must override this default behaviour."); + } + + /** + * Creates an endpoint object with the provided binding, implementation + * object and web service features. {@code Provider} implementations + * must override the default implementation. + * + * @param bindingId A URI specifying the desired binding (e.g. SOAP/HTTP) + * @param implementor A service implementation object to which + * incoming requests will be dispatched. The corresponding + * class MUST be annotated with all the necessary Web service + * annotations. + * @param features A list of WebServiceFeatures to configure on the + * endpoint. Supported features not in the {@code features} + * parameter will have their default values. + * @return The newly created endpoint. + * @since 1.7, JAX-WS 2.2 + */ + public Endpoint createEndpoint(String bindingId, Object implementor, + WebServiceFeature ... features) { + throw new UnsupportedOperationException("JAX-WS 2.2 implementation must override this default behaviour."); + } + + /** + * Creates an endpoint object with the provided binding, implementation + * class, invoker and web service features. Containers typically use + * this to create Endpoint objects. {@code Provider} + * implementations must override the default implementation. + * + * @param bindingId A URI specifying the desired binding (e.g. SOAP/HTTP). + * Can be null. + * @param implementorClass A service implementation class that + * MUST be annotated with all the necessary Web service + * annotations. + * @param invoker that does the actual invocation on the service instance. + * @param features A list of WebServiceFeatures to configure on the + * endpoint. Supported features not in the {@code features + * } parameter will have their default values. + * @return The newly created endpoint. + * @since 1.7, JAX-WS 2.2 + */ + public Endpoint createEndpoint(String bindingId, Class implementorClass, + Invoker invoker, WebServiceFeature ... features) { + throw new UnsupportedOperationException("JAX-WS 2.2 implementation must override this default behaviour."); + } + +} diff --git a/fine-third-jdk11/src/javax/xml/ws/spi/ServiceDelegate.java b/fine-third-jdk11/src/javax/xml/ws/spi/ServiceDelegate.java new file mode 100644 index 000000000..48e708448 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/spi/ServiceDelegate.java @@ -0,0 +1,652 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.spi; + +import java.util.Iterator; +import javax.xml.namespace.QName; +import javax.xml.ws.Dispatch; +import javax.xml.ws.Service; +import javax.xml.ws.handler.HandlerResolver; +import javax.xml.ws.WebServiceFeature; +import javax.xml.bind.JAXBContext; +import javax.xml.ws.EndpointReference; +import javax.xml.ws.WebServiceException; + + +/** + * Service delegates are used internally by {@code Service} objects + * to allow pluggability of JAX-WS implementations. + *

+ * Every {@code Service} object has its own delegate, created using + * the {@link javax.xml.ws.spi.Provider#createServiceDelegate} method. A {@code Service} + * object delegates all of its instance methods to its delegate. + * + * @see javax.xml.ws.Service + * @see javax.xml.ws.spi.Provider + * + * @since 1.6, JAX-WS 2.0 + */ +public abstract class ServiceDelegate { + + /** + * Default constructor. + */ + protected ServiceDelegate() { + } + + /** + * The {@code getPort} method returns a proxy. A service client + * uses this proxy to invoke operations on the target + * service endpoint. The {@code serviceEndpointInterface} + * specifies the service endpoint interface that is supported by + * the created dynamic proxy instance. + * + * @param Service endpoint interface + * @param portName Qualified name of the service endpoint in + * the WSDL service description + * @param serviceEndpointInterface Service endpoint interface + * supported by the dynamic proxy + * @return Object Proxy instance that + * supports the specified service endpoint + * interface + * @throws WebServiceException This exception is thrown in the + * following cases: + *

    + *
  • If there is an error in creation of + * the proxy + *
  • If there is any missing WSDL metadata + * as required by this method + *
  • If an illegal + * {@code serviceEndpointInterface} + * or {@code portName} is specified + *
+ * @see java.lang.reflect.Proxy + * @see java.lang.reflect.InvocationHandler + **/ + public abstract T getPort(QName portName, + Class serviceEndpointInterface); + + /** + * The {@code getPort} method returns a proxy. A service client + * uses this proxy to invoke operations on the target + * service endpoint. The {@code serviceEndpointInterface} + * specifies the service endpoint interface that is supported by + * the created dynamic proxy instance. + * + * @param Service endpoint interface + * @param portName Qualified name of the service endpoint in + * the WSDL service description + * @param serviceEndpointInterface Service endpoint interface + * supported by the dynamic proxy or instance + * @param features A list of WebServiceFeatures to configure on the + * proxy. Supported features not in the {@code features + * } parameter will have their default values. + * @return Object Proxy instance that + * supports the specified service endpoint + * interface + * @throws WebServiceException This exception is thrown in the + * following cases: + *
    + *
  • If there is an error in creation of + * the proxy + *
  • If there is any missing WSDL metadata + * as required by this method + *
  • If an illegal + * {@code serviceEndpointInterface} + * or {@code portName} is specified + *
  • If a feature is enabled that is not compatible + * with this port or is unsupported. + *
+ * @see java.lang.reflect.Proxy + * @see java.lang.reflect.InvocationHandler + * @see WebServiceFeature + * + * @since 1.6, JAX-WS 2.1 + **/ + public abstract T getPort(QName portName, + Class serviceEndpointInterface, WebServiceFeature... features); + + /** + * The {@code getPort} method returns a proxy. + * The parameter {@code endpointReference} specifies the + * endpoint that will be invoked by the returned proxy. If there + * are any reference parameters in the + * {@code endpointReference}, then those reference + * parameters MUST appear as SOAP headers, indicating them to be + * reference parameters, on all messages sent to the endpoint. + * The {@code endpointReference's} address MUST be used + * for invocations on the endpoint. + * The parameter {@code serviceEndpointInterface} specifies + * the service endpoint interface that is supported by the + * returned proxy. + * In the implementation of this method, the JAX-WS + * runtime system takes the responsibility of selecting a protocol + * binding (and a port) and configuring the proxy accordingly from + * the WSDL associated with this {@code Service} instance or + * from the metadata from the {@code endpointReference}. + * If this {@code Service} instance has a WSDL and + * the {@code endpointReference} metadata + * also has a WSDL, then the WSDL from this instance MUST be used. + * If this {@code Service} instance does not have a WSDL and + * the {@code endpointReference} does have a WSDL, then the + * WSDL from the {@code endpointReference} MAY be used. + * The returned proxy should not be reconfigured by the client. + * If this {@code Service} instance has a known proxy + * port that matches the information contained in + * the WSDL, + * then that proxy is returned, otherwise a WebServiceException + * is thrown. + *

+ * Calling this method has the same behavior as the following + *

+     * {@code port = service.getPort(portName, serviceEndpointInterface);}
+     * 
+ * where the {@code portName} is retrieved from the + * metadata of the {@code endpointReference} or from the + * {@code serviceEndpointInterface} and the WSDL + * associated with this {@code Service} instance. + * + * @param Service endpoint interface. + * @param endpointReference The {@code EndpointReference} + * for the target service endpoint that will be invoked by the + * returned proxy. + * @param serviceEndpointInterface Service endpoint interface. + * @param features A list of {@code WebServiceFeatures} to configure on the + * proxy. Supported features not in the {@code features + * } parameter will have their default values. + * @return Object Proxy instance that supports the + * specified service endpoint interface. + * @throws WebServiceException + *
    + *
  • If there is an error during creation + * of the proxy. + *
  • If there is any missing WSDL metadata + * as required by this method. + *
  • If the {@code endpointReference} metadata does + * not match the {@code serviceName} of this + * {@code Service} instance. + *
  • If a {@code portName} cannot be extracted + * from the WSDL or {@code endpointReference} metadata. + *
  • If an invalid + * {@code endpointReference} + * is specified. + *
  • If an invalid + * {@code serviceEndpointInterface} + * is specified. + *
  • If a feature is enabled that is not compatible + * with this port or is unsupported. + *
+ * + * @since 1.6, JAX-WS 2.1 + **/ + public abstract T getPort(EndpointReference endpointReference, + Class serviceEndpointInterface, WebServiceFeature... features); + + + /** + * The {@code getPort} method returns a proxy. The parameter + * {@code serviceEndpointInterface} specifies the service + * endpoint interface that is supported by the returned proxy. + * In the implementation of this method, the JAX-WS + * runtime system takes the responsibility of selecting a protocol + * binding (and a port) and configuring the proxy accordingly. + * The returned proxy should not be reconfigured by the client. + * + * @param Service endpoint interface + * @param serviceEndpointInterface Service endpoint interface + * @return Object instance that supports the + * specified service endpoint interface + * @throws WebServiceException + *
    + *
  • If there is an error during creation + * of the proxy + *
  • If there is any missing WSDL metadata + * as required by this method + *
  • If an illegal + * {@code serviceEndpointInterface} + * is specified + *
+ **/ + public abstract T getPort(Class serviceEndpointInterface); + + + /** + * The {@code getPort} method returns a proxy. The parameter + * {@code serviceEndpointInterface} specifies the service + * endpoint interface that is supported by the returned proxy. + * In the implementation of this method, the JAX-WS + * runtime system takes the responsibility of selecting a protocol + * binding (and a port) and configuring the proxy accordingly. + * The returned proxy should not be reconfigured by the client. + * + * @param Service endpoint interface + * @param serviceEndpointInterface Service endpoint interface + * @param features An array of {@code WebServiceFeatures} to configure on the + * proxy. Supported features not in the {@code features + * } parameter will have their default values. + * @return Object instance that supports the + * specified service endpoint interface + * @throws WebServiceException + *
    + *
  • If there is an error during creation + * of the proxy + *
  • If there is any missing WSDL metadata + * as required by this method + *
  • If an illegal + * {@code serviceEndpointInterface} + * is specified + *
  • If a feature is enabled that is not compatible + * with this port or is unsupported. + *
+ * + * @see WebServiceFeature + * + * @since 1.6, JAX-WS 2.1 + **/ + public abstract T getPort(Class serviceEndpointInterface, + WebServiceFeature... features); + + + /** + * Creates a new port for the service. Ports created in this way contain + * no WSDL port type information and can only be used for creating + * {@code Dispatch}instances. + * + * @param portName Qualified name for the target service endpoint + * @param bindingId A URI identifier of a binding. + * @param endpointAddress Address of the target service endpoint as a URI + * @throws WebServiceException If any error in the creation of + * the port + * + * @see javax.xml.ws.soap.SOAPBinding#SOAP11HTTP_BINDING + * @see javax.xml.ws.soap.SOAPBinding#SOAP12HTTP_BINDING + * @see javax.xml.ws.http.HTTPBinding#HTTP_BINDING + **/ + public abstract void addPort(QName portName, String bindingId, + String endpointAddress); + + + + /** + * Creates a {@code Dispatch} instance for use with objects of + * the user's choosing. + * + * @param type used for messages or message payloads. Implementations are required to + * support {@code javax.xml.transform.Source} and {@code javax.xml.soap.SOAPMessage}. + * @param portName Qualified name for the target service endpoint + * @param type The class of object used for messages or message + * payloads. Implementations are required to support + * {@code javax.xml.transform.Source} and {@code javax.xml.soap.SOAPMessage}. + * @param mode Controls whether the created dispatch instance is message + * or payload oriented, i.e. whether the user will work with complete + * protocol messages or message payloads. E.g. when using the SOAP + * protocol, this parameter controls whether the user will work with + * SOAP messages or the contents of a SOAP body. Mode MUST be {@code MESSAGE} + * when type is {@code SOAPMessage}. + * + * @return Dispatch instance + * @throws WebServiceException If any error in the creation of + * the {@code Dispatch} object + * @see javax.xml.transform.Source + * @see javax.xml.soap.SOAPMessage + **/ + public abstract Dispatch createDispatch(QName portName, Class type, + Service.Mode mode); + + /** + * Creates a {@code Dispatch} instance for use with objects of + * the user's choosing. + * + * @param type used for messages or message payloads. Implementations are required to + * support {@code javax.xml.transform.Source} and {@code javax.xml.soap.SOAPMessage}. + * @param portName Qualified name for the target service endpoint + * @param type The class of object used for messages or message + * payloads. Implementations are required to support + * {@code javax.xml.transform.Source} and {@code javax.xml.soap.SOAPMessage}. + * @param mode Controls whether the created dispatch instance is message + * or payload oriented, i.e. whether the user will work with complete + * protocol messages or message payloads. E.g. when using the SOAP + * protocol, this parameter controls whether the user will work with + * SOAP messages or the contents of a SOAP body. Mode MUST be {@code MESSAGE} + * when type is {@code SOAPMessage}. + * @param features A list of {@code WebServiceFeatures} to configure on the + * proxy. Supported features not in the {@code features + * } parameter will have their default values. + * + * @return Dispatch instance + * @throws WebServiceException If any error in the creation of + * the {@code Dispatch} object or if a + * feature is enabled that is not compatible with + * this port or is unsupported. + * + * @see javax.xml.transform.Source + * @see javax.xml.soap.SOAPMessage + * @see WebServiceFeature + * + * @since 1.6, JAX-WS 2.1 + **/ + public abstract Dispatch createDispatch(QName portName, Class type, + Service.Mode mode, WebServiceFeature... features); + + /** + * Creates a {@code Dispatch} instance for use with objects of + * the user's choosing. If there + * are any reference parameters in the + * {@code endpointReference}, then those reference + * parameters MUST appear as SOAP headers, indicating them to be + * reference parameters, on all messages sent to the endpoint. + * The {@code endpointReference's} address MUST be used + * for invocations on the endpoint. + * In the implementation of this method, the JAX-WS + * runtime system takes the responsibility of selecting a protocol + * binding (and a port) and configuring the dispatch accordingly from + * the WSDL associated with this {@code Service} instance or + * from the metadata from the {@code endpointReference}. + * If this {@code Service} instance has a WSDL and + * the {@code endpointReference} + * also has a WSDL in its metadata, then the WSDL from this instance MUST be used. + * If this {@code Service} instance does not have a WSDL and + * the {@code endpointReference} does have a WSDL, then the + * WSDL from the {@code endpointReference} MAY be used. + * An implementation MUST be able to retrieve the {@code portName} from the + * {@code endpointReference} metadata. + *

+ * This method behaves the same as calling + *

+     * {@code dispatch = service.createDispatch(portName, type, mode, features);}
+     * 
+ * where the {@code portName} is retrieved from the + * WSDL or {@code EndpointReference} metadata. + * + * @param type of object used to messages or message + * payloads. Implementations are required to support + * {@code javax.xml.transform.Source} and {@code javax.xml.soap.SOAPMessage}. + * @param endpointReference The {@code EndpointReference} + * for the target service endpoint that will be invoked by the + * returned {@code Dispatch} object. + * @param type The class of object used to messages or message + * payloads. Implementations are required to support + * {@code javax.xml.transform.Source} and {@code javax.xml.soap.SOAPMessage}. + * @param mode Controls whether the created dispatch instance is message + * or payload oriented, i.e. whether the user will work with complete + * protocol messages or message payloads. E.g. when using the SOAP + * protocol, this parameter controls whether the user will work with + * SOAP messages or the contents of a SOAP body. Mode MUST be {@code MESSAGE} + * when type is {@code SOAPMessage}. + * @param features An array of {@code WebServiceFeatures} to configure on the + * proxy. Supported features not in the {@code features + * } parameter will have their default values. + * + * @return Dispatch instance + * @throws WebServiceException + *
    + *
  • If there is any missing WSDL metadata + * as required by this method. + *
  • If the {@code endpointReference} metadata does + * not match the {@code serviceName} or {@code portName} + * of a WSDL associated + * with this {@code Service} instance. + *
  • If the {@code portName} cannot be determined + * from the {@code EndpointReference} metadata. + *
  • If any error in the creation of + * the {@code Dispatch} object. + *
  • If a feature is enabled that is not + * compatible with this port or is unsupported. + *
+ * + * @see javax.xml.transform.Source + * @see javax.xml.soap.SOAPMessage + * @see WebServiceFeature + * + * @since 1.6, JAX-WS 2.1 + **/ + public abstract Dispatch createDispatch(EndpointReference endpointReference, + Class type, Service.Mode mode, + WebServiceFeature... features); + + + + /** + * Creates a {@code Dispatch} instance for use with JAXB + * generated objects. + * + * @param portName Qualified name for the target service endpoint + * @param context The JAXB context used to marshall and unmarshall + * messages or message payloads. + * @param mode Controls whether the created dispatch instance is message + * or payload oriented, i.e. whether the user will work with complete + * protocol messages or message payloads. E.g. when using the SOAP + * protocol, this parameter controls whether the user will work with + * SOAP messages or the contents of a SOAP body. + * + * @return Dispatch instance + * @throws WebServiceException If any error in the creation of + * the {@code Dispatch} object + * + * @see javax.xml.bind.JAXBContext + **/ + public abstract Dispatch createDispatch(QName portName, + JAXBContext context, Service.Mode mode); + + + /** + * Creates a {@code Dispatch} instance for use with JAXB + * generated objects. + * + * @param portName Qualified name for the target service endpoint + * @param context The JAXB context used to marshall and unmarshall + * messages or message payloads. + * @param mode Controls whether the created dispatch instance is message + * or payload oriented, i.e. whether the user will work with complete + * protocol messages or message payloads. E.g. when using the SOAP + * protocol, this parameter controls whether the user will work with + * SOAP messages or the contents of a SOAP body. + * @param features A list of {@code WebServiceFeatures} to configure on the + * proxy. Supported features not in the {@code features + * } parameter will have their default values. + * + * @return Dispatch instance + * @throws WebServiceException If any error in the creation of + * the {@code Dispatch} object or if a + * feature is enabled that is not compatible with + * this port or is unsupported. + * + * @see javax.xml.bind.JAXBContext + * @see WebServiceFeature + * + * @since 1.6, JAX-WS 2.1 + **/ + public abstract Dispatch createDispatch(QName portName, + JAXBContext context, Service.Mode mode, WebServiceFeature... features); + + /** + * Creates a {@code Dispatch} instance for use with JAXB + * generated objects. If there + * are any reference parameters in the + * {@code endpointReference}, then those reference + * parameters MUST appear as SOAP headers, indicating them to be + * reference parameters, on all messages sent to the endpoint. + * The {@code endpointReference's} address MUST be used + * for invocations on the endpoint. + * In the implementation of this method, the JAX-WS + * runtime system takes the responsibility of selecting a protocol + * binding (and a port) and configuring the dispatch accordingly from + * the WSDL associated with this {@code Service} instance or + * from the metadata from the {@code endpointReference}. + * If this {@code Service} instance has a WSDL and + * the {@code endpointReference} + * also has a WSDL in its metadata, then the WSDL from this instance + * MUST be used. + * If this {@code Service} instance does not have a WSDL and + * the {@code endpointReference} does have a WSDL, then the + * WSDL from the {@code endpointReference} MAY be used. + * An implementation MUST be able to retrieve the {@code portName} from the + * {@code endpointReference} metadata. + *

+ * This method behavies the same as calling + *

+     * {@code dispatch = service.createDispatch(portName, context, mode, features);}
+     * 
+ * where the {@code portName} is retrieved from the + * WSDL or {@code endpointReference} metadata. + * + * @param endpointReference The {@code EndpointReference} + * for the target service endpoint that will be invoked by the + * returned {@code Dispatch} object. + * @param context The JAXB context used to marshall and unmarshall + * messages or message payloads. + * @param mode Controls whether the created dispatch instance is message + * or payload oriented, i.e. whether the user will work with complete + * protocol messages or message payloads. E.g. when using the SOAP + * protocol, this parameter controls whether the user will work with + * SOAP messages or the contents of a SOAP body. + * @param features An array of {@code WebServiceFeatures} to configure on the + * proxy. Supported features not in the {@code features + * } parameter will have their default values. + * + * @return Dispatch instance + * @throws WebServiceException + *
    + *
  • If there is any missing WSDL metadata + * as required by this method. + *
  • If the {@code endpointReference} metadata does + * not match the {@code serviceName} or {@code portName} + * of a WSDL associated + * with this {@code Service} instance. + *
  • If the {@code portName} cannot be determined + * from the {@code EndpointReference} metadata. + *
  • If any error in the creation of + * the {@code Dispatch} object. + *
  • if a feature is enabled that is not + * compatible with this port or is unsupported. + *
+ * + * @see javax.xml.bind.JAXBContext + * @see WebServiceFeature + * + * @since 1.6, JAX-WS 2.1 + **/ + public abstract Dispatch createDispatch(EndpointReference endpointReference, + JAXBContext context, Service.Mode mode, + WebServiceFeature... features); + + + /** + * Gets the name of this service. + * @return Qualified name of this service + **/ + public abstract QName getServiceName(); + + /** + * Returns an {@code Iterator} for the list of + * {@code QName}s of service endpoints grouped by this + * service + * + * @return Returns {@code java.util.Iterator} with elements + * of type {@code javax.xml.namespace.QName} + * @throws WebServiceException If this Service class does not + * have access to the required WSDL metadata + **/ + public abstract Iterator getPorts(); + + /** + * Gets the location of the WSDL document for this Service. + * + * @return URL for the location of the WSDL document for + * this service + **/ + public abstract java.net.URL getWSDLDocumentLocation(); + + /** + * Returns the configured handler resolver. + * + * @return HandlerResolver The {@code HandlerResolver} being + * used by this {@code Service} instance, or {@code null} + * if there isn't one. + **/ + public abstract HandlerResolver getHandlerResolver(); + + /** + * Sets the {@code HandlerResolver} for this {@code Service} + * instance. + *

+ * The handler resolver, if present, will be called once for each + * proxy or dispatch instance that is created, and the handler chain + * returned by the resolver will be set on the instance. + * + * @param handlerResolver The {@code HandlerResolver} to use + * for all subsequently created proxy/dispatch objects. + * + * @see javax.xml.ws.handler.HandlerResolver + **/ + public abstract void setHandlerResolver(HandlerResolver handlerResolver); + + /** + * Returns the executor for this {@code Service}instance. + * + * The executor is used for all asynchronous invocations that + * require callbacks. + * + * @return The {@code java.util.concurrent.Executor} to be + * used to invoke a callback. + * + * @see java.util.concurrent.Executor + **/ + public abstract java.util.concurrent.Executor getExecutor(); + + /** + * Sets the executor for this {@code Service} instance. + * + * The executor is used for all asynchronous invocations that + * require callbacks. + * + * @param executor The {@code java.util.concurrent.Executor} + * to be used to invoke a callback. + * + * @throws SecurityException If the instance does not support + * setting an executor for security reasons (e.g. the + * necessary permissions are missing). + * + * @see java.util.concurrent.Executor + **/ + public abstract void setExecutor(java.util.concurrent.Executor executor); + +} diff --git a/fine-third-jdk11/src/javax/xml/ws/spi/ServiceLoaderUtil.java b/fine-third-jdk11/src/javax/xml/ws/spi/ServiceLoaderUtil.java new file mode 100644 index 000000000..3d6fd97bd --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/spi/ServiceLoaderUtil.java @@ -0,0 +1,140 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2015-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.spi; + +import java.util.ServiceLoader; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Shared ServiceLoader/FactoryFinder Utils shared among SAAJ, JAXB and JAXWS + * Class duplicated to all those projects. + * + * @author Miroslav.Kos@oracle.com + */ +class ServiceLoaderUtil { + + static P firstByServiceLoader(Class

spiClass, + Logger logger, + ExceptionHandler handler) throws T { + logger.log(Level.FINE, "Using java.util.ServiceLoader to find {0}", spiClass.getName()); + // service discovery + try { + ServiceLoader

serviceLoader = ServiceLoader.load(spiClass); + + for (P impl : serviceLoader) { + logger.fine("ServiceProvider loading Facility used; returning object [" + + impl.getClass().getName() + "]"); + + return impl; + } + } catch (Throwable t) { + throw handler.createException(t, "Error while searching for service [" + spiClass.getName() + "]"); + } + return null; + } + + static void checkPackageAccess(String className) { + // make sure that the current thread has an access to the package of the given name. + SecurityManager s = System.getSecurityManager(); + if (s != null) { + int i = className.lastIndexOf('.'); + if (i != -1) { + s.checkPackageAccess(className.substring(0, i)); + } + } + } + + static Class nullSafeLoadClass(String className, ClassLoader classLoader) throws ClassNotFoundException { + if (classLoader == null) { + return Class.forName(className); + } else { + return classLoader.loadClass(className); + } + } + + // Returns instance of required class. It checks package access (security) + // unless it is defaultClassname. It means if you are trying to instantiate + // default implementation (fallback), pass the class name to both first and second parameter. + static Object newInstance(String className, + String defaultImplClassName, ClassLoader classLoader, + final ExceptionHandler handler) throws T { + try { + return safeLoadClass(className, defaultImplClassName, classLoader).newInstance(); + } catch (ClassNotFoundException x) { + throw handler.createException(x, "Provider " + className + " not found"); + } catch (Exception x) { + throw handler.createException(x, "Provider " + className + " could not be instantiated: " + x); + } + } + + static Class safeLoadClass(String className, + String defaultImplClassName, + ClassLoader classLoader) throws ClassNotFoundException { + + try { + checkPackageAccess(className); + } catch (SecurityException se) { + // anyone can access the platform default factory class without permission + if (defaultImplClassName != null && defaultImplClassName.equals(className)) { + return Class.forName(className); + } + // not platform default implementation ... + throw se; + } + return nullSafeLoadClass(className, classLoader); + } + + static ClassLoader contextClassLoader(ExceptionHandler exceptionHandler) throws T { + try { + return Thread.currentThread().getContextClassLoader(); + } catch (Exception x) { + throw exceptionHandler.createException(x, x.toString()); + } + } + + static abstract class ExceptionHandler { + + public abstract T createException(Throwable throwable, String message); + + } + +} diff --git a/fine-third-jdk11/src/javax/xml/ws/spi/WebServiceFeatureAnnotation.java b/fine-third-jdk11/src/javax/xml/ws/spi/WebServiceFeatureAnnotation.java new file mode 100644 index 000000000..dba26c43d --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/spi/WebServiceFeatureAnnotation.java @@ -0,0 +1,101 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.spi; + +import java.lang.annotation.Documented; +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import javax.xml.ws.WebServiceFeature; +import javax.xml.ws.WebServiceRef; +import javax.xml.ws.RespectBinding; +import javax.xml.ws.soap.Addressing; +import javax.xml.ws.soap.MTOM; + +/** + * Annotation used to identify other annotations + * as a {@code WebServiceFeature}. + *

+ * Each {@code WebServiceFeature} annotation annotated with + * this annotation MUST contain an + * {@code enabled} property of type + * {@code boolean} with a default value of {@code true}. + *

+ * JAX-WS defines the following + * {@code WebServiceFeature} annotations ({@code Addressing}, + * {@code MTOM}, {@code RespectBinding}), however, an implementation + * may define vendors specific annotations for other features. + *

+ * Annotations annotated with {@code WebServiceFeatureAnnotation} MUST + * have the same @Target of {@link WebServiceRef} annotation, so that the resulting + * feature annotation can be used in conjunction with the {@link WebServiceRef} + * annotation if necessary. + *

+ * If a JAX-WS implementation encounters an annotation annotated + * with the {@code WebServiceFeatureAnnotation} that it does not + * recognize/support an error MUST be given. + * + * @see Addressing + * @see MTOM + * @see RespectBinding + * + * @since 1.6, JAX-WS 2.1 + */ +@Target(ElementType.ANNOTATION_TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface WebServiceFeatureAnnotation { + /** + * Unique identifier for the WebServiceFeature. This + * identifier MUST be unique across all implementations + * of JAX-WS. + * @return unique identifier for the WebServiceFeature + */ + String id(); + + /** + * The {@code WebServiceFeature} bean that is associated + * with the {@code WebServiceFeature} annotation + * @return the {@code WebServiceFeature} bean + */ + Class bean(); +} diff --git a/fine-third-jdk11/src/javax/xml/ws/spi/http/HttpContext.java b/fine-third-jdk11/src/javax/xml/ws/spi/http/HttpContext.java new file mode 100644 index 000000000..50afe4c6a --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/spi/http/HttpContext.java @@ -0,0 +1,117 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2009-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.spi.http; + +import javax.xml.ws.Endpoint; +import java.util.Set; + +/** + * HttpContext represents a mapping between the root URI path of a web + * service to a {@link HttpHandler} which is invoked to handle requests + * destined for that path on the associated container. + *

+ * Container provides the implementation for this and it matches + * web service requests to corresponding HttpContext objects. + * + * @author Jitendra Kotamraju + * @since 1.7, JAX-WS 2.2 + */ +public abstract class HttpContext { + + /** + * The handler to set for this context. + */ + protected HttpHandler handler; + + /** + * JAX-WS runtime sets its handler during + * {@link Endpoint#publish(HttpContext)} to handle + * HTTP requests for this context. Container or its extensions + * use this handler to process the requests. + * + * @param handler the handler to set for this context + */ + public void setHandler(HttpHandler handler) { + this.handler = handler; + } + + /** + * Returns the path for this context. This path uniquely identifies + * an endpoint inside an application and the path is relative to + * application's context path. Container should give this + * path based on how it matches request URIs to this HttpContext object. + * + *

+ * For servlet container, this is typically a url-pattern for an endpoint. + * + *

+ * Endpoint's address for this context can be computed as follows: + *

+     *  HttpExchange exch = ...;
+     *  String endpointAddress =
+     *      exch.getScheme() + "://"
+     *      + exch.getLocalAddress().getHostName()
+     *      + ":" + exch.getLocalAddress().getPort()
+     *      + exch.getContextPath() + getPath();
+     * 
+ * + * @return this context's path + */ + public abstract String getPath(); + + /** + * Returns an attribute value for container's configuration + * and other data that can be used by jax-ws runtime. + * + * @param name attribute name + * @return attribute value + */ + public abstract Object getAttribute(String name); + + /** + * Returns all attribute names for container's configuration + * and other data that can be used by jax-ws runtime. + * + * @return set of all attribute names + */ + public abstract Set getAttributeNames(); + +} diff --git a/fine-third-jdk11/src/javax/xml/ws/spi/http/HttpExchange.java b/fine-third-jdk11/src/javax/xml/ws/spi/http/HttpExchange.java new file mode 100644 index 000000000..f3d65f2f6 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/spi/http/HttpExchange.java @@ -0,0 +1,343 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.spi.http; + +import javax.xml.ws.handler.MessageContext; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.security.Principal; + +/** + * This class encapsulates a HTTP request received and a + * response to be generated in one exchange. It provides methods + * for examining the request from the client, and for building and + * sending the response. + *

+ * A {@code HttpExchange} must be closed to free or reuse + * underlying resources. The effect of failing to close an exchange + * is undefined. + * + * @author Jitendra Kotamraju + * @since 1.7, JAX-WS 2.2 + */ +public abstract class HttpExchange { + + /** + * Standard property: cipher suite value when the request is received + * over HTTPS + *

Type: String + */ + public static final String REQUEST_CIPHER_SUITE = + "javax.xml.ws.spi.http.request.cipher.suite"; + + /** + * Standard property: bit size of the algorithm when the request is + * received over HTTPS + *

Type: Integer + */ + public static final String REQUEST_KEY_SIZE = + "javax.xml.ws.spi.http.request.key.size"; + + /** + * Standard property: A SSL certificate, if any, associated with the request + * + *

Type: java.security.cert.X509Certificate[] + * The order of this array is defined as being in ascending order of trust. + * The first certificate in the chain is the one set by the client, the next + * is the one used to authenticate the first, and so on. + */ + public static final String REQUEST_X509CERTIFICATE = + "javax.xml.ws.spi.http.request.cert.X509Certificate"; + + /** + * Returns an immutable Map containing the HTTP headers that were + * included with this request. The keys in this Map will be the header + * names, while the values will be a List of Strings containing each value + * that was included (either for a header that was listed several times, + * or one that accepts a comma-delimited list of values on a single line). + * In either of these cases, the values for the header name will be + * presented in the order that they were included in the request. + *

+ * The keys in Map are case-insensitive. + * + * @return an immutable Map which can be used to access request headers + */ + public abstract Map> getRequestHeaders(); + + /** + * Returns the value of the specified request header. If the request + * did not include a header of the specified name, this method returns + * null. If there are multiple headers with the same name, this method + * returns the first header in the request. The header name is + * case-insensitive. This is a convienence method to get a header + * (instead of using the {@link #getRequestHeaders}). + * + * @param name the name of the request header + * @return returns the value of the requested header, + * or null if the request does not have a header of that name + */ + public abstract String getRequestHeader(String name); + + /** + * Returns a mutable Map into which the HTTP response headers can be stored + * and which will be transmitted as part of this response. The keys in the + * Map will be the header names, while the values must be a List of Strings + * containing each value that should be included multiple times + * (in the order that they should be included). + *

+ * The keys in Map are case-insensitive. + * + * @return a mutable Map which can be used to set response headers. + */ + public abstract Map> getResponseHeaders(); + + /** + * Adds a response header with the given name and value. This method + * allows a response header to have multiple values. This is a + * convenience method to add a response header(instead of using the + * {@link #getResponseHeaders()}). + * + * @param name the name of the header + * @param value the additional header value. If it contains octet string, + * it should be encoded according to + * RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt) + * + * @see #getResponseHeaders + */ + public abstract void addResponseHeader(String name, String value); + + /** + * Returns the part of the request's URI from the protocol + * name up to the query string in the first line of the HTTP request. + * Container doesn't decode this string. + * + * @return the request URI + */ + public abstract String getRequestURI(); + + /** + * Returns the context path of all the endpoints in an application. + * This path is the portion of the request URI that indicates the + * context of the request. The context path always comes first in a + * request URI. The path starts with a "/" character but does not + * end with a "/" character. If this method returns "", the request + * is for default context. The container does not decode this string. + * + *

+ * Context path is used in computing the endpoint address. See + * {@link HttpContext#getPath} + * + * @return context path of all the endpoints in an application + * @see HttpContext#getPath + */ + public abstract String getContextPath(); + + /** + * Get the HTTP request method + * + * @return the request method + */ + public abstract String getRequestMethod(); + + /** + * Returns a {@link HttpContext} for this exchange. + * Container matches the request with the associated Endpoint's HttpContext + * + * @return the HttpContext for this exchange + */ + public abstract HttpContext getHttpContext(); + + /** + * This must be called to end an exchange. Container takes care of + * closing request and response streams. This must be called so that + * the container can free or reuse underlying resources. + * + * @throws IOException if any i/o error + */ + public abstract void close() throws IOException; + + /** + * Returns a stream from which the request body can be read. + * Multiple calls to this method will return the same stream. + * + * @return the stream from which the request body can be read. + * @throws IOException if any i/o error during request processing + */ + public abstract InputStream getRequestBody() throws IOException; + + /** + * Returns a stream to which the response body must be + * written. {@link #setStatus}) must be called prior to calling + * this method. Multiple calls to this method (for the same exchange) + * will return the same stream. + * + * @return the stream to which the response body is written + * @throws IOException if any i/o error during response processing + */ + public abstract OutputStream getResponseBody() throws IOException; + + /** + * Sets the HTTP status code for the response. + * + *

+ * This method must be called prior to calling {@link #getResponseBody}. + * + * @param status the response code to send + * @see #getResponseBody + */ + public abstract void setStatus(int status); + + /** + * Returns the unresolved address of the remote entity invoking + * this request. + * + * @return the InetSocketAddress of the caller + */ + public abstract InetSocketAddress getRemoteAddress(); + + /** + * Returns the unresolved local address on which the request was received. + * + * @return the InetSocketAddress of the local interface + */ + public abstract InetSocketAddress getLocalAddress(); + + /** + * Returns the protocol string from the request in the form + * protocol/majorVersion.minorVersion. For example, + * "HTTP/1.1" + * + * @return the protocol string from the request + */ + public abstract String getProtocol(); + + /** + * Returns the name of the scheme used to make this request, + * for example: http, or https. + * + * @return name of the scheme used to make this request + */ + public abstract String getScheme(); + + /** + * Returns the extra path information that follows the web service + * path but precedes the query string in the request URI and will start + * with a "/" character. + * + *

+ * This can be used for {@link MessageContext#PATH_INFO} + * + * @return decoded extra path information of web service. + * It is the path that comes + * after the web service path but before the query string in the + * request URI + * {@code null} if there is no extra path in the request URI + */ + public abstract String getPathInfo(); + + /** + * Returns the query string that is contained in the request URI + * after the path. + * + *

+ * This can be used for {@link MessageContext#QUERY_STRING} + * + * @return undecoded query string of request URI, or + * {@code null} if the request URI doesn't have one + */ + public abstract String getQueryString(); + + /** + * Returns an attribute that is associated with this + * {@code HttpExchange}. JAX-WS handlers and endpoints may then + * access the attribute via {@link MessageContext}. + *

+ * Servlet containers must expose {@link MessageContext#SERVLET_CONTEXT}, + * {@link MessageContext#SERVLET_REQUEST}, and + * {@link MessageContext#SERVLET_RESPONSE} + * as attributes. + * + *

If the request has been received by the container using HTTPS, the + * following information must be exposed as attributes. These attributes + * are {@link #REQUEST_CIPHER_SUITE}, and {@link #REQUEST_KEY_SIZE}. + * If there is a SSL certificate associated with the request, it must + * be exposed using {@link #REQUEST_X509CERTIFICATE} + * + * @param name attribute name + * @return the attribute value, or {@code null} if the attribute doesn't + * exist + */ + public abstract Object getAttribute(String name); + + /** + * Gives all the attribute names that are associated with + * this {@code HttpExchange}. + * + * @return set of all attribute names + * @see #getAttribute(String) + */ + public abstract Set getAttributeNames(); + + /** + * Returns the {@link Principal} that represents the authenticated + * user for this {@code HttpExchange}. + * + * @return Principal for an authenticated user, or + * {@code null} if not authenticated + */ + public abstract Principal getUserPrincipal(); + + /** + * Indicates whether an authenticated user is included in the specified + * logical "role". + * + * @param role specifies the name of the role + * @return {@code true} if the user making this request belongs to a + * given role + */ + public abstract boolean isUserInRole(String role); + +} diff --git a/fine-third-jdk11/src/javax/xml/ws/spi/http/HttpHandler.java b/fine-third-jdk11/src/javax/xml/ws/spi/http/HttpHandler.java new file mode 100644 index 000000000..abc9c1ea6 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/spi/http/HttpHandler.java @@ -0,0 +1,69 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2009-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.spi.http; + +import javax.xml.ws.Endpoint; +import java.io.IOException; + +/** + * A handler which is invoked to process HTTP requests. + *

+ * JAX-WS runtime provides the implementation for this and sets + * it using {@link HttpContext#setHandler(HttpHandler)} during + * {@link Endpoint#publish(HttpContext) } + * + * @author Jitendra Kotamraju + * @since 1.7, JAX-WS 2.2 + */ +public abstract class HttpHandler { + /** + * Handles a given request and generates an appropriate response. + * See {@link HttpExchange} for a description of the steps + * involved in handling an exchange. Container invokes this method + * when it receives an incoming request. + * + * @param exchange the exchange containing the request from the + * client and used to send the response + * @throws IOException when an I/O error happens during request + * handling + */ + public abstract void handle(HttpExchange exchange) throws IOException; +} diff --git a/fine-third-jdk11/src/javax/xml/ws/spi/http/package-info.java b/fine-third-jdk11/src/javax/xml/ws/spi/http/package-info.java new file mode 100644 index 000000000..d67eecd52 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/spi/http/package-info.java @@ -0,0 +1,110 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2009-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +/** + Provides HTTP SPI that is used for portable deployment of JAX-WS + web services in containers(for e.g. servlet containers). This SPI + is not for end developers but provides a way for the container + developers to deploy JAX-WS services portably. + +

+ The portable deployment is done as below: +

    +
  1. Container creates {@link javax.xml.ws.Endpoint} objects for an + application. The necessary information to create Endpoint objects + may be got from web service deployment descriptor files.
  2. +
  3. Container needs to create {@link javax.xml.ws.spi.http.HttpContext} + objects for the deployment. For example, a HttpContext could be + created using servlet configuration(for e.g url-pattern) for the + web service in servlet container case.
  4. +
  5. Then publishes all the endpoints using + {@link javax.xml.ws.Endpoint#publish(HttpContext)}. During publish(), + JAX-WS runtime registers a {@link javax.xml.ws.spi.http.HttpHandler} + callback to handle incoming requests or + {@link javax.xml.ws.spi.http.HttpExchange} objects. The HttpExchange + object encapsulates a HTTP request and a response. +
+ +
{@literal
+  Container                               JAX-WS runtime
+  ---------                               --------------
+  1. Creates Invoker1, ... InvokerN
+  2. Provider.createEndpoint(...)     --> 3. creates Endpoint1
+     configures Endpoint1
+     ...
+  4. Provider.createEndpoint(...)     --> 5. creates EndpointN
+     configures EndpointN
+  6. Creates ApplicationContext
+  7. creates HttpContext1, ... HttpContextN
+  8. Endpoint1.publish(HttpContext1)  --> 9. creates HttpHandler1
+                                          HttpContext1.setHandler(HttpHandler1)
+     ...
+ 10. EndpointN.publish(HttpContextN)  --> 11. creates HttpHandlerN
+                                         HttpContextN.setHandler(HttpHandlerN)
+
+  }
+ + The request processing is done as below(for every request): +
{@literal
+  Container                               JAX-WS runtime
+  ---------                               --------------
+  1. Creates a HttpExchange
+  2. Gets handler from HttpContext
+  3. HttpHandler.handle(HttpExchange) --> 4. reads request from HttpExchange
+                                      <-- 5. Calls Invoker
+  6. Invokes the actual instance
+                                          7. Writes the response to HttpExchange
+  }
+ +

+ The portable undeployment is done as below: +

+  Container
+  ---------
+  1. {@literal @}preDestroy on instances
+  2. Endpoint1.stop()
+  ...
+  3. EndpointN.stop()
+  
+ + @author Jitendra Kotamraju + @since 1.7, JAX-WS 2.2 + */ +package javax.xml.ws.spi.http; diff --git a/fine-third-jdk11/src/javax/xml/ws/spi/package-info.java b/fine-third-jdk11/src/javax/xml/ws/spi/package-info.java new file mode 100644 index 000000000..fc9fe13ba --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/spi/package-info.java @@ -0,0 +1,44 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +/** + * This package defines SPIs for JAX-WS. + */ +package javax.xml.ws.spi; diff --git a/fine-third-jdk11/src/javax/xml/ws/wsaddressing/W3CEndpointReference.java b/fine-third-jdk11/src/javax/xml/ws/wsaddressing/W3CEndpointReference.java new file mode 100644 index 000000000..74c0a98e7 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/wsaddressing/W3CEndpointReference.java @@ -0,0 +1,188 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.wsaddressing; + + +import org.w3c.dom.Element; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.XmlValue; +import javax.xml.namespace.QName; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.ws.EndpointReference; +import javax.xml.ws.WebServiceException; +import java.util.List; +import java.util.Map; + + +/** + * This class represents a W3C Addressing EndpointReferece which is + * a remote reference to a web service endpoint that supports the + * W3C WS-Addressing 1.0 - Core Recommendation. + *

+ * Developers should use this class in their SEIs if they want to + * pass/return endpoint references that represent the W3C WS-Addressing + * recommendation. + *

+ * JAXB will use the JAXB annotations and bind this class to XML infoset + * that is consistent with that defined by WS-Addressing. See + * + * WS-Addressing + * for more information on WS-Addressing EndpointReferences. + * + * @since 1.6, JAX-WS 2.1 + */ + +// XmlRootElement allows this class to be marshalled on its own +@XmlRootElement(name="EndpointReference",namespace=W3CEndpointReference.NS) +@XmlType(name="EndpointReferenceType",namespace=W3CEndpointReference.NS) +public final class W3CEndpointReference extends EndpointReference { + + private final JAXBContext w3cjc = getW3CJaxbContext(); + + // should be changed to package private, keeping original modifier to keep backwards compatibility + + /** + * Addressing namespace. + */ + protected static final String NS = "http://www.w3.org/2005/08/addressing"; + + // default constructor forbidden ... + // should be private, keeping original modifier to keep backwards compatibility + + /** + * Default constructor. + */ + protected W3CEndpointReference() { + } + + /** + * Creates an EPR from infoset representation + * + * @param source A source object containing valid XmlInfoset + * instance consistent with the W3C WS-Addressing Core + * recommendation. + * + * @throws WebServiceException + * If the source does NOT contain a valid W3C WS-Addressing + * EndpointReference. + * @throws NullPointerException + * If the {@code null} {@code source} value is given + */ + public W3CEndpointReference(Source source) { + try { + W3CEndpointReference epr = w3cjc.createUnmarshaller().unmarshal(source,W3CEndpointReference.class).getValue(); + this.address = epr.address; + this.metadata = epr.metadata; + this.referenceParameters = epr.referenceParameters; + this.elements = epr.elements; + this.attributes = epr.attributes; + } catch (JAXBException e) { + throw new WebServiceException("Error unmarshalling W3CEndpointReference " ,e); + } catch (ClassCastException e) { + throw new WebServiceException("Source did not contain W3CEndpointReference", e); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void writeTo(Result result){ + try { + Marshaller marshaller = w3cjc.createMarshaller(); + marshaller.marshal(this, result); + } catch (JAXBException e) { + throw new WebServiceException("Error marshalling W3CEndpointReference. ", e); + } + } + + private static JAXBContext getW3CJaxbContext() { + try { + return JAXBContext.newInstance(W3CEndpointReference.class); + } catch (JAXBException e) { + throw new WebServiceException("Error creating JAXBContext for W3CEndpointReference. ", e); + } + } + + // private but necessary properties for databinding + @XmlElement(name="Address",namespace=NS) + private Address address; + @XmlElement(name="ReferenceParameters",namespace=NS) + private Elements referenceParameters; + @XmlElement(name="Metadata",namespace=NS) + private Elements metadata; + // attributes and elements are not private for performance reasons + // (JAXB can bypass reflection) + @XmlAnyAttribute + Map attributes; + @XmlAnyElement + List elements; + + + @XmlType(name="address", namespace=W3CEndpointReference.NS) + private static class Address { + protected Address() {} + @XmlValue + String uri; + @XmlAnyAttribute + Map attributes; + } + + + @XmlType(name="elements", namespace=W3CEndpointReference.NS) + private static class Elements { + protected Elements() {} + @XmlAnyElement + List elements; + @XmlAnyAttribute + Map attributes; + } + +} diff --git a/fine-third-jdk11/src/javax/xml/ws/wsaddressing/W3CEndpointReferenceBuilder.java b/fine-third-jdk11/src/javax/xml/ws/wsaddressing/W3CEndpointReferenceBuilder.java new file mode 100644 index 000000000..2d4309a01 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/wsaddressing/W3CEndpointReferenceBuilder.java @@ -0,0 +1,373 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package javax.xml.ws.wsaddressing; + + +import org.w3c.dom.Element; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.HashMap; +import javax.xml.namespace.QName; +import javax.xml.ws.WebServiceException; +import javax.xml.ws.spi.Provider; + + +/** + * This class is used to build {@code W3CEndpointReference} + * instances. The intended use of this clsss is for + * an application component, for example a factory component, + * to create an {@code W3CEndpointReference} for a + * web service endpoint published by the same + * Java EE application. It can also be used to create + * {@code W3CEndpointReferences} for an Java SE based + * endpoint by providing the {@code address} property. + *

+ * When creating a {@code W3CEndpointReference} for an + * endpoint that is not published by the same Java EE application, + * the {@code address} property MUST be specified. + *

+ * When creating a {@code W3CEndpointReference} for an endpoint + * published by the same Java EE application, the {@code address} + * property MAY be {@code null} but then the {@code serviceName} + * and {@code endpointName} MUST specify an endpoint published by + * the same Java EE application. + *

+ * When the {@code wsdlDocumentLocation} is specified it MUST refer + * to a valid WSDL document and the {@code serviceName} and + * {@code endpointName} (if specified) MUST match a service and port + * in the WSDL document. + * + * @since 1.6, JAX-WS 2.1 + */ +public final class W3CEndpointReferenceBuilder { + /** + * Creates a new {@code W3CEndpointReferenceBuilder} instance. + */ + public W3CEndpointReferenceBuilder() { + referenceParameters = new ArrayList(); + metadata = new ArrayList(); + attributes = new HashMap(); + elements = new ArrayList(); + } + + /** + * Sets the {@code address} to the + * {@code W3CEndpointReference} instance's + * {@code wsa:Address}. + *

+ * The {@code address} MUST be set to a non-{@code null} + * value when building a {@code W3CEndpointReference} for a + * web service endpoint that is not published by the same + * Java EE application or when running on Java SE. + * + * @param address The address of the endpoint to be targeted + * by the returned {@code W3CEndpointReference}. + * + * @return A {@code W3CEndpointReferenceBuilder} instance with + * the {@code address} set to the {@code wsa:Address}. + */ + public W3CEndpointReferenceBuilder address(String address) { + this.address = address; + return this; + } + + /** + * Sets the {@code interfaceName} as the + * {@code wsam:InterfaceName} element in the + * {@code wsa:Metadata} element. + * + * See + * 2.1 Referencing WSDL Metadata from an EPR for more details. + * + * @param interfaceName The port type name of the endpoint to be targeted + * by the returned {@code W3CEndpointReference}. + * + * @return A {@code W3CEndpointReferenceBuilder} instance with + * the {@code interfaceName} as {@code wsam:InterfaceName} + * element added to the {@code wsa:Metadata} element + * @since 1.7 + */ + public W3CEndpointReferenceBuilder interfaceName(QName interfaceName) { + this.interfaceName = interfaceName; + return this; + } + + /** + * Sets the {@code serviceName} as the + * {@code wsam:ServiceName} element in the + * {@code wsa:Metadata} element. + * + * See + * 2.1 Referencing WSDL Metadata from an EPR for more details. + * + * @param serviceName The service name of the endpoint to be targeted + * by the returned {@code W3CEndpointReference}. This property + * may also be used with the {@code endpointName} (portName) + * property to lookup the {@code address} of a web service + * endpoint that is published by the same Java EE application. + * + * @return A {@code W3CEndpointReferenceBuilder} instance with + * the {@code serviceName} as {@code wsam:ServiceName} + * element added to the {@code wsa:Metadata} element + * + */ + public W3CEndpointReferenceBuilder serviceName(QName serviceName) { + this.serviceName = serviceName; + return this; + } + + /** + * Sets the {@code endpointName} as + * {@code wsam:ServiceName/@EndpointName} in the + * {@code wsa:Metadata} element. This method can only be called + * after the {@link #serviceName(QName)} method has been called. + *

+ * See + * 2.1 Referencing WSDL Metadata from an EPR for more details. + * + * @param endpointName The name of the endpoint to be targeted + * by the returned {@code W3CEndpointReference}. The + * {@code endpointName} (portName) property may also be + * used with the {@code serviceName} property to lookup + * the {@code address} of a web service + * endpoint published by the same Java EE application. + * + * @return A {@code W3CEndpointReferenceBuilder} instance with + * the {@code endpointName} as + * {@code wsam:ServiceName/@EndpointName} in the + * {@code wsa:Metadata} element. + * + * @throws java.lang.IllegalStateException if the {@code serviceName} + * has not been set + * + * @throws java.lang.IllegalArgumentException if the {@code endpointName}'s + * Namespace URI doesn't match {@code serviceName}'s Namespace URI + * + */ + public W3CEndpointReferenceBuilder endpointName(QName endpointName) { + if (serviceName == null) { + throw new IllegalStateException("The W3CEndpointReferenceBuilder's serviceName must be set before setting the endpointName: "+endpointName); + } + + this.endpointName = endpointName; + return this; + } + + /** + * Sets the {@code wsdlDocumentLocation} that will be referenced + * as {@code wsa:Metadata/@wsdli:wsdlLocation}. The namespace name + * for the wsdli:wsdlLocation's value can be taken from the WSDL itself. + * + *

+ * See + * 2.1 Referencing WSDL Metadata from an EPR for more details. + * + * @param wsdlDocumentLocation The location of the WSDL document to + * be referenced in the {@code wsa:Metadata} of the + * {@code W3CEndpointReference}. + * @return A {@code W3CEndpointReferenceBuilder} instance with + * the {@code wsdlDocumentLocation} that is to be referenced. + */ + public W3CEndpointReferenceBuilder wsdlDocumentLocation(String wsdlDocumentLocation) { + this.wsdlDocumentLocation = wsdlDocumentLocation; + return this; + } + + /** + * Adds the {@code referenceParameter} to the + * {@code W3CEndpointReference} instance + * {@code wsa:ReferenceParameters} element. + * + * @param referenceParameter The element to be added to the + * {@code wsa:ReferenceParameters} element. + * + * @return A {@code W3CEndpointReferenceBuilder} instance with + * the {@code referenceParameter} added to the + * {@code wsa:ReferenceParameters} element. + * + * @throws java.lang.IllegalArgumentException if {@code referenceParameter} + * is {@code null}. + */ + public W3CEndpointReferenceBuilder referenceParameter(Element referenceParameter) { + if (referenceParameter == null) + throw new java.lang.IllegalArgumentException("The referenceParameter cannot be null."); + referenceParameters.add(referenceParameter); + return this; + } + + /** + * Adds the {@code metadataElement} to the + * {@code W3CEndpointReference} instance's + * {@code wsa:Metadata} element. + * + * @param metadataElement The element to be added to the + * {@code wsa:Metadata} element. + * + * @return A {@code W3CEndpointReferenceBuilder} instance with + * the {@code metadataElement} added to the + * {@code wsa:Metadata} element. + * + * @throws java.lang.IllegalArgumentException if {@code metadataElement} + * is {@code null}. + */ + public W3CEndpointReferenceBuilder metadata(Element metadataElement) { + if (metadataElement == null) + throw new java.lang.IllegalArgumentException("The metadataElement cannot be null."); + metadata.add(metadataElement); + return this; + } + + /** + * Adds an extension element to the + * {@code W3CEndpointReference} instance's + * {@code wsa:EndpointReference} element. + * + * @param element The extension element to be added to the + * {@code W3CEndpointReference} + * @return A {@code W3CEndpointReferenceBuilder} instance with + * the extension {@code element} added to the + * {@code W3CEndpointReference} instance. + * @throws java.lang.IllegalArgumentException if {@code element} + * is {@code null}. + * + * @since 1.7, JAX-WS 2.2 + */ + public W3CEndpointReferenceBuilder element(Element element) { + if (element == null) { + throw new IllegalArgumentException("The extension element cannot be null."); + } + elements.add(element); + return this; + } + + /** + * Adds an extension attribute to the + * {@code W3CEndpointReference} instance's + * {@code wsa:EndpointReference} element. + * + * @param name The name of the extension attribute to be added to the + * {@code W3CEndpointReference} + * @param value extension attribute value + * @return A {@code W3CEndpointReferenceBuilder} instance with + * the extension attribute added to the {@code W3CEndpointReference} + * instance. + * @throws java.lang.IllegalArgumentException if {@code name} + * or {@code value} is {@code null}. + * + * @since 1.7, JAX-WS 2.2 + */ + public W3CEndpointReferenceBuilder attribute(QName name, String value) { + if (name == null || value == null) { + throw new IllegalArgumentException("The extension attribute name or value cannot be null."); + } + attributes.put(name, value); + return this; + } + + /** + * Builds a {@code W3CEndpointReference} from the accumulated + * properties set on this {@code W3CEndpointReferenceBuilder} + * instance. + *

+ * This method can be used to create a {@code W3CEndpointReference} + * for any endpoint by specifying the {@code address} property along + * with any other desired properties. This method + * can also be used to create a {@code W3CEndpointReference} for + * an endpoint that is published by the same Java EE application. + * This method can automatically determine the {@code address} of + * an endpoint published by the same Java EE application that is identified by the + * {@code serviceName} and + * {@code endpointName} properties. If the {@code address} is + * {@code null} and the {@code serviceName} and + * {@code endpointName} + * do not identify an endpoint published by the same Java EE application, a + * {@code java.lang.IllegalStateException} MUST be thrown. + * + * + * @return {@code W3CEndpointReference} from the accumulated + * properties set on this {@code W3CEndpointReferenceBuilder} + * instance. This method never returns {@code null}. + * + * @throws IllegalStateException + *

    + *
  • If the {@code address}, {@code serviceName} and + * {@code endpointName} are all {@code null}. + *
  • If the {@code serviceName} service is {@code null} and the + * {@code endpointName} is NOT {@code null}. + *
  • If the {@code address} property is {@code null} and + * the {@code serviceName} and {@code endpointName} do not + * specify a valid endpoint published by the same Java EE + * application. + *
  • If the {@code serviceName} is NOT {@code null} + * and is not present in the specified WSDL. + *
  • If the {@code endpointName} port is not {@code null} and it + * is not present in {@code serviceName} service in the WSDL. + *
  • If the {@code wsdlDocumentLocation} is NOT {@code null} + * and does not represent a valid WSDL. + *
+ * @throws WebServiceException If an error occurs while creating the + * {@code W3CEndpointReference}. + * + */ + public W3CEndpointReference build() { + if (elements.isEmpty() && attributes.isEmpty() && interfaceName == null) { + // 2.1 API + return Provider.provider().createW3CEndpointReference(address, + serviceName, endpointName, metadata, wsdlDocumentLocation, + referenceParameters); + } + return Provider.provider().createW3CEndpointReference(address, + interfaceName, serviceName, endpointName, metadata, wsdlDocumentLocation, + referenceParameters, elements, attributes); + } + + private String address; + private List referenceParameters; + private List metadata; + private QName interfaceName; + private QName serviceName; + private QName endpointName; + private String wsdlDocumentLocation; + private Map attributes; + private List elements; +} diff --git a/fine-third-jdk11/src/javax/xml/ws/wsaddressing/package-info.java b/fine-third-jdk11/src/javax/xml/ws/wsaddressing/package-info.java new file mode 100644 index 000000000..30866eb90 --- /dev/null +++ b/fine-third-jdk11/src/javax/xml/ws/wsaddressing/package-info.java @@ -0,0 +1,46 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2005-2017 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://oss.oracle.com/licenses/CDDL+GPL-1.1 + * or LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +/** + * This package defines APIs related to WS-Addressing. + */ +@javax.xml.bind.annotation.XmlSchema(namespace=W3CEndpointReference.NS, + location="http://www.w3.org/2006/03/addressing/ws-addr.xsd") +package javax.xml.ws.wsaddressing;