|  |  |  | License Codehaus OpenEJB OpenJMS OpenORB Tyrex
Old releases
General
Release 1.3
Release 1.3rc1
Release 1.2
Main
Home
About
Features
Download
Dependencies
Reference guide
Publications
JavaDoc
Maven 2 support
Maven 2 archetypes
DTD & Schemas
Recent HTML changes
News Archive
RSS news feed
Project Wiki
Development/Support
Mailing Lists
SVN/JIRA
Contributing
Support
Continuous builds
Prof. services
Related projects
Spring ORM support
Spring XML factories
WS frameworks
XML
XML
XML Code Generator
XML Code Generator
JDO
Introduction
First steps
Using JDO
JDO Config
Types
JDO Mapping
JDO FAQ
JDO Examples
JDO HOW-TOs
Tips & Tricks
Other Features
JDO sample JAR
Tools
Schema generator
Advanced JDO
Caching
OQL
Trans. & Locks
Design
KeyGen
Long Trans.
Nested Attrs.
Pooling Examples
LOBs
Best practice
DDL Generator
Using DDL Generator
Properties
Ant task
Type Mapping
More
The Examples
3rd Party Tools
JDO Tests
XML Tests
Configuration
About
License
User stories
Contributors
Marketplace
Status, Todo
Changelog
Library
Contact
Project Name
## How to map field(s) as constructor argument Intended Audience Prerequisites Basic concept Mapping file References ## Intended Audience Anyone who wants to map a class in Castor XML and wants to map fields as constructor arguments. This document helps people to get familiar with the basic/advanced concepts of mapping and shows an example. ## Prerequisites None. ## Basic concept Assume you have a class `Foo`, as shown below
    public class Foo {

        private int size = 20;

        public Foo() { }

        public Foo(int size) {
            this.size = size;
        }

        public int getSize() {
            return size;
        }

        public void setSize(int size) {
            this.size = size;
        }

    }
As shown above, the `Foo` class has - in addition to the default constructor, which is required by Castor XML - a second constructor that allows you to specify a custom size at object initialization. ## Mapping file Here's the mapping file to instruct Castor XML about the existence of `Foo` respectively:
    <?xml version="1.0"?>
    <mapping>
      <class name="Foo">
         <field name="size" get-method="getSize" set-method="%1" type="int">
            <bind-xml node="attribute"/>
         </field>
      </class>
    </mapping>
The `setMethod="%1"` fragment above tells Castor to use the `size` attribute as a constructor argument when calling `Foo(int)` during instantiation. ## References
- | XML mapping
| Copyright © 1999-2005 ExoLab Group, Intalio Inc., and Contributors. All rights reserved. Java, EJB, JDBC, JNDI, JTA, Sun, Sun Microsystems are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and in other countries. XML, XML Schema, XSLT and related standards are trademarks or registered trademarks of MIT, INRIA, Keio or others, and a product of the World Wide Web Consortium. All other product names mentioned herein are trademarks of their respective owners. |