Skip to content

Commit

Permalink
[SHRINKDESC-128] Missing Attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfbattenfeld authored and ALRubinger committed Jul 29, 2012
1 parent 67a629e commit c83a840
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,30 @@ public static boolean hasChildsOf(final Element parentElement, XsdElementEnum ch
return false;
}


/**
* Checks for the first parent node occurrence of the a w3c parentEnum element.
* @param parentElement the element from which the search starts.
* @param parentEnum the <code>XsdElementEnum</code> specifying the parent element.
* @return true, if found, otherwise false.
*/
public static boolean hasParentOf(final Element parentElement, XsdElementEnum parentEnum )
{
Node parent = parentElement.getParentNode();
while (parent != null) {
if (parent.getNodeType() == Node.ELEMENT_NODE)
{
final Element parentElm = (Element) parent;
if (parentEnum.isTagNameEqual(parentElm.getTagName()))
{
return true;
}
}
parent = parent.getParentNode();
}
return false;
}

/**
* Logs out metadata information.
* @param metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ public boolean filter(final Metadata metadata, final TreeWalker walker)
final Node node = element.getAttributes().getNamedItem("type");
if(node != null)
{
final boolean isTextOnlyElement = MetadataUtil.hasParentOf(element, XsdElementEnum.simpleContent);
if (node.getNodeValue().endsWith(":ID"))
{
return false;
if (isTextOnlyElement) {
return false;
}
}

final MetadataElement classElement = new MetadataElement(element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,18 @@ public boolean filter(final Metadata metadata, final TreeWalker walker)
{
final Element parentElementWithName = (Element) parentNodeWithName;
final String mixedStr = MetadataUtil.getAttributeValue(parentElementWithName, "mixed");
if (mixedStr == null || mixedStr.equals("false"))
{
final String dataTypeName = MetadataUtil.getAttributeValue(parentElementWithName, "name");
final String typeStr = MetadataUtil.getAttributeValue(element, "base");
final MetadataItem dataType = new MetadataItem(dataTypeName);
dataType.setMappedTo(typeStr);
dataType.setNamespace(metadata.getCurrentNamespace());
dataType.setSchemaName(metadata.getCurrentSchmema());
metadata.getDataTypeList().add(dataType);
final boolean isTextOnlyElement = MetadataUtil.hasParentOf(element, XsdElementEnum.simpleContent);
if (!isTextOnlyElement || parentElementWithName.hasChildNodes() || baseStr.indexOf(":string") > 0) {
if (mixedStr == null || mixedStr.equals("false"))
{
final String dataTypeName = MetadataUtil.getAttributeValue(parentElementWithName, "name");
final String typeStr = MetadataUtil.getAttributeValue(element, "base");
final MetadataItem dataType = new MetadataItem(dataTypeName);
dataType.setMappedTo(typeStr);
dataType.setNamespace(metadata.getCurrentNamespace());
dataType.setSchemaName(metadata.getCurrentSchmema());
metadata.getDataTypeList().add(dataType);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public void testAttributeFilterWithComplexTypeAsParent() throws Exception {
" <xsd:attribute name=\"updatable\" type=\"xsd:boolean\"/>" +
" <xsd:attribute name=\"column-definition\" type=\"xsd:string\"/>" +
" <xsd:attribute name=\"table\" type=\"xsd:string\"/>" +
" <xsd:attribute name=\"id\" type=\"xsd:ID\"/>" +
" </xsd:complexType>" +
"</xsd:schema>";

Expand All @@ -66,6 +67,7 @@ public void testAttributeFilterWithComplexTypeAsParent() throws Exception {
DomTestUtil.assertClassAttribute(e.get(5), "<xsd:attribute name=\"updatable\" type=\"xsd:boolean\"/>");
DomTestUtil.assertClassAttribute(e.get(6), "<xsd:attribute name=\"column-definition\" type=\"xsd:string\"/>");
DomTestUtil.assertClassAttribute(e.get(7), "<xsd:attribute name=\"table\" type=\"xsd:string\"/>");
DomTestUtil.assertClassAttribute(e.get(8), "<xsd:attribute name=\"id\" type=\"xsd:ID\"/>");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void testAttributeGroupFilterWithComplexTypeAsParent() throws Exception {
" <xsd:element name=\"absolute-ordering\" type=\"javaee:absoluteOrderingType\"/>" +
" </xsd:choice>" +
" <xsd:attributeGroup ref=\"javaee:web-common-attributes\"/>" +
" <xsd:attribute name=\"id\" type=\"xsd:ID\"/>" +
" </xsd:complexType>" +
"</xsd:schema>";

Expand All @@ -59,6 +60,7 @@ public void testAttributeGroupFilterWithComplexTypeAsParent() throws Exception {
Assert.assertEquals("web-appType", metadata.getClassList().get(0).getName(), "web-appType");
Assert.assertEquals("javaee:web-commonType", metadata.getClassList().get(0).getReferences().get(0).getRef(), "javaee:web-commonType");
Assert.assertEquals("javaee:web-common-attributes", metadata.getClassList().get(0).getReferences().get(1).getRef(), "javaee:web-common-attributes");
DomTestUtil.assertClassAttribute(metadata.getClassList().get(0).getElements().get(2), "<xsd:attribute name=\"id\" type=\"xsd:ID\"");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ public void testComplexTypeFilterStandaloneComplexType() throws Exception {

@Test
public void testComplexTypeFilterWithMixedContent() throws Exception {
final boolean isLogging = false;
final boolean isLogging = true;
final String xmlFragment =
"<xsd:schema xmlns=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" >" +
" <xsd:complexType name=\"loader-repositoryType\" mixed=\"true\">" +
" <xsd:sequence>" +
" <xsd:element name=\"loader-repository-config\" type=\"jboss:loader-repository-configType\" minOccurs=\"0\" maxOccurs=\"unbounded\"/>" +
" </xsd:sequence><xsd:attribute name=\"id\" type=\"xsd:ID\"/>" +
" </xsd:sequence>" +
" <xsd:attribute name=\"id\" type=\"xsd:ID\"/>" +
" <xsd:attribute name=\"loaderRepositoryClass\" type=\"xsd:string\"/>" +
" </xsd:complexType>\">" +
"</xsd:schema>";
Expand All @@ -50,7 +51,8 @@ public void testComplexTypeFilterWithMixedContent() throws Exception {
final List<MetadataElement> e = metadata.getClassList().get(0).getElements();
DomTestUtil.assertElement(e.get(0), "<xsd:element name=\"loader-repositoryType\" type=\"text\"/>");
DomTestUtil.assertElement(e.get(1), "<xsd:element name=\"loader-repository-config\" type=\"jboss:loader-repository-configType\" minOccurs=\"0\" maxOccurs=\"unbounded\"/>");
DomTestUtil.assertClassAttribute(e.get(2), "<xsd:attribute name=\"loaderRepositoryClass\" type=\"xsd:string\"/>");
DomTestUtil.assertClassAttribute(e.get(2), "<xsd:attribute name=\"id\" type=\"xsd:ID\"/>");
DomTestUtil.assertClassAttribute(e.get(3), "<xsd:attribute name=\"loaderRepositoryClass\" type=\"xsd:string\"/>");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public void testGeneratedEjbJarXml() throws Exception
.description("description1")
.displayName("display-name1")
.createIcon()
.id("iconID1")
.smallIcon("small-icon1")
.largeIcon("large-icon1").up()
.ejbName("ejb-name0")
Expand Down Expand Up @@ -127,6 +128,7 @@ public void testGeneratedEjbJarXml() throws Exception
.description("description7")
.displayName("display-name2")
.createIcon()
.id("iconID2")
.smallIcon("small-icon2")
.largeIcon("large-icon2").up()
.serviceRefName("service-ref-name0")
Expand Down
4 changes: 2 additions & 2 deletions test/src/test/resources/test-gen-ejbjar31.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<message-driven>
<description>description1</description>
<display-name>display-name1</display-name>
<icon>
<icon id="iconID1">
<small-icon>small-icon1</small-icon>
<large-icon>large-icon1</large-icon>
</icon>
Expand Down Expand Up @@ -111,7 +111,7 @@
<service-ref>
<description>description7</description>
<display-name>display-name2</display-name>
<icon>
<icon id="iconID2">
<small-icon>small-icon2</small-icon>
<large-icon>large-icon2</large-icon>
</icon>
Expand Down

0 comments on commit c83a840

Please sign in to comment.