List of usage examples for javax.xml.stream Location getColumnNumber
int getColumnNumber();
From source file:org.plasma.sdo.xml.StreamUnmarshaller.java
private void readCharacters(StreamProperty streamProperty, String data, XMLEvent event) throws UnmarshallerException { PlasmaType type = streamProperty.getType(); PlasmaProperty property = streamProperty.getProperty(); if (!property.getType().isDataType()) { Location loc = event.getLocation(); String msg = "line:col[" + loc.getLineNumber() + ":" + loc.getColumnNumber() + "]"; msg += " - cannot set reference propery (" + type.getURI() + "#" + type.getName() + "." + property.getName() + ") - from character data"; throw new UnmarshallerException(msg); }//from w ww . j a va2 s .c o m if (!property.isReadOnly()) { if (!property.isMany()) { Object value = PlasmaDataHelper.INSTANCE.convert(property, data); streamProperty.set(value); } else { Object value = PlasmaDataHelper.INSTANCE.convert(property, data); streamProperty.set(value); } } else { Location loc = event.getLocation(); String msg = "line:col[" + loc.getLineNumber() + ":" + loc.getColumnNumber() + "]"; msg += " - cannot set readonly propery (" + property.getName() + ") - ignoring character data '" + data + "' for readonly propery, " + type.getURI() + "#" + type.getName() + "." + property.getName(); log.warn(msg); } }
From source file:org.plasma.sdo.xml.StreamUnmarshaller.java
@SuppressWarnings("unchecked") private void readAttributes(XMLEvent event, StreamObject prototype) throws UnmarshallerException { boolean serialIdAttributeFound = false; PlasmaType type = prototype.getType(); Iterator<Attribute> iter = event.asStartElement().getAttributes(); while (iter.hasNext()) { Attribute attrib = (Attribute) iter.next(); QName attribName = attrib.getName(); String localPart = attribName.getLocalPart(); if (XMLConstants.ATTRIB_TARGET_NAMESPACE.equals(localPart)) { continue; } else if (XMLConstants.XMLSCHEMA_INSTANCE_NAMESPACE_URI.equals(attribName.getNamespaceURI())) { // its an XSI attribute we care about if ("type".equals(localPart)) { String xsiTypeLocalName = attrib.getValue(); int delim = xsiTypeLocalName.indexOf(":"); if (delim >= 0) xsiTypeLocalName = xsiTypeLocalName.substring(delim + 1); // In order to validate XML graphs with both containment // and non containment references with an XML schema, // the Schema types must be generated with XSI 'xsi:type' // attribute to indicate a subclass. The subclass name will be // either 1.) matching the local for the type, wherein we // assume a containment reference or 2.) matching a generated // synthetic name for the non-containment reference for the // type, e.g. 'MyTypeRef'. So for containment references // we should find 'xsi:type="prefix:MyType" and for // non-containment references we should find 'xsi:type="prefix:MyTypeRef" // or some other generated suffix with no name collisions. if (!xsiTypeLocalName.equals(type.getLocalName())) { if (log.isDebugEnabled()) log.debug("type as non-containment reference, " + type.getURI() + "#" + type.getName()); prototype.setNonContainmentReference(true); }/* w w w. jav a 2 s . co m*/ } continue; } PlasmaProperty property = findPropertyByLocalName(type, localPart); if (property == null) { if (!SchemaUtil.getSerializationAttributeName().equals(localPart)) { Location loc = event.getLocation(); String msg = "line:col[" + loc.getLineNumber() + ":" + loc.getColumnNumber() + "]"; msg += " - no property '" + localPart + "' found defined for type " + type.getURI() + "#" + type.getName(); throw new UnmarshallerException(msg); } else { prototype.setSerialId(attrib.getValue()); serialIdAttributeFound = true; continue; } } if (property.getType().isDataType()) { if (property.isMany()) { Location loc = event.getLocation(); String msg = "line:col[" + loc.getLineNumber() + ":" + loc.getColumnNumber() + "]"; msg += " - unexpected 'many' propery (" + type.getURI() + "#" + type.getName() + "." + property.getName() + ") can only set singular properties from attribute '" + localPart + "'"; throw new UnmarshallerException(msg); } Object value = PlasmaDataHelper.INSTANCE.convert(property, attrib.getValue()); if (!property.isReadOnly()) { prototype.set(property, value); } else { DataFlavor dataFlavor = property.getDataFlavor(); switch (dataFlavor) { case integral: Location loc = event.getLocation(); String msg = "line:col[" + loc.getLineNumber() + ":" + loc.getColumnNumber() + "]"; msg += " - cannot set integral readonly propery (" + property.getName() + ") - ignoring attribute data '" + attrib.getValue() + "' for readonly propery, " + type.getURI() + "#" + type.getName() + "." + property.getName(); log.warn(msg); break; default: prototype.set(property, value); } } } else { Location loc = event.getLocation(); String msg = "line:col[" + loc.getLineNumber() + ":" + loc.getColumnNumber() + "]"; msg += " - expected datatype property - attribute '" + localPart + "' is a reference property as defined in type " + type.getURI() + "#" + type.getName(); throw new UnmarshallerException(msg); } } if (!serialIdAttributeFound) { Location loc = event.getLocation(); String msg = "line:col[" + loc.getLineNumber() + ":" + loc.getColumnNumber() + "]"; msg += " - expected serialization attribute '" + SchemaUtil.getSerializationAttributeName() + "' for type " + type.getURI() + "#" + type.getName(); throw new UnmarshallerException(msg); } }
From source file:org.plasma.sdo.xml.StreamUnmarshaller.java
private PlasmaProperty getPropertyByLocalName(XMLEvent event, PlasmaType type, String localName) throws UnmarshallerException { PlasmaProperty property = findPropertyByLocalName(type, localName); if (property == null) { Location loc = event.getLocation(); String msg = "line:col[" + loc.getLineNumber() + ":" + loc.getColumnNumber() + "]"; msg += " - no property with local name (" + localName + ") found defined for type " + type.getURI() + "#" + type.getName(); ;/*from ww w . j av a 2s . c o m*/ throw new UnmarshallerException(msg); } return property; }