http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3d4de7e1/commons/src/main/java/org/apache/tapestry5/services/InvalidationListener.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/tapestry5/services/InvalidationListener.java b/commons/src/main/java/org/apache/tapestry5/services/InvalidationListener.java new file mode 100644 index 0000000..b9b4aa3 --- /dev/null +++ b/commons/src/main/java/org/apache/tapestry5/services/InvalidationListener.java @@ -0,0 +1,33 @@ +// Copyright 2006, 2007, 2012 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. + +package org.apache.tapestry5.services; + +/** + * Interface for objects that may cache information that can be invalidated. Invalidation occurs when external files, + * from which in-memory data is cached, is determined to have changed. Granularity is very limited; when any external + * file is found to have changed, the event is fired (with the expectation that the cleared cache will be repopulated as + * necessary). + * + * @see org.apache.tapestry5.services.InvalidationEventHub + * @since 5.1.0.0 + * @deprecated In 5.4; use {@link InvalidationEventHub#addInvalidationCallback(Runnable)} instead + */ +public interface InvalidationListener +{ + /** + * Invoked to indicate that some object is invalid. The receiver should clear its cache. + */ + void objectWasInvalidated(); +}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3d4de7e1/settings.gradle ---------------------------------------------------------------------- diff --git a/settings.gradle b/settings.gradle index 6397777..593c3a4 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,5 +4,5 @@ include "tapestry-beanvalidator", "tapestry-jpa", "tapestry-kaptcha" include "tapestry-javadoc", "quickstart", "tapestry-clojure", "tapestry-mongodb" include "tapestry-test-data", 'tapestry-internal-test', "tapestry-ioc-junit" include "tapestry-webresources", "tapestry-runner", "tapestry-test-constants" -include "tapestry-ioc-jcache" +include "tapestry-ioc-jcache", "beanmodel", "commons" // include "tapestry-cdi" http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3d4de7e1/tapestry-core/build.gradle ---------------------------------------------------------------------- diff --git a/tapestry-core/build.gradle b/tapestry-core/build.gradle index c16cd48..584200a 100644 --- a/tapestry-core/build.gradle +++ b/tapestry-core/build.gradle @@ -18,6 +18,7 @@ configurations { dependencies { compile project(':tapestry-ioc') compile project(':tapestry-json') + compile project(':beanmodel') provided project(":tapestry-test") provided project(":tapestry-test-constants") @@ -26,11 +27,6 @@ dependencies { compile "commons-codec:commons-codec:1.5" - // Transitive will bring in the unwanted string template library as well - compile "org.antlr:antlr-runtime:3.5.2", { - exclude group: "org.antlr", module: "stringtemplate" - } - // Antlr3 tool path used with the antlr3 task antlr3 "org.antlr:antlr:3.5.2" http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3d4de7e1/tapestry-core/src/main/java/org/apache/tapestry5/PropertyConduit.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/PropertyConduit.java b/tapestry-core/src/main/java/org/apache/tapestry5/PropertyConduit.java deleted file mode 100644 index 3dbb0c0..0000000 --- a/tapestry-core/src/main/java/org/apache/tapestry5/PropertyConduit.java +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2007 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. - -package org.apache.tapestry5; - -import org.apache.tapestry5.ioc.AnnotationProvider; - -/** - * Used to read or update the value associated with a property. A PropertyConduit provides access to the annotations on - * the underlying getter and/or setter methods. - */ -public interface PropertyConduit extends AnnotationProvider -{ - /** - * Reads the property from the instance. - * - * @param instance object containing the property - * @return the current value of the property - */ - Object get(Object instance); - - /** - * Changes the current value of the property. - * - * @param instance object containing the property - * @param value to change the property to - */ - void set(Object instance, Object value); - - /** - * Returns the type of the property read or updated by the conduit. - */ - Class getPropertyType(); -} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3d4de7e1/tapestry-core/src/main/java/org/apache/tapestry5/PropertyConduit2.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/PropertyConduit2.java b/tapestry-core/src/main/java/org/apache/tapestry5/PropertyConduit2.java deleted file mode 100644 index 839d70f..0000000 --- a/tapestry-core/src/main/java/org/apache/tapestry5/PropertyConduit2.java +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2007 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. - -package org.apache.tapestry5; - -import java.lang.reflect.Method; -import java.lang.reflect.Type; - -import org.apache.tapestry5.services.PropertyConduitSource; - - -/** - * Extension to {@link PropertyConduit} that adds a method to access the generic property type. - * {@link PropertyConduitSource} instances should ideally return PropertyConduit2 objects, not PropertyConduit. - * This is only primarily of interest to {@link Binding2}. - * - * @since 5.4 - */ -public interface PropertyConduit2 extends PropertyConduit -{ - /** - * Returns the generic type of the property - * - * @see Method#getGenericReturnType() - * @see java.lang.reflect.Field#getGenericType() - * - */ - Type getPropertyGenericType(); -} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3d4de7e1/tapestry-core/src/main/java/org/apache/tapestry5/beaneditor/BeanModel.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/beaneditor/BeanModel.java b/tapestry-core/src/main/java/org/apache/tapestry5/beaneditor/BeanModel.java deleted file mode 100644 index 0a60fd7..0000000 --- a/tapestry-core/src/main/java/org/apache/tapestry5/beaneditor/BeanModel.java +++ /dev/null @@ -1,169 +0,0 @@ -// Copyright 2007, 2008, 2009, 2010, 2011 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. - -package org.apache.tapestry5.beaneditor; - -import org.apache.tapestry5.PropertyConduit; - -import java.util.List; - -/** - * Provides the information necessary to build a user interface to view, create or edit an instance of a particular - * type. - * <p/> - * BeanModels are not thread-safe, they are also not serializable. - * <p/> - * Here, and in {@link org.apache.tapestry5.beaneditor.PropertyModel}, the term "propertyName" is used for simplicitly. - * However, a full {@linkplain org.apache.tapestry5.services.PropertyConduitSource#create(Class, String) property - * expression} may be utilized when {@linkplain #add(String) adding new properties to an existing BeanModel}. - * - * @see org.apache.tapestry5.services.BeanModelSource - */ -public interface BeanModel<T> -{ - /** - * Returns the type of bean for which this model was initially created. - */ - Class<T> getBeanType(); - - - /** - * Creates a new bean instance. This is based on {@link org.apache.tapestry5.ioc.ObjectLocator#autobuild(Class)}, - * so a public constructor will be used, and dependencies injected. - * - * @return new instance of the bean - */ - T newInstance(); - - /** - * Returns a list of the editable properties of the bean, in <em>presentation</em> order. - */ - List<String> getPropertyNames(); - - /** - * Returns the named model. - * - * @param propertyName name of property to retrieve model for (case is ignored) - * @return the model for the property - * @throws RuntimeException if the bean editor model does not have a property model for the provided name - */ - PropertyModel get(String propertyName); - - /** - * Returns the identified model. Property ids are a stripped version of the property name. Case is ignored. - * - * @param propertyId matched caselessly against {@link org.apache.tapestry5.beaneditor.PropertyModel#getId()} - * @throws RuntimeException if the bean editor model does not have a property model with the indicated id - */ - PropertyModel getById(String propertyId); - - /** - * Adds a new property to the model, returning its mutable model for further refinement. The property is added to - * the <em>end</em> of the list of properties. The property must be real (but may have been excluded if there was no - * {@linkplain org.apache.tapestry5.beaneditor.DataType datatype} associated with the property). To add a synthetic - * property, use {@link #add(String, org.apache.tapestry5.PropertyConduit)} - * - * @param propertyName name of property to add - * @return the new property model (for further configuration) - * @throws RuntimeException if the property already exists - */ - PropertyModel add(String propertyName); - - - /** - * Adds a new synthetic property to the model, returning its mutable model for further refinement. The property is added to - * the <em>end</em> of the list of properties. - * - * @param propertyName name of property to add - * @param expression expression for the property - * @return the new property model (for further configuration) - * @throws RuntimeException if the property already exists - * @since 5.3 - */ - PropertyModel addExpression(String propertyName, String expression); - - /** - * Adds an empty property (one with no property conduit). - * - * @param propertyName name of property to add - * @return the new property model (for further configuration) - * @throws RuntimeException if the property already exists - * @since 5.3 - */ - PropertyModel addEmpty(String propertyName); - - /** - * Adds a new property to the model (as with {@link #add(String)}), ordered before or after an existing property. - * - * @param position controls whether the new property is ordered before or after the existing property - * @param existingPropertyName the name of an existing property (this must exist) - * @param propertyName the new property to add - * @return the new property model (for further configuration) - * @throws RuntimeException if the existing property does not exist, or if the new property already does exist - */ - PropertyModel add(RelativePosition position, String existingPropertyName, String propertyName); - - /** - * Adds a new property to the model, ordered before or after an existing property. - * - * @param position controls whether the new property is ordered before or after the existing property - * @param existingPropertyName the name of an existing property (this must exist) - * @param propertyName the new property to add - * @param conduit conduit used to read or update the property; this may be null for a synthetic or - * placeholder property - * @return the new property model (for further configuration) - * @throws RuntimeException if the existing property does not exist, or if the new property already does exist - */ - PropertyModel add(RelativePosition position, String existingPropertyName, String propertyName, - PropertyConduit conduit); - - /** - * Adds a new, synthetic property to the model, returning its mutable model for further refinement. - * - * @param propertyName name of property to add - * @param conduit the conduit used to read or update the property; this may be null for a synthetic or - * placeholder property. Instead of passing null, please invoke {@link #addEmpty(String)}. - * @return the model for the property - * @throws RuntimeException if the property already exists - * @see #addExpression(String, String) - */ - PropertyModel add(String propertyName, PropertyConduit conduit); - - /** - * Removes the named properties from the model, if present. It is not considered an error to remove a property that - * does not exist. - * - * @param propertyNames the names of properties to be removed (case insensitive) - * @return the model for further modifications - */ - BeanModel<T> exclude(String... propertyNames); - - /** - * Re-orders the properties of the model into the specified order. Existing properties that are not indicated are - * retained, but ordered to the end of the list. - * - * @param propertyNames property names in order they should be displayed (case insensitive) - * @return the model for further modifications - */ - BeanModel<T> reorder(String... propertyNames); - - /** - * Re-orders the properties of the model into the specified order. Existing properties that are not indicated are - * <<removed>>. - * - * @param propertyNames the names of properties to be retained - * @return the model for further modifications - */ - BeanModel<T> include(String... propertyNames); -} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3d4de7e1/tapestry-core/src/main/java/org/apache/tapestry5/beaneditor/PropertyModel.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/beaneditor/PropertyModel.java b/tapestry-core/src/main/java/org/apache/tapestry5/beaneditor/PropertyModel.java deleted file mode 100644 index 6095fb9..0000000 --- a/tapestry-core/src/main/java/org/apache/tapestry5/beaneditor/PropertyModel.java +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2007, 2008 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. - -package org.apache.tapestry5.beaneditor; - -import org.apache.tapestry5.PropertyConduit; -import org.apache.tapestry5.ioc.AnnotationProvider; - -/** - * Part of a {@link org.apache.tapestry5.beaneditor.BeanModel} that defines the attributes of a single property of a - * bean. - * <p/> - * <p/> - * A PropertyModel is also an {@link AnnotationProvider}, as long as the {@link org.apache.tapestry5.PropertyConduit} is - * non-null. When there is no property conduit, then {@link org.apache.tapestry5.ioc.AnnotationProvider#getAnnotation(Class)} - * will return null. - */ -public interface PropertyModel extends AnnotationProvider -{ - /** - * Returns the name of the property (which may, in fact, be a property expression). - */ - String getPropertyName(); - - /** - * Returns the id used to access other resources (this is based on the property name, but with any excess - * punctuation stripped out). - */ - String getId(); - - /** - * Returns a user-presentable label for the property. - */ - String getLabel(); - - /** - * Returns the type of the property. - */ - Class getPropertyType(); - - /** - * Returns a logical name for the type of UI needed to view or edit the property. This is initially determined from - * the property type. - */ - String getDataType(); - - /** - * Changes the data type for the property. - * - * @param dataType - * @return the property model, for further changes - */ - PropertyModel dataType(String dataType); - - /** - * Returns an object used to read or update the property. For virtual properties (properties that do not actually - * exist on the bean), the conduit may be null. - */ - PropertyConduit getConduit(); - - /** - * Changes the label for the property to the provided value. - * - * @param label new label for property - * @return the property model, for further changes - */ - PropertyModel label(String label); - - /** - * Returns the containing model, often used for "fluent" construction of the model. - */ - BeanModel model(); - - /** - * Returns true if the property can be used for sorting. By default, this is true only if the property type - * implements Comparable. - */ - boolean isSortable(); - - /** - * Updates sortable and returns the model for further changes. - * - * @return the property model, for further changes - */ - PropertyModel sortable(boolean sortable); -} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3d4de7e1/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalPropertyConduit.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalPropertyConduit.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalPropertyConduit.java deleted file mode 100644 index 315b372..0000000 --- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalPropertyConduit.java +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2010 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. - -package org.apache.tapestry5.internal; - -import org.apache.tapestry5.PropertyConduit2; - - -/** - * Extension to {@link org.apache.tapestry5.PropertyConduit2} that adds a method to determine the name of the property. - * - * @since 5.2.0 - * - */ -public interface InternalPropertyConduit extends PropertyConduit2 -{ - /** - * Returns the name of the property read or updated by the conduit or null. - * If the expression points to a property on a bean (e.g. user.name) this method returns the last property in the chain. - * Otherwise this method returns {@code null}. - * - * @return property name or {@code null} - * - */ - String getPropertyName(); -} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3d4de7e1/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/BeanModelImpl.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/BeanModelImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/BeanModelImpl.java deleted file mode 100644 index 26eb309..0000000 --- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/BeanModelImpl.java +++ /dev/null @@ -1,289 +0,0 @@ -// Copyright 2007, 2008, 2010, 2011 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. - -package org.apache.tapestry5.internal.beaneditor; - -import org.apache.tapestry5.PropertyConduit; -import org.apache.tapestry5.beaneditor.BeanModel; -import org.apache.tapestry5.beaneditor.PropertyModel; -import org.apache.tapestry5.beaneditor.RelativePosition; -import org.apache.tapestry5.internal.services.CoercingPropertyConduitWrapper; -import org.apache.tapestry5.ioc.Messages; -import org.apache.tapestry5.ioc.ObjectLocator; -import org.apache.tapestry5.ioc.internal.util.CollectionFactory; -import org.apache.tapestry5.ioc.internal.util.InternalUtils; -import org.apache.tapestry5.ioc.services.TypeCoercer; -import org.apache.tapestry5.ioc.util.AvailableValues; -import org.apache.tapestry5.ioc.util.UnknownValueException; -import org.apache.tapestry5.plastic.PlasticUtils; -import org.apache.tapestry5.services.PropertyConduitSource; - -import java.util.List; -import java.util.Map; - -public class BeanModelImpl<T> implements BeanModel<T> -{ - private final Class<T> beanType; - - private final PropertyConduitSource propertyConduitSource; - - private final TypeCoercer typeCoercer; - - private final Messages messages; - - private final ObjectLocator locator; - - private final Map<String, PropertyModel> properties = CollectionFactory.newCaseInsensitiveMap(); - - // The list of property names, in desired order (generally not alphabetical order). - - private final List<String> propertyNames = CollectionFactory.newList(); - - private static PropertyConduit NULL_PROPERTY_CONDUIT = null; - - public BeanModelImpl(Class<T> beanType, PropertyConduitSource propertyConduitSource, TypeCoercer typeCoercer, - Messages messages, ObjectLocator locator) - - { - this.beanType = beanType; - this.propertyConduitSource = propertyConduitSource; - this.typeCoercer = typeCoercer; - this.messages = messages; - this.locator = locator; - } - - public Class<T> getBeanType() - { - return beanType; - } - - public T newInstance() - { - return locator.autobuild("Instantiating new instance of " + beanType.getName(), beanType); - } - - public PropertyModel add(String propertyName) - { - return addExpression(propertyName, propertyName); - } - - public PropertyModel addEmpty(String propertyName) - { - return add(propertyName, NULL_PROPERTY_CONDUIT); - } - - public PropertyModel addExpression(String propertyName, String expression) - { - PropertyConduit conduit = createConduit(expression); - - return add(propertyName, conduit); - - } - - private void validateNewPropertyName(String propertyName) - { - assert InternalUtils.isNonBlank(propertyName); - if (properties.containsKey(propertyName)) - throw new RuntimeException(String.format( - "Bean editor model for %s already contains a property model for property '%s'.", - beanType.getName(), propertyName)); - } - - public PropertyModel add(RelativePosition position, String existingPropertyName, String propertyName, - PropertyConduit conduit) - { - assert position != null; - validateNewPropertyName(propertyName); - - // Locate the existing one. - - PropertyModel existing = get(existingPropertyName); - - // Use the case normalized property name. - - int pos = propertyNames.indexOf(existing.getPropertyName()); - - PropertyModel newModel = new PropertyModelImpl(this, propertyName, conduit, messages); - - properties.put(propertyName, newModel); - - int offset = position == RelativePosition.AFTER ? 1 : 0; - - propertyNames.add(pos + offset, propertyName); - - return newModel; - } - - public PropertyModel add(RelativePosition position, String existingPropertyName, String propertyName) - { - PropertyConduit conduit = createConduit(propertyName); - - return add(position, existingPropertyName, propertyName, conduit); - } - - public PropertyModel add(String propertyName, PropertyConduit conduit) - { - validateNewPropertyName(propertyName); - - PropertyModel propertyModel = new PropertyModelImpl(this, propertyName, conduit, messages); - - properties.put(propertyName, propertyModel); - - // Remember the order in which the properties were added. - - propertyNames.add(propertyName); - - return propertyModel; - } - - private CoercingPropertyConduitWrapper createConduit(String propertyName) - { - return new CoercingPropertyConduitWrapper(propertyConduitSource.create(beanType, propertyName), typeCoercer); - } - - public PropertyModel get(String propertyName) - { - PropertyModel propertyModel = properties.get(propertyName); - - if (propertyModel == null) - throw new UnknownValueException(String.format( - "Bean editor model for %s does not contain a property named '%s'.", beanType.getName(), - propertyName), new AvailableValues("Defined properties", propertyNames)); - - return propertyModel; - } - - public PropertyModel getById(String propertyId) - { - for (PropertyModel model : properties.values()) - { - if (model.getId().equalsIgnoreCase(propertyId)) - return model; - } - - // Not found, so we throw an exception. A bit of work to set - // up the exception however. - - List<String> ids = CollectionFactory.newList(); - - for (PropertyModel model : properties.values()) - { - ids.add(model.getId()); - } - - throw new UnknownValueException(String.format( - "Bean editor model for %s does not contain a property with id '%s'.", beanType.getName(), propertyId), - new AvailableValues("Defined property ids", ids)); - } - - public List<String> getPropertyNames() - { - return CollectionFactory.newList(propertyNames); - } - - public BeanModel<T> exclude(String... propertyNames) - { - for (String propertyName : propertyNames) - { - PropertyModel model = properties.get(propertyName); - - if (model == null) - continue; - - // De-referencing from the model is needed because the name provided may not be a - // case-exact match, so we get the normalized or canonical name from the model because - // that's the one in propertyNames. - - this.propertyNames.remove(model.getPropertyName()); - - properties.remove(propertyName); - } - - return this; - } - - public BeanModel<T> reorder(String... propertyNames) - { - List<String> remainingPropertyNames = CollectionFactory.newList(this.propertyNames); - List<String> reorderedPropertyNames = CollectionFactory.newList(); - - for (String name : propertyNames) - { - PropertyModel model = get(name); - - // Get the canonical form (which may differ from name in terms of case) - String canonical = model.getPropertyName(); - - reorderedPropertyNames.add(canonical); - - remainingPropertyNames.remove(canonical); - } - - this.propertyNames.clear(); - this.propertyNames.addAll(reorderedPropertyNames); - - // Any unspecified names are ordered to the end. Don't want them? Remove them instead. - this.propertyNames.addAll(remainingPropertyNames); - - return this; - } - - public BeanModel<T> include(String... propertyNames) - { - List<String> reorderedPropertyNames = CollectionFactory.newList(); - Map<String, PropertyModel> reduced = CollectionFactory.newCaseInsensitiveMap(); - - for (String name : propertyNames) - { - - PropertyModel model = get(name); - - String canonical = model.getPropertyName(); - - reorderedPropertyNames.add(canonical); - reduced.put(canonical, model); - - } - - this.propertyNames.clear(); - this.propertyNames.addAll(reorderedPropertyNames); - - properties.clear(); - properties.putAll(reduced); - - return this; - } - - @Override - public String toString() - { - StringBuilder builder = new StringBuilder("BeanModel["); - builder.append(PlasticUtils.toTypeName(beanType)); - - builder.append(" properties:"); - String sep = ""; - - for (String name : propertyNames) - { - builder.append(sep); - builder.append(name); - - sep = ", "; - } - - builder.append("]"); - - return builder.toString(); - } -} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3d4de7e1/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/PropertyModelImpl.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/PropertyModelImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/PropertyModelImpl.java deleted file mode 100644 index 703ce44..0000000 --- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/PropertyModelImpl.java +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright 2007, 2008, 2010, 2011, 2014 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. - -package org.apache.tapestry5.internal.beaneditor; - -import org.apache.tapestry5.PropertyConduit; -import org.apache.tapestry5.beaneditor.BeanModel; -import org.apache.tapestry5.beaneditor.PropertyModel; -import org.apache.tapestry5.beaneditor.Sortable; -import org.apache.tapestry5.internal.TapestryInternalUtils; -import org.apache.tapestry5.ioc.Messages; -import org.apache.tapestry5.ioc.internal.util.InternalUtils; -import org.apache.tapestry5.plastic.PlasticUtils; - -import java.lang.annotation.Annotation; - -@SuppressWarnings("all") -public class PropertyModelImpl implements PropertyModel -{ - private final BeanModel model; - - private final String name; - - private final PropertyConduit conduit; - - private final String id; - - private String label; - - private String dataType; - - private boolean sortable; - - public PropertyModelImpl(BeanModel model, String name, PropertyConduit conduit, Messages messages) - { - this.model = model; - this.name = name; - this.conduit = conduit; - - id = TapestryInternalUtils.extractIdFromPropertyExpression(name); - - label = TapestryInternalUtils.defaultLabel(id, messages, name); - - // TAP5-2305 - if (conduit != null) - { - Sortable sortableAnnotation = conduit.getAnnotation(Sortable.class); - if (sortableAnnotation != null) - { - sortable = sortableAnnotation.value(); - } - else - { - // Primitive types need to be converted to wrapper types before checking to see - // if they are sortable. - Class wrapperType = PlasticUtils.toWrapperType(getPropertyType()); - sortable = Comparable.class.isAssignableFrom(wrapperType); - } - } - } - - public String getId() - { - return id; - } - - public Class getPropertyType() - { - return conduit == null ? Object.class : conduit.getPropertyType(); - } - - public PropertyConduit getConduit() - { - return conduit; - } - - public PropertyModel label(String label) - { - assert InternalUtils.isNonBlank(label); - this.label = label; - - return this; - } - - public String getLabel() - { - return label; - } - - public String getPropertyName() - { - return name; - } - - public BeanModel model() - { - return model; - } - - public PropertyModel dataType(String dataType) - { - this.dataType = dataType; - - return this; - } - - public String getDataType() - { - return dataType; - } - - public boolean isSortable() - { - return sortable; - } - - public PropertyModel sortable(boolean sortable) - { - this.sortable = sortable; - - return this; - } - - public <T extends Annotation> T getAnnotation(Class<T> annotationClass) - { - return conduit == null ? null : conduit.getAnnotation(annotationClass); - } -} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3d4de7e1/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/CoercingPropertyConduitWrapper.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/CoercingPropertyConduitWrapper.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/CoercingPropertyConduitWrapper.java deleted file mode 100644 index 4dbfb2d..0000000 --- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/CoercingPropertyConduitWrapper.java +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2007 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. - -package org.apache.tapestry5.internal.services; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; - -import org.apache.tapestry5.PropertyConduit; -import org.apache.tapestry5.PropertyConduit2; -import org.apache.tapestry5.ioc.services.TypeCoercer; - -public class CoercingPropertyConduitWrapper implements PropertyConduit2 -{ - private final PropertyConduit conduit; - - private final TypeCoercer coercer; - - public CoercingPropertyConduitWrapper(final PropertyConduit conduit, final TypeCoercer coercer) - { - this.conduit = conduit; - this.coercer = coercer; - } - - public Object get(Object instance) - { - return conduit.get(instance); - } - - public <T extends Annotation> T getAnnotation(Class<T> annotationClass) - { - return conduit.getAnnotation(annotationClass); - } - - public Class getPropertyType() - { - return conduit.getPropertyType(); - } - - public Type getPropertyGenericType() - { - if (conduit instanceof PropertyConduit2) { - return ((PropertyConduit2) conduit).getPropertyGenericType(); - } - return conduit.getPropertyType(); - } - - @SuppressWarnings("unchecked") - public void set(Object instance, Object value) - { - Object coerced = coercer.coerce(value, getPropertyType()); - - conduit.set(instance, coerced); - } - -} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3d4de7e1/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitDelegate.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitDelegate.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitDelegate.java deleted file mode 100644 index 1242031..0000000 --- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitDelegate.java +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2007, 2008, 2009, 2010, 2011 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. - -package org.apache.tapestry5.internal.services; - -import java.lang.annotation.Annotation; - -import org.apache.tapestry5.internal.InternalPropertyConduit; -import org.apache.tapestry5.internal.util.IntegerRange; -import org.apache.tapestry5.ioc.AnnotationProvider; -import org.apache.tapestry5.ioc.internal.util.InternalUtils; -import org.apache.tapestry5.ioc.services.TypeCoercer; - -/** - * Companion class for {@link org.apache.tapestry5.PropertyConduit} instances created by the - * {@link org.apache.tapestry5.services.PropertyConduitSource}. - */ -@SuppressWarnings("all") -public class PropertyConduitDelegate -{ - private final TypeCoercer typeCoercer; - - public PropertyConduitDelegate(TypeCoercer typeCoercer) - { - this.typeCoercer = typeCoercer; - } - - public final IntegerRange range(int from, int to) - { - return new IntegerRange(from, to); - } - - public final <T> T coerce(Object value, Class<T> type) - { - return typeCoercer.coerce(value, type); - } - - public final boolean invert(Object value) - { - return coerce(value, Boolean.class).equals(Boolean.FALSE); - } -}