1/*
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3 */
4/*
5 * Licensed to the Apache Software Foundation (ASF) under one or more
6 * contributor license agreements.  See the NOTICE file distributed with
7 * this work for additional information regarding copyright ownership.
8 * The ASF licenses this file to You under the Apache License, Version 2.0
9 * (the "License"); you may not use this file except in compliance with
10 * the License.  You may obtain a copy of the License at
11 *
12 *      http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21package com.sun.org.apache.xerces.internal.impl.dv.dtd;
22
23import com.sun.org.apache.xerces.internal.impl.dv.DatatypeValidator;
24import java.util.Collections;
25import java.util.HashMap;
26import java.util.Map;
27
28/**
29 * the factory to create/return built-in XML 1.1 DVs and create user-defined DVs
30 *
31 * @xerces.internal
32 *
33 * @author Neil Graham, IBM
34 *
35 */
36public class XML11DTDDVFactoryImpl extends DTDDVFactoryImpl {
37
38    static Map<String, DatatypeValidator> XML11BUILTINTYPES;
39    static {
40        Map<String, DatatypeValidator> xml11BuiltInTypes = new HashMap<>();
41        xml11BuiltInTypes.put("XML11ID", new XML11IDDatatypeValidator());
42        DatatypeValidator dvTemp = new XML11IDREFDatatypeValidator();
43        xml11BuiltInTypes.put("XML11IDREF", dvTemp);
44        xml11BuiltInTypes.put("XML11IDREFS", new ListDatatypeValidator(dvTemp));
45        dvTemp = new XML11NMTOKENDatatypeValidator();
46        xml11BuiltInTypes.put("XML11NMTOKEN", dvTemp);
47        xml11BuiltInTypes.put("XML11NMTOKENS", new ListDatatypeValidator(dvTemp));
48        XML11BUILTINTYPES = Collections.unmodifiableMap(xml11BuiltInTypes);
49    } // <clinit>
50
51    /**
52     * return a dtd type of the given name
53     * This will call the super class if and only if it does not
54     * recognize the passed-in name.
55     *
56     * @param name  the name of the datatype
57     * @return      the datatype validator of the given name
58     */
59    @Override
60    public DatatypeValidator getBuiltInDV(String name) {
61        if(XML11BUILTINTYPES.get(name) != null) {
62            return XML11BUILTINTYPES.get(name);
63        }
64        return fBuiltInTypes.get(name);
65    }
66
67    /**
68     * get all built-in DVs, which are stored in a Map keyed by the name
69     * New XML 1.1 datatypes are inserted.
70     *
71     * @return      a Map which contains all datatypes
72     */
73    @Override
74    public Map<String, DatatypeValidator> getBuiltInTypes() {
75        final HashMap<String, DatatypeValidator> toReturn = new HashMap<>(fBuiltInTypes);
76        toReturn.putAll(XML11BUILTINTYPES);
77        return toReturn;
78    }
79}//XML11DTDDVFactoryImpl
80