KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > xml > types > CmsXmlNestedContentDefinition


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/xml/types/CmsXmlNestedContentDefinition.java,v $
3  * Date : $Date: 2006/03/27 14:53:03 $
4  * Version: $Revision: 1.16 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.xml.types;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.main.CmsRuntimeException;
36 import org.opencms.xml.CmsXmlContentDefinition;
37 import org.opencms.xml.I_CmsXmlDocument;
38
39 import java.util.Locale JavaDoc;
40
41 import org.dom4j.Element;
42
43 /**
44  * A nested content XML definition that is included by another XML content definition.<p>
45  *
46  * @author Alexander Kandzior
47  *
48  * @version $Revision: 1.16 $
49  *
50  * @since 6.0.0
51  */

52 public class CmsXmlNestedContentDefinition extends A_CmsXmlContentValue implements I_CmsXmlSchemaType {
53
54     /** The nested content definition. */
55     private CmsXmlContentDefinition m_nestedContentDefinition;
56
57     /**
58      * Creates a new XML content value for the nested content definition.<p>
59      *
60      * @param document the XML content instance this value belongs to
61      * @param contentDefinition the nested XML content definition
62      * @param element the XML element that contains this value
63      * @param locale the locale this value is created for
64      * @param type the type instance to create the value for
65      */

66     public CmsXmlNestedContentDefinition(
67         CmsXmlContentDefinition contentDefinition,
68         I_CmsXmlDocument document,
69         Element element,
70         Locale JavaDoc locale,
71         I_CmsXmlSchemaType type) {
72
73         super(document, element, locale, type);
74         m_nestedContentDefinition = contentDefinition;
75     }
76
77     /**
78      * Creates a new nested content definition.<p>
79      *
80      * @param contentDefinition the content definition to nest
81      * @param name the name of the XML node containing the value according to the XML schema
82      * @param minOccurs minimum number of occurences of this type according to the XML schema
83      * @param maxOccurs maximum number of occurences of this type according to the XML schema
84      */

85     public CmsXmlNestedContentDefinition(
86         CmsXmlContentDefinition contentDefinition,
87         String JavaDoc name,
88         String JavaDoc minOccurs,
89         String JavaDoc maxOccurs) {
90
91         super(name, minOccurs, maxOccurs);
92         m_nestedContentDefinition = contentDefinition;
93     }
94
95     /**
96      * @see org.opencms.xml.types.I_CmsXmlSchemaType#createValue(I_CmsXmlDocument, org.dom4j.Element, Locale)
97      */

98     public I_CmsXmlContentValue createValue(I_CmsXmlDocument document, Element element, Locale JavaDoc locale) {
99
100         return new CmsXmlNestedContentDefinition(m_nestedContentDefinition, document, element, locale, this);
101     }
102
103     /**
104      * @see org.opencms.xml.types.I_CmsXmlSchemaType#generateXml(org.opencms.file.CmsObject, org.opencms.xml.I_CmsXmlDocument, org.dom4j.Element, java.util.Locale)
105      */

106     public Element generateXml(CmsObject cms, I_CmsXmlDocument document, Element root, Locale JavaDoc locale) {
107
108         // create the XML base node for the nested content definition
109
Element element = root.addElement(getName());
110         // create a default XML element for the nested content definition
111
element = m_nestedContentDefinition.createDefaultXml(cms, document, element, Locale.ENGLISH);
112         // retrun the generated element
113
return element;
114     }
115
116     /**
117      * Returns the nested content definition.<p>
118      *
119      * @return the nested content definition
120      */

121     public CmsXmlContentDefinition getNestedContentDefinition() {
122
123         return m_nestedContentDefinition;
124     }
125
126     /**
127      * @see org.opencms.xml.types.I_CmsXmlSchemaType#getSchemaDefinition()
128      */

129     public String JavaDoc getSchemaDefinition() {
130
131         throw new CmsRuntimeException(Messages.get().container(Messages.ERR_NESTED_SCHEMA_0));
132     }
133
134     /**
135      * @see org.opencms.xml.types.I_CmsXmlContentValue#getStringValue(org.opencms.file.CmsObject)
136      */

137     public String JavaDoc getStringValue(CmsObject cms) throws CmsRuntimeException {
138
139         throw new CmsRuntimeException(Messages.get().container(Messages.ERR_NESTED_GETVALUE_0));
140     }
141
142     /**
143      * @see org.opencms.xml.types.I_CmsXmlSchemaType#getTypeName()
144      */

145     public String JavaDoc getTypeName() {
146
147         return m_nestedContentDefinition.getTypeName();
148     }
149
150     /**
151      * Returns <code>false</code>, since nested content definitions are never simple.<p>
152      *
153      * @see org.opencms.xml.types.I_CmsXmlSchemaType#isSimpleType()
154      */

155     public boolean isSimpleType() {
156
157         return false;
158     }
159
160     /**
161      * @see org.opencms.xml.types.I_CmsXmlSchemaType#newInstance(java.lang.String, java.lang.String, java.lang.String)
162      */

163     public I_CmsXmlSchemaType newInstance(String JavaDoc name, String JavaDoc minOccurs, String JavaDoc maxOccurs) {
164
165         throw new CmsRuntimeException(Messages.get().container(Messages.ERR_NESTED_NEWINSTANCE_0));
166     }
167
168     /**
169      * @see org.opencms.xml.types.I_CmsXmlContentValue#setStringValue(org.opencms.file.CmsObject, java.lang.String)
170      */

171     public void setStringValue(CmsObject cms, String JavaDoc value) {
172
173         throw new CmsRuntimeException(Messages.get().container(Messages.ERR_NESTED_SETVALUE_0));
174     }
175 }
Popular Tags