Author: nbelaevski
Date: 2010-02-28 13:37:27 -0500 (Sun, 28 Feb 2010)
New Revision: 16504
Modified:
root/cdk-sandbox/trunk/xsd2javadoc/src/main/java/org/richfaces/xsd2tld/SchemaTransformer.java
Log:
Reference elements/attributes removed from schema documentation generation
Modified:
root/cdk-sandbox/trunk/xsd2javadoc/src/main/java/org/richfaces/xsd2tld/SchemaTransformer.java
===================================================================
---
root/cdk-sandbox/trunk/xsd2javadoc/src/main/java/org/richfaces/xsd2tld/SchemaTransformer.java 2010-02-26
15:14:27 UTC (rev 16503)
+++
root/cdk-sandbox/trunk/xsd2javadoc/src/main/java/org/richfaces/xsd2tld/SchemaTransformer.java 2010-02-28
18:37:27 UTC (rev 16504)
@@ -1,4 +1,5 @@
package org.richfaces.xsd2tld;
+
import static org.richfaces.xsd2tld.SchemaTransformerUtils.createLookup;
import static org.richfaces.xsd2tld.SchemaTransformerUtils.createTagClassName;
import static org.richfaces.xsd2tld.SchemaTransformerUtils.getJavaClassNameByType;
@@ -76,9 +77,9 @@
private SchemaModelFactory schemaModelFactory = SchemaModelFactory.getDefault();
private List<SchemaModel> schemaModels = new ArrayList<SchemaModel>();
-
+
private AXIModelFactory axiModelFactory = AXIModelFactory.getDefault();
-
+
private TldTaglibType createTaglib(String namespaceUri) {
TldTaglibType taglib = objectFactory.createTldTaglibType();
@@ -86,37 +87,37 @@
taglib.setUri(namespaceUri);
return taglib;
}
-
+
protected SchemaModel parseSchema(String fileName) throws Exception {
ModelSource modelSource = new ModelSource(createLookup(fileName), false);
SchemaModel schemaModel = schemaModelFactory.getModel(modelSource);
schemaModel.sync();
-
+
return schemaModel;
}
-
+
public void setTaglibShortNames(Map<String, String> taglibShortNames) {
this.taglibShortNames = taglibShortNames;
}
-
+
public void addSchema(String fileName) throws Exception {
SchemaModel schemaModel = parseSchema(fileName);
schemaModels.add(schemaModel);
}
-
+
public void parseSchemas() {
for (SchemaModel schemaModel : schemaModels) {
Schema schema = schemaModel.getSchema();
String targetNamespace = schema.getTargetNamespace();
TldTaglibType taglib = createTaglib(targetNamespace);
-
+
String shortName = taglibShortNames.get(targetNamespace);
if (shortName == null) {
shortName = getShortName(schema);
}
-
+
taglib.setShortName(shortName);
Annotation schemaAnnotation = schema.getAnnotation();
@@ -125,7 +126,7 @@
if (documentationElements != null) {
List<Object> descriptionsList = taglib.getDescription();
for (Documentation documentationElement : documentationElements) {
-
//descriptionsList.addAll(parseRawXml(documentationElement.getContentFragment()));
+ //
descriptionsList.addAll(parseRawXml(documentationElement.getContentFragment()));
descriptionsList.add(documentationElement.getContentFragment());
}
}
@@ -133,31 +134,29 @@
addElementsAndAttributes(schemaModel, taglib);
}
-
+
schemaModels.clear();
}
-
+
public void writeTransformedSchemas(String outputDirectory) {
File outputDirectoryObject = new File(outputDirectory);
outputDirectoryObject.mkdirs();
-
+
for (TldTaglibType taglib : taglibs.values()) {
File outputFile = new File(outputDirectoryObject, taglib.getShortName() +
".tld");
outputFile.delete();
JAXB.marshal(objectFactory.createTaglib(taglib), outputFile);
}
}
-
+
private static String getDocumentation(AXIComponent axiComponent) {
SchemaComponent peer = axiComponent.getPeer();
- if (peer == null ||
- peer.getAnnotation() == null ||
- peer.getAnnotation().getDocumentationElements() == null) {
+ if (peer == null || peer.getAnnotation() == null ||
peer.getAnnotation().getDocumentationElements() == null) {
return null;
}
StringBuilder buffer = new StringBuilder();
- for(Documentation doc : peer.getAnnotation().getDocumentationElements()) {
+ for (Documentation doc : peer.getAnnotation().getDocumentationElements()) {
buffer.append(doc.getContentFragment());
}
@@ -167,7 +166,7 @@
private String getElementQName(AXIComponent component) {
return "{" + component.getTargetNamespace() + "}" +
((AXIType) component).getName();
}
-
+
/**
* @param schema
* @param taglib
@@ -178,39 +177,40 @@
AXIModel axiModel = axiModelFactory.getModel(schemaModel);
final Set<String> visitedObjects = new HashSet<String>();
-
+
axiModel.getRoot().accept(new AXINonCyclicVisitor(axiModel) {
-
+
private void addAttribute(TagType tagType, AbstractAttribute
abstractAttribute) {
TldAttributeType tldAttribute = objectFactory.createTldAttributeType();
- //TODO namespace check
+ // TODO namespace check
tldAttribute.setName(abstractAttribute.getName());
if (abstractAttribute instanceof Attribute) {
Attribute attribute = (Attribute) abstractAttribute;
tldAttribute.setRequired(Use.REQUIRED.equals(attribute.getUse()));
- tldAttribute.setType(getJavaClassNameByType( (Datatype)
attribute.getType() ));
+ tldAttribute.setType(getJavaClassNameByType((Datatype)
attribute.getType()));
} else {
- //TODO
+ // TODO
}
String attributeDocumentation = getDocumentation(abstractAttribute);
if (attributeDocumentation != null &&
attributeDocumentation.length() != 0) {
-
//tldAttribute.getDescription().addAll(parseRawXml(attributeDocumentation));
+ //
tldAttribute.getDescription().addAll(parseRawXml(attributeDocumentation));
tldAttribute.getDescription().add(normalizeXml(attributeDocumentation));
}
tagType.getAttribute().add(tldAttribute);
}
-
+
private static final String GLOBAL_ATTRIBUTES =
"_global_attributes";
-
+
@Override
public void visit(Attribute attribute) {
super.visit(attribute);
-
- if (targetNamespace.equals(attribute.getTargetNamespace()) &&
attribute.isGlobal() && visitedObjects.add(getElementQName(attribute))) {
+
+ if (!attribute.isReference() &&
targetNamespace.equals(attribute.getTargetNamespace())
+ && attribute.isGlobal() &&
visitedObjects.add(getElementQName(attribute))) {
TagType globalTagType = null;
List<TagType> tags = taglib.getTag();
for (TagType tagType : tags) {
@@ -219,35 +219,37 @@
break;
}
}
-
+
if (globalTagType == null) {
globalTagType = objectFactory.createTagType();
globalTagType.setName(GLOBAL_ATTRIBUTES);
- globalTagType.getDescription().add("Global attributes of
" + attribute.getTargetNamespace() + " namespace");
-
+ globalTagType.getDescription().add(
+ "Global attributes of " +
attribute.getTargetNamespace() + " namespace");
+
taglib.getTag().add(globalTagType);
}
-
+
addAttribute(globalTagType, attribute);
}
}
-
+
@Override
public void visit(Element e) {
super.visit(e);
- if (targetNamespace.equals(e.getTargetNamespace()) &&
visitedObjects.add(getElementQName(e))) {
+ if (!e.isReference() &&
targetNamespace.equals(e.getTargetNamespace())
+ && visitedObjects.add(getElementQName(e))) {
List<TagType> tagsList = taglib.getTag();
TagType tagType = objectFactory.createTagType();
-
+
String tagName = e.getName();
tagType.setName(tagName);
tagType.setTagClass(createTagClassName(tagName));
String documentation = getDocumentation(e);
if (documentation != null && documentation.length() != 0) {
- //tagType.getDescription().addAll(parseRawXml(documentation));
+ // tagType.getDescription().addAll(parseRawXml(documentation));
tagType.getDescription().add(normalizeXml(documentation));
}
@@ -267,13 +269,13 @@
private static enum State {
FILES, LOCAL_NAMES_HASH, OUTPUT_DIR
}
-
+
public static void main(String[] args) throws Exception {
State state = State.FILES;
-
+
String outputDirectoryPath = null;
SchemaTransformer schemaTransformer = new SchemaTransformer();
-
+
for (String arg : args) {
if (state == State.LOCAL_NAMES_HASH) {
schemaTransformer.setTaglibShortNames(parseLiteralHash(arg));
@@ -289,11 +291,11 @@
schemaTransformer.addSchema(arg);
}
}
-
+
schemaTransformer.parseSchemas();
-
+
File outputDirectory = new File(outputDirectoryPath);
-
+
schemaTransformer.writeTransformedSchemas(outputDirectory.getAbsolutePath());
}
}