1 /** 2 * Redistribution and use of this software and associated documentation ("Software"), with or 3 * without modification, are permitted provided that the following conditions are met: 4 * 5 * 1. Redistributions of source code must retain copyright statements and notices. Redistributions 6 * must also contain a copy of this document. 7 * 8 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of 9 * conditions and the following disclaimer in the documentation and/or other materials provided with 10 * the distribution. 11 * 12 * 3. The name "Exolab" must not be used to endorse or promote products derived from this Software 13 * without prior written permission of Intalio, Inc. For written permission, please contact 14 * info@exolab.org. 15 * 16 * 4. Products derived from this Software may not be called "Exolab" nor may "Exolab" appear in 17 * their names without prior written permission of Intalio, Inc. Exolab is a registered trademark of 18 * Intalio, Inc. 19 * 20 * 5. Due credit should be given to the Exolab Project (http://www.exolab.org/). 21 * 22 * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 24 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTALIO, INC. OR ITS 25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 29 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 31 * Copyright 1999-2003 (C) Intalio, Inc. All Rights Reserved. 32 * 33 * $Id$ 34 */ 35 36 package org.exolab.castor.xml.schema; 37 38 /** 39 * An extension of the ContentType to support simple content extension and restriction for 40 * complexTypes. 41 * 42 * 43 * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a> 44 * @version $Revision$ $Date: 2005-12-13 14:58:48 -0700 (Tue, 13 Dec 2005) $ 45 */ 46 public class SimpleContent extends ContentType implements java.io.Serializable { 47 /** SerialVersionUID */ 48 private static final long serialVersionUID = 6406889524623062413L; 49 50 /** 51 * The associated parent Schema 52 */ 53 private Schema _schema = null; 54 55 /** 56 * The simpleType definition that defines this content type (if any) 57 */ 58 private SimpleType _simpleType; 59 60 /** 61 * The name of the simpleType, used when the simpleType has not yet been read or added to the 62 * parent Schema 63 */ 64 private String _typeName = null; 65 66 /** 67 * Creates a new SimpleContent 68 */ 69 public SimpleContent() { 70 super(ContentType.SIMPLE); 71 } // -- ContentType 72 73 /** 74 * Creates a new SimpleContent using the given SimpleContent. This constructor will copy from the 75 * given SimpleContent. 76 * 77 * 78 * @param content the SimpleContent to copy from 79 */ 80 public SimpleContent(SimpleContent content) { 81 super(ContentType.SIMPLE); 82 if (content != null) { 83 _simpleType = content._simpleType; 84 _typeName = content._typeName; 85 _schema = content._schema; 86 } 87 } // -- ContentType 88 89 /** 90 * Creates a new SimpleContent 91 * 92 * @param simpleType the simpleType of this SimpleContent 93 */ 94 public SimpleContent(SimpleType simpleType) { 95 super(ContentType.SIMPLE); 96 _simpleType = simpleType; 97 } // -- SimpleContent 98 99 /** 100 * Creates a new SimpleContent 101 * 102 * @param schema the associated parent Schema 103 * @param typeName the name of the base simpleType, or complexType (must also be a SimpleContent). 104 * 105 */ 106 public SimpleContent(Schema schema, String typeName) { 107 super(ContentType.SIMPLE); 108 if (schema == null) { 109 String err = "The argument 'schema' must not be null."; 110 throw new IllegalArgumentException(err); 111 } 112 if (typeName == null) { 113 String err = "The argument 'typeName' must not be null."; 114 throw new IllegalArgumentException(err); 115 } 116 _schema = schema; 117 _typeName = typeName; 118 } // -- SimpleContent 119 120 /** 121 * Creates a copy of this SimpleContent 122 * 123 * @return the new SimpleContent which is a copy of this SimpleContent 124 */ 125 public SimpleContent copy() { 126 return new SimpleContent(this); 127 } // -- copy 128 129 /** 130 * Returns the simpleType that represents that contentType. This may be null, if no simpleType has 131 * been set. 132 * 133 * @return the simpleType that represents that contentType. 134 */ 135 public SimpleType getSimpleType() { 136 if ((_simpleType == null) && (_typeName != null)) { 137 XMLType base = _schema.getType(_typeName); 138 if (base != null) { 139 if (base.isSimpleType()) { 140 _simpleType = (SimpleType) base; 141 } else { 142 ComplexType complexType = (ComplexType) base; 143 if (complexType.isSimpleContent()) { 144 SimpleContent sc = (SimpleContent) complexType.getContentType(); 145 _simpleType = sc.getSimpleType(); 146 } else { 147 // -- Report error 148 String error = "The base ComplexType '" + _typeName + "' "; 149 error += "must be a simpleContent."; 150 throw new IllegalStateException(error); 151 } 152 } 153 } 154 } 155 return _simpleType; 156 } // -- getSimpleType 157 158 /** 159 * Returns the name of the associated type for this SimpleContent 160 * 161 * @return the associated type name for this SimpleContent. 162 */ 163 public String getTypeName() { 164 if (_simpleType != null) { 165 return _simpleType.getName(); 166 } 167 return _typeName; 168 } // -- getTypeName 169 170 171 /** 172 * Sets the simpleType that represents that contentType. 173 * 174 * @param simpleType the simpleType to set 175 */ 176 public void setSimpleType(SimpleType simpleType) { 177 _simpleType = simpleType; 178 } // -- setSimpleType 179 180 181 } // -- SimpleContent