Author: sabob
Date: Sat Mar 27 03:47:18 2010
New Revision: 928134
URL: http://svn.apache.org/viewvc?rev=928134&view=rev
Log:
added new default autobinding mode which binds both public and annotated fields. CLK-648
Added:
click/trunk/click/documentation/dtds/click-2.2.dtd
Modified:
click/trunk/click/documentation/docs/click-dtd-example.html
click/trunk/click/documentation/docs/click-dtd.html
click/trunk/click/documentation/docs/roadmap-changes.html
click/trunk/click/documentation/docs/upgrade-path.html
click/trunk/click/framework/src/org/apache/click/service/ConfigService.java
click/trunk/click/framework/src/org/apache/click/service/XmlConfigService.java
Modified: click/trunk/click/documentation/docs/click-dtd-example.html
URL: http://svn.apache.org/viewvc/click/trunk/click/documentation/docs/click-dtd-example.html?rev=928134&r1=928133&r2=928134&view=diff
==============================================================================
--- click/trunk/click/documentation/docs/click-dtd-example.html (original)
+++ click/trunk/click/documentation/docs/click-dtd-example.html Sat Mar 27 03:47:18 2010
@@ -37,11 +37,11 @@
Provides an example of all <a href="click-dtd.html">DTD</a> ELEMENTS and ATTRIBUTES:
<pre class="prettyprint">
-<!-- A Click Application (click.xml) Example. -->
+<!-- A complete Click Application (click.xml) Example. -->
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<click-app charset="UTF-8" locale="en">
- <!-- A automatically mapped Page package. Note automapping and autobinding is true
by default -->
+ <!-- An automatically mapped Page package. Note automapping and autobinding is true
by default -->
<pages package="com.mycorp.banking.page" automapping="true" autobinding="true">
<!-- A custom mapped Page -->
<page path="index.htm" classname="com.mycorp.page.Home"/>
Modified: click/trunk/click/documentation/docs/click-dtd.html
URL: http://svn.apache.org/viewvc/click/trunk/click/documentation/docs/click-dtd.html?rev=928134&r1=928133&r2=928134&view=diff
==============================================================================
--- click/trunk/click/documentation/docs/click-dtd.html (original)
+++ click/trunk/click/documentation/docs/click-dtd.html Sat Mar 27 03:47:18 2010
@@ -56,7 +56,7 @@ Click application XML descriptor Documen
<!ELEMENT <span class="red">pages</span> (<span class="blue">page</span>*,
<span class="blue">excludes</span>*)>
<!ATTLIST <span class="red">pages</span> <span class="blue">package</span>
CDATA #IMPLIED>
<!ATTLIST <span class="red">pages</span> <span class="blue">automapping</span>
(true|false) "<span class="green">true</span>">
- <!ATTLIST <span class="red">pages</span> <span class="blue">autobinding</span>
(annotation|public|none) "<span class="green">public</span>">
+ <!ATTLIST <span class="red">pages</span> <span class="blue">autobinding</span>
(default|annotation|public|none) "<span class="green">public</span>">
<!-- Page definition. -->
<!ELEMENT <span class="red">page</span> (<span class="blue">header</span>*)>
Modified: click/trunk/click/documentation/docs/roadmap-changes.html
URL: http://svn.apache.org/viewvc/click/trunk/click/documentation/docs/roadmap-changes.html?rev=928134&r1=928133&r2=928134&view=diff
==============================================================================
--- click/trunk/click/documentation/docs/roadmap-changes.html (original)
+++ click/trunk/click/documentation/docs/roadmap-changes.html Sat Mar 27 03:47:18 2010
@@ -177,6 +177,12 @@ includes improved Ajax support and @Bind
and <a href="click-api/org/apache/click/Context.html#hasRequestAttribute(java.lang.String)">Context.hasRequestAttribute(String)</a>.
</li>
<li class="change">
+ Improved default autobinding mode to bind both public fields and fields
+ annotated with @Bindable. In previous versions the default autobinding
+ mode only binded public Page fields
+ [<a target="_blank" href="https://issues.apache.org/jira/browse/CLK-648">CLK-648</a>].
+ </li>
+ <li class="change">
Added mock support for user <a href="mock-api/org/apache/click/servlet/MockPrincipal.html">principals</a>
and roles. This issue was raised and fixed by Sven Pfeiffer
[<a target="_blank" href="https://issues.apache.org/jira/browse/CLK-585">CLK-585</a>].
Modified: click/trunk/click/documentation/docs/upgrade-path.html
URL: http://svn.apache.org/viewvc/click/trunk/click/documentation/docs/upgrade-path.html?rev=928134&r1=928133&r2=928134&view=diff
==============================================================================
--- click/trunk/click/documentation/docs/upgrade-path.html (original)
+++ click/trunk/click/documentation/docs/upgrade-path.html Sat Mar 27 03:47:18 2010
@@ -106,6 +106,11 @@ versions please email the Click user gro
</li>
</ul>
</li>
+ <li class="change">
+ In previous releases, the default autobinding mode, binded only
+ public Page fields. In 2.2.0 the default autobinding mode binds
+ both public fields and fields annotated with @Bindable.
+ </li>
</ul>
</dd>
Added: click/trunk/click/documentation/dtds/click-2.2.dtd
URL: http://svn.apache.org/viewvc/click/trunk/click/documentation/dtds/click-2.2.dtd?rev=928134&view=auto
==============================================================================
--- click/trunk/click/documentation/dtds/click-2.2.dtd (added)
+++ click/trunk/click/documentation/dtds/click-2.2.dtd Sat Mar 27 03:47:18 2010
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!--
+ 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.
+-->
+
+<!--
+ DTD for the Click Application Configuration File, Version 2.2
+
+ To support validation of your configuration file, include the following
+ DOCTYPE element at the beginning (after the "xml" declaration):
+
+ <!DOCTYPE click-app PUBLIC
+ "-//Apache Software Foundation//DTD Click Configuration 2.2//EN"
+ "http://click.apache.org/dtds/click_2_2.dtd">
+-->
+
+<!-- The Click Application (click.xml) Document Type Definition. -->
+<!ELEMENT click-app (pages*, headers?, format?, mode?, controls?, file-upload-service?,
log-service?, template-service?)>
+ <!ATTLIST click-app charset CDATA #IMPLIED>
+ <!ATTLIST click-app locale CDATA #IMPLIED>
+
+ <!-- Application pages. -->
+ <!ELEMENT pages (page*, excludes*)>
+ <!ATTLIST pages package CDATA #IMPLIED>
+ <!ATTLIST pages automapping (true|false) "true">
+ <!ATTLIST pages autobinding (defualt|annotation|public|none) "annotation">
+
+ <!-- Page definition. -->
+ <!ELEMENT page (header*)>
+ <!ATTLIST page path CDATA #REQUIRED>
+ <!ATTLIST page classname CDATA #REQUIRED>
+
+ <!-- Excludes definition. -->
+ <!ELEMENT excludes (#PCDATA)>
+ <!ATTLIST excludes pattern CDATA #REQUIRED>
+
+ <!-- Application default page headers. -->
+ <!ELEMENT headers (header*)>
+
+ <!-- Header definition. -->
+ <!ELEMENT header (#PCDATA)>
+ <!ATTLIST header name CDATA #REQUIRED>
+ <!ATTLIST header value CDATA #REQUIRED>
+ <!ATTLIST header type (String|Integer|Date) "String">
+
+ <!-- Page template formatter class. An new format object added to
+ the Velocity context under the key: "format". -->
+ <!ELEMENT format (#PCDATA)>
+ <!ATTLIST format classname CDATA #FIXED "org.apache.click.util.Format">
+
+ <!-- Application mode, which configures logging and caching. -->
+ <!ELEMENT mode (#PCDATA)>
+ <!ATTLIST mode value (production|profile|development|debug|trace) "development">
+
+ <!-- Application control objects. -->
+ <!ELEMENT controls (control*, control-set*)>
+
+ <!-- Deployable control class. -->
+ <!ELEMENT control (#PCDATA)>
+ <!ATTLIST control classname CDATA #REQUIRED>
+
+ <!-- Deployable Third Party Set of Controls -->
+ <!ELEMENT control-set (#PCDATA)>
+ <!ATTLIST control-set name CDATA #REQUIRED>
+
+ <!-- File Upload Service. -->
+ <!ELEMENT file-upload-service (property*)>
+ <!ATTLIST file-upload-service classname CDATA #FIXED "org.apache.click.service.FileUploadService">
+
+ <!-- Property definition. -->
+ <!ELEMENT property (#PCDATA)>
+ <!ATTLIST property name CDATA #REQUIRED>
+ <!ATTLIST property value CDATA #REQUIRED>
+
+ <!-- Log Service. -->
+ <!ELEMENT log-service (property*)>
+ <!ATTLIST log-service classname CDATA #FIXED "org.apache.click.service.ConsoleLogService">
+
+ <!-- Template Service class. -->
+ <!ELEMENT template-service (property*)>
+ <!ATTLIST template-service classname CDATA #FIXED "org.apache.click.service.VelocityTemplateService">
Modified: click/trunk/click/framework/src/org/apache/click/service/ConfigService.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/service/ConfigService.java?rev=928134&r1=928133&r2=928134&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/service/ConfigService.java (original)
+++ click/trunk/click/framework/src/org/apache/click/service/ConfigService.java Sat Mar 27
03:47:18 2010
@@ -119,7 +119,7 @@ public interface ConfigService {
public static final String NOT_FOUND_PATH = "/click/not-found.htm";
/** The page auto binding mode. */
- public enum AutoBinding { PUBLIC, ANNOTATION, NONE };
+ public enum AutoBinding { DEFAULT, PUBLIC, ANNOTATION, NONE };
/**
* The servlet context attribute name. The ClickServlet stores the
Modified: click/trunk/click/framework/src/org/apache/click/service/XmlConfigService.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/service/XmlConfigService.java?rev=928134&r1=928133&r2=928134&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/service/XmlConfigService.java (original)
+++ click/trunk/click/framework/src/org/apache/click/service/XmlConfigService.java Sat Mar
27 03:47:18 2010
@@ -968,29 +968,31 @@ public class XmlConfigService implements
// Determine whether to use autobinding.
String autobindingStr = pagesElm.getAttribute("autobinding");
if (StringUtils.isBlank(autobindingStr)) {
- autobindingStr = "true";
- }
-
- if ("annotation".equalsIgnoreCase(autobindingStr)) {
- autobinding = AutoBinding.ANNOTATION;
-
- } else if ("public".equalsIgnoreCase(autobindingStr)) {
- autobinding = AutoBinding.PUBLIC;
+ autobinding = AutoBinding.DEFAULT;
+ } else {
- } else if ("none".equalsIgnoreCase(autobindingStr)) {
- autobinding = AutoBinding.NONE;
+ if ("annotation".equalsIgnoreCase(autobindingStr)) {
+ autobinding = AutoBinding.ANNOTATION;
- // Provided for backward compatibility
- } else if ("true".equalsIgnoreCase(autobindingStr)) {
- autobinding = AutoBinding.PUBLIC;
+ } else if ("public".equalsIgnoreCase(autobindingStr)) {
+ autobinding = AutoBinding.PUBLIC;
- // Provided for backward compatibility
- } else if ("false".equalsIgnoreCase(autobindingStr)) {
- autobinding = AutoBinding.NONE;
+ } else if ("none".equalsIgnoreCase(autobindingStr)) {
+ autobinding = AutoBinding.NONE;
- } else {
- String msg = "Invalid pages autobinding attribute: " + autobindingStr;
- throw new RuntimeException(msg);
+ // Provided for backward compatibility
+ } else if ("true".equalsIgnoreCase(autobindingStr)) {
+ autobinding = AutoBinding.DEFAULT;
+
+ // Provided for backward compatibility
+ } else if ("false".equalsIgnoreCase(autobindingStr)) {
+ autobinding = AutoBinding.NONE;
+
+ } else {
+ String msg = "Invalid pages autobinding attribute: "
+ + autobindingStr;
+ throw new RuntimeException(msg);
+ }
}
// TODO: if autobinding is set to false an there are multiple pages how should
this be handled
@@ -1750,46 +1752,42 @@ public class XmlConfigService implements
return null;
}
+ /**
+ * Return an array of bindable fields for the given page class based on
+ * the binding mode.
+ *
+ * @param pageClass the page class
+ * @param mode the binding mode
+ * @return the field array of bindable fields
+ */
private static Field[] getBindablePageFields(Class pageClass, AutoBinding mode) {
- if (mode == AutoBinding.PUBLIC) {
- return pageClass.getFields();
+ if (mode == AutoBinding.DEFAULT) {
- } else if (mode == AutoBinding.ANNOTATION) {
+ // Get @Bindable fields
+ Map<String, Field> fieldMap = getAnnotatedBindableFields(pageClass);
- List<Class> pageClassList = new ArrayList<Class>();
- pageClassList.add(pageClass);
-
- Class parentClass = pageClass.getSuperclass();
- while (parentClass != null) {
- // Include parent classes up to but excluding Page.class
- if (parentClass.isAssignableFrom(Page.class)) {
- break;
- }
- pageClassList.add(parentClass);
- parentClass = parentClass.getSuperclass();
+ // Add public fields
+ Field[] publicFields = pageClass.getFields();
+ for (Field field : publicFields) {
+ fieldMap.put(field.getName(), field);
}
- // Reverse class list so parents are processed first, with the
- // actual page class fields processed last. This will enable the
- // page classes fields to override parent class fields
- Collections.reverse(pageClassList);
+ // Copy the field map values into a field list
+ Field[] fieldArray = new Field[fieldMap.size()];
- Map<String, Field> fieldMap = new TreeMap<String, Field>();
+ int i = 0;
+ for (Field field : fieldMap.values()) {
+ fieldArray[i++] = field;
+ }
- for (Class aPageClass : pageClassList) {
+ return fieldArray;
- for (Field field : aPageClass.getDeclaredFields()) {
+ } else if (mode == AutoBinding.PUBLIC) {
+ return pageClass.getFields();
- if (field.getAnnotation(Bindable.class) != null) {
- fieldMap.put(field.getName(), field);
+ } else if (mode == AutoBinding.ANNOTATION) {
- // If field is not public set accessibility true
- if (!Modifier.isPublic(field.getModifiers())) {
- field.setAccessible(true);
- }
- }
- }
- }
+ Map<String, Field> fieldMap = getAnnotatedBindableFields(pageClass);
// Copy the field map values into a field list
Field[] fieldArray = new Field[fieldMap.size()];
@@ -1806,6 +1804,52 @@ public class XmlConfigService implements
}
}
+ /**
+ * Return the fields annotated with the Bindable annotation.
+ *
+ * @param pageClass the page class
+ * @return the map of bindable fields
+ */
+ private static Map getAnnotatedBindableFields(Class pageClass) {
+
+ List<Class> pageClassList = new ArrayList<Class>();
+ pageClassList.add(pageClass);
+
+ Class parentClass = pageClass.getSuperclass();
+ while (parentClass != null) {
+ // Include parent classes up to but excluding Page.class
+ if (parentClass.isAssignableFrom(Page.class)) {
+ break;
+ }
+ pageClassList.add(parentClass);
+ parentClass = parentClass.getSuperclass();
+ }
+
+ // Reverse class list so parents are processed first, with the
+ // actual page class fields processed last. This will enable the
+ // page classes fields to override parent class fields
+ Collections.reverse(pageClassList);
+
+ Map<String, Field> fieldMap = new TreeMap<String, Field>();
+
+ for (Class aPageClass : pageClassList) {
+
+ for (Field field : aPageClass.getDeclaredFields()) {
+
+ if (field.getAnnotation(Bindable.class) != null) {
+ fieldMap.put(field.getName(), field);
+
+ // If field is not public set accessibility true
+ if (!Modifier.isPublic(field.getModifiers())) {
+ field.setAccessible(true);
+ }
+ }
+ }
+ }
+
+ return fieldMap;
+ }
+
// ---------------------------------------------------------- Inner Classes
/**
@@ -1884,7 +1928,7 @@ public class XmlConfigService implements
}
- fieldArray = getBindablePageFields(pageClass, autobinding);
+ fieldArray = XmlConfigService.getBindablePageFields(pageClass, autobinding);
fields = new HashMap();
for (int i = 0; i < fieldArray.length; i++) {
|