use of org.eclipse.xsd.XSDFactory in project tmdm-studio-se by Talend.
the class XSDAnnotationsStructure method inputChanged.
protected void inputChanged(Object component) {
if (component instanceof XSDAnnotation) {
annotation = (XSDAnnotation) component;
if (annotation.getContainer() instanceof XSDElementDeclaration) {
declaration = (XSDElementDeclaration) annotation.getContainer();
} else if (annotation.getContainer() instanceof XSDComplexTypeDefinition) {
complexTypeDef = (XSDComplexTypeDefinition) annotation.getContainer();
}
}
if (component instanceof XSDElementDeclaration) {
declaration = (XSDElementDeclaration) component;
if (declaration.getAnnotation() == null) {
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
annotation = factory.createXSDAnnotation();
} else {
annotation = declaration.getAnnotation();
}
}
if (component instanceof XSDComplexTypeDefinition) {
complexTypeDef = (XSDComplexTypeDefinition) component;
componet = complexTypeDef;
if (complexTypeDef.getAnnotation() == null) {
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
annotation = factory.createXSDAnnotation();
} else {
annotation = complexTypeDef.getAnnotation();
}
}
if (component instanceof XSDModelGroup) {
XSDModelGroup group = (XSDModelGroup) component;
if (group.getContainer().getContainer() instanceof XSDComplexTypeDefinition) {
complexTypeDef = (XSDComplexTypeDefinition) group.getContainer().getContainer();
if (complexTypeDef.getAnnotation() == null) {
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
annotation = factory.createXSDAnnotation();
} else {
annotation = complexTypeDef.getAnnotation();
}
}
}
if (component instanceof XSDParticle) {
XSDTerm term = ((XSDParticle) component).getTerm();
if (term instanceof XSDElementDeclaration) {
declaration = (XSDElementDeclaration) term;
if (declaration.getAnnotation() == null) {
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
annotation = factory.createXSDAnnotation();
} else {
annotation = declaration.getAnnotation();
}
}
}
}
use of org.eclipse.xsd.XSDFactory in project tmdm-studio-se by Talend.
the class XSDGenerateHTML method loadAndPrint.
/**
* Load the XML Schema file and print the documentation based on it.
*
* @param xsdFile the name of an XML Schema file.
*/
public void loadAndPrint(String xsdFile) throws Exception {
XSDFactory xsdFactory = XSDFactory.eINSTANCE;
// Create a resource set and load the main schema file into it.
//
ResourceSet resourceSet = new ResourceSetImpl();
XSDResourceImpl xsdResource = (XSDResourceImpl) resourceSet.getResource(URI.createFileURI(xsdFile), true);
XSDSchema xsdSchema = xsdResource.getSchema();
// $NON-NLS-1$
String elementContentHeaderDocumentation = getContentDocumentation("element-header");
if (elementContentHeaderDocumentation != null) {
System.out.println(elementContentHeaderDocumentation);
}
List all = new ArrayList(xsdSchema.getElementDeclarations());
// $NON-NLS-1$
XSDElementDeclaration simpleContent = xsdSchema.resolveElementDeclaration("simpleContent");
// $NON-NLS-1$
XSDElementDeclaration complexContent = xsdSchema.resolveElementDeclaration("complexContent");
for (int i = 0; i <= 1; ++i) {
for (int j = 0; j <= 1; ++j) {
XSDElementDeclaration parentElement = (i == 0 ? complexContent : simpleContent);
XSDComplexTypeDefinition xsdComplexTypeDefinition = (XSDComplexTypeDefinition) parentElement.getTypeDefinition();
XSDElementDeclaration specialElementDeclaration = (XSDElementDeclaration) ((XSDParticle) ((XSDModelGroup) ((XSDParticle) ((XSDModelGroup) ((XSDParticle) (xsdComplexTypeDefinition.getContentType())).getTerm()).getParticles().get(1)).getTerm()).getParticles().get(j)).getTerm();
all.add(specialElementDeclaration);
specialAnchorMap.put(specialElementDeclaration, parentElement);
}
}
all = XSDNamedComponentImpl.sortNamedComponents(all);
for (Iterator i = all.iterator(); i.hasNext(); ) {
XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration) i.next();
XSDElementDeclaration parentElementDeclaration = (XSDElementDeclaration) specialAnchorMap.get(xsdElementDeclaration);
String elementDeclarationName = xsdElementDeclaration.getName();
String key = // $NON-NLS-1$ //$NON-NLS-2$
(parentElementDeclaration == null ? "" : parentElementDeclaration.getName() + "::") + elementDeclarationName;
String elementDeclarationMarkup = getElementDeclarationMarkup(key);
// $NON-NLS-1$
System.out.print("<h2>");
System.out.print(elementDeclarationName.substring(0, 1).toUpperCase());
System.out.print(elementDeclarationName.substring(1));
// $NON-NLS-1$
System.out.println("</h2>");
// $NON-NLS-1$
System.out.println("<div class='reprdef'>");
// $NON-NLS-1$
System.out.println("<table cols=1 width='100%'><tr><td>");
System.out.print(// $NON-NLS-1$
"<div class='reprHeader'><span class='reprdef'>XML Representation Summary: </span><code>");
// $NON-NLS-1$ //$NON-NLS-2$
System.out.print("<a name='" + getLocalAnchor(xsdElementDeclaration) + "'>");
System.out.print(getStandardLink(xsdElementDeclaration));
System.out.print(elementDeclarationName);
// $NON-NLS-1$
System.out.print("</a></a></code>");
// $NON-NLS-1$
System.out.print(" Element Information Item ");
if (parentElementDeclaration != null) {
// $NON-NLS-1$
System.out.print("<small>(");
// $NON-NLS-1$ //$NON-NLS-2$
System.out.print("<a href='#" + getLocalAnchor(parentElementDeclaration) + "'>");
System.out.print(parentElementDeclaration.getName());
// $NON-NLS-1$
System.out.print("</a>)</small>");
} else if ("restriction".equals(elementDeclarationName)) {
// $NON-NLS-1$
// $NON-NLS-1$
System.out.print("<small>(simpleType)</small>");
}
// $NON-NLS-1$
System.out.println("</div>");
// $NON-NLS-1$
System.out.println("<div class='reprBody'>");
if (elementDeclarationMarkup != null) {
// $NON-NLS-1$ //$NON-NLS-2$
System.out.print("<div class='" + elementDeclarationMarkup + "'>");
}
// $NON-NLS-1$
System.out.print("<tt><");
System.out.print(elementDeclarationName);
// $NON-NLS-1$
System.out.print("</tt>");
String componentLinks = getComponentLinks(xsdElementDeclaration);
if (componentLinks != null) {
System.out.print(componentLinks);
}
// $NON-NLS-1$
System.out.println("<br>");
StringBuffer attributeDocumentationBuffer = new StringBuffer();
Map repeatedDocumentationMap = new HashMap();
XSDTypeDefinition xsdTypeDefinition = xsdElementDeclaration.getTypeDefinition();
XSDComplexTypeDefinition generalType = xsdSchema.resolveComplexTypeDefinitionURI(xsdElementDeclaration.getURI());
if (generalType.getContainer() != null) {
xsdTypeDefinition = generalType;
}
if (xsdTypeDefinition instanceof XSDSimpleTypeDefinition) {
// $NON-NLS-1$
System.out.println("<tt>></tt><br>");
} else if (xsdTypeDefinition instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition xsdComplexTypeDefinition = (XSDComplexTypeDefinition) xsdTypeDefinition;
for (Iterator attributeUses = xsdComplexTypeDefinition.getAttributeUses().iterator(); attributeUses.hasNext(); ) {
XSDAttributeUse xsdAttributeUse = (XSDAttributeUse) attributeUses.next();
XSDAttributeDeclaration xsdAttributeDeclaration = xsdAttributeUse.getAttributeDeclaration();
String attributeDeclarationName = xsdAttributeDeclaration.getName();
// $NON-NLS-1$
System.out.print("<tt> ");
if (xsdAttributeDeclaration.getTargetNamespace() != null) {
// $NON-NLS-1$
System.out.print("xml:");
}
String attributeDeclarationMarkup = null;
String attributeDeclarationDocumentation = null;
if (!"ignored".equals(elementDeclarationMarkup)) {
// $NON-NLS-1$
attributeDeclarationMarkup = getAttributeDeclarationMarkup(attributeDeclarationName);
if (attributeDeclarationMarkup == null) {
attributeDeclarationMarkup = getAttributeDeclarationMarkup(// $NON-NLS-1$
elementDeclarationName + "." + attributeDeclarationName);
}
attributeDeclarationDocumentation = getAttributeDeclarationDocumentation(attributeDeclarationName);
if (attributeDeclarationDocumentation == null) {
attributeDeclarationDocumentation = getAttributeDeclarationDocumentation(// $NON-NLS-1$
elementDeclarationName + "." + attributeDeclarationName);
}
}
if (attributeDeclarationDocumentation != null) {
Integer oldInsertIndex = (Integer) repeatedDocumentationMap.get(attributeDeclarationDocumentation);
if (oldInsertIndex != null) {
// $NON-NLS-1$
String insertion = "<br>" + attributeDeclarationName;
attributeDocumentationBuffer.insert(oldInsertIndex.intValue(), insertion);
repeatedDocumentationMap.put(attributeDeclarationDocumentation, new Integer(oldInsertIndex.intValue() + insertion.length()));
} else {
if (attributeDocumentationBuffer.length() == 0) {
// $NON-NLS-1$
attributeDocumentationBuffer.append("<table cols=2 width='100%'>\n");
attributeDocumentationBuffer.append(// $NON-NLS-1$
"<tr>\n<th width=25% valign=top align=left><b>Attribute</b></th>\n");
attributeDocumentationBuffer.append(// $NON-NLS-1$
"<th width=75% valign=top align=left><b>Description</b></th>\n</tr>\n");
}
// $NON-NLS-1$
attributeDocumentationBuffer.append("<tr><td><b>");
if (attributeDeclarationMarkup != null) {
// $NON-NLS-1$ //$NON-NLS-2$
attributeDocumentationBuffer.append("<span class='" + attributeDeclarationMarkup + "'>");
}
attributeDocumentationBuffer.append(attributeDeclarationName);
int insertIndex = attributeDocumentationBuffer.length();
if (attributeDeclarationMarkup != null) {
// $NON-NLS-1$
attributeDocumentationBuffer.append("</span>");
}
// $NON-NLS-1$
attributeDocumentationBuffer.append("</b></td>\n<td valign=top>\n");
attributeDocumentationBuffer.append(attributeDeclarationDocumentation);
// $NON-NLS-1$
attributeDocumentationBuffer.append("</td></tr>");
repeatedDocumentationMap.put(attributeDeclarationDocumentation, new Integer(insertIndex));
}
}
if (attributeDeclarationMarkup != null) {
// $NON-NLS-1$ //$NON-NLS-2$
System.out.print("<span class='" + attributeDeclarationMarkup + "'>");
}
if (xsdAttributeUse.isRequired()) {
// $NON-NLS-1$
System.out.print("<b>");
System.out.print(attributeDeclarationName);
// $NON-NLS-1$
System.out.print("</b>");
} else {
System.out.print(attributeDeclarationName);
}
if (attributeDeclarationMarkup != null) {
// $NON-NLS-1$
System.out.print("</span>");
}
// $NON-NLS-1$
System.out.print(" = </tt>");
XSDSimpleTypeDefinition xsdSimpleTypeDefinition = xsdAttributeDeclaration.getTypeDefinition();
printSimpleTypeDefinition(xsdSimpleTypeDefinition);
if (xsdAttributeUse.getLexicalValue() != null) {
// $NON-NLS-1$
System.out.print(" : ");
if ("".equals(xsdAttributeUse.getLexicalValue())) {
// $NON-NLS-1$
// $NON-NLS-1$
System.out.print("\"\"");
} else {
System.out.print(xsdAttributeUse.getLexicalValue());
}
}
if (attributeUses.hasNext()) {
// $NON-NLS-1$
System.out.println("<br>");
}
}
if (xsdComplexTypeDefinition.getAttributeWildcard() != null) {
// $NON-NLS-1$
System.out.println("<br>");
System.out.println(// $NON-NLS-1$
"<span class='" + ALLOWS + // $NON-NLS-1$
"'><tt><em> { any attributes with non-schema namespace . . . }</em></tt></span>");
}
// $NON-NLS-1$
System.out.println("<tt>></tt><br>");
if (xsdComplexTypeDefinition.getContentType() instanceof XSDParticle) {
// $NON-NLS-1$
System.out.print("<tt><em> Content:</em> ");
printParticle((XSDParticle) xsdComplexTypeDefinition.getContentType(), elementDeclarationMarkup);
// $NON-NLS-1$
System.out.print("</tt>");
} else if (xsdComplexTypeDefinition.getContentType() instanceof XSDSimpleTypeDefinition) {
// $NON-NLS-1$
System.out.print("<b>***** simple</b>");
} else {
// $NON-NLS-1$
System.out.print("<b>{ **** empty }</b>");
}
// $NON-NLS-1$
System.out.println("<br>");
}
// $NON-NLS-1$
System.out.print("<tt></");
System.out.print(elementDeclarationName);
// $NON-NLS-1$
System.out.println("></tt>");
if (elementDeclarationMarkup != null) {
// $NON-NLS-1$
System.out.print("</div>");
}
// $NON-NLS-1$
System.out.println("</div>");
String elementDeclarationDocumentation = getElementDeclarationDocumentation(key);
if (elementDeclarationDocumentation != null) {
// $NON-NLS-1$
System.out.println("<div class='reprBody'>");
System.out.println(elementDeclarationDocumentation);
// $NON-NLS-1$
System.out.println("</div>");
}
if (attributeDocumentationBuffer.length() > 0) {
// $NON-NLS-1$
System.out.println("<div class='reprBody'>");
System.out.print(attributeDocumentationBuffer);
// $NON-NLS-1$
System.out.println("</table>");
// $NON-NLS-1$
System.out.println("</div>");
}
// $NON-NLS-1$
System.out.println("</td></tr></table>");
// $NON-NLS-1$
System.out.println("</div>");
}
// System.out.println("<h1>Built-in Datatypes</h1>");
// $NON-NLS-1$
String typeContentHeaderDocumentation = getContentDocumentation("type-header");
if (typeContentHeaderDocumentation != null) {
System.out.println(typeContentHeaderDocumentation);
}
// $NON-NLS-1$
System.out.println("<table border=true cols=3 width='100%'>");
// $NON-NLS-1$
System.out.println("<tr>");
// $NON-NLS-1$
System.out.println("<th width=33% valign=top align=left><b>Type</b></th>");
// $NON-NLS-1$
System.out.println("<th width=33% valign=top align=left><b>Properties & Facets</b></th>");
// $NON-NLS-1$
System.out.println("<th width=34% valign=top align=left><b>Effective Value</b></th>");
// $NON-NLS-1$
System.out.println("</tr>");
// $NON-NLS-1$
XSDSimpleTypeDefinition anyTypeDefinition = xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("anyType");
XSDSimpleTypeDefinition anySimpleTypeDefinition = xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition(// $NON-NLS-1$
"anySimpleType");
XSDSimpleTypeDefinition anyListTypeDefinition = xsdFactory.createXSDSimpleTypeDefinition();
anyListTypeDefinition.setVariety(XSDVariety.LIST_LITERAL);
// $NON-NLS-1$
anyListTypeDefinition.setName("anyListType");
anyListTypeDefinition.setItemTypeDefinition(anySimpleTypeDefinition);
xsdSchema.getContents().add(anyListTypeDefinition);
// $NON-NLS-1$
anyListTypeDefinition.getElement().setAttribute(XSDConstants.ID_ATTRIBUTE, "anyListType");
XSDSimpleTypeDefinition anyUnionTypeDefinition = xsdFactory.createXSDSimpleTypeDefinition();
anyUnionTypeDefinition.setVariety(XSDVariety.UNION_LITERAL);
// $NON-NLS-1$
anyUnionTypeDefinition.setName("anyUnionType");
anyUnionTypeDefinition.getMemberTypeDefinitions().add(anySimpleTypeDefinition);
xsdSchema.getContents().add(anyUnionTypeDefinition);
// $NON-NLS-1$
anyUnionTypeDefinition.getElement().setAttribute(XSDConstants.ID_ATTRIBUTE, "anyUnionType");
List allTypeDefinitions = new ArrayList(xsdSchema.getTypeDefinitions());
allTypeDefinitions.add(0, anySimpleTypeDefinition);
allTypeDefinitions.add(0, anyTypeDefinition);
for (Iterator i = allTypeDefinitions.iterator(); i.hasNext(); ) {
XSDTypeDefinition xsdTypeDefinition = (XSDTypeDefinition) i.next();
if (xsdTypeDefinition instanceof XSDSimpleTypeDefinition && xsdTypeDefinition.getElement() != null && xsdTypeDefinition.getName().equals(xsdTypeDefinition.getElement().getAttribute(XSDConstants.ID_ATTRIBUTE))) {
XSDSimpleTypeDefinition xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) xsdTypeDefinition;
// $NON-NLS-1$
System.out.println("<tr>");
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("<a name='" + xsdSimpleTypeDefinition.getName() + "-simple-type'>");
// $NON-NLS-1$
System.out.println("<td>");
boolean isPrimitive = XSDVariety.ATOMIC_LITERAL == xsdSimpleTypeDefinition.getVariety() && xsdSimpleTypeDefinition.getBaseTypeDefinition() == anySimpleTypeDefinition;
if (isPrimitive) {
// $NON-NLS-1$
System.out.print("<b>");
}
System.out.print(getSimpleTypeDefinitionLink(xsdSimpleTypeDefinition));
if (isPrimitive) {
// $NON-NLS-1$
System.out.print("</b>");
}
for (XSDSimpleTypeDefinition baseTypeDefinition = xsdSimpleTypeDefinition; ; baseTypeDefinition = baseTypeDefinition.getBaseTypeDefinition()) {
String javaClass = (String) schemaTypeToJavaClassMap.get(baseTypeDefinition.getName());
if (javaClass != null) {
// $NON-NLS-1$
System.out.println("<br> <br>");
if (baseTypeDefinition == xsdSimpleTypeDefinition) {
// ) //$NON-NLS-1$
System.out.print("<b>");
}
// $NON-NLS-1$
int dotIndex = javaClass.lastIndexOf(".");
// $NON-NLS-1$
System.out.print("<font size=-2>");
System.out.print(javaClass.substring(0, dotIndex + 1));
// $NON-NLS-1$
System.out.print("</font><br> ");
System.out.print(javaClass.substring(dotIndex + 1));
if (baseTypeDefinition == xsdSimpleTypeDefinition) {
// (
// $NON-NLS-1$
System.out.print("<b>");
}
System.out.println();
break;
}
}
// $NON-NLS-1$
System.out.println("<br>");
// $NON-NLS-1$
System.out.println("</td>");
// $NON-NLS-1$
System.out.println("</a>");
StringBuffer validFacets = new StringBuffer();
StringBuffer effectiveFacetValues = new StringBuffer();
// $NON-NLS-1$
validFacets.append("variety<br>\n");
effectiveFacetValues.append(xsdSimpleTypeDefinition.isSetVariety() ? // $NON-NLS-1$
"<b>" + xsdSimpleTypeDefinition.getVariety() + "</b>" : // $NON-NLS-1$ //$NON-NLS-2$
"<em>absent</em>");
// $NON-NLS-1$
effectiveFacetValues.append("<br>\n");
// $NON-NLS-1$
validFacets.append("base type definition<br>\n");
XSDSimpleTypeDefinition baseTypeDefinition = xsdSimpleTypeDefinition.getBaseTypeDefinition();
while (baseTypeDefinition.getName() == null) {
baseTypeDefinition = baseTypeDefinition.getBaseTypeDefinition();
}
// $NON-NLS-1$
effectiveFacetValues.append("<a href='#");
effectiveFacetValues.append(baseTypeDefinition.getName());
// $NON-NLS-1$
effectiveFacetValues.append("-simple-type'>");
effectiveFacetValues.append(baseTypeDefinition.getName());
// $NON-NLS-1$
effectiveFacetValues.append("</a><br>\n");
// $NON-NLS-1$
validFacets.append("ordered<br>\n");
effectiveFacetValues.append(// $NON-NLS-1$ //$NON-NLS-2$
"anyUnionType".equals(xsdSimpleTypeDefinition.getName()) ? // $NON-NLS-1$ //$NON-NLS-2$
"*" : xsdSimpleTypeDefinition.getOrderedFacet().getValue().getName());
// $NON-NLS-1$
effectiveFacetValues.append("<br>\n");
// $NON-NLS-1$
validFacets.append("bounded<br>\n");
effectiveFacetValues.append(// $NON-NLS-1$ //$NON-NLS-2$
"anyUnionType".equals(xsdSimpleTypeDefinition.getName()) ? // $NON-NLS-1$ //$NON-NLS-2$
"*" : // $NON-NLS-1$ //$NON-NLS-2$
xsdSimpleTypeDefinition.getBoundedFacet().isValue() ? "true" : "false");
// $NON-NLS-1$
effectiveFacetValues.append("<br>\n");
// $NON-NLS-1$
validFacets.append("cardinality<br>\n");
effectiveFacetValues.append(// $NON-NLS-1$ //$NON-NLS-2$
"anyUnionType".equals(xsdSimpleTypeDefinition.getName()) ? // $NON-NLS-1$ //$NON-NLS-2$
"*" : XSDCardinality.COUNTABLY_INFINITE_LITERAL == xsdSimpleTypeDefinition.getCardinalityFacet().getValue() ? "countably infinite" : // $NON-NLS-1$
xsdSimpleTypeDefinition.getCardinalityFacet().getValue().getName());
// $NON-NLS-1$
effectiveFacetValues.append("<br>\n");
// $NON-NLS-1$
validFacets.append("numeric<br>\n");
effectiveFacetValues.append(// $NON-NLS-1$ //$NON-NLS-2$
"anyUnionType".equals(xsdSimpleTypeDefinition.getName()) ? // $NON-NLS-1$ //$NON-NLS-2$
"*" : // $NON-NLS-1$ //$NON-NLS-2$
xsdSimpleTypeDefinition.getNumericFacet().isValue() ? "true" : "false");
// $NON-NLS-1$
effectiveFacetValues.append("<br>\n");
if (xsdSimpleTypeDefinition.getValidFacets().contains("length")) {
// $NON-NLS-1$
// $NON-NLS-1$
validFacets.append("length<br>\n");
if (xsdSimpleTypeDefinition.getEffectiveLengthFacet() != null) {
XSDLengthFacet xsdLengthFacet = xsdSimpleTypeDefinition.getEffectiveLengthFacet();
if (xsdLengthFacet.isFixed()) {
// $NON-NLS-1$
effectiveFacetValues.append("<b>");
}
effectiveFacetValues.append(xsdLengthFacet.getValue());
if (xsdLengthFacet.isFixed()) {
// $NON-NLS-1$
effectiveFacetValues.append("</b>");
}
}
// $NON-NLS-1$
effectiveFacetValues.append("<br>\n");
}
if (xsdSimpleTypeDefinition.getValidFacets().contains("minLength")) {
// $NON-NLS-1$
// $NON-NLS-1$
validFacets.append("minLength<br>\n");
if (xsdSimpleTypeDefinition.getEffectiveMinLengthFacet() != null) {
XSDMinLengthFacet xsdMinLengthFacet = xsdSimpleTypeDefinition.getEffectiveMinLengthFacet();
if (xsdMinLengthFacet.isFixed()) {
// $NON-NLS-1$
effectiveFacetValues.append("<b>");
}
effectiveFacetValues.append(xsdMinLengthFacet.getValue());
if (xsdMinLengthFacet.isFixed()) {
// $NON-NLS-1$
effectiveFacetValues.append("</b>");
}
}
// $NON-NLS-1$
effectiveFacetValues.append("<br>\n");
}
if (xsdSimpleTypeDefinition.getValidFacets().contains("maxLength")) {
// $NON-NLS-1$
// $NON-NLS-1$
validFacets.append("maxLength<br>\n");
if (xsdSimpleTypeDefinition.getEffectiveMaxLengthFacet() != null) {
XSDMaxLengthFacet xsdMaxLengthFacet = xsdSimpleTypeDefinition.getEffectiveMaxLengthFacet();
if (xsdMaxLengthFacet.isFixed()) {
// $NON-NLS-1$
effectiveFacetValues.append("<b>");
}
effectiveFacetValues.append(xsdMaxLengthFacet.getValue());
if (xsdMaxLengthFacet.isFixed()) {
// $NON-NLS-1$
effectiveFacetValues.append("</b>");
}
}
// $NON-NLS-1$
effectiveFacetValues.append("<br>\n");
}
if (xsdSimpleTypeDefinition.getValidFacets().contains("pattern")) {
// $NON-NLS-1$
// $NON-NLS-1$
validFacets.append("pattern<br>\n");
if (xsdSimpleTypeDefinition.getEffectivePatternFacet() != null) {
// XSDPatternFacet xsdPatternFacet =
// xsdSimpleTypeDefinition.getEffectivePatternFacet();
// $NON-NLS-1$
effectiveFacetValues.append("*");
}
// $NON-NLS-1$
effectiveFacetValues.append("<br>\n");
}
if (xsdSimpleTypeDefinition.getValidFacets().contains("enumeration")) {
// $NON-NLS-1$
// $NON-NLS-1$
validFacets.append("enumeration<br>\n");
if (xsdSimpleTypeDefinition.getEffectiveEnumerationFacet() != null) {
XSDEnumerationFacet xsdEnumerationFacet = xsdSimpleTypeDefinition.getEffectiveEnumerationFacet();
for (Iterator enumerators = xsdEnumerationFacet.getValue().iterator(); enumerators.hasNext(); ) {
String enumerator = (String) enumerators.next();
effectiveFacetValues.append(enumerator);
// $NON-NLS-1$
effectiveFacetValues.append(" ");
}
}
// $NON-NLS-1$
effectiveFacetValues.append("<br>\n");
}
if (xsdSimpleTypeDefinition.getValidFacets().contains("whiteSpace")) {
// $NON-NLS-1$
// $NON-NLS-1$
validFacets.append("whiteSpace<br>\n");
if (xsdSimpleTypeDefinition.getEffectiveWhiteSpaceFacet() != null) {
XSDWhiteSpaceFacet xsdWhiteSpaceFacet = xsdSimpleTypeDefinition.getEffectiveWhiteSpaceFacet();
if (xsdWhiteSpaceFacet.isFixed()) {
// $NON-NLS-1$
effectiveFacetValues.append("<b>");
}
effectiveFacetValues.append(xsdWhiteSpaceFacet.getValue());
if (xsdWhiteSpaceFacet.isFixed()) {
// $NON-NLS-1$
effectiveFacetValues.append("</b>");
}
}
// $NON-NLS-1$
effectiveFacetValues.append("<br>\n");
}
if (xsdSimpleTypeDefinition.getValidFacets().contains("maxInclusive")) {
// $NON-NLS-1$
// $NON-NLS-1$
validFacets.append("maxInclusive<br>\n");
if (xsdSimpleTypeDefinition.getEffectiveMaxFacet() instanceof XSDMaxInclusiveFacet) {
XSDMaxInclusiveFacet xsdMaxInclusiveFacet = (XSDMaxInclusiveFacet) xsdSimpleTypeDefinition.getEffectiveMaxFacet();
if (xsdMaxInclusiveFacet.isFixed()) {
// $NON-NLS-1$
effectiveFacetValues.append("<b>");
}
effectiveFacetValues.append(xsdMaxInclusiveFacet.getValue());
if (xsdMaxInclusiveFacet.isFixed()) {
// $NON-NLS-1$
effectiveFacetValues.append("</b>");
}
}
// $NON-NLS-1$
effectiveFacetValues.append("<br>\n");
}
if (xsdSimpleTypeDefinition.getValidFacets().contains("maxExclusive")) {
// $NON-NLS-1$
// $NON-NLS-1$
validFacets.append("maxExclusive<br>\n");
if (xsdSimpleTypeDefinition.getEffectiveMaxFacet() instanceof XSDMaxExclusiveFacet) {
XSDMaxExclusiveFacet xsdMaxExclusiveFacet = (XSDMaxExclusiveFacet) xsdSimpleTypeDefinition.getEffectiveMaxFacet();
if (xsdMaxExclusiveFacet.isFixed()) {
// $NON-NLS-1$
effectiveFacetValues.append("<b>");
}
effectiveFacetValues.append(xsdMaxExclusiveFacet.getValue());
if (xsdMaxExclusiveFacet.isFixed()) {
// $NON-NLS-1$
effectiveFacetValues.append("</b>");
}
}
// $NON-NLS-1$
effectiveFacetValues.append("<br>\n");
}
if (xsdSimpleTypeDefinition.getValidFacets().contains("minInclusive")) {
// $NON-NLS-1$
// $NON-NLS-1$
validFacets.append("maxInclusive<br>\n");
if (xsdSimpleTypeDefinition.getEffectiveMinFacet() instanceof XSDMinInclusiveFacet) {
XSDMinInclusiveFacet xsdMinInclusiveFacet = (XSDMinInclusiveFacet) xsdSimpleTypeDefinition.getEffectiveMinFacet();
if (xsdMinInclusiveFacet.isFixed()) {
// $NON-NLS-1$
effectiveFacetValues.append("<b>");
}
effectiveFacetValues.append(xsdMinInclusiveFacet.getValue());
if (xsdMinInclusiveFacet.isFixed()) {
// $NON-NLS-1$
effectiveFacetValues.append("</b>");
}
}
// $NON-NLS-1$
effectiveFacetValues.append("<br>\n");
}
if (xsdSimpleTypeDefinition.getValidFacets().contains("minExclusive")) {
// $NON-NLS-1$
// $NON-NLS-1$
validFacets.append("maxExclusive<br>\n");
if (xsdSimpleTypeDefinition.getEffectiveMinFacet() instanceof XSDMinExclusiveFacet) {
XSDMinExclusiveFacet xsdMinExclusiveFacet = (XSDMinExclusiveFacet) xsdSimpleTypeDefinition.getEffectiveMinFacet();
if (xsdMinExclusiveFacet.isFixed()) {
// $NON-NLS-1$
effectiveFacetValues.append("<b>");
}
effectiveFacetValues.append(xsdMinExclusiveFacet.getValue());
if (xsdMinExclusiveFacet.isFixed()) {
// $NON-NLS-1$
effectiveFacetValues.append("</b>");
}
}
// $NON-NLS-1$
effectiveFacetValues.append("<br>\n");
}
if (xsdSimpleTypeDefinition.getValidFacets().contains("totalDigits")) {
// $NON-NLS-1$
// $NON-NLS-1$
validFacets.append("totalDigits<br>\n");
if (xsdSimpleTypeDefinition.getEffectiveTotalDigitsFacet() != null) {
XSDTotalDigitsFacet xsdTotalDigitsFacet = xsdSimpleTypeDefinition.getEffectiveTotalDigitsFacet();
if (xsdTotalDigitsFacet.isFixed()) {
// $NON-NLS-1$
effectiveFacetValues.append("<b>");
}
effectiveFacetValues.append(xsdTotalDigitsFacet.getValue());
if (xsdTotalDigitsFacet.isFixed()) {
// $NON-NLS-1$
effectiveFacetValues.append("</b>");
}
}
// $NON-NLS-1$
effectiveFacetValues.append("<br>\n");
}
if (xsdSimpleTypeDefinition.getValidFacets().contains("fractionDigits")) {
// $NON-NLS-1$
// $NON-NLS-1$
validFacets.append("fractionDigits<br>\n");
if (xsdSimpleTypeDefinition.getEffectiveFractionDigitsFacet() != null) {
XSDFractionDigitsFacet xsdFractionDigitsFacet = xsdSimpleTypeDefinition.getEffectiveFractionDigitsFacet();
if (xsdFractionDigitsFacet.isFixed()) {
// $NON-NLS-1$
effectiveFacetValues.append("<b>");
}
effectiveFacetValues.append(xsdFractionDigitsFacet.getValue());
if (xsdFractionDigitsFacet.isFixed()) {
// $NON-NLS-1$
effectiveFacetValues.append("</b>");
}
}
// $NON-NLS-1$
effectiveFacetValues.append("<br>\n");
}
// $NON-NLS-1$
System.out.println("<td>");
System.out.print(validFacets);
// $NON-NLS-1$
System.out.println("</td>");
// $NON-NLS-1$
System.out.print("<td>");
System.out.println(effectiveFacetValues);
// $NON-NLS-1$
System.out.println("</td>");
// $NON-NLS-1$
System.out.println("</tr>");
}
}
// $NON-NLS-1$
System.out.println("</table>");
// $NON-NLS-1$
String appendixContentHeaderDocumentation = getContentDocumentation("appendix-header");
if (appendixContentHeaderDocumentation != null) {
System.out.println(appendixContentHeaderDocumentation);
}
}
use of org.eclipse.xsd.XSDFactory in project tmdm-studio-se by Talend.
the class XSDEditParticleAction method doAction.
@Override
public IStatus doAction() {
try {
IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
String originalXpath = getOriginalXpath();
// $NON-NLS-1$
String entity = originalXpath.substring(0, originalXpath.indexOf("/"));
selParticle = (XSDParticle) selection.getFirstElement();
if (!(selParticle.getTerm() instanceof XSDElementDeclaration)) {
return Status.CANCEL_STATUS;
}
XSDElementDeclaration decl = (XSDElementDeclaration) selParticle.getContent();
XSDElementDeclaration ref = null;
if (decl.isElementDeclarationReference()) {
// it is a ref
ref = decl.getResolvedElementDeclaration();
}
EList eDecls = decl.getSchema().getElementDeclarations();
ArrayList<String> elementDeclarations = new ArrayList<String>();
for (Iterator iter = eDecls.iterator(); iter.hasNext(); ) {
XSDElementDeclaration d = (XSDElementDeclaration) iter.next();
if (d.getTargetNamespace() != null && d.getTargetNamespace().equals(IConstants.DEFAULT_NAME_SPACE)) {
continue;
}
if (!d.getQName().equals(entity)) {
elementDeclarations.add(// $NON-NLS-1$ //$NON-NLS-2$
d.getQName() + (d.getTargetNamespace() != null ? " : " + d.getTargetNamespace() : ""));
}
}
// $NON-NLS-1$
elementDeclarations.add("");
XSDIdentityConstraintDefinition identify = null;
XSDXPathDefinition keyPath = null;
List<Object> keyInfo = Util.getKeyInfo(decl);
boolean isPK = false;
if (keyInfo != null && keyInfo.size() > 0) {
identify = (XSDIdentityConstraintDefinition) keyInfo.get(0);
keyPath = (XSDXPathDefinition) keyInfo.get(1);
isPK = true;
}
initEleName = decl.getName();
dialog = new BusinessElementInputDialog(this, page.getSite().getShell(), Messages.XSDEditParticleAction_InputDialogTitle, decl.getName(), ref == null ? null : ref.getQName(), elementDeclarations, selParticle.getMinOccurs(), selParticle.getMaxOccurs(), false, isPK);
dialog.setBlockOnOpen(true);
int ret = dialog.open();
if (ret == Window.CANCEL) {
return Status.CANCEL_STATUS;
}
if (keyPath != null) {
identify.getFields().remove(keyPath);
}
// find reference
XSDElementDeclaration newRef = null;
if (!"".equals(refName.trim())) {
// $NON-NLS-1$
newRef = Util.findReference(refName, schema);
if (newRef == null) {
MessageDialog.openError(this.page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDEditParticleAction_ErrorMsg, refName));
return Status.CANCEL_STATUS;
}
}
// ref
// update validation rule
Set<String> paths = new HashSet<String>();
Util.collectElementPaths((IStructuredContentProvider) page.getElementsViewer().getContentProvider(), page.getSite(), selParticle, paths, null);
//
// $NON-NLS-1$
decl.setName("".equals(this.elementName) ? null : this.elementName);
if (keyPath != null) {
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
XSDXPathDefinition field = factory.createXSDXPathDefinition();
field.setVariety(keyPath.getVariety());
field.setValue(elementName);
identify.getFields().add(field);
}
if (newRef != null) {
decl.setResolvedElementDeclaration(newRef);
decl.setTypeDefinition(null);
Element elem = decl.getElement();
if (elem.getAttributes().getNamedItem("type") != null) {
// $NON-NLS-1$
elem.getAttributes().removeNamedItem("type");
}
decl.updateElement();
} else if (ref != null) {
// fliu
// no more element declarations --> we create a new Declaration with String simpleType definition
// instead
// FIXME: dereferecning and element is buggy
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
XSDElementDeclaration newD = factory.createXSDElementDeclaration();
newD.setName(this.elementName);
newD.updateElement();
XSDSimpleTypeDefinition stringType = ((SchemaTreeContentProvider) page.getTreeViewer().getContentProvider()).getXsdSchema().getSchemaForSchema().resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, // $NON-NLS-1$
"string");
newD.setTypeDefinition(stringType);
if (selParticle.getContainer() instanceof XSDModelGroup) {
XSDModelGroup group = ((XSDModelGroup) selParticle.getContainer());
((XSDModelGroup) selParticle.getContainer()).getContents().remove(selParticle);
selParticle = factory.createXSDParticle();
selParticle.setContent(newD);
group.getContents().add(selParticle);
}
}
if (Util.changeElementTypeToSequence(decl, maxOccurs) == Status.CANCEL_STATUS) {
return Status.CANCEL_STATUS;
}
selParticle.setMinOccurs(this.minOccurs);
if (maxOccurs > -1) {
selParticle.setMaxOccurs(this.maxOccurs);
} else {
if (selParticle.getElement().getAttributeNode("maxOccurs") != null) {
// $NON-NLS-1$//$NON-NLS-2$
selParticle.getElement().getAttributeNode("maxOccurs").setNodeValue("unbounded");
} else {
// $NON-NLS-1$//$NON-NLS-2$
selParticle.getElement().setAttribute("maxOccurs", "unbounded");
}
}
selParticle.updateElement();
updateReference(originalXpath);
if (elementExAdapter != null) {
elementExAdapter.renameElement(decl.getSchema(), paths, decl.getName());
}
if (mapinfoExAdapter != null) {
mapinfoExAdapter.renameElementMapinfo(paths, decl.getName());
}
page.refresh();
page.markDirty();
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDEditParticleAction_ErrorMsg1, e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
use of org.eclipse.xsd.XSDFactory in project tmdm-studio-se by Talend.
the class XSDAddComplexTypeElementAction method createParticle.
private XSDParticle createParticle() {
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
XSDElementDeclaration resultElementDeclaration = factory.createXSDElementDeclaration();
resultElementDeclaration.setName(elementName);
resultElementDeclaration.setTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), defaultTypeName));
XSDParticle resultParticle = factory.createXSDParticle();
resultParticle.setContent(resultElementDeclaration);
resultParticle.setMinOccurs(this.minOccurs);
XSDModelGroup group = modelGroup;
if (maxOccurs > -1) {
resultParticle.setMaxOccurs(this.maxOccurs);
group.getContents().add(group.getContents().size(), resultParticle);
group.updateElement();
} else {
resultParticle.setMaxOccurs(this.maxOccurs);
group.getContents().add(group.getContents().size(), resultParticle);
group.updateElement();
if (resultParticle.getElement().getAttributeNode("maxOccurs") != null) {
// $NON-NLS-1$
// $NON-NLS-1$//$NON-NLS-2$
resultParticle.getElement().getAttributeNode("maxOccurs").setNodeValue("unbounded");
} else {
// $NON-NLS-1$//$NON-NLS-2$
resultParticle.getElement().setAttribute("maxOccurs", "unbounded");
}
}
Util.changeElementTypeToSequence(resultElementDeclaration, maxOccurs);
if (dialogR.isInherit()) {
XSDTerm totm = resultParticle.getTerm();
XSDElementDeclaration concept = null;
Object parent = Util.getParent(resultParticle);
if (parent instanceof XSDElementDeclaration) {
concept = (XSDElementDeclaration) parent;
} else {
concept = (XSDElementDeclaration) resultParticle.getContent();
}
XSDAnnotation fromannotation = null;
if (concept != null) {
fromannotation = concept.getAnnotation();
}
if (fromannotation != null) {
XSDAnnotationsStructure struc = new XSDAnnotationsStructure(totm);
if (((XSDElementDeclaration) totm).getType() != null) {
addAnnotion(struc, fromannotation);
}
}
}
return resultParticle;
}
use of org.eclipse.xsd.XSDFactory in project tmdm-studio-se by Talend.
the class XSDAddComplexTypeElementAction method transformToComplexType.
private boolean transformToComplexType(XSDParticle particle) {
XSDElementDeclaration decl = (XSDElementDeclaration) particle.getContent();
List<XSDComplexTypeDefinition> types = Util.getComplexTypes(schema);
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
// $NON-NLS-1$
boolean anonymous = (typeName == null) || ("".equals(typeName));
boolean alreadyExists = false;
XSDComplexTypeDefinition complexType = null;
// the sub element created if needed
XSDParticle subParticle = null;
XSDParticle groupParticle = null;
XSDElementDeclaration subElement = null;
XSDElementDeclaration parent = null;
Object pObject = Util.getParent(decl);
if (pObject instanceof XSDElementDeclaration) {
parent = (XSDElementDeclaration) pObject;
}
if (!anonymous) {
if (typeName.lastIndexOf(" : ") != -1) {
// $NON-NLS-1$
// $NON-NLS-1$
typeName = typeName.substring(0, typeName.lastIndexOf(" : "));
}
for (XSDComplexTypeDefinition td : types) {
if ((td.getName().equals(typeName))) {
alreadyExists = true;
complexType = td;
break;
}
}
} else {
if (decl.getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
alreadyExists = false;
}
}
if (alreadyExists) {
XSDParticle partCnt = (XSDParticle) complexType.getContentType();
partCnt.unsetMaxOccurs();
partCnt.unsetMinOccurs();
XSDTypeDefinition superType = null;
for (XSDTypeDefinition type : types) {
if (type.getName().equals(superTypeName)) {
superType = type;
break;
}
}
if (superType != null) {
XSDModelGroup mdlGrp = (XSDModelGroup) partCnt.getTerm();
boolean status = updateCompositorType(superType, mdlGrp);
if (!status) {
return false;
}
complexType.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL);
complexType.setBaseTypeDefinition(superType);
}
if (isAbstract) {
complexType.setAbstract(isAbstract);
} else {
complexType.unsetAbstract();
}
if (parent != null) {
parent.updateElement();
}
if (complexType != null) {
complexType.updateElement();
}
} else {
// Create if does not exist
// add an element declaration
subElement = factory.createXSDElementDeclaration();
// $NON-NLS-1$
subElement.setName("subelement");
subElement.setTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), defaultTypeName));
subParticle = factory.createXSDParticle();
subParticle.unsetMaxOccurs();
subParticle.unsetMinOccurs();
subParticle.setContent(subElement);
subParticle.updateElement();
// create group
XSDModelGroup group = factory.createXSDModelGroup();
if (isChoice) {
group.setCompositor(XSDCompositor.CHOICE_LITERAL);
} else if (isAll) {
group.setCompositor(XSDCompositor.ALL_LITERAL);
} else {
group.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
}
group.getContents().add(0, subParticle);
group.updateElement();
// create the complex type
complexType = factory.createXSDComplexTypeDefinition();
// complexType.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL);
if (!anonymous) {
// if (true) {
XSDTypeDefinition superType = null;
for (XSDTypeDefinition type : types) {
if (type.getName().equals(superTypeName)) {
superType = type;
break;
}
}
complexType.setName(typeName);
if (superType != null) {
boolean status = updateCompositorType(superType, group);
if (!status) {
return false;
}
complexType.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL);
complexType.setBaseTypeDefinition(superType);
}
if (isAbstract) {
complexType.setAbstract(isAbstract);
} else {
complexType.unsetAbstract();
}
schema.getContents().add(complexType);
}
complexType.updateElement();
// add the group
groupParticle = factory.createXSDParticle();
groupParticle.unsetMaxOccurs();
groupParticle.unsetMinOccurs();
groupParticle.setContent(group);
groupParticle.updateElement();
complexType.setContent(groupParticle);
complexType.updateElement();
}
// set complex type to concept
if (anonymous) {
decl.setAnonymousTypeDefinition(complexType);
} else {
decl.setTypeDefinition(complexType);
}
decl.updateElement();
schema.update();
return true;
}
Aggregations