001: /*
002: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.internal.xjc.outline;
027:
028: import com.sun.codemodel.internal.JBlock;
029: import com.sun.codemodel.internal.JExpression;
030: import com.sun.codemodel.internal.JVar;
031: import com.sun.tools.internal.xjc.model.CPropertyInfo;
032:
033: /**
034: * Encapsulates the access on a field.
035: *
036: * @author
037: * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
038: */
039: public interface FieldAccessor {
040:
041: /**
042: * Dumps everything in this field into the given variable.
043: *
044: * <p>
045: * This generates code that accesses the field from outside.
046: *
047: * @param block
048: * The code will be generated into this block.
049: * @param $var
050: * Variable whose type is {@link FieldOutline#getRawType()}
051: */
052: void toRawValue(JBlock block, JVar $var);
053:
054: /**
055: * Sets the value of the field from the specified expression.
056: *
057: * <p>
058: * This generates code that accesses the field from outside.
059: *
060: * @param block
061: * The code will be generated into this block.
062: * @param uniqueName
063: * Identifier that the caller guarantees to be unique in
064: * the given block. When the callee needs to produce additional
065: * variables, it can do so by adding suffixes to this unique
066: * name. For example, if the uniqueName is "abc", then the
067: * caller guarantees that any identifier "abc.*" is unused
068: * in this block.
069: * @param $var
070: * The expression that evaluates to a value of the type
071: * {@link FieldOutline#getRawType()}.
072: */
073: void fromRawValue(JBlock block, String uniqueName, JExpression $var);
074:
075: /**
076: * Generates a code fragment to remove any "set" value
077: * and move this field to the "unset" state.
078: *
079: * @param body
080: * The code will be appended at the end of this block.
081: */
082: void unsetValues(JBlock body);
083:
084: /**
085: * Return an expression that evaluates to true only when
086: * this field has a set value(s).
087: *
088: * @return null
089: * if the isSetXXX/unsetXXX method does not make sense
090: * for the given field.
091: */
092: JExpression hasSetValue();
093:
094: /**
095: * Gets the {@link FieldOutline} from which
096: * this object is created.
097: */
098: FieldOutline owner();
099:
100: /**
101: * Short for <tt>owner().getPropertyInfo()</tt>
102: */
103: CPropertyInfo getPropertyInfo();
104: }
|