1 64 65 package com.jcorporate.expresso.core.dataobjects; 66 67 74 75 public final class DataObjectFactory { 76 77 private DataObjectFactory() { 78 } 79 80 89 public static Object createObject(Class clazz, 90 String dataContext, int uid) 91 throws DataException { 92 return DataObjectFactory.createObject(clazz, dataContext, null, uid); 93 94 } 95 96 105 public static DataObject createDataObject(Class clazz, 106 String dataContext, int uid) 107 throws DataException { 108 return (DataObject) DataObjectFactory.createObject(clazz, dataContext, null, uid); 109 } 110 111 112 123 public static DataObject createDataObject(Class clazz, String dataContext, 124 String definition, int uid) 125 throws DataException { 126 return (DataObject) DataObjectFactory.createObject(clazz, dataContext, definition, uid); 127 } 128 129 140 public static Object createObject(Class clazz, String dataContext, 141 String definition, int uid) 142 throws DataException { 143 Object returnValue; 144 try { 145 returnValue = clazz.newInstance(); 146 } catch (IllegalAccessException ex) { 147 throw new DataException("No default constructor for: " 148 + clazz.getName(), ex); 149 } catch (InstantiationException ex) { 150 throw new DataException("Error creating new instance of " 151 + clazz.getName(), ex); 152 } 153 154 if (returnValue instanceof Defineable) { 155 if (definition == null) { 156 throw new IllegalArgumentException ("Must have non-null " + 157 "definition for Defineable objects!"); 158 } 159 160 ((Defineable) returnValue).setDefinitionName(definition); 161 } 162 163 if (returnValue instanceof ContextNested) { 164 ((ContextNested) returnValue).setDataContext(dataContext); 165 } 166 167 168 if (returnValue instanceof Securable) { 169 ((Securable) returnValue).setRequestingUid(uid); 170 } 171 172 return returnValue; 173 } 174 } | Popular Tags |