⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 data.java

📁 电子地图服务器,搭建自己的地图服务
💻 JAVA
📖 第 1 页 / 共 5 页
字号:

    private final Map loadCoverages(DataDTO dto) {
        if ((dto == null) || (dto.getCoverages() == null)) {
            return Collections.EMPTY_MAP; // we *are* allowed no datasets
        }

        Map map = new HashMap(dto.getCoverages().size());
        CoverageInfoDTO coverageDTO;
        String id;
        CoverageInfo coverageInfo;

        for (Iterator i = dto.getCoverages().values().iterator(); i.hasNext();) {
            coverageDTO = (CoverageInfoDTO) i.next();
            id = coverageDTO.getName();

            try {
                coverageInfo = new CoverageInfo(coverageDTO, this);
            } catch (ConfigurationException e) {
                coverageInfo = null;
            }

            map.put(id, coverageInfo);
            // set layer name, type raster (1)
            layerNames.put(id, TYPE_RASTER);

            if ((dto.getFormats() != null)
                    && (dto.getFormats().get(coverageDTO.getFormatId()) != null)) {
                if (LOGGER.isLoggable(Level.FINE)) {
                    LOGGER.fine(new StringBuffer("Register Coverage '").append(id).append("'")
                                                                       .toString());
                }
            } else {
                if (LOGGER.isLoggable(Level.FINE)) {
                    LOGGER.fine(new StringBuffer("Did not Register Coverage '").append(id)
                                                                               .append("' as didn't exist a valid Format")
                                                                               .toString());
                }
            }
        }

        return map;
    }

    /**
     * Configure a map of FeatureTypeInfo by prefix:typeName.
     *
     * <p>
     * Note that this map uses namespace prefix (not datastore ID like the the
     * configuration system). That is because this is the actual runtime, in
     * which we access FeatureTypes by namespace. The configuration system uses
     * dataStoreId which is assumed to be more stable across changes (one can
     * reassing a FeatureType to a different namespace, but not a different
     * dataStore).
     * </p>
     *
     * <p>
     * Note loadDataStores() and loadNamespaces() must be called prior to using
     * this function!
     * </p>
     *
     * @param dto
     *            configDTO
     *
     * @return
     *
     * @throws NullPointerException
     *             DOCUMENT ME!
     */
    private final Map loadFeatureTypes(DataDTO dto) {
        errors = new HashMap();
        featureTypes = new HashMap(); // to fix lazy loading

        if ((dto == null) || (dto.getFeaturesTypes() == null)) {
            errors = null;

            return Collections.EMPTY_MAP; // we *are* allowed no datasets
        }

        Map map = new HashMap(dto.getFeaturesTypes().size());
        FeatureTypeInfoDTO featureTypeDTO;
        String key;
        DataStoreInfo dataStoreInfo;
        String dataStoreId;
        String typeName;
        Style s;
        
        //let's sort the featuretypes first, and give some good loading messages as we go along.
        FeatureTypeInfoDTO[] ftypes = (FeatureTypeInfoDTO[])
            dto.getFeaturesTypes().values().toArray(new FeatureTypeInfoDTO[dto.getFeaturesTypes().size()]);
        Arrays.sort(ftypes, new Comparator() {
            public int compare(Object arg0, Object arg1) {
                FeatureTypeInfoDTO a0 = (FeatureTypeInfoDTO)arg0;
                FeatureTypeInfoDTO a1 = (FeatureTypeInfoDTO)arg1;
                return a0.getKey().compareToIgnoreCase(a1.getKey());
            }
        });
        
        int curLayerNum = 0;
        final int totalLayers = ftypes.length;
        
SCHEMA: 
        for (Iterator i = Arrays.asList(ftypes).iterator(); i.hasNext();) {
            curLayerNum++;
            featureTypeDTO = (FeatureTypeInfoDTO) i.next();

            if (featureTypeDTO == null) {
                if (LOGGER.isLoggable(Level.WARNING)) {
                    LOGGER.warning(new StringBuffer("Ignore null FeatureTypeInfo DTO!").toString());
                }

                continue;
            }

            key = featureTypeDTO.getKey(); // dataStoreId:typeName
            
            LOGGER.info("Loading feature type '" + key + "' (layer " + curLayerNum + "/" + totalLayers + ")");

            if (LOGGER.isLoggable(Level.FINER)) {
                LOGGER.finer(new StringBuffer("FeatureType ").append(key)
                                                             .append(": loading feature type info dto:")
                                                             .append(featureTypeDTO).toString());
            }

            dataStoreId = featureTypeDTO.getDataStoreId();

            if (LOGGER.isLoggable(Level.FINEST)) {
                LOGGER.finest(new StringBuffer("FeatureType ").append(key).append(" looking up :")
                                                              .append(dataStoreId).toString());
            }

            dataStoreInfo = (DataStoreInfo) dataStores.get(dataStoreId);

            if (dataStoreInfo == null) {
                if (LOGGER.isLoggable(Level.SEVERE)) {
                    LOGGER.severe(new StringBuffer("FeatureTypeInfo ").append(key)
                                                                      .append(" could not be used - DataStore ")
                                                                      .append(dataStoreId)
                                                                      .append(" is not defined!")
                                                                      .toString());
                }

                DataStoreInfoDTO tmp = (DataStoreInfoDTO) dto.getDataStores().get(dataStoreId);

                if ((tmp != null) && (!tmp.isEnabled())) {
                    errors.put(featureTypeDTO, Boolean.FALSE);
                } else {
                    errors.put(featureTypeDTO,
                        new ConfigurationException("FeatureTypeInfo " + key
                            + " could not be used - DataStore " + dataStoreId + " is not defined!"));
                }

                continue;
            } else {
                if (LOGGER.isLoggable(Level.FINEST)) {
                    LOGGER.finest(new StringBuffer(key).append(" datastore found :")
                                                       .append(dataStoreInfo).toString());
                }
            }

            s = getStyle(featureTypeDTO.getDefaultStyle());

            if (s == null) {
                if (LOGGER.isLoggable(Level.SEVERE)) {
                    LOGGER.severe(new StringBuffer("FeatureTypeInfo ").append(key)
                                                                      .append(" ignored - Style '")
                                                                      .append(featureTypeDTO
                            .getDefaultStyle()).append("' not found!").toString());
                }

                errors.put(featureTypeDTO,
                    new ConfigurationException("FeatureTypeInfo " + key + " ignored - Style '"
                        + featureTypeDTO.getDefaultStyle() + "' not found!"));

                continue SCHEMA;
            }

            // Check attributes configured correctly against schema
            typeName = featureTypeDTO.getName();

            try {
                DataStore dataStore = dataStoreInfo.getDataStore();
                FeatureType featureType = dataStore.getSchema(typeName);

                Set attributeNames = new HashSet();
                Set ATTRIBUTENames = new HashSet();

                // as far as I can tell an emtpy list indicates that no
                // schema.xml file was found. I may be approaching this
                // all wrong, is this logic contained elsewhere?
                // CH: Yeah, this shit was super messed up. It was causing null
                // pointer
                // exceptions, and then it created this createAttrDTO flag that
                // wasn't
                // then used by anyone. So I fixed the null and made it so it
                // creates
                // AttributeTypeInfoDTO's (once again, I hate these) from the
                // FeatureType
                // of the real datastore.
                // boolean createAttrDTO =
                // (featureTypeDTO.getSchemaAttributes().size() == 0);
                if (LOGGER.isLoggable(Level.FINE)) {
                    LOGGER.fine(new StringBuffer("locading datastore ").append(typeName).toString());
                }

                boolean createAttrDTO;

                if (featureTypeDTO.getSchemaAttributes() == null) {
                    createAttrDTO = true;
                } else {
                    createAttrDTO = featureTypeDTO.getSchemaAttributes().size() == 0;
                }

                if (createAttrDTO) {
                    List attributeDTOs = createAttrDTOsFromSchema(featureType);
                    featureTypeDTO.setSchemaAttributes(attributeDTOs);

                    if (LOGGER.isLoggable(Level.FINER)) {
                        LOGGER.finer(new StringBuffer(
                                "No schema found, setting featureTypeDTO with ").append(
                                attributeDTOs).toString());
                    }
                } else {
                    for (int index = 0; index < featureType.getAttributeCount(); index++) {
                        AttributeType attrib = featureType.getAttributeType(index);
                        attributeNames.add(attrib.getName());
                        ATTRIBUTENames.add(attrib.getName().toUpperCase());
                    }

                    if (featureTypeDTO.getSchemaAttributes() != null) {
                        for (Iterator a = featureTypeDTO.getSchemaAttributes().iterator();
                                a.hasNext();) {
                            AttributeTypeInfoDTO attribDTO = (AttributeTypeInfoDTO) a.next();
                            String attributeName = attribDTO.getName();

                            if (!attributeNames.contains(attributeName)) {
                                if (ATTRIBUTENames.contains(attributeName.toUpperCase())) {
                                    if (LOGGER.isLoggable(Level.SEVERE)) {
                                        LOGGER.severe(new StringBuffer("FeatureTypeInfo ").append(
                                                key).append(" ignored - attribute '")
                                                                                          .append(attributeName)
                                                                                          .append("' not found - please check captialization")
                                                                                          .toString());
                                    }
                                } else {
                                    if (LOGGER.isLoggable(Level.SEVERE)) {
                                        LOGGER.severe(new StringBuffer("FeatureTypeInfo ").append(
                                                key).append(" ignored - attribute '")
                                                                                          .append(attributeName)
                                                                                          .append("' not found!")
                                                                                          .toString());
                                    }

                                    String names = "";
                                    Iterator x = attributeNames.iterator();

                                    if (x.hasNext()) {
                                        names = x.next().toString();
                                    }

                                    while (x.hasNext())
                                        names = ":::" + x.next().toString();

                                    if (LOGGER.isLoggable(Level.SEVERE)) {
                                        LOGGER.severe(new StringBuffer(
                                                "Valid attribute names include :::").append(names)
                                                                                                           .toString());
                                    }
                                }

                                errors.put(featureTypeDTO,
                                    new ConfigurationException(
                                        new StringBuffer("FeatureTypeInfo ").append(key)
                                                                            .append(" could not be used - DataStore ")
                                                                            .append(dataStoreId)
                                                                            .append(" is not defined!")
                                                                            .toString()));

                                continue SCHEMA;
                            }
                        }
                    }
                }
            } catch (IllegalStateException illegalState) {
                if (LOGGER.isLoggable(Level.SEVERE)) {
                    LOGGER.severe(new StringBuffer("FeatureTypeInfo ").append(key)
                                                                      .append(" ignored - as DataStore ")
                                                                      .append(dataStoreId)
                                                                      .append(" is disabled!")
                                                                      .toString());
                }

                errors.put(featureTypeDTO, Boolean.FALSE);

                continue;
            } catch (IOException ioException) {
                if (LOGGER.isLoggable(Level.SEVERE)) {
                    LOGGER.log(Level.SEVERE,
                        new StringBuffer("FeatureTypeInfo ").append(key)
                                                            .append(" ignored - as DataStore ")
                                                            .append(dataStoreId)
                                                            .append(" is unavailable:")
                                                            .append(ioException).toString());
                }

                if (LOGGER.isLoggable(Level.FINE)) {
                    LOGGER.log(Level.FINE, new StringBuffer(key).append(" unavailable").toString(),
                        ioException);
                }

                errors.put(featureTypeDTO, ioException);

                continue;
            } catch (NoSuchElementException nse) {
                if (LOGGER.isLoggable(Level.SEVERE)) {
                    LOGGER.log(Level.SEVERE,
                        new StringBuffer("FeatureTypeInfo ").append(key)
                                                            .append(" ignored - as DataStore ")
                                                            .append(dataStoreId)
                                                            .append(" can't find FeatureType '"
                            + typeName + "'.  Error was:\n").append(nse).toString());
                }

                if (LOGGER.isLoggable(Level.FINE)) {
                    LOGGER.log(Level.FINE, typeName + " not found", nse);
                }

                continue;
            } catch (Throwable unExpected) {
                if (LOGGER.isLoggable(Level.SEVERE)) {
                    LOGGER.log(Level.SEVERE,
                        new StringBuffer("FeatureTypeInfo ").append(key)
                                                            .append(" ignored - as DataStore ")
                                                            .append(dataStoreId)
                                                            .append(" is broken:").append(unExpected)
                                                            .toString());
                }

                if (LOGGER.isLoggable(Level.FINE)) {
                    LOGGER.log(Level.FINE, new StringBuffer(key).append(" unavailable").toString(),
                        unExpected);
                }

                errors.put(featureTypeDTO, unExpected);

                continue;
            }

            String prefix = dataStoreInfo.getNamesSpacePrefix();

            if (LOGGER.isLoggable(Level.FINEST)) {
                LOGGER.finest(new StringBuffer("FeatureType ").append(key)
                                                              .append(" creating FeatureTypeInfo for ")
                                                              .append(prefix).append(":")
                                                              .append(typeName).toString());
            }

            FeatureTypeInfo featureTypeInfo = null;

            try {
                featureTypeInfo = new FeatureTypeInfo(featureTypeDTO, this);
            } catch (ConfigurationException configException) {
                if (LOGGER.isLoggable(Level.SEVERE)) {
                    LOGGER.log(Level.SEVERE,
                        new StringBuffer("FeatureTypeInfo ").append(key)
                                                            .append(" ignored - configuration problem:")
                                                            .append(configException).toString());
                }

                if (LOGGER.isLoggable(Level.FINEST)) {
                    LOGGER.log(Level.FINEST,
                        new StringBuffer(key).append(" unavailable").toString(), configException);
                }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -