extracts a DeserializerStringCache from the DeserializationContext

@param context
an existing DeserializationContext containing a
DeserializerStringCache
@return a wrapped ObjectReader with the string cache attribute
19855
public static DeserializerStringCache from(DeserializationContext context) {
        return withCache(context, cache -> {
            if (cache == null) {
                cache = new DeserializerStringCache(new HashMap<CharBuffer, String>(),
                        new HashMap<CharBuffer, String>());
            }
            return cache;
        });
    }
873924
@Override
    public ISerializer<?> get(Class<?> clazz) {
        ISerializer<?> contextSerializer = super.get(clazz);

        if (contextSerializer != null) {
            return contextSerializer;
        }

        for (ISerializer<?> item : this) {
            if (item.getType().isAssignableFrom(clazz)) {
                return item;
            }
        }

        return null;
    }
1004384
private JSONObject getARP(final Context context) {
        try {
            final String nameSpaceKey = getNamespaceARPKey();
            if (nameSpaceKey == null) return null;

            final SharedPreferences prefs = StorageHelper.getPreferences(context, nameSpaceKey);
            final Map<String, ?> all = prefs.getAll();
            final Iterator<? extends Map.Entry<String, ?>> iter = all.entrySet().iterator();

            while (iter.hasNext()) {
                final Map.Entry<String, ?> kv = iter.next();
                final Object o = kv.getValue();
                if (o instanceof Number && ((Number) o).intValue() == -1) {
                    iter.remove();
                }
            }
            final JSONObject ret = new JSONObject(all);
            getConfigLogger().verbose(getAccountId(), "Fetched ARP for namespace key: " + nameSpaceKey + " values: " + all.toString());
            return ret;
        } catch (Throwable t) {
            getConfigLogger().verbose(getAccountId(), "Failed to construct ARP object", t);
            return null;
        }
    }
425036
public static WebApp get(ServletContext context) {
        Object o = context.getAttribute(WebApp.class.getName());
        if(o==null) {
            synchronized (WebApp.class) {
                o = context.getAttribute(WebApp.class.getName());
                if(o==null) {
                    o = new WebApp(context);
                    context.setAttribute(WebApp.class.getName(),o);
                }
            }
        }
        return (WebApp)o;
    }
1110585
public static ClassReader instance(Context context) {
        ClassReader instance = context.get(classReaderKey);
        if (instance == null)
            instance = new ClassReader(context, true);
        return instance;
    }
49366
@FFDCIgnore({ClassNotFoundException.class })
	public static final Serializable deserialize(byte[] array, String cacheName) throws IOException, ClassNotFoundException {

		if (array == null) {
			return null;
		}
		
		Serializable object = null;

		try {
			if (null != _instance) {
				SerializationService ss = _instance.serializationServiceRef.getService();
				if (null != ss) {
					try {
						ClassLoader tccl = getContextClassLoader();
						ObjectInputStream objectInputStream = ss.createObjectInputStream(new ByteArrayInputStream(array), tccl);
						object = (Serializable) objectInputStream.readObject();
					}catch (ClassNotFoundException e){
						if (null != cacheName){
							Library sharedLib = getSharedLibrary(cacheName);
							if (null != sharedLib){
								ObjectInputStream objectInputStream = new DeserializationObjectInputStream(new ByteArrayInputStream(array), sharedLib.getClassLoader());
								object = (Serializable) objectInputStream.readObject();
							}
						}
					}
				}
			}

			if (null == object) {
				object = deserializeUsingTCCL(array, 0, array.length, getContextClassLoader());
			}
		} catch (ClassNotFoundException e) {
			try {
				object = deserialize(array, 0, array.length);
			} catch (ClassNotFoundException e1) {
				throw e1;
			}
		}
		return object;
	}
753761
public static MemoryCache createMemoryCache(Context context, int memoryCacheSize) {
		if (memoryCacheSize == 0) {
			ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
			int memoryClass = am.getMemoryClass();
			if (hasHoneycomb() && isLargeHeap(context)) {
				memoryClass = getLargeMemoryClass(am);
			}
			memoryCacheSize = 1024 * 1024 * memoryClass / 8;
		}
		return new LruMemoryCache(memoryCacheSize);
	}
138637
public <T> T deser(Object obj, InputStream in) throws IOException {
		Map<Class, Deserializer> deserializers = cachedDeserializers.get();
		Deserializer deSer = deserializers.get(obj.getClass());
		if(deSer == null) {
			deSer = serialization.getDeserializer(obj.getClass());
			deserializers.put(obj.getClass(), deSer);
		}
		deSer.open(in);
		obj = deSer.deserialize(obj);
		deSer.close();
		return (T) obj;
	}
