-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jaxb-package): possibility to choose a JAXBContext instantiation…
… using package mode (#2005) Co-authored-by: jernat <[email protected]> Co-authored-by: Marvin Froeder <[email protected]>
- Loading branch information
1 parent
02f6eaa
commit 042a587
Showing
11 changed files
with
357 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright 2012-2023 The Feign 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 feign.jaxb; | ||
|
||
/** Encapsulate data used to build the cache key of JAXBContext. */ | ||
interface JAXBContextCacheKey {} |
39 changes: 39 additions & 0 deletions
39
jaxb/src/main/java/feign/jaxb/JAXBContextClassCacheKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2012-2023 The Feign 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 feign.jaxb; | ||
|
||
import java.util.Objects; | ||
|
||
/** Encapsulate data used to build the cache key of JAXBContext when created using class mode. */ | ||
final class JAXBContextClassCacheKey implements JAXBContextCacheKey { | ||
|
||
private final Class<?> clazz; | ||
|
||
JAXBContextClassCacheKey(Class<?> clazz) { | ||
this.clazz = clazz; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
JAXBContextClassCacheKey that = (JAXBContextClassCacheKey) o; | ||
return clazz.equals(that.clazz); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(clazz); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
jaxb/src/main/java/feign/jaxb/JAXBContextInstantationMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2012-2023 The Feign 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 feign.jaxb; | ||
|
||
import javax.xml.bind.JAXBContext; | ||
import javax.xml.bind.JAXBException; | ||
|
||
/** Provides differents ways to instantiate a JAXB Context. */ | ||
public enum JAXBContextInstantationMode { | ||
CLASS { | ||
@Override | ||
JAXBContextCacheKey getJAXBContextCacheKey(Class<?> clazz) { | ||
return new JAXBContextClassCacheKey(clazz); | ||
} | ||
|
||
@Override | ||
JAXBContext getJAXBContext(Class<?> clazz) throws JAXBException { | ||
return JAXBContext.newInstance(clazz); | ||
} | ||
}, | ||
|
||
PACKAGE { | ||
@Override | ||
JAXBContextCacheKey getJAXBContextCacheKey(Class<?> clazz) { | ||
return new JAXBContextPackageCacheKey(clazz.getPackage().getName(), clazz.getClassLoader()); | ||
} | ||
|
||
@Override | ||
JAXBContext getJAXBContext(Class<?> clazz) throws JAXBException { | ||
return JAXBContext.newInstance(clazz.getPackage().getName(), clazz.getClassLoader()); | ||
} | ||
}; | ||
|
||
abstract JAXBContextCacheKey getJAXBContextCacheKey(Class<?> clazz); | ||
|
||
abstract JAXBContext getJAXBContext(Class<?> clazz) throws JAXBException; | ||
} |
42 changes: 42 additions & 0 deletions
42
jaxb/src/main/java/feign/jaxb/JAXBContextPackageCacheKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2012-2023 The Feign 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 feign.jaxb; | ||
|
||
import java.util.Objects; | ||
|
||
/** Encapsulate data used to build the cache key of JAXBContext when created using package mode. */ | ||
final class JAXBContextPackageCacheKey implements JAXBContextCacheKey { | ||
|
||
private final String packageName; | ||
|
||
private final ClassLoader classLoader; | ||
|
||
JAXBContextPackageCacheKey(String packageName, ClassLoader classLoader) { | ||
this.packageName = packageName; | ||
this.classLoader = classLoader; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
JAXBContextPackageCacheKey that = (JAXBContextPackageCacheKey) o; | ||
return packageName.equals(that.packageName) && classLoader.equals(that.classLoader); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(packageName, classLoader); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
jaxb/src/test/java/feign/jaxb/mock/anotherpackage/MockedJAXBObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright 2012-2023 The Feign 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 feign.jaxb.mock.anotherpackage; | ||
|
||
import javax.xml.bind.annotation.XmlRootElement; | ||
|
||
@XmlRootElement(name = "anothertest") | ||
public class MockedJAXBObject {} |
24 changes: 24 additions & 0 deletions
24
jaxb/src/test/java/feign/jaxb/mock/anotherpackage/ObjectFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2012-2023 The Feign 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 feign.jaxb.mock.anotherpackage; | ||
|
||
import javax.xml.bind.annotation.XmlRegistry; | ||
|
||
@XmlRegistry | ||
public class ObjectFactory { | ||
|
||
public MockedJAXBObject createMockedJAXBObject() { | ||
return new MockedJAXBObject(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
jaxb/src/test/java/feign/jaxb/mock/onepackage/AnotherMockedJAXBObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright 2012-2023 The Feign 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 feign.jaxb.mock.onepackage; | ||
|
||
import javax.xml.bind.annotation.XmlRootElement; | ||
|
||
@XmlRootElement | ||
public class AnotherMockedJAXBObject {} |
Oops, something went wrong.