Does Castle Windsor allow the resolution of value types? - inversion-of-control

I'm trying to pass a parameter into a component that requires a System.TimeSpan. I'm only able to get the 'long ticks' ctor to resolve.
Here's a snippet of the config file:
<component id="timeInForce" type="System.TimeSpan, mscorlib">
<parameters>
<hours>0</hours>
<minutes>15</minutes>
<seconds>0</seconds>
</parameters>
</component>
<component id="FooSettings" type="Foo.FooSettings, Foo">
<parameters>
<tif>${timeInForce}</tif>
</parameters>
</component>
This is the exception:
Castle.MicroKernel.Handlers.HandlerException : Cant create component 'timeInForce'
as it has dependencies to be satisfied.
timeInForce is waiting for the following dependencies:
Keys (components with specific keys)
- ticks which was not registered.
Passing a tick value for the component parameter works, as in:
<parameters><tif>0</tif></parameters>
but this defeats the purpose.

What's happening (from what I can see) is that the ticks property is being incorrectly identified as a compulsory parameter (because it belongs to the constructor with the least number of arguments) even though all value types have a default parameter-less constructor.
However the constructor candidate matching the most parameters will still be selected even if you supply additional parameters (i.e. ticks) so you can work around this by just including ticks in the list of parameters:
<component id="timeInForce"" type="System.TimeSpan, mscorlib">
<parameters>
<ticks>0</ticks>
<hours>0</hours>
<minutes>15</minutes>
<seconds>0</seconds>
</parameters>
</component>
Here is a quick test to verify it works (which passes for against the castle trunk):
string xml = #"<?xml version=""1.0"" encoding=""utf-8"" ?>
<castle>
<components>
<component id=""timeInForce"" type=""System.TimeSpan, mscorlib"">
<parameters>
<ticks>0</ticks>
<hours>0</hours>
<minutes>15</minutes>
<seconds>0</seconds>
</parameters>
</component>
</components>
</castle>";
WindsorContainer container = new WindsorContainer(
new XmlInterpreter(new StaticContentResource(xml)));
TimeSpan span = container.Resolve<TimeSpan>("timeInForce");
Assert.AreEqual(new TimeSpan(0, 15, 0), span);
However, what I would suggest rather then the approach your using is to implement your own type converter, as discussed in the castle documentation.
That way you could develop your own shorthand form for a timespan i.e. "15m" or "2h15m" or whatever takes your fancy - making your config a little easier to read and maintain and working round the issues you're currently experiencing.

Related

phing loadfile to property does not override previous value

<loadfile property="test-from-file" file="value.txt" />
<echo message="test-from-file = ${test-from-file}" />
<loadfile property="test-from-file" file="value2.txt" />
<echo message="test-from-file = ${test-from-file}" />
The second loadfile does not change the value of the test-from-file property.
Is there any way to get this working?
As stated in comments by Jawi, properties are not overridden by design. A property works as a constant in Phing. So if it is already defined, then it won't be changed by later property definitions.
I think that you should revert your <property> task call in order to define your preferred sources first.
Alternatively, you can also use <property override="true"> to alter default behavior and override existing values, changing properties from constant to variable.

GWT property with is-multi-valued already defined

While migrating from GWT 2.7.0 to 2.8.2 I came upon property:
<define-configuration-property name="CssResource.gssDefaultInUiBinder"
is-multi-valued="true" />
If this is left as it is, I get an error: The configuration property named CssResource.gssDefaultInUiBinder is already defined with a different 'is-multi-valued' setting.
Does that mean that I can't set attribute is-multi-valued to already defined property? Why would this work with GWT 2.7.0 then? Can anyone give me an explanation about this attribute? Because I am failing to find one...
Attribute set in GWT resources:
<!-- The default for GSS in UiBinder -->
<define-configuration-property name="CssResource.gssDefaultInUiBinder" is-multi-valued="false" />
gwt/user/src/com/google/gwt/resources/Resources.gwt.xml
Correct - you should not be trying to change is-multi-valued, it doesn't really make any sense. You can't re-define a property or configuration-property after it has been set, you can only set the value.
If you want to turn the gss-in-ui-binder flag on, use this:
<set-configuration-property name="CssResource.gssDefaultInUiBinder" value="true" />
If you want to turn it off, either do nothing, or do this:
<set-configuration-property name="CssResource.gssDefaultInUiBinder" value="false" />

