1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements.  See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership.  The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License.  You may obtain a copy of the License at
10 *
11 *   http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied.  See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21 
22 package org.apache.openoffice.ooxml.schema.model.base;
23 
24 import javax.xml.namespace.QName;
25 
26 /** Similar to the QName class.  A qualified name that consists of the local
27  *  part and a namespace.
28  *  The namespace is stored both as URI and short form (prefix).
29  */
30 public class QualifiedName
31     implements Comparable<QualifiedName>
32 {
QualifiedName(final QName aName)33     public QualifiedName (final QName aName)
34     {
35         msLocalPart = aName.getLocalPart();
36         msNamespacePrefix = aName.getPrefix();
37         msNamespaceURI = aName.getNamespaceURI();
38     }
39 
40 
41 
42 
QualifiedName( final String sNamespaceURI, final String sNamespacePrefix, final String sLocalPart)43     public QualifiedName (
44         final String sNamespaceURI,
45         final String sNamespacePrefix,
46         final String sLocalPart)
47     {
48         msLocalPart = sLocalPart;
49         msNamespacePrefix = sNamespacePrefix;
50         msNamespaceURI = sNamespaceURI;
51     }
52 
53 
54 
55 
QualifiedName(final String sLocalPart)56     public QualifiedName (final String sLocalPart)
57     {
58         this(null, null, sLocalPart);
59     }
60 
61 
62 
63 
64     /** Return a textual representation for informal (and informative) display.
65      */
GetDisplayName()66     public String GetDisplayName ()
67     {
68         if (msNamespacePrefix == null)
69             return msLocalPart;
70         else
71             return msNamespacePrefix + ":" + msLocalPart;
72     }
73 
74 
75 
76 
GetStateName()77     public String GetStateName()
78     {
79         if (msNamespacePrefix == null)
80             return msLocalPart;
81         else
82             return msNamespacePrefix + "_" + msLocalPart;
83     }
84 
85 
86 
87 
GetNamespaceURI()88     public String GetNamespaceURI ()
89     {
90         return msNamespaceURI;
91     }
92 
93 
94 
95 
GetNamespacePrefix()96     public String GetNamespacePrefix ()
97     {
98         return msNamespacePrefix;
99     }
100 
101 
102 
103 
GetLocalPart()104     public String GetLocalPart ()
105     {
106         return msLocalPart;
107     }
108 
109 
110 
111 
112     /** Compare QualifiedName objects (e.g. for sorting them).
113      *  Primary sort key is the local part.
114      *  Secondary key is the namespace prefix.
115      *  Missing prefixes come before existing prefixes.
116      */
117     @Override
compareTo(final QualifiedName aOther)118     public int compareTo (final QualifiedName aOther)
119     {
120         final int nComparisonResult = msLocalPart.compareTo(aOther.msLocalPart);
121         if (nComparisonResult != 0)
122             return nComparisonResult;
123         else
124             if (msNamespacePrefix==null && aOther.msNamespacePrefix==null)
125                 return 0;
126             else if (msNamespacePrefix!=null && aOther.msNamespacePrefix!=null)
127                 return msNamespacePrefix.compareTo(aOther.msNamespacePrefix);
128             else if (msNamespacePrefix==null)
129                 return -1;
130             else
131                 return +1;
132     }
133 
134 
135 
136 
137     @Override
toString()138     public String toString ()
139     {
140         return GetDisplayName();
141     }
142 
143 
144 
145 
146     private final String msLocalPart;
147     private final String msNamespacePrefix;
148     private final String msNamespaceURI;
149 }
150