1 19 package org.openharmonise.rm.resources.metadata.properties.ranges; 20 21 import java.util.*; 22 23 import org.openharmonise.commons.dsi.AbstractDataStoreInterface; 24 import org.openharmonise.rm.*; 25 import org.openharmonise.rm.factory.*; 26 import org.openharmonise.rm.metadata.*; 27 import org.openharmonise.rm.publishing.*; 28 import org.openharmonise.rm.resources.AbstractParentObject; 29 import org.openharmonise.rm.resources.metadata.properties.PropertyGroup; 30 import org.w3c.dom.Element ; 31 32 33 41 public class ProfileRange extends AbstractRange implements Range, Publishable { 42 43 46 public final static String TAG_PROFILE_RANGE = "ProfileRange"; 47 48 51 public final static String TAG_PATH_RESTRICTION = "PathRestriction"; 52 53 57 static final private String SEPARATOR = "|"; 58 59 64 private List m_property_restrictions = null; 65 66 70 public ProfileRange() { 71 super(Profile.class.getName(), null); 72 } 73 74 84 public ProfileRange(String sObjClassName, String sDetails) { 85 super(sObjClassName, sDetails); 86 } 87 88 91 public boolean isValid(Object obj) { 92 return (obj instanceof Profile); 93 } 94 95 98 public boolean equals(Object obj) { 99 boolean bResult = false; 100 101 if (obj instanceof ProfileRange) { 102 bResult = super.equals(obj); 103 } 104 105 return bResult; 106 } 107 108 114 public List getAllowedPropertyParents() { 115 return new ArrayList(m_property_restrictions); 116 } 117 118 124 public void setAllowedPropertyParents(List allowedParents) { 125 if ((m_property_restrictions == null && allowedParents != null) 126 || m_property_restrictions.equals(allowedParents) == false) { 127 m_property_restrictions = new ArrayList(allowedParents); 128 isChanged(true); 129 } 130 131 } 132 133 140 public void addAllowedPropertyParent(String sPath) { 141 if(m_property_restrictions == null) { 142 m_property_restrictions = new ArrayList(); 143 } 144 145 if(m_property_restrictions.contains(sPath) == false) { 146 m_property_restrictions.add(sPath); 147 isChanged(true); 148 } 149 } 150 151 154 public String getDetails() { 155 if (isChanged()) { 156 StringBuffer strbuf = new StringBuffer (); 157 if (m_property_restrictions != null) { 158 Iterator iter = m_property_restrictions.iterator(); 159 160 while (iter.hasNext()) { 161 String sPath = (String ) iter.next(); 162 strbuf.append(sPath); 163 164 if (iter.hasNext()) { 165 strbuf.append(SEPARATOR); 166 } 167 } 168 169 } 170 super.setDetails(strbuf.toString()); 171 } 172 173 return super.getDetails(); 174 } 175 176 179 public void setDetails(String sDetails) { 180 if (m_property_restrictions == null) { 181 m_property_restrictions = new ArrayList(); 182 } 183 184 if (sDetails != null) { 185 StringTokenizer tokenizer = 186 new StringTokenizer(sDetails, SEPARATOR); 187 188 int i = 0; 189 int nTmp = 0; 190 while (tokenizer.hasMoreTokens()) { 191 String token = tokenizer.nextToken(); 192 193 if (token != null && token.length() > 0) { 194 m_property_restrictions.add(token); 195 } 196 } 197 } 198 super.setDetails(sDetails); 199 } 200 201 212 public List getAllowedProperties(AbstractDataStoreInterface dsi) 213 throws DataAccessException { 214 List props = new Vector(); 215 216 List propGroupPaths = this.getAllowedPropertyParents(); 217 218 Iterator iter = propGroupPaths.iterator(); 219 220 while (iter.hasNext()) { 221 String sPath = (String ) iter.next(); 222 223 try { 224 PropertyGroup propGroup = 225 (PropertyGroup) HarmoniseObjectFactory.instantiateHarmoniseObject( 226 dsi, 227 PropertyGroup.class.getName(), 228 sPath); 229 230 if(propGroup != null) { 231 props.addAll( 232 propGroup.getChildrenByType( 233 AbstractParentObject.LEAF_NODES)); 234 } else { 235 handleInvalidParentRestriction(sPath); 236 } 237 238 } catch (HarmoniseFactoryException e) { 239 throw new DataAccessException(e.getLocalizedMessage(),e); 240 } 241 242 } 243 244 return props; 245 } 246 247 252 private void handleInvalidParentRestriction(String path) { 253 if(m_property_restrictions != null && path != null) { 254 m_property_restrictions.remove(path); 255 } 256 } 257 258 261 public Class getPropertyInstanceClass() throws ClassNotFoundException { 262 return ProfilePropertyInstance.class; 263 } 264 265 268 public String getTagName() { 269 return TAG_PROFILE_RANGE; 270 } 271 272 275 public void populate(Element xmlElement, State state) 276 throws PopulateException { 277 String sTagname = xmlElement.getTagName(); 278 279 if(sTagname.equals(TAG_PATH_RESTRICTION)) { 280 String sPath = xmlElement.getFirstChild().getNodeValue(); 281 addAllowedPropertyParent(sPath.trim()); 282 } else { 283 super.populate(xmlElement, state); 284 } 285 286 } 287 288 } 289 | Popular Tags |