org.apache.myfaces.cdi.util.AbstractContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of myfaces-impl Show documentation
Show all versions of myfaces-impl Show documentation
The private implementation classes of the Apache MyFaces Core JSF-2.3-next Implementation
/*
* 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.myfaces.cdi.util;
import javax.enterprise.context.ContextNotActiveException;
import javax.enterprise.context.spi.Context;
import javax.enterprise.context.spi.Contextual;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.PassivationCapable;
import java.util.Map;
/**
* A skeleton containing the most important parts of a custom CDI Context.
* An implementing Context needs to implement the missing methods from the
* {@link Context} interface and {@link #getContextualStorage(boolean)}.
*
* NOTE: Taken from Apache DeltaSpike
*/
public abstract class AbstractContext implements Context
{
/**
* Whether the Context is for a passivating scope.
*/
private boolean passivatingScope;
protected AbstractContext(BeanManager beanManager)
{
passivatingScope = beanManager.isPassivatingScope(getScope());
}
/**
* An implementation has to return the underlying storage which
* contains the items held in the Context.
* @param createIfNotExist whether a ContextualStorage shall get created if it doesn't yet exist.
* @return the underlying storage
*/
protected abstract ContextualStorage getContextualStorage(boolean createIfNotExist);
/**
* @return whether the served scope is a passivating scope
*/
public boolean isPassivatingScope()
{
return passivatingScope;
}
@Override
public T get(Contextual bean)
{
checkActive();
ContextualStorage storage = getContextualStorage(false);
if (storage == null)
{
return null;
}
Map