001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify
008: * it under the terms of the GNU General Public License as published by
009: * the Free Software Foundation; either version 2 of the License, or
010: * (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc.,59 Temple Place, Suite 330, Boston, MA 02111-1307
020: * USA
021: *
022: *
023: * $Id: ContentNodeImpl.java 6044 2007-03-18 03:55:52Z mpreston $
024: */
025: package com.bostechcorp.cbesb.common.mdl.impl;
026:
027: import org.jdom.Attribute;
028: import org.jdom.Element;
029:
030: import com.bostechcorp.cbesb.common.mdl.IContentNode;
031: import com.bostechcorp.cbesb.common.mdl.IMDLDocument;
032: import com.bostechcorp.cbesb.common.mdl.MDLDocConstants;
033:
034: /**
035: * Represents the content specifications of a child element.
036: *
037: */
038: public abstract class ContentNodeImpl implements IContentNode {
039:
040: /**
041: * Specifies the minimum number of instances allowed in the data.
042: */
043: private int minOccurs;
044:
045: /**
046: * Specifies the maximum number of instances allowed in the data.
047: */
048: private int maxOccurs;
049:
050: /**
051: * The containing MDL document used to resolve references.
052: */
053: public IMDLDocument mdlDocument;
054:
055: /**
056: * Constructor.
057: */
058: public ContentNodeImpl() {
059: minOccurs = 1;
060: maxOccurs = 1;
061: }
062:
063: /* (non-Javadoc)
064: * @see com.bostechcorp.cbesb.legacydata.mdl.ContentNode#getMinOccurs()
065: */
066: public int getMinOccurs() {
067: return minOccurs;
068: }
069:
070: /* (non-Javadoc)
071: * @see com.bostechcorp.cbesb.legacydata.mdl.ContentNode#setMinOccurs(int)
072: */
073: public void setMinOccurs(int minOccurs) {
074: this .minOccurs = minOccurs;
075: }
076:
077: /* (non-Javadoc)
078: * @see com.bostechcorp.cbesb.legacydata.mdl.ContentNode#getMaxOccurs()
079: */
080: public int getMaxOccurs() {
081: return maxOccurs;
082: }
083:
084: /* (non-Javadoc)
085: * @see com.bostechcorp.cbesb.legacydata.mdl.ContentNode#setMaxOccurs(int)
086: */
087: public void setMaxOccurs(int maxOccurs) {
088: this .maxOccurs = maxOccurs;
089: }
090:
091: public abstract void serializeToJDom(
092: MDLSerializerUtil serializerUtil, Element mdlParent);
093:
094: protected void populateJDomAttributes(
095: MDLSerializerUtil serializerUtil, Element elem) {
096:
097: if (minOccurs != 1) {
098: Attribute attrMinOccurs = serializerUtil.createAttribute(
099: MDLDocConstants.MDL_CONTENT_MINOCCURS, Integer
100: .toString(minOccurs));
101: elem.setAttribute(attrMinOccurs);
102: }
103: if (maxOccurs != 1) {
104: String maxOccurVal;
105: if (maxOccurs == -1) {
106: maxOccurVal = MDLDocConstants.MDL_CONTENT_UNBOUNDED;
107: } else {
108: maxOccurVal = Integer.toString(maxOccurs);
109: }
110: Attribute attrMaxOccurs = serializerUtil.createAttribute(
111: MDLDocConstants.MDL_CONTENT_MAXOCCURS, maxOccurVal);
112: elem.setAttribute(attrMaxOccurs);
113: }
114: }
115: }
|