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 property customization information.
037: */
038: public class MemberPropertyCustom extends MemberCustom {
039: // values specific to member level
040: private String m_getName;
041: private String m_setName;
042:
043: /**
044: * Constructor.
045: *
046: * @param parent
047: */
048: protected MemberPropertyCustom(NestingBase parent) {
049: super (parent);
050: }
051:
052: /**
053: * Constructor with name known.
054: *
055: * @param parent
056: * @param name
057: */
058: protected MemberPropertyCustom(NestingBase parent, String name) {
059: super (parent, name);
060: }
061:
062: /**
063: * Check if collection member.
064: *
065: * @return <code>false</code>
066: */
067: public boolean isCollection() {
068: return false;
069: }
070:
071: /**
072: * Get 'get' method name.
073: *
074: * @return 'get' method name (<code>null</code> if none)
075: */
076: public String getGetName() {
077: return m_getName;
078: }
079:
080: /**
081: * Get 'set' method name.
082: *
083: * @return 'set' method name (<code>null</code> if none)
084: */
085: public String getSetName() {
086: return m_setName;
087: }
088:
089: /**
090: * Post-set method that converts the get/set method names to a member name.
091: *
092: * @throws JiBXException
093: */
094: protected void postset() throws JiBXException {
095: if (m_getName == null && m_setName == null) {
096: throw new JiBXException(
097: "'get-name' or 'set-name' attribute is required for <property> element");
098: } else {
099: if (m_setName == null) {
100: setBaseName(memberNameFromGetMethod(m_getName));
101: } else {
102: setBaseName(memberNameFromSetMethod(m_setName));
103: }
104: }
105: }
106:
107: /**
108: * Complete customization information based on access method information.
109: *
110: * @param gmeth read access method (<code>null</code> if none)
111: * @param smeth write access method (<code>null</code> if none)
112: * @param type value type
113: * @param req required member flag (<code>null</code> if unknown)
114: */
115: /*package*/void completeProperty(IClassItem gmeth,
116: IClassItem smeth, String type, Boolean req) {
117: if (m_getName == null && gmeth != null) {
118: m_getName = gmeth.getName();
119: }
120: if (m_setName == null && smeth != null) {
121: m_setName = smeth.getName();
122: }
123: complete(type, req);
124: }
125:
126: private static MemberPropertyCustom factory(
127: IUnmarshallingContext ictx) {
128: return new MemberPropertyCustom(getContainingClass(ictx));
129: }
130: }
|