View Javadoc

1   /**
2    *
3    */
4   package javax.jmdns.impl;
5   
6   import java.net.InetAddress;
7   
8   /**
9    *
10   */
11  public interface NameRegister {
12  
13      /**
14       *
15       */
16      public enum NameType {
17          /**
18           * This name represents a host name
19           */
20          HOST,
21          /**
22           * This name represents a service name
23           */
24          SERVICE,
25      }
26  
27      public static class UniqueNamePerInterface implements NameRegister {
28  
29          /*
30           * (non-Javadoc)
31           * @see javax.jmdns.impl.NameRegister#register(java.net.InetAddress, java.lang.String, javax.jmdns.impl.NameRegister.NameType)
32           */
33          @Override
34          public void register(InetAddress networkInterface, String name, NameType type) {
35              // TODO Auto-generated method stub
36  
37          }
38  
39          /*
40           * (non-Javadoc)
41           * @see javax.jmdns.impl.NameRegister#checkName(java.net.InetAddress, java.lang.String, javax.jmdns.impl.NameRegister.NameType)
42           */
43          @Override
44          public boolean checkName(InetAddress networkInterface, String name, NameType type) {
45              // TODO Auto-generated method stub
46              return false;
47          }
48  
49          /*
50           * (non-Javadoc)
51           * @see javax.jmdns.impl.NameRegister#incrementHostName(java.net.InetAddress, java.lang.String, javax.jmdns.impl.NameRegister.NameType)
52           */
53          @Override
54          public String incrementHostName(InetAddress networkInterface, String name, NameType type) {
55              // TODO Auto-generated method stub
56              return null;
57          }
58  
59      }
60  
61      public static class UniqueNameAcrossInterface implements NameRegister {
62  
63          /*
64           * (non-Javadoc)
65           * @see javax.jmdns.impl.NameRegister#register(java.net.InetAddress, java.lang.String, javax.jmdns.impl.NameRegister.NameType)
66           */
67          @Override
68          public void register(InetAddress networkInterface, String name, NameType type) {
69              // TODO Auto-generated method stub
70  
71          }
72  
73          /*
74           * (non-Javadoc)
75           * @see javax.jmdns.impl.NameRegister#checkName(java.net.InetAddress, java.lang.String, javax.jmdns.impl.NameRegister.NameType)
76           */
77          @Override
78          public boolean checkName(InetAddress networkInterface, String name, NameType type) {
79              // TODO Auto-generated method stub
80              return false;
81          }
82  
83          /*
84           * (non-Javadoc)
85           * @see javax.jmdns.impl.NameRegister#incrementHostName(java.net.InetAddress, java.lang.String, javax.jmdns.impl.NameRegister.NameType)
86           */
87          @Override
88          public String incrementHostName(InetAddress networkInterface, String name, NameType type) {
89              // TODO Auto-generated method stub
90              return null;
91          }
92  
93      }
94  
95      public static class Factory {
96  
97          private static volatile NameRegister _register;
98  
99          /**
100          * Register a Name register.
101          *
102          * @param register
103          *            new register
104          * @throws IllegalStateException
105          *             the register can only be set once
106          */
107         public static void setRegistry(NameRegister register) throws IllegalStateException {
108             if (_register != null) {
109                 throw new IllegalStateException("The register can only be set once.");
110             }
111             if (register != null) {
112                 _register = register;
113             }
114         }
115 
116         /**
117          * Returns the name register.
118          *
119          * @return name register
120          */
121         public static NameRegister getRegistry() {
122             if (_register == null) {
123                 _register = new UniqueNamePerInterface();
124             }
125             return _register;
126         }
127 
128     }
129 
130     /**
131      * Registers a name that is defended by this group of mDNS.
132      *
133      * @param networkInterface
134      *            IP address to handle
135      * @param name
136      *            name to register
137      * @param type
138      *            name type to register
139      */
140     public abstract void register(InetAddress networkInterface, String name, NameType type);
141 
142     /**
143      * Checks a name that is defended by this group of mDNS.
144      *
145      * @param networkInterface
146      *            IP address to handle
147      * @param name
148      *            name to check
149      * @param type
150      *            name type to check
151      * @return <code>true</code> if the name is not in conflict, <code>flase</code> otherwise.
152      */
153     public abstract boolean checkName(InetAddress networkInterface, String name, NameType type);
154 
155     /**
156      * Increments a name that is defended by this group of mDNS after it has been found in conflict.
157      *
158      * @param networkInterface
159      *            IP address to handle
160      * @param name
161      *            name to increment
162      * @param type
163      *            name type to increments
164      * @return new name
165      */
166     public abstract String incrementHostName(InetAddress networkInterface, String name, NameType type);
167 
168 }