83466
private GenericRecord deserialize(Event event, GenericRecord reuse)
      throws EventDeliveryException {
    decoder = DecoderFactory.get().binaryDecoder(event.getBody(), decoder);
    // no checked exception is thrown in the CacheLoader
    DatumReader<GenericRecord> reader = readers.getUnchecked(schema(event));
    try {
      return reader.read(reuse, decoder);
    } catch (IOException ex) {
      throw new EventDeliveryException("Cannot deserialize event", ex);
    }
  }
646095
public static void clear(ObjectReader reader, final CacheScope scope) {
        withCache(reader, cache -> {
            if (scope == CacheScope.GLOBAL_SCOPE) {
                if (debugLogEnabled)
                    logger.debug("clearing global-level cache with size {}", cache.globalCache.size());
                cache.globalCache.clear();
            }
            if (debugLogEnabled)
                logger.debug("clearing app-level serialization cache with size {}", cache.applicationCache.size());
            cache.applicationCache.clear();
            return null;
        });
    }
1076376
public void parseContext(Object contextLike) throws JsonLdError {
        Context context;
        if (api != null) {
            context = new Context(api.opts);
        } else {
            context = new Context();
        }
        // Context will do our recursive parsing and initial IRI resolution
        context = context.parse(contextLike);
        // And then leak to us the potential 'prefixes'
        final Map<String, String> prefixes = context.getPrefixes(true);

        for (final String key : prefixes.keySet()) {
            final String val = prefixes.get(key);
            if ("@vocab".equals(key)) {
                if (val == null || isString(val)) {
                    setNamespace("", val);
                } else {
                }
            } else if (!isKeyword(key)) {
                setNamespace(key, val);
                // TODO: should we make sure val is a valid URI prefix (i.e. it
                // ends with /# or ?)
                // or is it ok that full URIs for terms are used?
            }
        }
    }
1007339
public TemplateModel parseStandalone(
            final ITemplateContext context, final String template, final Set<String> templateSelectors,
            final TemplateMode templateMode, final boolean useCache, final boolean failIfNotExists) {

        Validate.notNull(context, "Context cannot be null");
        Validate.notNull(template, "Template cannot be null");
        // templateSelectors CAN be null if we are going to render the entire template
        // templateMode CAN be null if we are going to use the mode specified by the template resolver
        // templateResolutionAttributes CAN be null


        final String ownerTemplate = context.getTemplateData().getTemplate();
        final Map<String,Object> templateResolutionAttributes = context.getTemplateResolutionAttributes();

        final Set<String> cleanTemplateSelectors;
        if (templateSelectors != null && !templateSelectors.isEmpty()) {
            Validate.containsNoEmpties(
                    templateSelectors, "If specified, the Template Selector set cannot contain any nulls or empties");
            if (templateSelectors.size() == 1) {
                cleanTemplateSelectors = Collections.singleton(templateSelectors.iterator().next());
            } else {
                // We will be using a TreeSet because we want the selectors to be ORDERED, so that comparison at the
                // equals(...) method works alright
                cleanTemplateSelectors = Collections.unmodifiableSet(new TreeSet<String>(templateSelectors));
            }
        } else {
            cleanTemplateSelectors = null;
        }


        final TemplateCacheKey cacheKey =
                useCache?
                        new TemplateCacheKey(
                                ownerTemplate,
                                template, cleanTemplateSelectors,
                                0, 0,
                                templateMode,
                                templateResolutionAttributes)
                        : null;

        /*
         * First look at the cache - it might be already cached
         */
        if (useCache && this.templateCache != null) {
            final TemplateModel cached =  this.templateCache.get(cacheKey);
            if (cached != null) {
                /*
                 * Just at the end, and importantly AFTER CACHING, check if we need to apply any pre-processors
                 * to this model before returning and letting the engine insert the model in any way it needs.
                 */
                return applyPreProcessorsIfNeeded(context, cached);
            }
        }


        /*
         * Resolve the template
         */
        final TemplateResolution templateResolution =
                resolveTemplate(this.configuration, ownerTemplate, template, templateResolutionAttributes, failIfNotExists);


        /*
         * Once the template has been resolved (or tried to), and depending on the value of our 'failIfNotExists'
         * flag, we will check two conditions in which we will be returning null:
         *
         *    1. No template resolver has been able to resolve the template (this can happen if resolvers are
         *       configured with the 'checkExistence' flag to true).
         *    2. If the template was resolved, its existence should be checked in order to avoid exceptions during
         *       the reading phase.
         *
         * NOTE we will not cache this "null" result because the fact that a template is cacheable or not is
         * determined by template resolvers. And in this case there is no template resolver being applied
         * (actually, we are here because no resolver had success).
         */
        if (!failIfNotExists) {

            if (templateResolution == null) {
                // No resolver could resolve this
                return null;
            }

            if (!templateResolution.isTemplateResourceExistenceVerified()) {
                final ITemplateResource resource = templateResolution.getTemplateResource();
                if (resource == null || !resource.exists()) {
                    // Calling resource.exists() each time is not great, but think this only happens if the resource
                    // has not been cached (e.g. when it does not exist)
                    return null;
                }
            }

        }


        /*
         * Build the TemplateData object
         */
        final TemplateData templateData =
                buildTemplateData(templateResolution, template, cleanTemplateSelectors, templateMode, useCache);


        /*
         *  Create the Template Handler that will be in charge of building the TemplateModel
         */
        final ModelBuilderTemplateHandler builderHandler = new ModelBuilderTemplateHandler(this.configuration, templateData);


        /*
         * PROCESS THE TEMPLATE
         */
        final ITemplateParser parser = getParserForTemplateMode(templateData.getTemplateMode());
        parser.parseStandalone(
                this.configuration,
                ownerTemplate, template, cleanTemplateSelectors, templateData.getTemplateResource(),
                templateData.getTemplateMode(), templateResolution.getUseDecoupledLogic(), builderHandler);

        final TemplateModel templateModel = builderHandler.getModel();


        /*
         * Cache the template if it is cacheable
         */
        if (useCache && this.templateCache != null) {
            if (templateResolution.getValidity().isCacheable()) {
                this.templateCache.put(cacheKey, templateModel);
            }
        }


        /*
         * Last step: just at the end, and importantly AFTER CACHING, check if we need to apply any pre-processors
         * to this model before returning and letting the engine insert the model in any way it needs.
         */
        return applyPreProcessorsIfNeeded(context, templateModel);

    }
