use of org.apache.geode.cache.Declarable in project geode by apache.
the class CacheXmlGenerator method generate.
/**
* Generates XML for a <code>CacheCallback</code>
*/
private void generate(String kind, Object callback) throws SAXException {
if (callback == null) {
return;
}
handler.startElement("", kind, kind, EMPTY);
String className = callback.getClass().getName();
handler.startElement("", CLASS_NAME, CLASS_NAME, EMPTY);
handler.characters(className.toCharArray(), 0, className.length());
handler.endElement("", CLASS_NAME, CLASS_NAME);
Properties props = null;
if (callback instanceof Declarable2) {
props = ((Declarable2) callback).getConfig();
} else if (callback instanceof ReflectionBasedAutoSerializer) {
props = ((ReflectionBasedAutoSerializer) callback).getConfig();
} else if (callback instanceof Declarable && cache instanceof GemFireCacheImpl) {
props = ((InternalCache) cache).getDeclarableProperties((Declarable) callback);
}
generate(props, null);
handler.endElement("", kind, kind);
}
use of org.apache.geode.cache.Declarable in project geode by apache.
the class CacheXmlGenerator method generateFunctionService.
/**
* @throws SAXException
*/
private void generateFunctionService() throws SAXException {
Map<String, Function> functions = FunctionService.getRegisteredFunctions();
if (!generateDefaults() && functions.isEmpty()) {
return;
}
handler.startElement("", FUNCTION_SERVICE, FUNCTION_SERVICE, EMPTY);
for (Function function : functions.values()) {
if (function instanceof Declarable) {
handler.startElement("", FUNCTION, FUNCTION, EMPTY);
generate((Declarable) function, false);
handler.endElement("", FUNCTION, FUNCTION);
}
}
handler.endElement("", FUNCTION_SERVICE, FUNCTION_SERVICE);
}
use of org.apache.geode.cache.Declarable in project geode by apache.
the class CacheXmlParser method endPdxSerializer.
/**
*
*/
private void endPdxSerializer() {
Declarable d = createDeclarable();
if (!(d instanceof PdxSerializer)) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_IS_NOT_AN_INSTANCE_OF_A_PDX_SERIALIZER.toLocalizedString(d.getClass().getName()));
}
PdxSerializer serializer = (PdxSerializer) d;
this.cache.setPdxSerializer(serializer);
}
use of org.apache.geode.cache.Declarable in project geode by apache.
the class CacheXmlParser method endCacheWriter.
/**
* When a <code>cache-writer</code> element is finished, the {@link Parameter}s and class names
* are popped off the stack. The cache writer is instantiated and initialized with the parameters,
* if appropriate.
* <p>
* A cache-writer may be created in the context of region-attributes or dynamic-region-factory. In
* the latter case, there may be a disk-dir on top of the stack, represented by a File object.
*/
private void endCacheWriter() {
Declarable d = createDeclarable();
if (!(d instanceof CacheWriter)) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_IS_NOT_AN_INSTANCE_OF_A_CACHEWRITER.toLocalizedString(d.getClass().getName()));
}
Object a = stack.peek();
// check for disk-dir
if ((a instanceof File)) {
Object sav = stack.pop();
// pop out disk size
Object size = stack.pop();
a = stack.peek();
//
if (!(a instanceof RegionAttributesCreation)) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_0_MUST_BE_DEFINED_IN_THE_CONTEXT_OF_1.toLocalizedString(new Object[] { CACHE_WRITER, DYNAMIC_REGION_FACTORY }));
}
stack.push(size);
stack.push(sav);
} else // check for normal region-attributes
if (!(a instanceof RegionAttributesCreation)) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_0_MUST_BE_DEFINED_IN_THE_CONTEXT_OF_REGIONATTRIBUTES.toLocalizedString(CACHE_WRITER));
}
RegionAttributesCreation attrs = (RegionAttributesCreation) a;
attrs.setCacheWriter((CacheWriter) d);
}
use of org.apache.geode.cache.Declarable in project geode by apache.
the class CacheXmlParser method endFunctionName.
/**
* When we have finished a function element, we create the Declarable and push it onto stack
*/
private void endFunctionName() {
Declarable d = createDeclarable();
if (!(d instanceof Function)) {
String s = LocalizedStrings.CacheXmlParser_A_0_IS_NOT_AN_INSTANCE_OF_A_FUNCTION.toLocalizedString(d.getClass().getName());
throw new CacheXmlException(s);
}
Object fs = stack.peek();
if (!(fs instanceof FunctionServiceCreation)) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_IS_ONLY_ALLOWED_IN_THE_CONTEXT_OF_1_MJTDEBUG_E_2.toLocalizedString(new Object[] { FUNCTION, FUNCTION_SERVICE, fs }));
}
FunctionServiceCreation funcService = (FunctionServiceCreation) fs;
funcService.registerFunction((Function) d);
}
Aggregations