use of easik.xml.xsd.nodes.constraints.XSDAbstractKey in project fql by CategoricalData.
the class XSDElement method setKeys.
/**
* Use an entity node to set the keys, including foreign keyrefs and
* uniques.
* <p/>
* Key is set from the primary key. KeyRefs are set from the outgoing edges.
* Uniques are set by Uniques and by noninclusion injective outgoing edges.
*
* @param node
* we are working with
*/
@SuppressWarnings("unused")
public void setKeys(final EntityNode node) {
final List<UniqueKey<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>> uniqueKeyList = node.getUniqueKeys();
final XSDComplexType myType = (XSDComplexType) getElementType();
constraints = new ArrayList<XSDAbstractKey>(uniqueKeyList.size() + 3);
final String idName = Easik.getInstance().getSettings().getProperty("xml_id_name");
final String keyrefName = Easik.getInstance().getSettings().getProperty("xml_keyref_name");
final boolean idIsAttribute = Boolean.valueOf(Easik.getInstance().getSettings().getProperty("xml_id_is_attribute"));
final XSDKey primaryKey = node.createXMLPrimaryKey(this);
final XSDElement theParent = (XSDElement) getParent();
theParent.addConstraint(primaryKey);
for (final SketchEdge edge : node.getOutgoingEdges()) {
final boolean isInclusion = edge.getTargetEntity().getName().equals(theParent.getName());
if (edge.isInjective()) {
if (!isInclusion) {
constraints.add(new XSDUniqueKey(edge.getForeignKeyName(keyrefName), this, edge.getName()));
}
}
if (!isInclusion) {
theParent.addConstraint(new XSDKeyRef(this, edge.getTargetEntity().getXMLPrimaryKeyName(), edge.getName()));
myType.addAtom(new XSDElement(edge.getName(), edge.isPartial(), XSDBaseType.xsInt));
}
}
for (final UniqueKey<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> k : uniqueKeyList) {
this.addConstraint(new XSDUniqueKey(this, k));
}
}
use of easik.xml.xsd.nodes.constraints.XSDAbstractKey in project fql by CategoricalData.
the class XSDElement method getBody.
/**
* Text of the body of the tag, including embedded anonymous types and
* constraints
*
* @return XML body of this node.
*/
@Override
public String getBody() {
final StringBuilder ret = new StringBuilder(400);
if (null != contents) {
ret.append('<').append(nsPrefix).append(":complexType>").append(lineSep).append(contents.toString()).append(lineSep).append("</").append(nsPrefix).append(":complexType>").append(lineSep);
} else {
if (!getElementType().isReferencable()) {
ret.append(getElementType().toString());
}
}
if ((null != constraints) && (constraints.size() > 0)) {
for (final XSDAbstractKey uniq : constraints) {
ret.append(uniq.toString()).append(lineSep);
}
final int len = ret.length();
ret.delete(len - lineSep.length(), len);
}
return ret.toString();
}
Aggregations