
com.tacitknowledge.flip.context.ContextMap Maven / Gradle / Ivy
The newest version!
/* Copyright 2012 Tacit Knowledge
*
* 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 com.tacitknowledge.flip.context;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.tacitknowledge.flip.exceptions.UnknownContextPropertyException;
/**
* The map view of context used to access the context properties. This map does
* not holds any information retrieved from context provider. It acts as a view
* so it evaluates the value of the property exactly in that moment when it was
* asked using {@link #get(java.lang.Object) } method. Almost of the methods
* throws {@link UnsupportedOperationException}, exceptions of this rule are:
* {@link #isEmpty() } which always returns {@code "true"}, {@link #size()} which
* always returns {@code "1"} and {@link #containsKey(java.lang.Object)} which returns
* the real existence of the property.
*
* @author Serghei Soloviov
* @author Petric Coroli
*/
public class ContextMap implements Map
{
public static final String GLOBAL = "_all";
private final List contexts;
/**
* Constructs the map view based on the list of context descriptors. The
* order of the context descriptors is important because if two contexts
* has the same property will be returned the value of that which is first
* in this list.
*
* @param contexts the list of context descriptors.
*/
public ContextMap(final List contexts)
{
this.contexts = contexts;
}
@Override
public int size()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isEmpty()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean containsKey(final Object key)
{
try
{
getValue(String.valueOf(key));
return true;
}
catch (final MissingValueException ex)
{
return false;
}
}
@Override
public boolean containsValue(final Object value)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Object get(final Object key)
{
try
{
return getValue(String.valueOf(key));
}
catch (final MissingValueException ex)
{
throw new UnknownContextPropertyException(String.format("Cannot find property named [%s].", key));
}
}
@Override
public Object put(final String key, final Object value)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Object remove(final Object key)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void putAll(final Map extends String, ? extends Object> m)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void clear()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Set keySet()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Collection
© 2015 - 2025 Weber Informatics LLC | Privacy Policy