Author: kylem
Date: Wed Feb 23 11:25:04 2005
New Revision: 155053
URL: http://svn.apache.org/viewcvs?view=rev&rev=155053
Log:
Added support for localization of strings specified via BeanInfo
(org.apache.beehive.controls.api.packaging.*) annotations. A string annotation
value can have the form "%<resource-specifier>%" and the value will be pulled
from a resource bundle. The <resource-specifier> string is a base resource
bundle name (which will be customized based upon the default locale)
concatenated with a resource name inside the bundle, seperated by '.'.
Generated BeanInfo classes will dynamically pull the string value from the
resource bundle, enabling BeanInfo attributes (name, displayName,
shortDescription, etc) to be customized for different locales. The beaninfo
test in the Controls checkin test set includes a sample usage.
Added:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanInfo.java
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/beaninfo/InfoTestBundle.java
Modified:
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/ControlBean.java
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlBeanContext.java
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBeanInfo.vm
incubator/beehive/trunk/controls/test/build.xml
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/beaninfo/InfoTest.java
Modified:
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/ControlBean.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/ControlBean.java?view=diff&r1=155052&r2=155053
==============================================================================
---
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/ControlBean.java
(original)
+++
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/ControlBean.java
Wed Feb 23 11:25:04 2005
@@ -35,6 +35,13 @@
public interface ControlBean extends BeanContextProxy, java.io.Serializable
{
/**
+ * The IDSeparator character is used to separated individual control IDs
in nesting
+ * scenarios whether the identifier is actually a composite path that
represents
+ * a nesting relationship.
+ */
+ public static final char IDSeparator = '/';
+
+ /**
* Returns the <code>java.beans.beancontext.BeanContext</code> that
provides the parent
* context for the Java Control.
* @return the containing <code>BeanContext</code> for the Java
ControlBean.
Modified:
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlBeanContext.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlBeanContext.java?view=diff&r1=155052&r2=155053
==============================================================================
---
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlBeanContext.java
(original)
+++
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlBeanContext.java
Wed Feb 23 11:25:04 2005
@@ -176,6 +176,13 @@
public boolean isSingleThreadedContainer();
/**
+ * Returns the peer ControlBean associated with this ControlBeanContext.
If the context
+ * represents a top-level container (i.e. not a Control containing other
controls), null
+ * will be returned.
+ */
+ public ControlBean getControlBean();
+
+ /**
* Returns any child ControlBean that is nested in the ControlBeanContext,
or null
* if no matching child is found. The <code>id</code> parameter is
relative to
* the current nesting context, not an absolute control id.
Modified:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java?view=diff&r1=155052&r2=155053
==============================================================================
---
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java
(original)
+++
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java
Wed Feb 23 11:25:04 2005
@@ -58,9 +58,6 @@
abstract public class ControlBean
implements
org.apache.beehive.controls.api.bean.ControlBean
{
- public static final char IDSeparator = '/';
- public static final char FactorySeparator = ':';
-
/**
*
* @param context the containing ControlBeanContext. May be null,
in which case the bean will attempt to
Modified:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java?view=diff&r1=155052&r2=155053
==============================================================================
---
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
(original)
+++
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
Wed Feb 23 11:25:04 2005
@@ -196,7 +196,7 @@
{
ControlBean parentBean = cbcs.getControlBean();
if (parentBean != null)
- id = parentBean.getControlID() + ControlBean.IDSeparator +
id;
+ id = parentBean.getControlID() +
org.apache.beehive.controls.api.bean.ControlBean.IDSeparator + id;
}
_bean.setControlID(id);
@@ -330,7 +330,7 @@
public ControlBean getBean(String id)
{
// If no control id separator found, the bean is a direct child of
this context
- int delim = id.indexOf(ControlBean.IDSeparator);
+ int delim =
id.indexOf(org.apache.beehive.controls.api.bean.ControlBean.IDSeparator);
if (delim < 0) // child is a direct descendent
return (ControlBean)_childMap.get(id);
@@ -344,7 +344,11 @@
return
((ControlBeanContext)bean.getBeanContextProxy()).getBean(id.substring(delim+1));
}
- /* package */ ControlBean getControlBean()
+ /**
+ * Returns the ControlBean associated directly with the
ControlBeanContext. If the
+ * context represents a top-level container, will return null.
+ */
+ public ControlBean getControlBean()
{
return _bean;
}
Added:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanInfo.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanInfo.java?view=auto&rev=155053
==============================================================================
---
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanInfo.java
(added)
+++
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanInfo.java
Wed Feb 23 11:25:04 2005
@@ -0,0 +1,90 @@
+package org.apache.beehive.controls.runtime.bean;
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * The ControlBeanInfo class is an abstract base class for the JavaBean
BeanInfo classes generated
+ * to support Beehive controls. It is used to bundle helper code common
across all generated
+ * BeanInfo classes.
+ */
+abstract public class ControlBeanInfo extends java.beans.SimpleBeanInfo
+{
+ /**
+ * Protected constructor that is called from generated BeanInfo subclasses.
+ * @param beanClass the JavaBean class for which BeanInfo is being
provided.
+ */
+ protected ControlBeanInfo(Class beanClass)
+ {
+ super();
+ _beanClass = beanClass;
+ }
+
+ /*
+ * Gets a possibly-localized string for the given input string.
+ * @param input This the the string that may be localizable. If it is of
the form
+ * "%foo.bar.Baz%", then the resource Baz will be looked up in the foo.bar
bundle using
+ * standard ResourceBundle rules for the default Locale using the
control's classloader.
+ * If the input does not start and end with '%', or if the bundle is not
located, the string
+ * will be returned verbatim.
+ * @return the string to be displayed, or the input string if no resource
is found.
+ */
+ final protected String localizeString(String input)
+ {
+ if (input == null || !input.startsWith("%") || !input.endsWith("%"))
+ return input;
+ String bundleName = input.substring(1, input.length()-1);
+ String resourceName = null;
+ String output = input;
+ int lastDot = bundleName.lastIndexOf('.');
+ while (lastDot != -1 && lastDot != 0 && (lastDot+1 <
bundleName.length()))
+ {
+ // move last element from bundle to resource. foo.bar.Baz could
be the
+ // Baz property in foo.bar, or the bar.Baz property in foo.
+ if (resourceName == null)
+ resourceName = bundleName.substring(lastDot+1);
+ else
+ resourceName = bundleName.substring(lastDot+1) + '.' +
resourceName;
+ bundleName = bundleName.substring(0, lastDot);
+
+ try
+ {
+ ResourceBundle bundle = ResourceBundle.getBundle(bundleName,
Locale.getDefault(),
+
_beanClass.getClassLoader());
+ if (bundle != null)
+ {
+ String lookup = bundle.getString(resourceName);
+ if (lookup != null)
+ return lookup;
+ }
+ }
+ catch (MissingResourceException mre)
+ { }
+
+ lastDot = bundleName.lastIndexOf('.');
+
+ }
+
+ return input;
+ }
+
+ Class _beanClass;
+}
Modified:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBeanInfo.vm
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBeanInfo.vm?view=diff&r1=155052&r2=155053
==============================================================================
---
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBeanInfo.vm
(original)
+++
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBeanInfo.vm
Wed Feb 23 11:25:04 2005
@@ -25,18 +25,25 @@
## The initFeatureDescriptor macro will initialize the contents of a
FeatureDescriptor using
## a FeatureInfo annotation instance.
##
+## The localizeString is used to inject code to do resource bundle lookup on
string values that
+## begin/end with '%'. See
org.apache.beehive.controls.runtime.ControlBeanInfo.localizeString()
+## for details
+##
+#macro (localizeString $string)
+#if ($string.startsWith('%') && $string.endsWith('%'))
localizeString("$string") #else "$string" #end
+#end
#macro (initFeatureDescriptor $featureDesc $featureInfo $defaultName)
#if (! $featureInfo.name().equals(""))
-${featureDesc}.setName("$featureInfo.name()");
+${featureDesc}.setName(#localizeString("$featureInfo.name()"));
#else
${featureDesc}.setName("$defaultName");
#end
#if (! $featureInfo.displayName().equals(""))
-${featureDesc}.setDisplayName("$featureInfo.displayName()");
+${featureDesc}.setDisplayName(#localizeString("$featureInfo.displayName()"));
#else
${featureDesc}.setDisplayName("$defaultName");
#end
-${featureDesc}.setShortDescription("$featureInfo.shortDescription()");
+${featureDesc}.setShortDescription(#localizeString("$featureInfo.shortDescription()"));
${featureDesc}.setExpert($featureInfo.isExpert());
${featureDesc}.setHidden($featureInfo.isHidden());
${featureDesc}.setPreferred($featureInfo.isPreferred());
@@ -70,7 +77,7 @@
#if ($intf.superClass)
extends ${bean.superClass.className}BeanInfo
#else
- extends java.beans.SimpleBeanInfo
+ extends org.apache.beehive.controls.runtime.bean.ControlBeanInfo
#end
{
#if ($intf.operations.size() != 0 || $intf.eventSets.size() != 0)
@@ -82,6 +89,23 @@
}
#end
+ /**
+ * Default null-arg constructor used to create a new BeanInfo instance
+ */
+ public ${bean.shortName}BeanInfo()
+ {
+ super(${bean.className}.class);
+ }
+
+ /**
+ * Protected constructor used if this BeanInfo class is extended.
+ */
+ protected ${bean.shortName}BeanInfo(Class beanClass)
+ {
+ super(beanClass);
+ }
+
+ // java.beans.BeanInfo.getBeanDescriptor
public BeanDescriptor getBeanDescriptor()
{
BeanDescriptor bd = new BeanDescriptor(${bean.className}.class);
@@ -89,8 +113,8 @@
#if ($featureInfo)
#initFeatureDescriptor("bd" $featureInfo $bean.shortName)
#else
- bd.setName("$bean.shortName");
- bd.setDisplayName("$bean.shortName");
+ bd.setName(#localizeString("$bean.shortName"));
+ bd.setDisplayName(#localizeString("$bean.shortName"));
#end
//
@@ -170,7 +194,7 @@
#foreach ($propertySet in $intf.propertySets)
#foreach ($property in $propertySet.properties)
#if ($propertySet.hasSetters())
- pd = new PropertyDescriptor("$property.name",
${bean.className}.class);
+ pd = new PropertyDescriptor(#localizeString("$property.name"),
${bean.className}.class);
#else
#if ($property.getType().equals("boolean"))
#set ( $getterName = "is${property.accessorName}" )
@@ -201,6 +225,7 @@
#end
}
+ // java.beans.BeanInfo.getPropertyDescriptors
public PropertyDescriptor [] getPropertyDescriptors()
{
PropertyDescriptor [] propDescriptors = new
PropertyDescriptor[$intf.propertyCount];
@@ -302,8 +327,8 @@
try
{
- esd = new
ControlEventSetDescriptor("$eventSet.descriptorName", eventIntf,
- eventDescriptors, addListener, removeListener,
getListeners);
+ esd = new
ControlEventSetDescriptor(localizeString("$eventSet.descriptorName"),
+ eventIntf, eventDescriptors, addListener,
removeListener, getListeners);
#if ($eventSet.featureInfo)
#initFeatureDescriptor("esd" $eventSet.featureInfo
$eventSet.descriptorName)
#end
@@ -325,6 +350,7 @@
#end
}
+ // java.beans.BeanInfo.getEventSetDescriptors
public EventSetDescriptor [] getEventSetDescriptors()
{
EventSetDescriptor [] eventSetDescriptors = new
EventSetDescriptor[$intf.eventSetCount];
Modified: incubator/beehive/trunk/controls/test/build.xml
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/build.xml?view=diff&r1=155052&r2=155053
==============================================================================
--- incubator/beehive/trunk/controls/test/build.xml (original)
+++ incubator/beehive/trunk/controls/test/build.xml Wed Feb 23 11:25:04 2005
@@ -462,7 +462,10 @@
<property name="gtlf.file"
value="${controls.test.root}/${tch.base-logfile-name}.xml"/>
<property name="output.file"
value="${controls.test.root}/${tch.base-logfile-name}.html"/>
</ant>
- </target>
+
+ <fail if="run.failed">Controls Test failed. See tch.* for
details</fail>
+
+ </target>
<!-- =============================================== -->
<!-- TCH and Mantis targets for running tests -->
Modified:
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/beaninfo/InfoTest.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/beaninfo/InfoTest.java?view=diff&r1=155052&r2=155053
==============================================================================
---
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/beaninfo/InfoTest.java
(original)
+++
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/beaninfo/InfoTest.java
Wed Feb 23 11:25:04 2005
@@ -27,8 +27,8 @@
}) */
@ManifestAttribute(name="Attribute1", value="Value1")
@FeatureInfo(
- name="InfoTest name",
- displayName="InfoTest display name",
+
name="%org.apache.beehive.controls.test.controls.beaninfo.InfoTestBundle.name%",
+
displayName="%org.apache.beehive.controls.test.controls.beaninfo.InfoTestBundle.displayName%",
attributes=
{
@FeatureAttribute(name="fa1", value="fv1"),
@@ -42,7 +42,9 @@
public @interface TestProps
{
@PropertyInfo(bound=true, constrained=false)
- @FeatureInfo(name="InfoTest prop1", displayName="InfoTest prop1")
+ @FeatureInfo(
+
name="%org.apache.beehive.controls.test.controls.beaninfo.InfoTestBundle.prop1.name%",
+ displayName="InfoTest prop1")
public int prop1() default 0;
public boolean prop2() default false;
}
@@ -58,7 +60,7 @@
@FeatureInfo(
name="infoTestMethod name",
- displayName="infoTestMethod display name",
+
displayName="%org.apache.beehive.controls.test.controls.beaninfo.InfoTestBundle.infoTestMethod.displayName%",
isHidden=true,
isExpert=true,
attributes=
Added:
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/beaninfo/InfoTestBundle.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/beaninfo/InfoTestBundle.java?view=auto&rev=155053
==============================================================================
---
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/beaninfo/InfoTestBundle.java
(added)
+++
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/beaninfo/InfoTestBundle.java
Wed Feb 23 11:25:04 2005
@@ -0,0 +1,25 @@
+package org.apache.beehive.controls.test.controls.beaninfo;
+
+import java.util.ListResourceBundle;
+
+/**
+ * A resource bundle containing feature info strings. This is used to test
the '%<key>%'
+ * substitution syntax for bean info annotations.
+ */
+
+public class InfoTestBundle extends ListResourceBundle
+{
+ static final Object[][] contents =
+ {
+ {"name", "InfoTest name"},
+ {"displayName", "InfoTest display name"},
+ {"prop1.name", "InfoTest prop1"},
+ {"infoTestMethod.displayName", "infoTestMethod display name"}
+ };
+
+ public Object[][] getContents()
+ {
+ return contents;
+ }
+
+}