KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > util > impl > NamespaceMapperImpl


1 /*
2  * Copyright 2003,2004 The Apache Software Foundation.
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
18  */

19
20 package org.apache.pluto.util.impl;
21
22 import org.apache.pluto.om.common.ObjectID;
23 import org.apache.pluto.util.NamespaceMapper;
24
25 /**
26  **/

27
28 public class NamespaceMapperImpl implements NamespaceMapper
29 {
30     public NamespaceMapperImpl()
31     {
32     }
33
34     // org.apache.pluto.util.NamespaceMapper implementation ---------------------------------------
35
public String JavaDoc encode(ObjectID ns, String JavaDoc name)
36     {
37         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(50);
38         buffer.append("Pluto_");
39         buffer.append(ns);
40         buffer.append('_');
41         buffer.append(name);
42         return buffer.toString();
43     }
44
45     public String JavaDoc encode(ObjectID ns1, ObjectID ns2, String JavaDoc name)
46     {
47         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(50);
48         buffer.append("Pluto_");
49         buffer.append(ns1);
50         buffer.append('_');
51         buffer.append(ns2);
52         buffer.append('_');
53         buffer.append(name);
54         return buffer.toString();
55     }
56
57     public String JavaDoc decode(ObjectID ns, String JavaDoc name)
58     {
59         if (!name.startsWith("Pluto_"))
60         {
61             return null;
62         }
63         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(50);
64         buffer.append("Pluto_");
65         buffer.append(ns);
66         buffer.append('_');
67         if (!name.startsWith(buffer.toString()))
68         {
69             return null;
70         }
71         return name.substring(buffer.length());
72     }
73     // --------------------------------------------------------------------------------------------
74
}
75
Popular Tags