1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.Components
.Binder
18 using Castle
.Components
.Validator
;
20 public delegate void BinderHandler(object instance
, String prefix
, Node node
);
23 /// Defines the contract for a data binder implementation approach.
25 public interface IDataBinder
27 bool CanBindParameter(Type desiredType
, String paramName
, CompositeNode treeRoot
);
29 bool CanBindObject(Type targetType
, String prefix
, CompositeNode treeRoot
);
31 object BindParameter(Type targetType
, String paramName
, CompositeNode treeRoot
);
34 /// Create an instance of the specified type and binds the properties that
35 /// are available on the datasource.
37 /// <param name="targetType">The target type. Can be an array</param>
38 /// <param name="prefix">The obligatory prefix that distinguishes it on the datasource</param>
39 /// <param name="treeRoot">A hierarchycal representation of flat data</param>
40 /// <returns>an instance of the specified target type</returns>
41 object BindObject(Type targetType
, String prefix
, CompositeNode treeRoot
);
44 /// Create an instance of the specified type and binds the properties that
45 /// are available on the datasource respecting the white and black list
47 /// <param name="targetType">The target type. Can be an array</param>
48 /// <param name="prefix">The obligatory prefix that distinguishes it on the datasource</param>
49 /// <param name="excludedProperties">A list of comma separated values specifing the properties that should be ignored</param>
50 /// <param name="allowedProperties">A list of comma separated values specifing the properties that should not be ignored</param>
51 /// <param name="treeRoot">A hierarchycal representation of flat data</param>
52 /// <returns>an instance of the specified target type</returns>
53 object BindObject(Type targetType
, String prefix
, String excludedProperties
, String allowedProperties
, CompositeNode treeRoot
);
56 /// Binds the properties that are available on the datasource to the specified object instance.
58 /// <param name="instance">The target instance.</param>
59 /// <param name="prefix">The obligatory prefix that distinguishes it on the datasource</param>
60 /// <param name="treeRoot">A hierarchycal representation of flat data</param>
61 /// <returns>an instance of the specified target type</returns>
62 void BindObjectInstance(object instance
, String prefix
, CompositeNode treeRoot
);
65 /// Binds the properties that
66 /// are available on the datasource respecting the white and black list
68 /// <param name="instance">The target type.</param>
69 /// <param name="prefix">The obligatory prefix that distinguishes it on the datasource</param>
70 /// <param name="excludedProperties">A list of comma separated values specifing the properties that should be ignored</param>
71 /// <param name="allowedProperties">A list of comma separated values specifing the properties that should not be ignored</param>
72 /// <param name="treeRoot">A hierarchycal representation of flat data</param>
73 /// <returns>an instance of the specified target type</returns>
74 void BindObjectInstance(object instance
, String prefix
, String excludedProperties
, String allowedProperties
, CompositeNode treeRoot
);
77 /// Represents the databind errors
79 ErrorList ErrorList { get; }
82 /// Gets the validation error summary.
84 /// <param name="instance">The instance.</param>
85 ErrorSummary
GetValidationSummary(object instance
);
88 /// Exposes the <see cref="IBinderTranslator"/> implementation
89 /// if one was provided
91 IBinderTranslator Translator { get; set; }
94 /// Exposes the <see cref="IConverter"/> implementation
96 IConverter Converter { get; set; }
99 /// Gets or sets the validator runner instance.
101 /// <value>The validator instance.</value>
102 ValidatorRunner Validator { get; set; }
105 /// Invoked before the data binder implementation starts to
106 /// work on a class instance
108 event BinderHandler OnBeforeBinding
;
111 /// Invoked after the data binder implementation starts to
112 /// work on a class instance
114 event BinderHandler OnAfterBinding
;