List of usage examples for org.dom4j Element attributeIterator
Iterator<Attribute> attributeIterator();
From source file:com.zimbra.cs.account.AttributeManager.java
License:Open Source License
private void loadAttrs(File file, Document doc) { Element root = doc.getRootElement(); if (!root.getName().equals(E_ATTRS)) { error(null, file, "root tag is not " + E_ATTRS); return;//from w w w . ja va 2 s .c om } Map<Integer, String> idsSeen = new HashMap<Integer, String>(); String group = root.attributeValue(A_GROUP); String groupIdStr = root.attributeValue(A_GROUP_ID); if (group == null ^ groupIdStr == null) { error(null, file, A_GROUP + " and " + A_GROUP_ID + " both have to be both specified"); } int groupId = -1; if (group != null) { try { groupId = Integer.valueOf(groupIdStr); } catch (NumberFormatException nfe) { error(null, file, A_GROUP_ID + " is not a number: " + groupIdStr); } } if (groupId == 2) { error(null, file, A_GROUP_ID + " is not valid (used by ZimbraObjectClass)"); } else if (groupId > 0) { if (mGroupMap.containsKey(groupId)) { error(null, file, "duplicate group id: " + groupId); } else if (mGroupMap.containsValue(group)) { error(null, file, "duplicate group: " + group); } else { mGroupMap.put(groupId, group); } } NEXT_ATTR: for (Iterator iter = root.elementIterator(); iter.hasNext();) { Element eattr = (Element) iter.next(); if (!eattr.getName().equals(E_ATTR)) { error(null, file, "unknown element: " + eattr.getName()); continue; } AttributeCallback callback = null; AttributeType type = null; AttributeOrder order = null; String value = null; String min = null; String max = null; boolean immutable = false; // boolean ignore = false; int id = -1; String parentOid = null; AttributeCardinality cardinality = null; Set<AttributeClass> requiredIn = null; Set<AttributeClass> optionalIn = null; Set<AttributeFlag> flags = null; String canonicalName = null; String name = eattr.attributeValue(A_NAME); if (name == null) { error(null, file, "no name specified"); continue; } canonicalName = name.toLowerCase(); List<AttributeServerType> requiresRestart = null; Version deprecatedSinceVer = null; List<Version> sinceVer = null; Boolean ephemeral = false; for (Iterator attrIter = eattr.attributeIterator(); attrIter.hasNext();) { Attribute attr = (Attribute) attrIter.next(); String aname = attr.getName(); if (aname.equals(A_NAME)) { // nothing to do - already processed } else if (aname.equals(A_CALLBACK)) { callback = loadCallback(attr.getValue()); } else if (aname.equals(A_IMMUTABLE)) { immutable = "1".equals(attr.getValue()); } else if (aname.equals(A_MAX)) { max = attr.getValue(); } else if (aname.equals(A_MIN)) { min = attr.getValue(); } else if (aname.equals(A_TYPE)) { type = AttributeType.getType(attr.getValue()); if (type == null) { error(name, file, "unknown <attr> type: " + attr.getValue()); continue NEXT_ATTR; } } else if (aname.equals(A_VALUE)) { value = attr.getValue(); } else if (aname.equals(A_PARENT_OID)) { parentOid = attr.getValue(); if (!parentOid.matches("^\\d+(\\.\\d+)+")) error(name, file, "invalid parent OID " + parentOid + ": must be an OID"); } else if (aname.equals(A_ID)) { try { id = Integer.parseInt(attr.getValue()); if (id < 0) { error(name, file, "invalid id " + id + ": must be positive"); } } catch (NumberFormatException nfe) { error(name, file, aname + " is not a number: " + attr.getValue()); } } else if (aname.equals(A_CARDINALITY)) { try { cardinality = AttributeCardinality.valueOf(attr.getValue()); } catch (IllegalArgumentException iae) { error(name, file, aname + " is not valid: " + attr.getValue()); } } else if (aname.equals(A_REQUIRED_IN)) { requiredIn = parseClasses(name, file, attr.getValue()); } else if (aname.equals(A_OPTIONAL_IN)) { optionalIn = parseClasses(name, file, attr.getValue()); } else if (aname.equals(A_FLAGS)) { flags = parseFlags(name, file, attr.getValue()); } else if (aname.equals(A_ORDER)) { try { order = AttributeOrder.valueOf(attr.getValue()); } catch (IllegalArgumentException iae) { error(name, file, aname + " is not valid: " + attr.getValue()); } } else if (aname.equals(A_REQUIRES_RESTART)) { requiresRestart = parseRequiresRestart(name, file, attr.getValue()); } else if (aname.equals(A_DEPRECATED_SINCE)) { String depreSince = attr.getValue(); if (depreSince != null) { try { deprecatedSinceVer = new Version(depreSince); } catch (ServiceException e) { error(name, file, aname + " is not valid: " + attr.getValue() + " (" + e.getMessage() + ")"); } } } else if (aname.equals(A_SINCE)) { String since = attr.getValue(); if (since != null) { try { String[] versions = since.split(","); sinceVer = new ArrayList<Version>(); for (String verStr : versions) { sinceVer.add(new Version(verStr.trim())); } } catch (ServiceException e) { error(name, file, aname + " is not valid: " + attr.getValue() + " (" + e.getMessage() + ")"); } } } else { error(name, file, "unknown <attr> attr: " + aname); } } List<String> globalConfigValues = new LinkedList<String>(); List<String> globalConfigValuesUpgrade = null; // note: init to null instead of empty List List<String> defaultCOSValues = new LinkedList<String>(); List<String> defaultExternalCOSValues = new LinkedList<String>(); List<String> defaultCOSValuesUpgrade = null; // note: init to null instead of empty List String description = null; String deprecateDesc = null; for (Iterator elemIter = eattr.elementIterator(); elemIter.hasNext();) { Element elem = (Element) elemIter.next(); if (elem.getName().equals(E_GLOBAL_CONFIG_VALUE)) { globalConfigValues.add(elem.getText()); } else if (elem.getName().equals(E_GLOBAL_CONFIG_VALUE_UPGRADE)) { if (globalConfigValuesUpgrade == null) globalConfigValuesUpgrade = new LinkedList<String>(); globalConfigValuesUpgrade.add(elem.getText()); } else if (elem.getName().equals(E_DEFAULT_COS_VALUE)) { defaultCOSValues.add(elem.getText()); } else if (elem.getName().equals(E_DEFAULT_EXTERNAL_COS_VALUE)) { defaultExternalCOSValues.add(elem.getText()); } else if (elem.getName().equals(E_DEFAULT_COS_VALUE_UPGRADE)) { if (defaultCOSValuesUpgrade == null) defaultCOSValuesUpgrade = new LinkedList<String>(); defaultCOSValuesUpgrade.add(elem.getText()); } else if (elem.getName().equals(E_DESCRIPTION)) { if (description != null) { error(name, file, "more than one " + E_DESCRIPTION); } description = elem.getText(); } else if (elem.getName().equals(E_DEPRECATE_DESC)) { if (deprecateDesc != null) { error(name, file, "more than one " + E_DEPRECATE_DESC); } deprecateDesc = elem.getText(); } else { error(name, file, "unknown element: " + elem.getName()); } } if (deprecatedSinceVer != null && deprecateDesc == null) error(name, file, "missing element " + E_DEPRECATE_DESC); else if (deprecatedSinceVer == null && deprecateDesc != null) error(name, file, "missing attr " + A_DEPRECATED_SINCE); if (deprecatedSinceVer != null) { String deprecateInfo = "Deprecated since: " + deprecatedSinceVer.toString() + ". " + deprecateDesc; if (description == null) description = deprecateInfo; else description = deprecateInfo + ". Orig desc: " + description; } // since is required after(inclusive) oid 525 - first attribute in 5.0 if (sinceVer == null && id >= 525) { error(name, file, "missing since (required after(inclusive) oid 710)"); } // Check that if id is specified, then cardinality is specified. if (id > 0 && cardinality == null) { error(name, file, "cardinality not specified"); } // Check that if id is specified, then at least one object class is defined if (id > 0 && (optionalIn != null && optionalIn.isEmpty()) && (requiredIn != null && requiredIn.isEmpty())) { error(name, file, "atleast one of " + A_REQUIRED_IN + " or " + A_OPTIONAL_IN + " must be specified"); } // Check that if id is specified, it must be unique if (id > 0) { String idForAttr = idsSeen.get(Integer.valueOf(id)); if (idForAttr != null) { error(name, file, "duplicate id: " + id + " is already used for " + idForAttr); } else { idsSeen.put(Integer.valueOf(id), name); } } // Check that if it is COS inheritable it is in account and COS classes checkFlag(name, file, flags, AttributeFlag.accountInherited, AttributeClass.account, AttributeClass.cos, null, requiredIn, optionalIn); // Check that if it is COS-domain inheritable it is in account and COS and domain classes checkFlag(name, file, flags, AttributeFlag.accountCosDomainInherited, AttributeClass.account, AttributeClass.cos, AttributeClass.domain, requiredIn, optionalIn); // Check that if it is domain inheritable it is in domain and global config checkFlag(name, file, flags, AttributeFlag.domainInherited, AttributeClass.domain, AttributeClass.globalConfig, null, requiredIn, optionalIn); // Check that if it is server inheritable it is in server and global config checkFlag(name, file, flags, AttributeFlag.serverInherited, AttributeClass.server, AttributeClass.globalConfig, null, requiredIn, optionalIn); // Check that if it is serverPreferAlwaysOn it is in server and alwaysOnCluster checkFlag(name, file, flags, AttributeFlag.serverPreferAlwaysOn, AttributeClass.server, AttributeClass.alwaysOnCluster, null, requiredIn, optionalIn); // Check that is cardinality is single, then not more than one // default value is specified if (cardinality == AttributeCardinality.single) { if (globalConfigValues.size() > 1) { error(name, file, "more than one global config value specified for cardinality " + AttributeCardinality.single); } if (defaultCOSValues.size() > 1 || defaultExternalCOSValues.size() > 1) { error(name, file, "more than one default COS value specified for cardinality " + AttributeCardinality.single); } } checkEphemeralFlags(name, file, flags, min, max, cardinality); AttributeInfo info = createAttributeInfo(name, id, parentOid, groupId, callback, type, order, value, immutable, min, max, cardinality, requiredIn, optionalIn, flags, globalConfigValues, defaultCOSValues, defaultExternalCOSValues, globalConfigValuesUpgrade, defaultCOSValuesUpgrade, mMinimize ? null : description, requiresRestart, sinceVer, deprecatedSinceVer); if (mAttrs.get(canonicalName) != null) { error(name, file, "duplicate definiton"); } mAttrs.put(canonicalName, info); if (flags != null) { for (AttributeFlag flag : flags) { mFlagToAttrsMap.get(flag).add(name); if (flag == AttributeFlag.accountCosDomainInherited) mFlagToAttrsMap.get(AttributeFlag.accountInherited).add(name); } } if (requiredIn != null || optionalIn != null) { if (requiredIn != null) { for (AttributeClass klass : requiredIn) { mClassToAttrsMap.get(klass).add(name); mClassToLowerCaseAttrsMap.get(klass).add(name.toLowerCase()); } } if (optionalIn != null) { for (AttributeClass klass : optionalIn) { mClassToAttrsMap.get(klass).add(name); mClassToLowerCaseAttrsMap.get(klass).add(name.toLowerCase()); } } } if (isBinaryType(type)) { mBinaryAttrs.add(canonicalName); } else if (isBinaryTransferType(type)) { mBinaryTransferAttrs.add(canonicalName); } if (flags != null && flags.contains(AttributeFlag.ephemeral)) { mEphemeralAttrs.put(canonicalName, info); mEphemeralAttrsSet.add(name); if (!info.isDynamic()) { addNonDynamicEphemeralAttr(info); } } } }
From source file:com.zimbra.cs.account.AttributeManager.java
License:Open Source License
private void loadObjectClasses(File file, Document doc) { Element root = doc.getRootElement(); if (!root.getName().equals(E_OBJECTCLASSES)) { error(null, file, "root tag is not " + E_OBJECTCLASSES); return;// w w w. ja v a2s.c o m } String group = root.attributeValue(A_GROUP); String groupIdStr = root.attributeValue(A_GROUP_ID); if (group == null ^ groupIdStr == null) { error(null, file, A_GROUP + " and " + A_GROUP_ID + " both have to be both specified"); } int groupId = -1; if (group != null) { try { groupId = Integer.valueOf(groupIdStr); } catch (NumberFormatException nfe) { error(null, file, A_GROUP_ID + " is not a number: " + groupIdStr); } } if (groupId == 1) { error(null, file, A_GROUP_ID + " is not valid (used by ZimbraAttrType)"); } else if (groupId > 0) { if (mOCGroupMap.containsKey(groupId)) { error(null, file, "duplicate group id: " + groupId); } else if (mOCGroupMap.containsValue(group)) { error(null, file, "duplicate group: " + group); } else { mOCGroupMap.put(groupId, group); } } for (Iterator iter = root.elementIterator(); iter.hasNext();) { Element eattr = (Element) iter.next(); if (!eattr.getName().equals(E_OBJECTCLASS)) { error(null, file, "unknown element: " + eattr.getName()); continue; } int id = -1; ObjectClassType type = null; String canonicalName = null; String name = eattr.attributeValue(A_NAME); if (name == null) { error(null, file, "no name specified"); continue; } canonicalName = name.toLowerCase(); for (Iterator attrIter = eattr.attributeIterator(); attrIter.hasNext();) { Attribute attr = (Attribute) attrIter.next(); String aname = attr.getName(); if (aname.equals(A_NAME)) { // nothing to do - already processed } else if (aname.equals(A_TYPE)) { type = ObjectClassType.valueOf(attr.getValue()); } else if (aname.equals(A_ID)) { try { id = Integer.parseInt(attr.getValue()); if (id < 0) { error(name, file, "invalid id " + id + ": must be positive"); } } catch (NumberFormatException nfe) { error(name, file, aname + " is not a number: " + attr.getValue()); } } else { error(name, file, "unknown <attr> attr: " + aname); } } List<String> superOCs = new LinkedList<String>(); String description = null; List<String> comment = null; for (Iterator elemIter = eattr.elementIterator(); elemIter.hasNext();) { Element elem = (Element) elemIter.next(); if (elem.getName().equals(E_SUP)) { superOCs.add(elem.getText()); } else if (elem.getName().equals(E_DESCRIPTION)) { if (description != null) { error(name, file, "more than one " + E_DESCRIPTION); } description = elem.getText(); } else if (elem.getName().equals(E_COMMENT)) { if (comment != null) { error(name, file, "more than one " + E_COMMENT); } comment = new ArrayList<String>(); String[] lines = elem.getText().trim().split("\\n"); for (String line : lines) comment.add(line.trim()); } else { error(name, file, "unknown element: " + elem.getName()); } } // Check that if all bits are specified if (id <= 0) { error(name, file, "id not specified"); } if (type == null) { error(name, file, "type not specified"); } if (description == null) { error(name, file, "desc not specified"); } if (superOCs.isEmpty()) { error(name, file, "sup not specified"); } // there must be a one-to-one mapping between enums in AttributeClass and ocs defined in the xml AttributeClass attrClass = AttributeClass.getAttributeClass(name); if (attrClass == null) { error(name, file, "unknown class in AttributeClass: " + name); } ObjectClassInfo info = new ObjectClassInfo(attrClass, name, id, groupId, type, superOCs, mMinimize ? null : description, mMinimize ? null : comment); if (mOCs.get(canonicalName) != null) { error(name, file, "duplicate objectclass definiton"); } mOCs.put(canonicalName, info); } }
From source file:cz.muni.stanse.utils.xmlpatterns.XMLPattern.java
License:GNU General Public License
private static boolean matchingElements(final Element XMLpivot, final Element XMLelement, final XMLPatternVariablesAssignment varsAssignment) { if (XMLpivot.getName().equals("nested")) { final String elementName = XMLelement.getName(); for (final Iterator<Attribute> j = XMLpivot.attributeIterator(); j.hasNext();) if (elementName.equals(j.next().getValue())) return false; return onNested(XMLpivot, XMLelement, varsAssignment); }//from w ww . j a v a2 s . c om if (XMLpivot.getName().equals("ignore")) return true; if (XMLpivot.getName().equals("var")) { if (!satisfyVarConstraints(XMLelement.getName(), XMLpivot.attribute("match"), XMLpivot.attribute("except"))) return false; varsAssignment.put(XMLpivot.attribute("name").getValue(), XMLelement); return true; } if (!XMLpivot.getName().equals(XMLelement.getName())) return false; if (!matchingAttributes(XMLpivot.attributes(), XMLelement)) return false; if (XMLpivot.isTextOnly() != XMLelement.isTextOnly()) return false; if (XMLpivot.isTextOnly() && !XMLpivot.getText().equals(XMLelement.getText())) return false; final Iterator<Element> i = XMLpivot.elementIterator(); final Iterator<Element> j = XMLelement.elementIterator(); while (i.hasNext() && j.hasNext()) { final Element pivotNext = i.next(); if (pivotNext.getName().equals("any")) return true; if (!matchingElements(pivotNext, j.next(), varsAssignment)) return false; } if (i.hasNext() || j.hasNext()) return false; return true; }
From source file:darks.orm.core.config.CacheConfiguration.java
License:Apache License
public void readAppCacheConfig(Element element) throws Exception { if (element == null) return;/* w ww.ja v a2 s .c o m*/ appCacheData = new CacheConfigData(); appCacheData.setCacheEnumType(CacheScopeType.Application); appCacheData.setId("application"); for (Iterator<Attribute> it = element.attributeIterator(); it.hasNext();) { Attribute at = it.next(); String name = at.getName().trim(); String value = at.getValue().trim(); if ("id".equalsIgnoreCase(name)) { if (value != null && !"".equals(value)) appCacheData.setId(value); } else if ("strategy".equalsIgnoreCase(name)) { if ("Fifo".equalsIgnoreCase(value)) { appCacheData.setCacheStrategy(CacheControlStrategy.Fifo); } else if ("Lru".equalsIgnoreCase(value)) { appCacheData.setCacheStrategy(CacheControlStrategy.Lru); } else if ("SoftRef".equalsIgnoreCase(value)) { appCacheData.setCacheStrategy(CacheControlStrategy.SoftRef); } else if ("WeakRef".equalsIgnoreCase(value)) { appCacheData.setCacheStrategy(CacheControlStrategy.WeakRef); } } else if ("maxObject".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; appCacheData.setMaxObject(Integer.parseInt(value)); } else if ("eternal".equalsIgnoreCase(name)) { if ("false".equalsIgnoreCase(value)) { appCacheData.setEternal(false); } else { appCacheData.setEternal(true); } } else if ("entirety".equalsIgnoreCase(name)) { if ("false".equalsIgnoreCase(value)) { appCacheData.setEntirety(false); } else { appCacheData.setEntirety(true); } } else if ("idleTime".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; appCacheData.setIdleTime(Integer.parseInt(value) * 1000); } else if ("liveTime".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; appCacheData.setLiveTime(Integer.parseInt(value) * 1000); } else if ("copyStrategy".equalsIgnoreCase(name)) { value = value.toLowerCase(); if ("field".equalsIgnoreCase(value)) appCacheData.setCopyStrategyType(CopyStrategyType.Field); else if ("serial".equalsIgnoreCase(value)) appCacheData.setCopyStrategyType(CopyStrategyType.Serial); else if ("ref".equalsIgnoreCase(value)) appCacheData.setCopyStrategyType(CopyStrategyType.Ref); } } cacheMap.put(appCacheData.getId(), appCacheData); }
From source file:darks.orm.core.config.CacheConfiguration.java
License:Apache License
public void readThreadCacheConfig(Element element) throws Exception { if (element == null) { return;//from www . ja va 2 s. c o m } threadCacheData = new CacheConfigData(); threadCacheData.setCacheEnumType(CacheScopeType.Thread); threadCacheData.setId("thread"); for (Iterator<Attribute> it = element.attributeIterator(); it.hasNext();) { Attribute at = it.next(); String name = at.getName().trim(); String value = at.getValue().trim(); if ("id".equalsIgnoreCase(name)) { if (value != null && !"".equals(value)) threadCacheData.setId(value); } else if ("strategy".equalsIgnoreCase(name)) { if ("Fifo".equalsIgnoreCase(value)) { threadCacheData.setCacheStrategy(CacheControlStrategy.Fifo); } else if ("Lru".equalsIgnoreCase(value)) { threadCacheData.setCacheStrategy(CacheControlStrategy.Lru); } else if ("SoftRef".equalsIgnoreCase(value)) { threadCacheData.setCacheStrategy(CacheControlStrategy.SoftRef); } else if ("WeakRef".equalsIgnoreCase(value)) { threadCacheData.setCacheStrategy(CacheControlStrategy.WeakRef); } } else if ("maxObject".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; threadCacheData.setMaxObject(Integer.parseInt(value)); } else if ("entirety".equalsIgnoreCase(name)) { if ("false".equalsIgnoreCase(value)) { threadCacheData.setEntirety(false); } else { threadCacheData.setEntirety(true); } } else if ("copyStrategy".equalsIgnoreCase(name)) { value = value.toLowerCase(); if ("field".equalsIgnoreCase(value)) { threadCacheData.setCopyStrategyType(CopyStrategyType.Field); } else if ("serial".equalsIgnoreCase(value)) { threadCacheData.setCopyStrategyType(CopyStrategyType.Serial); } else if ("ref".equalsIgnoreCase(value)) { threadCacheData.setCopyStrategyType(CopyStrategyType.Ref); } } } cacheMap.put(threadCacheData.getId(), threadCacheData); }
From source file:darks.orm.core.config.CacheConfiguration.java
License:Apache License
public void readSessionCacheConfig(Element element) throws Exception { if (element == null) return;//from w w w . ja v a 2 s .c om sessionCacheData = new CacheConfigData(); sessionCacheData.setCacheEnumType(CacheScopeType.Session); sessionCacheData.setId("session"); for (Iterator<Attribute> it = element.attributeIterator(); it.hasNext();) { Attribute at = it.next(); String name = at.getName().trim(); String value = at.getValue().trim(); if ("id".equalsIgnoreCase(name)) { if (value != null && !"".equals(value)) sessionCacheData.setId(value); } else if ("strategy".equalsIgnoreCase(name)) { if ("Fifo".equalsIgnoreCase(value)) { sessionCacheData.setCacheStrategy(CacheControlStrategy.Fifo); } else if ("Lru".equalsIgnoreCase(value)) { sessionCacheData.setCacheStrategy(CacheControlStrategy.Lru); } else if ("SoftRef".equalsIgnoreCase(value)) { sessionCacheData.setCacheStrategy(CacheControlStrategy.SoftRef); } else if ("WeakRef".equalsIgnoreCase(value)) { sessionCacheData.setCacheStrategy(CacheControlStrategy.WeakRef); } } else if ("maxObject".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; sessionCacheData.setMaxObject(Integer.parseInt(value)); } else if ("entirety".equalsIgnoreCase(name)) { if ("false".equalsIgnoreCase(value)) { sessionCacheData.setEntirety(false); } else { sessionCacheData.setEntirety(true); } } else if ("copyStrategy".equalsIgnoreCase(name)) { value = value.toLowerCase(); if ("field".equalsIgnoreCase(value)) sessionCacheData.setCopyStrategyType(CopyStrategyType.Field); else if ("serial".equalsIgnoreCase(value)) sessionCacheData.setCopyStrategyType(CopyStrategyType.Serial); else if ("ref".equalsIgnoreCase(value)) sessionCacheData.setCopyStrategyType(CopyStrategyType.Ref); } } cacheMap.put(sessionCacheData.getId(), sessionCacheData); }
From source file:darks.orm.core.config.CacheConfiguration.java
License:Apache License
public void readEHCacheConfig(Element element) throws Exception { if (element == null) return;// w w w . j a va2 s. co m CacheConfigData ehCacheData = new CacheConfigData(); ehCacheData.setCacheEnumType(CacheScopeType.EHCache); for (Iterator<Attribute> it = element.attributeIterator(); it.hasNext();) { Attribute at = it.next(); String name = at.getName().trim(); String value = at.getValue().trim(); if ("id".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) throw new Exception("EHCache Config id is null"); ehCacheData.setId(value); } if ("name".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) throw new Exception("EHCache Config name is null"); ehCacheData.setId(value); } if ("configPath".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; ehCacheData.setEhcacheConfigPath(value); } else if ("maxElementsInMemory".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; ehCacheData.setMaxObject(Integer.parseInt(value)); } else if ("maxElementsOnDisk".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; ehCacheData.setMaxElementsOnDisk(Integer.parseInt(value)); } else if ("eternal".equalsIgnoreCase(name)) { if ("false".equalsIgnoreCase(value)) { ehCacheData.setEternal(false); } else { ehCacheData.setEternal(true); } } else if ("timeToIdleSeconds".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; ehCacheData.setIdleTime(Integer.parseInt(value)); } else if ("timeToLiveSeconds".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; ehCacheData.setLiveTime(Integer.parseInt(value)); } else if ("overflowToDisk".equalsIgnoreCase(name)) { if ("false".equalsIgnoreCase(value)) { ehCacheData.setOverflowToDisk(false); } else { ehCacheData.setOverflowToDisk(true); } } else if ("diskPersistent".equalsIgnoreCase(name)) { if ("false".equalsIgnoreCase(value)) { ehCacheData.setDiskPersistent(false); } else { ehCacheData.setDiskPersistent(true); } } else if ("diskExpiryThreadIntervalSeconds".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; ehCacheData.setDiskExpiryThreadIntervalSeconds(Integer.parseInt(value)); } else if ("memoryStoreEvictionPolicy".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; ehCacheData.setMemoryStoreEvictionPolicy(value); } } cacheMap.put(ehCacheData.getId(), ehCacheData); }
From source file:darks.orm.core.config.sqlmap.DDLConfigReader.java
License:Apache License
/** * DDL/*from ww w . j a v a2 s .c o m*/ * * @param element */ public void reader(Element element) { // DDL for (Iterator<Attribute> it = element.attributeIterator(); it.hasNext();) { try { Attribute at = it.next(); String name = at.getName().trim(); String value = at.getValue().trim(); if ("schema".equalsIgnoreCase(name)) { sqlMapConfig.setSchema(value); } else if ("catalog".equalsIgnoreCase(name)) { sqlMapConfig.setCatalog(value); } } catch (Exception e) { e.printStackTrace(); } } // DDL for (Iterator<Element> it = element.elementIterator(); it.hasNext();) { try { Element el = it.next(); String name = el.getName().trim(); if ("create".equalsIgnoreCase(name)) { readCreate(el); } else if ("alter".equalsIgnoreCase(name)) { readAlter(el); } } catch (Exception e) { e.printStackTrace(); } } }
From source file:darks.orm.core.config.sqlmap.DDLConfigReader.java
License:Apache License
/** * //from w ww . jav a 2 s . co m * * @param element * @param type */ public void readLabel(Element element, DDLType type) { DDLData ddlData = new DDLData(); String sql = element.getTextTrim(); String strRndId = UUIDHelper.getUUID(); ddlData.setId(strRndId); ddlData.setSql(sql); ddlData.setType(type); for (Iterator<Attribute> it = element.attributeIterator(); it.hasNext();) { try { Attribute at = it.next(); String name = at.getName().trim(); String value = at.getValue().trim(); if ("id".equalsIgnoreCase(name)) { ddlData.setId(value); } else if ("tableName".equalsIgnoreCase(name)) { ddlData.setTableName(value); } else if ("checkTable".equalsIgnoreCase(name)) { if ("true".equalsIgnoreCase(value)) ddlData.setCheckTable(true); else if ("false".equalsIgnoreCase(value)) ddlData.setCheckTable(false); } else if ("autoRunable".equalsIgnoreCase(name)) { if ("true".equalsIgnoreCase(value)) ddlData.setAutoRunable(true); else if ("false".equalsIgnoreCase(value)) ddlData.setAutoRunable(false); } } catch (Exception e) { e.printStackTrace(); } } sqlMapConfig.addDDLData(ddlData.getId(), ddlData); }
From source file:darks.orm.core.config.sqlmap.DMLConfigReader.java
License:Apache License
/** * Read and parse query tags//from ww w . j av a 2 s.c o m * * @param element Query tag element * @param namesp namespace * @throws Exception */ private DMLData readQuery(Element element, String namesp) throws Exception { if (!"".equals(namesp)) { if (!namesp.endsWith(".")) namesp += "."; } DMLData dmlData = new DMLData(); dmlData.setType(DMLType.Query); DMLQueryData queryData = new DMLQueryData(); queryData.setQueryType(QueryEnumType.Auto); queryData.setAutoCascade(true); dmlData.setQueryData(queryData); try { for (Iterator<Attribute> it = element.attributeIterator(); it.hasNext();) { Attribute attr = it.next(); readQueryAttribute(attr, dmlData, queryData); } } catch (Exception e) { throw new ConfigException(e.getMessage(), e); } if (queryData.getResultClass() == null) { throw new ConfigException("Sqlmap query " + dmlData.getId() + " loss result class config"); } if (dmlData.getId() == null) return null; RootTag rootTag = new RootTag(); parseSqlTag(rootTag, element, namesp); dmlData.setSqlTag(rootTag); String sql = element.getTextTrim(); if (sql != null && !"".equals(sql)) { queryData.setQueryDataType(DMLQueryDataType.Simple); queryData.setSQL(sql); } else { if (!readConstitute(element, queryData)) { if (!readSelect(element, queryData, "")) { return null; } } } AspectData aspectData = parseAspectXml(element); queryData.setAspectData(aspectData); sqlMapConfig.addDMLData(namesp + dmlData.getId(), dmlData); return dmlData; }