001 // Copyright 2004, 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.hivemind.schema.impl; 016 017 import java.util.ArrayList; 018 import java.util.Collections; 019 import java.util.Iterator; 020 import java.util.List; 021 022 import org.apache.hivemind.schema.AttributeModel; 023 import org.apache.hivemind.schema.ElementModel; 024 import org.apache.hivemind.schema.Rule; 025 026 /** 027 * Implementation of {@link org.apache.hivemind.schema.ElementModel}. 028 * 029 * @author Howard Lewis Ship 030 */ 031 public class ElementModelImpl extends SchemaImpl implements ElementModel 032 { 033 private String _elementName; 034 035 private List _attributeModels; 036 037 private List _shareableAttributeModels; 038 039 private String _keyAttribute; 040 041 private List _rules; 042 043 private List _shareableRules; 044 045 private String _contentTranslator; 046 047 public String getElementName() 048 { 049 return _elementName; 050 } 051 052 public void setElementName(String string) 053 { 054 _elementName = string; 055 } 056 057 public void addAttributeModel(AttributeModel attributeModel) 058 { 059 if (_attributeModels == null) 060 _attributeModels = new ArrayList(); 061 062 _attributeModels.add(attributeModel); 063 _shareableAttributeModels = null; 064 } 065 066 public List getAttributeModels() 067 { 068 if (_shareableAttributeModels == null) 069 _shareableAttributeModels = _attributeModels == null ? Collections.EMPTY_LIST 070 : Collections.unmodifiableList(_attributeModels); 071 072 return _shareableAttributeModels; 073 } 074 075 public AttributeModel getAttributeModel(String name) 076 { 077 if (_attributeModels == null) 078 return null; 079 080 for (Iterator i = _attributeModels.iterator(); i.hasNext();) 081 { 082 AttributeModel am = (AttributeModel) i.next(); 083 084 if (am.getName().equals(name)) 085 return am; 086 } 087 088 return null; 089 } 090 091 public void setKeyAttribute(String keyAttribute) 092 { 093 _keyAttribute = keyAttribute; 094 } 095 096 public String getKeyAttribute() 097 { 098 return _keyAttribute; 099 } 100 101 public void addRule(Rule rule) 102 { 103 if (_rules == null) 104 _rules = new ArrayList(); 105 106 _rules.add(rule); 107 _shareableRules = null; 108 } 109 110 public List getRules() 111 { 112 if (_shareableRules == null) 113 _shareableRules = _rules == null ? Collections.EMPTY_LIST : Collections 114 .unmodifiableList(_rules); 115 116 return _shareableRules; 117 } 118 119 public String getContentTranslator() 120 { 121 return _contentTranslator; 122 } 123 124 public void setContentTranslator(String string) 125 { 126 _contentTranslator = string; 127 } 128 129 }