if (null == version.getSchemaLocation()) { throw new IllegalStateException("No schema for version " + version.getVersion()); addAttribute(atts, W3C_XML_SCHEMA_INSTANCE_PREFIX, W3C_XML_SCHEMA_INSTANCE_ATTRIBUTE_SCHEMA_LOCATION, version.getNamespace() + " " + version.getSchemaLocation()); handler.startPrefixMapping(XmlConstants.DEFAULT_PREFIX, version.getNamespace()); addAttribute(atts, VERSION, this.version.getVersion()); if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_5) >= 0) { if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) { if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) { if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) { if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) { if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) { if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) { if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) >= 0) { if (creation.hasMessageSyncInterval()) { atts.addAttribute("", "", MESSAGE_SYNC_INTERVAL, "",
/** * Test that {@link CacheXmlVersion#valueForVersion(String)} matches the same * {@link CacheXmlVersion} via {@link CacheXmlVersion#getVersion()}. * * @since GemFire 8.1 */ @Test public void testValueForVersion() { for (final CacheXmlVersion cacheXmlVersion : CacheXmlVersion.values()) { assertSame(cacheXmlVersion, CacheXmlVersion.valueForVersion(cacheXmlVersion.getVersion())); } }
/** * Writes the generator's state to pw */ private void generate(PrintWriter pw) { // Use JAXP's transformation API to turn SAX events into pretty // XML text try { Source src = new SAXSource(this, new InputSource()); Result res = new StreamResult(pw); TransformerFactory xFactory = TransformerFactory.newInstance(); Transformer xform = xFactory.newTransformer(); xform.setOutputProperty(OutputKeys.METHOD, "xml"); xform.setOutputProperty(OutputKeys.INDENT, "yes"); if (!useSchema) { // set the doctype system and public ids from version for older DTDs. xform.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, version.getSystemId()); xform.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, version.getPublicId()); } xform.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); xform.transform(src, res); pw.flush(); } catch (Exception ex) { RuntimeException ex2 = new RuntimeException( "An Exception was thrown while generating XML."); ex2.initCause(ex); throw ex2; } }
private void generateRegion(Region root) throws SAXException { if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_0) >= 0) { generate(root, REGION); } else { generate(root, VM_ROOT_REGION); } }
version = CacheXmlVersion.valueForVersion(VERSION_LATEST); // we won't know the version, so
/** * Asserts that Cache type is defined as a embedded ComplexType under an Element named "cache" for * version 8.1. * * @since GemFire 8.1 */ @Test public void testCacheDefinedAsNestedComplexType8_1() throws Exception { Document doc = loadSchema(CacheXmlVersion.GEMFIRE_8_1.getSchemaLocation()); final XPathContext xPathContext = new XPathContext(CacheElement.XSD_PREFIX, XMLConstants.W3C_XML_SCHEMA_NS_URI); final Node cacheType = XmlUtils.querySingleElement(doc.getFirstChild(), CacheElement.CACHE_TYPE_EMBEDDED, xPathContext); assertNotNull("Cache type is not embedded complexType.", cacheType); }
/** * Generates XML for the client-subscription tag * * @param bridge instance of <code>CacheServer</code> * * @since GemFire 5.7 */ private void generateClientHaQueue(CacheServer bridge) throws SAXException { AttributesImpl atts = new AttributesImpl(); ClientSubscriptionConfigImpl csc = (ClientSubscriptionConfigImpl) bridge.getClientSubscriptionConfig(); try { atts.addAttribute("", "", CLIENT_SUBSCRIPTION_EVICTION_POLICY, "", csc.getEvictionPolicy()); atts.addAttribute("", "", CLIENT_SUBSCRIPTION_CAPACITY, "", String.valueOf(csc.getCapacity())); if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) { String dsVal = csc.getDiskStoreName(); if (dsVal != null) { atts.addAttribute("", "", DISK_STORE_NAME, "", dsVal); } } if (csc.getDiskStoreName() == null && csc.hasOverflowDirectory()) { atts.addAttribute("", "", OVERFLOW_DIRECTORY, "", csc.getOverflowDirectory()); } handler.startElement("", CLIENT_SUBSCRIPTION, CLIENT_SUBSCRIPTION, atts); handler.endElement("", CLIENT_SUBSCRIPTION, CLIENT_SUBSCRIPTION); } catch (Exception ex) { ex.printStackTrace(); } }
/** * Creates a generator for a default cache. */ private CacheXmlGenerator() { this.cache = null; this.useSchema = true; this.version = CacheXmlVersion.valueForVersion(VERSION_LATEST); this.generateDefaults = true; this.creation = new CacheCreation(); creation.setLockLease(GemFireCacheImpl.DEFAULT_LOCK_LEASE); creation.setLockTimeout(GemFireCacheImpl.DEFAULT_LOCK_TIMEOUT); creation.setSearchTimeout(GemFireCacheImpl.DEFAULT_SEARCH_TIMEOUT); // No cache proxy creation.setIsServer(false); creation.setCopyOnRead(GemFireCacheImpl.DEFAULT_COPY_ON_READ); }
} else if (ea.getAlgorithm() == EvictionAlgorithm.LRU_HEAP) { handler.startElement("", LRU_HEAP_PERCENTAGE, LRU_HEAP_PERCENTAGE, atts); if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) { ObjectSizer os = ea.getObjectSizer(); if (!(os instanceof SizeClassOnceObjectSizer)) {
/** * Creates a new <code>CacheXmlGenerator</code> that generates XML for a given * <code>ClientCache</code>. */ private CacheXmlGenerator(ClientCache cache, boolean useSchema, String version, boolean includeKeysValues) { this.cache = (Cache) cache; this.useSchema = useSchema; this.version = CacheXmlVersion.valueForVersion(version); this.includeKeysValues = includeKeysValues; this.generateDefaults = true; if (cache instanceof ClientCacheCreation) { this.creation = (ClientCacheCreation) cache; this.creation.startingGenerate(); } else { this.creation = new ClientCacheCreation(); if (generateDefaults() || cache.getCopyOnRead()) { this.creation.setCopyOnRead(cache.getCopyOnRead()); } } }
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_1) < 0) { return;
this.cache = cache; this.useSchema = useSchema; this.version = CacheXmlVersion.valueForVersion(version); this.includeKeysValues = includeKeysValues; this.generateDefaults = generateDefaults;
/** * Previous strings based version just check ordinal comparison of strings. It failed test for * "8_0".compareTo("8.1") < 0. It also would have failed for "9.0".compareTo("10.0") < 0. Testing * that ENUM based solution is ordinal correct for comparisons. * * @since GemFire 8.1 */ @Test public void testOrdinal() { assertTrue(GEMFIRE_3_0.compareTo(GEMFIRE_4_0) < 0); assertTrue(GEMFIRE_4_0.compareTo(GEMFIRE_4_1) < 0); assertTrue(GEMFIRE_4_1.compareTo(GEMFIRE_5_0) < 0); assertTrue(GEMFIRE_5_0.compareTo(GEMFIRE_5_1) < 0); assertTrue(GEMFIRE_5_1.compareTo(GEMFIRE_5_5) < 0); assertTrue(GEMFIRE_5_5.compareTo(GEMFIRE_5_7) < 0); assertTrue(GEMFIRE_5_7.compareTo(GEMFIRE_5_8) < 0); assertTrue(GEMFIRE_5_8.compareTo(GEMFIRE_6_0) < 0); assertTrue(GEMFIRE_6_0.compareTo(GEMFIRE_6_1) < 0); assertTrue(GEMFIRE_6_1.compareTo(GEMFIRE_6_5) < 0); assertTrue(GEMFIRE_6_5.compareTo(GEMFIRE_6_6) < 0); assertTrue(GEMFIRE_6_6.compareTo(GEMFIRE_7_0) < 0); assertTrue(GEMFIRE_7_0.compareTo(GEMFIRE_8_0) < 0); assertTrue(GEMFIRE_8_0.compareTo(GEMFIRE_8_1) < 0); assertTrue(GEMFIRE_8_1.compareTo(GEODE_1_0) < 0); }
/** * When a <code>partition-attributes</code> element is finished, the {@link PartitionAttributes} * are on top of the stack followed by the {@link RegionAttributesCreation} to which the partition * attributes are assigned. */ private void endPartitionAttributes() { PartitionAttributesImpl paf = (PartitionAttributesImpl) stack.pop(); paf.validateAttributes(); RegionAttributesCreation rattrs = peekRegionAttributesContext(PARTITION_ATTRIBUTES); // change the 5.0 default data policy (EMPTY) to the current default if (rattrs.hasDataPolicy() && rattrs.getDataPolicy().isEmpty() && (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_0) == 0)) { rattrs.setDataPolicy(PartitionedRegionHelper.DEFAULT_DATA_POLICY); } rattrs.setPartitionAttributes(paf); }
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_0) < 0) { return; if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_1) < 0) { return; if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_0) < 0) { return; if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) < 0) { return; if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) < 0) { return; if (this.version.compareTo(CacheXmlVersion.GEMFIRE_8_0) < 0) { return; if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) { handler.startElement("", CACHE_SERVER, CACHE_SERVER, atts); } else { if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) { String[] groups = bridge.getGroups(); if (groups.length > 0) { if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) { handler.endElement("", "", CACHE_SERVER); } else {
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) >= 0) { if (generateDefaults() || pa.getLocalMaxMemory() != ((PartitionAttributesImpl) pa).getLocalMaxMemoryDefault()) if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) { if (pa.getColocatedWith() != null) atts.addAttribute("", "", PARTITION_COLOCATED_WITH, "", pa.getColocatedWith()); if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) { if (generateDefaults() || pa.getRecoveryDelay() != PartitionAttributesFactory.RECOVERY_DELAY_DEFAULT) if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) { PartitionResolver rr = pa.getPartitionResolver(); if (rr != null) { if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_1) >= 0) { PartitionListener[] listeners = pa.getPartitionListeners(); for (int i = 0; i < listeners.length; i++) { if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) { List<FixedPartitionAttributes> staticAttrs = pa.getFixedPartitionAttributes(); if (staticAttrs != null) { if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) < 0) { Properties p = pa.getLocalProperties(); generate(p, LOCAL_PROPERTIES);
/** * Generates XML for a CacheTransactionManager * * @since GemFire 4.0 */ private void generate(CacheTransactionManager txMgr) throws SAXException { if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_0) < 0) { return; } if (txMgr == null) { return; } if (!generateDefaults() && txMgr.getWriter() == null && txMgr.getListeners().length == 0) { return; } handler.startElement("", TRANSACTION_MANAGER, TRANSACTION_MANAGER, EMPTY); { TransactionListener[] listeners = txMgr.getListeners(); for (int i = 0; i < listeners.length; i++) { generate(TRANSACTION_LISTENER, listeners[i]); } if (txMgr.getWriter() != null) { generate(TRANSACTION_WRITER, txMgr.getWriter()); } } handler.endElement("", TRANSACTION_MANAGER, TRANSACTION_MANAGER); }
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) < 0) { return; try { atts.addAttribute("", "", NAME, "", cp.getName()); if (this.version.compareTo(CacheXmlVersion.GEODE_1_0) >= 0) { if (generateDefaults() || cp .getSubscriptionTimeoutMultiplier() != PoolFactory.DEFAULT_SUBSCRIPTION_TIMEOUT_MULTIPLIER) { String.valueOf(cp.getThreadLocalConnections())); if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_1) > 0) { if (generateDefaults() || cp.getPRSingleHopEnabled() != PoolFactory.DEFAULT_PR_SINGLE_HOP_ENABLED) if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_1) > 0) { if (generateDefaults() || cp.getMultiuserAuthentication() != PoolFactory.DEFAULT_MULTIUSER_AUTHENTICATION)
String.valueOf(receiver.getSocketBufferSize())); if (this.version.compareTo(CacheXmlVersion.GEMFIRE_8_0) < 0) { return;