List of usage examples for org.jdom2 Element getName
public String getName()
From source file:com.bc.ceres.binio.binx.BinX.java
License:Open Source License
private Type parseUseType(Element typeElement) throws BinXException { String typeName = getTypeName(typeElement, true); Type type = definitions.get(typeName); if (type == null) { throw new BinXException(MessageFormat.format("Element ''{0}'': Unknown type definition: {1}", typeElement.getName(), typeName)); }//from w w w . j a v a2 s. c o m return type; }
From source file:com.bc.ceres.binio.binx.BinX.java
License:Open Source License
private CompoundType parseArrayVariable(Element typeElement) throws BinXException { Element sizeRefElement = getChild(typeElement, "sizeRef", 0, true); Element arrayTypeElement = getChild(typeElement, 1, true); String sequenceName = getVarName(arrayTypeElement, false); if (sequenceName == null) { sequenceName = getVarName(typeElement, false); if (sequenceName == null) { throw new BinXException( MessageFormat.format("Element ''{0}'': Missing name", typeElement.getName())); }/*from w w w.j a v a2s.c o m*/ } Element sizeRefTypeElement = getChild(sizeRefElement, true); String sizeRefName = getVarName(sizeRefTypeElement, false); if (sizeRefName == null) { sizeRefName = sequenceName + elementCountPostfix; } Type sizeRefType = parseAnyType(sizeRefTypeElement); if (!isIntegerType(sizeRefType)) { throw new BinXException(MessageFormat.format("Element ''{0}'': 'sizeRef' must be an integer type", typeElement.getName())); } Type arrayType = parseAnyType(arrayTypeElement); SequenceType sequenceType = VAR_SEQUENCE(arrayType, sizeRefName); return COMPOUND(generateArrayVariableCompoundName(sequenceName), MEMBER(sizeRefName, sizeRefType), MEMBER(sequenceName, sequenceType)); }
From source file:com.bc.ceres.binio.binx.BinX.java
License:Open Source License
private Type parseUnion(Element typeElement) throws BinXException { // todo - implement union (nf - 2008-11-27) throw new BinXException( MessageFormat.format("Element ''{0}'': Type not implemented", typeElement.getName())); }
From source file:com.bc.ceres.binio.binx.BinX.java
License:Open Source License
private Type parseArrayFixed(Element typeElement) throws BinXException { Element arrayTypeElement = getChild(typeElement, 0, true); Element dimElement = getChild(typeElement, "dim", 1, true); if (!dimElement.getChildren().isEmpty()) { // todo - implement multi-dimensional arrays (rq - 2008-11-27) throw new BinXException(MessageFormat.format( "Element ''{0}'': Multi-dimensional arrays not yet implemented", typeElement.getName())); }/* w ww . j a v a 2s .co m*/ final Type arrayType = parseAnyType(arrayTypeElement); final int indexFrom = getAttributeIntValue(dimElement, "indexFrom", 0); if (indexFrom != 0) { throw new BinXException( MessageFormat.format("Element ''{0}'': Attribute 'indexFrom' other than zero not supported.", typeElement.getName())); } final int indexTo = getAttributeIntValue(dimElement, "indexTo"); return SEQUENCE(arrayType, indexTo + 1); }
From source file:com.bc.ceres.binio.binx.BinX.java
License:Open Source License
private Type parseArrayStreamed(Element typeElement) throws BinXException { // todo - implement arrayStreamed (nf - 2008-11-27) throw new BinXException( MessageFormat.format("Element ''{0}'': Type not implemented", typeElement.getName())); }
From source file:com.bc.ceres.binio.binx.BinX.java
License:Open Source License
private Element getChild(Element element, String name, boolean require) throws BinXException { final Element child = element.getChild(name, namespace); if (require && child == null) { throw new BinXException( MessageFormat.format("Element ''{0}}': child ''{1}'' not found.", element.getName(), name)); }/*from w w w.j a v a 2s. c o m*/ return child; }
From source file:com.bc.ceres.binio.binx.BinX.java
License:Open Source License
private Element getChild(Element element, String name, int index, boolean require) throws BinXException { final List children = getChildren(element, null, require); if (children.size() <= index) { if (require) { if (name != null) { throw new BinXException( MessageFormat.format("Element ''{0}'': Expected to have a child ''{1}'' at index {2}", element.getName(), name, index)); } else { throw new BinXException(MessageFormat.format( "Element ''{0}'': Expected to have a child at index {1}", element.getName(), index)); }/*from w ww . j a v a 2 s . c o m*/ } else { return null; } } final Element child = (Element) children.get(index); if (name != null && !name.equals(child.getName())) { throw new BinXException(MessageFormat.format("Element ''{0}'': Expected child ''{1}'' at index {2}", element.getName(), name, index)); } return child; }
From source file:com.bc.ceres.binio.binx.BinX.java
License:Open Source License
private List getChildren(Element element, String name, boolean require) throws BinXException { final List children = element.getChildren(name, namespace); if (require && children.isEmpty()) { if (name != null) { throw new BinXException( MessageFormat.format("Element ''{0}'': Expected to have at least one child of ''{1}''", element.getName(), name)); } else {// w w w. jav a 2 s .c o m throw new BinXException(MessageFormat.format("Element ''{0}'': Expected to have at least one child", element.getName())); } } return children; }
From source file:com.bc.ceres.binio.binx.BinX.java
License:Open Source License
private static String getAttributeValue(Element element, String name, boolean require) throws BinXException { final String value = element.getAttributeValue(name); if (require && value == null) { throw new BinXException( MessageFormat.format("Element ''{0}'': attribute ''{1}'' not found.", element.getName(), name)); }/*w w w .java2s .c o m*/ return value != null ? value.trim() : value; }
From source file:com.bc.ceres.binio.binx.BinX.java
License:Open Source License
private static Integer getAttributeIntValue(Element element, String attributeName, boolean required) throws BinXException { final String value = getAttributeValue(element, attributeName, required); if (value == null) { return null; }/*from w w w. j a v a 2 s . c om*/ try { return Integer.valueOf(value); } catch (NumberFormatException e) { throw new BinXException(MessageFormat.format("Element ''{0}'': Attribute ''{1}'' must be an integer.", element.getName(), attributeName)); } }