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: ContentGroupImpl.java 6050 2007-03-18 19:12:43Z mpreston $
024: */
025: package com.bostechcorp.cbesb.common.mdl.impl;
026:
027: import java.util.Iterator;
028: import java.util.Vector;
029:
030: import org.jdom.Attribute;
031: import org.jdom.Element;
032:
033: import com.bostechcorp.cbesb.common.mdl.IContentGroup;
034: import com.bostechcorp.cbesb.common.mdl.IContentNode;
035: import com.bostechcorp.cbesb.common.mdl.MDLDocConstants;
036:
037: /**
038: * Represents a group in the content.
039: *
040: */
041: public class ContentGroupImpl extends ContentNodeImpl implements
042: IContentGroup {
043:
044: /**
045: * Name of group element.
046: */
047: private String name;
048:
049: /**
050: * NamespaceURI of group element.
051: */
052: private String namespaceURI;
053:
054: /**
055: * Child set of group.
056: */
057: private Vector<IContentNode> content;
058:
059: /**
060: * Constructor.
061: */
062: public ContentGroupImpl() {
063: name = "";
064: namespaceURI = "";
065: content = new Vector<IContentNode>();
066: }
067:
068: /* (non-Javadoc)
069: * @see com.bostechcorp.cbesb.legacydata.mdl.ContentGroup#getName()
070: */
071: public String getName() {
072: return name;
073: }
074:
075: /* (non-Javadoc)
076: * @see com.bostechcorp.cbesb.legacydata.mdl.ContentGroup#setName(java.lang.String)
077: */
078: public void setName(String name) {
079: this .name = name;
080: }
081:
082: /* (non-Javadoc)
083: * @see com.bostechcorp.cbesb.legacydata.mdl.ContentGroup#getNamespaceURI()
084: */
085: public String getNamespaceURI() {
086: return namespaceURI;
087: }
088:
089: /* (non-Javadoc)
090: * @see com.bostechcorp.cbesb.legacydata.mdl.ContentGroup#setNamespaceURI(java.lang.String)
091: */
092: public void setNamespaceURI(String namespaceURI) {
093: this .namespaceURI = namespaceURI;
094: }
095:
096: /* (non-Javadoc)
097: * @see com.bostechcorp.cbesb.common.mdl.IContentGroup#getChildCount()
098: */
099: public int getChildCount() {
100: return content.size();
101: }
102:
103: /* (non-Javadoc)
104: * @see com.bostechcorp.cbesb.common.mdl.IContentGroup#getChildAtIndex(int)
105: */
106: public IContentNode getChildAtIndex(int index) {
107: if (index >= 0 && index < content.size()) {
108: return (IContentNode) content.get(index);
109: } else {
110: return null;
111: }
112: }
113:
114: /* (non-Javadoc)
115: * @see com.bostechcorp.cbesb.common.mdl.IContentGroup#getChildren()
116: */
117: public IContentNode[] getChildren() {
118: IContentNode[] contentNodes = new IContentNode[content.size()];
119:
120: Iterator iterator = content.iterator();
121: int index = 0;
122: while (iterator.hasNext()) {
123: contentNodes[index] = (IContentNode) iterator.next();
124: index++;
125: }
126: return contentNodes;
127: }
128:
129: /* (non-Javadoc)
130: * @see com.bostechcorp.cbesb.common.mdl.IContentGroup#appendChild(com.bostechcorp.cbesb.common.mdl.IContentNode)
131: */
132: public void appendChild(IContentNode child) {
133: content.add(child);
134: }
135:
136: /* (non-Javadoc)
137: * @see com.bostechcorp.cbesb.common.mdl.IContentGroup#insertChildAtIndex(com.bostechcorp.cbesb.common.mdl.IContentNode, int)
138: */
139: public void insertChildAtIndex(IContentNode child, int index) {
140: content.insertElementAt(child, index);
141: }
142:
143: /* (non-Javadoc)
144: * @see com.bostechcorp.cbesb.common.mdl.IContentGroup#removeChildAtIndex(int)
145: */
146: public void removeChildAtIndex(int index) {
147: content.remove(index);
148: }
149:
150: public void serializeToJDom(MDLSerializerUtil serializerUtil,
151: Element mdlParent) {
152: Element elemGroup = serializerUtil
153: .createElement(MDLDocConstants.MDL_GROUP);
154: mdlParent.addContent(elemGroup);
155:
156: Attribute attrName = serializerUtil.createAttribute(
157: MDLDocConstants.MDL_NAME, name);
158: elemGroup.setAttribute(attrName);
159:
160: populateJDomAttributes(serializerUtil, elemGroup);
161:
162: for (int i = 0; i < getChildCount(); i++) {
163: ContentNodeImpl child = (ContentNodeImpl) getChildAtIndex(i);
164: child.serializeToJDom(serializerUtil, elemGroup);
165: }
166: }
167: }
|