Method from org.apache.tapestry5.internal.beaneditor.BeanModelImpl Detail: |
public PropertyModel add(String propertyName) {
PropertyConduit conduit = createConduit(propertyName);
return add(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;
}
|
public PropertyModel add(RelativePosition position,
String existingPropertyName,
String propertyName) {
PropertyConduit conduit = createConduit(propertyName);
return add(position, existingPropertyName, propertyName, conduit);
}
|
public PropertyModel add(RelativePosition position,
String existingPropertyName,
String propertyName,
PropertyConduit conduit) {
Defense.notNull(position, "position");
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 BeanModel 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 PropertyModel get(String propertyName) {
PropertyModel propertyModel = properties.get(propertyName);
if (propertyModel == null)
throw new RuntimeException(BeanEditorMessages.unknownProperty(beanType,
propertyName,
properties.keySet()));
return propertyModel;
}
|
public Class<T> getBeanType() {
return beanType;
}
|
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 RuntimeException(BeanEditorMessages.unknownPropertyId(beanType,
propertyId, ids));
}
|
public List<String> getPropertyNames() {
return CollectionFactory.newList(propertyNames);
}
|
public BeanModel 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;
}
|
public T newInstance() {
return locator.autobuild(beanType);
}
|
public BeanModel 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 String toString() {
StringBuilder builder = new StringBuilder("BeanModel[");
builder.append(ClassFabUtils.toJavaClassName(beanType));
builder.append(" properties:");
String sep = "";
for (String name : propertyNames)
{
builder.append(sep);
builder.append(name);
sep = ", ";
}
builder.append("]");
return builder.toString();
}
|