001: package org.geotools.feature.iso.type;
002:
003: import java.util.ArrayList;
004: import java.util.Collection;
005: import java.util.Collections;
006: import java.util.Iterator;
007: import java.util.Set;
008:
009: import org.geotools.resources.Utilities;
010: import org.opengis.feature.type.AssociationDescriptor;
011: import org.opengis.feature.type.AttributeDescriptor;
012: import org.opengis.feature.type.AttributeType;
013: import org.opengis.feature.type.ComplexType;
014: import org.opengis.feature.type.StructuralDescriptor;
015: import org.opengis.feature.type.Name;
016: import org.opengis.util.InternationalString;
017:
018: /**
019: * Base class for complex types.
020: *
021: * @author gabriel
022: */
023: public class ComplexTypeImpl extends AttributeTypeImpl implements
024: ComplexType {
025:
026: protected Collection/*<StructuralDescriptor>*/PROPERTIES = null;
027:
028: protected Collection/*<AttributeDescriptor>*/SCHEMA = null;
029:
030: protected Collection/*<AssociationDescriptor>*/ASSOCIATIONS = null;
031:
032: public ComplexTypeImpl(Name name, Collection schema,
033: boolean identified, boolean isAbstract,
034: Set/*<Filter>*/restrictions, AttributeType super Type,
035: InternationalString description) {
036:
037: super (name, Collection.class, identified, isAbstract,
038: restrictions, super Type, description);
039:
040: PROPERTIES = schema;
041:
042: SCHEMA = null;
043: ASSOCIATIONS = null;
044:
045: if (schema != null) {
046: //split out attributes and associatoins
047: try {
048: SCHEMA = (Collection) PROPERTIES.getClass()
049: .newInstance();
050: ASSOCIATIONS = (Collection) PROPERTIES.getClass()
051: .newInstance();
052: } catch (Exception e) {
053: //default to list
054: SCHEMA = new ArrayList();
055: ASSOCIATIONS = new ArrayList();
056: }
057:
058: for (Iterator itr = PROPERTIES.iterator(); itr.hasNext();) {
059: StructuralDescriptor sd = (StructuralDescriptor) itr
060: .next();
061: if (sd instanceof AttributeDescriptor) {
062: SCHEMA.add(sd);
063: } else if (sd instanceof AssociationDescriptor) {
064: ASSOCIATIONS.add(sd);
065: }
066: }
067: } else {
068: PROPERTIES = Collections.EMPTY_LIST;
069: SCHEMA = Collections.EMPTY_LIST;
070: ASSOCIATIONS = Collections.EMPTY_LIST;
071: }
072: }
073:
074: public AttributeType getSuper() {
075: return SUPER;
076: }
077:
078: public Collection getProperties() {
079: return PROPERTIES;
080: }
081:
082: public Collection attributes() {
083: return SCHEMA;
084: }
085:
086: public Collection associations() {
087: return ASSOCIATIONS;
088: }
089:
090: //package visibility
091: void setAttributes(Collection SCHEMA) {
092: this .SCHEMA = SCHEMA;
093: }
094:
095: //JD: not sure about this, ask JG
096: public boolean isInline() {
097: return false;
098: }
099:
100: public boolean equals(Object o) {
101: if (!(o instanceof ComplexType)) {
102: return false;
103: }
104: if (!super .equals(o)) {
105: return false;
106: }
107: if (o instanceof ComplexTypeImpl) {
108: Collection otherSchema = ((ComplexTypeImpl) o).SCHEMA;
109: if (!SCHEMA.equals(otherSchema)) {
110: return false;
111: }
112: }
113:
114: return true;
115: }
116:
117: public Collection getStructuralProperties() {
118: //TODO: associations
119: return attributes();
120: }
121:
122: public int hashCode() {
123: return super .hashCode() * SCHEMA.hashCode();
124: }
125:
126: public String toString() {
127: StringBuffer sb = new StringBuffer(Utilities
128: .getShortClassName(this ));
129: sb.append("[name=").append(getName()).append(", binding=")
130: .append(BINDING).append(", abstrsct= ").append(
131: isAbstract()).append(", identified=").append(
132: IDENTIFIED).append(", restrictions=").append(
133: getRestrictions()).append(", superType=")
134: .append(SUPER).append(", schema=").append(SCHEMA)
135: .append("]");
136:
137: return sb.toString();
138: }
139: }
|