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

📄 datatransferobjectfactory.java

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

        for (int i = 0; i < attributeNames.length; i++) {
            list.add(create(schemaBase, attributeNames[i]));
        }

        return list;
    }

    /**
     * Test is attribute is a required attribtue of schemaBase.
     *
     * @return <code>True</code> if attribute is required for schemaBase
     */
    public static boolean isManditory(String schemaBase, String attribute) {
        String[] required = getRequiredBaseAttributes(schemaBase);

        for (int i = 0; i < required.length; i++) {
            if (attribute.equals(required[i])) {
                return true;
            }
        }

        return false;
    }

    /**
     * Required Attributes for schemaBase.
     * <p>
     * This information is a hardcoded representation of what woudl be available
     * if we had actually parsed the GML XMLSchema.
     * </p>
     * @param schemaBase
     * @return
     */
    public static String[] getRequiredBaseAttributes(String schemaBase) {
        if (schemaBaseMap.containsKey(schemaBase)) {
            return (String[]) schemaBaseMap.get(schemaBase);
        }

        return new String[] {  };
    }

    public static Map schemaBaseMap = new HashMap();

    static {
        schemaBaseMap.put("gml:AbstractFeatureType", new String[] {  }); //"description","name","boundedBy"} );
                                                                         /*schemaBaseMap.put("AbstractFeatureCollectionBaseType",
        new String[] {"description","name","boundedBy"} );
        schemaBaseMap.put("GeometryPropertyType",
        new String[] {"geometry"} );
        schemaBaseMap.put("FeatureAssociationType",
        new String[] {"feature"} );
        schemaBaseMap.put("BoundingShapeType",
        new String[] {"box"} );
        schemaBaseMap.put("PointPropertyType",
        new String[] {"point"} );
        schemaBaseMap.put("PolygonPropertyType",
        new String[] {"polygon"} );
        schemaBaseMap.put("LineStringPropertyType",
        new String[] {"lineString"} );
        schemaBaseMap.put("MultiPointPropertyType",
        new String[] {"multiPoint"} );
        schemaBaseMap.put("MultiLineStringPropertyType",
        new String[] {"multiLineString"} );
        schemaBaseMap.put("MultiPolygonPropertyType",
        new String[] {"multiPolygonString"} );
        schemaBaseMap.put("MultiGeometryPropertyType",
        new String[] {"multiGeometry"} );
        schemaBaseMap.put("NullType", new String[] {} );*/
    }

    /**
     * Mappings for name and type, or null if not found.
     * <p>
     * List construction order:
     * <ul>
     * <li>Use of property types if name and exact type match one of the gml
     *     properties references.<br>
     *     For <code>name="pointProperty", type=com.vividsolutions.jts.geom.Point</code> maps to:
     *     <b>gml:PointPropertyType</b>
     *     </li>
     * <li>Search the schema for defined types are checked for an exact match
     *     based on type.<br>
     *     For <code>type=java.lang.String</code> maps to:
     *      <b>xs:string</b>
     *      </li>
     * <li>A linear seach of the defined types is made making use of
     *     isAssignable.<br>
     *     For <code>type=com.vividsolutions.jts.geom.Geometry</code> maps to:
     *     <b>gml:PointType gml:LineStringType gml:LinearRingType gml:BoxType gml:PolygonType gml:GeometryCollectionType gml:MultiPointType gml:MultiLineStringType, gml:MultiPolygonType</b>
     *     </li>
     * <li>As a wild assumption we assume <code>xs:string</code> can be used.<br>
     *     For <code>type=java.net.URL</code> maps to: <b>xs:string</b>
     *    </li>
     * </ul>
     * <p>
     * All mappings are consulted using using a linear search.
     * The list is returned in the order of most specific to least specific.
     * </p>
     * Complete Example:
     * <code>name="pointProperty", class=type=com.vividsolutions.jts.geom.Point</code>
     * <p>
     * Expected Mapping:
     * </p>
     * <ul>
     * <li>gml:PointPropertyType - pointProperty & Point.class match</li>
     * <li>gml:PointType - Point.class match</li>
     * <li>gml:AbstractGeometry - Point instance of Geometry match</li>
     * <li>xs:string - String assumption</li>
     * </ul>
     * @param name attribute name
     * @param type attribtue type
     * @return List of NameSpaceElements is returned in the order of most specific to least specific.
     */
    public static List getElements(String name, Class type) {
        NameSpaceTranslator xs = NameSpaceTranslatorFactory.getInstance()
                                                           .getNameSpaceTranslator("xs");
        NameSpaceTranslator gml = NameSpaceTranslatorFactory.getInstance()
                                                            .getNameSpaceTranslator("gml");
        List result = new LinkedList();

        if ((name == null) || (name == "")) {
            throw new NullPointerException("Element name must be defined.");
        }

        if (type == null) {
            throw new NullPointerException("Element type must be defined.");
        }

        Set s = xs.getAssociatedTypes(type);
        s.addAll(xs.getAssociatedTypes(name));
        s.addAll(gml.getAssociatedTypes(type));
        s.addAll(gml.getAssociatedTypes(name));

        Iterator i = s.iterator();

        while (i.hasNext()) {
            NameSpaceElement element = (NameSpaceElement) i.next();

            if (name.equals(element.getTypeDefName())) {
                if (!result.contains(element)) {
                    result.add(element);
                } else if (name.equals(element.getTypeRefName())) {
                    if (!result.contains(element)) {
                        result.add(element);
                    } else if (name.equals(element.getQualifiedTypeDefName())) {
                        if (!result.contains(element)) {
                            result.add(element);
                        } else if (name.equals(element.getQualifiedTypeRefName())) {
                            if (!result.contains(element)) {
                                result.add(element);
                            }
                        }
                    }
                }
            }
        }

        if (!Object.class.equals(type)) {
            Class cls = type;

            while (!Object.class.equals(cls)) {
                i = s.iterator();

                while (i.hasNext()) {
                    NameSpaceElement element = (NameSpaceElement) i.next();

                    // 	add the rest afterwards
                    if (element.getJavaClass().equals(cls) && !result.contains(element)) {
                        result.add(element);
                    }
                }

                cls = cls.getSuperclass();
            }
        }

        i = s.iterator();

        while (i.hasNext()) {
            NameSpaceElement element = (NameSpaceElement) i.next();

            // 	add the rest afterwards
            if (!result.contains(element)) {
                result.add(element);
            }
        }

        NameSpaceElement element = xs.getElement("string");

        if (!result.contains(element)) {
            result.add(element);
        }

        return result;
    }

    /**
     * Retrive best NameSpaceElement match for provided attribtue name and type.
     * <p>
     * Best match is determined by the search order defined by getElements.
     * </p>
     * @param name
     * @param type
     * @return Closest NameSapceElement
     */
    private static final NameSpaceElement getBestMatch(String name, Class type) {
        return (NameSpaceElement) getElements(name, type).get(0);
    }
}

⌨️ 快捷键说明

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