View Javadoc
1   /*
2     (C) Copyright IBM Corp. 2006, 2009
3   
4     THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
5     ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
6     CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
7   
8     You can obtain a current copy of the Eclipse Public License from
9     http://www.opensource.org/licenses/eclipse-1.0.php
10  
11    @author : Endre Bak, ebak@de.ibm.com
12   * 
13   * Flag       Date        Prog         Description
14   * -------------------------------------------------------------------------------
15   * 1565892    2006-12-04  ebak         Make SBLIM client JSR48 compliant
16   * 2003590    2008-06-30  blaschke-oss Change licensing from CPL to EPL
17   * 2524131    2009-01-21  raman_arora  Upgrade client to JDK 1.5 (Phase 1)
18   * 2797550    2009-06-01  raman_arora  JSR48 compliance - add Java Generics
19   */
20  
21  package org.metricshub.wbem.sblim.cimclient.internal.cimxml;
22  
23  /*-
24   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
25   * WBEM Java Client
26   * ჻჻჻჻჻჻
27   * Copyright 2023 - 2025 MetricsHub
28   * ჻჻჻჻჻჻
29   * Licensed under the Apache License, Version 2.0 (the "License");
30   * you may not use this file except in compliance with the License.
31   * You may obtain a copy of the License at
32   *
33   *      http://www.apache.org/licenses/LICENSE-2.0
34   *
35   * Unless required by applicable law or agreed to in writing, software
36   * distributed under the License is distributed on an "AS IS" BASIS,
37   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38   * See the License for the specific language governing permissions and
39   * limitations under the License.
40   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
41   */
42  
43  import org.metricshub.wbem.javax.cim.CIMObjectPath;
44  import org.metricshub.wbem.javax.cim.CIMProperty;
45  
46  /**
47   * Class LocalPathBuilder helps CIM-XML parsers to build local CIMObjectPathes.
48   */
49  public class LocalPathBuilder {
50  	private CIMObjectPath iBasePath;
51  
52  	/**
53  	 * Ctor.
54  	 *
55  	 * @param pBasePath
56  	 */
57  	public LocalPathBuilder(CIMObjectPath pBasePath) {
58  		this.iBasePath = pBasePath;
59  	}
60  
61  	/**
62  	 * getBasePath
63  	 *
64  	 * @return CIMObjectPath
65  	 */
66  	public CIMObjectPath getBasePath() {
67  		return this.iBasePath;
68  	}
69  
70  	/**
71  	 * build
72  	 *
73  	 * @param pObjPathStr
74  	 * @return CIMObjectPath
75  	 */
76  	public CIMObjectPath build(String pObjPathStr) {
77  		return build(this.iBasePath, pObjPathStr);
78  	}
79  
80  	/**
81  	 * build
82  	 *
83  	 * @param pObjName
84  	 * @param pNameSpace
85  	 * @return CIMObjectPath
86  	 */
87  	public CIMObjectPath build(String pObjName, String pNameSpace) {
88  		return build(this.iBasePath, pObjName, pNameSpace);
89  	}
90  
91  	/**
92  	 * build
93  	 *
94  	 * @param pObjName
95  	 * @param pNameSpace
96  	 * @param pKeys
97  	 * @return CIMObjectPath
98  	 */
99  	public CIMObjectPath build(String pObjName, String pNameSpace, CIMProperty<?>[] pKeys) {
100 		return build(this.iBasePath, pObjName, pNameSpace, pKeys);
101 	}
102 
103 	/**
104 	 * build
105 	 *
106 	 * @param pHost
107 	 * @param pNameSpace
108 	 * @param pObjName
109 	 * @param pKeys
110 	 * @return CIMObjectPath
111 	 */
112 	public CIMObjectPath build(String pHost, String pNameSpace, String pObjName, CIMProperty<?>[] pKeys) {
113 		return build(this.iBasePath, pHost, pNameSpace, pObjName, pKeys);
114 	}
115 
116 	/**
117 	 * build
118 	 *
119 	 * @param pScheme
120 	 * @param pHost
121 	 * @param pPort
122 	 * @param pNameSpace
123 	 * @param pObjName
124 	 * @param pKeys
125 	 * @return CIMObjectPath
126 	 */
127 	public CIMObjectPath build(
128 		String pScheme,
129 		String pHost,
130 		String pPort,
131 		String pNameSpace,
132 		String pObjName,
133 		CIMProperty<?>[] pKeys
134 	) {
135 		return build(this.iBasePath, pScheme, pHost, pPort, pNameSpace, pObjName, pKeys);
136 	}
137 
138 	/**
139 	 * build
140 	 *
141 	 * @param pBasePath
142 	 * @param pObjPathStr
143 	 * @return CIMObjectPath
144 	 */
145 	public static CIMObjectPath build(CIMObjectPath pBasePath, String pObjPathStr) {
146 		CIMObjectPath path = new CIMObjectPath(pObjPathStr);
147 		return build(
148 			pBasePath,
149 			path.getScheme(),
150 			path.getHost(),
151 			path.getPort(),
152 			path.getNamespace(),
153 			path.getObjectName(),
154 			path.getKeys()
155 		);
156 	}
157 
158 	/**
159 	 * build
160 	 *
161 	 * @param pBasePath
162 	 * @param pObjName
163 	 * @param pNameSpace
164 	 * @return CIMObjectPath
165 	 */
166 	public static CIMObjectPath build(CIMObjectPath pBasePath, String pObjName, String pNameSpace) {
167 		return build(pBasePath, null, null, null, pNameSpace, pObjName, null);
168 	}
169 
170 	/**
171 	 * build
172 	 *
173 	 * @param pBasePath
174 	 * @param pObjName
175 	 * @param pNameSpace
176 	 * @param pKeys
177 	 * @return CIMObjectPath
178 	 */
179 	public static CIMObjectPath build(
180 		CIMObjectPath pBasePath,
181 		String pObjName,
182 		String pNameSpace,
183 		CIMProperty<?>[] pKeys
184 	) {
185 		return build(pBasePath, null, null, null, pNameSpace, pObjName, pKeys);
186 	}
187 
188 	/**
189 	 * build
190 	 *
191 	 * @param pBasePath
192 	 * @param pHost
193 	 * @param pNameSpace
194 	 * @param pObjName
195 	 * @param pKeys
196 	 * @return CIMObjectPath
197 	 */
198 	public static CIMObjectPath build(
199 		CIMObjectPath pBasePath,
200 		String pHost,
201 		String pNameSpace,
202 		String pObjName,
203 		CIMProperty<?>[] pKeys
204 	) {
205 		return build(pBasePath, null, pHost, null, pNameSpace, pObjName, pKeys);
206 	}
207 
208 	/**
209 	 * build
210 	 *
211 	 * @param pBasePath
212 	 * @param pScheme
213 	 * @param pHost
214 	 * @param pPort
215 	 * @param pNameSpace
216 	 * @param pObjName
217 	 * @param pKeys
218 	 * @return CIMObjectPath
219 	 */
220 	public static CIMObjectPath build(
221 		CIMObjectPath pBasePath,
222 		String pScheme,
223 		String pHost,
224 		String pPort,
225 		String pNameSpace,
226 		String pObjName,
227 		CIMProperty<?>[] pKeys
228 	) {
229 		if (pBasePath == null) return new CIMObjectPath(pScheme, pHost, pPort, pNameSpace, pObjName, pKeys);
230 		return new CIMObjectPath(
231 			pScheme == null ? pBasePath.getScheme() : pScheme,
232 			pHost == null ? pBasePath.getHost() : pHost,
233 			pPort == null ? pBasePath.getPort() : pPort,
234 			pNameSpace == null ? pBasePath.getNamespace() : pNameSpace,
235 			pObjName == null ? pBasePath.getObjectName() : pObjName,
236 			pKeys // local
237 			// objectpath shouldn't contain keys
238 		);
239 	}
240 }