Browse Source
Co-authored-by: jernat <jernat.morbal@gmail.com> Co-authored-by: Marvin Froeder <velo@users.noreply.github.com>pull/2010/head
Jeremy Balan
2 years ago
committed by
GitHub
11 changed files with 369 additions and 15 deletions
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
/* |
||||
* 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 { |
||||
} |
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
/* |
||||
* 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); |
||||
} |
||||
} |
@ -0,0 +1,51 @@
@@ -0,0 +1,51 @@
|
||||
/* |
||||
* 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; |
||||
} |
@ -0,0 +1,46 @@
@@ -0,0 +1,46 @@
|
||||
/* |
||||
* 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); |
||||
} |
||||
} |
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
/* |
||||
* 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 { |
||||
} |
@ -0,0 +1,24 @@
@@ -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(); |
||||
} |
||||
} |
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
/* |
||||
* 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 { |
||||
} |
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
/* |
||||
* 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(name = "test") |
||||
public class MockedJAXBObject { |
||||
} |
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
/* |
||||
* 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.XmlRegistry; |
||||
|
||||
@XmlRegistry |
||||
public class ObjectFactory { |
||||
|
||||
public MockedJAXBObject createMockedJAXBObject() { |
||||
return new MockedJAXBObject(); |
||||
} |
||||
|
||||
public AnotherMockedJAXBObject createAnotherMockedJAXBObject() { |
||||
return new AnotherMockedJAXBObject(); |
||||
} |
||||
} |
Loading…
Reference in new issue