1 19 package org.openharmonise.rm.metadata; 20 21 import org.openharmonise.commons.dsi.AbstractDataStoreInterface; 22 import org.openharmonise.commons.xml.XMLUtils; 23 import org.openharmonise.rm.*; 24 import org.openharmonise.rm.factory.*; 25 import org.openharmonise.rm.resources.AbstractObject; 26 import org.openharmonise.rm.resources.metadata.properties.Property; 27 import org.openharmonise.rm.resources.metadata.properties.ranges.Range; 28 import org.w3c.dom.Element ; 29 30 38 public class PropertyInstanceFactory { 39 40 45 private PropertyInstanceFactory() { 46 super(); 47 } 48 49 66 public static AbstractPropertyInstance getPropertyInstance( 67 AbstractDataStoreInterface dsi, Element el, Profile prof) 68 throws DataAccessException, HarmoniseFactoryException, ProfileException { 69 AbstractPropertyInstance propInst = getPropertyInstance(dsi, el); 70 if (prof != null) { 71 AbstractPropertyInstance tmpPropInst = prof 72 .getPropertyInstance(propInst.getProperty()); 73 74 if (tmpPropInst != null) { 75 try { 76 tmpPropInst.populate(el, null); 77 } catch (PopulateException e) { 78 throw new DataAccessException(e); 79 } 80 propInst = tmpPropInst; 81 } else { 82 prof.addPropertyInstance(propInst); 83 } 84 85 } 86 87 return propInst; 88 } 89 90 102 public static AbstractPropertyInstance getPropertyInstance( 103 AbstractDataStoreInterface dsi, Element el) 104 throws DataAccessException, HarmoniseFactoryException { 105 Element propertyElm = XMLUtils.getFirstNamedChild(el, 106 Property.TAG_PROPERTY); 107 String sPropertyId = el.getAttribute(AbstractObject.ATTRIB_ID); 109 110 Property prop = null; 111 112 prop = (Property) HarmoniseObjectFactory.instantiatePublishableObject(dsi, 113 propertyElm, null); 114 115 if (prop == null) { 116 throw new HarmoniseFactoryException("Could not find property requested"); 117 } 118 119 return getPropertyInstance(dsi, prop); 120 } 121 122 136 public static AbstractPropertyInstance getPropertyInstance( 137 AbstractDataStoreInterface dsi, Property prop) 138 throws DataAccessException { 139 AbstractPropertyInstance propInst = null; 140 141 Range range = prop.getRange(); 142 143 try { 144 if(range != null) { 145 propInst = (AbstractPropertyInstance) range 146 .getPropertyInstanceClass().newInstance(); 147 propInst.setDataStoreInterface(dsi); 148 propInst.setProperty(prop); 149 } else { 150 throw new DataAccessException("Unable to get Property instance with no range"); 151 } 152 } catch (PopulateException e) { 153 throw new DataAccessException(e.getLocalizedMessage(), e); 154 } catch (InstantiationException e) { 155 throw new DataAccessException(e.getLocalizedMessage(), e); 156 } catch (IllegalAccessException e) { 157 throw new DataAccessException(e.getLocalizedMessage(), e); 158 } catch (ClassNotFoundException e) { 159 throw new DataAccessException(e.getLocalizedMessage(), e); 160 } 161 162 return propInst; 163 } 164 } | Popular Tags |