• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Libphonenumber Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.i18n.phonenumbers.metadata;
18 
19 import com.google.i18n.phonenumbers.MetadataLoader;
20 import com.google.i18n.phonenumbers.metadata.init.ClassPathResourceMetadataLoader;
21 import com.google.i18n.phonenumbers.metadata.init.MetadataParser;
22 import com.google.i18n.phonenumbers.metadata.source.FormattingMetadataSource;
23 import com.google.i18n.phonenumbers.metadata.source.FormattingMetadataSourceImpl;
24 import com.google.i18n.phonenumbers.metadata.source.MetadataSource;
25 import com.google.i18n.phonenumbers.metadata.source.MetadataSourceImpl;
26 import com.google.i18n.phonenumbers.metadata.source.MultiFileModeFileNameProvider;
27 import com.google.i18n.phonenumbers.metadata.source.PhoneMetadataFileNameProvider;
28 import com.google.i18n.phonenumbers.metadata.source.RegionMetadataSource;
29 import com.google.i18n.phonenumbers.metadata.source.RegionMetadataSourceImpl;
30 
31 /**
32  * Provides metadata init and source dependencies when metadata is stored in multi-file mode and
33  * loaded as a classpath resource.
34  */
35 public final class DefaultMetadataDependenciesProvider {
36 
37   private static final DefaultMetadataDependenciesProvider INSTANCE = new DefaultMetadataDependenciesProvider();
38 
getInstance()39   public static DefaultMetadataDependenciesProvider getInstance() {
40     return INSTANCE;
41   }
42 
DefaultMetadataDependenciesProvider()43   private DefaultMetadataDependenciesProvider() {
44   }
45 
46   private final MetadataParser metadataParser = MetadataParser.newLenientParser();
47   private final MetadataLoader metadataLoader = new ClassPathResourceMetadataLoader();
48 
49   private final PhoneMetadataFileNameProvider phoneNumberMetadataFileNameProvider =
50       new MultiFileModeFileNameProvider(
51           "/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto");
52   private final MetadataSource phoneNumberMetadataSource =
53       new MetadataSourceImpl(
54           phoneNumberMetadataFileNameProvider,
55           metadataLoader,
56           metadataParser);
57 
58   private final PhoneMetadataFileNameProvider shortNumberMetadataFileNameProvider =
59       new MultiFileModeFileNameProvider(
60           "/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto");
61   private final RegionMetadataSource shortNumberMetadataSource =
62       new RegionMetadataSourceImpl(
63           shortNumberMetadataFileNameProvider,
64           metadataLoader,
65           metadataParser);
66 
67   private final PhoneMetadataFileNameProvider alternateFormatsMetadataFileNameProvider =
68       new MultiFileModeFileNameProvider(
69           "/com/google/i18n/phonenumbers/data/PhoneNumberAlternateFormatsProto");
70   private final FormattingMetadataSource alternateFormatsMetadataSource =
71       new FormattingMetadataSourceImpl(
72           alternateFormatsMetadataFileNameProvider,
73           metadataLoader,
74           metadataParser);
75 
getMetadataParser()76   public MetadataParser getMetadataParser() {
77     return metadataParser;
78   }
79 
getMetadataLoader()80   public MetadataLoader getMetadataLoader() {
81     return metadataLoader;
82   }
83 
getPhoneNumberMetadataFileNameProvider()84   public PhoneMetadataFileNameProvider getPhoneNumberMetadataFileNameProvider() {
85     return phoneNumberMetadataFileNameProvider;
86   }
87 
getPhoneNumberMetadataSource()88   public MetadataSource getPhoneNumberMetadataSource() {
89     return phoneNumberMetadataSource;
90   }
91 
getShortNumberMetadataFileNameProvider()92   public PhoneMetadataFileNameProvider getShortNumberMetadataFileNameProvider() {
93     return shortNumberMetadataFileNameProvider;
94   }
95 
getShortNumberMetadataSource()96   public RegionMetadataSource getShortNumberMetadataSource() {
97     return shortNumberMetadataSource;
98   }
99 
getAlternateFormatsMetadataFileNameProvider()100   public PhoneMetadataFileNameProvider getAlternateFormatsMetadataFileNameProvider() {
101     return alternateFormatsMetadataFileNameProvider;
102   }
103 
getAlternateFormatsMetadataSource()104   public FormattingMetadataSource getAlternateFormatsMetadataSource() {
105     return alternateFormatsMetadataSource;
106   }
107 
getCarrierDataDirectory()108   public String getCarrierDataDirectory() {
109     return "/com/google/i18n/phonenumbers/carrier/data/";
110   }
111 
getGeocodingDataDirectory()112   public String getGeocodingDataDirectory() {
113     return "/com/google/i18n/phonenumbers/geocoding/data/";
114   }
115 }
116