Author: alexsmirnov
Date: 2010-07-22 17:32:57 -0400 (Thu, 22 Jul 2010)
New Revision: 18206
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java
Log:
https://jira.jboss.org/browse/RF-8888
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java 2010-07-22
21:32:08 UTC (rev 18205)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java 2010-07-22
21:32:57 UTC (rev 18206)
@@ -45,30 +45,35 @@
* @author akolonitsky
* @since Feb 3, 2010
*/
-public class TaglibGeneratorVisitor extends SimpleVisitor<Boolean,ComponentLibrary>
{
+public class TaglibGeneratorVisitor extends SimpleVisitor<Boolean,
ComponentLibrary> {
private static final String COMPONENT = "component";
private static final String COMPONENT_TYPE = "component-type";
private static final String RENDERER_TYPE = "renderer-type";
private static final String HANDLER_CLASS = "handler-class";
/**
- * <p class="changed_added_4_0">Generated document.
- * IDEA - set document as visitor patameter, to reuse this object
instance.</p>
- */
+ * <p class="changed_added_4_0">
+ * Generated document. IDEA - set document as visitor patameter, to reuse this object
instance.
+ * </p>
+ */
private Document document = DocumentHelper.createDocument();
/**
- * <p class="changed_added_4_0">faces-config element in
document.</p>
- */
+ * <p class="changed_added_4_0">
+ * faces-config element in document.
+ * </p>
+ */
private Element faceletTaglib;
- private boolean empty=true;
+ private boolean empty = true;
public TaglibGeneratorVisitor() {
}
/**
- * <p class="changed_added_4_0"></p>
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @return the empty
*/
public boolean isEmpty() {
@@ -84,11 +89,12 @@
}
@Override
- public Boolean visitComponentLibrary(ComponentLibrary model,ComponentLibrary
componentLibrary) {
+ public Boolean visitComponentLibrary(ComponentLibrary model, ComponentLibrary
componentLibrary) {
faceletTaglib = document.addElement("facelet-taglib",
"http://java.sun.com/xml/ns/javaee");
faceletTaglib.addAttribute("xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance");
- faceletTaglib.addAttribute("xsi:schemaLocation",
"http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd");
+ faceletTaglib.addAttribute("xsi:schemaLocation",
+ "http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd");
faceletTaglib.addAttribute("version", "2.0");
faceletTaglib.addAttribute("id", model.getTaglib().getShortName());
@@ -98,56 +104,56 @@
}
@Override
- public Boolean visitComponent(ComponentModel model,ComponentLibrary componentLibrary)
{
+ public Boolean visitComponent(ComponentModel model, ComponentLibrary
componentLibrary) {
for (TagModel tagModel : model.getTags()) {
- if (TagType.Facelets != tagModel.getType()
- && TagType.All != tagModel.getType()) {
-
- continue;
+ if (isFaceletsTag(tagModel)) {
+ Element tag = createTag(tagModel.getName());
+ // TODO - investigate proper usage of the <handler-class> element.
+ // Most libraries use <handler-class> INSTEAD of <component>
+ Element component = tag.addElement(COMPONENT);
+ addDescription(component, model);
+ component.addElement(COMPONENT_TYPE).addText(model.getId().getType());
+ FacesId rendererType = model.getRendererType();
+ // RendererModel renderer =
componentLibrary.getRenderer(model.getFamily(), model.getId().getType());
+ if (null != rendererType) {
+
component.addElement(RENDERER_TYPE).addText(rendererType.toString());
+ }
+ addTagHandler(component, tagModel);
+ appendAttributes(tag, model);
}
-
- Element tag = createTag(tagModel.getName());
- // TODO - investigate proper usage of the <handler-class> element.
- // Most libraries use <handler-class> INSTEAD of <component>
- Element component = tag.addElement(COMPONENT);
- component.addElement(COMPONENT_TYPE).addText(model.getId().getType());
- FacesId rendererType = model.getRendererType();
-// RendererModel renderer = componentLibrary.getRenderer(model.getFamily(),
model.getId().getType());
- if (null != rendererType) {
- component.addElement(RENDERER_TYPE).addText(rendererType.toString());
- }
- addTagHandler(component, tagModel);
- appendAttributs(tag, model);
}
return null;
}
/**
- * <p class="changed_added_4_0"></p>
- * @param parent DOM element for which <handler-class> element should
be appended.
- * @param tag model.
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param parent
+ * DOM element for which <handler-class> element should be
appended.
+ * @param tag
+ * model.
* @return true is explicit handler class definition was generated.
*/
private boolean addTagHandler(Element parent, TagModel tag) {
if (tag != null && tag.getTargetClass() != null) {
- parent.addElement(HANDLER_CLASS).addText(tag.getTargetClass().toString());
+ parent.addElement(HANDLER_CLASS).addText(tag.getTargetClass().getName());
return true;
} else {
return false;
}
}
-
-
@Override
- public Boolean visitConverter(ConverterModel model,ComponentLibrary componentLibrary)
{
+ public Boolean visitConverter(ConverterModel model, ComponentLibrary
componentLibrary) {
for (TagModel tagModel : model.getTags()) {
- if (TagType.Facelets.equals(tagModel.getType())) {
+ if (isFaceletsTag(tagModel)) {
Element tag = createTag(tagModel.getName());
+ addDescription(tag, model);
Element converter = tag.addElement("converter");
converter.addElement("converter-id",
model.getId().toString());
addTagHandler(converter, tagModel);
- appendAttributs(tag, model);
+ appendAttributes(tag, model);
}
}
return null;
@@ -155,36 +161,38 @@
/**
* This method generates validator tag.
- * <pre>
+ *
+ * <pre>
* <tag>
* <tag-name>formatValidator</tag-name>
* <validator>
* <validator-id></validator-id>
* <handler-class></handler-class>
* </validator>
- *
+ *
* <attribute>
* ...
* </attribute>
- * </tag>
- * <pre>
- *
+ * </tag>
+ *
+ * <pre>
+ *
* */
- public Boolean visitValidator(ValidatorModel model,ComponentLibrary componentLibrary)
{
+ public Boolean visitValidator(ValidatorModel model, ComponentLibrary
componentLibrary) {
for (TagModel tagModel : model.getTags()) {
- if (TagType.Facelets.equals(tagModel.getType())) {
+ if (isFaceletsTag(tagModel)) {
Element tag = createTag(tagModel.getName());
+ addDescription(tag, model);
Element validator = tag.addElement("validator");
validator.addElement("validator-id",
model.getId().toString());
addTagHandler(validator, tagModel);
- appendAttributs(tag, model);
+ appendAttributes(tag, model);
}
}
return null;
}
-
- private void appendAttributs(Element tag, BeanModelBase model) {
+ private void appendAttributes(Element tag, BeanModelBase model) {
for (PropertyBase entry : model.getAttributes()) {
if (!entry.isHidden() && !entry.isReadOnly()) {
createAttributeElement(tag, entry.getName(), entry);
@@ -193,60 +201,57 @@
}
/**
- * <attribute>
- * <description></description>
- * <name>formatPatterns</name>
- * <required>true</required>
- * <type>String</type>
- * </attribute>
- *
+ * <attribute> <description></description>
<name>formatPatterns</name> <required>true</required>
<type>String</type>
+ * </attribute>
+ *
* @param tag
* @param name
* @param attribute
- *
+ *
* @return
* */
private Element createAttributeElement(Element tag, String name, PropertyBase
attribute) {
Element attr = tag.addElement("attribute");
- if (attribute.getDescription() != null) {
-
attr.addElement("description").addText(attribute.getDescription());
+ addDescription(attr, attribute);
+ attr.addElement("name").addText(name);
+ attr.addElement("type").addText(attribute.getType().getName());
+ if (attribute.isRequired()) {
+ attr.addElement("required").addText("true");
}
- attr.addElement("name").addText(name);
- attr.addElement("type").addText(attribute.getType().toString());
return attr;
}
private Element createTag(String tagName) {
Element tag = faceletTaglib.addElement("tag");
tag.addElement("tag-name").addText(tagName);
- empty=false;
+ empty = false;
return tag;
}
@Override
- public Boolean visitBehavior(BehaviorModel model,ComponentLibrary componentLibrary)
{
+ public Boolean visitBehavior(BehaviorModel model, ComponentLibrary componentLibrary)
{
for (TagModel tagModel : model.getTags()) {
- if (TagType.Facelets.equals(tagModel.getType())) {
+ if (isFaceletsTag(tagModel)) {
Element tag = createTag(tagModel.getName());
+ addDescription(tag, model);
Element behavior = tag.addElement("behavior");
behavior.addElement("behavior-id").addText(model.getId().toString());
addTagHandler(behavior, tagModel);
- appendAttributs(tag, model);
+ appendAttributes(tag, model);
}
}
return null;
}
-
@Override
- public Boolean visitFunction(FunctionModel model,ComponentLibrary componentLibrary)
{
-
if(TagType.Facelets.equals(model.getType())||TagType.All.equals(model.getType())){
+ public Boolean visitFunction(FunctionModel model, ComponentLibrary componentLibrary)
{
+ if (isFaceletsTag(model.getType())) {
Element functionElement = faceletTaglib.addElement("function");
addDescription(functionElement, model);
functionElement.addElement("function-name").addText(model.getName());
-
functionElement.addElement("function-class").addText(model.getFunctionClass().toString());
+
functionElement.addElement("function-class").addText(model.getFunctionClass().getName());
functionElement.addElement("function-signature").addText(model.getSignature());
- empty=false;
+ empty = false;
}
return null;
}
@@ -254,35 +259,48 @@
@Override
public Boolean visitEvent(EventModel model, ComponentLibrary param) {
for (TagModel tagModel : model.getTags()) {
- if (TagType.Facelets.equals(tagModel.getType())) {
+ if (isFaceletsTag(tagModel)) {
Element tag = createTag(tagModel.getName());
addTagHandler(tag, tagModel);
}
}
return null;
}
+
+ private boolean isFaceletsTag(TagType type) {
+
+ return TagType.Facelets.equals(type) || TagType.All.equals(type);
+ }
+
+ private boolean isFaceletsTag(TagModel tagModel) {
+ return isFaceletsTag(tagModel.getType());
+ }
+
/**
- * <p class="changed_added_4_0">Add common description
elements.</p>
+ * <p class="changed_added_4_0">
+ * Add common description elements.
+ * </p>
+ *
* @param parant
* @param model
*/
- private void addDescription(Element parent, DescriptionGroup model){
- if(!Strings.isEmpty(model.getDescription())){
+ private void addDescription(Element parent, DescriptionGroup model) {
+ if (!Strings.isEmpty(model.getDescription())) {
parent.addElement("description").addText(model.getDescription());
}
- if(!Strings.isEmpty(model.getDisplayname())){
+ if (!Strings.isEmpty(model.getDisplayname())) {
parent.addElement("display-name").addText(model.getDisplayname());
}
- if(null != model.getIcon()){
+ if (null != model.getIcon()) {
Element iconElement = parent.addElement("icon");
- if(!Strings.isEmpty(model.getIcon().getSmallIcon())){
+ if (!Strings.isEmpty(model.getIcon().getSmallIcon())) {
iconElement.addElement("small-icon").addText(model.getIcon().getSmallIcon());
}
- if(!Strings.isEmpty(model.getIcon().getLargeIcon())){
+ if (!Strings.isEmpty(model.getIcon().getLargeIcon())) {
iconElement.addElement("large-icon").addText(model.getIcon().getLargeIcon());
}
-
+
}
}
-
+
}