cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache CXF > cxf-xjc-dv
Date Fri, 22 Oct 2010 17:47:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/15/_/styles/combined.css?spaceKey=CXF&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CXF/cxf-xjc-dv">cxf-xjc-dv</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~dkulp">Daniel
Kulp</a>
    </h4>
        <br/>
                         <h4>Changes (4)</h4>
                                 
    
<div id="page-diffs">
            <table class="diff" cellpadding="0" cellspacing="0">
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >        return foreground; <br>
   } <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{code}
<br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">Normally,
XJC would just generate code like: <br>{code:java} <br>    public String getBackground()
{ <br>        return background; <br>    } <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
   public String getForeground() { <br>        return foreground; <br>    } <br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">so
code that works with the beans need to take the possible null return into account. <br>
<br> <br>h3.  To use with Maven <br> <br>{code:xml} <br>   
       &lt;plugin&gt; <br>                &lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
<br>                &lt;artifactId&gt;cxf-xjc-plugin&lt;/artifactId&gt;
<br>                &lt;executions&gt; <br>                    &lt;execution&gt;
<br>                        &lt;goals&gt; <br>                       
    &lt;goal&gt;xsdtojava&lt;/goal&gt; <br>                        &lt;/goals&gt;
<br>                    &lt;/execution&gt; <br>                &lt;/executions&gt;
<br>                &lt;configuration&gt; <br>                    &lt;xsdOptions&gt;
<br>                        &lt;xsdOption&gt; <br>                   
        &lt;extension&gt;true&lt;/extension&gt; <br>               
            &lt;xsd&gt;${basedir}/src/main/resources/schemas/configuration/foo.xsd&lt;/xsd&gt;
<br>                            &lt;extensionArgs&gt; <br>           
                    &lt;arg&gt;-Xdv&lt;/arg&gt; <br>               
            &lt;/extensionArgs&gt; <br>                        &lt;/xsdOption&gt;
<br>                    &lt;/xsdOptions&gt; <br>                    &lt;extensions&gt;
<br>                        &lt;extension&gt;org.apache.cxf.xjcplugins:cxf-xjc-dv:2.3.0&lt;/extension&gt;
<br>                    &lt;/extensions&gt; <br>                &lt;/configuration&gt;
<br>            &lt;/plugin&gt; <br> <br>{code} <br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="cxf-xjc-dv-CXFXJCDefaultValuePlugin"></a>CXF XJC Default
Value Plugin</h2>

<p>The CXF XJC Default Value Plugin provides and XJC plugin that updates the generated
beans to return the default value defined  in the schema for fields that are unset in the
instance.   </p>

<p>For example, if the schema contains:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;xs:complexType name=<span class="code-quote">"pageColor"</span>&gt;</span>
  	<span class="code-tag">&lt;xs:sequence&gt;</span>
	    <span class="code-tag">&lt;xs:element name=<span class="code-quote">"background"</span>
type=<span class="code-quote">"xs:string"</span> default=<span class="code-quote">"red"</span>/&gt;</span>
	    <span class="code-tag">&lt;xs:element name=<span class="code-quote">"foreground"</span>
type=<span class="code-quote">"xs:string"</span> default=<span class="code-quote">"blue"</span>/&gt;</span>
   <span class="code-tag">&lt;/xs:sequence&gt;</span>
<span class="code-tag">&lt;/xs:complexType&gt;</span>
</pre>
</div></div>

<p>it would generate getter methods like:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    <span class="code-keyword">public</span> <span class="code-object">String</span>
getBackground() {
        <span class="code-keyword">if</span> (<span class="code-keyword">null</span>
== background) {
            <span class="code-keyword">return</span> <span class="code-quote">"red"</span>;
        }
        <span class="code-keyword">return</span> background;
    }

    <span class="code-keyword">public</span> <span class="code-object">String</span>
getForeground() {
        <span class="code-keyword">if</span> (<span class="code-keyword">null</span>
== foreground) {
            <span class="code-keyword">return</span> <span class="code-quote">"blue"</span>;
        }
        <span class="code-keyword">return</span> foreground;
    }
</pre>
</div></div>

<p>Normally, XJC would just generate code like:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    <span class="code-keyword">public</span> <span class="code-object">String</span>
getBackground() {
        <span class="code-keyword">return</span> background;
    }

    <span class="code-keyword">public</span> <span class="code-object">String</span>
getForeground() {
        <span class="code-keyword">return</span> foreground;
    }
</pre>
</div></div>
<p>so code that works with the beans need to take the possible null return into account.</p>


<h3><a name="cxf-xjc-dv-TousewithMaven"></a>To use with Maven</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
           <span class="code-tag">&lt;plugin&gt;</span>
                <span class="code-tag">&lt;groupId&gt;</span>org.apache.cxf<span
class="code-tag">&lt;/groupId&gt;</span>
                <span class="code-tag">&lt;artifactId&gt;</span>cxf-xjc-plugin<span
class="code-tag">&lt;/artifactId&gt;</span>
                <span class="code-tag">&lt;executions&gt;</span>
                    <span class="code-tag">&lt;execution&gt;</span>
                        <span class="code-tag">&lt;goals&gt;</span>
                            <span class="code-tag">&lt;goal&gt;</span>xsdtojava<span
class="code-tag">&lt;/goal&gt;</span>
                        <span class="code-tag">&lt;/goals&gt;</span>
                    <span class="code-tag">&lt;/execution&gt;</span>
                <span class="code-tag">&lt;/executions&gt;</span>
                <span class="code-tag">&lt;configuration&gt;</span>
                    <span class="code-tag">&lt;xsdOptions&gt;</span>
                        <span class="code-tag">&lt;xsdOption&gt;</span>
                            <span class="code-tag">&lt;extension&gt;</span>true<span
class="code-tag">&lt;/extension&gt;</span>
                            <span class="code-tag">&lt;xsd&gt;</span>${basedir}/src/main/resources/schemas/configuration/foo.xsd<span
class="code-tag">&lt;/xsd&gt;</span>
                            <span class="code-tag">&lt;extensionArgs&gt;</span>
                                <span class="code-tag">&lt;arg&gt;</span>-Xdv<span
class="code-tag">&lt;/arg&gt;</span>
                            <span class="code-tag">&lt;/extensionArgs&gt;</span>
                        <span class="code-tag">&lt;/xsdOption&gt;</span>
                    <span class="code-tag">&lt;/xsdOptions&gt;</span>
                    <span class="code-tag">&lt;extensions&gt;</span>
                        <span class="code-tag">&lt;extension&gt;</span>org.apache.cxf.xjcplugins:cxf-xjc-dv:2.3.0<span
class="code-tag">&lt;/extension&gt;</span>
                    <span class="code-tag">&lt;/extensions&gt;</span>
                <span class="code-tag">&lt;/configuration&gt;</span>
            <span class="code-tag">&lt;/plugin&gt;</span>

</pre>
</div></div>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CXF/cxf-xjc-dv">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=24184044&revisedVersion=2&originalVersion=1">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CXF/cxf-xjc-dv?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message