use of org.apache.geode.cache.CacheXmlException in project geode by apache.
the class CacheXmlParser method endDiskDirs.
/**
* When a <code>disk-dirs</code> element is finished, the directory {@link File}s are on the stack
* followed by the {@link RegionAttributesCreation} to which the expiration attributes are
* assigned.
*/
private void endDiskDirs() {
List dirs = new ArrayList();
List sizes = new ArrayList();
while (stack.peek() instanceof File) {
dirs.add(stack.pop());
sizes.add(stack.pop());
}
Assert.assertTrue(!dirs.isEmpty());
Assert.assertTrue(!sizes.isEmpty());
// should set the disk-dirs and sizes in reverse order since parsers would have reversed
// the order because of pushing into stack
File[] disks = new File[dirs.size()];
int dirsLength = dirs.size();
for (int i = 0; i < dirsLength; i++) {
disks[i] = (File) dirs.get((dirsLength - 1) - i);
}
int[] diskSizes = new int[sizes.size()];
for (int i = 0; i < dirsLength; i++) {
diskSizes[i] = ((Integer) sizes.get((dirsLength - 1) - i)).intValue();
}
Object a = stack.peek();
if (a instanceof RegionAttributesCreation) {
RegionAttributesCreation attrs = (RegionAttributesCreation) a;
attrs.setDiskDirsAndSize(disks, diskSizes);
} else if (a instanceof DiskStoreAttributesCreation) {
DiskStoreAttributesCreation attrs = (DiskStoreAttributesCreation) a;
attrs.setDiskDirsAndSize(disks, diskSizes);
} else {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_MUST_BE_DEFINED_IN_THE_CONTEXT_OF_REGIONATTRIBUTES.toLocalizedString(DISK_DIRS));
}
}
use of org.apache.geode.cache.CacheXmlException in project geode by apache.
the class CacheXmlParser method getClassFromStack.
private Class getClassFromStack() {
Object o = this.stack.peek();
if (!(o instanceof String)) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_NO_CLASSNAME_FOUND.toLocalizedString());
}
String className = (String) this.stack.pop();
try {
Class c = InternalDataSerializer.getCachedClass(className);
return c;
} catch (Exception e) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_CLASS_NOT_FOUND.toLocalizedString(className), e);
}
}
use of org.apache.geode.cache.CacheXmlException in project geode by apache.
the class CacheXmlParser method endGatewayTransportFilter.
private void endGatewayTransportFilter() {
Declarable d = createDeclarable();
if (!(d instanceof GatewayTransportFilter)) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_IS_NOT_AN_INSTANCE_OF_A_1.toLocalizedString(new Object[] { d.getClass().getName(), "GatewayTransportFilter" }));
}
Object a = stack.peek();
if (a instanceof GatewaySenderFactory) {
GatewaySenderFactory senderFactory = (GatewaySenderFactory) a;
senderFactory.addGatewayTransportFilter((GatewayTransportFilter) d);
} else if (a instanceof GatewayReceiverFactory) {
GatewayReceiverFactory receiverFactory = (GatewayReceiverFactory) a;
receiverFactory.addGatewayTransportFilter((GatewayTransportFilter) d);
} else {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_MUST_BE_DEFINED_IN_THE_CONTEXT_OF_GATEWAYSENDER_OR_GATEWAYRECEIVER.toLocalizedString(GATEWAY_TRANSPORT_FILTER));
}
}
use of org.apache.geode.cache.CacheXmlException in project geode by apache.
the class CacheXmlParser method endCacheListener.
/**
* When a <code>cache-listener</code> element is finished, the {@link Parameter}s and class names
* are popped off the stack. The cache listener is instantiated and initialized with the
* parameters, if appropriate.
*/
private void endCacheListener() {
Declarable d = createDeclarable();
if (!(d instanceof CacheListener)) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_IS_NOT_AN_INSTANCE_OF_A_CACHELISTENER.toLocalizedString(d.getClass().getName()));
}
RegionAttributesCreation attrs = peekRegionAttributesContext(CACHE_LISTENER);
attrs.addCacheListener((CacheListener) d);
}
use of org.apache.geode.cache.CacheXmlException in project geode by apache.
the class CacheXml66DUnitTest method testBadKeyConstraintClass.
/**
* Tests parsing an XML file with a non-existent key constraint class.
*/
@Test
public void testBadKeyConstraintClass() throws Exception {
setXmlFile(findFile("badKeyConstraintClass.xml"));
IgnoredException expectedException = IgnoredException.addIgnoredException("While reading Cache XML file");
try {
getCache();
fail("Should have thrown a CacheXmlException");
} catch (CacheXmlException ex) {
assertTrue(ex.getCause() instanceof ClassNotFoundException);
} finally {
expectedException.remove();
}
}
Aggregations