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

📄 data.java

📁 电子地图服务器,搭建自己的地图服务
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * then <code>null</code> is returned.
     * </p>
     *
     * @param uri A namespace uri, non-null
     *
     * @return NameSpaceInfo resulting from the specified uri.
     */
    public synchronized NameSpaceInfo getNameSpaceFromURI(String uri) {
        for (Iterator i = nameSpaces.values().iterator(); i.hasNext();) {
            NameSpaceInfo nsInfo = (NameSpaceInfo) i.next();

            if (nsInfo.getURI().equals(uri)) {
                return nsInfo;
            }
        }

        return null;
    }

    /**
     * getDefaultNameSpace purpose.
     *
     * <p>
     * Returns the default NameSpaceInfo for this Data object.
     * </p>
     *
     * @return NameSpaceInfo the default name space
     *
     * @uml.property name="defaultNameSpace"
     */
    public synchronized NameSpaceInfo getDefaultNameSpace() {
        return defaultNameSpace;
    }

    /**
     * getStyles purpose.
     *
     * <p>
     * A reference to the map of styles
     * </p>
     *
     * @return Map A map containing the Styles.
     *
     * @uml.property name="styles"
     */
    public synchronized Map getStyles() {
        return this.styles;
    }

    public synchronized Style getStyle(String id) {
        return (Style) styles.get(id);
    }

    /**
     * Locate FeatureTypeInfo by name
     *
     * <p>
     * The following searchness is used::
     *
     * <ul>
     * <li> search prefix:typeName for direct match with name </li>
     * <li> search prefix:typeName for match with defaultnamespaceprefix:name
     * </li>
     * <li> linear search of typeName for direct match </li>
     * </ul>
     * </p>
     *
     * <p>
     * Yes this is the magic method used by TransasctionResponse. If you
     * wondered what it was doing - this is it.
     * </p>
     *
     * @param name
     *            String The FeatureTypeInfo Name
     *
     * @return FeatureTypeInfo
     *
     * @throws NoSuchElementException
     */
    public synchronized FeatureTypeInfo getFeatureTypeInfo(String name)
        throws NoSuchElementException {
        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.fine(new StringBuffer("getting type ").append(name).toString());
        }

        FeatureTypeInfo found = null;

        found = (FeatureTypeInfo) featureTypes.get(name);

        if (found != null) {
            return found;
        }

        String defaultPrefix = defaultNameSpace.getPrefix();
        found = (FeatureTypeInfo) featureTypes.get(defaultPrefix + ":" + name);

        if (found != null) {
            return found;
        }

        for (Iterator i = featureTypes.values().iterator(); i.hasNext();) {
            FeatureTypeInfo fto = (FeatureTypeInfo) i.next();

            if ((name != null) && name.equals(fto.getName())) {
                found = fto;
            }
        }

        if (found != null) {
            return found;
        }

        throw new NoSuchElementException("Could not locate FeatureTypeConfig '" + name + "'");
    }

    /**
     * Gets a FeatureTypeINfo from a qualified name.
     * <p>
     * This method calls through to {@link #getFeatureTypeInfo(String, String)}.
     * </p>
     * @param name The qualified name of the feature type.
     */
    public FeatureTypeInfo getFeatureTypeInfo(QName name) {
        return getFeatureTypeInfo(name.getLocalPart(), name.getNamespaceURI());
    }

    /**
     * Gets a FeatureTypeInfo from a local type name (ie unprefixed), and a uri.
     *
     * <p>
     * This method is slow, use getFeatureType(String typeName), where possible.
     * For not he only user should be TransactionFeatureHandler.
     * </p>
     *
     * <p>
     * TODO: Jody here - David is this still correct?
     * </p>
     *
     * @param typename
     *            Name NameSpaceInfo name
     * @param uri
     *            NameSpaceInfo uri
     *
     * @return FeatureTypeInfo
     */
    public synchronized FeatureTypeInfo getFeatureTypeInfo(String typename, String uri) {
        // For some reason I don't understand GR patched this to remove the namespace 
        // test, but this breaks if there are multiple feature types with the same
        // name in different namespaces. Now, to stay on the safe side, I will lookup
        // first based on both name and namespace, and return a pure name matcher only
        // if a full name + namespace match was not found
        
        // This will be returned if we matched only the name but not the namespace
        FeatureTypeInfo fallback = null;
        for (Iterator it = featureTypes.values().iterator(); it.hasNext();) {
            FeatureTypeInfo fType = (FeatureTypeInfo) it.next();

            if (fType.isEnabled()) {
                String typeId = fType.getNameSpace().getPrefix() + ":" + typename;
                boolean t1 = fType.getName().equals(typeId);
                boolean t2 = fType.getNameSpace().getUri().equals(uri);

                /**
                 * GR:
                 *
                 * @HACK it seems not to be working, so I'm just comparing the
                 *       prefixed name (don't should it be enough?)
                 */
                if (t1 && t2) {
                    return fType;
                } else if(t1) {
                    fallback = fType;
                }
            }
        }

        return fallback;
    }

    public synchronized CoverageInfo getCoverageInfo(String name)
        throws NoSuchElementException {
        LOGGER.fine("getting coverage " + name);

        CoverageInfo found = null;

        found = (CoverageInfo) coverages.get(name);

        if (found != null) {
            return found;
        }

        String defaultPrefix = defaultNameSpace.getPrefix();
        found = (CoverageInfo) coverages.get(defaultPrefix + ":" + name);

        if (found != null) {
            return found;
        }

        for (Iterator i = coverages.values().iterator(); i.hasNext();) {
            CoverageInfo cvo = (CoverageInfo) i.next();

            if ((name != null) && name.equals(cvo.getName())) {
                found = cvo;
            }
        }

        if (found != null) {
            return found;
        }

        throw new NoSuchElementException("Could not locate CoverageConfig '" + name + "'");
    }

    public synchronized CoverageInfo getCoverageInfo(String name, String uri) {
        for (Iterator it = coverages.values().iterator(); it.hasNext();) {
            CoverageInfo cvo = (CoverageInfo) it.next();

            if (cvo.isEnabled()) {
                String cvId = cvo.getNameSpace().getPrefix() + ":" + name;
                boolean t1 = cvo.getName().equals(cvId);
                boolean t2 = cvo.getNameSpace().getUri().equals(uri);

                if (t1) {
                    return cvo;
                }
            }
        }

        return null;
    }

    /**
     * Retrieve map of FeatureTypeInfo by prefix:typeName.
     *
     * <p>
     * Returns all the featuretype information objects
     * </p>
     *
     * @return Map of FetureTypeInfo by prefix:typeName
     */
    public synchronized Map getFeatureTypeInfos() {
        return Collections.unmodifiableMap(featureTypes);
    }

    public synchronized Map getCoverageInfos() {
        return Collections.unmodifiableMap(coverages);
    }

    // TODO: detect if a user put a full url, instead of just one to be
    // resolved, and
    // use that instead.
    public Style loadStyle(String fileName, String base)
        throws IOException {
        return loadStyle(new File(base + fileName));
    }

    /**
     * Load GeoTools2 Style from a fileName
     *
     * @param fileName
     *            DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     *
     * @throws IOException
     *             DOCUMENT ME!
     */
    public Style loadStyle(File fileName) throws IOException {
        SLDParser stylereader = new SLDParser(styleFactory, fileName);

        return stylereader.readXML()[0];
    }

    /**
     * tests whether a given file is a file containing type information.
     *
     * @param testFile
     *            the file to test.
     *
     * @return <tt>true</tt> if the file has type info.
     */
    private static boolean isInfoFile(File testFile) {
        String testName = testFile.getAbsolutePath();
        int start = testName.length() - INFO_FILE.length();
        int end = testName.length();

        return testName.substring(start, end).equals(INFO_FILE);
    }

    /**
     * The number of connections currently held.
     *
     * <p>
     * We will need to modify DataStore to provide access to the current count
     * of its connection pool (if appropriate). Right now we are asumming a one
     * DataStore equals One "Connection".
     * </p>
     *
     * <p>
     * This is a good compromize since I just want to indicate the amount of
     * resources currently tied up by GeoServer.
     * </p>
     *
     * @return Number of available connections.
     */
    public synchronized int getConnectionCount() {
        int count = 0;
        DataStoreInfo meta;
        DataStore dataStore;

        for (Iterator i = dataStores.values().iterator(); i.hasNext();) {
            meta = (DataStoreInfo) i.next();

            if (!meta.isEnabled()) {
                continue; // disabled
            }

            try {
                dataStore = meta.getDataStore();
            } catch (Throwable notAvailable) {
                continue; // not available
            }

            // TODO: All DataStore to indicate number of connections
            count += 1;
        }

        return count;
    }

    /**
     * Count locks currently held.
     *
     * <p>
     * Not sure if this should be the number of features locked, or the number
     * of FeatureLocks in existence (a FeatureLock may lock several features.
     * </p>
     *
     * @return number of locks currently held
     */
    public synchronized int getLockCount() {
        int count = 0;
        DataStore dataStore;
        ;

        LockingManager lockingManager;

        for (Iterator i = dataStores.values().iterator(); i.hasNext();) {
            DataStoreInfo meta = (DataStoreInfo) i.next();

            if (!meta.isEnabled()) {
                continue; // disabled
            }

            try {
                dataStore = meta.getDataStore();
            } catch (IllegalStateException notAvailable) {
                continue; // not available
            } catch (Throwable huh) {
                continue; // not even working
            }

            lockingManager = dataStore.getLockingManager();

            if (lockingManager == null) {
                continue; // locks not supported
            }

            // TODO: implement LockingManger.getLockSet()
            // count += lockingManager.getLockSet();
        }

        return count;

⌨️ 快捷键说明

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