src/share/jaxws_classes/com/sun/tools/internal/xjc/generator/bean/field/AbstractFieldWithVar.java

Tue, 06 Mar 2012 16:09:35 -0800

author
ohair
date
Tue, 06 Mar 2012 16:09:35 -0800
changeset 286
f50545b5e2f1
child 368
0989ad8c0860
permissions
-rw-r--r--

7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom

     1 /*
     2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.internal.xjc.generator.bean.field;
    28 import com.sun.codemodel.internal.JBlock;
    29 import com.sun.codemodel.internal.JExpression;
    30 import com.sun.codemodel.internal.JFieldRef;
    31 import com.sun.codemodel.internal.JFieldVar;
    32 import com.sun.codemodel.internal.JMod;
    33 import com.sun.codemodel.internal.JType;
    34 import com.sun.codemodel.internal.JVar;
    35 import com.sun.tools.internal.xjc.api.SpecVersion;
    36 import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
    37 import com.sun.tools.internal.xjc.model.CPropertyInfo;
    39 /**
    40  *
    41  *
    42  * @author
    43  *     Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com), Martin Grebac
    44  */
    45 abstract class AbstractFieldWithVar extends AbstractField {
    47     /**
    48      * Field declaration of the actual list object that we use
    49      * to store data.
    50      */
    51     private JFieldVar field;
    53     /**
    54      * Invoke {@link #createField()} after calling the
    55      * constructor.
    56      */
    57     AbstractFieldWithVar( ClassOutlineImpl outline, CPropertyInfo prop ) {
    58         super(outline,prop);
    59     }
    61     protected final void createField() {
    62         field = outline.implClass.field( JMod.PROTECTED,
    63             getFieldType(), prop.getName(false) );
    65         annotate(field);
    66     }
    68     /**
    69      * Gets the name of the getter method.
    70      *
    71      * <p>
    72      * This encapsulation is necessary because sometimes we use
    73      * {@code isXXXX} as the method name.
    74      */
    75     protected String getGetterMethod() {
    76         if (getOptions().enableIntrospection) {
    77             return ((getFieldType().isPrimitive() &&
    78                      getFieldType().boxify().getPrimitiveType()==codeModel.BOOLEAN) ?
    79                          "is":"get") + prop.getName(true);
    80         } else {
    81             return (getFieldType().boxify().getPrimitiveType()==codeModel.BOOLEAN?"is":"get")+prop.getName(true);
    82         }
    83     }
    85     /**
    86      * Returns the type used to store the value of the field in memory.
    87      */
    88     protected abstract JType getFieldType();
    90     protected JFieldVar ref() { return field; }
    92     public final JType getRawType() {
    93         return exposedType;
    94     }
    96     protected abstract class Accessor extends AbstractField.Accessor {
    98         protected Accessor(JExpression $target) {
    99             super($target);
   100             this.$ref = $target.ref(AbstractFieldWithVar.this.ref());
   101         }
   103         /**
   104          * Reference to the field bound by the target object.
   105          */
   106         protected final JFieldRef $ref;
   108         public final void toRawValue(JBlock block, JVar $var) {
   109             if (getOptions().enableIntrospection) {
   110                 block.assign($var,$target.invoke(getGetterMethod()));
   111             } else {
   112                 block.assign($var,$target.invoke(getGetterMethod()));
   113             }
   114         }
   116         public final void fromRawValue(JBlock block, String uniqueName, JExpression $var) {
   117             block.invoke($target,("set"+prop.getName(true))).arg($var);
   118         }
   119     }
   120 }

mercurial