Mybatis Generator's bug: configuration items should be ordered?

If I put "<commentGenerator>" after "<jdbcConnection>", MBG proposed an error that context content should match: blablabla...
But when I put "<commentGenerator>" before "<jdbcConnection>", everything is ok. Here I have something to complain to the official website that if the order of these items is need, why you do not tell us! What an important thing! You r kidding the freshmen. Maybe it is some where I do not know, but this is a key point to build the MBG's configuration file successfully, why not put this NOTE on the top of the tutorial or somewhere eye-catching?
<generatorConfiguration >
<classPathEntry location="D:\mariadb-java-client-1.1.7.jar" />
<context id="db" >
<commentGenerator>
<property name="suppressAllComments" value="true" />
<property name="suppressDate" value="true" />
</commentGenerator>
<jdbcConnection driverClass="org.mariadb.jdbc.Driver"
connectionURL="jdbc:mariadb://localhost:3306/dbname"
userId="root"
password="password"
/>
<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- Model Class -->
<javaModelGenerator targetPackage="org.infrastructure.model" targetProject="infrastructure\src\main\java">
<property name="enableSubPackages" value="false" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- XML Files -->
<sqlMapGenerator targetPackage="sqlMap" targetProject="infrastructure\src\main\config">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- DAO -->
<javaClientGenerator type="XMLMAPPER" targetPackage="org.infrastructure.dao" targetProject="infrastructure\src\main\java">
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- Tables -->
<table tableName="user" domainObjectName="User" ></table>
</context>
</generatorConfiguration>
First of all, in your xml configuration file, it doesn't contains a valid root element, which always should be like <!DOCTYPE .../>. About how to add a correct root element of mybatis generator configuration file, please see example from MyBatis GeneratorXML Configuration File Reference.
If you correctly specified root element such as following:
<!DOCTYPE generatorConfiguration PUBLIC
"-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"
>
This root element contains a typical DTD declaration located at http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd. This is the definition of the order of these items is need. And we are going to see what it looks like.
From line 47 of this document type definition, it defines element named context. The content is as following:
<!--
The context element is used to describe a context for generating files, and the source tables.
-->
<!ELEMENT context (property*, plugin*, commentGenerator?, jdbcConnection, javaTypeResolver?,javaModelGenerator, sqlMapGenerator?, javaClientGenerator?, table+)>
Which obviously defined the order of the element in context, that is:
property*, plugin*, commentGenerator?, jdbcConnection,
javaTypeResolver?,javaModelGenerator, sqlMapGenerator?,
javaClientGenerator?, table+
In this element, all children must occurs as following rules:
+ for specifying that there must be one or more occurrences of the item — the effective content of each occurrence may be different;
* for specifying that any number (zero or more) of occurrences is allowed — the item is optional and the effective content of each occurrence may be different;
? for specifying that there must not be more than one occurrence — the item is optional;
If there is no quantifier, the specified item must occur exactly one time at the specified position in the content of the element.
After we understanding its real meaning, why you could not change the order of commentGenerator and jdbcConnection should be clear.
Maybe you want to know how to make the element out of order, question How to define DTD without strict element order could be useful.
Wish it helpful.

JAXB binding XBRL element does not work

