You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2006/10/01 20:12:37 UTC
svn commit: r451775 - in /myfaces/tobago/trunk: core/
core/src/main/faces-config/ core/src/main/resources/META-INF/
tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/
Author: bommel
Date: Sun Oct 1 11:12:36 2006
New Revision: 451775
URL: http://svn.apache.org/viewvc?view=rev&rev=451775
Log:
[TOBAGO-140] generate faces-config from annotations
Added:
myfaces/tobago/trunk/core/src/main/faces-config/
myfaces/tobago/trunk/core/src/main/faces-config/faces-config.xml
- copied, changed from r450936, myfaces/tobago/trunk/core/src/main/resources/META-INF/faces-config.xml
Removed:
myfaces/tobago/trunk/core/src/main/resources/META-INF/faces-config.xml
Modified:
myfaces/tobago/trunk/core/pom.xml
myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationVisitor.java
Modified: myfaces/tobago/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/pom.xml?view=diff&rev=451775&r1=451774&r2=451775
==============================================================================
--- myfaces/tobago/trunk/core/pom.xml (original)
+++ myfaces/tobago/trunk/core/pom.xml Sun Oct 1 11:12:36 2006
@@ -19,6 +19,10 @@
<targetPath>META-INF</targetPath>
<directory>target/generated-tld</directory>
</resource>
+ <resource>
+ <targetPath>META-INF</targetPath>
+ <directory>src/main/faces-config</directory>
+ </resource>
</resources>
<plugins>
Copied: myfaces/tobago/trunk/core/src/main/faces-config/faces-config.xml (from r450936, myfaces/tobago/trunk/core/src/main/resources/META-INF/faces-config.xml)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/faces-config/faces-config.xml?view=diff&rev=451775&p1=myfaces/tobago/trunk/core/src/main/resources/META-INF/faces-config.xml&r1=450936&p2=myfaces/tobago/trunk/core/src/main/faces-config/faces-config.xml&r2=451775
==============================================================================
--- myfaces/tobago/trunk/core/src/main/resources/META-INF/faces-config.xml (original)
+++ myfaces/tobago/trunk/core/src/main/faces-config/faces-config.xml Sun Oct 1 11:12:36 2006
@@ -34,9 +34,7 @@
</message-bundle>
</application>
- <lifecycle>
- <phase-listener>org.apache.myfaces.tobago.ajax.api.AjaxPhaseListener</phase-listener>
- </lifecycle>
+
<component>
<component-type>org.apache.myfaces.tobago.DateInput</component-type>
@@ -203,5 +201,8 @@
<render-kit-class>org.apache.myfaces.tobago.renderkit.TobagoRenderKit</render-kit-class>
</render-kit>
-
+ <lifecycle>
+ <phase-listener>org.apache.myfaces.tobago.ajax.api.AjaxPhaseListener</phase-listener>
+ </lifecycle>
+
</faces-config>
Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationVisitor.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationVisitor.java?view=diff&rev=451775&r1=451774&r2=451775
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationVisitor.java (original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationVisitor.java Sun Oct 1 11:12:36 2006
@@ -72,6 +72,8 @@
private static final String ATTRIBUTE = "attribute";
private static final String ATTRIBUTE_NAME = "attribute-name";
private static final String ATTRIBUTE_CLASS = "attribute-class";
+ private static final String APPLICATION = "application";
+ private static final String FACTORY = "factory";
public FacesConfigAnnotationVisitor(AnnotationProcessorEnvironment env) {
super(env);
@@ -126,23 +128,22 @@
List<Element> elementsToAdd = new ArrayList<Element>();
for (Element newElement: newComponents) {
- boolean found = false;
- for (Element element: components) {
- if (equals(element, newElement)) {
- found = true;
- break;
- }
- }
+ boolean found = containsElement(components, newElement);
if (!found) {
elementsToAdd.add(newElement);
}
}
if (!elementsToAdd.isEmpty() && !components.isEmpty()) {
- int lastIndex = rootElement.indexOf(components.get(components.size()-1));
- rootElement.addContent(lastIndex+1, elementsToAdd);
+ int lastIndex = getIndexAfter(rootElement, COMPONENT);
+ rootElement.addContent(lastIndex, elementsToAdd);
} else if (!elementsToAdd.isEmpty()) {
- rootElement.addContent(0, elementsToAdd);
+ // if facesconfig contains no component section add the components after factory or application
+ int lastIndex = getIndexAfter(rootElement, FACTORY);
+ if (lastIndex == 0) {
+ lastIndex = getIndexAfter(rootElement, APPLICATION);
+ }
+ rootElement.addContent(lastIndex, elementsToAdd);
}
document.setDocType(new DocType("faces-config",
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN",
@@ -162,6 +163,26 @@
}
}
}
+
+ private boolean containsElement(List<Element> components, Element newElement) {
+ boolean found = false;
+ for (Element element: components) {
+ if (equals(element, newElement)) {
+ found = true;
+ break;
+ }
+ }
+ return found;
+ }
+
+ private int getIndexAfter(Element rootElement, String tagName) {
+ List<Element> components = rootElement.getChildren(tagName, rootElement.getNamespace());
+ if (!components.isEmpty()) {
+ return rootElement.indexOf(components.get(components.size()-1))+1;
+ }
+ return 0;
+ }
+
public boolean equals(Element element1, Element element2) {
Namespace namespace = element1.getNamespace();
if (element1.getName().equals(element2.getName()) && element1.getNamespace().equals(element2.getNamespace())) {
@@ -298,11 +319,13 @@
UIComponentTag componentTag = decl.getAnnotation(UIComponentTag.class);
if (componentTag != null) {
try {
- Class uiComponentClass = Class.forName(componentTag.uiComponent());
+ Class<?> uiComponentClass = Class.forName(componentTag.uiComponent());
Element element = createElement(decl, componentTag, uiComponentClass, namespace);
if (element != null) {
- addAttributes(decl, uiComponentClass, element, namespace);
- components.add(element);
+ if (!containsElement(components, element)) {
+ //addAttributes(decl, uiComponentClass, element, namespace);
+ components.add(element);
+ }
}
} catch (Exception e) {
e.printStackTrace();
@@ -317,8 +340,10 @@
Class<?> uiComponentClass = Class.forName(componentTag.uiComponent());
Element element = createElement(decl, componentTag, uiComponentClass, namespace);
if (element != null) {
- addAttributes(decl, uiComponentClass, element, namespace);
- components.add(element);
+ if (!containsElement(components, element)) {
+ //addAttributes(decl, uiComponentClass, element, namespace);
+ components.add(element);
+ }
}
} catch (Exception e) {
e.printStackTrace();