Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.cxf.jaxb;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.transform.dom.DOMSource;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.common.util.CacheMap;
import org.apache.cxf.common.util.CachedClass;
import org.apache.cxf.common.util.StringUtils;
/**
*
*/
public final class JAXBContextCache {
public static final class CachedContextAndSchemas {
private WeakReference context;
private WeakReference>> classes;
private Collection schemas;
CachedContextAndSchemas(JAXBContext context, Set> classes) {
this.context = new WeakReference(context);
this.classes = new WeakReference>>(classes);
}
public JAXBContext getContext() {
return context.get();
}
public Set> getClasses() {
return classes.get();
}
public void setClasses(Set> cls) {
classes = new WeakReference>>(cls);
}
public Collection getSchemas() {
return schemas;
}
public void setSchemas(Collection schemas) {
this.schemas = schemas;
}
}
private static final Map>, CachedContextAndSchemas> JAXBCONTEXT_CACHE
= new CacheMap>, CachedContextAndSchemas>();
private static final Map OBJECT_FACTORY_CACHE
= new CacheMap();
private JAXBContextCache() {
//utility class
}
/**
* Clear any caches to make sure new contexts are created
*/
public static void clearCaches() {
synchronized (JAXBCONTEXT_CACHE) {
JAXBCONTEXT_CACHE.clear();
}
synchronized (OBJECT_FACTORY_CACHE) {
OBJECT_FACTORY_CACHE.clear();
}
}
public static void scanPackages(Set> classes) {
JAXBUtils.scanPackages(classes, OBJECT_FACTORY_CACHE);
}
public static CachedContextAndSchemas getCachedContextAndSchemas(Class> cls) throws JAXBException {
Set> classes = new HashSet>();
classes.add(cls);
scanPackages(classes);
return JAXBContextCache.getCachedContextAndSchemas(classes, null, null, null, false);
}
public static CachedContextAndSchemas getCachedContextAndSchemas(String pkg,
Map props,
ClassLoader loader)
throws JAXBException {
Set> classes = new HashSet>();
addPackage(classes, pkg, loader);
return getCachedContextAndSchemas(classes, null, props, null, true);
}
public static CachedContextAndSchemas getCachedContextAndSchemas(final Set> classes,
String defaultNs,
Map props,
Collection