I am trying to generate localised XBRL classes with JAXB in Eclipse, but I have been getting an error:
[ERROR] Property "Title" is already defined. Use <jaxb:property> to resolve this conflict.
line 145 of http://www.xbrl.org/2003/xl-2003-12-31.xsd
[ERROR] The following location is relevant to the above error
line 151 of http://www.xbrl.org/2003/xl-2003-12-31.xsd
As the error suggests, an element and an attribute name conflicts. These are lines 145 and 151:
<element ref="xl:title" minOccurs="0" maxOccurs="unbounded" />
<attribute ref="xlink:title" use="optional" />
So I'd need to rename either (or both). This is what I've been trying to do - bind the element title to titleElement:
<jxb:bindings version="1.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xl="http://www.xbrl.org/2003/XLink"
schemaLocation="http://www.xbrl.org/2003/xl-2003-12-31.xsd">
<jxb:bindings node="//element[#ref='xl:title']">
<jxb:property ref="xl:titleElement"/>
</jxb:bindings>
</jxb:bindings>
This produces the following error, plus the original "title already defined" errors:
[ERROR] XPath evaluation of "//element[#ref='xl:title']" results in empty target node
line 6 of titleElementAttributeFixer.xjb
Suggestions to get it working?
EDIT: as helderdarocha suggested, my expression was wrong. I am new to XML and XPath, and it was a bit confusing since the element does not have the "xs:" namespace typed excplicitly. After I fixed that error, I got another one:
[ERROR] XPath evaluation of "//xs:element[#ref='xl:title']" results in too many (3) target nodes
As all the "ref" attributes need to be updated, I put the tag "multiple='true'" in the binding. Now I am getting the following error, and cannot figure out how to solve it:
[ERROR] cvc-complex-type.3.2.2: Attribute 'ref' is not allowed to appear in element 'jxb:property'.
Ideas for this? I do want to bind the contents in the attribute 'ref' for the element in question to another name.
I solved the problem after all by applying these SO questions:
JAXB fails to generate Java classes for XBRL
JAXB XJC Two declarations cause a collision. Customized binding cannot be honored
So after I solved the original problem, I had additional problems with objectfactory collisions, which I fixed as well. This is how my working bindings.xjb looks in general:
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
version="2.1">
<bindings schemaLocation="http://www.xbrl.org/2003/xl-2003-12-31.xsd"
node="//xsd:schema//xsd:element[#name='title']">
<property name="xlTitle"/>
</bindings>
<bindings schemaLocation="<local_dimension_file_D002>.xsd"
node="//xsd:schema//xsd:element[#name='AcceleratedDepreciation']">
<factoryMethod name="AcceleratedDepreciationD002"/>
</bindings>
...many more objectfactory collisions solved...
</bindings>
I hope this helps other XBRL/XML/JAXB newcomers to get started.
Your XPath expression is incorrect. Your bindings XML declares an xs prefix to qualify all XML Schema elements, but your XPath expression tries to find an element element from no-namespace since it's not qualified.
You should use:
<jxb:bindings node="//xs:element[#ref='xl:title']">
<jxb:property ref="xl:titleElement"/>
</jxb:bindings>

cannot insert NULL into ("ESB"."ADDRESS_API"."LABEL_NAME_MAP")

Attempting to hit the Customers end point and the API keeps rejecting my request with this extremely nondescript error:
<ErrorCode>-3002</ErrorCode>
<ErrorDesc>cannot insert NULL into ("ESB"."ADDRESS_API"."LABEL_NAME_MAP")</ErrorDesc>
<DBErrorCode>01400</DBErrorCode>
Here is the sample XML:
<?xml version='1.0' encoding='utf-8' ?>
<Add RequestId='47e1633341s4521a24e269ad12ab3f6' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://www.intuit.com/sb/cdm/v2'>
<ExternalRealmId>111111111</ExternalRealmId>
<Object xsi:type='Customer'>
<TypeOf>Organization</TypeOf>
<Name>SampleCustomer</Name>
<Address>
<Line1>123 E. Fake St</Line1>
<Line2>Suite 1</Line2>
<City>Somewhere</City>
<Country>USA</Country>
<CountrySubDivisionCode>FL</CountrySubDivisionCode>
<PostalCode>12345</PostalCode>
<Default>true</Default>
<Tag>Billing</Tag>
</Address>
<Phone>
<DeviceType>LandLine</DeviceType>
<FreeFormNumber>123-456-4563</FreeFormNumber>
<Default>true</Default>
<Tag>Main</Tag>
</Phone>
<DBAName>Sample Customer</DBAName>
<AcctNum>51f2ce86134c03000a000155</AcctNum>
</Object>
</Add>
Any suggestions? These exceptions are super confusion. I found the one related to "ESB"."PHONE_API"."LABEL_NAME_MAP" was related to an empty phone number field. That isn't the case with this request.
You edited your post to reflect a correct tag, so this answer may no longer be relevant
My first guess would be that, per the documentation, the Address/Tag node allowable values are defined by the PhysicalAddressLabelType enum.
Tag - String - Tag (or label) that identifies the use of the address. The
values allowed are defined in the PhysicalAddressLabelType.
If you look at the allowable values, you'll see the only allowable values are:
Billing
Shipping
But you specified:
Office
Can you try specifying a valid value?
Likewise, you're specifying an invalid Tag for the Phone node as well. The allowable values are here:
https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/v2/0500_quickbooks_windows/062_enumerations/telephonenumberlabeltype
But you've specified:
Main
Can you try specifying a valid value?