1 /* Copyright 2004 The Apache Software Foundation 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 package org.apache.xmlbeans.impl.inst2xsd.util; 16 17 import javax.xml.namespace.QName; 18 19 /** 20 * @author Cezar Andrei (cezar.andrei at bea.com) Date: Jul 16, 2004 21 */ 22 public class Element 23 { 24 private QName _name = null; // if isRef is true is the name of the referenced name 25 private Element _ref = null; 26 private boolean _isGlobal = false; 27 private int _minOccurs = 1; 28 private int _maxOccurs = 1; 29 public static final int UNBOUNDED = -1; 30 private boolean _isNillable = false; 31 private Type _type = null; 32 private String _comment = null; 33 34 public QName getName() 35 { 36 return _name; 37 } 38 39 public void setName(QName name) 40 { 41 _name = name; 42 } 43 44 public boolean isRef() 45 { 46 return _ref!=null; 47 } 48 49 public Element getRef() 50 { 51 return _ref; 52 } 53 54 public void setRef(Element ref) 55 { 56 assert _isGlobal==false; 57 _ref = ref; 58 _type = null; 59 } 60 61 public boolean isGlobal() 62 { 63 return _isGlobal; 64 } 65 66 public void setGlobal(boolean isGlobal) 67 { 68 _isGlobal = isGlobal; 69 _minOccurs = 1; 70 _maxOccurs = 1; 71 } 72 73 public int getMinOccurs() 74 { 75 return _minOccurs; 76 } 77 78 public void setMinOccurs(int minOccurs) 79 { 80 _minOccurs = minOccurs; 81 } 82 83 public int getMaxOccurs() 84 { 85 return _maxOccurs; 86 } 87 88 public void setMaxOccurs(int maxOccurs) 89 { 90 _maxOccurs = maxOccurs; 91 } 92 93 public boolean isNillable() 94 { 95 return _isNillable; 96 } 97 98 public void setNillable(boolean isNillable) 99 { 100 _isNillable = isNillable; 101 } 102 103 public Type getType() 104 { 105 return isRef() ? getRef().getType() : _type; 106 } 107 108 public void setType(Type type) 109 { 110 assert !isRef(); 111 _type = type; 112 } 113 114 public String getComment() 115 { 116 return _comment; 117 } 118 119 public void setComment(String comment) 120 { 121 _comment = comment; 122 } 123 124 public String toString() 125 { 126 return "\n Element{" + 127 " _name = " + _name + 128 ", _ref = " + (_ref!=null) + 129 ", _isGlobal = " + _isGlobal + 130 ", _minOccurs = " + _minOccurs + 131 ", _maxOccurs = " + _maxOccurs + 132 ", _isNillable = " + _isNillable + 133 ", _comment = " + _comment + 134 ",\n _type = " + ( _type==null ? "null" : 135 (_type.isGlobal() ? _type.getName().toString() : _type.toString())) + 136 "\n }"; 137 } 138 }