commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Charles Hudak" <charles.hu...@cardionet.com>
Subject RE: [Betwixt] Mapping Beans to Beans
Date Mon, 16 Aug 2004 22:14:05 GMT
> Yes. A mapping like below:
> <mapping classOne="VO1" classTwo="VO2"> Bi-directional
>   <property1="errorMessage" property2="errorMSG"/> Property names are 
> different
>   <property1="MyResults" property2="YourResults"/> Nested Objects: 
> Arrays of Results
>   </default> Will do a PropertyUtils.copyProperties() and catch all 
> the generic properties that are named the same on both objects
> </mapping>
>
> Nice things to have: default values, conversion (int to String, etc.)

>conversions are a nice little problem :)

> I have been looking at some code in-house and they spend hundreds or 
> thousands of line of code doing simple/stupid Value Object 
> conversions.

I've built a mapping framework similar to this that does property mapping between objects
and allows translations, type conversions as well as field muxing and demuxing. An example
configuration is below. I originally had the bidirectional support but found with things like
muxing and demuxing as well as adaption at the field level that it made the schema a PITA.
I decided to force binding configurations to specifically be defined in each direction. This
framework has eliminated the need to do things like foo.setFubar(fubar.getFubar()) completely
in our codebase. It has also made mapping back and forth between VO's and our JAXB objects
very easy.

<?xml version="1.0" encoding="UTF-8"?>
<binding-config version="1.0">
	<converters>
		<converter
			class="com.cardionet.sync.binding.converter.CalendarConverter"
			type="java.util.Calendar" />
		<converter
			class="com.cardionet.sync.binding.converter.TimestampConverter"
			type="java.sql.Timestamp" />
	</converters>
	<object-bindings>
		<!-- Patient to PatientDTO -->
		<object-binding
			object-from="com.cardionet.sync.update.domain.PatientVisitType$Patient"
			object-to="com.cardionet.common.cndomain.ejb.dto.PatientDTO">
			<field-binding
				class="com.cardionet.sync.binding.SimpleFieldBinder">
				<config>
					<from>lastName</from>
					<to>lastName</to>
				</config>
				<adapters>
					<adapter
						class="com.cardionet.sync.binding.adapter.EchoAdapter" />
				</adapters>
			</field-binding>
			<field-binding
				class="com.cardionet.sync.binding.SimpleFieldBinder">
				<config>
					<from>firstName</from>
					<to>firstName</to>
				</config>
			</field-binding>
			<field-binding
				class="com.cardionet.sync.binding.SimpleFieldBinder">
				<config>
					<from>middleInitial</from>
					<to>middleInitial</to>
					<adapters>
						<adapter
							class="com.cardionet.sync.binding.adapter.DefaultStringValueAdapter">
							<config>
								<default-value />
							</config>
						</adapter>
					</adapters>
				</config>
			</field-binding>
		</object-binding>
        <object-binding 
            object-from="com.cardionet.sync.update.domain.PhysicianInfo"
			object-to="com.cardionet.common.sceodomain.vo.LocationVO">
            <field-binding class="com.cardionet.sync.binding.MultiplexingFieldBinder">
                <config>
                    <!-- TODO: figure out how to deal with credentials -->
                    <from>physician.firstName</from>
                    <from>physician.lastName</from>
                    <from>physician.physicianCredentials</from>
                    <to>address1</to>
                    <multiplexor class="com.cardionet.sync.binding.ConcatenatingMultiplexor">
                        <config>
                            <separator> </separator>
                        </config>                        
                    </multiplexor>
                </config>
            </field-binding>            
			<field-binding class="com.cardionet.sync.binding.SimpleFieldBinder">
                <config>
                    <from>medicalGroup.name</from>
                    <to>address2</to>
                </config>
            </field-binding>
            <field-binding class="com.cardionet.sync.binding.SimpleFieldBinder">
                <config>
                    <from>facility.facilityName</from>
                    <to>address3</to>
                </config>
            </field-binding>
            <field-binding class="com.cardionet.sync.binding.SimpleFieldBinder">
                <config>
                    <from>physician.phoneAreaCode</from>
                    <to>phone1a</to>
                    <adapters>
                        <adapter class="com.cardionet.sync.binding.adapter.FormatAreaCodeAdapter"/>
                    </adapters>
                </config>
            </field-binding>
            <field-binding class="com.cardionet.sync.binding.SimpleFieldBinder">
                <config>
                    <from>physician.phone</from>
                    <to>phone1</to>                    
                </config>
            </field-binding>
        </object-binding>      
	</object-bindings>
</binding-config>






---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message