001: /*
002: Copyright (c) 2007, Dennis M. Sosnoski
003: All rights reserved.
004:
005: Redistribution and use in source and binary forms, with or without modification,
006: are permitted provided that the following conditions are met:
007:
008: * Redistributions of source code must retain the above copyright notice, this
009: list of conditions and the following disclaimer.
010: * Redistributions in binary form must reproduce the above copyright notice,
011: this list of conditions and the following disclaimer in the documentation
012: and/or other materials provided with the distribution.
013: * Neither the name of JiBX nor the names of its contributors may be used
014: to endorse or promote products derived from this software without specific
015: prior written permission.
016:
017: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
018: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
019: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
021: ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: */
028:
029: package org.jibx.binding.generator;
030:
031: import org.jibx.binding.model.IClassItem;
032: import org.jibx.runtime.IUnmarshallingContext;
033: import org.jibx.runtime.JiBXException;
034:
035: /**
036: * Member field customization information.
037: */
038: public class MemberFieldCustom extends MemberCustom {
039: // values specific to member level
040: private String m_fieldName;
041:
042: /**
043: * Constructor.
044: *
045: * @param parent
046: */
047: protected MemberFieldCustom(NestingBase parent) {
048: super (parent);
049: }
050:
051: /**
052: * Constructor with name known.
053: *
054: * @param parent
055: * @param name
056: */
057: protected MemberFieldCustom(NestingBase parent, String name) {
058: super (parent, name);
059: }
060:
061: /**
062: * Check if collection member.
063: *
064: * @return <code>false</code>
065: */
066: public boolean isCollection() {
067: return false;
068: }
069:
070: /**
071: * Get field name.
072: *
073: * @return field name (<code>null</code> if none)
074: */
075: public String getFieldName() {
076: return m_fieldName;
077: }
078:
079: /**
080: * Post-set method that converts the field name to a member name.
081: *
082: * @throws JiBXException
083: */
084: protected void postset() throws JiBXException {
085: if (m_fieldName == null) {
086: throw new JiBXException(
087: "'field' attribute is required for <field> element");
088: } else {
089: ClassCustom clas = (ClassCustom) getParent();
090: setBaseName(memberNameFromField(m_fieldName, clas
091: .getStripPrefixes(), clas.getStripSuffixes()));
092: }
093: }
094:
095: /**
096: * Complete customization information based on field information.
097: *
098: * @param field (<code>null</code> if none available)
099: * @param req required member flag (<code>null</code> if unknown)
100: */
101: /*package*/void completeField(IClassItem field, Boolean req) {
102: if (m_fieldName == null) {
103: m_fieldName = field.getName();
104: }
105: complete(field == null ? null : field.getTypeName(), req);
106: }
107:
108: private static MemberFieldCustom factory(IUnmarshallingContext ictx) {
109: return new MemberFieldCustom(getContainingClass(ictx));
110: }
111: }
|