Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 3436:0d63581c5df1
FLYSArtifact: Prevent NPE in getOutputForState(). Why does this happen?
flys-artifacts/trunk@5099 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 23 Jul 2012 08:38:23 +0000 |
parents | 1b41dc00b1f7 |
children | 5da58c5c1517 |
comparison
equal
deleted
inserted
replaced
3435:262e7d7e58fe | 3436:0d63581c5df1 |
---|---|
1028 if (filterFacets == null || filterFacets.isEmpty()) { | 1028 if (filterFacets == null || filterFacets.isEmpty()) { |
1029 logger.debug("No filter for Outputs."); | 1029 logger.debug("No filter for Outputs."); |
1030 return outs; | 1030 return outs; |
1031 } | 1031 } |
1032 | 1032 |
1033 logger.debug("Filter Facets with " + filterFacets.size() + " filters."); | 1033 boolean debug = logger.isDebugEnabled(); |
1034 | |
1035 if (debug) { | |
1036 logger.debug( | |
1037 "Filter Facets with " + filterFacets.size() + " filters."); | |
1038 } | |
1034 | 1039 |
1035 List<Output> filtered = new ArrayList<Output>(); | 1040 List<Output> filtered = new ArrayList<Output>(); |
1036 | 1041 |
1037 for (Output out: outs) { | 1042 for (Output out: outs) { |
1038 String outName = out.getName(); | 1043 String outName = out.getName(); |
1039 | 1044 |
1040 logger.debug(" filter Facets for Output: " + outName); | 1045 if (debug) { |
1046 logger.debug(" filter Facets for Output: " + outName); | |
1047 } | |
1041 | 1048 |
1042 List<Facet> fFacets = filterFacets.get(outName); | 1049 List<Facet> fFacets = filterFacets.get(outName); |
1043 if (fFacets != null) { | 1050 if (fFacets != null) { |
1044 logger.debug("" + fFacets.size() + " filters for: " + outName); | 1051 if (debug) { |
1045 | 1052 logger.debug("" + fFacets.size() + " filters for: " + outName); |
1046 if (logger.isDebugEnabled()) { | |
1047 for (Facet tmp: fFacets) { | 1053 for (Facet tmp: fFacets) { |
1048 logger.debug(" filter = '" + tmp.getName() + "'"); | 1054 logger.debug(" filter = '" + tmp.getName() + "'"); |
1049 } | 1055 } |
1050 } | 1056 } |
1051 | 1057 |
1059 break; | 1065 break; |
1060 } | 1066 } |
1061 } | 1067 } |
1062 } | 1068 } |
1063 | 1069 |
1064 logger.debug("Facets after filtering = " + resultFacets.size()); | 1070 if (debug) { |
1071 logger.debug( | |
1072 "Facets after filtering = " + resultFacets.size()); | |
1073 } | |
1065 | 1074 |
1066 if (!resultFacets.isEmpty()) { | 1075 if (!resultFacets.isEmpty()) { |
1067 DefaultOutput nout = new DefaultOutput( | 1076 DefaultOutput nout = new DefaultOutput( |
1068 out.getName(), | 1077 out.getName(), |
1069 out.getDescription(), | 1078 out.getDescription(), |
1072 filtered.add(nout); | 1081 filtered.add(nout); |
1073 } | 1082 } |
1074 } | 1083 } |
1075 } | 1084 } |
1076 | 1085 |
1077 logger.debug("All Facets after filtering = " + filtered.size()); | 1086 if (debug) { |
1087 logger.debug("All Facets after filtering = " + filtered.size()); | |
1088 } | |
1078 | 1089 |
1079 return filtered; | 1090 return filtered; |
1080 } | 1091 } |
1081 | 1092 |
1082 | 1093 |
1085 * all previous states). | 1096 * all previous states). |
1086 * | 1097 * |
1087 * @return list of outputs | 1098 * @return list of outputs |
1088 */ | 1099 */ |
1089 public List<Output> getOutputs(Object context) { | 1100 public List<Output> getOutputs(Object context) { |
1090 logger.debug("##### Get Outputs for: " + identifier() + " #####"); | 1101 if (logger.isDebugEnabled()) { |
1102 logger.debug("##### Get Outputs for: " + identifier() + " #####"); | |
1103 } | |
1091 | 1104 |
1092 dumpArtifact(); | 1105 dumpArtifact(); |
1093 | 1106 |
1094 List<String> stateIds = getPreviousStateIds(); | 1107 List<String> stateIds = getPreviousStateIds(); |
1095 List<Output> generated = new ArrayList<Output>(); | 1108 List<Output> generated = new ArrayList<Output>(); |
1127 * Get output(s) for a specific state. | 1140 * Get output(s) for a specific state. |
1128 * @param state State of interest | 1141 * @param state State of interest |
1129 * @return list of output(s) for given state. | 1142 * @return list of output(s) for given state. |
1130 */ | 1143 */ |
1131 protected List<Output> getOutputForState(DefaultState state) { | 1144 protected List<Output> getOutputForState(DefaultState state) { |
1132 logger.debug("Find Outputs for State: " + state.getID()); | 1145 |
1146 if (state == null) { | |
1147 logger.error("state == null: This should not happen!"); | |
1148 return new ArrayList<Output>(); | |
1149 } | |
1150 | |
1151 boolean debug = logger.isDebugEnabled(); | |
1152 | |
1153 if (debug) { | |
1154 logger.debug("Find Outputs for State: " + state.getID()); | |
1155 } | |
1133 | 1156 |
1134 List<Output> list = state.getOutputs(); | 1157 List<Output> list = state.getOutputs(); |
1135 if (list == null || list.size() == 0) { | 1158 if (list == null || list.size() == 0) { |
1136 logger.debug("-> No output modes for this state."); | 1159 if (debug) { |
1160 logger.debug("-> No output modes for this state."); | |
1161 } | |
1137 return new ArrayList<Output>(); | 1162 return new ArrayList<Output>(); |
1138 } | 1163 } |
1139 | 1164 |
1140 String stateId = state.getID(); | 1165 String stateId = state.getID(); |
1141 | 1166 |
1142 List<Facet> fs = facets.get(stateId); | 1167 List<Facet> fs = facets.get(stateId); |
1143 | 1168 |
1144 if (fs == null || fs.size() == 0) { | 1169 if (fs == null || fs.size() == 0) { |
1145 logger.debug("No facets found."); | 1170 if (debug) { |
1171 logger.debug("No facets found."); | |
1172 } | |
1146 return new ArrayList<Output>(); | 1173 return new ArrayList<Output>(); |
1147 } | 1174 } |
1148 | 1175 |
1149 List<Output> gen = generateOutputs(list, fs); | 1176 List<Output> gen = generateOutputs(list, fs); |
1150 | 1177 |
1151 logger.debug("State '" + stateId + "' has " + gen.size() + " outs"); | 1178 if (debug) { |
1179 logger.debug("State '" + stateId + "' has " + gen.size() + " outs"); | |
1180 } | |
1152 | 1181 |
1153 return gen; | 1182 return gen; |
1154 } | 1183 } |
1155 | 1184 |
1156 | 1185 |
1432 /** | 1461 /** |
1433 * Destroy the states. | 1462 * Destroy the states. |
1434 */ | 1463 */ |
1435 @Override | 1464 @Override |
1436 public void endOfLife(Object context) { | 1465 public void endOfLife(Object context) { |
1437 logger.info("FLYSArtifact.endOfLife: " + identifier()); | 1466 if (logger.isDebugEnabled()) { |
1467 logger.debug("FLYSArtifact.endOfLife: " + identifier()); | |
1468 } | |
1438 | 1469 |
1439 ArrayList<String> ids = (ArrayList<String>) getPreviousStateIds(); | 1470 ArrayList<String> ids = (ArrayList<String>) getPreviousStateIds(); |
1440 ArrayList<String> toDestroy = (ArrayList<String>) ids.clone(); | 1471 ArrayList<String> toDestroy = (ArrayList<String>) ids.clone(); |
1441 | 1472 |
1442 toDestroy.add(getCurrentStateId()); | 1473 toDestroy.add(getCurrentStateId()); |