/** * Initializes all auxiliary data structures. First the {@link de.xirp.profile.Profile profile} * beans are parsed. After that, all same named {@link de.xirp.profile.Profile profiles} obtain a * unique name. The incomplete {@link de.xirp.profile.Profile profiles} are added to the * corresponding map and the complete {@link de.xirp.profile.Profile profiles} are also added to * their corresponding map. <br> * <br> * After that step, the {@link de.xirp.profile.Robot robot} beans are created by the parser for * each {@link de.xirp.profile.Profile profile}. The {@link de.xirp.profile.Robot robots} are * created and added to the corresponding {@link java.util.Vector vector} in the {@link * de.xirp.profile.Profile profiles}. While parsing the {@link de.xirp.profile.Robot robots} the * contained {@link de.xirp.profile.CommunicationSpecification comm-spec} beans are parsed and * added to the corresponding {@link java.util.Vector vector} in the {@link de.xirp.profile.Robot * robot}. After all {@link de.xirp.profile.Robot robots} have been created, all same named {@link * de.xirp.profile.Robot robots} obtain a unique name. <br> * <br> * All {@link de.xirp.profile.Profile profiles} and {@link de.xirp.profile.Robot robots} obtain * unique names to guarantee that {@link de.xirp.profile.Profile profiles} and {@link * de.xirp.profile.Robot robots} can be clearly identified. The unique names are achieved by * enumerating the same named objects. * * @throws JAXBException if something went wrong while parsing. * @see de.xirp.profile.Robot * @see de.xirp.profile.Profile * @see de.xirp.profile.CommunicationSpecification */ private void init() throws JAXBException { logClass.info(I18n.getString("ProfileParser.log.parsing")); // $NON-NLS-1$ File profDir = new File(Constants.CONF_PROFILES_DIR); File dtdP = new File(Constants.CONF_PROFILES_DIR + File.separator + "profile.dtd"); // $NON-NLS-1$ File dtdC = new File( Constants.CONF_COMMSPECS_DIR + File.separator + "communication.dtd"); // $NON-NLS-1$ File dtdR = new File(Constants.CONF_ROBOTS_DIR + File.separator + "robot.dtd"); // $NON-NLS-1$ if (!dtdP.exists()) { try { throw new FileNotFoundException( I18n.getString("ProfileParser.log.noProfilesDTD", dtdP.getName())); // $NON-NLS-1$ } catch (FileNotFoundException e) { logClass.info( I18n.getString("ProfileParser.log.failed") + Constants.LINE_SEPARATOR); // $NON-NLS-1$ logClass.error( "Error: " + e.getMessage() // $NON-NLS-1$ + Constants.LINE_SEPARATOR, e); } } else if (!dtdC.exists()) { try { throw new FileNotFoundException( I18n.getString("ProfileParser.log.noProfilesDTD", dtdC.getName())); // $NON-NLS-1$ } catch (FileNotFoundException e) { logClass.info( I18n.getString("ProfileParser.log.failed") + Constants.LINE_SEPARATOR); // $NON-NLS-1$ logClass.error( "Error: " + e.getMessage() // $NON-NLS-1$ + Constants.LINE_SEPARATOR, e); } } else if (!dtdR.exists()) { try { throw new FileNotFoundException( I18n.getString("ProfileParser.log.noProfilesDTD", dtdR.getName())); // $NON-NLS-1$ } catch (FileNotFoundException e) { logClass.info( I18n.getString("ProfileParser.log.failed") + Constants.LINE_SEPARATOR); // $NON-NLS-1$ logClass.error( "Error: " + e.getMessage() // $NON-NLS-1$ + Constants.LINE_SEPARATOR, e); } } File[] files = profDir.listFiles( new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(Constants.PROFILE_POSTFIX); } }); if (files.length <= 0) { try { throw new FileNotFoundException( I18n.getString("ProfileParser.exception.noProfilesFound")); // $NON-NLS-1$ } catch (FileNotFoundException e) { logClass.info( I18n.getString("ProfileParser.log.failed") // $NON-NLS-1$ + Constants.LINE_SEPARATOR + e.getMessage() + Constants.LINE_SEPARATOR); logClass.info( I18n.getString("ProfileParser.log.noProfilesLoaded") // $NON-NLS-1$ + Constants.LINE_SEPARATOR); } } MultiValueHashMap<String, Profile> profileNames = new MultiValueHashMap<String, Profile>(); Profile profile; for (File xmlFile : files) { profile = parseProfile(xmlFile); profile.setProFile(xmlFile); profileNames.put(profile.getName(), profile); } List<Profile> prfls = new ArrayList<Profile>(); for (Entry<String, List<Profile>> e : profileNames.entrySet()) { List<Profile> list = e.getValue(); if (list.size() > 1) { for (int i = 0; i < list.size(); i++) { Profile aux = list.get(i); aux.setName(aux.getName() + " #" + (i + 1)); // $NON-NLS-1$ prfls.add(aux); } } else { prfls.add(list.get(0)); } } MultiValueHashMap<String, Robot> robotNames = new MultiValueHashMap<String, Robot>(); for (Profile p : prfls) { for (Robot r : p.getRobots()) { robotNames.put(r.getName(), r); } } for (Entry<String, List<Robot>> e : robotNames.entrySet()) { List<Robot> list = e.getValue(); if (list.size() > 1) { for (int i = 0; i < list.size(); i++) { Robot aux = list.get(i); aux.setName(aux.getName() + " #" + (i + 1)); // $NON-NLS-1$ } } } for (Profile p : prfls) { if (p.isComplete()) { profiles.put(p.getName(), p); } else { incompleteProfiles.put(p.getName(), p); } } }