svn commit: r585844 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util: EntityCrypto.java EntityDataAssert.java EntityDataLoader.java EntitySaxReader.java EntityTypeUtil.java SequenceUtil.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r585844 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util: EntityCrypto.java EntityDataAssert.java EntityDataLoader.java EntitySaxReader.java EntityTypeUtil.java SequenceUtil.java

doogie-3
Author: doogie
Date: Wed Oct 17 20:54:48 2007
New Revision: 585844

URL: http://svn.apache.org/viewvc?rev=585844&view=rev
Log:
Java 1.5 markup for entity util.

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityCrypto.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataLoader.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntitySaxReader.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityTypeUtil.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/SequenceUtil.java

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityCrypto.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityCrypto.java?rev=585844&r1=585843&r2=585844&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityCrypto.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityCrypto.java Wed Oct 17 20:54:48 2007
@@ -45,12 +45,12 @@
     public static final String module = EntityCrypto.class.getName();
 
     protected GenericDelegator delegator = null;
-    protected Map keyMap = null;
+    protected Map<String, SecretKey> keyMap = null;
 
     protected EntityCrypto() { }
     public EntityCrypto(GenericDelegator delegator) {
         this.delegator = delegator;
-        this.keyMap = new HashMap();
+        this.keyMap = new HashMap<String, SecretKey>();
 
         // check the key table and make sure there
         // make sure there are some dummy keys
@@ -88,7 +88,7 @@
     }
 
     protected SecretKey getKey(String name) throws EntityCryptoException {
-        SecretKey key = (SecretKey) keyMap.get(name);
+        SecretKey key = keyMap.get(name);
         if (key == null) {
             synchronized(this) {
                 String keyName = HashCrypt.getDigestHash(name);
@@ -102,7 +102,7 @@
     protected SecretKey getKeyFromStore(String keyName) throws EntityCryptoException {
         GenericValue keyValue = null;
         try {
-            keyValue = delegator.findByPrimaryKey("EntityKeyStore", UtilMisc.toMap("keyName", keyName));
+            keyValue = delegator.findByPrimaryKey("EntityKeyStore", "keyName", keyName);
         } catch (GenericEntityException e) {
             throw new EntityCryptoException(e);
         }

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java?rev=585844&r1=585843&r2=585844&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java Wed Oct 17 20:54:48 2007
@@ -40,7 +40,7 @@
 
     public static final String module = EntityDataAssert.class.getName();
 
-    public static int assertData(URL dataUrl, GenericDelegator delegator, List errorMessages) throws GenericEntityException, SAXException, ParserConfigurationException, IOException {
+    public static int assertData(URL dataUrl, GenericDelegator delegator, List<Object> errorMessages) throws GenericEntityException, SAXException, ParserConfigurationException, IOException {
         int rowsChecked = 0;
 
         if (dataUrl == null) {
@@ -71,7 +71,7 @@
         return rowsChecked;
     }
     
-    public static void checkValueList(List valueList, GenericDelegator delegator, List errorMessages) throws GenericEntityException {
+    public static void checkValueList(List valueList, GenericDelegator delegator, List<Object> errorMessages) throws GenericEntityException {
         if (valueList == null) return;
         
         Iterator valueIter = valueList.iterator();
@@ -81,7 +81,7 @@
         }
     }
     
-    public static void checkSingleValue(GenericValue checkValue, GenericDelegator delegator, List errorMessages) throws GenericEntityException {
+    public static void checkSingleValue(GenericValue checkValue, GenericDelegator delegator, List<Object> errorMessages) throws GenericEntityException {
         if (checkValue == null) {
             errorMessages.add("Got a value to check was null");
             return;
@@ -98,10 +98,7 @@
             }
 
             ModelEntity modelEntity = checkValue.getModelEntity();
-            List nonpkFieldNameList = modelEntity.getNoPkFieldNames();
-            Iterator nonpkFieldNameIter = nonpkFieldNameList.iterator();
-            while (nonpkFieldNameIter.hasNext()) {
-                String nonpkFieldName = (String) nonpkFieldNameIter.next();
+            for (String nonpkFieldName: modelEntity.getNoPkFieldNames()) {
                 // skip the fields the entity engine maintains
                 if (ModelEntity.CREATE_STAMP_FIELD.equals(nonpkFieldName) || ModelEntity.CREATE_STAMP_TX_FIELD.equals(nonpkFieldName) ||
                         ModelEntity.STAMP_FIELD.equals(nonpkFieldName) || ModelEntity.STAMP_TX_FIELD.equals(nonpkFieldName)) {

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataLoader.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataLoader.java?rev=585844&r1=585843&r2=585844&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataLoader.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataLoader.java Wed Oct 17 20:54:48 2007
@@ -37,6 +37,7 @@
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.entity.GenericDelegator;
 import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.config.DatasourceInfo;
 import org.ofbiz.entity.config.EntityConfigUtil;
 import org.ofbiz.entity.config.EntityDataReaderInfo;
@@ -56,10 +57,7 @@
         StringBuilder pathBuffer = new StringBuilder();
         if (helperName != null && helperName.length() > 0) {
             DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName);
-            List sqlLoadPathElements = datasourceInfo.sqlLoadPaths;
-            Iterator slpIter = sqlLoadPathElements.iterator();
-            while (slpIter.hasNext()) {
-                Element sqlLoadPathElement = (Element) slpIter.next();
+            for (Element sqlLoadPathElement: datasourceInfo.sqlLoadPaths) {
                 String prependEnv = sqlLoadPathElement.getAttribute("prepend-env");
                 pathBuffer.append(pathBuffer.length() == 0 ? "" : ";");
                 if (prependEnv != null && prependEnv.length() > 0) {
@@ -72,29 +70,27 @@
         return pathBuffer.toString();
     }
 
-    public static List getUrlList(String helperName) {
+    public static List<URL> getUrlList(String helperName) {
         DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName);
         return getUrlList(helperName, null, datasourceInfo.readDatas);
     }
 
-    public static List getUrlList(String helperName, String componentName) {
+    public static List<URL> getUrlList(String helperName, String componentName) {
         DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName);
         return getUrlList(helperName, componentName, datasourceInfo.readDatas);
     }
 
-    public static List getUrlList(String helperName, List readerNames) {
+    public static List<URL> getUrlList(String helperName, List readerNames) {
         return getUrlList(helperName, null, readerNames);
     }
 
-    public static List getUrlList(String helperName, String componentName, List readerNames) {
+    public static List<URL> getUrlList(String helperName, String componentName, List readerNames) {
         String paths = getPathsString(helperName);
-        List urlList = new LinkedList();
+        List<URL> urlList = new LinkedList<URL>();
         
         // first get files from resources
         if (readerNames != null) {
-            Iterator readDataIter = readerNames.iterator();
-            while (readDataIter.hasNext()) {
-                Object readerInfo = readDataIter.next();
+            for (Object readerInfo: readerNames) {
                 String readerName = null;
                 if (readerInfo instanceof String) {
                     readerName = (String) readerInfo;
@@ -108,10 +104,7 @@
                 EntityDataReaderInfo entityDataReaderInfo = EntityConfigUtil.getEntityDataReaderInfo(readerName);
                 
                 if (entityDataReaderInfo != null) {
-                    List resourceElements = entityDataReaderInfo.resourceElements;
-                    Iterator resIter = resourceElements.iterator();
-                    while (resIter.hasNext()) {
-                        Element resourceElement = (Element) resIter.next();
+                    for (Element resourceElement: entityDataReaderInfo.resourceElements) {
                         ResourceHandler handler = new MainResourceHandler(EntityConfigUtil.ENTITY_ENGINE_XML_FILENAME, resourceElement);
                         try {
                             urlList.add(handler.getURL());
@@ -122,10 +115,7 @@
                     }
         
                     // get all of the component resource model stuff, ie specified in each ofbiz-component.xml file
-                    List componentResourceInfos = ComponentConfig.getAllEntityResourceInfos("data", componentName);
-                    Iterator componentResourceInfoIter = componentResourceInfos.iterator();
-                    while (componentResourceInfoIter.hasNext()) {
-                        ComponentConfig.EntityResourceInfo componentResourceInfo = (ComponentConfig.EntityResourceInfo) componentResourceInfoIter.next();
+                    for (ComponentConfig.EntityResourceInfo componentResourceInfo: ComponentConfig.getAllEntityResourceInfos("data", componentName)) {
                         if (readerName.equals(componentResourceInfo.readerName)) {
                             ResourceHandler handler = componentResourceInfo.createResourceHandler();
                             try {
@@ -154,16 +144,14 @@
                 File loadDir = new File(path);
                 if (loadDir.exists() && loadDir.isDirectory()) {
                     File[] files = loadDir.listFiles();
-                    List tempFileList = new LinkedList();
-                    for (int i = 0; i < files.length; i++) {
-                        if (files[i].getName().toLowerCase().endsWith(".xml")) {
-                            tempFileList.add(files[i]);
+                    List<File> tempFileList = new LinkedList<File>();
+                    for (File file: files) {
+                        if (file.getName().toLowerCase().endsWith(".xml")) {
+                            tempFileList.add(file);
                         }
                     }
                     Collections.sort(tempFileList);
-                    Iterator tempFileIter = tempFileList.iterator();
-                    while (tempFileIter.hasNext()) {
-                        File dataFile = (File) tempFileIter.next();
+                    for (File dataFile: tempFileList) {
                         if (dataFile.exists()) {
                             URL url = null;
                             try {
@@ -185,15 +173,15 @@
         return urlList;
     }
 
-    public static int loadData(URL dataUrl, String helperName, GenericDelegator delegator, List errorMessages) throws GenericEntityException {
+    public static int loadData(URL dataUrl, String helperName, GenericDelegator delegator, List<Object> errorMessages) throws GenericEntityException {
         return loadData(dataUrl, helperName, delegator, errorMessages, -1);
     }
 
-    public static int loadData(URL dataUrl, String helperName, GenericDelegator delegator, List errorMessages, int txTimeout) throws GenericEntityException {
+    public static int loadData(URL dataUrl, String helperName, GenericDelegator delegator, List<Object> errorMessages, int txTimeout) throws GenericEntityException {
         return loadData(dataUrl, helperName, delegator, errorMessages, txTimeout, false, false, false);
     }
 
-    public static int loadData(URL dataUrl, String helperName, GenericDelegator delegator, List errorMessages, int txTimeout, boolean dummyFks, boolean maintainTxs, boolean tryInsert) throws GenericEntityException {
+    public static int loadData(URL dataUrl, String helperName, GenericDelegator delegator, List<Object> errorMessages, int txTimeout, boolean dummyFks, boolean maintainTxs, boolean tryInsert) throws GenericEntityException {
         int rowsChanged = 0;
         
         if (dataUrl == null) {
@@ -230,13 +218,11 @@
         return rowsChanged;
     }
 
-    public static int generateData(GenericDelegator delegator, List errorMessages) throws GenericEntityException {
+    public static int generateData(GenericDelegator delegator, List<Object> errorMessages) throws GenericEntityException {
         int rowsChanged = 0;
         ModelReader reader = delegator.getModelReader();
-        Collection entityCol = reader.getEntityNames();
-        Iterator classNamesIterator = entityCol.iterator();
-        while (classNamesIterator != null && classNamesIterator.hasNext()) {
-            ModelEntity entity = reader.getModelEntity((String) classNamesIterator.next());
+        for (String entityName: reader.getEntityNames()) {
+            ModelEntity entity = reader.getModelEntity(entityName);
             String baseName = entity.getPlainTableName();
             if (entity instanceof ModelViewEntity) {
                 baseName = ModelUtil.javaNameToDbName(entity.getEntityName());
@@ -244,31 +230,30 @@
 
             if (baseName != null) {
                 try {
-                    List toBeStored = new LinkedList();
+                    List<GenericValue> toBeStored = new LinkedList<GenericValue>();
                     toBeStored.add(
                         delegator.makeValue(
                             "SecurityPermission",
-                            UtilMisc.toMap(
                                 "permissionId",
                                 baseName + "_ADMIN",
                                 "description",
-                                "Permission to Administer a " + entity.getEntityName() + " entity.")));
-                    toBeStored.add(delegator.makeValue("SecurityGroupPermission", UtilMisc.toMap("groupId", "FULLADMIN", "permissionId", baseName + "_ADMIN")));
+                                "Permission to Administer a " + entity.getEntityName() + " entity."));
+                    toBeStored.add(delegator.makeValue("SecurityGroupPermission", "groupId", "FULLADMIN", "permissionId", baseName + "_ADMIN"));
                     rowsChanged += delegator.storeAll(toBeStored);
                 } catch (GenericEntityException e) {
                     errorMessages.add("[install.generateData] ERROR: Failed Security Generation for entity \"" + baseName + "\"");
                 }
 
                 /*
-                toStore.add(delegator.makeValue("SecurityPermission", UtilMisc.toMap("permissionId", baseName + "_VIEW", "description", "Permission to View a " + entity.getEntityName() + " entity.")));
-                toStore.add(delegator.makeValue("SecurityPermission", UtilMisc.toMap("permissionId", baseName + "_CREATE", "description", "Permission to Create a " + entity.getEntityName() + " entity.")));
-                toStore.add(delegator.makeValue("SecurityPermission", UtilMisc.toMap("permissionId", baseName + "_UPDATE", "description", "Permission to Update a " + entity.getEntityName() + " entity.")));
-                toStore.add(delegator.makeValue("SecurityPermission", UtilMisc.toMap("permissionId", baseName + "_DELETE", "description", "Permission to Delete a " + entity.getEntityName() + " entity.")));
+                toStore.add(delegator.makeValue("SecurityPermission", "permissionId", baseName + "_VIEW", "description", "Permission to View a " + entity.getEntityName() + " entity."));
+                toStore.add(delegator.makeValue("SecurityPermission", "permissionId", baseName + "_CREATE", "description", "Permission to Create a " + entity.getEntityName() + " entity."));
+                toStore.add(delegator.makeValue("SecurityPermission", "permissionId", baseName + "_UPDATE", "description", "Permission to Update a " + entity.getEntityName() + " entity."));
+                toStore.add(delegator.makeValue("SecurityPermission", "permissionId", baseName + "_DELETE", "description", "Permission to Delete a " + entity.getEntityName() + " entity."));
                 
-                toStore.add(delegator.makeValue("SecurityGroupPermission", UtilMisc.toMap("groupId", "FLEXADMIN", "permissionId", baseName + "_VIEW")));
-                toStore.add(delegator.makeValue("SecurityGroupPermission", UtilMisc.toMap("groupId", "FLEXADMIN", "permissionId", baseName + "_CREATE")));
-                toStore.add(delegator.makeValue("SecurityGroupPermission", UtilMisc.toMap("groupId", "FLEXADMIN", "permissionId", baseName + "_UPDATE")));
-                toStore.add(delegator.makeValue("SecurityGroupPermission", UtilMisc.toMap("groupId", "FLEXADMIN", "permissionId", baseName + "_DELETE")));
+                toStore.add(delegator.makeValue("SecurityGroupPermission", "groupId", "FLEXADMIN", "permissionId", baseName + "_VIEW"));
+                toStore.add(delegator.makeValue("SecurityGroupPermission", "groupId", "FLEXADMIN", "permissionId", baseName + "_CREATE"));
+                toStore.add(delegator.makeValue("SecurityGroupPermission", "groupId", "FLEXADMIN", "permissionId", baseName + "_UPDATE"));
+                toStore.add(delegator.makeValue("SecurityGroupPermission", "groupId", "FLEXADMIN", "permissionId", baseName + "_DELETE"));
                 */
             }
         }

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntitySaxReader.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntitySaxReader.java?rev=585844&r1=585843&r2=585844&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntitySaxReader.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntitySaxReader.java Wed Oct 17 20:54:48 2007
@@ -85,9 +85,9 @@
     protected boolean checkDataOnly = false;
     protected boolean doCacheClear = true;
     protected boolean disableEeca = false;
-    protected List messageList = null;
+    protected List<Object> messageList = null;
 
-    protected List valuesToWrite = new ArrayList(valuesPerWrite);
+    protected List<GenericValue> valuesToWrite = new ArrayList<GenericValue>(valuesPerWrite);
 
     protected boolean isParseForTemplate = false;
     protected CharSequence templatePath = null;
@@ -174,14 +174,14 @@
         return this.disableEeca;
     }
     
-    public List getMessageList() {
+    public List<Object> getMessageList() {
         if (this.checkDataOnly && this.messageList == null) {
             messageList = FastList.newInstance();
         }
         return this.messageList;
     }
     
-    public void setMessageList(List messageList) {
+    public void setMessageList(List<Object> messageList) {
         this.messageList = messageList;
     }
 
@@ -275,7 +275,7 @@
         return numberRead;
     }
 
-    protected void writeValues(List valuesToWrite) throws GenericEntityException {
+    protected void writeValues(List<GenericValue> valuesToWrite) throws GenericEntityException {
         if (this.checkDataOnly) {
             EntityDataAssert.checkValueList(valuesToWrite, delegator, this.getMessageList());
         } else {
@@ -331,7 +331,7 @@
                     Template template = new Template("FMImportFilter", templateReader, config);
                     NodeModel nodeModel = NodeModel.wrap(this.rootNodeForTemplate);
 
-                    Map context = FastMap.newInstance();
+                    Map<String, Object> context = FastMap.newInstance();
                     BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
                     TemplateHashModel staticModels = wrapper.getStaticModels();
                     context.put("Static", staticModels);

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityTypeUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityTypeUtil.java?rev=585844&r1=585843&r2=585844&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityTypeUtil.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityTypeUtil.java Wed Oct 17 20:54:48 2007
@@ -35,13 +35,10 @@
     
     public static final String module = EntityTypeUtil.class.getName();
 
-    public static boolean isType(Collection thisCollection, String typeRelation, GenericValue targetType) {
-        Iterator iter = thisCollection.iterator();
-
-        while (iter.hasNext()) {
+    public static boolean isType(Collection<GenericValue> thisCollection, String typeRelation, GenericValue targetType) {
+        for (GenericValue value: thisCollection) {
             try {
-                GenericValue related = ((GenericValue) iter.next()).getRelatedOne(typeRelation);
-
+                GenericValue related = value.getRelatedOne(typeRelation);
                 if (isType(related, targetType)) {
                     return true;
                 } // else keep looking
@@ -81,12 +78,12 @@
         }
     }
 
-    public static List getDescendantTypes(GenericValue typeValue) {
+    public static List<GenericValue> getDescendantTypes(GenericValue typeValue) {
         // assumes Child relation is "Child<entityName>"
-        List descendantTypes = new ArrayList();
+        List<GenericValue> descendantTypes = new ArrayList<GenericValue>();
 
         // first get all childrenTypes ...
-        List childrenTypes = null;
+        List<GenericValue> childrenTypes = null;
         try {
             childrenTypes = typeValue.getRelatedCache("Child" + typeValue.getEntityName());
         } catch (GenericEntityException e) {
@@ -100,10 +97,8 @@
         descendantTypes.addAll(childrenTypes);
 
         // then add all descendants of the children
-        Iterator childrenTypeIter = childrenTypes.iterator();
-        while (childrenTypeIter.hasNext()) {
-            GenericValue childType = (GenericValue) childrenTypeIter.next();
-            List childTypeDescendants = getDescendantTypes(childType);
+        for (GenericValue childType: childrenTypes) {
+            List<GenericValue> childTypeDescendants = getDescendantTypes(childType);
             if (childTypeDescendants != null) {
                 descendantTypes.addAll(childTypeDescendants);
             }

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/SequenceUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/SequenceUtil.java?rev=585844&r1=585843&r2=585844&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/SequenceUtil.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/SequenceUtil.java Wed Oct 17 20:54:48 2007
@@ -43,7 +43,7 @@
 
     public static final String module = SequenceUtil.class.getName();
 
-    Map sequences = new Hashtable();
+    Map<String, SequenceBank> sequences = new Hashtable<String, SequenceBank>();
     String helperName;
     ModelEntity seqEntity;
     String tableName;
@@ -82,7 +82,7 @@
     
     public void forceBankRefresh(String seqName, long staggerMax) {
         // don't use the get method because we don't want to create if it fails
-        SequenceBank bank = (SequenceBank) sequences.get(seqName);
+        SequenceBank bank = sequences.get(seqName);
         if (bank == null) {
             return;
         }
@@ -95,7 +95,7 @@
 
         if (bank == null) {
             synchronized(this) {
-                bank = (SequenceBank) sequences.get(seqName);
+                bank = sequences.get(seqName);
                 if (bank == null) {
                     bank = new SequenceBank(seqName, seqModelEntity, this);
                     sequences.put(seqName, bank);