public static DocumentBuilder getDocumentBuilder() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); // the actual builder or parser DocumentBuilder builder = factory.newDocumentBuilder(); builder.setEntityResolver(new CacheXmlParser()); return builder; }
/** * Creates and initializes an instance of {@link Declarable} from the contents of the stack. * * @throws CacheXmlException Something goes wrong while instantiating or initializing the * declarable */ private Declarable createDeclarable() { return createDeclarable(cache, stack); }
@Override public InputSource resolveEntity(String name, String publicId, String baseURI, String systemId) throws SAXException, IOException { return handler.resolveEntity(name, publicId, baseURI, systemId); }
private void endAsyncEventListener() { Declarable d = createDeclarable(); if (!(d instanceof AsyncEventListener)) { throw new CacheXmlException( String.format("A %s is not an instance of a AsyncEventListener", d.getClass().getName())); } AsyncEventQueueCreation eventChannel = peekAsyncEventQueueContext(ASYNC_EVENT_LISTENER); eventChannel.setAsyncEventListener((AsyncEventListener) d); }
/** * When a <code>partition-resolver</code> element is finished, the {@link Parameter}s and class * names are popped off the stack. The <code>PartitionResolver</code> is instantiated and * initialized with the parameters, if appropriate. */ private void endPartitionResolver() { Declarable d = createDeclarable(); if (!(d instanceof PartitionResolver)) { throw new CacheXmlException(String.format("A %s is not an instance of a %s", new Object[] {d.getClass().getName(), "PartitionResolver"})); } PartitionAttributesImpl pai = peekPartitionAttributesImpl(PARTITION_ATTRIBUTES); pai.setPartitionResolver((PartitionResolver) d); }
endCache(); } else if (qName.equals(CLIENT_CACHE)) { endClientCache(); } else if (qName.equals(BRIDGE_SERVER)) { endCacheServer(); } else if (qName.equals(CACHE_SERVER)) { endCacheServer(); } else if (qName.equals(LOAD_PROBE)) { endLoadProbe(); } else if (qName.equals(CLIENT_SUBSCRIPTION)) { endClientHaQueue(); } else if (qName.equals(CONNECTION_POOL)) { endPool(); } else if (qName.equals(DYNAMIC_REGION_FACTORY)) { endDynamicRegionFactory(); } else if (qName.equals(GATEWAY_SENDER)) { endSerialGatewaySender(); } else if (qName.equals(GATEWAY_RECEIVER)) { endGatewayReceiver(); } else if (qName.equals(GATEWAY_EVENT_FILTER)) { endGatewayEventFilter(); } else if (qName.equals(GATEWAY_EVENT_SUBSTITUTION_FILTER)) { endGatewayEventSubstitutionFilter(); } else if (qName.equals(GATEWAY_TRANSPORT_FILTER)) { endGatewayTransportFilter(); } else if (qName.equals(ASYNC_EVENT_QUEUE)) { endAsyncEventQueue(); } else if (qName.equals(REGION)) { endRegion();
startCache(atts); } else if (qName.equals(CLIENT_CACHE)) { startClientCache(atts); } else if (qName.equals(BRIDGE_SERVER)) { startCacheServer(atts); } else if (qName.equals(CACHE_SERVER)) { startCacheServer(atts); } else if (qName.equals(LOAD_PROBE)) { } else if (qName.equals(CONNECTION_POOL)) { startPool(atts); } else if (qName.equals(CLIENT_SUBSCRIPTION)) { startClientHaQueue(atts); } else if (qName.equals(DYNAMIC_REGION_FACTORY)) { startDynamicRegionFactory(atts); } else if (qName.equals(GATEWAY_SENDER)) { startGatewaySender(atts); } else if (qName.equals(GATEWAY_RECEIVER)) { startGatewayReceiver(atts); } else if (qName.equals(GATEWAY_EVENT_FILTER)) { } else if (qName.equals(GATEWAY_TRANSPORT_FILTER)) { } else if (qName.equals(GATEWAY_EVENT_SUBSTITUTION_FILTER)) { } else if (qName.equals(ASYNC_EVENT_QUEUE)) { startAsyncEventQueue(atts); } else if (qName.equals(GATEWAY_CONFLICT_RESOLVER)) { } else if (qName.equals(LOCATOR)) { doLocator(atts); } else if (qName.equals(REGION)) { startRegion(atts);
/** * 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( String.format("A %s is not an instance of a CacheListener.", d.getClass().getName())); } RegionAttributesCreation attrs = peekRegionAttributesContext(CACHE_LISTENER); attrs.addCacheListener((CacheListener) d); }
private Document loadSchema(final String schemaLocation) throws Exception { final CacheXmlParser entityResolver = new CacheXmlParser(); final XMLReader xmlReader = XMLReaderFactory.createXMLReader(); xmlReader.setEntityResolver(entityResolver); return XmlUtils.getDocumentBuilder() .parse(entityResolver.resolveEntity(null, schemaLocation).getByteStream()); }
@Override public void characters(char[] ch, int start, int length) throws SAXException { handler.characters(ch, start, length); }
/** * Complete the configuration of a <code>lru-heap-percentage</code> eviction controller. Check for * the declaration of an {@link ObjectSizer}. Assign the attributes to the enclosed * <code>region-attributes</code> */ private void endLRUHeapPercentage() { Object declCheck = stack.peek(); Declarable d = null; if (declCheck instanceof String || declCheck instanceof Parameter) { d = createDeclarable(); if (!(d instanceof ObjectSizer)) { String s = "A " + d.getClass().getName() + " is not an instance of a ObjectSizer"; throw new CacheXmlException(s); } } EvictionAttributesImpl eai = (EvictionAttributesImpl) stack.pop(); if (d != null) { eai.setObjectSizer((ObjectSizer) d); } RegionAttributesCreation regAttrs = peekRegionAttributesContext(LRU_HEAP_PERCENTAGE); regAttrs.setEvictionAttributes(eai); }
/** * When a <code>partition-listener</code> element is finished, the {@link Parameter}s and class * names are popped off the stack. The <code>PartitionListener</code> is instantiated and * initialized with the parameters, if appropriate. */ private void endPartitionListener() { Declarable d = createDeclarable(); if (!(d instanceof PartitionListener)) { throw new CacheXmlException(String.format("A %s is not an instance of a %s", new Object[] {d.getClass().getName(), "PartitionListener"})); } PartitionAttributesImpl pai = peekPartitionAttributesImpl(PARTITION_ATTRIBUTES); pai.addPartitionListener((PartitionListener) d); }
/** * When we have finished a <code>declarable</code>, instantiate an instance of the * {@link Declarable}and push it on the stack. */ private void endDeclarable() { Declarable d = createDeclarable(); stack.push(d); }
/** * Complete the configuration of a <code>lru-memory-size</code> eviction controller. Check for the * declaration of an {@link ObjectSizer}. Assign the attributes to the enclose * <code>region-attributes</code> */ private void endLRUMemorySize() { Object declCheck = stack.peek(); Declarable d = null; if (declCheck instanceof String || declCheck instanceof Parameter) { d = createDeclarable(); if (!(d instanceof ObjectSizer)) { throw new CacheXmlException( String.format("A %s is not an instance of a ObjectSizer.", d.getClass().getName())); } } EvictionAttributesImpl eai = (EvictionAttributesImpl) stack.pop(); if (d != null) { eai.setObjectSizer((ObjectSizer) d); } RegionAttributesCreation regAttrs = peekRegionAttributesContext(LRU_MEMORY_SIZE); regAttrs.setEvictionAttributes(eai); }
/** * Resolve schema from <code>schemaLocationsNape</code> or <code>namespaceUri</code> for given * <code>namespaceUri</code>. * * @param schemaLocationMap {@link Map} of namespaceUri to URLs. * @param namespaceUri Namespace URI for schema. * @return {@link InputSource} for schema if found. * @throws IOException if unable to open {@link InputSource}. * @since GemFire 8.1 */ private static InputSource resolveSchema(final Map<String, String> schemaLocationMap, String namespaceUri) throws IOException { final EntityResolver2 entityResolver = new CacheXmlParser(); InputSource inputSource = null; // Try loading schema from locations until we find one. final String location = schemaLocationMap.get(namespaceUri); try { inputSource = entityResolver.resolveEntity(null, location); } catch (final SAXException e) { // ignore } if (null == inputSource) { // Try getting it from the namespace, will throw if does not exist. inputSource = new InputSource(new URL(namespaceUri).openStream()); } return inputSource; }
@Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { return handler.resolveEntity(publicId, systemId); }
private void endCustomExpiry() { Declarable d = createDeclarable(); if (!(d instanceof CustomExpiry)) { throw new CacheXmlException( String.format("A %s is not an instance of CustomExpiry", d.getClass().getName())); } stack.push(d); }
CacheXmlParser handler = new CacheXmlParser(); try { SAXParserFactory factory = SAXParserFactory.newInstance();
/** * When a <code>load-probe</code> element is encountered, create a new probe for the current * <code>CacheServer</code>. * * @since GemFire 5.7 */ private void endLoadProbe() { Declarable d = createDeclarable(); if (!(d instanceof ServerLoadProbe)) { throw new CacheXmlException(String.format("A %s is not an instance of a %s", new Object[] {d.getClass().getName(), "BridgeLoadProbe"})); } stack.push(d); }