org.nuiton.jaxx.runtime.context.JAXXContextEntryDef Maven / Gradle / Ivy
The newest version!
/*
* #%L
* JAXX :: Runtime
* %%
* Copyright (C) 2008 - 2024 Code Lutin, Ultreia.io
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
package org.nuiton.jaxx.runtime.context;
import org.nuiton.jaxx.runtime.JAXXContext;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
* To qualify an entry in a {@link JAXXContext}.
*
* Use the factory methods newContextEntryDef
and
* newListContextEntryDef
to obtain new instances.
*
* @param type of the entry associated to the definition
* @author Tony Chemit - [email protected]
*/
public class JAXXContextEntryDef implements Serializable {
/** name of the entry, can be nuill for a unamed entry. */
protected String name;
/** class of the entry, can not be null */
protected Class klass;
private static final long serialVersionUID = 1L;
public String getName() {
return name;
}
public Class getKlass() {
return klass;
}
public O getContextValue(JAXXContext context) {
return context.getContextValue(klass, name);
}
public void removeContextValue(JAXXContext context) {
context.removeContextValue(klass, name);
}
public void setContextValue(JAXXContext context, O value) {
context.setContextValue(value, name);
}
@Override
public String toString() {
return super.toString() + "<" + klass + ":" + name + ">";
}
public JAXXContextEntryDef(Class klass) {
this(null, klass);
}
/**
* Special constructor for map, otherwise it is not possible to cast to O
*
* @param mapClass map class
* @param name name of content
* @since 2.0.2
*/
@SuppressWarnings({"unchecked"})
public JAXXContextEntryDef(Class