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 2008/03/13 12:14:46 UTC
svn commit: r636712 [5/6] - in /myfaces/tobago/trunk: core/
core/src/main/faces-config/ core/src/main/java/org/apache/myfaces/tobago/
core/src/main/java/org/apache/myfaces/tobago/ajax/api/
core/src/main/java/org/apache/myfaces/tobago/component/ core/sr...
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java?rev=636712&r1=636711&r2=636712&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java Thu Mar 13 04:14:02 2008
@@ -47,7 +47,9 @@
import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE_HEADER;
import static org.apache.myfaces.tobago.TobagoConstants.ATTR_TIP;
import static org.apache.myfaces.tobago.TobagoConstants.ATTR_WIDTH_LIST;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LAYOUT_WIDTH;
import static org.apache.myfaces.tobago.TobagoConstants.ATTR_WIDTH_LIST_STRING;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_INNER_WIDTH;
import static org.apache.myfaces.tobago.TobagoConstants.FACET_MENUPOPUP;
import static org.apache.myfaces.tobago.TobagoConstants.FACET_PAGER_PAGE;
import static org.apache.myfaces.tobago.TobagoConstants.FACET_PAGER_ROW;
@@ -55,6 +57,7 @@
import static org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_LINK;
import static org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_MENUBAR;
import static org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_MENUCOMMAND;
+import static org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_OUT;
import static org.apache.myfaces.tobago.TobagoConstants.SUBCOMPONENT_SEP;
import org.apache.myfaces.tobago.ajax.api.AjaxRenderer;
import static org.apache.myfaces.tobago.ajax.api.AjaxResponse.CODE_NOT_MODIFIED;
@@ -71,6 +74,11 @@
import org.apache.myfaces.tobago.component.UIMenuCommand;
import org.apache.myfaces.tobago.component.UIPage;
import org.apache.myfaces.tobago.component.UIReload;
+import org.apache.myfaces.tobago.component.UILayout;
+import org.apache.myfaces.tobago.component.LayoutTokens;
+import org.apache.myfaces.tobago.component.RelativeLayoutToken;
+import org.apache.myfaces.tobago.component.LayoutToken;
+import org.apache.myfaces.tobago.component.FixedLayoutToken;
import org.apache.myfaces.tobago.config.TobagoConfig;
import org.apache.myfaces.tobago.context.ResourceManager;
import org.apache.myfaces.tobago.context.ResourceManagerFactory;
@@ -79,7 +87,7 @@
import org.apache.myfaces.tobago.model.SheetState;
import org.apache.myfaces.tobago.renderkit.LayoutableRendererBase;
import org.apache.myfaces.tobago.renderkit.RenderUtil;
-import org.apache.myfaces.tobago.renderkit.SheetRendererWorkaround;
+import org.apache.myfaces.tobago.renderkit.LayoutInformationProvider;
import org.apache.myfaces.tobago.renderkit.html.CommandRendererHelper;
import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
import org.apache.myfaces.tobago.renderkit.html.HtmlConstants;
@@ -87,6 +95,8 @@
import org.apache.myfaces.tobago.renderkit.html.HtmlStyleMap;
import org.apache.myfaces.tobago.renderkit.html.StyleClasses;
import org.apache.myfaces.tobago.util.StringUtil;
+import org.apache.myfaces.tobago.util.LayoutUtil;
+import org.apache.myfaces.tobago.util.LayoutInfo;
import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
import javax.faces.application.Application;
@@ -103,7 +113,7 @@
import java.util.Locale;
import java.util.Map;
-public class SheetRenderer extends LayoutableRendererBase implements SheetRendererWorkaround, AjaxRenderer {
+public class SheetRenderer extends LayoutableRendererBase implements AjaxRenderer {
private static final Log LOG = LogFactory.getLog(SheetRenderer.class);
@@ -1104,7 +1114,7 @@
&& component.getFacet(FACET_RELOAD) instanceof UIReload
&& component.getFacet(FACET_RELOAD).isRendered()) {
UIReload reload = (UIReload) component.getFacet(FACET_RELOAD);
- update = reload.getUpdate();
+ update = reload.isUpdate();
}
if (update) {
// TODO find a better way
@@ -1161,4 +1171,157 @@
throws IOException {
// DO Nothing
}
+
+ public void layoutBegin(FacesContext context, UIComponent component) throws IOException {
+ UILayout.prepareDimension(context, component);
+ }
+
+ public void layoutEnd(FacesContext context, UIComponent component) throws IOException {
+ if (component instanceof UIData) {
+ UIData data = (UIData) component;
+ ensureColumnWidthList(context, data);
+ prepareDimensions(context, data);
+ }
+ }
+
+ private void ensureColumnWidthList(FacesContext facesContext, UIData data) {
+ List<Integer> currentWidthList = null;
+ List<UIColumn> rendererdColumns = data.getRenderedColumns();
+
+ final Map attributes = data.getAttributes();
+ String widthListString = null;
+ SheetState state = data.getSheetState(facesContext);
+ if (state != null) {
+ widthListString = state.getColumnWidths();
+ }
+ if (widthListString == null) {
+ widthListString = (String) attributes.get(ATTR_WIDTH_LIST_STRING);
+ }
+
+ if (widthListString != null) {
+ currentWidthList = StringUtil.parseIntegerList(widthListString);
+ }
+ if (currentWidthList != null && currentWidthList.size() != rendererdColumns.size()) {
+ currentWidthList = null;
+ }
+
+
+ if (currentWidthList == null) {
+ LayoutTokens tokens = data.getColumnLayout();
+ List<UIColumn> allColumns = data.getAllColumns();
+ LayoutTokens newTokens = new LayoutTokens();
+ if (allColumns.size() > 0) {
+ for (int i = 0; i < allColumns.size(); i++) {
+ UIColumn column = allColumns.get(i);
+ if (column.isRendered()) {
+ if (tokens == null) {
+ if (column instanceof org.apache.myfaces.tobago.component.UIColumn) {
+ newTokens.addToken(
+ LayoutTokens.parseToken(((org.apache.myfaces.tobago.component.UIColumn) column).getWidth()));
+ } else {
+ newTokens.addToken(RelativeLayoutToken.DEFAULT_INSTANCE);
+ }
+ } else {
+ if (i < tokens.getSize()) {
+ newTokens.addToken(tokens.get(i));
+ } else {
+ newTokens.addToken(RelativeLayoutToken.DEFAULT_INSTANCE);
+ }
+ }
+ }
+ }
+ }
+
+
+ int space = LayoutUtil.getInnerSpace(facesContext, data, true);
+ space -= getContentBorder(facesContext, data);
+ if (needVerticalScrollbar(facesContext, data)) {
+ space -= getScrollbarWidth(facesContext, data);
+ }
+ LayoutInfo layoutInfo = new LayoutInfo(newTokens.getSize(), space, newTokens, data.getClientId(facesContext), false);
+ parseFixedWidth(facesContext, layoutInfo, rendererdColumns);
+ layoutInfo.parseColumnLayout(space);
+ currentWidthList = layoutInfo.getSpaceList();
+ }
+
+ if (currentWidthList != null) {
+ if (rendererdColumns.size() != currentWidthList.size()) {
+ LOG.warn("widthList.size() = " + currentWidthList.size()
+ + " != columns.size() = " + rendererdColumns.size() + " widthList : "
+ + LayoutInfo.listToTokenString(currentWidthList));
+ } else {
+ data.setWidthList(currentWidthList);
+ }
+ }
+ }
+
+ private void parseFixedWidth(FacesContext facesContext, LayoutInfo layoutInfo, List<UIColumn> rendereredColumns) {
+ LayoutTokens tokens = layoutInfo.getLayoutTokens();
+ for (int i = 0; i < tokens.getSize(); i++) {
+ LayoutToken token = tokens.get(i);
+ if (token instanceof FixedLayoutToken) {
+ int width = 0;
+ if (!rendereredColumns.isEmpty()) {
+ if (i < rendereredColumns.size()) {
+ UIColumn column = rendereredColumns.get(i);
+ if (column instanceof UIColumnSelector) {
+ LayoutInformationProvider renderer
+ = ComponentUtil.getRenderer(facesContext, column);
+ if (renderer == null) {
+ LOG.warn("can't find renderer for " + column.getClass().getName());
+ renderer = ComponentUtil.getRenderer(facesContext,
+ org.apache.myfaces.tobago.component.UIPanel.COMPONENT_FAMILY, RENDERER_TYPE_OUT);
+ }
+ width = renderer.getFixedWidth(facesContext, column);
+
+ } else {
+ for (UIComponent component : (List<UIComponent>) column.getChildren()) {
+ LayoutInformationProvider renderer
+ = ComponentUtil.getRenderer(facesContext, component);
+ width += renderer.getFixedWidth(facesContext, component);
+ }
+ }
+ layoutInfo.update(width, i);
+ } else {
+ layoutInfo.update(0, i);
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("More LayoutTokens found than rows! skipping!");
+ }
+ }
+ }
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("set column " + i + " from fixed to with " + width);
+ }
+ }
+ }
+ }
+
+ private void prepareDimensions(FacesContext facesContext, UIData data) {
+ // prepare width's in column's children components
+
+ List<Integer> columnWidths = data.getWidthList();
+ int i = 0;
+ for (UIColumn column : data.getRenderedColumns()) {
+ if (i < columnWidths.size()) {
+ Integer width = columnWidths.get(i);
+ if (!(column instanceof UIColumnSelector)) {
+ if (column.getChildCount() == 1) {
+ UIComponent child = (UIComponent) column.getChildren().get(0);
+ int cellPaddingWidth = getConfiguredValue(facesContext, data, "cellPaddingWidth");
+ child.getAttributes().put(
+ ATTR_LAYOUT_WIDTH, width - cellPaddingWidth);
+ child.getAttributes().remove(ATTR_INNER_WIDTH);
+ } else {
+ LOG.warn("More or less than 1 child in column! "
+ + "Can't set width for column " + i + " to " + width);
+ }
+ }
+ } else {
+ LOG.warn("More columns than columnSizes! "
+ + "Can't set width for column " + i);
+ }
+ i++;
+ }
+ }
+
}
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java?rev=636712&r1=636711&r2=636712&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java Thu Mar 13 04:14:02 2008
@@ -283,7 +283,6 @@
component.getFacets().put(TobagoConstants.FACET_TOOL_BAR, toolBar);
UITab activeTab = null;
-
int index = 0;
for (UIComponent child: (List<UIComponent>) component.getChildren()) {
if (child instanceof UITab) {
@@ -311,7 +310,7 @@
if (virtualTab == index) {
outerClass.addClass("tab", "selected-outer");
innerClass.addClass("tab", "selected-inner");
- activeTab = (UITab) tab;
+ activeTab = tab;
} else {
outerClass.addClass("tab", "unselected-outer");
innerClass.addClass("tab", "unselected-inner");
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TextAreaRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TextAreaRenderer.java?rev=636712&r1=636711&r2=636712&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TextAreaRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TextAreaRenderer.java Thu Mar 13 04:14:02 2008
@@ -28,7 +28,8 @@
import static org.apache.myfaces.tobago.TobagoConstants.ATTR_READONLY;
import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ROWS;
import org.apache.myfaces.tobago.component.ComponentUtil;
-import org.apache.myfaces.tobago.component.UIInput;
+import org.apache.myfaces.tobago.component.UIInputBase;
+import org.apache.myfaces.tobago.component.UITextarea;
import org.apache.myfaces.tobago.renderkit.HtmlUtils;
import org.apache.myfaces.tobago.renderkit.InputRendererBase;
import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
@@ -46,12 +47,12 @@
@Override
public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
- if (!(component instanceof UIInput)) {
- LOG.error("Wrong type: Need " + UIInput.class.getName() + ", but was " + component.getClass().getName());
+ if (!(component instanceof UITextarea)) {
+ LOG.error("Wrong type: Need " + UITextarea.class.getName() + ", but was " + component.getClass().getName());
return;
}
- UIInput input = (UIInput) component;
+ UIInputBase input = (UIInputBase) component;
String title = HtmlRendererUtil.getTitleFromTipAndMessages(facesContext, component);
String clientId = input.getClientId(facesContext);
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ToolBarRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ToolBarRenderer.java?rev=636712&r1=636711&r2=636712&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ToolBarRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ToolBarRenderer.java Thu Mar 13 04:14:02 2008
@@ -521,7 +521,8 @@
popupMenu.getAttributes().put(ATTR_MENU_POPUP, Boolean.TRUE);
popupMenu.getAttributes().put(ATTR_MENU_POPUP_TYPE, "ToolBarButton");
popupMenu.setRendererType(RENDERER_TYPE_MENUBAR);
- popupMenu.getAttributes().remove(ATTR_LABEL);
+ //popupMenu.getAttributes().remove(ATTR_LABEL);
+ //popupMenu.getAttributes().remove();
popupMenu.getAttributes().put(ATTR_IMAGE, "image/toolbarButtonMenu.gif");
RenderUtil.encode(facesContext, popupMenu);
}
Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-annotation/src/main/java/org/apache/myfaces/tobago/apt/annotation/DynamicExpression.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-annotation/src/main/java/org/apache/myfaces/tobago/apt/annotation/DynamicExpression.java?rev=636712&r1=636711&r2=636712&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-annotation/src/main/java/org/apache/myfaces/tobago/apt/annotation/DynamicExpression.java (original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-annotation/src/main/java/org/apache/myfaces/tobago/apt/annotation/DynamicExpression.java Thu Mar 13 04:14:02 2008
@@ -24,15 +24,54 @@
*/
public enum DynamicExpression {
- VALUE_BINDING, METHOD_BINDING, NONE;
+ VALUE_BINDING(false, true), VALUE_BINDING_REQUIRED(true, true),
+ METHOD_BINDING(false, false), METHOD_BINDING_REQUIRED(true, false),
+ PROHIBITED(false, false);
+
+ private boolean required;
+ private boolean valueExpression;
+
+ DynamicExpression(boolean required, boolean valueExpression) {
+ this.required = required;
+ this.valueExpression = valueExpression;
+ }
+
+ public boolean isRequired() {
+ return required;
+ }
+
+ public boolean isValueExpression() {
+ return valueExpression;
+ }
+
+ public String toMetaDataString() {
+ switch (this) {
+ case VALUE_BINDING:
+ return "ALLOWED";
+ case METHOD_BINDING:
+ return "ALLOWED";
+ case VALUE_BINDING_REQUIRED:
+ return "REQUIRED";
+ case METHOD_BINDING_REQUIRED:
+ return "REQUIRED";
+ case PROHIBITED:
+ return "PROHIBITED";
+ default:
+ throw new IllegalStateException("Unexpected DynamicExpression " + name());
+ }
+ }
public String toString() {
switch (this) {
case VALUE_BINDING:
return "VB";
+ case VALUE_BINDING_REQUIRED:
+ return "VB";
case METHOD_BINDING:
return "MB";
- case NONE:
+ case METHOD_BINDING_REQUIRED:
+ return "MB";
+ case PROHIBITED:
return "NONE";
default:
throw new IllegalStateException("Unexpected DynamicExpression " + name());
Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-annotation/src/main/java/org/apache/myfaces/tobago/apt/annotation/Tag.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-annotation/src/main/java/org/apache/myfaces/tobago/apt/annotation/Tag.java?rev=636712&r1=636711&r2=636712&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-annotation/src/main/java/org/apache/myfaces/tobago/apt/annotation/Tag.java (original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-annotation/src/main/java/org/apache/myfaces/tobago/apt/annotation/Tag.java Thu Mar 13 04:14:02 2008
@@ -39,4 +39,6 @@
String deprecatedName() default "";
+ boolean isBodyTag() default false;
+
}
Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-annotation/src/main/java/org/apache/myfaces/tobago/apt/annotation/UIComponentTag.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-annotation/src/main/java/org/apache/myfaces/tobago/apt/annotation/UIComponentTag.java?rev=636712&r1=636711&r2=636712&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-annotation/src/main/java/org/apache/myfaces/tobago/apt/annotation/UIComponentTag.java (original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-annotation/src/main/java/org/apache/myfaces/tobago/apt/annotation/UIComponentTag.java Thu Mar 13 04:14:02 2008
@@ -35,27 +35,44 @@
String uiComponent();
+ String uiComponentBaseClass() default "javax.faces.component.UIComponentBase";
+
+ String componentType() default "";
+
+ String componentFamily() default "";
+
String rendererType() default "";
String displayName() default "";
+ boolean isLayout() default false;
+
+ boolean isAjaxEnabled() default false;
+
+ boolean namingContainer() default false;
+
Facet[] facets() default {};
+ boolean generate() default true;
+
boolean isComponentAlreadyDefined() default false;
/**
* Array of supported component-types that explictly enumerates the
* set of allowd component children for this component. Other possible values are: ALL...
+ * @return
*/
String [] allowedChildComponenents() default { "ALL" };
/**
* Specifies the category of a component palette.
+ * @return
*/
Category category() default Category.GENERAL;
/**
* Specifies whether this component should be available on a component palette.
+ * @return
*/
boolean isHidden() default false;
Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-annotation/src/main/java/org/apache/myfaces/tobago/apt/annotation/UIComponentTagAttribute.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-annotation/src/main/java/org/apache/myfaces/tobago/apt/annotation/UIComponentTagAttribute.java?rev=636712&r1=636711&r2=636712&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-annotation/src/main/java/org/apache/myfaces/tobago/apt/annotation/UIComponentTagAttribute.java (original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-annotation/src/main/java/org/apache/myfaces/tobago/apt/annotation/UIComponentTagAttribute.java Thu Mar 13 04:14:02 2008
@@ -40,11 +40,11 @@
/** allow faces expression language, e.g. #{bean} */
DynamicExpression expression() default DynamicExpression.VALUE_BINDING;
+ String[] methodSignature() default { };
+
String defaultValue() default "";
String displayName() default "";
-
- String valueExpression() default "ALLOWED";
/**
* Specifies whether this property should be visible
Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/pom.xml?rev=636712&r1=636711&r2=636712&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/pom.xml (original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/pom.xml Thu Mar 13 04:14:02 2008
@@ -68,6 +68,11 @@
<version>1.0.5</version>
</dependency>
<dependency>
+ <groupId>org.antlr</groupId>
+ <artifactId>stringtemplate</artifactId>
+ <version>3.0</version>
+ </dependency>
+ <dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.0</version>
Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/AnnotationDeclarationVisitorCollector.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/AnnotationDeclarationVisitorCollector.java?rev=636712&r1=636711&r2=636712&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/AnnotationDeclarationVisitorCollector.java (original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/AnnotationDeclarationVisitorCollector.java Thu Mar 13 04:14:02 2008
@@ -30,7 +30,6 @@
/*
* Created: Mar 22, 2005 8:12:24 PM
- * User: bommel
* $Id$
*/
public class AnnotationDeclarationVisitorCollector extends SimpleDeclarationVisitor {
Added: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CreateComponentAnnotationProcessor.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CreateComponentAnnotationProcessor.java?rev=636712&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CreateComponentAnnotationProcessor.java (added)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CreateComponentAnnotationProcessor.java Thu Mar 13 04:14:02 2008
@@ -0,0 +1,58 @@
+package org.apache.myfaces.tobago.apt;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import com.sun.mirror.apt.AnnotationProcessor;
+import com.sun.mirror.apt.AnnotationProcessorEnvironment;
+import com.sun.mirror.declaration.AnnotationTypeDeclaration;
+import com.sun.mirror.declaration.Declaration;
+import com.sun.mirror.util.DeclarationVisitors;
+
+import javax.xml.parsers.ParserConfigurationException;
+import java.util.Set;
+import java.util.Collection;
+import java.io.IOException;
+
+
+public class CreateComponentAnnotationProcessor implements AnnotationProcessor {
+ private final AnnotationProcessorEnvironment env;
+ private final Set<AnnotationTypeDeclaration> atds;
+
+ public CreateComponentAnnotationProcessor(Set<AnnotationTypeDeclaration> atds,
+ AnnotationProcessorEnvironment env) {
+ this.atds = atds;
+ this.env = env;
+ this.env.getMessager().printNotice("Starting annotation process");
+ }
+
+ public void process() {
+ CreateComponentAnnotationVisitor visitor = new CreateComponentAnnotationVisitor(env);
+
+ for (AnnotationTypeDeclaration atd : atds) {
+ System.err.println("Collecting annotation " + atd);
+ env.getMessager().printNotice("Collecting annotation "+atd);
+ Collection<Declaration> decls = env.getDeclarationsAnnotatedWith(atd);
+ for (Declaration decl : decls) {
+ decl.accept(DeclarationVisitors.getDeclarationScanner(visitor, DeclarationVisitors.NO_OP));
+ }
+ }
+
+ visitor.process();
+
+ }
+}
Propchange: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CreateComponentAnnotationProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CreateComponentAnnotationProcessor.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CreateComponentAnnotationProcessorFactory.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CreateComponentAnnotationProcessorFactory.java?rev=636712&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CreateComponentAnnotationProcessorFactory.java (added)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CreateComponentAnnotationProcessorFactory.java Thu Mar 13 04:14:02 2008
@@ -0,0 +1,59 @@
+package org.apache.myfaces.tobago.apt;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import com.sun.mirror.apt.AnnotationProcessorFactory;
+import com.sun.mirror.apt.AnnotationProcessor;
+import com.sun.mirror.apt.AnnotationProcessorEnvironment;
+import com.sun.mirror.declaration.AnnotationTypeDeclaration;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Arrays;
+import java.util.Set;
+
+public class CreateComponentAnnotationProcessorFactory implements AnnotationProcessorFactory {
+
+ private static final Collection<String> SUPPORTED_ANNOTATIONS
+ = Collections.unmodifiableCollection(Arrays.asList(
+ "org.apache.myfaces.tobago.apt.annotation.Tag",
+ "org.apache.myfaces.tobago.apt.annotation.TagAttribute",
+ "org.apache.myfaces.tobago.apt.annotation.UIComponentTag",
+ "org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute",
+ "org.apache.myfaces.tobago.apt.annotation.Taglib"));
+
+ private static final Collection<String> SUPPORTED_OPTIONS = Collections.EMPTY_LIST;
+
+ private CreateComponentAnnotationProcessor annotationProcessor = null;
+
+ public Collection<String> supportedAnnotationTypes() {
+ return SUPPORTED_ANNOTATIONS;
+ }
+
+ public Collection<String> supportedOptions() {
+ return SUPPORTED_OPTIONS;
+ }
+
+ public AnnotationProcessor getProcessorFor(Set<AnnotationTypeDeclaration> atds,
+ AnnotationProcessorEnvironment env) {
+ if (annotationProcessor == null) {
+ annotationProcessor = new CreateComponentAnnotationProcessor(atds, env);
+ }
+ return annotationProcessor;
+ }
+}
Propchange: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CreateComponentAnnotationProcessorFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CreateComponentAnnotationProcessorFactory.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CreateComponentAnnotationVisitor.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CreateComponentAnnotationVisitor.java?rev=636712&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CreateComponentAnnotationVisitor.java (added)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CreateComponentAnnotationVisitor.java Thu Mar 13 04:14:02 2008
@@ -0,0 +1,253 @@
+package org.apache.myfaces.tobago.apt;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.antlr.stringtemplate.StringTemplateGroup;
+import org.antlr.stringtemplate.StringTemplate;
+import org.apache.myfaces.tobago.apt.generate.RendererInfo;
+import org.apache.myfaces.tobago.apt.generate.TagInfo;
+import org.apache.myfaces.tobago.apt.generate.ClassInfo;
+import org.apache.myfaces.tobago.apt.generate.PropertyInfo;
+import org.apache.myfaces.tobago.apt.generate.ComponentPropertyInfo;
+import org.apache.myfaces.tobago.apt.annotation.UIComponentTag;
+import org.apache.myfaces.tobago.apt.annotation.Tag;
+import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
+import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
+import org.apache.commons.io.IOUtils;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.Writer;
+import java.io.File;
+import java.io.IOException;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Collection;
+import java.util.Arrays;
+import java.lang.reflect.Method;
+
+import com.sun.mirror.apt.AnnotationProcessorEnvironment;
+import com.sun.mirror.apt.Filer;
+import com.sun.mirror.declaration.InterfaceDeclaration;
+import com.sun.mirror.declaration.TypeDeclaration;
+import com.sun.mirror.declaration.MethodDeclaration;
+import com.sun.mirror.type.InterfaceType;
+
+/*
+ * Date: Apr 22, 2007
+ * Time: 10:26:23 PM
+ */
+public class CreateComponentAnnotationVisitor extends AbstractAnnotationVisitor {
+
+ private StringTemplateGroup rendererStringTemplateGroup;
+ private StringTemplateGroup tagStringTemplateGroup;
+ private StringTemplateGroup componentStringTemplateGroup;
+ private Set<String> renderer = new HashSet<String>();
+ private Set<String> ignoredProperties;
+
+ public CreateComponentAnnotationVisitor(AnnotationProcessorEnvironment env) {
+ super(env);
+ InputStream stream = getClass().getClassLoader().getResourceAsStream("org/apache/myfaces/tobago/apt/renderer.stg");
+ Reader reader = new InputStreamReader(stream);
+ rendererStringTemplateGroup = new StringTemplateGroup(reader);
+ stream = getClass().getClassLoader().getResourceAsStream("org/apache/myfaces/tobago/apt/tag.stg");
+ reader = new InputStreamReader(stream);
+ tagStringTemplateGroup = new StringTemplateGroup(reader);
+ stream = getClass().getClassLoader().getResourceAsStream("org/apache/myfaces/tobago/apt/component.stg");
+ reader = new InputStreamReader(stream);
+ componentStringTemplateGroup = new StringTemplateGroup(reader);
+ ignoredProperties = new HashSet<String>();
+ ignoredProperties.add("id");
+ ignoredProperties.add("rendered");
+ ignoredProperties.add("binding");
+
+ }
+
+ public void process() {
+ for (InterfaceDeclaration decl : getCollectedInterfaceDeclarations()) {
+ if (decl.getAnnotation(UIComponentTag.class) != null) {
+ createRenderer(decl);
+ System.err.println(decl);
+ System.err.println(decl.getAnnotation(Tag.class));
+ if (decl.getAnnotation(Tag.class) != null) {
+ createTag(decl);
+ }
+ }
+ }
+ }
+
+ private void createTag(InterfaceDeclaration decl) {
+ Tag tag = decl.getAnnotation(Tag.class);
+ UIComponentTag componentTag = decl.getAnnotation(UIComponentTag.class);
+ String className = "org.apache.myfaces.tobago.internal.taglib."
+ + tag.name().substring(0, 1).toUpperCase(Locale.ENGLISH) + tag.name().substring(1) + "Tag";
+ TagInfo tagInfo = new TagInfo(className, componentTag.rendererType());
+ if (tag.isBodyTag()) {
+ tagInfo.setSuperClass("org.apache.myfaces.tobago.taglib.component.TobagoBodyTag");
+ } else {
+ tagInfo.setSuperClass("org.apache.myfaces.tobago.taglib.component.TobagoTag");
+ }
+ tagInfo.setComponentClassName(componentTag.uiComponent());
+
+ StringTemplate stringTemplate = tagStringTemplateGroup.getInstanceOf("tag");
+ stringTemplate.setAttribute("tagInfo", tagInfo);
+ addProperties(decl, tagInfo);
+ if (componentTag.generate()) {
+ StringTemplate componentStringTemplate = componentStringTemplateGroup.getInstanceOf("component");
+ TagInfo componentInfo = new TagInfo(componentTag.uiComponent(), componentTag.rendererType());
+ componentInfo.setSuperClass(componentTag.uiComponentBaseClass());
+ componentInfo.setComponentFamily(componentTag.componentFamily());
+ componentInfo.setNamingContainer(componentTag.namingContainer());
+ componentInfo.setAjaxComponent(componentTag.isAjaxEnabled());
+ if (componentInfo.isAjaxComponent()) {
+ componentInfo.addInterface("org.apache.myfaces.tobago.ajax.api.AjaxComponent");
+ }
+ if (componentInfo.isNamingContainer()) {
+ componentInfo.addInterface("javax.faces.component.NamingContainer");
+ }
+ if (componentTag.componentType().length() > 0) {
+ componentInfo.setComponentType(componentTag.componentType());
+ } else {
+ componentInfo.setComponentType(componentTag.uiComponent().replace(".component.UI", "."));
+ }
+ try {
+ Class compenentClass = Class.forName(componentTag.uiComponentBaseClass());
+ int index = 0;
+ for (PropertyInfo info:tagInfo.getProperties()) {
+ try {
+ Method method = compenentClass.getMethod("get" + info.getUpperCamelCaseName());
+ } catch (NoSuchMethodException e) {
+ ComponentPropertyInfo componentPropertyInfo =
+ (ComponentPropertyInfo) info.fill(new ComponentPropertyInfo());
+ componentPropertyInfo.setIndex(index);
+ componentInfo.getProperties().add(componentPropertyInfo);
+ if ("markup".equals(info.getName())) {
+ componentInfo.setMarkup(true);
+ }
+ index++;
+ }
+ }
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ if (componentInfo.hasMarkup()) {
+ componentInfo.addInterface("org.apache.myfaces.tobago.component.SupportsMarkup");
+ }
+
+ componentStringTemplate.setAttribute("componentInfo", componentInfo);
+ writeFile(componentInfo, componentStringTemplate);
+ }
+
+ writeFile(tagInfo, stringTemplate);
+ }
+
+ private void createRenderer(TypeDeclaration decl) {
+ UIComponentTag componentTag = decl.getAnnotation(UIComponentTag.class);
+
+ String rendererType = componentTag.rendererType();
+
+ if (rendererType != null && rendererType.length() > 0) {
+ String className = "org.apache.myfaces.tobago.renderkit." + rendererType + "Renderer";
+ if (renderer.contains(className)) {
+ // allready created
+ return;
+ }
+ renderer.add(className);
+ RendererInfo info = new RendererInfo(className, rendererType);
+ if (componentTag.isLayout()) {
+ info.setSuperClass("org.apache.myfaces.tobago.renderkit.AbstractLayoutRendererWrapper");
+ } else if (componentTag.isAjaxEnabled()) {
+ info.setSuperClass("org.apache.myfaces.tobago.renderkit.AbstractAjaxRendererBaseWrapper");
+ } else {
+ info.setSuperClass("org.apache.myfaces.tobago.renderkit.AbstractLayoutableRendererBaseWrapper");
+ }
+ if (componentTag.isAjaxEnabled()) {
+ info.addInterface("org.apache.myfaces.tobago.ajax.api.AjaxRenderer");
+ }
+ StringTemplate stringTemplate = rendererStringTemplateGroup.getInstanceOf("renderer");
+ stringTemplate.setAttribute("renderInfo", info);
+ writeFile(info, stringTemplate);
+ }
+ }
+
+ protected void addProperties(InterfaceDeclaration type, TagInfo info) {
+ addProperties(type.getSuperinterfaces(), info);
+ for (MethodDeclaration decl : getCollectedMethodDeclarations()) {
+ if (decl.getDeclaringType().equals(type)) {
+ addProperty(decl, info);
+ }
+ }
+ }
+
+ protected void addProperties(Collection<InterfaceType> interfaces, TagInfo info) {
+ for (InterfaceType type : interfaces) {
+ addProperties(type.getDeclaration(), info);
+ }
+ }
+
+ protected void addProperty(MethodDeclaration decl, TagInfo info) {
+ TagAttribute tagAttribute = decl.getAnnotation(TagAttribute.class);
+ UIComponentTagAttribute uiComponentTagAttribute = decl.getAnnotation(UIComponentTagAttribute.class);
+ if (uiComponentTagAttribute != null) {
+ String simpleName = decl.getSimpleName();
+ if (simpleName.startsWith("set")) {
+ String attributeStr = simpleName.substring(3, 4).toLowerCase(Locale.ENGLISH) + simpleName.substring(4);
+ if (ignoredProperties.contains(attributeStr)) {
+ return;
+ }
+ PropertyInfo propertyInfo = new PropertyInfo(attributeStr);
+ propertyInfo.setAllowdValues(uiComponentTagAttribute.allowedValues());
+ String type;
+ if (uiComponentTagAttribute.expression().isRequired()) {
+ if (uiComponentTagAttribute.expression().isValueExpression()) {
+ type = "javax.faces.el.ValueBinding";
+ } else {
+ type = "javax.faces.el.MethodBinding";
+ }
+ } else if (uiComponentTagAttribute.type().length == 1) {
+ type = uiComponentTagAttribute.type()[0];
+ } else {
+ throw new IllegalArgumentException("Type should be single argument "
+ + Arrays.toString(uiComponentTagAttribute.type()));
+ }
+ propertyInfo.setType(type);
+ propertyInfo.setDefaultValue(uiComponentTagAttribute.defaultValue().length() > 0
+ ?uiComponentTagAttribute.defaultValue():null);
+ propertyInfo.setMethodSignature(uiComponentTagAttribute.methodSignature());
+ propertyInfo.setDeprecated(decl.getAnnotation(Deprecated.class) != null);
+ // TODO
+ info.getProperties().add(propertyInfo);
+ }
+ }
+ }
+
+ private void writeFile(ClassInfo info, StringTemplate stringTemplate) {
+ Writer writer = null;
+ try {
+ writer = getEnv().getFiler().createTextFile(Filer.Location.SOURCE_TREE, info.getPackageName(),
+ new File(info.getClassName() + ".java"), null);
+ writer.append(stringTemplate.toString());
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ IOUtils.closeQuietly(writer);
+ }
+ }
+}
Propchange: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CreateComponentAnnotationVisitor.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FaceletAnnotationProcessorFactory.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FaceletAnnotationProcessorFactory.java?rev=636712&r1=636711&r2=636712&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FaceletAnnotationProcessorFactory.java (original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FaceletAnnotationProcessorFactory.java Thu Mar 13 04:14:02 2008
@@ -36,9 +36,11 @@
public class FaceletAnnotationProcessorFactory implements AnnotationProcessorFactory {
private static final Collection<String> SUPPORTED_ANNOTATIONS
- = Collections.unmodifiableCollection(Arrays.asList("org.apache.myfaces.tobago.apt.annotation.Tag",
- "org.apache.myfaces.tobago.apt.annotation.TagAttribute", "org.apache.myfaces.tobago.apt.annotation.Taglib",
- "org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute"));
+ = Collections.unmodifiableCollection(Arrays.asList(
+ "org.apache.myfaces.tobago.apt.annotation.Tag",
+ "org.apache.myfaces.tobago.apt.annotation.TagAttribute",
+ "org.apache.myfaces.tobago.apt.annotation.Taglib",
+ "org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute"));
private static final Collection<String> SUPPORTED_OPTIONS = Collections.emptyList();
Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationProcessorFactory.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationProcessorFactory.java?rev=636712&r1=636711&r2=636712&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationProcessorFactory.java (original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationProcessorFactory.java Thu Mar 13 04:14:02 2008
@@ -34,11 +34,17 @@
public class FacesConfigAnnotationProcessorFactory implements AnnotationProcessorFactory {
private static final Collection<String> SUPPORTED_ANNOTATIONS
- = Collections.unmodifiableCollection(Arrays.asList("org.apache.myfaces.tobago.apt.annotation.Tag",
- "org.apache.myfaces.tobago.apt.annotation.TagAttribute", "org.apache.myfaces.tobago.apt.annotation.Taglib",
+ = Collections.unmodifiableCollection(Arrays.asList(
+ "org.apache.myfaces.tobago.apt.annotation.Tag",
+ "org.apache.myfaces.tobago.apt.annotation.TagAttribute",
+ "org.apache.myfaces.tobago.apt.annotation.Taglib",
"org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute",
+ "org.apache.myfaces.tobago.apt.annotation.UIComponentTag",
+ "org.apache.myfaces.tobago.apt.annotation.Facet",
+ "org.apache.myfaces.tobago.apt.annotation.Preliminary",
"org.apache.myfaces.tobago.apt.annotation.Converter",
- "org.apache.myfaces.tobago.apt.annotation.Validator"));
+ "org.apache.myfaces.tobago.apt.annotation.Validator"
+ ));
private static final Collection<String> SUPPORTED_OPTIONS =
Collections.unmodifiableCollection(Arrays.asList(FacesConfigAnnotationVisitor.SOURCE_FACES_CONFIG_KEY,
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?rev=636712&r1=636711&r2=636712&view=diff
==============================================================================
--- 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 Thu Mar 13 04:14:02 2008
@@ -22,7 +22,6 @@
import com.sun.mirror.declaration.ClassDeclaration;
import com.sun.mirror.declaration.InterfaceDeclaration;
import com.sun.mirror.declaration.MethodDeclaration;
-import com.sun.mirror.declaration.PackageDeclaration;
import com.sun.mirror.declaration.TypeDeclaration;
import com.sun.mirror.type.InterfaceType;
import org.apache.commons.io.IOUtils;
@@ -107,6 +106,13 @@
private static final String VALIDATOR_ID = "validator-id";
private static final String VALIDATOR_FOR_CLASS = "validator-for-class";
private static final String VALIDATOR_CLASS = "validator-class";
+ private static final String RENDERER = "renderer";
+ private static final String COMPONENT_FAMILY = "component-family";
+ private static final String RENDER_KIT = "render-kit";
+ private static final String RENDER_KIT_ID = "render-kit-id";
+ private static final String RENDER_KIT_CLASS = "render-kit-class";
+ private static final String RENDERER_TYPE = "renderer-type";
+ private static final String RENDERER_CLASS = "renderer-class";
public FacesConfigAnnotationVisitor(AnnotationProcessorEnvironment env) {
super(env);
@@ -123,113 +129,121 @@
targetFacesConfigFile = entry.getKey().substring(TARGET_FACES_CONFIG_KEY.length() + 3);
}
}
- // TODO remove the foreach
- for (PackageDeclaration packageDeclaration : getCollectedPackageDeclarations()) {
- Document document;
- Writer writer = null;
- try {
- String content = FileUtils.fileRead(sourceFacesConfigFile);
- SAXBuilder builder = new SAXBuilder();
- builder.setEntityResolver(new EntityResolver() {
- public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
- if ("-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN".equals(publicId)) {
- InputStream stream = FacesConfigAnnotationVisitor.class.getResourceAsStream(
- "/org/apache/myfaces/tobago/dtd/web-facesconfig_1_1.dtd");
- return new InputSource(stream);
- }
- return null;
- }
- });
- document = builder.build(new StringReader(content));
-
- // Normalise line endings. For some reason, JDOM replaces \r\n inside a comment with \n.
- normaliseLineEndings(document);
-
- // rewrite DOM as a string to find differences, since text outside the root element is not tracked
-
- Element rootElement = document.getRootElement();
- Namespace namespace = rootElement.getNamespace();
- List<Element> components = rootElement.getChildren(COMPONENT, namespace);
-
- List<Element> newComponents = new ArrayList<Element>();
- List<Element> newConverters = new ArrayList<Element>();
- List<Element> newValidators = new ArrayList<Element>();
-
- for (ClassDeclaration decl : getCollectedClassDeclarations()) {
- if (decl.getPackage().equals(packageDeclaration)
- && decl.getAnnotation(UIComponentTag.class) != null) {
- addElement(decl, newComponents, namespace);
- } else if (decl.getAnnotation(Converter.class) != null) {
- addConverter(decl, newConverters, namespace);
- } else if (decl.getAnnotation(Validator.class) != null) {
- addValidator(decl, newValidators, namespace);
- }
- }
-
- for (InterfaceDeclaration decl : getCollectedInterfaceDeclarations()) {
- if (decl.getPackage().equals(packageDeclaration)) {
- addElement(decl, newComponents, namespace);
+ Document document;
+ Writer writer = null;
+ try {
+ String content = FileUtils.fileRead(sourceFacesConfigFile);
+ SAXBuilder builder = new SAXBuilder();
+ builder.setEntityResolver(new EntityResolver() {
+ public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
+ if ("-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN".equals(publicId)) {
+ InputStream stream = FacesConfigAnnotationVisitor.class.getResourceAsStream(
+ "/org/apache/myfaces/tobago/dtd/web-facesconfig_1_1.dtd");
+ return new InputSource(stream);
}
+ return null;
}
- List<Element> elementsToAdd = new ArrayList<Element>();
- // sort out duplicates
- for (Element newElement : newComponents) {
- boolean found = containsElement(components, newElement);
- if (!found) {
+ });
+ document = builder.build(new StringReader(content));
- elementsToAdd.add(newElement);
- }
- }
- if (!elementsToAdd.isEmpty()) {
- // if facesconfig contains no component section add the components after factory or application
- int lastIndex = getIndexAfter(rootElement, COMPONENT, FACTORY, APPLICATION);
- rootElement.addContent(lastIndex, elementsToAdd);
- }
- if (!newConverters.isEmpty()) {
- int lastIndex = getIndexAfter(rootElement, CONVERTER, COMPONENT, FACTORY, APPLICATION);
- rootElement.addContent(lastIndex, newConverters);
- }
- if (!newValidators.isEmpty()) {
- rootElement.addContent(newValidators);
- }
- document.setDocType(new DocType("faces-config",
- "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN",
- "http://java.sun.com/dtd/web-facesconfig_1_1.dtd"));
-
- writer =
- getEnv().getFiler().createTextFile(Filer.Location.SOURCE_TREE, "", new File(targetFacesConfigFile), null);
-
- StringWriter facesConfig = new StringWriter(1024);
- Format format = Format.getPrettyFormat();
- format.setLineSeparator(SEPARATOR);
- XMLOutputter out = new XMLOutputter(format);
-
- out.output(document, facesConfig);
- // TODO: is this replace really necessary?
- String facesConfigStr =
- facesConfig.toString().replaceFirst(" xmlns=\"http://java.sun.com/JSF/Configuration\"", "");
- // TODO: Find a better way
- facesConfigStr = facesConfigStr.replaceFirst("\"http://java.sun.com/dtd/web-facesconfig_1_1.dtd\"",
- "\"http://java.sun.com/dtd/web-facesconfig_1_1.dtd\"[\n"
- + "<!ELEMENT allowed-child-components (#PCDATA)>\n"
- + "<!ELEMENT category (#PCDATA)>\n"
- + "<!ELEMENT deprecated (#PCDATA)>\n"
- + "<!ELEMENT hidden (#PCDATA)>\n"
- + "<!ELEMENT preferred (#PCDATA)>\n"
- + "<!ELEMENT read-only (#PCDATA)>\n"
- + "<!ELEMENT value-expression (#PCDATA)>\n"
- + "<!ELEMENT property-values (#PCDATA)>\n"
- + "<!ELEMENT required (#PCDATA)>\n"
- + "]");
- writer.append(facesConfigStr);
+ // Normalise line endings. For some reason, JDOM replaces \r\n inside a comment with \n.
+ normaliseLineEndings(document);
- } catch (JDOMException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- IOUtils.closeQuietly(writer);
- }
+ // rewrite DOM as a string to find differences, since text outside the root element is not tracked
+
+ Element rootElement = document.getRootElement();
+ Namespace namespace = rootElement.getNamespace();
+ List<Element> components = rootElement.getChildren(COMPONENT, namespace);
+
+ List<Element> newComponents = new ArrayList<Element>();
+ List<Element> newRenderer = new ArrayList<Element>();
+ List<Element> newConverters = new ArrayList<Element>();
+ List<Element> newValidators = new ArrayList<Element>();
+
+ for (ClassDeclaration decl : getCollectedClassDeclarations()) {
+ if (decl.getAnnotation(UIComponentTag.class) != null) {
+ addElement(decl, newComponents, newRenderer, namespace);
+ } else if (decl.getAnnotation(Converter.class) != null) {
+ addConverter(decl, newConverters, namespace);
+ } else if (decl.getAnnotation(Validator.class) != null) {
+ addValidator(decl, newValidators, namespace);
+ }
+ }
+
+ for (InterfaceDeclaration decl : getCollectedInterfaceDeclarations()) {
+ if (decl.getAnnotation(UIComponentTag.class) != null) {
+ addElement(decl, newComponents, newRenderer, namespace);
+ }
+ }
+ List<Element> elementsToAdd = new ArrayList<Element>();
+ // sort out duplicates
+ for (Element newElement : newComponents) {
+ boolean found = containsElement(components, newElement);
+ if (!found) {
+ elementsToAdd.add(newElement);
+ }
+ }
+ if (!elementsToAdd.isEmpty()) {
+ // if facesconfig contains no component section add the components after factory or application
+ int lastIndex = getIndexAfter(rootElement, COMPONENT, FACTORY, APPLICATION);
+ rootElement.addContent(lastIndex, elementsToAdd);
+ }
+ if (!newRenderer.isEmpty()) {
+ Element renderKit = new Element(RENDER_KIT, namespace);
+ Element renderKitId = new Element(RENDER_KIT_ID, namespace);
+ renderKitId.setText("tobago");
+ renderKit.addContent(renderKitId);
+ Element renderKitClass = new Element(RENDER_KIT_CLASS, namespace);
+ renderKitClass.setText("org.apache.myfaces.tobago.renderkit.TobagoRenderKit");
+ renderKit.addContent(renderKitClass);
+ renderKit.addContent(newRenderer);
+ int lastIndex = getIndexAfter(rootElement, CONVERTER, COMPONENT, FACTORY, APPLICATION);
+ rootElement.addContent(lastIndex, renderKit);
+ }
+ if (!newConverters.isEmpty()) {
+ int lastIndex = getIndexAfter(rootElement, RENDER_KIT, CONVERTER, COMPONENT, FACTORY, APPLICATION);
+ rootElement.addContent(lastIndex, newConverters);
+ }
+ if (!newValidators.isEmpty()) {
+ rootElement.addContent(newValidators);
+ }
+ document.setDocType(new DocType("faces-config",
+ "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN",
+ "http://java.sun.com/dtd/web-facesconfig_1_1.dtd"));
+
+ writer =
+ getEnv().getFiler().createTextFile(Filer.Location.SOURCE_TREE, "", new File(targetFacesConfigFile), null);
+
+ StringWriter facesConfig = new StringWriter(1024);
+ Format format = Format.getPrettyFormat();
+ format.setLineSeparator(SEPARATOR);
+ XMLOutputter out = new XMLOutputter(format);
+
+ out.output(document, facesConfig);
+ // TODO: is this replace really necessary?
+ String facesConfigStr =
+ facesConfig.toString().replaceFirst(" xmlns=\"http://java.sun.com/JSF/Configuration\"", "");
+ // TODO: Find a better way
+ facesConfigStr = facesConfigStr.replaceFirst("\"http://java.sun.com/dtd/web-facesconfig_1_1.dtd\"",
+ "\"http://java.sun.com/dtd/web-facesconfig_1_1.dtd\"[\n"
+ + "<!ELEMENT allowed-child-components (#PCDATA)>\n"
+ + "<!ELEMENT category (#PCDATA)>\n"
+ + "<!ELEMENT deprecated (#PCDATA)>\n"
+ + "<!ELEMENT hidden (#PCDATA)>\n"
+ + "<!ELEMENT preferred (#PCDATA)>\n"
+ + "<!ELEMENT read-only (#PCDATA)>\n"
+ + "<!ELEMENT value-expression (#PCDATA)>\n"
+ + "<!ELEMENT property-values (#PCDATA)>\n"
+ + "<!ELEMENT required (#PCDATA)>\n"
+ + "]");
+ writer.append(facesConfigStr);
+
+ } catch (JDOMException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ IOUtils.closeQuietly(writer);
}
}
@@ -314,7 +328,7 @@
return false;
}
- protected Element createElement(TypeDeclaration decl, UIComponentTag componentTag,
+ protected Element createComponentElement(TypeDeclaration decl, UIComponentTag componentTag,
Class uiComponentClass, Namespace namespace) throws IOException, NoSuchFieldException, IllegalAccessException {
Field componentField = uiComponentClass.getField("COMPONENT_TYPE");
String componentType = (String) componentField.get(null);
@@ -336,6 +350,35 @@
return element;
}
+ protected void addRendererElement(TypeDeclaration decl, UIComponentTag componentTag,
+ Class uiComponentClass, List<Element> renderer, Namespace namespace) throws IOException, NoSuchFieldException, IllegalAccessException {
+ String rendererType = componentTag.rendererType();
+ if (rendererType != null && rendererType.length() > 0) {
+ Field componentField = uiComponentClass.getField("COMPONENT_FAMILY");
+ String componentFamily = (String) componentField.get(null);
+ Element element = new Element(RENDERER, namespace);
+ String displayName = componentTag.displayName();
+ if (displayName.equals("")) {
+ displayName = uiComponentClass.getName().substring(uiComponentClass.getName().lastIndexOf(".") + 1);
+ }
+ Element elementDisplayName = new Element(DISPLAY_NAME, namespace);
+ elementDisplayName.setText(displayName);
+ element.addContent(elementDisplayName);
+ Element elementComponentFamily = new Element(COMPONENT_FAMILY, namespace);
+ elementComponentFamily.addContent(componentFamily);
+ element.addContent(elementComponentFamily);
+ Element elementType = new Element(RENDERER_TYPE, namespace);
+ elementType.setText(rendererType);
+ element.addContent(elementType);
+ Element elementClass = new Element(RENDERER_CLASS, namespace);
+ String className = "org.apache.myfaces.tobago.renderkit." + rendererType + "Renderer";
+ elementClass.setText(className);
+ element.addContent(elementClass);
+ renderer.add(element);
+ }
+ }
+
+
private Element createElementExtension(TypeDeclaration decl, UIComponentTag uiComponentTag,
Namespace namespace) {
Element elementExtension = new Element(COMPONENT_EXTENSION, namespace);
@@ -384,17 +427,17 @@
Element propertyName = new Element(PROPERTY_NAME, namespace);
Element propertyClass = new Element(PROPERTY_CLASS, namespace);
Element defaultValue = new Element(DEFAULT_VALUE, namespace);
-
+
propertyName.setText(attributeStr);
addClass(componentAttribute, propertyClass);
defaultValue.setText(componentAttribute.defaultValue());
-
+
addDescription(d, property, namespace);
-
+
property.addContent(propertyName);
property.addContent(propertyClass);
property.addContent(defaultValue);
-
+
property.addContent(createPropertyOrAttributeExtension(PROPERTY_EXTENSION, d, componentAttribute, namespace));
properties.add(property);
} catch (NoSuchMethodException e) {
@@ -409,11 +452,11 @@
defaultValue.setText(componentAttribute.defaultValue());
addDescription(d, attribute, namespace);
-
+
attribute.addContent(attributeName);
attribute.addContent(attributeClass);
attribute.addContent(defaultValue);
-
+
attribute.addContent(createPropertyOrAttributeExtension(ATTRIBUTE_EXTENSION, d,
componentAttribute, namespace));
@@ -453,12 +496,8 @@
private Element createPropertyOrAttributeExtension(String extensionType, MethodDeclaration methodDeclaration,
UIComponentTagAttribute uiComponentTagAttribute, Namespace namespace) throws IllegalArgumentException {
Element extensionElement = new Element(extensionType, namespace);
-// Element allowsValueBinding = new Element(ALLOWS_VALUE_BINDING, namespace);
-// DynamicExpression dynamicExpression = uiComponentTagAttribute.expression();
-// allowsValueBinding.setText((dynamicExpression == DynamicExpression.VALUE_BINDING) ? "true" : "false");
-// extensionElement.addContent(allowsValueBinding);
Element valueExpression = new Element(VALUE_EXPRESSION, namespace);
- valueExpression.setText(uiComponentTagAttribute.valueExpression());
+ valueExpression.setText(uiComponentTagAttribute.expression().toMetaDataString());
extensionElement.addContent(valueExpression);
String[] allowedValues = uiComponentTagAttribute.allowedValues();
if (allowedValues.length > 0) {
@@ -550,63 +589,69 @@
element.addContent(facetElement);
}
}
-
- protected void addElement(ClassDeclaration decl, List<Element> components, Namespace namespace) throws IOException {
+
+ protected void addElement(ClassDeclaration decl, List<Element> components, List<Element> renderer,
+ Namespace namespace) throws IOException {
UIComponentTag componentTag = decl.getAnnotation(UIComponentTag.class);
- if (componentTag != null && !componentTag.isComponentAlreadyDefined()) {
+ if (componentTag != null) {
try {
Class<?> uiComponentClass = Class.forName(componentTag.uiComponent());
- Element element = createElement(decl, componentTag, uiComponentClass, namespace);
- if (element != null) {
- if (!containsElement(components, element)) {
- addFacets(componentTag, namespace, element);
- List attributes = new ArrayList();
- List properties = new ArrayList();
- addAttributes(decl, uiComponentClass, attributes, properties, namespace);
- if (!attributes.isEmpty()) {
- element.addContent(attributes);
+ if (!componentTag.isComponentAlreadyDefined()) {
+ Element element = createComponentElement(decl, componentTag, uiComponentClass, namespace);
+ if (element != null) {
+ if (!containsElement(components, element)) {
+ addFacets(componentTag, namespace, element);
+ List attributes = new ArrayList();
+ List properties = new ArrayList();
+ addAttributes(decl, uiComponentClass, attributes, properties, namespace);
+ if (!attributes.isEmpty()) {
+ element.addContent(attributes);
+ }
+ if (!properties.isEmpty()) {
+ element.addContent(properties);
+ }
+ element.addContent(createElementExtension(decl, componentTag, namespace));
+ components.add(element);
+ } else {
+ // TODO add facet and attributes
}
- if (!properties.isEmpty()) {
- element.addContent(properties);
- }
- element.addContent(createElementExtension(decl, componentTag, namespace));
- components.add(element);
- } else {
- // TODO add facet and attributes
}
-
}
+ addRendererElement(decl, componentTag, uiComponentClass, renderer, namespace);
} catch (Exception e) {
e.printStackTrace();
}
}
}
- protected void addElement(InterfaceDeclaration decl, List<Element> components, Namespace namespace)
- throws IOException {
+ protected void addElement(InterfaceDeclaration decl, List<Element> components, List<Element> renderer,
+ Namespace namespace) throws IOException {
UIComponentTag componentTag = decl.getAnnotation(UIComponentTag.class);
- if (componentTag != null && !componentTag.isComponentAlreadyDefined()) {
+ if (componentTag != null) {
try {
Class<?> uiComponentClass = Class.forName(componentTag.uiComponent());
- Element element = createElement(decl, componentTag, uiComponentClass, namespace);
- if (element != null) {
- if (!containsElement(components, element)) {
- addFacets(componentTag, namespace, element);
- List attributes = new ArrayList();
- List properties = new ArrayList();
- addAttributes(decl, uiComponentClass, properties, attributes, namespace);
- if (!attributes.isEmpty()) {
- element.addContent(attributes);
- }
- if (!properties.isEmpty()) {
- element.addContent(properties);
+ if (!componentTag.isComponentAlreadyDefined()) {
+ Element element = createComponentElement(decl, componentTag, uiComponentClass, namespace);
+ if (element != null) {
+ if (!containsElement(components, element)) {
+ addFacets(componentTag, namespace, element);
+ List attributes = new ArrayList();
+ List properties = new ArrayList();
+ addAttributes(decl, uiComponentClass, properties, attributes, namespace);
+ if (!attributes.isEmpty()) {
+ element.addContent(attributes);
+ }
+ if (!properties.isEmpty()) {
+ element.addContent(properties);
+ }
+ element.addContent(createElementExtension(decl, componentTag, namespace));
+ components.add(element);
+ } else {
+ // TODO add facet and attributes
}
- element.addContent(createElementExtension(decl, componentTag, namespace));
- components.add(element);
- } else {
- // TODO add facet and attributes
}
}
+ addRendererElement(decl, componentTag, uiComponentClass, renderer, namespace);
} catch (Exception e) {
e.printStackTrace();
}
Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TaglibAnnotationProcessorFactory.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TaglibAnnotationProcessorFactory.java?rev=636712&r1=636711&r2=636712&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TaglibAnnotationProcessorFactory.java (original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TaglibAnnotationProcessorFactory.java Thu Mar 13 04:14:02 2008
@@ -29,15 +29,15 @@
/*
* Created: Mar 5, 2005 12:39:32 PM
- * User: bommel
* $Id$
*/
public class TaglibAnnotationProcessorFactory implements AnnotationProcessorFactory {
private static final Collection<String> SUPPORTED_ANNOTATIONS
- = Collections.unmodifiableCollection(Arrays.asList("org.apache.myfaces.tobago.apt.annotation.Tag",
- "org.apache.myfaces.tobago.apt.annotation.TagAttribute",
- "org.apache.myfaces.tobago.apt.annotation.Taglib"));
+ = Collections.unmodifiableCollection(Arrays.asList(
+ "org.apache.myfaces.tobago.apt.annotation.Tag",
+ "org.apache.myfaces.tobago.apt.annotation.TagAttribute",
+ "org.apache.myfaces.tobago.apt.annotation.Taglib"));
private static final Collection<String> SUPPORTED_OPTIONS = Collections.emptySet();
Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TaglibAnnotationVisitor.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TaglibAnnotationVisitor.java?rev=636712&r1=636711&r2=636712&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TaglibAnnotationVisitor.java (original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TaglibAnnotationVisitor.java Thu Mar 13 04:14:02 2008
@@ -56,7 +56,6 @@
/*
* Created: Mar 22, 2005 8:18:35 PM
- * User: bommel
*/
public class TaglibAnnotationVisitor extends AbstractAnnotationVisitor {
@@ -170,6 +169,11 @@
String className =
decl.getQualifiedName().substring(0, decl.getQualifiedName().length()-"Declaration".length());
+ if (decl.getAnnotation(UIComponentTag.class) != null) {
+ className = "org.apache.myfaces.tobago.internal.taglib."
+ + annotationTag.name().substring(0, 1).toUpperCase(Locale.ENGLISH)
+ + annotationTag.name().substring(1) + "Tag";
+ }
//decl.getQualifiedName().replaceAll("Declaration", "");
String msg = "Replacing: " + decl.getQualifiedName()
+ " -> " + className;
Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TobagoAnnotationProcessor.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TobagoAnnotationProcessor.java?rev=636712&r1=636711&r2=636712&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TobagoAnnotationProcessor.java (original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TobagoAnnotationProcessor.java Thu Mar 13 04:14:02 2008
@@ -29,7 +29,6 @@
/*
* Created: Apr 27, 2005 4:37:16 PM
- * User: bommel
* $Id$
*/
public class TobagoAnnotationProcessor implements AnnotationProcessor {
Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TobagoAnnotationProcessorFactory.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TobagoAnnotationProcessorFactory.java?rev=636712&r1=636711&r2=636712&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TobagoAnnotationProcessorFactory.java (original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TobagoAnnotationProcessorFactory.java Thu Mar 13 04:14:02 2008
@@ -35,9 +35,11 @@
public class TobagoAnnotationProcessorFactory implements AnnotationProcessorFactory {
private static final Collection<String> SUPPORTED_ANNOTATIONS
- = Collections.unmodifiableCollection(Arrays.asList("org.apache.myfaces.tobago.apt.annotation.Tag",
- "org.apache.myfaces.tobago.apt.annotation.TagAttribute", "org.apache.myfaces.tobago.apt.annotation.Taglib",
- "org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute"));
+ = Collections.unmodifiableCollection(Arrays.asList(
+ "org.apache.myfaces.tobago.apt.annotation.Tag",
+ "org.apache.myfaces.tobago.apt.annotation.TagAttribute",
+ "org.apache.myfaces.tobago.apt.annotation.Taglib",
+ "org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute"));
private static final Collection<String> SUPPORTED_OPTIONS = Collections.emptyList();
Added: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/ClassInfo.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/ClassInfo.java?rev=636712&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/ClassInfo.java (added)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/ClassInfo.java Thu Mar 13 04:14:02 2008
@@ -0,0 +1,85 @@
+package org.apache.myfaces.tobago.apt.generate;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.Set;
+import java.util.HashSet;
+
+
+public class ClassInfo {
+ private String className;
+ private String packageName;
+ private Imports imports;
+ private String superClassName;
+ private Set<String> interfaces = new HashSet<String>();
+
+ public ClassInfo(String qualifiedName) {
+ this.className = ClassUtils.getSimpleName(qualifiedName);
+ this.packageName = ClassUtils.getPackageName(qualifiedName);
+ imports = new Imports(packageName);
+ }
+
+ public String getClassName() {
+ return className;
+ }
+
+ public String getPackageName() {
+ return packageName;
+ }
+
+ public void setSuperClass(String qualifiedName) {
+ String name = ClassUtils.getSimpleName(qualifiedName);
+ if (!name.equals(className)) {
+ imports.addImport(qualifiedName);
+ this.superClassName = name;
+ } else {
+ this.superClassName = qualifiedName;
+ }
+ }
+
+ public String getSuperClassName() {
+ return superClassName;
+ }
+
+ public boolean hasSuperClass() {
+ return superClassName != null && superClassName.length() > 0;
+ }
+
+ public void addImport(String qualifiedName) {
+ imports.addImport(qualifiedName);
+ }
+
+ public Set<String> getImports() {
+ return imports.getImports();
+ }
+
+ public void addInterface(String qualifiedName) {
+ String name = ClassUtils.getSimpleName(qualifiedName);
+ if (!name.equals(className)) {
+ imports.addImport(qualifiedName);
+ this.interfaces.add(name);
+ } else {
+ this.interfaces.add(qualifiedName);
+ }
+ }
+
+ public Set<String> getInterfaces() {
+ return interfaces;
+ }
+
+}
Propchange: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/ClassInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/ClassInfo.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/ClassUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/ClassUtils.java?rev=636712&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/ClassUtils.java (added)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/ClassUtils.java Thu Mar 13 04:14:02 2008
@@ -0,0 +1,48 @@
+package org.apache.myfaces.tobago.apt.generate;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class ClassUtils {
+
+ public static String getPackageName(String qualifiedName) {
+ int pos = qualifiedName.lastIndexOf('.');
+ if (pos != -1) {
+ return qualifiedName.substring(0, pos);
+ }
+ return null;
+ }
+
+ public static String getSimpleName(String qualifiedName) {
+ int pos = qualifiedName.lastIndexOf('.');
+ if (pos != -1) {
+ return qualifiedName.substring(pos + 1);
+ }
+ return null;
+ }
+
+ public static boolean isSystemClass(String qualifiedClassName) {
+ return qualifiedClassName.startsWith("java.lang.");
+ }
+
+ public static boolean isPrimitive(String qualifiedClassName) {
+ return ("int".equals(qualifiedClassName) || "boolean".equals(qualifiedClassName) || "long".equals(qualifiedClassName) ||
+ "char".equals(qualifiedClassName) || "float".equals(qualifiedClassName) || "double".equals(qualifiedClassName) ||
+ "short".equals(qualifiedClassName) || "byte".equals(qualifiedClassName));
+
+ }
+}
Propchange: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/ClassUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/ClassUtils.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/ComponentPropertyInfo.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/ComponentPropertyInfo.java?rev=636712&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/ComponentPropertyInfo.java (added)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/ComponentPropertyInfo.java Thu Mar 13 04:14:02 2008
@@ -0,0 +1,46 @@
+package org.apache.myfaces.tobago.apt.generate;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class ComponentPropertyInfo extends PropertyInfo {
+ private int index;
+
+ public String getPropertyTemplate() {
+ return getShortType() + "Property";
+ }
+
+ public String getPropertySaveStateTemplate() {
+ return getShortType() + "SaveStateProperty";
+ }
+
+ public String getPropertyRestoreStateTemplate() {
+ return getShortType() + "RestoreStateProperty";
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ public void setIndex(int index) {
+ this.index = index;
+ }
+
+ public int getIndexPlusOne() {
+ return index + 1;
+ }
+}
Propchange: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/ComponentPropertyInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/ComponentPropertyInfo.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/Imports.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/Imports.java?rev=636712&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/Imports.java (added)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/Imports.java Thu Mar 13 04:14:02 2008
@@ -0,0 +1,61 @@
+package org.apache.myfaces.tobago.apt.generate;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.TreeSet;
+import java.util.Set;
+
+
+public class Imports {
+
+ private Set<String> imports = new TreeSet<String>();
+
+ private String packageName;
+
+ public Imports() {
+ }
+
+ public Imports(String packageName) {
+ this.packageName = packageName;
+ }
+
+ public void addImport(String qualifiedName) {
+ if (!ClassUtils.isSystemClass(qualifiedName) && !ClassUtils.isPrimitive(qualifiedName)) {
+ if (!(packageName != null && packageName.equals(ClassUtils.getPackageName(qualifiedName)))) {
+ if (!imports.contains(qualifiedName)) {
+ imports.add(qualifiedName);
+ }
+ }
+ }
+ }
+
+ public void addImports(Imports newImports) {
+ for (String qualifiedName : newImports.imports) {
+ addImport(qualifiedName);
+ }
+ }
+
+ public boolean contains(String qualifiedClassName) {
+ return imports.contains(qualifiedClassName);
+ }
+
+ public Set<String> getImports() {
+ return imports;
+ }
+
+}
Propchange: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/Imports.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/Imports.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/PropertyInfo.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/PropertyInfo.java?rev=636712&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/PropertyInfo.java (added)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/generate/PropertyInfo.java Thu Mar 13 04:14:02 2008
@@ -0,0 +1,114 @@
+package org.apache.myfaces.tobago.apt.generate;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.Locale;
+
+public class PropertyInfo {
+ private String name;
+ private String type;
+ private String[] allowdValues;
+ private String[] methodSignature;
+ private String defaultValue;
+ private boolean deprecated;
+
+ public PropertyInfo() {
+ }
+
+ public PropertyInfo(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public boolean isMethodBinding() {
+ return "javax.faces.el.MethodBinding".equals(type);
+ }
+
+ public String getShortType() {
+ String shortType = type.substring(type.lastIndexOf('.')+1, type.length());
+ return shortType.replace("[]", "Array");
+ }
+
+ public String getUpperCamelCaseName() {
+ return name.substring(0, 1).toUpperCase(Locale.ENGLISH) + name.substring(1);
+ }
+
+ public String getPropertyName() {
+ if (name.equals("for")) {
+ return "forComponent";
+ }
+ return name;
+ }
+
+ public String[] getAllowdValues() {
+ return allowdValues;
+ }
+
+ public void setAllowdValues(String[] allowdValues) {
+ this.allowdValues = allowdValues;
+ }
+
+ public String[] getMethodSignature() {
+ return methodSignature;
+ }
+
+ public void setMethodSignature(String[] methodSignature) {
+ this.methodSignature = methodSignature;
+ }
+
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ public void setDefaultValue(String defaultValue) {
+ this.defaultValue = defaultValue;
+ }
+
+ public void setDeprecated(boolean deprecated) {
+ this.deprecated = deprecated;
+ }
+
+ public boolean isDeprecated() {
+ return deprecated;
+ }
+
+ public PropertyInfo fill(PropertyInfo info) {
+ info.setName(name);
+ info.setType(type);
+ info.setAllowdValues(allowdValues);
+ info.setDefaultValue(defaultValue);
+ info.setDeprecated(deprecated);
+ info.setMethodSignature(methodSignature);
+ return info;
+ }
+}