804734
private Properties extractIndexingProperties(OperationContext context, ModelNode operation, String cacheConfiguration) {
        Properties properties = new Properties();
        PathAddress cacheAddress = getCacheAddressFromOperation(operation);
        Resource cacheConfigResource = context.readResourceFromRoot(cacheAddress.subAddress(0, 2), true)
              .getChild(PathElement.pathElement(ModelKeys.CONFIGURATIONS, ModelKeys.CONFIGURATIONS_NAME))
              .getChild(PathElement.pathElement(getConfigurationKey(), cacheConfiguration));

        PathElement indexingPathElement = PathElement.pathElement(ModelKeys.INDEXING, ModelKeys.INDEXING_NAME);

        if (cacheConfigResource == null || !cacheConfigResource.hasChild(indexingPathElement)) {
            return properties;
        }

        Resource indexingResource = cacheConfigResource.getChild(indexingPathElement);
        if (indexingResource == null) return properties;

        ModelNode indexingModel = indexingResource.getModel();
        boolean hasProperties = indexingModel.hasDefined(ModelKeys.INDEXING_PROPERTIES);

        if (!hasProperties) return properties;

        ModelNode modelNode = indexingResource.getModel().get(ModelKeys.INDEXING_PROPERTIES);
        List<Property> modelProperties = modelNode.asPropertyList();
        modelProperties.forEach(p -> properties.put(p.getName(), p.getValue().asString()));
        return properties;
    }
95011
public static ObjectReader init(ObjectReader reader) {
        return reader.withAttribute(ATTR_STRING_CACHE, new DeserializerStringCache(
                new HashMap<CharBuffer, String>(2048), new LinkedHashMap<CharBuffer, String>(4096, 0.75f, true) {
                    @Override
                    protected boolean removeEldestEntry(Entry<CharBuffer, String> eldest) {
                        return size() > LRU_LIMIT;
                    }

                }));
    }
1129376
private static JAXBContext getContext(String[] contexts) throws Exception {
		List<String> ctx = Lists.asList(BASE_CONTEXT, contexts);
		return JAXBContext.newInstance(JOINER.join(ctx));
	}
1367682
public void get(Object rootVal,
                  MatchSpaceKey msg,
                  EvalCache cache,
                  Object contextValue,
                  SearchResults result)
    throws MatchingException,BadMessageFormatMatchingException
  {
    if (tc.isEntryEnabled())
	    tc.entry(this,cclass, "get", new Object[]{rootVal,msg,cache,result});

    if (result instanceof CacheingSearchResults)
      ((CacheingSearchResults) result).setMatcher(vacantChild);
    vacantChild.get(null, msg, cache, contextValue, result);

    if (tc.isEntryEnabled())
	    tc.exit(this,cclass, "get");
  }
959310
@JsonIgnore
    public PrincipalAttributesRepositoryCache getCacheInstanceFromApplicationContext() {
        val ctx = ApplicationContextProvider.getApplicationContext();
        return ctx.getBean("principalAttributesRepositoryCache", PrincipalAttributesRepositoryCache.class);
    }