diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 55aed6a..62baa53 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,7 +18,7 @@ on: jobs: build: - uses: sentrysoftware/workflows/.github/workflows/maven-build.yml@v3 + uses: metricshub/workflows/.github/workflows/maven-build.yml@v2 with: jdkVersion: "17" debug: ${{ github.event_name == 'workflow_dispatch' && inputs.debug }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5a72abb..cf17156 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -10,7 +10,7 @@ on: jobs: deploy: - uses: sentrysoftware/workflows/.github/workflows/maven-central-deploy.yml@v3 + uses: metricshub/workflows/.github/workflows/maven-central-deploy.yml@v2 with: jdkVersion: "17" secrets: inherit diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 14d640c..ba8ec25 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ on: jobs: release: - uses: sentrysoftware/workflows/.github/workflows/maven-central-release.yml@v3 + uses: metricshub/workflows/.github/workflows/maven-central-release.yml@v2 with: releaseVersion: ${{ inputs.releaseVersion }} developmentVersion: ${{ inputs.developmentVersion }} diff --git a/README.md b/README.md index 62df03a..6845666 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # WBEM Java Client -![GitHub release (with filter)](https://img.shields.io/github/v/release/sentrysoftware/wbem) -![Build](https://img.shields.io/github/actions/workflow/status/sentrysoftware/wbem/deploy.yml) -![GitHub top language](https://img.shields.io/github/languages/top/sentrysoftware/wbem) -![License](https://img.shields.io/github/license/sentrysoftware/wbem) +![GitHub release (with filter)](https://img.shields.io/github/v/release/metricshub/wbem-java) +![Build](https://img.shields.io/github/actions/workflow/status/metricshub/wbem-java/deploy.yml) +![GitHub top language](https://img.shields.io/github/languages/top/metricshub/wbem-java) +![License](https://img.shields.io/github/license/metricshub/wbem-java) This project is a fork of the excellent [Standards Based Linux Instrumentation](https://sourceforge.net/projects/sblim/) ([see also](https://sblim.sourceforge.net/wiki/index.php/Main_Page)). -See **[Project Documentation](https://sentrysoftware.org/wbem)** and the [Javadoc](https://sentrysoftware.org/wbem/apidocs) for more information on how to use this library in your code. +See **[Project Documentation](https://metricshub.org/wbem-java)** and the [Javadoc](https://metricshub.org/wbem-java/apidocs) for more information on how to use this library in your code. The Web-Based Enterprise Management (WBEM) Java Client is a library that enables to: * Connect to a WBEM Server diff --git a/checkstyle.xml b/checkstyle.xml index 2098fe6..cf46deb 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -46,30 +46,18 @@ - + - - - - - - - - - - - - @@ -92,15 +80,8 @@ - - - - - - - @@ -123,19 +104,13 @@ - - - - - - @@ -143,33 +118,24 @@ - - - - - - - - - + - @@ -179,43 +145,21 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/pom.xml b/pom.xml index 438686f..1867c0d 100644 --- a/pom.xml +++ b/pom.xml @@ -2,24 +2,24 @@ 4.0.0 - org.sentrysoftware + org.metricshub oss-parent 2 - org.sentrysoftware - wbem + org.metricshub + wbem-java 1.1.00-SNAPSHOT WBEM Java Client WBEM Java Client - Sentry Software - https://sentrysoftware.com + MetricsHub + https://metricshub.com - https://sentrysoftware.org/wbem + https://metricshub.org/wbem-java 2023 @@ -32,33 +32,26 @@ GitHub - https://github.com/sentrysoftware/wbem/issues/ + https://github.com/metricshub/wbem-java/issues/ - scm:git:https://github.com/sentrysoftware/wbem.git - https://github.com/sentrysoftware/wbem + scm:git:https://github.com/metricshub/wbem-java.git + https://github.com/metricshub/wbem-java HEAD Bertrand Martin (@bertysentry) - bertrand@sentrysoftware.com + bertrand@metricshub.com maintainer Nassim BOUTEKEDJIRET (@NassimBtk) - nassim@sentrysoftware.com - - maintainer - - - - Kawtar Bakour (@KawtarBK9) - kawtar@sentrysoftware.com + nassim@metricshub.com maintainer @@ -126,30 +119,13 @@ ${maven.compiler.target} public true - org.sentrysoftware.wbem.javax.*:org.sentrysoftware.wbem.sblim.* + org.metricshub.wbem.javax.*:org.metricshub.wbem.sblim.* - - - - - - maven-site-plugin - - - org.sentrysoftware.maven - maven-skin-tools - 1.2.00 - - - - - - diff --git a/src/main/java/org/sentrysoftware/wbem/client/Utils.java b/src/main/java/org/metricshub/wbem/client/Utils.java similarity index 70% rename from src/main/java/org/sentrysoftware/wbem/client/Utils.java rename to src/main/java/org/metricshub/wbem/client/Utils.java index a1c27ff..7d1e072 100644 --- a/src/main/java/org/sentrysoftware/wbem/client/Utils.java +++ b/src/main/java/org/metricshub/wbem/client/Utils.java @@ -1,106 +1,102 @@ -package org.sentrysoftware.wbem.client; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.time.LocalDateTime; -import java.time.OffsetDateTime; -import java.time.ZoneOffset; -import java.time.format.DateTimeFormatter; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class Utils { - - /** - * Check if the required argument is not null. - * - * @param argument - * @param name - * @throws IllegalArgumentException if the argument is null - */ - public static void checkNonNull(final T argument, final String name) { - if (argument == null) { - throw new IllegalArgumentException(name + " must not be null."); - } - } - - /** - * Default separator for array values - */ - public static final String DEFAULT_ARRAY_SEPARATOR = "|"; - - public static final String EMPTY = ""; - - /** - * Formatter/Parser of the first part of CIM_DATETIME - */ - public static final DateTimeFormatter WBEM_CIM_DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); - - /** - * Regex that matches with a CIM_DATETIME string format See - * https://docs.microsoft.com/en-us/windows/win32/wmisdk/cim-datetime - *
    - *
  • group(1): yyyymmddHHMMSS - *
  • group(2): optional fraction of seconds - *
  • group(3): timezone offset... in minutes (sigh) - */ - private static final Pattern CIM_DATETIME_PATTERN = Pattern - .compile("^([0-9]{14})(?:\\.([0-9]{3,6}))?([+-][0-9]{3})$"); - - /** - * Convert a String holding a CIM_DATETIME (i.e. a string in the form of - * yyyymmddHHMMSS.mmmmmmsUUU) to an OffsetDateTime object - * - * @param stringValue String value with a CIM_DATETIME - * @return OffsetDateTime instance - */ - public static OffsetDateTime convertCimDateTime(final String stringValue) { - - if (stringValue == null) { - return null; - } - - final Matcher dateTimeMatcher = CIM_DATETIME_PATTERN.matcher(stringValue); - if (!dateTimeMatcher.find()) { - throw new IllegalArgumentException("Not a valid CIM_DATETIME value: " + stringValue); - } - - // LocalDateTime - final LocalDateTime localDateTime = LocalDateTime.parse(dateTimeMatcher.group(1), WBEM_CIM_DATETIME_FORMATTER); - - // Note: we're not taking the milliseconds and microseconds into account from - // group(2) - - // Zone Offset - final String zoneOffset = dateTimeMatcher.group(3); - if (zoneOffset == null) { - throw new IllegalStateException( - "Unable to get the timezone offset from CIM_DATETIME value: " + stringValue); - } - final int secondsOffset = Integer.parseInt(zoneOffset) * 60; - final ZoneOffset offset = ZoneOffset.ofTotalSeconds(secondsOffset); - - return OffsetDateTime.of(localDateTime, offset); - } - -} +package org.metricshub.wbem.client; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.time.LocalDateTime; +import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Utils { + + /** + * Check if the required argument is not null. + * + * @param argument + * @param name + * @throws IllegalArgumentException if the argument is null + */ + public static void checkNonNull(final T argument, final String name) { + if (argument == null) { + throw new IllegalArgumentException(name + " must not be null."); + } + } + + /** + * Default separator for array values + */ + public static final String DEFAULT_ARRAY_SEPARATOR = "|"; + + public static final String EMPTY = ""; + + /** + * Formatter/Parser of the first part of CIM_DATETIME + */ + public static final DateTimeFormatter WBEM_CIM_DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); + + /** + * Regex that matches with a CIM_DATETIME string format See + * https://docs.microsoft.com/en-us/windows/win32/wmisdk/cim-datetime + *
      + *
    • group(1): yyyymmddHHMMSS + *
    • group(2): optional fraction of seconds + *
    • group(3): timezone offset... in minutes (sigh) + */ + private static final Pattern CIM_DATETIME_PATTERN = Pattern.compile( + "^([0-9]{14})(?:\\.([0-9]{3,6}))?([+-][0-9]{3})$" + ); + + /** + * Convert a String holding a CIM_DATETIME (i.e. a string in the form of + * yyyymmddHHMMSS.mmmmmmsUUU) to an OffsetDateTime object + * + * @param stringValue String value with a CIM_DATETIME + * @return OffsetDateTime instance + */ + public static OffsetDateTime convertCimDateTime(final String stringValue) { + if (stringValue == null) { + return null; + } + + final Matcher dateTimeMatcher = CIM_DATETIME_PATTERN.matcher(stringValue); + if (!dateTimeMatcher.find()) { + throw new IllegalArgumentException("Not a valid CIM_DATETIME value: " + stringValue); + } + + // LocalDateTime + final LocalDateTime localDateTime = LocalDateTime.parse(dateTimeMatcher.group(1), WBEM_CIM_DATETIME_FORMATTER); + + // Note: we're not taking the milliseconds and microseconds into account from + // group(2) + + // Zone Offset + final String zoneOffset = dateTimeMatcher.group(3); + if (zoneOffset == null) { + throw new IllegalStateException("Unable to get the timezone offset from CIM_DATETIME value: " + stringValue); + } + final int secondsOffset = Integer.parseInt(zoneOffset) * 60; + final ZoneOffset offset = ZoneOffset.ofTotalSeconds(secondsOffset); + + return OffsetDateTime.of(localDateTime, offset); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/client/WbemCimDataHandler.java b/src/main/java/org/metricshub/wbem/client/WbemCimDataHandler.java similarity index 60% rename from src/main/java/org/sentrysoftware/wbem/client/WbemCimDataHandler.java rename to src/main/java/org/metricshub/wbem/client/WbemCimDataHandler.java index e97dfc3..2495289 100644 --- a/src/main/java/org/sentrysoftware/wbem/client/WbemCimDataHandler.java +++ b/src/main/java/org/metricshub/wbem/client/WbemCimDataHandler.java @@ -1,185 +1,186 @@ -package org.sentrysoftware.wbem.client; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMDateTimeAbsolute; -import org.sentrysoftware.wbem.javax.cim.CIMDateTimeInterval; -import org.sentrysoftware.wbem.javax.cim.CIMInstance; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import org.sentrysoftware.wbem.javax.cim.CIMProperty; - -/** - * Handler for CIMProperty conversion to string. - * - */ -public class WbemCimDataHandler { - - private WbemCimDataHandler() { } - - public static final String PATH_PROPERTY = "__Path"; - - private static final Map> CONVERT_MAP; - static { - final Map> map = new HashMap<>(); - map.put(CIMDataType.STRING, String::valueOf); - map.put(CIMDataType.BOOLEAN, String::valueOf); - map.put(CIMDataType.SINT8, String::valueOf); - map.put(CIMDataType.SINT16, String::valueOf); - map.put(CIMDataType.SINT32, String::valueOf); - map.put(CIMDataType.SINT64, String::valueOf); - map.put(CIMDataType.CHAR16, String::valueOf); - map.put(CIMDataType.REAL32, String::valueOf); - map.put(CIMDataType.REAL64, String::valueOf); - map.put(CIMDataType.OBJECT, String::valueOf); - map.put(CIMDataType.DATETIME, WbemCimDataHandler::convertDateTime); - map.put(CIMDataType.UINT8, String::valueOf); - map.put(CIMDataType.UINT16, String::valueOf); - map.put(CIMDataType.UINT32, String::valueOf); - map.put(CIMDataType.UINT64, String::valueOf); - map.put(CIMDataType.REFERENCE, WbemCimDataHandler::convertReference); - CONVERT_MAP = Collections.unmodifiableMap(map); - } - - /** - * Get the value of the CIM property. - * - * @param property The property name. - * @param cimInstance The CIM instance. - * @param arraySeparator The array separator value. default value '|' - * @return - */ - public static String getCimPropertyAsString( - final String property, - final CIMInstance cimInstance, - final String arraySeparator) { - Utils.checkNonNull(property, "property"); - Utils.checkNonNull(cimInstance, "cimInstance"); - - if (PATH_PROPERTY.equalsIgnoreCase(property)) { - final CIMObjectPath objectPath = cimInstance.getObjectPath(); - Utils.checkNonNull(objectPath, "objectPath"); - return convertReference(objectPath); - } - - // first check getProperty - CIMProperty cimProperty = cimInstance.getProperty(property); - - // then, if null, check getKeys - final String separator = arraySeparator == null? Utils.DEFAULT_ARRAY_SEPARATOR : arraySeparator; - if (cimProperty == null && cimInstance.getKeys() != null) { - return Stream.of(cimInstance.getKeys()) - .filter(key -> key.getName() != null && key.getName().equalsIgnoreCase(property)) - .findFirst() - .map(cp -> convertCimPropertyValue(cp, separator)) - .orElse(Utils.EMPTY); - } - - return cimProperty == null ? - Utils.EMPTY : convertCimPropertyValue(cimProperty, separator); - } - - /** - * Convert the CIM property value into a String. - * - * @param cimProperty The CIM property. - * @param arraySeparator The array separator value. - * @return - */ - private static String convertCimPropertyValue( - final CIMProperty cimProperty, - final String arraySeparator) { - final Object cimPropertyValue = cimProperty.getValue(); - if (cimPropertyValue == null) { - return Utils.EMPTY; - } - - final CIMDataType dataType = cimProperty.getDataType(); - if (dataType == null) { - return cimPropertyValue.toString(); - } - - return dataType.isArray() ? - convertArray(cimProperty, arraySeparator) : - CONVERT_MAP.getOrDefault(dataType.getType(), Object::toString).apply(cimPropertyValue); - } - - /** - * Convert a CIM property value array. - * - * @param cimProperty The CIM property. - * @param arraySeparator The array separator value. - * @return - */ - private static String convertArray( - final CIMProperty cimProperty, - final String arraySeparator) { - return Arrays.stream((Object[]) cimProperty.getValue()) - .map(obj -> (obj == null) ? Utils.EMPTY : CONVERT_MAP.getOrDefault(cimProperty.getDataType().getType(), Object::toString).apply(obj)) - .collect(Collectors.joining(arraySeparator, Utils.EMPTY, arraySeparator)); - } - - /** - * Convert a CIMObjectPath reference to string: - *
    • take the part after ':'
    • - *
    • escape back slash
    • - *
    • escape double quotes
    • - * - * @param cimPropertyValue - * @return - */ - private static String convertReference(final Object cimPropertyValue) { - final CIMObjectPath objectPath = (CIMObjectPath) cimPropertyValue; - final String str = objectPath.toString(); - return str - .substring(str.indexOf(':') + 1) // take the part after : (if exists) - .replace("\\\\", "\\") // Replace \\ by \ - .replace("\\\"", "\""); // Replace \" by " - } - - /** - * Convert a CIMDateTime into a string containing to Epoch time milliseconds. - * - * @param cimPropertyValue - * @return - */ - private static String convertDateTime(final Object cimPropertyValue) { - if (cimPropertyValue == null) { - return Utils.EMPTY; - } - - if (cimPropertyValue instanceof CIMDateTimeAbsolute) { - final String dateTimeString = ((CIMDateTimeAbsolute) cimPropertyValue).getDateTimeString(); - return String.valueOf(Utils.convertCimDateTime(dateTimeString).toInstant().toEpochMilli()); - } - return String.valueOf(((CIMDateTimeInterval) cimPropertyValue).getTotalMilliseconds()); - } -} +package org.metricshub.wbem.client; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMDateTimeAbsolute; +import org.metricshub.wbem.javax.cim.CIMDateTimeInterval; +import org.metricshub.wbem.javax.cim.CIMInstance; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.cim.CIMProperty; + +/** + * Handler for CIMProperty conversion to string. + * + */ +public class WbemCimDataHandler { + + private WbemCimDataHandler() {} + + public static final String PATH_PROPERTY = "__Path"; + + private static final Map> CONVERT_MAP; + + static { + final Map> map = new HashMap<>(); + map.put(CIMDataType.STRING, String::valueOf); + map.put(CIMDataType.BOOLEAN, String::valueOf); + map.put(CIMDataType.SINT8, String::valueOf); + map.put(CIMDataType.SINT16, String::valueOf); + map.put(CIMDataType.SINT32, String::valueOf); + map.put(CIMDataType.SINT64, String::valueOf); + map.put(CIMDataType.CHAR16, String::valueOf); + map.put(CIMDataType.REAL32, String::valueOf); + map.put(CIMDataType.REAL64, String::valueOf); + map.put(CIMDataType.OBJECT, String::valueOf); + map.put(CIMDataType.DATETIME, WbemCimDataHandler::convertDateTime); + map.put(CIMDataType.UINT8, String::valueOf); + map.put(CIMDataType.UINT16, String::valueOf); + map.put(CIMDataType.UINT32, String::valueOf); + map.put(CIMDataType.UINT64, String::valueOf); + map.put(CIMDataType.REFERENCE, WbemCimDataHandler::convertReference); + CONVERT_MAP = Collections.unmodifiableMap(map); + } + + /** + * Get the value of the CIM property. + * + * @param property The property name. + * @param cimInstance The CIM instance. + * @param arraySeparator The array separator value. default value '|' + * @return + */ + public static String getCimPropertyAsString( + final String property, + final CIMInstance cimInstance, + final String arraySeparator + ) { + Utils.checkNonNull(property, "property"); + Utils.checkNonNull(cimInstance, "cimInstance"); + + if (PATH_PROPERTY.equalsIgnoreCase(property)) { + final CIMObjectPath objectPath = cimInstance.getObjectPath(); + Utils.checkNonNull(objectPath, "objectPath"); + return convertReference(objectPath); + } + + // first check getProperty + CIMProperty cimProperty = cimInstance.getProperty(property); + + // then, if null, check getKeys + final String separator = arraySeparator == null ? Utils.DEFAULT_ARRAY_SEPARATOR : arraySeparator; + if (cimProperty == null && cimInstance.getKeys() != null) { + return Stream + .of(cimInstance.getKeys()) + .filter(key -> key.getName() != null && key.getName().equalsIgnoreCase(property)) + .findFirst() + .map(cp -> convertCimPropertyValue(cp, separator)) + .orElse(Utils.EMPTY); + } + + return cimProperty == null ? Utils.EMPTY : convertCimPropertyValue(cimProperty, separator); + } + + /** + * Convert the CIM property value into a String. + * + * @param cimProperty The CIM property. + * @param arraySeparator The array separator value. + * @return + */ + private static String convertCimPropertyValue(final CIMProperty cimProperty, final String arraySeparator) { + final Object cimPropertyValue = cimProperty.getValue(); + if (cimPropertyValue == null) { + return Utils.EMPTY; + } + + final CIMDataType dataType = cimProperty.getDataType(); + if (dataType == null) { + return cimPropertyValue.toString(); + } + + return dataType.isArray() + ? convertArray(cimProperty, arraySeparator) + : CONVERT_MAP.getOrDefault(dataType.getType(), Object::toString).apply(cimPropertyValue); + } + + /** + * Convert a CIM property value array. + * + * @param cimProperty The CIM property. + * @param arraySeparator The array separator value. + * @return + */ + private static String convertArray(final CIMProperty cimProperty, final String arraySeparator) { + return Arrays + .stream((Object[]) cimProperty.getValue()) + .map( + obj -> + (obj == null) + ? Utils.EMPTY + : CONVERT_MAP.getOrDefault(cimProperty.getDataType().getType(), Object::toString).apply(obj) + ) + .collect(Collectors.joining(arraySeparator, Utils.EMPTY, arraySeparator)); + } + + /** + * Convert a CIMObjectPath reference to string: + *
    • take the part after ':'
    • + *
    • escape back slash
    • + *
    • escape double quotes
    • + * + * @param cimPropertyValue + * @return + */ + private static String convertReference(final Object cimPropertyValue) { + final CIMObjectPath objectPath = (CIMObjectPath) cimPropertyValue; + final String str = objectPath.toString(); + return str + .substring(str.indexOf(':') + 1) // take the part after : (if exists) + .replace("\\\\", "\\") // Replace \\ by \ + .replace("\\\"", "\""); // Replace \" by " + } + + /** + * Convert a CIMDateTime into a string containing to Epoch time milliseconds. + * + * @param cimPropertyValue + * @return + */ + private static String convertDateTime(final Object cimPropertyValue) { + if (cimPropertyValue == null) { + return Utils.EMPTY; + } + + if (cimPropertyValue instanceof CIMDateTimeAbsolute) { + final String dateTimeString = ((CIMDateTimeAbsolute) cimPropertyValue).getDateTimeString(); + return String.valueOf(Utils.convertCimDateTime(dateTimeString).toInstant().toEpochMilli()); + } + return String.valueOf(((CIMDateTimeInterval) cimPropertyValue).getTotalMilliseconds()); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/client/WbemClient.java b/src/main/java/org/metricshub/wbem/client/WbemClient.java similarity index 54% rename from src/main/java/org/sentrysoftware/wbem/client/WbemClient.java rename to src/main/java/org/metricshub/wbem/client/WbemClient.java index 6dfbdd7..421c451 100644 --- a/src/main/java/org/sentrysoftware/wbem/client/WbemClient.java +++ b/src/main/java/org/metricshub/wbem/client/WbemClient.java @@ -1,229 +1,231 @@ -package org.sentrysoftware.wbem.client; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.net.URL; -import java.util.ArrayList; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import javax.security.auth.Subject; - -import org.sentrysoftware.wbem.javax.cim.CIMInstance; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import org.sentrysoftware.wbem.javax.cim.CIMProperty; -import org.sentrysoftware.wbem.javax.wbem.CloseableIterator; -import org.sentrysoftware.wbem.javax.wbem.WBEMException; -import org.sentrysoftware.wbem.javax.wbem.client.EnumerateResponse; -import org.sentrysoftware.wbem.javax.wbem.client.PasswordCredential; -import org.sentrysoftware.wbem.javax.wbem.client.UserPrincipal; -import org.sentrysoftware.wbem.javax.wbem.client.WBEMClient; -import org.sentrysoftware.wbem.javax.wbem.client.WBEMClientConstants; -import org.sentrysoftware.wbem.javax.wbem.client.WBEMClientFactory; - -/** - * Matsya WBEM client for query execution. - * - */ -public class WbemClient implements AutoCloseable { - - private static final Locale[] FIXED_AVAILABLE_LOCALES_ARRAY = {Locale.ENGLISH}; - - private WBEMClient client; - - private CloseableIterator iterator; - - /** - * Connect to WBEM client. - * - * @param url - * @param username - * @param password - * @param timeout - * @throws WBEMException - */ - public void connect( - final URL url, - final String username, - final char[] password, - int timeout) throws WBEMException { - - Utils.checkNonNull(url, "url"); - Utils.checkNonNull(username, "username"); - Utils.checkNonNull(password, "password"); - - final CIMObjectPath cimObjectPath = new CIMObjectPath( - url.getProtocol(), - url.getHost(), - String.valueOf(url.getPort()), - null, - null, - null); - - final Subject subject = new Subject(); - subject.getPrincipals().add(new UserPrincipal(username)); - subject.getPrivateCredentials().add(new PasswordCredential(password)); - - // Create and initialize a WBEM client. - client = WBEMClientFactory.getClient("CIM-XML"); - client.setProperty(WBEMClientConstants.PROP_TIMEOUT, String.valueOf(timeout)); - client.initialize(cimObjectPath, subject, FIXED_AVAILABLE_LOCALES_ARRAY); - } - - @Override - public void close() { - if (iterator != null) { - iterator.close(); - } - - if (client != null) { - client.close(); - } - } - - /** - * Execute a WQL query on remote. - * @param wqlQuery The query handler. - * @param namespace The WBEM namespace. - * @param arraySeparator The array separator value. default value '|' - * @return - * @throws WBEMException - */ - public WbemQueryResult executeWql( - final WqlQuery wqlQuery, - final String namespace, - final String arraySeparator) throws WBEMException { - - Utils.checkNonNull(wqlQuery, "wqlQuery"); - Utils.checkNonNull(namespace, "namespace"); - - if (client == null) { - throw new IllegalStateException("client must be connected first."); - } - - iterator = client.enumerateInstances( - new CIMObjectPath(null, null, null, namespace, wqlQuery.getClassName(), null), - true, - false, - true, - wqlQuery.getPropertiesArray()); - - return enumerateInstances(wqlQuery, iterator, arraySeparator); - } - - /** - * Get associators. - * @param wqlQuery The query handler. - * @param objectPathAssociators The object path for ASSOCIATORS. - * @param arraySeparator The array separator value. default value '|' - * @return - * @throws WBEMException - */ - public WbemQueryResult getAssociators( - final WqlQuery wqlQuery, - final String objectPathAssociators, - final String arraySeparator) throws WBEMException { - - Utils.checkNonNull(wqlQuery, "wqlQuery"); - Utils.checkNonNull(objectPathAssociators, "objectPathAssociators"); - - if (client == null) { - throw new IllegalStateException("client must be connected first."); - } - - final EnumerateResponse response = client.associators( - new CIMObjectPath(objectPathAssociators), - wqlQuery.getClassName(), - null, - null, - null, - false, - wqlQuery.getPropertiesArray(), - null, - null, - null, - false, - null); - iterator = response.getResponses(); - - return enumerateInstances(wqlQuery, iterator, arraySeparator); - } - - public static WbemQueryResult enumerateInstances( - final WqlQuery wqlQuery, - final CloseableIterator iterator, - final String arraySeparator) { - if (iterator == null) { - return new WbemQueryResult(new ArrayList<>(), new ArrayList<>()); - } - - Set properties = null; - List originalProperties = null; - final List> values = new ArrayList<>(); - - while (iterator.hasNext()) { - final CIMInstance cimInstance = iterator.next(); - - if (properties == null) { - properties = - wqlQuery.getProperties().isEmpty() ? - Stream.of(cimInstance.getProperties()) - .map(CIMProperty::getName) - .collect(Collectors.toCollection(LinkedHashSet::new)) : - wqlQuery.getProperties(); - } - - if (originalProperties == null) { - originalProperties = wqlQuery.hasDuplicateProperties() ? - wqlQuery.getOriginalProperties() : - properties.stream().collect(Collectors.toList()); - } - - final List row; - if (wqlQuery.hasDuplicateProperties()) { - - final Map cimProperties = properties.stream().collect(Collectors.toMap( - String::toLowerCase, - property -> WbemCimDataHandler.getCimPropertyAsString(property, cimInstance, arraySeparator))); - - row = originalProperties.stream() - .map(property -> cimProperties.get(property.toLowerCase())) - .collect(Collectors.toList()); - - } else { - row = properties.stream() - .map(property -> WbemCimDataHandler.getCimPropertyAsString(property, cimInstance, arraySeparator)) - .collect(Collectors.toList()); - } - - values.add(row); - } - - return new WbemQueryResult(originalProperties, values); - } -} +package org.metricshub.wbem.client; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.net.URL; +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import javax.security.auth.Subject; +import org.metricshub.wbem.javax.cim.CIMInstance; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.cim.CIMProperty; +import org.metricshub.wbem.javax.wbem.CloseableIterator; +import org.metricshub.wbem.javax.wbem.WBEMException; +import org.metricshub.wbem.javax.wbem.client.EnumerateResponse; +import org.metricshub.wbem.javax.wbem.client.PasswordCredential; +import org.metricshub.wbem.javax.wbem.client.UserPrincipal; +import org.metricshub.wbem.javax.wbem.client.WBEMClient; +import org.metricshub.wbem.javax.wbem.client.WBEMClientConstants; +import org.metricshub.wbem.javax.wbem.client.WBEMClientFactory; + +/** + * Matsya WBEM client for query execution. + * + */ +public class WbemClient implements AutoCloseable { + private static final Locale[] FIXED_AVAILABLE_LOCALES_ARRAY = { Locale.ENGLISH }; + + private WBEMClient client; + + private CloseableIterator iterator; + + /** + * Connect to WBEM client. + * + * @param url + * @param username + * @param password + * @param timeout + * @throws WBEMException + */ + public void connect(final URL url, final String username, final char[] password, int timeout) throws WBEMException { + Utils.checkNonNull(url, "url"); + Utils.checkNonNull(username, "username"); + Utils.checkNonNull(password, "password"); + + final CIMObjectPath cimObjectPath = new CIMObjectPath( + url.getProtocol(), + url.getHost(), + String.valueOf(url.getPort()), + null, + null, + null + ); + + final Subject subject = new Subject(); + subject.getPrincipals().add(new UserPrincipal(username)); + subject.getPrivateCredentials().add(new PasswordCredential(password)); + + // Create and initialize a WBEM client. + client = WBEMClientFactory.getClient("CIM-XML"); + client.setProperty(WBEMClientConstants.PROP_TIMEOUT, String.valueOf(timeout)); + client.initialize(cimObjectPath, subject, FIXED_AVAILABLE_LOCALES_ARRAY); + } + + @Override + public void close() { + if (iterator != null) { + iterator.close(); + } + + if (client != null) { + client.close(); + } + } + + /** + * Execute a WQL query on remote. + * @param wqlQuery The query handler. + * @param namespace The WBEM namespace. + * @param arraySeparator The array separator value. default value '|' + * @return + * @throws WBEMException + */ + public WbemQueryResult executeWql(final WqlQuery wqlQuery, final String namespace, final String arraySeparator) + throws WBEMException { + Utils.checkNonNull(wqlQuery, "wqlQuery"); + Utils.checkNonNull(namespace, "namespace"); + + if (client == null) { + throw new IllegalStateException("client must be connected first."); + } + + iterator = + client.enumerateInstances( + new CIMObjectPath(null, null, null, namespace, wqlQuery.getClassName(), null), + true, + false, + true, + wqlQuery.getPropertiesArray() + ); + + return enumerateInstances(wqlQuery, iterator, arraySeparator); + } + + /** + * Get associators. + * @param wqlQuery The query handler. + * @param objectPathAssociators The object path for ASSOCIATORS. + * @param arraySeparator The array separator value. default value '|' + * @return + * @throws WBEMException + */ + public WbemQueryResult getAssociators( + final WqlQuery wqlQuery, + final String objectPathAssociators, + final String arraySeparator + ) + throws WBEMException { + Utils.checkNonNull(wqlQuery, "wqlQuery"); + Utils.checkNonNull(objectPathAssociators, "objectPathAssociators"); + + if (client == null) { + throw new IllegalStateException("client must be connected first."); + } + + final EnumerateResponse response = client.associators( + new CIMObjectPath(objectPathAssociators), + wqlQuery.getClassName(), + null, + null, + null, + false, + wqlQuery.getPropertiesArray(), + null, + null, + null, + false, + null + ); + iterator = response.getResponses(); + + return enumerateInstances(wqlQuery, iterator, arraySeparator); + } + + public static WbemQueryResult enumerateInstances( + final WqlQuery wqlQuery, + final CloseableIterator iterator, + final String arraySeparator + ) { + if (iterator == null) { + return new WbemQueryResult(new ArrayList<>(), new ArrayList<>()); + } + + Set properties = null; + List originalProperties = null; + final List> values = new ArrayList<>(); + + while (iterator.hasNext()) { + final CIMInstance cimInstance = iterator.next(); + + if (properties == null) { + properties = + wqlQuery.getProperties().isEmpty() + ? Stream + .of(cimInstance.getProperties()) + .map(CIMProperty::getName) + .collect(Collectors.toCollection(LinkedHashSet::new)) + : wqlQuery.getProperties(); + } + + if (originalProperties == null) { + originalProperties = + wqlQuery.hasDuplicateProperties() + ? wqlQuery.getOriginalProperties() + : properties.stream().collect(Collectors.toList()); + } + + final List row; + if (wqlQuery.hasDuplicateProperties()) { + final Map cimProperties = properties + .stream() + .collect( + Collectors.toMap( + String::toLowerCase, + property -> WbemCimDataHandler.getCimPropertyAsString(property, cimInstance, arraySeparator) + ) + ); + + row = + originalProperties + .stream() + .map(property -> cimProperties.get(property.toLowerCase())) + .collect(Collectors.toList()); + } else { + row = + properties + .stream() + .map(property -> WbemCimDataHandler.getCimPropertyAsString(property, cimInstance, arraySeparator)) + .collect(Collectors.toList()); + } + + values.add(row); + } + + return new WbemQueryResult(originalProperties, values); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/client/WbemExecutor.java b/src/main/java/org/metricshub/wbem/client/WbemExecutor.java similarity index 53% rename from src/main/java/org/sentrysoftware/wbem/client/WbemExecutor.java rename to src/main/java/org/metricshub/wbem/client/WbemExecutor.java index b9212d9..ab15c5c 100644 --- a/src/main/java/org/sentrysoftware/wbem/client/WbemExecutor.java +++ b/src/main/java/org/metricshub/wbem/client/WbemExecutor.java @@ -1,194 +1,166 @@ -package org.sentrysoftware.wbem.client; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.net.URL; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import org.sentrysoftware.wbem.client.exceptions.WqlQuerySyntaxException; -import org.sentrysoftware.wbem.javax.wbem.WBEMException; - -/** - * Functions to execute WBEM query. - * - */ -public class WbemExecutor { - - private WbemExecutor() { } - - /** - * Execute a WBEM query on remote. - * - * @param url The remote URL. - * @param namespace The WBEM namespace. - * @param username The user name. - * @param password The Password. - * @param query The WQL Query to execute. - * @param timeout Timeout in milliseconds. - * @param arraySeparator The array separator value. default value '|' - * @return - * @throws WqlQuerySyntaxException On WQL syntax errors. - * @throws WBEMException On WBEM errors. - * @throws TimeoutException To notify userName of timeout. - * @throws InterruptedException - */ - public static WbemQueryResult executeWql( - final URL url, - final String namespace, - final String username, - final char[] password, - final String query, - int timeout, - final String arraySeparator) - throws WqlQuerySyntaxException, - WBEMException, - TimeoutException, - InterruptedException { - return executeMethod( - url, - namespace, - username, - password, - query, - null, - timeout, - arraySeparator); - } - - /** - * Execute WBEM get associators on remote. - * - * @param url The remote URL. - * @param username The user name. - * @param password The Password. - * @param query The WQL Query to execute. - * @param objectPathAssociators The object path for ASSOCIATORS. - * @param timeout Timeout in milliseconds. - * @param arraySeparator The array separator value. default value '|' - * @return - * @throws WqlQuerySyntaxException On WQL syntax errors. - * @throws WBEMException On WBEM errors. - * @throws TimeoutException To notify userName of timeout. - * @throws InterruptedException - */ - public static WbemQueryResult getAssociators( - final URL url, - final String username, - final char[] password, - final String query, - final String objectPathAssociators, - int timeout, - final String arraySeparator) - throws WqlQuerySyntaxException, - WBEMException, - TimeoutException, - InterruptedException { - return executeMethod( - url, - null, - username, - password, - query, - objectPathAssociators, - timeout, - arraySeparator); - } - - /** - * Execute the WBEM method with timeout. - * - * @param url - * @param namespace - * @param username - * @param password - * @param query - * @param objectPathAssociators - * @param timeout - * @param arraySeparator - * @return - * @throws InterruptedException - * @throws TimeoutException - * @throws WBEMException - * @throws WqlQuerySyntaxException - */ - private static WbemQueryResult executeMethod( - final URL url, - final String namespace, - final String username, - final char[] password, - final String query, - final String objectPathAssociators, - int timeout, - final String arraySeparator) - throws InterruptedException, - TimeoutException, - WBEMException, - WqlQuerySyntaxException { - - Utils.checkNonNull(url, "url"); - Utils.checkNonNull(username, "username"); - Utils.checkNonNull(password, "password"); - - final WqlQuery wqlQuery = WqlQuery.parseQuery(query); - - final ExecutorService executor = Executors.newSingleThreadExecutor(); - - final Future future = executor.submit(() -> { - try (final WbemClient matsyaWbemClient = new WbemClient()) { - matsyaWbemClient.connect(url, username, password, timeout); - - return objectPathAssociators == null ? - matsyaWbemClient.executeWql(wqlQuery, namespace, arraySeparator) : - matsyaWbemClient.getAssociators(wqlQuery, objectPathAssociators, arraySeparator); - } - }); - - try { - return future.get(timeout, TimeUnit.MILLISECONDS); - - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw (InterruptedException) e; - - } catch (TimeoutException e) { - future.cancel(true); - throw e; - - } catch (ExecutionException e) { - if (e.getCause() instanceof WBEMException) { - throw (WBEMException) e.getCause(); - } - // else should be RunTimeException as matsyaWbemClient only thrown - // WBEMException as checked exceptions. - throw (RuntimeException) e.getCause(); - } - finally { - executor.shutdownNow(); - } - } -} +package org.metricshub.wbem.client; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.net.URL; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.metricshub.wbem.client.exceptions.WqlQuerySyntaxException; +import org.metricshub.wbem.javax.wbem.WBEMException; + +/** + * Functions to execute WBEM query. + * + */ +public class WbemExecutor { + + private WbemExecutor() {} + + /** + * Execute a WBEM query on remote. + * + * @param url The remote URL. + * @param namespace The WBEM namespace. + * @param username The user name. + * @param password The Password. + * @param query The WQL Query to execute. + * @param timeout Timeout in milliseconds. + * @param arraySeparator The array separator value. default value '|' + * @return + * @throws WqlQuerySyntaxException On WQL syntax errors. + * @throws WBEMException On WBEM errors. + * @throws TimeoutException To notify userName of timeout. + * @throws InterruptedException + */ + public static WbemQueryResult executeWql( + final URL url, + final String namespace, + final String username, + final char[] password, + final String query, + int timeout, + final String arraySeparator + ) + throws WqlQuerySyntaxException, WBEMException, TimeoutException, InterruptedException { + return executeMethod(url, namespace, username, password, query, null, timeout, arraySeparator); + } + + /** + * Execute WBEM get associators on remote. + * + * @param url The remote URL. + * @param username The user name. + * @param password The Password. + * @param query The WQL Query to execute. + * @param objectPathAssociators The object path for ASSOCIATORS. + * @param timeout Timeout in milliseconds. + * @param arraySeparator The array separator value. default value '|' + * @return + * @throws WqlQuerySyntaxException On WQL syntax errors. + * @throws WBEMException On WBEM errors. + * @throws TimeoutException To notify userName of timeout. + * @throws InterruptedException + */ + public static WbemQueryResult getAssociators( + final URL url, + final String username, + final char[] password, + final String query, + final String objectPathAssociators, + int timeout, + final String arraySeparator + ) + throws WqlQuerySyntaxException, WBEMException, TimeoutException, InterruptedException { + return executeMethod(url, null, username, password, query, objectPathAssociators, timeout, arraySeparator); + } + + /** + * Execute the WBEM method with timeout. + * + * @param url + * @param namespace + * @param username + * @param password + * @param query + * @param objectPathAssociators + * @param timeout + * @param arraySeparator + * @return + * @throws InterruptedException + * @throws TimeoutException + * @throws WBEMException + * @throws WqlQuerySyntaxException + */ + private static WbemQueryResult executeMethod( + final URL url, + final String namespace, + final String username, + final char[] password, + final String query, + final String objectPathAssociators, + int timeout, + final String arraySeparator + ) + throws InterruptedException, TimeoutException, WBEMException, WqlQuerySyntaxException { + Utils.checkNonNull(url, "url"); + Utils.checkNonNull(username, "username"); + Utils.checkNonNull(password, "password"); + + final WqlQuery wqlQuery = WqlQuery.parseQuery(query); + + final ExecutorService executor = Executors.newSingleThreadExecutor(); + + final Future future = executor.submit( + () -> { + try (final WbemClient matsyaWbemClient = new WbemClient()) { + matsyaWbemClient.connect(url, username, password, timeout); + + return objectPathAssociators == null + ? matsyaWbemClient.executeWql(wqlQuery, namespace, arraySeparator) + : matsyaWbemClient.getAssociators(wqlQuery, objectPathAssociators, arraySeparator); + } + } + ); + + try { + return future.get(timeout, TimeUnit.MILLISECONDS); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw (InterruptedException) e; + } catch (TimeoutException e) { + future.cancel(true); + throw e; + } catch (ExecutionException e) { + if (e.getCause() instanceof WBEMException) { + throw (WBEMException) e.getCause(); + } + // else should be RunTimeException as matsyaWbemClient only thrown + // WBEMException as checked exceptions. + throw (RuntimeException) e.getCause(); + } finally { + executor.shutdownNow(); + } + } +} diff --git a/src/main/java/org/metricshub/wbem/client/WbemQueryResult.java b/src/main/java/org/metricshub/wbem/client/WbemQueryResult.java new file mode 100644 index 0000000..04e8eb4 --- /dev/null +++ b/src/main/java/org/metricshub/wbem/client/WbemQueryResult.java @@ -0,0 +1,48 @@ +package org.metricshub.wbem.client; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.List; + +/** + * Wrapper class for WBEM query result. + * + */ +public class WbemQueryResult { + /** List of the properties of the query. */ + private final List properties; + + /** Query results. */ + private final List> values; + + public WbemQueryResult(final List properties, final List> values) { + this.properties = properties; + this.values = values; + } + + public List getProperties() { + return properties; + } + + public List> getValues() { + return values; + } +} diff --git a/src/main/java/org/metricshub/wbem/client/WqlQuery.java b/src/main/java/org/metricshub/wbem/client/WqlQuery.java new file mode 100644 index 0000000..18e4f02 --- /dev/null +++ b/src/main/java/org/metricshub/wbem/client/WqlQuery.java @@ -0,0 +1,137 @@ +package org.metricshub.wbem.client; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.metricshub.wbem.client.exceptions.WqlQuerySyntaxException; + +/** + * Handler for WQL query. + * + */ +public class WqlQuery { + + private WqlQuery() {} + + private static final String ID = "[^\\s]+"; + private static final String LIST_SEPARATOR = "\\s*,\\s*"; + + private static final Pattern CHECK_SELECT_PATTERN = Pattern.compile( + "^\\s*SELECT\\s+(\\*|(?!SELECT|FROM|WHERE)\\w+|((?!SELECT|FROM|WHERE)\\w+\\s*,\\s*)+((?!SELECT|FROM|WHERE)\\w+))\\s+FROM\\s+((?!SELECT|WHERE|FROM)\\w+)\\s*?$", + Pattern.CASE_INSENSITIVE + ); + + private static final Pattern EXTRACT_SELECT_PATTERN = Pattern.compile( + "^\\s*SELECT\\s+(.+)\\s+FROM\\s+(" + ID + ")\\s*$", + Pattern.CASE_INSENSITIVE + ); + private static final int SELECT_GROUP_CLASSNAME = 2; + private static final int SELECT_GROUP_FIELDS = 1; + private static final int SELECT_GROUP_COUNT = 2; + + private String className; + private Set properties; + private List originalProperties; + + /** + * Constructor for WQL query. + * + * @param query the WQL query. + * @throws WqlQuerySyntaxException On WQL Syntax exception. + */ + public static WqlQuery parseQuery(final String query) throws WqlQuerySyntaxException { + Utils.checkNonNull(query, "query"); + + if (CHECK_SELECT_PATTERN.matcher(query).find()) { + final WqlQuery wqlQuery = new WqlQuery(); + wqlQuery.parseSelect(query); + return wqlQuery; + } + throw new WqlQuerySyntaxException(query); + } + + public String getClassName() { + return className; + } + + public String[] getPropertiesArray() { + return properties.isEmpty() + ? null + : properties + .stream() + .filter(property -> !WbemCimDataHandler.PATH_PROPERTY.equalsIgnoreCase(property)) + .toArray(String[]::new); + } + + public Set getProperties() { + return properties; + } + + public List getOriginalProperties() { + return originalProperties; + } + + public boolean hasDuplicateProperties() { + return properties != null && originalProperties != null && properties.size() != originalProperties.size(); + } + + private void parseSelect(final String query) throws WqlQuerySyntaxException { + final Matcher matcher = EXTRACT_SELECT_PATTERN.matcher(query); + if (!matcher.find()) { + throw new WqlQuerySyntaxException(query); + } + if (matcher.groupCount() < SELECT_GROUP_COUNT) { + throw new WqlQuerySyntaxException(query); + } + + className = matcher.group(SELECT_GROUP_CLASSNAME); + + final String fieldsList = matcher.group(SELECT_GROUP_FIELDS); + final String[] fieldArray = Optional + .ofNullable(fieldsList) + .filter(s -> !"*".equals(s)) + .map(s -> s.split(LIST_SEPARATOR)) + .orElse(new String[0]); + + originalProperties = Stream.of(fieldArray).map(String::trim).collect(Collectors.toList()); + + // using a map, so the properties will keep the case and the order of the query. + final Map originalMap = new HashMap<>(); + originalProperties + .stream() + .forEach(property -> originalMap.computeIfAbsent(property.toLowerCase(), prop -> property)); + + properties = + originalProperties + .stream() + .map(property -> originalMap.get(property.toLowerCase())) + .collect(Collectors.toCollection(LinkedHashSet::new)); + } +} diff --git a/src/main/java/org/metricshub/wbem/client/exceptions/WqlQuerySyntaxException.java b/src/main/java/org/metricshub/wbem/client/exceptions/WqlQuerySyntaxException.java new file mode 100644 index 0000000..a54c3ed --- /dev/null +++ b/src/main/java/org/metricshub/wbem/client/exceptions/WqlQuerySyntaxException.java @@ -0,0 +1,37 @@ +package org.metricshub.wbem.client.exceptions; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * Exception for a syntax error in the WQL Query parameter. + * + */ +public class WqlQuerySyntaxException extends Exception { + private static final long serialVersionUID = 1L; + + public WqlQuerySyntaxException(final String wqlQuery) { + super("Syntax error in WQL Query: " + wqlQuery); + } + + public WqlQuerySyntaxException(final Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMArgument.java b/src/main/java/org/metricshub/wbem/javax/cim/CIMArgument.java similarity index 79% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/CIMArgument.java rename to src/main/java/org/metricshub/wbem/javax/cim/CIMArgument.java index 6c11b0d..b3136ae 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMArgument.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/CIMArgument.java @@ -1,102 +1,99 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - * 2944839 2010-02-08 blaschke-oss Remove redundant toString() methods - * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues - * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:58 EST 2010 -/** - * This class represents an instance of a CIMParameter used for a - * method invocation. A CIMArgument has a name, data type and - * value. A CIMArgument corresponds to a CIMParameter - * defined for a CIMMethod. - * - * @param - * Type parameter. - * - * @see CIMParameter - */ -public class CIMArgument extends CIMValuedElement { - - private static final long serialVersionUID = 4727439564059428267L; - - /** - * Constructs a CIMArgument to be used for method invocations. - * A CIMArgument corresponds to a CIMParameter. - * For each CIMParameter being populated during a method - * invocation a CIMArgument object must be created. - * - * @param pName - * Name of the CIM argument. - * @param pType - * CIMDataType of the argument. - * @param pValue - * Value of the argument. - * @throws IllegalArgumentException - * If the value does not match the type. - * @see CIMParameter - */ - public CIMArgument(String pName, CIMDataType pType, E pValue) throws IllegalArgumentException { - super(pName, pType, pValue); - } - - /** - * Compares this object against the specified object. The result is - * true if and only if the argument is not null - * and is a CIMArgument that represents the same name, type and - * value as this CIMArgument. - * - * @param pObj - * The object to compare with. - * @return true if the objects are the same; false - * otherwise. - */ - @Override - public boolean equals(Object pObj) { - if (!(pObj instanceof CIMArgument)) return false; - return super.equals(pObj); - } -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + * 2944839 2010-02-08 blaschke-oss Remove redundant toString() methods + * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues + * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:58 EST 2010 +/** + * This class represents an instance of a CIMParameter used for a + * method invocation. A CIMArgument has a name, data type and + * value. A CIMArgument corresponds to a CIMParameter + * defined for a CIMMethod. + * + * @param + * Type parameter. + * + * @see CIMParameter + */ +public class CIMArgument extends CIMValuedElement { + private static final long serialVersionUID = 4727439564059428267L; + + /** + * Constructs a CIMArgument to be used for method invocations. + * A CIMArgument corresponds to a CIMParameter. + * For each CIMParameter being populated during a method + * invocation a CIMArgument object must be created. + * + * @param pName + * Name of the CIM argument. + * @param pType + * CIMDataType of the argument. + * @param pValue + * Value of the argument. + * @throws IllegalArgumentException + * If the value does not match the type. + * @see CIMParameter + */ + public CIMArgument(String pName, CIMDataType pType, E pValue) throws IllegalArgumentException { + super(pName, pType, pValue); + } + + /** + * Compares this object against the specified object. The result is + * true if and only if the argument is not null + * and is a CIMArgument that represents the same name, type and + * value as this CIMArgument. + * + * @param pObj + * The object to compare with. + * @return true if the objects are the same; false + * otherwise. + */ + @Override + public boolean equals(Object pObj) { + if (!(pObj instanceof CIMArgument)) return false; + return super.equals(pObj); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMClass.java b/src/main/java/org/metricshub/wbem/javax/cim/CIMClass.java similarity index 83% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/CIMClass.java rename to src/main/java/org/metricshub/wbem/javax/cim/CIMClass.java index 24f06e5..40291e1 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMClass.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/CIMClass.java @@ -1,575 +1,602 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant - * 1669961 2006-04-16 lupusalex CIMTypedElement.getType() =>getDataType() - * 1737123 2007-06-15 ebak Differences to JSR48 public review draft - * 1783288 2007-09-10 ebak CIMClass.isAssociation() not working for retrieved classes. - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2823494 2009-08-03 rgummada Change Boolean constructor to static - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - * 2944842 2010-02-08 blaschke-oss Missing thrown ArrayIndexOutOfBoundsException - * 2975917 2010-03-24 blaschke-oss TCK: CIMClass.getProperty() does not handle null property - * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues - * 3496301 2012-03-02 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final - * 3500619 2012-03-16 blaschke-oss JSR48 1.0.0: CIMClass association/key clean up - * 3521119 2012-04-24 blaschke-oss JSR48 1.0.0: remove CIMObjectPath 2/3/4-parm ctors - * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods - * 2719 2013-12-10 blaschke-oss TCK: CIM APIs should not generate NullPointerException - * 2716 2013-12-11 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.TreeSet; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.CIMElementSorter; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.CIMQualifiedElementInterfaceImpl; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.MOF; - -//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013 -/** - * This class represents a CIM class as defined by the Distributed Management - * Task Force (DMTF) CIM Infrastructure - * Specification (DSP004). A CIMClass has the following attributes: - *
        - *
      • an object path describing the location and name of the class
      • - *
      • superclass name (can be null if no superclass)
      • - *
      • an array of qualifiers for the class
      • - *
      • an array of properties
      • - *
      • an array of methods
      • - *
      - */ -public class CIMClass extends CIMElement implements CIMQualifiedElementInterface, - CIMNamedElementInterface { - - private static final long serialVersionUID = -5634561913210025100L; - - private CIMQualifiedElementInterfaceImpl iQualiImpl; - - private CIMObjectPath iObjPath; - - private String iSuperClass; - - private CIMClassProperty[] iProps; - - private CIMMethod[] iMethods; - - private boolean iIsKeyed; - - private boolean iIsAssoc; - - /** - * Creates and instantiates a Java object representing a CIM Class. This - * method may or may not validate the pIsAssociation and - * pIsKeyed parameters. If an invalid value is supplied (i.e. - * the class is an association, but the pIsAssociation was set - * to false), it may or may not be corrected. - * - * @param pPath - * Object Name of the CIM class. - * @param pSuperClass - * Name of the superclass. - * @param pQualifiers - * List of qualifiers of the CIM class. - * @param pProperties - * List of properties of the CIM class. - * @param pMethods - * List of methods of the CIM class. - * @param pIsAssociation - * true if the CIM class is an Association, - * false otherwise. - * @param pIsKeyed - * true if the CIM class has Keys, - * false otherwise. - * @throws IllegalArgumentException - * If pPath is null. - * - */ - public CIMClass(CIMObjectPath pPath, String pSuperClass, CIMQualifier[] pQualifiers, - CIMClassProperty[] pProperties, CIMMethod[] pMethods, boolean pIsAssociation, - boolean pIsKeyed) { - this(pPath, pSuperClass, pQualifiers, pProperties, pMethods); - // if (this.isAssociation() != pIsAssociation) { - // throw new IllegalArgumentException( - // "pIsAssociation does not match pQualifiers! pIsAssociation is " + - // pIsAssociation - // + " while pQualifiers " - // + (this.isAssociation() ? "contains" : "does not contain") - // + " qualifier with association in class " + - // this.iObjPath.getObjectName()); - // } - // if (this.isKeyed() != pIsKeyed) { - // throw new IllegalArgumentException( - // "pIsKeyed does not match pProperties! pIsKeyed is " + pIsKeyed - // + " while pProperties " - // + (this.isKeyed() ? "contains" : "does not contain") - // + " property with key qualifier in class " + - // this.iObjPath.getObjectName()); - // } - } - - /** - * Creates and instantiates a Java object representing a CIM Class. This - * constructor will inspect the class to determine if it is an association - * or has keys. - * - * @param pName - * Name of the CIM class. - * @param pSuperClass - * Name of the superclass. - * @param pQualifiers - * List of qualifiers of the CIM class. - * @param pProperties - * List of properties of the CIM class. - * @param pMethods - * List of methods of the CIM class. - * @throws IllegalArgumentException - * If pName is null. - */ - public CIMClass(String pName, String pSuperClass, CIMQualifier[] pQualifiers, - CIMClassProperty[] pProperties, CIMMethod[] pMethods) { - this(new CIMObjectPath(null, null, null, null, pName, null), pSuperClass, pQualifiers, - pProperties, pMethods); - } - - /** - * This private constructor does the actual work for the two public - * constructors and sets the iIsAssoc and iIsKeyed instance variables based - * on whether there is qualifier with name="Association" and value=true and - * a property with a qualifier with name="Key" and value=true, respectively. - */ - private CIMClass(CIMObjectPath pPath, String pSuperClass, CIMQualifier[] pQualifiers, - CIMClassProperty[] pProperties, CIMMethod[] pMethods) { - super(pPath == null ? null : pPath.getObjectName()); - this.iObjPath = pPath; - this.iSuperClass = pSuperClass; - this.iQualiImpl = new CIMQualifiedElementInterfaceImpl(pQualifiers); - this.iProps = (CIMClassProperty[]) CIMElementSorter.sort(pProperties); - this.iMethods = (CIMMethod[]) CIMElementSorter.sort(pMethods); - this.iIsAssoc = this.iQualiImpl.hasQualifierValue("Association", Boolean.TRUE); - this.iIsKeyed = hasKey(pProperties); - } - - /** - * Indicates whether the specified CIMClass is equal to this - * CIMClass. - * - * @param pObj - * The CIMClass object with which to compare. - * @return true if this object is the same as the - * pObj argument; false otherwise. - */ - @Override - public boolean equals(Object pObj) { - if (!(pObj instanceof CIMClass)) return false; - CIMClass that = (CIMClass) pObj; - if (!super.equals(that)) return false; - if (this.iSuperClass == null ? that.iSuperClass != null : !this.iSuperClass - .equalsIgnoreCase(that.iSuperClass)) return false; - if (!this.iQualiImpl.equals(that.iQualiImpl) || !Arrays.equals(this.iProps, that.iProps) - || !Arrays.equals(this.iMethods, that.iMethods) || this.iIsAssoc != that.iIsAssoc - || isKeyed() != that.isKeyed()) return false; - return true; - } - - /** - * This method returns a new CIMClass with properties filtered - * according to the input parameters. Inclusion of class origin and - * qualifiers can also be controlled. Methods will not be included in the - * class returned. - * - * @param pLocalOnly - * If true only the elements defined in this class - * are included; otherwise all elements are included. - * @param pIncludeQualifiers - * If true qualifiers are included on all elements; - * otherwise no qualifiers are included. - * @param pIncludeClassOrigin - * If true, the ClassOrigin attribute is included. - * @param pPropertyList - * If the PropertyList input parameter is not - * null, the members of the array define one or more - * Property names. The CIMClass returned does not - * include elements for any Properties missing from this list. If - * the PropertyList input parameter is an empty - * array this signifies that no Properties are included in the - * class returned. If the PropertyList input - * parameter is null this specifies that all - * Properties are included in the class returned. If the - * PropertyList contains duplicate elements or - * invalid property names, they are ignored. - * @return CIMClass matching the requested criteria. - */ - public CIMClass filterProperties(boolean pLocalOnly, boolean pIncludeQualifiers, - boolean pIncludeClassOrigin, String[] pPropertyList) { - ArrayList> newPropAList = new ArrayList>(); - // place pPropertyList into a set, for easy and fast search - TreeSet set; - if (pPropertyList != null) { - set = new TreeSet(); - for (int i = 0; i < pPropertyList.length; i++) - set.add(pPropertyList[i].toUpperCase()); - } else set = null; - for (int i = 0; i < getPropertyCount(); i++) { - CIMClassProperty refProp = getProperty(i); - if (pLocalOnly && refProp.isPropagated()) continue; - if (set == null || set.contains(refProp.getName().toUpperCase())) newPropAList - .add(new CIMClassProperty(refProp.getName(), refProp.getDataType(), - refProp.getValue(), - pIncludeQualifiers ? refProp.getQualifiers() : null, - pIncludeQualifiers ? refProp.isKey() : false, // FIXME: - // Should it depend on pIncludeQualifiers? - refProp.isPropagated(), pIncludeClassOrigin ? refProp.getOriginClass() - : null)); - } - return new CIMClass(getObjectPath(), getSuperClassName(), getQualifiers(), newPropAList - .toArray(new CIMClassProperty[0]), null, isAssociation(), isKeyed()); - } - - /** - * Returns a list of key properties for this CIM class. - * - * @return The list of CIM properties that are keys for this CIM class. - */ - public CIMClassProperty[] getKeys() { - ArrayList> keyAList = new ArrayList>(); - for (int i = 0; i < getPropertyCount(); i++) { - CIMClassProperty prop = getProperty(i); - if (prop.isKey()) keyAList.add(prop); - } - return keyAList.toArray(new CIMClassProperty[0]); - } - - /** - * Get a method by index. - * - * @param pIndex - * The index of the method to retrieve. - * @return The CIMMethod at the specified index. - * @throws ArrayIndexOutOfBoundsException - */ - public CIMMethod getMethod(int pIndex) throws ArrayIndexOutOfBoundsException { - return this.iMethods[pIndex]; - } - - /** - * Returns the specified CIM method in this CIM class. - * - * @param pName - * The string name of the method to retrieve. The name may be - * specified in the form "originClass.methodName". - * @return The CIM method specified or null if the method does - * not exist. - */ - - public CIMMethod getMethod(String pName) { - return getMethod(pName, null); - } - - /** - * Returns the CIM method specified by its name and optionally, its origin - * class. The origin class is the class in which the method is defined. - * - * @param pName - * The string name of the method to get. - * @param pOriginClass - * (Optional) The class in which the method was defined. - * @return The CIM method specified or null if the method does - * not exist. - */ - public CIMMethod getMethod(String pName, String pOriginClass) { - CIMMethod method = (CIMMethod) CIMElementSorter.find(this.iMethods, pName); - if (method == null) return null; - if (pOriginClass == null || pOriginClass.equalsIgnoreCase(method.getOriginClass())) return method; - return null; - } - - /** - * Get the number of methods defined in this CIM class. - * - * @return The number of methods defined in the CIM class. - */ - public int getMethodCount() { - return this.iMethods == null ? 0 : this.iMethods.length; - } - - /** - * Get the CIM methods defined in this CIM class. - * - * @return The methods in this CIM class. - */ - public CIMMethod[] getMethods() { - return this.iMethods != null ? this.iMethods : new CIMMethod[0]; - } - - /** - * This method returns the CIMObjectPath that represents this - * CIM class. - * - * @return The CIMObjectPath that represents this CIM class. - */ - public CIMObjectPath getObjectPath() { - return this.iObjPath; - } - - /** - * Get the properties defined for this CIM class. - * - * @return The properties for this class. - */ - public CIMClassProperty[] getProperties() { - return this.iProps != null ? this.iProps : new CIMClassProperty[0]; - } - - /** - * Get a class property by index. - * - * @param pIndex - * The index of the class property to retrieve. - * @return The CIMClassProperty at the specified index. - * @throws ArrayIndexOutOfBoundsException - */ - public CIMClassProperty getProperty(int pIndex) throws ArrayIndexOutOfBoundsException { - return this.iProps[pIndex]; - } - - /** - * Gets the specified property. - * - * @param pName - * The text string for the name of the property. - * @return The property requested or null if the property does - * not exist. - */ - public CIMClassProperty getProperty(String pName) { - return (CIMClassProperty) CIMElementSorter.find(this.iProps, pName); - } - - /** - * Gets the specified property. - * - * @param pName - * The string name of the property to get. - * @param pOriginClass - * (Optional) The string name of the class in which the property - * was defined. - * @return The property requested or null if the property does - * not exist. - */ - public CIMClassProperty getProperty(String pName, String pOriginClass) { - CIMClassProperty prop = (CIMClassProperty) CIMElementSorter.find(this.iProps, pName); - if (prop == null || pOriginClass == null) return prop; - return pOriginClass.equalsIgnoreCase(prop.getOriginClass()) ? prop : null; - } - - /** - * Get the number of properties defined in this CIMClass. - * - * @return The number of properties defined in the CIMClass. - */ - public int getPropertyCount() { - return this.iProps != null ? this.iProps.length : 0; - } - - /** - * Get a qualifier by index. - * - * @param pIndex - * The index of the qualifier to retrieve. - * @return The qualifier at the specified index. - * @throws ArrayIndexOutOfBoundsException - */ - public CIMQualifier getQualifier(int pIndex) throws ArrayIndexOutOfBoundsException { - return this.iQualiImpl.getQualifier(pIndex); - } - - /** - * Gets a qualifier by name. - * - * @param pName - * The name of the qualifier to get. - * @return The qualifier requested or null if the qualifier - * does not exist. - */ - public CIMQualifier getQualifier(String pName) { - return this.iQualiImpl.getQualifier(pName); - } - - /** - * Get the number of qualifiers defined in this CIM class. - * - * @return The number of qualifiers defined in the CIM class. - */ - public int getQualifierCount() { - return this.iQualiImpl.getQualifierCount(); - } - - /** - * Returns the list of qualifiers for the CIM class. - * - * @return Qualifiers for this class. - */ - public CIMQualifier[] getQualifiers() { - return this.iQualiImpl.getQualifiers(); - } - - /** - * Gets a qualifier value by name. - * - * @param pName - * The name of the qualifier to get. - * @return null if the qualifier does not exist or value is - * null, otherwise returns the reference to the - * qualifier. - */ - public Object getQualifierValue(String pName) { - return this.iQualiImpl.getQualifierValue(pName); - } - - /** - * Gets the name of the parent of this CIM class. - * - * @return The name of the parent class. - */ - public String getSuperClassName() { - return this.iSuperClass; - } - - /** - * Checks whether the specified qualifier is one of the qualifiers in this - * CIM class. - * - * @param pName - * The name of the qualifier. - * @return true if the qualifier exists in this CIM class, - * otherwise false. - */ - public boolean hasQualifier(String pName) { - return this.iQualiImpl.hasQualifier(pName); - } - - /** - * Checks whether the specified qualifier is one of the qualifiers defined - * for this class with the specified value. This method will return - * false if the qualifier is not applied or if the value does - * not match. - * - * @param pName - * The name of the qualifier. - * @param pValue - * The value to be tested. - * @return true if the qualifier exists and has the value, - * otherwise false. - */ - public boolean hasQualifierValue(String pName, Object pValue) { - return this.iQualiImpl.hasQualifierValue(pName, pValue); - } - - /** - * Identifies whether or not this CIM class is an association. An - * association is a relationship between two or more classes or instances of - * two or more classes. The properties of an association class include - * references, or pointers, to the two or more instances. All CIM classes - * can be included in one or more associations. - * - * @return true if this CIM class is an association; otherwise, - * false. - */ - public boolean isAssociation() { - return this.iIsAssoc; - } - - /** - * Identifies whether or not this class is keyed. Only keyed classes can - * have instances. Returns true if this CIM class has one or - * more key properties. Otherwise, returns false. - * - * @return true if this CIM class has a key property, otherwise - * returns false. - */ - public boolean isKeyed() { - return this.iIsKeyed; - } - - /** - * Returns a new CIM instance initialized with the default CIM properties, - * values and name of this CIM class. - * - * @return A CIM instance of this CIM class. - */ - public CIMInstance newInstance() { - return new CIMInstance(this.iObjPath, this.iProps); - } - - /** - * Returns a String representation of the CIM class. This - * method is intended to be used only for debugging purposes, and the format - * of the returned string may vary between implementations. The returned - * string may be empty but may not be null. - * - * @return A String representation of this CIM class. - */ - @Override - public String toString() { - return MOF.classDeclaration(this, MOF.EMPTY); - } - - /** - * Checks whether an array of properties contains a key. - * - * @param pProps - * Array of properties. - * @return true if at least one of the class properties is a - * key, false otherwise. - */ - private static boolean hasKey(CIMClassProperty[] pProps) { - if (pProps == null) return false; - for (int i = 0; i < pProps.length; i++) - if (pProps[i].isKey()) return true; - return false; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant + * 1669961 2006-04-16 lupusalex CIMTypedElement.getType() =>getDataType() + * 1737123 2007-06-15 ebak Differences to JSR48 public review draft + * 1783288 2007-09-10 ebak CIMClass.isAssociation() not working for retrieved classes. + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2823494 2009-08-03 rgummada Change Boolean constructor to static + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + * 2944842 2010-02-08 blaschke-oss Missing thrown ArrayIndexOutOfBoundsException + * 2975917 2010-03-24 blaschke-oss TCK: CIMClass.getProperty() does not handle null property + * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues + * 3496301 2012-03-02 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final + * 3500619 2012-03-16 blaschke-oss JSR48 1.0.0: CIMClass association/key clean up + * 3521119 2012-04-24 blaschke-oss JSR48 1.0.0: remove CIMObjectPath 2/3/4-parm ctors + * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods + * 2719 2013-12-10 blaschke-oss TCK: CIM APIs should not generate NullPointerException + * 2716 2013-12-11 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.TreeSet; +import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMElementSorter; +import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMQualifiedElementInterfaceImpl; +import org.metricshub.wbem.sblim.cimclient.internal.util.MOF; + +//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013 +/** + * This class represents a CIM class as defined by the Distributed Management + * Task Force (DMTF) CIM Infrastructure + * Specification (DSP004). A CIMClass has the following attributes: + *
        + *
      • an object path describing the location and name of the class
      • + *
      • superclass name (can be null if no superclass)
      • + *
      • an array of qualifiers for the class
      • + *
      • an array of properties
      • + *
      • an array of methods
      • + *
      + */ +public class CIMClass extends CIMElement implements CIMQualifiedElementInterface, CIMNamedElementInterface { + private static final long serialVersionUID = -5634561913210025100L; + + private CIMQualifiedElementInterfaceImpl iQualiImpl; + + private CIMObjectPath iObjPath; + + private String iSuperClass; + + private CIMClassProperty[] iProps; + + private CIMMethod[] iMethods; + + private boolean iIsKeyed; + + private boolean iIsAssoc; + + /** + * Creates and instantiates a Java object representing a CIM Class. This + * method may or may not validate the pIsAssociation and + * pIsKeyed parameters. If an invalid value is supplied (i.e. + * the class is an association, but the pIsAssociation was set + * to false), it may or may not be corrected. + * + * @param pPath + * Object Name of the CIM class. + * @param pSuperClass + * Name of the superclass. + * @param pQualifiers + * List of qualifiers of the CIM class. + * @param pProperties + * List of properties of the CIM class. + * @param pMethods + * List of methods of the CIM class. + * @param pIsAssociation + * true if the CIM class is an Association, + * false otherwise. + * @param pIsKeyed + * true if the CIM class has Keys, + * false otherwise. + * @throws IllegalArgumentException + * If pPath is null. + * + */ + public CIMClass( + CIMObjectPath pPath, + String pSuperClass, + CIMQualifier[] pQualifiers, + CIMClassProperty[] pProperties, + CIMMethod[] pMethods, + boolean pIsAssociation, + boolean pIsKeyed + ) { + this(pPath, pSuperClass, pQualifiers, pProperties, pMethods); + // if (this.isAssociation() != pIsAssociation) { + // throw new IllegalArgumentException( + // "pIsAssociation does not match pQualifiers! pIsAssociation is " + + // pIsAssociation + // + " while pQualifiers " + // + (this.isAssociation() ? "contains" : "does not contain") + // + " qualifier with association in class " + + // this.iObjPath.getObjectName()); + // } + // if (this.isKeyed() != pIsKeyed) { + // throw new IllegalArgumentException( + // "pIsKeyed does not match pProperties! pIsKeyed is " + pIsKeyed + // + " while pProperties " + // + (this.isKeyed() ? "contains" : "does not contain") + // + " property with key qualifier in class " + + // this.iObjPath.getObjectName()); + // } + } + + /** + * Creates and instantiates a Java object representing a CIM Class. This + * constructor will inspect the class to determine if it is an association + * or has keys. + * + * @param pName + * Name of the CIM class. + * @param pSuperClass + * Name of the superclass. + * @param pQualifiers + * List of qualifiers of the CIM class. + * @param pProperties + * List of properties of the CIM class. + * @param pMethods + * List of methods of the CIM class. + * @throws IllegalArgumentException + * If pName is null. + */ + public CIMClass( + String pName, + String pSuperClass, + CIMQualifier[] pQualifiers, + CIMClassProperty[] pProperties, + CIMMethod[] pMethods + ) { + this(new CIMObjectPath(null, null, null, null, pName, null), pSuperClass, pQualifiers, pProperties, pMethods); + } + + /** + * This private constructor does the actual work for the two public + * constructors and sets the iIsAssoc and iIsKeyed instance variables based + * on whether there is qualifier with name="Association" and value=true and + * a property with a qualifier with name="Key" and value=true, respectively. + */ + private CIMClass( + CIMObjectPath pPath, + String pSuperClass, + CIMQualifier[] pQualifiers, + CIMClassProperty[] pProperties, + CIMMethod[] pMethods + ) { + super(pPath == null ? null : pPath.getObjectName()); + this.iObjPath = pPath; + this.iSuperClass = pSuperClass; + this.iQualiImpl = new CIMQualifiedElementInterfaceImpl(pQualifiers); + this.iProps = (CIMClassProperty[]) CIMElementSorter.sort(pProperties); + this.iMethods = (CIMMethod[]) CIMElementSorter.sort(pMethods); + this.iIsAssoc = this.iQualiImpl.hasQualifierValue("Association", Boolean.TRUE); + this.iIsKeyed = hasKey(pProperties); + } + + /** + * Indicates whether the specified CIMClass is equal to this + * CIMClass. + * + * @param pObj + * The CIMClass object with which to compare. + * @return true if this object is the same as the + * pObj argument; false otherwise. + */ + @Override + public boolean equals(Object pObj) { + if (!(pObj instanceof CIMClass)) return false; + CIMClass that = (CIMClass) pObj; + if (!super.equals(that)) return false; + if ( + this.iSuperClass == null ? that.iSuperClass != null : !this.iSuperClass.equalsIgnoreCase(that.iSuperClass) + ) return false; + if ( + !this.iQualiImpl.equals(that.iQualiImpl) || + !Arrays.equals(this.iProps, that.iProps) || + !Arrays.equals(this.iMethods, that.iMethods) || + this.iIsAssoc != that.iIsAssoc || + isKeyed() != that.isKeyed() + ) return false; + return true; + } + + /** + * This method returns a new CIMClass with properties filtered + * according to the input parameters. Inclusion of class origin and + * qualifiers can also be controlled. Methods will not be included in the + * class returned. + * + * @param pLocalOnly + * If true only the elements defined in this class + * are included; otherwise all elements are included. + * @param pIncludeQualifiers + * If true qualifiers are included on all elements; + * otherwise no qualifiers are included. + * @param pIncludeClassOrigin + * If true, the ClassOrigin attribute is included. + * @param pPropertyList + * If the PropertyList input parameter is not + * null, the members of the array define one or more + * Property names. The CIMClass returned does not + * include elements for any Properties missing from this list. If + * the PropertyList input parameter is an empty + * array this signifies that no Properties are included in the + * class returned. If the PropertyList input + * parameter is null this specifies that all + * Properties are included in the class returned. If the + * PropertyList contains duplicate elements or + * invalid property names, they are ignored. + * @return CIMClass matching the requested criteria. + */ + public CIMClass filterProperties( + boolean pLocalOnly, + boolean pIncludeQualifiers, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) { + ArrayList> newPropAList = new ArrayList>(); + // place pPropertyList into a set, for easy and fast search + TreeSet set; + if (pPropertyList != null) { + set = new TreeSet(); + for (int i = 0; i < pPropertyList.length; i++) set.add(pPropertyList[i].toUpperCase()); + } else set = null; + for (int i = 0; i < getPropertyCount(); i++) { + CIMClassProperty refProp = getProperty(i); + if (pLocalOnly && refProp.isPropagated()) continue; + if (set == null || set.contains(refProp.getName().toUpperCase())) newPropAList.add( + new CIMClassProperty( + refProp.getName(), + refProp.getDataType(), + refProp.getValue(), + pIncludeQualifiers ? refProp.getQualifiers() : null, + pIncludeQualifiers ? refProp.isKey() : false, // FIXME: + // Should it depend on pIncludeQualifiers? + refProp.isPropagated(), + pIncludeClassOrigin ? refProp.getOriginClass() : null + ) + ); + } + return new CIMClass( + getObjectPath(), + getSuperClassName(), + getQualifiers(), + newPropAList.toArray(new CIMClassProperty[0]), + null, + isAssociation(), + isKeyed() + ); + } + + /** + * Returns a list of key properties for this CIM class. + * + * @return The list of CIM properties that are keys for this CIM class. + */ + public CIMClassProperty[] getKeys() { + ArrayList> keyAList = new ArrayList>(); + for (int i = 0; i < getPropertyCount(); i++) { + CIMClassProperty prop = getProperty(i); + if (prop.isKey()) keyAList.add(prop); + } + return keyAList.toArray(new CIMClassProperty[0]); + } + + /** + * Get a method by index. + * + * @param pIndex + * The index of the method to retrieve. + * @return The CIMMethod at the specified index. + * @throws ArrayIndexOutOfBoundsException + */ + public CIMMethod getMethod(int pIndex) throws ArrayIndexOutOfBoundsException { + return this.iMethods[pIndex]; + } + + /** + * Returns the specified CIM method in this CIM class. + * + * @param pName + * The string name of the method to retrieve. The name may be + * specified in the form "originClass.methodName". + * @return The CIM method specified or null if the method does + * not exist. + */ + + public CIMMethod getMethod(String pName) { + return getMethod(pName, null); + } + + /** + * Returns the CIM method specified by its name and optionally, its origin + * class. The origin class is the class in which the method is defined. + * + * @param pName + * The string name of the method to get. + * @param pOriginClass + * (Optional) The class in which the method was defined. + * @return The CIM method specified or null if the method does + * not exist. + */ + public CIMMethod getMethod(String pName, String pOriginClass) { + CIMMethod method = (CIMMethod) CIMElementSorter.find(this.iMethods, pName); + if (method == null) return null; + if (pOriginClass == null || pOriginClass.equalsIgnoreCase(method.getOriginClass())) return method; + return null; + } + + /** + * Get the number of methods defined in this CIM class. + * + * @return The number of methods defined in the CIM class. + */ + public int getMethodCount() { + return this.iMethods == null ? 0 : this.iMethods.length; + } + + /** + * Get the CIM methods defined in this CIM class. + * + * @return The methods in this CIM class. + */ + public CIMMethod[] getMethods() { + return this.iMethods != null ? this.iMethods : new CIMMethod[0]; + } + + /** + * This method returns the CIMObjectPath that represents this + * CIM class. + * + * @return The CIMObjectPath that represents this CIM class. + */ + public CIMObjectPath getObjectPath() { + return this.iObjPath; + } + + /** + * Get the properties defined for this CIM class. + * + * @return The properties for this class. + */ + public CIMClassProperty[] getProperties() { + return this.iProps != null ? this.iProps : new CIMClassProperty[0]; + } + + /** + * Get a class property by index. + * + * @param pIndex + * The index of the class property to retrieve. + * @return The CIMClassProperty at the specified index. + * @throws ArrayIndexOutOfBoundsException + */ + public CIMClassProperty getProperty(int pIndex) throws ArrayIndexOutOfBoundsException { + return this.iProps[pIndex]; + } + + /** + * Gets the specified property. + * + * @param pName + * The text string for the name of the property. + * @return The property requested or null if the property does + * not exist. + */ + public CIMClassProperty getProperty(String pName) { + return (CIMClassProperty) CIMElementSorter.find(this.iProps, pName); + } + + /** + * Gets the specified property. + * + * @param pName + * The string name of the property to get. + * @param pOriginClass + * (Optional) The string name of the class in which the property + * was defined. + * @return The property requested or null if the property does + * not exist. + */ + public CIMClassProperty getProperty(String pName, String pOriginClass) { + CIMClassProperty prop = (CIMClassProperty) CIMElementSorter.find(this.iProps, pName); + if (prop == null || pOriginClass == null) return prop; + return pOriginClass.equalsIgnoreCase(prop.getOriginClass()) ? prop : null; + } + + /** + * Get the number of properties defined in this CIMClass. + * + * @return The number of properties defined in the CIMClass. + */ + public int getPropertyCount() { + return this.iProps != null ? this.iProps.length : 0; + } + + /** + * Get a qualifier by index. + * + * @param pIndex + * The index of the qualifier to retrieve. + * @return The qualifier at the specified index. + * @throws ArrayIndexOutOfBoundsException + */ + public CIMQualifier getQualifier(int pIndex) throws ArrayIndexOutOfBoundsException { + return this.iQualiImpl.getQualifier(pIndex); + } + + /** + * Gets a qualifier by name. + * + * @param pName + * The name of the qualifier to get. + * @return The qualifier requested or null if the qualifier + * does not exist. + */ + public CIMQualifier getQualifier(String pName) { + return this.iQualiImpl.getQualifier(pName); + } + + /** + * Get the number of qualifiers defined in this CIM class. + * + * @return The number of qualifiers defined in the CIM class. + */ + public int getQualifierCount() { + return this.iQualiImpl.getQualifierCount(); + } + + /** + * Returns the list of qualifiers for the CIM class. + * + * @return Qualifiers for this class. + */ + public CIMQualifier[] getQualifiers() { + return this.iQualiImpl.getQualifiers(); + } + + /** + * Gets a qualifier value by name. + * + * @param pName + * The name of the qualifier to get. + * @return null if the qualifier does not exist or value is + * null, otherwise returns the reference to the + * qualifier. + */ + public Object getQualifierValue(String pName) { + return this.iQualiImpl.getQualifierValue(pName); + } + + /** + * Gets the name of the parent of this CIM class. + * + * @return The name of the parent class. + */ + public String getSuperClassName() { + return this.iSuperClass; + } + + /** + * Checks whether the specified qualifier is one of the qualifiers in this + * CIM class. + * + * @param pName + * The name of the qualifier. + * @return true if the qualifier exists in this CIM class, + * otherwise false. + */ + public boolean hasQualifier(String pName) { + return this.iQualiImpl.hasQualifier(pName); + } + + /** + * Checks whether the specified qualifier is one of the qualifiers defined + * for this class with the specified value. This method will return + * false if the qualifier is not applied or if the value does + * not match. + * + * @param pName + * The name of the qualifier. + * @param pValue + * The value to be tested. + * @return true if the qualifier exists and has the value, + * otherwise false. + */ + public boolean hasQualifierValue(String pName, Object pValue) { + return this.iQualiImpl.hasQualifierValue(pName, pValue); + } + + /** + * Identifies whether or not this CIM class is an association. An + * association is a relationship between two or more classes or instances of + * two or more classes. The properties of an association class include + * references, or pointers, to the two or more instances. All CIM classes + * can be included in one or more associations. + * + * @return true if this CIM class is an association; otherwise, + * false. + */ + public boolean isAssociation() { + return this.iIsAssoc; + } + + /** + * Identifies whether or not this class is keyed. Only keyed classes can + * have instances. Returns true if this CIM class has one or + * more key properties. Otherwise, returns false. + * + * @return true if this CIM class has a key property, otherwise + * returns false. + */ + public boolean isKeyed() { + return this.iIsKeyed; + } + + /** + * Returns a new CIM instance initialized with the default CIM properties, + * values and name of this CIM class. + * + * @return A CIM instance of this CIM class. + */ + public CIMInstance newInstance() { + return new CIMInstance(this.iObjPath, this.iProps); + } + + /** + * Returns a String representation of the CIM class. This + * method is intended to be used only for debugging purposes, and the format + * of the returned string may vary between implementations. The returned + * string may be empty but may not be null. + * + * @return A String representation of this CIM class. + */ + @Override + public String toString() { + return MOF.classDeclaration(this, MOF.EMPTY); + } + + /** + * Checks whether an array of properties contains a key. + * + * @param pProps + * Array of properties. + * @return true if at least one of the class properties is a + * key, false otherwise. + */ + private static boolean hasKey(CIMClassProperty[] pProps) { + if (pProps == null) return false; + for (int i = 0; i < pProps.length; i++) if (pProps[i].isKey()) return true; + return false; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMClassProperty.java b/src/main/java/org/metricshub/wbem/javax/cim/CIMClassProperty.java similarity index 83% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/CIMClassProperty.java rename to src/main/java/org/metricshub/wbem/javax/cim/CIMClassProperty.java index c6a90f4..c8d3eb5 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMClassProperty.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/CIMClassProperty.java @@ -1,263 +1,273 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant - * 1660756 2007-02-22 ebak Embedded object support - * 1669961 2006-04-16 lupusalex CIMTypedElement.getType() =>getDataType() - * 1737123 2007-06-15 ebak Differences to JSR48 public review draft - * 1737141 2007-06-18 ebak Sync up with JSR48 evolution - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2823494 2009-08-03 rgummada Change Boolean constructor to static - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - * 2944839 2010-02-08 blaschke-oss Remove redundant toString() methods - * 2944842 2010-02-08 blaschke-oss Missing thrown ArrayIndexOutOfBoundsException - * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues - * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.CIMQualifiedElementInterfaceImpl; - -//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:58 EST 2010 -/** - * This class represents a CIM property (when used for a CIMClass) - * as defined by the Distributed Management Task Force (DMTF) CIM Infrastructure Specification (DSP004). This class is to be used for all CIMClass - * properties. NOTE: For instance properties, use the class - * CIMProperty. - * - * @param - * Type parameter. - * - */ -public class CIMClassProperty extends CIMProperty implements CIMQualifiedElementInterface { - - private static final long serialVersionUID = -1455588144409014311L; - - private CIMQualifiedElementInterfaceImpl iQualiImpl; - - /** - * This method constructs an instance of CIMClassProperty. - * - * @param pName - * The name of the property. - * @param pType - * The data type of the property. - * @param pValue - * The value of the property. - * @param pQualifiers - * The qualifiers for the property. - * @param pKey - * true if the property is a key, otherwise - * false. - * @param pPropagated - * true if the property was inherited, otherwise - * false. - * @param pOriginClass - * The original class in which the property was defined. - */ - public CIMClassProperty(String pName, CIMDataType pType, E pValue, - CIMQualifier[] pQualifiers, boolean pKey, boolean pPropagated, String pOriginClass) { - super(pName, pType, pValue, pKey | hasKey(pQualifiers), pPropagated, pOriginClass); - this.iQualiImpl = new CIMQualifiedElementInterfaceImpl(pQualifiers, pKey, true); - } - - /** - * Compares this object against the specified object. The result is - * true if and only if the argument is not null and is a - * CIMClassProperty that represents the same name, type and - * value as this object. - * - * @param pObj - * The object to compare with. - * @return true if the objects are the same; false - * otherwise. - */ - @Override - public boolean equals(Object pObj) { - if (!(pObj instanceof CIMClassProperty)) return false; - if (!super.equals(pObj)) return false; - return this.iQualiImpl.equals(((CIMClassProperty) pObj).iQualiImpl); - } - - /** - * Returns a CIMClassProperty filtered as specified. - * - * @param pIncludeQualifiers - * If true all qualifiers are returned; otherwise no - * qualifiers. - * @param pIncludeClassOrigin - * If true the class origin is included; otherwise - * no class origin is present. - * @return A filtered CIMClassProperty. - */ - public CIMClassProperty filter(boolean pIncludeQualifiers, boolean pIncludeClassOrigin) { - return filter(pIncludeQualifiers, pIncludeClassOrigin, false); - } - - /** - * Returns a CIMClassProperty filtered as specified. - * - * @param pIncludeQualifiers - * If true all qualifiers are returned; otherwise no - * qualifiers. - * @param pIncludeClassOrigin - * If true the class origin is included; otherwise - * no class origin is present. - * @param pLocalOnly - * If true only the qualifiers that were not - * propagated will be included. - * @return CIMClassProperty A filtered CIMClassProperty. - */ - public CIMClassProperty filter(boolean pIncludeQualifiers, boolean pIncludeClassOrigin, - boolean pLocalOnly) { - // FIXME: should key depend on pIncludeQualifiers? - return new CIMClassProperty(getName(), getDataType(), getValue(), - pIncludeQualifiers ? this.iQualiImpl.getQualifiers(pLocalOnly) : null, isKey(), - isPropagated(), pIncludeClassOrigin ? getOriginClass() : null); - } - - /** - * Get a qualifier by index. - * - * @param pIndex - * The index of the qualifier to retrieve. - * @return The qualifier at the specified index. - * @throws ArrayIndexOutOfBoundsException - */ - public CIMQualifier getQualifier(int pIndex) throws ArrayIndexOutOfBoundsException { - return this.iQualiImpl.getQualifier(pIndex); - } - - /** - * Gets a qualifier by name. - * - * @param pName - * The name of the qualifier to get. - * @return The qualifier requested or null if the qualifier - * does not exist. - */ - public CIMQualifier getQualifier(String pName) { - return this.iQualiImpl.getQualifier(pName); - } - - /** - * Get the number of qualifiers defined for this property. - * - * @return The number of qualifiers defined for this property. - */ - public int getQualifierCount() { - return this.iQualiImpl.getQualifierCount(); - } - - /** - * Returns the list of qualifiers for this property. - * - * @return Qualifiers for this property. - */ - public CIMQualifier[] getQualifiers() { - return this.iQualiImpl.getQualifiers(); - } - - /** - * Gets a qualifier value by name. - * - * @param pName - * The name of the qualifier to get. - * @return null if the qualifier does not exist or value is - * null, otherwise returns the reference to the - * qualifier. - */ - public Object getQualifierValue(String pName) { - return this.iQualiImpl.getQualifierValue(pName); - } - - /** - * Checks whether the specified qualifier is one of the qualifiers defined - * for this property. - * - * @param pName - * The name of the qualifier. - * @return true if the qualifier exists in this property, - * otherwise false. - */ - public boolean hasQualifier(String pName) { - return this.iQualiImpl.hasQualifier(pName); - } - - /** - * Checks whether the specified qualifier is one of the qualifiers defined - * for this property with the specified value. This method will return - * false if the qualifier is not applied or if the value does - * not match. - * - * @param pName - * The name of the qualifier. - * @param pValue - * The value to be tested. - * @return true if the qualifier exists in this property, - * otherwise false. - */ - public boolean hasQualifierValue(String pName, Object pValue) { - return this.iQualiImpl.hasQualifierValue(pName, pValue); - } - - /** - * Checks whether an array of qualifiers contains a key. - * - * @param pQualiA - * Array of qualifiers. - * - * @return true if at least one of the qualifiers is a key, - * false otherwise. - */ - private static boolean hasKey(CIMQualifier[] pQualiA) { - if (pQualiA == null) return false; - Boolean trueBool = Boolean.TRUE; - for (int i = 0; i < pQualiA.length; i++) { - CIMQualifier quali = pQualiA[i]; - if ("key".equalsIgnoreCase(quali.getName())) { return trueBool.equals(quali.getValue()); } - } - return false; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant + * 1660756 2007-02-22 ebak Embedded object support + * 1669961 2006-04-16 lupusalex CIMTypedElement.getType() =>getDataType() + * 1737123 2007-06-15 ebak Differences to JSR48 public review draft + * 1737141 2007-06-18 ebak Sync up with JSR48 evolution + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2823494 2009-08-03 rgummada Change Boolean constructor to static + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + * 2944839 2010-02-08 blaschke-oss Remove redundant toString() methods + * 2944842 2010-02-08 blaschke-oss Missing thrown ArrayIndexOutOfBoundsException + * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues + * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMQualifiedElementInterfaceImpl; + +//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:58 EST 2010 +/** + * This class represents a CIM property (when used for a CIMClass) + * as defined by the Distributed Management Task Force (DMTF) CIM Infrastructure Specification (DSP004). This class is to be used for all CIMClass + * properties. NOTE: For instance properties, use the class + * CIMProperty. + * + * @param + * Type parameter. + * + */ +public class CIMClassProperty extends CIMProperty implements CIMQualifiedElementInterface { + private static final long serialVersionUID = -1455588144409014311L; + + private CIMQualifiedElementInterfaceImpl iQualiImpl; + + /** + * This method constructs an instance of CIMClassProperty. + * + * @param pName + * The name of the property. + * @param pType + * The data type of the property. + * @param pValue + * The value of the property. + * @param pQualifiers + * The qualifiers for the property. + * @param pKey + * true if the property is a key, otherwise + * false. + * @param pPropagated + * true if the property was inherited, otherwise + * false. + * @param pOriginClass + * The original class in which the property was defined. + */ + public CIMClassProperty( + String pName, + CIMDataType pType, + E pValue, + CIMQualifier[] pQualifiers, + boolean pKey, + boolean pPropagated, + String pOriginClass + ) { + super(pName, pType, pValue, pKey | hasKey(pQualifiers), pPropagated, pOriginClass); + this.iQualiImpl = new CIMQualifiedElementInterfaceImpl(pQualifiers, pKey, true); + } + + /** + * Compares this object against the specified object. The result is + * true if and only if the argument is not null and is a + * CIMClassProperty that represents the same name, type and + * value as this object. + * + * @param pObj + * The object to compare with. + * @return true if the objects are the same; false + * otherwise. + */ + @Override + public boolean equals(Object pObj) { + if (!(pObj instanceof CIMClassProperty)) return false; + if (!super.equals(pObj)) return false; + return this.iQualiImpl.equals(((CIMClassProperty) pObj).iQualiImpl); + } + + /** + * Returns a CIMClassProperty filtered as specified. + * + * @param pIncludeQualifiers + * If true all qualifiers are returned; otherwise no + * qualifiers. + * @param pIncludeClassOrigin + * If true the class origin is included; otherwise + * no class origin is present. + * @return A filtered CIMClassProperty. + */ + public CIMClassProperty filter(boolean pIncludeQualifiers, boolean pIncludeClassOrigin) { + return filter(pIncludeQualifiers, pIncludeClassOrigin, false); + } + + /** + * Returns a CIMClassProperty filtered as specified. + * + * @param pIncludeQualifiers + * If true all qualifiers are returned; otherwise no + * qualifiers. + * @param pIncludeClassOrigin + * If true the class origin is included; otherwise + * no class origin is present. + * @param pLocalOnly + * If true only the qualifiers that were not + * propagated will be included. + * @return CIMClassProperty A filtered CIMClassProperty. + */ + public CIMClassProperty filter(boolean pIncludeQualifiers, boolean pIncludeClassOrigin, boolean pLocalOnly) { + // FIXME: should key depend on pIncludeQualifiers? + return new CIMClassProperty( + getName(), + getDataType(), + getValue(), + pIncludeQualifiers ? this.iQualiImpl.getQualifiers(pLocalOnly) : null, + isKey(), + isPropagated(), + pIncludeClassOrigin ? getOriginClass() : null + ); + } + + /** + * Get a qualifier by index. + * + * @param pIndex + * The index of the qualifier to retrieve. + * @return The qualifier at the specified index. + * @throws ArrayIndexOutOfBoundsException + */ + public CIMQualifier getQualifier(int pIndex) throws ArrayIndexOutOfBoundsException { + return this.iQualiImpl.getQualifier(pIndex); + } + + /** + * Gets a qualifier by name. + * + * @param pName + * The name of the qualifier to get. + * @return The qualifier requested or null if the qualifier + * does not exist. + */ + public CIMQualifier getQualifier(String pName) { + return this.iQualiImpl.getQualifier(pName); + } + + /** + * Get the number of qualifiers defined for this property. + * + * @return The number of qualifiers defined for this property. + */ + public int getQualifierCount() { + return this.iQualiImpl.getQualifierCount(); + } + + /** + * Returns the list of qualifiers for this property. + * + * @return Qualifiers for this property. + */ + public CIMQualifier[] getQualifiers() { + return this.iQualiImpl.getQualifiers(); + } + + /** + * Gets a qualifier value by name. + * + * @param pName + * The name of the qualifier to get. + * @return null if the qualifier does not exist or value is + * null, otherwise returns the reference to the + * qualifier. + */ + public Object getQualifierValue(String pName) { + return this.iQualiImpl.getQualifierValue(pName); + } + + /** + * Checks whether the specified qualifier is one of the qualifiers defined + * for this property. + * + * @param pName + * The name of the qualifier. + * @return true if the qualifier exists in this property, + * otherwise false. + */ + public boolean hasQualifier(String pName) { + return this.iQualiImpl.hasQualifier(pName); + } + + /** + * Checks whether the specified qualifier is one of the qualifiers defined + * for this property with the specified value. This method will return + * false if the qualifier is not applied or if the value does + * not match. + * + * @param pName + * The name of the qualifier. + * @param pValue + * The value to be tested. + * @return true if the qualifier exists in this property, + * otherwise false. + */ + public boolean hasQualifierValue(String pName, Object pValue) { + return this.iQualiImpl.hasQualifierValue(pName, pValue); + } + + /** + * Checks whether an array of qualifiers contains a key. + * + * @param pQualiA + * Array of qualifiers. + * + * @return true if at least one of the qualifiers is a key, + * false otherwise. + */ + private static boolean hasKey(CIMQualifier[] pQualiA) { + if (pQualiA == null) return false; + Boolean trueBool = Boolean.TRUE; + for (int i = 0; i < pQualiA.length; i++) { + CIMQualifier quali = pQualiA[i]; + if ("key".equalsIgnoreCase(quali.getName())) { + return trueBool.equals(quali.getValue()); + } + } + return false; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMDataType.java b/src/main/java/org/metricshub/wbem/javax/cim/CIMDataType.java similarity index 79% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/CIMDataType.java rename to src/main/java/org/metricshub/wbem/javax/cim/CIMDataType.java index 4ffa30d..cd68ad6 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMDataType.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/CIMDataType.java @@ -1,737 +1,793 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1663270 2007-02-19 ebak Minor performance problems - * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant - * 1660756 2007-02-22 ebak Embedded object support - * 1669225 2007-04-16 lupusalex Ctor CIMDataType(int) shall be private - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2870455 2009-09-30 blaschke-oss Missing CLASS_ARRAY_T in CIMDataType - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - * 3004779 2010-06-16 blaschke-oss TCK: CIMDataType not throwing IllegalArgumentException - * 3513353 2012-03-30 blaschke-oss TCK: CIMDataType arrays must have length >= 1 - * 3513349 2012-03-31 blaschke-oss TCK: CIMDataType must not accept null string - * 3517503 2012-04-13 blaschke-oss Missing parm in CIMDataType ctor javadoc - * 3521131 2012-04-24 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final II - * 2632 2013-05-02 blaschke-oss Potential Null Point Exception in CIMDataType - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.Serializable; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.MOF; - -//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_02) on Sun Apr 22 15:31:53 EDT 2012 -/** - * This class represents a CIM data type as defined by the Distributed - * Management Task Force (DMTF) CIM - * Infrastructure Specification (DSP004). The specification only allows a set number of data types. This - * class defines the mapping of CIM data types to Java objects.
      - *
      - * Note: CIM allows the fixed size of an array as part of the data type. The - * predefined classes are unbounded.
      - *
      - * The following table shows the mapping of CIM data type to Java.
      - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
      CIM Data TypeJava Representation
      uint8UnsignedInteger8
      sint8Byte
      uint16UnsignedInteger16
      sint16Short
      uint32UnsignedInteger32
      sint32Integer
      uint64UnsignedInteger64
      sint64Long
      stringString
      booleanBoolean
      real32Float
      real64Double
      datetimeCIMDataTimeAbsolute
      - * CIMDataTimeInterval
      <classname> refCIMObjectPath
      char16Character
      mapping of CIM data type to Java
      - */ -public class CIMDataType extends Object implements Serializable { - - private static final long serialVersionUID = 1L; - - /** - * Boolean - * - * @see Boolean - */ - public static final int BOOLEAN = 9; - - /** - * Boolean unbounded array data type - * - * @see Boolean - */ - public static final CIMDataType BOOLEAN_ARRAY_T = new CIMDataType(BOOLEAN, true); - - /** - * Boolean data type - * - * @see Boolean - */ - public static final CIMDataType BOOLEAN_T = new CIMDataType(BOOLEAN, false); - - /** - * 16-bit UCS-2 character - * - * @see Character - */ - public static final int CHAR16 = 13; - - /** - * 16-bit UCS-2 character unbounded Array type - * - * @see Character - */ - public static final CIMDataType CHAR16_ARRAY_T = new CIMDataType(CHAR16, true); - - /** - * 16-bit UCS-2 character data type - * - * @see Character - */ - public static final CIMDataType CHAR16_T = new CIMDataType(CHAR16, false); - - /** - * CIMClass type - */ - public static final int CLASS = 17; - - /** - * CIMClass unbounded Array type - * - * @see CIMClass - */ - public static final CIMDataType CLASS_ARRAY_T = new CIMDataType(CLASS, true); - - /** - * CIMClass type - * - * @see CIMClass - */ - public static final CIMDataType CLASS_T = new CIMDataType(CLASS, false); - - /** - * A string containing the date-time - * - * @see CIMDateTimeInterval CIMDateTimeAbsolute - */ - public static final int DATETIME = 12; - - /** - * A date-time unbounded array data type - * - * @see CIMDateTimeInterval CIMDateTimeAbsolute - */ - public static final CIMDataType DATETIME_ARRAY_T = new CIMDataType(DATETIME, true); - - /** - * A date-time data type - * - * @see CIMDateTimeInterval CIMDateTimeAbsolute - */ - public static final CIMDataType DATETIME_T = new CIMDataType(DATETIME, false); - - /** - * Invalid type - */ - public static final int INVALID = -1; - - /** - * Invalid data type - */ - public static final CIMDataType INVALID_T = new CIMDataType(INVALID, false); - - /** - * Null type - */ - public static final int NULL = 16; - - /** - * CIMInstance type - * - * @see CIMInstance - */ - public static final int OBJECT = 15; - - /** - * CIMInstance unbounded Array type - * - * @see CIMInstance - */ - public static final CIMDataType OBJECT_ARRAY_T = new CIMDataType(OBJECT, true); - - /** - * CIMInstance type data type (Note: For CIMV2, this can only be used when - * the property has either an EmbeddedInstance or EmbeddedObject qualifier) - * - * @see CIMInstance - */ - public static final CIMDataType OBJECT_T = new CIMDataType(OBJECT, false); - - /** - * IEEE 4-byte floating-point - * - * @see Float - */ - public static final int REAL32 = 10; - - /** - * IEEE 4-byte floating-point unbounded array data type - * - * @see Float - */ - public static final CIMDataType REAL32_ARRAY_T = new CIMDataType(REAL32, true); - - /** - * IEEE 4-byte floating-point data type - * - * @see Float - */ - public static final CIMDataType REAL32_T = new CIMDataType(REAL32, false); - - /** - * IEEE 8-byte floating-point - * - * @see Double - */ - public static final int REAL64 = 11; - - /** - * IEEE 8-byte floating-point unbounded array data type - * - * @see Double - */ - public static final CIMDataType REAL64_ARRAY_T = new CIMDataType(REAL64, true); - - /** - * IEEE 8-byte floating-point data type - * - * @see Double - */ - public static final CIMDataType REAL64_T = new CIMDataType(REAL64, false); - - /** - * Reference type - * - * @see CIMObjectPath - */ - public static final int REFERENCE = 14; - - /** - * Signed 16-bit integer - * - * @see Short - */ - public static final int SINT16 = 3; - - /** - * Signed 16-bit integer unbounded array data type - * - * @see Short - */ - public static final CIMDataType SINT16_ARRAY_T = new CIMDataType(SINT16, true); - - /** - * Signed 16-bit integer data type - * - * @see Short - */ - public static final CIMDataType SINT16_T = new CIMDataType(SINT16, false); - - /** - * Signed 32-bit integer - * - * @see Integer - */ - public static final int SINT32 = 5; - - /** - * Signed 32-bit integer unbounded array data type - * - * @see Integer - */ - public static final CIMDataType SINT32_ARRAY_T = new CIMDataType(SINT32, true); - - /** - * Signed 32-bit integer data type - * - * @see Integer - */ - public static final CIMDataType SINT32_T = new CIMDataType(SINT32, false); - - /** - * Signed 64-bit integer - */ - public static final int SINT64 = 7; - - /** - * Signed 64-bit integer unbounded array data type - * - * @see Long - */ - public static final CIMDataType SINT64_ARRAY_T = new CIMDataType(SINT64, true); - - /** - * Signed 64-bit integer data type - * - * @see Long - */ - public static final CIMDataType SINT64_T = new CIMDataType(SINT64, false); - - /** - * Signed 8-bit integer - * - * @see Byte - */ - public static final int SINT8 = 1; - - /** - * Signed 8-bit integer unbounded array data type - * - * @see Byte - */ - public static final CIMDataType SINT8_ARRAY_T = new CIMDataType(SINT8, true); - - /** - * Signed 8-bit integer data type - * - * @see Byte - */ - public static final CIMDataType SINT8_T = new CIMDataType(SINT8, false); - - /** - * UCS-2 string - * - * @see String - */ - public static final int STRING = 8; - - /** - * UCS-2 string unbounded array data type - * - * @see String - */ - public static final CIMDataType STRING_ARRAY_T = new CIMDataType(STRING, true); - - /** - * UCS-2 string data type - * - * @see String - */ - public static final CIMDataType STRING_T = new CIMDataType(STRING, false); - - /** - * Unsigned 16-bit integer - * - * @see UnsignedInteger16 - */ - public static final int UINT16 = 2; - - /** - * Unsigned 16-bit integer unbounded array data type - * - * @see UnsignedInteger16 - */ - public static final CIMDataType UINT16_ARRAY_T = new CIMDataType(UINT16, true); - - /** - * Unsigned 16-bit integer data type - * - * @see UnsignedInteger16 - */ - public static final CIMDataType UINT16_T = new CIMDataType(UINT16, false); - - /** - * Unsigned 32-bit integer - * - * @see UnsignedInteger32 - */ - public static final int UINT32 = 4; - - /** - * Unsigned 32-bit integer unbounded array data type - * - * @see UnsignedInteger32 - */ - public static final CIMDataType UINT32_ARRAY_T = new CIMDataType(UINT32, true); - - /** - * Unsigned 32-bit integer data type - * - * @see UnsignedInteger32 - */ - public static final CIMDataType UINT32_T = new CIMDataType(UINT32, false); - - /** - * Unsigned 64-bit integer - * - * @see UnsignedInteger64 - */ - public static final int UINT64 = 6; - - /** - * Unsigned 64-bit integer unbounded array data type - * - * @see UnsignedInteger64 - */ - public static final CIMDataType UINT64_ARRAY_T = new CIMDataType(UINT64, true); - - /** - * Unsigned 64-bit integer data type - * - * @see UnsignedInteger64 - */ - public static final CIMDataType UINT64_T = new CIMDataType(UINT64, false); - - /** - * Unsigned 8-bit integer - * - * @see UnsignedInteger8 - */ - public static final int UINT8 = 0; - - /** - * Unsigned 8-bit integer unbounded array data type - * - * @see UnsignedInteger8 - */ - public static final CIMDataType UINT8_ARRAY_T = new CIMDataType(UINT8, true); - - /** - * Unsigned 8-bit integer data type - * - * @see UnsignedInteger8 - */ - public static final CIMDataType UINT8_T = new CIMDataType(UINT8, false); - - private int iTypeCode; - - /** - * non array if <0
      - * unbounded if =0
      - * bounded if >0 - */ - private int iBound; - - private String iRefClassName; - - /** - * Sets the data type (non-array). - * - * @param pType - * The data type of the class. - */ - private void setType(int pType) { - this.iTypeCode = pType; - this.iBound = -1; - } - - /** - * Sets the data type (array). - * - * @param pType - * The data type of the class. - * @param pBound - * Array bounds or unbounded if zero. - * - */ - private void setType(int pType, int pBound) { - this.iTypeCode = pType; - this.iBound = pBound; - } - - /** - * Constructs a CIMDataType. - * - * @param pType - * The data type as defined in the CIM class. - * @param pIsArray - * true if data type is unbounded array, - * false if data type is scalar. - * @throws IllegalArgumentException - */ - public CIMDataType(int pType, boolean pIsArray) throws IllegalArgumentException { - if (pIsArray) { - setType(pType, 0); - } else { - setType(pType); - } - } - - /** - * Constructs a CIMDataType array object of the specified type - * and size. This should only be used when the size is being limited/defined - * as part of the data type. - * - * @param pType - * The data type as defined in the CIM class. - * @param pSize - * The maximum number of elements in the array. - * @throws IllegalArgumentException - * If the pSize value specified is not a positive - * integer. - */ - public CIMDataType(int pType, int pSize) throws IllegalArgumentException { - if (pSize <= 0) throw new IllegalArgumentException( - "Maximum number of elements must be positive integer!"); - setType(pType, pSize); - } - - /** - * Creates a new CIM REFERENCE data type object with the specified class - * reference. - * - * @param pClassName - * The CIM class reference name. - * @throws IllegalArgumentException - * If the pClassName is null. - */ - public CIMDataType(String pClassName) { - if (pClassName == null) throw new IllegalArgumentException("Class name must not be null!"); - setType(REFERENCE); - this.iRefClassName = pClassName; - } - - /** - * Creates a new CIM REFERENCE array data type object with the specified - * class reference. - * - * @param pClassName - * The CIM class reference name. - * @param pSize - * The size of the array. 0 indicates the array is unbounded. - * @throws IllegalArgumentException - * If the pClassName is null. - */ - public CIMDataType(String pClassName, int pSize) { - if (pClassName == null) throw new IllegalArgumentException("Class name must not be null!"); - if (pSize < 0) throw new IllegalArgumentException( - "Maximum number of elements cannot be negative integer!"); - setType(REFERENCE, pSize); - this.iRefClassName = pClassName; - } - - /** - * Checks that the specified CIMDataType is equal to this - * CIMDataType. - * - * @param pObj - * The object to compare. - * @return true if the specified object is equal to this - * CIMDataType; false otherwise. - */ - @Override - public boolean equals(Object pObj) { - if (this == pObj) return true; - if (!(pObj instanceof CIMDataType)) return false; - CIMDataType that = (CIMDataType) pObj; - if (this.iRefClassName == null && that.iRefClassName != null) return false; - boolean refMatch = (this.iRefClassName == null ? true : this.iRefClassName - .equals(that.iRefClassName)); - return (this.iTypeCode == that.iTypeCode && isArray() == that.isArray() && refMatch); - } - - /** - * Get the data type of an object. - * - * @param pObj - * The object whose data type is to be returned. - * @return The data type of the specified object. - * @throws IllegalArgumentException - * If pObj is not a valid CIM Type. - */ - public static final CIMDataType getDataType(Object pObj) throws IllegalArgumentException { - if (pObj instanceof Byte) { return SINT8_T; } - if (pObj instanceof Byte[]) { return SINT8_ARRAY_T; } - if (pObj instanceof Short) { return SINT16_T; } - if (pObj instanceof Short[]) { return SINT16_ARRAY_T; } - if (pObj instanceof Integer) { return SINT32_T; } - if (pObj instanceof Integer[]) { return SINT32_ARRAY_T; } - if (pObj instanceof Long) { return SINT64_T; } - if (pObj instanceof Long[]) { return SINT64_ARRAY_T; } - if (pObj instanceof UnsignedInteger8) { return UINT8_T; } - if (pObj instanceof UnsignedInteger8[]) { return UINT8_ARRAY_T; } - if (pObj instanceof UnsignedInteger16) { return UINT16_T; } - if (pObj instanceof UnsignedInteger16[]) { return UINT16_ARRAY_T; } - if (pObj instanceof UnsignedInteger32) { return UINT32_T; } - if (pObj instanceof UnsignedInteger32[]) { return UINT32_ARRAY_T; } - if (pObj instanceof UnsignedInteger64) { return UINT64_T; } - if (pObj instanceof UnsignedInteger64[]) { return UINT64_ARRAY_T; } - if (pObj instanceof Boolean) { return BOOLEAN_T; } - if (pObj instanceof Boolean[]) { return BOOLEAN_ARRAY_T; } - if (pObj instanceof Character) { return CHAR16_T; } - if (pObj instanceof Character[]) { return CHAR16_ARRAY_T; } - if (pObj instanceof String) { return STRING_T; } - if (pObj instanceof String[]) { return STRING_ARRAY_T; } - if (pObj instanceof Float) { return REAL32_T; } - if (pObj instanceof Float[]) { return REAL32_ARRAY_T; } - if (pObj instanceof Double) { return REAL64_T; } - if (pObj instanceof Double[]) { return REAL64_ARRAY_T; } - if (pObj instanceof CIMDateTime) { return DATETIME_T; } - if (pObj instanceof CIMDateTime[]) { return DATETIME_ARRAY_T; } - if (pObj instanceof CIMClass) { return CLASS_T; } - if (pObj instanceof CIMClass[]) { return CLASS_ARRAY_T; } - if (pObj instanceof CIMInstance) { return OBJECT_T; } - if (pObj instanceof CIMInstance[]) { return OBJECT_ARRAY_T; } - if (pObj instanceof CIMObjectPath) { - CIMObjectPath op = (CIMObjectPath) pObj; - return new CIMDataType(op.getObjectName()); - } - if (pObj instanceof CIMObjectPath[]) { - CIMObjectPath[] ops = (CIMObjectPath[]) pObj; - for (int i = 0; i < ops.length; i++) - if (ops[i] != null) return new CIMDataType(ops[i].getObjectName(), 0); - } - // TODO: tracing - /* - * String msg= "Cannot determine the CIMDataType of class:"+ - * pObj.getClass().getName()+"!"; - */ - throw new IllegalArgumentException("Invalid CIM Type!"); - } - - /** - * Returns the class name of the CIM REFERENCE data type. - * - * @return The CIM REFERENCE class name. - */ - public String getRefClassName() { - return this.iRefClassName; - } - - /** - * Returns the size of the maximum number of elements an array data type may - * hold. - * - * @return The maximum size of the array data type. - */ - public int getSize() { - return this.iBound; - } - - /** - * Returns the data type. - * - * @return The data type. - */ - public int getType() { - return this.iTypeCode; - } - - /** - * Checks if the data type is an array type. - * - * @return true if the data type is an array type, - * false otherwise. - */ - public boolean isArray() { - return this.iBound >= 0; - } - - /** - * Returns a String representation of the - * CIMDataType. This method is intended to be used only for - * debugging purposes, and the format of the returned string may vary - * between implementations. The returned string may be empty but may not be - * null. - * - * @return A string representation of this data type. - */ - @Override - public String toString() { - return MOF.dataType(this); - } -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1663270 2007-02-19 ebak Minor performance problems + * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant + * 1660756 2007-02-22 ebak Embedded object support + * 1669225 2007-04-16 lupusalex Ctor CIMDataType(int) shall be private + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2870455 2009-09-30 blaschke-oss Missing CLASS_ARRAY_T in CIMDataType + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + * 3004779 2010-06-16 blaschke-oss TCK: CIMDataType not throwing IllegalArgumentException + * 3513353 2012-03-30 blaschke-oss TCK: CIMDataType arrays must have length >= 1 + * 3513349 2012-03-31 blaschke-oss TCK: CIMDataType must not accept null string + * 3517503 2012-04-13 blaschke-oss Missing parm in CIMDataType ctor javadoc + * 3521131 2012-04-24 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final II + * 2632 2013-05-02 blaschke-oss Potential Null Point Exception in CIMDataType + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.Serializable; +import org.metricshub.wbem.sblim.cimclient.internal.util.MOF; + +//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_02) on Sun Apr 22 15:31:53 EDT 2012 +/** + * This class represents a CIM data type as defined by the Distributed + * Management Task Force (DMTF) CIM + * Infrastructure Specification (DSP004). The specification only allows a set number of data types. This + * class defines the mapping of CIM data types to Java objects.
      + *
      + * Note: CIM allows the fixed size of an array as part of the data type. The + * predefined classes are unbounded.
      + *
      + * The following table shows the mapping of CIM data type to Java.
      + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
      CIM Data TypeJava Representation
      uint8UnsignedInteger8
      sint8Byte
      uint16UnsignedInteger16
      sint16Short
      uint32UnsignedInteger32
      sint32Integer
      uint64UnsignedInteger64
      sint64Long
      stringString
      booleanBoolean
      real32Float
      real64Double
      datetimeCIMDataTimeAbsolute
      + * CIMDataTimeInterval
      <classname> refCIMObjectPath
      char16Character
      mapping of CIM data type to Java
      + */ +public class CIMDataType implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * Boolean + * + * @see Boolean + */ + public static final int BOOLEAN = 9; + + /** + * Boolean unbounded array data type + * + * @see Boolean + */ + public static final CIMDataType BOOLEAN_ARRAY_T = new CIMDataType(BOOLEAN, true); + + /** + * Boolean data type + * + * @see Boolean + */ + public static final CIMDataType BOOLEAN_T = new CIMDataType(BOOLEAN, false); + + /** + * 16-bit UCS-2 character + * + * @see Character + */ + public static final int CHAR16 = 13; + + /** + * 16-bit UCS-2 character unbounded Array type + * + * @see Character + */ + public static final CIMDataType CHAR16_ARRAY_T = new CIMDataType(CHAR16, true); + + /** + * 16-bit UCS-2 character data type + * + * @see Character + */ + public static final CIMDataType CHAR16_T = new CIMDataType(CHAR16, false); + + /** + * CIMClass type + */ + public static final int CLASS = 17; + + /** + * CIMClass unbounded Array type + * + * @see CIMClass + */ + public static final CIMDataType CLASS_ARRAY_T = new CIMDataType(CLASS, true); + + /** + * CIMClass type + * + * @see CIMClass + */ + public static final CIMDataType CLASS_T = new CIMDataType(CLASS, false); + + /** + * A string containing the date-time + * + * @see CIMDateTimeInterval CIMDateTimeAbsolute + */ + public static final int DATETIME = 12; + + /** + * A date-time unbounded array data type + * + * @see CIMDateTimeInterval CIMDateTimeAbsolute + */ + public static final CIMDataType DATETIME_ARRAY_T = new CIMDataType(DATETIME, true); + + /** + * A date-time data type + * + * @see CIMDateTimeInterval CIMDateTimeAbsolute + */ + public static final CIMDataType DATETIME_T = new CIMDataType(DATETIME, false); + + /** + * Invalid type + */ + public static final int INVALID = -1; + + /** + * Invalid data type + */ + public static final CIMDataType INVALID_T = new CIMDataType(INVALID, false); + + /** + * Null type + */ + public static final int NULL = 16; + + /** + * CIMInstance type + * + * @see CIMInstance + */ + public static final int OBJECT = 15; + + /** + * CIMInstance unbounded Array type + * + * @see CIMInstance + */ + public static final CIMDataType OBJECT_ARRAY_T = new CIMDataType(OBJECT, true); + + /** + * CIMInstance type data type (Note: For CIMV2, this can only be used when + * the property has either an EmbeddedInstance or EmbeddedObject qualifier) + * + * @see CIMInstance + */ + public static final CIMDataType OBJECT_T = new CIMDataType(OBJECT, false); + + /** + * IEEE 4-byte floating-point + * + * @see Float + */ + public static final int REAL32 = 10; + + /** + * IEEE 4-byte floating-point unbounded array data type + * + * @see Float + */ + public static final CIMDataType REAL32_ARRAY_T = new CIMDataType(REAL32, true); + + /** + * IEEE 4-byte floating-point data type + * + * @see Float + */ + public static final CIMDataType REAL32_T = new CIMDataType(REAL32, false); + + /** + * IEEE 8-byte floating-point + * + * @see Double + */ + public static final int REAL64 = 11; + + /** + * IEEE 8-byte floating-point unbounded array data type + * + * @see Double + */ + public static final CIMDataType REAL64_ARRAY_T = new CIMDataType(REAL64, true); + + /** + * IEEE 8-byte floating-point data type + * + * @see Double + */ + public static final CIMDataType REAL64_T = new CIMDataType(REAL64, false); + + /** + * Reference type + * + * @see CIMObjectPath + */ + public static final int REFERENCE = 14; + + /** + * Signed 16-bit integer + * + * @see Short + */ + public static final int SINT16 = 3; + + /** + * Signed 16-bit integer unbounded array data type + * + * @see Short + */ + public static final CIMDataType SINT16_ARRAY_T = new CIMDataType(SINT16, true); + + /** + * Signed 16-bit integer data type + * + * @see Short + */ + public static final CIMDataType SINT16_T = new CIMDataType(SINT16, false); + + /** + * Signed 32-bit integer + * + * @see Integer + */ + public static final int SINT32 = 5; + + /** + * Signed 32-bit integer unbounded array data type + * + * @see Integer + */ + public static final CIMDataType SINT32_ARRAY_T = new CIMDataType(SINT32, true); + + /** + * Signed 32-bit integer data type + * + * @see Integer + */ + public static final CIMDataType SINT32_T = new CIMDataType(SINT32, false); + + /** + * Signed 64-bit integer + */ + public static final int SINT64 = 7; + + /** + * Signed 64-bit integer unbounded array data type + * + * @see Long + */ + public static final CIMDataType SINT64_ARRAY_T = new CIMDataType(SINT64, true); + + /** + * Signed 64-bit integer data type + * + * @see Long + */ + public static final CIMDataType SINT64_T = new CIMDataType(SINT64, false); + + /** + * Signed 8-bit integer + * + * @see Byte + */ + public static final int SINT8 = 1; + + /** + * Signed 8-bit integer unbounded array data type + * + * @see Byte + */ + public static final CIMDataType SINT8_ARRAY_T = new CIMDataType(SINT8, true); + + /** + * Signed 8-bit integer data type + * + * @see Byte + */ + public static final CIMDataType SINT8_T = new CIMDataType(SINT8, false); + + /** + * UCS-2 string + * + * @see String + */ + public static final int STRING = 8; + + /** + * UCS-2 string unbounded array data type + * + * @see String + */ + public static final CIMDataType STRING_ARRAY_T = new CIMDataType(STRING, true); + + /** + * UCS-2 string data type + * + * @see String + */ + public static final CIMDataType STRING_T = new CIMDataType(STRING, false); + + /** + * Unsigned 16-bit integer + * + * @see UnsignedInteger16 + */ + public static final int UINT16 = 2; + + /** + * Unsigned 16-bit integer unbounded array data type + * + * @see UnsignedInteger16 + */ + public static final CIMDataType UINT16_ARRAY_T = new CIMDataType(UINT16, true); + + /** + * Unsigned 16-bit integer data type + * + * @see UnsignedInteger16 + */ + public static final CIMDataType UINT16_T = new CIMDataType(UINT16, false); + + /** + * Unsigned 32-bit integer + * + * @see UnsignedInteger32 + */ + public static final int UINT32 = 4; + + /** + * Unsigned 32-bit integer unbounded array data type + * + * @see UnsignedInteger32 + */ + public static final CIMDataType UINT32_ARRAY_T = new CIMDataType(UINT32, true); + + /** + * Unsigned 32-bit integer data type + * + * @see UnsignedInteger32 + */ + public static final CIMDataType UINT32_T = new CIMDataType(UINT32, false); + + /** + * Unsigned 64-bit integer + * + * @see UnsignedInteger64 + */ + public static final int UINT64 = 6; + + /** + * Unsigned 64-bit integer unbounded array data type + * + * @see UnsignedInteger64 + */ + public static final CIMDataType UINT64_ARRAY_T = new CIMDataType(UINT64, true); + + /** + * Unsigned 64-bit integer data type + * + * @see UnsignedInteger64 + */ + public static final CIMDataType UINT64_T = new CIMDataType(UINT64, false); + + /** + * Unsigned 8-bit integer + * + * @see UnsignedInteger8 + */ + public static final int UINT8 = 0; + + /** + * Unsigned 8-bit integer unbounded array data type + * + * @see UnsignedInteger8 + */ + public static final CIMDataType UINT8_ARRAY_T = new CIMDataType(UINT8, true); + + /** + * Unsigned 8-bit integer data type + * + * @see UnsignedInteger8 + */ + public static final CIMDataType UINT8_T = new CIMDataType(UINT8, false); + + private int iTypeCode; + + /** + * non array if <0
      + * unbounded if =0
      + * bounded if >0 + */ + private int iBound; + + private String iRefClassName; + + /** + * Sets the data type (non-array). + * + * @param pType + * The data type of the class. + */ + private void setType(int pType) { + this.iTypeCode = pType; + this.iBound = -1; + } + + /** + * Sets the data type (array). + * + * @param pType + * The data type of the class. + * @param pBound + * Array bounds or unbounded if zero. + * + */ + private void setType(int pType, int pBound) { + this.iTypeCode = pType; + this.iBound = pBound; + } + + /** + * Constructs a CIMDataType. + * + * @param pType + * The data type as defined in the CIM class. + * @param pIsArray + * true if data type is unbounded array, + * false if data type is scalar. + * @throws IllegalArgumentException + */ + public CIMDataType(int pType, boolean pIsArray) throws IllegalArgumentException { + if (pIsArray) { + setType(pType, 0); + } else { + setType(pType); + } + } + + /** + * Constructs a CIMDataType array object of the specified type + * and size. This should only be used when the size is being limited/defined + * as part of the data type. + * + * @param pType + * The data type as defined in the CIM class. + * @param pSize + * The maximum number of elements in the array. + * @throws IllegalArgumentException + * If the pSize value specified is not a positive + * integer. + */ + public CIMDataType(int pType, int pSize) throws IllegalArgumentException { + if (pSize <= 0) throw new IllegalArgumentException("Maximum number of elements must be positive integer!"); + setType(pType, pSize); + } + + /** + * Creates a new CIM REFERENCE data type object with the specified class + * reference. + * + * @param pClassName + * The CIM class reference name. + * @throws IllegalArgumentException + * If the pClassName is null. + */ + public CIMDataType(String pClassName) { + if (pClassName == null) throw new IllegalArgumentException("Class name must not be null!"); + setType(REFERENCE); + this.iRefClassName = pClassName; + } + + /** + * Creates a new CIM REFERENCE array data type object with the specified + * class reference. + * + * @param pClassName + * The CIM class reference name. + * @param pSize + * The size of the array. 0 indicates the array is unbounded. + * @throws IllegalArgumentException + * If the pClassName is null. + */ + public CIMDataType(String pClassName, int pSize) { + if (pClassName == null) throw new IllegalArgumentException("Class name must not be null!"); + if (pSize < 0) throw new IllegalArgumentException("Maximum number of elements cannot be negative integer!"); + setType(REFERENCE, pSize); + this.iRefClassName = pClassName; + } + + /** + * Checks that the specified CIMDataType is equal to this + * CIMDataType. + * + * @param pObj + * The object to compare. + * @return true if the specified object is equal to this + * CIMDataType; false otherwise. + */ + @Override + public boolean equals(Object pObj) { + if (this == pObj) return true; + if (!(pObj instanceof CIMDataType)) return false; + CIMDataType that = (CIMDataType) pObj; + if (this.iRefClassName == null && that.iRefClassName != null) return false; + boolean refMatch = (this.iRefClassName == null ? true : this.iRefClassName.equals(that.iRefClassName)); + return (this.iTypeCode == that.iTypeCode && isArray() == that.isArray() && refMatch); + } + + /** + * Get the data type of an object. + * + * @param pObj + * The object whose data type is to be returned. + * @return The data type of the specified object. + * @throws IllegalArgumentException + * If pObj is not a valid CIM Type. + */ + public static final CIMDataType getDataType(Object pObj) throws IllegalArgumentException { + if (pObj instanceof Byte) { + return SINT8_T; + } + if (pObj instanceof Byte[]) { + return SINT8_ARRAY_T; + } + if (pObj instanceof Short) { + return SINT16_T; + } + if (pObj instanceof Short[]) { + return SINT16_ARRAY_T; + } + if (pObj instanceof Integer) { + return SINT32_T; + } + if (pObj instanceof Integer[]) { + return SINT32_ARRAY_T; + } + if (pObj instanceof Long) { + return SINT64_T; + } + if (pObj instanceof Long[]) { + return SINT64_ARRAY_T; + } + if (pObj instanceof UnsignedInteger8) { + return UINT8_T; + } + if (pObj instanceof UnsignedInteger8[]) { + return UINT8_ARRAY_T; + } + if (pObj instanceof UnsignedInteger16) { + return UINT16_T; + } + if (pObj instanceof UnsignedInteger16[]) { + return UINT16_ARRAY_T; + } + if (pObj instanceof UnsignedInteger32) { + return UINT32_T; + } + if (pObj instanceof UnsignedInteger32[]) { + return UINT32_ARRAY_T; + } + if (pObj instanceof UnsignedInteger64) { + return UINT64_T; + } + if (pObj instanceof UnsignedInteger64[]) { + return UINT64_ARRAY_T; + } + if (pObj instanceof Boolean) { + return BOOLEAN_T; + } + if (pObj instanceof Boolean[]) { + return BOOLEAN_ARRAY_T; + } + if (pObj instanceof Character) { + return CHAR16_T; + } + if (pObj instanceof Character[]) { + return CHAR16_ARRAY_T; + } + if (pObj instanceof String) { + return STRING_T; + } + if (pObj instanceof String[]) { + return STRING_ARRAY_T; + } + if (pObj instanceof Float) { + return REAL32_T; + } + if (pObj instanceof Float[]) { + return REAL32_ARRAY_T; + } + if (pObj instanceof Double) { + return REAL64_T; + } + if (pObj instanceof Double[]) { + return REAL64_ARRAY_T; + } + if (pObj instanceof CIMDateTime) { + return DATETIME_T; + } + if (pObj instanceof CIMDateTime[]) { + return DATETIME_ARRAY_T; + } + if (pObj instanceof CIMClass) { + return CLASS_T; + } + if (pObj instanceof CIMClass[]) { + return CLASS_ARRAY_T; + } + if (pObj instanceof CIMInstance) { + return OBJECT_T; + } + if (pObj instanceof CIMInstance[]) { + return OBJECT_ARRAY_T; + } + if (pObj instanceof CIMObjectPath) { + CIMObjectPath op = (CIMObjectPath) pObj; + return new CIMDataType(op.getObjectName()); + } + if (pObj instanceof CIMObjectPath[]) { + CIMObjectPath[] ops = (CIMObjectPath[]) pObj; + for (int i = 0; i < ops.length; i++) if (ops[i] != null) return new CIMDataType(ops[i].getObjectName(), 0); + } + // TODO: tracing + /* + * String msg= "Cannot determine the CIMDataType of class:"+ + * pObj.getClass().getName()+"!"; + */ + throw new IllegalArgumentException("Invalid CIM Type!"); + } + + /** + * Returns the class name of the CIM REFERENCE data type. + * + * @return The CIM REFERENCE class name. + */ + public String getRefClassName() { + return this.iRefClassName; + } + + /** + * Returns the size of the maximum number of elements an array data type may + * hold. + * + * @return The maximum size of the array data type. + */ + public int getSize() { + return this.iBound; + } + + /** + * Returns the data type. + * + * @return The data type. + */ + public int getType() { + return this.iTypeCode; + } + + /** + * Checks if the data type is an array type. + * + * @return true if the data type is an array type, + * false otherwise. + */ + public boolean isArray() { + return this.iBound >= 0; + } + + /** + * Returns a String representation of the + * CIMDataType. This method is intended to be used only for + * debugging purposes, and the format of the returned string may vary + * between implementations. The returned string may be empty but may not be + * null. + * + * @return A string representation of this data type. + */ + @Override + public String toString() { + return MOF.dataType(this); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMDateTime.java b/src/main/java/org/metricshub/wbem/javax/cim/CIMDateTime.java similarity index 81% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/CIMDateTime.java rename to src/main/java/org/metricshub/wbem/javax/cim/CIMDateTime.java index 9e4612f..df20a22 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMDateTime.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/CIMDateTime.java @@ -1,137 +1,134 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2227442 2008-11-05 blaschke-oss Add missing serialVersionUID - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2795671 2009-05-22 raman_arora Add Type to Comparable - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - * 3496301 2012-03-02 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.Serializable; - -//Sync'd against JSR48 1.0.0 javadoc (build 1.6.0_18) on Thu Mar 01 12:21:26 EST 2012 -/** - * This abstract class represents a CIM Datetime data type as defined by the - * Distributed Management Task Force (DMTF) CIM - * Infrastructure Specification (DSP004). It is in the format yyyyMMddHHmmss.SSSSSSsutc where: - *
        - *
      • yyyy - is a 4 digit year
      • - *
      • MM - is the month
      • - *
      • dd - is the day of the month
      • - *
      • HH - is the hour (24 hour clock)
      • - *
      • mm - is the minute
      • - *
      • ss - is the second
      • - *
      • SSSSSS - is the number of microseconds
      • - *
      • s - is "+" or "-", indicating the sign of the UTC (Universal Coordinated - * Time; for all intents and purposes the same as Greenwich Mean Time) - * correction field, or a ":". In the case of a ":" the value is interpreted as - * a time interval, and yyyyMM are interpreted as days.
      • - *
      • utc - is the offset from UTC in minutes (using the sign indicated by s). - * It is ignored for a time interval.
      • - *
      - * - * For example, the absolute datetime for Monday, May 25, 1998, at 1:30 PM EST - * would be represented as: 19980525133015.000000-300. Values must be - * zero-padded so that the entire string is always the same 25-character length. - * Fields which are not significant must be replaced with asterisk characters. - * Similarly, intervals use the same format, except that the interpretation of - * the fields is based on elapsed time.
      - * For example, the interval datetime for an elapsed time of 1 day, 13 hours, 23 - * minutes, 12 seconds would be: 00000001132312.000000:000. A UTC offset of zero - * is always used for interval properties. - */ -public abstract class CIMDateTime extends Object implements Serializable, Comparable { - - private static final long serialVersionUID = 3424668043014662166L; - - /** - * Creates a CIMDateTime object using a string. - * - * @param pDateString - * A string in the format of yyyyMMddHHmmss.SSSSSSsutc. - * @throws IllegalArgumentException - * If string is not in the correct format. - */ - public CIMDateTime(String pDateString) throws IllegalArgumentException { - // FIXME: what to do here? - } - - protected CIMDateTime() { - // FIXME: what to do here? - } - - /** - * Determines whether the CIMDateTime that is passed in is - * equal to the current CIMDateTime object. - * - * @param pObj - * The CIMDateTime object to compare to. - * @return true if this CIMDateTime object is equal to the one - * that was passed in, otherwise false. - */ - @Override - public boolean equals(Object pObj) { - if (!(pObj instanceof CIMDateTime)) return false; - CIMDateTime that = (CIMDateTime) pObj; - return getDateTimeString().equals(that.getDateTimeString()); - } - - /** - * Gets the internal string representation of this object. - * - * @return The internal representation of the CIMDateTime - * object. - */ - public abstract String getDateTimeString(); - - /** - * Returns the hash code for this object. - * - * @return A hash code value for this object. - * @see java.lang.Object#hashCode() - */ - @Override - public abstract int hashCode(); -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2227442 2008-11-05 blaschke-oss Add missing serialVersionUID + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2795671 2009-05-22 raman_arora Add Type to Comparable + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + * 3496301 2012-03-02 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.Serializable; + +//Sync'd against JSR48 1.0.0 javadoc (build 1.6.0_18) on Thu Mar 01 12:21:26 EST 2012 +/** + * This abstract class represents a CIM Datetime data type as defined by the + * Distributed Management Task Force (DMTF) CIM + * Infrastructure Specification (DSP004). It is in the format yyyyMMddHHmmss.SSSSSSsutc where: + *
        + *
      • yyyy - is a 4 digit year
      • + *
      • MM - is the month
      • + *
      • dd - is the day of the month
      • + *
      • HH - is the hour (24 hour clock)
      • + *
      • mm - is the minute
      • + *
      • ss - is the second
      • + *
      • SSSSSS - is the number of microseconds
      • + *
      • s - is "+" or "-", indicating the sign of the UTC (Universal Coordinated + * Time; for all intents and purposes the same as Greenwich Mean Time) + * correction field, or a ":". In the case of a ":" the value is interpreted as + * a time interval, and yyyyMM are interpreted as days.
      • + *
      • utc - is the offset from UTC in minutes (using the sign indicated by s). + * It is ignored for a time interval.
      • + *
      + * + * For example, the absolute datetime for Monday, May 25, 1998, at 1:30 PM EST + * would be represented as: 19980525133015.000000-300. Values must be + * zero-padded so that the entire string is always the same 25-character length. + * Fields which are not significant must be replaced with asterisk characters. + * Similarly, intervals use the same format, except that the interpretation of + * the fields is based on elapsed time.
      + * For example, the interval datetime for an elapsed time of 1 day, 13 hours, 23 + * minutes, 12 seconds would be: 00000001132312.000000:000. A UTC offset of zero + * is always used for interval properties. + */ +public abstract class CIMDateTime implements Serializable, Comparable { + private static final long serialVersionUID = 3424668043014662166L; + + /** + * Creates a CIMDateTime object using a string. + * + * @param pDateString + * A string in the format of yyyyMMddHHmmss.SSSSSSsutc. + * @throws IllegalArgumentException + * If string is not in the correct format. + */ + public CIMDateTime(String pDateString) throws IllegalArgumentException { + // FIXME: what to do here? + } + + protected CIMDateTime() { + // FIXME: what to do here? + } + + /** + * Determines whether the CIMDateTime that is passed in is + * equal to the current CIMDateTime object. + * + * @param pObj + * The CIMDateTime object to compare to. + * @return true if this CIMDateTime object is equal to the one + * that was passed in, otherwise false. + */ + @Override + public boolean equals(Object pObj) { + if (!(pObj instanceof CIMDateTime)) return false; + CIMDateTime that = (CIMDateTime) pObj; + return getDateTimeString().equals(that.getDateTimeString()); + } + + /** + * Gets the internal string representation of this object. + * + * @return The internal representation of the CIMDateTime + * object. + */ + public abstract String getDateTimeString(); + + /** + * Returns the hash code for this object. + * + * @return A hash code value for this object. + * @see java.lang.Object#hashCode() + */ + @Override + public abstract int hashCode(); +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMDateTimeAbsolute.java b/src/main/java/org/metricshub/wbem/javax/cim/CIMDateTimeAbsolute.java similarity index 87% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/CIMDateTimeAbsolute.java rename to src/main/java/org/metricshub/wbem/javax/cim/CIMDateTimeAbsolute.java index e54ee6d..8421e43 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMDateTimeAbsolute.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/CIMDateTimeAbsolute.java @@ -1,404 +1,397 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant - * 1678807 2007-03-12 ebak Minor CIMDateTime suggestions - * 1931621 2008-04-02 blaschke-oss CIMDateTimeAbsolute(Calendar) does not respect DST - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al - * 2795671 2009-05-22 raman_arora Add Type to Comparable - * 2806362 2009-06-14 blaschke-oss Missing new CIMDateTimeAbsolute.getUTCOffset() method - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - * 2944826 2010-02-08 blaschke-oss getUTCOffset() incorrect if not significant field - * 2973300 2010-03-19 blaschke-oss TCK: CIMDateTimeXXX.compareTo() does not handle null - * 3022501 2010-06-30 blaschke-oss Possible integer overflow in getTotalUSec - * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues - * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods - * 2674 2013-09-26 blaschke-oss Null pointer exception in CIMDateTime(String) - * 2716 2013-12-11 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Calendar; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.DTStringReader; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.DTStringWriter; - -//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013 -/** - * This class represents the datetime data type when used as a time value as - * specified in the CIM Infrastructure specification. It is in the format - * yyyyMMddHHmmss.SSSSSSsutc where: - *
        - *
      • yyyy - is a 4 digit year
      • - *
      • MM - is the month
      • - *
      • dd - is the day of the month
      • - *
      • HH - is the hour (24 hour clock)
      • - *
      • mm - is the minute
      • - *
      • ss - is the second
      • - *
      • SSSSSS - is the number of microseconds
      • - *
      • s - is "+" or "-", indicating the sign of the UTC (Universal Coordinated - * Time; for all intents and purposes the same as Greenwich Mean Time)
      • - *
      • utc - is the offset from UTC in minutes (using the sign indicated by s).
      • - *
      - * For example Monday, May 25, 1998, at 1:30 PM EST would be represented as: - * 19980525133015.000000-300. Values must be zero-padded so that the entire - * string is always the same 25-character length. Fields which are not - * significant must be replaced with asterisk characters. - */ -public class CIMDateTimeAbsolute extends CIMDateTime { - - private static final long serialVersionUID = 7556792806296945178l; - - private int iYear, iMonth, iDay, iHour, iMin, iSec, iUSec, iUtc; - - private boolean iUnsignificantUtc; - - private String iStr; - - /** - * Create a CIMDateTimeAbsolute object using the current - * Time/Date of the system. - */ - public CIMDateTimeAbsolute() { - set(Calendar.getInstance()); - } - - /** - * Create a CIMDateTimeAbsolute object using a - * Calendar object. - * - * @param pCalendar - * A Calendar object used to initialize this object. - * @throws IllegalArgumentException - * If Calendar object is null. - */ - public CIMDateTimeAbsolute(Calendar pCalendar) throws IllegalArgumentException { - if (pCalendar == null) throw new IllegalArgumentException("Null Calendar is not allowed!"); - if (pCalendar.get(Calendar.YEAR) > 9999) throw new IllegalArgumentException( - "The year field cannot be greater than 9999!"); - set(pCalendar); - } - - /** - * Creates a CIMDateTimeAbsolute object using a string. - * - * @param pDateTime - * A string in the format of yyyyMMddHHmmss.SSSSSSsutc. - * @throws IllegalArgumentException - * If string is not in the correct format or null. - */ - public CIMDateTimeAbsolute(String pDateTime) throws IllegalArgumentException { - if (pDateTime == null) throw new IllegalArgumentException("Null DateTime is not allowed!"); - DTStringReader reader = new DTStringReader(pDateTime); - this.iYear = reader.readAndCheck(4, "year", 0, 9999, true); - this.iMonth = reader.readAndCheck(2, "month", 1, 12, true); - this.iDay = reader.readAndCheck(2, "day", 1, 31, true); - this.iHour = reader.readAndCheck(2, "hour", 0, 23, true); - this.iMin = reader.readAndCheck(2, "minute", 0, 59, true); - this.iSec = reader.readAndCheck(2, "second", 0, 59, true); - reader.read('.'); - this.iUSec = reader.readAndCheck(6, "microSeconds", 0, 999999, true); - char sign = reader.read(); - if (sign != '+' && sign != '-') { - String msg = "Illegal character '" + sign + "' at position " + reader.getPos() - + "! '+' or '-' is expected."; - throw new IllegalArgumentException(msg); - } - this.iUtc = reader.read(3, "utc", true); - if (reader.isUnsignificant()) { - this.iUnsignificantUtc = true; - } else if (sign == '-') { - this.iUtc = -this.iUtc; - } - if (reader.read() != 0) throw new IllegalArgumentException("Extra character at the end of " - + pDateTime + " !"); - this.iStr = pDateTime; - } - - /** - * Compares the CIMDateTimeAbsolute object with this one. If - * either date has "Not Significant" fields then we can only compare the - * significant fields. - * - * @param pDateTime - * The CIMDateTimeAbsolute to be compared with this - * one. - * @return -1, zero, or 1 as this date is less than, equal to, or greater - * than the specified date. - * @throws IllegalArgumentException - * If the object passed in is not an instance of - * CIMDataTimeAbsolute. - */ - public int compareTo(CIMDateTime pDateTime) throws IllegalArgumentException { - if (!(pDateTime instanceof CIMDateTimeAbsolute)) { - String msg = "pDateTime must be a CIMDateTimeAbsolute instance while it is a " - + (pDateTime == null ? "null!" : pDateTime.getClass().getName() + " instance!"); - throw new IllegalArgumentException(msg); - } - - CIMDateTimeAbsolute that = (CIMDateTimeAbsolute) pDateTime; - /* - * Comparison: 1. building Calendars from both dates. If a field is not - * significant it and it's corresponding pair is cleared. - */ - int mask = getMask() & that.getMask(); - long thisMicros = getTotalUSec(mask); - long thatMicros = that.getTotalUSec(mask); - long val = thisMicros - thatMicros; - if (val == 0) return 0; - return val < 0 ? -1 : 1; - } - - /** - * Gets the internal string representation of the date/time object. - * - * @return The internal representation of the date/time object. - */ - @Override - public String getDateTimeString() { - if (this.iStr != null) return this.iStr; - // yyyyMMddHHmmss.uuuuuuSutc - DTStringWriter dTWriter = new DTStringWriter(); - dTWriter.write(4, this.iYear); - dTWriter.write(2, this.iMonth); - dTWriter.write(2, this.iDay); - dTWriter.write(2, this.iHour); - dTWriter.write(2, this.iMin); - dTWriter.write(2, this.iSec); - dTWriter.write('.'); - dTWriter.write(6, this.iUSec); - if (this.iUnsignificantUtc) dTWriter.write("+***"); - else dTWriter.writeSigned(3, this.iUtc); - return this.iStr = dTWriter.toString(); - } - - /** - * Returns day value of this date. - * - * @return If day field "not significant" this returns -1, otherwise returns - * day of this date. - */ - public int getDay() { - return this.iDay; - } - - /** - * Returns hour value of this date. - * - * @return If hour field "not significant" this returns -1, otherwise - * returns hour of this date. - */ - public int getHour() { - return this.iHour; - } - - /** - * Returns microsecond value of this date. - * - * @return If microsecond field "not significant" this returns -1, otherwise - * returns microseconds of this date. - */ - public int getMicrosecond() { - return this.iUSec; - } - - /** - * Returns minute value of this date. - * - * @return If minute field "not significant" this returns -1, otherwise - * returns minute of this date. - */ - public int getMinute() { - return this.iMin; - } - - /** - * Returns month value of this date. - * - * @return If month field "not significant" this returns -1, otherwise - * returns the month of this date. - */ - public int getMonth() { - return this.iMonth; - } - - /** - * Returns second value of this date. - * - * @return If second field "not significant" this returns -1, otherwise - * returns second of this date. - */ - public int getSecond() { - return this.iSec; - } - - /** - * Returns UTC offset value of this date. - * - * @return UTC offset of this date. - */ - public int getUTCOffset() { - return this.iUnsignificantUtc ? -1 : this.iUtc; - } - - /** - * Returns year value of this Date. - * - * @return If year field "not significant" this returns -1, otherwise - * returns the year of this date. - */ - public int getYear() { - return this.iYear; - } - - /** - * Returns the hash code for this object. - * - * @return A hash code value for this object. - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - return getDateTimeString().hashCode(); - } - - /** - * Returns a String representation of the - * CIMDateTimeAbsolute. This method is intended to be used only - * for debugging purposes, and the format of the returned string may vary - * between implementations. The returned string may be empty but may not be - * null. - * - * @return String representation of this datetime. - */ - @Override - public String toString() { - return getDateTimeString(); - } - - private static final int YEAR = 1, MONTH = 2, DAY = 4, HOUR = 8, MIN = 16, SEC = 32, USEC = 64, - UTC = 128; - - /** - * Get mask of this CIMDateTimeAbsolute where bit is set if the - * corresponding field is significant or clear if it is not significant. - * - * @return Mask of significant fields in datetime object. - */ - private int getMask() { - int mask = 0; - if (this.iYear != -1) mask |= YEAR; - if (this.iMonth != -1) mask |= MONTH; - if (this.iDay != -1) mask |= DAY; - if (this.iHour != -1) mask |= HOUR; - if (this.iMin != -1) mask |= MIN; - if (this.iSec != -1) mask |= SEC; - if (this.iUSec != -1) mask |= USEC; - if (!this.iUnsignificantUtc) mask |= UTC; - return mask; - } - - /** - * Get value of a field based on mask. - * - * @param pMask - * Mask of significant fields. - * @param pField - * Field. - * @param pValue - * Value of field. - * @param pInitValue - * Initial value of field. - * @return Value of field if field significant, otherwise initial value. - */ - private int mask(int pMask, int pField, int pValue, int pInitValue) { - return ((pMask & pField) > 0) ? pValue : pInitValue; - } - - /** - * Get total microseconds of CIMDateTimeAbsolute object where - * only significant fields are used in calculation. - * - * @param pMask - * Mask of significant fields. - * @return Total microseconds of significant fields in datetime. - */ - private long getTotalUSec(int pMask) { - Calendar cal = Calendar.getInstance(); - cal.set(Calendar.YEAR, mask(pMask, YEAR, this.iYear, 0)); - cal.set(Calendar.MONTH, mask(pMask, MONTH, this.iMonth - 1, 0)); - cal.set(Calendar.DAY_OF_MONTH, mask(pMask, DAY, this.iDay, 1)); - cal.set(Calendar.HOUR_OF_DAY, mask(pMask, HOUR, this.iHour, 0)); - cal.set(Calendar.MINUTE, mask(pMask, MIN, this.iMin, 0)); - cal.set(Calendar.SECOND, mask(pMask, SEC, this.iSec, 0)); - int millis = this.iUSec / 1000, micros = this.iUSec % 1000; - cal.set(Calendar.MILLISECOND, mask(pMask, USEC, millis, 0)); - long totalMicros = cal.getTimeInMillis() * 1000; - if ((pMask & USEC) > 0) totalMicros += micros; - /* - * UTC is added to the calculated micros - */ - if ((pMask & UTC) > 0) totalMicros += this.iUtc * 60000000L; - return totalMicros; - } - - /** - * Initializes this CIMDateTimeAbsolute object from the - * Calendar passed in. - * - * @param pCal - * Calendar object. - */ - private void set(Calendar pCal) { - this.iYear = pCal.get(Calendar.YEAR); - this.iMonth = pCal.get(Calendar.MONTH) + 1; - this.iDay = pCal.get(Calendar.DAY_OF_MONTH); - this.iHour = pCal.get(Calendar.HOUR_OF_DAY); - this.iMin = pCal.get(Calendar.MINUTE); - this.iSec = pCal.get(Calendar.SECOND); - this.iUSec = pCal.get(Calendar.MILLISECOND) * 1000; - if (pCal.getTimeZone().inDaylightTime(pCal.getTime())) { - this.iUtc = (pCal.get(Calendar.ZONE_OFFSET) + pCal.get(Calendar.DST_OFFSET)) / 60000; - } else { - this.iUtc = pCal.get(Calendar.ZONE_OFFSET) / 60000; - } - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant + * 1678807 2007-03-12 ebak Minor CIMDateTime suggestions + * 1931621 2008-04-02 blaschke-oss CIMDateTimeAbsolute(Calendar) does not respect DST + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al + * 2795671 2009-05-22 raman_arora Add Type to Comparable + * 2806362 2009-06-14 blaschke-oss Missing new CIMDateTimeAbsolute.getUTCOffset() method + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + * 2944826 2010-02-08 blaschke-oss getUTCOffset() incorrect if not significant field + * 2973300 2010-03-19 blaschke-oss TCK: CIMDateTimeXXX.compareTo() does not handle null + * 3022501 2010-06-30 blaschke-oss Possible integer overflow in getTotalUSec + * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues + * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods + * 2674 2013-09-26 blaschke-oss Null pointer exception in CIMDateTime(String) + * 2716 2013-12-11 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Calendar; +import org.metricshub.wbem.sblim.cimclient.internal.cim.DTStringReader; +import org.metricshub.wbem.sblim.cimclient.internal.cim.DTStringWriter; + +//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013 +/** + * This class represents the datetime data type when used as a time value as + * specified in the CIM Infrastructure specification. It is in the format + * yyyyMMddHHmmss.SSSSSSsutc where: + *
        + *
      • yyyy - is a 4 digit year
      • + *
      • MM - is the month
      • + *
      • dd - is the day of the month
      • + *
      • HH - is the hour (24 hour clock)
      • + *
      • mm - is the minute
      • + *
      • ss - is the second
      • + *
      • SSSSSS - is the number of microseconds
      • + *
      • s - is "+" or "-", indicating the sign of the UTC (Universal Coordinated + * Time; for all intents and purposes the same as Greenwich Mean Time)
      • + *
      • utc - is the offset from UTC in minutes (using the sign indicated by s).
      • + *
      + * For example Monday, May 25, 1998, at 1:30 PM EST would be represented as: + * 19980525133015.000000-300. Values must be zero-padded so that the entire + * string is always the same 25-character length. Fields which are not + * significant must be replaced with asterisk characters. + */ +public class CIMDateTimeAbsolute extends CIMDateTime { + private static final long serialVersionUID = 7556792806296945178l; + + private int iYear, iMonth, iDay, iHour, iMin, iSec, iUSec, iUtc; + + private boolean iUnsignificantUtc; + + private String iStr; + + /** + * Create a CIMDateTimeAbsolute object using the current + * Time/Date of the system. + */ + public CIMDateTimeAbsolute() { + set(Calendar.getInstance()); + } + + /** + * Create a CIMDateTimeAbsolute object using a + * Calendar object. + * + * @param pCalendar + * A Calendar object used to initialize this object. + * @throws IllegalArgumentException + * If Calendar object is null. + */ + public CIMDateTimeAbsolute(Calendar pCalendar) throws IllegalArgumentException { + if (pCalendar == null) throw new IllegalArgumentException("Null Calendar is not allowed!"); + if (pCalendar.get(Calendar.YEAR) > 9999) throw new IllegalArgumentException( + "The year field cannot be greater than 9999!" + ); + set(pCalendar); + } + + /** + * Creates a CIMDateTimeAbsolute object using a string. + * + * @param pDateTime + * A string in the format of yyyyMMddHHmmss.SSSSSSsutc. + * @throws IllegalArgumentException + * If string is not in the correct format or null. + */ + public CIMDateTimeAbsolute(String pDateTime) throws IllegalArgumentException { + if (pDateTime == null) throw new IllegalArgumentException("Null DateTime is not allowed!"); + DTStringReader reader = new DTStringReader(pDateTime); + this.iYear = reader.readAndCheck(4, "year", 0, 9999, true); + this.iMonth = reader.readAndCheck(2, "month", 1, 12, true); + this.iDay = reader.readAndCheck(2, "day", 1, 31, true); + this.iHour = reader.readAndCheck(2, "hour", 0, 23, true); + this.iMin = reader.readAndCheck(2, "minute", 0, 59, true); + this.iSec = reader.readAndCheck(2, "second", 0, 59, true); + reader.read('.'); + this.iUSec = reader.readAndCheck(6, "microSeconds", 0, 999999, true); + char sign = reader.read(); + if (sign != '+' && sign != '-') { + String msg = "Illegal character '" + sign + "' at position " + reader.getPos() + "! '+' or '-' is expected."; + throw new IllegalArgumentException(msg); + } + this.iUtc = reader.read(3, "utc", true); + if (reader.isUnsignificant()) { + this.iUnsignificantUtc = true; + } else if (sign == '-') { + this.iUtc = -this.iUtc; + } + if (reader.read() != 0) throw new IllegalArgumentException("Extra character at the end of " + pDateTime + " !"); + this.iStr = pDateTime; + } + + /** + * Compares the CIMDateTimeAbsolute object with this one. If + * either date has "Not Significant" fields then we can only compare the + * significant fields. + * + * @param pDateTime + * The CIMDateTimeAbsolute to be compared with this + * one. + * @return -1, zero, or 1 as this date is less than, equal to, or greater + * than the specified date. + * @throws IllegalArgumentException + * If the object passed in is not an instance of + * CIMDataTimeAbsolute. + */ + public int compareTo(CIMDateTime pDateTime) throws IllegalArgumentException { + if (!(pDateTime instanceof CIMDateTimeAbsolute)) { + String msg = + "pDateTime must be a CIMDateTimeAbsolute instance while it is a " + + (pDateTime == null ? "null!" : pDateTime.getClass().getName() + " instance!"); + throw new IllegalArgumentException(msg); + } + + CIMDateTimeAbsolute that = (CIMDateTimeAbsolute) pDateTime; + /* + * Comparison: 1. building Calendars from both dates. If a field is not + * significant it and it's corresponding pair is cleared. + */ + int mask = getMask() & that.getMask(); + long thisMicros = getTotalUSec(mask); + long thatMicros = that.getTotalUSec(mask); + long val = thisMicros - thatMicros; + if (val == 0) return 0; + return val < 0 ? -1 : 1; + } + + /** + * Gets the internal string representation of the date/time object. + * + * @return The internal representation of the date/time object. + */ + @Override + public String getDateTimeString() { + if (this.iStr != null) return this.iStr; + // yyyyMMddHHmmss.uuuuuuSutc + DTStringWriter dTWriter = new DTStringWriter(); + dTWriter.write(4, this.iYear); + dTWriter.write(2, this.iMonth); + dTWriter.write(2, this.iDay); + dTWriter.write(2, this.iHour); + dTWriter.write(2, this.iMin); + dTWriter.write(2, this.iSec); + dTWriter.write('.'); + dTWriter.write(6, this.iUSec); + if (this.iUnsignificantUtc) dTWriter.write("+***"); else dTWriter.writeSigned(3, this.iUtc); + return this.iStr = dTWriter.toString(); + } + + /** + * Returns day value of this date. + * + * @return If day field "not significant" this returns -1, otherwise returns + * day of this date. + */ + public int getDay() { + return this.iDay; + } + + /** + * Returns hour value of this date. + * + * @return If hour field "not significant" this returns -1, otherwise + * returns hour of this date. + */ + public int getHour() { + return this.iHour; + } + + /** + * Returns microsecond value of this date. + * + * @return If microsecond field "not significant" this returns -1, otherwise + * returns microseconds of this date. + */ + public int getMicrosecond() { + return this.iUSec; + } + + /** + * Returns minute value of this date. + * + * @return If minute field "not significant" this returns -1, otherwise + * returns minute of this date. + */ + public int getMinute() { + return this.iMin; + } + + /** + * Returns month value of this date. + * + * @return If month field "not significant" this returns -1, otherwise + * returns the month of this date. + */ + public int getMonth() { + return this.iMonth; + } + + /** + * Returns second value of this date. + * + * @return If second field "not significant" this returns -1, otherwise + * returns second of this date. + */ + public int getSecond() { + return this.iSec; + } + + /** + * Returns UTC offset value of this date. + * + * @return UTC offset of this date. + */ + public int getUTCOffset() { + return this.iUnsignificantUtc ? -1 : this.iUtc; + } + + /** + * Returns year value of this Date. + * + * @return If year field "not significant" this returns -1, otherwise + * returns the year of this date. + */ + public int getYear() { + return this.iYear; + } + + /** + * Returns the hash code for this object. + * + * @return A hash code value for this object. + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return getDateTimeString().hashCode(); + } + + /** + * Returns a String representation of the + * CIMDateTimeAbsolute. This method is intended to be used only + * for debugging purposes, and the format of the returned string may vary + * between implementations. The returned string may be empty but may not be + * null. + * + * @return String representation of this datetime. + */ + @Override + public String toString() { + return getDateTimeString(); + } + + private static final int YEAR = 1, MONTH = 2, DAY = 4, HOUR = 8, MIN = 16, SEC = 32, USEC = 64, UTC = 128; + + /** + * Get mask of this CIMDateTimeAbsolute where bit is set if the + * corresponding field is significant or clear if it is not significant. + * + * @return Mask of significant fields in datetime object. + */ + private int getMask() { + int mask = 0; + if (this.iYear != -1) mask |= YEAR; + if (this.iMonth != -1) mask |= MONTH; + if (this.iDay != -1) mask |= DAY; + if (this.iHour != -1) mask |= HOUR; + if (this.iMin != -1) mask |= MIN; + if (this.iSec != -1) mask |= SEC; + if (this.iUSec != -1) mask |= USEC; + if (!this.iUnsignificantUtc) mask |= UTC; + return mask; + } + + /** + * Get value of a field based on mask. + * + * @param pMask + * Mask of significant fields. + * @param pField + * Field. + * @param pValue + * Value of field. + * @param pInitValue + * Initial value of field. + * @return Value of field if field significant, otherwise initial value. + */ + private int mask(int pMask, int pField, int pValue, int pInitValue) { + return ((pMask & pField) > 0) ? pValue : pInitValue; + } + + /** + * Get total microseconds of CIMDateTimeAbsolute object where + * only significant fields are used in calculation. + * + * @param pMask + * Mask of significant fields. + * @return Total microseconds of significant fields in datetime. + */ + private long getTotalUSec(int pMask) { + Calendar cal = Calendar.getInstance(); + cal.set(Calendar.YEAR, mask(pMask, YEAR, this.iYear, 0)); + cal.set(Calendar.MONTH, mask(pMask, MONTH, this.iMonth - 1, 0)); + cal.set(Calendar.DAY_OF_MONTH, mask(pMask, DAY, this.iDay, 1)); + cal.set(Calendar.HOUR_OF_DAY, mask(pMask, HOUR, this.iHour, 0)); + cal.set(Calendar.MINUTE, mask(pMask, MIN, this.iMin, 0)); + cal.set(Calendar.SECOND, mask(pMask, SEC, this.iSec, 0)); + int millis = this.iUSec / 1000, micros = this.iUSec % 1000; + cal.set(Calendar.MILLISECOND, mask(pMask, USEC, millis, 0)); + long totalMicros = cal.getTimeInMillis() * 1000; + if ((pMask & USEC) > 0) totalMicros += micros; + /* + * UTC is added to the calculated micros + */ + if ((pMask & UTC) > 0) totalMicros += this.iUtc * 60000000L; + return totalMicros; + } + + /** + * Initializes this CIMDateTimeAbsolute object from the + * Calendar passed in. + * + * @param pCal + * Calendar object. + */ + private void set(Calendar pCal) { + this.iYear = pCal.get(Calendar.YEAR); + this.iMonth = pCal.get(Calendar.MONTH) + 1; + this.iDay = pCal.get(Calendar.DAY_OF_MONTH); + this.iHour = pCal.get(Calendar.HOUR_OF_DAY); + this.iMin = pCal.get(Calendar.MINUTE); + this.iSec = pCal.get(Calendar.SECOND); + this.iUSec = pCal.get(Calendar.MILLISECOND) * 1000; + if (pCal.getTimeZone().inDaylightTime(pCal.getTime())) { + this.iUtc = (pCal.get(Calendar.ZONE_OFFSET) + pCal.get(Calendar.DST_OFFSET)) / 60000; + } else { + this.iUtc = pCal.get(Calendar.ZONE_OFFSET) / 60000; + } + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMDateTimeInterval.java b/src/main/java/org/metricshub/wbem/javax/cim/CIMDateTimeInterval.java similarity index 78% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/CIMDateTimeInterval.java rename to src/main/java/org/metricshub/wbem/javax/cim/CIMDateTimeInterval.java index 4488470..e34571a 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMDateTimeInterval.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/CIMDateTimeInterval.java @@ -1,565 +1,632 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant - * 1678807 2007-03-12 ebak Minor CIMDateTime suggestions - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2795671 2009-05-22 raman_arora Add Type to Comparable - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - * 2944830 2010-02-08 blaschke-oss Fix spelling of checkGranurality() - * 2973300 2010-03-19 blaschke-oss TCK: CIMDateTimeXXX.compareTo() does not handle null - * 2989367 2010-04-29 blaschke-oss CIMDateTimeInterval(long) constructor range wrong - * 2989424 2010-04-29 blaschke-oss TCK: CIMDateTimeInterval constructor - * 2992349 2010-04-29 blaschke-oss CIMDateTimeInterval hr/min/sec max is 23/59/59, not 24/60/60 - * 2994249 2010-04-30 blaschke-oss CIMDateTimeInterval(long) calculates milliseconds - * 3018178 2010-06-18 blaschke-oss CIMDateTimeInterval clean up - * 3026302 2010-07-07 blaschke-oss CIMDateTimeInterval uses # constructor instead of valueOf - * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues - * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods - * 2674 2013-09-26 blaschke-oss Null pointer exception in CIMDateTime(String) - * 2716 2013-12-11 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.DTStringReader; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.DTStringWriter; - -//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013 -/** - * This class represents the datetime data type when used as a time value as - * specified by the Distributed Management Task Force (DMTF) CIM Infrastructure Specification (DSP004). It is in the format ddddddddHHMMSS.mmmmmm:000 where: - *
        - *
      • dddddddd - is the days in interval
      • - *
      • HH - is the hours in interval
      • - *
      • MM - is the minutes in interval
      • - *
      • SS - is the seconds in interval
      • - *
      • mmmmmm - is the microseconds in interval
      • - *
      - * For example, an elapsed time of 1 day, 13 hours, 23 minutes, 12 seconds would - * be: 00000001132312.000000:000. A UTC offset of zero is always used for - * interval properties.
      - * Fields that are not significant MUST be replaced with asterisk ("*") - * characters. Not significant fields are those that are beyond the resolution - * of the data source. This is used to indicate the precision of the value and - * can only be done for an adjacent set of fields, starting with the least - * significant field (mmmmmm), and continuing to more significant fields. The - * granularity of using asterisks is always the entire field, except for the - * mmmmmm field where the granularity is single digits. The UTC offset field - * MUST NOT contain asterisks.
      - * For example, if an interval of 1 day, 13 hours, 23 minutes, 12 seconds, and - * 125 milliseconds was measured with a precision of 1 millisecond, the format - * would be: 00000001132312.125***:000. - * - */ -public class CIMDateTimeInterval extends CIMDateTime { - - private static final long serialVersionUID = -7362881414085831668l; - - private int iDays, iHours, iMinutes, iSeconds, iUSeconds; - - private String iStr; - - private boolean iTotalMicrosCalced; - - private long iTotalMicros; - - private int iUnsignificantUSecDigits; - - private static final int MAX_DAY = 99999999, MAX_HOUR = 23, MAX_MIN = 59, MAX_SEC = 59, - MAX_MILLISEC = 999, MAX_MICROSEC = 999999; - - private static final long MAX_INTERVAL = ((((long) MAX_DAY * 24 * 60 * 60) - + ((long) MAX_HOUR * 60 * 60) + ((long) MAX_MIN * 60) + MAX_SEC) * 1000) - + MAX_MILLISEC; - - private static final long MILLISEC_ACCURACY_DIV = 1000, - SEC_ACCURACY_DIV = 1000 * MILLISEC_ACCURACY_DIV, - MIN_ACCURACY_DIV = 60 * SEC_ACCURACY_DIV, HOUR_ACCURACY_DIV = 60 * MIN_ACCURACY_DIV, - DAY_ACCURACY_DIV = 24 * HOUR_ACCURACY_DIV, - NO_ACCURACY_DIV = 100000000 * DAY_ACCURACY_DIV; - - private static final long[] USEC_ACCURACY_DIV_A = { 1, 10, 100, MILLISEC_ACCURACY_DIV, 10000, - 100000, SEC_ACCURACY_DIV }; - - private long iAccuracyDivisor = 1; - - /** - * Constructs a CIMDateTimeInterval using the individual values - * of the interval (day, hours, minutes, seconds and microseconds). Any - * property that has a -1 will make that field "not significant" (i.e. that - * field has asterisks in the datetime string). - * - * @param pDays - * Number of days in the interval (-1 - 99999999). - * @param pHours - * Number of hours in the interval (-1 - 23). - * @param pMinutes - * Number of minutes in the interval (-1 - 59). - * @param pSeconds - * Number of seconds in the interval (-1 - 59). - * @param pMicroseconds - * Number of microseconds in the interval (-1 - 999999). - * @throws IllegalArgumentException - * If any value is not valid. - */ - public CIMDateTimeInterval(int pDays, int pHours, int pMinutes, int pSeconds, int pMicroseconds) - throws IllegalArgumentException { - boolean notSignificant = checkLimits("pDays", pDays, 0, MAX_DAY, false); - if (notSignificant) this.iAccuracyDivisor = NO_ACCURACY_DIV; - notSignificant = checkLimits("pHours", pHours, 0, MAX_HOUR, notSignificant); - if (notSignificant && this.iAccuracyDivisor == 1) this.iAccuracyDivisor = DAY_ACCURACY_DIV; - notSignificant = checkLimits("pMinutes", pMinutes, 0, MAX_MIN, notSignificant); - if (notSignificant && this.iAccuracyDivisor == 1) this.iAccuracyDivisor = HOUR_ACCURACY_DIV; - notSignificant = checkLimits("pSeconds", pSeconds, 0, MAX_SEC, notSignificant); - if (notSignificant && this.iAccuracyDivisor == 1) this.iAccuracyDivisor = MIN_ACCURACY_DIV; - notSignificant = checkLimits("pMicroseconds", pMicroseconds, 0, MAX_MICROSEC, - notSignificant); - if (notSignificant) { - this.iUnsignificantUSecDigits = 6; - if (this.iAccuracyDivisor == 1) this.iAccuracyDivisor = USEC_ACCURACY_DIV_A[this.iUnsignificantUSecDigits]; - } else { - this.iUnsignificantUSecDigits = 0; - } - - this.iDays = pDays; - this.iHours = pHours; - this.iMinutes = pMinutes; - this.iSeconds = pSeconds; - this.iUSeconds = pMicroseconds; - - debug("CIMDateTimeInterval(" + pDays + "," + pHours + "," + pMinutes + "," + pSeconds + "," - + pMicroseconds + "): days=" + this.iDays + ", hours=" + this.iHours + ", mins=" - + this.iMinutes + ", secs=" + this.iSeconds + ", usecs=" + this.iUSeconds - + ", acc div=" + this.iAccuracyDivisor + ", unsig digits=" - + this.iUnsignificantUSecDigits); - } - - /** - * Constructs a CIMDateTimeInterval using a milliseconds value. - * - * @param pMilliseconds - * Number of milliseconds in the interval (0 - 8639999999999999). - * @throws IllegalArgumentException - */ - public CIMDateTimeInterval(long pMilliseconds) throws IllegalArgumentException { - if (pMilliseconds < 0 || pMilliseconds > MAX_INTERVAL) throw new IllegalArgumentException( - "pMilliseconds must be between 0 and " + MAX_INTERVAL + ". " + pMilliseconds - + " is illegal!"); - long totalUSecs = pMilliseconds * 1000; - long totalSecs = pMilliseconds / 1000; - long totalMins = totalSecs / 60; - long totalHours = totalMins / 60; - long totalDays = totalHours / 24; - - this.iUSeconds = (int) (totalUSecs % 1000000); - this.iSeconds = (int) (totalSecs % 60); - this.iMinutes = (int) (totalMins % 60); - this.iHours = (int) (totalHours % 24); - this.iDays = (int) totalDays; - - this.iUnsignificantUSecDigits = 3; - this.iAccuracyDivisor = USEC_ACCURACY_DIV_A[this.iUnsignificantUSecDigits]; - - this.iTotalMicrosCalced = true; - this.iTotalMicros = pMilliseconds * 1000; - - debug("CIMDateTimeInterval(" + pMilliseconds + "): days=" + this.iDays + ", hours=" - + this.iHours + ", mins=" + this.iMinutes + ", secs=" + this.iSeconds + ", usecs=" - + this.iUSeconds + ", acc div=" + this.iAccuracyDivisor + ", unsig digits=" - + this.iUnsignificantUSecDigits); - } - - /** - * Creates a CIMDateTimeInterval object using a string. - * - * @param pIntervalString - * A string in the format of ddddddddHHMMSS.mmmmmm:000. - * @throws IllegalArgumentException - * If string is not in the correct format or null. - */ - public CIMDateTimeInterval(String pIntervalString) throws IllegalArgumentException { - if (pIntervalString == null) throw new IllegalArgumentException( - "Null IntervalString is not allowed!"); - if (pIntervalString.length() != LENGTH) throw new IllegalArgumentException("Length of " - + pIntervalString + " must be " + LENGTH + ", " + pIntervalString.length() - + " is not valid!"); - String intervalStr = setAccuracy(pIntervalString); - DTStringReader dtReader = new DTStringReader(intervalStr); - this.iDays = dtReader.readAndCheck(8, "days", 0, MAX_DAY, true); - this.iHours = dtReader.readAndCheck(2, "hours", 0, MAX_HOUR, true); - this.iMinutes = dtReader.readAndCheck(2, "minutes", 0, MAX_MIN, true); - this.iSeconds = dtReader.readAndCheck(2, "seconds", 0, MAX_SEC, true); - dtReader.read('.'); - this.iUSeconds = dtReader.readAndCheck(6, "microseconds", 0, MAX_MICROSEC, false); - if (this.iAccuracyDivisor >= SEC_ACCURACY_DIV) this.iUSeconds = -1; - dtReader.read(':'); - int zeros = dtReader.read(3, "zeros", false); - if (zeros != 0) { - String msg = "In " + pIntervalString - + " the last 3 characters after ':' must be zeros!"; - throw new IllegalArgumentException(msg); - } - - debug("CIMDateTimeInterval(\"" + pIntervalString + "\"): days=" + this.iDays + ", hours=" - + this.iHours + ", mins=" + this.iMinutes + ", secs=" + this.iSeconds + ", usecs=" - + this.iUSeconds + ", acc div=" + this.iAccuracyDivisor + ", unsig digits=" - + this.iUnsignificantUSecDigits); - } - - /** - * Compares the CIMDateTimeInterval object with this one. If - * either interval has "Not Significant" fields then we only compare the - * significant fields. - * - * @param pObj - * The CIMDateTimeInterval to be compared with this - * one. - * @return -1, zero, or 1 as this interval is less than, equal to, or - * greater than the specified interval. - * @throws IllegalArgumentException - * If the object passed in is not an instance of - * CIMDataTimeInterval. - */ - public int compareTo(CIMDateTime pObj) throws IllegalArgumentException { - if (!(pObj instanceof CIMDateTimeInterval)) { - String msg = "This method requires a CIMDateTimeInterval instance, while it has received a " - + (pObj == null ? "null!" : pObj.getClass().getName() + " instance!"); - throw new IllegalArgumentException(msg); - } - CIMDateTimeInterval that = (CIMDateTimeInterval) pObj; - long accuracyDivisor = Math.max(this.iAccuracyDivisor, that.iAccuracyDivisor); - debug("this.acDiv=" + this.iAccuracyDivisor + ", that.acDiv=" + that.iAccuracyDivisor - + ", acDiv=" + accuracyDivisor); - Long thisMicros = Long.valueOf(calcMicros(accuracyDivisor)); - Long thatMicros = Long.valueOf(that.calcMicros(accuracyDivisor)); - debug("thisUs=" + thisMicros + ", thatUs=" + thatMicros); - return thisMicros.compareTo(thatMicros); - } - - /** - * Gets the internal string representation of this object. - * - * @return The internal representation of the - * CIMDateTimeInterval object. - */ - @Override - public String getDateTimeString() { - if (this.iStr != null) return this.iStr; - // ddddddddHHMMSS.mmmmmm:000 - DTStringWriter dtWriter = new DTStringWriter(); - dtWriter.write(8, this.iDays); - dtWriter.write(2, this.iHours); - dtWriter.write(2, this.iMinutes); - dtWriter.write(2, this.iSeconds); - dtWriter.write('.'); - dtWriter.writeUSec(this.iUSeconds / (int) this.iAccuracyDivisor, - this.iUnsignificantUSecDigits); - dtWriter.write(":000"); - return dtWriter.toString(); - } - - /** - * Returns days value of this interval. - * - * @return If days field "not significant" this returns -1, otherwise - * returns number of days in the interval. - */ - public int getDays() { - return this.iDays; - } - - /** - * Returns hours value of this interval. - * - * @return If hours field "not significant" this returns -1, otherwise - * returns number of hours in the interval. - */ - public int getHours() { - return this.iHours; - } - - /** - * Returns microseconds value of this interval. - * - * @return If microseconds field "not significant" this returns -1, - * otherwise returns number of microseconds in the interval. - */ - public int getMicroseconds() { - return this.iUSeconds; - } - - /** - * Returns minutes value of this interval. - * - * @return If minutes field "not significant" this returns -1, otherwise - * returns number of minutes in the interval. - */ - public int getMinutes() { - return this.iMinutes; - } - - /** - * Returns seconds value of this interval. - * - * @return If seconds field "not significant" this returns -1, otherwise - * returns number of seconds in the interval. - */ - public int getSeconds() { - return this.iSeconds; - } - - /** - * Returns the total length of the interval in milliseconds. - * - * @return The length of the interval in milliseconds. - */ - public long getTotalMilliseconds() { - return getTotalMicros() / 1000; - } - - /** - * Returns the hash code for this object. - * - * @return A hash code value for this object. - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - return getDateTimeString().hashCode(); - } - - /** - * Returns a String representation of the - * CIMDateTimeInterval. This method is intended to be used only - * for debugging purposes, and the format of the returned string may vary - * between implementations. The returned string may be empty but may not be - * null. - * - * @return String representation of this datetime. - */ - @Override - public String toString() { - return getDateTimeString(); - } - - // ddddddddHHMMSS.mmmmmm:000 - - private static final int DAY_START_IDX = 0, HOUR_START_IDX = 8, MIN_START_IDX = 10, - SEC_START_IDX = 12, DOT_IDX = 14, USEC_START_IDX = 15, UTC_START_IDX = 21, LENGTH = 25; - - /** - * Checks the granularity of the CIMDateTimeAbsolute precision. - * - * @param pIdx - * Index of first asterisk in datetime string. - * @param pFieldName - * Name of field. - * @param pFieldStartIdx - * Index of first character in field of datetime string. - * @param pNextStartIdx - * Index of first character in subsequent field of datetime - * string. - * @return true if field is completely unsignificant, - * false otherwise. - * @throws IllegalArgumentException - * If field is not completely significant or completely - * unsignificant (mix of asterisks and digits). - */ - private boolean checkGranularity(int pIdx, String pFieldName, int pFieldStartIdx, - int pNextStartIdx) throws IllegalArgumentException { - if (pIdx > pFieldStartIdx && pIdx < pNextStartIdx) throw new IllegalArgumentException( - "Partial unsignificant digits are not allowed for field " + pFieldName + " in " - + this.iStr + "!"); - return pIdx == pFieldStartIdx; - } - - /** - * Find index of first asterisk within string. - * - * @param pIvStr - * Time interval string. - * @return Index of first asterisk or -1 if asterisk does not exist. - */ - private static int findStar(String pIvStr) { - for (int i = 0; i < UTC_START_IDX; i++) - if (pIvStr.charAt(i) == '*') return i; - return -1; - } - - /** - * Verify that all characters in the string after the starting index are - * asterisks. - * - * @param pIvStr - * Time interval string. - * @param pStartIdx - * Starting index. - */ - private static void checkStars(String pIvStr, int pStartIdx) { - for (int i = pStartIdx; i < UTC_START_IDX; i++) { - char ch = pIvStr.charAt(i); - if (i != DOT_IDX && ch != '*') throw new IllegalArgumentException("In " + pIvStr - + " every digit character after the first '*' character must " + "be '*', '" - + ch + "' is invalid!"); - } - } - - /** - * Determines the accuracy (precision) of the interval string and replaces - * all asterisks in microsecond field with zeros. - * - * @param pIntervalStr - * Time interval string. - * @return Corrected time interval string with iAccuracyDivisor - * set. - */ - private String setAccuracy(String pIntervalStr) throws IllegalArgumentException { - this.iStr = pIntervalStr; - /* - * String transformation. Checking the correct location of '*' - * characters. '*' characters in usec field are replaced into '0' - * characters - */ - int startIdx = findStar(this.iStr); - if (startIdx < 0) return this.iStr; - // all remaining digit fields must contain '*' characters except for utc - checkStars(this.iStr, startIdx + 1); - if (checkGranularity(startIdx, "Day", DAY_START_IDX, HOUR_START_IDX)) { - this.iAccuracyDivisor = NO_ACCURACY_DIV; - } else if (checkGranularity(startIdx, "Hour", HOUR_START_IDX, MIN_START_IDX)) { - this.iAccuracyDivisor = DAY_ACCURACY_DIV; - } else if (checkGranularity(startIdx, "Minute", MIN_START_IDX, SEC_START_IDX)) { - this.iAccuracyDivisor = HOUR_ACCURACY_DIV; - } else if (checkGranularity(startIdx, "Second", SEC_START_IDX, DOT_IDX)) { - this.iAccuracyDivisor = MIN_ACCURACY_DIV; - } else { - // dealing with usec granularity - this.iUnsignificantUSecDigits = UTC_START_IDX - startIdx; - this.iAccuracyDivisor = USEC_ACCURACY_DIV_A[this.iUnsignificantUSecDigits]; - } - // all '*' in usec field is replaced into '0' - char[] buf = this.iStr.toCharArray(); - if (startIdx < USEC_START_IDX) startIdx = USEC_START_IDX; - for (int i = startIdx; i < UTC_START_IDX; i++) { - if (i == DOT_IDX) continue; - if (this.iStr.charAt(i) != '*') throw new IllegalArgumentException( - "All remaining digits must be marked as unsignificant in " + this.iStr + " !"); - buf[i] = '0'; - } - return new String(buf); - } - - /** - * Get total microseconds of CIMDateTimeInterval object. - * - * @return Total microseconds of time interval. - */ - private long getTotalMicros() { - if (this.iTotalMicrosCalced) return this.iTotalMicros; - this.iTotalMicrosCalced = true; - // iTotalMicros = iUSeconds + 1000000 * (iSeconds + 60 * (iMinutes + 60 - // * (iHours + 24 * iDays))); - this.iTotalMicros = this.iUSeconds > 0 ? this.iUSeconds : 0; - if (this.iSeconds > 0) this.iTotalMicros += SEC_ACCURACY_DIV * this.iSeconds; - if (this.iMinutes > 0) this.iTotalMicros += MIN_ACCURACY_DIV * this.iMinutes; - if (this.iHours > 0) this.iTotalMicros += HOUR_ACCURACY_DIV * this.iHours; - if (this.iDays > 0) this.iTotalMicros += DAY_ACCURACY_DIV * this.iDays; - debug("days=" + this.iDays + " ,hours=" + this.iHours + " ,mins=" + this.iMinutes - + ", secs=" + this.iSeconds + ", usecs=" + this.iUSeconds + ", totalMicros=" - + this.iTotalMicros); - return this.iTotalMicros; - } - - /** - * Calculates microseconds of CIMDateTimeInterval object taking - * accuracy (precision) into consideration. - * - * @param pAccuracyDivisor - * Accuracy divisor of time interval. - * @return Total microseconds of time interval rounded down to precision. - */ - private long calcMicros(long pAccuracyDivisor) { - long remainder = getTotalMicros() % pAccuracyDivisor; - return getTotalMicros() - remainder; - } - - /** - * Checks validity of time interval field, making sure value is between - * minimum and maximum values and is not significant if following an - * unsignifcant field. - * - * @param pName - * Name of field. - * @param pValue - * Value of field. - * @param pLow - * Minimum value of field. - * @param pHigh - * Maximum value of field. - * @param pNotSignificant - * trueif previous field not significant. - * @return true if field is not significant, false - * otherwise. - * @throws IllegalArgumentException - */ - private static boolean checkLimits(String pName, int pValue, int pLow, int pHigh, - boolean pNotSignificant) throws IllegalArgumentException { - if (pValue == -1) return true; - if (pNotSignificant) throw new IllegalArgumentException( - "Not significant fields must be followed by not significant fields!"); - if (pValue < pLow || pValue > pHigh) throw new IllegalArgumentException(pName - + " must be between " + pLow + " and " + pHigh + ". " + pValue + " is invalid!"); - return false; - } - - /** - * Prints debug message. - * - * @param pMsg - * Debug message. - */ - private static void debug(String pMsg) { - // System.out.println(pMsg); - } -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant + * 1678807 2007-03-12 ebak Minor CIMDateTime suggestions + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2795671 2009-05-22 raman_arora Add Type to Comparable + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + * 2944830 2010-02-08 blaschke-oss Fix spelling of checkGranurality() + * 2973300 2010-03-19 blaschke-oss TCK: CIMDateTimeXXX.compareTo() does not handle null + * 2989367 2010-04-29 blaschke-oss CIMDateTimeInterval(long) constructor range wrong + * 2989424 2010-04-29 blaschke-oss TCK: CIMDateTimeInterval constructor + * 2992349 2010-04-29 blaschke-oss CIMDateTimeInterval hr/min/sec max is 23/59/59, not 24/60/60 + * 2994249 2010-04-30 blaschke-oss CIMDateTimeInterval(long) calculates milliseconds + * 3018178 2010-06-18 blaschke-oss CIMDateTimeInterval clean up + * 3026302 2010-07-07 blaschke-oss CIMDateTimeInterval uses # constructor instead of valueOf + * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues + * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods + * 2674 2013-09-26 blaschke-oss Null pointer exception in CIMDateTime(String) + * 2716 2013-12-11 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.sblim.cimclient.internal.cim.DTStringReader; +import org.metricshub.wbem.sblim.cimclient.internal.cim.DTStringWriter; + +//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013 +/** + * This class represents the datetime data type when used as a time value as + * specified by the Distributed Management Task Force (DMTF) CIM Infrastructure Specification (DSP004). It is in the format ddddddddHHMMSS.mmmmmm:000 where: + *
        + *
      • dddddddd - is the days in interval
      • + *
      • HH - is the hours in interval
      • + *
      • MM - is the minutes in interval
      • + *
      • SS - is the seconds in interval
      • + *
      • mmmmmm - is the microseconds in interval
      • + *
      + * For example, an elapsed time of 1 day, 13 hours, 23 minutes, 12 seconds would + * be: 00000001132312.000000:000. A UTC offset of zero is always used for + * interval properties.
      + * Fields that are not significant MUST be replaced with asterisk ("*") + * characters. Not significant fields are those that are beyond the resolution + * of the data source. This is used to indicate the precision of the value and + * can only be done for an adjacent set of fields, starting with the least + * significant field (mmmmmm), and continuing to more significant fields. The + * granularity of using asterisks is always the entire field, except for the + * mmmmmm field where the granularity is single digits. The UTC offset field + * MUST NOT contain asterisks.
      + * For example, if an interval of 1 day, 13 hours, 23 minutes, 12 seconds, and + * 125 milliseconds was measured with a precision of 1 millisecond, the format + * would be: 00000001132312.125***:000. + * + */ +public class CIMDateTimeInterval extends CIMDateTime { + private static final long serialVersionUID = -7362881414085831668l; + + private int iDays, iHours, iMinutes, iSeconds, iUSeconds; + + private String iStr; + + private boolean iTotalMicrosCalced; + + private long iTotalMicros; + + private int iUnsignificantUSecDigits; + + private static final int MAX_DAY = 99999999, MAX_HOUR = 23, MAX_MIN = 59, MAX_SEC = 59, MAX_MILLISEC = + 999, MAX_MICROSEC = 999999; + + private static final long MAX_INTERVAL = + ((((long) MAX_DAY * 24 * 60 * 60) + ((long) MAX_HOUR * 60 * 60) + ((long) MAX_MIN * 60) + MAX_SEC) * 1000) + + MAX_MILLISEC; + + private static final long MILLISEC_ACCURACY_DIV = 1000, SEC_ACCURACY_DIV = + 1000 * MILLISEC_ACCURACY_DIV, MIN_ACCURACY_DIV = 60 * SEC_ACCURACY_DIV, HOUR_ACCURACY_DIV = + 60 * MIN_ACCURACY_DIV, DAY_ACCURACY_DIV = 24 * HOUR_ACCURACY_DIV, NO_ACCURACY_DIV = 100000000 * DAY_ACCURACY_DIV; + + private static final long[] USEC_ACCURACY_DIV_A = { + 1, + 10, + 100, + MILLISEC_ACCURACY_DIV, + 10000, + 100000, + SEC_ACCURACY_DIV + }; + + private long iAccuracyDivisor = 1; + + /** + * Constructs a CIMDateTimeInterval using the individual values + * of the interval (day, hours, minutes, seconds and microseconds). Any + * property that has a -1 will make that field "not significant" (i.e. that + * field has asterisks in the datetime string). + * + * @param pDays + * Number of days in the interval (-1 - 99999999). + * @param pHours + * Number of hours in the interval (-1 - 23). + * @param pMinutes + * Number of minutes in the interval (-1 - 59). + * @param pSeconds + * Number of seconds in the interval (-1 - 59). + * @param pMicroseconds + * Number of microseconds in the interval (-1 - 999999). + * @throws IllegalArgumentException + * If any value is not valid. + */ + public CIMDateTimeInterval(int pDays, int pHours, int pMinutes, int pSeconds, int pMicroseconds) + throws IllegalArgumentException { + boolean notSignificant = checkLimits("pDays", pDays, 0, MAX_DAY, false); + if (notSignificant) this.iAccuracyDivisor = NO_ACCURACY_DIV; + notSignificant = checkLimits("pHours", pHours, 0, MAX_HOUR, notSignificant); + if (notSignificant && this.iAccuracyDivisor == 1) this.iAccuracyDivisor = DAY_ACCURACY_DIV; + notSignificant = checkLimits("pMinutes", pMinutes, 0, MAX_MIN, notSignificant); + if (notSignificant && this.iAccuracyDivisor == 1) this.iAccuracyDivisor = HOUR_ACCURACY_DIV; + notSignificant = checkLimits("pSeconds", pSeconds, 0, MAX_SEC, notSignificant); + if (notSignificant && this.iAccuracyDivisor == 1) this.iAccuracyDivisor = MIN_ACCURACY_DIV; + notSignificant = checkLimits("pMicroseconds", pMicroseconds, 0, MAX_MICROSEC, notSignificant); + if (notSignificant) { + this.iUnsignificantUSecDigits = 6; + if (this.iAccuracyDivisor == 1) this.iAccuracyDivisor = USEC_ACCURACY_DIV_A[this.iUnsignificantUSecDigits]; + } else { + this.iUnsignificantUSecDigits = 0; + } + + this.iDays = pDays; + this.iHours = pHours; + this.iMinutes = pMinutes; + this.iSeconds = pSeconds; + this.iUSeconds = pMicroseconds; + + debug( + "CIMDateTimeInterval(" + + pDays + + "," + + pHours + + "," + + pMinutes + + "," + + pSeconds + + "," + + pMicroseconds + + "): days=" + + this.iDays + + ", hours=" + + this.iHours + + ", mins=" + + this.iMinutes + + ", secs=" + + this.iSeconds + + ", usecs=" + + this.iUSeconds + + ", acc div=" + + this.iAccuracyDivisor + + ", unsig digits=" + + this.iUnsignificantUSecDigits + ); + } + + /** + * Constructs a CIMDateTimeInterval using a milliseconds value. + * + * @param pMilliseconds + * Number of milliseconds in the interval (0 - 8639999999999999). + * @throws IllegalArgumentException + */ + public CIMDateTimeInterval(long pMilliseconds) throws IllegalArgumentException { + if (pMilliseconds < 0 || pMilliseconds > MAX_INTERVAL) throw new IllegalArgumentException( + "pMilliseconds must be between 0 and " + MAX_INTERVAL + ". " + pMilliseconds + " is illegal!" + ); + long totalUSecs = pMilliseconds * 1000; + long totalSecs = pMilliseconds / 1000; + long totalMins = totalSecs / 60; + long totalHours = totalMins / 60; + long totalDays = totalHours / 24; + + this.iUSeconds = (int) (totalUSecs % 1000000); + this.iSeconds = (int) (totalSecs % 60); + this.iMinutes = (int) (totalMins % 60); + this.iHours = (int) (totalHours % 24); + this.iDays = (int) totalDays; + + this.iUnsignificantUSecDigits = 3; + this.iAccuracyDivisor = USEC_ACCURACY_DIV_A[this.iUnsignificantUSecDigits]; + + this.iTotalMicrosCalced = true; + this.iTotalMicros = pMilliseconds * 1000; + + debug( + "CIMDateTimeInterval(" + + pMilliseconds + + "): days=" + + this.iDays + + ", hours=" + + this.iHours + + ", mins=" + + this.iMinutes + + ", secs=" + + this.iSeconds + + ", usecs=" + + this.iUSeconds + + ", acc div=" + + this.iAccuracyDivisor + + ", unsig digits=" + + this.iUnsignificantUSecDigits + ); + } + + /** + * Creates a CIMDateTimeInterval object using a string. + * + * @param pIntervalString + * A string in the format of ddddddddHHMMSS.mmmmmm:000. + * @throws IllegalArgumentException + * If string is not in the correct format or null. + */ + public CIMDateTimeInterval(String pIntervalString) throws IllegalArgumentException { + if (pIntervalString == null) throw new IllegalArgumentException("Null IntervalString is not allowed!"); + if (pIntervalString.length() != LENGTH) throw new IllegalArgumentException( + "Length of " + pIntervalString + " must be " + LENGTH + ", " + pIntervalString.length() + " is not valid!" + ); + String intervalStr = setAccuracy(pIntervalString); + DTStringReader dtReader = new DTStringReader(intervalStr); + this.iDays = dtReader.readAndCheck(8, "days", 0, MAX_DAY, true); + this.iHours = dtReader.readAndCheck(2, "hours", 0, MAX_HOUR, true); + this.iMinutes = dtReader.readAndCheck(2, "minutes", 0, MAX_MIN, true); + this.iSeconds = dtReader.readAndCheck(2, "seconds", 0, MAX_SEC, true); + dtReader.read('.'); + this.iUSeconds = dtReader.readAndCheck(6, "microseconds", 0, MAX_MICROSEC, false); + if (this.iAccuracyDivisor >= SEC_ACCURACY_DIV) this.iUSeconds = -1; + dtReader.read(':'); + int zeros = dtReader.read(3, "zeros", false); + if (zeros != 0) { + String msg = "In " + pIntervalString + " the last 3 characters after ':' must be zeros!"; + throw new IllegalArgumentException(msg); + } + + debug( + "CIMDateTimeInterval(\"" + + pIntervalString + + "\"): days=" + + this.iDays + + ", hours=" + + this.iHours + + ", mins=" + + this.iMinutes + + ", secs=" + + this.iSeconds + + ", usecs=" + + this.iUSeconds + + ", acc div=" + + this.iAccuracyDivisor + + ", unsig digits=" + + this.iUnsignificantUSecDigits + ); + } + + /** + * Compares the CIMDateTimeInterval object with this one. If + * either interval has "Not Significant" fields then we only compare the + * significant fields. + * + * @param pObj + * The CIMDateTimeInterval to be compared with this + * one. + * @return -1, zero, or 1 as this interval is less than, equal to, or + * greater than the specified interval. + * @throws IllegalArgumentException + * If the object passed in is not an instance of + * CIMDataTimeInterval. + */ + public int compareTo(CIMDateTime pObj) throws IllegalArgumentException { + if (!(pObj instanceof CIMDateTimeInterval)) { + String msg = + "This method requires a CIMDateTimeInterval instance, while it has received a " + + (pObj == null ? "null!" : pObj.getClass().getName() + " instance!"); + throw new IllegalArgumentException(msg); + } + CIMDateTimeInterval that = (CIMDateTimeInterval) pObj; + long accuracyDivisor = Math.max(this.iAccuracyDivisor, that.iAccuracyDivisor); + debug( + "this.acDiv=" + this.iAccuracyDivisor + ", that.acDiv=" + that.iAccuracyDivisor + ", acDiv=" + accuracyDivisor + ); + Long thisMicros = Long.valueOf(calcMicros(accuracyDivisor)); + Long thatMicros = Long.valueOf(that.calcMicros(accuracyDivisor)); + debug("thisUs=" + thisMicros + ", thatUs=" + thatMicros); + return thisMicros.compareTo(thatMicros); + } + + /** + * Gets the internal string representation of this object. + * + * @return The internal representation of the + * CIMDateTimeInterval object. + */ + @Override + public String getDateTimeString() { + if (this.iStr != null) return this.iStr; + // ddddddddHHMMSS.mmmmmm:000 + DTStringWriter dtWriter = new DTStringWriter(); + dtWriter.write(8, this.iDays); + dtWriter.write(2, this.iHours); + dtWriter.write(2, this.iMinutes); + dtWriter.write(2, this.iSeconds); + dtWriter.write('.'); + dtWriter.writeUSec(this.iUSeconds / (int) this.iAccuracyDivisor, this.iUnsignificantUSecDigits); + dtWriter.write(":000"); + return dtWriter.toString(); + } + + /** + * Returns days value of this interval. + * + * @return If days field "not significant" this returns -1, otherwise + * returns number of days in the interval. + */ + public int getDays() { + return this.iDays; + } + + /** + * Returns hours value of this interval. + * + * @return If hours field "not significant" this returns -1, otherwise + * returns number of hours in the interval. + */ + public int getHours() { + return this.iHours; + } + + /** + * Returns microseconds value of this interval. + * + * @return If microseconds field "not significant" this returns -1, + * otherwise returns number of microseconds in the interval. + */ + public int getMicroseconds() { + return this.iUSeconds; + } + + /** + * Returns minutes value of this interval. + * + * @return If minutes field "not significant" this returns -1, otherwise + * returns number of minutes in the interval. + */ + public int getMinutes() { + return this.iMinutes; + } + + /** + * Returns seconds value of this interval. + * + * @return If seconds field "not significant" this returns -1, otherwise + * returns number of seconds in the interval. + */ + public int getSeconds() { + return this.iSeconds; + } + + /** + * Returns the total length of the interval in milliseconds. + * + * @return The length of the interval in milliseconds. + */ + public long getTotalMilliseconds() { + return getTotalMicros() / 1000; + } + + /** + * Returns the hash code for this object. + * + * @return A hash code value for this object. + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return getDateTimeString().hashCode(); + } + + /** + * Returns a String representation of the + * CIMDateTimeInterval. This method is intended to be used only + * for debugging purposes, and the format of the returned string may vary + * between implementations. The returned string may be empty but may not be + * null. + * + * @return String representation of this datetime. + */ + @Override + public String toString() { + return getDateTimeString(); + } + + // ddddddddHHMMSS.mmmmmm:000 + + private static final int DAY_START_IDX = 0, HOUR_START_IDX = 8, MIN_START_IDX = 10, SEC_START_IDX = 12, DOT_IDX = + 14, USEC_START_IDX = 15, UTC_START_IDX = 21, LENGTH = 25; + + /** + * Checks the granularity of the CIMDateTimeAbsolute precision. + * + * @param pIdx + * Index of first asterisk in datetime string. + * @param pFieldName + * Name of field. + * @param pFieldStartIdx + * Index of first character in field of datetime string. + * @param pNextStartIdx + * Index of first character in subsequent field of datetime + * string. + * @return true if field is completely unsignificant, + * false otherwise. + * @throws IllegalArgumentException + * If field is not completely significant or completely + * unsignificant (mix of asterisks and digits). + */ + private boolean checkGranularity(int pIdx, String pFieldName, int pFieldStartIdx, int pNextStartIdx) + throws IllegalArgumentException { + if (pIdx > pFieldStartIdx && pIdx < pNextStartIdx) throw new IllegalArgumentException( + "Partial unsignificant digits are not allowed for field " + pFieldName + " in " + this.iStr + "!" + ); + return pIdx == pFieldStartIdx; + } + + /** + * Find index of first asterisk within string. + * + * @param pIvStr + * Time interval string. + * @return Index of first asterisk or -1 if asterisk does not exist. + */ + private static int findStar(String pIvStr) { + for (int i = 0; i < UTC_START_IDX; i++) if (pIvStr.charAt(i) == '*') return i; + return -1; + } + + /** + * Verify that all characters in the string after the starting index are + * asterisks. + * + * @param pIvStr + * Time interval string. + * @param pStartIdx + * Starting index. + */ + private static void checkStars(String pIvStr, int pStartIdx) { + for (int i = pStartIdx; i < UTC_START_IDX; i++) { + char ch = pIvStr.charAt(i); + if (i != DOT_IDX && ch != '*') throw new IllegalArgumentException( + "In " + + pIvStr + + " every digit character after the first '*' character must " + + "be '*', '" + + ch + + "' is invalid!" + ); + } + } + + /** + * Determines the accuracy (precision) of the interval string and replaces + * all asterisks in microsecond field with zeros. + * + * @param pIntervalStr + * Time interval string. + * @return Corrected time interval string with iAccuracyDivisor + * set. + */ + private String setAccuracy(String pIntervalStr) throws IllegalArgumentException { + this.iStr = pIntervalStr; + /* + * String transformation. Checking the correct location of '*' + * characters. '*' characters in usec field are replaced into '0' + * characters + */ + int startIdx = findStar(this.iStr); + if (startIdx < 0) return this.iStr; + // all remaining digit fields must contain '*' characters except for utc + checkStars(this.iStr, startIdx + 1); + if (checkGranularity(startIdx, "Day", DAY_START_IDX, HOUR_START_IDX)) { + this.iAccuracyDivisor = NO_ACCURACY_DIV; + } else if (checkGranularity(startIdx, "Hour", HOUR_START_IDX, MIN_START_IDX)) { + this.iAccuracyDivisor = DAY_ACCURACY_DIV; + } else if (checkGranularity(startIdx, "Minute", MIN_START_IDX, SEC_START_IDX)) { + this.iAccuracyDivisor = HOUR_ACCURACY_DIV; + } else if (checkGranularity(startIdx, "Second", SEC_START_IDX, DOT_IDX)) { + this.iAccuracyDivisor = MIN_ACCURACY_DIV; + } else { + // dealing with usec granularity + this.iUnsignificantUSecDigits = UTC_START_IDX - startIdx; + this.iAccuracyDivisor = USEC_ACCURACY_DIV_A[this.iUnsignificantUSecDigits]; + } + // all '*' in usec field is replaced into '0' + char[] buf = this.iStr.toCharArray(); + if (startIdx < USEC_START_IDX) startIdx = USEC_START_IDX; + for (int i = startIdx; i < UTC_START_IDX; i++) { + if (i == DOT_IDX) continue; + if (this.iStr.charAt(i) != '*') throw new IllegalArgumentException( + "All remaining digits must be marked as unsignificant in " + this.iStr + " !" + ); + buf[i] = '0'; + } + return new String(buf); + } + + /** + * Get total microseconds of CIMDateTimeInterval object. + * + * @return Total microseconds of time interval. + */ + private long getTotalMicros() { + if (this.iTotalMicrosCalced) return this.iTotalMicros; + this.iTotalMicrosCalced = true; + // iTotalMicros = iUSeconds + 1000000 * (iSeconds + 60 * (iMinutes + 60 + // * (iHours + 24 * iDays))); + this.iTotalMicros = this.iUSeconds > 0 ? this.iUSeconds : 0; + if (this.iSeconds > 0) this.iTotalMicros += SEC_ACCURACY_DIV * this.iSeconds; + if (this.iMinutes > 0) this.iTotalMicros += MIN_ACCURACY_DIV * this.iMinutes; + if (this.iHours > 0) this.iTotalMicros += HOUR_ACCURACY_DIV * this.iHours; + if (this.iDays > 0) this.iTotalMicros += DAY_ACCURACY_DIV * this.iDays; + debug( + "days=" + + this.iDays + + " ,hours=" + + this.iHours + + " ,mins=" + + this.iMinutes + + ", secs=" + + this.iSeconds + + ", usecs=" + + this.iUSeconds + + ", totalMicros=" + + this.iTotalMicros + ); + return this.iTotalMicros; + } + + /** + * Calculates microseconds of CIMDateTimeInterval object taking + * accuracy (precision) into consideration. + * + * @param pAccuracyDivisor + * Accuracy divisor of time interval. + * @return Total microseconds of time interval rounded down to precision. + */ + private long calcMicros(long pAccuracyDivisor) { + long remainder = getTotalMicros() % pAccuracyDivisor; + return getTotalMicros() - remainder; + } + + /** + * Checks validity of time interval field, making sure value is between + * minimum and maximum values and is not significant if following an + * unsignifcant field. + * + * @param pName + * Name of field. + * @param pValue + * Value of field. + * @param pLow + * Minimum value of field. + * @param pHigh + * Maximum value of field. + * @param pNotSignificant + * trueif previous field not significant. + * @return true if field is not significant, false + * otherwise. + * @throws IllegalArgumentException + */ + private static boolean checkLimits(String pName, int pValue, int pLow, int pHigh, boolean pNotSignificant) + throws IllegalArgumentException { + if (pValue == -1) return true; + if (pNotSignificant) throw new IllegalArgumentException( + "Not significant fields must be followed by not significant fields!" + ); + if (pValue < pLow || pValue > pHigh) throw new IllegalArgumentException( + pName + " must be between " + pLow + " and " + pHigh + ". " + pValue + " is invalid!" + ); + return false; + } + + /** + * Prints debug message. + * + * @param pMsg + * Debug message. + */ + private static void debug(String pMsg) { + // System.out.println(pMsg); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMElement.java b/src/main/java/org/metricshub/wbem/javax/cim/CIMElement.java similarity index 80% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/CIMElement.java rename to src/main/java/org/metricshub/wbem/javax/cim/CIMElement.java index 3393264..c0e2b07 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMElement.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/CIMElement.java @@ -1,148 +1,146 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, a.wolf-reber@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-09-26 lupusalex Make SBLIM client JSR48 compliant - * 1737141 2007-06-18 ebak Sync up with JSR48 evolution - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2227442 2008-11-05 blaschke-oss Add missing serialVersionUID - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2795671 2009-05-22 raman_arora Add Type to Comparable - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - * 3410126 2011-09-15 blaschke-oss TCK: CIM element name cannot be null - * 2716 2013-12-11 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.Serializable; - -//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013 -/** - * CIMElement is an abstract base class that represents a CIM - * Element as defined by the Distributed Management Task Force (DMTF) CIM Infrastructure Specification (DSP004). - */ -public abstract class CIMElement extends Object implements Serializable, Comparable { - - private static final long serialVersionUID = -3310480832682118922L; - - private String iName; - - /** - * Creates a new CIM element with the given name. - * - * @param pName - * The string for the name of the element. - * @throws IllegalArgumentException - * If name is null. - */ - public CIMElement(String pName) { - if (pName == null) throw new IllegalArgumentException("CIM element name cannot be null"); - this.iName = pName; - } - - /** - * Compares this element name to the CIMElement passed in. - * - * @param pObj - * The CIMElement to be compared. - * @return A negative integer, zero, or a positive integer as this object is - * less than, equal to, or greater than the specified object. - */ - public int compareTo(CIMElement pObj) { - if (pObj == null) return -1; - CIMElement that = pObj; - return this.iName.compareToIgnoreCase(that.iName); - } - - /** - * Takes a CIM element and returns true if it is equal to this - * CIM element. Otherwise, it returns false. Useful for - * comparing two CIM elements, for example, to determine whether a CIM - * element exists in a Collection. - * - * @param pObj - * The object to be compared a CIM element. - * @return true indicates the specified CIM element equals this - * CIM element, false indicates the CIM element does - * not equal this CIM element. - */ - @Override - public boolean equals(Object pObj) { - if (pObj instanceof CIMElement) { return this.iName - .equalsIgnoreCase(((CIMElement) pObj).iName); } - return false; - } - - /** - * Returns a string representing the name of a CIM element instance. - * - * @return The name of this CIM element. - */ - public String getName() { - return this.iName; - } - - /** - * Returns a hash code value for the CIM element. This method is supported - * for the benefit of hashtables such as those provided by - * java.util.Hashtable. - * - * @return A hash code value for this CIM element. - */ - @Override - public int hashCode() { - return this.iName.hashCode(); - } - - /** - * Returns a String representation of the - * CIMElement. This method is intended to be used only for - * debugging purposes. The format of the returned string may vary between - * implementations. The returned string may be empty but may not be - * null - * - * @return String representation of this CIM element. - */ - @Override - public String toString() { - return this.iName; - } -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, a.wolf-reber@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-09-26 lupusalex Make SBLIM client JSR48 compliant + * 1737141 2007-06-18 ebak Sync up with JSR48 evolution + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2227442 2008-11-05 blaschke-oss Add missing serialVersionUID + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2795671 2009-05-22 raman_arora Add Type to Comparable + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + * 3410126 2011-09-15 blaschke-oss TCK: CIM element name cannot be null + * 2716 2013-12-11 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.Serializable; + +//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013 +/** + * CIMElement is an abstract base class that represents a CIM + * Element as defined by the Distributed Management Task Force (DMTF) CIM Infrastructure Specification (DSP004). + */ +public abstract class CIMElement implements Serializable, Comparable { + private static final long serialVersionUID = -3310480832682118922L; + + private String iName; + + /** + * Creates a new CIM element with the given name. + * + * @param pName + * The string for the name of the element. + * @throws IllegalArgumentException + * If name is null. + */ + public CIMElement(String pName) { + if (pName == null) throw new IllegalArgumentException("CIM element name cannot be null"); + this.iName = pName; + } + + /** + * Compares this element name to the CIMElement passed in. + * + * @param pObj + * The CIMElement to be compared. + * @return A negative integer, zero, or a positive integer as this object is + * less than, equal to, or greater than the specified object. + */ + public int compareTo(CIMElement pObj) { + if (pObj == null) return -1; + CIMElement that = pObj; + return this.iName.compareToIgnoreCase(that.iName); + } + + /** + * Takes a CIM element and returns true if it is equal to this + * CIM element. Otherwise, it returns false. Useful for + * comparing two CIM elements, for example, to determine whether a CIM + * element exists in a Collection. + * + * @param pObj + * The object to be compared a CIM element. + * @return true indicates the specified CIM element equals this + * CIM element, false indicates the CIM element does + * not equal this CIM element. + */ + @Override + public boolean equals(Object pObj) { + if (pObj instanceof CIMElement) { + return this.iName.equalsIgnoreCase(((CIMElement) pObj).iName); + } + return false; + } + + /** + * Returns a string representing the name of a CIM element instance. + * + * @return The name of this CIM element. + */ + public String getName() { + return this.iName; + } + + /** + * Returns a hash code value for the CIM element. This method is supported + * for the benefit of hashtables such as those provided by + * java.util.Hashtable. + * + * @return A hash code value for this CIM element. + */ + @Override + public int hashCode() { + return this.iName.hashCode(); + } + + /** + * Returns a String representation of the + * CIMElement. This method is intended to be used only for + * debugging purposes. The format of the returned string may vary between + * implementations. The returned string may be empty but may not be + * null + * + * @return String representation of this CIM element. + */ + @Override + public String toString() { + return this.iName; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMFlavor.java b/src/main/java/org/metricshub/wbem/javax/cim/CIMFlavor.java similarity index 73% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/CIMFlavor.java rename to src/main/java/org/metricshub/wbem/javax/cim/CIMFlavor.java index b8bb603..469732e 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMFlavor.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/CIMFlavor.java @@ -1,89 +1,85 @@ -/* - (C) Copyright IBM Corp. 2006, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant - * 1737123 2007-06-15 ebak Differences to JSR48 public review draft - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.Serializable; - -//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:58 EST 2010 -/** - * This class represents a CIM Flavor as defined by the Distributed Management - * Task Force (DMTF) CIM Infrastructure - * Specification (DSP004). CIM flavors specify overriding and inheritance rules. These - * rules specify how qualifiers are transmitted from classes to derived classes. - */ -public class CIMFlavor extends Object implements Serializable { - - private static final long serialVersionUID = -4177389103635687939l; - - /** - * The qualifier cannot be overridden. - */ - public static final int DISABLEOVERRIDE = 1; - - /** - * The qualifier applies only to the class in which it is declared. - */ - public static final int RESTRICTED = 2; - - /** - * The qualifier can be specified in multiple locales (language and country - * combination). - */ - public static final int TRANSLATE = 4; - - private static final int[] flavors = { DISABLEOVERRIDE, RESTRICTED, TRANSLATE }; - - /** - * Returns an array of possible flavors. - * - * @return All possible flavors. - */ - public static int[] getFlavors() { - return flavors; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant + * 1737123 2007-06-15 ebak Differences to JSR48 public review draft + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.Serializable; + +//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:58 EST 2010 +/** + * This class represents a CIM Flavor as defined by the Distributed Management + * Task Force (DMTF) CIM Infrastructure + * Specification (DSP004). CIM flavors specify overriding and inheritance rules. These + * rules specify how qualifiers are transmitted from classes to derived classes. + */ +public class CIMFlavor implements Serializable { + private static final long serialVersionUID = -4177389103635687939l; + + /** + * The qualifier cannot be overridden. + */ + public static final int DISABLEOVERRIDE = 1; + + /** + * The qualifier applies only to the class in which it is declared. + */ + public static final int RESTRICTED = 2; + + /** + * The qualifier can be specified in multiple locales (language and country + * combination). + */ + public static final int TRANSLATE = 4; + + private static final int[] flavors = { DISABLEOVERRIDE, RESTRICTED, TRANSLATE }; + + /** + * Returns an array of possible flavors. + * + * @return All possible flavors. + */ + public static int[] getFlavors() { + return flavors; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMInstance.java b/src/main/java/org/metricshub/wbem/javax/cim/CIMInstance.java similarity index 83% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/CIMInstance.java rename to src/main/java/org/metricshub/wbem/javax/cim/CIMInstance.java index f9954ef..9bb0280 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMInstance.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/CIMInstance.java @@ -1,368 +1,378 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant - * 1669961 2006-04-16 lupusalex CIMTypedElement.getType() =>getDataType() - * 1776114 2007-08-21 ebak Cannot derive instance of class CIM_IndicationSubscription - * 1855726 2008-02-11 blaschke-oss CIMInstance.deriveInstance is setting wrong CIMObjectPath - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - * 2944842 2010-02-08 blaschke-oss Missing thrown ArrayIndexOutOfBoundsException - * 3529151 2012-08-22 blaschke-oss TCK: CIMInstance property APIs include keys from COP - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.logging.Level; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.CIMElementSorter; -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.MOF; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.StringSorter; - -//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:58 EST 2010 -/** - * This class represents a CIM instance as defined by the Distributed Management - * Task Force (DMTF) CIM Infrastructure - * Specification (DSP004). - */ -public class CIMInstance extends Object implements CIMNamedElementInterface, Serializable { - - private static final long serialVersionUID = -249160087013230559L; - - private static final CIMProperty[] EMPTY_PROP_A = new CIMProperty[0]; - - private CIMObjectPath iObjPath; - - private CIMProperty[] iProps; - - /** - * Constructs a CIMInstance object using the name and - * properties specified. - * - * @param pName - * The CIMObjectPath for this - * CIMInstance. - * @param pProps - * The properties for this CIMInstance. - * @throws IllegalArgumentException - * If pName is null or - * pName.getObjectName() is null.
      - * [OPTIONAL] - If the key property values do not match the - * values in the property array. This is optional due to the - * cost of the verification. Some implementations may leave it - * up to the developer to ensure that the values match. - */ - public CIMInstance(CIMObjectPath pName, CIMProperty[] pProps) - throws IllegalArgumentException { - if (pName == null) { - String msg = "CIMObjectPath parameter cannot be null!"; - // TODO: tracing - throw new IllegalArgumentException(msg); - } - if (pName.getObjectName() == null) { - String msg = "ObjectName cannot be null!"; - // TODO: tracing - throw new IllegalArgumentException(msg); - } - - this.iObjPath = pName; - if (pProps != null) { - this.iProps = pProps; - CIMElementSorter.sort(this.iProps); - } else { - this.iProps = new CIMProperty[0]; - } - } - - /** - * Returns a CIMInstance with the updated - * CIMObjectPath. - * - * @param pPath - * The complete CIMObjectPath for this instance. - * @return A new CIMInstance with the updated - * CIMObjectPath. - */ - public CIMInstance deriveInstance(CIMObjectPath pPath) { - return new CIMInstance(pPath, this.iProps); - } - - /** - * Returns a CIMInstance with the updated values for the - * properties in pPropA. Any new properties are ignored. - * - * @param pPropA - * The array of properties to update. - * @return A new instance with the updated properties. - */ - public CIMInstance deriveInstance(CIMProperty[] pPropA) { - if (pPropA == null || pPropA.length == 0) return this; - CIMProperty[] newPropA = new CIMProperty[getPropertyCount()]; - for (int i = 0; i < newPropA.length; i++) - newPropA[i] = this.iProps[i]; - for (int i = 0; i < pPropA.length; i++) { - CIMProperty newProp = pPropA[i]; - int idx = CIMElementSorter.findIdx(newPropA, newProp.getName()); - if (idx < 0) continue; - CIMProperty oldProp = newPropA[idx]; - /* - * 1776114 -> reference type comparison shouldn't be sensitive to - * the referenced class name due to derivation - */ - if (!typesEqual(oldProp, newProp)) { - LogAndTraceBroker.getBroker().trace( - Level.FINE, - "CIMInstance.deriveInstance() can update only property " - + "values but not property types!\n" + "original property: " - + oldProp + "\nnew property: " + newProp); - continue; - } - newPropA[idx] = new CIMProperty(oldProp.getName(), newProp.getDataType(), - newProp.getValue(), oldProp.isKey(), oldProp.isPropagated(), oldProp - .getOriginClass()); - } - return new CIMInstance(this.iObjPath, newPropA); - } - - /** - * Indicates whether some other instance is equal to this one. Two - * CIMInstances are considered equal if the names are the same. - * This method does NOT compare each property value. - * - * @param pObj - * The object to compare. - * @return true if the specified path references the same - * instance, otherwise false. - */ - @Override - public boolean equals(Object pObj) { - if (!(pObj instanceof CIMInstance)) return false; - CIMInstance that = (CIMInstance) pObj; - return this.iObjPath.equals(that.iObjPath); - } - - /** - * This method returns a new CIMInstance with properties - * filtered according to the input parameters. Inclusion of class origin and - * qualifiers can also be controlled. - * - * @param pLocalOnly - * Include only the properties values that were instantiated in - * this instance. - * @param pIncludeClassOrigin - * classOrigins are only included if true. - * @param pPropertyList - * If the pPropertyList input parameter is not - * null, the members of the array define one or more - * Property names. The returned Instance does not include - * elements for any Properties missing from this list. If the - * pPropertyList input parameter is an empty array - * this signifies that no Properties are included in each - * returned class. If the pPropertyList input - * parameter is null this specifies that all - * Properties are included in each returned class. If the - * pPropertyList contains duplicate elements or - * invalid property names, they are ignored. - * @return CIMInstance matching the input filter. - */ - public CIMInstance filterProperties(boolean pLocalOnly, boolean pIncludeClassOrigin, - String[] pPropertyList) { - StringSorter.sort(pPropertyList); - ArrayList> propAList = new ArrayList>(); - for (int i = 0; i < getPropertyCount(); i++) { - CIMProperty prop = getProperty(i); - if (pLocalOnly && prop.isPropagated()) continue; - if (pPropertyList != null && !StringSorter.find(pPropertyList, prop.getName())) continue; - propAList.add(new CIMProperty(prop.getName(), prop.getDataType(), prop - .getValue(), prop.isKey(), prop.isPropagated(), pIncludeClassOrigin ? prop - .getOriginClass() : null)); - } - return new CIMInstance(this.iObjPath, propAList.toArray(EMPTY_PROP_A)); - } - - /** - * Get the name of the class that instantiates this CIM instance. - * - * @return Name of class that instantiates this CIM instance. - */ - public String getClassName() { - return this.iObjPath.getObjectName(); - } - - /** - * Get the key properties for this instance. - * - * @return An array of key properties. - */ - public CIMProperty[] getKeys() { - return this.iObjPath.getKeys(); - } - - /** - * Returns the CIMObjectPath that represents this instance. - * - * @return The CIMObjectPath that represents this instance. - */ - public CIMObjectPath getObjectPath() { - return this.iObjPath; - } - - /** - * Retrieve an array of the properties for this instance. - * - * @return An array of the CIM properties for this instance. - */ - public CIMProperty[] getProperties() { - return this.iProps == null ? new CIMProperty[0] : this.iProps; - } - - /** - * Get a class property by index. - * - * @param pIndex - * The index of the class property to retrieve. - * @return The CIMProperty at the specified index. - * @throws ArrayIndexOutOfBoundsException - */ - public CIMProperty getProperty(int pIndex) throws ArrayIndexOutOfBoundsException { - return this.iProps[pIndex]; - } - - /** - * Returns the specified property. - * - * @param pName - * The text string for the name of the property. - * @return The property requested or null if the property does - * not exist. - */ - public CIMProperty getProperty(String pName) { - return getProperty(pName, null); - } - - /** - * Returns the specified CIMProperty. - * - * @param pName - * The string name of the property to get. - * @param pOriginClass - * (Optional) The string name of the class in which the property - * was defined. - * @return null if the property does not exist, otherwise - * returns the CIM property. - */ - public CIMProperty getProperty(String pName, String pOriginClass) { - CIMProperty prop = (CIMProperty) CIMElementSorter.find(this.iProps, pName); - if (prop == null) return null; - if (pOriginClass == null) return prop; - if (pOriginClass.equalsIgnoreCase(prop.getOriginClass())) return prop; - return null; - } - - /** - * Get the number of properties defined in this CIMInstance. - * - * @return The number of properties defined in the CIMInstance. - */ - public int getPropertyCount() { - return this.iProps == null ? 0 : this.iProps.length; - } - - /** - * Returns the value of a property of this CIM Instance. - * - * @param name - * The name of the property. - * @return The value for the specified property name or null if - * the property does not exist. - */ - public Object getPropertyValue(String name) { - CIMProperty prop = getProperty(name); - return prop == null ? null : prop.getValue(); - } - - /** - * Computes the hash code for this instance. The hash code will be the - * object path of the instance not including the host or namespace - * information. - * - * @return The integer representing the hash code for this object path. - */ - @Override - public int hashCode() { - return toString().hashCode(); - } - - /** - * Returns a String representation of the - * CIMInstance. This method is intended to be used only for - * debugging purposes, and the format of the returned string may vary - * between implementations. The returned string may be empty but may not be - * null. - * - * @return String representation of this instance. - */ - @Override - public String toString() { - return MOF.instanceDeclaration(this, MOF.EMPTY); - } - - /** - * Indicates whether the data types of the two properties are equal. - * - * @param pProp0 - * First property. - *@param pProp1 - * Second property. - * @return true if the data types are the same, - * false otherwise. - */ - private static boolean typesEqual(CIMProperty pProp0, CIMProperty pProp1) { - CIMDataType type0 = pProp0.getDataType(), type1 = pProp0.getDataType(); - return type0.getType() == type1.getType() && type0.isArray() == type1.isArray(); - - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant + * 1669961 2006-04-16 lupusalex CIMTypedElement.getType() =>getDataType() + * 1776114 2007-08-21 ebak Cannot derive instance of class CIM_IndicationSubscription + * 1855726 2008-02-11 blaschke-oss CIMInstance.deriveInstance is setting wrong CIMObjectPath + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + * 2944842 2010-02-08 blaschke-oss Missing thrown ArrayIndexOutOfBoundsException + * 3529151 2012-08-22 blaschke-oss TCK: CIMInstance property APIs include keys from COP + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.logging.Level; +import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMElementSorter; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; +import org.metricshub.wbem.sblim.cimclient.internal.util.MOF; +import org.metricshub.wbem.sblim.cimclient.internal.util.StringSorter; + +//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:58 EST 2010 +/** + * This class represents a CIM instance as defined by the Distributed Management + * Task Force (DMTF) CIM Infrastructure + * Specification (DSP004). + */ +public class CIMInstance implements CIMNamedElementInterface, Serializable { + private static final long serialVersionUID = -249160087013230559L; + + private static final CIMProperty[] EMPTY_PROP_A = new CIMProperty[0]; + + private CIMObjectPath iObjPath; + + private CIMProperty[] iProps; + + /** + * Constructs a CIMInstance object using the name and + * properties specified. + * + * @param pName + * The CIMObjectPath for this + * CIMInstance. + * @param pProps + * The properties for this CIMInstance. + * @throws IllegalArgumentException + * If pName is null or + * pName.getObjectName() is null.
      + * [OPTIONAL] - If the key property values do not match the + * values in the property array. This is optional due to the + * cost of the verification. Some implementations may leave it + * up to the developer to ensure that the values match. + */ + public CIMInstance(CIMObjectPath pName, CIMProperty[] pProps) throws IllegalArgumentException { + if (pName == null) { + String msg = "CIMObjectPath parameter cannot be null!"; + // TODO: tracing + throw new IllegalArgumentException(msg); + } + if (pName.getObjectName() == null) { + String msg = "ObjectName cannot be null!"; + // TODO: tracing + throw new IllegalArgumentException(msg); + } + + this.iObjPath = pName; + if (pProps != null) { + this.iProps = pProps; + CIMElementSorter.sort(this.iProps); + } else { + this.iProps = new CIMProperty[0]; + } + } + + /** + * Returns a CIMInstance with the updated + * CIMObjectPath. + * + * @param pPath + * The complete CIMObjectPath for this instance. + * @return A new CIMInstance with the updated + * CIMObjectPath. + */ + public CIMInstance deriveInstance(CIMObjectPath pPath) { + return new CIMInstance(pPath, this.iProps); + } + + /** + * Returns a CIMInstance with the updated values for the + * properties in pPropA. Any new properties are ignored. + * + * @param pPropA + * The array of properties to update. + * @return A new instance with the updated properties. + */ + public CIMInstance deriveInstance(CIMProperty[] pPropA) { + if (pPropA == null || pPropA.length == 0) return this; + CIMProperty[] newPropA = new CIMProperty[getPropertyCount()]; + for (int i = 0; i < newPropA.length; i++) newPropA[i] = this.iProps[i]; + for (int i = 0; i < pPropA.length; i++) { + CIMProperty newProp = pPropA[i]; + int idx = CIMElementSorter.findIdx(newPropA, newProp.getName()); + if (idx < 0) continue; + CIMProperty oldProp = newPropA[idx]; + /* + * 1776114 -> reference type comparison shouldn't be sensitive to + * the referenced class name due to derivation + */ + if (!typesEqual(oldProp, newProp)) { + LogAndTraceBroker + .getBroker() + .trace( + Level.FINE, + "CIMInstance.deriveInstance() can update only property " + + "values but not property types!\n" + + "original property: " + + oldProp + + "\nnew property: " + + newProp + ); + continue; + } + newPropA[idx] = + new CIMProperty( + oldProp.getName(), + newProp.getDataType(), + newProp.getValue(), + oldProp.isKey(), + oldProp.isPropagated(), + oldProp.getOriginClass() + ); + } + return new CIMInstance(this.iObjPath, newPropA); + } + + /** + * Indicates whether some other instance is equal to this one. Two + * CIMInstances are considered equal if the names are the same. + * This method does NOT compare each property value. + * + * @param pObj + * The object to compare. + * @return true if the specified path references the same + * instance, otherwise false. + */ + @Override + public boolean equals(Object pObj) { + if (!(pObj instanceof CIMInstance)) return false; + CIMInstance that = (CIMInstance) pObj; + return this.iObjPath.equals(that.iObjPath); + } + + /** + * This method returns a new CIMInstance with properties + * filtered according to the input parameters. Inclusion of class origin and + * qualifiers can also be controlled. + * + * @param pLocalOnly + * Include only the properties values that were instantiated in + * this instance. + * @param pIncludeClassOrigin + * classOrigins are only included if true. + * @param pPropertyList + * If the pPropertyList input parameter is not + * null, the members of the array define one or more + * Property names. The returned Instance does not include + * elements for any Properties missing from this list. If the + * pPropertyList input parameter is an empty array + * this signifies that no Properties are included in each + * returned class. If the pPropertyList input + * parameter is null this specifies that all + * Properties are included in each returned class. If the + * pPropertyList contains duplicate elements or + * invalid property names, they are ignored. + * @return CIMInstance matching the input filter. + */ + public CIMInstance filterProperties(boolean pLocalOnly, boolean pIncludeClassOrigin, String[] pPropertyList) { + StringSorter.sort(pPropertyList); + ArrayList> propAList = new ArrayList>(); + for (int i = 0; i < getPropertyCount(); i++) { + CIMProperty prop = getProperty(i); + if (pLocalOnly && prop.isPropagated()) continue; + if (pPropertyList != null && !StringSorter.find(pPropertyList, prop.getName())) continue; + propAList.add( + new CIMProperty( + prop.getName(), + prop.getDataType(), + prop.getValue(), + prop.isKey(), + prop.isPropagated(), + pIncludeClassOrigin ? prop.getOriginClass() : null + ) + ); + } + return new CIMInstance(this.iObjPath, propAList.toArray(EMPTY_PROP_A)); + } + + /** + * Get the name of the class that instantiates this CIM instance. + * + * @return Name of class that instantiates this CIM instance. + */ + public String getClassName() { + return this.iObjPath.getObjectName(); + } + + /** + * Get the key properties for this instance. + * + * @return An array of key properties. + */ + public CIMProperty[] getKeys() { + return this.iObjPath.getKeys(); + } + + /** + * Returns the CIMObjectPath that represents this instance. + * + * @return The CIMObjectPath that represents this instance. + */ + public CIMObjectPath getObjectPath() { + return this.iObjPath; + } + + /** + * Retrieve an array of the properties for this instance. + * + * @return An array of the CIM properties for this instance. + */ + public CIMProperty[] getProperties() { + return this.iProps == null ? new CIMProperty[0] : this.iProps; + } + + /** + * Get a class property by index. + * + * @param pIndex + * The index of the class property to retrieve. + * @return The CIMProperty at the specified index. + * @throws ArrayIndexOutOfBoundsException + */ + public CIMProperty getProperty(int pIndex) throws ArrayIndexOutOfBoundsException { + return this.iProps[pIndex]; + } + + /** + * Returns the specified property. + * + * @param pName + * The text string for the name of the property. + * @return The property requested or null if the property does + * not exist. + */ + public CIMProperty getProperty(String pName) { + return getProperty(pName, null); + } + + /** + * Returns the specified CIMProperty. + * + * @param pName + * The string name of the property to get. + * @param pOriginClass + * (Optional) The string name of the class in which the property + * was defined. + * @return null if the property does not exist, otherwise + * returns the CIM property. + */ + public CIMProperty getProperty(String pName, String pOriginClass) { + CIMProperty prop = (CIMProperty) CIMElementSorter.find(this.iProps, pName); + if (prop == null) return null; + if (pOriginClass == null) return prop; + if (pOriginClass.equalsIgnoreCase(prop.getOriginClass())) return prop; + return null; + } + + /** + * Get the number of properties defined in this CIMInstance. + * + * @return The number of properties defined in the CIMInstance. + */ + public int getPropertyCount() { + return this.iProps == null ? 0 : this.iProps.length; + } + + /** + * Returns the value of a property of this CIM Instance. + * + * @param name + * The name of the property. + * @return The value for the specified property name or null if + * the property does not exist. + */ + public Object getPropertyValue(String name) { + CIMProperty prop = getProperty(name); + return prop == null ? null : prop.getValue(); + } + + /** + * Computes the hash code for this instance. The hash code will be the + * object path of the instance not including the host or namespace + * information. + * + * @return The integer representing the hash code for this object path. + */ + @Override + public int hashCode() { + return toString().hashCode(); + } + + /** + * Returns a String representation of the + * CIMInstance. This method is intended to be used only for + * debugging purposes, and the format of the returned string may vary + * between implementations. The returned string may be empty but may not be + * null. + * + * @return String representation of this instance. + */ + @Override + public String toString() { + return MOF.instanceDeclaration(this, MOF.EMPTY); + } + + /** + * Indicates whether the data types of the two properties are equal. + * + * @param pProp0 + * First property. + *@param pProp1 + * Second property. + * @return true if the data types are the same, + * false otherwise. + */ + private static boolean typesEqual(CIMProperty pProp0, CIMProperty pProp1) { + CIMDataType type0 = pProp0.getDataType(), type1 = pProp0.getDataType(); + return type0.getType() == type1.getType() && type0.isArray() == type1.isArray(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMMethod.java b/src/main/java/org/metricshub/wbem/javax/cim/CIMMethod.java similarity index 83% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/CIMMethod.java rename to src/main/java/org/metricshub/wbem/javax/cim/CIMMethod.java index de77c23..93dcae3 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMMethod.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/CIMMethod.java @@ -1,305 +1,310 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant - * 1660756 2007-02-22 ebak Embedded object support - * 1737141 2007-06-18 ebak Sync up with JSR48 evolution - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - * 2944842 2010-02-08 blaschke-oss Missing thrown ArrayIndexOutOfBoundsException - * 3001333 2010-05-19 blaschke-oss CIMMethod class ignores propagated parameter - * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues - * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Arrays; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.CIMElementSorter; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.CIMQualifiedElementInterfaceImpl; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.MOF; - -//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 -/** - * This class represents a CIM Method as defined by the Distributed Management - * Task Force (DMTF) CIM Infrastructure - * Specification (DSP004). - * - * @param - * Type parameter. - */ -public class CIMMethod extends CIMTypedElement implements CIMQualifiedElementInterface { - - private static final long serialVersionUID = -3920536802046705977L; - - private CIMQualifiedElementInterfaceImpl iQualiImpl; - - private CIMParameter[] iParams; - - private boolean iPropagated; - - private String iOriginClass; - - /** - * Constructs a CIMMethod object with the specified - * information. - * - * @param pName - * The name of the method. - * @param pType - * The data type of the method. - * @param pQualis - * The method qualifiers. - * @param pParams - * The array of parameters for this method. - * @param pPropagated - * Is this method propagated from the superclass. - * @param pOriginClass - * The class this method was defined or overridden in. - */ - public CIMMethod(String pName, CIMDataType pType, CIMQualifier[] pQualis, - CIMParameter[] pParams, boolean pPropagated, String pOriginClass) { - super(pName, pType); - this.iQualiImpl = new CIMQualifiedElementInterfaceImpl(pQualis, false, true); - this.iParams = (CIMParameter[]) CIMElementSorter.sort(pParams); - this.iPropagated = pPropagated; - this.iOriginClass = pOriginClass; - } - - /** - * Compares this object against the specified object. The result is - * true if and only if the argument is not null - * and is a CIMMethod object that represents the same value as - * this object. - * - * @param pObj - * The object to compare. - * @return true if the objects are the same; false - * otherwise. - */ - @Override - public boolean equals(Object pObj) { - if (!(pObj instanceof CIMMethod)) return false; - if (!super.equals(pObj)) return false; - CIMMethod that = (CIMMethod) pObj; - if (!this.iQualiImpl.equals(that.iQualiImpl)) return false; - if (this.iPropagated != that.iPropagated) return false; - return Arrays.equals(getParameters(), that.getParameters()); - } - - /** - * Returns a CIMMethod filtered as specified. - * - * @param pIncludeQualifiers - * If true all qualifiers are returned; otherwise no - * qualifiers. - * @param pIncludeClassOrigin - * If true the class origin is included; otherwise - * no class origin is present. - * @return A filtered CIMMethod. - */ - public CIMMethod filter(boolean pIncludeQualifiers, boolean pIncludeClassOrigin) { - return filter(pIncludeQualifiers, pIncludeClassOrigin, false); - } - - /** - * Returns a CIMMethod filtered as specified. - * - * @param pIncludeQualifiers - * If true all qualifiers are returned; otherwise no - * qualifiers. - * @param pIncludeClassOrigin - * If true the class origin is included; otherwise - * no class origin is present - * @param pLocalOnly - * If true only the qualifiers defined on this class - * are included; otherwise all qualifiers are included. - * - * @return A filtered CIMMethod. - */ - public CIMMethod filter(boolean pIncludeQualifiers, boolean pIncludeClassOrigin, - boolean pLocalOnly) { - return new CIMMethod(getName(), getDataType(), pIncludeQualifiers ? this.iQualiImpl - .getQualifiers(pLocalOnly) : null, this.iParams, this.iPropagated, - pIncludeClassOrigin ? this.iOriginClass : null); - } - - /** - * Returns the class name in which this method was defined or overridden. - * - * @return Name of class where this property was defined. - */ - public String getOriginClass() { - return this.iOriginClass; - } - - /** - * Get the parameter that matches the specified name. - * - * @param pName - * The name of the CIMParameter to retrieve. - * @return CIMParameter matching the name specified; otherwise - * null. - */ - public CIMParameter getParameter(String pName) { - return (CIMParameter) CIMElementSorter.find(this.iParams, pName); - } - - /** - * Returns an array of the parameters for this method. - * - * @return The parameters for this method. - */ - public CIMParameter[] getParameters() { - return this.iParams == null ? new CIMParameter[0] : this.iParams; - } - - /** - * Get a qualifier by index. - * - * @param pIndex - * The index of the qualifier. - * @return The Qualifier at index pIndex. - * @throws ArrayIndexOutOfBoundsException - */ - public CIMQualifier getQualifier(int pIndex) throws ArrayIndexOutOfBoundsException { - return this.iQualiImpl.getQualifier(pIndex); - } - - /** - * Gets a qualifier by name. - * - * @param pName - * The name of the qualifier to get. - * @return null if the qualifier does not exist, otherwise - * returns the reference to the qualifier. - */ - public CIMQualifier getQualifier(String pName) { - return this.iQualiImpl.getQualifier(pName); - } - - /** - * Get the number of qualifiers defined for this CIM Method. - * - * @return The number of qualifiers. - */ - public int getQualifierCount() { - return this.iQualiImpl.getQualifierCount(); - } - - /** - * Returns the list of qualifiers for this class. - * - * @return Qualifiers for this class. - */ - public CIMQualifier[] getQualifiers() { - return this.iQualiImpl.getQualifiers(); - } - - /** - * Gets a qualifier value by name. - * - * @param pName - * The name of the qualifier to get. - * @return null if the qualifier does not exist or value is - * null, otherwise returns the reference to the - * qualifier. - */ - public Object getQualifierValue(String pName) { - return this.iQualiImpl.getQualifierValue(pName); - } - - /** - * Checks whether the specified qualifier is one of the qualifiers in this - * CIM method. - * - * @param pName - * The name of the qualifier. - * @return true if the qualifier exists in this CIM method, - * otherwise false. - */ - public boolean hasQualifier(String pName) { - return this.iQualiImpl.hasQualifier(pName); - } - - /** - * Checks whether the specified qualifier is one of the qualifiers defined - * for this method with the specified value. This method will return - * false if the qualifier is not applied or if the value does - * not match. - * - * @param pName - * The name of the qualifier. - * @param pValue - * The value to be tested. - * @return true if the qualifier exists and has this value, - * otherwise false. - */ - public boolean hasQualifierValue(String pName, Object pValue) { - return this.iQualiImpl.hasQualifierValue(pName, pValue); - } - - /** - * Determines if this method is Propagated. - * - * @return true if this method is propagated. - */ - public boolean isPropagated() { - return this.iPropagated; - } - - /** - * Returns a String representation of the - * CIMMethod. This method is intended to be used only for - * debugging purposes, and the format of the returned string may vary - * between implementations. The returned string may be empty but may not be - * null. - * - * @return The string representation of this method. - */ - @Override - public String toString() { - return MOF.methodDeclaration(this, MOF.EMPTY); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant + * 1660756 2007-02-22 ebak Embedded object support + * 1737141 2007-06-18 ebak Sync up with JSR48 evolution + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + * 2944842 2010-02-08 blaschke-oss Missing thrown ArrayIndexOutOfBoundsException + * 3001333 2010-05-19 blaschke-oss CIMMethod class ignores propagated parameter + * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues + * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Arrays; +import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMElementSorter; +import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMQualifiedElementInterfaceImpl; +import org.metricshub.wbem.sblim.cimclient.internal.util.MOF; + +//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 +/** + * This class represents a CIM Method as defined by the Distributed Management + * Task Force (DMTF) CIM Infrastructure + * Specification (DSP004). + * + * @param + * Type parameter. + */ +public class CIMMethod extends CIMTypedElement implements CIMQualifiedElementInterface { + private static final long serialVersionUID = -3920536802046705977L; + + private CIMQualifiedElementInterfaceImpl iQualiImpl; + + private CIMParameter[] iParams; + + private boolean iPropagated; + + private String iOriginClass; + + /** + * Constructs a CIMMethod object with the specified + * information. + * + * @param pName + * The name of the method. + * @param pType + * The data type of the method. + * @param pQualis + * The method qualifiers. + * @param pParams + * The array of parameters for this method. + * @param pPropagated + * Is this method propagated from the superclass. + * @param pOriginClass + * The class this method was defined or overridden in. + */ + public CIMMethod( + String pName, + CIMDataType pType, + CIMQualifier[] pQualis, + CIMParameter[] pParams, + boolean pPropagated, + String pOriginClass + ) { + super(pName, pType); + this.iQualiImpl = new CIMQualifiedElementInterfaceImpl(pQualis, false, true); + this.iParams = (CIMParameter[]) CIMElementSorter.sort(pParams); + this.iPropagated = pPropagated; + this.iOriginClass = pOriginClass; + } + + /** + * Compares this object against the specified object. The result is + * true if and only if the argument is not null + * and is a CIMMethod object that represents the same value as + * this object. + * + * @param pObj + * The object to compare. + * @return true if the objects are the same; false + * otherwise. + */ + @Override + public boolean equals(Object pObj) { + if (!(pObj instanceof CIMMethod)) return false; + if (!super.equals(pObj)) return false; + CIMMethod that = (CIMMethod) pObj; + if (!this.iQualiImpl.equals(that.iQualiImpl)) return false; + if (this.iPropagated != that.iPropagated) return false; + return Arrays.equals(getParameters(), that.getParameters()); + } + + /** + * Returns a CIMMethod filtered as specified. + * + * @param pIncludeQualifiers + * If true all qualifiers are returned; otherwise no + * qualifiers. + * @param pIncludeClassOrigin + * If true the class origin is included; otherwise + * no class origin is present. + * @return A filtered CIMMethod. + */ + public CIMMethod filter(boolean pIncludeQualifiers, boolean pIncludeClassOrigin) { + return filter(pIncludeQualifiers, pIncludeClassOrigin, false); + } + + /** + * Returns a CIMMethod filtered as specified. + * + * @param pIncludeQualifiers + * If true all qualifiers are returned; otherwise no + * qualifiers. + * @param pIncludeClassOrigin + * If true the class origin is included; otherwise + * no class origin is present + * @param pLocalOnly + * If true only the qualifiers defined on this class + * are included; otherwise all qualifiers are included. + * + * @return A filtered CIMMethod. + */ + public CIMMethod filter(boolean pIncludeQualifiers, boolean pIncludeClassOrigin, boolean pLocalOnly) { + return new CIMMethod( + getName(), + getDataType(), + pIncludeQualifiers ? this.iQualiImpl.getQualifiers(pLocalOnly) : null, + this.iParams, + this.iPropagated, + pIncludeClassOrigin ? this.iOriginClass : null + ); + } + + /** + * Returns the class name in which this method was defined or overridden. + * + * @return Name of class where this property was defined. + */ + public String getOriginClass() { + return this.iOriginClass; + } + + /** + * Get the parameter that matches the specified name. + * + * @param pName + * The name of the CIMParameter to retrieve. + * @return CIMParameter matching the name specified; otherwise + * null. + */ + public CIMParameter getParameter(String pName) { + return (CIMParameter) CIMElementSorter.find(this.iParams, pName); + } + + /** + * Returns an array of the parameters for this method. + * + * @return The parameters for this method. + */ + public CIMParameter[] getParameters() { + return this.iParams == null ? new CIMParameter[0] : this.iParams; + } + + /** + * Get a qualifier by index. + * + * @param pIndex + * The index of the qualifier. + * @return The Qualifier at index pIndex. + * @throws ArrayIndexOutOfBoundsException + */ + public CIMQualifier getQualifier(int pIndex) throws ArrayIndexOutOfBoundsException { + return this.iQualiImpl.getQualifier(pIndex); + } + + /** + * Gets a qualifier by name. + * + * @param pName + * The name of the qualifier to get. + * @return null if the qualifier does not exist, otherwise + * returns the reference to the qualifier. + */ + public CIMQualifier getQualifier(String pName) { + return this.iQualiImpl.getQualifier(pName); + } + + /** + * Get the number of qualifiers defined for this CIM Method. + * + * @return The number of qualifiers. + */ + public int getQualifierCount() { + return this.iQualiImpl.getQualifierCount(); + } + + /** + * Returns the list of qualifiers for this class. + * + * @return Qualifiers for this class. + */ + public CIMQualifier[] getQualifiers() { + return this.iQualiImpl.getQualifiers(); + } + + /** + * Gets a qualifier value by name. + * + * @param pName + * The name of the qualifier to get. + * @return null if the qualifier does not exist or value is + * null, otherwise returns the reference to the + * qualifier. + */ + public Object getQualifierValue(String pName) { + return this.iQualiImpl.getQualifierValue(pName); + } + + /** + * Checks whether the specified qualifier is one of the qualifiers in this + * CIM method. + * + * @param pName + * The name of the qualifier. + * @return true if the qualifier exists in this CIM method, + * otherwise false. + */ + public boolean hasQualifier(String pName) { + return this.iQualiImpl.hasQualifier(pName); + } + + /** + * Checks whether the specified qualifier is one of the qualifiers defined + * for this method with the specified value. This method will return + * false if the qualifier is not applied or if the value does + * not match. + * + * @param pName + * The name of the qualifier. + * @param pValue + * The value to be tested. + * @return true if the qualifier exists and has this value, + * otherwise false. + */ + public boolean hasQualifierValue(String pName, Object pValue) { + return this.iQualiImpl.hasQualifierValue(pName, pValue); + } + + /** + * Determines if this method is Propagated. + * + * @return true if this method is propagated. + */ + public boolean isPropagated() { + return this.iPropagated; + } + + /** + * Returns a String representation of the + * CIMMethod. This method is intended to be used only for + * debugging purposes, and the format of the returned string may vary + * between implementations. The returned string may be empty but may not be + * null. + * + * @return The string representation of this method. + */ + @Override + public String toString() { + return MOF.methodDeclaration(this, MOF.EMPTY); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMNamedElementInterface.java b/src/main/java/org/metricshub/wbem/javax/cim/CIMNamedElementInterface.java similarity index 67% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/CIMNamedElementInterface.java rename to src/main/java/org/metricshub/wbem/javax/cim/CIMNamedElementInterface.java index 318a916..b7c498b 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMNamedElementInterface.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/CIMNamedElementInterface.java @@ -1,61 +1,57 @@ -/* - (C) Copyright IBM Corp. 2006, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------------------------- - * 2006-04-25 ebak Initial commit - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 -/** - * The NamedElementInterface is used by CIM Elements that are named. For - * example, CIM Qualifier Types, CIM Classes and CIM Instances are all named and - * can be retrieved by a WBEM client. - */ -public interface CIMNamedElementInterface { - - /** - * Retrieve the ObjectPath that represents the name for this element. - * - * @return The Object Path that represents the element. - */ - CIMObjectPath getObjectPath(); - -} +/* + (C) Copyright IBM Corp. 2006, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------------------------- + * 2006-04-25 ebak Initial commit + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 +/** + * The NamedElementInterface is used by CIM Elements that are named. For + * example, CIM Qualifier Types, CIM Classes and CIM Instances are all named and + * can be retrieved by a WBEM client. + */ +public interface CIMNamedElementInterface { + /** + * Retrieve the ObjectPath that represents the name for this element. + * + * @return The Object Path that represents the element. + */ + CIMObjectPath getObjectPath(); +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMObjectPath.java b/src/main/java/org/metricshub/wbem/javax/cim/CIMObjectPath.java similarity index 82% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/CIMObjectPath.java rename to src/main/java/org/metricshub/wbem/javax/cim/CIMObjectPath.java index a44e867..be0192f 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMObjectPath.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/CIMObjectPath.java @@ -1,674 +1,684 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant - * 1669961 2006-04-16 lupusalex CIMTypedElement.getType() =>getDataType() - * 1716991 2006-05-11 lupusalex FVT: CIMObjectPath.equals() should ignore host name - * 1737141 2007-06-18 ebak Sync up with JSR48 evolution - * 1917321 2008-05-29 rgummada javadoc update to constructors with 2 and more parms - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2845128 2009-09-24 blaschke-oss CIMObjectPath.toString() misses host - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - * 2944824 2010-02-08 blaschke-oss Missing getXmlSchemaName() in CIMObjectPath - * 2975975 2010-03-24 blaschke-oss TCK: CIMObjectPath(String) does not handle null - * 3023141 2010-07-01 blaschke-oss CIMObjectPath uses # constructor instead of valueOf - * 3496349 2012-03-02 blaschke-oss JSR48 1.0.0: add CIMObjectPath getKeyValue - * 3510090 2012-03-23 blaschke-oss Fix CIMObjectPath.toString() inconsistencies - * 3513343 2012-03-31 blaschke-oss TCK: CIMObjectPath must validate XML schema name - * 3513347 2012-03-31 blaschke-oss TCK: CIMObjectPath allows empty string - * 3521131 2012-04-24 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final II - * 3521119 2012-04-24 blaschke-oss JSR48 1.0.0: remove CIMObjectPath 2/3/4-parm ctors - * 3529151 2012-08-22 blaschke-oss TCK: CIMInstance property APIs include keys from COP - * 2660 2013-09-04 blaschke-oss CIMObjectPath.equalsModelPath same as equals - * 2716 2013-12-11 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.Serializable; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Arrays; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.CIMElementSorter; -import org.sentrysoftware.wbem.sblim.cimclient.internal.uri.BooleanValue; -import org.sentrysoftware.wbem.sblim.cimclient.internal.uri.CharValue; -import org.sentrysoftware.wbem.sblim.cimclient.internal.uri.DateTimeValue; -import org.sentrysoftware.wbem.sblim.cimclient.internal.uri.IntegerValue; -import org.sentrysoftware.wbem.sblim.cimclient.internal.uri.KeyValuePair; -import org.sentrysoftware.wbem.sblim.cimclient.internal.uri.KeyValuePairs; -import org.sentrysoftware.wbem.sblim.cimclient.internal.uri.RealValue; -import org.sentrysoftware.wbem.sblim.cimclient.internal.uri.ReferenceValue; -import org.sentrysoftware.wbem.sblim.cimclient.internal.uri.StringValue; -import org.sentrysoftware.wbem.sblim.cimclient.internal.uri.URI; -import org.sentrysoftware.wbem.sblim.cimclient.internal.uri.URIString; -import org.sentrysoftware.wbem.sblim.cimclient.internal.uri.Value; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.MOF; - -//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013 -/** - * This class represents the CIM Object Path as defined by the Distributed - * Management Task Force (DMTF) CIM - * Infrastructure Specification (DSP004). In order to uniquely identify a given object, a CIM object path - * includes the host, namespace, object name and keys (if the object is an - * instance).
      - *
      - * For example, the object path:
      - *
      - * - * http://myserver/root/cimv2:My_ComputerSystem.Name=mycomputer, - * CreationClassName=My_ComputerSystem - *
      - *
      - * has two parts:
      - *
      - *
      • Namespace Path
      • - *
      • - * http://myserver/root/cimv2 - * JSR48 defines the namespace path to include the scheme, host, port (optional) - * and namespace - * The example specifies the "root/cimv2" namespace on the host - * myserver.
      • Model Path
      • - *
      • My_ComputerSystem.Name=mycomputer,CreationClassName=My_ComputerSystem - *
        - * DSP0004 defines the model path for a class or qualifier type as the name of - * the class/qualifier type
        - * DSP0004 defines the model path for an instance as the class - * name.(key=value),*
        - * The example specifies an instance for the class - * My_ComputerSystem which is uniquely identified by two key - * properties and values:
      • Name=mycomputer
      • - *
      • - * CreationClassName=My_ComputerSystem
      - */ -public class CIMObjectPath extends Object implements Serializable { - - private static final long serialVersionUID = 4593259690658425064L; - - private String iScheme, iHost, iPort, iNamespace, iObjectName, iXmlSchemaName; - - private CIMProperty[] iKeys; - - /** - * Class TypeValuePair represents a type-value pair with special - * identification functionality for integer and real numbers. - * - */ - private static class TypeValuePair { - - private CIMDataType iType; - - private Object iValue; - - /** - * Constructs a type-value pair with the specified type and value. - * - * @param pType - * Type. - * @param pValue - * Value. - */ - public TypeValuePair(CIMDataType pType, Object pValue) { - this.iType = pType; - this.iValue = pValue; - } - - /** - * Constructs a type-value pair with the specified integer value. - * - * @param intVal - * Integer value. - */ - public TypeValuePair(IntegerValue intVal) { - if (intVal.isSigned()) { - switch (intVal.getBitWidth()) { - case 8: - this.iType = CIMDataType.SINT8_T; - this.iValue = Byte.valueOf(intVal.byteValue()); - break; - case 16: - this.iType = CIMDataType.SINT16_T; - this.iValue = Short.valueOf(intVal.shortValue()); - break; - case 32: - this.iType = CIMDataType.SINT32_T; - this.iValue = Integer.valueOf(intVal.intValue()); - break; - default: - this.iType = CIMDataType.SINT64_T; - this.iValue = Long.valueOf(intVal.longValue()); - } - - } else { // unsigned integers - switch (intVal.getBitWidth()) { - case 8: - this.iType = CIMDataType.UINT8_T; - this.iValue = new UnsignedInteger8(intVal.shortValue()); - break; - case 16: - this.iType = CIMDataType.UINT16_T; - this.iValue = new UnsignedInteger16(intVal.intValue()); - break; - case 32: - this.iType = CIMDataType.UINT32_T; - this.iValue = new UnsignedInteger32(intVal.longValue()); - break; - default: - this.iType = CIMDataType.UINT64_T; - this.iValue = new UnsignedInteger64(intVal.bigIntValue()); - } - } - } - - /** - * Constructs a type-value pair with the specified real value. - * - * @param pRealVal - * Real value. - */ - public TypeValuePair(RealValue pRealVal) { - // TODO: handle precision - if (pRealVal.isDouble()) { - this.iType = CIMDataType.REAL64_T; - this.iValue = new Double(pRealVal.doubleValue()); - } else { - this.iType = CIMDataType.REAL32_T; - this.iValue = new Float(pRealVal.floatValue()); - } - } - - /** - * Returns the type of the type-value pair. - * - * @return Type of type-value pair. - */ - public CIMDataType getType() { - return this.iType; - } - - /** - * Returns the value of the type-value pair. - * - * @return Value of type-value pair. - */ - public Object getValue() { - return this.iValue; - } - - } - - /** - * Extracts and returns sorted list of key-value pairs from the URI. - * - * @param pURI - * The Uniform Resource Identifier. - * @return Sorted array of keys in URI. - */ - private CIMProperty[] getKeysFromURI(URI pURI) { - KeyValuePairs pairs = pURI.getKeyValuePairs(); - if (pairs == null) return null; - CIMProperty[] keys = new CIMProperty[pairs.size()]; - for (int i = 0; i < pairs.size(); i++) { - KeyValuePair pair = (KeyValuePair) pairs.elementAt(i); - String name = pair.getKey(); - Value uriVal = pair.getValue(); - TypeValuePair typeValue; - if (uriVal instanceof StringValue) { - typeValue = new TypeValuePair(CIMDataType.STRING_T, uriVal.toString()); - } else if (uriVal instanceof ReferenceValue) { - ReferenceValue refVal = (ReferenceValue) uriVal; - CIMObjectPath op = new CIMObjectPath(refVal.getRef()); - typeValue = new TypeValuePair(new CIMDataType(op.getObjectName()), op); - } else if (uriVal instanceof BooleanValue) { - typeValue = new TypeValuePair(CIMDataType.BOOLEAN_T, ((BooleanValue) uriVal) - .getBoolean()); - } else if (uriVal instanceof CharValue) { - typeValue = new TypeValuePair(CIMDataType.CHAR16_T, ((CharValue) uriVal) - .getCharacter()); - } else if (uriVal instanceof IntegerValue) { - typeValue = new TypeValuePair((IntegerValue) uriVal); - } else if (uriVal instanceof RealValue) { - typeValue = new TypeValuePair((RealValue) uriVal); - } else if (uriVal instanceof DateTimeValue) { - typeValue = new TypeValuePair(CIMDataType.DATETIME_T, ((DateTimeValue) uriVal) - .getDateTime()); - } else { - // TODO: error or warning tracing - typeValue = new TypeValuePair(CIMDataType.INVALID_T, null); - } - keys[i] = new CIMProperty(name, typeValue.getType(), typeValue.getValue(), - true, false, null); - } - return (CIMProperty[]) CIMElementSorter.sort(keys); - } - - /** - * Initializes the elements of the CIMObjectPath from the given - * URI. - * - * @param pURI - * The Uniform Resource Identifier. - */ - private void setURI(URI pURI) { - this.iNamespace = pURI.getNamespaceName(); - this.iScheme = pURI.getNamespaceType(); - this.iHost = pURI.getHost(); - this.iPort = pURI.getPort(); - this.iObjectName = pURI.getClassName(); - this.iKeys = getKeysFromURI(pURI); - } - - /** - * Constructs a CIM Object Path referencing an instance of the specified CIM - * element in the given URI. - * - * @param pURI - * The Uniform Resource Identifier. - */ - private CIMObjectPath(URI pURI) { - setURI(pURI); - } - - /** - * Constructs a CIM Object Path referencing a CIM element. The name can - * refer to a class name or a qualifier type name, depending on the - * particular CIM element identified. In order to refer to an instance, the - * key properties and their corresponding values must be set.
      - *
      - * Should be able to handle strings, like:
      - * - * http://myserver.org:5066/root/cimv2:My_ComputerSystem.Name="mycmp",CreationClassName="My_ComputerSystem" - *
      - * http://myserver.org/root/cimv2:My_ComputerSystem.Name="mycmp",CreationClassName="My_ComputerSystem" - *
      - * //myserver.org/root/cimv2:My_ComputerSystem
      - * /root/cimv2:My_ComputerSystem - *
      - * - * @param pObjectPath - * The string representation of an object path for a CIM element - * that will be parsed and used to initialize the object. - * @throws IllegalArgumentException - * If the pObjectPath is null or an - * empty string. - */ - public CIMObjectPath(String pObjectPath) { - URI uri; - - if (pObjectPath == null) throw new IllegalArgumentException("ObjectPath is null!"); - if (pObjectPath.trim().length() == 0) throw new IllegalArgumentException( - "ObjectPath is empty!"); - - try { - uri = URI.parse(pObjectPath); - } catch (IllegalArgumentException asURI) { - try { - uri = URI.parseRef(new URIString(pObjectPath), false); - } catch (IllegalArgumentException asUntypedRef) { - try { - uri = URI.parseRef(new URIString(pObjectPath), true); - } catch (IllegalArgumentException asTypedRef) { - String msg = "Parsing of ObjectPath string has failed!\n" - + "Nested error messages:\n" + "When parsing as normal URI string:\n" - + asURI.getMessage() + "When parsing as untyped reference:\n" - + asUntypedRef.getMessage() + "When parsing as typed reference:\n" - + asTypedRef.getMessage(); - // TODO: tracing - throw new IllegalArgumentException(msg); - } - } - } - setURI(uri); - } - - /** - * Constructs a CIM Object Path referencing an instance of the specified CIM - * element as defined in the specified namespace on the specified host and - * identified by the given key properties and their corresponding values. - * Note that the connection mechanism and the port number to which a client - * connection is established are also specified.
      - *
      - * NOTE: When using this API against OpenPegasus CIMOM, do not provide the - * preceding '/' in the namespace parameter. For example, OpenPegasus will - * accept "root/cimv2" as a namespace but will not accept - * "/root/cimv2". - * - * @param pScheme - * The connection scheme to the host (e.g. http, https, ...) - * @param pHost - * The host name or IP Address. - * @param pPort - * The port on the host to which the connection was established. - * @param pNamespace - * The namepace in which the CIM element is defined. - * @param pObjectName - * The name of the CIM element referenced. - * @param pKeys - * The keys and their corresponding values that identify an - * instance of the CIM element. - */ - public CIMObjectPath(String pScheme, String pHost, String pPort, String pNamespace, - String pObjectName, CIMProperty[] pKeys) { - this.iScheme = pScheme; - this.iHost = pHost; - this.iPort = pPort; - this.iNamespace = pNamespace; - this.iObjectName = pObjectName; - if (pKeys != null) { - for (int i = 0; i < pKeys.length; i++) - if (!pKeys[i].isKey()) throw new IllegalArgumentException( - "All CIMObjectPath properties must be keys!"); - } - this.iKeys = (CIMProperty[]) CIMElementSorter.sort(pKeys); - } - - /** - * Constructs a CIM Object Path referencing an instance of the specified CIM - * element as defined in the specified namespace on the specified host and - * identified by the given key properties and their corresponding values. - * Note that the connection mechanism and the port number to which a client - * connection is established are also specified.
      - *
      - * NOTE: When using this API against OpenPegasus CIMOM, do not provide the - * preceding '/' in the namespace parameter. For example, OpenPegasus will - * accept "root/cimv2" as a namespace but will not accept - * "/root/cimv2". - * - * @param pScheme - * The connection scheme to the host (e.g. http, https, ...) - * @param pHost - * The host name or IP Address. - * @param pPort - * The port on the host to which the connection was established. - * @param pNamespace - * The namepace in which the CIM element is defined. - * @param pObjectName - * The name of the CIM element referenced. - * @param pKeys - * The keys and their corresponding values that identify an - * instance of the CIM element. - * @param pXmlSchemaName - * The name of the XML Schema for this object. This is only - * needed for protocols that require this information. - */ - public CIMObjectPath(String pScheme, String pHost, String pPort, String pNamespace, - String pObjectName, CIMProperty[] pKeys, String pXmlSchemaName) { - this(pScheme, pHost, pPort, pNamespace, pObjectName, pKeys); - if (pXmlSchemaName != null) { - try { - new URL(pXmlSchemaName); - } catch (MalformedURLException e) { - throw new IllegalArgumentException(e); - } - } - this.iXmlSchemaName = pXmlSchemaName; - } - - /** - * Compares this CIM object path with the specified CIM object path for - * equality. - * - * @param pObj - * The object to compare to this CIM object path. Only the model - * paths are compared. - * @return true if the specified path references the same - * object, otherwise false is returned. - */ - @Override - public boolean equals(Object pObj) { - return equalsWorker(pObj, true); - } - - private boolean equalsWorker(Object pObj, boolean pIncludeNamespacePath) { - if (!(pObj instanceof CIMObjectPath)) return false; - CIMObjectPath that = (CIMObjectPath) pObj; - // hostname information is not any longer part of the comparison, since - // there is no reliable way to attach hostnames - if (pIncludeNamespacePath) { - boolean namespaceEqual = (this.iNamespace == null ? that.iNamespace == null - : this.iNamespace.equalsIgnoreCase(that.iNamespace)); - if (!namespaceEqual) return false; - } - return (this.iObjectName == null ? that.iObjectName == null : this.iObjectName - .equalsIgnoreCase(that.iObjectName)) - && keysEqual(that); - } - - /** - * Compares this CIM object path's keys with the specified CIM object path's - * keys for equality.
      - *
      - * NOTE: CIMProperty.equals() shouldn't be used for keys, - * because the XML doesn't contain originClass and propagated information. - * - * @param pThat - * The object path whose keys are to be compared to this CIM - * object path's keys. - * @return true if the keys are the same, otherwise - * false is returned. - */ - private boolean keysEqual(CIMObjectPath pThat) { - if (pThat == this) return true; - if (this.iKeys == null) return pThat.iKeys == null; - if (pThat.iKeys == null) return false; - if (this.iKeys.length != pThat.iKeys.length) return false; - for (int i = 0; i < this.iKeys.length; i++) { - CIMProperty thisKey = this.iKeys[i], thatKey = pThat.iKeys[i]; - if (!equals(thisKey, thatKey)) { return false; } - } - return true; - } - - /** - * Compares two properties for equality. - * - * @param pThis - * First property. - * @param pThat - * Second property. - * @return true if the properties are equal, false - * otherwise. - */ - private boolean equals(CIMProperty pThis, CIMProperty pThat) { - if (pThis.getDataType() != null && pThis.getDataType().isArray()) { return ncEqualsIC(pThis - .getName(), pThat.getName()) - && ncEquals(pThis.getDataType(), pThat.getDataType()) - && Arrays.equals((Object[]) pThis.getValue(), (Object[]) pThat.getValue()); - - } - return ncEqualsIC(pThis.getName(), pThat.getName()) - && ncEquals(pThis.getDataType(), pThat.getDataType()) - && ncEquals(pThis.getValue(), pThat.getValue()); - } - - /** - * Compares two objects for equality. - * - * @param pThis - * First object. - * @param pThat - * Second object. - * @return true if the objects are equal, false - * otherwise. - */ - private boolean ncEquals(Object pThis, Object pThat) { - return pThis == null ? pThat == null : pThis.equals(pThat); - } - - /** - * Compares two strings for equality, ignoring case. - * - * @param pThis - * First string. - * @param pThat - * Second string. - * @return true if the strings are equal, false - * otherwise. - */ - private boolean ncEqualsIC(String pThis, String pThat) { - return pThis == null ? pThat == null : pThis.equalsIgnoreCase(pThat); - } - - /** - * Compares this model path with the specified model path for equality. If - * the model path includes references, then the references will also be - * compared for the model path (i.e. the namespace part of the object path - * will be ignored). - * - * @param pModelPath - * The object to compare. - * @return true if the specified path references the same - * object, otherwise false. - */ - public boolean equalsModelPath(CIMObjectPath pModelPath) { - return equalsWorker(pModelPath, false); - } - - /** - * Gets the host. - * - * @return The name of the host. - */ - public String getHost() { - return this.iHost; - } - - /** - * Gets a key property by name. - * - * @param pName - * The name of the key property to retrieve. - * @return The CIMProperty with the given name, or - * null if it is not found. - */ - public CIMProperty getKey(String pName) { - return (CIMProperty) CIMElementSorter.find(this.iKeys, pName); - } - - /** - * Gets all key properties. - * - * @return The container of key properties. - */ - public CIMProperty[] getKeys() { - return this.iKeys == null ? new CIMProperty[0] : this.iKeys; - } - - /** - * @param pName - * The name of the key property to retrieve. - * @return The value of the key property. - */ - public Object getKeyValue(String pName) { - CIMProperty prop = getKey(pName); - return prop == null ? prop : prop.getValue(); - } - - /** - * Gets the namespace. - * - * @return The name of the namespace. - */ - public String getNamespace() { - return this.iNamespace; - } - - /** - * Gets the object name. Depending on the type of CIM element referenced, - * this may be either a class name or a qualifier type name. - * - * @return The name of this CIM element. - */ - public String getObjectName() { - return this.iObjectName; - } - - /** - * Gets the the port on the host to which the connection was established. - * - * @return The port on the host. - */ - public String getPort() { - return this.iPort; - } - - /** - * Get the connection scheme. - * - * @return The connection scheme (e.g. http, https,...) - */ - public String getScheme() { - return this.iScheme; - } - - /** - * Get the XML Schema for this object (optional). - * - * @return The XML Schema name. - */ - public String getXmlSchemaName() { - return this.iXmlSchemaName; - } - - /** - * Computes the hash code for this object path. - * - * @return The integer representing the hash code for this object path. - */ - @Override - public int hashCode() { - return toString().hashCode(); - } - - /** - * Returns a String representation of the CIM object path. This - * method is intended to be used only for debugging purposes. The format of - * the value returned may vary between implementations. The string returned - * may be empty but may not be null. - * - * @return A string representation of this CIM object path. - */ - @Override - public String toString() { - return MOF.objectHandle(this, false, false); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant + * 1669961 2006-04-16 lupusalex CIMTypedElement.getType() =>getDataType() + * 1716991 2006-05-11 lupusalex FVT: CIMObjectPath.equals() should ignore host name + * 1737141 2007-06-18 ebak Sync up with JSR48 evolution + * 1917321 2008-05-29 rgummada javadoc update to constructors with 2 and more parms + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2845128 2009-09-24 blaschke-oss CIMObjectPath.toString() misses host + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + * 2944824 2010-02-08 blaschke-oss Missing getXmlSchemaName() in CIMObjectPath + * 2975975 2010-03-24 blaschke-oss TCK: CIMObjectPath(String) does not handle null + * 3023141 2010-07-01 blaschke-oss CIMObjectPath uses # constructor instead of valueOf + * 3496349 2012-03-02 blaschke-oss JSR48 1.0.0: add CIMObjectPath getKeyValue + * 3510090 2012-03-23 blaschke-oss Fix CIMObjectPath.toString() inconsistencies + * 3513343 2012-03-31 blaschke-oss TCK: CIMObjectPath must validate XML schema name + * 3513347 2012-03-31 blaschke-oss TCK: CIMObjectPath allows empty string + * 3521131 2012-04-24 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final II + * 3521119 2012-04-24 blaschke-oss JSR48 1.0.0: remove CIMObjectPath 2/3/4-parm ctors + * 3529151 2012-08-22 blaschke-oss TCK: CIMInstance property APIs include keys from COP + * 2660 2013-09-04 blaschke-oss CIMObjectPath.equalsModelPath same as equals + * 2716 2013-12-11 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.Serializable; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Arrays; +import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMElementSorter; +import org.metricshub.wbem.sblim.cimclient.internal.uri.BooleanValue; +import org.metricshub.wbem.sblim.cimclient.internal.uri.CharValue; +import org.metricshub.wbem.sblim.cimclient.internal.uri.DateTimeValue; +import org.metricshub.wbem.sblim.cimclient.internal.uri.IntegerValue; +import org.metricshub.wbem.sblim.cimclient.internal.uri.KeyValuePair; +import org.metricshub.wbem.sblim.cimclient.internal.uri.KeyValuePairs; +import org.metricshub.wbem.sblim.cimclient.internal.uri.RealValue; +import org.metricshub.wbem.sblim.cimclient.internal.uri.ReferenceValue; +import org.metricshub.wbem.sblim.cimclient.internal.uri.StringValue; +import org.metricshub.wbem.sblim.cimclient.internal.uri.URI; +import org.metricshub.wbem.sblim.cimclient.internal.uri.URIString; +import org.metricshub.wbem.sblim.cimclient.internal.uri.Value; +import org.metricshub.wbem.sblim.cimclient.internal.util.MOF; + +//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013 +/** + * This class represents the CIM Object Path as defined by the Distributed + * Management Task Force (DMTF) CIM + * Infrastructure Specification (DSP004). In order to uniquely identify a given object, a CIM object path + * includes the host, namespace, object name and keys (if the object is an + * instance).
      + *
      + * For example, the object path:
      + *
      + * + * http://myserver/root/cimv2:My_ComputerSystem.Name=mycomputer, + * CreationClassName=My_ComputerSystem + *
      + *
      + * has two parts:
      + *
      + *
      • Namespace Path
      • + *
      • + * http://myserver/root/cimv2 + * JSR48 defines the namespace path to include the scheme, host, port (optional) + * and namespace + * The example specifies the "root/cimv2" namespace on the host + * myserver.
      • Model Path
      • + *
      • My_ComputerSystem.Name=mycomputer,CreationClassName=My_ComputerSystem + *
        + * DSP0004 defines the model path for a class or qualifier type as the name of + * the class/qualifier type
        + * DSP0004 defines the model path for an instance as the class + * name.(key=value),*
        + * The example specifies an instance for the class + * My_ComputerSystem which is uniquely identified by two key + * properties and values:
      • Name=mycomputer
      • + *
      • + * CreationClassName=My_ComputerSystem
      + */ +public class CIMObjectPath implements Serializable { + private static final long serialVersionUID = 4593259690658425064L; + + private String iScheme, iHost, iPort, iNamespace, iObjectName, iXmlSchemaName; + + private CIMProperty[] iKeys; + + /** + * Class TypeValuePair represents a type-value pair with special + * identification functionality for integer and real numbers. + * + */ + private static class TypeValuePair { + private CIMDataType iType; + + private Object iValue; + + /** + * Constructs a type-value pair with the specified type and value. + * + * @param pType + * Type. + * @param pValue + * Value. + */ + public TypeValuePair(CIMDataType pType, Object pValue) { + this.iType = pType; + this.iValue = pValue; + } + + /** + * Constructs a type-value pair with the specified integer value. + * + * @param intVal + * Integer value. + */ + public TypeValuePair(IntegerValue intVal) { + if (intVal.isSigned()) { + switch (intVal.getBitWidth()) { + case 8: + this.iType = CIMDataType.SINT8_T; + this.iValue = Byte.valueOf(intVal.byteValue()); + break; + case 16: + this.iType = CIMDataType.SINT16_T; + this.iValue = Short.valueOf(intVal.shortValue()); + break; + case 32: + this.iType = CIMDataType.SINT32_T; + this.iValue = Integer.valueOf(intVal.intValue()); + break; + default: + this.iType = CIMDataType.SINT64_T; + this.iValue = Long.valueOf(intVal.longValue()); + } + } else { // unsigned integers + switch (intVal.getBitWidth()) { + case 8: + this.iType = CIMDataType.UINT8_T; + this.iValue = new UnsignedInteger8(intVal.shortValue()); + break; + case 16: + this.iType = CIMDataType.UINT16_T; + this.iValue = new UnsignedInteger16(intVal.intValue()); + break; + case 32: + this.iType = CIMDataType.UINT32_T; + this.iValue = new UnsignedInteger32(intVal.longValue()); + break; + default: + this.iType = CIMDataType.UINT64_T; + this.iValue = new UnsignedInteger64(intVal.bigIntValue()); + } + } + } + + /** + * Constructs a type-value pair with the specified real value. + * + * @param pRealVal + * Real value. + */ + public TypeValuePair(RealValue pRealVal) { + // TODO: handle precision + if (pRealVal.isDouble()) { + this.iType = CIMDataType.REAL64_T; + this.iValue = new Double(pRealVal.doubleValue()); + } else { + this.iType = CIMDataType.REAL32_T; + this.iValue = new Float(pRealVal.floatValue()); + } + } + + /** + * Returns the type of the type-value pair. + * + * @return Type of type-value pair. + */ + public CIMDataType getType() { + return this.iType; + } + + /** + * Returns the value of the type-value pair. + * + * @return Value of type-value pair. + */ + public Object getValue() { + return this.iValue; + } + } + + /** + * Extracts and returns sorted list of key-value pairs from the URI. + * + * @param pURI + * The Uniform Resource Identifier. + * @return Sorted array of keys in URI. + */ + private CIMProperty[] getKeysFromURI(URI pURI) { + KeyValuePairs pairs = pURI.getKeyValuePairs(); + if (pairs == null) return null; + CIMProperty[] keys = new CIMProperty[pairs.size()]; + for (int i = 0; i < pairs.size(); i++) { + KeyValuePair pair = (KeyValuePair) pairs.elementAt(i); + String name = pair.getKey(); + Value uriVal = pair.getValue(); + TypeValuePair typeValue; + if (uriVal instanceof StringValue) { + typeValue = new TypeValuePair(CIMDataType.STRING_T, uriVal.toString()); + } else if (uriVal instanceof ReferenceValue) { + ReferenceValue refVal = (ReferenceValue) uriVal; + CIMObjectPath op = new CIMObjectPath(refVal.getRef()); + typeValue = new TypeValuePair(new CIMDataType(op.getObjectName()), op); + } else if (uriVal instanceof BooleanValue) { + typeValue = new TypeValuePair(CIMDataType.BOOLEAN_T, ((BooleanValue) uriVal).getBoolean()); + } else if (uriVal instanceof CharValue) { + typeValue = new TypeValuePair(CIMDataType.CHAR16_T, ((CharValue) uriVal).getCharacter()); + } else if (uriVal instanceof IntegerValue) { + typeValue = new TypeValuePair((IntegerValue) uriVal); + } else if (uriVal instanceof RealValue) { + typeValue = new TypeValuePair((RealValue) uriVal); + } else if (uriVal instanceof DateTimeValue) { + typeValue = new TypeValuePair(CIMDataType.DATETIME_T, ((DateTimeValue) uriVal).getDateTime()); + } else { + // TODO: error or warning tracing + typeValue = new TypeValuePair(CIMDataType.INVALID_T, null); + } + keys[i] = new CIMProperty(name, typeValue.getType(), typeValue.getValue(), true, false, null); + } + return (CIMProperty[]) CIMElementSorter.sort(keys); + } + + /** + * Initializes the elements of the CIMObjectPath from the given + * URI. + * + * @param pURI + * The Uniform Resource Identifier. + */ + private void setURI(URI pURI) { + this.iNamespace = pURI.getNamespaceName(); + this.iScheme = pURI.getNamespaceType(); + this.iHost = pURI.getHost(); + this.iPort = pURI.getPort(); + this.iObjectName = pURI.getClassName(); + this.iKeys = getKeysFromURI(pURI); + } + + /** + * Constructs a CIM Object Path referencing an instance of the specified CIM + * element in the given URI. + * + * @param pURI + * The Uniform Resource Identifier. + */ + private CIMObjectPath(URI pURI) { + setURI(pURI); + } + + /** + * Constructs a CIM Object Path referencing a CIM element. The name can + * refer to a class name or a qualifier type name, depending on the + * particular CIM element identified. In order to refer to an instance, the + * key properties and their corresponding values must be set.
      + *
      + * Should be able to handle strings, like:
      + * + * http://myserver.org:5066/root/cimv2:My_ComputerSystem.Name="mycmp",CreationClassName="My_ComputerSystem" + *
      + * http://myserver.org/root/cimv2:My_ComputerSystem.Name="mycmp",CreationClassName="My_ComputerSystem" + *
      + * //myserver.org/root/cimv2:My_ComputerSystem
      + * /root/cimv2:My_ComputerSystem + *
      + * + * @param pObjectPath + * The string representation of an object path for a CIM element + * that will be parsed and used to initialize the object. + * @throws IllegalArgumentException + * If the pObjectPath is null or an + * empty string. + */ + public CIMObjectPath(String pObjectPath) { + URI uri; + + if (pObjectPath == null) throw new IllegalArgumentException("ObjectPath is null!"); + if (pObjectPath.trim().length() == 0) throw new IllegalArgumentException("ObjectPath is empty!"); + + try { + uri = URI.parse(pObjectPath); + } catch (IllegalArgumentException asURI) { + try { + uri = URI.parseRef(new URIString(pObjectPath), false); + } catch (IllegalArgumentException asUntypedRef) { + try { + uri = URI.parseRef(new URIString(pObjectPath), true); + } catch (IllegalArgumentException asTypedRef) { + String msg = + "Parsing of ObjectPath string has failed!\n" + + "Nested error messages:\n" + + "When parsing as normal URI string:\n" + + asURI.getMessage() + + "When parsing as untyped reference:\n" + + asUntypedRef.getMessage() + + "When parsing as typed reference:\n" + + asTypedRef.getMessage(); + // TODO: tracing + throw new IllegalArgumentException(msg); + } + } + } + setURI(uri); + } + + /** + * Constructs a CIM Object Path referencing an instance of the specified CIM + * element as defined in the specified namespace on the specified host and + * identified by the given key properties and their corresponding values. + * Note that the connection mechanism and the port number to which a client + * connection is established are also specified.
      + *
      + * NOTE: When using this API against OpenPegasus CIMOM, do not provide the + * preceding '/' in the namespace parameter. For example, OpenPegasus will + * accept "root/cimv2" as a namespace but will not accept + * "/root/cimv2". + * + * @param pScheme + * The connection scheme to the host (e.g. http, https, ...) + * @param pHost + * The host name or IP Address. + * @param pPort + * The port on the host to which the connection was established. + * @param pNamespace + * The namepace in which the CIM element is defined. + * @param pObjectName + * The name of the CIM element referenced. + * @param pKeys + * The keys and their corresponding values that identify an + * instance of the CIM element. + */ + public CIMObjectPath( + String pScheme, + String pHost, + String pPort, + String pNamespace, + String pObjectName, + CIMProperty[] pKeys + ) { + this.iScheme = pScheme; + this.iHost = pHost; + this.iPort = pPort; + this.iNamespace = pNamespace; + this.iObjectName = pObjectName; + if (pKeys != null) { + for (int i = 0; i < pKeys.length; i++) if (!pKeys[i].isKey()) throw new IllegalArgumentException( + "All CIMObjectPath properties must be keys!" + ); + } + this.iKeys = (CIMProperty[]) CIMElementSorter.sort(pKeys); + } + + /** + * Constructs a CIM Object Path referencing an instance of the specified CIM + * element as defined in the specified namespace on the specified host and + * identified by the given key properties and their corresponding values. + * Note that the connection mechanism and the port number to which a client + * connection is established are also specified.
      + *
      + * NOTE: When using this API against OpenPegasus CIMOM, do not provide the + * preceding '/' in the namespace parameter. For example, OpenPegasus will + * accept "root/cimv2" as a namespace but will not accept + * "/root/cimv2". + * + * @param pScheme + * The connection scheme to the host (e.g. http, https, ...) + * @param pHost + * The host name or IP Address. + * @param pPort + * The port on the host to which the connection was established. + * @param pNamespace + * The namepace in which the CIM element is defined. + * @param pObjectName + * The name of the CIM element referenced. + * @param pKeys + * The keys and their corresponding values that identify an + * instance of the CIM element. + * @param pXmlSchemaName + * The name of the XML Schema for this object. This is only + * needed for protocols that require this information. + */ + public CIMObjectPath( + String pScheme, + String pHost, + String pPort, + String pNamespace, + String pObjectName, + CIMProperty[] pKeys, + String pXmlSchemaName + ) { + this(pScheme, pHost, pPort, pNamespace, pObjectName, pKeys); + if (pXmlSchemaName != null) { + try { + new URL(pXmlSchemaName); + } catch (MalformedURLException e) { + throw new IllegalArgumentException(e); + } + } + this.iXmlSchemaName = pXmlSchemaName; + } + + /** + * Compares this CIM object path with the specified CIM object path for + * equality. + * + * @param pObj + * The object to compare to this CIM object path. Only the model + * paths are compared. + * @return true if the specified path references the same + * object, otherwise false is returned. + */ + @Override + public boolean equals(Object pObj) { + return equalsWorker(pObj, true); + } + + private boolean equalsWorker(Object pObj, boolean pIncludeNamespacePath) { + if (!(pObj instanceof CIMObjectPath)) return false; + CIMObjectPath that = (CIMObjectPath) pObj; + // hostname information is not any longer part of the comparison, since + // there is no reliable way to attach hostnames + if (pIncludeNamespacePath) { + boolean namespaceEqual = + (this.iNamespace == null ? that.iNamespace == null : this.iNamespace.equalsIgnoreCase(that.iNamespace)); + if (!namespaceEqual) return false; + } + return ( + (this.iObjectName == null ? that.iObjectName == null : this.iObjectName.equalsIgnoreCase(that.iObjectName)) && + keysEqual(that) + ); + } + + /** + * Compares this CIM object path's keys with the specified CIM object path's + * keys for equality.
      + *
      + * NOTE: CIMProperty.equals() shouldn't be used for keys, + * because the XML doesn't contain originClass and propagated information. + * + * @param pThat + * The object path whose keys are to be compared to this CIM + * object path's keys. + * @return true if the keys are the same, otherwise + * false is returned. + */ + private boolean keysEqual(CIMObjectPath pThat) { + if (pThat == this) return true; + if (this.iKeys == null) return pThat.iKeys == null; + if (pThat.iKeys == null) return false; + if (this.iKeys.length != pThat.iKeys.length) return false; + for (int i = 0; i < this.iKeys.length; i++) { + CIMProperty thisKey = this.iKeys[i], thatKey = pThat.iKeys[i]; + if (!equals(thisKey, thatKey)) { + return false; + } + } + return true; + } + + /** + * Compares two properties for equality. + * + * @param pThis + * First property. + * @param pThat + * Second property. + * @return true if the properties are equal, false + * otherwise. + */ + private boolean equals(CIMProperty pThis, CIMProperty pThat) { + if (pThis.getDataType() != null && pThis.getDataType().isArray()) { + return ( + ncEqualsIC(pThis.getName(), pThat.getName()) && + ncEquals(pThis.getDataType(), pThat.getDataType()) && + Arrays.equals((Object[]) pThis.getValue(), (Object[]) pThat.getValue()) + ); + } + return ( + ncEqualsIC(pThis.getName(), pThat.getName()) && + ncEquals(pThis.getDataType(), pThat.getDataType()) && + ncEquals(pThis.getValue(), pThat.getValue()) + ); + } + + /** + * Compares two objects for equality. + * + * @param pThis + * First object. + * @param pThat + * Second object. + * @return true if the objects are equal, false + * otherwise. + */ + private boolean ncEquals(Object pThis, Object pThat) { + return pThis == null ? pThat == null : pThis.equals(pThat); + } + + /** + * Compares two strings for equality, ignoring case. + * + * @param pThis + * First string. + * @param pThat + * Second string. + * @return true if the strings are equal, false + * otherwise. + */ + private boolean ncEqualsIC(String pThis, String pThat) { + return pThis == null ? pThat == null : pThis.equalsIgnoreCase(pThat); + } + + /** + * Compares this model path with the specified model path for equality. If + * the model path includes references, then the references will also be + * compared for the model path (i.e. the namespace part of the object path + * will be ignored). + * + * @param pModelPath + * The object to compare. + * @return true if the specified path references the same + * object, otherwise false. + */ + public boolean equalsModelPath(CIMObjectPath pModelPath) { + return equalsWorker(pModelPath, false); + } + + /** + * Gets the host. + * + * @return The name of the host. + */ + public String getHost() { + return this.iHost; + } + + /** + * Gets a key property by name. + * + * @param pName + * The name of the key property to retrieve. + * @return The CIMProperty with the given name, or + * null if it is not found. + */ + public CIMProperty getKey(String pName) { + return (CIMProperty) CIMElementSorter.find(this.iKeys, pName); + } + + /** + * Gets all key properties. + * + * @return The container of key properties. + */ + public CIMProperty[] getKeys() { + return this.iKeys == null ? new CIMProperty[0] : this.iKeys; + } + + /** + * @param pName + * The name of the key property to retrieve. + * @return The value of the key property. + */ + public Object getKeyValue(String pName) { + CIMProperty prop = getKey(pName); + return prop == null ? prop : prop.getValue(); + } + + /** + * Gets the namespace. + * + * @return The name of the namespace. + */ + public String getNamespace() { + return this.iNamespace; + } + + /** + * Gets the object name. Depending on the type of CIM element referenced, + * this may be either a class name or a qualifier type name. + * + * @return The name of this CIM element. + */ + public String getObjectName() { + return this.iObjectName; + } + + /** + * Gets the the port on the host to which the connection was established. + * + * @return The port on the host. + */ + public String getPort() { + return this.iPort; + } + + /** + * Get the connection scheme. + * + * @return The connection scheme (e.g. http, https,...) + */ + public String getScheme() { + return this.iScheme; + } + + /** + * Get the XML Schema for this object (optional). + * + * @return The XML Schema name. + */ + public String getXmlSchemaName() { + return this.iXmlSchemaName; + } + + /** + * Computes the hash code for this object path. + * + * @return The integer representing the hash code for this object path. + */ + @Override + public int hashCode() { + return toString().hashCode(); + } + + /** + * Returns a String representation of the CIM object path. This + * method is intended to be used only for debugging purposes. The format of + * the value returned may vary between implementations. The string returned + * may be empty but may not be null. + * + * @return A string representation of this CIM object path. + */ + @Override + public String toString() { + return MOF.objectHandle(this, false, false); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMParameter.java b/src/main/java/org/metricshub/wbem/javax/cim/CIMParameter.java similarity index 84% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/CIMParameter.java rename to src/main/java/org/metricshub/wbem/javax/cim/CIMParameter.java index eac1e7d..9ec83a0 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMParameter.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/CIMParameter.java @@ -1,231 +1,230 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant - * 1660756 2007-02-22 ebak Embedded object support - * 1737141 2007-06-19 ebak Sync up with JSR48 evolution - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - * 2944842 2010-02-08 blaschke-oss Missing thrown ArrayIndexOutOfBoundsException - * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues - * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.CIMQualifiedElementInterfaceImpl; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.MOF; - -//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 -/** - * This class represents a CIM Parameter. A CIM Parameter is a schema item, thus - * it can only be part of a CIMMethod definition for a - * CIMClass. A parameter can be used to define an input, output or - * input/output parameter. A CIMParameter consists of a name, data - * type and qualifiers. CIMParameters do not have values - so you - * can not set a default value. CIM Parameters are defined by the Distributed - * Management Task Force (DMTF) CIM - * Infrastructure Specification (DSP004). To invoke a method, you would use CIMArgument. - * - * @param - * Type parameter. - * - * @see CIMMethod - */ -public class CIMParameter extends CIMTypedElement implements CIMQualifiedElementInterface { - - private static final long serialVersionUID = -4741931597423829396L; - - private CIMQualifiedElementInterfaceImpl iQualiImpl; - - /** - * Constructs a CIMParameter object using the specified name, - * data type and qualifiers. Takes a string for the name of an existing CIM - * parameter and creates a new instance of a CIM parameter, using the name - * and identifier of the existing CIM parameter. - * - * @param pName - * Name of this parameter. - * @param pType - * Data type of this parameter. - * @param pQualifiers - * Qualifiers for this parameter. - */ - public CIMParameter(String pName, CIMDataType pType, CIMQualifier[] pQualifiers) { - super(pName, pType); - this.iQualiImpl = new CIMQualifiedElementInterfaceImpl(pQualifiers, false, true); - } - - /** - * Compares this object against the specified object. The result is - * true if and only if the argument is not null - * and is a CIMParameter object that represents the same value - * as this object. - * - * @param pObj - * The object to compare. - * @return true if the objects are the same; false - * otherwise. - */ - @Override - public boolean equals(Object pObj) { - if (!(pObj instanceof CIMParameter)) return false; - if (!super.equals(pObj)) return false; - CIMParameter that = (CIMParameter) pObj; - return this.iQualiImpl.equals(that.iQualiImpl); - } - - /** - * Returns a CIMParameter filtered as specified. - * - * @param pIncludeQualifiers - * If true all qualifiers are returned; otherwise no - * qualifiers. - * @param pLocalOnly - * If true only the qualifiers that were not - * propagated will be included. - * @return A filtered CIMParameter. - */ - public CIMParameter filter(boolean pIncludeQualifiers, boolean pLocalOnly) { - return new CIMParameter(getName(), getDataType(), pIncludeQualifiers ? this.iQualiImpl - .getQualifiers(pLocalOnly) : null); - } - - /** - * Get a qualifier by index. - * - * @param pIndex - * The index of the qualifier. - * @return The Qualifier at index pIndex. - * @throws ArrayIndexOutOfBoundsException - */ - public CIMQualifier getQualifier(int pIndex) throws ArrayIndexOutOfBoundsException { - return this.iQualiImpl.getQualifier(pIndex); - } - - /** - * Gets a qualifier by name. - * - * @param pName - * The name of the qualifier to get. - * @return null if the qualifier does not exist, otherwise - * returns the reference to the qualifier. - */ - public CIMQualifier getQualifier(String pName) { - return this.iQualiImpl.getQualifier(pName); - } - - /** - * Get the number of qualifiers defined for this CIM Parameter. - * - * @return The number of qualifiers. - */ - public int getQualifierCount() { - return this.iQualiImpl.getQualifierCount(); - } - - /** - * Returns the list of qualifiers for this class. - * - * @return Qualifiers for this class. - */ - public CIMQualifier[] getQualifiers() { - return this.iQualiImpl.getQualifiers(); - } - - /** - * Gets a qualifier value by name. - * - * @param pName - * The name of the qualifier to get. - * @return null if the qualifier does not exist or value is - * null, otherwise returns the reference to the - * qualifier. - */ - public Object getQualifierValue(String pName) { - return this.iQualiImpl.getQualifierValue(pName); - } - - /** - * Checks whether the specified qualifier is one of the qualifiers in this - * CIM element. - * - * @param pName - * The name of the qualifier. - * @return true if the qualifier exists in this CIM parameter, - * otherwise false. - */ - public boolean hasQualifier(String pName) { - return this.iQualiImpl.hasQualifier(pName); - } - - /** - * Checks whether the specified qualifier is one of the qualifiers defined - * for this parameter with the specified value. This method will return - * false if the qualifier is not applied or if the value does - * not match. - * - * @param pName - * The name of the qualifier. - * @param pValue - * The value to be tested. - * @return true if the qualifier exists in this property, - * otherwise false. - */ - public boolean hasQualifierValue(String pName, Object pValue) { - return this.iQualiImpl.hasQualifierValue(pName, pValue); - } - - /** - * Returns a String representation of the - * CIMParameter. This method is intended to be used only for - * debugging purposes, and the format of the returned string may vary - * between implementations. The returned string may be empty but may not be - * null. - * - * @return String representation of this parameter. - */ - @Override - public String toString() { - return MOF.parameter(this, MOF.EMPTY); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant + * 1660756 2007-02-22 ebak Embedded object support + * 1737141 2007-06-19 ebak Sync up with JSR48 evolution + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + * 2944842 2010-02-08 blaschke-oss Missing thrown ArrayIndexOutOfBoundsException + * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues + * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMQualifiedElementInterfaceImpl; +import org.metricshub.wbem.sblim.cimclient.internal.util.MOF; + +//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 +/** + * This class represents a CIM Parameter. A CIM Parameter is a schema item, thus + * it can only be part of a CIMMethod definition for a + * CIMClass. A parameter can be used to define an input, output or + * input/output parameter. A CIMParameter consists of a name, data + * type and qualifiers. CIMParameters do not have values - so you + * can not set a default value. CIM Parameters are defined by the Distributed + * Management Task Force (DMTF) CIM + * Infrastructure Specification (DSP004). To invoke a method, you would use CIMArgument. + * + * @param + * Type parameter. + * + * @see CIMMethod + */ +public class CIMParameter extends CIMTypedElement implements CIMQualifiedElementInterface { + private static final long serialVersionUID = -4741931597423829396L; + + private CIMQualifiedElementInterfaceImpl iQualiImpl; + + /** + * Constructs a CIMParameter object using the specified name, + * data type and qualifiers. Takes a string for the name of an existing CIM + * parameter and creates a new instance of a CIM parameter, using the name + * and identifier of the existing CIM parameter. + * + * @param pName + * Name of this parameter. + * @param pType + * Data type of this parameter. + * @param pQualifiers + * Qualifiers for this parameter. + */ + public CIMParameter(String pName, CIMDataType pType, CIMQualifier[] pQualifiers) { + super(pName, pType); + this.iQualiImpl = new CIMQualifiedElementInterfaceImpl(pQualifiers, false, true); + } + + /** + * Compares this object against the specified object. The result is + * true if and only if the argument is not null + * and is a CIMParameter object that represents the same value + * as this object. + * + * @param pObj + * The object to compare. + * @return true if the objects are the same; false + * otherwise. + */ + @Override + public boolean equals(Object pObj) { + if (!(pObj instanceof CIMParameter)) return false; + if (!super.equals(pObj)) return false; + CIMParameter that = (CIMParameter) pObj; + return this.iQualiImpl.equals(that.iQualiImpl); + } + + /** + * Returns a CIMParameter filtered as specified. + * + * @param pIncludeQualifiers + * If true all qualifiers are returned; otherwise no + * qualifiers. + * @param pLocalOnly + * If true only the qualifiers that were not + * propagated will be included. + * @return A filtered CIMParameter. + */ + public CIMParameter filter(boolean pIncludeQualifiers, boolean pLocalOnly) { + return new CIMParameter( + getName(), + getDataType(), + pIncludeQualifiers ? this.iQualiImpl.getQualifiers(pLocalOnly) : null + ); + } + + /** + * Get a qualifier by index. + * + * @param pIndex + * The index of the qualifier. + * @return The Qualifier at index pIndex. + * @throws ArrayIndexOutOfBoundsException + */ + public CIMQualifier getQualifier(int pIndex) throws ArrayIndexOutOfBoundsException { + return this.iQualiImpl.getQualifier(pIndex); + } + + /** + * Gets a qualifier by name. + * + * @param pName + * The name of the qualifier to get. + * @return null if the qualifier does not exist, otherwise + * returns the reference to the qualifier. + */ + public CIMQualifier getQualifier(String pName) { + return this.iQualiImpl.getQualifier(pName); + } + + /** + * Get the number of qualifiers defined for this CIM Parameter. + * + * @return The number of qualifiers. + */ + public int getQualifierCount() { + return this.iQualiImpl.getQualifierCount(); + } + + /** + * Returns the list of qualifiers for this class. + * + * @return Qualifiers for this class. + */ + public CIMQualifier[] getQualifiers() { + return this.iQualiImpl.getQualifiers(); + } + + /** + * Gets a qualifier value by name. + * + * @param pName + * The name of the qualifier to get. + * @return null if the qualifier does not exist or value is + * null, otherwise returns the reference to the + * qualifier. + */ + public Object getQualifierValue(String pName) { + return this.iQualiImpl.getQualifierValue(pName); + } + + /** + * Checks whether the specified qualifier is one of the qualifiers in this + * CIM element. + * + * @param pName + * The name of the qualifier. + * @return true if the qualifier exists in this CIM parameter, + * otherwise false. + */ + public boolean hasQualifier(String pName) { + return this.iQualiImpl.hasQualifier(pName); + } + + /** + * Checks whether the specified qualifier is one of the qualifiers defined + * for this parameter with the specified value. This method will return + * false if the qualifier is not applied or if the value does + * not match. + * + * @param pName + * The name of the qualifier. + * @param pValue + * The value to be tested. + * @return true if the qualifier exists in this property, + * otherwise false. + */ + public boolean hasQualifierValue(String pName, Object pValue) { + return this.iQualiImpl.hasQualifierValue(pName, pValue); + } + + /** + * Returns a String representation of the + * CIMParameter. This method is intended to be used only for + * debugging purposes, and the format of the returned string may vary + * between implementations. The returned string may be empty but may not be + * null. + * + * @return String representation of this parameter. + */ + @Override + public String toString() { + return MOF.parameter(this, MOF.EMPTY); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMProperty.java b/src/main/java/org/metricshub/wbem/javax/cim/CIMProperty.java similarity index 80% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/CIMProperty.java rename to src/main/java/org/metricshub/wbem/javax/cim/CIMProperty.java index 6a69a50..7f203e8 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMProperty.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/CIMProperty.java @@ -1,169 +1,172 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant - * 1737141 2007-06-18 ebak Sync up with JSR48 evolution - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues - * 3496301 2012-03-02 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final - * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -//Sync'd against JSR48 1.0.0 javadoc (build 1.6.0_18) on Thu Mar 01 12:21:26 EST 2012 -/** - * This class represents a CIM Property as defined by the Distributed Management - * Task Force (DMTF) CIM Infrastructure - * Specification (DSP004). A CIM Property Object consists of a name, data type and value. - * The CIM Property object also includes a flag to signify whether the property - * is a key property (used as part of the name of the CIM element), a flag to - * signify whether it was propagated from a parent class and the class origin - * information (where the property was originally defined). - * - * @param - * Type parameter. - */ -public class CIMProperty extends CIMValuedElement { - - private static final long serialVersionUID = -4741931597423829396L; - - private boolean iKey, iPropagated; - - private String iOriginClass; - - /** - * Constructs a CIMProperty to be used in instances. For a - * CIMClass, CIMClassProperty shall be used. This - * can only be used for non-Key properties, non-propagated properties and - * when the the origin class is not needed. - * - * @param pName - * The name of the property. - * @param pType - * The CIMDataType of the property. - * @param pValue - * The value of the property. - */ - public CIMProperty(String pName, CIMDataType pType, E pValue) { - this(pName, pType, pValue, false, false, null); - } - - /** - * Constructs a CIMProperty to be used in instances. For a - * CIMClass, CIMClassProperty shall be used. - * - * @param pName - * The name of the property. - * @param pType - * The CIMDataType of the property. - * @param pValue - * The value of the property. - * @param pKey - * true if the property is a key; otherwise - * false. - * @param pPropagated - * true if the value was propagated from the class. - * @param pOriginClass - * The class in which this property was defined or overridden. - */ - public CIMProperty(String pName, CIMDataType pType, E pValue, boolean pKey, - boolean pPropagated, String pOriginClass) { - super(pName, pType, pValue); - this.iKey = pKey; - this.iPropagated = pPropagated; - this.iOriginClass = pOriginClass; - } - - /** - * Compares this object against the specified object. The result is - * true if and only if the argument is not null - * and is a CIMProperty that represents the same name, type and - * value as this object. - * - * @param pObj - * The object to compare with. - * @return true if the objects are the same; false - * otherwise. - */ - @Override - public boolean equals(Object pObj) { - if (!(pObj instanceof CIMProperty)) return false; - if (!super.equals(pObj)) return false; - CIMProperty that = (CIMProperty) pObj; - return this.iKey == that.iKey - && this.iPropagated == that.iPropagated - && (this.iOriginClass == null ? that.iOriginClass == null : this.iOriginClass - .equalsIgnoreCase(that.iOriginClass)); - } - - /** - * Returns the class in which this property was defined or overridden. - * - * @return Name of class where this property was defined. - */ - public String getOriginClass() { - return this.iOriginClass; - } - - /** - * Convenience method for determining if this property is a Key. - * - * @return true if this property is a key. - */ - public boolean isKey() { - return this.iKey; - } - - /** - * Determines if this property is Propagated. When this property is part of - * a class, this value designates that the class origin value is the same as - * the class name. - * - * @return true if this property is propagated. - */ - public boolean isPropagated() { - return this.iPropagated; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant + * 1737141 2007-06-18 ebak Sync up with JSR48 evolution + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues + * 3496301 2012-03-02 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final + * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +//Sync'd against JSR48 1.0.0 javadoc (build 1.6.0_18) on Thu Mar 01 12:21:26 EST 2012 +/** + * This class represents a CIM Property as defined by the Distributed Management + * Task Force (DMTF) CIM Infrastructure + * Specification (DSP004). A CIM Property Object consists of a name, data type and value. + * The CIM Property object also includes a flag to signify whether the property + * is a key property (used as part of the name of the CIM element), a flag to + * signify whether it was propagated from a parent class and the class origin + * information (where the property was originally defined). + * + * @param + * Type parameter. + */ +public class CIMProperty extends CIMValuedElement { + private static final long serialVersionUID = -4741931597423829396L; + + private boolean iKey, iPropagated; + + private String iOriginClass; + + /** + * Constructs a CIMProperty to be used in instances. For a + * CIMClass, CIMClassProperty shall be used. This + * can only be used for non-Key properties, non-propagated properties and + * when the the origin class is not needed. + * + * @param pName + * The name of the property. + * @param pType + * The CIMDataType of the property. + * @param pValue + * The value of the property. + */ + public CIMProperty(String pName, CIMDataType pType, E pValue) { + this(pName, pType, pValue, false, false, null); + } + + /** + * Constructs a CIMProperty to be used in instances. For a + * CIMClass, CIMClassProperty shall be used. + * + * @param pName + * The name of the property. + * @param pType + * The CIMDataType of the property. + * @param pValue + * The value of the property. + * @param pKey + * true if the property is a key; otherwise + * false. + * @param pPropagated + * true if the value was propagated from the class. + * @param pOriginClass + * The class in which this property was defined or overridden. + */ + public CIMProperty( + String pName, + CIMDataType pType, + E pValue, + boolean pKey, + boolean pPropagated, + String pOriginClass + ) { + super(pName, pType, pValue); + this.iKey = pKey; + this.iPropagated = pPropagated; + this.iOriginClass = pOriginClass; + } + + /** + * Compares this object against the specified object. The result is + * true if and only if the argument is not null + * and is a CIMProperty that represents the same name, type and + * value as this object. + * + * @param pObj + * The object to compare with. + * @return true if the objects are the same; false + * otherwise. + */ + @Override + public boolean equals(Object pObj) { + if (!(pObj instanceof CIMProperty)) return false; + if (!super.equals(pObj)) return false; + CIMProperty that = (CIMProperty) pObj; + return ( + this.iKey == that.iKey && + this.iPropagated == that.iPropagated && + (this.iOriginClass == null ? that.iOriginClass == null : this.iOriginClass.equalsIgnoreCase(that.iOriginClass)) + ); + } + + /** + * Returns the class in which this property was defined or overridden. + * + * @return Name of class where this property was defined. + */ + public String getOriginClass() { + return this.iOriginClass; + } + + /** + * Convenience method for determining if this property is a Key. + * + * @return true if this property is a key. + */ + public boolean isKey() { + return this.iKey; + } + + /** + * Determines if this property is Propagated. When this property is part of + * a class, this value designates that the class origin value is the same as + * the class name. + * + * @return true if this property is propagated. + */ + public boolean isPropagated() { + return this.iPropagated; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMQualifiedElementInterface.java b/src/main/java/org/metricshub/wbem/javax/cim/CIMQualifiedElementInterface.java similarity index 79% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/CIMQualifiedElementInterface.java rename to src/main/java/org/metricshub/wbem/javax/cim/CIMQualifiedElementInterface.java index cf82a7f..f7f7f76 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMQualifiedElementInterface.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/CIMQualifiedElementInterface.java @@ -1,124 +1,120 @@ -/* - (C) Copyright IBM Corp. 2006, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 -/** - * The CIMQualifiedElementInterface is used by CIM Elements that - * have qualifiers. For example, CIM Classes, CIM Properties, CIM Methods and - * CIM Parameters are all CIM Elements that have qualifiers. - */ -public interface CIMQualifiedElementInterface { - - /** - * Get a qualifier by index. - * - * @param pIndex - * The index of the qualifier. - * @return The Qualifier at index pIndex. - */ - public CIMQualifier getQualifier(int pIndex); - - /** - * Gets a qualifier by name. - * - * @param pName - * The name of the qualifier to get. - * @return null if the qualifier does not exist, otherwise - * returns the reference to the qualifier. - */ - public CIMQualifier getQualifier(String pName); - - /** - * Get the number of qualifiers defined for this CIM Element. - * - * @return The number of qualifiers. - */ - public int getQualifierCount(); - - /** - * Returns the list of qualifiers for this class. - * - * @return Qualifiers for this class. - */ - public CIMQualifier[] getQualifiers(); - - /** - * Gets a qualifier value by name. - * - * @param pName - * The name of the qualifier to get. - * @return null if the qualifier does not exist or value is - * null, otherwise returns the reference to the - * qualifier. - */ - public Object getQualifierValue(String pName); - - /** - * Checks whether the specified qualifier is one of the qualifiers in this - * CIM element. - * - * @param pName - * The name of the qualifier. - * @return true if the qualifier exists in this CIM element, - * otherwise false. - */ - public boolean hasQualifier(String pName); - - /** - * Checks whether the specified qualifier is one of the qualifiers defined - * for this property with the specified value. This method will return - * false if the qualifier is not applied or if the value does - * not match. - * - * @param pName - * The name of the qualifier. - * @param pValue - * The value to be tested. - * @return true if the qualifier exists and has the value, - * otherwise false. - */ - public boolean hasQualifierValue(String pName, Object pValue); - -} +/* + (C) Copyright IBM Corp. 2006, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 +/** + * The CIMQualifiedElementInterface is used by CIM Elements that + * have qualifiers. For example, CIM Classes, CIM Properties, CIM Methods and + * CIM Parameters are all CIM Elements that have qualifiers. + */ +public interface CIMQualifiedElementInterface { + /** + * Get a qualifier by index. + * + * @param pIndex + * The index of the qualifier. + * @return The Qualifier at index pIndex. + */ + public CIMQualifier getQualifier(int pIndex); + + /** + * Gets a qualifier by name. + * + * @param pName + * The name of the qualifier to get. + * @return null if the qualifier does not exist, otherwise + * returns the reference to the qualifier. + */ + public CIMQualifier getQualifier(String pName); + + /** + * Get the number of qualifiers defined for this CIM Element. + * + * @return The number of qualifiers. + */ + public int getQualifierCount(); + + /** + * Returns the list of qualifiers for this class. + * + * @return Qualifiers for this class. + */ + public CIMQualifier[] getQualifiers(); + + /** + * Gets a qualifier value by name. + * + * @param pName + * The name of the qualifier to get. + * @return null if the qualifier does not exist or value is + * null, otherwise returns the reference to the + * qualifier. + */ + public Object getQualifierValue(String pName); + + /** + * Checks whether the specified qualifier is one of the qualifiers in this + * CIM element. + * + * @param pName + * The name of the qualifier. + * @return true if the qualifier exists in this CIM element, + * otherwise false. + */ + public boolean hasQualifier(String pName); + + /** + * Checks whether the specified qualifier is one of the qualifiers defined + * for this property with the specified value. This method will return + * false if the qualifier is not applied or if the value does + * not match. + * + * @param pName + * The name of the qualifier. + * @param pValue + * The value to be tested. + * @return true if the qualifier exists and has the value, + * otherwise false. + */ + public boolean hasQualifierValue(String pName, Object pValue); +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMQualifier.java b/src/main/java/org/metricshub/wbem/javax/cim/CIMQualifier.java similarity index 84% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/CIMQualifier.java rename to src/main/java/org/metricshub/wbem/javax/cim/CIMQualifier.java index c89b9ab..667db18 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMQualifier.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/CIMQualifier.java @@ -1,181 +1,176 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant - * 1737141 2007-06-18 ebak Sync up with JSR48 evolution - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues - * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.MOF; - -//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 -/** - * This class represents a CIM qualifier as defined by the Distributed - * Management Task Force (DMTF) CIM - * Infrastructure Specification (DSP004). A qualifier provides additional information about classes, - * associations, methods, parameters, properties, and/or references. A - * CIMQualifier must have a CIM Qualifier Type. A qualifier and its - * qualifier type must have the same name and data type. CIM Qualifiers can only - * be applied to elements that are allowed by the scope defined by the CIM - * Qualifier Type. - * - * @param - * Type parameter. - * @see CIMQualifierType - */ -public class CIMQualifier extends CIMValuedElement { - - private static final long serialVersionUID = 3568987946093931214L; - - private int iFlavor; - - private boolean iPropagated; - - /** - * Constructs a CIM qualifier with the specified name, type, value, and - * flavors. - * - * @param pName - * The name of the qualifier. - * @param pType - * The data type of the qualifier. - * @param pValue - * The value of the qualifier. - * @param pFlavor - * A list of override permissions. Flavors can be overridden from - * the Qualifier Type definition to either restrict the - * subclassing of a qualifier or to allow it. For the list of CIM - * Flavors see the CIMFlavor class. - * @see CIMFlavor - */ - public CIMQualifier(String pName, CIMDataType pType, E pValue, int pFlavor) { - this(pName, pType, pValue, pFlavor, false); - } - - /** - * Constructs a CIM qualifier with the specified name, type, value, and - * flavors. - * - * @param pName - * The name of the qualifier. - * @param pType - * The data type of the qualifier. - * @param pValue - * The value of the qualifier. - * @param pFlavor - * A list of override permissions. Flavors can be overridden from - * the Qualifier Type definition to either restrict the - * subclassing of a qualifier or to allow it. For the list of CIM - * Flavors see the CIMFlavor class. - * @param pIsPropagated - * true if the qualifier was propagated; - * false otherwise. - * @see CIMFlavor - */ - public CIMQualifier(String pName, CIMDataType pType, E pValue, int pFlavor, - boolean pIsPropagated) { - super(pName, pType, pValue); - this.iFlavor = pFlavor; - this.iPropagated = pIsPropagated; - } - - /** - * Compares this CIMQualifier against the specified - * CIMQualifier. The result is true if and only if - * the argument is not null and is a CIMQualifier - * that represents the same name, type and value as this - * CIMQualifier. - * - * @param pObj - * The object to compare. - * @return true if the input qualifier is equal, otherwise - * false. - */ - @Override - public boolean equals(Object pObj) { - if (!(pObj instanceof CIMQualifier)) return false; - if (!super.equals(pObj)) return false; - CIMQualifier that = (CIMQualifier) pObj; - return this.iFlavor == that.iFlavor && this.iPropagated == that.iPropagated; - } - - /** - * Returns the CIM flavors for this CIM qualifier. - * - * @return A BitSet of CIM flavors in this CIM qualifier. - */ - public int getFlavor() { - return this.iFlavor; - } - - /** - * Determines if this qualifier is propagated. If the qualifier was - * inherited, this value will be true. If the qualifier was - * applied to the element directly, this value will be false. - * - * @return true if this property is propagated; - * false otherwise. - */ - public boolean isPropagated() { - return this.iPropagated; - } - - /** - * Returns a String representation of the - * CIMQualifier. This method is intended to be used only for - * debugging purposes, and the format of the returned string may vary - * between implementations. The returned string may be empty but may not be - * null. - * - * @return A string representation of this qualifier. - */ - @Override - public String toString() { - return MOF.qualifier(this); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant + * 1737141 2007-06-18 ebak Sync up with JSR48 evolution + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues + * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.sblim.cimclient.internal.util.MOF; + +//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 +/** + * This class represents a CIM qualifier as defined by the Distributed + * Management Task Force (DMTF) CIM + * Infrastructure Specification (DSP004). A qualifier provides additional information about classes, + * associations, methods, parameters, properties, and/or references. A + * CIMQualifier must have a CIM Qualifier Type. A qualifier and its + * qualifier type must have the same name and data type. CIM Qualifiers can only + * be applied to elements that are allowed by the scope defined by the CIM + * Qualifier Type. + * + * @param + * Type parameter. + * @see CIMQualifierType + */ +public class CIMQualifier extends CIMValuedElement { + private static final long serialVersionUID = 3568987946093931214L; + + private int iFlavor; + + private boolean iPropagated; + + /** + * Constructs a CIM qualifier with the specified name, type, value, and + * flavors. + * + * @param pName + * The name of the qualifier. + * @param pType + * The data type of the qualifier. + * @param pValue + * The value of the qualifier. + * @param pFlavor + * A list of override permissions. Flavors can be overridden from + * the Qualifier Type definition to either restrict the + * subclassing of a qualifier or to allow it. For the list of CIM + * Flavors see the CIMFlavor class. + * @see CIMFlavor + */ + public CIMQualifier(String pName, CIMDataType pType, E pValue, int pFlavor) { + this(pName, pType, pValue, pFlavor, false); + } + + /** + * Constructs a CIM qualifier with the specified name, type, value, and + * flavors. + * + * @param pName + * The name of the qualifier. + * @param pType + * The data type of the qualifier. + * @param pValue + * The value of the qualifier. + * @param pFlavor + * A list of override permissions. Flavors can be overridden from + * the Qualifier Type definition to either restrict the + * subclassing of a qualifier or to allow it. For the list of CIM + * Flavors see the CIMFlavor class. + * @param pIsPropagated + * true if the qualifier was propagated; + * false otherwise. + * @see CIMFlavor + */ + public CIMQualifier(String pName, CIMDataType pType, E pValue, int pFlavor, boolean pIsPropagated) { + super(pName, pType, pValue); + this.iFlavor = pFlavor; + this.iPropagated = pIsPropagated; + } + + /** + * Compares this CIMQualifier against the specified + * CIMQualifier. The result is true if and only if + * the argument is not null and is a CIMQualifier + * that represents the same name, type and value as this + * CIMQualifier. + * + * @param pObj + * The object to compare. + * @return true if the input qualifier is equal, otherwise + * false. + */ + @Override + public boolean equals(Object pObj) { + if (!(pObj instanceof CIMQualifier)) return false; + if (!super.equals(pObj)) return false; + CIMQualifier that = (CIMQualifier) pObj; + return this.iFlavor == that.iFlavor && this.iPropagated == that.iPropagated; + } + + /** + * Returns the CIM flavors for this CIM qualifier. + * + * @return A BitSet of CIM flavors in this CIM qualifier. + */ + public int getFlavor() { + return this.iFlavor; + } + + /** + * Determines if this qualifier is propagated. If the qualifier was + * inherited, this value will be true. If the qualifier was + * applied to the element directly, this value will be false. + * + * @return true if this property is propagated; + * false otherwise. + */ + public boolean isPropagated() { + return this.iPropagated; + } + + /** + * Returns a String representation of the + * CIMQualifier. This method is intended to be used only for + * debugging purposes, and the format of the returned string may vary + * between implementations. The returned string may be empty but may not be + * null. + * + * @return A string representation of this qualifier. + */ + @Override + public String toString() { + return MOF.qualifier(this); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMQualifierType.java b/src/main/java/org/metricshub/wbem/javax/cim/CIMQualifierType.java similarity index 83% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/CIMQualifierType.java rename to src/main/java/org/metricshub/wbem/javax/cim/CIMQualifierType.java index e215e40..4c0802b 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMQualifierType.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/CIMQualifierType.java @@ -1,174 +1,170 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - * 2975989 2010-03-24 blaschke-oss TCK: CIMQualifierType constructor does not handle null - * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues - * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.MOF; - -//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 -/** - * The CIMQualifierType class represents a CIM Qualifier Type as defined by the - * Distributed Management Task Force (DMTF) CIM - * Infrastructure Specification (DSP004). A Qualifier Type supplies the definition/rules for a qualifier. - * A qualifier must have a qualifier type. CIMQualifierType has the following - * components: - *
        - *
      • Name - The name of the qualifier type.
      • - *
      • Data Type - The data type of the qualifier type.
      • - *
      • Value - The default value of the qualifier type (can be - * null/uninitialized)
      • - *
      • Scopes - The scopes applicable to this qualifier type. In - * other words what CIM Elements can the qualifier based on this type be applied - * to.
      • - *
      • Flavors - The flavors applicable to this qualifier type. - * Flavors describe the propagation and override rules for a qualifier.
      • - *
      - * - * @param - * Type parameter. - * @see CIMScope - * @see CIMFlavor - * @see CIMQualifier - */ -public class CIMQualifierType extends CIMValuedElement implements CIMNamedElementInterface { - - private static final long serialVersionUID = -4563643521754840535L; - - private CIMObjectPath iObjPath; - - private int iScope, iFlavor; - - /** - * Constructs a new CIM qualifier type, using the name, type of the - * specified CIM qualifier type. - * - * @param pPath - * The CIMObjectPath of a CIM qualifier type. - * @param pType - * The CIMDataType of the qualifier type. - * @param pValue - * The default value or null if no default value. - * @param pScope - * The applicable scopes for the qualifier type. - * @param pFlavor - * The applicable flavors for the qualifier type. - * @throws IllegalArgumentException - * If the value/data type does not match. - */ - public CIMQualifierType(CIMObjectPath pPath, CIMDataType pType, E pValue, int pScope, - int pFlavor) throws IllegalArgumentException { - super(pPath == null ? null : pPath.getObjectName(), pType, pValue); - this.iObjPath = pPath; - this.iScope = pScope; - this.iFlavor = pFlavor; - } - - /** - * Compares this object against the specified object. The result is - * true if and only if the argument is not null - * and is a CIMQualifierType object that represents the same - * value as this object. - * - * @param pObj - * The object to compare. - * @return true if the specified object it is the same as this - * CIMQualifierType. Otherwise, false. - */ - @Override - public boolean equals(Object pObj) { - if (!(pObj instanceof CIMQualifierType)) return false; - if (!super.equals(pObj)) return false; - CIMQualifierType that = (CIMQualifierType) pObj; - return this.iObjPath.equals(that.iObjPath) && this.iScope == that.iScope; - } - - /** - * Returns the flavors of this qualifier type as a BitSet. - * - * @return BitSet of flavors for this qualifier type. - */ - public int getFlavor() { - return this.iFlavor; - } - - /** - * Get the object path for this CIMQualifierType. - * - * @return The CIMObjectPath that represents this qualifier - * type. - */ - public CIMObjectPath getObjectPath() { - return this.iObjPath; - } - - /** - * Returns the scopes of this qualifier type as a bit set. - * - * @return Bit set of CIM element scopes for which this qualifier type is - * applicable. - */ - public int getScope() { - return this.iScope; - } - - /** - * Returns a String representation of the - * CIMQualifierType This method is intended to be used only for - * debugging purposes, and the format of the returned string may vary - * between implementations. The returned string may be empty but may not be - * null. - * - * @return A string representation of this qualifier type. - */ - @Override - public String toString() { - return MOF.qualifierDeclaration(this); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + * 2975989 2010-03-24 blaschke-oss TCK: CIMQualifierType constructor does not handle null + * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues + * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.sblim.cimclient.internal.util.MOF; + +//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 +/** + * The CIMQualifierType class represents a CIM Qualifier Type as defined by the + * Distributed Management Task Force (DMTF) CIM + * Infrastructure Specification (DSP004). A Qualifier Type supplies the definition/rules for a qualifier. + * A qualifier must have a qualifier type. CIMQualifierType has the following + * components: + *
        + *
      • Name - The name of the qualifier type.
      • + *
      • Data Type - The data type of the qualifier type.
      • + *
      • Value - The default value of the qualifier type (can be + * null/uninitialized)
      • + *
      • Scopes - The scopes applicable to this qualifier type. In + * other words what CIM Elements can the qualifier based on this type be applied + * to.
      • + *
      • Flavors - The flavors applicable to this qualifier type. + * Flavors describe the propagation and override rules for a qualifier.
      • + *
      + * + * @param + * Type parameter. + * @see CIMScope + * @see CIMFlavor + * @see CIMQualifier + */ +public class CIMQualifierType extends CIMValuedElement implements CIMNamedElementInterface { + private static final long serialVersionUID = -4563643521754840535L; + + private CIMObjectPath iObjPath; + + private int iScope, iFlavor; + + /** + * Constructs a new CIM qualifier type, using the name, type of the + * specified CIM qualifier type. + * + * @param pPath + * The CIMObjectPath of a CIM qualifier type. + * @param pType + * The CIMDataType of the qualifier type. + * @param pValue + * The default value or null if no default value. + * @param pScope + * The applicable scopes for the qualifier type. + * @param pFlavor + * The applicable flavors for the qualifier type. + * @throws IllegalArgumentException + * If the value/data type does not match. + */ + public CIMQualifierType(CIMObjectPath pPath, CIMDataType pType, E pValue, int pScope, int pFlavor) + throws IllegalArgumentException { + super(pPath == null ? null : pPath.getObjectName(), pType, pValue); + this.iObjPath = pPath; + this.iScope = pScope; + this.iFlavor = pFlavor; + } + + /** + * Compares this object against the specified object. The result is + * true if and only if the argument is not null + * and is a CIMQualifierType object that represents the same + * value as this object. + * + * @param pObj + * The object to compare. + * @return true if the specified object it is the same as this + * CIMQualifierType. Otherwise, false. + */ + @Override + public boolean equals(Object pObj) { + if (!(pObj instanceof CIMQualifierType)) return false; + if (!super.equals(pObj)) return false; + CIMQualifierType that = (CIMQualifierType) pObj; + return this.iObjPath.equals(that.iObjPath) && this.iScope == that.iScope; + } + + /** + * Returns the flavors of this qualifier type as a BitSet. + * + * @return BitSet of flavors for this qualifier type. + */ + public int getFlavor() { + return this.iFlavor; + } + + /** + * Get the object path for this CIMQualifierType. + * + * @return The CIMObjectPath that represents this qualifier + * type. + */ + public CIMObjectPath getObjectPath() { + return this.iObjPath; + } + + /** + * Returns the scopes of this qualifier type as a bit set. + * + * @return Bit set of CIM element scopes for which this qualifier type is + * applicable. + */ + public int getScope() { + return this.iScope; + } + + /** + * Returns a String representation of the + * CIMQualifierType This method is intended to be used only for + * debugging purposes, and the format of the returned string may vary + * between implementations. The returned string may be empty but may not be + * null. + * + * @return A string representation of this qualifier type. + */ + @Override + public String toString() { + return MOF.qualifierDeclaration(this); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMScope.java b/src/main/java/org/metricshub/wbem/javax/cim/CIMScope.java similarity index 75% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/CIMScope.java rename to src/main/java/org/metricshub/wbem/javax/cim/CIMScope.java index e76bc81..319681c 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMScope.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/CIMScope.java @@ -1,113 +1,108 @@ -/* - (C) Copyright IBM Corp. 2006, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant - * 1737123 2007-06-15 ebak Differences to JSR48 public review draft - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.Serializable; - -//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 -/** - * This class represents a CIM Scope as defined by the Distributed Management - * Task Force (DMTF) CIM Infrastructure - * Specification (DSP004). This class is used in a CIMQualifierType to define - * what elements the qualifier can be applied to. - */ -public class CIMScope extends Object implements Serializable { - - private static final long serialVersionUID = -4563643521754840535l; - - /** - * Scope representing a qualifier that can be applied to any element. - */ - public static final int ANY = 127; - - /** - * Scope representing a qualifier that can be applied to an association. - */ - public static final int ASSOCIATION = 2; - - /** - * Scope representing a qualifier that can be applied to a CIM class. - */ - public static final int CLASS = 1; - - /** - * Scope representing a qualifier that can be applied to an indication. - */ - public static final int INDICATION = 4; - - /** - * Scope representing a qualifier that can be applied to a method. - */ - public static final int METHOD = 32; - - /** - * Scope representing a qualifier that can be applied to a parameter. - */ - public static final int PARAMETER = 64; - - /** - * Scope representing a qualifier that can be applied to a property. - */ - public static final int PROPERTY = 8; - - /** - * Scope representing a qualifier that can be applied to a reference. - */ - public static final int REFERENCE = 16; - - private static final int[] SCOPES = { ANY, ASSOCIATION, CLASS, INDICATION, METHOD, PARAMETER, - PROPERTY, REFERENCE }; - - /** - * Returns the complete set of possible scopes. - * - * @return An int array of all scopes. - */ - public static int[] getScopes() { - return SCOPES; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant + * 1737123 2007-06-15 ebak Differences to JSR48 public review draft + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.Serializable; + +//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 +/** + * This class represents a CIM Scope as defined by the Distributed Management + * Task Force (DMTF) CIM Infrastructure + * Specification (DSP004). This class is used in a CIMQualifierType to define + * what elements the qualifier can be applied to. + */ +public class CIMScope implements Serializable { + private static final long serialVersionUID = -4563643521754840535l; + + /** + * Scope representing a qualifier that can be applied to any element. + */ + public static final int ANY = 127; + + /** + * Scope representing a qualifier that can be applied to an association. + */ + public static final int ASSOCIATION = 2; + + /** + * Scope representing a qualifier that can be applied to a CIM class. + */ + public static final int CLASS = 1; + + /** + * Scope representing a qualifier that can be applied to an indication. + */ + public static final int INDICATION = 4; + + /** + * Scope representing a qualifier that can be applied to a method. + */ + public static final int METHOD = 32; + + /** + * Scope representing a qualifier that can be applied to a parameter. + */ + public static final int PARAMETER = 64; + + /** + * Scope representing a qualifier that can be applied to a property. + */ + public static final int PROPERTY = 8; + + /** + * Scope representing a qualifier that can be applied to a reference. + */ + public static final int REFERENCE = 16; + + private static final int[] SCOPES = { ANY, ASSOCIATION, CLASS, INDICATION, METHOD, PARAMETER, PROPERTY, REFERENCE }; + + /** + * Returns the complete set of possible scopes. + * + * @return An int array of all scopes. + */ + public static int[] getScopes() { + return SCOPES; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMTypedElement.java b/src/main/java/org/metricshub/wbem/javax/cim/CIMTypedElement.java similarity index 79% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/CIMTypedElement.java rename to src/main/java/org/metricshub/wbem/javax/cim/CIMTypedElement.java index 653f563..fdfe782 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMTypedElement.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/CIMTypedElement.java @@ -1,127 +1,124 @@ -/* - (C) Copyright IBM Corp. 2006, 2011 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant - * 1669961 2006-04-16 lupusalex CIMTypedElement.getType() =>getDataType() - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2227442 2008-11-05 blaschke-oss Add missing serialVersionUID - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.MOF; - -//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 -/** - * CIMTypedElement is an abstract class that represents a CIM - * element that contains just the data type, but no value. - */ -public abstract class CIMTypedElement extends CIMElement { - - private static final long serialVersionUID = -8839964536590822815L; - - private CIMDataType iType; - - /** - * Constructs a CIMTypedElement with the given name and data - * type. - * - * @param pName - * Name of the element. - * @param pType - * Data type of the element. - */ - public CIMTypedElement(String pName, CIMDataType pType) { - super(pName); - this.iType = pType; - } - - /** - * Compares this object against the specified object. The result is - * true if and only if the argument is not null - * and is a CIMTypedElement that represents the same name and - * type as this object. - * - * @param pObj - * The object to compare with. - * @return true if the objects are the same; false - * otherwise. - */ - @Override - public boolean equals(Object pObj) { - if (!(pObj instanceof CIMTypedElement)) return false; - CIMTypedElement that = (CIMTypedElement) pObj; - if (!super.equals(that)) return false; - return this.iType.equals(that.iType); - } - - /** - * Returns the CIMDataType for this CIM Element. - * - * @return CIMDataType of this CIM element. - */ - public CIMDataType getDataType() { - return this.iType; - } - - /** - * Returns a hash code value for the CIM typed element. This method is - * supported for the benefit of hashtables such as those provided by - * java.util.Hashtable. - * - * @return A hash code value for this CIM typed element. - */ - @Override - public int hashCode() { - return toString().hashCode(); - } - - /** - * Returns a String representation of the CIM Element. This - * method is intended to be used only for debugging purposes, and the format - * of the returned string may vary between implementations. The returned - * string may be empty but may not be null. - * - * @return String representation of this element. - */ - @Override - public String toString() { - return MOF.typedElement(this, MOF.EMPTY); - } -} +/* + (C) Copyright IBM Corp. 2006, 2011 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant + * 1669961 2006-04-16 lupusalex CIMTypedElement.getType() =>getDataType() + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2227442 2008-11-05 blaschke-oss Add missing serialVersionUID + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.sblim.cimclient.internal.util.MOF; + +//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 +/** + * CIMTypedElement is an abstract class that represents a CIM + * element that contains just the data type, but no value. + */ +public abstract class CIMTypedElement extends CIMElement { + private static final long serialVersionUID = -8839964536590822815L; + + private CIMDataType iType; + + /** + * Constructs a CIMTypedElement with the given name and data + * type. + * + * @param pName + * Name of the element. + * @param pType + * Data type of the element. + */ + public CIMTypedElement(String pName, CIMDataType pType) { + super(pName); + this.iType = pType; + } + + /** + * Compares this object against the specified object. The result is + * true if and only if the argument is not null + * and is a CIMTypedElement that represents the same name and + * type as this object. + * + * @param pObj + * The object to compare with. + * @return true if the objects are the same; false + * otherwise. + */ + @Override + public boolean equals(Object pObj) { + if (!(pObj instanceof CIMTypedElement)) return false; + CIMTypedElement that = (CIMTypedElement) pObj; + if (!super.equals(that)) return false; + return this.iType.equals(that.iType); + } + + /** + * Returns the CIMDataType for this CIM Element. + * + * @return CIMDataType of this CIM element. + */ + public CIMDataType getDataType() { + return this.iType; + } + + /** + * Returns a hash code value for the CIM typed element. This method is + * supported for the benefit of hashtables such as those provided by + * java.util.Hashtable. + * + * @return A hash code value for this CIM typed element. + */ + @Override + public int hashCode() { + return toString().hashCode(); + } + + /** + * Returns a String representation of the CIM Element. This + * method is intended to be used only for debugging purposes, and the format + * of the returned string may vary between implementations. The returned + * string may be empty but may not be null. + * + * @return String representation of this element. + */ + @Override + public String toString() { + return MOF.typedElement(this, MOF.EMPTY); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMValuedElement.java b/src/main/java/org/metricshub/wbem/javax/cim/CIMValuedElement.java similarity index 78% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/CIMValuedElement.java rename to src/main/java/org/metricshub/wbem/javax/cim/CIMValuedElement.java index ccc0f9d..2b46061 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/CIMValuedElement.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/CIMValuedElement.java @@ -1,155 +1,150 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant - * 1669961 2006-04-16 lupusalex CIMTypedElement.getType() =>getDataType() - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues - * 3411879 2011-09-20 blaschke-oss TCK: CIM element value must match type - * 2716 2013-12-11 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Arrays; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.MOF; - -//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013 -/** - * CIMValuedElement is a base class used by any element that - * contains a name, type and value. - * - * @param - * Type parameter. - */ -public abstract class CIMValuedElement extends CIMTypedElement { - - private static final long serialVersionUID = 4234L; - - private E iValue; - - /** - * Creates a new CIM element with the given name, type and value. - * - * @param pName - * The string for the name for this element. - * @param pType - * The data type for this element. - * @param pValue - * The value for this element. null is a valid - * value. - * @throws IllegalArgumentException - * If the value does not match the data type. - */ - protected CIMValuedElement(String pName, CIMDataType pType, E pValue) { - super(pName, pType); - - if (pType != null && pValue != null) { - CIMDataType valueDataType; - try { - valueDataType = CIMDataType.getDataType(pValue); - } catch (IllegalArgumentException e) { - // Value has unknown data type, cannot validate - valueDataType = null; - } - if (valueDataType != null && valueDataType.getType() != pType.getType()) throw new IllegalArgumentException( - "CIM value does not match type: " + valueDataType.getType() + " != " - + pType.getType()); - } - - this.iValue = pValue; - } - - /** - * Compares this object against the specified object. The result is - * true if and only if the argument is not null - * and is a CIMValuedElement that represents the same name, - * type and value as this object. - * - * @param pObj - * The object to compare with. - * @return true if the objects are the same; false - * otherwise. - */ - @Override - public boolean equals(Object pObj) { - if (!(pObj instanceof CIMValuedElement)) return false; - CIMValuedElement that = (CIMValuedElement) pObj; - if (!super.equals(that)) return false; - if (getDataType().isArray()) { return Arrays.equals((Object[]) this.iValue, - (Object[]) that.iValue); } - return this.iValue == null ? that.iValue == null : this.iValue.equals(that.iValue); - } - - /** - * Returns the value for this CIM Element. - * - * @return The value of the CIM Element. null is a valid value. - */ - public E getValue() { - return this.iValue; - } - - /** - * Returns a hash code value for the CIM valued element. This method is - * supported for the benefit of hashtables such as those provided by - * java.util.Hashtable. - * - * @return A hash code value for this CIM valued element. - */ - @Override - public int hashCode() { - return toString().hashCode(); - } - - /** - * Returns a String representation of the CIM Element. This - * method is intended to be used only for debugging purposes, and the format - * of the returned string may vary between implementations. The returned - * string may be empty but may not be null. - * - * @return String representation of this element. - */ - @Override - public String toString() { - return MOF.valuedElement(this, MOF.EMPTY); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-06 ebak Make SBLIM client JSR48 compliant + * 1669961 2006-04-16 lupusalex CIMTypedElement.getType() =>getDataType() + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues + * 3411879 2011-09-20 blaschke-oss TCK: CIM element value must match type + * 2716 2013-12-11 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Arrays; +import org.metricshub.wbem.sblim.cimclient.internal.util.MOF; + +//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013 +/** + * CIMValuedElement is a base class used by any element that + * contains a name, type and value. + * + * @param + * Type parameter. + */ +public abstract class CIMValuedElement extends CIMTypedElement { + private static final long serialVersionUID = 4234L; + + private E iValue; + + /** + * Creates a new CIM element with the given name, type and value. + * + * @param pName + * The string for the name for this element. + * @param pType + * The data type for this element. + * @param pValue + * The value for this element. null is a valid + * value. + * @throws IllegalArgumentException + * If the value does not match the data type. + */ + protected CIMValuedElement(String pName, CIMDataType pType, E pValue) { + super(pName, pType); + if (pType != null && pValue != null) { + CIMDataType valueDataType; + try { + valueDataType = CIMDataType.getDataType(pValue); + } catch (IllegalArgumentException e) { + // Value has unknown data type, cannot validate + valueDataType = null; + } + if (valueDataType != null && valueDataType.getType() != pType.getType()) throw new IllegalArgumentException( + "CIM value does not match type: " + valueDataType.getType() + " != " + pType.getType() + ); + } + + this.iValue = pValue; + } + + /** + * Compares this object against the specified object. The result is + * true if and only if the argument is not null + * and is a CIMValuedElement that represents the same name, + * type and value as this object. + * + * @param pObj + * The object to compare with. + * @return true if the objects are the same; false + * otherwise. + */ + @Override + public boolean equals(Object pObj) { + if (!(pObj instanceof CIMValuedElement)) return false; + CIMValuedElement that = (CIMValuedElement) pObj; + if (!super.equals(that)) return false; + if (getDataType().isArray()) { + return Arrays.equals((Object[]) this.iValue, (Object[]) that.iValue); + } + return this.iValue == null ? that.iValue == null : this.iValue.equals(that.iValue); + } + + /** + * Returns the value for this CIM Element. + * + * @return The value of the CIM Element. null is a valid value. + */ + public E getValue() { + return this.iValue; + } + + /** + * Returns a hash code value for the CIM valued element. This method is + * supported for the benefit of hashtables such as those provided by + * java.util.Hashtable. + * + * @return A hash code value for this CIM valued element. + */ + @Override + public int hashCode() { + return toString().hashCode(); + } + + /** + * Returns a String representation of the CIM Element. This + * method is intended to be used only for debugging purposes, and the format + * of the returned string may vary between implementations. The returned + * string may be empty but may not be null. + * + * @return String representation of this element. + */ + @Override + public String toString() { + return MOF.valuedElement(this, MOF.EMPTY); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/UnsignedInteger16.java b/src/main/java/org/metricshub/wbem/javax/cim/UnsignedInteger16.java similarity index 86% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/UnsignedInteger16.java rename to src/main/java/org/metricshub/wbem/javax/cim/UnsignedInteger16.java index 96b0dbf..b767aa1 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/UnsignedInteger16.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/UnsignedInteger16.java @@ -1,247 +1,242 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-09 ebak Make SBLIM client JSR48 compliant - * 1737123 2007-06-15 ebak Differences to JSR48 public review draft - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al - * 2795671 2009-05-22 raman_arora Add Type to Comparable - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - * 2973233 2010-03-19 blaschke-oss TCK: UnsignedIntegerNN.hashCode() not working - * 2719 2013-12-10 blaschke-oss TCK: CIM APIs should not generate NullPointerException - * 2716 2013-12-11 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013 -/** - * This class represents an UnsignedInteger16. A - * uint16 data type is defined by the (DMTF) CIM Infrastructure Specification (DSP004). - */ -public class UnsignedInteger16 extends Number implements Comparable { - - private static final long serialVersionUID = -4992164525643467216L; - - /** - * The maximum value for an UnsignedInteger16. - */ - public static final int MAX_VALUE = 65535; - - /** - * The minimum value for an UnsignedInteger16. - */ - public static final int MIN_VALUE = 0; - - private int iValue; - - /** - * Sets the value of this integer object if it falls within the range of - * minimum and maximum values. - * - * @param pValue - * The integer. - * @throws NumberFormatException - * If the integer is out of range. - */ - private void setValue(int pValue) throws NumberFormatException { - if (pValue > MAX_VALUE || pValue < MIN_VALUE) { - String msg = "uint16:" + pValue + " is out of range!"; - throw new NumberFormatException(msg); - } - this.iValue = pValue; - } - - /** - * Constructs an unsigned 16-bit integer object for the specified int value. - * Only the lower 16 bits are considered. - * - * @param pValue - * The integer to be represented as an unsigned 16-bit integer. - * @throws NumberFormatException - * If the number is out of range. - */ - public UnsignedInteger16(int pValue) throws NumberFormatException { - setValue(pValue); - } - - /** - * Constructs an unsigned 16-bit integer object for the specified string. - * Only the lower 16 bits are considered. - * - * @param pValue - * The string to be represented as an unsigned 16-bit integer. - * @throws NumberFormatException - * If the number is out of range. - * @throws IllegalArgumentException - * If value is null. - */ - public UnsignedInteger16(String pValue) throws NumberFormatException { - if (pValue == null) throw new IllegalArgumentException("String value cannot be null!"); - setValue(Integer.parseInt(pValue)); - } - - /** - * Compares this object with the specified object for order. Returns a - * negative integer, zero, or a positive integer as this object is less - * than, equal to, or greater than the specified object. - * - * @param pOther - * The Object to be compared. - * @return A negative integer, zero, or a positive integer as this object is - * less than, equal to, or greater than the specified object. - * @throws ClassCastException - * If the specified object's type prevents it from being - * compared to this Object. - * @throws IllegalArgumentException - * If value is null. - */ - public int compareTo(UnsignedInteger16 pOther) { - if (pOther == null) throw new IllegalArgumentException( - "Other UnsignedInteger16 cannot be null!"); - UnsignedInteger16 that = pOther; - int d = this.iValue - that.iValue; - if (d == 0) return 0; - return d < 0 ? -1 : 1; - } - - /** - * Compares this object against the specified object. The result is - * true if and only if the argument is not null and is an - * UnsignedInteger16 object that represents the same value as - * this object. - * - * @param pObj - * The object to compare. - * @return true if the objects are the same; false - * otherwise. - */ - @Override - public boolean equals(Object pObj) { - if (!(pObj instanceof UnsignedInteger16)) return false; - return this.iValue == ((UnsignedInteger16) pObj).iValue; - } - - /** - * Returns the value of this unsigned integer object as a byte. - * - * @return The byte value of this unsigned integer object. - */ - @Override - public byte byteValue() { - return (byte) this.iValue; - } - - /** - * Returns the value of this unsigned integer object as a - * double. - * - * @return Value of this unsigned integer object as a double. - */ - @Override - public double doubleValue() { - return this.iValue; - } - - /** - * Returns the value of this unsigned integer object as a float - * . - * - * @return Value of this unsigned integer object as a float. - */ - @Override - public float floatValue() { - return this.iValue; - } - - /** - * Computes the hash code for this unsigned integer object. - * - * @return The integer representing the hash code for this unsigned integer - * object. - */ - @Override - public int hashCode() { - return Integer.valueOf(this.iValue).hashCode(); - } - - /** - * Returns the value of this unsigned integer object as an int. - * - * @return Value of this unsigned integer object as an int. - */ - @Override - public int intValue() { - return this.iValue; - } - - /** - * Returns the value of this unsigned integer object as a long. - * - * @return Value of this unsigned integer object as a long. - */ - @Override - public long longValue() { - return this.iValue; - } - - /** - * Returns the value of this unsigned integer object as a short - * . - * - * @return Value of this unsigned integer object as a short. - */ - @Override - public short shortValue() { - return (short) this.iValue; - } - - /** - * Returns the text representation of this unsigned integer object. - * - * @return Text representation of this unsigned integer. - */ - @Override - public String toString() { - return Integer.toString(this.iValue); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-09 ebak Make SBLIM client JSR48 compliant + * 1737123 2007-06-15 ebak Differences to JSR48 public review draft + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al + * 2795671 2009-05-22 raman_arora Add Type to Comparable + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + * 2973233 2010-03-19 blaschke-oss TCK: UnsignedIntegerNN.hashCode() not working + * 2719 2013-12-10 blaschke-oss TCK: CIM APIs should not generate NullPointerException + * 2716 2013-12-11 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013 +/** + * This class represents an UnsignedInteger16. A + * uint16 data type is defined by the (DMTF) CIM Infrastructure Specification (DSP004). + */ +public class UnsignedInteger16 extends Number implements Comparable { + private static final long serialVersionUID = -4992164525643467216L; + + /** + * The maximum value for an UnsignedInteger16. + */ + public static final int MAX_VALUE = 65535; + + /** + * The minimum value for an UnsignedInteger16. + */ + public static final int MIN_VALUE = 0; + + private int iValue; + + /** + * Sets the value of this integer object if it falls within the range of + * minimum and maximum values. + * + * @param pValue + * The integer. + * @throws NumberFormatException + * If the integer is out of range. + */ + private void setValue(int pValue) throws NumberFormatException { + if (pValue > MAX_VALUE || pValue < MIN_VALUE) { + String msg = "uint16:" + pValue + " is out of range!"; + throw new NumberFormatException(msg); + } + this.iValue = pValue; + } + + /** + * Constructs an unsigned 16-bit integer object for the specified int value. + * Only the lower 16 bits are considered. + * + * @param pValue + * The integer to be represented as an unsigned 16-bit integer. + * @throws NumberFormatException + * If the number is out of range. + */ + public UnsignedInteger16(int pValue) throws NumberFormatException { + setValue(pValue); + } + + /** + * Constructs an unsigned 16-bit integer object for the specified string. + * Only the lower 16 bits are considered. + * + * @param pValue + * The string to be represented as an unsigned 16-bit integer. + * @throws NumberFormatException + * If the number is out of range. + * @throws IllegalArgumentException + * If value is null. + */ + public UnsignedInteger16(String pValue) throws NumberFormatException { + if (pValue == null) throw new IllegalArgumentException("String value cannot be null!"); + setValue(Integer.parseInt(pValue)); + } + + /** + * Compares this object with the specified object for order. Returns a + * negative integer, zero, or a positive integer as this object is less + * than, equal to, or greater than the specified object. + * + * @param pOther + * The Object to be compared. + * @return A negative integer, zero, or a positive integer as this object is + * less than, equal to, or greater than the specified object. + * @throws ClassCastException + * If the specified object's type prevents it from being + * compared to this Object. + * @throws IllegalArgumentException + * If value is null. + */ + public int compareTo(UnsignedInteger16 pOther) { + if (pOther == null) throw new IllegalArgumentException("Other UnsignedInteger16 cannot be null!"); + UnsignedInteger16 that = pOther; + int d = this.iValue - that.iValue; + if (d == 0) return 0; + return d < 0 ? -1 : 1; + } + + /** + * Compares this object against the specified object. The result is + * true if and only if the argument is not null and is an + * UnsignedInteger16 object that represents the same value as + * this object. + * + * @param pObj + * The object to compare. + * @return true if the objects are the same; false + * otherwise. + */ + @Override + public boolean equals(Object pObj) { + if (!(pObj instanceof UnsignedInteger16)) return false; + return this.iValue == ((UnsignedInteger16) pObj).iValue; + } + + /** + * Returns the value of this unsigned integer object as a byte. + * + * @return The byte value of this unsigned integer object. + */ + @Override + public byte byteValue() { + return (byte) this.iValue; + } + + /** + * Returns the value of this unsigned integer object as a + * double. + * + * @return Value of this unsigned integer object as a double. + */ + @Override + public double doubleValue() { + return this.iValue; + } + + /** + * Returns the value of this unsigned integer object as a float + * . + * + * @return Value of this unsigned integer object as a float. + */ + @Override + public float floatValue() { + return this.iValue; + } + + /** + * Computes the hash code for this unsigned integer object. + * + * @return The integer representing the hash code for this unsigned integer + * object. + */ + @Override + public int hashCode() { + return Integer.valueOf(this.iValue).hashCode(); + } + + /** + * Returns the value of this unsigned integer object as an int. + * + * @return Value of this unsigned integer object as an int. + */ + @Override + public int intValue() { + return this.iValue; + } + + /** + * Returns the value of this unsigned integer object as a long. + * + * @return Value of this unsigned integer object as a long. + */ + @Override + public long longValue() { + return this.iValue; + } + + /** + * Returns the value of this unsigned integer object as a short + * . + * + * @return Value of this unsigned integer object as a short. + */ + @Override + public short shortValue() { + return (short) this.iValue; + } + + /** + * Returns the text representation of this unsigned integer object. + * + * @return Text representation of this unsigned integer. + */ + @Override + public String toString() { + return Integer.toString(this.iValue); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/UnsignedInteger32.java b/src/main/java/org/metricshub/wbem/javax/cim/UnsignedInteger32.java similarity index 86% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/UnsignedInteger32.java rename to src/main/java/org/metricshub/wbem/javax/cim/UnsignedInteger32.java index c14fc95..426ffee 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/UnsignedInteger32.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/UnsignedInteger32.java @@ -1,246 +1,241 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-09 ebak Make SBLIM client JSR48 compliant - * 1737123 2007-06-15 ebak Differences to JSR48 public review draft - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al - * 2795671 2009-05-22 raman_arora Add Type to Comparable - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - * 2973233 2010-03-19 blaschke-oss TCK: UnsignedIntegerNN.hashCode() not working - * 2719 2013-12-10 blaschke-oss TCK: CIM APIs should not generate NullPointerException - * 2716 2013-12-11 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013 -/** - * This class represents an UnsignedInteger32. A - * uint32 data type is defined by the (DMTF) CIM Infrastructure Specification (DSP004). - */ -public class UnsignedInteger32 extends Number implements Comparable { - - private static final long serialVersionUID = -8861436527534071393L; - - /** - * The maximum value for an UnsignedInteger32. - */ - public static final long MAX_VALUE = 4294967295l; - - /** - * The minimum value for an UnsignedInteger32. - */ - public static final long MIN_VALUE = 0l; - - private long iValue; - - /** - * Sets the value of this integer object if it falls within the range of - * minimum and maximum values. - * - * @param pValue - * The integer. - * @throws NumberFormatException - * If the integer is out of range. - */ - private void setValue(long pValue) throws NumberFormatException { - if (pValue > MAX_VALUE || pValue < MIN_VALUE) { - String msg = "uint32:" + pValue + " is out of range!"; - throw new NumberFormatException(msg); - } - this.iValue = pValue; - } - - /** - * Constructs an unsigned 32-bit integer object for the specified long - * value. Only the lower 32 bits are considered. - * - * @param pValue - * The long to be represented as an unsigned 32-bit integer. - * @throws NumberFormatException - * If the number is out of range. - */ - public UnsignedInteger32(long pValue) throws NumberFormatException { - setValue(pValue); - } - - /** - * Constructs an unsigned 32-bit integer object for the specified string. - * Only the lower 32 bits are considered. - * - * @param pValue - * The string to be represented as an unsigned 32-bit integer. - * @throws NumberFormatException - * If the number is out of range. - * @throws IllegalArgumentException - * If value is null. - */ - public UnsignedInteger32(String pValue) throws NumberFormatException { - if (pValue == null) throw new IllegalArgumentException("String value cannot be null!"); - setValue(Long.parseLong(pValue)); - } - - /** - * Compares this object with the specified object for order. Returns a - * negative integer, zero, or a positive integer as this object is less - * than, equal to, or greater than the specified object. - * - * @param pOther - * The Object to be compared. - * @return A negative integer, zero, or a positive integer as this object is - * less than, equal to, or greater than the specified object. - * @throws ClassCastException - * If the specified object's type prevents it from being - * compared to this Object. - * @throws IllegalArgumentException - * If value is null. - */ - public int compareTo(UnsignedInteger32 pOther) { - if (pOther == null) throw new IllegalArgumentException( - "Other UnsignedInteger32 cannot be null!"); - UnsignedInteger32 that = pOther; - long d = this.iValue - that.iValue; - if (d == 0) return 0; - return d < 0 ? -1 : 1; - } - - /** - * Compares this object against the specified object. The result is - * true if and only if the argument is not null and is an - * UnsignedInteger32 object that represents the same value as this object. - * - * @param pObj - * The object to compare. - * @return true if the objects are the same; false - * otherwise. - */ - @Override - public boolean equals(Object pObj) { - if (!(pObj instanceof UnsignedInteger32)) return false; - return this.iValue == ((UnsignedInteger32) pObj).iValue; - } - - /** - * Returns the value of this unsigned integer object as a byte. - * - * @return The byte value of this unsigned integer object. - */ - @Override - public byte byteValue() { - return (byte) this.iValue; - } - - /** - * Returns the value of this unsigned integer object as a - * double. - * - * @return Value of this unsigned integer object as a double. - */ - @Override - public double doubleValue() { - return this.iValue; - } - - /** - * Returns the value of this unsigned integer object as a float - * . - * - * @return Value of this unsigned integer object as a float. - */ - @Override - public float floatValue() { - return this.iValue; - } - - /** - * Computes the hash code for this unsigned integer object. - * - * @return The integer representing the hash code for this unsigned integer - * object. - */ - @Override - public int hashCode() { - return Long.valueOf(this.iValue).hashCode(); - } - - /** - * Returns the value of this unsigned integer object as an int. - * - * @return Value of this unsigned integer object as an int. - */ - @Override - public int intValue() { - return (int) this.iValue; - } - - /** - * Returns the value of this unsigned integer object as a long. - * - * @return Value of this unsigned integer object as a long. - */ - @Override - public long longValue() { - return this.iValue; - } - - /** - * Returns the value of this unsigned integer object as a short - * . - * - * @return Value of this unsigned integer object as a short. - */ - @Override - public short shortValue() { - return (short) this.iValue; - } - - /** - * Returns the text representation of this unsigned integer object. - * - * @return Text representation of this unsigned integer. - */ - @Override - public String toString() { - return Long.toString(this.iValue); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-09 ebak Make SBLIM client JSR48 compliant + * 1737123 2007-06-15 ebak Differences to JSR48 public review draft + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al + * 2795671 2009-05-22 raman_arora Add Type to Comparable + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + * 2973233 2010-03-19 blaschke-oss TCK: UnsignedIntegerNN.hashCode() not working + * 2719 2013-12-10 blaschke-oss TCK: CIM APIs should not generate NullPointerException + * 2716 2013-12-11 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013 +/** + * This class represents an UnsignedInteger32. A + * uint32 data type is defined by the (DMTF) CIM Infrastructure Specification (DSP004). + */ +public class UnsignedInteger32 extends Number implements Comparable { + private static final long serialVersionUID = -8861436527534071393L; + + /** + * The maximum value for an UnsignedInteger32. + */ + public static final long MAX_VALUE = 4294967295l; + + /** + * The minimum value for an UnsignedInteger32. + */ + public static final long MIN_VALUE = 0l; + + private long iValue; + + /** + * Sets the value of this integer object if it falls within the range of + * minimum and maximum values. + * + * @param pValue + * The integer. + * @throws NumberFormatException + * If the integer is out of range. + */ + private void setValue(long pValue) throws NumberFormatException { + if (pValue > MAX_VALUE || pValue < MIN_VALUE) { + String msg = "uint32:" + pValue + " is out of range!"; + throw new NumberFormatException(msg); + } + this.iValue = pValue; + } + + /** + * Constructs an unsigned 32-bit integer object for the specified long + * value. Only the lower 32 bits are considered. + * + * @param pValue + * The long to be represented as an unsigned 32-bit integer. + * @throws NumberFormatException + * If the number is out of range. + */ + public UnsignedInteger32(long pValue) throws NumberFormatException { + setValue(pValue); + } + + /** + * Constructs an unsigned 32-bit integer object for the specified string. + * Only the lower 32 bits are considered. + * + * @param pValue + * The string to be represented as an unsigned 32-bit integer. + * @throws NumberFormatException + * If the number is out of range. + * @throws IllegalArgumentException + * If value is null. + */ + public UnsignedInteger32(String pValue) throws NumberFormatException { + if (pValue == null) throw new IllegalArgumentException("String value cannot be null!"); + setValue(Long.parseLong(pValue)); + } + + /** + * Compares this object with the specified object for order. Returns a + * negative integer, zero, or a positive integer as this object is less + * than, equal to, or greater than the specified object. + * + * @param pOther + * The Object to be compared. + * @return A negative integer, zero, or a positive integer as this object is + * less than, equal to, or greater than the specified object. + * @throws ClassCastException + * If the specified object's type prevents it from being + * compared to this Object. + * @throws IllegalArgumentException + * If value is null. + */ + public int compareTo(UnsignedInteger32 pOther) { + if (pOther == null) throw new IllegalArgumentException("Other UnsignedInteger32 cannot be null!"); + UnsignedInteger32 that = pOther; + long d = this.iValue - that.iValue; + if (d == 0) return 0; + return d < 0 ? -1 : 1; + } + + /** + * Compares this object against the specified object. The result is + * true if and only if the argument is not null and is an + * UnsignedInteger32 object that represents the same value as this object. + * + * @param pObj + * The object to compare. + * @return true if the objects are the same; false + * otherwise. + */ + @Override + public boolean equals(Object pObj) { + if (!(pObj instanceof UnsignedInteger32)) return false; + return this.iValue == ((UnsignedInteger32) pObj).iValue; + } + + /** + * Returns the value of this unsigned integer object as a byte. + * + * @return The byte value of this unsigned integer object. + */ + @Override + public byte byteValue() { + return (byte) this.iValue; + } + + /** + * Returns the value of this unsigned integer object as a + * double. + * + * @return Value of this unsigned integer object as a double. + */ + @Override + public double doubleValue() { + return this.iValue; + } + + /** + * Returns the value of this unsigned integer object as a float + * . + * + * @return Value of this unsigned integer object as a float. + */ + @Override + public float floatValue() { + return this.iValue; + } + + /** + * Computes the hash code for this unsigned integer object. + * + * @return The integer representing the hash code for this unsigned integer + * object. + */ + @Override + public int hashCode() { + return Long.valueOf(this.iValue).hashCode(); + } + + /** + * Returns the value of this unsigned integer object as an int. + * + * @return Value of this unsigned integer object as an int. + */ + @Override + public int intValue() { + return (int) this.iValue; + } + + /** + * Returns the value of this unsigned integer object as a long. + * + * @return Value of this unsigned integer object as a long. + */ + @Override + public long longValue() { + return this.iValue; + } + + /** + * Returns the value of this unsigned integer object as a short + * . + * + * @return Value of this unsigned integer object as a short. + */ + @Override + public short shortValue() { + return (short) this.iValue; + } + + /** + * Returns the text representation of this unsigned integer object. + * + * @return Text representation of this unsigned integer. + */ + @Override + public String toString() { + return Long.toString(this.iValue); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/UnsignedInteger64.java b/src/main/java/org/metricshub/wbem/javax/cim/UnsignedInteger64.java similarity index 87% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/UnsignedInteger64.java rename to src/main/java/org/metricshub/wbem/javax/cim/UnsignedInteger64.java index f07f7c1..7d72fa0 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/UnsignedInteger64.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/UnsignedInteger64.java @@ -1,278 +1,273 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-09 ebak Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al - * 2795671 2009-05-22 raman_arora Add Type to Comparable - * 2935258 2010-01-19 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - * 2973230 2010-03-19 blaschke-oss TCK: UnsignedInteger64.equals() does not handle null - * 2719 2013-12-10 blaschke-oss TCK: CIM APIs should not generate NullPointerException - * 2716 2013-12-11 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.math.BigInteger; - -//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013 -/** - * This class represents an UnsignedInteger64. A - * uint64 data type is defined by the (DMTF) CIM Infrastructure Specification (DSP004). - */ -public class UnsignedInteger64 extends Number implements Comparable { - - private static final long serialVersionUID = -3734165689168941119L; - - /** - * The maximum value for an UnsignedInteger64. - */ - public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615"); - - /** - * The minimum value for an UnsignedInteger64. - */ - public static final BigInteger MIN_VALUE = BigInteger.ZERO; - - private BigInteger iValue; - - /** - * Sets the value of this integer object if it falls within the range of - * minimum and maximum values. - * - * @param pValue - * The integer. - * @throws NumberFormatException - * If the integer is out of range. - */ - private void setValue(BigInteger pValue) throws NumberFormatException { - if (pValue.compareTo(MAX_VALUE) > 0 || pValue.compareTo(MIN_VALUE) < 0) { - String msg = "uint64:" + pValue + " is out of range!"; - throw new NumberFormatException(msg); - } - this.iValue = pValue; - } - - /** - * Constructs an unsigned 64-bit integer object for the specified - * BigInteger. Only the lower 64 bits are considered. - * - * @param pValue - * The BigInteger to be represented as an unsigned - * 64-bit integer. - * @throws NumberFormatException - * If the number is out of range. - * @throws IllegalArgumentException - * If value is null. - */ - public UnsignedInteger64(BigInteger pValue) throws NumberFormatException { - if (pValue == null) throw new IllegalArgumentException("BigInteger value cannot be null!"); - setValue(pValue); - } - - /** - * Constructs an unsigned 64-bit integer object for the specified array of - * bytes. Only the lower 64 bits are considered. - * - * @param pValue - * The byte array to be represented as an unsigned 64-bit - * integer. - * @throws NumberFormatException - * If the number is out of range. - * @throws IllegalArgumentException - * If value is null. - */ - public UnsignedInteger64(byte[] pValue) throws NumberFormatException { - if (pValue == null) throw new IllegalArgumentException("byte[] value cannot be null!"); - setValue(new BigInteger(pValue)); - } - - /** - * Constructs an unsigned 64-bit integer object from the specified string. - * Only the lower 64 bits are considered. - * - * @param pValue - * The string to be represented as an unsigned 64-bit integer. - * @throws NumberFormatException - * If the number is out of range. - * @throws IllegalArgumentException - * If value is null. - */ - public UnsignedInteger64(String pValue) throws NumberFormatException { - if (pValue == null) throw new IllegalArgumentException("String value cannot be null!"); - setValue(new BigInteger(pValue)); - } - - /** - * Get the value as a BigInteger. - * - * @return BigInteger representation of this object. - */ - public BigInteger bigIntegerValue() { - return this.iValue; - } - - /** - * Compares this object with the specified object for order. Returns a - * negative integer, zero, or a positive integer as this object is less - * than, equal to, or greater than the specified object. - * - * @param pOther - * The Object to be compared. - * @return A negative integer, zero, or a positive integer as this object is - * less than, equal to, or greater than the specified object. - * @throws ClassCastException - * If the specified object's type prevents it from being - * compared to this Object. - * @throws IllegalArgumentException - * If value is null. - */ - public int compareTo(UnsignedInteger64 pOther) { - if (pOther == null) throw new IllegalArgumentException( - "Other UnsignedInteger64 cannot be null!"); - UnsignedInteger64 that = pOther; - int d = this.iValue.compareTo(that.iValue); - if (d == 0) return 0; - return d < 0 ? -1 : 1; - } - - /** - * Compares this object against the specified object. The result is - * true if and only if the argument is not null - * and is an UnsignedInteger64 object that represents the same - * value as this object. - * - * @param pOther - * The object to compare. - * @return true if the objects are the same; false - * otherwise. - */ - @Override - public boolean equals(Object pOther) { - if (!(pOther instanceof UnsignedInteger64)) return false; - return this.iValue.equals(((UnsignedInteger64) pOther).iValue); - } - - /** - * Returns the value of this unsigned integer object as a byte. - * - * @return The byte value of this unsigned integer object. - */ - @Override - public byte byteValue() { - return this.iValue.byteValue(); - } - - /** - * Returns the value of this unsigned integer object as a - * double. - * - * @return Value of this unsigned integer object as a double. - */ - @Override - public double doubleValue() { - return this.iValue.doubleValue(); - } - - /** - * Returns the value of this unsigned integer object as a float - * . - * - * @return Value of this unsigned integer object as a float. - */ - @Override - public float floatValue() { - return this.iValue.floatValue(); - } - - /** - * Computes the hash code for this unsigned integer object. - * - * @return The integer representing the hash code for this unsigned integer - * object. - */ - @Override - public int hashCode() { - return this.iValue.hashCode(); - } - - /** - * Returns the value of this unsigned integer object as an int. - * - * @return Value of this unsigned integer object as an int. - */ - @Override - public int intValue() { - return this.iValue.intValue(); - } - - /** - * Returns the value of this unsigned integer object as a long. - * - * @return Value of this unsigned integer object as a long. - */ - @Override - public long longValue() { - return this.iValue.longValue(); - } - - /** - * Returns the value of this unsigned integer object as a short - * . - * - * @return Value of this unsigned integer object as a short. - */ - @Override - public short shortValue() { - return this.iValue.shortValue(); - } - - /** - * Returns the text representation of this unsigned integer object. - * - * @return Text representation of this unsigned integer. - */ - @Override - public String toString() { - return this.iValue.toString(); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-09 ebak Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al + * 2795671 2009-05-22 raman_arora Add Type to Comparable + * 2935258 2010-01-19 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + * 2973230 2010-03-19 blaschke-oss TCK: UnsignedInteger64.equals() does not handle null + * 2719 2013-12-10 blaschke-oss TCK: CIM APIs should not generate NullPointerException + * 2716 2013-12-11 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.math.BigInteger; + +//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013 +/** + * This class represents an UnsignedInteger64. A + * uint64 data type is defined by the (DMTF) CIM Infrastructure Specification (DSP004). + */ +public class UnsignedInteger64 extends Number implements Comparable { + private static final long serialVersionUID = -3734165689168941119L; + + /** + * The maximum value for an UnsignedInteger64. + */ + public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615"); + + /** + * The minimum value for an UnsignedInteger64. + */ + public static final BigInteger MIN_VALUE = BigInteger.ZERO; + + private BigInteger iValue; + + /** + * Sets the value of this integer object if it falls within the range of + * minimum and maximum values. + * + * @param pValue + * The integer. + * @throws NumberFormatException + * If the integer is out of range. + */ + private void setValue(BigInteger pValue) throws NumberFormatException { + if (pValue.compareTo(MAX_VALUE) > 0 || pValue.compareTo(MIN_VALUE) < 0) { + String msg = "uint64:" + pValue + " is out of range!"; + throw new NumberFormatException(msg); + } + this.iValue = pValue; + } + + /** + * Constructs an unsigned 64-bit integer object for the specified + * BigInteger. Only the lower 64 bits are considered. + * + * @param pValue + * The BigInteger to be represented as an unsigned + * 64-bit integer. + * @throws NumberFormatException + * If the number is out of range. + * @throws IllegalArgumentException + * If value is null. + */ + public UnsignedInteger64(BigInteger pValue) throws NumberFormatException { + if (pValue == null) throw new IllegalArgumentException("BigInteger value cannot be null!"); + setValue(pValue); + } + + /** + * Constructs an unsigned 64-bit integer object for the specified array of + * bytes. Only the lower 64 bits are considered. + * + * @param pValue + * The byte array to be represented as an unsigned 64-bit + * integer. + * @throws NumberFormatException + * If the number is out of range. + * @throws IllegalArgumentException + * If value is null. + */ + public UnsignedInteger64(byte[] pValue) throws NumberFormatException { + if (pValue == null) throw new IllegalArgumentException("byte[] value cannot be null!"); + setValue(new BigInteger(pValue)); + } + + /** + * Constructs an unsigned 64-bit integer object from the specified string. + * Only the lower 64 bits are considered. + * + * @param pValue + * The string to be represented as an unsigned 64-bit integer. + * @throws NumberFormatException + * If the number is out of range. + * @throws IllegalArgumentException + * If value is null. + */ + public UnsignedInteger64(String pValue) throws NumberFormatException { + if (pValue == null) throw new IllegalArgumentException("String value cannot be null!"); + setValue(new BigInteger(pValue)); + } + + /** + * Get the value as a BigInteger. + * + * @return BigInteger representation of this object. + */ + public BigInteger bigIntegerValue() { + return this.iValue; + } + + /** + * Compares this object with the specified object for order. Returns a + * negative integer, zero, or a positive integer as this object is less + * than, equal to, or greater than the specified object. + * + * @param pOther + * The Object to be compared. + * @return A negative integer, zero, or a positive integer as this object is + * less than, equal to, or greater than the specified object. + * @throws ClassCastException + * If the specified object's type prevents it from being + * compared to this Object. + * @throws IllegalArgumentException + * If value is null. + */ + public int compareTo(UnsignedInteger64 pOther) { + if (pOther == null) throw new IllegalArgumentException("Other UnsignedInteger64 cannot be null!"); + UnsignedInteger64 that = pOther; + int d = this.iValue.compareTo(that.iValue); + if (d == 0) return 0; + return d < 0 ? -1 : 1; + } + + /** + * Compares this object against the specified object. The result is + * true if and only if the argument is not null + * and is an UnsignedInteger64 object that represents the same + * value as this object. + * + * @param pOther + * The object to compare. + * @return true if the objects are the same; false + * otherwise. + */ + @Override + public boolean equals(Object pOther) { + if (!(pOther instanceof UnsignedInteger64)) return false; + return this.iValue.equals(((UnsignedInteger64) pOther).iValue); + } + + /** + * Returns the value of this unsigned integer object as a byte. + * + * @return The byte value of this unsigned integer object. + */ + @Override + public byte byteValue() { + return this.iValue.byteValue(); + } + + /** + * Returns the value of this unsigned integer object as a + * double. + * + * @return Value of this unsigned integer object as a double. + */ + @Override + public double doubleValue() { + return this.iValue.doubleValue(); + } + + /** + * Returns the value of this unsigned integer object as a float + * . + * + * @return Value of this unsigned integer object as a float. + */ + @Override + public float floatValue() { + return this.iValue.floatValue(); + } + + /** + * Computes the hash code for this unsigned integer object. + * + * @return The integer representing the hash code for this unsigned integer + * object. + */ + @Override + public int hashCode() { + return this.iValue.hashCode(); + } + + /** + * Returns the value of this unsigned integer object as an int. + * + * @return Value of this unsigned integer object as an int. + */ + @Override + public int intValue() { + return this.iValue.intValue(); + } + + /** + * Returns the value of this unsigned integer object as a long. + * + * @return Value of this unsigned integer object as a long. + */ + @Override + public long longValue() { + return this.iValue.longValue(); + } + + /** + * Returns the value of this unsigned integer object as a short + * . + * + * @return Value of this unsigned integer object as a short. + */ + @Override + public short shortValue() { + return this.iValue.shortValue(); + } + + /** + * Returns the text representation of this unsigned integer object. + * + * @return Text representation of this unsigned integer. + */ + @Override + public String toString() { + return this.iValue.toString(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/UnsignedInteger8.java b/src/main/java/org/metricshub/wbem/javax/cim/UnsignedInteger8.java similarity index 86% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/UnsignedInteger8.java rename to src/main/java/org/metricshub/wbem/javax/cim/UnsignedInteger8.java index 3382f78..fc72da7 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/cim/UnsignedInteger8.java +++ b/src/main/java/org/metricshub/wbem/javax/cim/UnsignedInteger8.java @@ -1,249 +1,244 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-09 ebak Make SBLIM client JSR48 compliant - * 1737123 2007-06-15 ebak Differences to JSR48 public review draft - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al - * 2795671 2009-05-22 raman_arora Add Type to Comparable - * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 - * 2944833 2010-02-08 blaschke-oss Need private setValue in UnsignedInteger8 - * 2973233 2010-03-19 blaschke-oss TCK: UnsignedIntegerNN.hashCode() not working - * 2719 2013-12-10 blaschke-oss TCK: CIM APIs should not generate NullPointerException - * 2716 2013-12-11 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V - */ - -package org.sentrysoftware.wbem.javax.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013 -/** - * This class represents an UnsignedInteger8. A uint8 - * data type is defined by the (DMTF) CIM - * Infrastructure Specification (DSP004). - */ -public class UnsignedInteger8 extends Number implements Comparable { - - private static final long serialVersionUID = 4392496278679167896L; - - /** - * The maximum possible value for an UnsignedInteger8. - */ - public static final short MAX_VALUE = 255; - - /** - * The minimum possible value for an UnsignedInteger8. - */ - public static final short MIN_VALUE = 0; - - private short iValue; - - /** - * Sets the value of this integer object if it falls within the range of - * minimum and maximum values. - * - * @param pValue - * The integer. - * @throws NumberFormatException - * If the integer is out of range. - */ - private void setValue(short pValue) throws NumberFormatException { - if (pValue > MAX_VALUE || pValue < MIN_VALUE) { - String msg = "uint8:" + pValue + " is out of range!"; - throw new NumberFormatException(msg); - } - this.iValue = pValue; - } - - /** - * Constructs an unsigned 8-bit integer object for the specified short - * value. Only the lower 8 bits are considered. - * - * @param pValue - * The short to be represented as an unsigned 8-bit integer - * object. - * @throws NumberFormatException - * If the number is out of range. - */ - public UnsignedInteger8(short pValue) throws NumberFormatException { - setValue(pValue); - } - - /** - * Constructs an unsigned 8-bit integer object for the specified string. - * Only the lower 8 bits are considered. - * - * @param pValue - * The string to be represented as an unsigned 8-bit integer. - * @throws NumberFormatException - * If the number is out of range. - * @throws IllegalArgumentException - * If value is null. - */ - public UnsignedInteger8(String pValue) throws NumberFormatException { - if (pValue == null) throw new IllegalArgumentException("String value cannot be null!"); - setValue(Short.parseShort(pValue)); - } - - /** - * Compares this object with the specified object for order. Returns a - * negative integer, zero, or a positive integer as this object is less - * than, equal to, or greater than the specified object. - * - * @param pOther - * The Object to be compared. - * @return A negative integer, zero, or a positive integer as this object is - * less than, equal to, or greater than the specified object. - * @throws ClassCastException - * If the specified object's type prevents it from being - * compared to this Object. - * @throws IllegalArgumentException - * If value is null. - */ - public int compareTo(UnsignedInteger8 pOther) { - if (pOther == null) throw new IllegalArgumentException( - "Other UnsignedInteger8 cannot be null!"); - UnsignedInteger8 that = pOther; - int d = this.iValue - that.iValue; - if (d == 0) return 0; - return d < 0 ? -1 : 1; - } - - /** - * Compares this object against the specified object. The result is true if - * and only if the argument is not null and is an - * UnsignedInteger8 object that represents the same value as - * this object. - * - * @param pObj - * The object to compare. - * @return true if the objects are the same; false - * otherwise. - */ - @Override - public boolean equals(Object pObj) { - if (!(pObj instanceof UnsignedInteger8)) return false; - return this.iValue == ((UnsignedInteger8) pObj).iValue; - } - - /** - * Returns the value of this unsigned integer object as a byte. - * - * @return The byte value of this unsigned integer object. - */ - @Override - public byte byteValue() { - return (byte) this.iValue; - } - - /** - * Returns the value of this unsigned integer object as a - * double. - * - * @return Value of this unsigned integer object as a double. - */ - @Override - public double doubleValue() { - return this.iValue; - } - - /** - * Returns the value of this unsigned integer object as a float - * . - * - * @return Value of this unsigned integer object as a float. - */ - @Override - public float floatValue() { - return this.iValue; - } - - /** - * Computes the hash code for this unsigned integer object. - * - * @return The integer representing the hash code for this unsigned integer - * object. - */ - @Override - public int hashCode() { - return Short.valueOf(this.iValue).hashCode(); - } - - /** - * Returns the value of this unsigned integer object as an int. - * - * @return Value of this unsigned integer object as an int. - */ - @Override - public int intValue() { - return this.iValue; - } - - /** - * Returns the value of this unsigned integer object as a long. - * - * @return Value of this unsigned integer object as a long. - */ - @Override - public long longValue() { - return this.iValue; - } - - /** - * Returns the value of this unsigned integer object as a short - * . - * - * @return Value of this unsigned integer object as a short. - */ - @Override - public short shortValue() { - return this.iValue; - } - - /** - * Returns the text representation of this unsigned integer object. - * - * @return Text representation of this unsigned integer. - */ - @Override - public String toString() { - return Short.toString(this.iValue); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-09 ebak Make SBLIM client JSR48 compliant + * 1737123 2007-06-15 ebak Differences to JSR48 public review draft + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al + * 2795671 2009-05-22 raman_arora Add Type to Comparable + * 2935258 2010-01-22 blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0 + * 2944833 2010-02-08 blaschke-oss Need private setValue in UnsignedInteger8 + * 2973233 2010-03-19 blaschke-oss TCK: UnsignedIntegerNN.hashCode() not working + * 2719 2013-12-10 blaschke-oss TCK: CIM APIs should not generate NullPointerException + * 2716 2013-12-11 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V + */ + +package org.metricshub.wbem.javax.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013 +/** + * This class represents an UnsignedInteger8. A uint8 + * data type is defined by the (DMTF) CIM + * Infrastructure Specification (DSP004). + */ +public class UnsignedInteger8 extends Number implements Comparable { + private static final long serialVersionUID = 4392496278679167896L; + + /** + * The maximum possible value for an UnsignedInteger8. + */ + public static final short MAX_VALUE = 255; + + /** + * The minimum possible value for an UnsignedInteger8. + */ + public static final short MIN_VALUE = 0; + + private short iValue; + + /** + * Sets the value of this integer object if it falls within the range of + * minimum and maximum values. + * + * @param pValue + * The integer. + * @throws NumberFormatException + * If the integer is out of range. + */ + private void setValue(short pValue) throws NumberFormatException { + if (pValue > MAX_VALUE || pValue < MIN_VALUE) { + String msg = "uint8:" + pValue + " is out of range!"; + throw new NumberFormatException(msg); + } + this.iValue = pValue; + } + + /** + * Constructs an unsigned 8-bit integer object for the specified short + * value. Only the lower 8 bits are considered. + * + * @param pValue + * The short to be represented as an unsigned 8-bit integer + * object. + * @throws NumberFormatException + * If the number is out of range. + */ + public UnsignedInteger8(short pValue) throws NumberFormatException { + setValue(pValue); + } + + /** + * Constructs an unsigned 8-bit integer object for the specified string. + * Only the lower 8 bits are considered. + * + * @param pValue + * The string to be represented as an unsigned 8-bit integer. + * @throws NumberFormatException + * If the number is out of range. + * @throws IllegalArgumentException + * If value is null. + */ + public UnsignedInteger8(String pValue) throws NumberFormatException { + if (pValue == null) throw new IllegalArgumentException("String value cannot be null!"); + setValue(Short.parseShort(pValue)); + } + + /** + * Compares this object with the specified object for order. Returns a + * negative integer, zero, or a positive integer as this object is less + * than, equal to, or greater than the specified object. + * + * @param pOther + * The Object to be compared. + * @return A negative integer, zero, or a positive integer as this object is + * less than, equal to, or greater than the specified object. + * @throws ClassCastException + * If the specified object's type prevents it from being + * compared to this Object. + * @throws IllegalArgumentException + * If value is null. + */ + public int compareTo(UnsignedInteger8 pOther) { + if (pOther == null) throw new IllegalArgumentException("Other UnsignedInteger8 cannot be null!"); + UnsignedInteger8 that = pOther; + int d = this.iValue - that.iValue; + if (d == 0) return 0; + return d < 0 ? -1 : 1; + } + + /** + * Compares this object against the specified object. The result is true if + * and only if the argument is not null and is an + * UnsignedInteger8 object that represents the same value as + * this object. + * + * @param pObj + * The object to compare. + * @return true if the objects are the same; false + * otherwise. + */ + @Override + public boolean equals(Object pObj) { + if (!(pObj instanceof UnsignedInteger8)) return false; + return this.iValue == ((UnsignedInteger8) pObj).iValue; + } + + /** + * Returns the value of this unsigned integer object as a byte. + * + * @return The byte value of this unsigned integer object. + */ + @Override + public byte byteValue() { + return (byte) this.iValue; + } + + /** + * Returns the value of this unsigned integer object as a + * double. + * + * @return Value of this unsigned integer object as a double. + */ + @Override + public double doubleValue() { + return this.iValue; + } + + /** + * Returns the value of this unsigned integer object as a float + * . + * + * @return Value of this unsigned integer object as a float. + */ + @Override + public float floatValue() { + return this.iValue; + } + + /** + * Computes the hash code for this unsigned integer object. + * + * @return The integer representing the hash code for this unsigned integer + * object. + */ + @Override + public int hashCode() { + return Short.valueOf(this.iValue).hashCode(); + } + + /** + * Returns the value of this unsigned integer object as an int. + * + * @return Value of this unsigned integer object as an int. + */ + @Override + public int intValue() { + return this.iValue; + } + + /** + * Returns the value of this unsigned integer object as a long. + * + * @return Value of this unsigned integer object as a long. + */ + @Override + public long longValue() { + return this.iValue; + } + + /** + * Returns the value of this unsigned integer object as a short + * . + * + * @return Value of this unsigned integer object as a short. + */ + @Override + public short shortValue() { + return this.iValue; + } + + /** + * Returns the text representation of this unsigned integer object. + * + * @return Text representation of this unsigned integer. + */ + @Override + public String toString() { + return Short.toString(this.iValue); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/cim/package.html b/src/main/java/org/metricshub/wbem/javax/cim/package.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/javax/cim/package.html rename to src/main/java/org/metricshub/wbem/javax/cim/package.html diff --git a/src/main/java/org/sentrysoftware/wbem/javax/wbem/CloseableIterator.java b/src/main/java/org/metricshub/wbem/javax/wbem/CloseableIterator.java similarity index 74% rename from src/main/java/org/sentrysoftware/wbem/javax/wbem/CloseableIterator.java rename to src/main/java/org/metricshub/wbem/javax/wbem/CloseableIterator.java index f1c3225..292a25d 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/wbem/CloseableIterator.java +++ b/src/main/java/org/metricshub/wbem/javax/wbem/CloseableIterator.java @@ -1,82 +1,78 @@ -/* - (C) Copyright IBM Corp. 2006, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, a.wolf-reber@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-11-08 lupusalex Make SBLIM client JSR48 compliant - * 1737141 2007-06-18 ebak Sync up with JSR48 evolution - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2912104 2009-12-10 blaschke-oss Sync up javax.wbem.* with JSR48 1.0.0 - * 2958941 2010-02-25 blaschke-oss Sync up javax.wbem.* javadoc with JSR48 1.0.0 - */ -package org.sentrysoftware.wbem.javax.wbem; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Iterator; - -//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 -/** - * A CloseableIterator is a subclass of Iterator that - * adds support for allowing the underlying implementation to serve up the - * elements as they become available. The methods hasNext() and - * next() may block while waiting for elements from the underlying - * implementation. Since next() or hasNext() can only - * throw runtime exceptions, if a consumer receives a runtime exception for one - * of these methods they must call getWBEMException() to get the - * actual WBEMException. - * - * @param - * Type parameter. - */ -public interface CloseableIterator extends Iterator { - - /** - * Closes the Iterator. This allows the underlying - * implementation to do any cleanup and disconnect from any source that it - * may be using. - */ - public void close(); - - /** - * If next() or hasNext() throws a - * RuntimeException, this method must be called to get the - * WBEMException. - * - * @return The WBEMException or null if one was not thrown. - */ - public WBEMException getWBEMException(); - -} +/* + (C) Copyright IBM Corp. 2006, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, a.wolf-reber@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-11-08 lupusalex Make SBLIM client JSR48 compliant + * 1737141 2007-06-18 ebak Sync up with JSR48 evolution + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2912104 2009-12-10 blaschke-oss Sync up javax.wbem.* with JSR48 1.0.0 + * 2958941 2010-02-25 blaschke-oss Sync up javax.wbem.* javadoc with JSR48 1.0.0 + */ +package org.metricshub.wbem.javax.wbem; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Iterator; + +//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 +/** + * A CloseableIterator is a subclass of Iterator that + * adds support for allowing the underlying implementation to serve up the + * elements as they become available. The methods hasNext() and + * next() may block while waiting for elements from the underlying + * implementation. Since next() or hasNext() can only + * throw runtime exceptions, if a consumer receives a runtime exception for one + * of these methods they must call getWBEMException() to get the + * actual WBEMException. + * + * @param + * Type parameter. + */ +public interface CloseableIterator extends Iterator { + /** + * Closes the Iterator. This allows the underlying + * implementation to do any cleanup and disconnect from any source that it + * may be using. + */ + void close(); + + /** + * If next() or hasNext() throws a + * RuntimeException, this method must be called to get the + * WBEMException. + * + * @return The WBEMException or null if one was not thrown. + */ + WBEMException getWBEMException(); +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/wbem/WBEMException.java b/src/main/java/org/metricshub/wbem/javax/wbem/WBEMException.java similarity index 81% rename from src/main/java/org/sentrysoftware/wbem/javax/wbem/WBEMException.java rename to src/main/java/org/metricshub/wbem/javax/wbem/WBEMException.java index 8ae2f20..dae941f 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/wbem/WBEMException.java +++ b/src/main/java/org/metricshub/wbem/javax/wbem/WBEMException.java @@ -1,388 +1,385 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-11-08 lupusalex Make SBLIM client JSR48 compliant - * 1715482 2007-05-10 lupusalex CIM_ERR_FAILED thrown when access denied - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al - * 2912104 2009-12-10 blaschke-oss Sync up javax.wbem.* with JSR48 1.0.0 - * 2958941 2010-02-25 blaschke-oss Sync up javax.wbem.* javadoc with JSR48 1.0.0 - * 2958990 2010-02-25 blaschke-oss Remove WBEMException.CIM_ERR_TYPE_MISMATCH - * 2959039 2010-02-25 blaschke-oss Fix WBEMException.toString() logic - * 3490032 2012-02-21 blaschke-oss TCK: WBEMException must validate error ID - * 3496301 2012-03-02 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final - * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods - */ - -package org.sentrysoftware.wbem.javax.wbem; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMInstance; - -//Sync'd against JSR48 1.0.0 javadoc (build 1.6.0_18) on Thu Mar 01 12:21:26 EST 2012 -/** - * WBEMException is returned when there is a WBEM Operations error. - * WBEMException includes the following:
      - *
        - *
      • ID - The ID of the exception
      • - *
      • Description - Brief description of the exception
      • - *
      • CIMInstance[] - Optional array of CIM_Error - * instances
      • - *
      - */ -public class WBEMException extends Exception { - - private static final long serialVersionUID = 1224653110826327234L; - - /** - * Access Denied Exception. Thrown when the principal is not authenticated - * or authorized. - */ - public static final int CIM_ERR_ACCESS_DENIED = 2; - - /** - * Element already exists. - */ - public static final int CIM_ERR_ALREADY_EXISTS = 11; - - /** - * Class has subclasses. The exception is thrown by the WBEM Server to - * disallow invalidation of the subclasses by the super class deletion. - * Clients must explicitly delete the subclasses first. The check for - * subclasses is made before the check for class instances. - */ - public static final int CIM_ERR_CLASS_HAS_CHILDREN = 8; - - /** - * Class has instances. The exception is thrown by the WBEM Server to - * disallow invalidation of the instances by the class deletion. Clients - * must explicitly delete the instances first. The check for subclasses is - * made before the check for class instances i.e. - * CIM_ERR_CLASS_HAS_CHILDREN is thrown before - * CIM_ERR_CLASS_HAS_INSTANCES - */ - public static final int CIM_ERR_CLASS_HAS_INSTANCES = 9; - - /** - * The WBEM Server does not support continuation on error. - */ - public static final int CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED = 26; - - /** - * General Exception. If no other error IDs match the error, this one should - * be returned. - */ - public static final int CIM_ERR_FAILED = 1; - - /** - * Using a filter in the enumeration is not supported by the WBEM Server. - */ - public static final int CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED = 25; - - /** - * Invalid class specified. For e.g. when one tries to add an instance for a - * class that does not exist. This error message uses one parameter, the - * invalid class name. - */ - public static final int CIM_ERR_INVALID_CLASS = 5; - - /** - * The enumeration identified by the specified context cannot be found, is - * in a closed state, does not exist, or is otherwise invalid. - */ - public static final int CIM_ERR_INVALID_ENUMERATION_CONTEXT = 21; - - /** - * Invalid namespace Exception. Thrown when the specified namespace does not - * exist. - */ - public static final int CIM_ERR_INVALID_NAMESPACE = 3; - - /** - * The specified operation timeout is not supported by the WBEM Server. - */ - public static final int CIM_ERR_INVALID_OPERATION_TIMEOUT = 22; - - /** - * Invalid parameter is passed to a method. This error message uses one - * parameter, the parameter which caused the exception. - */ - public static final int CIM_ERR_INVALID_PARAMETER = 4; - - /** - * Invalid query. This error message has two parameters, the invalid snippet - * of the query, and additional info with the actual error in the query. - */ - public static final int CIM_ERR_INVALID_QUERY = 15; - - /** - * The destination is invalid. - */ - public static final int CIM_ERR_INVALID_RESPONSE_DESTINATION = 19; - - /** - * The super class does not exist. - */ - public static final int CIM_ERR_INVALID_SUPERCLASS = 10; - - /** - * The method is not available. - */ - public static final int CIM_ERR_METHOD_NOT_AVAILABLE = 16; - - /** - * The method is not found. - */ - public static final int CIM_ERR_METHOD_NOT_FOUND = 17; - - /** - * The namespace is not empty. - */ - public static final int CIM_ERR_NAMESPACE_NOT_EMPTY = 20; - - /** - * The property does not exist in the class/instance being manipulated. This - * error message uses one parameter, the name of the property that does not - * exist. - */ - public static final int CIM_ERR_NO_SUCH_PROPERTY = 12; - - /** - * Element cannot be found. This error message uses one parameter, the - * element that cannot be found. - */ - public static final int CIM_ERR_NOT_FOUND = 6; - - /** - * The action is not supported. This can be thrown by a provider or the WBEM - * Server itself when it does not support a particular method. - */ - public static final int CIM_ERR_NOT_SUPPORTED = 7; - - /** - * The attempt to abandon a concurrent Pull operation on the same - * enumeration failed, the concurrent Pull operation proceeds normally. - */ - public static final int CIM_ERR_PULL_CANNOT_BE_ABANDONED = 24; - - /** - * The Pull operation has been abandoned due to execution of a concurrent - * CloseEnumeration operation on the same enumeration. - */ - public static final int CIM_ERR_PULL_HAS_BEEN_ABANDONED = 23; - - /** - * The requested query language is not recognized. This error message has - * one parameter, the invalid query language string. - */ - public static final int CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED = 14; - - /** - * The WBEM Server is in the process of shutting down and cannot process the - * operation at this time. - */ - public static final int CIM_ERR_SERVER_IS_SHUTTING_DOWN = 28; - - /** - * The WBEM Server has failed the operation based upon exceeding server - * limits. - */ - public static final int CIM_ERR_SERVER_LIMITS_EXCEEDED = 27; - - private static final String[] MESSAGES = new String[] { - /* 00 */"SUCCESS", - /* 01 */"CIM_ERR_FAILED", - /* 02 */"CIM_ERR_ACCESS_DENIED", - /* 03 */"CIM_ERR_INVALID_NAMESPACE", - /* 04 */"CIM_ERR_INVALID_PARAMETER", - /* 05 */"CIM_ERR_INVALID_CLASS", - /* 06 */"CIM_ERR_NOT_FOUND", - /* 07 */"CIM_ERR_NOT_SUPPORTED", - /* 08 */"CIM_ERR_CLASS_HAS_CHILDREN", - /* 09 */"CIM_ERR_CLASS_HAS_INSTANCES", - /* 10 */"CIM_ERR_INVALID_SUPERCLASS", - /* 11 */"CIM_ERR_ALREADY_EXISTS", - /* 12 */"CIM_ERR_NO_SUCH_PROPERTY", - /* 13 */null, - /* 14 */"CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED", - /* 15 */"CIM_ERR_INVALID_QUERY", - /* 16 */"CIM_ERR_METHOD_NOT_AVAILABLE", - /* 17 */"CIM_ERR_METHOD_NOT_FOUND", - /* 18 */null, - /* 19 */"CIM_ERR_INVALID_RESPONSE_DESTINATION", - /* 20 */"CIM_ERR_NAMESPACE_NOT_EMPTY", - /* 21 */"CIM_ERR_INVALID_ENUMERATION_CONTEXT", - /* 22 */"CIM_ERR_INVALID_OPERATION_TIMEOUT", - /* 23 */"CIM_ERR_PULL_HAS_BEEN_ABANDONED", - /* 24 */"CIM_ERR_PULL_CANNOT_BE_ABANDONED", - /* 25 */"CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED", - /* 26 */"CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED", - /* 27 */"CIM_ERR_SERVER_LIMITS_EXCEEDED", - /* 28 */"CIM_ERR_SERVER_IS_SHUTTING_DOWN" }; - - private int iErrorID; - - private CIMInstance[] iCimErrors; - - /** - * Constructs a new exception using the specified ID. The detailed message - * will be null. - * - * @param pID - * The Error ID to use. - * @throws IllegalArgumentException - * If the pID does not match one of the predefined messages. - */ - public WBEMException(int pID) { - this(pID, null, null, null); - } - - /** - * Constructs a new exception using the specified ID and detailed message. - * - * @param pID - * The error ID. - * @param pMessage - * The detailed message. - * @throws IllegalArgumentException - * If the pID does not match one of the predefined messages. - */ - public WBEMException(int pID, String pMessage) { - this(pID, pMessage, null, null); - } - - /** - * Constructs a new exception using the specified ID, detailed message and - * CIM_Error instances. - * - * @param pID - * The error ID. - * @param pMessage - * The detailed message. - * @param pErrors - * Array of CIM_Error instances. - * @throws IllegalArgumentException - * If the pID does not match one of the predefined messages. - */ - public WBEMException(int pID, String pMessage, CIMInstance[] pErrors) { - this(pID, pMessage, pErrors, null); - } - - /** - * Constructs a new exception using the specified ID, detailed message, - * CIM_Error instances and cause. - * - * @param pID - * The error ID. - * @param pMessage - * The detailed message. - * @param pErrors - * Array of CIM_Error instances. - * @param pCause - * Throwable cause. - * @throws IllegalArgumentException - * If the pID does not match one of the predefined messages. - */ - public WBEMException(int pID, String pMessage, CIMInstance[] pErrors, Throwable pCause) { - super(pMessage, pCause); - if (!isValidID(pID)) throw new IllegalArgumentException("Invalid error ID!"); - this.iErrorID = pID; - this.iCimErrors = pErrors; - } - - /** - * Constructs a new exception using the specified detailed message. The - * ID will be CIM_ERR_FAILED. - * - * @param pMessage - * The detailed message. - */ - public WBEMException(String pMessage) { - this(CIM_ERR_FAILED, pMessage, null, null); - } - - /** - * Get the CIM Error Instances. - * - * @return Any CIM Error instances associated with this exception; - * null if none. - */ - public CIMInstance[] getCIMErrors() { - return this.iCimErrors; - } - - /** - * Returns the ID of the error. - * - * @return The ID of the error. - */ - public int getID() { - return this.iErrorID; - } - - /** - * Prints out the ID and the optional detailed message. - * - * @return A String representation of the exception. - */ - @Override - public String toString() { - return "WBEMException: " + getCIMMessage() - + (super.getMessage() != null ? " (" + super.getMessage() + ")" : ""); - } - - /** - * Returns a string representation of the exception ID. - * - * @return A String representation of the exception ID. - */ - private String getCIMMessage() { - return isValidID(this.iErrorID) ? MESSAGES[this.iErrorID] : String.valueOf(this.iErrorID); - } - - /** - * Returns validity of error ID. - * - * @param pID - * The error ID. - * - * @return true if error ID is valid, false - * otherwise. - */ - private boolean isValidID(int pID) { - return pID >= 0 && pID < MESSAGES.length && MESSAGES[pID] != null; - } -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-11-08 lupusalex Make SBLIM client JSR48 compliant + * 1715482 2007-05-10 lupusalex CIM_ERR_FAILED thrown when access denied + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al + * 2912104 2009-12-10 blaschke-oss Sync up javax.wbem.* with JSR48 1.0.0 + * 2958941 2010-02-25 blaschke-oss Sync up javax.wbem.* javadoc with JSR48 1.0.0 + * 2958990 2010-02-25 blaschke-oss Remove WBEMException.CIM_ERR_TYPE_MISMATCH + * 2959039 2010-02-25 blaschke-oss Fix WBEMException.toString() logic + * 3490032 2012-02-21 blaschke-oss TCK: WBEMException must validate error ID + * 3496301 2012-03-02 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final + * 3565581 2012-09-07 blaschke-oss TCK: remove unnecessary overriding methods + */ + +package org.metricshub.wbem.javax.wbem; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMInstance; + +//Sync'd against JSR48 1.0.0 javadoc (build 1.6.0_18) on Thu Mar 01 12:21:26 EST 2012 +/** + * WBEMException is returned when there is a WBEM Operations error. + * WBEMException includes the following:
      + *
        + *
      • ID - The ID of the exception
      • + *
      • Description - Brief description of the exception
      • + *
      • CIMInstance[] - Optional array of CIM_Error + * instances
      • + *
      + */ +public class WBEMException extends Exception { + private static final long serialVersionUID = 1224653110826327234L; + + /** + * Access Denied Exception. Thrown when the principal is not authenticated + * or authorized. + */ + public static final int CIM_ERR_ACCESS_DENIED = 2; + + /** + * Element already exists. + */ + public static final int CIM_ERR_ALREADY_EXISTS = 11; + + /** + * Class has subclasses. The exception is thrown by the WBEM Server to + * disallow invalidation of the subclasses by the super class deletion. + * Clients must explicitly delete the subclasses first. The check for + * subclasses is made before the check for class instances. + */ + public static final int CIM_ERR_CLASS_HAS_CHILDREN = 8; + + /** + * Class has instances. The exception is thrown by the WBEM Server to + * disallow invalidation of the instances by the class deletion. Clients + * must explicitly delete the instances first. The check for subclasses is + * made before the check for class instances i.e. + * CIM_ERR_CLASS_HAS_CHILDREN is thrown before + * CIM_ERR_CLASS_HAS_INSTANCES + */ + public static final int CIM_ERR_CLASS_HAS_INSTANCES = 9; + + /** + * The WBEM Server does not support continuation on error. + */ + public static final int CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED = 26; + + /** + * General Exception. If no other error IDs match the error, this one should + * be returned. + */ + public static final int CIM_ERR_FAILED = 1; + + /** + * Using a filter in the enumeration is not supported by the WBEM Server. + */ + public static final int CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED = 25; + + /** + * Invalid class specified. For e.g. when one tries to add an instance for a + * class that does not exist. This error message uses one parameter, the + * invalid class name. + */ + public static final int CIM_ERR_INVALID_CLASS = 5; + + /** + * The enumeration identified by the specified context cannot be found, is + * in a closed state, does not exist, or is otherwise invalid. + */ + public static final int CIM_ERR_INVALID_ENUMERATION_CONTEXT = 21; + + /** + * Invalid namespace Exception. Thrown when the specified namespace does not + * exist. + */ + public static final int CIM_ERR_INVALID_NAMESPACE = 3; + + /** + * The specified operation timeout is not supported by the WBEM Server. + */ + public static final int CIM_ERR_INVALID_OPERATION_TIMEOUT = 22; + + /** + * Invalid parameter is passed to a method. This error message uses one + * parameter, the parameter which caused the exception. + */ + public static final int CIM_ERR_INVALID_PARAMETER = 4; + + /** + * Invalid query. This error message has two parameters, the invalid snippet + * of the query, and additional info with the actual error in the query. + */ + public static final int CIM_ERR_INVALID_QUERY = 15; + + /** + * The destination is invalid. + */ + public static final int CIM_ERR_INVALID_RESPONSE_DESTINATION = 19; + + /** + * The super class does not exist. + */ + public static final int CIM_ERR_INVALID_SUPERCLASS = 10; + + /** + * The method is not available. + */ + public static final int CIM_ERR_METHOD_NOT_AVAILABLE = 16; + + /** + * The method is not found. + */ + public static final int CIM_ERR_METHOD_NOT_FOUND = 17; + + /** + * The namespace is not empty. + */ + public static final int CIM_ERR_NAMESPACE_NOT_EMPTY = 20; + + /** + * The property does not exist in the class/instance being manipulated. This + * error message uses one parameter, the name of the property that does not + * exist. + */ + public static final int CIM_ERR_NO_SUCH_PROPERTY = 12; + + /** + * Element cannot be found. This error message uses one parameter, the + * element that cannot be found. + */ + public static final int CIM_ERR_NOT_FOUND = 6; + + /** + * The action is not supported. This can be thrown by a provider or the WBEM + * Server itself when it does not support a particular method. + */ + public static final int CIM_ERR_NOT_SUPPORTED = 7; + + /** + * The attempt to abandon a concurrent Pull operation on the same + * enumeration failed, the concurrent Pull operation proceeds normally. + */ + public static final int CIM_ERR_PULL_CANNOT_BE_ABANDONED = 24; + + /** + * The Pull operation has been abandoned due to execution of a concurrent + * CloseEnumeration operation on the same enumeration. + */ + public static final int CIM_ERR_PULL_HAS_BEEN_ABANDONED = 23; + + /** + * The requested query language is not recognized. This error message has + * one parameter, the invalid query language string. + */ + public static final int CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED = 14; + + /** + * The WBEM Server is in the process of shutting down and cannot process the + * operation at this time. + */ + public static final int CIM_ERR_SERVER_IS_SHUTTING_DOWN = 28; + + /** + * The WBEM Server has failed the operation based upon exceeding server + * limits. + */ + public static final int CIM_ERR_SERVER_LIMITS_EXCEEDED = 27; + + private static final String[] MESSAGES = new String[] { + /* 00 */"SUCCESS", + /* 01 */"CIM_ERR_FAILED", + /* 02 */"CIM_ERR_ACCESS_DENIED", + /* 03 */"CIM_ERR_INVALID_NAMESPACE", + /* 04 */"CIM_ERR_INVALID_PARAMETER", + /* 05 */"CIM_ERR_INVALID_CLASS", + /* 06 */"CIM_ERR_NOT_FOUND", + /* 07 */"CIM_ERR_NOT_SUPPORTED", + /* 08 */"CIM_ERR_CLASS_HAS_CHILDREN", + /* 09 */"CIM_ERR_CLASS_HAS_INSTANCES", + /* 10 */"CIM_ERR_INVALID_SUPERCLASS", + /* 11 */"CIM_ERR_ALREADY_EXISTS", + /* 12 */"CIM_ERR_NO_SUCH_PROPERTY", + /* 13 */null, + /* 14 */"CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED", + /* 15 */"CIM_ERR_INVALID_QUERY", + /* 16 */"CIM_ERR_METHOD_NOT_AVAILABLE", + /* 17 */"CIM_ERR_METHOD_NOT_FOUND", + /* 18 */null, + /* 19 */"CIM_ERR_INVALID_RESPONSE_DESTINATION", + /* 20 */"CIM_ERR_NAMESPACE_NOT_EMPTY", + /* 21 */"CIM_ERR_INVALID_ENUMERATION_CONTEXT", + /* 22 */"CIM_ERR_INVALID_OPERATION_TIMEOUT", + /* 23 */"CIM_ERR_PULL_HAS_BEEN_ABANDONED", + /* 24 */"CIM_ERR_PULL_CANNOT_BE_ABANDONED", + /* 25 */"CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED", + /* 26 */"CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED", + /* 27 */"CIM_ERR_SERVER_LIMITS_EXCEEDED", + /* 28 */"CIM_ERR_SERVER_IS_SHUTTING_DOWN" + }; + + private int iErrorID; + + private CIMInstance[] iCimErrors; + + /** + * Constructs a new exception using the specified ID. The detailed message + * will be null. + * + * @param pID + * The Error ID to use. + * @throws IllegalArgumentException + * If the pID does not match one of the predefined messages. + */ + public WBEMException(int pID) { + this(pID, null, null, null); + } + + /** + * Constructs a new exception using the specified ID and detailed message. + * + * @param pID + * The error ID. + * @param pMessage + * The detailed message. + * @throws IllegalArgumentException + * If the pID does not match one of the predefined messages. + */ + public WBEMException(int pID, String pMessage) { + this(pID, pMessage, null, null); + } + + /** + * Constructs a new exception using the specified ID, detailed message and + * CIM_Error instances. + * + * @param pID + * The error ID. + * @param pMessage + * The detailed message. + * @param pErrors + * Array of CIM_Error instances. + * @throws IllegalArgumentException + * If the pID does not match one of the predefined messages. + */ + public WBEMException(int pID, String pMessage, CIMInstance[] pErrors) { + this(pID, pMessage, pErrors, null); + } + + /** + * Constructs a new exception using the specified ID, detailed message, + * CIM_Error instances and cause. + * + * @param pID + * The error ID. + * @param pMessage + * The detailed message. + * @param pErrors + * Array of CIM_Error instances. + * @param pCause + * Throwable cause. + * @throws IllegalArgumentException + * If the pID does not match one of the predefined messages. + */ + public WBEMException(int pID, String pMessage, CIMInstance[] pErrors, Throwable pCause) { + super(pMessage, pCause); + if (!isValidID(pID)) throw new IllegalArgumentException("Invalid error ID!"); + this.iErrorID = pID; + this.iCimErrors = pErrors; + } + + /** + * Constructs a new exception using the specified detailed message. The + * ID will be CIM_ERR_FAILED. + * + * @param pMessage + * The detailed message. + */ + public WBEMException(String pMessage) { + this(CIM_ERR_FAILED, pMessage, null, null); + } + + /** + * Get the CIM Error Instances. + * + * @return Any CIM Error instances associated with this exception; + * null if none. + */ + public CIMInstance[] getCIMErrors() { + return this.iCimErrors; + } + + /** + * Returns the ID of the error. + * + * @return The ID of the error. + */ + public int getID() { + return this.iErrorID; + } + + /** + * Prints out the ID and the optional detailed message. + * + * @return A String representation of the exception. + */ + @Override + public String toString() { + return "WBEMException: " + getCIMMessage() + (super.getMessage() != null ? " (" + super.getMessage() + ")" : ""); + } + + /** + * Returns a string representation of the exception ID. + * + * @return A String representation of the exception ID. + */ + private String getCIMMessage() { + return isValidID(this.iErrorID) ? MESSAGES[this.iErrorID] : String.valueOf(this.iErrorID); + } + + /** + * Returns validity of error ID. + * + * @param pID + * The error ID. + * + * @return true if error ID is valid, false + * otherwise. + */ + private boolean isValidID(int pID) { + return pID >= 0 && pID < MESSAGES.length && MESSAGES[pID] != null; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/wbem/client/EnumerateResponse.java b/src/main/java/org/metricshub/wbem/javax/wbem/client/EnumerateResponse.java similarity index 76% rename from src/main/java/org/sentrysoftware/wbem/javax/wbem/client/EnumerateResponse.java rename to src/main/java/org/metricshub/wbem/javax/wbem/client/EnumerateResponse.java index e5ffc70..9bdf5f4 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/wbem/client/EnumerateResponse.java +++ b/src/main/java/org/metricshub/wbem/javax/wbem/client/EnumerateResponse.java @@ -1,118 +1,114 @@ -/* - (C) Copyright IBM Corp. 2006, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Ramandeep S Arora, IBM, arorar@us.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 2845211 2009-08-27 raman_arora Pull Enumeration Feature (SAX Parser) - * 2959264 2010-02-25 blaschke-oss Sync up javax.client.* javadoc with JSR48 1.0.0 - */ -package org.sentrysoftware.wbem.javax.wbem.client; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.wbem.CloseableIterator; - -//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 -/** - * This class is a container that stores the information from a Pull request. - * - * @param - * Type parameter. - */ -public class EnumerateResponse { - - private String iContext; - - private CloseableIterator iResponses; - - private boolean iEnd; - - /** - * Creates an EnumerateResponse. - * - * @param pContext - * The enumeration context returned. This will be used for any - * future calls for this particular enumeration. - * @param pResponses - * The results of the operation. - * @param pEnd - * true if this is the last of the results; - * false otherwise. - */ - public EnumerateResponse(String pContext, CloseableIterator pResponses, boolean pEnd) { - this.iContext = pContext; - this.iResponses = pResponses; - this.iEnd = pEnd; - } - - /** - * Get the context that can be used for a subsequent pull request. - * - * @return The Enumeration Context returned from the server. - */ - public String getContext() { - return this.iContext; - } - - /** - * Get the CloseableIterator for the returned CIM Elements. - * - * @return CloseableIterator for the elements returned. - */ - public CloseableIterator getResponses() { - return this.iResponses; - } - - /** - * If true, there are no more elements to be returned. - * - * @return true if this is the last of the results; - * false otherwise. - */ - public boolean isEnd() { - return this.iEnd; - } - - /* - This iterates over the responses. As a side effect, - CloseableIterator.hasNext() will not return anything after this is - called. - - public void debug() { CloseableIterator iterator = - this.getResponses(); while (iterator.hasNext()) - System.out.println(iterator.next()); - - System.out.println("Enum Context =" + this.getContext()); - System.out.println("Is End = " + this.isEnd()); - System.out.println("Done...\n"); } - */ -} +/* + (C) Copyright IBM Corp. 2006, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Ramandeep S Arora, IBM, arorar@us.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 2845211 2009-08-27 raman_arora Pull Enumeration Feature (SAX Parser) + * 2959264 2010-02-25 blaschke-oss Sync up javax.client.* javadoc with JSR48 1.0.0 + */ +package org.metricshub.wbem.javax.wbem.client; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.wbem.CloseableIterator; + +//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 +/** + * This class is a container that stores the information from a Pull request. + * + * @param + * Type parameter. + */ +public class EnumerateResponse { + private String iContext; + + private CloseableIterator iResponses; + + private boolean iEnd; + + /** + * Creates an EnumerateResponse. + * + * @param pContext + * The enumeration context returned. This will be used for any + * future calls for this particular enumeration. + * @param pResponses + * The results of the operation. + * @param pEnd + * true if this is the last of the results; + * false otherwise. + */ + public EnumerateResponse(String pContext, CloseableIterator pResponses, boolean pEnd) { + this.iContext = pContext; + this.iResponses = pResponses; + this.iEnd = pEnd; + } + + /** + * Get the context that can be used for a subsequent pull request. + * + * @return The Enumeration Context returned from the server. + */ + public String getContext() { + return this.iContext; + } + + /** + * Get the CloseableIterator for the returned CIM Elements. + * + * @return CloseableIterator for the elements returned. + */ + public CloseableIterator getResponses() { + return this.iResponses; + } + + /** + * If true, there are no more elements to be returned. + * + * @return true if this is the last of the results; + * false otherwise. + */ + public boolean isEnd() { + return this.iEnd; + } + /* + This iterates over the responses. As a side effect, + CloseableIterator.hasNext() will not return anything after this is + called. + + public void debug() { CloseableIterator iterator = + this.getResponses(); while (iterator.hasNext()) + System.out.println(iterator.next()); + + System.out.println("Enum Context =" + this.getContext()); + System.out.println("Is End = " + this.isEnd()); + System.out.println("Done...\n"); } + */ +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/wbem/client/PasswordCredential.java b/src/main/java/org/metricshub/wbem/javax/wbem/client/PasswordCredential.java similarity index 79% rename from src/main/java/org/sentrysoftware/wbem/javax/wbem/client/PasswordCredential.java rename to src/main/java/org/metricshub/wbem/javax/wbem/client/PasswordCredential.java index f5c90ee..be60024 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/wbem/client/PasswordCredential.java +++ b/src/main/java/org/metricshub/wbem/javax/wbem/client/PasswordCredential.java @@ -1,136 +1,132 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------------------------- - * 2006-04-25 ebak Initial commit - * 2006-04-27 wolfalex Full implementation - * 1737141 2007-06-18 ebak Sync up with JSR48 evolution - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2899389 2009-11-18 blaschke-oss Password maximum length of 16? - * 2959264 2010-02-25 blaschke-oss Sync up javax.client.* javadoc with JSR48 1.0.0 - * 2978722 2010-03-29 blaschke-oss PasswordCredential(char[]) constructor is wrong - * 3496301 2012-03-02 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final - */ - -package org.sentrysoftware.wbem.javax.wbem.client; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -//Sync'd against JSR48 1.0.0 javadoc (build 1.6.0_18) on Thu Mar 01 12:21:26 EST 2012 -/** - * PasswordCredential implements a password based credential. This - * is used with UserPrincipal. PasswordCredential - * includes the password and optionally the host information for which the - * password is used to authenticate the UserPrincipal. - * - */ -public class PasswordCredential extends Object { - - private String iPw; - - private String iHostname; - - /** - * Creates a PasswordCredential using the supplied password. - * - * @param pCredential - * The user login password in clear text. - * @throws IllegalArgumentException - * If the credential is null. - */ - public PasswordCredential(char[] pCredential) { - if (pCredential != null) { - this.iPw = new String(pCredential); - } else { - throw new IllegalArgumentException("Invalid password"); - } - } - - /** - * Creates a PasswordCredential using the supplied password. - * - * @param pCredential - * The user login password in clear text. - * @throws IllegalArgumentException - * If the credential is null. - */ - public PasswordCredential(String pCredential) { - if (pCredential != null) { - this.iPw = pCredential; - } else { - throw new IllegalArgumentException("Invalid password"); - } - } - - /** - * Creates a PasswordCredential using the supplied password and - * host name. - * - * @param pCredential - * The user login password in clear text. - * @param pHostname - * The host name information for which the password is used to - * authenticate. - * @throws IllegalArgumentException - * If the credential is null. - */ - public PasswordCredential(String pCredential, String pHostname) { - if (pCredential != null) { - this.iPw = pCredential; - } else { - throw new IllegalArgumentException("Invalid password"); - } - this.iHostname = pHostname; - } - - /** - * Get the host name for which the password is used to authenticate. - * - * @return The host name. - */ - public String getHostName() { - return this.iHostname; - } - - /** - * Return the user login password in clear text. - * - * @return The user login password. - */ - public char[] getUserPassword() { - return this.iPw.toCharArray(); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------------------------- + * 2006-04-25 ebak Initial commit + * 2006-04-27 wolfalex Full implementation + * 1737141 2007-06-18 ebak Sync up with JSR48 evolution + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2899389 2009-11-18 blaschke-oss Password maximum length of 16? + * 2959264 2010-02-25 blaschke-oss Sync up javax.client.* javadoc with JSR48 1.0.0 + * 2978722 2010-03-29 blaschke-oss PasswordCredential(char[]) constructor is wrong + * 3496301 2012-03-02 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final + */ + +package org.metricshub.wbem.javax.wbem.client; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +//Sync'd against JSR48 1.0.0 javadoc (build 1.6.0_18) on Thu Mar 01 12:21:26 EST 2012 +/** + * PasswordCredential implements a password based credential. This + * is used with UserPrincipal. PasswordCredential + * includes the password and optionally the host information for which the + * password is used to authenticate the UserPrincipal. + * + */ +public class PasswordCredential { + private String iPw; + + private String iHostname; + + /** + * Creates a PasswordCredential using the supplied password. + * + * @param pCredential + * The user login password in clear text. + * @throws IllegalArgumentException + * If the credential is null. + */ + public PasswordCredential(char[] pCredential) { + if (pCredential != null) { + this.iPw = new String(pCredential); + } else { + throw new IllegalArgumentException("Invalid password"); + } + } + + /** + * Creates a PasswordCredential using the supplied password. + * + * @param pCredential + * The user login password in clear text. + * @throws IllegalArgumentException + * If the credential is null. + */ + public PasswordCredential(String pCredential) { + if (pCredential != null) { + this.iPw = pCredential; + } else { + throw new IllegalArgumentException("Invalid password"); + } + } + + /** + * Creates a PasswordCredential using the supplied password and + * host name. + * + * @param pCredential + * The user login password in clear text. + * @param pHostname + * The host name information for which the password is used to + * authenticate. + * @throws IllegalArgumentException + * If the credential is null. + */ + public PasswordCredential(String pCredential, String pHostname) { + if (pCredential != null) { + this.iPw = pCredential; + } else { + throw new IllegalArgumentException("Invalid password"); + } + this.iHostname = pHostname; + } + + /** + * Get the host name for which the password is used to authenticate. + * + * @return The host name. + */ + public String getHostName() { + return this.iHostname; + } + + /** + * Return the user login password in clear text. + * + * @return The user login password. + */ + public char[] getUserPassword() { + return this.iPw.toCharArray(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/wbem/client/RoleCredential.java b/src/main/java/org/metricshub/wbem/javax/wbem/client/RoleCredential.java similarity index 80% rename from src/main/java/org/sentrysoftware/wbem/javax/wbem/client/RoleCredential.java rename to src/main/java/org/metricshub/wbem/javax/wbem/client/RoleCredential.java index 8ff1641..8a4a64d 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/wbem/client/RoleCredential.java +++ b/src/main/java/org/metricshub/wbem/javax/wbem/client/RoleCredential.java @@ -1,125 +1,121 @@ -/* - (C) Copyright IBM Corp. 2006, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------------------------- - * 2006-04-25 ebak Initial commit - * 1737141 2007-06-18 ebak Sync up with JSR48 evolution - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2899859 2009-11-18 blaschke-oss javax.wbem.client missing JSR48 credential/principal APIs - * 2959264 2010-02-25 blaschke-oss Sync up javax.client.* javadoc with JSR48 1.0.0 - * 2978722 2010-03-29 blaschke-oss PasswordCredential(char[]) constructor is wrong - */ - -package org.sentrysoftware.wbem.javax.wbem.client; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -//Sync'd against JSR48 1.0.0 (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 -/** - * RoleCredential implements a password based credential for a - * role. RoleCredential includes the credential (e.g. password) and - * optionally the host information for which the password is used to - * authenticate the RolePrincipal. RoleCredential - * should be used in conjunction with the RolePrincipal instance. - * This should only be used when a client is assuming a role on a WBEM Server - * that requires a password. - */ -public class RoleCredential extends Object { - - private String iCredential; - - private String iHostname; - - /** - * Creates a role credential using the supplied credential. - * - * @param pCredential - * The role credential in clear text. - * @throws IllegalArgumentException - * If the credential is null. - */ - public RoleCredential(char[] pCredential) throws IllegalArgumentException { - if (pCredential == null) throw new IllegalArgumentException("credential cannot be null!"); - this.iCredential = new String(pCredential); - } - - /** - * Creates a role credential using the supplied credential. - * - * @param pCredential - * The role credential in clear text. - * @throws IllegalArgumentException - * If the credential is null. - */ - public RoleCredential(String pCredential) throws IllegalArgumentException { - if (pCredential == null) throw new IllegalArgumentException("credential cannot be null!"); - this.iCredential = pCredential; - } - - /** - * Creates a role credential using the supplied credential and host name. - * - * @param pCredential - * The role credential in clear text. - * @param pHostname - * - The host name for this credential. - * @throws IllegalArgumentException - * If the credential is null. - */ - public RoleCredential(String pCredential, String pHostname) throws IllegalArgumentException { - if (pCredential == null) throw new IllegalArgumentException("credential cannot be null!"); - this.iCredential = pCredential; - this.iHostname = pHostname; - } - - /** - * Return the role credential in clear text. - * - * @return The role credential. - */ - public char[] getCredential() { - return this.iCredential.toCharArray(); - } - - /** - * Get the host name for which the password is used to authenticate. - * - * @return The host name. - */ - public String getHostName() { - return this.iHostname; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------------------------- + * 2006-04-25 ebak Initial commit + * 1737141 2007-06-18 ebak Sync up with JSR48 evolution + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2899859 2009-11-18 blaschke-oss javax.wbem.client missing JSR48 credential/principal APIs + * 2959264 2010-02-25 blaschke-oss Sync up javax.client.* javadoc with JSR48 1.0.0 + * 2978722 2010-03-29 blaschke-oss PasswordCredential(char[]) constructor is wrong + */ + +package org.metricshub.wbem.javax.wbem.client; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +//Sync'd against JSR48 1.0.0 (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 +/** + * RoleCredential implements a password based credential for a + * role. RoleCredential includes the credential (e.g. password) and + * optionally the host information for which the password is used to + * authenticate the RolePrincipal. RoleCredential + * should be used in conjunction with the RolePrincipal instance. + * This should only be used when a client is assuming a role on a WBEM Server + * that requires a password. + */ +public class RoleCredential { + private String iCredential; + + private String iHostname; + + /** + * Creates a role credential using the supplied credential. + * + * @param pCredential + * The role credential in clear text. + * @throws IllegalArgumentException + * If the credential is null. + */ + public RoleCredential(char[] pCredential) throws IllegalArgumentException { + if (pCredential == null) throw new IllegalArgumentException("credential cannot be null!"); + this.iCredential = new String(pCredential); + } + + /** + * Creates a role credential using the supplied credential. + * + * @param pCredential + * The role credential in clear text. + * @throws IllegalArgumentException + * If the credential is null. + */ + public RoleCredential(String pCredential) throws IllegalArgumentException { + if (pCredential == null) throw new IllegalArgumentException("credential cannot be null!"); + this.iCredential = pCredential; + } + + /** + * Creates a role credential using the supplied credential and host name. + * + * @param pCredential + * The role credential in clear text. + * @param pHostname + * - The host name for this credential. + * @throws IllegalArgumentException + * If the credential is null. + */ + public RoleCredential(String pCredential, String pHostname) throws IllegalArgumentException { + if (pCredential == null) throw new IllegalArgumentException("credential cannot be null!"); + this.iCredential = pCredential; + this.iHostname = pHostname; + } + + /** + * Return the role credential in clear text. + * + * @return The role credential. + */ + public char[] getCredential() { + return this.iCredential.toCharArray(); + } + + /** + * Get the host name for which the password is used to authenticate. + * + * @return The host name. + */ + public String getHostName() { + return this.iHostname; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/wbem/client/RolePrincipal.java b/src/main/java/org/metricshub/wbem/javax/wbem/client/RolePrincipal.java similarity index 75% rename from src/main/java/org/sentrysoftware/wbem/javax/wbem/client/RolePrincipal.java rename to src/main/java/org/metricshub/wbem/javax/wbem/client/RolePrincipal.java index 9dccf45..5523c43 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/wbem/client/RolePrincipal.java +++ b/src/main/java/org/metricshub/wbem/javax/wbem/client/RolePrincipal.java @@ -1,148 +1,145 @@ -/* - (C) Copyright IBM Corp. 2006, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------------------------- - * 2006-04-25 ebak Initial commit - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2899859 2009-11-18 blaschke-oss javax.wbem.client missing JSR48 credential/principal APIs - * 2959264 2010-02-25 blaschke-oss Sync up javax.client.* javadoc with JSR48 1.0.0 - */ - -package org.sentrysoftware.wbem.javax.wbem.client; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.security.Principal; - -//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 -/** - * RolePrincipal implements a Principal identity for a role. That - * is, it represents the role name to be assumed on a system. - * RolePrincipal includes the role and optionally the host - * information for which the role is used to authenticate. - */ -public class RolePrincipal extends Object implements Principal { - - private String iRole; - - private String iHost; - - /** - * This constructor accepts the role name. - * - * @param pRole - * The role name. - */ - public RolePrincipal(String pRole) { - this.iRole = pRole; - } - - /** - * This constructor accepts the role name and host name. - * - * @param pRole - * The role name. - * @param pHost - * The host name. - */ - public RolePrincipal(String pRole, String pHost) { - this.iRole = pRole; - this.iHost = pHost; - } - - /** - * The equals method checks if the specified principal is the - * same principal as this object. The principals are equal if the specified - * object is an instance of RolePrincipal and the user name and - * host name are the same. - * - * @param pObj - * The Principal to compare for equality. - * @return true if they are equal, otherwise false - * . - */ - @Override - public boolean equals(Object pObj) { - if (!(pObj instanceof RolePrincipal)) return false; - RolePrincipal that = (RolePrincipal) pObj; - return (this.iRole == null ? that.iRole == null : this.iRole.equalsIgnoreCase(that.iRole)) - && (this.iHost == null ? that.iHost == null : this.iHost - .equalsIgnoreCase(that.iHost)); - } - - /** - * Get the host for which the principal uses to authenticate. - * - * @return The host name. - */ - public String getHostName() { - return this.iHost; - } - - /** - * Return the name of this principal identity; that is, return the login - * name. - * - * @return The name of this principal identity. - * @see java.security.Principal#getName() - */ - public String getName() { - return this.iRole; - } - - /** - * The hashCode() method returns an integer hash code to - * represent this principal. - * - * @return An integer hash code representing the principal. - */ - @Override - public int hashCode() { - return this.iRole == null ? 0 : this.iRole.hashCode(); - } - - /** - * The toString() method returns a string representation of the - * principal suitable for displaying in messages. It should not be used for - * making authorization checks. - * - * @return A printable string form of the role principal. - */ - @Override - public String toString() { - return this.iRole; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------------------------- + * 2006-04-25 ebak Initial commit + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2899859 2009-11-18 blaschke-oss javax.wbem.client missing JSR48 credential/principal APIs + * 2959264 2010-02-25 blaschke-oss Sync up javax.client.* javadoc with JSR48 1.0.0 + */ + +package org.metricshub.wbem.javax.wbem.client; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.security.Principal; + +//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 +/** + * RolePrincipal implements a Principal identity for a role. That + * is, it represents the role name to be assumed on a system. + * RolePrincipal includes the role and optionally the host + * information for which the role is used to authenticate. + */ +public class RolePrincipal implements Principal { + private String iRole; + + private String iHost; + + /** + * This constructor accepts the role name. + * + * @param pRole + * The role name. + */ + public RolePrincipal(String pRole) { + this.iRole = pRole; + } + + /** + * This constructor accepts the role name and host name. + * + * @param pRole + * The role name. + * @param pHost + * The host name. + */ + public RolePrincipal(String pRole, String pHost) { + this.iRole = pRole; + this.iHost = pHost; + } + + /** + * The equals method checks if the specified principal is the + * same principal as this object. The principals are equal if the specified + * object is an instance of RolePrincipal and the user name and + * host name are the same. + * + * @param pObj + * The Principal to compare for equality. + * @return true if they are equal, otherwise false + * . + */ + @Override + public boolean equals(Object pObj) { + if (!(pObj instanceof RolePrincipal)) return false; + RolePrincipal that = (RolePrincipal) pObj; + return ( + (this.iRole == null ? that.iRole == null : this.iRole.equalsIgnoreCase(that.iRole)) && + (this.iHost == null ? that.iHost == null : this.iHost.equalsIgnoreCase(that.iHost)) + ); + } + + /** + * Get the host for which the principal uses to authenticate. + * + * @return The host name. + */ + public String getHostName() { + return this.iHost; + } + + /** + * Return the name of this principal identity; that is, return the login + * name. + * + * @return The name of this principal identity. + * @see java.security.Principal#getName() + */ + public String getName() { + return this.iRole; + } + + /** + * The hashCode() method returns an integer hash code to + * represent this principal. + * + * @return An integer hash code representing the principal. + */ + @Override + public int hashCode() { + return this.iRole == null ? 0 : this.iRole.hashCode(); + } + + /** + * The toString() method returns a string representation of the + * principal suitable for displaying in messages. It should not be used for + * making authorization checks. + * + * @return A printable string form of the role principal. + */ + @Override + public String toString() { + return this.iRole; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/wbem/client/UserPrincipal.java b/src/main/java/org/metricshub/wbem/javax/wbem/client/UserPrincipal.java similarity index 78% rename from src/main/java/org/sentrysoftware/wbem/javax/wbem/client/UserPrincipal.java rename to src/main/java/org/metricshub/wbem/javax/wbem/client/UserPrincipal.java index 4dd3804..ebc9e4c 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/wbem/client/UserPrincipal.java +++ b/src/main/java/org/metricshub/wbem/javax/wbem/client/UserPrincipal.java @@ -1,166 +1,162 @@ -/* - (C) Copyright IBM Corp. 2006, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------------------------- - * 2006-04-25 ebak Initial commit - * 2006-04-27 wolfalex Full implementation - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2899859 2009-11-18 blaschke-oss javax.wbem.client missing JSR48 credential/principal APIs - * 2959264 2010-02-25 blaschke-oss Sync up javax.client.* javadoc with JSR48 1.0.0 - */ -package org.sentrysoftware.wbem.javax.wbem.client; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.security.Principal; - -//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 -/** - * UserPrincipal implements a Principal identity for a client user - * identity that authenticates with a username and password. In other words, it - * represents the user's login identity on the remote system. - * UserPrincipal includes the username and optionally the host - * information for which the username is used to authenticate. - */ -public class UserPrincipal extends Object implements Principal { - - private String iUserName; - - private String iHostName; - - /** - * This constructor accepts the user name. - * - * @param pUserName - * The user login name. - * @throws IllegalArgumentException - * If the is null. - */ - public UserPrincipal(String pUserName) throws IllegalArgumentException { - if (pUserName == null) throw new IllegalArgumentException("userName is null!"); - this.iUserName = pUserName; - } - - /** - * This constructor accepts the user name and host name. - * - * @param pUserName - * The user login name. - * @param pHostName - * The host name for this principal. - * @throws IllegalArgumentException - * If the pUserName is null. - */ - public UserPrincipal(String pUserName, String pHostName) throws IllegalArgumentException { - if (pUserName == null) throw new IllegalArgumentException("userName is null!"); - this.iUserName = pUserName; - this.iHostName = pHostName; - } - - /** - * The equals method checks if the specified object is the same - * principal as this object. The principals are equal if the specified - * object is an instance of UserPrincipal and the user name and - * authentication host name are the same. - * - * @param pOtherPrincipal - * Principal instance to compare for equality. - * @return true if the object are equal; false - * otherwise. - */ - @Override - public boolean equals(Object pOtherPrincipal) { - if (!(pOtherPrincipal instanceof UserPrincipal)) return false; - UserPrincipal that = (UserPrincipal) pOtherPrincipal; - return (this.iUserName == null ? that.iUserName == null : this.iUserName - .equalsIgnoreCase(that.iUserName)) - && (this.iHostName == null ? that.iHostName == null : this.iHostName - .equalsIgnoreCase(that.iHostName)); - } - - /** - * Return the host name associated with this principal. - * - * @return The host name. - */ - public String getHostName() { - return this.iHostName; - } - - /** - * Return the name of this principal identity; that is, return the login - * name. - * - * @return The name of this principal identity. - * @see java.security.Principal#getName() - */ - public String getName() { - return this.iUserName; - } - - /** - * Return the principal's login user name. - * - * @return The user login name. - */ - public String getUserName() { - return this.iUserName; - } - - /** - * The hashCode method returns an integer hash code to - * represent this principal. It can be used to test for non-equality, or as - * an index key in a hash table. - * - * @return An integer hash code representing the principal. - */ - @Override - public int hashCode() { - return this.iUserName != null ? this.iUserName.hashCode() : 0; - } - - /** - * The toString method returns a string representation of the - * principal suitable for displaying in messages. It should not be used for - * making authorization checks, however. - * - * @return A printable string form of the principal identity. - */ - @Override - public String toString() { - return this.iUserName; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------------------------- + * 2006-04-25 ebak Initial commit + * 2006-04-27 wolfalex Full implementation + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2899859 2009-11-18 blaschke-oss javax.wbem.client missing JSR48 credential/principal APIs + * 2959264 2010-02-25 blaschke-oss Sync up javax.client.* javadoc with JSR48 1.0.0 + */ +package org.metricshub.wbem.javax.wbem.client; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.security.Principal; + +//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 +/** + * UserPrincipal implements a Principal identity for a client user + * identity that authenticates with a username and password. In other words, it + * represents the user's login identity on the remote system. + * UserPrincipal includes the username and optionally the host + * information for which the username is used to authenticate. + */ +public class UserPrincipal implements Principal { + private String iUserName; + + private String iHostName; + + /** + * This constructor accepts the user name. + * + * @param pUserName + * The user login name. + * @throws IllegalArgumentException + * If the is null. + */ + public UserPrincipal(String pUserName) throws IllegalArgumentException { + if (pUserName == null) throw new IllegalArgumentException("userName is null!"); + this.iUserName = pUserName; + } + + /** + * This constructor accepts the user name and host name. + * + * @param pUserName + * The user login name. + * @param pHostName + * The host name for this principal. + * @throws IllegalArgumentException + * If the pUserName is null. + */ + public UserPrincipal(String pUserName, String pHostName) throws IllegalArgumentException { + if (pUserName == null) throw new IllegalArgumentException("userName is null!"); + this.iUserName = pUserName; + this.iHostName = pHostName; + } + + /** + * The equals method checks if the specified object is the same + * principal as this object. The principals are equal if the specified + * object is an instance of UserPrincipal and the user name and + * authentication host name are the same. + * + * @param pOtherPrincipal + * Principal instance to compare for equality. + * @return true if the object are equal; false + * otherwise. + */ + @Override + public boolean equals(Object pOtherPrincipal) { + if (!(pOtherPrincipal instanceof UserPrincipal)) return false; + UserPrincipal that = (UserPrincipal) pOtherPrincipal; + return ( + (this.iUserName == null ? that.iUserName == null : this.iUserName.equalsIgnoreCase(that.iUserName)) && + (this.iHostName == null ? that.iHostName == null : this.iHostName.equalsIgnoreCase(that.iHostName)) + ); + } + + /** + * Return the host name associated with this principal. + * + * @return The host name. + */ + public String getHostName() { + return this.iHostName; + } + + /** + * Return the name of this principal identity; that is, return the login + * name. + * + * @return The name of this principal identity. + * @see java.security.Principal#getName() + */ + public String getName() { + return this.iUserName; + } + + /** + * Return the principal's login user name. + * + * @return The user login name. + */ + public String getUserName() { + return this.iUserName; + } + + /** + * The hashCode method returns an integer hash code to + * represent this principal. It can be used to test for non-equality, or as + * an index key in a hash table. + * + * @return An integer hash code representing the principal. + */ + @Override + public int hashCode() { + return this.iUserName != null ? this.iUserName.hashCode() : 0; + } + + /** + * The toString method returns a string representation of the + * principal suitable for displaying in messages. It should not be used for + * making authorization checks, however. + * + * @return A printable string form of the principal identity. + */ + @Override + public String toString() { + return this.iUserName; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/wbem/client/WBEMClient.java b/src/main/java/org/metricshub/wbem/javax/wbem/client/WBEMClient.java similarity index 91% rename from src/main/java/org/sentrysoftware/wbem/javax/wbem/client/WBEMClient.java rename to src/main/java/org/metricshub/wbem/javax/wbem/client/WBEMClient.java index 6bf4b2d..882e8c9 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/wbem/client/WBEMClient.java +++ b/src/main/java/org/metricshub/wbem/javax/wbem/client/WBEMClient.java @@ -1,2254 +1,2369 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-11-08 lupusalex Make SBLIM client JSR48 compliant - * 1686000 2007-04-19 ebak modifyInstance() missing from WBEMClient - * 1737141 2007-06-18 ebak Sync up with JSR48 evolution - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2845211 2009-08-27 raman_arora Pull Enumeration Feature (SAX Parser) - * 2858933 2009-10-12 raman_arora JSR48 new APIs: associatorClasses & associatorInstances - * 2886829 2009-11-18 raman_arora JSR48 new APIs: referenceClasses & referenceInstances - * 2959586 2010-03-01 blaschke-oss Sync up WBEMClient javadoc with JSR48 1.0.0 - * 2961592 2010-03-01 blaschke-oss Remove WBEMClient.setLocales() UnsupportedOperationException - * 3496301 2012-03-02 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final - * 3496343 2012-03-02 blaschke-oss JSR48 1.0.0: deprecate WBEMClient associators and references - * 3514537 2012-04-03 blaschke-oss TCK: execQueryInstances requires boolean, not Boolean - * 3521131 2012-04-24 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final II - * 3521328 2012-04-25 blaschke-oss JSR48 1.0.0: remove WBEMClient associators and references - * 3525657 2012-05-10 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final III - * 3555752 2012-09-13 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final IV - * 2716 2013-12-11 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V - */ - -package org.sentrysoftware.wbem.javax.wbem.client; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Locale; - -import org.sentrysoftware.wbem.javax.cim.CIMArgument; -import org.sentrysoftware.wbem.javax.cim.CIMClass; -import org.sentrysoftware.wbem.javax.cim.CIMInstance; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import org.sentrysoftware.wbem.javax.cim.CIMQualifierType; -import org.sentrysoftware.wbem.javax.cim.UnsignedInteger32; -import org.sentrysoftware.wbem.javax.cim.UnsignedInteger64; -import javax.security.auth.Subject; -import org.sentrysoftware.wbem.javax.wbem.CloseableIterator; -import org.sentrysoftware.wbem.javax.wbem.WBEMException; - -//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013 -/** - * The WBEMClient interface is used to invoke WBEM operations - * against a WBEM Server. A WBEMClient implementation can be - * retrieved from the WBEMClientFactory specifying the protocol to - * be used. - * - * @see WBEMClientFactory - */ -public interface WBEMClient { - - /** - * Enumerates CIM classes that are associated to a specified source CIM - * class. - * - * @param pObjectName - * CIMObjectPath defining the source CIM Class whose - * associated classes are to be returned. The - * pObjectName shall include the host, namespace and - * object name. The keys shall not be populated. - * @param pAssociationClass - * This string shall contain a valid CIM Association class name - * or be null. It filters the classes returned to - * contain only classes associated to the source Object via this - * CIM Association class or one of its subclasses. - * @param pResultClass - * This string shall either contain a valid CIM Class name or be - * null. It filters the classes returned to contain - * only the classes of this class name or one of its subclasses. - * @param pRole - * This string shall either contain a valid Property name or be - * null. It filters the classes returned to contain - * only classes associated to the source class via an Association - * class in which the source class plays the specified - * role. (i.e. the Property name in the Association class that - * refers to the source class matches this value) For - * example, if "Antecedent" is specified, then only Associations - * in which the source class is the "Antecedent" reference are - * examined. - * @param pResultRole - * This string shall either contain a valid Property name or be - * null. It filters the classes returned to contain - * only classes associated to the source class via an Association - * class in which the class returned plays the specified - * role. (i.e. the Property name in the Association class that - * refers to the class returned matches this value) - * @param pIncludeQualifiers - * If true, all Qualifiers for each class (including - * Qualifiers on the Object and on any returned Properties) MUST - * be included in the classes returned. If false, no - * Qualifiers are present in each class returned. - * @param pIncludeClassOrigin - * The class origin attribute is the name of the class that first - * defined the property or method. If true, the - * class origin attribute shall be present for each property and - * method on all classes returned. If false, the - * class origin shall not be present. - * @param pPropertyList - * An array of property names used to filter what is contained in - * the classes returned. Each CIMClass returned - * shall only contain elements for the properties of the names - * specified. Duplicate and invalid property names are ignored - * and the request is otherwise processed normally. An empty - * array indicates that no properties should be included in the - * classes returned. A null value indicates that all - * properties should be contained in the classes returned. - * @return If successful, a CloseableIterator containing zero - * or more CIMClasses meeting the specified criteria - * are returned. - * @throws UnsupportedOperationException - * If the client implementation (or protocol) does not support - * the operation. - * @throws WBEMException - * If unsuccessful, one of the following status codes shall be - * returned along with zero or more instances of - * CIM_Error. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized - * or otherwise incorrect parameters) - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public CloseableIterator associatorClasses(CIMObjectPath pObjectName, - String pAssociationClass, String pResultClass, String pRole, String pResultRole, - boolean pIncludeQualifiers, boolean pIncludeClassOrigin, String[] pPropertyList) - throws WBEMException; - - /** - * Enumerates CIM Instances associated to a specified source CIM Instance. - * - * @param pObjectName - * CIMObjectPath defining the source CIM Instance - * whose associated instances are to be returned. The - * pObjectName must contain the host, namespace, - * object name and keys for the instance. - * @param pAssociationClass - * This string shall either contain a valid CIM Association class - * name or be null. It filters the instances - * returned to contain only instances associated to the source - * instance via this CIM Association class or one of its - * subclasses. - * @param pResultClass - * This string shall either contain a valid CIM Class name or be - * null. It filters the instances returned to - * contain only the instances of this Class name or one of its - * subclasses. - * @param pRole - * This string shall either contain a valid Property name or be - * null. It filters the Objects returned to contain - * only Objects associated to the source Object via an - * Association class in which the source Object plays the - * specified role. (i.e. the Property name in the Association - * class that refers to the source Object matches this - * value) If "Antecedent" is specified, then only Associations in - * which the source Object is the "Antecedent" reference are - * examined. - * @param pResultRole - * This string shall either contain a valid Property name or be - * null. It filters the instances returned to - * contain only instances associated to the source instance via - * an Association class in which the instance returned - * plays the specified role. (i.e. the Property name in the - * Association class that refers to the instance returned - * matches this value) For example, if "Dependent" is specified, - * then only Associations in which the instance returned is the - * "Dependent" reference are examined. - * @param pIncludeClassOrigin - * The class origin attribute is the name of the class that first - * defined the property. If true, the class origin - * attribute may be present for each property on all instances - * returned, even if requested the server may ignore the request - * and not return the class origin. If false, the - * class origin shall not be present. - * @param pPropertyList - * An array of property names used to filter what is contained in - * the Objects returned. Each CIMInstance returned - * only contains elements for the properties of the names - * specified. Duplicate and invalid property names are ignored - * and the request is otherwise processed normally. An empty - * array indicates that no properties should be included in the - * instances returned. A null value indicates that - * all properties should be contained in the instances returned. - * @return If successful, a CloseableIterator containing zero - * or more CIMInstances meeting the specified criteria - * is returned. - * @throws WBEMException - * If unsuccessful, one of the following status codes shall be - * returned along with zero or more instances of - * CIM_Error. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized - * or otherwise incorrect parameters) - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public CloseableIterator associatorInstances(CIMObjectPath pObjectName, - String pAssociationClass, String pResultClass, String pRole, String pResultRole, - boolean pIncludeClassOrigin, String[] pPropertyList) throws WBEMException; - - /** - * Enumerates the CIMObjectPaths of CIM Objects that are - * associated to a particular source CIM Object. If the source Object is a - * CIM Class, then a CloseableIterator of - * CIMObjectPath s of the classes associated to the source - * Object is returned. If the source Object is a CIM Instance, then a - * CloseableIterator of CIMObjectPaths of the - * CIMInstance objects associated to the source Object is - * returned. - * - * @param pObjectName - * CIMObjectPath defining the source CIM Object - * whose associated Objects are to be returned. This argument may - * contain either a Class name or the modelpath of an Instance. - * (i.e. Keys populated) - * @param pAssociationClass - * This string MUST either contain a valid CIM Association class - * name or be null. It filters the Objects returned - * to contain only Objects associated to the source Object via - * this CIM Association class or one of its subclasses. - * @param pResultClass - * This string MUST either contain a valid CIM Class name or be - * null. It filters the Objects returned to contain - * only the Objects of this Class name or one of its subclasses. - * @param pRole - * This string MUST either contain a valid Property name or be - * null. It filters the Objects returned to contain - * only Objects associated to the source Object via an - * Association class in which the source Object plays the - * specified role. (i.e. the Property name in the Association - * class that refers to the source Object matches this - * value) If "Antecedent" is specified, then only Associations in - * which the source Object is the "Antecedent" reference are - * examined. - * @param pResultRole - * This string MUST either contain a valid Property name or be - * null. It filters the Objects returned to contain - * only Objects associated to the source Object via an - * Association class in which the Object returned plays - * the specified role. (i.e. the Property name in the Association - * class that refers to the Object returned matches this - * value) If "Dependent" is specified, then only Associations in - * which the Object returned is the "Dependent" reference are - * examined. - * @return If successful, a CloseableIterator containing zero - * or more CIMObjectPath objects of the CIM Classes or - * CIM Instances meeting the specified criteria is returned. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized - * or otherwise incorrect parameters) - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public CloseableIterator associatorNames(CIMObjectPath pObjectName, - String pAssociationClass, String pResultClass, String pRole, String pResultRole) - throws WBEMException; - - /** - * associatorPaths shall start an enumeration session for - * traversing associations starting from the instance defined in the - * pInstancePath parameter using any specified filtering - * criteria and return zero or more CIMObjectPath objects. - * - * @param pInstancePath - * The CIMObjectPath for the instance for which the - * enumeration is to be performed. - * @param pAssociationClass - * This string MUST either contain a valid CIM Association class - * name or be null. It filters the Objects returned - * to contain only Objects associated to the source Object via - * this CIM Association class or one of its subclasses. - * @param pResultClass - * This string MUST either contain a valid CIM Class name or be - * null. It filters the Objects returned to contain - * only the Objects of this Class name or one of its subclasses. - * @param pRole - * This string MUST either contain a valid Property name or be - * null. It filters the Objects returned to contain - * only Objects associated to the source Object via an - * Association class in which the source Object plays the - * specified role. (i.e. the Property name in the Association - * class that refers to the source Object matches this - * value) If "Antecedent" is specified, then only Associations in - * which the source Object is the "Antecedent" reference are - * examined. - * @param pResultRole - * This string MUST either contain a valid Property name or be - * null. It filters the Objects returned to contain - * only Objects associated to the source Object via an - * Association class in which the Object returned plays - * the specified role. (i.e. the Property name in the Association - * class that refers to the Object returned matches this - * value) If "Dependent" is specified, then only Associations in - * which the Object returned is the "Dependent" reference are - * examined. - * @param pFilterQueryLanguage - * The pFilterQueryLanguage represents the query - * language for the pFilterQuery argument. This must - * be left null if a pFilterQuery is - * not supplied. If the implementation does not support the query - * language specified, the - * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error shall - * be returned. If the implementation does not support filtered - * enumerations, the - * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error - * shall be returned. - * @param pFilterQuery - * The pFilterQuery specifies a query in the form of - * the query language specified by the - * pFilterQueryLanguage parameter. If this value is - * not null, the pFilterQueryLanguage - * parameter must be non-null. This value shall act - * as an additional filter on the result set. If the - * implementation does not support the query language specified, - * the CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error - * shall be returned. If the implementation does not support - * filtered enumerations, the - * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error - * shall be returned. - * @param pTimeout - * This input parameter determines the minimum time the CIM - * server shall maintain the open enumeration session after the - * last Open or Pull operation (unless the enumeration session is - * closed). If the operation timeout is exceeded, the - * implementation may close the enumeration session at any time, - * releasing any resources allocated to the enumeration session. - * A pTimeout of 0 means that there is no operation - * timeout. That is, the enumeration session is never closed - * based on time. If pTimeout is null, - * the implementation shall choose an operation timeout. All - * other values for pTimeout specify the operation - * timeout in seconds. A implementation may restrict the set of - * allowable values for pTimeout. Specifically, the - * implementation may not allow 0 (no timeout). If the specified - * value is not an allowable value, the implementation shall - * return failure with the status code - * CIM_ERR_INVALID_OPERATION_TIMEOUT. - * @param pContinueOnError - * If true, requests that the operation resume when - * an error is received. If a implementation does not support - * continuation on error and pContinueOnError is - * true, it shall throw a WBEMException - * with the status code - * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED. If a - * implementation supports continuation on error and - * pContinueOnError is true, the - * enumeration session shall remain open when a Pull operation - * fails, and any subsequent successful Pull operations shall - * return the set of elements that would have been returned if - * the failing Pull operations were successful. This behavior is - * subject to the consistency rules defined for pulled - * enumerations. If pContinueOnError is - * false, the enumeration session shall be closed - * when either the operation completes successfully or when a - * WBEMExcetpion is thrown. - * @param pMaxObjects - * Defines the maximum number of elements that this Open - * operation can return. The implementation may deliver any - * number of elements up to pMaxObjects but shall - * not deliver more than pMaxObjects elements. An - * implementation may choose to never return any elements during - * an Open operation, regardless of the value of - * pMaxObjects. Note that a CIM client can use a - * pMaxObjects value of 0 to specify that it does - * not want to retrieve any instances in the Open operation. - * @return The return value of a successful Open operation is an array of - * enumerated elements with a number of entries from 0 up to a - * maximum defined by pMaxObjects. These entries meet - * the criteria defined in the Open operation. Note that returning - * no entries in the array does not imply that the enumeration - * session is exhausted. Client must evaluate the - * EnumerateResponse.isEnd() to determine if there are - * more elements. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_SERVER_IS_SHUTTING_DOWN - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_OPERATION_TIMEOUT - * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED - * CIM_ERR_INVALID_PARAMETER - * CIM_ERR_NOT_FOUND (the source instance was not found) - * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED - * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED - * CIM_ERR_INVALID_QUERY - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public EnumerateResponse associatorPaths(CIMObjectPath pInstancePath, - String pAssociationClass, String pResultClass, String pRole, String pResultRole, - String pFilterQueryLanguage, String pFilterQuery, UnsignedInteger32 pTimeout, - boolean pContinueOnError, UnsignedInteger32 pMaxObjects) throws WBEMException; - - /** - * associators shall start an enumeration session for - * traversing associations starting from the instance defined in the - * pInstancePath parameter using any specified filtering - * criteria and return zero or more CIMInstance objects. - * - * @param pInstancePath - * The CIMObjectPath for the instance for which the - * enumeration is to be performed. - * @param pAssociationClass - * This string MUST either contain a valid CIM Association class - * name or be null. It filters the Objects returned - * to contain only Objects associated to the source Object via - * this CIM Association class or one of its subclasses. - * @param pResultClass - * This string MUST either contain a valid CIM Class name or be - * null. It filters the Objects returned to contain - * only the Objects of this Class name or one of its subclasses. - * @param pRole - * This string MUST either contain a valid Property name or be - * null. It filters the Objects returned to contain - * only Objects associated to the source Object via an - * Association class in which the source Object plays the - * specified role. (i.e. the Property name in the Association - * class that refers to the source Object matches this - * value) If "Antecedent" is specified, then only Associations in - * which the source Object is the "Antecedent" reference are - * examined. - * @param pResultRole - * This string MUST either contain a valid Property name or be - * null. It filters the Objects returned to contain - * only Objects associated to the source Object via an - * Association class in which the Object returned plays - * the specified role. (i.e. the Property name in the Association - * class that refers to the Object returned matches this - * value) If "Dependent" is specified, then only Associations in - * which the Object returned is the "Dependent" reference are - * examined. - * @param pIncludeClassOrigin - * The class origin attribute is the name of the class that first - * defined the property. If true, the class origin - * attribute may be present for each property on all instances - * returned, even if requested the server may ignore the request - * and not return the class origin. If false, the - * class origin shall not be present. - * @param pPropertyList - * An array of property names used to filter what is contained in - * the Objects returned. Each CIMClass or - * CIMInstance returned only contains elements for - * the properties of the names specified. Duplicate and invalid - * property names are ignored and the request is otherwise - * processed normally. An empty array indicates that no - * properties should be included in the Objects returned. A - * null value indicates that all properties should - * be contained in the Objects returned. NOTE: Properties - * should not be specified in this parameter unless a non- - * null value is specified in the - * pResultClass parameter. - * @param pFilterQueryLanguage - * The pFilterQueryLanguage represents the query - * language for the pFilterQuery argument. This must - * be left null if a filterQuery is not supplied. If - * the implementation does not support the query language - * specified, the - * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error shall - * be returned. If the implementation does not support filtered - * enumerations, the - * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error - * shall be returned. - * @param pFilterQuery - * The pFilterQuery specifies a query in the form of - * the query language specified by the - * pFilterQueryLanguage parameter. If this value is - * not null, the pFilterQueryLanguage - * parameter must be non-null. This value shall act - * as an additional filter on the result set. If the - * implementation does not support the query language specified, - * the CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error - * shall be returned. If the implementation does not support - * filtered enumerations, the - * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error - * shall be returned. - * @param pTimeout - * This input parameter determines the minimum time the CIM - * server shall maintain the open enumeration session after the - * last Open or Pull operation (unless the enumeration session is - * closed). If the operation timeout is exceeded, the - * implementation may close the enumeration session at any time, - * releasing any resources allocated to the enumeration session. - * A pTimeout of 0 means that there is no operation - * timeout. That is, the enumeration session is never closed - * based on time. If pTimeout is null, - * the implementation shall choose an operation timeout. All - * other values for pTimeout specify the operation - * timeout in seconds. A implementation may restrict the set of - * allowable values for pTimeout. Specifically, the - * implementation may not allow 0 (no timeout). If the specified - * value is not an allowable value, the implementation shall - * return failure with the status code - * CIM_ERR_INVALID_OPERATION_TIMEOUT. - * @param pContinueOnError - * If true, requests that the operation resume when - * an error is received. If a implementation does not support - * continuation on error and pContinueOnError is - * true, it shall throw a WBEMException - * with the status code - * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED. If a - * implementation supports continuation on error and - * pContinueOnError is true, the - * enumeration session shall remain open when a Pull operation - * fails, and any subsequent successful Pull operations shall - * return the set of elements that would have been returned if - * the failing Pull operations were successful. This behavior is - * subject to the consistency rules defined for pulled - * enumerations. If pContinueOnError is - * false, the enumeration session shall be closed - * when either the operation completes successfully or when a - * WBEMExcetpion is thrown. - * @param pMaxObjects - * Defines the maximum number of elements that this Open - * operation can return. The implementation may deliver any - * number of elements up to pMaxObjects but shall - * not deliver more than pMaxObjects elements. An - * implementation may choose to never return any elements during - * an Open operation, regardless of the value of - * pMaxObjects. Note that a CIM client can use a - * pMaxObjects value of 0 to specify that it does - * not want to retrieve any instances in the Open operation. - * @return The return value of a successful Open operation is an array of - * enumerated elements with a number of entries from 0 up to a - * maximum defined by pMaxObjects. These entries meet - * the criteria defined in the Open operation. Note that returning - * no entries in the array does not imply that the enumeration - * session is exhausted. Client must evaluate the - * EnumerateResponse.isEnd() to determine if there are - * more elements. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_SERVER_IS_SHUTTING_DOWN - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_OPERATION_TIMEOUT - * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED - * CIM_ERR_INVALID_PARAMETER - * CIM_ERR_NOT_FOUND (The source instance was not found) - * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED - * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED - * CIM_ERR_INVALID_QUERY - * CIM_ERR_FAILED (Some other unspecified error occurred) - * - */ - public EnumerateResponse associators(CIMObjectPath pInstancePath, - String pAssociationClass, String pResultClass, String pRole, String pResultRole, - boolean pIncludeClassOrigin, String[] pPropertyList, String pFilterQueryLanguage, - String pFilterQuery, UnsignedInteger32 pTimeout, boolean pContinueOnError, - UnsignedInteger32 pMaxObjects) throws WBEMException; - - /** - * Closes the WBEMClient session. - */ - public void close(); - - /** - * closeEnumeration shall close an enumeration session that has - * been previously started but not yet completed. Clients should always use - * this method when an enumeration session has been started and the client - * does not retrieve all the results. If a client has started an enumeration - * session and retrieves all the results until the - * EnumerationResponse.isEnd() is true, this method shall not - * be called. - * - * @param pPath - * The CIMObjectPath representing the namespace to - * be used. - * @param pContext - * The enumeration context to close. - * @throws WBEMException - */ - public void closeEnumeration(CIMObjectPath pPath, String pContext) throws WBEMException; - - /** - * Create a CIM class. The namespace from the - * CIMClass.getObjectPath() shall be used. - * - * @param pClass - * The CIMClass to be created. - * @throws UnsupportedOperationException - * If the client implementation (or protocol) does not support - * the operation. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized - * or otherwise incorrect parameters) - * CIM_ERR_ALREADY_EXISTS (the CIM Class already exists) - * CIM_ERR_INVALID_SUPERCLASS (the putative CIM Class declares a - * non-existent superclass) - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public void createClass(CIMClass pClass) throws WBEMException; - - /** - * Create a CIM Instance. The namespace from the - * CIMInstance.getObjectPath() shall be used. The keys of the - * CIMInstance may be modified by the implementation and the - * client must use the returned object path to determine the name of the - * instance. It is possible for a client to leave keys of instances empty/ - * null and the provider can fill them in. This is - * implementation specific unless specified by a CIM Schema or in a DMTF - * Profile. - * - * @param pInstance - * The CIMInstance to be created. - * @return CIMObjectPath of the instance created. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED (provider does not support this method) - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (for this method) - * CIM_ERR_INVALID_CLASS (in this namespace) - * CIM_ERR_ALREADY_EXISTS - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public CIMObjectPath createInstance(CIMInstance pInstance) throws WBEMException; - - /** - * Deletes the CIM class for the object specified by the CIM object path. - * - * @param pPath - * The CIMObjectPath identifying the namespace and - * class name to delete. - * @throws UnsupportedOperationException - * If the client implementation (or protocol) does not support - * the operation. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized - * or otherwise incorrect parameters) - * CIM_ERR_NOT_FOUND (the CIM Class to be deleted does not exist) - * CIM_ERR_CLASS_HAS_CHILDREN (the CIM Class has one or more subclasses - * which cannot be deleted) - * CIM_ERR_CLASS_HAS_INSTANCES (the CIM Class has one or more instances - * which cannot be deleted) - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public void deleteClass(CIMObjectPath pPath) throws WBEMException; - - /** - * Delete the CIM instance specified by the CIM object path. - * - * @param pPath - * The object path of the instance to be deleted. It must include - * all of the keys. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED (provider does not support this method) - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (for this method) - * CIM_ERR_INVALID_CLASS (in this namespace) - * CIM_ERR_NOT_FOUND (if the instance does not exist) - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public void deleteInstance(CIMObjectPath pPath) throws WBEMException; - - /** - * Delete a CIM Qualifier type. - * - * @param pPath - * The CIMObjectPath identifying the name and - * namespace of the CIM qualifier type to delete. - * @throws UnsupportedOperationException - * If the client implementation (or protocol) does not support - * the operation. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (for this method) - * CIM_ERR_NOT_FOUND (the Qualifier did not exist) - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public void deleteQualifierType(CIMObjectPath pPath) throws WBEMException; - - /** - * Enumerate CIM Classes. - * - * @param pPath - * The object path of the class to be enumerated. Only the - * namespace and object name should be populated. If the object - * name is set to an empty string (i.e. ""), then all base - * classes in the target namespace are returned. - * @param pDeep - * If true, the classes returned shall include - * subclasses. If false, the classes returned shall - * not include subclasses. - * @param pLocalOnly - * If true, only elements (properties, methods and - * qualifiers) defined in, or overridden in the class are - * included in the response. If false, all elements - * of the class definition are returned. - * @param pIncludeQualifiers - * If true, all Qualifiers for each Class and its - * elements (properties, methods, references) are included. If - * false, no Qualifiers are present in the classes - * returned. - * @param pIncludeClassOrigin - * The class origin attribute is the name of the class that first - * defined the property or method. If true, the - * class origin attribute shall be present for each property and - * method on all returned CIMClasses. If - * false, the class origin shall not be present. - * @return A CloseableIterator of CIMClasses. - * @throws UnsupportedOperationException - * If the client implementation (or protocol) does not support - * the operation. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized - * or otherwise incorrect parameters) - * CIM_ERR_INVALID_CLASS (the CIM Class that is the basis for this - * enumeration does not exist) - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public CloseableIterator enumerateClasses(CIMObjectPath pPath, boolean pDeep, - boolean pLocalOnly, boolean pIncludeQualifiers, boolean pIncludeClassOrigin) - throws WBEMException; - - /** - * Enumerate the names of CIM Classes. - * - * @param pPath - * The CIMObjectPath identifying the class to be - * enumerated. If the class name in the object path specified is - * an empty string (i.e. ""), all base classes in the target - * namespace are returned. Note that only the namespace and the - * name components should be populated. - * @param pDeep - * If true, the enumeration returned shall contain - * the names of all classes derived from the class being - * enumerated. If false, the enumeration returned - * contains only the names of the first level children of the - * class. - * @return A CloseableIterator of CIMObjectPaths. - * @throws UnsupportedOperationException - * If the client implementation (or protocol) does not support - * the operation. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized - * or otherwise incorrect parameters) - * CIM_ERR_INVALID_CLASS (the CIM Class that is the basis for this - * enumeration does not exist) - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public CloseableIterator enumerateClassNames(CIMObjectPath pPath, boolean pDeep) - throws WBEMException; - - /** - * Enumerate the names of the instances for a specified class. The names of - * all subclass instances are returned. - * - * @param pPath - * The CIMObjectPath identifying the class whose - * instances are to be enumerated. Only the namespace and class - * name components are used. All other information (e.g. Keys) is - * ignored. - * @return CloseabelIterator of CIMObjectPaths. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED (provider does not support this method) - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (for this method) - * CIM_ERR_INVALID_CLASS (in this namespace) - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public CloseableIterator enumerateInstanceNames(CIMObjectPath pPath) - throws WBEMException; - - /** - * enumerateInstancePaths shall enumerate the instances of the - * specified class in pClassPath and return zero or more - * CIMObjectPaths. - * - * @param pClassPath - * The CIMObjectPath for the class for which the - * enumeration is to be performed. - * @param pFilterQueryLanguage - * The pFilterQueryLanguage represents the query - * language for the pFilterQuery argument. This must - * be left null if a pFilterQuery is - * not supplied. If the implementation does not support the query - * language specified, the - * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error shall - * be returned. If the implementation does not support filtered - * enumerations, the - * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error - * shall be returned. - * @param pFilterQuery - * The pFilterQuery specifies a query in the form of - * the query language specified by the - * pFilterQueryLanguage parameter. If this value is - * not null, the pFilterQueryLanguage - * parameter must be non-null. This value shall act - * as an additional filter on the result set. If the - * implementation does not support the query language specified, - * the CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error - * shall be returned. If the implementation does not support - * filtered enumerations, the - * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error - * shall be returned. - * @param pTimeout - * This input parameter determines the minimum time the CIM - * server shall maintain the open enumeration session after the - * last Open or Pull operation (unless the enumeration session is - * closed). If the operation timeout is exceeded, the - * implementation may close the enumeration session at any time, - * releasing any resources allocated to the enumeration session. - * A pTimeout of 0 means that there is no operation - * timeout. That is, the enumeration session is never closed - * based on time. If pTimeout is null, - * the implementation shall choose an operation timeout. All - * other values for pTimeout specify the operation - * timeout in seconds. A implementation may restrict the set of - * allowable values for pTimeout. Specifically, the - * implementation may not allow 0 (no timeout). If the specified - * value is not an allowable value, the implementation shall - * return failure with the status code - * CIM_ERR_INVALID_OPERATION_TIMEOUT. - * @param pContinueOnError - * If true, requests that the operation resume when - * an error is received. If a implementation does not support - * continuation on error and pContinueOnError is - * true, it shall throw a WBEMException - * with the status code - * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED. If a - * implementation supports continuation on error and - * pContinueOnError is true, the - * enumeration session shall remain open when a Pull operation - * fails, and any subsequent successful Pull operations shall - * return the set of elements that would have been returned if - * the failing Pull operations were successful. This behavior is - * subject to the consistency rules defined for pulled - * enumerations. If pContinueOnError is - * false, the enumeration session shall be closed - * when either the operation completes successfully or when a - * WBEMExcetpion is thrown. - * @param pMaxObjects - * Defines the maximum number of elements that this Open - * operation can return. The implementation may deliver any - * number of elements up to pMaxObjects but shall - * not deliver more than pMaxObjects elements. An - * implementation may choose to never return any elements during - * an Open operation, regardless of the value of - * pMaxObjects. Note that a CIM client can use a - * pMaxObjects value of 0 to specify that it does - * not want to retrieve any instances in the Open operation. - * @return The return value of a successful Open operation is an array of - * enumerated elements with a number of entries from 0 up to a - * maximum defined by pMaxObjects. These entries meet - * the criteria defined in the Open operation. Note that returning - * no entries in the array does not imply that the enumeration - * session is exhausted. Client must evaluate the - * EnumerateResponse.isEnd() to determine if there are - * more elements. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_SERVER_IS_SHUTTING_DOWN - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_OPERATION_TIMEOUT - * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED - * CIM_ERR_INVALID_PARAMETER - * CIM_ERR_INVALID_CLASS (the source class does not exist) - * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED - * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED - * CIM_ERR_INVALID_QUERY - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public EnumerateResponse enumerateInstancePaths(CIMObjectPath pClassPath, - String pFilterQueryLanguage, String pFilterQuery, UnsignedInteger32 pTimeout, - boolean pContinueOnError, UnsignedInteger32 pMaxObjects) throws WBEMException; - - /** - * Enumerate the instances of a class. The instances of all subclasses are - * also returned. - * - * @param pPath - * The object path of the class to be enumerated. Only the - * namespace and class name components are used. Any other - * information (e.g. Keys) is ignored. - * @param pDeep - * If true, this specifies that, for each returned - * Instance of the Class, all properties of the Instance must be - * present (subject to constraints imposed by the other - * parameters), including any which were added by subclassing the - * specified Class. If false, each returned Instance - * includes only properties defined for the specified Class in - * path. - * @param pLocalOnly - * If true, only properties that were instantiated - * in the instance are returned. WBEM Servers may ignore this - * parameter and return all properties. - * @param pIncludeClassOrigin - * The class origin attribute is the name of the class that first - * defined the property. If true, the class origin - * attribute may be present for each property on all returned - * CIMInstances, even if requested the server may ignore the - * request and not return the class origin. If false - * , the class origin shall not be present. - * @param pPropertyList - * An array of property names used to filter what is contained in - * the instances returned. Each instance returned only contains - * elements for the properties of the names specified. Duplicate - * and invalid property names are ignored and the request is - * otherwise processed normally. An empty array indicates that no - * properties should be returned. A null value indicates - * that all properties should be returned. - * @return A CloseableIterator of CIMInstances. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (for this method) - * CIM_ERR_INVALID_CLASS (in this namespace) - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public CloseableIterator enumerateInstances(CIMObjectPath pPath, boolean pDeep, - boolean pLocalOnly, boolean pIncludeClassOrigin, String[] pPropertyList) - throws WBEMException; - - /** - * enumerateInstances shall enumerate the instances of the - * specified class in pClassPath and return zero or more - * CIMInstances. - * - * @param pClassPath - * The CIMObjectPath for the class for which the - * enumeration is to be performed. - * @param pDeepInheritance - * If true, this specifies that, for each returned - * Instance of the Class, all properties of the Instance must be - * present (subject to constraints imposed by the other - * parameters), including any which were added by subclassing the - * specified Class. If false, each returned Instance - * includes only properties defined for the specified Class in - * path. - * @param pIncludeClassOrigin - * The class origin attribute is the name of the class that first - * defined the property. If true, the class origin - * attribute may be present for each property on all instances - * returned, even if requested the server may ignore the request - * and not return the class origin. If false, the - * class origin shall not be present. - * @param pPropertyList - * An array of property names used to filter what is contained in - * the Objects returned. Each CIMInstance returned - * only contains elements for the properties of the names - * specified. Duplicate and invalid property names are ignored - * and the request is otherwise processed normally. An empty - * array indicates that no properties should be included in the - * Objects returned. A null value indicates that all - * properties should be contained in the Objects returned. - * @param pFilterQueryLanguage - * The pFilterQueryLanguage represents the query - * language for the pFilterQuery argument. This must - * be left null if a pFilterQuery is - * not supplied. If the implementation does not support the query - * language specified, the - * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error shall - * be returned. If the implementation does not support filtered - * enumerations, the - * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error - * shall be returned. - * @param pFilterQuery - * The pFilterQuery specifies a query in the form of - * the query language specified by the - * pFilterQueryLanguage parameter. If this value is - * not null, the pFilterQueryLanguage - * parameter must be non-null. This value shall act - * as an additional filter on the result set. If the - * implementation does not support the query language specified, - * the CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error - * shall be returned. If the implementation does not support - * filtered enumerations, the - * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error - * shall be returned. - * @param pTimeout - * This input parameter determines the minimum time the CIM - * server shall maintain the open enumeration session after the - * last Open or Pull operation (unless the enumeration session is - * closed). If the operation timeout is exceeded, the - * implementation may close the enumeration session at any time, - * releasing any resources allocated to the enumeration session. - * A pTimeout of 0 means that there is no operation - * timeout. That is, the enumeration session is never closed - * based on time. If pTimeout is null, - * the implementation shall choose an operation timeout. All - * other values for pTimeout specify the operation - * timeout in seconds. A implementation may restrict the set of - * allowable values for pTimeout. Specifically, the - * implementation may not allow 0 (no timeout). If the specified - * value is not an allowable value, the implementation shall - * return failure with the status code - * CIM_ERR_INVALID_OPERATION_TIMEOUT. - * @param pContinueOnError - * If true, requests that the operation resume when - * an error is received. If a implementation does not support - * continuation on error and pContinueOnError is - * true, it shall throw a WBEMException - * with the status code - * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED. If a - * implementation supports continuation on error and - * pContinueOnError is true, the - * enumeration session shall remain open when a Pull operation - * fails, and any subsequent successful Pull operations shall - * return the set of elements that would have been returned if - * the failing Pull operations were successful. This behavior is - * subject to the consistency rules defined for pulled - * enumerations. If pContinueOnError is - * false, the enumeration session shall be closed - * when either the operation completes successfully or when a - * WBEMExcetpion is thrown. - * @param pMaxObjects - * Defines the maximum number of elements that this Open - * operation can return. The implementation may deliver any - * number of elements up to pMaxObjects but shall - * not deliver more than pMaxObjects elements. An - * implementation may choose to never return any elements during - * an Open operation, regardless of the value of - * pMaxObjects. Note that a CIM client can use a - * pMaxObjects value of 0 to specify that it does - * not want to retrieve any instances in the Open operation. - * @return The return value of a successful Open operation is an array of - * enumerated elements with a number of entries from 0 up to a - * maximum defined by pMaxObjects. These entries meet - * the criteria defined in the Open operation. Note that returning - * no entries in the array does not imply that the enumeration - * session is exhausted. Client must evaluate the - * EnumerateResponse.isEnd() to determine if there are - * more elements. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_SERVER_IS_SHUTTING_DOWN - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_OPERATION_TIMEOUT - * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED - * CIM_ERR_INVALID_PARAMETER - * CIM_ERR_INVALID_CLASS (the source class does not exist) - * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED - * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED - * CIM_ERR_INVALID_QUERY - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public EnumerateResponse enumerateInstances(CIMObjectPath pClassPath, - boolean pDeepInheritance, boolean pIncludeClassOrigin, String[] pPropertyList, - String pFilterQueryLanguage, String pFilterQuery, UnsignedInteger32 pTimeout, - boolean pContinueOnError, UnsignedInteger32 pMaxObjects) throws WBEMException; - - /** - * Enumerates the CIM Qualifier types for a specific namespace. - * - * @param pPath - * The CIMObjectPath identifying the namespace whose - * qualifier types are to be enumerated. - * @return A CloseableIterator of CIMQualifierType - * s. - * @throws UnsupportedOperationException - * If the client implementation (or protocol) does not support - * the operation. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized - * or otherwise incorrect parameters) - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public CloseableIterator> enumerateQualifierTypes(CIMObjectPath pPath) - throws WBEMException; - - /** - * enumerationCount provides an estimated count of the total - * number of objects in an open enumeration session represented by an - * enumeration context. - * - * @param pPath - * The namespace for the enumeration context. - * @param pEnumerationContext - * The enumeration context to count. - * @return The estimated number of objects. - * @throws UnsupportedOperationException - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_SERVER_IS_SHUTTING_DOWN - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER - * CIM_ERR_INVALID_ENUMERATION_CONTEXT - * CIM_ERR_SERVER_LIMITS_EXCEEDED - * CIM_ERR_FAILED - * - * - */ - public UnsignedInteger64 enumerationCount(CIMObjectPath pPath, String pEnumerationContext) - throws WBEMException; - - /** - * execQuery shall execute a query to retrieve objects. - * - * @param pPath - * CIMObjectPath identifying the class to query. - * Only the namespace and class name components are used. All - * other information (e.g. Keys) is ignored. - * @param pQuery - * A string containing the text of the query. - * @param pQueryLanguage - * A string that identifies the query language to use to parse - * the query string specified. - * @return A CloseableIterator of CIMInstances. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED (provider does not support this method) - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized - * or otherwise incorrect parameters) - * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED (the requested query language - * is not recognized) - * CIM_ERR_INVALID_QUERY (the query is not a valid query in the specified - * query language) - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public CloseableIterator execQuery(CIMObjectPath pPath, String pQuery, - String pQueryLanguage) throws WBEMException; - - /** - * execQueryInstances shall execute a query to retrieve - * instances. - * - * @param pObjectName - * The CIMObjectPath representing the namespace to - * be used. - * @param pFilterQuery - * The pFilterQuery specifies a query in the form of - * the query language specified by the - * pFilterQueryLanguage parameter. If this value is - * not null, the pFilterQueryLanguage - * parameter must be non-null. This value shall act - * as an additional filter on the result set. If the - * implementation does not support the query language specified, - * the CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error - * shall be returned. If the implementation does not support - * filtered enumerations, the - * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error - * shall be returned. - * @param pFilterQueryLanguage - * The pFilterQueryLanguage represents the query - * language for the pFilterQuery argument. This must - * be left null if a pFilterQuery is - * not supplied. If the implementation does not support the query - * language specified, the - * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error shall - * be returned. If the implementation does not support filtered - * enumerations, the - * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error - * shall be returned. - * @param pReturnQueryResultClass - * The pReturnQueryResultClass controls whether a - * class definition is returned in pQueryResultClass - * . If it is set to false, - * pQueryResultClass shall be set to - * null on output. If it is set to true - * , the value of the pQueryResultClass on output - * shall be a class definition that defines the properties - * (columns) of each row of the query result. - * @param pTimeout - * This input parameter determines the minimum time the CIM - * server shall maintain the open enumeration session after the - * last Open or Pull operation (unless the enumeration session is - * closed). If the operation timeout is exceeded, the - * implementation may close the enumeration session at any time, - * releasing any resources allocated to the enumeration session. - * A pTimeout of 0 means that there is no operation - * timeout. That is, the enumeration session is never closed - * based on time. If pTimeout is null, - * the implementation shall choose an operation timeout. All - * other values for pTimeout specify the operation - * timeout in seconds. A implementation may restrict the set of - * allowable values for pTimeout. Specifically, the - * implementation may not allow 0 (no timeout). If the specified - * value is not an allowable value, the implementation shall - * return failure with the status code - * CIM_ERR_INVALID_OPERATION_TIMEOUT. - * @param pContinueOnError - * If true, requests that the operation resume when - * an error is received. If a implementation does not support - * continuation on error and pContinueOnError is - * true, it shall throw a WBEMException - * with the status code - * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED. If a - * implementation supports continuation on error and - * pContinueOnError is true, the - * enumeration session shall remain open when a Pull operation - * fails, and any subsequent successful Pull operations shall - * return the set of elements that would have been returned if - * the failing Pull operations were successful. This behavior is - * subject to the consistency rules defined for pulled - * enumerations. If pContinueOnError is - * false, the enumeration session shall be closed - * when either the operation completes successfully or when a - * WBEMExcetpion is thrown. - * @param pMaxObjects - * Defines the maximum number of elements that this Open - * operation can return. The implementation may deliver any - * number of elements up to pMaxObjects but shall - * not deliver more than pMaxObjects elements. An - * implementation may choose to never return any elements during - * an Open operation, regardless of the value of - * pMaxObjects. Note that a CIM client can use a - * pMaxObjects value of 0 to specify that it does - * not want to retrieve any instances in the Open operation. - * @param pQueryResultClass - * The pQueryResultClass is an output argument. It - * shall be null if the - * pReturnQueryResultClass input parameter is set to - * false. Otherwise, it shall return a class - * definition where each property of the class corresponds to one - * entry of the query select list. The class definition - * corresponds to one row of the query result. The class name of - * this returned class shall be "CIM_QueryResult". This class - * definition is valid only in the context of this enumeration. - * @return The return value of a successful Open operation is an array of - * enumerated elements with a number of entries from 0 up to a - * maximum defined by pMaxObjects. These entries meet - * the criteria defined in the Open operation. Note that returning - * no entries in the array does not imply that the enumeration - * session is exhausted. Client must evaluate the - * EnumerateResponse.isEnd() to determine if there are - * more elements. - * @throws UnsupportedOperationException - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_SERVER_IS_SHUTTING_DOWN - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_OPERATION_TIMEOUT - * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED - * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized - * or otherwise incorrect parameters) - * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED (the requested filter query - * language is not recognized) - * CIM_ERR_INVALID_QUERY (the filter query is not a valid query in the - * specified filter query language) - * CIM_ERR_QUERY_FEATURE_NOT_SUPPORTED (the query requires support for - * features that are not supported) - * CIM_ERR_FAILED (Some other unspecified error occurred) - * - */ - public EnumerateResponse execQueryInstances(CIMObjectPath pObjectName, - String pFilterQuery, String pFilterQueryLanguage, boolean pReturnQueryResultClass, - UnsignedInteger32 pTimeout, boolean pContinueOnError, UnsignedInteger32 pMaxObjects, - CIMClass pQueryResultClass) throws WBEMException; - - /** - * Returns the CIMClass for the specified - * CIMObjectPath. - * - * @param pName - * The object path of the class to be returned. Only the name - * space and class name components are used. All other - * information (e.g. keys) is ignored. - * @param pLocalOnly - * If true, only elements (properties, methods, - * references) overridden or defined in the class are included in - * the CIMClassreturned. If false, all - * elements of the class definition are returned. - * @param pIncludeQualifiers - * If true, all Qualifiers for the class and its - * elements are included in the CIMClass returned. - * If false, no Qualifier information is contained - * in the CIMClass returned. - * @param pIncludeClassOrigin - * The class origin attribute is the name of the class that first - * defined the property or method. If true, the - * class origin attribute shall be present for each property and - * method on all returned CIMClasses. If - * false, the class origin shall not be present. - * @param pPropertyList - * An array of property names used to filter what is contained in - * the CIMClass returned. The CIMClass - * returned only contains elements for the properties of the - * names specified. Duplicate and invalid property names are - * ignored and the request is otherwise processed normally. An - * empty array indicates that no properties should be returned. A - * null value indicates that all properties should - * be returned. - * @return CIMClass meeting the criteria specified. - * @throws UnsupportedOperationException - * If the client implementation (or protocol) does not support - * the operation. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized - * or otherwise incorrect parameters) - * CIM_ERR_NOT_FOUND (the requested CIM Class does not exist in the - * specified namespace) - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public CIMClass getClass(CIMObjectPath pName, boolean pLocalOnly, boolean pIncludeQualifiers, - boolean pIncludeClassOrigin, String[] pPropertyList) throws WBEMException; - - /** - * Get a CIMInstance. - * - * @param pName - * The object path of the instance to be returned. The Keys in - * this CIMObjectPath must be populated. - * @param pLocalOnly - * If true, only properties overridden or defined in - * the class are included in the CIMInstance - * returned. If false, all properties of the class - * definition are returned. WBEM Servers may ignore this - * parameter and return all properties. - * @param pIncludeClassOrigin - * The class origin attribute is the name of the class that first - * defined the property. If true, the class origin - * attribute may be present for each property of the - * CIMInstance, even if requested the server may - * ignore the request and not return the class origin. If - * false, the class origin shall not be present. - * @param pPropertyList - * An array of property names used to filter what is contained in - * the CIMClass returned. The CIMClass - * returned only contains elements for the properties of the - * names specified. Duplicate and invalid property names are - * ignored and the request is otherwise processed normally. An - * empty array indicates that no properties should be returned. A - * null value indicates that all properties should - * be returned. - * @return CIMInstance identified by the - * CIMObjectPath specified. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED (provider does not support this method) - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (for this method) - * CIM_ERR_INVALID_CLASS (in this namespace) - * CIM_ERR_NOT_FOUND (if instance does not exist) - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public CIMInstance getInstance(CIMObjectPath pName, boolean pLocalOnly, - boolean pIncludeClassOrigin, String[] pPropertyList) throws WBEMException; - - /** - * getInstancePaths shall get the CIMObjectPaths - * using an enumeration context. - * - * @param pPath - * The CIMObjectPath representing the namespace to - * be used. - * @param pContext - * The enumeration context value for the enumeration session to - * be used. - * @param pMaxObjects - * Defines the maximum number of elements that this Open - * operation can return. The implementation may deliver any - * number of elements up to pMaxObjects but shall - * not deliver more than pMaxObjects elements. An - * implementation may choose to never return any elements during - * an Open operation, regardless of the value of - * pMaxObjects. - * @return EnumerateResponse that includes zero or more - * CIMObjectPath objects. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_SERVER_IS_SHUTTING_DOWN - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER - * CIM_ERR_INVALID_ENUMERATION_CONTEXT - * CIM_ERR_SERVER_LIMITS_EXCEEDED - * CIM_ERR_PULL_HAS_BEEN_ABANDONED - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public EnumerateResponse getInstancePaths(CIMObjectPath pPath, String pContext, - UnsignedInteger32 pMaxObjects) throws WBEMException; - - /** - * getInstances shall get the instances from an enumeration - * session started by execQueryInstances. - * - * @param pPath - * The CIMObjectPath representing the namespace to - * be used. - * @param pContext - * The enumeration context value for the enumeration session to - * be used. - * @param pMaxObjects - * Defines the maximum number of elements that this Open - * operation can return. The implementation may deliver any - * number of elements up to pMaxObjects but shall - * not deliver more than pMaxObjects elements. An - * implementation may choose to never return any elements during - * an Open operation, regardless of the value of - * pMaxObjects. Note that a CIM client can use a - * pMaxObjects value of 0 to specify that it does - * not want to retrieve any instances in the Open operation. - * @return EnumerateResponse that includes zero or more - * CIMObjectPath objects. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_SERVER_IS_SHUTTING_DOWN - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER - * CIM_ERR_INVALID_ENUMERATION_CONTEXT - * CIM_ERR_SERVER_LIMITS_EXCEEDED - * CIM_ERR_PULL_HAS_BEEN_ABANDONED - * CIM_ERR_FAILED - * - */ - public EnumerateResponse getInstances(CIMObjectPath pPath, String pContext, - UnsignedInteger32 pMaxObjects) throws WBEMException; - - /** - * getInstancesWithPath shall use the enumeration context - * provided to get the next set of instances for the enumeration session. - * - * @param pPath - * The CIMObjectPath representing the namespace to - * be used. - * @param pContext - * The enumeration context value for the enumeration session to - * be used. - * @param pMaxObjects - * Defines the maximum number of elements that this Open - * operation can return. The implementation may deliver any - * number of elements up to pMaxObjects but shall - * not deliver more than pMaxObjects elements. An - * implementation may choose to never return any elements during - * an Open operation, regardless of the value of - * pMaxObjects. - * @return EnumerateResponse that includes zero or more - * CIMObjectPath. objects. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_SERVER_IS_SHUTTING_DOWN - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER - * CIM_ERR_INVALID_ENUMERATION_CONTEXT - * CIM_ERR_SERVER_LIMITS_EXCEEDED - * CIM_ERR_PULL_HAS_BEEN_ABANDONED - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public EnumerateResponse getInstancesWithPath(CIMObjectPath pPath, - String pContext, UnsignedInteger32 pMaxObjects) throws WBEMException; - - /** - * Get property values. See WBEMClientConstants for a list of - * standard properties. - * - * @param pKey - * The name of the property. - * @return The value of the property. - * @see WBEMClientConstants - */ - public String getProperty(String pKey); - - /** - * Get a CIMQualifierType. - * - * @param pName - * CIMObjectPath that identifies the - * CIMQualifierType to return. - * @return The CIMQualifierType object. - * @throws UnsupportedOperationException - * If the client implementation (or protocol) does not support - * the operation. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized - * or otherwise incorrect parameters) - * CIM_ERR_NOT_FOUND (the requested Qualifier declaration did not exist) - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public CIMQualifierType getQualifierType(CIMObjectPath pName) throws WBEMException; - - /** - * Initialize the client connection. This must be called before any - * operations. This must only be called once. - * - * @param pName - * The protocol and host to use (e.g. http://192.168.1.128/). Any - * other fields shall be ignored. - * @param pSubject - * The principal/credential pairs for this connection. - * @param pLocales - * An array of locales in order of priority of preference. - * @throws IllegalArgumentException - * If the host or scheme portion of the object path is null, or - * if the protocol is not supported. - * @throws WBEMException - * If the protocol adapter or security cannot be initialized. - */ - public void initialize(CIMObjectPath pName, Subject pSubject, Locale[] pLocales) - throws IllegalArgumentException, WBEMException; - - /** - * Executes the specified method on the specified object. - * - * @param pName - * CIM object path of the object whose method must be invoked. It - * must include all of the keys. - * @param pMethodName - * The name of the method to be invoked. - * @param pInputArguments - * The CIMArgument array of method input parameters. - *

      - * @param pOutputArguments - * The CIMArgument array of method output - * parameters. The array should be allocated large enough to hold - * all returned parameters. - * @return The return value of the specified method. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED (implementation DOES NOT support ANY - * Extrinsic Method Invocation) - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (for this method) - * CIM_ERR_NOT_FOUND (if instance does not exist) - * CIM_ERR_METHOD_NOT_FOUND - * CIM_ERR_METHOD_NOT_AVAILABLE - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public Object invokeMethod(CIMObjectPath pName, String pMethodName, - CIMArgument[] pInputArguments, CIMArgument[] pOutputArguments) - throws WBEMException; - - /** - * Modify the CIMClass. - * - * @param pClass - * CIMClass to be modified. - * @throws UnsupportedOperationException - * If the client implementation (or protocol) does not support - * the operation. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized - * or otherwise incorrect parameters) - * CIM_ERR_INVALID_SUPERCLASS (the putative CIM Class declares a - * non-existent superclass) - * CIM_ERR_CLASS_HAS_CHILDREN (the modification could not be performed - * because it was not possible to update the subclasses of the Class - * in a consistent fashion) - * CIM_ERR_CLASS_HAS_INSTANCES (the modification could not be performed - * because it was not possible to update the instances of the Class in - * a consistent fashion) - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public void modifyClass(CIMClass pClass) throws WBEMException; - - /** - * Modify some or all of the properties of the specified - * CIMInstance. - * - * @param pInstance - * CIMInstance to be modified. All Keys must be - * populated. - * @param pPropertyList - * An array of property names used to specify which values from - * the CIMInstance specified to set. Properties not - * specified in this list but set in the CIMInstance - * specified are not modified. Duplicate property names are - * ignored and the request is otherwise processed normally. If - * the pPropertyList contains invalid property names - * for the instance to be modified, the server shall reject the - * request. An empty array indicates that no properties should be - * modified. A null value indicates that all - * properties should be modified. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED (provider does not support this method) - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (for this method) - * CIM_ERR_INVALID_CLASS (in this namespace) - * CIM_ERR_NOT_FOUND (if instance does not exist) - * CIM_ERR_NO_SUCH_PROPERTY (in this instance) - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public void modifyInstance(CIMInstance pInstance, String[] pPropertyList) throws WBEMException; - - /** - * Enumerates the Association classes that refer to a specified source CIM - * Class. - * - * @param pObjectName - * CIMObjectPath defining the source CIM class whose - * referring classes are to be returned. pObjectName - * shall contain the scheme, host, namespace and object name - * (class name). - * @param pResultClass - * This string shall either contain a valid CIM Class name or be - * null. The pResultClass filters the - * classes returned to contain only the classes of this Class - * name or one of its subclasses. - * @param pRole - * This string MUST either contain a valid Property name or be - * null. It filters the Objects returned to contain - * only Objects referring to the source Object via a Property - * with the specified name. If "Antecedent" is specified, then - * only Associations in which the source Object is the - * "Antecedent" reference are returned. - * @param pIncludeQualifiers - * If true, all Qualifiers for each Object - * (including Qualifiers on the Object and on any returned - * Properties) shall be included in the classes returned. If - * false, no Qualifiers shall be present in each - * class returned. - * @param pIncludeClassOrigin - * The class origin attribute is the name of the class that first - * defined the property or method. If true, the - * class Origin attribute shall be present for each property and - * method on all classes returned. If false, the - * class origin shall not be present. - * @param pPropertyList - * An array of property names used to filter what is contained in - * the Objects returned. Each CIMClass returned - * shall only contains elements for the properties of the names - * specified. Duplicate and invalid property names are ignored - * and the request is otherwise processed normally. An empty - * array indicates that no properties should be included in the - * classes returned. A null value indicates that all - * properties should be contained in the classes returned. - * @return If successful, a CloseableIterator referencing zero - * or more CIMClasses meeting the specified criteria. - * @throws UnsupportedOperationException - * If the client implementation (or protocol) does not support - * the operation. - * @throws WBEMException - * If unsuccessful, one of the following status codes shall be - * returned along with zero or more instance of - * CIM_Error. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized - * or otherwise incorrect parameters) - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - - CloseableIterator referenceClasses(CIMObjectPath pObjectName, String pResultClass, - String pRole, boolean pIncludeQualifiers, boolean pIncludeClassOrigin, - String[] pPropertyList) throws WBEMException; - - /** - * Enumerates the Association instances that refer to a specified source CIM - * Instance. - * - * @param pObjectName - * CIMObjectPath defining the source CIM Instance - * whose referring instances are to be returned. The - * pObjectName shall include the host, object name - * and keys. - * @param pResultClass - * This string shall either contain a valid CIM Class name or be - * null. It filters the instances returned to - * contain only the instances of this Class name or one of its - * subclasses. - * @param pRole - * This string shall either contain a valid Property name or be - * null. The role filters the instances returned to - * contain only instances referring to the source instance via a - * property with the specified name. For example, If "Antecedent" - * is specified, then only Associations in which the source - * instance is the "Antecedent" reference are returned. - * @param pIncludeClassOrigin - * The class origin attribute is the name of the class that first - * defined the property. If true, the class origin - * attribute may be present for each property and on all - * instances returned, even if requested the server may ignore - * the request and not return the class origin. If - * false, the class origin shall not be present. - * @param pPropertyList - * An array of property names used to filter what is contained in - * the instances returned. Each CIMInstance returned - * shall only contain elements for the properties of the names - * specified. Duplicate and invalid property names are ignored - * and the request is otherwise processed normally. An empty - * array indicates that no properties should be included in the - * instances returned. A null value indicates that - * all properties supported shall be contained in the instance - * returned. - * @return If successful, a CloseableIterator referencing zero - * or more CIMInstances meeting the specified criteria. - * @throws WBEMException - * If unsuccessful, one of the following status codes shall be - * returned along with zero or more CIM_Error - * instances. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized - * or otherwise incorrect parameters) - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - CloseableIterator referenceInstances(CIMObjectPath pObjectName, - String pResultClass, String pRole, boolean pIncludeClassOrigin, String[] pPropertyList) - throws WBEMException; - - /** - * Enumerates the CIMObjectPaths of Association Objects that - * refer to a particular source CIM Object. If the source Object is a CIM - * Class, then a CloseableIterator of - * CIMObjectPaths of the Association classes that refer to the - * source Object is returned. If the source Object is a CIM Instance, then a - * CloseableIterator of CIMObjectPaths of the - * CIMInstance objects that refer to the source Object is - * returned. - * - * @param pObjectName - * CIMObjectPath defining the source CIM Object - * whose referring Objects are to be returned. This argument may - * contain either a Class name or the modelpath of an Instance. - * (i.e. Keys populated) - * @param pResultClass - * This string MUST either contain a valid CIM Class name or be - * null. It filters the Objects returned to contain - * only the Objects of this Class name or one of its subclasses. - * @param pRole - * This string MUST either contain a valid Property name or be - * null. It filters the Objects returned to contain - * only Objects referring to the source Object via a Property - * with the specified name. If "Antecedent" is specified, then - * only Associations in which the source Object is the - * "Antecedent" reference are returned. - * @return If successful, a CloseableIterator referencing zero - * or more CIMObjectPaths of CIMClasses or - * CIMInstances meeting the specified criteria. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized - * or otherwise incorrect parameters) - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public CloseableIterator referenceNames(CIMObjectPath pObjectName, - String pResultClass, String pRole) throws WBEMException; - - /** - * referencePaths shall start an enumeration session for - * association instances that have references that refer to the instance - * defined in the pInstancePath parameter and return zero or - * more CIMObjectPath objects. - * - * @param pInstancePath - * The CIMObjectPath for the instance for which the - * enumeration is to be performed. - * @param pResultClass - * This string MUST either contain a valid CIM Class name or be - * null. It filters the Objects returned to contain - * only the Objects of this Class name or one of its subclasses. - * @param pRole - * This string MUST either contain a valid Property name or be - * null. It filters the Objects returned to contain - * only Objects referring to the source Object via a Property - * with the specified name. If "Antecedent" is specified, then - * only Associations in which the source Object is the - * "Antecedent" reference are returned. - * @param pFilterQueryLanguage - * The pFilterQueryLanguage represents the query - * language for the pFilterQuery argument. This must - * be left null if a pFilterQuery is - * not supplied. If the implementation does not support the query - * language specified, the - * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error shall - * be returned. If the implementation does not support filtered - * enumerations, the - * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error - * shall be returned. - * @param pFilterQuery - * The pFilterQuery specifies a query in the form of - * the query language specified by the - * pFilterQueryLanguage parameter. If this value is - * not null, the pFilterQueryLanguage - * parameter must be non-null. This value shall act - * as an additional filter on the result set. If the - * implementation does not support the query language specified, - * the CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error - * shall be returned. If the implementation does not support - * filtered enumerations, the - * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error - * shall be returned. - * @param pTimeout - * This input parameter determines the minimum time the CIM - * server shall maintain the open enumeration session after the - * last Open or Pull operation (unless the enumeration session is - * closed). If the operation timeout is exceeded, the - * implementation may close the enumeration session at any time, - * releasing any resources allocated to the enumeration session. - * A pTimeout of 0 means that there is no operation - * timeout. That is, the enumeration session is never closed - * based on time. If pTimeout is null, - * the implementation shall choose an operation timeout. All - * other values for pTimeout specify the operation - * timeout in seconds. A implementation may restrict the set of - * allowable values for pTimeout. Specifically, the - * implementation may not allow 0 (no timeout). If the specified - * value is not an allowable value, the implementation shall - * return failure with the status code - * CIM_ERR_INVALID_OPERATION_TIMEOUT. - * @param pContinueOnError - * If true, requests that the operation resume when - * an error is received. If a implementation does not support - * continuation on error and pContinueOnError is - * true, it shall throw a WBEMException - * with the status code - * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED. If a - * implementation supports continuation on error and - * pContinueOnError is true, the - * enumeration session shall remain open when a Pull operation - * fails, and any subsequent successful Pull operations shall - * return the set of elements that would have been returned if - * the failing Pull operations were successful. This behavior is - * subject to the consistency rules defined for pulled - * enumerations. If pContinueOnError is - * false, the enumeration session shall be closed - * when either the operation completes successfully or when a - * WBEMExcetpion is thrown. - * @param pMaxObjects - * Defines the maximum number of elements that this Open - * operation can return. The implementation may deliver any - * number of elements up to pMaxObjects but shall - * not deliver more than pMaxObjects elements. An - * implementation may choose to never return any elements during - * an Open operation, regardless of the value of - * pMaxObjects. Note that a CIM client can use a - * pMaxObjects value of 0 to specify that it does - * not want to retrieve any instances in the Open operation. - * @return The return value of a successful Open operation is an array of - * enumerated elements with a number of entries from 0 up to a - * maximum defined by pMaxObjects. These entries meet - * the criteria defined in the Open operation. Note that returning - * no entries in the array does not imply that the enumeration - * session is exhausted. Client must evaluate the - * EnumerateResponse.isEnd() to determine if there are - * more elements. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_SERVER_IS_SHUTTING_DOWN - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_OPERATION_TIMEOUT - * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED - * CIM_ERR_INVALID_PARAMETER - * CIM_ERR_NOT_FOUND (the source instance was not found) - * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED - * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED - * CIM_ERR_INVALID_QUERY - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public EnumerateResponse referencePaths(CIMObjectPath pInstancePath, - String pResultClass, String pRole, String pFilterQueryLanguage, String pFilterQuery, - UnsignedInteger32 pTimeout, boolean pContinueOnError, UnsignedInteger32 pMaxObjects) - throws WBEMException; - - /** - * references shall start an enumeration session for - * association instances that have references that refer to the instance - * defined in the pInstancePath parameter and return zero or - * more CIMInstance objects. - * - * @param pInstancePath - * The CIMObjectPath for the instance for which the - * enumeration is to be performed. - * @param pResultClass - * This string shall either contain a CIM Class name or be - * null. It filters the instances returned to - * contain only the instances of this Class name or one of its - * subclasses. - * @param pRole - * This string shall either contain a Property name or be - * null. It filters the instances returned to - * contain only instances referring to the source instance via a - * Property with the specified name. If "Antecedent" is - * specified, then only Associations in which the source instance - * is the "Antecedent" reference are returned. - * @param pIncludeClassOrigin - * The class origin attribute is the name of the class that first - * defined the property. If true, the class origin - * attribute may be present for each property on all instances - * returned, even if requested the server may ignore the request - * and not return the class origin. If false, the - * class origin shall not be present. - * @param pPropertyList - * An array of property names used to filter what is contained in - * the instances returned. Each CIMInstance returned - * only contains elements for the properties of the names - * specified. Duplicate and invalid property names are ignored - * and the request is otherwise processed normally. An empty - * array indicates that no properties should be included in the - * Objects returned. A null value indicates that all - * non-null properties of the instance are included. - * @param pFilterQueryLanguage - * The pFilterQueryLanguage represents the query - * language for the pFilterQuery argument. This must - * be left null if a pFilterQuery is - * not supplied. If the implementation does not support the query - * language specified, the - * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error shall - * be returned. If the implementation does not support filtered - * enumerations, the - * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error - * shall be returned. - * @param pFilterQuery - * The pFilterQuery specifies a query in the form of - * the query language specified by the - * pFilterQueryLanguage parameter. If this value is - * not null, the pFilterQueryLanguage - * parameter must be non-null. This value shall act - * as an additional filter on the result set. If the - * implementation does not support the query language specified, - * the CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error - * shall be returned. If the implementation does not support - * filtered enumerations, the - * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error - * shall be returned. - * @param pTimeout - * This input parameter determines the minimum time the CIM - * server shall maintain the open enumeration session after the - * last Open or Pull operation (unless the enumeration session is - * closed). If the operation timeout is exceeded, the - * implementation may close the enumeration session at any time, - * releasing any resources allocated to the enumeration session. - * A pTimeout of 0 means that there is no operation - * timeout. That is, the enumeration session is never closed - * based on time. If pTimeout is null, - * the implementation shall choose an operation timeout. All - * other values for pTimeout specify the operation - * timeout in seconds. A implementation may restrict the set of - * allowable values for pTimeout. Specifically, the - * implementation may not allow 0 (no timeout). If the specified - * value is not an allowable value, the implementation shall - * return failure with the status code - * CIM_ERR_INVALID_OPERATION_TIMEOUT. - * @param pContinueOnError - * If true, requests that the operation resume when - * an error is received. If a implementation does not support - * continuation on error and pContinueOnError is - * true, it shall throw a WBEMException - * with the status code - * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED. If a - * implementation supports continuation on error and - * pContinueOnError is true, the - * enumeration session shall remain open when a Pull operation - * fails, and any subsequent successful Pull operations shall - * return the set of elements that would have been returned if - * the failing Pull operations were successful. This behavior is - * subject to the consistency rules defined for pulled - * enumerations. If pContinueOnError is - * false, the enumeration session shall be closed - * when either the operation completes successfully or when a - * WBEMExcetpion is thrown. - * @param pMaxObjects - * Defines the maximum number of elements that this Open - * operation can return. The implementation may deliver any - * number of elements up to pMaxObjects but shall - * not deliver more than pMaxObjects elements. An - * implementation may choose to never return any elements during - * an Open operation, regardless of the value of - * pMaxObjects. Note that a CIM client can use a - * pMaxObjects value of 0 to specify that it does - * not want to retrieve any instances in the Open operation. - * @return The return value of a successful Open operation is an array of - * enumerated elements with a number of entries from 0 up to a - * maximum defined by pMaxObjects. These entries meet - * the criteria defined in the Open operation. Note that returning - * no entries in the array does not imply that the enumeration - * session is exhausted. Client must evaluate the - * EnumerateResponse.isEnd() to determine if there are - * more elements. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_SERVER_IS_SHUTTING_DOWN - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_OPERATION_TIMEOUT - * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED - * CIM_ERR_INVALID_PARAMETER - * CIM_ERR_NOT_FOUND (the source instance was not found) - * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED - * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED - * CIM_ERR_INVALID_QUERY - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public EnumerateResponse references(CIMObjectPath pInstancePath, - String pResultClass, String pRole, boolean pIncludeClassOrigin, String[] pPropertyList, - String pFilterQueryLanguage, String pFilterQuery, UnsignedInteger32 pTimeout, - boolean pContinueOnError, UnsignedInteger32 pMaxObjects) throws WBEMException; - - /** - * Change the locales that were provided during initialization. - * - * @param pLocales - * An array of locales in order of priority of preference. - */ - public void setLocales(Locale[] pLocales); - - /** - * Set properties that enable options or protocol specific properties. See - * WBEMClientConstants for a list of standard properties. - * - * @param pKey - * The name of the property. - * @param pValue - * The value of the property. - * @throws IllegalArgumentException - * If the name is not a supported property name. - * @see WBEMClientConstants - */ - public void setProperty(String pKey, String pValue); - - /** - * Add a CIMQualifierType to the specified namespace if it does - * not already exist. Otherwise, it modifies the qualifier type to the value - * specified. - * - * @param pQualifierType - * The CIM qualifier type to be added. - * @throws UnsupportedOperationException - * If the client implementation (or protocol) does not support - * the operation. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - * - * CIM_ERR_ACCESS_DENIED - * CIM_ERR_NOT_SUPPORTED - * CIM_ERR_INVALID_NAMESPACE - * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized - * or otherwise incorrect parameters) - * CIM_ERR_FAILED (some other unspecified error occurred) - * - */ - public void setQualifierType(CIMQualifierType pQualifierType) throws WBEMException; -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-11-08 lupusalex Make SBLIM client JSR48 compliant + * 1686000 2007-04-19 ebak modifyInstance() missing from WBEMClient + * 1737141 2007-06-18 ebak Sync up with JSR48 evolution + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2845211 2009-08-27 raman_arora Pull Enumeration Feature (SAX Parser) + * 2858933 2009-10-12 raman_arora JSR48 new APIs: associatorClasses & associatorInstances + * 2886829 2009-11-18 raman_arora JSR48 new APIs: referenceClasses & referenceInstances + * 2959586 2010-03-01 blaschke-oss Sync up WBEMClient javadoc with JSR48 1.0.0 + * 2961592 2010-03-01 blaschke-oss Remove WBEMClient.setLocales() UnsupportedOperationException + * 3496301 2012-03-02 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final + * 3496343 2012-03-02 blaschke-oss JSR48 1.0.0: deprecate WBEMClient associators and references + * 3514537 2012-04-03 blaschke-oss TCK: execQueryInstances requires boolean, not Boolean + * 3521131 2012-04-24 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final II + * 3521328 2012-04-25 blaschke-oss JSR48 1.0.0: remove WBEMClient associators and references + * 3525657 2012-05-10 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final III + * 3555752 2012-09-13 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final IV + * 2716 2013-12-11 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V + */ + +package org.metricshub.wbem.javax.wbem.client; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Locale; +import javax.security.auth.Subject; +import org.metricshub.wbem.javax.cim.CIMArgument; +import org.metricshub.wbem.javax.cim.CIMClass; +import org.metricshub.wbem.javax.cim.CIMInstance; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.cim.CIMQualifierType; +import org.metricshub.wbem.javax.cim.UnsignedInteger32; +import org.metricshub.wbem.javax.cim.UnsignedInteger64; +import org.metricshub.wbem.javax.wbem.CloseableIterator; +import org.metricshub.wbem.javax.wbem.WBEMException; + +//Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013 +/** + * The WBEMClient interface is used to invoke WBEM operations + * against a WBEM Server. A WBEMClient implementation can be + * retrieved from the WBEMClientFactory specifying the protocol to + * be used. + * + * @see WBEMClientFactory + */ +public interface WBEMClient { + /** + * Enumerates CIM classes that are associated to a specified source CIM + * class. + * + * @param pObjectName + * CIMObjectPath defining the source CIM Class whose + * associated classes are to be returned. The + * pObjectName shall include the host, namespace and + * object name. The keys shall not be populated. + * @param pAssociationClass + * This string shall contain a valid CIM Association class name + * or be null. It filters the classes returned to + * contain only classes associated to the source Object via this + * CIM Association class or one of its subclasses. + * @param pResultClass + * This string shall either contain a valid CIM Class name or be + * null. It filters the classes returned to contain + * only the classes of this class name or one of its subclasses. + * @param pRole + * This string shall either contain a valid Property name or be + * null. It filters the classes returned to contain + * only classes associated to the source class via an Association + * class in which the source class plays the specified + * role. (i.e. the Property name in the Association class that + * refers to the source class matches this value) For + * example, if "Antecedent" is specified, then only Associations + * in which the source class is the "Antecedent" reference are + * examined. + * @param pResultRole + * This string shall either contain a valid Property name or be + * null. It filters the classes returned to contain + * only classes associated to the source class via an Association + * class in which the class returned plays the specified + * role. (i.e. the Property name in the Association class that + * refers to the class returned matches this value) + * @param pIncludeQualifiers + * If true, all Qualifiers for each class (including + * Qualifiers on the Object and on any returned Properties) MUST + * be included in the classes returned. If false, no + * Qualifiers are present in each class returned. + * @param pIncludeClassOrigin + * The class origin attribute is the name of the class that first + * defined the property or method. If true, the + * class origin attribute shall be present for each property and + * method on all classes returned. If false, the + * class origin shall not be present. + * @param pPropertyList + * An array of property names used to filter what is contained in + * the classes returned. Each CIMClass returned + * shall only contain elements for the properties of the names + * specified. Duplicate and invalid property names are ignored + * and the request is otherwise processed normally. An empty + * array indicates that no properties should be included in the + * classes returned. A null value indicates that all + * properties should be contained in the classes returned. + * @return If successful, a CloseableIterator containing zero + * or more CIMClasses meeting the specified criteria + * are returned. + * @throws UnsupportedOperationException + * If the client implementation (or protocol) does not support + * the operation. + * @throws WBEMException + * If unsuccessful, one of the following status codes shall be + * returned along with zero or more instances of + * CIM_Error. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized + * or otherwise incorrect parameters) + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public CloseableIterator associatorClasses( + CIMObjectPath pObjectName, + String pAssociationClass, + String pResultClass, + String pRole, + String pResultRole, + boolean pIncludeQualifiers, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException; + + /** + * Enumerates CIM Instances associated to a specified source CIM Instance. + * + * @param pObjectName + * CIMObjectPath defining the source CIM Instance + * whose associated instances are to be returned. The + * pObjectName must contain the host, namespace, + * object name and keys for the instance. + * @param pAssociationClass + * This string shall either contain a valid CIM Association class + * name or be null. It filters the instances + * returned to contain only instances associated to the source + * instance via this CIM Association class or one of its + * subclasses. + * @param pResultClass + * This string shall either contain a valid CIM Class name or be + * null. It filters the instances returned to + * contain only the instances of this Class name or one of its + * subclasses. + * @param pRole + * This string shall either contain a valid Property name or be + * null. It filters the Objects returned to contain + * only Objects associated to the source Object via an + * Association class in which the source Object plays the + * specified role. (i.e. the Property name in the Association + * class that refers to the source Object matches this + * value) If "Antecedent" is specified, then only Associations in + * which the source Object is the "Antecedent" reference are + * examined. + * @param pResultRole + * This string shall either contain a valid Property name or be + * null. It filters the instances returned to + * contain only instances associated to the source instance via + * an Association class in which the instance returned + * plays the specified role. (i.e. the Property name in the + * Association class that refers to the instance returned + * matches this value) For example, if "Dependent" is specified, + * then only Associations in which the instance returned is the + * "Dependent" reference are examined. + * @param pIncludeClassOrigin + * The class origin attribute is the name of the class that first + * defined the property. If true, the class origin + * attribute may be present for each property on all instances + * returned, even if requested the server may ignore the request + * and not return the class origin. If false, the + * class origin shall not be present. + * @param pPropertyList + * An array of property names used to filter what is contained in + * the Objects returned. Each CIMInstance returned + * only contains elements for the properties of the names + * specified. Duplicate and invalid property names are ignored + * and the request is otherwise processed normally. An empty + * array indicates that no properties should be included in the + * instances returned. A null value indicates that + * all properties should be contained in the instances returned. + * @return If successful, a CloseableIterator containing zero + * or more CIMInstances meeting the specified criteria + * is returned. + * @throws WBEMException + * If unsuccessful, one of the following status codes shall be + * returned along with zero or more instances of + * CIM_Error. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized + * or otherwise incorrect parameters) + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public CloseableIterator associatorInstances( + CIMObjectPath pObjectName, + String pAssociationClass, + String pResultClass, + String pRole, + String pResultRole, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException; + + /** + * Enumerates the CIMObjectPaths of CIM Objects that are + * associated to a particular source CIM Object. If the source Object is a + * CIM Class, then a CloseableIterator of + * CIMObjectPath s of the classes associated to the source + * Object is returned. If the source Object is a CIM Instance, then a + * CloseableIterator of CIMObjectPaths of the + * CIMInstance objects associated to the source Object is + * returned. + * + * @param pObjectName + * CIMObjectPath defining the source CIM Object + * whose associated Objects are to be returned. This argument may + * contain either a Class name or the modelpath of an Instance. + * (i.e. Keys populated) + * @param pAssociationClass + * This string MUST either contain a valid CIM Association class + * name or be null. It filters the Objects returned + * to contain only Objects associated to the source Object via + * this CIM Association class or one of its subclasses. + * @param pResultClass + * This string MUST either contain a valid CIM Class name or be + * null. It filters the Objects returned to contain + * only the Objects of this Class name or one of its subclasses. + * @param pRole + * This string MUST either contain a valid Property name or be + * null. It filters the Objects returned to contain + * only Objects associated to the source Object via an + * Association class in which the source Object plays the + * specified role. (i.e. the Property name in the Association + * class that refers to the source Object matches this + * value) If "Antecedent" is specified, then only Associations in + * which the source Object is the "Antecedent" reference are + * examined. + * @param pResultRole + * This string MUST either contain a valid Property name or be + * null. It filters the Objects returned to contain + * only Objects associated to the source Object via an + * Association class in which the Object returned plays + * the specified role. (i.e. the Property name in the Association + * class that refers to the Object returned matches this + * value) If "Dependent" is specified, then only Associations in + * which the Object returned is the "Dependent" reference are + * examined. + * @return If successful, a CloseableIterator containing zero + * or more CIMObjectPath objects of the CIM Classes or + * CIM Instances meeting the specified criteria is returned. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized + * or otherwise incorrect parameters) + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public CloseableIterator associatorNames( + CIMObjectPath pObjectName, + String pAssociationClass, + String pResultClass, + String pRole, + String pResultRole + ) + throws WBEMException; + + /** + * associatorPaths shall start an enumeration session for + * traversing associations starting from the instance defined in the + * pInstancePath parameter using any specified filtering + * criteria and return zero or more CIMObjectPath objects. + * + * @param pInstancePath + * The CIMObjectPath for the instance for which the + * enumeration is to be performed. + * @param pAssociationClass + * This string MUST either contain a valid CIM Association class + * name or be null. It filters the Objects returned + * to contain only Objects associated to the source Object via + * this CIM Association class or one of its subclasses. + * @param pResultClass + * This string MUST either contain a valid CIM Class name or be + * null. It filters the Objects returned to contain + * only the Objects of this Class name or one of its subclasses. + * @param pRole + * This string MUST either contain a valid Property name or be + * null. It filters the Objects returned to contain + * only Objects associated to the source Object via an + * Association class in which the source Object plays the + * specified role. (i.e. the Property name in the Association + * class that refers to the source Object matches this + * value) If "Antecedent" is specified, then only Associations in + * which the source Object is the "Antecedent" reference are + * examined. + * @param pResultRole + * This string MUST either contain a valid Property name or be + * null. It filters the Objects returned to contain + * only Objects associated to the source Object via an + * Association class in which the Object returned plays + * the specified role. (i.e. the Property name in the Association + * class that refers to the Object returned matches this + * value) If "Dependent" is specified, then only Associations in + * which the Object returned is the "Dependent" reference are + * examined. + * @param pFilterQueryLanguage + * The pFilterQueryLanguage represents the query + * language for the pFilterQuery argument. This must + * be left null if a pFilterQuery is + * not supplied. If the implementation does not support the query + * language specified, the + * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error shall + * be returned. If the implementation does not support filtered + * enumerations, the + * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error + * shall be returned. + * @param pFilterQuery + * The pFilterQuery specifies a query in the form of + * the query language specified by the + * pFilterQueryLanguage parameter. If this value is + * not null, the pFilterQueryLanguage + * parameter must be non-null. This value shall act + * as an additional filter on the result set. If the + * implementation does not support the query language specified, + * the CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error + * shall be returned. If the implementation does not support + * filtered enumerations, the + * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error + * shall be returned. + * @param pTimeout + * This input parameter determines the minimum time the CIM + * server shall maintain the open enumeration session after the + * last Open or Pull operation (unless the enumeration session is + * closed). If the operation timeout is exceeded, the + * implementation may close the enumeration session at any time, + * releasing any resources allocated to the enumeration session. + * A pTimeout of 0 means that there is no operation + * timeout. That is, the enumeration session is never closed + * based on time. If pTimeout is null, + * the implementation shall choose an operation timeout. All + * other values for pTimeout specify the operation + * timeout in seconds. A implementation may restrict the set of + * allowable values for pTimeout. Specifically, the + * implementation may not allow 0 (no timeout). If the specified + * value is not an allowable value, the implementation shall + * return failure with the status code + * CIM_ERR_INVALID_OPERATION_TIMEOUT. + * @param pContinueOnError + * If true, requests that the operation resume when + * an error is received. If a implementation does not support + * continuation on error and pContinueOnError is + * true, it shall throw a WBEMException + * with the status code + * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED. If a + * implementation supports continuation on error and + * pContinueOnError is true, the + * enumeration session shall remain open when a Pull operation + * fails, and any subsequent successful Pull operations shall + * return the set of elements that would have been returned if + * the failing Pull operations were successful. This behavior is + * subject to the consistency rules defined for pulled + * enumerations. If pContinueOnError is + * false, the enumeration session shall be closed + * when either the operation completes successfully or when a + * WBEMExcetpion is thrown. + * @param pMaxObjects + * Defines the maximum number of elements that this Open + * operation can return. The implementation may deliver any + * number of elements up to pMaxObjects but shall + * not deliver more than pMaxObjects elements. An + * implementation may choose to never return any elements during + * an Open operation, regardless of the value of + * pMaxObjects. Note that a CIM client can use a + * pMaxObjects value of 0 to specify that it does + * not want to retrieve any instances in the Open operation. + * @return The return value of a successful Open operation is an array of + * enumerated elements with a number of entries from 0 up to a + * maximum defined by pMaxObjects. These entries meet + * the criteria defined in the Open operation. Note that returning + * no entries in the array does not imply that the enumeration + * session is exhausted. Client must evaluate the + * EnumerateResponse.isEnd() to determine if there are + * more elements. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_SERVER_IS_SHUTTING_DOWN + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_OPERATION_TIMEOUT + * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED + * CIM_ERR_INVALID_PARAMETER + * CIM_ERR_NOT_FOUND (the source instance was not found) + * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED + * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED + * CIM_ERR_INVALID_QUERY + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public EnumerateResponse associatorPaths( + CIMObjectPath pInstancePath, + String pAssociationClass, + String pResultClass, + String pRole, + String pResultRole, + String pFilterQueryLanguage, + String pFilterQuery, + UnsignedInteger32 pTimeout, + boolean pContinueOnError, + UnsignedInteger32 pMaxObjects + ) + throws WBEMException; + + /** + * associators shall start an enumeration session for + * traversing associations starting from the instance defined in the + * pInstancePath parameter using any specified filtering + * criteria and return zero or more CIMInstance objects. + * + * @param pInstancePath + * The CIMObjectPath for the instance for which the + * enumeration is to be performed. + * @param pAssociationClass + * This string MUST either contain a valid CIM Association class + * name or be null. It filters the Objects returned + * to contain only Objects associated to the source Object via + * this CIM Association class or one of its subclasses. + * @param pResultClass + * This string MUST either contain a valid CIM Class name or be + * null. It filters the Objects returned to contain + * only the Objects of this Class name or one of its subclasses. + * @param pRole + * This string MUST either contain a valid Property name or be + * null. It filters the Objects returned to contain + * only Objects associated to the source Object via an + * Association class in which the source Object plays the + * specified role. (i.e. the Property name in the Association + * class that refers to the source Object matches this + * value) If "Antecedent" is specified, then only Associations in + * which the source Object is the "Antecedent" reference are + * examined. + * @param pResultRole + * This string MUST either contain a valid Property name or be + * null. It filters the Objects returned to contain + * only Objects associated to the source Object via an + * Association class in which the Object returned plays + * the specified role. (i.e. the Property name in the Association + * class that refers to the Object returned matches this + * value) If "Dependent" is specified, then only Associations in + * which the Object returned is the "Dependent" reference are + * examined. + * @param pIncludeClassOrigin + * The class origin attribute is the name of the class that first + * defined the property. If true, the class origin + * attribute may be present for each property on all instances + * returned, even if requested the server may ignore the request + * and not return the class origin. If false, the + * class origin shall not be present. + * @param pPropertyList + * An array of property names used to filter what is contained in + * the Objects returned. Each CIMClass or + * CIMInstance returned only contains elements for + * the properties of the names specified. Duplicate and invalid + * property names are ignored and the request is otherwise + * processed normally. An empty array indicates that no + * properties should be included in the Objects returned. A + * null value indicates that all properties should + * be contained in the Objects returned. NOTE: Properties + * should not be specified in this parameter unless a non- + * null value is specified in the + * pResultClass parameter. + * @param pFilterQueryLanguage + * The pFilterQueryLanguage represents the query + * language for the pFilterQuery argument. This must + * be left null if a filterQuery is not supplied. If + * the implementation does not support the query language + * specified, the + * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error shall + * be returned. If the implementation does not support filtered + * enumerations, the + * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error + * shall be returned. + * @param pFilterQuery + * The pFilterQuery specifies a query in the form of + * the query language specified by the + * pFilterQueryLanguage parameter. If this value is + * not null, the pFilterQueryLanguage + * parameter must be non-null. This value shall act + * as an additional filter on the result set. If the + * implementation does not support the query language specified, + * the CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error + * shall be returned. If the implementation does not support + * filtered enumerations, the + * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error + * shall be returned. + * @param pTimeout + * This input parameter determines the minimum time the CIM + * server shall maintain the open enumeration session after the + * last Open or Pull operation (unless the enumeration session is + * closed). If the operation timeout is exceeded, the + * implementation may close the enumeration session at any time, + * releasing any resources allocated to the enumeration session. + * A pTimeout of 0 means that there is no operation + * timeout. That is, the enumeration session is never closed + * based on time. If pTimeout is null, + * the implementation shall choose an operation timeout. All + * other values for pTimeout specify the operation + * timeout in seconds. A implementation may restrict the set of + * allowable values for pTimeout. Specifically, the + * implementation may not allow 0 (no timeout). If the specified + * value is not an allowable value, the implementation shall + * return failure with the status code + * CIM_ERR_INVALID_OPERATION_TIMEOUT. + * @param pContinueOnError + * If true, requests that the operation resume when + * an error is received. If a implementation does not support + * continuation on error and pContinueOnError is + * true, it shall throw a WBEMException + * with the status code + * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED. If a + * implementation supports continuation on error and + * pContinueOnError is true, the + * enumeration session shall remain open when a Pull operation + * fails, and any subsequent successful Pull operations shall + * return the set of elements that would have been returned if + * the failing Pull operations were successful. This behavior is + * subject to the consistency rules defined for pulled + * enumerations. If pContinueOnError is + * false, the enumeration session shall be closed + * when either the operation completes successfully or when a + * WBEMExcetpion is thrown. + * @param pMaxObjects + * Defines the maximum number of elements that this Open + * operation can return. The implementation may deliver any + * number of elements up to pMaxObjects but shall + * not deliver more than pMaxObjects elements. An + * implementation may choose to never return any elements during + * an Open operation, regardless of the value of + * pMaxObjects. Note that a CIM client can use a + * pMaxObjects value of 0 to specify that it does + * not want to retrieve any instances in the Open operation. + * @return The return value of a successful Open operation is an array of + * enumerated elements with a number of entries from 0 up to a + * maximum defined by pMaxObjects. These entries meet + * the criteria defined in the Open operation. Note that returning + * no entries in the array does not imply that the enumeration + * session is exhausted. Client must evaluate the + * EnumerateResponse.isEnd() to determine if there are + * more elements. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_SERVER_IS_SHUTTING_DOWN + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_OPERATION_TIMEOUT + * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED + * CIM_ERR_INVALID_PARAMETER + * CIM_ERR_NOT_FOUND (The source instance was not found) + * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED + * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED + * CIM_ERR_INVALID_QUERY + * CIM_ERR_FAILED (Some other unspecified error occurred) + * + */ + public EnumerateResponse associators( + CIMObjectPath pInstancePath, + String pAssociationClass, + String pResultClass, + String pRole, + String pResultRole, + boolean pIncludeClassOrigin, + String[] pPropertyList, + String pFilterQueryLanguage, + String pFilterQuery, + UnsignedInteger32 pTimeout, + boolean pContinueOnError, + UnsignedInteger32 pMaxObjects + ) + throws WBEMException; + + /** + * Closes the WBEMClient session. + */ + public void close(); + + /** + * closeEnumeration shall close an enumeration session that has + * been previously started but not yet completed. Clients should always use + * this method when an enumeration session has been started and the client + * does not retrieve all the results. If a client has started an enumeration + * session and retrieves all the results until the + * EnumerationResponse.isEnd() is true, this method shall not + * be called. + * + * @param pPath + * The CIMObjectPath representing the namespace to + * be used. + * @param pContext + * The enumeration context to close. + * @throws WBEMException + */ + public void closeEnumeration(CIMObjectPath pPath, String pContext) throws WBEMException; + + /** + * Create a CIM class. The namespace from the + * CIMClass.getObjectPath() shall be used. + * + * @param pClass + * The CIMClass to be created. + * @throws UnsupportedOperationException + * If the client implementation (or protocol) does not support + * the operation. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized + * or otherwise incorrect parameters) + * CIM_ERR_ALREADY_EXISTS (the CIM Class already exists) + * CIM_ERR_INVALID_SUPERCLASS (the putative CIM Class declares a + * non-existent superclass) + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public void createClass(CIMClass pClass) throws WBEMException; + + /** + * Create a CIM Instance. The namespace from the + * CIMInstance.getObjectPath() shall be used. The keys of the + * CIMInstance may be modified by the implementation and the + * client must use the returned object path to determine the name of the + * instance. It is possible for a client to leave keys of instances empty/ + * null and the provider can fill them in. This is + * implementation specific unless specified by a CIM Schema or in a DMTF + * Profile. + * + * @param pInstance + * The CIMInstance to be created. + * @return CIMObjectPath of the instance created. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED (provider does not support this method) + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (for this method) + * CIM_ERR_INVALID_CLASS (in this namespace) + * CIM_ERR_ALREADY_EXISTS + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public CIMObjectPath createInstance(CIMInstance pInstance) throws WBEMException; + + /** + * Deletes the CIM class for the object specified by the CIM object path. + * + * @param pPath + * The CIMObjectPath identifying the namespace and + * class name to delete. + * @throws UnsupportedOperationException + * If the client implementation (or protocol) does not support + * the operation. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized + * or otherwise incorrect parameters) + * CIM_ERR_NOT_FOUND (the CIM Class to be deleted does not exist) + * CIM_ERR_CLASS_HAS_CHILDREN (the CIM Class has one or more subclasses + * which cannot be deleted) + * CIM_ERR_CLASS_HAS_INSTANCES (the CIM Class has one or more instances + * which cannot be deleted) + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public void deleteClass(CIMObjectPath pPath) throws WBEMException; + + /** + * Delete the CIM instance specified by the CIM object path. + * + * @param pPath + * The object path of the instance to be deleted. It must include + * all of the keys. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED (provider does not support this method) + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (for this method) + * CIM_ERR_INVALID_CLASS (in this namespace) + * CIM_ERR_NOT_FOUND (if the instance does not exist) + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public void deleteInstance(CIMObjectPath pPath) throws WBEMException; + + /** + * Delete a CIM Qualifier type. + * + * @param pPath + * The CIMObjectPath identifying the name and + * namespace of the CIM qualifier type to delete. + * @throws UnsupportedOperationException + * If the client implementation (or protocol) does not support + * the operation. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (for this method) + * CIM_ERR_NOT_FOUND (the Qualifier did not exist) + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public void deleteQualifierType(CIMObjectPath pPath) throws WBEMException; + + /** + * Enumerate CIM Classes. + * + * @param pPath + * The object path of the class to be enumerated. Only the + * namespace and object name should be populated. If the object + * name is set to an empty string (i.e. ""), then all base + * classes in the target namespace are returned. + * @param pDeep + * If true, the classes returned shall include + * subclasses. If false, the classes returned shall + * not include subclasses. + * @param pLocalOnly + * If true, only elements (properties, methods and + * qualifiers) defined in, or overridden in the class are + * included in the response. If false, all elements + * of the class definition are returned. + * @param pIncludeQualifiers + * If true, all Qualifiers for each Class and its + * elements (properties, methods, references) are included. If + * false, no Qualifiers are present in the classes + * returned. + * @param pIncludeClassOrigin + * The class origin attribute is the name of the class that first + * defined the property or method. If true, the + * class origin attribute shall be present for each property and + * method on all returned CIMClasses. If + * false, the class origin shall not be present. + * @return A CloseableIterator of CIMClasses. + * @throws UnsupportedOperationException + * If the client implementation (or protocol) does not support + * the operation. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized + * or otherwise incorrect parameters) + * CIM_ERR_INVALID_CLASS (the CIM Class that is the basis for this + * enumeration does not exist) + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public CloseableIterator enumerateClasses( + CIMObjectPath pPath, + boolean pDeep, + boolean pLocalOnly, + boolean pIncludeQualifiers, + boolean pIncludeClassOrigin + ) + throws WBEMException; + + /** + * Enumerate the names of CIM Classes. + * + * @param pPath + * The CIMObjectPath identifying the class to be + * enumerated. If the class name in the object path specified is + * an empty string (i.e. ""), all base classes in the target + * namespace are returned. Note that only the namespace and the + * name components should be populated. + * @param pDeep + * If true, the enumeration returned shall contain + * the names of all classes derived from the class being + * enumerated. If false, the enumeration returned + * contains only the names of the first level children of the + * class. + * @return A CloseableIterator of CIMObjectPaths. + * @throws UnsupportedOperationException + * If the client implementation (or protocol) does not support + * the operation. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized + * or otherwise incorrect parameters) + * CIM_ERR_INVALID_CLASS (the CIM Class that is the basis for this + * enumeration does not exist) + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public CloseableIterator enumerateClassNames(CIMObjectPath pPath, boolean pDeep) throws WBEMException; + + /** + * Enumerate the names of the instances for a specified class. The names of + * all subclass instances are returned. + * + * @param pPath + * The CIMObjectPath identifying the class whose + * instances are to be enumerated. Only the namespace and class + * name components are used. All other information (e.g. Keys) is + * ignored. + * @return CloseabelIterator of CIMObjectPaths. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED (provider does not support this method) + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (for this method) + * CIM_ERR_INVALID_CLASS (in this namespace) + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public CloseableIterator enumerateInstanceNames(CIMObjectPath pPath) throws WBEMException; + + /** + * enumerateInstancePaths shall enumerate the instances of the + * specified class in pClassPath and return zero or more + * CIMObjectPaths. + * + * @param pClassPath + * The CIMObjectPath for the class for which the + * enumeration is to be performed. + * @param pFilterQueryLanguage + * The pFilterQueryLanguage represents the query + * language for the pFilterQuery argument. This must + * be left null if a pFilterQuery is + * not supplied. If the implementation does not support the query + * language specified, the + * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error shall + * be returned. If the implementation does not support filtered + * enumerations, the + * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error + * shall be returned. + * @param pFilterQuery + * The pFilterQuery specifies a query in the form of + * the query language specified by the + * pFilterQueryLanguage parameter. If this value is + * not null, the pFilterQueryLanguage + * parameter must be non-null. This value shall act + * as an additional filter on the result set. If the + * implementation does not support the query language specified, + * the CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error + * shall be returned. If the implementation does not support + * filtered enumerations, the + * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error + * shall be returned. + * @param pTimeout + * This input parameter determines the minimum time the CIM + * server shall maintain the open enumeration session after the + * last Open or Pull operation (unless the enumeration session is + * closed). If the operation timeout is exceeded, the + * implementation may close the enumeration session at any time, + * releasing any resources allocated to the enumeration session. + * A pTimeout of 0 means that there is no operation + * timeout. That is, the enumeration session is never closed + * based on time. If pTimeout is null, + * the implementation shall choose an operation timeout. All + * other values for pTimeout specify the operation + * timeout in seconds. A implementation may restrict the set of + * allowable values for pTimeout. Specifically, the + * implementation may not allow 0 (no timeout). If the specified + * value is not an allowable value, the implementation shall + * return failure with the status code + * CIM_ERR_INVALID_OPERATION_TIMEOUT. + * @param pContinueOnError + * If true, requests that the operation resume when + * an error is received. If a implementation does not support + * continuation on error and pContinueOnError is + * true, it shall throw a WBEMException + * with the status code + * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED. If a + * implementation supports continuation on error and + * pContinueOnError is true, the + * enumeration session shall remain open when a Pull operation + * fails, and any subsequent successful Pull operations shall + * return the set of elements that would have been returned if + * the failing Pull operations were successful. This behavior is + * subject to the consistency rules defined for pulled + * enumerations. If pContinueOnError is + * false, the enumeration session shall be closed + * when either the operation completes successfully or when a + * WBEMExcetpion is thrown. + * @param pMaxObjects + * Defines the maximum number of elements that this Open + * operation can return. The implementation may deliver any + * number of elements up to pMaxObjects but shall + * not deliver more than pMaxObjects elements. An + * implementation may choose to never return any elements during + * an Open operation, regardless of the value of + * pMaxObjects. Note that a CIM client can use a + * pMaxObjects value of 0 to specify that it does + * not want to retrieve any instances in the Open operation. + * @return The return value of a successful Open operation is an array of + * enumerated elements with a number of entries from 0 up to a + * maximum defined by pMaxObjects. These entries meet + * the criteria defined in the Open operation. Note that returning + * no entries in the array does not imply that the enumeration + * session is exhausted. Client must evaluate the + * EnumerateResponse.isEnd() to determine if there are + * more elements. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_SERVER_IS_SHUTTING_DOWN + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_OPERATION_TIMEOUT + * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED + * CIM_ERR_INVALID_PARAMETER + * CIM_ERR_INVALID_CLASS (the source class does not exist) + * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED + * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED + * CIM_ERR_INVALID_QUERY + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public EnumerateResponse enumerateInstancePaths( + CIMObjectPath pClassPath, + String pFilterQueryLanguage, + String pFilterQuery, + UnsignedInteger32 pTimeout, + boolean pContinueOnError, + UnsignedInteger32 pMaxObjects + ) + throws WBEMException; + + /** + * Enumerate the instances of a class. The instances of all subclasses are + * also returned. + * + * @param pPath + * The object path of the class to be enumerated. Only the + * namespace and class name components are used. Any other + * information (e.g. Keys) is ignored. + * @param pDeep + * If true, this specifies that, for each returned + * Instance of the Class, all properties of the Instance must be + * present (subject to constraints imposed by the other + * parameters), including any which were added by subclassing the + * specified Class. If false, each returned Instance + * includes only properties defined for the specified Class in + * path. + * @param pLocalOnly + * If true, only properties that were instantiated + * in the instance are returned. WBEM Servers may ignore this + * parameter and return all properties. + * @param pIncludeClassOrigin + * The class origin attribute is the name of the class that first + * defined the property. If true, the class origin + * attribute may be present for each property on all returned + * CIMInstances, even if requested the server may ignore the + * request and not return the class origin. If false + * , the class origin shall not be present. + * @param pPropertyList + * An array of property names used to filter what is contained in + * the instances returned. Each instance returned only contains + * elements for the properties of the names specified. Duplicate + * and invalid property names are ignored and the request is + * otherwise processed normally. An empty array indicates that no + * properties should be returned. A null value indicates + * that all properties should be returned. + * @return A CloseableIterator of CIMInstances. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (for this method) + * CIM_ERR_INVALID_CLASS (in this namespace) + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public CloseableIterator enumerateInstances( + CIMObjectPath pPath, + boolean pDeep, + boolean pLocalOnly, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException; + + /** + * enumerateInstances shall enumerate the instances of the + * specified class in pClassPath and return zero or more + * CIMInstances. + * + * @param pClassPath + * The CIMObjectPath for the class for which the + * enumeration is to be performed. + * @param pDeepInheritance + * If true, this specifies that, for each returned + * Instance of the Class, all properties of the Instance must be + * present (subject to constraints imposed by the other + * parameters), including any which were added by subclassing the + * specified Class. If false, each returned Instance + * includes only properties defined for the specified Class in + * path. + * @param pIncludeClassOrigin + * The class origin attribute is the name of the class that first + * defined the property. If true, the class origin + * attribute may be present for each property on all instances + * returned, even if requested the server may ignore the request + * and not return the class origin. If false, the + * class origin shall not be present. + * @param pPropertyList + * An array of property names used to filter what is contained in + * the Objects returned. Each CIMInstance returned + * only contains elements for the properties of the names + * specified. Duplicate and invalid property names are ignored + * and the request is otherwise processed normally. An empty + * array indicates that no properties should be included in the + * Objects returned. A null value indicates that all + * properties should be contained in the Objects returned. + * @param pFilterQueryLanguage + * The pFilterQueryLanguage represents the query + * language for the pFilterQuery argument. This must + * be left null if a pFilterQuery is + * not supplied. If the implementation does not support the query + * language specified, the + * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error shall + * be returned. If the implementation does not support filtered + * enumerations, the + * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error + * shall be returned. + * @param pFilterQuery + * The pFilterQuery specifies a query in the form of + * the query language specified by the + * pFilterQueryLanguage parameter. If this value is + * not null, the pFilterQueryLanguage + * parameter must be non-null. This value shall act + * as an additional filter on the result set. If the + * implementation does not support the query language specified, + * the CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error + * shall be returned. If the implementation does not support + * filtered enumerations, the + * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error + * shall be returned. + * @param pTimeout + * This input parameter determines the minimum time the CIM + * server shall maintain the open enumeration session after the + * last Open or Pull operation (unless the enumeration session is + * closed). If the operation timeout is exceeded, the + * implementation may close the enumeration session at any time, + * releasing any resources allocated to the enumeration session. + * A pTimeout of 0 means that there is no operation + * timeout. That is, the enumeration session is never closed + * based on time. If pTimeout is null, + * the implementation shall choose an operation timeout. All + * other values for pTimeout specify the operation + * timeout in seconds. A implementation may restrict the set of + * allowable values for pTimeout. Specifically, the + * implementation may not allow 0 (no timeout). If the specified + * value is not an allowable value, the implementation shall + * return failure with the status code + * CIM_ERR_INVALID_OPERATION_TIMEOUT. + * @param pContinueOnError + * If true, requests that the operation resume when + * an error is received. If a implementation does not support + * continuation on error and pContinueOnError is + * true, it shall throw a WBEMException + * with the status code + * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED. If a + * implementation supports continuation on error and + * pContinueOnError is true, the + * enumeration session shall remain open when a Pull operation + * fails, and any subsequent successful Pull operations shall + * return the set of elements that would have been returned if + * the failing Pull operations were successful. This behavior is + * subject to the consistency rules defined for pulled + * enumerations. If pContinueOnError is + * false, the enumeration session shall be closed + * when either the operation completes successfully or when a + * WBEMExcetpion is thrown. + * @param pMaxObjects + * Defines the maximum number of elements that this Open + * operation can return. The implementation may deliver any + * number of elements up to pMaxObjects but shall + * not deliver more than pMaxObjects elements. An + * implementation may choose to never return any elements during + * an Open operation, regardless of the value of + * pMaxObjects. Note that a CIM client can use a + * pMaxObjects value of 0 to specify that it does + * not want to retrieve any instances in the Open operation. + * @return The return value of a successful Open operation is an array of + * enumerated elements with a number of entries from 0 up to a + * maximum defined by pMaxObjects. These entries meet + * the criteria defined in the Open operation. Note that returning + * no entries in the array does not imply that the enumeration + * session is exhausted. Client must evaluate the + * EnumerateResponse.isEnd() to determine if there are + * more elements. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_SERVER_IS_SHUTTING_DOWN + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_OPERATION_TIMEOUT + * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED + * CIM_ERR_INVALID_PARAMETER + * CIM_ERR_INVALID_CLASS (the source class does not exist) + * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED + * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED + * CIM_ERR_INVALID_QUERY + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public EnumerateResponse enumerateInstances( + CIMObjectPath pClassPath, + boolean pDeepInheritance, + boolean pIncludeClassOrigin, + String[] pPropertyList, + String pFilterQueryLanguage, + String pFilterQuery, + UnsignedInteger32 pTimeout, + boolean pContinueOnError, + UnsignedInteger32 pMaxObjects + ) + throws WBEMException; + + /** + * Enumerates the CIM Qualifier types for a specific namespace. + * + * @param pPath + * The CIMObjectPath identifying the namespace whose + * qualifier types are to be enumerated. + * @return A CloseableIterator of CIMQualifierType + * s. + * @throws UnsupportedOperationException + * If the client implementation (or protocol) does not support + * the operation. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized + * or otherwise incorrect parameters) + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public CloseableIterator> enumerateQualifierTypes(CIMObjectPath pPath) throws WBEMException; + + /** + * enumerationCount provides an estimated count of the total + * number of objects in an open enumeration session represented by an + * enumeration context. + * + * @param pPath + * The namespace for the enumeration context. + * @param pEnumerationContext + * The enumeration context to count. + * @return The estimated number of objects. + * @throws UnsupportedOperationException + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_SERVER_IS_SHUTTING_DOWN + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER + * CIM_ERR_INVALID_ENUMERATION_CONTEXT + * CIM_ERR_SERVER_LIMITS_EXCEEDED + * CIM_ERR_FAILED + * + * + */ + public UnsignedInteger64 enumerationCount(CIMObjectPath pPath, String pEnumerationContext) throws WBEMException; + + /** + * execQuery shall execute a query to retrieve objects. + * + * @param pPath + * CIMObjectPath identifying the class to query. + * Only the namespace and class name components are used. All + * other information (e.g. Keys) is ignored. + * @param pQuery + * A string containing the text of the query. + * @param pQueryLanguage + * A string that identifies the query language to use to parse + * the query string specified. + * @return A CloseableIterator of CIMInstances. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED (provider does not support this method) + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized + * or otherwise incorrect parameters) + * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED (the requested query language + * is not recognized) + * CIM_ERR_INVALID_QUERY (the query is not a valid query in the specified + * query language) + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public CloseableIterator execQuery(CIMObjectPath pPath, String pQuery, String pQueryLanguage) + throws WBEMException; + + /** + * execQueryInstances shall execute a query to retrieve + * instances. + * + * @param pObjectName + * The CIMObjectPath representing the namespace to + * be used. + * @param pFilterQuery + * The pFilterQuery specifies a query in the form of + * the query language specified by the + * pFilterQueryLanguage parameter. If this value is + * not null, the pFilterQueryLanguage + * parameter must be non-null. This value shall act + * as an additional filter on the result set. If the + * implementation does not support the query language specified, + * the CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error + * shall be returned. If the implementation does not support + * filtered enumerations, the + * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error + * shall be returned. + * @param pFilterQueryLanguage + * The pFilterQueryLanguage represents the query + * language for the pFilterQuery argument. This must + * be left null if a pFilterQuery is + * not supplied. If the implementation does not support the query + * language specified, the + * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error shall + * be returned. If the implementation does not support filtered + * enumerations, the + * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error + * shall be returned. + * @param pReturnQueryResultClass + * The pReturnQueryResultClass controls whether a + * class definition is returned in pQueryResultClass + * . If it is set to false, + * pQueryResultClass shall be set to + * null on output. If it is set to true + * , the value of the pQueryResultClass on output + * shall be a class definition that defines the properties + * (columns) of each row of the query result. + * @param pTimeout + * This input parameter determines the minimum time the CIM + * server shall maintain the open enumeration session after the + * last Open or Pull operation (unless the enumeration session is + * closed). If the operation timeout is exceeded, the + * implementation may close the enumeration session at any time, + * releasing any resources allocated to the enumeration session. + * A pTimeout of 0 means that there is no operation + * timeout. That is, the enumeration session is never closed + * based on time. If pTimeout is null, + * the implementation shall choose an operation timeout. All + * other values for pTimeout specify the operation + * timeout in seconds. A implementation may restrict the set of + * allowable values for pTimeout. Specifically, the + * implementation may not allow 0 (no timeout). If the specified + * value is not an allowable value, the implementation shall + * return failure with the status code + * CIM_ERR_INVALID_OPERATION_TIMEOUT. + * @param pContinueOnError + * If true, requests that the operation resume when + * an error is received. If a implementation does not support + * continuation on error and pContinueOnError is + * true, it shall throw a WBEMException + * with the status code + * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED. If a + * implementation supports continuation on error and + * pContinueOnError is true, the + * enumeration session shall remain open when a Pull operation + * fails, and any subsequent successful Pull operations shall + * return the set of elements that would have been returned if + * the failing Pull operations were successful. This behavior is + * subject to the consistency rules defined for pulled + * enumerations. If pContinueOnError is + * false, the enumeration session shall be closed + * when either the operation completes successfully or when a + * WBEMExcetpion is thrown. + * @param pMaxObjects + * Defines the maximum number of elements that this Open + * operation can return. The implementation may deliver any + * number of elements up to pMaxObjects but shall + * not deliver more than pMaxObjects elements. An + * implementation may choose to never return any elements during + * an Open operation, regardless of the value of + * pMaxObjects. Note that a CIM client can use a + * pMaxObjects value of 0 to specify that it does + * not want to retrieve any instances in the Open operation. + * @param pQueryResultClass + * The pQueryResultClass is an output argument. It + * shall be null if the + * pReturnQueryResultClass input parameter is set to + * false. Otherwise, it shall return a class + * definition where each property of the class corresponds to one + * entry of the query select list. The class definition + * corresponds to one row of the query result. The class name of + * this returned class shall be "CIM_QueryResult". This class + * definition is valid only in the context of this enumeration. + * @return The return value of a successful Open operation is an array of + * enumerated elements with a number of entries from 0 up to a + * maximum defined by pMaxObjects. These entries meet + * the criteria defined in the Open operation. Note that returning + * no entries in the array does not imply that the enumeration + * session is exhausted. Client must evaluate the + * EnumerateResponse.isEnd() to determine if there are + * more elements. + * @throws UnsupportedOperationException + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_SERVER_IS_SHUTTING_DOWN + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_OPERATION_TIMEOUT + * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED + * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized + * or otherwise incorrect parameters) + * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED (the requested filter query + * language is not recognized) + * CIM_ERR_INVALID_QUERY (the filter query is not a valid query in the + * specified filter query language) + * CIM_ERR_QUERY_FEATURE_NOT_SUPPORTED (the query requires support for + * features that are not supported) + * CIM_ERR_FAILED (Some other unspecified error occurred) + * + */ + public EnumerateResponse execQueryInstances( + CIMObjectPath pObjectName, + String pFilterQuery, + String pFilterQueryLanguage, + boolean pReturnQueryResultClass, + UnsignedInteger32 pTimeout, + boolean pContinueOnError, + UnsignedInteger32 pMaxObjects, + CIMClass pQueryResultClass + ) + throws WBEMException; + + /** + * Returns the CIMClass for the specified + * CIMObjectPath. + * + * @param pName + * The object path of the class to be returned. Only the name + * space and class name components are used. All other + * information (e.g. keys) is ignored. + * @param pLocalOnly + * If true, only elements (properties, methods, + * references) overridden or defined in the class are included in + * the CIMClassreturned. If false, all + * elements of the class definition are returned. + * @param pIncludeQualifiers + * If true, all Qualifiers for the class and its + * elements are included in the CIMClass returned. + * If false, no Qualifier information is contained + * in the CIMClass returned. + * @param pIncludeClassOrigin + * The class origin attribute is the name of the class that first + * defined the property or method. If true, the + * class origin attribute shall be present for each property and + * method on all returned CIMClasses. If + * false, the class origin shall not be present. + * @param pPropertyList + * An array of property names used to filter what is contained in + * the CIMClass returned. The CIMClass + * returned only contains elements for the properties of the + * names specified. Duplicate and invalid property names are + * ignored and the request is otherwise processed normally. An + * empty array indicates that no properties should be returned. A + * null value indicates that all properties should + * be returned. + * @return CIMClass meeting the criteria specified. + * @throws UnsupportedOperationException + * If the client implementation (or protocol) does not support + * the operation. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized + * or otherwise incorrect parameters) + * CIM_ERR_NOT_FOUND (the requested CIM Class does not exist in the + * specified namespace) + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public CIMClass getClass( + CIMObjectPath pName, + boolean pLocalOnly, + boolean pIncludeQualifiers, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException; + + /** + * Get a CIMInstance. + * + * @param pName + * The object path of the instance to be returned. The Keys in + * this CIMObjectPath must be populated. + * @param pLocalOnly + * If true, only properties overridden or defined in + * the class are included in the CIMInstance + * returned. If false, all properties of the class + * definition are returned. WBEM Servers may ignore this + * parameter and return all properties. + * @param pIncludeClassOrigin + * The class origin attribute is the name of the class that first + * defined the property. If true, the class origin + * attribute may be present for each property of the + * CIMInstance, even if requested the server may + * ignore the request and not return the class origin. If + * false, the class origin shall not be present. + * @param pPropertyList + * An array of property names used to filter what is contained in + * the CIMClass returned. The CIMClass + * returned only contains elements for the properties of the + * names specified. Duplicate and invalid property names are + * ignored and the request is otherwise processed normally. An + * empty array indicates that no properties should be returned. A + * null value indicates that all properties should + * be returned. + * @return CIMInstance identified by the + * CIMObjectPath specified. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED (provider does not support this method) + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (for this method) + * CIM_ERR_INVALID_CLASS (in this namespace) + * CIM_ERR_NOT_FOUND (if instance does not exist) + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public CIMInstance getInstance( + CIMObjectPath pName, + boolean pLocalOnly, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException; + + /** + * getInstancePaths shall get the CIMObjectPaths + * using an enumeration context. + * + * @param pPath + * The CIMObjectPath representing the namespace to + * be used. + * @param pContext + * The enumeration context value for the enumeration session to + * be used. + * @param pMaxObjects + * Defines the maximum number of elements that this Open + * operation can return. The implementation may deliver any + * number of elements up to pMaxObjects but shall + * not deliver more than pMaxObjects elements. An + * implementation may choose to never return any elements during + * an Open operation, regardless of the value of + * pMaxObjects. + * @return EnumerateResponse that includes zero or more + * CIMObjectPath objects. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_SERVER_IS_SHUTTING_DOWN + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER + * CIM_ERR_INVALID_ENUMERATION_CONTEXT + * CIM_ERR_SERVER_LIMITS_EXCEEDED + * CIM_ERR_PULL_HAS_BEEN_ABANDONED + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public EnumerateResponse getInstancePaths( + CIMObjectPath pPath, + String pContext, + UnsignedInteger32 pMaxObjects + ) + throws WBEMException; + + /** + * getInstances shall get the instances from an enumeration + * session started by execQueryInstances. + * + * @param pPath + * The CIMObjectPath representing the namespace to + * be used. + * @param pContext + * The enumeration context value for the enumeration session to + * be used. + * @param pMaxObjects + * Defines the maximum number of elements that this Open + * operation can return. The implementation may deliver any + * number of elements up to pMaxObjects but shall + * not deliver more than pMaxObjects elements. An + * implementation may choose to never return any elements during + * an Open operation, regardless of the value of + * pMaxObjects. Note that a CIM client can use a + * pMaxObjects value of 0 to specify that it does + * not want to retrieve any instances in the Open operation. + * @return EnumerateResponse that includes zero or more + * CIMObjectPath objects. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_SERVER_IS_SHUTTING_DOWN + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER + * CIM_ERR_INVALID_ENUMERATION_CONTEXT + * CIM_ERR_SERVER_LIMITS_EXCEEDED + * CIM_ERR_PULL_HAS_BEEN_ABANDONED + * CIM_ERR_FAILED + * + */ + public EnumerateResponse getInstances( + CIMObjectPath pPath, + String pContext, + UnsignedInteger32 pMaxObjects + ) + throws WBEMException; + + /** + * getInstancesWithPath shall use the enumeration context + * provided to get the next set of instances for the enumeration session. + * + * @param pPath + * The CIMObjectPath representing the namespace to + * be used. + * @param pContext + * The enumeration context value for the enumeration session to + * be used. + * @param pMaxObjects + * Defines the maximum number of elements that this Open + * operation can return. The implementation may deliver any + * number of elements up to pMaxObjects but shall + * not deliver more than pMaxObjects elements. An + * implementation may choose to never return any elements during + * an Open operation, regardless of the value of + * pMaxObjects. + * @return EnumerateResponse that includes zero or more + * CIMObjectPath. objects. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_SERVER_IS_SHUTTING_DOWN + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER + * CIM_ERR_INVALID_ENUMERATION_CONTEXT + * CIM_ERR_SERVER_LIMITS_EXCEEDED + * CIM_ERR_PULL_HAS_BEEN_ABANDONED + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public EnumerateResponse getInstancesWithPath( + CIMObjectPath pPath, + String pContext, + UnsignedInteger32 pMaxObjects + ) + throws WBEMException; + + /** + * Get property values. See WBEMClientConstants for a list of + * standard properties. + * + * @param pKey + * The name of the property. + * @return The value of the property. + * @see WBEMClientConstants + */ + public String getProperty(String pKey); + + /** + * Get a CIMQualifierType. + * + * @param pName + * CIMObjectPath that identifies the + * CIMQualifierType to return. + * @return The CIMQualifierType object. + * @throws UnsupportedOperationException + * If the client implementation (or protocol) does not support + * the operation. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized + * or otherwise incorrect parameters) + * CIM_ERR_NOT_FOUND (the requested Qualifier declaration did not exist) + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public CIMQualifierType getQualifierType(CIMObjectPath pName) throws WBEMException; + + /** + * Initialize the client connection. This must be called before any + * operations. This must only be called once. + * + * @param pName + * The protocol and host to use (e.g. http://192.168.1.128/). Any + * other fields shall be ignored. + * @param pSubject + * The principal/credential pairs for this connection. + * @param pLocales + * An array of locales in order of priority of preference. + * @throws IllegalArgumentException + * If the host or scheme portion of the object path is null, or + * if the protocol is not supported. + * @throws WBEMException + * If the protocol adapter or security cannot be initialized. + */ + public void initialize(CIMObjectPath pName, Subject pSubject, Locale[] pLocales) + throws IllegalArgumentException, WBEMException; + + /** + * Executes the specified method on the specified object. + * + * @param pName + * CIM object path of the object whose method must be invoked. It + * must include all of the keys. + * @param pMethodName + * The name of the method to be invoked. + * @param pInputArguments + * The CIMArgument array of method input parameters. + *

      + * @param pOutputArguments + * The CIMArgument array of method output + * parameters. The array should be allocated large enough to hold + * all returned parameters. + * @return The return value of the specified method. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED (implementation DOES NOT support ANY + * Extrinsic Method Invocation) + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (for this method) + * CIM_ERR_NOT_FOUND (if instance does not exist) + * CIM_ERR_METHOD_NOT_FOUND + * CIM_ERR_METHOD_NOT_AVAILABLE + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public Object invokeMethod( + CIMObjectPath pName, + String pMethodName, + CIMArgument[] pInputArguments, + CIMArgument[] pOutputArguments + ) + throws WBEMException; + + /** + * Modify the CIMClass. + * + * @param pClass + * CIMClass to be modified. + * @throws UnsupportedOperationException + * If the client implementation (or protocol) does not support + * the operation. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized + * or otherwise incorrect parameters) + * CIM_ERR_INVALID_SUPERCLASS (the putative CIM Class declares a + * non-existent superclass) + * CIM_ERR_CLASS_HAS_CHILDREN (the modification could not be performed + * because it was not possible to update the subclasses of the Class + * in a consistent fashion) + * CIM_ERR_CLASS_HAS_INSTANCES (the modification could not be performed + * because it was not possible to update the instances of the Class in + * a consistent fashion) + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public void modifyClass(CIMClass pClass) throws WBEMException; + + /** + * Modify some or all of the properties of the specified + * CIMInstance. + * + * @param pInstance + * CIMInstance to be modified. All Keys must be + * populated. + * @param pPropertyList + * An array of property names used to specify which values from + * the CIMInstance specified to set. Properties not + * specified in this list but set in the CIMInstance + * specified are not modified. Duplicate property names are + * ignored and the request is otherwise processed normally. If + * the pPropertyList contains invalid property names + * for the instance to be modified, the server shall reject the + * request. An empty array indicates that no properties should be + * modified. A null value indicates that all + * properties should be modified. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED (provider does not support this method) + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (for this method) + * CIM_ERR_INVALID_CLASS (in this namespace) + * CIM_ERR_NOT_FOUND (if instance does not exist) + * CIM_ERR_NO_SUCH_PROPERTY (in this instance) + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public void modifyInstance(CIMInstance pInstance, String[] pPropertyList) throws WBEMException; + + /** + * Enumerates the Association classes that refer to a specified source CIM + * Class. + * + * @param pObjectName + * CIMObjectPath defining the source CIM class whose + * referring classes are to be returned. pObjectName + * shall contain the scheme, host, namespace and object name + * (class name). + * @param pResultClass + * This string shall either contain a valid CIM Class name or be + * null. The pResultClass filters the + * classes returned to contain only the classes of this Class + * name or one of its subclasses. + * @param pRole + * This string MUST either contain a valid Property name or be + * null. It filters the Objects returned to contain + * only Objects referring to the source Object via a Property + * with the specified name. If "Antecedent" is specified, then + * only Associations in which the source Object is the + * "Antecedent" reference are returned. + * @param pIncludeQualifiers + * If true, all Qualifiers for each Object + * (including Qualifiers on the Object and on any returned + * Properties) shall be included in the classes returned. If + * false, no Qualifiers shall be present in each + * class returned. + * @param pIncludeClassOrigin + * The class origin attribute is the name of the class that first + * defined the property or method. If true, the + * class Origin attribute shall be present for each property and + * method on all classes returned. If false, the + * class origin shall not be present. + * @param pPropertyList + * An array of property names used to filter what is contained in + * the Objects returned. Each CIMClass returned + * shall only contains elements for the properties of the names + * specified. Duplicate and invalid property names are ignored + * and the request is otherwise processed normally. An empty + * array indicates that no properties should be included in the + * classes returned. A null value indicates that all + * properties should be contained in the classes returned. + * @return If successful, a CloseableIterator referencing zero + * or more CIMClasses meeting the specified criteria. + * @throws UnsupportedOperationException + * If the client implementation (or protocol) does not support + * the operation. + * @throws WBEMException + * If unsuccessful, one of the following status codes shall be + * returned along with zero or more instance of + * CIM_Error. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized + * or otherwise incorrect parameters) + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + + CloseableIterator referenceClasses( + CIMObjectPath pObjectName, + String pResultClass, + String pRole, + boolean pIncludeQualifiers, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException; + + /** + * Enumerates the Association instances that refer to a specified source CIM + * Instance. + * + * @param pObjectName + * CIMObjectPath defining the source CIM Instance + * whose referring instances are to be returned. The + * pObjectName shall include the host, object name + * and keys. + * @param pResultClass + * This string shall either contain a valid CIM Class name or be + * null. It filters the instances returned to + * contain only the instances of this Class name or one of its + * subclasses. + * @param pRole + * This string shall either contain a valid Property name or be + * null. The role filters the instances returned to + * contain only instances referring to the source instance via a + * property with the specified name. For example, If "Antecedent" + * is specified, then only Associations in which the source + * instance is the "Antecedent" reference are returned. + * @param pIncludeClassOrigin + * The class origin attribute is the name of the class that first + * defined the property. If true, the class origin + * attribute may be present for each property and on all + * instances returned, even if requested the server may ignore + * the request and not return the class origin. If + * false, the class origin shall not be present. + * @param pPropertyList + * An array of property names used to filter what is contained in + * the instances returned. Each CIMInstance returned + * shall only contain elements for the properties of the names + * specified. Duplicate and invalid property names are ignored + * and the request is otherwise processed normally. An empty + * array indicates that no properties should be included in the + * instances returned. A null value indicates that + * all properties supported shall be contained in the instance + * returned. + * @return If successful, a CloseableIterator referencing zero + * or more CIMInstances meeting the specified criteria. + * @throws WBEMException + * If unsuccessful, one of the following status codes shall be + * returned along with zero or more CIM_Error + * instances. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized + * or otherwise incorrect parameters) + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + CloseableIterator referenceInstances( + CIMObjectPath pObjectName, + String pResultClass, + String pRole, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException; + + /** + * Enumerates the CIMObjectPaths of Association Objects that + * refer to a particular source CIM Object. If the source Object is a CIM + * Class, then a CloseableIterator of + * CIMObjectPaths of the Association classes that refer to the + * source Object is returned. If the source Object is a CIM Instance, then a + * CloseableIterator of CIMObjectPaths of the + * CIMInstance objects that refer to the source Object is + * returned. + * + * @param pObjectName + * CIMObjectPath defining the source CIM Object + * whose referring Objects are to be returned. This argument may + * contain either a Class name or the modelpath of an Instance. + * (i.e. Keys populated) + * @param pResultClass + * This string MUST either contain a valid CIM Class name or be + * null. It filters the Objects returned to contain + * only the Objects of this Class name or one of its subclasses. + * @param pRole + * This string MUST either contain a valid Property name or be + * null. It filters the Objects returned to contain + * only Objects referring to the source Object via a Property + * with the specified name. If "Antecedent" is specified, then + * only Associations in which the source Object is the + * "Antecedent" reference are returned. + * @return If successful, a CloseableIterator referencing zero + * or more CIMObjectPaths of CIMClasses or + * CIMInstances meeting the specified criteria. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized + * or otherwise incorrect parameters) + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public CloseableIterator referenceNames(CIMObjectPath pObjectName, String pResultClass, String pRole) + throws WBEMException; + + /** + * referencePaths shall start an enumeration session for + * association instances that have references that refer to the instance + * defined in the pInstancePath parameter and return zero or + * more CIMObjectPath objects. + * + * @param pInstancePath + * The CIMObjectPath for the instance for which the + * enumeration is to be performed. + * @param pResultClass + * This string MUST either contain a valid CIM Class name or be + * null. It filters the Objects returned to contain + * only the Objects of this Class name or one of its subclasses. + * @param pRole + * This string MUST either contain a valid Property name or be + * null. It filters the Objects returned to contain + * only Objects referring to the source Object via a Property + * with the specified name. If "Antecedent" is specified, then + * only Associations in which the source Object is the + * "Antecedent" reference are returned. + * @param pFilterQueryLanguage + * The pFilterQueryLanguage represents the query + * language for the pFilterQuery argument. This must + * be left null if a pFilterQuery is + * not supplied. If the implementation does not support the query + * language specified, the + * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error shall + * be returned. If the implementation does not support filtered + * enumerations, the + * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error + * shall be returned. + * @param pFilterQuery + * The pFilterQuery specifies a query in the form of + * the query language specified by the + * pFilterQueryLanguage parameter. If this value is + * not null, the pFilterQueryLanguage + * parameter must be non-null. This value shall act + * as an additional filter on the result set. If the + * implementation does not support the query language specified, + * the CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error + * shall be returned. If the implementation does not support + * filtered enumerations, the + * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error + * shall be returned. + * @param pTimeout + * This input parameter determines the minimum time the CIM + * server shall maintain the open enumeration session after the + * last Open or Pull operation (unless the enumeration session is + * closed). If the operation timeout is exceeded, the + * implementation may close the enumeration session at any time, + * releasing any resources allocated to the enumeration session. + * A pTimeout of 0 means that there is no operation + * timeout. That is, the enumeration session is never closed + * based on time. If pTimeout is null, + * the implementation shall choose an operation timeout. All + * other values for pTimeout specify the operation + * timeout in seconds. A implementation may restrict the set of + * allowable values for pTimeout. Specifically, the + * implementation may not allow 0 (no timeout). If the specified + * value is not an allowable value, the implementation shall + * return failure with the status code + * CIM_ERR_INVALID_OPERATION_TIMEOUT. + * @param pContinueOnError + * If true, requests that the operation resume when + * an error is received. If a implementation does not support + * continuation on error and pContinueOnError is + * true, it shall throw a WBEMException + * with the status code + * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED. If a + * implementation supports continuation on error and + * pContinueOnError is true, the + * enumeration session shall remain open when a Pull operation + * fails, and any subsequent successful Pull operations shall + * return the set of elements that would have been returned if + * the failing Pull operations were successful. This behavior is + * subject to the consistency rules defined for pulled + * enumerations. If pContinueOnError is + * false, the enumeration session shall be closed + * when either the operation completes successfully or when a + * WBEMExcetpion is thrown. + * @param pMaxObjects + * Defines the maximum number of elements that this Open + * operation can return. The implementation may deliver any + * number of elements up to pMaxObjects but shall + * not deliver more than pMaxObjects elements. An + * implementation may choose to never return any elements during + * an Open operation, regardless of the value of + * pMaxObjects. Note that a CIM client can use a + * pMaxObjects value of 0 to specify that it does + * not want to retrieve any instances in the Open operation. + * @return The return value of a successful Open operation is an array of + * enumerated elements with a number of entries from 0 up to a + * maximum defined by pMaxObjects. These entries meet + * the criteria defined in the Open operation. Note that returning + * no entries in the array does not imply that the enumeration + * session is exhausted. Client must evaluate the + * EnumerateResponse.isEnd() to determine if there are + * more elements. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_SERVER_IS_SHUTTING_DOWN + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_OPERATION_TIMEOUT + * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED + * CIM_ERR_INVALID_PARAMETER + * CIM_ERR_NOT_FOUND (the source instance was not found) + * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED + * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED + * CIM_ERR_INVALID_QUERY + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public EnumerateResponse referencePaths( + CIMObjectPath pInstancePath, + String pResultClass, + String pRole, + String pFilterQueryLanguage, + String pFilterQuery, + UnsignedInteger32 pTimeout, + boolean pContinueOnError, + UnsignedInteger32 pMaxObjects + ) + throws WBEMException; + + /** + * references shall start an enumeration session for + * association instances that have references that refer to the instance + * defined in the pInstancePath parameter and return zero or + * more CIMInstance objects. + * + * @param pInstancePath + * The CIMObjectPath for the instance for which the + * enumeration is to be performed. + * @param pResultClass + * This string shall either contain a CIM Class name or be + * null. It filters the instances returned to + * contain only the instances of this Class name or one of its + * subclasses. + * @param pRole + * This string shall either contain a Property name or be + * null. It filters the instances returned to + * contain only instances referring to the source instance via a + * Property with the specified name. If "Antecedent" is + * specified, then only Associations in which the source instance + * is the "Antecedent" reference are returned. + * @param pIncludeClassOrigin + * The class origin attribute is the name of the class that first + * defined the property. If true, the class origin + * attribute may be present for each property on all instances + * returned, even if requested the server may ignore the request + * and not return the class origin. If false, the + * class origin shall not be present. + * @param pPropertyList + * An array of property names used to filter what is contained in + * the instances returned. Each CIMInstance returned + * only contains elements for the properties of the names + * specified. Duplicate and invalid property names are ignored + * and the request is otherwise processed normally. An empty + * array indicates that no properties should be included in the + * Objects returned. A null value indicates that all + * non-null properties of the instance are included. + * @param pFilterQueryLanguage + * The pFilterQueryLanguage represents the query + * language for the pFilterQuery argument. This must + * be left null if a pFilterQuery is + * not supplied. If the implementation does not support the query + * language specified, the + * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error shall + * be returned. If the implementation does not support filtered + * enumerations, the + * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error + * shall be returned. + * @param pFilterQuery + * The pFilterQuery specifies a query in the form of + * the query language specified by the + * pFilterQueryLanguage parameter. If this value is + * not null, the pFilterQueryLanguage + * parameter must be non-null. This value shall act + * as an additional filter on the result set. If the + * implementation does not support the query language specified, + * the CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED error + * shall be returned. If the implementation does not support + * filtered enumerations, the + * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED error + * shall be returned. + * @param pTimeout + * This input parameter determines the minimum time the CIM + * server shall maintain the open enumeration session after the + * last Open or Pull operation (unless the enumeration session is + * closed). If the operation timeout is exceeded, the + * implementation may close the enumeration session at any time, + * releasing any resources allocated to the enumeration session. + * A pTimeout of 0 means that there is no operation + * timeout. That is, the enumeration session is never closed + * based on time. If pTimeout is null, + * the implementation shall choose an operation timeout. All + * other values for pTimeout specify the operation + * timeout in seconds. A implementation may restrict the set of + * allowable values for pTimeout. Specifically, the + * implementation may not allow 0 (no timeout). If the specified + * value is not an allowable value, the implementation shall + * return failure with the status code + * CIM_ERR_INVALID_OPERATION_TIMEOUT. + * @param pContinueOnError + * If true, requests that the operation resume when + * an error is received. If a implementation does not support + * continuation on error and pContinueOnError is + * true, it shall throw a WBEMException + * with the status code + * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED. If a + * implementation supports continuation on error and + * pContinueOnError is true, the + * enumeration session shall remain open when a Pull operation + * fails, and any subsequent successful Pull operations shall + * return the set of elements that would have been returned if + * the failing Pull operations were successful. This behavior is + * subject to the consistency rules defined for pulled + * enumerations. If pContinueOnError is + * false, the enumeration session shall be closed + * when either the operation completes successfully or when a + * WBEMExcetpion is thrown. + * @param pMaxObjects + * Defines the maximum number of elements that this Open + * operation can return. The implementation may deliver any + * number of elements up to pMaxObjects but shall + * not deliver more than pMaxObjects elements. An + * implementation may choose to never return any elements during + * an Open operation, regardless of the value of + * pMaxObjects. Note that a CIM client can use a + * pMaxObjects value of 0 to specify that it does + * not want to retrieve any instances in the Open operation. + * @return The return value of a successful Open operation is an array of + * enumerated elements with a number of entries from 0 up to a + * maximum defined by pMaxObjects. These entries meet + * the criteria defined in the Open operation. Note that returning + * no entries in the array does not imply that the enumeration + * session is exhausted. Client must evaluate the + * EnumerateResponse.isEnd() to determine if there are + * more elements. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_SERVER_IS_SHUTTING_DOWN + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_OPERATION_TIMEOUT + * CIM_ERR_CONTINUATION_ON_ERROR_NOT_SUPPORTED + * CIM_ERR_INVALID_PARAMETER + * CIM_ERR_NOT_FOUND (the source instance was not found) + * CIM_ERR_FILTERED_ENUMERATION_NOT_SUPPORTED + * CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED + * CIM_ERR_INVALID_QUERY + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public EnumerateResponse references( + CIMObjectPath pInstancePath, + String pResultClass, + String pRole, + boolean pIncludeClassOrigin, + String[] pPropertyList, + String pFilterQueryLanguage, + String pFilterQuery, + UnsignedInteger32 pTimeout, + boolean pContinueOnError, + UnsignedInteger32 pMaxObjects + ) + throws WBEMException; + + /** + * Change the locales that were provided during initialization. + * + * @param pLocales + * An array of locales in order of priority of preference. + */ + public void setLocales(Locale[] pLocales); + + /** + * Set properties that enable options or protocol specific properties. See + * WBEMClientConstants for a list of standard properties. + * + * @param pKey + * The name of the property. + * @param pValue + * The value of the property. + * @throws IllegalArgumentException + * If the name is not a supported property name. + * @see WBEMClientConstants + */ + public void setProperty(String pKey, String pValue); + + /** + * Add a CIMQualifierType to the specified namespace if it does + * not already exist. Otherwise, it modifies the qualifier type to the value + * specified. + * + * @param pQualifierType + * The CIM qualifier type to be added. + * @throws UnsupportedOperationException + * If the client implementation (or protocol) does not support + * the operation. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + * + * CIM_ERR_ACCESS_DENIED + * CIM_ERR_NOT_SUPPORTED + * CIM_ERR_INVALID_NAMESPACE + * CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized + * or otherwise incorrect parameters) + * CIM_ERR_FAILED (some other unspecified error occurred) + * + */ + public void setQualifierType(CIMQualifierType pQualifierType) throws WBEMException; +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/wbem/client/WBEMClientConstants.java b/src/main/java/org/metricshub/wbem/javax/wbem/client/WBEMClientConstants.java similarity index 83% rename from src/main/java/org/sentrysoftware/wbem/javax/wbem/client/WBEMClientConstants.java rename to src/main/java/org/metricshub/wbem/javax/wbem/client/WBEMClientConstants.java index becaeab..d02cde4 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/wbem/client/WBEMClientConstants.java +++ b/src/main/java/org/metricshub/wbem/javax/wbem/client/WBEMClientConstants.java @@ -1,160 +1,157 @@ -/* - (C) Copyright IBM Corp. 2009, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Dave Blaschke, blaschke@us.ibm.com - * - * Change History - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 2882448 2009-10-21 blaschke-oss Add WBEMClientConstants from JSR48 - * 2884718 2009-10-23 blaschke-oss Merge JSR48 and SBLIM client properties - * 2930341 2010-01-12 blaschke-oss Sync up WBEMClientConstants with JSR48 1.0.0 - * 2959264 2010-02-25 blaschke-oss Sync up javax.client.* javadoc with JSR48 1.0.0 - * 3496301 2012-03-02 blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final - * 3496355 2012-03-02 blaschke-oss JSR48 1.0.0: add new WBEMClientConstants - * 3521157 2012-05-10 blaschke-oss JSR48 1.0.0: PROP_ENABLE_*_LOGGING is Level, not 0/1 - */ -package org.sentrysoftware.wbem.javax.wbem.client; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -//Sync'd against JSR48 1.0.0 javadoc (build 1.6.0_18) on Thu Mar 01 12:21:26 EST 2012 -/** - * This class defines the constants used for WBEMClient - * configuration. If a property is tagged as optional an implementation may or - * may not support the property. If the implementation does not support the - * property, it must throw an IllegalArgumentException if the - * property value is attempted to be set. - */ -public class WBEMClientConstants { - - /** - * Use this property to set the list of ciphers the client will support. - * Setting this value to null will use the default set of ciphers provided - * by the version of Java being used. Optional. - */ - public static final String PROP_CLIENT_CIPHERS = "javax.wbem.client.ciphers"; - - /** - * This property along with the PROP_CLIENT_KEYSTORE_PASSWORD and - * PROP_CLIENT_TRUSTSTORE are used to configure mutual authentication. This - * property is used to provide the filename of the keystore. The path can be - * relative or full. Optional. - */ - public static final String PROP_CLIENT_KEYSTORE = "javax.wbem.client.keyStore"; - - /** - * This property along with the PROP_CLIENT_KEYSTORE and - * PROP_CLIENT_TRUSTSTORE are used to configure mutual authentication. This - * property is used to provide the password of the keystore. Optional. - */ - public static final String PROP_CLIENT_KEYSTORE_PASSWORD = "javax.wbem.client.keyStorePassword"; - - /** - * This property along with the PROP_CLIENT_KEYSTORE and - * PROP_CLIENT_KEYSTORE_PASSWORD are used to configure mutual - * authentication. This property is used to provide the filename of the - * truststore. The path can be relative or full. Optional. - */ - public static final String PROP_CLIENT_TRUSTSTORE = "javax.wbem.client.trustStore"; - - /** - * The value for this property is the level of debug requested. - */ - public static final String PROP_ENABLE_CONSOLE_LOGGING = "javax.wbem.client.log.console.enabled"; - - /** - * The value for this property is the level of debug requested. - */ - public static final String PROP_ENABLE_FILE_LOGGING = "javax.wbem.client.log.file.enabled"; - - /** - * The maximum size in bytes for each log file. The default is 5MB. Note - * that when the last entry is written, it may go past the limit. - */ - public static final String PROP_LOG_BYTE_LIMIT = "javax.wbem.client.log.maxfilesize"; - - /** - * Set this property to the directory where the log files are created. The - * default is the directory in which the WBEM client program is run. - */ - public static final String PROP_LOG_DIR = "javax.wbem.client.log.dir"; - - /** - * The name of the client log file. For a WBEM client using the CIM-XML or - * WS-Management protocol the default is cimclient_log_N.txt where N is the - * logfile number. The first client log file number is 0. - */ - public static final String PROP_LOG_FILENAME = "javax.wbem.client.log.filename"; - - /** - * The number of log files that will be used. They will be used in - * round-robin fashion. The default is 3. - */ - public static final String PROP_LOG_NUM_FILES = "javax.wbem.client.log.numfiles"; - - /** - * The timeout for the client to wait for connections. This value is in - * milliseconds. The default is 0 - unlimited. This value must be a valid - * integer. - */ - public static final String PROP_TIMEOUT = "javax.wbem.client.timeout"; - - /** - * This property will enable HTTP chunking for a client request. Set this - * property to "1" to use chunking. Set to "0" to not use chunking. The - * default is 1. Optional. - */ - public static final String PROPERTY_WBEM_CHUNKING = "javax.wbem.chunking"; - - /** - * The CIM-XML Protocol as defined by the DMTF in the following - * specifications: - * - *
      -	 * DSP0200 - CIM Operations over HTTP 
      -	 * DSP0201 - Representation of CIM Using XML 
      -	 * DSP0203 - CIM DTD
      -	 * 
      -	 */
      -	public static final String PROTOCOL_CIMXML = "CIM-XML";
      -
      -	/**
      -	 * The WS-Management Protocol as defined by the DMTF in the following
      -	 * specifications:
      -	 * 
      -	 * 
      -	 * DSP0226 - WS-Management 
      -	 * DSP0227 - WS-Management CIM Binding Specification 
      -	 * DSP0230 - WS-CIM Mapping Specification
      -	 * 
      -	 */
      -	public static final String PROTOCOL_WSMANAGEMENT = "WS-Management";
      -}
      +/*
      +  (C) Copyright IBM Corp. 2009, 2012
      +
      +  THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
      +  ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
      +  CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
      +
      +  You can obtain a current copy of the Eclipse Public License from
      +  http://www.opensource.org/licenses/eclipse-1.0.php
      +
      +  @author : Dave Blaschke, blaschke@us.ibm.com
      + * 
      + * Change History
      + * Flag       Date        Prog         Description
      + * -------------------------------------------------------------------------------
      + * 2882448    2009-10-21  blaschke-oss Add WBEMClientConstants from JSR48
      + * 2884718    2009-10-23  blaschke-oss Merge JSR48 and SBLIM client properties
      + * 2930341    2010-01-12  blaschke-oss Sync up WBEMClientConstants with JSR48 1.0.0
      + * 2959264    2010-02-25  blaschke-oss Sync up javax.client.* javadoc with JSR48 1.0.0
      + * 3496301    2012-03-02  blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final
      + * 3496355    2012-03-02  blaschke-oss JSR48 1.0.0: add new WBEMClientConstants
      + * 3521157    2012-05-10  blaschke-oss JSR48 1.0.0: PROP_ENABLE_*_LOGGING is Level, not 0/1
      + */
      +package org.metricshub.wbem.javax.wbem.client;
      +
      +/*-
      + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
      + * WBEM Java Client
      + * ჻჻჻჻჻჻
      + * Copyright 2023 - 2025 MetricsHub
      + * ჻჻჻჻჻჻
      + * Licensed under the Apache License, Version 2.0 (the "License");
      + * you may not use this file except in compliance with the License.
      + * You may obtain a copy of the License at
      + *
      + *      http://www.apache.org/licenses/LICENSE-2.0
      + *
      + * Unless required by applicable law or agreed to in writing, software
      + * distributed under the License is distributed on an "AS IS" BASIS,
      + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      + * See the License for the specific language governing permissions and
      + * limitations under the License.
      + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
      + */
      +
      +//Sync'd against JSR48 1.0.0 javadoc (build 1.6.0_18) on Thu Mar 01 12:21:26 EST 2012
      +/**
      + * This class defines the constants used for WBEMClient
      + * configuration. If a property is tagged as optional an implementation may or
      + * may not support the property. If the implementation does not support the
      + * property, it must throw an IllegalArgumentException if the
      + * property value is attempted to be set.
      + */
      +public class WBEMClientConstants {
      +	/**
      +	 * Use this property to set the list of ciphers the client will support.
      +	 * Setting this value to null will use the default set of ciphers provided
      +	 * by the version of Java being used. Optional.
      +	 */
      +	public static final String PROP_CLIENT_CIPHERS = "javax.wbem.client.ciphers";
      +
      +	/**
      +	 * This property along with the PROP_CLIENT_KEYSTORE_PASSWORD and
      +	 * PROP_CLIENT_TRUSTSTORE are used to configure mutual authentication. This
      +	 * property is used to provide the filename of the keystore. The path can be
      +	 * relative or full. Optional.
      +	 */
      +	public static final String PROP_CLIENT_KEYSTORE = "javax.wbem.client.keyStore";
      +
      +	/**
      +	 * This property along with the PROP_CLIENT_KEYSTORE and
      +	 * PROP_CLIENT_TRUSTSTORE are used to configure mutual authentication. This
      +	 * property is used to provide the password of the keystore. Optional.
      +	 */
      +	public static final String PROP_CLIENT_KEYSTORE_PASSWORD = "javax.wbem.client.keyStorePassword";
      +
      +	/**
      +	 * This property along with the PROP_CLIENT_KEYSTORE and
      +	 * PROP_CLIENT_KEYSTORE_PASSWORD are used to configure mutual
      +	 * authentication. This property is used to provide the filename of the
      +	 * truststore. The path can be relative or full. Optional.
      +	 */
      +	public static final String PROP_CLIENT_TRUSTSTORE = "javax.wbem.client.trustStore";
      +
      +	/**
      +	 * The value for this property is the level of debug requested.
      +	 */
      +	public static final String PROP_ENABLE_CONSOLE_LOGGING = "javax.wbem.client.log.console.enabled";
      +
      +	/**
      +	 * The value for this property is the level of debug requested.
      +	 */
      +	public static final String PROP_ENABLE_FILE_LOGGING = "javax.wbem.client.log.file.enabled";
      +
      +	/**
      +	 * The maximum size in bytes for each log file. The default is 5MB. Note
      +	 * that when the last entry is written, it may go past the limit.
      +	 */
      +	public static final String PROP_LOG_BYTE_LIMIT = "javax.wbem.client.log.maxfilesize";
      +
      +	/**
      +	 * Set this property to the directory where the log files are created. The
      +	 * default is the directory in which the WBEM client program is run.
      +	 */
      +	public static final String PROP_LOG_DIR = "javax.wbem.client.log.dir";
      +
      +	/**
      +	 * The name of the client log file. For a WBEM client using the CIM-XML or
      +	 * WS-Management protocol the default is cimclient_log_N.txt where N is the
      +	 * logfile number. The first client log file number is 0.
      +	 */
      +	public static final String PROP_LOG_FILENAME = "javax.wbem.client.log.filename";
      +
      +	/**
      +	 * The number of log files that will be used. They will be used in
      +	 * round-robin fashion. The default is 3.
      +	 */
      +	public static final String PROP_LOG_NUM_FILES = "javax.wbem.client.log.numfiles";
      +
      +	/**
      +	 * The timeout for the client to wait for connections. This value is in
      +	 * milliseconds. The default is 0 - unlimited. This value must be a valid
      +	 * integer.
      +	 */
      +	public static final String PROP_TIMEOUT = "javax.wbem.client.timeout";
      +
      +	/**
      +	 * This property will enable HTTP chunking for a client request. Set this
      +	 * property to "1" to use chunking. Set to "0" to not use chunking. The
      +	 * default is 1. Optional.
      +	 */
      +	public static final String PROPERTY_WBEM_CHUNKING = "javax.wbem.chunking";
      +
      +	/**
      +	 * The CIM-XML Protocol as defined by the DMTF in the following
      +	 * specifications:
      +	 *
      +	 * 
      +	 * DSP0200 - CIM Operations over HTTP
      +	 * DSP0201 - Representation of CIM Using XML
      +	 * DSP0203 - CIM DTD
      +	 *
      +	 */
      +	public static final String PROTOCOL_CIMXML = "CIM-XML";
      +
      +	/**
      +	 * The WS-Management Protocol as defined by the DMTF in the following
      +	 * specifications:
      +	 *
      +	 * 
      +	 * DSP0226 - WS-Management
      +	 * DSP0227 - WS-Management CIM Binding Specification
      +	 * DSP0230 - WS-CIM Mapping Specification
      +	 *
      +	 */
      +	public static final String PROTOCOL_WSMANAGEMENT = "WS-Management";
      +}
      diff --git a/src/main/java/org/sentrysoftware/wbem/javax/wbem/client/WBEMClientFactory.java b/src/main/java/org/metricshub/wbem/javax/wbem/client/WBEMClientFactory.java
      similarity index 72%
      rename from src/main/java/org/sentrysoftware/wbem/javax/wbem/client/WBEMClientFactory.java
      rename to src/main/java/org/metricshub/wbem/javax/wbem/client/WBEMClientFactory.java
      index ec48a00..08d00db 100644
      --- a/src/main/java/org/sentrysoftware/wbem/javax/wbem/client/WBEMClientFactory.java
      +++ b/src/main/java/org/metricshub/wbem/javax/wbem/client/WBEMClientFactory.java
      @@ -1,116 +1,114 @@
      -/*
      -  (C) Copyright IBM Corp. 2006, 2012
      -
      -  THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
      -  ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
      -  CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
      -
      -  You can obtain a current copy of the Eclipse Public License from
      -  http://www.opensource.org/licenses/eclipse-1.0.php
      -
      -  @author : Alexander Wolf-Reber, a.wolf-reber@de.ibm.com
      - * 
      - * Change History
      - * Flag       Date        Prog         Description
      - * -------------------------------------------------------------------------------
      - * 1565892    2006-11-08  lupusalex    Make SBLIM client JSR48 compliant
      - * 1737141    2007-06-18  ebak         Sync up with JSR48 evolution
      - * 2003590    2008-06-30  blaschke-oss Change licensing from CPL to EPL
      - * 2204488 	  2008-10-28  raman_arora  Fix code to remove compiler warnings
      - * 2524131    2009-01-21  raman_arora  Upgrade client to JDK 1.5 (Phase 1)
      - * 2882448    2009-10-21  blaschke-oss Add WBEMClientConstants from JSR48
      - * 2959264    2010-02-25  blaschke-oss Sync up javax.client.* javadoc with JSR48 1.0.0
      - * 3490355    2012-02-21  blaschke-oss TCK: Cannot instantiate WBEMClientFactory
      - */
      -
      -package org.sentrysoftware.wbem.javax.wbem.client;
      -
      -/*-
      - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
      - * WBEM Java Client
      - * ჻჻჻჻჻჻
      - * Copyright (C) 2023 Sentry Software
      - * ჻჻჻჻჻჻
      - * This program is free software: you can redistribute it and/or modify
      - * it under the terms of the GNU Lesser General Public License as
      - * published by the Free Software Foundation, either version 3 of the
      - * License, or (at your option) any later version.
      - *
      - * This program is distributed in the hope that it will be useful,
      - * but WITHOUT ANY WARRANTY; without even the implied warranty of
      - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      - * GNU General Lesser Public License for more details.
      - *
      - * You should have received a copy of the GNU General Lesser Public
      - * License along with this program.  If not, see
      - * .
      - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
      - */
      -
      -import org.sentrysoftware.wbem.javax.wbem.WBEMException;
      -
      -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.WBEMClientCIMXML;
      -
      -//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010
      -/**
      - * This class defines the functionality of a WBEMClient factory,
      - * which is used to retrieve a WBEMClient for a specified protocol.
      - * An example of how to use the factory is included below.
      - * 
      - * 
      - *   ...
      - *   WBEMClient cc = null;
      - *   
      - *   try {
      - *     cc = WBEMClientFactory.getClient(WBEMClientConstants.PROTOCOL_CIMXML);
      - *   } catch (Exception e) {
      - *     System.out.println("Received error when trying to retrieve client handle");
      - *     System.exit(-1);
      - *   }
      - *   
      - *   // initialize the client 
      - *   cc.initialize(cns, s, null);
      - *   ...
      - * 
      - */ - -public class WBEMClientFactory extends Object { - - private static final String[] cProtocols = { WBEMClientConstants.PROTOCOL_CIMXML }; - - /** - * - */ - public WBEMClientFactory() { /**/} - - /** - * Get a WBEMClient for a protocol. - * - * @param pProtocol - * The protocol name (e.g. "CIM-XML"). - * @return The WBEMClient implementation for the protocol - * specified. - * @throws IllegalArgumentException - *
      If the protocol is - * null or empty.
      If the protocol is not - * supported.
      - * @throws WBEMException - * If the protocol implementation could not be loaded. - */ - public static WBEMClient getClient(String pProtocol) throws WBEMException { - - if (WBEMClientConstants.PROTOCOL_CIMXML.equalsIgnoreCase(pProtocol)) { return new WBEMClientCIMXML(); } - - throw new IllegalArgumentException("\"" + pProtocol + "\" is not a supported protocol"); - } - - /** - * Get the names of the supported protocols. - * - * @return A string array of the supported protocols. - */ - public static String[] getSupportedProtocols() { - return cProtocols; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-11-08 lupusalex Make SBLIM client JSR48 compliant + * 1737141 2007-06-18 ebak Sync up with JSR48 evolution + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2882448 2009-10-21 blaschke-oss Add WBEMClientConstants from JSR48 + * 2959264 2010-02-25 blaschke-oss Sync up javax.client.* javadoc with JSR48 1.0.0 + * 3490355 2012-02-21 blaschke-oss TCK: Cannot instantiate WBEMClientFactory + */ + +package org.metricshub.wbem.javax.wbem.client; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.wbem.WBEMException; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.WBEMClientCIMXML; + +//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 +/** + * This class defines the functionality of a WBEMClient factory, + * which is used to retrieve a WBEMClient for a specified protocol. + * An example of how to use the factory is included below. + * + *
      + *   ...
      + *   WBEMClient cc = null;
      + *
      + *   try {
      + *     cc = WBEMClientFactory.getClient(WBEMClientConstants.PROTOCOL_CIMXML);
      + *   } catch (Exception e) {
      + *     System.out.println("Received error when trying to retrieve client handle");
      + *     System.exit(-1);
      + *   }
      + *
      + *   // initialize the client
      + *   cc.initialize(cns, s, null);
      + *   ...
      + * 
      + */ + +public class WBEMClientFactory { + private static final String[] cProtocols = { WBEMClientConstants.PROTOCOL_CIMXML }; + + /** + * + */ + public WBEMClientFactory() { + /**/ + } + + /** + * Get a WBEMClient for a protocol. + * + * @param pProtocol + * The protocol name (e.g. "CIM-XML"). + * @return The WBEMClient implementation for the protocol + * specified. + * @throws IllegalArgumentException + *
      If the protocol is + * null or empty.
      If the protocol is not + * supported.
      + * @throws WBEMException + * If the protocol implementation could not be loaded. + */ + public static WBEMClient getClient(String pProtocol) throws WBEMException { + if (WBEMClientConstants.PROTOCOL_CIMXML.equalsIgnoreCase(pProtocol)) { + return new WBEMClientCIMXML(); + } + + throw new IllegalArgumentException("\"" + pProtocol + "\" is not a supported protocol"); + } + + /** + * Get the names of the supported protocols. + * + * @return A string array of the supported protocols. + */ + public static String[] getSupportedProtocols() { + return cProtocols; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/wbem/client/package.html b/src/main/java/org/metricshub/wbem/javax/wbem/client/package.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/javax/wbem/client/package.html rename to src/main/java/org/metricshub/wbem/javax/wbem/client/package.html diff --git a/src/main/java/org/sentrysoftware/wbem/javax/wbem/listener/IndicationListener.java b/src/main/java/org/metricshub/wbem/javax/wbem/listener/IndicationListener.java similarity index 69% rename from src/main/java/org/sentrysoftware/wbem/javax/wbem/listener/IndicationListener.java rename to src/main/java/org/metricshub/wbem/javax/wbem/listener/IndicationListener.java index 5fc1a9e..fe03af6 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/wbem/listener/IndicationListener.java +++ b/src/main/java/org/metricshub/wbem/javax/wbem/listener/IndicationListener.java @@ -1,70 +1,65 @@ -/* - (C) Copyright IBM Corp. 2006, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1565892 2006-12-14 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2959240 2010-02-25 blaschke-oss Sync up javax.listener.* javadoc with JSR48 1.0.0 - */ - -package org.sentrysoftware.wbem.javax.wbem.listener; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.EventListener; - -import org.sentrysoftware.wbem.javax.cim.CIMInstance; - -//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 -/** - * This interface is implemented by the code that wants to create a listener for - * indications. See the WBEMListenerFactory class for an example. - */ -public interface IndicationListener extends EventListener { - - /** - * Called when an indication has been received by the listener - * - * @param pIndicationURL - * The URL to which the indication was posted. For example if the - * indication was delivered over the https protocol to the - * destination listener https://hostname:6111/, pIndicationURL - * would be set to https://hostname:6111/. - * @param pIndication - * The indication received. - */ - public void indicationOccured(String pIndicationURL, CIMInstance pIndication); - -} +/* + (C) Copyright IBM Corp. 2006, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1565892 2006-12-14 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2959240 2010-02-25 blaschke-oss Sync up javax.listener.* javadoc with JSR48 1.0.0 + */ + +package org.metricshub.wbem.javax.wbem.listener; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.EventListener; +import org.metricshub.wbem.javax.cim.CIMInstance; + +//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 +/** + * This interface is implemented by the code that wants to create a listener for + * indications. See the WBEMListenerFactory class for an example. + */ +public interface IndicationListener extends EventListener { + /** + * Called when an indication has been received by the listener + * + * @param pIndicationURL + * The URL to which the indication was posted. For example if the + * indication was delivered over the https protocol to the + * destination listener https://hostname:6111/, pIndicationURL + * would be set to https://hostname:6111/. + * @param pIndication + * The indication received. + */ + public void indicationOccured(String pIndicationURL, CIMInstance pIndication); +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/wbem/listener/WBEMListener.java b/src/main/java/org/metricshub/wbem/javax/wbem/listener/WBEMListener.java similarity index 77% rename from src/main/java/org/sentrysoftware/wbem/javax/wbem/listener/WBEMListener.java rename to src/main/java/org/metricshub/wbem/javax/wbem/listener/WBEMListener.java index f7cbce3..6cba4d4 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/wbem/listener/WBEMListener.java +++ b/src/main/java/org/metricshub/wbem/javax/wbem/listener/WBEMListener.java @@ -1,124 +1,119 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1565892 2006-12-14 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2959240 2010-02-25 blaschke-oss Sync up javax.listener.* javadoc with JSR48 1.0.0 - * 3496385 2012-03-02 blaschke-oss JSR48 1.0.0: add WBEMListener get/setProperty - */ - -package org.sentrysoftware.wbem.javax.wbem.listener; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; - -//Sync'd against JSR48 1.0.0 javadoc (build 1.6.0_18) on Thu Mar 01 12:21:26 EST 2012 -/** - * The WBEMListener interface is used to add/remove WBEM Indication - * Listeners. The implementation of a WBEMListener can be retrieved - * from the WBEMListenerFactor by specifying the protocol to use to - * listen for indications. - */ -public interface WBEMListener { - - /** - * Add a new listener using the specified port. - * - * @param pListener - * The Indication Listener that will be called when an indication - * is received. - * @param pPort - * The port to listen on. Use 0 to specify any available port. - * @param pTransport - * The transport to use (e.g. HTTP or HTTPS). - * @return The port that was used. - * @throws IOException - * If the port is already in use. - */ - public int addListener(IndicationListener pListener, int pPort, String pTransport) - throws IOException; - - /** - * Add a new listener using the specified port. - * - * @param pListener - * The Indication Listener that will be called when an indication - * is received. - * @param pPort - * The port to listen on. Use 0 to specify any available port. - * @param pTransport - * The transport to use (e.g. HTTP or HTTPS). - * @param localAddr - * The local IP address to bind to. This is only needed in - * multi-homed systems. - * @return The port that was used. - * @throws IOException - * If the port is already in use. - */ - public int addListener(IndicationListener pListener, int pPort, String pTransport, - String localAddr) throws IOException; - - /** - * Get a property value. - * - * @param pName - * The name of the property. - * @return The value of the property. - */ - public String getProperty(String pName); - - /** - * Remove the listener associated with the specified port. - * - * @param pPort - * The port. - */ - public void removeListener(int pPort); - - /** - * Set a property for the WBEM Listener. - * - * @param pName - * The name of the property. - * @param pValue - * The value of the property. - * @throws IllegalArgumentException - * If the name is not a supported property name. - */ - public void setProperty(String pName, String pValue); - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1565892 2006-12-14 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2959240 2010-02-25 blaschke-oss Sync up javax.listener.* javadoc with JSR48 1.0.0 + * 3496385 2012-03-02 blaschke-oss JSR48 1.0.0: add WBEMListener get/setProperty + */ + +package org.metricshub.wbem.javax.wbem.listener; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; + +//Sync'd against JSR48 1.0.0 javadoc (build 1.6.0_18) on Thu Mar 01 12:21:26 EST 2012 +/** + * The WBEMListener interface is used to add/remove WBEM Indication + * Listeners. The implementation of a WBEMListener can be retrieved + * from the WBEMListenerFactor by specifying the protocol to use to + * listen for indications. + */ +public interface WBEMListener { + /** + * Add a new listener using the specified port. + * + * @param pListener + * The Indication Listener that will be called when an indication + * is received. + * @param pPort + * The port to listen on. Use 0 to specify any available port. + * @param pTransport + * The transport to use (e.g. HTTP or HTTPS). + * @return The port that was used. + * @throws IOException + * If the port is already in use. + */ + public int addListener(IndicationListener pListener, int pPort, String pTransport) throws IOException; + + /** + * Add a new listener using the specified port. + * + * @param pListener + * The Indication Listener that will be called when an indication + * is received. + * @param pPort + * The port to listen on. Use 0 to specify any available port. + * @param pTransport + * The transport to use (e.g. HTTP or HTTPS). + * @param localAddr + * The local IP address to bind to. This is only needed in + * multi-homed systems. + * @return The port that was used. + * @throws IOException + * If the port is already in use. + */ + public int addListener(IndicationListener pListener, int pPort, String pTransport, String localAddr) + throws IOException; + + /** + * Get a property value. + * + * @param pName + * The name of the property. + * @return The value of the property. + */ + public String getProperty(String pName); + + /** + * Remove the listener associated with the specified port. + * + * @param pPort + * The port. + */ + public void removeListener(int pPort); + + /** + * Set a property for the WBEM Listener. + * + * @param pName + * The name of the property. + * @param pValue + * The value of the property. + * @throws IllegalArgumentException + * If the name is not a supported property name. + */ + public void setProperty(String pName, String pValue); +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/wbem/listener/WBEMListenerConstants.java b/src/main/java/org/metricshub/wbem/javax/wbem/listener/WBEMListenerConstants.java similarity index 76% rename from src/main/java/org/sentrysoftware/wbem/javax/wbem/listener/WBEMListenerConstants.java rename to src/main/java/org/metricshub/wbem/javax/wbem/listener/WBEMListenerConstants.java index 3408129..d173999 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/wbem/listener/WBEMListenerConstants.java +++ b/src/main/java/org/metricshub/wbem/javax/wbem/listener/WBEMListenerConstants.java @@ -1,81 +1,78 @@ -/* - (C) Copyright IBM Corp. 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Dave Blaschke, blaschke@us.ibm.com - * - * Change History - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 3496380 2012-03-02 blaschke-oss JSR48 1.0.0: add new WBEMListenerConstants - */ -package org.sentrysoftware.wbem.javax.wbem.listener; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -//Sync'd against JSR48 1.0.0 javadoc (build 1.6.0_18) on Thu Mar 01 12:21:26 EST 2012 -/** - * This class defines the constants used for WBEMListener - * configuration. If a property is tagged as optional an implementation may or - * may not support the property. If the implementation does not support the - * property, it must throw an IllegalArgumentException if the - * property value is attempted to be set. - */ -public class WBEMListenerConstants { - - /** - * Use this property to set the list of ciphers the listener will support. - * Setting this value to null will use the default set of ciphers provided - * by the version of Java being used. Optional. - */ - public static final String PROP_LISTENER_CIPHERS = "javax.wbem.listener.ciphers"; - - /** - * This property along with the PROP_LISTENER_KEYSTORE_PASSWORD and - * PROP_LISTENER_TRUSTSTORE are used to configure mutual authentication. - * This property is used to provide the filename of the keystore. The path - * can be relative or full. Optional. - */ - public static final String PROP_LISTENER_KEYSTORE = "javax.wbem.listener.keyStore"; - - /** - * This property along with the PROP_LISTENER_KEYSTORE and - * PROP_LISTENER_TRUSTSTORE are used to configure mutual authentication. - * This property is used to provide the password of the keystore. Optional. - */ - public static final String PROP_LISTENER_KEYSTORE_PASSWORD = "javax.wbem.listener.keyStorePassword"; - - /** - * This property along with the PROP_LISTENER_KEYSTORE and - * PROP_LISTENER_KEYSTORE_PASSWORD are used to configure mutual - * authentication. This property is used to provide the filename of the - * truststore. The path can be relative or full. Optional. - */ - public static final String PROP_LISTENER_TRUSTSTORE = "javax.wbem.listener.trustStore"; -} +/* + (C) Copyright IBM Corp. 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Dave Blaschke, blaschke@us.ibm.com + * + * Change History + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 3496380 2012-03-02 blaschke-oss JSR48 1.0.0: add new WBEMListenerConstants + */ +package org.metricshub.wbem.javax.wbem.listener; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +//Sync'd against JSR48 1.0.0 javadoc (build 1.6.0_18) on Thu Mar 01 12:21:26 EST 2012 +/** + * This class defines the constants used for WBEMListener + * configuration. If a property is tagged as optional an implementation may or + * may not support the property. If the implementation does not support the + * property, it must throw an IllegalArgumentException if the + * property value is attempted to be set. + */ +public class WBEMListenerConstants { + /** + * Use this property to set the list of ciphers the listener will support. + * Setting this value to null will use the default set of ciphers provided + * by the version of Java being used. Optional. + */ + public static final String PROP_LISTENER_CIPHERS = "javax.wbem.listener.ciphers"; + + /** + * This property along with the PROP_LISTENER_KEYSTORE_PASSWORD and + * PROP_LISTENER_TRUSTSTORE are used to configure mutual authentication. + * This property is used to provide the filename of the keystore. The path + * can be relative or full. Optional. + */ + public static final String PROP_LISTENER_KEYSTORE = "javax.wbem.listener.keyStore"; + + /** + * This property along with the PROP_LISTENER_KEYSTORE and + * PROP_LISTENER_TRUSTSTORE are used to configure mutual authentication. + * This property is used to provide the password of the keystore. Optional. + */ + public static final String PROP_LISTENER_KEYSTORE_PASSWORD = "javax.wbem.listener.keyStorePassword"; + + /** + * This property along with the PROP_LISTENER_KEYSTORE and + * PROP_LISTENER_KEYSTORE_PASSWORD are used to configure mutual + * authentication. This property is used to provide the filename of the + * truststore. The path can be relative or full. Optional. + */ + public static final String PROP_LISTENER_TRUSTSTORE = "javax.wbem.listener.trustStore"; +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/wbem/listener/WBEMListenerFactory.java b/src/main/java/org/metricshub/wbem/javax/wbem/listener/WBEMListenerFactory.java similarity index 68% rename from src/main/java/org/sentrysoftware/wbem/javax/wbem/listener/WBEMListenerFactory.java rename to src/main/java/org/metricshub/wbem/javax/wbem/listener/WBEMListenerFactory.java index d52009b..a479c34 100644 --- a/src/main/java/org/sentrysoftware/wbem/javax/wbem/listener/WBEMListenerFactory.java +++ b/src/main/java/org/metricshub/wbem/javax/wbem/listener/WBEMListenerFactory.java @@ -1,108 +1,107 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1565892 2006-12-14 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2798931 2009-06-01 raman_arora Fix spelling of getPROTOCOLS() - * 2882448 2009-10-21 blaschke-oss Add WBEMClientConstants from JSR48 - * 2959240 2010-02-25 blaschke-oss Sync up javax.listener.* javadoc with JSR48 1.0.0 - * 3490009 2012-02-21 blaschke-oss TCK: Too many WBEMListenerFactory class methods - * 3529062 2012-05-23 blaschke-oss WBEMListenerFactory should return new instance - */ - -package org.sentrysoftware.wbem.javax.wbem.listener; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.wbem.client.WBEMClientConstants; - -import org.sentrysoftware.wbem.sblim.cimclient.WBEMListenerSBLIM; - -//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 -/** - * This class is a factory for getting a WBEMListener - * implementation for a specified protocol. An example of how to use the factory - * is included below. - * - *
      - * ...
      - * class MyListener implements IndicationListener {
      - * 
      - *   public void indicationOccured(String pIndicationURL, CIMInstance pIndication) {
      - *     System.out.println(pIndication);
      - * 	 }
      - * }
      - * 
      - * String protocol = WBEMClientConstants.PROTOCOL_CIMXML;
      - * WBEMListener api = WBEMListenerFactory.getListener(protocol);
      - * int port = api.addListener(MyListener, 1234, protocol);
      - * 
      - */ -public class WBEMListenerFactory extends Object { - - private static final String[] PROTOCOLS = { WBEMClientConstants.PROTOCOL_CIMXML }; - - /** - * - */ - public WBEMListenerFactory() { /**/} - - /** - * Get a WBEM Listener implementation for the specified protocol. - * - * @param pProtocol - * The protocol name. - * @return Implementation of WBEMListener. - * @throws IllegalArgumentException - * Could not load protocol implementation. - */ - public static WBEMListener getListener(String pProtocol) throws IllegalArgumentException { - - if (WBEMClientConstants.PROTOCOL_CIMXML.equalsIgnoreCase(pProtocol)) { return new WBEMListenerSBLIM(); } - throw new IllegalArgumentException("Protocol: " + pProtocol - + " is not supported! Invoke getProtocols() for the list of " - + "supported protocols."); - } - - /** - * Get the names of the supported protocols. - * - * @return A string array of the protocol names supported. - */ - public static String[] getProtocols() { - return PROTOCOLS; - } -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1565892 2006-12-14 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2798931 2009-06-01 raman_arora Fix spelling of getPROTOCOLS() + * 2882448 2009-10-21 blaschke-oss Add WBEMClientConstants from JSR48 + * 2959240 2010-02-25 blaschke-oss Sync up javax.listener.* javadoc with JSR48 1.0.0 + * 3490009 2012-02-21 blaschke-oss TCK: Too many WBEMListenerFactory class methods + * 3529062 2012-05-23 blaschke-oss WBEMListenerFactory should return new instance + */ + +package org.metricshub.wbem.javax.wbem.listener; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.wbem.client.WBEMClientConstants; +import org.metricshub.wbem.sblim.cimclient.WBEMListenerSBLIM; + +//Sync'd against JSR48 1.0.0 javadoc (build 1.5.0_10) on Wed Jan 20 02:20:59 EST 2010 +/** + * This class is a factory for getting a WBEMListener + * implementation for a specified protocol. An example of how to use the factory + * is included below. + * + *
      + * ...
      + * class MyListener implements IndicationListener {
      + *
      + *   public void indicationOccured(String pIndicationURL, CIMInstance pIndication) {
      + *     System.out.println(pIndication);
      + * 	 }
      + * }
      + *
      + * String protocol = WBEMClientConstants.PROTOCOL_CIMXML;
      + * WBEMListener api = WBEMListenerFactory.getListener(protocol);
      + * int port = api.addListener(MyListener, 1234, protocol);
      + * 
      + */ +public class WBEMListenerFactory { + private static final String[] PROTOCOLS = { WBEMClientConstants.PROTOCOL_CIMXML }; + + /** + * + */ + public WBEMListenerFactory() { + /**/ + } + + /** + * Get a WBEM Listener implementation for the specified protocol. + * + * @param pProtocol + * The protocol name. + * @return Implementation of WBEMListener. + * @throws IllegalArgumentException + * Could not load protocol implementation. + */ + public static WBEMListener getListener(String pProtocol) throws IllegalArgumentException { + if (WBEMClientConstants.PROTOCOL_CIMXML.equalsIgnoreCase(pProtocol)) { + return new WBEMListenerSBLIM(); + } + throw new IllegalArgumentException( + "Protocol: " + pProtocol + " is not supported! Invoke getProtocols() for the list of " + "supported protocols." + ); + } + + /** + * Get the names of the supported protocols. + * + * @return A string array of the protocol names supported. + */ + public static String[] getProtocols() { + return PROTOCOLS; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/javax/wbem/listener/package.html b/src/main/java/org/metricshub/wbem/javax/wbem/listener/package.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/javax/wbem/listener/package.html rename to src/main/java/org/metricshub/wbem/javax/wbem/listener/package.html diff --git a/src/main/java/org/sentrysoftware/wbem/javax/wbem/package.html b/src/main/java/org/metricshub/wbem/javax/wbem/package.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/javax/wbem/package.html rename to src/main/java/org/metricshub/wbem/javax/wbem/package.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/CIMXMLTraceListener.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/CIMXMLTraceListener.java similarity index 67% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/CIMXMLTraceListener.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/CIMXMLTraceListener.java index 18cfdf6..94d4c34 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/CIMXMLTraceListener.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/CIMXMLTraceListener.java @@ -1,68 +1,64 @@ -/* - (C) Copyright IBM Corp. 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * Dave Blaschke, IBM, blaschke@us.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 3554738 2012-08-16 blaschke-oss dump CIM xml by LogAndTraceBroker.trace() - */ - -package org.sentrysoftware.wbem.sblim.cimclient; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.logging.Level; - -/** - * The interface CIMXMLTraceListener must be implemented if you want to attach - * your own CIM-XML logging framework to the CIM Client. - * - * @see LogAndTraceManager - */ -public interface CIMXMLTraceListener { - - /** - * Receive a CIM-XML trace message. - * - * @param pLevel - * One of the message level identifiers, e.g. FINE - * @param pMessage - * The CIM-XML message text - * @param pOutgoing - * true if CIM-XML is outgoing (being sent from - * client to server), false if CIM-XML is incoming - * (being sent from server to client) - */ - public void traceCIMXML(Level pLevel, String pMessage, boolean pOutgoing); - -} +/* + (C) Copyright IBM Corp. 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * Dave Blaschke, IBM, blaschke@us.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 3554738 2012-08-16 blaschke-oss dump CIM xml by LogAndTraceBroker.trace() + */ + +package org.metricshub.wbem.sblim.cimclient; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.logging.Level; + +/** + * The interface CIMXMLTraceListener must be implemented if you want to attach + * your own CIM-XML logging framework to the CIM Client. + * + * @see LogAndTraceManager + */ +public interface CIMXMLTraceListener { + /** + * Receive a CIM-XML trace message. + * + * @param pLevel + * One of the message level identifiers, e.g. FINE + * @param pMessage + * The CIM-XML message text + * @param pOutgoing + * true if CIM-XML is outgoing (being sent from + * client to server), false if CIM-XML is incoming + * (being sent from server to client) + */ + public void traceCIMXML(Level pLevel, String pMessage, boolean pOutgoing); +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/GenericExts.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/GenericExts.java similarity index 73% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/GenericExts.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/GenericExts.java index a807115..1d0078b 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/GenericExts.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/GenericExts.java @@ -1,105 +1,102 @@ -/* - (C) Copyright IBM Corp. 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Ramandeep Arora, arorar@us.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2797696 2009-05-27 raman_arora Input files use unsafe operations - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - */ - -package org.sentrysoftware.wbem.sblim.cimclient; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; -import java.util.Vector; - -/** - * Class GenericExts is responsible for generic initialization - */ -public class GenericExts { - - /** - * initArrayList : If arrayList is null then it will return the new - * arrayList of same type if it is not null then it will clear the arrayList - * - * @param - * : Type Parameter - * - * @param pAL - * : ArrayList to be initialized - * @return ArrayList : initialized ArrayList - */ - public static ArrayList initClearArrayList(ArrayList pAL) { - if (pAL == null) return new ArrayList(); - pAL.clear(); - return pAL; - } - - /** - * initArrayList : If arrayList is null then it will return the new - * arrayList of same type if it is not null then it will return the same - * arrayList - * - * @param - * : Type Parameter - * - * @param pAL - * : ArrayList to be initialized - * @return ArrayList : initialized ArrayList - */ - public static ArrayList initArrayList(ArrayList pAL) { - if (pAL == null) return new ArrayList(); - return pAL; - } - - /** - * cloneVector : Generic deep copy of the vector. If original vector is null - * then return value will also be null. - * - * @param - * : Type of vector - * - * @param oldVec - * : The original vector. - * - * @return Vector<T> : Deep copy of original vector. - */ - public static synchronized Vector cloneVector(Vector oldVec) { - if (oldVec == null) return null; - Vector newVec = new Vector(oldVec.size()); - for (T obj : oldVec) - newVec.add(obj); - return newVec; - } -} +/* + (C) Copyright IBM Corp. 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Ramandeep Arora, arorar@us.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2797696 2009-05-27 raman_arora Input files use unsafe operations + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + */ + +package org.metricshub.wbem.sblim.cimclient; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import java.util.Vector; + +/** + * Class GenericExts is responsible for generic initialization + */ +public class GenericExts { + + /** + * initArrayList : If arrayList is null then it will return the new + * arrayList of same type if it is not null then it will clear the arrayList + * + * @param + * : Type Parameter + * + * @param pAL + * : ArrayList to be initialized + * @return ArrayList : initialized ArrayList + */ + public static ArrayList initClearArrayList(ArrayList pAL) { + if (pAL == null) return new ArrayList(); + pAL.clear(); + return pAL; + } + + /** + * initArrayList : If arrayList is null then it will return the new + * arrayList of same type if it is not null then it will return the same + * arrayList + * + * @param + * : Type Parameter + * + * @param pAL + * : ArrayList to be initialized + * @return ArrayList : initialized ArrayList + */ + public static ArrayList initArrayList(ArrayList pAL) { + if (pAL == null) return new ArrayList(); + return pAL; + } + + /** + * cloneVector : Generic deep copy of the vector. If original vector is null + * then return value will also be null. + * + * @param + * : Type of vector + * + * @param oldVec + * : The original vector. + * + * @return Vector<T> : Deep copy of original vector. + */ + public static synchronized Vector cloneVector(Vector oldVec) { + if (oldVec == null) return null; + Vector newVec = new Vector(oldVec.size()); + for (T obj : oldVec) newVec.add(obj); + return newVec; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/IndicationListenerSBLIM.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/IndicationListenerSBLIM.java similarity index 70% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/IndicationListenerSBLIM.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/IndicationListenerSBLIM.java index f90f8ef..e1c8051 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/IndicationListenerSBLIM.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/IndicationListenerSBLIM.java @@ -1,77 +1,71 @@ -/* - (C) Copyright IBM Corp. 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * @author : Dave Blaschke, IBM, blaschke@us.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 3477087 2012-01-23 blaschke-oss Need Access to an Indication Sender's IP Address - */ - -package org.sentrysoftware.wbem.sblim.cimclient; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.net.InetAddress; -import java.util.EventListener; - -import org.sentrysoftware.wbem.javax.cim.CIMInstance; - -/** - * This interface is implemented by the code that wants to create a listener for - * indications. See the WBEMListenerFactory class for an example. - * - * The difference between this interface and IndicationListener is - * that the JSR48 standard (javax.wbem.listener.IndicationListener) - * does not allow for the listener to receive the IP of the indication sender - * whereas this internal interface ( - * org.sblim.cimclinet.IndicationListenerSBLIM) does. - */ -public interface IndicationListenerSBLIM extends EventListener { - - /** - * Called when an indication has been received by the listener - * - * @param pIndicationURL - * The URL to which the indication was posted. For example if the - * indication was delivered over the https protocol to the - * destination listener https://hostname:6111/, pIndicationURL - * would be set to https://hostname:6111/. - * @param pIndication - * The indication received. - * @param pSenderIP - * The internet address of the indication sender. - */ - public void indicationOccured(String pIndicationURL, CIMInstance pIndication, - InetAddress pSenderIP); - -} +/* + (C) Copyright IBM Corp. 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * @author : Dave Blaschke, IBM, blaschke@us.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 3477087 2012-01-23 blaschke-oss Need Access to an Indication Sender's IP Address + */ + +package org.metricshub.wbem.sblim.cimclient; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.net.InetAddress; +import java.util.EventListener; +import org.metricshub.wbem.javax.cim.CIMInstance; + +/** + * This interface is implemented by the code that wants to create a listener for + * indications. See the WBEMListenerFactory class for an example. + * + * The difference between this interface and IndicationListener is + * that the JSR48 standard (javax.wbem.listener.IndicationListener) + * does not allow for the listener to receive the IP of the indication sender + * whereas this internal interface ( + * org.sblim.cimclinet.IndicationListenerSBLIM) does. + */ +public interface IndicationListenerSBLIM extends EventListener { + /** + * Called when an indication has been received by the listener + * + * @param pIndicationURL + * The URL to which the indication was posted. For example if the + * indication was delivered over the https protocol to the + * destination listener https://hostname:6111/, pIndicationURL + * would be set to https://hostname:6111/. + * @param pIndication + * The indication received. + * @param pSenderIP + * The internet address of the indication sender. + */ + public void indicationOccured(String pIndicationURL, CIMInstance pIndication, InetAddress pSenderIP); +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/LogAndTraceManager.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/LogAndTraceManager.java similarity index 82% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/LogAndTraceManager.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/LogAndTraceManager.java index 49b51f3..107687b 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/LogAndTraceManager.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/LogAndTraceManager.java @@ -1,220 +1,214 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1565892 2006-11-13 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 3554738 2012-08-16 blaschke-oss dump CIM xml by LogAndTraceBroker.trace() - */ - -package org.sentrysoftware.wbem.sblim.cimclient; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.OutputStream; -import java.util.Collections; -import java.util.List; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; - -/** - * Class LogAndTraceManager provides the means to register/unregister log and - * trace listeners. It is the entry point for application that want to redirect - * the CIM Client's log and trace messages into their own logging framework. - * - */ -public class LogAndTraceManager { - - private static LogAndTraceManager cManager = new LogAndTraceManager(); - - /** - * Returns the singleton instance of the manager. - * - * @return The manager - */ - public static LogAndTraceManager getManager() { - return cManager; - } - - private LogAndTraceManager() { - super(); - } - - /** - * Adds a listener for log messages. The listener will be notified of any - * log event. - * - * @param pListener - * The listener - */ - public void addLogListener(LogListener pListener) { - LogAndTraceBroker.getBroker().addLogListener(pListener); - } - - /** - * Remove a listener. This listener will not be notified of log events - * anymore. - * - * @param pListener - * The listener - */ - public void removeLogListener(LogListener pListener) { - LogAndTraceBroker.getBroker().removeLogListener(pListener); - } - - /** - * Removes all listeners. Caution: This will also remove the internal - * console and file loggers. - */ - public void clearLogListeners() { - LogAndTraceBroker.getBroker().clearLogListeners(); - } - - /** - * Gets the registered log listeners including the internal console and file - * loggers. - * - * @return An unmodifiable list of listeners - */ - public List getLogListeners() { - return Collections.unmodifiableList(LogAndTraceBroker.getBroker().getLogListeners()); - } - - /** - * Adds a listener for log messages. The listener will be notified of any - * trace event. - * - * @param pListener - * The listener - */ - public void addTraceListener(TraceListener pListener) { - LogAndTraceBroker.getBroker().addTraceListener(pListener); - } - - /** - * Removes a listener. This listener will not be notified of trace events - * anymore. - * - * @param pListener - * The listener - */ - public void removeTraceListener(TraceListener pListener) { - LogAndTraceBroker.getBroker().removeTraceListener(pListener); - } - - /** - * Removes all listeners. Caution this will also remove the internal trace - * file listener. - */ - public void clearTraceListeners() { - LogAndTraceBroker.getBroker().clearTraceListeners(); - } - - /** - * Gets the registered trace listeners including the internal console and - * file loggers. - * - * @return A unmodifiable list of listeners - */ - public List getTraceListeners() { - return Collections.unmodifiableList(LogAndTraceBroker.getBroker().getTraceListeners()); - } - - /** - * Adds a listener for CIM-XML trace messages. The listener will be notified - * of any CIM-XML trace event. - * - * @param pListener - * The listener - */ - public void addCIMXMLTraceListener(CIMXMLTraceListener pListener) { - LogAndTraceBroker.getBroker().addCIMXMLTraceListener(pListener); - } - - /** - * Removes a CIM-XML trace listener. This listener will not be notified of - * CIM-XML trace events anymore. - * - * @param pListener - * The listener - */ - public void removeCIMXMLTraceListener(CIMXMLTraceListener pListener) { - LogAndTraceBroker.getBroker().removeCIMXMLTraceListener(pListener); - } - - /** - * Removes all CIM-XML trace listeners. - */ - public void clearCIMXMLTraceListeners() { - LogAndTraceBroker.getBroker().clearCIMXMLTraceListeners(); - } - - /** - * Gets the registered CIM-XML trace listeners. - * - * @return A unmodifiable list of listeners - */ - public List getCIMXMLTraceListeners() { - return Collections - .unmodifiableList(LogAndTraceBroker.getBroker().getCIMXMLTraceListeners()); - } - - /** - * Returns the stream to which the CIM-XML traces are sent. A value of - * null means that tracing is effectively disabled. Otherwise - * the CIM-XML tracing can be activated either globally or per-connection - * via the "sblim.wbem.cimxmlTracing" configuration property. - * - * @return The CIM-XML trace stream - */ - public OutputStream getXmlTraceStream() { - return LogAndTraceBroker.getBroker().getXmlTraceStream(); - } - - /** - * Sets the stream to which the CIM-XML traces are sent. A value of - * null means that tracing is effectively disabled. Otherwise - * the CIM-XML tracing can be activated either globally or per-connection - * via the "sblim.wbem.cimxmlTracing" configuration property. - * - * @param pStream - * The CIM-XML trace stream - */ - public void setXmlTraceStream(OutputStream pStream) { - LogAndTraceBroker.getBroker().setXmlTraceStream(pStream); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1565892 2006-11-13 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 3554738 2012-08-16 blaschke-oss dump CIM xml by LogAndTraceBroker.trace() + */ + +package org.metricshub.wbem.sblim.cimclient; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.OutputStream; +import java.util.Collections; +import java.util.List; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; + +/** + * Class LogAndTraceManager provides the means to register/unregister log and + * trace listeners. It is the entry point for application that want to redirect + * the CIM Client's log and trace messages into their own logging framework. + * + */ +public class LogAndTraceManager { + private static LogAndTraceManager cManager = new LogAndTraceManager(); + + /** + * Returns the singleton instance of the manager. + * + * @return The manager + */ + public static LogAndTraceManager getManager() { + return cManager; + } + + private LogAndTraceManager() { + super(); + } + + /** + * Adds a listener for log messages. The listener will be notified of any + * log event. + * + * @param pListener + * The listener + */ + public void addLogListener(LogListener pListener) { + LogAndTraceBroker.getBroker().addLogListener(pListener); + } + + /** + * Remove a listener. This listener will not be notified of log events + * anymore. + * + * @param pListener + * The listener + */ + public void removeLogListener(LogListener pListener) { + LogAndTraceBroker.getBroker().removeLogListener(pListener); + } + + /** + * Removes all listeners. Caution: This will also remove the internal + * console and file loggers. + */ + public void clearLogListeners() { + LogAndTraceBroker.getBroker().clearLogListeners(); + } + + /** + * Gets the registered log listeners including the internal console and file + * loggers. + * + * @return An unmodifiable list of listeners + */ + public List getLogListeners() { + return Collections.unmodifiableList(LogAndTraceBroker.getBroker().getLogListeners()); + } + + /** + * Adds a listener for log messages. The listener will be notified of any + * trace event. + * + * @param pListener + * The listener + */ + public void addTraceListener(TraceListener pListener) { + LogAndTraceBroker.getBroker().addTraceListener(pListener); + } + + /** + * Removes a listener. This listener will not be notified of trace events + * anymore. + * + * @param pListener + * The listener + */ + public void removeTraceListener(TraceListener pListener) { + LogAndTraceBroker.getBroker().removeTraceListener(pListener); + } + + /** + * Removes all listeners. Caution this will also remove the internal trace + * file listener. + */ + public void clearTraceListeners() { + LogAndTraceBroker.getBroker().clearTraceListeners(); + } + + /** + * Gets the registered trace listeners including the internal console and + * file loggers. + * + * @return A unmodifiable list of listeners + */ + public List getTraceListeners() { + return Collections.unmodifiableList(LogAndTraceBroker.getBroker().getTraceListeners()); + } + + /** + * Adds a listener for CIM-XML trace messages. The listener will be notified + * of any CIM-XML trace event. + * + * @param pListener + * The listener + */ + public void addCIMXMLTraceListener(CIMXMLTraceListener pListener) { + LogAndTraceBroker.getBroker().addCIMXMLTraceListener(pListener); + } + + /** + * Removes a CIM-XML trace listener. This listener will not be notified of + * CIM-XML trace events anymore. + * + * @param pListener + * The listener + */ + public void removeCIMXMLTraceListener(CIMXMLTraceListener pListener) { + LogAndTraceBroker.getBroker().removeCIMXMLTraceListener(pListener); + } + + /** + * Removes all CIM-XML trace listeners. + */ + public void clearCIMXMLTraceListeners() { + LogAndTraceBroker.getBroker().clearCIMXMLTraceListeners(); + } + + /** + * Gets the registered CIM-XML trace listeners. + * + * @return A unmodifiable list of listeners + */ + public List getCIMXMLTraceListeners() { + return Collections.unmodifiableList(LogAndTraceBroker.getBroker().getCIMXMLTraceListeners()); + } + + /** + * Returns the stream to which the CIM-XML traces are sent. A value of + * null means that tracing is effectively disabled. Otherwise + * the CIM-XML tracing can be activated either globally or per-connection + * via the "sblim.wbem.cimxmlTracing" configuration property. + * + * @return The CIM-XML trace stream + */ + public OutputStream getXmlTraceStream() { + return LogAndTraceBroker.getBroker().getXmlTraceStream(); + } + + /** + * Sets the stream to which the CIM-XML traces are sent. A value of + * null means that tracing is effectively disabled. Otherwise + * the CIM-XML tracing can be activated either globally or per-connection + * via the "sblim.wbem.cimxmlTracing" configuration property. + * + * @param pStream + * The CIM-XML trace stream + */ + public void setXmlTraceStream(OutputStream pStream) { + LogAndTraceBroker.getBroker().setXmlTraceStream(pStream); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/LogListener.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/LogListener.java similarity index 67% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/LogListener.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/LogListener.java index d6bcfe2..7e24c27 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/LogListener.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/LogListener.java @@ -1,68 +1,65 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1565892 2006-11-13 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.logging.Level; - -/** - * The interface LogListener must be implemented if you want to attach your own - * logging framework to the CIM Client. - * - * @see LogAndTraceManager - */ -public interface LogListener { - - /** - * Receive a message. - * - * @param pLevel - * One of the message level identifiers, e.g. SEVERE - * @param pMessageKey - * The identifier of the message - * @param pMessage - * The message text - * @param pParameters - * The parameters for the message - */ - public void log(Level pLevel, String pMessageKey, String pMessage, Object[] pParameters); -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1565892 2006-11-13 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.logging.Level; + +/** + * The interface LogListener must be implemented if you want to attach your own + * logging framework to the CIM Client. + * + * @see LogAndTraceManager + */ +public interface LogListener { + /** + * Receive a message. + * + * @param pLevel + * One of the message level identifiers, e.g. SEVERE + * @param pMessageKey + * The identifier of the message + * @param pMessage + * The message text + * @param pParameters + * The parameters for the message + */ + public void log(Level pLevel, String pMessageKey, String pMessage, Object[] pParameters); +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/TraceListener.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/TraceListener.java similarity index 72% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/TraceListener.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/TraceListener.java index f8fc366..d8adedf 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/TraceListener.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/TraceListener.java @@ -1,83 +1,79 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1565892 2006-11-14 lupusalex Make SBLIM client JSR48 compliant - * 1711092 2006-05-02 lupusalex Some fixes/additions of log&trace messages - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.logging.Level; - -/** - * The interface TraceListener must be implemented if you want to attach your - * own logging framework to the CIM Client. - * - * @see LogAndTraceManager - */ -public interface TraceListener { - - /** - * Receive a trace message. - * - * @param pLevel - * One of the message level identifiers, e.g. FINE - * @param pOrigin - * The java class/method/line-of-code sending the message. Might - * be null if algorithm failed to determine origin. - * @param pMessage - * The message text - */ - public void trace(Level pLevel, StackTraceElement pOrigin, String pMessage); - - /** - * Receive a trace message. - * - * @param pLevel - * One of the message level identifiers, e.g. SEVERE - * @param pOrigin - * The java class/method/line-of-code sending the message - * @param pMessage - * The message text - * @param pThrown - * The throwable associated with the message - */ - public void trace(Level pLevel, StackTraceElement pOrigin, String pMessage, Throwable pThrown); - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1565892 2006-11-14 lupusalex Make SBLIM client JSR48 compliant + * 1711092 2006-05-02 lupusalex Some fixes/additions of log&trace messages + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.logging.Level; + +/** + * The interface TraceListener must be implemented if you want to attach your + * own logging framework to the CIM Client. + * + * @see LogAndTraceManager + */ +public interface TraceListener { + /** + * Receive a trace message. + * + * @param pLevel + * One of the message level identifiers, e.g. FINE + * @param pOrigin + * The java class/method/line-of-code sending the message. Might + * be null if algorithm failed to determine origin. + * @param pMessage + * The message text + */ + public void trace(Level pLevel, StackTraceElement pOrigin, String pMessage); + + /** + * Receive a trace message. + * + * @param pLevel + * One of the message level identifiers, e.g. SEVERE + * @param pOrigin + * The java class/method/line-of-code sending the message + * @param pMessage + * The message text + * @param pThrown + * The throwable associated with the message + */ + public void trace(Level pLevel, StackTraceElement pOrigin, String pMessage, Throwable pThrown); +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/WBEMClientSBLIM.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/WBEMClientSBLIM.java similarity index 86% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/WBEMClientSBLIM.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/WBEMClientSBLIM.java index 5acae87..12f1910 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/WBEMClientSBLIM.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/WBEMClientSBLIM.java @@ -1,278 +1,272 @@ -/* - WBEMClientSBLIM.java - - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1565892 2006-11-08 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2942520 2010-03-08 blaschke-oss IPv6 link local address with scope_id including a dot not supported - * 3516848 2012-04-11 blaschke-oss enumerateNamespaces() method to WBEMClient - * 3522904 2012-05-02 blaschke-oss Add new API WBEMClientSBLIM.isActive() - * 2616 2013-02-23 blaschke-oss Add new API WBEMClientSBLIM.sendIndication() - */ - -package org.sentrysoftware.wbem.sblim.cimclient; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.net.URI; -import java.util.Locale; -import java.util.Properties; - -import org.sentrysoftware.wbem.javax.cim.CIMInstance; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import javax.net.SocketFactory; -import javax.security.auth.Subject; -import org.sentrysoftware.wbem.javax.wbem.CloseableIterator; -import org.sentrysoftware.wbem.javax.wbem.WBEMException; -import org.sentrysoftware.wbem.javax.wbem.client.WBEMClient; - -/** - * Class WBEMClientSBLIM contains the SBLIM CIM Client specific extensions to - * the WBEMClient interface. - * - * @see WBEMClient - * - */ -public interface WBEMClientSBLIM extends WBEMClient { - - /** - * Initialize the client connection. This must be called before any - * operations. This must only be called once. - * - * @param pUri - * The protocol and host to use. Any other fields will be - * ignored. - * @param pSubject - * The principal/credential pairs for this connection. - * @param pLocales - * An array of locales in order of priority of preference. - * @throws IllegalArgumentException - * If the host or scheme portion of the object path is null, or - * if the protocol is not supported. - * @throws WBEMException - * If the protocol adapter or security cannot be initialized. - */ - public void initialize(URI pUri, Subject pSubject, Locale[] pLocales) - throws IllegalArgumentException, WBEMException; - - /** - * Returns the client specific configuration properties. Note that only - * these properties are returned that override the global settings. The - * global settings can be accessed via the java.lang.System - * class.
      - * If the no client specific configuration is set, this method returns - * null - * - * @return The configuration properties - * @see System#getProperties() - */ - public Properties getProperties(); - - /** - * Sets the client specific configuration properties. Any previously set - * client specific properties are overwritten. The given properties are - * handled as an overlay on the global settings. That means that properties - * specified here override the corresponding global properties whereas - * properties not specified here are taken from the global properties. The - * global settings can be accessed via the java.lang.System - * class. - * - * @param pProperties - * The session specific properties. null resets this - * client to the global settings. - * - * @see System#setProperties(Properties) - */ - public void setProperties(Properties pProperties); - - /** - * Returns the effective value of a given configuration property. The method - * will return the local value of the current thread if one was set or - * otherwise client specific value if one was set or otherwise the global - * value if one was set or otherwise the default value. Valid property names - * can be found in the WBEMConfigurationProperties interface. - * - * @param pKey - * The name of the configuration property - * - * @return The value of the given configuration property - * @see WBEMConfigurationProperties - */ - public String getProperty(String pKey); - - /** - * Sets a client specific configuration property. This property will - * override the corresponding global property for this client instance. The - * global settings can be accessed via the java.lang.System - * class. Valid property names can be found in the - * WBEMConfigurationProperties interface. Unknown properties - * are ignored. - * - * @param pKey - * The name of the configuration property - * @param pValue - * The value of the configuration property. null - * resets to the global setting. - * @see WBEMConfigurationProperties - * @see System#setProperty(String, String) - */ - public void setProperty(String pKey, String pValue); - - /** - * Returns the configuration properties that are local to the current - * thread. Note that only these properties are returned that override the - * global and the client settings. The global settings can be accessed via - * the java.lang.System class, the client setting via - * getProperties().
      - * If the no client specific configuration is set, this method returns - * null - * - * @return The configuration properties - * @see System#getProperties() - * @see #getProperties() - */ - public Properties getLocalProperties(); - - /** - * Sets the configuration properties that are local to the current thread. - * Any previously set local properties (of the current thread) are - * overwritten. The given properties are handled as an overlay on the global - * settings and the client settings. That means that properties specified - * here override the corresponding properties whereas properties not - * specified here are taken from the client or global properties. The global - * settings can be accessed via the java.lang.System class, the - * client setting via getProperties(). - * - * @param pProperties - * The thread specific properties. null remove the - * local setting of the current thread. - * - * @see System#setProperties(Properties) - * @see #setProperties(Properties) - */ - public void setLocalProperties(Properties pProperties); - - /** - * Sets a local configuration property for the current thread. This property - * will override the corresponding global and client property for this - * client instance. The global settings can be accessed via the - * java.lang.System class, the client setting via - * getProperties(). Valid property names can be found in the - * WBEMConfigurationProperties interface. Unknown properties - * are ignored. - * - * @param pKey - * The name of the configuration property - * @param pValue - * The value of the configuration property. null - * resets to the global setting. - * @see WBEMConfigurationProperties - * @see System#setProperty(String, String) - * @see #setProperty(String, String) - */ - public void setLocalProperty(String pKey, String pValue); - - /** - * Gets the custom socket factory if one is set. The client uses this - * factory for socket creation instead of the default one. - * - * @return The custom factory used for socket creation. null - * indicates set the JRE default factory is used. - */ - public SocketFactory getCustomSocketFactory(); - - /** - * Sets a custom socket factory. The client will use this factory for socket - * creation instead of the JRE default. - * - * @param pFactory - * The factory to use for socket creation. null - * resets to the JRE default factory. - * @throws UnsupportedOperationException - * Some protocols might not communicate via TCP sockets - */ - public void setCustomSocketFactory(SocketFactory pFactory) throws UnsupportedOperationException; - - /** - * Enumerate the names of the instances of CIM namespaces. - * - * @param pNamespace - * The Interop Namespace, if known. If null, the default Interop - * Namespace names defined by DSP1033 are used. - * @return A CloseableIterator of CIMObjectPaths. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - *
      -	 *      CIM_ERR_FAILED (some other unspecified error occurred)
      -	 * 
      - */ - public CloseableIterator enumerateNamespaces(String pNamespace) - throws WBEMException; - - /** - * Returns an indication of whether the client is active (initialized and - * not closed) or inactive (not initialized or closed). - * - * @return true if client is active, false - * otherwise. - */ - public boolean isActive(); - - /** - * Sends the indication to the specified recipient. - * - * @param pRecipient - * URI of indication recipient. - * @param pIndication - * Indication. - * @return true if indication received successfully, - * false otherwise. - * @throws WBEMException - * If unsuccessful, one of the following status codes must be - * returned. The ORDERED list is: - * - *
      -	 *      CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized
      -	 *            or otherwise incorrect parameters)
      -	 *      CIM_ERR_FAILED (some other unspecified error occurred)
      -	 * 
      - */ - public boolean sendIndication(URI pRecipient, CIMInstance pIndication) throws WBEMException; -} +/* + WBEMClientSBLIM.java + + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1565892 2006-11-08 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2942520 2010-03-08 blaschke-oss IPv6 link local address with scope_id including a dot not supported + * 3516848 2012-04-11 blaschke-oss enumerateNamespaces() method to WBEMClient + * 3522904 2012-05-02 blaschke-oss Add new API WBEMClientSBLIM.isActive() + * 2616 2013-02-23 blaschke-oss Add new API WBEMClientSBLIM.sendIndication() + */ + +package org.metricshub.wbem.sblim.cimclient; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.net.URI; +import java.util.Locale; +import java.util.Properties; +import javax.net.SocketFactory; +import javax.security.auth.Subject; +import org.metricshub.wbem.javax.cim.CIMInstance; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.wbem.CloseableIterator; +import org.metricshub.wbem.javax.wbem.WBEMException; +import org.metricshub.wbem.javax.wbem.client.WBEMClient; + +/** + * Class WBEMClientSBLIM contains the SBLIM CIM Client specific extensions to + * the WBEMClient interface. + * + * @see WBEMClient + * + */ +public interface WBEMClientSBLIM extends WBEMClient { + /** + * Initialize the client connection. This must be called before any + * operations. This must only be called once. + * + * @param pUri + * The protocol and host to use. Any other fields will be + * ignored. + * @param pSubject + * The principal/credential pairs for this connection. + * @param pLocales + * An array of locales in order of priority of preference. + * @throws IllegalArgumentException + * If the host or scheme portion of the object path is null, or + * if the protocol is not supported. + * @throws WBEMException + * If the protocol adapter or security cannot be initialized. + */ + public void initialize(URI pUri, Subject pSubject, Locale[] pLocales) throws IllegalArgumentException, WBEMException; + + /** + * Returns the client specific configuration properties. Note that only + * these properties are returned that override the global settings. The + * global settings can be accessed via the java.lang.System + * class.
      + * If the no client specific configuration is set, this method returns + * null + * + * @return The configuration properties + * @see System#getProperties() + */ + public Properties getProperties(); + + /** + * Sets the client specific configuration properties. Any previously set + * client specific properties are overwritten. The given properties are + * handled as an overlay on the global settings. That means that properties + * specified here override the corresponding global properties whereas + * properties not specified here are taken from the global properties. The + * global settings can be accessed via the java.lang.System + * class. + * + * @param pProperties + * The session specific properties. null resets this + * client to the global settings. + * + * @see System#setProperties(Properties) + */ + public void setProperties(Properties pProperties); + + /** + * Returns the effective value of a given configuration property. The method + * will return the local value of the current thread if one was set or + * otherwise client specific value if one was set or otherwise the global + * value if one was set or otherwise the default value. Valid property names + * can be found in the WBEMConfigurationProperties interface. + * + * @param pKey + * The name of the configuration property + * + * @return The value of the given configuration property + * @see WBEMConfigurationProperties + */ + public String getProperty(String pKey); + + /** + * Sets a client specific configuration property. This property will + * override the corresponding global property for this client instance. The + * global settings can be accessed via the java.lang.System + * class. Valid property names can be found in the + * WBEMConfigurationProperties interface. Unknown properties + * are ignored. + * + * @param pKey + * The name of the configuration property + * @param pValue + * The value of the configuration property. null + * resets to the global setting. + * @see WBEMConfigurationProperties + * @see System#setProperty(String, String) + */ + public void setProperty(String pKey, String pValue); + + /** + * Returns the configuration properties that are local to the current + * thread. Note that only these properties are returned that override the + * global and the client settings. The global settings can be accessed via + * the java.lang.System class, the client setting via + * getProperties().
      + * If the no client specific configuration is set, this method returns + * null + * + * @return The configuration properties + * @see System#getProperties() + * @see #getProperties() + */ + public Properties getLocalProperties(); + + /** + * Sets the configuration properties that are local to the current thread. + * Any previously set local properties (of the current thread) are + * overwritten. The given properties are handled as an overlay on the global + * settings and the client settings. That means that properties specified + * here override the corresponding properties whereas properties not + * specified here are taken from the client or global properties. The global + * settings can be accessed via the java.lang.System class, the + * client setting via getProperties(). + * + * @param pProperties + * The thread specific properties. null remove the + * local setting of the current thread. + * + * @see System#setProperties(Properties) + * @see #setProperties(Properties) + */ + public void setLocalProperties(Properties pProperties); + + /** + * Sets a local configuration property for the current thread. This property + * will override the corresponding global and client property for this + * client instance. The global settings can be accessed via the + * java.lang.System class, the client setting via + * getProperties(). Valid property names can be found in the + * WBEMConfigurationProperties interface. Unknown properties + * are ignored. + * + * @param pKey + * The name of the configuration property + * @param pValue + * The value of the configuration property. null + * resets to the global setting. + * @see WBEMConfigurationProperties + * @see System#setProperty(String, String) + * @see #setProperty(String, String) + */ + public void setLocalProperty(String pKey, String pValue); + + /** + * Gets the custom socket factory if one is set. The client uses this + * factory for socket creation instead of the default one. + * + * @return The custom factory used for socket creation. null + * indicates set the JRE default factory is used. + */ + public SocketFactory getCustomSocketFactory(); + + /** + * Sets a custom socket factory. The client will use this factory for socket + * creation instead of the JRE default. + * + * @param pFactory + * The factory to use for socket creation. null + * resets to the JRE default factory. + * @throws UnsupportedOperationException + * Some protocols might not communicate via TCP sockets + */ + public void setCustomSocketFactory(SocketFactory pFactory) throws UnsupportedOperationException; + + /** + * Enumerate the names of the instances of CIM namespaces. + * + * @param pNamespace + * The Interop Namespace, if known. If null, the default Interop + * Namespace names defined by DSP1033 are used. + * @return A CloseableIterator of CIMObjectPaths. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + *
      +	 *      CIM_ERR_FAILED (some other unspecified error occurred)
      +	 * 
      + */ + public CloseableIterator enumerateNamespaces(String pNamespace) throws WBEMException; + + /** + * Returns an indication of whether the client is active (initialized and + * not closed) or inactive (not initialized or closed). + * + * @return true if client is active, false + * otherwise. + */ + public boolean isActive(); + + /** + * Sends the indication to the specified recipient. + * + * @param pRecipient + * URI of indication recipient. + * @param pIndication + * Indication. + * @return true if indication received successfully, + * false otherwise. + * @throws WBEMException + * If unsuccessful, one of the following status codes must be + * returned. The ORDERED list is: + * + *
      +	 *      CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized
      +	 *            or otherwise incorrect parameters)
      +	 *      CIM_ERR_FAILED (some other unspecified error occurred)
      +	 * 
      + */ + public boolean sendIndication(URI pRecipient, CIMInstance pIndication) throws WBEMException; +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/WBEMConfigurationProperties.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/WBEMConfigurationProperties.java similarity index 93% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/WBEMConfigurationProperties.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/WBEMConfigurationProperties.java index be80a47..aaea277 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/WBEMConfigurationProperties.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/WBEMConfigurationProperties.java @@ -1,1154 +1,1154 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, a.wolf-reber@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-11-08 lupusalex Make SBLIM client JSR48 compliant - * 1688273 2007-04-19 lupusalex Full support of HTTP trailers - * 1815707 2007-10-30 ebak TLS support - * 1827728 2007-11-12 ebak embeddedInstances: attribute EmbeddedObject not set - * 1848607 2007-12-11 ebak Strict EmbeddedObject types - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2372030 2008-12-01 blaschke-oss Add property to control synchronized SSL handshaking - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2846231 2009-09-23 rgummada connection failure on CIMOM w/o user/pw - * 2930341 2010-01-12 blaschke-oss Sync up WBEMClientConstants with JSR48 1.0.0 - * 2957387 2010-03-03 blaschke-oss EmbededObject XML attribute must not be all uppercases - * 2970881 2010-03-15 blaschke-oss Add property to control EmbeddedObject case - * 3046073 2010-09-07 blaschke-oss Performance hit due to socket conn. creation with timeout - * 3111718 2010-11-18 blaschke-oss org.sblim.cimclient SSL Code is using the wrong SSL Property - * 3185763 2011-02-25 blaschke-oss Reliable indication support - Phase 1 - * 3195069 2011-02-28 blaschke-oss Need support to disable SSL Handshake - * 3197423 2011-03-02 blaschke-oss Server authentication with PegasusLocalAuthInfo failing - * 3277928 2011-04-06 blaschke-oss CIM-XML tracing cannot be enabled in the field - * 3206904 2011-05-03 blaschke-oss Indication listener deadlock causes JVM to run out sockets - * 3288721 2011-05-20 blaschke-oss Need the function of indication reordering - * 3459036 2011-12-13 blaschke-oss Linked list for RI queue not efficient for many LDs - * 3485074 2012-02-06 blaschke-oss An Indication trace request - * 3492246 2012-02-23 blaschke-oss Rename new indication trace property - * 3492214 2012-02-23 blaschke-oss Add a SenderIPAddress property indications - * 3492224 2012-02-23 blaschke-oss Need two different timeouts for Socket connections - * 3521157 2012-05-10 blaschke-oss JSR48 1.0.0: PROP_ENABLE_*_LOGGING is Level, not 0/1 - * 3524050 2012-06-06 blaschke-oss Improve WWW-Authenticate in HTTPClient.java - * 3536399 2012-08-25 hellerda Add client/listener peer authentication properties - * 3572993 2012-10-01 blaschke-oss parseDouble("2.2250738585072012e-308") DoS vulnerability - * 3598613 2013-01-11 blaschke-oss different data type in cim instance and cim object path - * 2618 2013-02-27 blaschke-oss Need to add property to disable weak cipher suites for the secure indication - * 2628 2013-03-26 blaschke-oss Limit size of LinkedList of CIMEvents to be dispatched - * 2635 2013-05-16 blaschke-oss Slowloris DoS attack for CIM indication listener port - * 2642 2013-05-21 blaschke-oss Seperate properties needed for cim client and listener to filter out ciphers - * 2647 2013-07-01 blaschke-oss Add two ssl protocol properties for http server and client - * 2654 2013-07-29 blaschke-oss Check jcc idle time with CIMOM keepalive timeout to avoid EOF - * 2151 2013-08-20 blaschke-oss gzip compression not supported - * 2711 2013-11-13 blaschke-oss LOCALNAMESPACEPATH allows 0 NAMESPACE children - */ -package org.sentrysoftware.wbem.sblim.cimclient; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * The interface WBEMConfigurationProperties contains the names of all - * configuration properties that are recognized by the CIM Client. - * - */ -public interface WBEMConfigurationProperties { - - /** - * A URL string giving the location of the CIM client config file.
      - *
      - * By default the SBLIM CIM Client looks for - *
        - *
      • file:sblim-cim-client2.properties
      • - *
      • file:%USER_HOME%/sblim-cim-client2.properties
      • - *
      • file:/etc/java/sblim-cim-client2.properties
      • - *
      - * The first file found will be used. The default search list is not applied - * if this property is set, even if the given URL does not exist.
      - */ - public static final String CONFIG_URL = "sblim.wbem.configURL"; - - /** - * Sets the minimum level for messages to be written to the log file.
      - *
      - * Type: Discrete
      - * Recognition: Startup
      - * Range: OFF, SEVERE, WARNING, INFO, CONFIG, ALL
      - * Default: OFF, which disables file logging completely. - */ - public static final String LOG_FILE_LEVEL = "sblim.wbem.logFileLevel"; - - /** - * A string specifying the location of the log file. The string may include - * the following special components that will be replaced at runtime:
      - *
        - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
        /the local pathname separator
        %tthe system temporary directory
        %hthe value of the "user.home" system property
        %gthe generation number to distinguish rotated logs
        %ua unique number to resolve conflicts
        %%translates to a single percent sign "%"
        - *
      - * Thus for example a pattern of %t/java%g.log with a count of - * 2 would typically cause log files to be written on Unix to - * /var/tmp/java2.log
      - *
      - * Type: String
      - * Recognition: Startup
      - * Default: %t/cimclient_log_%g.txt. - */ - public static final String LOG_FILE_LOCATION = "sblim.wbem.logFileLocation"; - - /** - * Sets the maximum size in bytes of a single log file. When the limit is - * reached a new file is created. A limit of zero will create a new log file - * for every log record !
      - *
      - * Type: Integer
      - * Recognition: Startup
      - * Range: 0 .. Integer.MAX_VALUE
      - * Default: 100.000
      - */ - public static final String LOG_FILE_SIZE_LIMIT = "sblim.wbem.logFileSizeLimit"; - - /** - * Sets the number of log files to cycle through. When the number is - * exceeded the oldest file is dropped.
      - *
      - * Type: Integer
      - * Recognition: Startup
      - * Range: 1 .. Integer.MAX_VALUE
      - * Default: 5
      - */ - public static final String LOG_FILE_COUNT = "sblim.wbem.logFileCount"; - - /** - * Sets the minimum level for messages to be written to the console logger - * file.
      - *
      - * Type: Discrete
      - * Recognition: Startup
      - * Range: OFF, SEVERE, WARNING, INFO, CONFIG, ALL
      - * Default: OFF, which disables console logging completely. - */ - public static final String LOG_CONSOLE_LEVEL = "sblim.wbem.logConsoleLevel"; - - /** - * Sets the type of the console logger. Maybe either message log or trace - * log.
      - *
      - * Type: Discrete
      - * Recognition: Startup
      - * Range: MESSAGE, TRACE
      - * Default: MESSAGE. - */ - public static final String LOG_CONSOLE_TYPE = "sblim.wbem.logConsoleType"; - - /** - * Sets the minimum level for messages to be written to the trace file.
      - *
      - * Type: Discrete
      - * Recognition: Startup
      - * Range: - * OFF, SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST, ALL
      - * Default: OFF, which disables file tracing completely
      - */ - public static final String TRACE_FILE_LEVEL = "sblim.wbem.traceFileLevel"; - - /** - * A string specifying the location of the trace file. The string may - * include the following special components that will be replaced at - * runtime:
      - *
        - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
        /the local pathname separator
        %tthe system temporary directory
        %hthe value of the "user.home" system property
        %gthe generation number to distinguish rotated logs
        %ua unique number to resolve conflicts
        %%translates to a single percent sign "%"
        - *
      - * Thus for example a pattern of %t/java%g.log with a count of - * 2 would typically cause log files to be written on Unix to - * /var/tmp/java2.log
      - *
      - * Type: String
      - * Recognition: Startup
      - * Default: %t/cimclient_trace_%g.txt
      - */ - public static final String TRACE_FILE_LOCATION = "sblim.wbem.traceFileLocation"; - - /** - * Sets the maximum size in bytes of a single log file. When the limit is - * reached a new file is created. A limit of zero creates a new file for - * each trace record !
      - *
      - * Type: Integer
      - * Recognition: Startup
      - * Range: 0 .. Integer.MAX_VALUE
      - * Default: 1.000.000
      - */ - public static final String TRACE_FILE_SIZE_LIMIT = "sblim.wbem.traceFileSizeLimit"; - - /** - * Sets the number of log files to cycle through. When the number is - * exceeded the oldest file is dropped.
      - *
      - * Type: Integer
      - * Recognition: Startup
      - * Range: 1 .. Integer.MAX_VALUE
      - * Default: 5
      - */ - public static final String TRACE_FILE_COUNT = "sblim.wbem.traceFileCount"; - - /** - * The timeout for http requests. A timeout of zero is interpreted as - * infinite timeout.
      - *
      - * Type: Integer
      - * Unit: Milliseconds
      - * Recognition: Anytime
      - * Range: 0 .. Integer.MAX_VALUE
      - * Default: 0
      - */ - public static final String HTTP_TIMEOUT = "sblim.wbem.httpTimeout"; - - /** - * The size of the internal http connection pools. Each - * WBEMClient instance has it's own http connection pool. A - * positive value defines the number of connections, zero that no connection - * will be reused, and -1 all connections will be reused (when it's - * possible).
      - *
      - * Type: Integer
      - * Recognition: Anytime
      - * Range: -1, 0, 1 .. Integer.MAX_VALUE
      - * Default: 16
      - */ - public static final String HTTP_POOL_SIZE = "sblim.wbem.httpPoolSize"; - - /** - * The Java class name of the authentication module to use for http - * authentication.
      - *
      - * Type: String
      - * Recognition: On next authentication
      - * Range: - * - * org.sblim.cimclient.internal.http.WwwAuthInfo, org.sblim.cimclient.internal.http.PegasusLocalAuthInfo or any self-written subclass of org.sblim.cimclient.internal.http.AuthorizationInfo - *
      - * Default: org.sblim.cimclient.internal.http.WwwAuthInfo
      - */ - public static final String HTTP_AUTHENTICATION_MODULE = "sblim.wbem.httpAuthModule"; - - /** - * The WWW-Authenticate information to use when sending the first request to - * a server.
      - *
      - * Note: This string must exactly match what the server returns in the
      - * WWW-Authenticate field of an HTTP 401 response when authentication
      - * fails. The following two strings are examples:
      - *
      - * - * - * Basic realm="Secure Area" - * Digest realm="testrealm@host.com",qop="auth,auth-int",nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",opaque="5ccc069c403ebaf9f0171e9517f40e41" - * - * - * Type: String
      - * Recognition: On next authentication
      - * Range: Basic, Digest
      - * Default: none
      - */ - public static final String HTTP_WWW_AUTHENTICATE_INFO = "sblim.wbem.httpWwwAuthenticateInfo"; - - /** - * Specifies if MPOST is used for transmitting http messages. If false, POST - * is used.
      - *
      - * Type: Boolean
      - * Recognition: Anytime
      - * Range: true, false
      - * Default: true
      - */ - public static final String HTTP_USE_MPOST = "sblim.wbem.httpMPOST"; - - /** - * Specifies if chunking is used for transmitting http messages.
      - *
      - * Type: Boolean
      - * Recognition: Anytime
      - * Range: true, false
      - * Default: true
      - */ - public static final String HTTP_USE_CHUNKING = "sblim.wbem.httpChunking"; - - /** - * Specifies the http protocol version to use. This option is useful if the - * protocol negotiation fails.
      - *
      - * Type: String
      - * Recognition: Anytime
      - * Range: 1.0, 1.1
      - * Default: 1.1
      - */ - public static final String HTTP_VERSION = "sblim.wbem.httpVersion"; - - /** - * Specifies how often the client will retry to connect to a CIMOM which - * refused the connection in the first place.
      - *
      - * Type: Integer
      - * Recognition: Anytime
      - * Range: 0 .. Integer.MAX_VALUE
      - * Default: 0
      - */ - public static final String HTTP_CONNECTION_RETRIES = "sblim.wbem.httpConnectionRetries"; - - /** - * Specifies if the client will discard and request again http documents - * with less than a given number of bytes.
      - *
      - * Type: Boolean
      - * Recognition: Anytime
      - * Range: true, false
      - * Default: false
      - */ - public static final String HTTP_ENABLE_CONTENT_LENGTH_RETRY = "sblim.wbem.httpEnableContentLengthRetry"; - - /** - * Specifies the threshold above which a http document is regarded as valid - * by the content length retry algorithm.
      - *
      - * Type: Integer
      - * Recognition: Anytime
      - * Range: 0 .. Integer.MAX_VALUE
      - * Default: 50
      - */ - public static final String HTTP_CONTENT_LENGTH_THRESHOLD = "sblim.wbem.httpContentLengthThreshold"; - - /** - * The file path of the SSL keystore.
      - *
      - * Type: String
      - * Recognition: On next SSL connection
      - * Default: none
      - */ - public static final String KEYSTORE_PATH = "javax.net.ssl.keyStore"; - - /** - * The type of the keystore.
      - *
      - * Type: String
      - * Recognition: On next SSL connection
      - * Range: PKCS12, JKS, ...
      - * Default: JKS
      - */ - public static final String KEYSTORE_TYPE = "javax.net.ssl.keyStoreType"; - - /** - * The password of the keystore.
      - *
      - * Type: String
      - * Recognition: On next SSL connection
      - * Default: none
      - */ - public static final String KEYSTORE_PASSWORD = "javax.net.ssl.keyStorePassword"; - - /** - * The file path of the SSL truststore.
      - *
      - * Type: String
      - * Recognition: On next SSL connection
      - * Default: none
      - */ - public static final String TRUSTSTORE_PATH = "javax.net.ssl.trustStore"; - - /** - * The type of the truststore.
      - *
      - * Type: String
      - * Recognition: On next SSL connection
      - * Range: PKCS12, JKS, ...
      - * Default: JKS
      - */ - public static final String TRUSTSTORE_TYPE = "javax.net.ssl.trustStoreType"; - - /** - * The password of the truststore.
      - *
      - * Type: String
      - * Recognition: On next SSL connection
      - * Default: none
      - */ - public static final String TRUSTSTORE_PASSWORD = "javax.net.ssl.trustStorePassword"; - - /** - * The provider to use for creation of SSL client sockets.
      - *
      - * Security property: JRE global access via Security.setProperty() and Security.getProperty() ! - *
      - *
      - * Type: Java class name
      - * Recognition: On next SSL connection
      - * Default: Security.getProviders("SSLContext.SSL")
      - */ - public static final String SSL_SOCKET_PROVIDER = "sblim.wbem.sslSocketProvider"; - - /** - * The provider to use for creation of SSL server sockets.
      - *
      - * Security property: JRE global access via Security.setProperty() and Security.getProperty() ! - *
      - *
      - * Type: Java class name
      - * Recognition: On next SSL connection
      - * Default: Security.getProviders("SSLContext.SSL")
      - */ - public static final String SSL_SERVER_SOCKET_PROVIDER = "sblim.wbem.sslServerSocketProvider"; - - /** - * The protocol used for SSLContext.getInstance(String protocol). For - * IBMJSSE2 provider it can be "SSL_TLS".
      - *
      - * Security property: JRE global access via - * Security.setProperty() and - * Security.getProperty()
      - * Recognition: On next SSL connection
      - * Default: "SSL" - */ - public static final String SSL_PROTOCOL = "ssl.Protocol"; - - /** - * The protocol used for SSLContext.getInstance(String protocol) by a - * client. This property overrides any value set via the ssl.Protocol - * property.
      - *
      - * Recognition: On next SSL connection
      - * Default: none - */ - public static final String SSL_CLIENT_PROTOCOL = "sblim.wbem.sslClientProtocol"; - - /** - * The protocol used for SSLContext.getInstance(String protocol) by a - * listener. This property overrides any value set via the ssl.Protocol - * property.
      - *
      - * Recognition: On next SSL connection
      - * Default: none - */ - public static final String SSL_LISTENER_PROTOCOL = "sblim.wbem.sslListenerProtocol"; - - /** - * The key manager factory algorithm name.
      - *
      - * Security property: JRE global access via Security.setProperty() and Security.getProperty() ! - *
      - *
      - * Type: String
      - * Recognition: On next SSL connection
      - * Range: IbmX509, SunX509, ...
      - * Default: JRE specific
      - */ - public static final String SSL_KEYMANAGER_ALGORITHM = "ssl.KeyManagerFactory.algorithm"; - - /** - * The trust manager factory algorithm name.
      - *
      - * Security property: JRE global access via Security.setProperty() and Security.getProperty() ! - *
      - *
      - * Type: String
      - * Recognition: On next SSL connection
      - * Range: IbmX509, SunX509, ...
      - * Default: JRE specific
      - */ - public static final String SSL_TRUSTMANAGER_ALGORITHM = "ssl.TrustManagerFactory.algorithm"; - - /** - * Determines if a HTTPS client will attempt to authenticate the server - * (i.e. CIMOM) by verifying the server certificate.
      - *
      - * If false, do not attempt verification. If true, the client will attempt - * to verify the server certificate against the contents of the truststore; - * in this case a valid path must be defined in "javax.net.ssl.trustStore" - * or no connection will be permitted.
      - *
      - * Type: Boolean
      - * Recognition: On initialization of a new client
      - * Default: false
      - */ - public static final String SSL_CLIENT_PEER_VERIFICATION = "sblim.wbem.sslClientPeerVerification"; - - /** - * Determines how a HTTPS listener will handle authentication of a client - * (i.e. indication sender):
      - *
        - * - * - * - * - * - * - * - * - * - * - * - * - * - *
        ignoredo not examine the client certificate
        acceptexamine client certificate if presented; do not fail if not presented - *
        requireexamine client certificate; fail if not presented
        - *
      - * If set to "ignore", do not attempt verification. If set to "accept" or - * "require", the listener will attempt to verify the sender against the - * contents of the truststore; in this case a valid path must be defined in - * "javax.net.ssl.trustStore" or no connection will be permitted.
      - *
      - * Type: String
      - * Recognition: On next call to addListener()
      - * Default: ignore
      - */ - public static final String SSL_LISTENER_PEER_VERIFICATION = "sblim.wbem.sslListenerPeerVerification"; - - /** - * The comma-separated list of cipher suites that are to be disabled by the - * client when connecting via an SSL socket. In general, this is the list of - * cipher suites considered "too weak" for use in a particular environment.
      - *
      - * Type: String
      - * Recognition: On initialization of a new client
      - * Default: none
      - */ - public static final String SSL_CLIENT_CIPHER_SUITES_TO_DISABLE = "sblim.wbem.sslClientCipherSuitesToDisable"; - - /** - * The comma-separated list of cipher suites that are to be disabled by the - * listener when connecting via an SSL socket. In general, this is the list - * of cipher suites considered "too weak" for use in a particular - * environment.
      - *
      - * Type: String
      - * Recognition: On next call to addListener()
      - * Default: none
      - */ - public static final String SSL_LISTENER_CIPHER_SUITES_TO_DISABLE = "sblim.wbem.sslListenerCipherSuitesToDisable"; - - /** - * Specifies the XML parser for parsing CIM-XML responses.
      - * The SAX parser is the default choice since it is fast, resource saving - * and interoperable. The streaming algorithm of the PULL parser uses the - * fewest possible resources but at the prize to keep the CIMOMs response - * open for a long time. That works with many but not all CIMOMs. The DOM - * parser is slow and resource hungry but nice to debug.
      - *
      - * Type: Discrete
      - * Recognition: Anytime
      - * Range: DOM, PULL, SAX
      - * Default: SAX
      - */ - public static final String CIMXML_PARSER = "sblim.wbem.cimxmlParser"; - - /** - * Enables or disables tracing of CIM-XML communication. The trace is sent - * to an output stream the application has to set via the LogAndTraceManager - * class.
      - *
      - * Type: Boolean
      - * Recognition: Anytime
      - * Range: true, false
      - * Default: false
      - */ - public static final String CIMXML_TRACING = "sblim.wbem.cimxmlTracing"; - - /** - * Specifies the stream to use for tracing CIM-XML communication in the - * event the application does not set one via the LogAndTraceManager class. - * This stream can either be standard output (System.out), standard error - * output (System.err) or a filename to be opened by the client. - * - * Note: This property has no effect unless sblim.wbem.cimxmlTracing is set - * to true. - * - * Note: This property has no effect if the application already set the - * stream prior to client initialization. If the application sets the stream - * after client initialization, the stream specified by this property is - * overridden. - * - * Note: If a filename is specified, it is opened and all CIM-XML - * communication is written to it - no checks are made for an existing file - * or for filling up the disk. USE WITH CAUTION. - * - * Type: String
      - * Recognition: Startup
      - * Range: System.out, System.err, filename
      - * Default: none
      - */ - public static final String CIMXML_TRACE_STREAM = "sblim.wbem.cimxmlTraceStream"; - - /** - * - * Tells the XML builder how to sign embedded objects. This is necessary due to - * the non-consequent handling of embedded objects on different CIMOMs. - * "AttribOnly" - only the EmbeddedObject="instance/object" is used - * (should be good for Pegasus) - * "EmbObjQuali" - on qualified CIM-XML elements the EmbeddedObject qualifier is used - * for embedded classes and instances - * "EmbObjAndEmbInstQuali" - - * on qualified CIM-XML elements the EmbeddedObject qualifier is used - * for embedded classes and the EmbeddedInstance="className" qualifier - * is used for embedded instances - * Type: String - * Recognition: Anytime - * Range: AttribOnly, EmbObjQuali, EmbObjAndEmbInstQuali - * Default: AttribOnly - * - */ - public static final String CIMXML_EMBOBJBUILDER = "sblim.wbem.cimxmlEmbObjBuilder"; - - /** - * - * If set the type of valueless EmbeddedObjects are mapped to CLASS_T. It should work well - * with OpenPegasus-2.7.0. - * If unset no type mapping is done for valuless EmbeddedObjects. - * - * Type: Boolean - * Default: true - * - */ - public static final String CIMXML_PARSER_STRICT_EMBOBJ_TYPES = "sblim.wbem.cimxmlParser.strictEmbObjTypes"; - - /** - * - * If set to false, the embedded object entity in all requests is in mixed case - * (EmbeddedObject) per DSP0203. If set to true, the embedded object entity is in - * upper case (EMBEDDEDOBJECT) - this works with some older CIMOMs, such as OpenPegasus - * 2.6.1 and 2.7.0. - * - * <!ENTITY % EmbeddedObject "EmbeddedObject (object|instance) #IMPLIED"> - * - * Type: Boolean - * Recognition: Startup - * Range: true, false - * Default: true - * - */ - public static final String CIMXML_BUILDER_UPPERCASE_EMBOBJ_ENTITIES = "sblim.wbem.cimxmlBuilder.upperCaseEmbObjEntities"; - - /** - * - * If set to true, SSL handshakes are performed after an SSL socket is created by the - * socket factory. If set to false, handshakes are not performed, which is useful if - * if the handshake has already taken place. - * - * Type: Boolean - * Recognition: Anytime - * Default: true - * - */ - public static final String PERFORM_SSL_HANDSHAKE = "sblim.wbem.performSslHandshake"; - - /** - * - * If set to false, SSL handshakes are not synchronized. If set to true, SSL handshakes - * are synchronized as a workaround for an IBMJSSE1 problem with thread-safe handshakes. - * - * Note: This property has no affect unless sblim.wbem.performSslHandshake is set to - * true. - * - * Type: Boolean - * Recognition: Anytime - * Default: false - * - */ - public static final String SYNCHRONIZED_SSL_HANDSHAKE = "sblim.wbem.synchronizedSslHandshake"; - - /** - * - * If set to true, socket connections are attempted with the timeout value defined by - * sblim.wbem.socketConnectTimeout. If set to false, socket connections are attempted - * without a timeout. Using a timeout for socket connections is the preferred method - * but may introduce intermittent, significant performance impacts during the connection - * process in Java 5+ (see Sun bug 5092063). - * - * Type: Boolean - * Recognition: Anytime - * Default: true - * - */ - public static final String SOCKET_CONNECT_WITH_TIMEOUT = "sblim.wbem.socketConnectWithTimeout"; - - /** - * - * The timeout for socket connect requests. A timeout of zero is interpreted - * as infinite timeout. - * - * Note: This property has no effect unless socket connection with timeout is - * enabled (see the sblim.wbem.socketConnectWithTimeout property). - * - * Type: Integer - * Unit: Milliseconds - * Recognition: Anytime - * Range: 0 .. Integer.MAX_VALUE - * Default: 0 - * - */ - public static final String SOCKET_CONNECT_TIMEOUT = "sblim.wbem.socketConnectTimeout"; - - /** - * The idle timeout between socket requests after which the socket is - * automatically reset (closed, then reopened). A timeout of zero is - * interpreted as infinite timeout.
      - * Type: Integer
      - * Unit: Milliseconds
      - * Recognition: Anytime
      - * Range: 0 .. Integer.MAX_VALUE
      - * Default: 0
      - */ - public static final String SOCKET_IDLE_TIMEOUT = "sblim.wbem.socketIdleTimeout"; - - /** - * - * Turn on/off usage of the default user/password, which can be used - * if the CIMOM requires a "garbage" credential. If set to false, - * user-supplied credentials will be applied. If set to true, - * default credentials will be applied when both the user-supplied - * principal and credential are null/empty. - * - * Type: Boolean - * Recognition: Startup - * Default: false - * - */ - public static final String KEY_CREDENTIALS_DEFAULT_ENABLED = "sblim.wbem.default.authorization.enabled"; - - /** - * - * The name of the user for the "garbage" credential. - * - * Note: This property has no effect unless default authorization is - * enabled (see the sblim.wbem.default.authorization.enabled property) - * AND both the user-supplied principal and credential are null/empty. - * - * Type: String - * Recognition: Startup - * Default: "default" - * - */ - public static final String KEY_DEFAULT_PRINCIPAL = "sblim.wbem.default.principal"; - - /** - * - * The credential of the user for the "garbage" credential. - * - * Note: This property has no effect unless default authorization is - * enabled (see the sblim.wbem.default.authorization.enabled property) - * AND both the user-supplied principal and credential are null/empty. - * - * Type: String - * Recognition: Startup - * Default: "default" - * - */ - public static final String KEY_DEFAULT_CREDENTIAL = "sblim.wbem.default.credential"; - - /** - * The timeout for http connections of an indication listener. A timeout of - * zero is interpreted as infinite timeout.
      - *
      - * Type: Integer
      - * Unit: Milliseconds
      - * Recognition: On next creation of a WBEMListener
      - * Range: 0 .. Integer.MAX_VALUE
      - * Default: 10000
      - */ - public static final String LISTENER_HTTP_TIMEOUT = "sblim.wbem.listenerHttpTimeout"; - - /** - * The header timeout for http connections of an indication listener. The - * header timeout is defined as the maximum amount of time allowed to read - * in the entire http header. A timeout of zero is interpreted as infinite - * timeout.
      - *
      - * Note: One form of DoS attack sends periodic http header lines in an - * attempt to keep the socket open indefinitely. This timeout can be used to - * thwart such an attempt.
      - *
      - * Type: Integer
      - * Unit: Milliseconds
      - * Recognition: On next creation of a WBEMListener
      - * Range: 0 .. Integer.MAX_VALUE
      - * Default: 30000
      - */ - public static final String LISTENER_HTTP_HEADER_TIMEOUT = "sblim.wbem.listenerHttpHeaderTimeout"; - - /** - * The maximum allowable timeouts an http connection of an indication - * listener can have before the client ignores it. In other words, the - * number of times an IP exceeds sblim.wbem.listenerHttpTimeout and - * sblim.wbem.listenerHttpHeaderTimeout before it is blocked. A value of - * zero is interpreted as unlimited timeouts.
      - *
      - * Type: Integer
      - * Recognition: On next creation of a WBEMListener
      - * Range: 0 .. Integer.MAX_VALUE
      - * Default: 0
      - */ - public static final String LISTENER_HTTP_MAX_ALLOWED_TIMEOUTS = "sblim.wbem.listenerHttpMaxAllowedTimeouts"; - - /** - * The size of the thread pool for the connection handlers of the indication - * for http connections of an indication listener. This is the maximum - * number of handler threads the pool might create on heavy load.
      - * A value of -1 is interpreted as infinity.
      - * Type: Integer
      - * Unit: Count
      - * Recognition: On next creation of a WBEMListener
      - * Range: -1 .. Integer.MAX_VALUE
      - * Default: 8
      - */ - public static final String LISTENER_MAX_POOL_SIZE = "sblim.wbem.listenerPoolMaxSize"; - - /** - * The minimal number of connection handlers of the indication listener that - * will be kept open by the thread pool regardless of the current load.
      - * Type: Integer
      - * Unit: Count
      - * Recognition: On next creation of a WBEMListener
      - * Range: 0 .. Integer.MAX_VALUE
      - * Default: 2
      - */ - public static final String LISTENER_MIN_POOL_SIZE = "sblim.wbem.listenerPoolMinSize"; - - /** - * The maximum number of queued connections (the fixed capacity of the - * ArrayBlockingQueue of pending connections incoming to the listener). - * Whereas increasing this number will result in a correspondingly greater - * memory usage, making the number too small can result in HTTP 503 - * "Service temporarily overloaded" returned to server if there is no room - * in queue for an incoming connection.
      - * Type: Integer
      - * Unit: Count
      - * Recognition: On next creation of a WBEMListener
      - * Range: 1 .. Integer.MAX_VALUE
      - * Default: 32
      - */ - public static final String LISTENER_MAX_QUEUE_SIZE = "sblim.wbem.listenerQueueMaxSize"; - - /** - * The number of queued connections that is tolerated before the thread pool - * creates an additional handler thread. Increasing this value leads to a - * less "nervous" creation/destruction of handlers. However it - * makes the listener more vulnerable to frozen connections.
      - *
      - * Type: Integer
      - * Unit: Count
      - * Recognition: On next creation of a WBEMListener
      - * Range: 0 .. Integer.MAX_VALUE
      - * Default: 2
      - */ - public static final String LISTENER_BACKLOG = "sblim.wbem.listenerBacklog"; - - /** - * The idle time of a worker that is tolerated before the worker is - * destroyed by the thread pool. By setting the minimal pool size >0 you can - * protect a given number of worker from destruction.
      - *
      - * Type: Long
      - * Unit: Milliseconds
      - * Recognition: On next creation of a WBEMListener
      - * Range: 0 .. Long.MAX_VALUE
      - * Default: 30000
      - */ - public static final String LISTENER_HANDLER_MAX_IDLE = "sblim.wbem.listenerHandlerMaxIdle"; - - /** - * The maximum number of queued events (the fixed capacity of the LinkedList - * of indications awaiting delivery to the listener). When the maximum is - * reached, the oldest indications are discarded to make room for the newest - * ones. A value of 0 is interpreted as infinity.
      - * Type: Integer
      - * Unit: Count
      - * Recognition: On next creation of a WBEMListener
      - * Range: 0 .. Integer.MAX_VALUE
      - * Default: 0
      - */ - public static final String LISTENER_MAX_QUEUED_EVENTS = "sblim.wbem.listenerMaxQueuedEvents"; - - /** - * - * If set to true, reliable indication support is enabled and indications - * are processed accordingly. If set to false, reliable indication - * support is disabled and indications are passed directly to listener. - * - * If reliable indication support is enabled, incoming indications are - * handled as documented in DSP1054 which includes queuing unexpected - * indications, caching all indications for the duration of their sequence - * identifier lifetime, and logging missing, duplicate and out-of-order - * indications. - * - * The sequence identifier lifetime is defined as: - * DeliveryRetryAttempts * DeliveryRetryInterval * 10 - * These values can be set by the sblim.wbem.listenerDeliveryRetryAttempts - * and sblim.wbem.listenerDeliveryRetryInterval properties below. - * - * Unexpected indications are queued in either a linked list or a hash - * table based on the sblim.wbem.listenerReliableIndicationHashtableCapacity - * property below. The linked list is better suited for a small number of - * listener destinations per WBEMListener while the hash table is better - * suited for a large number. - * - * Type: Boolean - * Recognition: On next creation of a WBEMListener - * Default: false - * - */ - public static final String LISTENER_ENABLE_RELIABLE_INDICATIONS = "sblim.wbem.listenerEnableReliableIndications"; - - /** - * - * The default value to use for the CIM_IndicationService DeliveryRetryAttempts - * property. See DSP1054 for details on reliable indications. - * - * Note: This property has no effect unless reliable indication support is - * enabled. See the sblim.wbem.listenerEnableReliableIndications property. - * - * Type: Long - * Unit: Count - * Recognition: On next creation of a WBEMListener - * Range: 1 .. 1000 - * Default: 3 - * - */ - public static final String LISTENER_DELIVERY_RETRY_ATTEMPTS = "sblim.wbem.listenerDeliveryRetryAttempts"; - - /** - * - * The default value to use for the CIM_IndicationService DeliveryRetryInterval - * property. See DSP1054 for details on reliable indications. - * - * Note: This property has no effect unless reliable indication support is - * enabled. See the sblim.wbem.listenerEnableReliableIndications property. - * - * Type: Long - * Unit: Seconds - * Recognition: On next creation of a WBEMListener - * Range: 1 .. 86400 - * Default: 20 - * - */ - public static final String LISTENER_DELIVERY_RETRY_INTERVAL = "sblim.wbem.listenerDeliveryRetryInterval"; - - /** - * - * The default value to use for the reliable indication handler's initial - * hash table capacity. A value of 0 indicates use a linked list instead. - * Linked lists are better suited for a small number of listener destinations - * per WBEMListener while hash tables are better suited for a large number. - * - * Note: This property has no effect unless reliable indication support is - * enabled. See the sblim.wbem.listenerEnableReliableIndications property. - * - * Type: Integer - * Unit: Count - * Recognition: On next creation of a WBEMListener - * Range: 0 .. 25000 - * Default: 0 - * - */ - public static final String LISTENER_RELIABLE_INDICATION_HASHTABLE_CAPACITY = "sblim.wbem.listenerReliableIndicationHashtableCapacity"; - - /** - * - * The filter to use for tracing of incoming indications at the FINE level. - * - * If string is empty, no tracing of incoming indications will occur. If - * string is not empty, it identifies one or more properties to be included - * in the trace of all incoming indications. An optional class can be used - * to filter the output to include only those indications that contain the - * substring. For example, to trace the SequenceContext and SequenceNumber - * properties of all alerts, use the following: - * - * alert:sequencecontext,sequencenumber - * - * To trace the IndicationTime of all indications, use the following: - * - * indicationtime - * - * Note: This property has no effect unless tracing is enabled. See the - * sblim.wbem.traceFileLevel property. - * - * Type: String - * Recognition: On next creation of WBEMListener - * Format: [class:]property[,property]* - * - */ - public static final String LISTENER_INDICATION_TRACE_FILTER = "sblim.wbem.listenerIndicationTraceFilter"; - - /** - * - * If set to true, a property will be added to all indications that identifies - * the sender's IP address. If set to false, the property will not be added. - * - * The property is a CIMProperty with: - * name = "SBLIMJCC_SenderIPAddress" - * data type = CIMDataType.STRING_T - * value = String returned by InetAddress.getHostAddress() (i.e. 1.2.3.4) - * - * Type: Boolean - * Recognition: On next creation of a WBEMListener - * Default: false - * - */ - public static final String LISTENER_ADD_SENDER_IP_ADDRESS = "sblim.wbem.listenerAddSenderIPAddress"; - - /** - * - * If set to true, numeric string values passed to the java.lang.Double - * constructor or its parseDouble method will be checked to make sure they - * are not in the range that hangs Java 6- (see Sun bug 4421494). If - * set to false, the string values will not be checked. - * - * Note: This property should only be set to true if running on Java 5 or - * Java 6 prior to update 24. - * - * Type: Boolean - * Recognition: Startup - * Default: true - * - */ - public static final String VERIFY_JAVA_LANG_DOUBLE_STRINGS = "sblim.wbem.verifyJavaLangDoubleStrings"; - - /** - * - * If set to true, numeric key data types in a CIMInstance's CIMObjectPath - * will be synchronized to match those of the corresponding keys within - * the CIMInstance's CIMProperty[]. If set to false, the numeric key data - * types will not be synchronized. - * - * Note: Only numeric key data types in CIMInstances from CIMOM responses - * are synchronized, application calls to the CIMInstance constructor are - * not affected. - * - * Type: Boolean - * Recognition: Startup - * Default: false - * - */ - public static final String SYNCHRONIZE_NUMERIC_KEY_DATA_TYPES = "sblim.wbem.synchronizeNumericKeyDataTypes"; - - /** - * - * If set to true, gzip encoding is enabled. If set to false, gzip encoding - * is not enabled. When enabled, outgoing requests include the HTTP header - * "Accept-Encoding: gzip" to indicate to the CIMOM that the client handles - * message bodies compressed with gzip. If the incoming response includes - * "Content-Encoding: gzip" the message body will be decompressed with gzip - * before being processed. - * - * Note: This property does not affect indications or outgoing requests. - * - * Type: Boolean - * Recognition: Anytime - * Default: false - * - */ - public static final String ENABLE_GZIP_ENCODING = "sblim.wbem.enableGzipEncoding"; - - /** - * - * If set to true, the CIM-XML parser will allow empty LOCALNAMESPACEPATH - * elements in incoming responses. If set to false, the parser will not - * allow empty LOCALNAMESPACEPATH elements. - * - * Note: Some older CIMOMs sent empty LOCALNAMESPACEPATHs, relying on the - * client to provide the local namespace path. This is a violation of - * DSP0201, which dictates that LOCALNAMESPACEPATH must contain at least - * one NAMESPACE child. By default, this property is set to false so the - * client can adhere to the CIM-XML specifications. Set this property to - * true if "LOCALNAMESPACEPATH requires NAMESPACE" exceptions occur while - * interacting with one of these older CIMOMs. - * - * Type: Boolean - * Recognition: Anytime - * Default: false - * - */ - public static final String CIMXML_PARSER_ALLOW_EMPTY_LOCALNAMESPACEPATH = "sblim.wbem.cimxmlParser.allowEmptyLocalNameSpacePath"; - - /** - * AMMO-863 - *

      - * New configuration property to force the use of a strict mode for the - * HTTP header Connection=Keep-alive (that may not be used for HTTP/1.1). - */ - public static final String HTTP_KEEP_ALIVE_STRICT_MODE = "sblim.wbem.httpKeepAliveStrictMode"; -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, a.wolf-reber@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-11-08 lupusalex Make SBLIM client JSR48 compliant + * 1688273 2007-04-19 lupusalex Full support of HTTP trailers + * 1815707 2007-10-30 ebak TLS support + * 1827728 2007-11-12 ebak embeddedInstances: attribute EmbeddedObject not set + * 1848607 2007-12-11 ebak Strict EmbeddedObject types + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2372030 2008-12-01 blaschke-oss Add property to control synchronized SSL handshaking + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2846231 2009-09-23 rgummada connection failure on CIMOM w/o user/pw + * 2930341 2010-01-12 blaschke-oss Sync up WBEMClientConstants with JSR48 1.0.0 + * 2957387 2010-03-03 blaschke-oss EmbededObject XML attribute must not be all uppercases + * 2970881 2010-03-15 blaschke-oss Add property to control EmbeddedObject case + * 3046073 2010-09-07 blaschke-oss Performance hit due to socket conn. creation with timeout + * 3111718 2010-11-18 blaschke-oss org.sblim.cimclient SSL Code is using the wrong SSL Property + * 3185763 2011-02-25 blaschke-oss Reliable indication support - Phase 1 + * 3195069 2011-02-28 blaschke-oss Need support to disable SSL Handshake + * 3197423 2011-03-02 blaschke-oss Server authentication with PegasusLocalAuthInfo failing + * 3277928 2011-04-06 blaschke-oss CIM-XML tracing cannot be enabled in the field + * 3206904 2011-05-03 blaschke-oss Indication listener deadlock causes JVM to run out sockets + * 3288721 2011-05-20 blaschke-oss Need the function of indication reordering + * 3459036 2011-12-13 blaschke-oss Linked list for RI queue not efficient for many LDs + * 3485074 2012-02-06 blaschke-oss An Indication trace request + * 3492246 2012-02-23 blaschke-oss Rename new indication trace property + * 3492214 2012-02-23 blaschke-oss Add a SenderIPAddress property indications + * 3492224 2012-02-23 blaschke-oss Need two different timeouts for Socket connections + * 3521157 2012-05-10 blaschke-oss JSR48 1.0.0: PROP_ENABLE_*_LOGGING is Level, not 0/1 + * 3524050 2012-06-06 blaschke-oss Improve WWW-Authenticate in HTTPClient.java + * 3536399 2012-08-25 hellerda Add client/listener peer authentication properties + * 3572993 2012-10-01 blaschke-oss parseDouble("2.2250738585072012e-308") DoS vulnerability + * 3598613 2013-01-11 blaschke-oss different data type in cim instance and cim object path + * 2618 2013-02-27 blaschke-oss Need to add property to disable weak cipher suites for the secure indication + * 2628 2013-03-26 blaschke-oss Limit size of LinkedList of CIMEvents to be dispatched + * 2635 2013-05-16 blaschke-oss Slowloris DoS attack for CIM indication listener port + * 2642 2013-05-21 blaschke-oss Seperate properties needed for cim client and listener to filter out ciphers + * 2647 2013-07-01 blaschke-oss Add two ssl protocol properties for http server and client + * 2654 2013-07-29 blaschke-oss Check jcc idle time with CIMOM keepalive timeout to avoid EOF + * 2151 2013-08-20 blaschke-oss gzip compression not supported + * 2711 2013-11-13 blaschke-oss LOCALNAMESPACEPATH allows 0 NAMESPACE children + */ +package org.metricshub.wbem.sblim.cimclient; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * The interface WBEMConfigurationProperties contains the names of all + * configuration properties that are recognized by the CIM Client. + * + */ +public interface WBEMConfigurationProperties { + /** + * A URL string giving the location of the CIM client config file.
      + *
      + * By default the SBLIM CIM Client looks for + *

        + *
      • file:sblim-cim-client2.properties
      • + *
      • file:%USER_HOME%/sblim-cim-client2.properties
      • + *
      • file:/etc/java/sblim-cim-client2.properties
      • + *
      + * The first file found will be used. The default search list is not applied + * if this property is set, even if the given URL does not exist.
      + */ + public static final String CONFIG_URL = "sblim.wbem.configURL"; + + /** + * Sets the minimum level for messages to be written to the log file.
      + *
      + * Type: Discrete
      + * Recognition: Startup
      + * Range: OFF, SEVERE, WARNING, INFO, CONFIG, ALL
      + * Default: OFF, which disables file logging completely. + */ + public static final String LOG_FILE_LEVEL = "sblim.wbem.logFileLevel"; + + /** + * A string specifying the location of the log file. The string may include + * the following special components that will be replaced at runtime:
      + *
        + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
        /the local pathname separator
        %tthe system temporary directory
        %hthe value of the "user.home" system property
        %gthe generation number to distinguish rotated logs
        %ua unique number to resolve conflicts
        %%translates to a single percent sign "%"
        + *
      + * Thus for example a pattern of %t/java%g.log with a count of + * 2 would typically cause log files to be written on Unix to + * /var/tmp/java2.log
      + *
      + * Type: String
      + * Recognition: Startup
      + * Default: %t/cimclient_log_%g.txt. + */ + public static final String LOG_FILE_LOCATION = "sblim.wbem.logFileLocation"; + + /** + * Sets the maximum size in bytes of a single log file. When the limit is + * reached a new file is created. A limit of zero will create a new log file + * for every log record !
      + *
      + * Type: Integer
      + * Recognition: Startup
      + * Range: 0 .. Integer.MAX_VALUE
      + * Default: 100.000
      + */ + public static final String LOG_FILE_SIZE_LIMIT = "sblim.wbem.logFileSizeLimit"; + + /** + * Sets the number of log files to cycle through. When the number is + * exceeded the oldest file is dropped.
      + *
      + * Type: Integer
      + * Recognition: Startup
      + * Range: 1 .. Integer.MAX_VALUE
      + * Default: 5
      + */ + public static final String LOG_FILE_COUNT = "sblim.wbem.logFileCount"; + + /** + * Sets the minimum level for messages to be written to the console logger + * file.
      + *
      + * Type: Discrete
      + * Recognition: Startup
      + * Range: OFF, SEVERE, WARNING, INFO, CONFIG, ALL
      + * Default: OFF, which disables console logging completely. + */ + public static final String LOG_CONSOLE_LEVEL = "sblim.wbem.logConsoleLevel"; + + /** + * Sets the type of the console logger. Maybe either message log or trace + * log.
      + *
      + * Type: Discrete
      + * Recognition: Startup
      + * Range: MESSAGE, TRACE
      + * Default: MESSAGE. + */ + public static final String LOG_CONSOLE_TYPE = "sblim.wbem.logConsoleType"; + + /** + * Sets the minimum level for messages to be written to the trace file.
      + *
      + * Type: Discrete
      + * Recognition: Startup
      + * Range: + * OFF, SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST, ALL
      + * Default: OFF, which disables file tracing completely
      + */ + public static final String TRACE_FILE_LEVEL = "sblim.wbem.traceFileLevel"; + + /** + * A string specifying the location of the trace file. The string may + * include the following special components that will be replaced at + * runtime:
      + *
        + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
        /the local pathname separator
        %tthe system temporary directory
        %hthe value of the "user.home" system property
        %gthe generation number to distinguish rotated logs
        %ua unique number to resolve conflicts
        %%translates to a single percent sign "%"
        + *
      + * Thus for example a pattern of %t/java%g.log with a count of + * 2 would typically cause log files to be written on Unix to + * /var/tmp/java2.log
      + *
      + * Type: String
      + * Recognition: Startup
      + * Default: %t/cimclient_trace_%g.txt
      + */ + public static final String TRACE_FILE_LOCATION = "sblim.wbem.traceFileLocation"; + + /** + * Sets the maximum size in bytes of a single log file. When the limit is + * reached a new file is created. A limit of zero creates a new file for + * each trace record !
      + *
      + * Type: Integer
      + * Recognition: Startup
      + * Range: 0 .. Integer.MAX_VALUE
      + * Default: 1.000.000
      + */ + public static final String TRACE_FILE_SIZE_LIMIT = "sblim.wbem.traceFileSizeLimit"; + + /** + * Sets the number of log files to cycle through. When the number is + * exceeded the oldest file is dropped.
      + *
      + * Type: Integer
      + * Recognition: Startup
      + * Range: 1 .. Integer.MAX_VALUE
      + * Default: 5
      + */ + public static final String TRACE_FILE_COUNT = "sblim.wbem.traceFileCount"; + + /** + * The timeout for http requests. A timeout of zero is interpreted as + * infinite timeout.
      + *
      + * Type: Integer
      + * Unit: Milliseconds
      + * Recognition: Anytime
      + * Range: 0 .. Integer.MAX_VALUE
      + * Default: 0
      + */ + public static final String HTTP_TIMEOUT = "sblim.wbem.httpTimeout"; + + /** + * The size of the internal http connection pools. Each + * WBEMClient instance has it's own http connection pool. A + * positive value defines the number of connections, zero that no connection + * will be reused, and -1 all connections will be reused (when it's + * possible).
      + *
      + * Type: Integer
      + * Recognition: Anytime
      + * Range: -1, 0, 1 .. Integer.MAX_VALUE
      + * Default: 16
      + */ + public static final String HTTP_POOL_SIZE = "sblim.wbem.httpPoolSize"; + + /** + * The Java class name of the authentication module to use for http + * authentication.
      + *
      + * Type: String
      + * Recognition: On next authentication
      + * Range: + * + * org.sblim.cimclient.internal.http.WwwAuthInfo, org.sblim.cimclient.internal.http.PegasusLocalAuthInfo or any self-written subclass of org.sblim.cimclient.internal.http.AuthorizationInfo + *
      + * Default: org.sblim.cimclient.internal.http.WwwAuthInfo
      + */ + public static final String HTTP_AUTHENTICATION_MODULE = "sblim.wbem.httpAuthModule"; + + /** + * The WWW-Authenticate information to use when sending the first request to + * a server.
      + *
      + * Note: This string must exactly match what the server returns in the
      + * WWW-Authenticate field of an HTTP 401 response when authentication
      + * fails. The following two strings are examples:
      + *
      + * + * + * Basic realm="Secure Area" + * Digest realm="testrealm@host.com",qop="auth,auth-int",nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",opaque="5ccc069c403ebaf9f0171e9517f40e41" + * + * + * Type: String
      + * Recognition: On next authentication
      + * Range: Basic, Digest
      + * Default: none
      + */ + public static final String HTTP_WWW_AUTHENTICATE_INFO = "sblim.wbem.httpWwwAuthenticateInfo"; + + /** + * Specifies if MPOST is used for transmitting http messages. If false, POST + * is used.
      + *
      + * Type: Boolean
      + * Recognition: Anytime
      + * Range: true, false
      + * Default: true
      + */ + public static final String HTTP_USE_MPOST = "sblim.wbem.httpMPOST"; + + /** + * Specifies if chunking is used for transmitting http messages.
      + *
      + * Type: Boolean
      + * Recognition: Anytime
      + * Range: true, false
      + * Default: true
      + */ + public static final String HTTP_USE_CHUNKING = "sblim.wbem.httpChunking"; + + /** + * Specifies the http protocol version to use. This option is useful if the + * protocol negotiation fails.
      + *
      + * Type: String
      + * Recognition: Anytime
      + * Range: 1.0, 1.1
      + * Default: 1.1
      + */ + public static final String HTTP_VERSION = "sblim.wbem.httpVersion"; + + /** + * Specifies how often the client will retry to connect to a CIMOM which + * refused the connection in the first place.
      + *
      + * Type: Integer
      + * Recognition: Anytime
      + * Range: 0 .. Integer.MAX_VALUE
      + * Default: 0
      + */ + public static final String HTTP_CONNECTION_RETRIES = "sblim.wbem.httpConnectionRetries"; + + /** + * Specifies if the client will discard and request again http documents + * with less than a given number of bytes.
      + *
      + * Type: Boolean
      + * Recognition: Anytime
      + * Range: true, false
      + * Default: false
      + */ + public static final String HTTP_ENABLE_CONTENT_LENGTH_RETRY = "sblim.wbem.httpEnableContentLengthRetry"; + + /** + * Specifies the threshold above which a http document is regarded as valid + * by the content length retry algorithm.
      + *
      + * Type: Integer
      + * Recognition: Anytime
      + * Range: 0 .. Integer.MAX_VALUE
      + * Default: 50
      + */ + public static final String HTTP_CONTENT_LENGTH_THRESHOLD = "sblim.wbem.httpContentLengthThreshold"; + + /** + * The file path of the SSL keystore.
      + *
      + * Type: String
      + * Recognition: On next SSL connection
      + * Default: none
      + */ + public static final String KEYSTORE_PATH = "javax.net.ssl.keyStore"; + + /** + * The type of the keystore.
      + *
      + * Type: String
      + * Recognition: On next SSL connection
      + * Range: PKCS12, JKS, ...
      + * Default: JKS
      + */ + public static final String KEYSTORE_TYPE = "javax.net.ssl.keyStoreType"; + + /** + * The password of the keystore.
      + *
      + * Type: String
      + * Recognition: On next SSL connection
      + * Default: none
      + */ + public static final String KEYSTORE_PASSWORD = "javax.net.ssl.keyStorePassword"; + + /** + * The file path of the SSL truststore.
      + *
      + * Type: String
      + * Recognition: On next SSL connection
      + * Default: none
      + */ + public static final String TRUSTSTORE_PATH = "javax.net.ssl.trustStore"; + + /** + * The type of the truststore.
      + *
      + * Type: String
      + * Recognition: On next SSL connection
      + * Range: PKCS12, JKS, ...
      + * Default: JKS
      + */ + public static final String TRUSTSTORE_TYPE = "javax.net.ssl.trustStoreType"; + + /** + * The password of the truststore.
      + *
      + * Type: String
      + * Recognition: On next SSL connection
      + * Default: none
      + */ + public static final String TRUSTSTORE_PASSWORD = "javax.net.ssl.trustStorePassword"; + + /** + * The provider to use for creation of SSL client sockets.
      + *
      + * Security property: JRE global access via Security.setProperty() and Security.getProperty() ! + *
      + *
      + * Type: Java class name
      + * Recognition: On next SSL connection
      + * Default: Security.getProviders("SSLContext.SSL")
      + */ + public static final String SSL_SOCKET_PROVIDER = "sblim.wbem.sslSocketProvider"; + + /** + * The provider to use for creation of SSL server sockets.
      + *
      + * Security property: JRE global access via Security.setProperty() and Security.getProperty() ! + *
      + *
      + * Type: Java class name
      + * Recognition: On next SSL connection
      + * Default: Security.getProviders("SSLContext.SSL")
      + */ + public static final String SSL_SERVER_SOCKET_PROVIDER = "sblim.wbem.sslServerSocketProvider"; + + /** + * The protocol used for SSLContext.getInstance(String protocol). For + * IBMJSSE2 provider it can be "SSL_TLS".
      + *
      + * Security property: JRE global access via + * Security.setProperty() and + * Security.getProperty()
      + * Recognition: On next SSL connection
      + * Default: "SSL" + */ + public static final String SSL_PROTOCOL = "ssl.Protocol"; + + /** + * The protocol used for SSLContext.getInstance(String protocol) by a + * client. This property overrides any value set via the ssl.Protocol + * property.
      + *
      + * Recognition: On next SSL connection
      + * Default: none + */ + public static final String SSL_CLIENT_PROTOCOL = "sblim.wbem.sslClientProtocol"; + + /** + * The protocol used for SSLContext.getInstance(String protocol) by a + * listener. This property overrides any value set via the ssl.Protocol + * property.
      + *
      + * Recognition: On next SSL connection
      + * Default: none + */ + public static final String SSL_LISTENER_PROTOCOL = "sblim.wbem.sslListenerProtocol"; + + /** + * The key manager factory algorithm name.
      + *
      + * Security property: JRE global access via Security.setProperty() and Security.getProperty() ! + *
      + *
      + * Type: String
      + * Recognition: On next SSL connection
      + * Range: IbmX509, SunX509, ...
      + * Default: JRE specific
      + */ + public static final String SSL_KEYMANAGER_ALGORITHM = "ssl.KeyManagerFactory.algorithm"; + + /** + * The trust manager factory algorithm name.
      + *
      + * Security property: JRE global access via Security.setProperty() and Security.getProperty() ! + *
      + *
      + * Type: String
      + * Recognition: On next SSL connection
      + * Range: IbmX509, SunX509, ...
      + * Default: JRE specific
      + */ + public static final String SSL_TRUSTMANAGER_ALGORITHM = "ssl.TrustManagerFactory.algorithm"; + + /** + * Determines if a HTTPS client will attempt to authenticate the server + * (i.e. CIMOM) by verifying the server certificate.
      + *
      + * If false, do not attempt verification. If true, the client will attempt + * to verify the server certificate against the contents of the truststore; + * in this case a valid path must be defined in "javax.net.ssl.trustStore" + * or no connection will be permitted.
      + *
      + * Type: Boolean
      + * Recognition: On initialization of a new client
      + * Default: false
      + */ + public static final String SSL_CLIENT_PEER_VERIFICATION = "sblim.wbem.sslClientPeerVerification"; + + /** + * Determines how a HTTPS listener will handle authentication of a client + * (i.e. indication sender):
      + *
        + * + * + * + * + * + * + * + * + * + * + * + * + * + *
        ignoredo not examine the client certificate
        acceptexamine client certificate if presented; do not fail if not presented + *
        requireexamine client certificate; fail if not presented
        + *
      + * If set to "ignore", do not attempt verification. If set to "accept" or + * "require", the listener will attempt to verify the sender against the + * contents of the truststore; in this case a valid path must be defined in + * "javax.net.ssl.trustStore" or no connection will be permitted.
      + *
      + * Type: String
      + * Recognition: On next call to addListener()
      + * Default: ignore
      + */ + public static final String SSL_LISTENER_PEER_VERIFICATION = "sblim.wbem.sslListenerPeerVerification"; + + /** + * The comma-separated list of cipher suites that are to be disabled by the + * client when connecting via an SSL socket. In general, this is the list of + * cipher suites considered "too weak" for use in a particular environment.
      + *
      + * Type: String
      + * Recognition: On initialization of a new client
      + * Default: none
      + */ + public static final String SSL_CLIENT_CIPHER_SUITES_TO_DISABLE = "sblim.wbem.sslClientCipherSuitesToDisable"; + + /** + * The comma-separated list of cipher suites that are to be disabled by the + * listener when connecting via an SSL socket. In general, this is the list + * of cipher suites considered "too weak" for use in a particular + * environment.
      + *
      + * Type: String
      + * Recognition: On next call to addListener()
      + * Default: none
      + */ + public static final String SSL_LISTENER_CIPHER_SUITES_TO_DISABLE = "sblim.wbem.sslListenerCipherSuitesToDisable"; + + /** + * Specifies the XML parser for parsing CIM-XML responses.
      + * The SAX parser is the default choice since it is fast, resource saving + * and interoperable. The streaming algorithm of the PULL parser uses the + * fewest possible resources but at the prize to keep the CIMOMs response + * open for a long time. That works with many but not all CIMOMs. The DOM + * parser is slow and resource hungry but nice to debug.
      + *
      + * Type: Discrete
      + * Recognition: Anytime
      + * Range: DOM, PULL, SAX
      + * Default: SAX
      + */ + public static final String CIMXML_PARSER = "sblim.wbem.cimxmlParser"; + + /** + * Enables or disables tracing of CIM-XML communication. The trace is sent + * to an output stream the application has to set via the LogAndTraceManager + * class.
      + *
      + * Type: Boolean
      + * Recognition: Anytime
      + * Range: true, false
      + * Default: false
      + */ + public static final String CIMXML_TRACING = "sblim.wbem.cimxmlTracing"; + + /** + * Specifies the stream to use for tracing CIM-XML communication in the + * event the application does not set one via the LogAndTraceManager class. + * This stream can either be standard output (System.out), standard error + * output (System.err) or a filename to be opened by the client. + * + * Note: This property has no effect unless sblim.wbem.cimxmlTracing is set + * to true. + * + * Note: This property has no effect if the application already set the + * stream prior to client initialization. If the application sets the stream + * after client initialization, the stream specified by this property is + * overridden. + * + * Note: If a filename is specified, it is opened and all CIM-XML + * communication is written to it - no checks are made for an existing file + * or for filling up the disk. USE WITH CAUTION. + * + * Type: String
      + * Recognition: Startup
      + * Range: System.out, System.err, filename
      + * Default: none
      + */ + public static final String CIMXML_TRACE_STREAM = "sblim.wbem.cimxmlTraceStream"; + + /** + * + * Tells the XML builder how to sign embedded objects. This is necessary due to + * the non-consequent handling of embedded objects on different CIMOMs. + * "AttribOnly" - only the EmbeddedObject="instance/object" is used + * (should be good for Pegasus) + * "EmbObjQuali" - on qualified CIM-XML elements the EmbeddedObject qualifier is used + * for embedded classes and instances + * "EmbObjAndEmbInstQuali" - + * on qualified CIM-XML elements the EmbeddedObject qualifier is used + * for embedded classes and the EmbeddedInstance="className" qualifier + * is used for embedded instances + * Type: String + * Recognition: Anytime + * Range: AttribOnly, EmbObjQuali, EmbObjAndEmbInstQuali + * Default: AttribOnly + * + */ + public static final String CIMXML_EMBOBJBUILDER = "sblim.wbem.cimxmlEmbObjBuilder"; + + /** + * + * If set the type of valueless EmbeddedObjects are mapped to CLASS_T. It should work well + * with OpenPegasus-2.7.0. + * If unset no type mapping is done for valuless EmbeddedObjects. + * + * Type: Boolean + * Default: true + * + */ + public static final String CIMXML_PARSER_STRICT_EMBOBJ_TYPES = "sblim.wbem.cimxmlParser.strictEmbObjTypes"; + + /** + * + * If set to false, the embedded object entity in all requests is in mixed case + * (EmbeddedObject) per DSP0203. If set to true, the embedded object entity is in + * upper case (EMBEDDEDOBJECT) - this works with some older CIMOMs, such as OpenPegasus + * 2.6.1 and 2.7.0. + * + * <!ENTITY % EmbeddedObject "EmbeddedObject (object|instance) #IMPLIED"> + * + * Type: Boolean + * Recognition: Startup + * Range: true, false + * Default: true + * + */ + public static final String CIMXML_BUILDER_UPPERCASE_EMBOBJ_ENTITIES = + "sblim.wbem.cimxmlBuilder.upperCaseEmbObjEntities"; + + /** + * + * If set to true, SSL handshakes are performed after an SSL socket is created by the + * socket factory. If set to false, handshakes are not performed, which is useful if + * if the handshake has already taken place. + * + * Type: Boolean + * Recognition: Anytime + * Default: true + * + */ + public static final String PERFORM_SSL_HANDSHAKE = "sblim.wbem.performSslHandshake"; + + /** + * + * If set to false, SSL handshakes are not synchronized. If set to true, SSL handshakes + * are synchronized as a workaround for an IBMJSSE1 problem with thread-safe handshakes. + * + * Note: This property has no affect unless sblim.wbem.performSslHandshake is set to + * true. + * + * Type: Boolean + * Recognition: Anytime + * Default: false + * + */ + public static final String SYNCHRONIZED_SSL_HANDSHAKE = "sblim.wbem.synchronizedSslHandshake"; + + /** + * + * If set to true, socket connections are attempted with the timeout value defined by + * sblim.wbem.socketConnectTimeout. If set to false, socket connections are attempted + * without a timeout. Using a timeout for socket connections is the preferred method + * but may introduce intermittent, significant performance impacts during the connection + * process in Java 5+ (see Sun bug 5092063). + * + * Type: Boolean + * Recognition: Anytime + * Default: true + * + */ + public static final String SOCKET_CONNECT_WITH_TIMEOUT = "sblim.wbem.socketConnectWithTimeout"; + + /** + * + * The timeout for socket connect requests. A timeout of zero is interpreted + * as infinite timeout. + * + * Note: This property has no effect unless socket connection with timeout is + * enabled (see the sblim.wbem.socketConnectWithTimeout property). + * + * Type: Integer + * Unit: Milliseconds + * Recognition: Anytime + * Range: 0 .. Integer.MAX_VALUE + * Default: 0 + * + */ + public static final String SOCKET_CONNECT_TIMEOUT = "sblim.wbem.socketConnectTimeout"; + + /** + * The idle timeout between socket requests after which the socket is + * automatically reset (closed, then reopened). A timeout of zero is + * interpreted as infinite timeout.
      + * Type: Integer
      + * Unit: Milliseconds
      + * Recognition: Anytime
      + * Range: 0 .. Integer.MAX_VALUE
      + * Default: 0
      + */ + public static final String SOCKET_IDLE_TIMEOUT = "sblim.wbem.socketIdleTimeout"; + + /** + * + * Turn on/off usage of the default user/password, which can be used + * if the CIMOM requires a "garbage" credential. If set to false, + * user-supplied credentials will be applied. If set to true, + * default credentials will be applied when both the user-supplied + * principal and credential are null/empty. + * + * Type: Boolean + * Recognition: Startup + * Default: false + * + */ + public static final String KEY_CREDENTIALS_DEFAULT_ENABLED = "sblim.wbem.default.authorization.enabled"; + + /** + * + * The name of the user for the "garbage" credential. + * + * Note: This property has no effect unless default authorization is + * enabled (see the sblim.wbem.default.authorization.enabled property) + * AND both the user-supplied principal and credential are null/empty. + * + * Type: String + * Recognition: Startup + * Default: "default" + * + */ + public static final String KEY_DEFAULT_PRINCIPAL = "sblim.wbem.default.principal"; + + /** + * + * The credential of the user for the "garbage" credential. + * + * Note: This property has no effect unless default authorization is + * enabled (see the sblim.wbem.default.authorization.enabled property) + * AND both the user-supplied principal and credential are null/empty. + * + * Type: String + * Recognition: Startup + * Default: "default" + * + */ + public static final String KEY_DEFAULT_CREDENTIAL = "sblim.wbem.default.credential"; + + /** + * The timeout for http connections of an indication listener. A timeout of + * zero is interpreted as infinite timeout.
      + *
      + * Type: Integer
      + * Unit: Milliseconds
      + * Recognition: On next creation of a WBEMListener
      + * Range: 0 .. Integer.MAX_VALUE
      + * Default: 10000
      + */ + public static final String LISTENER_HTTP_TIMEOUT = "sblim.wbem.listenerHttpTimeout"; + + /** + * The header timeout for http connections of an indication listener. The + * header timeout is defined as the maximum amount of time allowed to read + * in the entire http header. A timeout of zero is interpreted as infinite + * timeout.
      + *
      + * Note: One form of DoS attack sends periodic http header lines in an + * attempt to keep the socket open indefinitely. This timeout can be used to + * thwart such an attempt.
      + *
      + * Type: Integer
      + * Unit: Milliseconds
      + * Recognition: On next creation of a WBEMListener
      + * Range: 0 .. Integer.MAX_VALUE
      + * Default: 30000
      + */ + public static final String LISTENER_HTTP_HEADER_TIMEOUT = "sblim.wbem.listenerHttpHeaderTimeout"; + + /** + * The maximum allowable timeouts an http connection of an indication + * listener can have before the client ignores it. In other words, the + * number of times an IP exceeds sblim.wbem.listenerHttpTimeout and + * sblim.wbem.listenerHttpHeaderTimeout before it is blocked. A value of + * zero is interpreted as unlimited timeouts.
      + *
      + * Type: Integer
      + * Recognition: On next creation of a WBEMListener
      + * Range: 0 .. Integer.MAX_VALUE
      + * Default: 0
      + */ + public static final String LISTENER_HTTP_MAX_ALLOWED_TIMEOUTS = "sblim.wbem.listenerHttpMaxAllowedTimeouts"; + + /** + * The size of the thread pool for the connection handlers of the indication + * for http connections of an indication listener. This is the maximum + * number of handler threads the pool might create on heavy load.
      + * A value of -1 is interpreted as infinity.
      + * Type: Integer
      + * Unit: Count
      + * Recognition: On next creation of a WBEMListener
      + * Range: -1 .. Integer.MAX_VALUE
      + * Default: 8
      + */ + public static final String LISTENER_MAX_POOL_SIZE = "sblim.wbem.listenerPoolMaxSize"; + + /** + * The minimal number of connection handlers of the indication listener that + * will be kept open by the thread pool regardless of the current load.
      + * Type: Integer
      + * Unit: Count
      + * Recognition: On next creation of a WBEMListener
      + * Range: 0 .. Integer.MAX_VALUE
      + * Default: 2
      + */ + public static final String LISTENER_MIN_POOL_SIZE = "sblim.wbem.listenerPoolMinSize"; + + /** + * The maximum number of queued connections (the fixed capacity of the + * ArrayBlockingQueue of pending connections incoming to the listener). + * Whereas increasing this number will result in a correspondingly greater + * memory usage, making the number too small can result in HTTP 503 + * "Service temporarily overloaded" returned to server if there is no room + * in queue for an incoming connection.
      + * Type: Integer
      + * Unit: Count
      + * Recognition: On next creation of a WBEMListener
      + * Range: 1 .. Integer.MAX_VALUE
      + * Default: 32
      + */ + public static final String LISTENER_MAX_QUEUE_SIZE = "sblim.wbem.listenerQueueMaxSize"; + + /** + * The number of queued connections that is tolerated before the thread pool + * creates an additional handler thread. Increasing this value leads to a + * less "nervous" creation/destruction of handlers. However it + * makes the listener more vulnerable to frozen connections.
      + *
      + * Type: Integer
      + * Unit: Count
      + * Recognition: On next creation of a WBEMListener
      + * Range: 0 .. Integer.MAX_VALUE
      + * Default: 2
      + */ + public static final String LISTENER_BACKLOG = "sblim.wbem.listenerBacklog"; + + /** + * The idle time of a worker that is tolerated before the worker is + * destroyed by the thread pool. By setting the minimal pool size >0 you can + * protect a given number of worker from destruction.
      + *
      + * Type: Long
      + * Unit: Milliseconds
      + * Recognition: On next creation of a WBEMListener
      + * Range: 0 .. Long.MAX_VALUE
      + * Default: 30000
      + */ + public static final String LISTENER_HANDLER_MAX_IDLE = "sblim.wbem.listenerHandlerMaxIdle"; + + /** + * The maximum number of queued events (the fixed capacity of the LinkedList + * of indications awaiting delivery to the listener). When the maximum is + * reached, the oldest indications are discarded to make room for the newest + * ones. A value of 0 is interpreted as infinity.
      + * Type: Integer
      + * Unit: Count
      + * Recognition: On next creation of a WBEMListener
      + * Range: 0 .. Integer.MAX_VALUE
      + * Default: 0
      + */ + public static final String LISTENER_MAX_QUEUED_EVENTS = "sblim.wbem.listenerMaxQueuedEvents"; + + /** + * + * If set to true, reliable indication support is enabled and indications + * are processed accordingly. If set to false, reliable indication + * support is disabled and indications are passed directly to listener. + * + * If reliable indication support is enabled, incoming indications are + * handled as documented in DSP1054 which includes queuing unexpected + * indications, caching all indications for the duration of their sequence + * identifier lifetime, and logging missing, duplicate and out-of-order + * indications. + * + * The sequence identifier lifetime is defined as: + * DeliveryRetryAttempts * DeliveryRetryInterval * 10 + * These values can be set by the sblim.wbem.listenerDeliveryRetryAttempts + * and sblim.wbem.listenerDeliveryRetryInterval properties below. + * + * Unexpected indications are queued in either a linked list or a hash + * table based on the sblim.wbem.listenerReliableIndicationHashtableCapacity + * property below. The linked list is better suited for a small number of + * listener destinations per WBEMListener while the hash table is better + * suited for a large number. + * + * Type: Boolean + * Recognition: On next creation of a WBEMListener + * Default: false + * + */ + public static final String LISTENER_ENABLE_RELIABLE_INDICATIONS = "sblim.wbem.listenerEnableReliableIndications"; + + /** + * + * The default value to use for the CIM_IndicationService DeliveryRetryAttempts + * property. See DSP1054 for details on reliable indications. + * + * Note: This property has no effect unless reliable indication support is + * enabled. See the sblim.wbem.listenerEnableReliableIndications property. + * + * Type: Long + * Unit: Count + * Recognition: On next creation of a WBEMListener + * Range: 1 .. 1000 + * Default: 3 + * + */ + public static final String LISTENER_DELIVERY_RETRY_ATTEMPTS = "sblim.wbem.listenerDeliveryRetryAttempts"; + + /** + * + * The default value to use for the CIM_IndicationService DeliveryRetryInterval + * property. See DSP1054 for details on reliable indications. + * + * Note: This property has no effect unless reliable indication support is + * enabled. See the sblim.wbem.listenerEnableReliableIndications property. + * + * Type: Long + * Unit: Seconds + * Recognition: On next creation of a WBEMListener + * Range: 1 .. 86400 + * Default: 20 + * + */ + public static final String LISTENER_DELIVERY_RETRY_INTERVAL = "sblim.wbem.listenerDeliveryRetryInterval"; + + /** + * + * The default value to use for the reliable indication handler's initial + * hash table capacity. A value of 0 indicates use a linked list instead. + * Linked lists are better suited for a small number of listener destinations + * per WBEMListener while hash tables are better suited for a large number. + * + * Note: This property has no effect unless reliable indication support is + * enabled. See the sblim.wbem.listenerEnableReliableIndications property. + * + * Type: Integer + * Unit: Count + * Recognition: On next creation of a WBEMListener + * Range: 0 .. 25000 + * Default: 0 + * + */ + public static final String LISTENER_RELIABLE_INDICATION_HASHTABLE_CAPACITY = + "sblim.wbem.listenerReliableIndicationHashtableCapacity"; + + /** + * + * The filter to use for tracing of incoming indications at the FINE level. + * + * If string is empty, no tracing of incoming indications will occur. If + * string is not empty, it identifies one or more properties to be included + * in the trace of all incoming indications. An optional class can be used + * to filter the output to include only those indications that contain the + * substring. For example, to trace the SequenceContext and SequenceNumber + * properties of all alerts, use the following: + * + * alert:sequencecontext,sequencenumber + * + * To trace the IndicationTime of all indications, use the following: + * + * indicationtime + * + * Note: This property has no effect unless tracing is enabled. See the + * sblim.wbem.traceFileLevel property. + * + * Type: String + * Recognition: On next creation of WBEMListener + * Format: [class:]property[,property]* + * + */ + public static final String LISTENER_INDICATION_TRACE_FILTER = "sblim.wbem.listenerIndicationTraceFilter"; + + /** + * + * If set to true, a property will be added to all indications that identifies + * the sender's IP address. If set to false, the property will not be added. + * + * The property is a CIMProperty with: + * name = "SBLIMJCC_SenderIPAddress" + * data type = CIMDataType.STRING_T + * value = String returned by InetAddress.getHostAddress() (i.e. 1.2.3.4) + * + * Type: Boolean + * Recognition: On next creation of a WBEMListener + * Default: false + * + */ + public static final String LISTENER_ADD_SENDER_IP_ADDRESS = "sblim.wbem.listenerAddSenderIPAddress"; + + /** + * + * If set to true, numeric string values passed to the java.lang.Double + * constructor or its parseDouble method will be checked to make sure they + * are not in the range that hangs Java 6- (see Sun bug 4421494). If + * set to false, the string values will not be checked. + * + * Note: This property should only be set to true if running on Java 5 or + * Java 6 prior to update 24. + * + * Type: Boolean + * Recognition: Startup + * Default: true + * + */ + public static final String VERIFY_JAVA_LANG_DOUBLE_STRINGS = "sblim.wbem.verifyJavaLangDoubleStrings"; + + /** + * + * If set to true, numeric key data types in a CIMInstance's CIMObjectPath + * will be synchronized to match those of the corresponding keys within + * the CIMInstance's CIMProperty[]. If set to false, the numeric key data + * types will not be synchronized. + * + * Note: Only numeric key data types in CIMInstances from CIMOM responses + * are synchronized, application calls to the CIMInstance constructor are + * not affected. + * + * Type: Boolean + * Recognition: Startup + * Default: false + * + */ + public static final String SYNCHRONIZE_NUMERIC_KEY_DATA_TYPES = "sblim.wbem.synchronizeNumericKeyDataTypes"; + + /** + * + * If set to true, gzip encoding is enabled. If set to false, gzip encoding + * is not enabled. When enabled, outgoing requests include the HTTP header + * "Accept-Encoding: gzip" to indicate to the CIMOM that the client handles + * message bodies compressed with gzip. If the incoming response includes + * "Content-Encoding: gzip" the message body will be decompressed with gzip + * before being processed. + * + * Note: This property does not affect indications or outgoing requests. + * + * Type: Boolean + * Recognition: Anytime + * Default: false + * + */ + public static final String ENABLE_GZIP_ENCODING = "sblim.wbem.enableGzipEncoding"; + + /** + * + * If set to true, the CIM-XML parser will allow empty LOCALNAMESPACEPATH + * elements in incoming responses. If set to false, the parser will not + * allow empty LOCALNAMESPACEPATH elements. + * + * Note: Some older CIMOMs sent empty LOCALNAMESPACEPATHs, relying on the + * client to provide the local namespace path. This is a violation of + * DSP0201, which dictates that LOCALNAMESPACEPATH must contain at least + * one NAMESPACE child. By default, this property is set to false so the + * client can adhere to the CIM-XML specifications. Set this property to + * true if "LOCALNAMESPACEPATH requires NAMESPACE" exceptions occur while + * interacting with one of these older CIMOMs. + * + * Type: Boolean + * Recognition: Anytime + * Default: false + * + */ + public static final String CIMXML_PARSER_ALLOW_EMPTY_LOCALNAMESPACEPATH = + "sblim.wbem.cimxmlParser.allowEmptyLocalNameSpacePath"; + + /** + * AMMO-863 + *

      + * New configuration property to force the use of a strict mode for the + * HTTP header Connection=Keep-alive (that may not be used for HTTP/1.1). + */ + public static final String HTTP_KEEP_ALIVE_STRICT_MODE = "sblim.wbem.httpKeepAliveStrictMode"; +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/WBEMListenerSBLIM.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/WBEMListenerSBLIM.java similarity index 75% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/WBEMListenerSBLIM.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/WBEMListenerSBLIM.java index b1be5ee..9a96ead 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/WBEMListenerSBLIM.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/WBEMListenerSBLIM.java @@ -1,465 +1,482 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1565892 2007-01-08 ebak Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 3023348 2010-07-02 blaschke-oss Listener uses # constructor instead of valueOf - * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues - * 3469018 2012-01-03 blaschke-oss Properties not passed to CIMIndicationHandler - * 3477087 2012-01-23 blaschke-oss Need Access to an Indication Sender's IP Address - * 3496385 2012-03-02 blaschke-oss JSR48 1.0.0: add WBEMListener get/setProperty - * 3513228 2012-04-23 blaschke-oss Reliable Indications support can create lots of threads - * 3529062 2012-05-23 blaschke-oss WBEMListenerFactory should return new instance - * 3529065 2012-05-31 hellerda Enable WBEMListener get/setProperty - * 2628 2013-03-26 blaschke-oss Limit size of LinkedList of CIMEvents to be dispatched - * 2635 2013-05-16 blaschke-oss Slowloris DoS attack for CIM indication listener port - * 2657 2013-08-20 blaschke-oss Potential null pointer exception in handleConnection - */ - -package org.sentrysoftware.wbem.sblim.cimclient; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.net.BindException; -import java.util.Enumeration; -import java.util.EventListener; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -import org.sentrysoftware.wbem.javax.wbem.listener.IndicationListener; -import org.sentrysoftware.wbem.javax.wbem.listener.WBEMListener; -import org.sentrysoftware.wbem.javax.wbem.listener.WBEMListenerConstants; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.HttpConnectionHandler; -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.HttpServerConnection; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConfiguration; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConstants; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.indications.CIMEventDispatcher; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.indications.CIMIndicationHandler; - -/** - * Class WBEMListenerSBLIM is the SBLIM implementation of the WBEMListener - * interface. - * - */ -public class WBEMListenerSBLIM implements WBEMListener { - - /** - * The real implementation of a listener that starts a HTTP server and - * processes incoming indications - * - */ - public class WBEMListenerImpl { - - private EventListener iIndicationListener; - - private HttpServerConnection iConnection; - - private CIMIndicationHandler iIndicationHandler; - - private HttpConnectionHandler iConnectionHandler; - - /** - * Ctor. - * - * @param pLocalAddress - * The local address to bind the port to. If null the port is - * bound to all local addresses. For use on multi-homed - * systems. - * @param pPort - * The port to listen on. If zero any free port will be - * chosen. - * @param pSSL - * SSL secured connection? - * @param pIndicationListener - * The indication listener to forward the incoming - * indications to (an instance of IndicationListener or - * IndicationListenerSBLIM). - * @param pProperties - * The configuration. - * @throws IOException - */ - public WBEMListenerImpl(String pLocalAddress, int pPort, boolean pSSL, - EventListener pIndicationListener, Properties pProperties) throws IOException { - - // Merge any properties passed via addListener - if (pProperties != null) { - for (Enumeration e = pProperties.keys(); e.hasMoreElements();) { - String key = (String) e.nextElement(); - String value = pProperties.getProperty(key); - setProperty(key, value); - } - } - WBEMConfiguration config = WBEMListenerSBLIM.this.iConfiguration; - if (!(pIndicationListener instanceof IndicationListener) - && !(pIndicationListener instanceof IndicationListenerSBLIM)) throw new IllegalArgumentException( - "Listener must be instance of IndicationListener or IndicationListenerSBLIM"); - this.iIndicationListener = pIndicationListener; - CIMEventDispatcher eventDispatcher = new CIMEventDispatcher(this.iIndicationListener, - config.getListenerMaxQueuedEvents()); - this.iIndicationHandler = new CIMIndicationHandler(eventDispatcher, config); - this.iConnectionHandler = new HttpConnectionHandler(this.iIndicationHandler, config); - this.iConnection = new HttpServerConnection(this.iConnectionHandler, pLocalAddress, - pPort, pSSL, config); - } - - @Override - protected void finalize() throws Throwable { - try { - stop(); - } finally { - super.finalize(); - } - } - - /** - * Starts the HTTP server connection receiving the indications. - */ - public void start() { - this.iConnection.start(); - } - - /** - * Stops the HTTP server connection receiving the indications and the - * indication handler. - */ - public void stop() { - this.iConnection.close(); - this.iIndicationHandler.close(); - } - - /** - * Returns the listener we forward the indications to. - * - * @return The listener. - */ - public IndicationListener getIndicationListener() { - return (this.iIndicationListener instanceof IndicationListener) ? (IndicationListener) this.iIndicationListener - : null; - } - - /** - * Returns the listener we forward the indications to. - * - * @return The listener. - */ - public IndicationListenerSBLIM getIndicationListenerSBLIM() { - return (this.iIndicationListener instanceof IndicationListenerSBLIM) ? (IndicationListenerSBLIM) this.iIndicationListener - : null; - } - - /** - * Returns the listener port. - * - * @return The listener port. - */ - public int getListenerPort() { - return this.iConnection.getPort(); - } - - /** - * Get the IPs blocked by the listener. - * - * @return The comma-separated list of blocked IPs. - */ - public String getBlockedIPs() { - return this.iConnectionHandler.getBlockedIPs(); - } - - /** - * Set the IPs to be blocked by the listener. - * - * @param pIPs - * The comma-separated list of blocked IPs. - */ - public void setBlockedIPs(String pIPs) { - this.iConnectionHandler.setBlockedIPs(pIPs); - } - } - - protected final WBEMConfiguration iConfiguration = new WBEMConfiguration(new Properties()); - - private Map iPortMap = new HashMap(); - - /** - * Ctor. - */ - public WBEMListenerSBLIM() { - super(); - } - - /* - * (non-Javadoc) - * - * @see org.sentrysoftware.wbem.javax.wbem.listener.WBEMListener#addListener(javax.wbem.listener. - * IndicationListener, int, java.lang.String) - */ - public int addListener(IndicationListener pListener, int pPort, String pTransport) - throws IOException { - return addListener((EventListener) pListener, pPort, pTransport, null, null); - } - - /* - * (non-Javadoc) - * - * @see org.sentrysoftware.wbem.javax.wbem.listener.WBEMListener#addListener(javax.wbem.listener. - * IndicationListener, int, java.lang.String, java.lang.String) - */ - public int addListener(IndicationListener pListener, int pPort, String pTransport, - String pLocalAddr) throws IOException { - return addListener((EventListener) pListener, pPort, pTransport, pLocalAddr, null); - } - - /** - * Add a new listener using the specified port. - * - * @param pListener - * The Indication Listener that will be called when an indication - * is received. - * @param pPort - * The port to listen on. Use 0 to specify any available port. - * @param pTransport - * The transport to use (e.g. HTTP or HTTPS). - * @param pLocalAddr - * The local IP address to bind to. This is only needed in - * multi-homed systems. A value of null will bind to - * all IP addresses. - * @param pConfigurationProperties - * The individual configuration properties for this listener. - * @return The port that was used. - * @throws IOException - * This exception is thrown when binding to pPort fails. - */ - public int addListener(IndicationListener pListener, int pPort, String pTransport, - String pLocalAddr, Properties pConfigurationProperties) throws IOException { - - return addListener((EventListener) pListener, pPort, pTransport, pLocalAddr, - pConfigurationProperties); - } - - /** - * Add a new listener using the specified port. - * - * @param pListener - * The SBLIM Indication Listener that will be called when an - * indication is received. - * @param pPort - * The port to listen on. Use 0 to specify any available port. - * @param pTransport - * The transport to use (e.g. HTTP or HTTPS). - * @return The port that was used. - * @throws IOException - * This exception is thrown when binding to pPort fails. - */ - public int addListener(IndicationListenerSBLIM pListener, int pPort, String pTransport) - throws IOException { - return addListener((EventListener) pListener, pPort, pTransport, null, null); - } - - /** - * Add a new listener using the specified port and local address. - * - * @param pListener - * The SBLIM Indication Listener that will be called when an - * indication is received. - * @param pPort - * The port to listen on. Use 0 to specify any available port. - * @param pTransport - * The transport to use (e.g. HTTP or HTTPS). - * @param pLocalAddr - * The local IP address to bind to. This is only needed in - * multi-homed systems. A value of null will bind to - * all IP addresses. - * @return The port that was used. - * @throws IOException - * This exception is thrown when binding to pPort fails. - */ - public int addListener(IndicationListenerSBLIM pListener, int pPort, String pTransport, - String pLocalAddr) throws IOException { - return addListener((EventListener) pListener, pPort, pTransport, pLocalAddr, null); - } - - /** - * Add a new listener using the specified port, local address and - * properties. - * - * @param pListener - * The SBLIM Indication Listener that will be called when an - * indication is received. - * @param pPort - * The port to listen on. Use 0 to specify any available port. - * @param pTransport - * The transport to use (e.g. HTTP or HTTPS). - * @param pLocalAddr - * The local IP address to bind to. This is only needed in - * multi-homed systems. A value of null will bind to - * all IP addresses. - * @param pConfigurationProperties - * The individual configuration properties for this listener. - * @return The port that was used. - * @throws IOException - * This exception is thrown when binding to pPort fails. - */ - public int addListener(IndicationListenerSBLIM pListener, int pPort, String pTransport, - String pLocalAddr, Properties pConfigurationProperties) throws IOException { - - return addListener((EventListener) pListener, pPort, pTransport, pLocalAddr, - pConfigurationProperties); - } - - /** - * Add a new listener using the specified port, local address and - * properties. This is the worker routine for all public addListener - * methods. - * - * @param pListener - * The indication listener (IndicationListener or - * IndicationListenerSBLIM) that will be called when - * an indication is received. - * @param pPort - * The port to listen on. Use 0 to specify any available port. - * @param pTransport - * The transport to use (e.g. HTTP or HTTPS). - * @param pLocalAddr - * The local IP address to bind to. This is only needed in - * multi-homed systems. A value of null will bind to - * all IP addresses. - * @param pConfigurationProperties - * The individual configuration properties for this listener. - * @return The port that was used. - * @throws IOException - * This exception is thrown when binding to pPort fails. - */ - private synchronized int addListener(EventListener pListener, int pPort, String pTransport, - String pLocalAddr, Properties pConfigurationProperties) throws IOException { - - if (pPort > 0 && this.iPortMap.containsKey(Integer.valueOf(pPort))) { throw new BindException( - "Port already in use."); } - boolean ssl; - if (pTransport.equalsIgnoreCase(WBEMConstants.HTTP)) ssl = false; - else if (pTransport.equalsIgnoreCase(WBEMConstants.HTTPS)) ssl = true; - else throw new IllegalArgumentException("Unknown transport: " + pTransport - + "! Valid values are http and https."); - - WBEMListenerImpl listener = new WBEMListenerImpl(pLocalAddr, pPort, ssl, pListener, - pConfigurationProperties); - listener.start(); - - this.iPortMap.put(Integer.valueOf(listener.getListenerPort()), listener); - - return listener.getListenerPort(); - } - - /** - * Get the IPs blocked by the listener associated with the specified port. - * - * @param pPort - * The port. - * @return The comma-separated list of blocked IPs. - */ - public String getBlockedIPs(int pPort) { - if (pPort <= 0 || !this.iPortMap.containsKey(Integer.valueOf(pPort))) { throw new IllegalArgumentException( - "Port not in use."); } - WBEMListenerImpl listener = this.iPortMap.get(Integer.valueOf(pPort)); - return listener != null ? listener.getBlockedIPs() : null; - } - - public String getProperty(String pName) { - if (pName.startsWith("javax.wbem.")) { - // Process JSR48 properties - if (pName.equals(WBEMListenerConstants.PROP_LISTENER_KEYSTORE)) { - return this.iConfiguration.getSslKeyStorePath(); - } else if (pName.equals(WBEMListenerConstants.PROP_LISTENER_KEYSTORE_PASSWORD)) { - return this.iConfiguration.getSslKeyStorePassword(); - } else if (pName.equals(WBEMListenerConstants.PROP_LISTENER_TRUSTSTORE)) { - return this.iConfiguration.getSslTrustStorePath(); - } else { - return null; - } - } - return this.iConfiguration.getDomainProperty(pName); - } - - public synchronized void removeListener(int pPort) { - WBEMListenerImpl listener = this.iPortMap.remove(Integer.valueOf(pPort)); - if (listener != null) { - listener.stop(); - } - } - - /** - * Set the IPs to be blocked by the listener associated with the specified - * port. - * - * @param pPort - * The port. - * @param pIPs - * The comma-separated list of blocked IPs. - */ - public void setBlockedIPs(int pPort, String pIPs) { - if (pPort <= 0 || !this.iPortMap.containsKey(Integer.valueOf(pPort))) { throw new IllegalArgumentException( - "Port not in use."); } - WBEMListenerImpl listener = this.iPortMap.get(Integer.valueOf(pPort)); - if (listener != null) { - listener.setBlockedIPs(pIPs); - } - } - - public void setProperty(String pName, String pValue) { - if (pName.startsWith("javax.wbem.")) { - // Process JSR48 properties - if (pName.equals(WBEMListenerConstants.PROP_LISTENER_KEYSTORE)) { - this.iConfiguration.setDomainProperty(WBEMConfigurationProperties.KEYSTORE_PATH, - pValue); - } else if (pName.equals(WBEMListenerConstants.PROP_LISTENER_KEYSTORE_PASSWORD)) { - this.iConfiguration.setDomainProperty( - WBEMConfigurationProperties.KEYSTORE_PASSWORD, pValue); - } else if (pName.equals(WBEMListenerConstants.PROP_LISTENER_TRUSTSTORE)) { - this.iConfiguration.setDomainProperty(WBEMConfigurationProperties.TRUSTSTORE_PATH, - pValue); - } else { - throw new IllegalArgumentException(pName); - } - } else { - this.iConfiguration.setDomainProperty(pName, pValue); - } - } -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1565892 2007-01-08 ebak Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 3023348 2010-07-02 blaschke-oss Listener uses # constructor instead of valueOf + * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues + * 3469018 2012-01-03 blaschke-oss Properties not passed to CIMIndicationHandler + * 3477087 2012-01-23 blaschke-oss Need Access to an Indication Sender's IP Address + * 3496385 2012-03-02 blaschke-oss JSR48 1.0.0: add WBEMListener get/setProperty + * 3513228 2012-04-23 blaschke-oss Reliable Indications support can create lots of threads + * 3529062 2012-05-23 blaschke-oss WBEMListenerFactory should return new instance + * 3529065 2012-05-31 hellerda Enable WBEMListener get/setProperty + * 2628 2013-03-26 blaschke-oss Limit size of LinkedList of CIMEvents to be dispatched + * 2635 2013-05-16 blaschke-oss Slowloris DoS attack for CIM indication listener port + * 2657 2013-08-20 blaschke-oss Potential null pointer exception in handleConnection + */ + +package org.metricshub.wbem.sblim.cimclient; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.net.BindException; +import java.util.Enumeration; +import java.util.EventListener; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import org.metricshub.wbem.javax.wbem.listener.IndicationListener; +import org.metricshub.wbem.javax.wbem.listener.WBEMListener; +import org.metricshub.wbem.javax.wbem.listener.WBEMListenerConstants; +import org.metricshub.wbem.sblim.cimclient.internal.http.HttpConnectionHandler; +import org.metricshub.wbem.sblim.cimclient.internal.http.HttpServerConnection; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfiguration; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConstants; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.indications.CIMEventDispatcher; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.indications.CIMIndicationHandler; + +/** + * Class WBEMListenerSBLIM is the SBLIM implementation of the WBEMListener + * interface. + * + */ +public class WBEMListenerSBLIM implements WBEMListener { + + /** + * The real implementation of a listener that starts a HTTP server and + * processes incoming indications + * + */ + public class WBEMListenerImpl { + private EventListener iIndicationListener; + + private HttpServerConnection iConnection; + + private CIMIndicationHandler iIndicationHandler; + + private HttpConnectionHandler iConnectionHandler; + + /** + * Ctor. + * + * @param pLocalAddress + * The local address to bind the port to. If null the port is + * bound to all local addresses. For use on multi-homed + * systems. + * @param pPort + * The port to listen on. If zero any free port will be + * chosen. + * @param pSSL + * SSL secured connection? + * @param pIndicationListener + * The indication listener to forward the incoming + * indications to (an instance of IndicationListener or + * IndicationListenerSBLIM). + * @param pProperties + * The configuration. + * @throws IOException + */ + public WBEMListenerImpl( + String pLocalAddress, + int pPort, + boolean pSSL, + EventListener pIndicationListener, + Properties pProperties + ) + throws IOException { + // Merge any properties passed via addListener + if (pProperties != null) { + for (Enumeration e = pProperties.keys(); e.hasMoreElements();) { + String key = (String) e.nextElement(); + String value = pProperties.getProperty(key); + setProperty(key, value); + } + } + WBEMConfiguration config = WBEMListenerSBLIM.this.iConfiguration; + if ( + !(pIndicationListener instanceof IndicationListener) && + !(pIndicationListener instanceof IndicationListenerSBLIM) + ) throw new IllegalArgumentException( + "Listener must be instance of IndicationListener or IndicationListenerSBLIM" + ); + this.iIndicationListener = pIndicationListener; + CIMEventDispatcher eventDispatcher = new CIMEventDispatcher( + this.iIndicationListener, + config.getListenerMaxQueuedEvents() + ); + this.iIndicationHandler = new CIMIndicationHandler(eventDispatcher, config); + this.iConnectionHandler = new HttpConnectionHandler(this.iIndicationHandler, config); + this.iConnection = new HttpServerConnection(this.iConnectionHandler, pLocalAddress, pPort, pSSL, config); + } + + @Override + protected void finalize() throws Throwable { + try { + stop(); + } finally { + super.finalize(); + } + } + + /** + * Starts the HTTP server connection receiving the indications. + */ + public void start() { + this.iConnection.start(); + } + + /** + * Stops the HTTP server connection receiving the indications and the + * indication handler. + */ + public void stop() { + this.iConnection.close(); + this.iIndicationHandler.close(); + } + + /** + * Returns the listener we forward the indications to. + * + * @return The listener. + */ + public IndicationListener getIndicationListener() { + return (this.iIndicationListener instanceof IndicationListener) + ? (IndicationListener) this.iIndicationListener + : null; + } + + /** + * Returns the listener we forward the indications to. + * + * @return The listener. + */ + public IndicationListenerSBLIM getIndicationListenerSBLIM() { + return (this.iIndicationListener instanceof IndicationListenerSBLIM) + ? (IndicationListenerSBLIM) this.iIndicationListener + : null; + } + + /** + * Returns the listener port. + * + * @return The listener port. + */ + public int getListenerPort() { + return this.iConnection.getPort(); + } + + /** + * Get the IPs blocked by the listener. + * + * @return The comma-separated list of blocked IPs. + */ + public String getBlockedIPs() { + return this.iConnectionHandler.getBlockedIPs(); + } + + /** + * Set the IPs to be blocked by the listener. + * + * @param pIPs + * The comma-separated list of blocked IPs. + */ + public void setBlockedIPs(String pIPs) { + this.iConnectionHandler.setBlockedIPs(pIPs); + } + } + + protected final WBEMConfiguration iConfiguration = new WBEMConfiguration(new Properties()); + + private Map iPortMap = new HashMap(); + + /** + * Ctor. + */ + public WBEMListenerSBLIM() { + super(); + } + + /* + * (non-Javadoc) + * + * @see org.metricshub.wbem.javax.wbem.listener.WBEMListener#addListener(javax.wbem.listener. + * IndicationListener, int, java.lang.String) + */ + public int addListener(IndicationListener pListener, int pPort, String pTransport) throws IOException { + return addListener((EventListener) pListener, pPort, pTransport, null, null); + } + + /* + * (non-Javadoc) + * + * @see org.metricshub.wbem.javax.wbem.listener.WBEMListener#addListener(javax.wbem.listener. + * IndicationListener, int, java.lang.String, java.lang.String) + */ + public int addListener(IndicationListener pListener, int pPort, String pTransport, String pLocalAddr) + throws IOException { + return addListener((EventListener) pListener, pPort, pTransport, pLocalAddr, null); + } + + /** + * Add a new listener using the specified port. + * + * @param pListener + * The Indication Listener that will be called when an indication + * is received. + * @param pPort + * The port to listen on. Use 0 to specify any available port. + * @param pTransport + * The transport to use (e.g. HTTP or HTTPS). + * @param pLocalAddr + * The local IP address to bind to. This is only needed in + * multi-homed systems. A value of null will bind to + * all IP addresses. + * @param pConfigurationProperties + * The individual configuration properties for this listener. + * @return The port that was used. + * @throws IOException + * This exception is thrown when binding to pPort fails. + */ + public int addListener( + IndicationListener pListener, + int pPort, + String pTransport, + String pLocalAddr, + Properties pConfigurationProperties + ) + throws IOException { + return addListener((EventListener) pListener, pPort, pTransport, pLocalAddr, pConfigurationProperties); + } + + /** + * Add a new listener using the specified port. + * + * @param pListener + * The SBLIM Indication Listener that will be called when an + * indication is received. + * @param pPort + * The port to listen on. Use 0 to specify any available port. + * @param pTransport + * The transport to use (e.g. HTTP or HTTPS). + * @return The port that was used. + * @throws IOException + * This exception is thrown when binding to pPort fails. + */ + public int addListener(IndicationListenerSBLIM pListener, int pPort, String pTransport) throws IOException { + return addListener((EventListener) pListener, pPort, pTransport, null, null); + } + + /** + * Add a new listener using the specified port and local address. + * + * @param pListener + * The SBLIM Indication Listener that will be called when an + * indication is received. + * @param pPort + * The port to listen on. Use 0 to specify any available port. + * @param pTransport + * The transport to use (e.g. HTTP or HTTPS). + * @param pLocalAddr + * The local IP address to bind to. This is only needed in + * multi-homed systems. A value of null will bind to + * all IP addresses. + * @return The port that was used. + * @throws IOException + * This exception is thrown when binding to pPort fails. + */ + public int addListener(IndicationListenerSBLIM pListener, int pPort, String pTransport, String pLocalAddr) + throws IOException { + return addListener((EventListener) pListener, pPort, pTransport, pLocalAddr, null); + } + + /** + * Add a new listener using the specified port, local address and + * properties. + * + * @param pListener + * The SBLIM Indication Listener that will be called when an + * indication is received. + * @param pPort + * The port to listen on. Use 0 to specify any available port. + * @param pTransport + * The transport to use (e.g. HTTP or HTTPS). + * @param pLocalAddr + * The local IP address to bind to. This is only needed in + * multi-homed systems. A value of null will bind to + * all IP addresses. + * @param pConfigurationProperties + * The individual configuration properties for this listener. + * @return The port that was used. + * @throws IOException + * This exception is thrown when binding to pPort fails. + */ + public int addListener( + IndicationListenerSBLIM pListener, + int pPort, + String pTransport, + String pLocalAddr, + Properties pConfigurationProperties + ) + throws IOException { + return addListener((EventListener) pListener, pPort, pTransport, pLocalAddr, pConfigurationProperties); + } + + /** + * Add a new listener using the specified port, local address and + * properties. This is the worker routine for all public addListener + * methods. + * + * @param pListener + * The indication listener (IndicationListener or + * IndicationListenerSBLIM) that will be called when + * an indication is received. + * @param pPort + * The port to listen on. Use 0 to specify any available port. + * @param pTransport + * The transport to use (e.g. HTTP or HTTPS). + * @param pLocalAddr + * The local IP address to bind to. This is only needed in + * multi-homed systems. A value of null will bind to + * all IP addresses. + * @param pConfigurationProperties + * The individual configuration properties for this listener. + * @return The port that was used. + * @throws IOException + * This exception is thrown when binding to pPort fails. + */ + private synchronized int addListener( + EventListener pListener, + int pPort, + String pTransport, + String pLocalAddr, + Properties pConfigurationProperties + ) + throws IOException { + if (pPort > 0 && this.iPortMap.containsKey(Integer.valueOf(pPort))) { + throw new BindException("Port already in use."); + } + boolean ssl; + if (pTransport.equalsIgnoreCase(WBEMConstants.HTTP)) ssl = false; else if ( + pTransport.equalsIgnoreCase(WBEMConstants.HTTPS) + ) ssl = true; else throw new IllegalArgumentException( + "Unknown transport: " + pTransport + "! Valid values are http and https." + ); + + WBEMListenerImpl listener = new WBEMListenerImpl(pLocalAddr, pPort, ssl, pListener, pConfigurationProperties); + listener.start(); + + this.iPortMap.put(Integer.valueOf(listener.getListenerPort()), listener); + + return listener.getListenerPort(); + } + + /** + * Get the IPs blocked by the listener associated with the specified port. + * + * @param pPort + * The port. + * @return The comma-separated list of blocked IPs. + */ + public String getBlockedIPs(int pPort) { + if (pPort <= 0 || !this.iPortMap.containsKey(Integer.valueOf(pPort))) { + throw new IllegalArgumentException("Port not in use."); + } + WBEMListenerImpl listener = this.iPortMap.get(Integer.valueOf(pPort)); + return listener != null ? listener.getBlockedIPs() : null; + } + + public String getProperty(String pName) { + if (pName.startsWith("javax.wbem.")) { + // Process JSR48 properties + if (pName.equals(WBEMListenerConstants.PROP_LISTENER_KEYSTORE)) { + return this.iConfiguration.getSslKeyStorePath(); + } else if (pName.equals(WBEMListenerConstants.PROP_LISTENER_KEYSTORE_PASSWORD)) { + return this.iConfiguration.getSslKeyStorePassword(); + } else if (pName.equals(WBEMListenerConstants.PROP_LISTENER_TRUSTSTORE)) { + return this.iConfiguration.getSslTrustStorePath(); + } else { + return null; + } + } + return this.iConfiguration.getDomainProperty(pName); + } + + public synchronized void removeListener(int pPort) { + WBEMListenerImpl listener = this.iPortMap.remove(Integer.valueOf(pPort)); + if (listener != null) { + listener.stop(); + } + } + + /** + * Set the IPs to be blocked by the listener associated with the specified + * port. + * + * @param pPort + * The port. + * @param pIPs + * The comma-separated list of blocked IPs. + */ + public void setBlockedIPs(int pPort, String pIPs) { + if (pPort <= 0 || !this.iPortMap.containsKey(Integer.valueOf(pPort))) { + throw new IllegalArgumentException("Port not in use."); + } + WBEMListenerImpl listener = this.iPortMap.get(Integer.valueOf(pPort)); + if (listener != null) { + listener.setBlockedIPs(pIPs); + } + } + + public void setProperty(String pName, String pValue) { + if (pName.startsWith("javax.wbem.")) { + // Process JSR48 properties + if (pName.equals(WBEMListenerConstants.PROP_LISTENER_KEYSTORE)) { + this.iConfiguration.setDomainProperty(WBEMConfigurationProperties.KEYSTORE_PATH, pValue); + } else if (pName.equals(WBEMListenerConstants.PROP_LISTENER_KEYSTORE_PASSWORD)) { + this.iConfiguration.setDomainProperty(WBEMConfigurationProperties.KEYSTORE_PASSWORD, pValue); + } else if (pName.equals(WBEMListenerConstants.PROP_LISTENER_TRUSTSTORE)) { + this.iConfiguration.setDomainProperty(WBEMConfigurationProperties.TRUSTSTORE_PATH, pValue); + } else { + throw new IllegalArgumentException(pName); + } + } else { + this.iConfiguration.setDomainProperty(pName, pValue); + } + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/discovery/AdvertisementCatalog.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/discovery/AdvertisementCatalog.java similarity index 84% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/discovery/AdvertisementCatalog.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/discovery/AdvertisementCatalog.java index 15c2234..54daae7 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/discovery/AdvertisementCatalog.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/discovery/AdvertisementCatalog.java @@ -1,560 +1,561 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1678915 2007-03-12 lupusalex Integrated WBEM service discovery via SLP - * 1729361 2007-06-04 lupusalex Multicast discovery is broken in DiscovererSLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - */ - -package org.sentrysoftware.wbem.sblim.cimclient.discovery; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; - -import javax.security.auth.Subject; -import org.sentrysoftware.wbem.javax.wbem.client.WBEMClient; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.logging.Level; -import java.util.Map; -import java.util.Set; - -/** - * Class AdvertisementCatalog implements a catalog for WBEM service - * advertisements. In practice we usually have multiple advertisements for a - * single service, because the DMTF mandates an advertisement per remote service - * access point (e.g. http, https, rmi). This class tries to ease the management - * of this by indexing services by the unique service id and therefore surfacing - * which advertisements belong to the same service. The application might then - * choose it's preferred communication mechanism. - * - * No thread synchronization provided, this is the responsibility of - * the caller. - * @since 2.0.2 - */ -public class AdvertisementCatalog { - - /** - * Interface EventListener specifies listener that are called when an - * advertisement is added to or removed from the catalog, expires or is - * renewed. - * - */ - public static interface EventListener { - - /** - * Called when an advertisement is added to the catalog that has not - * been a member of the catalog before. - * - * @param pEvent - * The type of the event. One of the constants - * EVENT_ADD, EVENT_REMOVE, EVENT_EXPIRE, EVENT_RENEW - * in AdvertisementCatalog. - * - * @param pAdvertisment - * The added advertisement - */ - public void advertisementEvent(int pEvent, WBEMServiceAdvertisement pAdvertisment); - } - - /** - * Class AdvertisementDecorator decorates a WBEMAdvertisement with state - * information required by the AdvertisementCatalog class - * - * @pattern Decorator - * iAvertisement!=null - */ - private static class AdvertisementDecorator implements WBEMServiceAdvertisement { - - private WBEMServiceAdvertisement iAdvertisement; - - private boolean iRefresh = false; - - /** - * Ctor. - * - * @param pAdvertisement - * The advertisement to decorate - */ - protected AdvertisementDecorator(WBEMServiceAdvertisement pAdvertisement) { - if (pAdvertisement == null) throw new IllegalArgumentException("Advertisement is null"); - this.iAdvertisement = pAdvertisement; - } - - /** - * Returns advertisement - * - * @return The value of advertisement. - */ - protected WBEMServiceAdvertisement getAdvertisementXXX() { - return this.iAdvertisement; - } - - /** - * Returns refresh - * - * @return The value of refresh. - */ - protected boolean isRefresh() { - return this.iRefresh; - } - - /** - * Sets advertisement - * - * @param pAdvertisement - * The new value of advertisement. - */ - protected void setAdvertisement(WBEMServiceAdvertisement pAdvertisement) { - this.iAdvertisement = pAdvertisement; - } - - /** - * Sets refresh - * - * @param pRefresh - * The new value of refresh. - */ - protected void setRefresh(boolean pRefresh) { - this.iRefresh = pRefresh; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object pObj) { - return this.iAdvertisement.equals(pObj); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - return this.iAdvertisement.hashCode(); - } - - /** - * @see WBEMServiceAdvertisement#createClient(javax.security.auth.Subject, java.util.Locale[]) - */ - public WBEMClient createClient(Subject pSubject, Locale[] pLocales) throws Exception { - return this.iAdvertisement.createClient(pSubject, pLocales); - } - - /** - * @see WBEMServiceAdvertisement#getAttribute(java.lang.String) - */ - public String getAttribute(String pAttributeName) { - return this.iAdvertisement.getAttribute(pAttributeName); - } - - /** - * @see WBEMServiceAdvertisement#getAttributes() - */ - public Set> getAttributes() { - return this.iAdvertisement.getAttributes(); - } - - /** - * @see WBEMServiceAdvertisement#getConcreteServiceType() - */ - public String getConcreteServiceType() { - return this.iAdvertisement.getConcreteServiceType(); - } - - /** - * @see WBEMServiceAdvertisement#getDirectory() - */ - public String getDirectory() { - return this.iAdvertisement.getDirectory(); - } - - /** - * @see WBEMServiceAdvertisement#getInteropNamespaces() - */ - public String[] getInteropNamespaces() { - return this.iAdvertisement.getInteropNamespaces(); - } - - /** - * @see WBEMServiceAdvertisement#getServiceId() - */ - public String getServiceId() { - return this.iAdvertisement.getServiceId(); - } - - /** - * @see WBEMServiceAdvertisement#getServiceUrl() - */ - public String getServiceUrl() { - return this.iAdvertisement.getServiceUrl(); - } - - /** - * @see WBEMServiceAdvertisement#isExpired() - */ - public boolean isExpired() { - return this.iAdvertisement.isExpired(); - } - - /** - * @see WBEMServiceAdvertisement#setExpired(boolean) - */ - public void setExpired(boolean pExpired) { - this.iAdvertisement.setExpired(pExpired); - } - } - - /** - * Event code when advertisement is added - */ - public static int EVENT_ADD = 1; - - /** - * Event code when advertisement is removed - */ - public static int EVENT_REMOVE = 2; - - /** - * Event code when advertisement expires - */ - public static int EVENT_EXPIRE = 4; - - /** - * Event code when advertisement is renewed - */ - public static int EVENT_RENEW = 8; - - private List iListeners = new LinkedList(); - - private HashMap> iCatalogByDirectory = new HashMap>(); - - private Map> iCatalogById = new HashMap>(); - - /** - * Ctor. - */ - public AdvertisementCatalog() { - /**/ - } - - /** - * Adds a listener for "add" events. The listener will be called whenever a - * advertisement is added to the catalog. - * - * @param pListener - * The listener - */ - public void addEventListener(EventListener pListener) { - this.iListeners.add(pListener); - } - - /** - * Adds new advertisements to the catalog. Existing advertisements sharing - * concrete type, url and directory are replaced. - * - * @param pAdvertisements - * The new advertisements - */ - public void addAdvertisements(WBEMServiceAdvertisement[] pAdvertisements) { - for (int i = 0; i < pAdvertisements.length; ++i) { - String url = ""; - try { - WBEMServiceAdvertisement advertisement = pAdvertisements[i]; - url = advertisement.getServiceUrl(); - WBEMProtocol protocol = makeProtocol(advertisement); - String serviceId = advertisement.getAttribute(WBEMServiceAdvertisement.SERVICE_ID); - { - List innerList = this.iCatalogByDirectory - .get(advertisement.getDirectory()); - if (innerList == null) { - innerList = new ArrayList(); - this.iCatalogByDirectory.put(advertisement.getDirectory(), innerList); - } - AdvertisementDecorator entry = findAdvertisement(innerList, advertisement); - if (entry != null) { - boolean wasExpired = entry.isExpired(); - entry.setAdvertisement(advertisement); - entry.setRefresh(false); - entry.setExpired(false); - if (wasExpired) { - notifyEventListeners(EVENT_RENEW, advertisement); - } - } else { - innerList.add(new AdvertisementDecorator(advertisement)); - notifyEventListeners(EVENT_ADD, advertisement); - } - } - { - Map innerMap = this.iCatalogById - .get(serviceId); - if (innerMap == null) { - innerMap = new HashMap(); - this.iCatalogById.put(serviceId, innerMap); - } - innerMap.put(protocol, advertisement); - } - } catch (Exception e) { - LogAndTraceBroker.getBroker().trace(Level.FINE, - "Incomplete advertisement for" + url, e); - } - } - } - - /** - * Returns the advertisement from the catalog corresponding to a given id - * and with the protocol preferred most. - * - * @param pId - * The service id - * @param pProtocols - * An array containing the desired protocols in order of - * preference. If a service doesn't advertise any of the given - * protocols this service returns null. - * @return The corresponding advertisement - */ - public WBEMServiceAdvertisement getAdvertisement(final String pId, - final WBEMProtocol[] pProtocols) { - Map innerMap = this.iCatalogById.get(pId); - if (innerMap == null) { return null; } - for (int i = 0; i < pProtocols.length; ++i) { - WBEMServiceAdvertisement advertisement = innerMap.get(pProtocols[i]); - if (advertisement != null) { return advertisement; } - } - return null; - } - - /** - * Returns the advertisements from the catalog corresponding to a given - * directory - * - * @param pDirectory - * The directory service - * @return The corresponding advertisements - */ - public WBEMServiceAdvertisement[] getAdvertisementsByDirectory(String pDirectory) { - List result = this.iCatalogByDirectory.get(pDirectory); - return (result != null ? (WBEMServiceAdvertisement[]) result - .toArray(new WBEMServiceAdvertisement[result.size()]) - : new WBEMServiceAdvertisement[] {}); - } - - /** - * Returns the advertisements from the catalog corresponding to a given id - * - * @param pId - * The service id - * @return The corresponding advertisements - */ - public WBEMServiceAdvertisement[] getAdvertisementsById(String pId) { - Map innerMap = this.iCatalogById.get(pId); - if (innerMap == null) { return null; } - Collection advertisements = innerMap.values(); - return advertisements.toArray(new WBEMServiceAdvertisement[advertisements.size()]); - } - - /** - * Returns an array of service ids known by this catalog - * - * @return The service ids - */ - public String[] getKnownIds() { - Set ids = this.iCatalogById.keySet(); - return ids.toArray(new String[ids.size()]); - } - - /** - * Refreshes the advertisements from a given directory. All existing - * advertisements from this directory are deleted first before the new ones - * are added. - * - * @param pDirectory - * The directory services we got the advertisements from - * @param pAdvertisements - * The advertisements - */ - public void refreshAdvertisements(final String[] pDirectory, - WBEMServiceAdvertisement[] pAdvertisements) { - for (int i = 0; i < pDirectory.length; ++i) { - markRefresh(pDirectory[i]); - } - addAdvertisements(pAdvertisements); - for (int i = 0; i < pDirectory.length; ++i) { - expire(pDirectory[i]); - } - } - - /** - * Removes a listener - * - * @param pListener - * The listener to remove - */ - public void removeEventListener(EventListener pListener) { - this.iListeners.remove(pListener); - } - - /** - * Removes the expired advertisements from the catalog. - * - * @param pDirectory - * When not null only the expired advertisements of - * the given directory are removed. Otherwise all expired - * advertisements are removed. - */ - public void removeExpired(String pDirectory) { - - if (pDirectory == null) { - Iterator iter = this.iCatalogByDirectory.keySet().iterator(); - while (iter.hasNext()) { - removeExpired(iter.next()); - } - return; - } - - List advertisementList = this.iCatalogByDirectory.get(pDirectory); - Iterator iter = advertisementList.iterator(); - while (iter.hasNext()) { - AdvertisementDecorator decorator = iter.next(); - if (decorator.isExpired()) { - iter.remove(); - notifyEventListeners(EVENT_REMOVE, decorator); - Map innerMap = this.iCatalogById - .get(decorator.getServiceId()); - innerMap.remove(makeProtocol(decorator)); - } - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - StringBuffer result = new StringBuffer(); - result.append("AdvertisementCatalog:"); - Iterator>> outer = this.iCatalogById - .entrySet().iterator(); - while (outer.hasNext()) { - Map.Entry> entry = outer.next(); - if (entry.getValue() == null) { - continue; - } - result.append("[service-id:\""); - result.append(entry.getKey()); - result.append("\""); - Map innerMap = entry.getValue(); - Iterator> inner = innerMap.entrySet() - .iterator(); - while (inner.hasNext()) { - Map.Entry innerEntry = inner.next(); - result.append("["); - result.append(innerEntry.getKey().toString()); - result.append("]"); - } - result.append("]"); - } - return result.toString(); - } - - private void expire(String pDirectory) { - List advertisementList = this.iCatalogByDirectory.get(pDirectory); - if (advertisementList == null) { return; } - Iterator iter = advertisementList.iterator(); - while (iter.hasNext()) { - AdvertisementDecorator advertisement = iter.next(); - if (advertisement.isRefresh()) { - advertisement.setRefresh(false); - advertisement.setExpired(true); - notifyEventListeners(EVENT_EXPIRE, advertisement); - } - } - } - - private AdvertisementDecorator findAdvertisement(List pList, - WBEMServiceAdvertisement pAdvertisement) { - Iterator iter = pList.iterator(); - while (iter.hasNext()) { - AdvertisementDecorator entry = iter.next(); - if (entry.getServiceUrl().equals(pAdvertisement.getServiceUrl())) { return entry; } - } - return null; - } - - private WBEMProtocol makeProtocol(WBEMServiceAdvertisement advertisement) { - String presentation = advertisement.getAttribute(WBEMServiceAdvertisement.COMM_MECHANISM); - if ("OTHER".equalsIgnoreCase(presentation)) { - presentation = advertisement - .getAttribute(WBEMServiceAdvertisement.OTHER_COMM_MECHN_DESC); - } - String transport = advertisement.getServiceUrl().split(":", 2)[0]; - WBEMProtocol protocol = new WBEMProtocol(transport, presentation); - return protocol; - } - - private void markRefresh(String pDirectory) { - List advertisementList = this.iCatalogByDirectory.get(pDirectory); - if (advertisementList == null) { return; } - Iterator iter = advertisementList.iterator(); - while (iter.hasNext()) { - AdvertisementDecorator advertisement = iter.next(); - advertisement.setRefresh(true); - } - } - - private void notifyEventListeners(int pEvent, WBEMServiceAdvertisement pAdvertisement) { - Iterator iter = this.iListeners.iterator(); - while (iter.hasNext()) { - iter.next().advertisementEvent(pEvent, pAdvertisement); - } - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1678915 2007-03-12 lupusalex Integrated WBEM service discovery via SLP + * 1729361 2007-06-04 lupusalex Multicast discovery is broken in DiscovererSLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + */ + +package org.metricshub.wbem.sblim.cimclient.discovery; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.logging.Level; +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import javax.security.auth.Subject; +import org.metricshub.wbem.javax.wbem.client.WBEMClient; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; + +/** + * Class AdvertisementCatalog implements a catalog for WBEM service + * advertisements. In practice we usually have multiple advertisements for a + * single service, because the DMTF mandates an advertisement per remote service + * access point (e.g. http, https, rmi). This class tries to ease the management + * of this by indexing services by the unique service id and therefore surfacing + * which advertisements belong to the same service. The application might then + * choose it's preferred communication mechanism. + * + * No thread synchronization provided, this is the responsibility of + * the caller. + * @since 2.0.2 + */ +public class AdvertisementCatalog { + + /** + * Interface EventListener specifies listener that are called when an + * advertisement is added to or removed from the catalog, expires or is + * renewed. + * + */ + public static interface EventListener { + /** + * Called when an advertisement is added to the catalog that has not + * been a member of the catalog before. + * + * @param pEvent + * The type of the event. One of the constants + * EVENT_ADD, EVENT_REMOVE, EVENT_EXPIRE, EVENT_RENEW + * in AdvertisementCatalog. + * + * @param pAdvertisment + * The added advertisement + */ + public void advertisementEvent(int pEvent, WBEMServiceAdvertisement pAdvertisment); + } + + /** + * Class AdvertisementDecorator decorates a WBEMAdvertisement with state + * information required by the AdvertisementCatalog class + * + * @pattern Decorator + * iAvertisement!=null + */ + private static class AdvertisementDecorator implements WBEMServiceAdvertisement { + private WBEMServiceAdvertisement iAdvertisement; + + private boolean iRefresh = false; + + /** + * Ctor. + * + * @param pAdvertisement + * The advertisement to decorate + */ + protected AdvertisementDecorator(WBEMServiceAdvertisement pAdvertisement) { + if (pAdvertisement == null) throw new IllegalArgumentException("Advertisement is null"); + this.iAdvertisement = pAdvertisement; + } + + /** + * Returns advertisement + * + * @return The value of advertisement. + */ + protected WBEMServiceAdvertisement getAdvertisementXXX() { + return this.iAdvertisement; + } + + /** + * Returns refresh + * + * @return The value of refresh. + */ + protected boolean isRefresh() { + return this.iRefresh; + } + + /** + * Sets advertisement + * + * @param pAdvertisement + * The new value of advertisement. + */ + protected void setAdvertisement(WBEMServiceAdvertisement pAdvertisement) { + this.iAdvertisement = pAdvertisement; + } + + /** + * Sets refresh + * + * @param pRefresh + * The new value of refresh. + */ + protected void setRefresh(boolean pRefresh) { + this.iRefresh = pRefresh; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object pObj) { + return this.iAdvertisement.equals(pObj); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return this.iAdvertisement.hashCode(); + } + + /** + * @see WBEMServiceAdvertisement#createClient(javax.security.auth.Subject, java.util.Locale[]) + */ + public WBEMClient createClient(Subject pSubject, Locale[] pLocales) throws Exception { + return this.iAdvertisement.createClient(pSubject, pLocales); + } + + /** + * @see WBEMServiceAdvertisement#getAttribute(java.lang.String) + */ + public String getAttribute(String pAttributeName) { + return this.iAdvertisement.getAttribute(pAttributeName); + } + + /** + * @see WBEMServiceAdvertisement#getAttributes() + */ + public Set> getAttributes() { + return this.iAdvertisement.getAttributes(); + } + + /** + * @see WBEMServiceAdvertisement#getConcreteServiceType() + */ + public String getConcreteServiceType() { + return this.iAdvertisement.getConcreteServiceType(); + } + + /** + * @see WBEMServiceAdvertisement#getDirectory() + */ + public String getDirectory() { + return this.iAdvertisement.getDirectory(); + } + + /** + * @see WBEMServiceAdvertisement#getInteropNamespaces() + */ + public String[] getInteropNamespaces() { + return this.iAdvertisement.getInteropNamespaces(); + } + + /** + * @see WBEMServiceAdvertisement#getServiceId() + */ + public String getServiceId() { + return this.iAdvertisement.getServiceId(); + } + + /** + * @see WBEMServiceAdvertisement#getServiceUrl() + */ + public String getServiceUrl() { + return this.iAdvertisement.getServiceUrl(); + } + + /** + * @see WBEMServiceAdvertisement#isExpired() + */ + public boolean isExpired() { + return this.iAdvertisement.isExpired(); + } + + /** + * @see WBEMServiceAdvertisement#setExpired(boolean) + */ + public void setExpired(boolean pExpired) { + this.iAdvertisement.setExpired(pExpired); + } + } + + /** + * Event code when advertisement is added + */ + public static int EVENT_ADD = 1; + + /** + * Event code when advertisement is removed + */ + public static int EVENT_REMOVE = 2; + + /** + * Event code when advertisement expires + */ + public static int EVENT_EXPIRE = 4; + + /** + * Event code when advertisement is renewed + */ + public static int EVENT_RENEW = 8; + + private List iListeners = new LinkedList(); + + private HashMap> iCatalogByDirectory = new HashMap>(); + + private Map> iCatalogById = new HashMap>(); + + /** + * Ctor. + */ + public AdvertisementCatalog() { + /**/ + } + + /** + * Adds a listener for "add" events. The listener will be called whenever a + * advertisement is added to the catalog. + * + * @param pListener + * The listener + */ + public void addEventListener(EventListener pListener) { + this.iListeners.add(pListener); + } + + /** + * Adds new advertisements to the catalog. Existing advertisements sharing + * concrete type, url and directory are replaced. + * + * @param pAdvertisements + * The new advertisements + */ + public void addAdvertisements(WBEMServiceAdvertisement[] pAdvertisements) { + for (int i = 0; i < pAdvertisements.length; ++i) { + String url = ""; + try { + WBEMServiceAdvertisement advertisement = pAdvertisements[i]; + url = advertisement.getServiceUrl(); + WBEMProtocol protocol = makeProtocol(advertisement); + String serviceId = advertisement.getAttribute(WBEMServiceAdvertisement.SERVICE_ID); + { + List innerList = this.iCatalogByDirectory.get(advertisement.getDirectory()); + if (innerList == null) { + innerList = new ArrayList(); + this.iCatalogByDirectory.put(advertisement.getDirectory(), innerList); + } + AdvertisementDecorator entry = findAdvertisement(innerList, advertisement); + if (entry != null) { + boolean wasExpired = entry.isExpired(); + entry.setAdvertisement(advertisement); + entry.setRefresh(false); + entry.setExpired(false); + if (wasExpired) { + notifyEventListeners(EVENT_RENEW, advertisement); + } + } else { + innerList.add(new AdvertisementDecorator(advertisement)); + notifyEventListeners(EVENT_ADD, advertisement); + } + } + { + Map innerMap = this.iCatalogById.get(serviceId); + if (innerMap == null) { + innerMap = new HashMap(); + this.iCatalogById.put(serviceId, innerMap); + } + innerMap.put(protocol, advertisement); + } + } catch (Exception e) { + LogAndTraceBroker.getBroker().trace(Level.FINE, "Incomplete advertisement for" + url, e); + } + } + } + + /** + * Returns the advertisement from the catalog corresponding to a given id + * and with the protocol preferred most. + * + * @param pId + * The service id + * @param pProtocols + * An array containing the desired protocols in order of + * preference. If a service doesn't advertise any of the given + * protocols this service returns null. + * @return The corresponding advertisement + */ + public WBEMServiceAdvertisement getAdvertisement(final String pId, final WBEMProtocol[] pProtocols) { + Map innerMap = this.iCatalogById.get(pId); + if (innerMap == null) { + return null; + } + for (int i = 0; i < pProtocols.length; ++i) { + WBEMServiceAdvertisement advertisement = innerMap.get(pProtocols[i]); + if (advertisement != null) { + return advertisement; + } + } + return null; + } + + /** + * Returns the advertisements from the catalog corresponding to a given + * directory + * + * @param pDirectory + * The directory service + * @return The corresponding advertisements + */ + public WBEMServiceAdvertisement[] getAdvertisementsByDirectory(String pDirectory) { + List result = this.iCatalogByDirectory.get(pDirectory); + return ( + result != null + ? (WBEMServiceAdvertisement[]) result.toArray(new WBEMServiceAdvertisement[result.size()]) + : new WBEMServiceAdvertisement[] {} + ); + } + + /** + * Returns the advertisements from the catalog corresponding to a given id + * + * @param pId + * The service id + * @return The corresponding advertisements + */ + public WBEMServiceAdvertisement[] getAdvertisementsById(String pId) { + Map innerMap = this.iCatalogById.get(pId); + if (innerMap == null) { + return null; + } + Collection advertisements = innerMap.values(); + return advertisements.toArray(new WBEMServiceAdvertisement[advertisements.size()]); + } + + /** + * Returns an array of service ids known by this catalog + * + * @return The service ids + */ + public String[] getKnownIds() { + Set ids = this.iCatalogById.keySet(); + return ids.toArray(new String[ids.size()]); + } + + /** + * Refreshes the advertisements from a given directory. All existing + * advertisements from this directory are deleted first before the new ones + * are added. + * + * @param pDirectory + * The directory services we got the advertisements from + * @param pAdvertisements + * The advertisements + */ + public void refreshAdvertisements(final String[] pDirectory, WBEMServiceAdvertisement[] pAdvertisements) { + for (int i = 0; i < pDirectory.length; ++i) { + markRefresh(pDirectory[i]); + } + addAdvertisements(pAdvertisements); + for (int i = 0; i < pDirectory.length; ++i) { + expire(pDirectory[i]); + } + } + + /** + * Removes a listener + * + * @param pListener + * The listener to remove + */ + public void removeEventListener(EventListener pListener) { + this.iListeners.remove(pListener); + } + + /** + * Removes the expired advertisements from the catalog. + * + * @param pDirectory + * When not null only the expired advertisements of + * the given directory are removed. Otherwise all expired + * advertisements are removed. + */ + public void removeExpired(String pDirectory) { + if (pDirectory == null) { + Iterator iter = this.iCatalogByDirectory.keySet().iterator(); + while (iter.hasNext()) { + removeExpired(iter.next()); + } + return; + } + + List advertisementList = this.iCatalogByDirectory.get(pDirectory); + Iterator iter = advertisementList.iterator(); + while (iter.hasNext()) { + AdvertisementDecorator decorator = iter.next(); + if (decorator.isExpired()) { + iter.remove(); + notifyEventListeners(EVENT_REMOVE, decorator); + Map innerMap = this.iCatalogById.get(decorator.getServiceId()); + innerMap.remove(makeProtocol(decorator)); + } + } + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuffer result = new StringBuffer(); + result.append("AdvertisementCatalog:"); + Iterator>> outer = + this.iCatalogById.entrySet().iterator(); + while (outer.hasNext()) { + Map.Entry> entry = outer.next(); + if (entry.getValue() == null) { + continue; + } + result.append("[service-id:\""); + result.append(entry.getKey()); + result.append("\""); + Map innerMap = entry.getValue(); + Iterator> inner = innerMap.entrySet().iterator(); + while (inner.hasNext()) { + Map.Entry innerEntry = inner.next(); + result.append("["); + result.append(innerEntry.getKey().toString()); + result.append("]"); + } + result.append("]"); + } + return result.toString(); + } + + private void expire(String pDirectory) { + List advertisementList = this.iCatalogByDirectory.get(pDirectory); + if (advertisementList == null) { + return; + } + Iterator iter = advertisementList.iterator(); + while (iter.hasNext()) { + AdvertisementDecorator advertisement = iter.next(); + if (advertisement.isRefresh()) { + advertisement.setRefresh(false); + advertisement.setExpired(true); + notifyEventListeners(EVENT_EXPIRE, advertisement); + } + } + } + + private AdvertisementDecorator findAdvertisement( + List pList, + WBEMServiceAdvertisement pAdvertisement + ) { + Iterator iter = pList.iterator(); + while (iter.hasNext()) { + AdvertisementDecorator entry = iter.next(); + if (entry.getServiceUrl().equals(pAdvertisement.getServiceUrl())) { + return entry; + } + } + return null; + } + + private WBEMProtocol makeProtocol(WBEMServiceAdvertisement advertisement) { + String presentation = advertisement.getAttribute(WBEMServiceAdvertisement.COMM_MECHANISM); + if ("OTHER".equalsIgnoreCase(presentation)) { + presentation = advertisement.getAttribute(WBEMServiceAdvertisement.OTHER_COMM_MECHN_DESC); + } + String transport = advertisement.getServiceUrl().split(":", 2)[0]; + WBEMProtocol protocol = new WBEMProtocol(transport, presentation); + return protocol; + } + + private void markRefresh(String pDirectory) { + List advertisementList = this.iCatalogByDirectory.get(pDirectory); + if (advertisementList == null) { + return; + } + Iterator iter = advertisementList.iterator(); + while (iter.hasNext()) { + AdvertisementDecorator advertisement = iter.next(); + advertisement.setRefresh(true); + } + } + + private void notifyEventListeners(int pEvent, WBEMServiceAdvertisement pAdvertisement) { + Iterator iter = this.iListeners.iterator(); + while (iter.hasNext()) { + iter.next().advertisementEvent(pEvent, pAdvertisement); + } + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/discovery/Discoverer.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/discovery/Discoverer.java similarity index 70% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/discovery/Discoverer.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/discovery/Discoverer.java index dd700c1..274eaaf 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/discovery/Discoverer.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/discovery/Discoverer.java @@ -1,73 +1,70 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1678915 2007-03-12 lupusalex Integrated WBEM service discovery via SLP - * 1729361 2007-06-04 lupusalex Multicast discovery is broken in DiscovererSLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.discovery; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * Interface Discoverer offers methodology for discovering WBEM services. - * - * Implementations SHALL ensure thread-safety - * @since 2.0.2 - */ -public interface Discoverer { - - /** - * Finds WBEM services using a given list of directory servers - * - * @param pDirectoryUrls - * An array of directory servers. For SLP this would be a list of - * DA URLs. - * @return The array of WBEM service advertisements found - */ - public WBEMServiceAdvertisement[] findWbemServices(String[] pDirectoryUrls); - - /** - * Finds directory services. The semantics of this method might be protocol - * specific. E.g. for SLP this sends a multicast into the local subnet - * looking first for directory agent, second for service agents. - * - * @return A String[] containing the URLs of the directories - * @since 2.0.3 - */ - public String[] findDirectoryServices(); -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1678915 2007-03-12 lupusalex Integrated WBEM service discovery via SLP + * 1729361 2007-06-04 lupusalex Multicast discovery is broken in DiscovererSLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.discovery; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * Interface Discoverer offers methodology for discovering WBEM services. + * + * Implementations SHALL ensure thread-safety + * @since 2.0.2 + */ +public interface Discoverer { + /** + * Finds WBEM services using a given list of directory servers + * + * @param pDirectoryUrls + * An array of directory servers. For SLP this would be a list of + * DA URLs. + * @return The array of WBEM service advertisements found + */ + public WBEMServiceAdvertisement[] findWbemServices(String[] pDirectoryUrls); + + /** + * Finds directory services. The semantics of this method might be protocol + * specific. E.g. for SLP this sends a multicast into the local subnet + * looking first for directory agent, second for service agents. + * + * @return A String[] containing the URLs of the directories + * @since 2.0.3 + */ + public String[] findDirectoryServices(); +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/discovery/DiscovererFactory.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/discovery/DiscovererFactory.java similarity index 68% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/discovery/DiscovererFactory.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/discovery/DiscovererFactory.java index 3a0a8cd..fa747b0 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/discovery/DiscovererFactory.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/discovery/DiscovererFactory.java @@ -1,93 +1,90 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1678915 2007-03-12 lupusalex Integrated WBEM service discovery via SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.discovery; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Locale; - -import org.sentrysoftware.wbem.sblim.cimclient.discovery.Discoverer; -import org.sentrysoftware.wbem.sblim.cimclient.internal.discovery.slp.DiscovererSLP; - -/** - * Class DiscovererFactory is responsible for creating concrete instances of the - * Discoverer interface. - * - * This class is thread-safe. - * - * @since 2.0.2 - */ -public class DiscovererFactory { - - /** - * The Service Location Protocol (SLP) - */ - public static final String SLP = "SLP"; - - private static final String[] cProtocols = new String[] { SLP }; - - /** - * Returns the concrete Discoverer for a given discovery protocol. - * - * @param pProtocol The discovery protocol, e.g. "SLP" - * @return The corresponding discoverer - * @throws IllegalArgumentException On unsupported protocols - * Factory Method - */ - public static Discoverer getDiscoverer(String pProtocol) throws IllegalArgumentException { - if (SLP.equalsIgnoreCase(pProtocol)) { - return new DiscovererSLP(Locale.US); - } - throw new IllegalArgumentException("Protocol " + pProtocol + " not supported."); - } - - /** - * Return an array of all supported discovery protocols - * - * @return The supported protocols - */ - public static String[] getSupportedProtocols() { - return cProtocols; - } - - private DiscovererFactory() { - /**/} -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1678915 2007-03-12 lupusalex Integrated WBEM service discovery via SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.discovery; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Locale; +import org.metricshub.wbem.sblim.cimclient.discovery.Discoverer; +import org.metricshub.wbem.sblim.cimclient.internal.discovery.slp.DiscovererSLP; + +/** + * Class DiscovererFactory is responsible for creating concrete instances of the + * Discoverer interface. + * + * This class is thread-safe. + * + * @since 2.0.2 + */ +public class DiscovererFactory { + /** + * The Service Location Protocol (SLP) + */ + public static final String SLP = "SLP"; + + private static final String[] cProtocols = new String[] { SLP }; + + /** + * Returns the concrete Discoverer for a given discovery protocol. + * + * @param pProtocol The discovery protocol, e.g. "SLP" + * @return The corresponding discoverer + * @throws IllegalArgumentException On unsupported protocols + * Factory Method + */ + public static Discoverer getDiscoverer(String pProtocol) throws IllegalArgumentException { + if (SLP.equalsIgnoreCase(pProtocol)) { + return new DiscovererSLP(Locale.US); + } + throw new IllegalArgumentException("Protocol " + pProtocol + " not supported."); + } + + /** + * Return an array of all supported discovery protocols + * + * @return The supported protocols + */ + public static String[] getSupportedProtocols() { + return cProtocols; + } + + private DiscovererFactory() { + /**/ + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/discovery/WBEMProtocol.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/discovery/WBEMProtocol.java similarity index 74% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/discovery/WBEMProtocol.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/discovery/WBEMProtocol.java index d8c8f97..ebe1956 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/discovery/WBEMProtocol.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/discovery/WBEMProtocol.java @@ -1,144 +1,139 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1678915 2007-03-29 lupusalex Integrated WBEM service discovery via SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.discovery; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * Class WBEMProtocol encapsulates a transport/presentation protocol pair. E.g. - * "HTTPS/CIM-XML" - * - * iTransport != null
      iPresentation != null
      - * @since 2.0.2 - */ -public class WBEMProtocol { - - private String iTransport; - - private String iPresentation; - - /** - * Ctor. - * - * @param pTransport - * The transport protocol (e.g. HTTP, HTTPS, RMI) - * @param pPresentation - * The presentation protocol (e.g. CIM-XML) - */ - public WBEMProtocol(String pTransport, String pPresentation) { - this.iTransport = pTransport != null ? pTransport.toUpperCase() : ""; - this.iPresentation = pPresentation != null ? pPresentation.toUpperCase() : ""; - } - - /** - * Returns the presentation protocol (e.g. CIM-XML) - * - * @return The value. - */ - public String getPresentation() { - return this.iPresentation; - } - - /** - * Sets the presentation protocol - * - * @param pPresentation - * The new value (e.g. CIM-XML) - */ - public void setPresentation(String pPresentation) { - this.iPresentation = pPresentation != null ? pPresentation : ""; - } - - /** - * Returns transport protocol (e.g. HTTP) - * - * @return The value. - */ - public String getTransport() { - return this.iTransport; - } - - /** - * Sets the transport protocol - * - * @param pTransport - * The new value (e.g. HTTP). - */ - public void setTransport(String pTransport) { - this.iTransport = pTransport != null ? pTransport : ""; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object pObj) { - if (pObj instanceof WBEMProtocol) { - WBEMProtocol that = (WBEMProtocol) pObj; - return (this.iTransport.equals(that.iTransport)) - && (this.iPresentation.equals(that.iPresentation)); - } - return false; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - return this.iTransport.hashCode() + this.iPresentation.hashCode(); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return this.iTransport + "/" + this.iPresentation; - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1678915 2007-03-29 lupusalex Integrated WBEM service discovery via SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.discovery; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * Class WBEMProtocol encapsulates a transport/presentation protocol pair. E.g. + * "HTTPS/CIM-XML" + * + * iTransport != null
      iPresentation != null
      + * @since 2.0.2 + */ +public class WBEMProtocol { + private String iTransport; + + private String iPresentation; + + /** + * Ctor. + * + * @param pTransport + * The transport protocol (e.g. HTTP, HTTPS, RMI) + * @param pPresentation + * The presentation protocol (e.g. CIM-XML) + */ + public WBEMProtocol(String pTransport, String pPresentation) { + this.iTransport = pTransport != null ? pTransport.toUpperCase() : ""; + this.iPresentation = pPresentation != null ? pPresentation.toUpperCase() : ""; + } + + /** + * Returns the presentation protocol (e.g. CIM-XML) + * + * @return The value. + */ + public String getPresentation() { + return this.iPresentation; + } + + /** + * Sets the presentation protocol + * + * @param pPresentation + * The new value (e.g. CIM-XML) + */ + public void setPresentation(String pPresentation) { + this.iPresentation = pPresentation != null ? pPresentation : ""; + } + + /** + * Returns transport protocol (e.g. HTTP) + * + * @return The value. + */ + public String getTransport() { + return this.iTransport; + } + + /** + * Sets the transport protocol + * + * @param pTransport + * The new value (e.g. HTTP). + */ + public void setTransport(String pTransport) { + this.iTransport = pTransport != null ? pTransport : ""; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object pObj) { + if (pObj instanceof WBEMProtocol) { + WBEMProtocol that = (WBEMProtocol) pObj; + return (this.iTransport.equals(that.iTransport)) && (this.iPresentation.equals(that.iPresentation)); + } + return false; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return this.iTransport.hashCode() + this.iPresentation.hashCode(); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return this.iTransport + "/" + this.iPresentation; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/discovery/WBEMServiceAdvertisement.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/discovery/WBEMServiceAdvertisement.java similarity index 91% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/discovery/WBEMServiceAdvertisement.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/discovery/WBEMServiceAdvertisement.java index 7e0b8f7..4fb64aa 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/discovery/WBEMServiceAdvertisement.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/discovery/WBEMServiceAdvertisement.java @@ -1,344 +1,340 @@ -/* - (C) Copyright IBM Corp. 2007, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1678915 2007-03-12 lupusalex Integrated WBEM service discovery via SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 3469427 2012-01-04 blaschke-oss Fix broken HTML links - */ - -package org.sentrysoftware.wbem.sblim.cimclient.discovery; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Locale; -import java.util.Set; -import java.util.Map.Entry; - -import javax.security.auth.Subject; -import org.sentrysoftware.wbem.javax.wbem.client.WBEMClient; - -/** - * Interface WBEMServiceAdvertisement is encapsulates the information collected - * about a service during discovery. The DMTF specifies a set a attributes that - * each service must advertise. These attributes are found as string constants - * in this interface and the method getAttribute() is offered to get an - * attribute by name. This design was chosen because the set of attributes might - * be extended by DMTF and vendor implementations. It's also unclear if upcoming - * new discovery protocols will have the same set of attributes as SLP. - * - * Immutable - * This class is thread-safe - * @since 2.0.2 - */ -public interface WBEMServiceAdvertisement { - - /** - * template-type (string): The scheme name of the service scheme. The scheme - * name consists of the service type name and an optional naming authority - * name, separated from the service type name by a period. See RFC 2609 - * section 3.2.2 for the conventions governing service type names. - */ - public static final String TEMPLATE_TYPE = "template-type"; - - /** - * template-version (string): The version number of the service type - * specification. - */ - public static final String TEMPLATE_VERSION = "template-version"; - - /** - * template-description (string): A description of the service suitable for - * inclusion in text read by people. - */ - public static final String TEMPLATE_DESCRIPTION = "template-description"; - - /** - * template-url-syntax (string): The template-url-syntax MUST be the WBEM - * URI Mapping of the location of one service access point offered by the - * WBEM Server over TCP transport. This attribute must provide sufficient - * addressing information so that the WBEM Server can be addressed directly - * using the URL. The WBEM URI Mapping is defined in the WBEM URI Mapping - * Specification 1.0.0 (DSP0207).
      - *
      - * Example: (template-url-syntax=https://localhost:5989) - */ - public static final String TEMPLATE_URL_SYNTAX = "template-url-syntax"; - - /** - * service-hi-name (string, optional): This string is used as a name of the - * CIM service for human interfaces. This attribute MUST be the - * CIM_ObjectManager.ElementName property value. - */ - public static final String SERVICE_HI_NAME = "service-hi-name"; - - /** - * service-hi-description (string, optional): This string is used as a - * description of the CIM service for human interfaces.This attribute MUST - * be the CIM_ObjectManager.Description property value. - */ - public static final String SERVICE_HI_DESC = "service-hi-description"; - - /** - * service-id (string, literal): The ID of this WBEM Server. The value MUST - * be the CIM_ObjectManager.Name property value. - */ - public static final String SERVICE_ID = "service-id"; - - /** - * CommunicationMechanism (string, literal): The communication mechanism - * (protocol) used by the CIM Object Manager for this service-location-tcp - * defined in this advertisement. This information MUST be the - * CIM_ObjectManagerCommunicationMechanism.CommunicationMechanism property - * value. CIM-XML is defined in the CIM Operations over HTTP specification - * which can be found at http://www.dmtf.org/
      - *
      - * Values: "Unknown", "Other", "cim-xml" - */ - public static final String COMM_MECHANISM = "CommunicationMechanism"; - - /** - * OtherCommunicationMechanismDescription (string, literal, optional): The - * other communication mechanism defined for the CIM Server in the case the - * "Other" value is set in the CommunicationMechanism string. This attribute - * MUST be the - * CIM_ObjectManagerCommunicationMechanism.OtherCommunicationMechanism - * property value. This attribute is optional because it is only required if - * the "other" value is set in CommunicationMechansim. The value returned is - * a free-form string. - */ - public static final String OTHER_COMM_MECHN_DESC = "OtherCommunicationMechanismDescription"; - - /** - * InteropSchemaNamespace (string, literal, multiple): Namespace within the - * target WBEM Server where the CIM Interop Schema can be accessed. Multiple - * namespaces may be provided. Each namespace provided MUST contain the same - * information. - */ - public static final String INTEROP_NS = "InteropSchemaNamespace"; - - /** - * ProtocolVersion (string, literal, optional): The version of the protocol. - * It MUST be the CIM_ObjectManagerCommunicationMechanism.Version property - * value. - */ - public static final String PROTOCOL_VERSION = "ProtocolVersion"; - - /** - * FunctionalProfilesSupported (string, literal, multiple): - * ProfilesSupported defines the CIM Operation profiles supported by the CIM - * Object Manager. This attribute MUST be the - * CIM_ObjectManagerCommunicationMechansim.FunctionalProfilesSupported - * property value.
      - *
      - * Values: - "Unknown", "Other", "Basic Read", "Basic Write", - "Schema Manipulation", "Instance Manipulation", - "Association Traversal", "Query Execution", - "Qualifier Declaration", "Indications" - */ - public static final String FUNCTIONAL_PROF_SUPP = "FunctionalProfilesSupported"; - - /** - * FunctionalProfileDescriptions (string, literal, multiple, optional): - * Other profile description if the "other" value is set in the - * ProfilesSupported attribute. This attribute is optional because it is - * returned only if the "other" value is set in the ProfilesSupported - * attribute. If provided it MUST be equal to the - * CIM_ObjectManagerCommunicationMechanism.FunctionalProfileDescriptions - * property value. - */ - public static final String FUNCTIONAL_PROF_DESC = "FunctionalProfileDescriptions"; - - /** - * MultipleOperationsSupported (boolean): Defines whether the CIM Object - * Manager supports batch operations. This attribute MUST be the - * CIM_ObjectManagerCommunicationMechanism.MultipleOperationsSupported - * property value. - */ - public static final String MULT_OPERATIONS_SUPP = "MultipleOperationsSupported"; - - /** - * AuthenticationMechanismsSupported (string, literal, multiple): Defines - * the authentication mechanism supported by the CIM Object Manager. This - * attributed MUST be the CIM_ObjectManagerCommunicationMechanism. - * AuthenticationMechanismsSupported property value.
      - *
      - * Values: "Unknown", "None", "Other", "Basic", "Digest" - */ - public static final String AUTH_MECH_SUPP = "AuthenticationMechanismsSupported"; - - /** - * AuthenticationMechansimDescriptions (string, literal, multiple, - * optional): Defines other Authentication mechanisms supported by the CIM - * Object Manager in the case where the "Other" value is set in any of the - * AuthenticationMechanismSupported attribute values. If provided, this - * attribute MUST be the CIM_ObjectManagerCommunicationMechanism. - * AuthenticationMechansimDescriptions property value. - */ - public static final String AUTH_MECH_DESC = "AuthenticationMechansimDescriptions"; - - /** - * Namespace (string, literal, multiple, optional): Namespace(s) supported - * on the CIM Object Manager. This attribute MUST be the CIM_Namespace.name - * property value for each instance of CIM_Namespace that exists. This - * attribute is optional. NOTE: This value is literal (L) because the - * namespace names MUST not be translated into other languages. - */ - public static final String NAMESPACE = "Namespace"; - - /** - * Classinfo (string, multiple, optional): This attributes is optional but - * if used, the values MUST be the CIM_Namespace.Classinfo property value. - * The values represent the classinfo (CIM Schema version, etc.) for the - * namespaces defined in the corresponding namespace listed in the Namespace - * attribute. Each entry in this attribute MUST correspond to the namespace - * defined in the same position of the namespace attribute. There must be - * one entry in this attribute for each entry in the namespace attribute. - */ - public static final String CLASSINFO = "Classinfo"; - - /** - * RegisteredProfilesSupported (string, literal, multiple): - * RegisteredProfilesSupported defines the Profiles that this WBEM Server - * has support for. Each entry in this attribute MUST be in the form of - * Organization:Profile Name{:Subprofile Name}
      - *
      - * Examples:
      - *
      - * - * DMTF:CIM Server
      - * DMTF:CIM Server:Protocol Adapter
      - * DMTF:CIM Server:Provider Registration
      - *

      - * The Organization MUST be the CIM_RegisteredProfile.RegisteredOrganization - * property value. The Profile Name MUST be the - * CIM_RegisteredProfile.RegisteredName property value. The subprofile Name - * MUST be the CIM_RegisteredProfile.RegisteredName property value when it - * is used as a Dependent in the CIM_SubProfileRequiresProfile association - * for the specified Profile Name (used as the antecedent). - * - */ - public static final String REG_PROF_SUPP = "RegisteredProfilesSupported"; - - /** - * Gets the URL of the directory from which this advertisement was received - * - * @return The directory URL - */ - public abstract String getDirectory(); - - /** - * Returns the concrete service type. E.g. for the SLP advertised service - * service:wbem:https this method would return - * https. - * - * @return The concrete service type - */ - public abstract String getConcreteServiceType(); - - /** - * Returns the interop namespaces - * - * @return The interop namespaces - */ - public abstract String[] getInteropNamespaces(); - - /** - * Returns the service url, e.g. http://9.155.62.79:5988 - * - * @return The service url - */ - public abstract String getServiceUrl(); - - /** - * Return the attribute value for a given attribute name - * - * @param pAttributeName - * The attribute name - * @return The value - */ - public abstract String getAttribute(String pAttributeName); - - /** - * Return the set of attributes of this advertisement - * - * @return A Set<Map.Entry<String, String>> containing the name - * value pairs of the attributes. - */ - public abstract Set> getAttributes(); - - /** - * Returns the service id - * - * @return The service id - */ - public abstract String getServiceId(); - - /** - * Returns the expiration state of the advertisement. - * - * @return true when advertisement is expired. - */ - public abstract boolean isExpired(); - - /** - * Sets the expirations state of the advertisement. Might be used by the - * application to mark an advertisement as expired, e.g. when it's no longer - * reported by the corresponding directory. Used for this purpose by - * AdvertisementCatalog. - * - * @param pExpired - * The new value - */ - public abstract void setExpired(boolean pExpired); - - /** - * Creates a fully-initialized WBEMClient instance connected to the service - * that is subject of this advertisement. On every call to this method a new - * client will be created. The client is not stored or cached anywhere in - * this class. - * - * @param pSubject - * The credential for authenticating with the service - * @param pLocales - * An array of locales ordered by preference - * @return The WBEM client - * @throws Exception - * @pattern Factory Methods - */ - public abstract WBEMClient createClient(Subject pSubject, Locale[] pLocales) throws Exception; -} +/* + (C) Copyright IBM Corp. 2007, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1678915 2007-03-12 lupusalex Integrated WBEM service discovery via SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 3469427 2012-01-04 blaschke-oss Fix broken HTML links + */ + +package org.metricshub.wbem.sblim.cimclient.discovery; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Locale; +import java.util.Map.Entry; +import java.util.Set; +import javax.security.auth.Subject; +import org.metricshub.wbem.javax.wbem.client.WBEMClient; + +/** + * Interface WBEMServiceAdvertisement is encapsulates the information collected + * about a service during discovery. The DMTF specifies a set a attributes that + * each service must advertise. These attributes are found as string constants + * in this interface and the method getAttribute() is offered to get an + * attribute by name. This design was chosen because the set of attributes might + * be extended by DMTF and vendor implementations. It's also unclear if upcoming + * new discovery protocols will have the same set of attributes as SLP. + * + * Immutable + * This class is thread-safe + * @since 2.0.2 + */ +public interface WBEMServiceAdvertisement { + /** + * template-type (string): The scheme name of the service scheme. The scheme + * name consists of the service type name and an optional naming authority + * name, separated from the service type name by a period. See RFC 2609 + * section 3.2.2 for the conventions governing service type names. + */ + public static final String TEMPLATE_TYPE = "template-type"; + + /** + * template-version (string): The version number of the service type + * specification. + */ + public static final String TEMPLATE_VERSION = "template-version"; + + /** + * template-description (string): A description of the service suitable for + * inclusion in text read by people. + */ + public static final String TEMPLATE_DESCRIPTION = "template-description"; + + /** + * template-url-syntax (string): The template-url-syntax MUST be the WBEM + * URI Mapping of the location of one service access point offered by the + * WBEM Server over TCP transport. This attribute must provide sufficient + * addressing information so that the WBEM Server can be addressed directly + * using the URL. The WBEM URI Mapping is defined in the WBEM URI Mapping + * Specification 1.0.0 (DSP0207).
      + *
      + * Example: (template-url-syntax=https://localhost:5989) + */ + public static final String TEMPLATE_URL_SYNTAX = "template-url-syntax"; + + /** + * service-hi-name (string, optional): This string is used as a name of the + * CIM service for human interfaces. This attribute MUST be the + * CIM_ObjectManager.ElementName property value. + */ + public static final String SERVICE_HI_NAME = "service-hi-name"; + + /** + * service-hi-description (string, optional): This string is used as a + * description of the CIM service for human interfaces.This attribute MUST + * be the CIM_ObjectManager.Description property value. + */ + public static final String SERVICE_HI_DESC = "service-hi-description"; + + /** + * service-id (string, literal): The ID of this WBEM Server. The value MUST + * be the CIM_ObjectManager.Name property value. + */ + public static final String SERVICE_ID = "service-id"; + + /** + * CommunicationMechanism (string, literal): The communication mechanism + * (protocol) used by the CIM Object Manager for this service-location-tcp + * defined in this advertisement. This information MUST be the + * CIM_ObjectManagerCommunicationMechanism.CommunicationMechanism property + * value. CIM-XML is defined in the CIM Operations over HTTP specification + * which can be found at http://www.dmtf.org/
      + *
      + * Values: "Unknown", "Other", "cim-xml" + */ + public static final String COMM_MECHANISM = "CommunicationMechanism"; + + /** + * OtherCommunicationMechanismDescription (string, literal, optional): The + * other communication mechanism defined for the CIM Server in the case the + * "Other" value is set in the CommunicationMechanism string. This attribute + * MUST be the + * CIM_ObjectManagerCommunicationMechanism.OtherCommunicationMechanism + * property value. This attribute is optional because it is only required if + * the "other" value is set in CommunicationMechansim. The value returned is + * a free-form string. + */ + public static final String OTHER_COMM_MECHN_DESC = "OtherCommunicationMechanismDescription"; + + /** + * InteropSchemaNamespace (string, literal, multiple): Namespace within the + * target WBEM Server where the CIM Interop Schema can be accessed. Multiple + * namespaces may be provided. Each namespace provided MUST contain the same + * information. + */ + public static final String INTEROP_NS = "InteropSchemaNamespace"; + + /** + * ProtocolVersion (string, literal, optional): The version of the protocol. + * It MUST be the CIM_ObjectManagerCommunicationMechanism.Version property + * value. + */ + public static final String PROTOCOL_VERSION = "ProtocolVersion"; + + /** + * FunctionalProfilesSupported (string, literal, multiple): + * ProfilesSupported defines the CIM Operation profiles supported by the CIM + * Object Manager. This attribute MUST be the + * CIM_ObjectManagerCommunicationMechansim.FunctionalProfilesSupported + * property value.
      + *
      + * Values: + "Unknown", "Other", "Basic Read", "Basic Write", + "Schema Manipulation", "Instance Manipulation", + "Association Traversal", "Query Execution", + "Qualifier Declaration", "Indications" + */ + public static final String FUNCTIONAL_PROF_SUPP = "FunctionalProfilesSupported"; + + /** + * FunctionalProfileDescriptions (string, literal, multiple, optional): + * Other profile description if the "other" value is set in the + * ProfilesSupported attribute. This attribute is optional because it is + * returned only if the "other" value is set in the ProfilesSupported + * attribute. If provided it MUST be equal to the + * CIM_ObjectManagerCommunicationMechanism.FunctionalProfileDescriptions + * property value. + */ + public static final String FUNCTIONAL_PROF_DESC = "FunctionalProfileDescriptions"; + + /** + * MultipleOperationsSupported (boolean): Defines whether the CIM Object + * Manager supports batch operations. This attribute MUST be the + * CIM_ObjectManagerCommunicationMechanism.MultipleOperationsSupported + * property value. + */ + public static final String MULT_OPERATIONS_SUPP = "MultipleOperationsSupported"; + + /** + * AuthenticationMechanismsSupported (string, literal, multiple): Defines + * the authentication mechanism supported by the CIM Object Manager. This + * attributed MUST be the CIM_ObjectManagerCommunicationMechanism. + * AuthenticationMechanismsSupported property value.
      + *
      + * Values: "Unknown", "None", "Other", "Basic", "Digest" + */ + public static final String AUTH_MECH_SUPP = "AuthenticationMechanismsSupported"; + + /** + * AuthenticationMechansimDescriptions (string, literal, multiple, + * optional): Defines other Authentication mechanisms supported by the CIM + * Object Manager in the case where the "Other" value is set in any of the + * AuthenticationMechanismSupported attribute values. If provided, this + * attribute MUST be the CIM_ObjectManagerCommunicationMechanism. + * AuthenticationMechansimDescriptions property value. + */ + public static final String AUTH_MECH_DESC = "AuthenticationMechansimDescriptions"; + + /** + * Namespace (string, literal, multiple, optional): Namespace(s) supported + * on the CIM Object Manager. This attribute MUST be the CIM_Namespace.name + * property value for each instance of CIM_Namespace that exists. This + * attribute is optional. NOTE: This value is literal (L) because the + * namespace names MUST not be translated into other languages. + */ + public static final String NAMESPACE = "Namespace"; + + /** + * Classinfo (string, multiple, optional): This attributes is optional but + * if used, the values MUST be the CIM_Namespace.Classinfo property value. + * The values represent the classinfo (CIM Schema version, etc.) for the + * namespaces defined in the corresponding namespace listed in the Namespace + * attribute. Each entry in this attribute MUST correspond to the namespace + * defined in the same position of the namespace attribute. There must be + * one entry in this attribute for each entry in the namespace attribute. + */ + public static final String CLASSINFO = "Classinfo"; + + /** + * RegisteredProfilesSupported (string, literal, multiple): + * RegisteredProfilesSupported defines the Profiles that this WBEM Server + * has support for. Each entry in this attribute MUST be in the form of + * Organization:Profile Name{:Subprofile Name}
      + *
      + * Examples:
      + *
      + * + * DMTF:CIM Server
      + * DMTF:CIM Server:Protocol Adapter
      + * DMTF:CIM Server:Provider Registration
      + *

      + * The Organization MUST be the CIM_RegisteredProfile.RegisteredOrganization + * property value. The Profile Name MUST be the + * CIM_RegisteredProfile.RegisteredName property value. The subprofile Name + * MUST be the CIM_RegisteredProfile.RegisteredName property value when it + * is used as a Dependent in the CIM_SubProfileRequiresProfile association + * for the specified Profile Name (used as the antecedent). + * + */ + public static final String REG_PROF_SUPP = "RegisteredProfilesSupported"; + + /** + * Gets the URL of the directory from which this advertisement was received + * + * @return The directory URL + */ + public abstract String getDirectory(); + + /** + * Returns the concrete service type. E.g. for the SLP advertised service + * service:wbem:https this method would return + * https. + * + * @return The concrete service type + */ + public abstract String getConcreteServiceType(); + + /** + * Returns the interop namespaces + * + * @return The interop namespaces + */ + public abstract String[] getInteropNamespaces(); + + /** + * Returns the service url, e.g. http://9.155.62.79:5988 + * + * @return The service url + */ + public abstract String getServiceUrl(); + + /** + * Return the attribute value for a given attribute name + * + * @param pAttributeName + * The attribute name + * @return The value + */ + public abstract String getAttribute(String pAttributeName); + + /** + * Return the set of attributes of this advertisement + * + * @return A Set<Map.Entry<String, String>> containing the name + * value pairs of the attributes. + */ + public abstract Set> getAttributes(); + + /** + * Returns the service id + * + * @return The service id + */ + public abstract String getServiceId(); + + /** + * Returns the expiration state of the advertisement. + * + * @return true when advertisement is expired. + */ + public abstract boolean isExpired(); + + /** + * Sets the expirations state of the advertisement. Might be used by the + * application to mark an advertisement as expired, e.g. when it's no longer + * reported by the corresponding directory. Used for this purpose by + * AdvertisementCatalog. + * + * @param pExpired + * The new value + */ + public abstract void setExpired(boolean pExpired); + + /** + * Creates a fully-initialized WBEMClient instance connected to the service + * that is subject of this advertisement. On every call to this method a new + * client will be created. The client is not stored or cached anywhere in + * this class. + * + * @param pSubject + * The credential for authenticating with the service + * @param pLocales + * An array of locales ordered by preference + * @return The WBEM client + * @throws Exception + * @pattern Factory Methods + */ + public abstract WBEMClient createClient(Subject pSubject, Locale[] pLocales) throws Exception; +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/discovery/package.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/discovery/package.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/discovery/package.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/discovery/package.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/bestpractise.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/bestpractise.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/bestpractise.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/bestpractise.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/configuration.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/configuration.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/configuration.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/configuration.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/development.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/development.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/development.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/development.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/discovery.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/discovery.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/discovery.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/discovery.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/embedded.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/embedded.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/embedded.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/embedded.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/firststeps.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/firststeps.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/firststeps.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/firststeps.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/history.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/history.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/history.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/history.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/indication_threading.png b/src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/indication_threading.png similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/indication_threading.png rename to src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/indication_threading.png diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/indications.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/indications.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/indications.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/indications.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/logging.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/logging.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/logging.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/logging.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/secure.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/secure.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/secure.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/secure.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/secure_indications.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/secure_indications.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/secure_indications.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/secure_indications.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/terminology.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/terminology.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/terminology.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/terminology.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/unittest.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/unittest.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/doc-files/unittest.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/doc-files/unittest.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/CIMElementSorter.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/CIMElementSorter.java similarity index 75% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/CIMElementSorter.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/CIMElementSorter.java index 8a2882d..ee9f515 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/CIMElementSorter.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/CIMElementSorter.java @@ -1,123 +1,116 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-10 ebak Make SBLIM client JSR48 compliant - * 1660756 2007-02-22 ebak Embedded object support - * 1737141 2007-06-18 ebak Sync up with JSR48 evolution - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Arrays; -import java.util.Comparator; - -import org.sentrysoftware.wbem.javax.cim.CIMElement; - -/** - * Class CIMElementSorter can sort CIMElement arrays and can do binary search by - * name in them. - */ -public class CIMElementSorter implements Comparator { - - private static final Comparator COMPARATOR = new CIMElementSorter(); - - /** - * Sorts the passed CIMElement array, the passed array is not copied. - * - * @param pArray - * the array which will be sorted if it's not null - * @return pArray - */ - public static CIMElement[] sort(CIMElement[] pArray) { - if (pArray == null || pArray.length == 0) return null; - synchronized (pArray) { - Arrays.sort(pArray /* , COMPARATOR */); - } - return pArray; - } - - /** - * Finds CIMElement, named pName, in pArray which must be a sorted array of - * CIMElements. - * - * @param pArray - * @param pName - * @return the CIMElement if found, otherwise null - */ - public static CIMElement find(CIMElement[] pArray, String pName) { - if (pArray == null) return null; - int idx; - synchronized (pArray) { - idx = Arrays.binarySearch(pArray, pName, COMPARATOR); - } - if (idx < 0) return null; - return pArray[idx]; - } - - /** - * Finds the index of CIMElement, named pName, in pArray which must be a - * sorted array of CIMElements. - * - * @param pArray - * @param pName - * @return the index, just like in case of Arrays.binarySearch() - * @see java.util.Arrays#binarySearch(Object[], Object, Comparator) - */ - public static int findIdx(CIMElement[] pArray, String pName) { - if (pArray == null) return -1; - synchronized (pArray) { - return Arrays.binarySearch(pArray, pName, COMPARATOR); - } - } - - /** - * @see java.util.Comparator#compare(Object, Object) - */ - public int compare(Object pObj0, Object pObj1) { - // ebak: handling null objects - if (pObj0 == null) return pObj1 == null ? 0 : 1; - if (pObj1 == null) return -1; - String name0 = pObj0 instanceof CIMElement ? ((CIMElement) pObj0).getName() - : (String) pObj0; - String name1 = pObj1 instanceof CIMElement ? ((CIMElement) pObj1).getName() - : (String) pObj1; - return name0.compareToIgnoreCase(name1); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-10 ebak Make SBLIM client JSR48 compliant + * 1660756 2007-02-22 ebak Embedded object support + * 1737141 2007-06-18 ebak Sync up with JSR48 evolution + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Arrays; +import java.util.Comparator; +import org.metricshub.wbem.javax.cim.CIMElement; + +/** + * Class CIMElementSorter can sort CIMElement arrays and can do binary search by + * name in them. + */ +public class CIMElementSorter implements Comparator { + private static final Comparator COMPARATOR = new CIMElementSorter(); + + /** + * Sorts the passed CIMElement array, the passed array is not copied. + * + * @param pArray + * the array which will be sorted if it's not null + * @return pArray + */ + public static CIMElement[] sort(CIMElement[] pArray) { + if (pArray == null || pArray.length == 0) return null; + synchronized (pArray) { + Arrays.sort(pArray/* , COMPARATOR */); + } + return pArray; + } + + /** + * Finds CIMElement, named pName, in pArray which must be a sorted array of + * CIMElements. + * + * @param pArray + * @param pName + * @return the CIMElement if found, otherwise null + */ + public static CIMElement find(CIMElement[] pArray, String pName) { + if (pArray == null) return null; + int idx; + synchronized (pArray) { + idx = Arrays.binarySearch(pArray, pName, COMPARATOR); + } + if (idx < 0) return null; + return pArray[idx]; + } + + /** + * Finds the index of CIMElement, named pName, in pArray which must be a + * sorted array of CIMElements. + * + * @param pArray + * @param pName + * @return the index, just like in case of Arrays.binarySearch() + * @see java.util.Arrays#binarySearch(Object[], Object, Comparator) + */ + public static int findIdx(CIMElement[] pArray, String pName) { + if (pArray == null) return -1; + synchronized (pArray) { + return Arrays.binarySearch(pArray, pName, COMPARATOR); + } + } + + /** + * @see java.util.Comparator#compare(Object, Object) + */ + public int compare(Object pObj0, Object pObj1) { + // ebak: handling null objects + if (pObj0 == null) return pObj1 == null ? 0 : 1; + if (pObj1 == null) return -1; + String name0 = pObj0 instanceof CIMElement ? ((CIMElement) pObj0).getName() : (String) pObj0; + String name1 = pObj1 instanceof CIMElement ? ((CIMElement) pObj1).getName() : (String) pObj1; + return name0.compareToIgnoreCase(name1); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/CIMHelper.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/CIMHelper.java similarity index 70% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/CIMHelper.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/CIMHelper.java index 1ce9442..5d0af54 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/CIMHelper.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/CIMHelper.java @@ -1,349 +1,370 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1565892 2006-12-06 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2964463 2010-03-08 blaschke-oss WBEMClient.initialize() throws wrong exception - * 2942520 2010-03-08 blaschke-oss IPv6 link local address with scope_id including a dot not supported - * 3513353 2012-03-30 blaschke-oss TCK: CIMDataType arrays must have length >= 1 - * 3513349 2012-03-31 blaschke-oss TCK: CIMDataType must not accept null string - * 3598613 2013-01-11 blaschke-oss different data type in cim instance and cim object path - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.math.BigInteger; -import java.net.URI; -import java.net.URISyntaxException; - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMInstance; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import org.sentrysoftware.wbem.javax.cim.CIMProperty; -import org.sentrysoftware.wbem.javax.cim.UnsignedInteger16; -import org.sentrysoftware.wbem.javax.cim.UnsignedInteger32; -import org.sentrysoftware.wbem.javax.cim.UnsignedInteger64; -import org.sentrysoftware.wbem.javax.cim.UnsignedInteger8; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConstants; - -/** - * Class CIMHelper provides convenience methods that are missing from the - * official JSR48 API - * - */ -public abstract class CIMHelper { - - private CIMHelper() { - // no instances - } - - /** - * Creates a URI of a CIMOM from a given CIM object path, adding default - * port if port not parsable. - * - * @param pPath - * The CIM object path. - * @return The URI. - * @throws URISyntaxException - */ - public static URI createCimomUri(CIMObjectPath pPath) throws URISyntaxException { - String scheme = pPath.getScheme(); - String host = pPath.getHost(); - int port = WBEMConstants.DEFAULT_WBEM_PORT; - try { - port = Integer.parseInt(pPath.getPort()); - } catch (NumberFormatException e) { - // stuck with default port - } - return new URI(scheme, null, host, port, WBEMConstants.CIMOM_PATH, null, null); - } - - /** - * Creates a URI of a CIMOM from a given URI, adding default port if port - * not specified. - * - * @param pUri - * The URI. - * @return The URI. - * @throws URISyntaxException - */ - public static URI createCimomUri(URI pUri) throws URISyntaxException { - String scheme = pUri.getScheme(); - String host = pUri.getHost(); - int port = pUri.getPort(); - if (port == -1) { - // stuck with default port - port = WBEMConstants.DEFAULT_WBEM_PORT; - } - return new URI(scheme, null, host, port, WBEMConstants.CIMOM_PATH, null, null); - } - - private static CIMDataType CIMScalarDataTypes[] = { - /* 00 */CIMDataType.UINT8_T, - /* 01 */CIMDataType.SINT8_T, - /* 02 */CIMDataType.UINT16_T, - /* 03 */CIMDataType.SINT16_T, - /* 04 */CIMDataType.UINT32_T, - /* 05 */CIMDataType.SINT32_T, - /* 06 */CIMDataType.UINT64_T, - /* 07 */CIMDataType.SINT64_T, - /* 08 */CIMDataType.STRING_T, - /* 09 */CIMDataType.BOOLEAN_T, - /* 10 */CIMDataType.REAL32_T, - /* 11 */CIMDataType.REAL64_T, - /* 12 */CIMDataType.DATETIME_T, - /* 13 */CIMDataType.CHAR16_T, - /* 14 */new CIMDataType(""), - /* 15 */CIMDataType.OBJECT_T, - /* 16 */null, - /* 17 */CIMDataType.CLASS_T }; - - /** - * Returns the CIMDataType of a scalar of the specified data type. This - * should be used in lieu of "new CIMDataType(pType)" which is not supported - * by the JSR48 standard. - * - * @param pType - * Data type. - * @return CIMDataType corresponding to data type. - */ - public static CIMDataType ScalarDataType(int pType) { - if (pType < 0 || pType >= CIMScalarDataTypes.length) return null; - return CIMScalarDataTypes[pType]; - } - - private static CIMDataType CIMArrayDataTypes[] = { - /* 00 */CIMDataType.UINT8_ARRAY_T, - /* 01 */CIMDataType.SINT8_ARRAY_T, - /* 02 */CIMDataType.UINT16_ARRAY_T, - /* 03 */CIMDataType.SINT16_ARRAY_T, - /* 04 */CIMDataType.UINT32_ARRAY_T, - /* 05 */CIMDataType.SINT32_ARRAY_T, - /* 06 */CIMDataType.UINT64_ARRAY_T, - /* 07 */CIMDataType.SINT64_ARRAY_T, - /* 08 */CIMDataType.STRING_ARRAY_T, - /* 09 */CIMDataType.BOOLEAN_ARRAY_T, - /* 10 */CIMDataType.REAL32_ARRAY_T, - /* 11 */CIMDataType.REAL64_ARRAY_T, - /* 12 */CIMDataType.DATETIME_ARRAY_T, - /* 13 */CIMDataType.CHAR16_ARRAY_T, - /* 14 */new CIMDataType("", 0), - /* 15 */CIMDataType.OBJECT_ARRAY_T, - /* 16 */null, - /* 17 */CIMDataType.CLASS_ARRAY_T }; - - /** - * Returns the CIMDataType of an unbounded array of the specified data type. - * This should be used in lieu of "new CIMDataType(pType,0)" which is not - * supported by the JSR48 standard. - * - * @param pType - * Data type. - * @return CIMDataType corresponding to data type. - */ - public static CIMDataType UnboundedArrayDataType(int pType) { - if (pType < 0 || pType >= CIMArrayDataTypes.length) return null; - return CIMArrayDataTypes[pType]; - } - - /** - * CIMInstanceWithSynchonizedNumericKeyDataTypes returns a - * CIMInstance where the data types of all numeric keys in the - * CIMObjectPath match those of the corresponding keys within - * the CIMProperty[]. - * - * The need for this conversion mechanism arises from a deficiency in the - * CIM-XML specs, where the TYPE (sint8, uint8, etc.) is required for - * PROPERTY but not for KEYVALUE. If a CIMOM sends a KEYVALUE of - * VALUETYPE="numeric" without TYPE, the Java CIM Client assumes a type of - * sint64, uint64 or real64. This can cause problems (i.e. - * ClassCastException) down the line if the TYPE of the corresponding - * PROPERTY is different. - * - * @param pObjectPath - * Instance object path. - * @param pProps - * Instance properties. - * @return CIMInstance with numeric key data types synchronized. - */ - public static CIMInstance CIMInstanceWithSynchonizedNumericKeyDataTypes( - CIMObjectPath pObjectPath, CIMProperty[] pProps) { - CIMInstance inst = new CIMInstance(pObjectPath, pProps); - CIMProperty[] oldKeys = inst.getKeys(); - CIMProperty[] newKeys = new CIMProperty[oldKeys.length]; - boolean update = false; - - for (int i = 0; i < oldKeys.length; i++) { - CIMDataType oldType = oldKeys[i].getDataType(); - CIMProperty prop = inst.getProperty(oldKeys[i].getName()); - if (oldType != null && prop != null && prop.getDataType() != null - && !prop.getDataType().equals(oldType) && isNumericObject(oldType) - && isNumericObject(prop.getDataType())) { - update = true; - newKeys[i] = new CIMProperty(oldKeys[i].getName(), prop.getDataType(), - translateNumericObject(oldKeys[i].getValue(), oldType, prop.getDataType()), - oldKeys[i].isKey(), oldKeys[i].isPropagated(), oldKeys[i].getOriginClass()); - } else { - newKeys[i] = oldKeys[i]; - } - } - - return (update ? inst.deriveInstance(new CIMObjectPath(pObjectPath.getScheme(), pObjectPath - .getHost(), pObjectPath.getPort(), pObjectPath.getNamespace(), pObjectPath - .getObjectName(), newKeys)) : inst); - } - - private static boolean isNumericObject(CIMDataType type) { - switch (type.getType()) { - case CIMDataType.SINT8: - case CIMDataType.SINT16: - case CIMDataType.SINT32: - case CIMDataType.SINT64: - case CIMDataType.UINT8: - case CIMDataType.UINT16: - case CIMDataType.UINT32: - case CIMDataType.UINT64: - case CIMDataType.REAL32: - case CIMDataType.REAL64: - return true; - } - return false; - } - - private static Object translateNumericObject(Object oldValue, CIMDataType oldType, - CIMDataType newType) { - if (oldValue == null) return null; - - int from = oldType.getType(), to = newType.getType(); - long newInt = 0; - double newDec = 0; - Object o = null; - boolean useInt = true; - - switch (from) { - case CIMDataType.SINT8: - Byte b = (Byte) oldValue; - newInt = b.longValue(); - break; - case CIMDataType.SINT16: - Short s = (Short) oldValue; - newInt = s.longValue(); - break; - case CIMDataType.SINT32: - Integer i = (Integer) oldValue; - newInt = i.longValue(); - break; - case CIMDataType.SINT64: - Long l = (Long) oldValue; - newInt = l.longValue(); - break; - case CIMDataType.UINT8: - UnsignedInteger8 u8 = (UnsignedInteger8) oldValue; - newInt = u8.longValue(); - break; - case CIMDataType.UINT16: - UnsignedInteger16 u16 = (UnsignedInteger16) oldValue; - newInt = u16.longValue(); - break; - case CIMDataType.UINT32: - UnsignedInteger32 u32 = (UnsignedInteger32) oldValue; - newInt = u32.longValue(); - break; - case CIMDataType.UINT64: - UnsignedInteger64 u64 = (UnsignedInteger64) oldValue; - newInt = u64.longValue(); - break; - case CIMDataType.REAL32: - Float f = (Float) oldValue; - newDec = f.doubleValue(); - useInt = false; - break; - case CIMDataType.REAL64: - Double d = (Double) oldValue; - newDec = d.doubleValue(); - useInt = false; - break; - } - - switch (to) { - case CIMDataType.SINT8: - byte b = (byte) (useInt ? newInt : newDec); - o = new Byte(b); - break; - case CIMDataType.SINT16: - short s = (short) (useInt ? newInt : newDec); - o = new Short(s); - break; - case CIMDataType.SINT32: - int i = (int) (useInt ? newInt : newDec); - o = new Integer(i); - break; - case CIMDataType.SINT64: - long l = (long) (useInt ? newInt : newDec); - o = new Long(l); - break; - case CIMDataType.UINT8: - byte u8 = (byte) (useInt ? newInt : newDec); - o = new UnsignedInteger8(u8); - break; - case CIMDataType.UINT16: - short u16 = (short) (useInt ? newInt : newDec); - o = new UnsignedInteger16(u16); - break; - case CIMDataType.UINT32: - int u32 = (int) (useInt ? newInt : newDec); - o = new UnsignedInteger32(u32); - break; - case CIMDataType.UINT64: - long u64 = (long) (useInt ? newInt : newDec); - o = new UnsignedInteger64(BigInteger.valueOf(u64)); - break; - case CIMDataType.REAL32: - float f = (float) (useInt ? newInt : newDec); - o = new Float(f); - break; - case CIMDataType.REAL64: - double d = useInt ? (double) newInt : newDec; - o = new Double(d); - break; - } - - return o; - } -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1565892 2006-12-06 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2964463 2010-03-08 blaschke-oss WBEMClient.initialize() throws wrong exception + * 2942520 2010-03-08 blaschke-oss IPv6 link local address with scope_id including a dot not supported + * 3513353 2012-03-30 blaschke-oss TCK: CIMDataType arrays must have length >= 1 + * 3513349 2012-03-31 blaschke-oss TCK: CIMDataType must not accept null string + * 3598613 2013-01-11 blaschke-oss different data type in cim instance and cim object path + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.math.BigInteger; +import java.net.URI; +import java.net.URISyntaxException; +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMInstance; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.cim.CIMProperty; +import org.metricshub.wbem.javax.cim.UnsignedInteger16; +import org.metricshub.wbem.javax.cim.UnsignedInteger32; +import org.metricshub.wbem.javax.cim.UnsignedInteger64; +import org.metricshub.wbem.javax.cim.UnsignedInteger8; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConstants; + +/** + * Class CIMHelper provides convenience methods that are missing from the + * official JSR48 API + * + */ +public abstract class CIMHelper { + + private CIMHelper() { + // no instances + } + + /** + * Creates a URI of a CIMOM from a given CIM object path, adding default + * port if port not parsable. + * + * @param pPath + * The CIM object path. + * @return The URI. + * @throws URISyntaxException + */ + public static URI createCimomUri(CIMObjectPath pPath) throws URISyntaxException { + String scheme = pPath.getScheme(); + String host = pPath.getHost(); + int port = WBEMConstants.DEFAULT_WBEM_PORT; + try { + port = Integer.parseInt(pPath.getPort()); + } catch (NumberFormatException e) { + // stuck with default port + } + return new URI(scheme, null, host, port, WBEMConstants.CIMOM_PATH, null, null); + } + + /** + * Creates a URI of a CIMOM from a given URI, adding default port if port + * not specified. + * + * @param pUri + * The URI. + * @return The URI. + * @throws URISyntaxException + */ + public static URI createCimomUri(URI pUri) throws URISyntaxException { + String scheme = pUri.getScheme(); + String host = pUri.getHost(); + int port = pUri.getPort(); + if (port == -1) { + // stuck with default port + port = WBEMConstants.DEFAULT_WBEM_PORT; + } + return new URI(scheme, null, host, port, WBEMConstants.CIMOM_PATH, null, null); + } + + private static CIMDataType CIMScalarDataTypes[] = { + /* 00 */CIMDataType.UINT8_T, + /* 01 */CIMDataType.SINT8_T, + /* 02 */CIMDataType.UINT16_T, + /* 03 */CIMDataType.SINT16_T, + /* 04 */CIMDataType.UINT32_T, + /* 05 */CIMDataType.SINT32_T, + /* 06 */CIMDataType.UINT64_T, + /* 07 */CIMDataType.SINT64_T, + /* 08 */CIMDataType.STRING_T, + /* 09 */CIMDataType.BOOLEAN_T, + /* 10 */CIMDataType.REAL32_T, + /* 11 */CIMDataType.REAL64_T, + /* 12 */CIMDataType.DATETIME_T, + /* 13 */CIMDataType.CHAR16_T, + /* 14 */new CIMDataType(""), + /* 15 */CIMDataType.OBJECT_T, + /* 16 */null, + /* 17 */CIMDataType.CLASS_T + }; + + /** + * Returns the CIMDataType of a scalar of the specified data type. This + * should be used in lieu of "new CIMDataType(pType)" which is not supported + * by the JSR48 standard. + * + * @param pType + * Data type. + * @return CIMDataType corresponding to data type. + */ + public static CIMDataType ScalarDataType(int pType) { + if (pType < 0 || pType >= CIMScalarDataTypes.length) return null; + return CIMScalarDataTypes[pType]; + } + + private static CIMDataType CIMArrayDataTypes[] = { + /* 00 */CIMDataType.UINT8_ARRAY_T, + /* 01 */CIMDataType.SINT8_ARRAY_T, + /* 02 */CIMDataType.UINT16_ARRAY_T, + /* 03 */CIMDataType.SINT16_ARRAY_T, + /* 04 */CIMDataType.UINT32_ARRAY_T, + /* 05 */CIMDataType.SINT32_ARRAY_T, + /* 06 */CIMDataType.UINT64_ARRAY_T, + /* 07 */CIMDataType.SINT64_ARRAY_T, + /* 08 */CIMDataType.STRING_ARRAY_T, + /* 09 */CIMDataType.BOOLEAN_ARRAY_T, + /* 10 */CIMDataType.REAL32_ARRAY_T, + /* 11 */CIMDataType.REAL64_ARRAY_T, + /* 12 */CIMDataType.DATETIME_ARRAY_T, + /* 13 */CIMDataType.CHAR16_ARRAY_T, + /* 14 */new CIMDataType("", 0), + /* 15 */CIMDataType.OBJECT_ARRAY_T, + /* 16 */null, + /* 17 */CIMDataType.CLASS_ARRAY_T + }; + + /** + * Returns the CIMDataType of an unbounded array of the specified data type. + * This should be used in lieu of "new CIMDataType(pType,0)" which is not + * supported by the JSR48 standard. + * + * @param pType + * Data type. + * @return CIMDataType corresponding to data type. + */ + public static CIMDataType UnboundedArrayDataType(int pType) { + if (pType < 0 || pType >= CIMArrayDataTypes.length) return null; + return CIMArrayDataTypes[pType]; + } + + /** + * CIMInstanceWithSynchonizedNumericKeyDataTypes returns a + * CIMInstance where the data types of all numeric keys in the + * CIMObjectPath match those of the corresponding keys within + * the CIMProperty[]. + * + * The need for this conversion mechanism arises from a deficiency in the + * CIM-XML specs, where the TYPE (sint8, uint8, etc.) is required for + * PROPERTY but not for KEYVALUE. If a CIMOM sends a KEYVALUE of + * VALUETYPE="numeric" without TYPE, the Java CIM Client assumes a type of + * sint64, uint64 or real64. This can cause problems (i.e. + * ClassCastException) down the line if the TYPE of the corresponding + * PROPERTY is different. + * + * @param pObjectPath + * Instance object path. + * @param pProps + * Instance properties. + * @return CIMInstance with numeric key data types synchronized. + */ + public static CIMInstance CIMInstanceWithSynchonizedNumericKeyDataTypes( + CIMObjectPath pObjectPath, + CIMProperty[] pProps + ) { + CIMInstance inst = new CIMInstance(pObjectPath, pProps); + CIMProperty[] oldKeys = inst.getKeys(); + CIMProperty[] newKeys = new CIMProperty[oldKeys.length]; + boolean update = false; + + for (int i = 0; i < oldKeys.length; i++) { + CIMDataType oldType = oldKeys[i].getDataType(); + CIMProperty prop = inst.getProperty(oldKeys[i].getName()); + if ( + oldType != null && + prop != null && + prop.getDataType() != null && + !prop.getDataType().equals(oldType) && + isNumericObject(oldType) && + isNumericObject(prop.getDataType()) + ) { + update = true; + newKeys[i] = + new CIMProperty( + oldKeys[i].getName(), + prop.getDataType(), + translateNumericObject(oldKeys[i].getValue(), oldType, prop.getDataType()), + oldKeys[i].isKey(), + oldKeys[i].isPropagated(), + oldKeys[i].getOriginClass() + ); + } else { + newKeys[i] = oldKeys[i]; + } + } + + return ( + update + ? inst.deriveInstance( + new CIMObjectPath( + pObjectPath.getScheme(), + pObjectPath.getHost(), + pObjectPath.getPort(), + pObjectPath.getNamespace(), + pObjectPath.getObjectName(), + newKeys + ) + ) + : inst + ); + } + + private static boolean isNumericObject(CIMDataType type) { + switch (type.getType()) { + case CIMDataType.SINT8: + case CIMDataType.SINT16: + case CIMDataType.SINT32: + case CIMDataType.SINT64: + case CIMDataType.UINT8: + case CIMDataType.UINT16: + case CIMDataType.UINT32: + case CIMDataType.UINT64: + case CIMDataType.REAL32: + case CIMDataType.REAL64: + return true; + } + return false; + } + + private static Object translateNumericObject(Object oldValue, CIMDataType oldType, CIMDataType newType) { + if (oldValue == null) return null; + + int from = oldType.getType(), to = newType.getType(); + long newInt = 0; + double newDec = 0; + Object o = null; + boolean useInt = true; + + switch (from) { + case CIMDataType.SINT8: + Byte b = (Byte) oldValue; + newInt = b.longValue(); + break; + case CIMDataType.SINT16: + Short s = (Short) oldValue; + newInt = s.longValue(); + break; + case CIMDataType.SINT32: + Integer i = (Integer) oldValue; + newInt = i.longValue(); + break; + case CIMDataType.SINT64: + Long l = (Long) oldValue; + newInt = l.longValue(); + break; + case CIMDataType.UINT8: + UnsignedInteger8 u8 = (UnsignedInteger8) oldValue; + newInt = u8.longValue(); + break; + case CIMDataType.UINT16: + UnsignedInteger16 u16 = (UnsignedInteger16) oldValue; + newInt = u16.longValue(); + break; + case CIMDataType.UINT32: + UnsignedInteger32 u32 = (UnsignedInteger32) oldValue; + newInt = u32.longValue(); + break; + case CIMDataType.UINT64: + UnsignedInteger64 u64 = (UnsignedInteger64) oldValue; + newInt = u64.longValue(); + break; + case CIMDataType.REAL32: + Float f = (Float) oldValue; + newDec = f.doubleValue(); + useInt = false; + break; + case CIMDataType.REAL64: + Double d = (Double) oldValue; + newDec = d.doubleValue(); + useInt = false; + break; + } + + switch (to) { + case CIMDataType.SINT8: + byte b = (byte) (useInt ? newInt : newDec); + o = new Byte(b); + break; + case CIMDataType.SINT16: + short s = (short) (useInt ? newInt : newDec); + o = new Short(s); + break; + case CIMDataType.SINT32: + int i = (int) (useInt ? newInt : newDec); + o = new Integer(i); + break; + case CIMDataType.SINT64: + long l = (long) (useInt ? newInt : newDec); + o = new Long(l); + break; + case CIMDataType.UINT8: + byte u8 = (byte) (useInt ? newInt : newDec); + o = new UnsignedInteger8(u8); + break; + case CIMDataType.UINT16: + short u16 = (short) (useInt ? newInt : newDec); + o = new UnsignedInteger16(u16); + break; + case CIMDataType.UINT32: + int u32 = (int) (useInt ? newInt : newDec); + o = new UnsignedInteger32(u32); + break; + case CIMDataType.UINT64: + long u64 = (long) (useInt ? newInt : newDec); + o = new UnsignedInteger64(BigInteger.valueOf(u64)); + break; + case CIMDataType.REAL32: + float f = (float) (useInt ? newInt : newDec); + o = new Float(f); + break; + case CIMDataType.REAL64: + double d = useInt ? (double) newInt : newDec; + o = new Double(d); + break; + } + + return o; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/CIMInstanceBuilder.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/CIMInstanceBuilder.java similarity index 76% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/CIMInstanceBuilder.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/CIMInstanceBuilder.java index 5885655..9cf6c06 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/CIMInstanceBuilder.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/CIMInstanceBuilder.java @@ -1,156 +1,161 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-11-30 ebak Make SBLIM client JSR48 compliant - * 1669961 2006-04-16 lupusalex CIMTypedElement.getType() =>getDataType() - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; -import java.util.List; - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import org.sentrysoftware.wbem.javax.cim.CIMProperty; - -/** - * Class CIMInstanceBuilder provides help for CIMInstance(CIMObjectPath, - * CIMProperty[]) constructor.
      - *
      - * CIMObjectPath param has to contain the key properties only.
      - * ( VALUE.NAMEDINSTANCE->INSTANCENAME->KEYBINDING )
      - * CIMProperty[] param has to contain all properties, including key properties.
      - * ( VALUE.NAMEDINSTANCE->INSTANCE->PROPERTY* )
      - * The implementation merges the properties from both params.
      - * From CIMObjectPath's keys only the type and value information is considered.
      - * - */ -public class CIMInstanceBuilder { - - private CIMProperty[] iProperties; - - private static final Object[] EMPTY_RPOP_A = new CIMProperty[0]; - - /** - * Ctor. - * - * @param pPath - * @param pProps - * @throws IllegalArgumentException - */ - public CIMInstanceBuilder(CIMObjectPath pPath, CIMProperty[] pProps) - throws IllegalArgumentException { - this.iProperties = pProps != null ? pProps : new CIMProperty[0]; - CIMElementSorter.sort(this.iProperties); - addPathKeys(pPath); - } - - /** - * Extends the keys of the passed CIMObjectPath. - * - * @param pPath - * @return the new CIMObjectPath - */ - public CIMObjectPath setKeys(CIMObjectPath pPath) { - List> keys = new ArrayList>(); - for (int i = 0; i < this.iProperties.length; ++i) { - CIMProperty prop = this.iProperties[i]; - if (prop.isKey()) keys.add(prop); - } - - /* - * CIMObjectPath( String scheme, String host, String port, String - * namespace, String objectName, CIMProperty[] keys ) - */ - return new CIMObjectPath(pPath.getScheme(), pPath.getHost(), pPath.getPort(), pPath - .getNamespace(), pPath.getObjectName(), (CIMProperty[]) keys.toArray(EMPTY_RPOP_A)); - } - - /** - * getAllPropertis - * - * @return all properties in an ordered way - */ - public CIMProperty[] getAllPropertis() { - return this.iProperties; - } - - private void addPathKeys(CIMObjectPath pPath) throws IllegalArgumentException { - CIMProperty[] keys = pPath.getKeys(); - for (int i = 0; i < keys.length; i++) { - CIMProperty key = keys[i]; - int pos = CIMElementSorter.findIdx(this.iProperties, key.getName()); - if (pos < 0) { - pos = -pos - 1; - CIMProperty[] newArray = new CIMProperty[this.iProperties.length + 1]; - System.arraycopy(this.iProperties, 0, newArray, 0, pos); - newArray[pos] = key; - System.arraycopy(this.iProperties, pos, newArray, pos + 1, this.iProperties.length - - pos); - this.iProperties = newArray; - } else { - CIMProperty prop = this.iProperties[pos]; - // typeAndValueCheck(key, prop); - if (!prop.isKey()) this.iProperties[pos] = mkKey(prop); - } - } - } - - private static CIMProperty mkKey(CIMProperty pProp) { - return new CIMProperty(pProp.getName(), pProp.getDataType(), pProp.getValue(), - true, pProp.isPropagated(), pProp.getOriginClass()); - } - - /* - * private static void typeAndValueCheck(CIMProperty pPathProp, CIMProperty - * pArrayProp) throws IllegalArgumentException { CIMDataType pType = - * pPathProp.getDataType(), aType = pArrayProp.getDataType(); if (pType == - * null ? aType != null : pType.getType() != aType.getType()) throw new - * IllegalArgumentException( pPathProp.getName() + " property presents in - * CIMObjectPath param and CIMProperty[] param " + "with different types!"); - * Object pValue = pPathProp.getValue(), aValue = pArrayProp.getValue(); if - * (pValue == null ? aValue != null : !pValue.equals(aValue)) throw new - * IllegalArgumentException( pPathProp.getName() + " property conatins - * different values in CIMObjectPath and " + "CIMProperty params!"); } - */ - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-11-30 ebak Make SBLIM client JSR48 compliant + * 1669961 2006-04-16 lupusalex CIMTypedElement.getType() =>getDataType() + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import java.util.List; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.cim.CIMProperty; + +/** + * Class CIMInstanceBuilder provides help for CIMInstance(CIMObjectPath, + * CIMProperty[]) constructor.
      + *
      + * CIMObjectPath param has to contain the key properties only.
      + * ( VALUE.NAMEDINSTANCE->INSTANCENAME->KEYBINDING )
      + * CIMProperty[] param has to contain all properties, including key properties.
      + * ( VALUE.NAMEDINSTANCE->INSTANCE->PROPERTY* )
      + * The implementation merges the properties from both params.
      + * From CIMObjectPath's keys only the type and value information is considered.
      + * + */ +public class CIMInstanceBuilder { + private CIMProperty[] iProperties; + + private static final Object[] EMPTY_RPOP_A = new CIMProperty[0]; + + /** + * Ctor. + * + * @param pPath + * @param pProps + * @throws IllegalArgumentException + */ + public CIMInstanceBuilder(CIMObjectPath pPath, CIMProperty[] pProps) throws IllegalArgumentException { + this.iProperties = pProps != null ? pProps : new CIMProperty[0]; + CIMElementSorter.sort(this.iProperties); + addPathKeys(pPath); + } + + /** + * Extends the keys of the passed CIMObjectPath. + * + * @param pPath + * @return the new CIMObjectPath + */ + public CIMObjectPath setKeys(CIMObjectPath pPath) { + List> keys = new ArrayList>(); + for (int i = 0; i < this.iProperties.length; ++i) { + CIMProperty prop = this.iProperties[i]; + if (prop.isKey()) keys.add(prop); + } + + /* + * CIMObjectPath( String scheme, String host, String port, String + * namespace, String objectName, CIMProperty[] keys ) + */ + return new CIMObjectPath( + pPath.getScheme(), + pPath.getHost(), + pPath.getPort(), + pPath.getNamespace(), + pPath.getObjectName(), + (CIMProperty[]) keys.toArray(EMPTY_RPOP_A) + ); + } + + /** + * getAllPropertis + * + * @return all properties in an ordered way + */ + public CIMProperty[] getAllPropertis() { + return this.iProperties; + } + + private void addPathKeys(CIMObjectPath pPath) throws IllegalArgumentException { + CIMProperty[] keys = pPath.getKeys(); + for (int i = 0; i < keys.length; i++) { + CIMProperty key = keys[i]; + int pos = CIMElementSorter.findIdx(this.iProperties, key.getName()); + if (pos < 0) { + pos = -pos - 1; + CIMProperty[] newArray = new CIMProperty[this.iProperties.length + 1]; + System.arraycopy(this.iProperties, 0, newArray, 0, pos); + newArray[pos] = key; + System.arraycopy(this.iProperties, pos, newArray, pos + 1, this.iProperties.length - pos); + this.iProperties = newArray; + } else { + CIMProperty prop = this.iProperties[pos]; + // typeAndValueCheck(key, prop); + if (!prop.isKey()) this.iProperties[pos] = mkKey(prop); + } + } + } + + private static CIMProperty mkKey(CIMProperty pProp) { + return new CIMProperty( + pProp.getName(), + pProp.getDataType(), + pProp.getValue(), + true, + pProp.isPropagated(), + pProp.getOriginClass() + ); + } + /* + * private static void typeAndValueCheck(CIMProperty pPathProp, CIMProperty + * pArrayProp) throws IllegalArgumentException { CIMDataType pType = + * pPathProp.getDataType(), aType = pArrayProp.getDataType(); if (pType == + * null ? aType != null : pType.getType() != aType.getType()) throw new + * IllegalArgumentException( pPathProp.getName() + " property presents in + * CIMObjectPath param and CIMProperty[] param " + "with different types!"); + * Object pValue = pPathProp.getValue(), aValue = pArrayProp.getValue(); if + * (pValue == null ? aValue != null : !pValue.equals(aValue)) throw new + * IllegalArgumentException( pPathProp.getName() + " property conatins + * different values in CIMObjectPath and " + "CIMProperty params!"); } + */ + +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/CIMOctetString.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/CIMOctetString.java similarity index 78% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/CIMOctetString.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/CIMOctetString.java index 0cca4a0..9e8f891 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/CIMOctetString.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/CIMOctetString.java @@ -1,484 +1,483 @@ -/* - (C) Copyright IBM Corp. 2011 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Dave Blaschke, IBM, blaschke@us.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 3397922 2011-08-30 blaschke-oss support OctetString - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.UnsignedInteger8; - -/** - * This class represents a CIM octet string, or length-prefixed string, where - * the length is four octets (32 bits) AND includes the four octets it occupies. - * In other words, the length of the octet string is the number of characters in - * the string plus four. There are three possible representations:
      - *
      - * 1) Byte array - This is an array of UnsignedInteger8 (unit8) objects. The - * first four bytes contain the length, so the ASCII string "DEB" would be - * represented as { 0x00, 0x00, 0x00, 0x07, 0x44, 0x45, 0x42 }
      - *
      - * 2) Hexadecimal string - This is a string of hexadecimal digits. The four - * bytes after the initial "0x" contain the length, so the ASCII string "DEB" - * would be represented as "0x00000007444542".
      - *
      - * 3) ASCII string
      - *
      - * One of these representations is passed into a constructor. The other - * representations are created on demand when a get() method is invoked or when - * the equals() method is invoked and the two octet strings have no - * representations in common. - */ -public class CIMOctetString { - - private UnsignedInteger8 iBytes[]; - - private String iASCIIString; - - private char iReplacementChar; // 0xFF indicates ASCII constructor used - - private String iHexString; - - private int iLength; - - /** - * Constructs a CIMOctetString from the given byte array. - * - * @param pBytes - * Byte array representation of octet string. - * @throws IllegalArgumentException - */ - public CIMOctetString(UnsignedInteger8 pBytes[]) throws IllegalArgumentException { - // Minimum (empty) byte array is { 0x00 0x00 0x00 0x04 } - if (pBytes == null || pBytes.length < 4) throw new IllegalArgumentException( - "Array of bytes must contain at least four bytes"); - - // Verify there are no null entries in byte array - for (int i = pBytes.length - 1; i >= 0; i--) - if (pBytes[i] == null) throw new IllegalArgumentException( - "Array of bytes must not contain any null bytes"); - - // Calculate length - this.iLength = pBytes[3].byteValue() + (pBytes[2].byteValue() * 0x100) - + (pBytes[1].byteValue() * 0x10000) + (pBytes[0].byteValue() * 0x1000000); - - // Verify calculated length matches actual length - if (this.iLength != pBytes.length) throw new IllegalArgumentException( - "Array of bytes contains invalid length: found " + this.iLength + ", expected " - + pBytes.length); - - // Save byte array in new object - this.iBytes = new UnsignedInteger8[this.iLength]; - for (int i = this.iLength - 1; i >= 0; i--) - this.iBytes[i] = pBytes[i]; - } - - /** - * Constructs a CIMOctetString from the given string. - * - * @param pString - * String representation of octet string. - * @param pIsHex - * true if string is hexadecimal string, - * false if string is ASCII string. - * - * @throws IllegalArgumentException - */ - public CIMOctetString(String pString, boolean pIsHex) throws IllegalArgumentException { - if (pString == null) throw new IllegalArgumentException("String cannot be null"); - - if (pIsHex) { - // Minimum (empty) hexadecimal string is "0x00000004" - if (pString.length() < 10) throw new IllegalArgumentException( - "Hexadecimal string must contain \"0x\" and at least four pairs of hex digits"); - - // Verify hexadecimal string starts with "0x" - if (pString.charAt(0) != '0' || pString.charAt(1) != 'x') throw new IllegalArgumentException( - "Hexadecimal string must begin with \"0x\""); - - // Calculate length - try { - this.iLength = Integer.parseInt(pString.substring(2, 10), 16); - } catch (NumberFormatException e) { - throw new IllegalArgumentException( - "Hexadecimal string length could not be parsed: " + e.toString()); - } - - // Verify calculated length matches actual length - if ((this.iLength * 2) + 2 != pString.length()) throw new IllegalArgumentException( - "Hexadecimal string contains invalid length: found " + this.iLength - + ", expected " + ((pString.length() - 2 / 2))); - - // Verify remainder of hexadecimal string contains only hexadecimal - // digits - for (int i = pString.length() - 1; i >= 10; i--) { - char ch = pString.charAt(i); - if (!((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F'))) throw new IllegalArgumentException( - "Hexadecimal string could not be parsed, invalid character \'" + ch - + "\' at index " + i); - } - - // Save hexadecimal string in new object - this.iHexString = new String(pString); - } else { - // Calculate length - this.iLength = pString.length() + 4; - - // Save ASCII string in new object and indicate constructor used - this.iASCIIString = new String(pString); - this.iReplacementChar = 0xFF; - } - } - - /** - * Takes a CIM octet string and returns true if it is equal to - * this CIM octet string. Otherwise, it returns false. Two - * octet strings are considered equal if all of their common representations - * are equal. If the octet strings have no representations in common, this - * method will build the missing one, starting with byte array and then - * hexadecmial string. - * - * NOTE: The ASCII string representation is only considered if both octet - * strings were constructed with an ASCII string. - * - * @param pObj - * The object to be compared a CIM element. - * @return true if the specified CIM octet string equals this - * CIM octet string, false otherwise. - */ - @Override - public synchronized boolean equals(Object pObj) { - // Verify parameter is CIMOctetString instance - if (!(pObj instanceof CIMOctetString)) return false; - - CIMOctetString that = (CIMOctetString) pObj; - int numCompares = 0; - - // Verify lengths are same - if (this.iLength != that.iLength) return false; - - // Verify byte arrays match if both non-null - if (this.iBytes != null && that.iBytes != null) { - for (int i = this.iLength - 1; i >= 0; i--) - if (this.iBytes[i].byteValue() != that.iBytes[i].byteValue()) return false; - numCompares++; - } - - // Verify hexadecimal strings match if both non-null - if (this.iHexString != null && that.iHexString != null) { - if (!this.iHexString.equalsIgnoreCase(that.iHexString)) return false; - numCompares++; - } - - // Verify ASCII strings match if both non-null - if (this.iASCIIString != null && that.iASCIIString != null - && this.iReplacementChar == that.iReplacementChar) { - if (!this.iASCIIString.equalsIgnoreCase(that.iASCIIString)) return false; - numCompares++; - } - - // Octet strings equal if at least one representation equal - if (numCompares > 0) return true; - - // At this point, the two CIMOctetString instances have no - // representations in common - time to make one - - if (this.iBytes != null && that.iBytes == null) { - that.getBytes(); - if (this.iBytes != null && that.iBytes != null) { - for (int i = this.iLength - 1; i >= 0; i--) - if (this.iBytes[i].byteValue() != that.iBytes[i].byteValue()) return false; - numCompares++; - } - } - - // Octet strings equal if byte arrays equal - if (numCompares > 0) return true; - - if (this.iBytes == null && that.iBytes != null) { - getBytes(); - if (this.iBytes != null && that.iBytes != null) { - for (int i = this.iLength - 1; i >= 0; i--) - if (this.iBytes[i].byteValue() != that.iBytes[i].byteValue()) return false; - numCompares++; - } - } - - // Octet strings equal if byte arrays equal - if (numCompares > 0) return true; - - if (this.iHexString != null && that.iHexString == null) { - that.getHexString(); - if (this.iHexString != null && that.iHexString != null) { - if (!this.iHexString.equalsIgnoreCase(that.iHexString)) return false; - numCompares++; - } - } - - // Octet strings equal if byte arrays equal - if (numCompares > 0) return true; - - if (this.iHexString == null && that.iHexString != null) { - getHexString(); - if (this.iHexString != null && that.iHexString != null) { - if (!this.iHexString.equalsIgnoreCase(that.iHexString)) return false; - numCompares++; - } - } - - // Octet strings equal if byte arrays equal - if (numCompares > 0) return true; - - return false; - } - - /** - * Returns ASCII string representation of octet string with non-printable - * characters replaced by pReplacementChar. If the ASCII string - * has not yet been created, it is created from the byte array or - * hexadecimal string. - * - * @param pReplacementChar - * Replacement character for non-printable characters which must - * be between 0x20 and 0x7E, inclusive. - * @return ASCII string representation of octet string. - */ - public synchronized String getASCIIString(char pReplacementChar) { - // If ASCII string constructor used, return original string - if (this.iASCIIString != null && this.iReplacementChar == 0xFF) return this.iASCIIString; - - // Verify replacement character is printable - if (pReplacementChar <= 0x1F || pReplacementChar >= 0x7F) throw new IllegalArgumentException( - "Replacement character not printable"); - - // If we already did this once, return previous string - if (this.iASCIIString != null && this.iReplacementChar == pReplacementChar) return this.iASCIIString; - - // Construct new ASCII string - StringBuilder str = new StringBuilder(""); - if (this.iBytes != null) { - for (int i = 4; i < this.iBytes.length; i++) { - char ch = (char) this.iBytes[i].byteValue(); - if (ch <= 0x1F || ch >= 0x7F) str.append(pReplacementChar); - else str.append(ch); - } - } else /* (this.iHexString != null) */{ - for (int i = 10; i < this.iHexString.length(); i += 2) { - char ch = (char) Integer.parseInt(this.iHexString.substring(i, i + 2), 16); - if (ch <= 0x1F || ch >= 0x7F) str.append(pReplacementChar); - else str.append(ch); - } - } - - // Save ASCII string in new object and indicate which replacement - // character used - this.iASCIIString = new String(str); - this.iReplacementChar = pReplacementChar; - - return this.iASCIIString; - } - - /** - * Returns byte array representation of octet string. If the byte array has - * not yet been created, it is created from the hexadecimal string or ASCII - * string. - * - * @return Byte array representation of octet string. - */ - public synchronized UnsignedInteger8[] getBytes() { - if (this.iBytes != null) return this.iBytes; - - if (this.iHexString != null) { - convertHexStringToBytes(); - } else /* if (this.iASCIIString != null) */{ - convertASCIIStringToBytes(); - } - - return this.iBytes; - } - - /** - * Returns hexadecimal string representation of octet string. If the - * hexadecimal string has not yet been created, it is created from the byte - * array or ASCII string. - * - * @return Hexadecimal string representation of octet string. - */ - public synchronized String getHexString() { - if (this.iHexString != null) return this.iHexString; - - if (this.iBytes != null) { - convertBytesToHexString(); - } else /* if (this.iASCIIString != null) */{ - convertASCIIStringToHexString(); - } - - return this.iHexString; - } - - /** - * Returns hash code value for octet string. - * - * @return Hash code value for octet string. - */ - @Override - public int hashCode() { - return toString().toLowerCase().hashCode(); - } - - /** - * Returns length of octet string, where length is number of octets plus - * four. - * - * @return Length of octet string. - */ - public int length() { - return this.iLength; - } - - /** - * Returns string representation of octet string. - * - * @return String representation of octet string. - */ - @Override - public String toString() { - return getHexString(); - } - - private void convertBytesToHexString() { - // Start with "0x" - StringBuilder str = new StringBuilder("0x"); - - // Append length - String len = Integer.toHexString(this.iLength); - for (int i = 8 - len.length(); i > 0; i--) - str.append('0'); - str.append(len); - - // Append string - for (int i = 4; i < this.iLength; i++) { - String octet = Integer.toHexString(this.iBytes[i].intValue()); - if (octet.length() == 1) str.append('0'); - str.append(octet); - } - - // Save hexadecimal string in new object - this.iHexString = new String(str); - - // debug("convertBytesToHexString: from {" + toBytesString() + "} to \"" - // + this.iHexString + "\""); - } - - private void convertHexStringToBytes() { - // Save byte array in new object - this.iBytes = new UnsignedInteger8[this.iLength]; - - // Convert each octet in hexadecimal string to byte - for (int idxByte = 0, idxStr = 2, len = this.iHexString.length(); idxStr < len; idxByte++, idxStr += 2) { - short s; - try { - s = Short.parseShort(this.iHexString.substring(idxStr, idxStr + 2), 16); - } catch (NumberFormatException e) { - throw new IllegalArgumentException("Hex string length could not be parsed: " - + e.toString()); - } - this.iBytes[idxByte] = new UnsignedInteger8(s); - } - - // debug("convertHexStringToBytes: from \"" + this.iHexString + - // "\" to {" + toBytesString() + "}"); - } - - private void convertASCIIStringToBytes() { - // Save byte array in new object - this.iBytes = new UnsignedInteger8[this.iLength]; - - // Convert length - this.iBytes[0] = new UnsignedInteger8((short) ((this.iLength >> 24) & 0xFF)); - this.iBytes[1] = new UnsignedInteger8((short) ((this.iLength >> 16) & 0xFF)); - this.iBytes[2] = new UnsignedInteger8((short) ((this.iLength >> 8) & 0xFF)); - this.iBytes[3] = new UnsignedInteger8((short) (this.iLength & 0xFF)); - - // Convert each character in ASCII string to byte - for (int idxStr = 0, idxByte = 4; idxStr < this.iASCIIString.length(); idxStr++, idxByte++) - this.iBytes[idxByte] = new UnsignedInteger8((short) (this.iASCIIString.charAt(idxStr))); - - // debug("convertASCIIStringToBytes: from \"" + this.iASCIIString + - // "\" to {" + toBytesString() + "}"); - } - - private void convertASCIIStringToHexString() { - // Start with "0x" - StringBuilder str = new StringBuilder("0x"); - - // Append length - String len = Integer.toHexString(this.iLength); - for (int i = 8 - len.length(); i > 0; i--) - str.append('0'); - str.append(len); - - // Append string - for (int idxAsc = 0, idxHex = 10; idxAsc < this.iASCIIString.length(); idxAsc++, idxHex++) { - String octet = Integer.toHexString((this.iASCIIString.charAt(idxAsc))); - if (octet.length() == 1) str.append('0'); - str.append(octet); - } - - // Save hexadecimal string in new object - this.iHexString = new String(str); - - // debug("convertASCIIStringToHexString: from \"" + this.iASCIIString + - // "\" to \"" + this.iHexString + "\""); - } - - // private String toBytesString() { - // StringBuilder str = new StringBuilder(); - // - // for (int i = 0; i < this.iLength; i++) { - // String octet = Integer.toHexString((this.iBytes[i].intValue())); - // if (i > 0) str.append(' '); - // if (octet.length() == 1) str.append('0'); - // str.append(octet); - // } - // return new String(str); - // } - - // private void debug(String str) { - // System.out.println(str); - // } -} +/* + (C) Copyright IBM Corp. 2011 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Dave Blaschke, IBM, blaschke@us.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 3397922 2011-08-30 blaschke-oss support OctetString + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.UnsignedInteger8; + +/** + * This class represents a CIM octet string, or length-prefixed string, where + * the length is four octets (32 bits) AND includes the four octets it occupies. + * In other words, the length of the octet string is the number of characters in + * the string plus four. There are three possible representations:
      + *
      + * 1) Byte array - This is an array of UnsignedInteger8 (unit8) objects. The + * first four bytes contain the length, so the ASCII string "DEB" would be + * represented as { 0x00, 0x00, 0x00, 0x07, 0x44, 0x45, 0x42 }
      + *
      + * 2) Hexadecimal string - This is a string of hexadecimal digits. The four + * bytes after the initial "0x" contain the length, so the ASCII string "DEB" + * would be represented as "0x00000007444542".
      + *
      + * 3) ASCII string
      + *
      + * One of these representations is passed into a constructor. The other + * representations are created on demand when a get() method is invoked or when + * the equals() method is invoked and the two octet strings have no + * representations in common. + */ +public class CIMOctetString { + private UnsignedInteger8 iBytes[]; + + private String iASCIIString; + + private char iReplacementChar; // 0xFF indicates ASCII constructor used + + private String iHexString; + + private int iLength; + + /** + * Constructs a CIMOctetString from the given byte array. + * + * @param pBytes + * Byte array representation of octet string. + * @throws IllegalArgumentException + */ + public CIMOctetString(UnsignedInteger8 pBytes[]) throws IllegalArgumentException { + // Minimum (empty) byte array is { 0x00 0x00 0x00 0x04 } + if (pBytes == null || pBytes.length < 4) throw new IllegalArgumentException( + "Array of bytes must contain at least four bytes" + ); + + // Verify there are no null entries in byte array + for (int i = pBytes.length - 1; i >= 0; i--) if (pBytes[i] == null) throw new IllegalArgumentException( + "Array of bytes must not contain any null bytes" + ); + + // Calculate length + this.iLength = + pBytes[3].byteValue() + + (pBytes[2].byteValue() * 0x100) + + (pBytes[1].byteValue() * 0x10000) + + (pBytes[0].byteValue() * 0x1000000); + + // Verify calculated length matches actual length + if (this.iLength != pBytes.length) throw new IllegalArgumentException( + "Array of bytes contains invalid length: found " + this.iLength + ", expected " + pBytes.length + ); + + // Save byte array in new object + this.iBytes = new UnsignedInteger8[this.iLength]; + for (int i = this.iLength - 1; i >= 0; i--) this.iBytes[i] = pBytes[i]; + } + + /** + * Constructs a CIMOctetString from the given string. + * + * @param pString + * String representation of octet string. + * @param pIsHex + * true if string is hexadecimal string, + * false if string is ASCII string. + * + * @throws IllegalArgumentException + */ + public CIMOctetString(String pString, boolean pIsHex) throws IllegalArgumentException { + if (pString == null) throw new IllegalArgumentException("String cannot be null"); + + if (pIsHex) { + // Minimum (empty) hexadecimal string is "0x00000004" + if (pString.length() < 10) throw new IllegalArgumentException( + "Hexadecimal string must contain \"0x\" and at least four pairs of hex digits" + ); + + // Verify hexadecimal string starts with "0x" + if (pString.charAt(0) != '0' || pString.charAt(1) != 'x') throw new IllegalArgumentException( + "Hexadecimal string must begin with \"0x\"" + ); + + // Calculate length + try { + this.iLength = Integer.parseInt(pString.substring(2, 10), 16); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Hexadecimal string length could not be parsed: " + e.toString()); + } + + // Verify calculated length matches actual length + if ((this.iLength * 2) + 2 != pString.length()) throw new IllegalArgumentException( + "Hexadecimal string contains invalid length: found " + + this.iLength + + ", expected " + + ((pString.length() - 2 / 2)) + ); + + // Verify remainder of hexadecimal string contains only hexadecimal + // digits + for (int i = pString.length() - 1; i >= 10; i--) { + char ch = pString.charAt(i); + if ( + !((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F')) + ) throw new IllegalArgumentException( + "Hexadecimal string could not be parsed, invalid character \'" + ch + "\' at index " + i + ); + } + + // Save hexadecimal string in new object + this.iHexString = new String(pString); + } else { + // Calculate length + this.iLength = pString.length() + 4; + + // Save ASCII string in new object and indicate constructor used + this.iASCIIString = new String(pString); + this.iReplacementChar = 0xFF; + } + } + + /** + * Takes a CIM octet string and returns true if it is equal to + * this CIM octet string. Otherwise, it returns false. Two + * octet strings are considered equal if all of their common representations + * are equal. If the octet strings have no representations in common, this + * method will build the missing one, starting with byte array and then + * hexadecmial string. + * + * NOTE: The ASCII string representation is only considered if both octet + * strings were constructed with an ASCII string. + * + * @param pObj + * The object to be compared a CIM element. + * @return true if the specified CIM octet string equals this + * CIM octet string, false otherwise. + */ + @Override + public synchronized boolean equals(Object pObj) { + // Verify parameter is CIMOctetString instance + if (!(pObj instanceof CIMOctetString)) return false; + + CIMOctetString that = (CIMOctetString) pObj; + int numCompares = 0; + + // Verify lengths are same + if (this.iLength != that.iLength) return false; + + // Verify byte arrays match if both non-null + if (this.iBytes != null && that.iBytes != null) { + for (int i = this.iLength - 1; i >= 0; i--) if ( + this.iBytes[i].byteValue() != that.iBytes[i].byteValue() + ) return false; + numCompares++; + } + + // Verify hexadecimal strings match if both non-null + if (this.iHexString != null && that.iHexString != null) { + if (!this.iHexString.equalsIgnoreCase(that.iHexString)) return false; + numCompares++; + } + + // Verify ASCII strings match if both non-null + if (this.iASCIIString != null && that.iASCIIString != null && this.iReplacementChar == that.iReplacementChar) { + if (!this.iASCIIString.equalsIgnoreCase(that.iASCIIString)) return false; + numCompares++; + } + + // Octet strings equal if at least one representation equal + if (numCompares > 0) return true; + + // At this point, the two CIMOctetString instances have no + // representations in common - time to make one + + if (this.iBytes != null && that.iBytes == null) { + that.getBytes(); + if (this.iBytes != null && that.iBytes != null) { + for (int i = this.iLength - 1; i >= 0; i--) if ( + this.iBytes[i].byteValue() != that.iBytes[i].byteValue() + ) return false; + numCompares++; + } + } + + // Octet strings equal if byte arrays equal + if (numCompares > 0) return true; + + if (this.iBytes == null && that.iBytes != null) { + getBytes(); + if (this.iBytes != null && that.iBytes != null) { + for (int i = this.iLength - 1; i >= 0; i--) if ( + this.iBytes[i].byteValue() != that.iBytes[i].byteValue() + ) return false; + numCompares++; + } + } + + // Octet strings equal if byte arrays equal + if (numCompares > 0) return true; + + if (this.iHexString != null && that.iHexString == null) { + that.getHexString(); + if (this.iHexString != null && that.iHexString != null) { + if (!this.iHexString.equalsIgnoreCase(that.iHexString)) return false; + numCompares++; + } + } + + // Octet strings equal if byte arrays equal + if (numCompares > 0) return true; + + if (this.iHexString == null && that.iHexString != null) { + getHexString(); + if (this.iHexString != null && that.iHexString != null) { + if (!this.iHexString.equalsIgnoreCase(that.iHexString)) return false; + numCompares++; + } + } + + // Octet strings equal if byte arrays equal + if (numCompares > 0) return true; + + return false; + } + + /** + * Returns ASCII string representation of octet string with non-printable + * characters replaced by pReplacementChar. If the ASCII string + * has not yet been created, it is created from the byte array or + * hexadecimal string. + * + * @param pReplacementChar + * Replacement character for non-printable characters which must + * be between 0x20 and 0x7E, inclusive. + * @return ASCII string representation of octet string. + */ + public synchronized String getASCIIString(char pReplacementChar) { + // If ASCII string constructor used, return original string + if (this.iASCIIString != null && this.iReplacementChar == 0xFF) return this.iASCIIString; + + // Verify replacement character is printable + if (pReplacementChar <= 0x1F || pReplacementChar >= 0x7F) throw new IllegalArgumentException( + "Replacement character not printable" + ); + + // If we already did this once, return previous string + if (this.iASCIIString != null && this.iReplacementChar == pReplacementChar) return this.iASCIIString; + + // Construct new ASCII string + StringBuilder str = new StringBuilder(""); + if (this.iBytes != null) { + for (int i = 4; i < this.iBytes.length; i++) { + char ch = (char) this.iBytes[i].byteValue(); + if (ch <= 0x1F || ch >= 0x7F) str.append(pReplacementChar); else str.append(ch); + } + } else /* (this.iHexString != null) */{ + for (int i = 10; i < this.iHexString.length(); i += 2) { + char ch = (char) Integer.parseInt(this.iHexString.substring(i, i + 2), 16); + if (ch <= 0x1F || ch >= 0x7F) str.append(pReplacementChar); else str.append(ch); + } + } + + // Save ASCII string in new object and indicate which replacement + // character used + this.iASCIIString = new String(str); + this.iReplacementChar = pReplacementChar; + + return this.iASCIIString; + } + + /** + * Returns byte array representation of octet string. If the byte array has + * not yet been created, it is created from the hexadecimal string or ASCII + * string. + * + * @return Byte array representation of octet string. + */ + public synchronized UnsignedInteger8[] getBytes() { + if (this.iBytes != null) return this.iBytes; + + if (this.iHexString != null) { + convertHexStringToBytes(); + } else /* if (this.iASCIIString != null) */{ + convertASCIIStringToBytes(); + } + + return this.iBytes; + } + + /** + * Returns hexadecimal string representation of octet string. If the + * hexadecimal string has not yet been created, it is created from the byte + * array or ASCII string. + * + * @return Hexadecimal string representation of octet string. + */ + public synchronized String getHexString() { + if (this.iHexString != null) return this.iHexString; + + if (this.iBytes != null) { + convertBytesToHexString(); + } else /* if (this.iASCIIString != null) */{ + convertASCIIStringToHexString(); + } + + return this.iHexString; + } + + /** + * Returns hash code value for octet string. + * + * @return Hash code value for octet string. + */ + @Override + public int hashCode() { + return toString().toLowerCase().hashCode(); + } + + /** + * Returns length of octet string, where length is number of octets plus + * four. + * + * @return Length of octet string. + */ + public int length() { + return this.iLength; + } + + /** + * Returns string representation of octet string. + * + * @return String representation of octet string. + */ + @Override + public String toString() { + return getHexString(); + } + + private void convertBytesToHexString() { + // Start with "0x" + StringBuilder str = new StringBuilder("0x"); + + // Append length + String len = Integer.toHexString(this.iLength); + for (int i = 8 - len.length(); i > 0; i--) str.append('0'); + str.append(len); + + // Append string + for (int i = 4; i < this.iLength; i++) { + String octet = Integer.toHexString(this.iBytes[i].intValue()); + if (octet.length() == 1) str.append('0'); + str.append(octet); + } + + // Save hexadecimal string in new object + this.iHexString = new String(str); + // debug("convertBytesToHexString: from {" + toBytesString() + "} to \"" + // + this.iHexString + "\""); + } + + private void convertHexStringToBytes() { + // Save byte array in new object + this.iBytes = new UnsignedInteger8[this.iLength]; + + // Convert each octet in hexadecimal string to byte + for (int idxByte = 0, idxStr = 2, len = this.iHexString.length(); idxStr < len; idxByte++, idxStr += 2) { + short s; + try { + s = Short.parseShort(this.iHexString.substring(idxStr, idxStr + 2), 16); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Hex string length could not be parsed: " + e.toString()); + } + this.iBytes[idxByte] = new UnsignedInteger8(s); + } + // debug("convertHexStringToBytes: from \"" + this.iHexString + + // "\" to {" + toBytesString() + "}"); + } + + private void convertASCIIStringToBytes() { + // Save byte array in new object + this.iBytes = new UnsignedInteger8[this.iLength]; + + // Convert length + this.iBytes[0] = new UnsignedInteger8((short) ((this.iLength >> 24) & 0xFF)); + this.iBytes[1] = new UnsignedInteger8((short) ((this.iLength >> 16) & 0xFF)); + this.iBytes[2] = new UnsignedInteger8((short) ((this.iLength >> 8) & 0xFF)); + this.iBytes[3] = new UnsignedInteger8((short) (this.iLength & 0xFF)); + + // Convert each character in ASCII string to byte + for (int idxStr = 0, idxByte = 4; idxStr < this.iASCIIString.length(); idxStr++, idxByte++) this.iBytes[idxByte] = + new UnsignedInteger8((short) (this.iASCIIString.charAt(idxStr))); + // debug("convertASCIIStringToBytes: from \"" + this.iASCIIString + + // "\" to {" + toBytesString() + "}"); + } + + private void convertASCIIStringToHexString() { + // Start with "0x" + StringBuilder str = new StringBuilder("0x"); + + // Append length + String len = Integer.toHexString(this.iLength); + for (int i = 8 - len.length(); i > 0; i--) str.append('0'); + str.append(len); + + // Append string + for (int idxAsc = 0; idxAsc < this.iASCIIString.length(); idxAsc++) { + String octet = Integer.toHexString((this.iASCIIString.charAt(idxAsc))); + if (octet.length() == 1) str.append('0'); + str.append(octet); + } + + // Save hexadecimal string in new object + this.iHexString = new String(str); + // debug("convertASCIIStringToHexString: from \"" + this.iASCIIString + + // "\" to \"" + this.iHexString + "\""); + } + // private String toBytesString() { + // StringBuilder str = new StringBuilder(); + // + // for (int i = 0; i < this.iLength; i++) { + // String octet = Integer.toHexString((this.iBytes[i].intValue())); + // if (i > 0) str.append(' '); + // if (octet.length() == 1) str.append('0'); + // str.append(octet); + // } + // return new String(str); + // } + + // private void debug(String str) { + // System.out.println(str); + // } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/CIMQualifiedElementInterfaceImpl.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/CIMQualifiedElementInterfaceImpl.java similarity index 75% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/CIMQualifiedElementInterfaceImpl.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/CIMQualifiedElementInterfaceImpl.java index 399fd23..932649a 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/CIMQualifiedElementInterfaceImpl.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/CIMQualifiedElementInterfaceImpl.java @@ -1,329 +1,330 @@ -/* - (C) Copyright IBM Corp. 2006, 2011 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-09 ebak Make SBLIM client JSR48 compliant - * 1660756 2007-02-22 ebak Embedded object support - * 1737141 2007-06-18 ebak Sync up with JSR48 evolution - * 1783288 2007-09-10 ebak CIMClass.isAssociation() not working for retrieved classes. - * 1796339 2007-10-01 ebak Serializable interface missing from internal componentry - * 1963102 2008-06-26 rgummada NullPointerException when getting qualifiers - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2620505 2009-02-24 rgummada EmbeddedObject qualifier is missing from CIMClass - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2823494 2009-08-03 rgummada Change Boolean constructor to static - * 2975885 2010-03-24 blaschke-oss TCK: CIMXXX.hasQualifierValue(null,null) returns true - * 3001680 2010-05-18 blaschke-oss CIMQualifierElementInterfaceImpl changes qualifiers - * 3023095 2010-07-01 blaschke-oss CIMQualifiedElementInterfaceImpl equals/hashCode issue - * 3154232 2011-01-13 blaschke-oss EmbeddedObject misspelled in javadoc - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMFlavor; -import org.sentrysoftware.wbem.javax.cim.CIMQualifiedElementInterface; -import org.sentrysoftware.wbem.javax.cim.CIMQualifier; - -/** - * Class CIMQualifiedElementInterfaceImpl is responsible for implementing the - * functionality of javax.cim.CIMQualifiedElementInterface - */ -public class CIMQualifiedElementInterfaceImpl implements CIMQualifiedElementInterface, Serializable { - - /** - * serialVersionUID - */ - private static final long serialVersionUID = 4533301297060752510L; - - private CIMQualifier[] iQualis; - - private CIMQualifier[] iLocalOnlyQualis; - - private boolean iEmbeddedObject; - - private static final CIMQualifier KEY = new CIMQualifier("Key", - CIMDataType.BOOLEAN_T, Boolean.TRUE, CIMFlavor.DISABLEOVERRIDE); - - private static final CIMQualifier ASSOCIATION = new CIMQualifier( - "Association", CIMDataType.BOOLEAN_T, Boolean.TRUE, CIMFlavor.DISABLEOVERRIDE); - - private static final CIMQualifier[] EMPTY_QA = new CIMQualifier[0]; - - /** - * Ctor. This constructor doesn't modify the passed qualifier list. - * - * @param pQualifiers - */ - public CIMQualifiedElementInterfaceImpl(CIMQualifier[] pQualifiers) { - setQualis(pQualifiers); - } - - /** - * Ctor. This constructor modifies the qualifier list according to the - * pIsKeyed flag. - * - * @param pQualifiers - * @param pIsKeyed - */ - public CIMQualifiedElementInterfaceImpl(CIMQualifier[] pQualifiers, boolean pIsKeyed) { - this(pQualifiers, pIsKeyed, false); - } - - /** - * Ctor. This constructor is able to not remove the EmbeddedObject - * qualifier. It is useful for the XML parser to parse EmbeddedObject - * qualified elements without values. - * - * @param pQualifiers - * @param pIsKeyed - * @param pKeepEmbObj - */ - public CIMQualifiedElementInterfaceImpl(CIMQualifier[] pQualifiers, boolean pIsKeyed, - boolean pKeepEmbObj) { - this(pQualifiers, pIsKeyed, pKeepEmbObj, false); - } - - /** - * Ctor. This constructor is able to not remove the EmbeddedObject - * qualifier. It is useful for the XML parser to parse EmbeddedObject - * qualified elements without values. It also adds or removes the - * Association qualifier depending on the value of pIsAssociation. - * - * @param pQualifiers - * @param pIsKeyed - * @param pKeepEmbObj - * @param pIsAssociation - */ - public CIMQualifiedElementInterfaceImpl(CIMQualifier[] pQualifiers, boolean pIsKeyed, - boolean pKeepEmbObj, boolean pIsAssociation) { - if (pKeepEmbObj) { - this.iQualis = (CIMQualifier[]) CIMElementSorter.sort(pQualifiers); - this.iEmbeddedObject = CIMElementSorter.findIdx(this.iQualis, "EmbeddedObject") >= 0; - } else { - setQualis(pQualifiers); - } - setBoolQualifier(KEY, pIsKeyed); - setBoolQualifier(ASSOCIATION, pIsAssociation); - } - - /** - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object pObj) { - if (!(pObj instanceof CIMQualifiedElementInterfaceImpl)) return false; - CIMQualifiedElementInterfaceImpl that = (CIMQualifiedElementInterfaceImpl) pObj; - return Arrays.equals(getQualifiers(), that.getQualifiers()); - } - - /** - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - return Arrays.hashCode(getQualifiers()); - } - - /** - * Sets the Qualifiers. If there is an EmbeddedObject qualifier, - * corresponding flag is set. - * - * @param pQualiA - */ - private void setQualis(CIMQualifier[] pQualiA) { - pQualiA = (CIMQualifier[]) CIMElementSorter.sort(pQualiA); - int rmIdx = CIMElementSorter.findIdx(pQualiA, "EmbeddedObject"); - if (rmIdx < 0) { - this.iQualis = pQualiA; - return; - } - this.iEmbeddedObject = true; - this.iQualis = pQualiA; - } - - /** - * if pValue is false and boolean qualifier exists it is removed.
      - * if pValue is true and boolean qualifier exists, it's value is changed to - * true, if boolean qualifier doesn't exist it is added. - * - * @param pQuali - * @param pValue - */ - private void setBoolQualifier(CIMQualifier pQuali, boolean pValue) { - int idx = CIMElementSorter.findIdx(this.iQualis, pQuali.getName()); - if (pValue) { - if (idx < 0) { - // insert the qualifier - // idx=-insertIdx-1 - // insertIdx=-idx-1; - insertQuali(pQuali, -idx - 1); - } else if (!pQuali.getValue().equals(this.iQualis[idx].getValue())) { - // change the qualifier if value different - this.iQualis[idx] = pQuali; - } - } else { - if (idx > 0) { - // remove the existing qualifier - removeQuali(idx); - } - } - } - - private void insertQuali(CIMQualifier pQuali, int idx) { - int origLength = this.iQualis == null ? 0 : this.iQualis.length; - CIMQualifier[] qualis = new CIMQualifier[origLength + 1]; - int srcIdx = 0, dstIdx = 0; - while (srcIdx < idx) - qualis[dstIdx++] = this.iQualis[srcIdx++]; - qualis[dstIdx++] = pQuali; - while (srcIdx < origLength) - qualis[dstIdx++] = this.iQualis[srcIdx++]; - this.iQualis = qualis; - } - - private void removeQuali(int idx) { - CIMQualifier[] qualis = new CIMQualifier[this.iQualis.length - 1]; - int srcIdx = 0, dstIdx = 0; - while (srcIdx < idx) - qualis[dstIdx++] = this.iQualis[srcIdx++]; - ++srcIdx; - while (srcIdx < this.iQualis.length) - qualis[dstIdx++] = this.iQualis[srcIdx++]; - this.iQualis = qualis; - } - - /* - * CIMQualifier( "Key", CIMDataType.BOOLEAN_T, new Boolean(true), - * CIMFlavor.DISABLEOVERRIDE ); - */ - - /** - * Returns true if the "key" Qualifier with true value presents. - * - * @return true/false - */ - public boolean isKeyed() { - return hasQualifierValue("key", Boolean.TRUE); - } - - /** - * Returns true if the "EmbeddedObject" qualifier with true value presents. - * - * @return true/false - */ - public boolean isEmbeddedObject() { - return this.iEmbeddedObject; - } - - /** - * @see org.sentrysoftware.wbem.javax.cim.CIMQualifiedElementInterface#getQualifier(int) - */ - public CIMQualifier getQualifier(int pIndex) { - return this.iQualis[pIndex]; - } - - /** - * @see org.sentrysoftware.wbem.javax.cim.CIMQualifiedElementInterface#getQualifier(java.lang.String) - */ - public CIMQualifier getQualifier(String pName) { - return (CIMQualifier) CIMElementSorter.find(this.iQualis, pName); - } - - /** - * @see org.sentrysoftware.wbem.javax.cim.CIMQualifiedElementInterface#getQualifierCount() - */ - public int getQualifierCount() { - return this.iQualis == null ? 0 : this.iQualis.length; - } - - /** - * @see org.sentrysoftware.wbem.javax.cim.CIMQualifiedElementInterface#getQualifierValue(java.lang.String) - */ - public Object getQualifierValue(String pName) { - CIMQualifier quali = getQualifier(pName); - if (quali == null) return null; - return quali.getValue(); - } - - /** - * @see org.sentrysoftware.wbem.javax.cim.CIMQualifiedElementInterface#getQualifiers() - */ - public CIMQualifier[] getQualifiers() { - return getQualifiers(false); - } - - /** - * getQualifiers - helps filtering based on the propagated flag. - * - * @param pLocalOnly - * @return CIMQualifier[] - */ - public CIMQualifier[] getQualifiers(boolean pLocalOnly) { - if (this.iQualis == null) return EMPTY_QA; - if (!pLocalOnly) return this.iQualis; - if (this.iLocalOnlyQualis == null) { - ArrayList> qualiL = new ArrayList>(this.iQualis.length); - for (int i = 0; i < this.iQualis.length; i++) - if (!this.iQualis[i].isPropagated()) qualiL.add(this.iQualis[i]); - this.iLocalOnlyQualis = qualiL.toArray(new CIMQualifier[qualiL.size()]); - } - return this.iLocalOnlyQualis; - } - - /** - * @see org.sentrysoftware.wbem.javax.cim.CIMQualifiedElementInterface#hasQualifier(java.lang.String) - */ - public boolean hasQualifier(String pName) { - return getQualifier(pName) != null; - } - - /** - * @see org.sentrysoftware.wbem.javax.cim.CIMQualifiedElementInterface#hasQualifierValue(java.lang.String, - * java.lang.Object) - */ - public boolean hasQualifierValue(String pName, Object pValue) { - if (!hasQualifier(pName)) return false; - Object value = getQualifierValue(pName); - return value == null ? pValue == null : value.equals(pValue); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2011 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-09 ebak Make SBLIM client JSR48 compliant + * 1660756 2007-02-22 ebak Embedded object support + * 1737141 2007-06-18 ebak Sync up with JSR48 evolution + * 1783288 2007-09-10 ebak CIMClass.isAssociation() not working for retrieved classes. + * 1796339 2007-10-01 ebak Serializable interface missing from internal componentry + * 1963102 2008-06-26 rgummada NullPointerException when getting qualifiers + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2620505 2009-02-24 rgummada EmbeddedObject qualifier is missing from CIMClass + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2823494 2009-08-03 rgummada Change Boolean constructor to static + * 2975885 2010-03-24 blaschke-oss TCK: CIMXXX.hasQualifierValue(null,null) returns true + * 3001680 2010-05-18 blaschke-oss CIMQualifierElementInterfaceImpl changes qualifiers + * 3023095 2010-07-01 blaschke-oss CIMQualifiedElementInterfaceImpl equals/hashCode issue + * 3154232 2011-01-13 blaschke-oss EmbeddedObject misspelled in javadoc + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMFlavor; +import org.metricshub.wbem.javax.cim.CIMQualifiedElementInterface; +import org.metricshub.wbem.javax.cim.CIMQualifier; + +/** + * Class CIMQualifiedElementInterfaceImpl is responsible for implementing the + * functionality of javax.cim.CIMQualifiedElementInterface + */ +public class CIMQualifiedElementInterfaceImpl implements CIMQualifiedElementInterface, Serializable { + /** + * serialVersionUID + */ + private static final long serialVersionUID = 4533301297060752510L; + + private CIMQualifier[] iQualis; + + private CIMQualifier[] iLocalOnlyQualis; + + private boolean iEmbeddedObject; + + private static final CIMQualifier KEY = new CIMQualifier( + "Key", + CIMDataType.BOOLEAN_T, + Boolean.TRUE, + CIMFlavor.DISABLEOVERRIDE + ); + + private static final CIMQualifier ASSOCIATION = new CIMQualifier( + "Association", + CIMDataType.BOOLEAN_T, + Boolean.TRUE, + CIMFlavor.DISABLEOVERRIDE + ); + + private static final CIMQualifier[] EMPTY_QA = new CIMQualifier[0]; + + /** + * Ctor. This constructor doesn't modify the passed qualifier list. + * + * @param pQualifiers + */ + public CIMQualifiedElementInterfaceImpl(CIMQualifier[] pQualifiers) { + setQualis(pQualifiers); + } + + /** + * Ctor. This constructor modifies the qualifier list according to the + * pIsKeyed flag. + * + * @param pQualifiers + * @param pIsKeyed + */ + public CIMQualifiedElementInterfaceImpl(CIMQualifier[] pQualifiers, boolean pIsKeyed) { + this(pQualifiers, pIsKeyed, false); + } + + /** + * Ctor. This constructor is able to not remove the EmbeddedObject + * qualifier. It is useful for the XML parser to parse EmbeddedObject + * qualified elements without values. + * + * @param pQualifiers + * @param pIsKeyed + * @param pKeepEmbObj + */ + public CIMQualifiedElementInterfaceImpl(CIMQualifier[] pQualifiers, boolean pIsKeyed, boolean pKeepEmbObj) { + this(pQualifiers, pIsKeyed, pKeepEmbObj, false); + } + + /** + * Ctor. This constructor is able to not remove the EmbeddedObject + * qualifier. It is useful for the XML parser to parse EmbeddedObject + * qualified elements without values. It also adds or removes the + * Association qualifier depending on the value of pIsAssociation. + * + * @param pQualifiers + * @param pIsKeyed + * @param pKeepEmbObj + * @param pIsAssociation + */ + public CIMQualifiedElementInterfaceImpl( + CIMQualifier[] pQualifiers, + boolean pIsKeyed, + boolean pKeepEmbObj, + boolean pIsAssociation + ) { + if (pKeepEmbObj) { + this.iQualis = (CIMQualifier[]) CIMElementSorter.sort(pQualifiers); + this.iEmbeddedObject = CIMElementSorter.findIdx(this.iQualis, "EmbeddedObject") >= 0; + } else { + setQualis(pQualifiers); + } + setBoolQualifier(KEY, pIsKeyed); + setBoolQualifier(ASSOCIATION, pIsAssociation); + } + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object pObj) { + if (!(pObj instanceof CIMQualifiedElementInterfaceImpl)) return false; + CIMQualifiedElementInterfaceImpl that = (CIMQualifiedElementInterfaceImpl) pObj; + return Arrays.equals(getQualifiers(), that.getQualifiers()); + } + + /** + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return Arrays.hashCode(getQualifiers()); + } + + /** + * Sets the Qualifiers. If there is an EmbeddedObject qualifier, + * corresponding flag is set. + * + * @param pQualiA + */ + private void setQualis(CIMQualifier[] pQualiA) { + pQualiA = (CIMQualifier[]) CIMElementSorter.sort(pQualiA); + int rmIdx = CIMElementSorter.findIdx(pQualiA, "EmbeddedObject"); + if (rmIdx < 0) { + this.iQualis = pQualiA; + return; + } + this.iEmbeddedObject = true; + this.iQualis = pQualiA; + } + + /** + * if pValue is false and boolean qualifier exists it is removed.
      + * if pValue is true and boolean qualifier exists, it's value is changed to + * true, if boolean qualifier doesn't exist it is added. + * + * @param pQuali + * @param pValue + */ + private void setBoolQualifier(CIMQualifier pQuali, boolean pValue) { + int idx = CIMElementSorter.findIdx(this.iQualis, pQuali.getName()); + if (pValue) { + if (idx < 0) { + // insert the qualifier + // idx=-insertIdx-1 + // insertIdx=-idx-1; + insertQuali(pQuali, -idx - 1); + } else if (!pQuali.getValue().equals(this.iQualis[idx].getValue())) { + // change the qualifier if value different + this.iQualis[idx] = pQuali; + } + } else { + if (idx > 0) { + // remove the existing qualifier + removeQuali(idx); + } + } + } + + private void insertQuali(CIMQualifier pQuali, int idx) { + int origLength = this.iQualis == null ? 0 : this.iQualis.length; + CIMQualifier[] qualis = new CIMQualifier[origLength + 1]; + int srcIdx = 0, dstIdx = 0; + while (srcIdx < idx) qualis[dstIdx++] = this.iQualis[srcIdx++]; + qualis[dstIdx++] = pQuali; + while (srcIdx < origLength) qualis[dstIdx++] = this.iQualis[srcIdx++]; + this.iQualis = qualis; + } + + private void removeQuali(int idx) { + CIMQualifier[] qualis = new CIMQualifier[this.iQualis.length - 1]; + int srcIdx = 0, dstIdx = 0; + while (srcIdx < idx) qualis[dstIdx++] = this.iQualis[srcIdx++]; + ++srcIdx; + while (srcIdx < this.iQualis.length) qualis[dstIdx++] = this.iQualis[srcIdx++]; + this.iQualis = qualis; + } + + /* + * CIMQualifier( "Key", CIMDataType.BOOLEAN_T, new Boolean(true), + * CIMFlavor.DISABLEOVERRIDE ); + */ + + /** + * Returns true if the "key" Qualifier with true value presents. + * + * @return true/false + */ + public boolean isKeyed() { + return hasQualifierValue("key", Boolean.TRUE); + } + + /** + * Returns true if the "EmbeddedObject" qualifier with true value presents. + * + * @return true/false + */ + public boolean isEmbeddedObject() { + return this.iEmbeddedObject; + } + + /** + * @see org.metricshub.wbem.javax.cim.CIMQualifiedElementInterface#getQualifier(int) + */ + public CIMQualifier getQualifier(int pIndex) { + return this.iQualis[pIndex]; + } + + /** + * @see org.metricshub.wbem.javax.cim.CIMQualifiedElementInterface#getQualifier(java.lang.String) + */ + public CIMQualifier getQualifier(String pName) { + return (CIMQualifier) CIMElementSorter.find(this.iQualis, pName); + } + + /** + * @see org.metricshub.wbem.javax.cim.CIMQualifiedElementInterface#getQualifierCount() + */ + public int getQualifierCount() { + return this.iQualis == null ? 0 : this.iQualis.length; + } + + /** + * @see org.metricshub.wbem.javax.cim.CIMQualifiedElementInterface#getQualifierValue(java.lang.String) + */ + public Object getQualifierValue(String pName) { + CIMQualifier quali = getQualifier(pName); + if (quali == null) return null; + return quali.getValue(); + } + + /** + * @see org.metricshub.wbem.javax.cim.CIMQualifiedElementInterface#getQualifiers() + */ + public CIMQualifier[] getQualifiers() { + return getQualifiers(false); + } + + /** + * getQualifiers - helps filtering based on the propagated flag. + * + * @param pLocalOnly + * @return CIMQualifier[] + */ + public CIMQualifier[] getQualifiers(boolean pLocalOnly) { + if (this.iQualis == null) return EMPTY_QA; + if (!pLocalOnly) return this.iQualis; + if (this.iLocalOnlyQualis == null) { + ArrayList> qualiL = new ArrayList>(this.iQualis.length); + for (int i = 0; i < this.iQualis.length; i++) if (!this.iQualis[i].isPropagated()) qualiL.add(this.iQualis[i]); + this.iLocalOnlyQualis = qualiL.toArray(new CIMQualifier[qualiL.size()]); + } + return this.iLocalOnlyQualis; + } + + /** + * @see org.metricshub.wbem.javax.cim.CIMQualifiedElementInterface#hasQualifier(java.lang.String) + */ + public boolean hasQualifier(String pName) { + return getQualifier(pName) != null; + } + + /** + * @see org.metricshub.wbem.javax.cim.CIMQualifiedElementInterface#hasQualifierValue(java.lang.String, + * java.lang.Object) + */ + public boolean hasQualifierValue(String pName, Object pValue) { + if (!hasQualifier(pName)) return false; + Object value = getQualifierValue(pName); + return value == null ? pValue == null : value.equals(pValue); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/CIMVersion.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/CIMVersion.java similarity index 77% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/CIMVersion.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/CIMVersion.java index f8acb6a..a272c98 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/CIMVersion.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/CIMVersion.java @@ -1,158 +1,155 @@ -/* - CIMVersion.java - - (C) Copyright IBM Corp. 2005, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM ,chungtan@us.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 2807325 2009-06-22 blaschke-oss Change licensing from CPL to EPL - * 2834838 2009-08-11 blaschke-oss Add interface to retrieve version number and product name - * 3027618 2010-07-14 blaschke-oss Close files/readers in finally blocks - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -/** - * Class CIMVersion is responsible for providing the exact version number, - * product name, etc. of the Java CIM Client - */ -public class CIMVersion { - - private static String PRODUCT_NAME = "n/a"; - - private static String VERSION = "n/a"; - - private static String COPYRIGHT = "n/a"; - - private static String BUILDDATE = "n/a"; - - private static String BUILDTIME = "n/a"; - - static { - Properties properties = new Properties(); - InputStream versionIS = null; - try { - versionIS = CIMVersion.class.getClassLoader().getResourceAsStream("com/sentrysoftware/sblim/cimclient/version.txt"); - properties.load(versionIS); - PRODUCT_NAME = properties.getProperty("PRODUCTNAME"); - VERSION = properties.getProperty("VERSION"); - COPYRIGHT = properties.getProperty("COPYRIGHT"); - BUILDDATE = properties.getProperty("BUILDDATE"); - BUILDTIME = properties.getProperty("BUILDTIME"); - } catch (FileNotFoundException e) { - System.out.println("Error: Could not open version.txt"); - } catch (IOException e) { - System.out.println("Error while reading version.txt"); - } finally { - if (versionIS != null) { - try { - versionIS.close(); - } catch (IOException e) { - /* Ignore exception on close */ - } - } - } - } - - /** - * Gets the build date - * - * @return The build date - */ - public static String getBuildDate() { - return BUILDDATE; - } - - /** - * Gets the build time - * - * @return The build time - */ - public static String getBuildTime() { - return BUILDTIME; - } - - /** - * Gets the copyright statement - * - * @return THe copyright - */ - public static String getCopyright() { - return COPYRIGHT; - } - - /** - * Gets the product name - * - * @return The product name - */ - public static String getProductName() { - return PRODUCT_NAME; - } - - /** - * Gets the version - * - * @return The version - */ - public static String getVersion() { - return VERSION; - } - - /** - * toString - * - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return (PRODUCT_NAME + "\n" + VERSION + "\n" + COPYRIGHT + "\n" + BUILDDATE + "\n" + BUILDTIME); - } - - /** - * main - * - * @param args - */ - public static void main(String[] args) { - System.out.println(new CIMVersion()); - } -} +/* + CIMVersion.java + + (C) Copyright IBM Corp. 2005, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM ,chungtan@us.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 2807325 2009-06-22 blaschke-oss Change licensing from CPL to EPL + * 2834838 2009-08-11 blaschke-oss Add interface to retrieve version number and product name + * 3027618 2010-07-14 blaschke-oss Close files/readers in finally blocks + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +/** + * Class CIMVersion is responsible for providing the exact version number, + * product name, etc. of the Java CIM Client + */ +public class CIMVersion { + private static String PRODUCT_NAME = "n/a"; + + private static String VERSION = "n/a"; + + private static String COPYRIGHT = "n/a"; + + private static String BUILDDATE = "n/a"; + + private static String BUILDTIME = "n/a"; + + static { + Properties properties = new Properties(); + InputStream versionIS = null; + try { + versionIS = CIMVersion.class.getClassLoader().getResourceAsStream("org/sblim/cimclient/version.txt"); + properties.load(versionIS); + PRODUCT_NAME = properties.getProperty("PRODUCTNAME"); + VERSION = properties.getProperty("VERSION"); + COPYRIGHT = properties.getProperty("COPYRIGHT"); + BUILDDATE = properties.getProperty("BUILDDATE"); + BUILDTIME = properties.getProperty("BUILDTIME"); + } catch (FileNotFoundException e) { + System.out.println("Error: Could not open version.txt"); + } catch (IOException e) { + System.out.println("Error while reading version.txt"); + } finally { + if (versionIS != null) { + try { + versionIS.close(); + } catch (IOException e) { + /* Ignore exception on close */ + } + } + } + } + + /** + * Gets the build date + * + * @return The build date + */ + public static String getBuildDate() { + return BUILDDATE; + } + + /** + * Gets the build time + * + * @return The build time + */ + public static String getBuildTime() { + return BUILDTIME; + } + + /** + * Gets the copyright statement + * + * @return THe copyright + */ + public static String getCopyright() { + return COPYRIGHT; + } + + /** + * Gets the product name + * + * @return The product name + */ + public static String getProductName() { + return PRODUCT_NAME; + } + + /** + * Gets the version + * + * @return The version + */ + public static String getVersion() { + return VERSION; + } + + /** + * toString + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return (PRODUCT_NAME + "\n" + VERSION + "\n" + COPYRIGHT + "\n" + BUILDDATE + "\n" + BUILDTIME); + } + + /** + * main + * + * @param args + */ + public static void main(String[] args) { + System.out.println(new CIMVersion()); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/DTStringReader.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/DTStringReader.java similarity index 72% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/DTStringReader.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/DTStringReader.java index 4fc3f3e..b58dc8b 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/DTStringReader.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/DTStringReader.java @@ -1,208 +1,211 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-12 ebak Make SBLIM client JSR48 compliant - * 1678807 2007-03-12 ebak Minor CIMDateTime suggestions - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 3526675 2012-05-14 blaschke-oss Unit test fails on Java 7 - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.io.StringReader; - -/** - * Class DTString helps parsing CIMDateTime Strings. - * - */ -public class DTStringReader { - - private String iDateTimeStr; - - private StringReader iReader; - - private int iPos = 0; - - private boolean iUnsignificant; - - /** - * Ctor. - * - * @param pDateTimeStr - */ - public DTStringReader(String pDateTimeStr) { - this.iDateTimeStr = pDateTimeStr; - this.iReader = new StringReader(pDateTimeStr); - } - - /** - * read - * - * @param pLen - * - number of characters to be read from the string - * @param pFieldName - * - the name of the field which is to be read (e.g. year, month, - * day ...) - * @param pAllowUnsignificant - * @return int - * @throws IllegalArgumentException - */ - public int read(int pLen, String pFieldName, boolean pAllowUnsignificant) - throws IllegalArgumentException { - char[] buf = new char[pLen]; - int read; - try { - read = this.iReader.read(buf); - this.iPos += pLen; - } catch (IOException e) { - String msg = "Failed to read " + pFieldName + " field from " + this.iDateTimeStr + '!'; - throw new IllegalArgumentException(msg); - } - if (read != pLen) { - String msg = "Length of " + pFieldName + " field should be " + pLen + " but only" - + read + " characters could be read!"; - throw new IllegalArgumentException(msg); - } - // Not significant check - if (pAllowUnsignificant) { - int cnt = 0; - for (int i = 0; i < buf.length; i++) - if (buf[i] == '*') ++cnt; - if (cnt == buf.length) { - this.iUnsignificant = true; - return -1; - } - } - this.iUnsignificant = false; - String field = new String(buf); - int res; - try { - res = Integer.parseInt(field); - } catch (NumberFormatException e) { - String msg = "Illegal " + pFieldName + " field \"" + field + "\" in \"" - + this.iDateTimeStr + "\"!"; - throw new IllegalArgumentException(msg); - } - if (res < 0) throw new IllegalArgumentException("Negative value is not allowed for " - + pFieldName + " in " + this.iDateTimeStr + "!"); - // Java 7 parseInt began allowing plus sign - if (field.indexOf('+') != -1) throw new IllegalArgumentException( - "Plus sign is not allowed for " + pFieldName + " in " + this.iDateTimeStr + "!"); - return res; - } - - /** - * readAndCheck - * - * @param pLen - * - number of digits to read - * @param pFieldName - * - the name of the field which is to be read (e.g. year, month, - * day...) - * @param pMin - * - the allowed minimum value (-1 is always allowed as not - * significant) - * @param pMax - * - the allowed maximum value - * @param pAllowUnsignificant - * @return int - * @throws IllegalArgumentException - */ - public int readAndCheck(int pLen, String pFieldName, int pMin, int pMax, - boolean pAllowUnsignificant) throws IllegalArgumentException { - int val = read(pLen, pFieldName, pAllowUnsignificant); - if (pAllowUnsignificant && val == -1) return val; - if (val < pMin || val > pMax) throw new IllegalArgumentException(pFieldName - + " must be between " + pMin + " and " + pMax + ", but " + val + " was read from " - + this.iDateTimeStr + " !"); - return val; - } - - /** - * read - * - * @return a char, 0 if failed - */ - public char read() { - try { - int i = this.iReader.read(); - if (i > 0) { - ++this.iPos; - return (char) i; - } - return 0; - } catch (IOException e) { - return 0; - } - } - - /** - * read - Throws an IllegalArgumentException if the read character is not c. - * - * @param c - * - contains the character which should be read from the String. - * @throws IllegalArgumentException - */ - public void read(char c) throws IllegalArgumentException { - if (read() != c) { - String msg = "'" + c + "' expected at position " + getPos() + " in " - + this.iDateTimeStr + "!"; - throw new IllegalArgumentException(msg); - } - } - - /** - * getPos - * - * @return the position in the reader - */ - public int getPos() { - return this.iPos; - } - - /** - * isUnsignificant - * - * @return boolean - */ - public boolean isUnsignificant() { - return this.iUnsignificant; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-12 ebak Make SBLIM client JSR48 compliant + * 1678807 2007-03-12 ebak Minor CIMDateTime suggestions + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 3526675 2012-05-14 blaschke-oss Unit test fails on Java 7 + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.io.StringReader; + +/** + * Class DTString helps parsing CIMDateTime Strings. + * + */ +public class DTStringReader { + private String iDateTimeStr; + + private StringReader iReader; + + private int iPos = 0; + + private boolean iUnsignificant; + + /** + * Ctor. + * + * @param pDateTimeStr + */ + public DTStringReader(String pDateTimeStr) { + this.iDateTimeStr = pDateTimeStr; + this.iReader = new StringReader(pDateTimeStr); + } + + /** + * read + * + * @param pLen + * - number of characters to be read from the string + * @param pFieldName + * - the name of the field which is to be read (e.g. year, month, + * day ...) + * @param pAllowUnsignificant + * @return int + * @throws IllegalArgumentException + */ + public int read(int pLen, String pFieldName, boolean pAllowUnsignificant) throws IllegalArgumentException { + char[] buf = new char[pLen]; + int read; + try { + read = this.iReader.read(buf); + this.iPos += pLen; + } catch (IOException e) { + String msg = "Failed to read " + pFieldName + " field from " + this.iDateTimeStr + '!'; + throw new IllegalArgumentException(msg); + } + if (read != pLen) { + String msg = + "Length of " + pFieldName + " field should be " + pLen + " but only" + read + " characters could be read!"; + throw new IllegalArgumentException(msg); + } + // Not significant check + if (pAllowUnsignificant) { + int cnt = 0; + for (int i = 0; i < buf.length; i++) if (buf[i] == '*') ++cnt; + if (cnt == buf.length) { + this.iUnsignificant = true; + return -1; + } + } + this.iUnsignificant = false; + String field = new String(buf); + int res; + try { + res = Integer.parseInt(field); + } catch (NumberFormatException e) { + String msg = "Illegal " + pFieldName + " field \"" + field + "\" in \"" + this.iDateTimeStr + "\"!"; + throw new IllegalArgumentException(msg); + } + if (res < 0) throw new IllegalArgumentException( + "Negative value is not allowed for " + pFieldName + " in " + this.iDateTimeStr + "!" + ); + // Java 7 parseInt began allowing plus sign + if (field.indexOf('+') != -1) throw new IllegalArgumentException( + "Plus sign is not allowed for " + pFieldName + " in " + this.iDateTimeStr + "!" + ); + return res; + } + + /** + * readAndCheck + * + * @param pLen + * - number of digits to read + * @param pFieldName + * - the name of the field which is to be read (e.g. year, month, + * day...) + * @param pMin + * - the allowed minimum value (-1 is always allowed as not + * significant) + * @param pMax + * - the allowed maximum value + * @param pAllowUnsignificant + * @return int + * @throws IllegalArgumentException + */ + public int readAndCheck(int pLen, String pFieldName, int pMin, int pMax, boolean pAllowUnsignificant) + throws IllegalArgumentException { + int val = read(pLen, pFieldName, pAllowUnsignificant); + if (pAllowUnsignificant && val == -1) return val; + if (val < pMin || val > pMax) throw new IllegalArgumentException( + pFieldName + + " must be between " + + pMin + + " and " + + pMax + + ", but " + + val + + " was read from " + + this.iDateTimeStr + + " !" + ); + return val; + } + + /** + * read + * + * @return a char, 0 if failed + */ + public char read() { + try { + int i = this.iReader.read(); + if (i > 0) { + ++this.iPos; + return (char) i; + } + return 0; + } catch (IOException e) { + return 0; + } + } + + /** + * read - Throws an IllegalArgumentException if the read character is not c. + * + * @param c + * - contains the character which should be read from the String. + * @throws IllegalArgumentException + */ + public void read(char c) throws IllegalArgumentException { + if (read() != c) { + String msg = "'" + c + "' expected at position " + getPos() + " in " + this.iDateTimeStr + "!"; + throw new IllegalArgumentException(msg); + } + } + + /** + * getPos + * + * @return the position in the reader + */ + public int getPos() { + return this.iPos; + } + + /** + * isUnsignificant + * + * @return boolean + */ + public boolean isUnsignificant() { + return this.iUnsignificant; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/DTStringWriter.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/DTStringWriter.java similarity index 74% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/DTStringWriter.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/DTStringWriter.java index 1bb1dfe..2e2ea07 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/DTStringWriter.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/DTStringWriter.java @@ -1,134 +1,130 @@ -/* - (C) Copyright IBM Corp. 2006, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-10-12 ebak Make SBLIM client JSR48 compliant - * 1678807 2007-03-12 ebak Minor CIMDateTime suggestions - * 1849235 2008-02-11 blaschke-oss DTStringWriter.writeSigned parameter pDigits is not used - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2989367 2010-04-29 blaschke-oss CIMDateTimeInterval(long) constructor range wrong - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cim; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Arrays; - -/** - * Class DTStringWriter helps making CIMDateTime Strings. - */ -public class DTStringWriter { - - private StringBuffer iBuf = new StringBuffer(); - - /** - * writeInt - writes an integer, the upper digits are filled with zeros - * - * @param pNum - * -1 means that asterisks have to be printed - * @param pDigits - */ - public void write(int pDigits, int pNum) { - if (pDigits <= 0) return; - if (pNum == -1) { - char[] cA = new char[pDigits]; - Arrays.fill(cA, '*'); - this.iBuf.append(cA); - return; - } - String str = Integer.toString(pNum); - int paddingDigits = pDigits - str.length(); - if (paddingDigits > 0) { - char[] cA = new char[paddingDigits]; - Arrays.fill(cA, '0'); - this.iBuf.append(cA).append(str); - } else this.iBuf.append(str); - } - - /** - * writeSignedInt - used for utc writing - * - * @param pNum - * @param pDigits - */ - public void writeSigned(int pDigits, int pNum) { - char sign; - if (pNum < 0) { - sign = '-'; - pNum = -pNum; - } else sign = '+'; - write(sign); - write(pDigits, pNum); - } - - /** - * writeUSec - * - * @param pUSec - * @param pUnsignificantDigits - */ - public void writeUSec(int pUSec, int pUnsignificantDigits) { - int digits = 6 - pUnsignificantDigits; - write(digits, pUSec); - for (int i = 0; i < pUnsignificantDigits; i++) - write('*'); - } - - /** - * writeChar - * - * @param pChar - */ - public void write(char pChar) { - this.iBuf.append(pChar); - } - - /** - * write - * - * @param pStr - */ - public void write(String pStr) { - this.iBuf.append(pStr); - } - - /** - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return this.iBuf.toString(); - } -} +/* + (C) Copyright IBM Corp. 2006, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-10-12 ebak Make SBLIM client JSR48 compliant + * 1678807 2007-03-12 ebak Minor CIMDateTime suggestions + * 1849235 2008-02-11 blaschke-oss DTStringWriter.writeSigned parameter pDigits is not used + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2989367 2010-04-29 blaschke-oss CIMDateTimeInterval(long) constructor range wrong + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cim; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Arrays; + +/** + * Class DTStringWriter helps making CIMDateTime Strings. + */ +public class DTStringWriter { + private StringBuffer iBuf = new StringBuffer(); + + /** + * writeInt - writes an integer, the upper digits are filled with zeros + * + * @param pNum + * -1 means that asterisks have to be printed + * @param pDigits + */ + public void write(int pDigits, int pNum) { + if (pDigits <= 0) return; + if (pNum == -1) { + char[] cA = new char[pDigits]; + Arrays.fill(cA, '*'); + this.iBuf.append(cA); + return; + } + String str = Integer.toString(pNum); + int paddingDigits = pDigits - str.length(); + if (paddingDigits > 0) { + char[] cA = new char[paddingDigits]; + Arrays.fill(cA, '0'); + this.iBuf.append(cA).append(str); + } else this.iBuf.append(str); + } + + /** + * writeSignedInt - used for utc writing + * + * @param pNum + * @param pDigits + */ + public void writeSigned(int pDigits, int pNum) { + char sign; + if (pNum < 0) { + sign = '-'; + pNum = -pNum; + } else sign = '+'; + write(sign); + write(pDigits, pNum); + } + + /** + * writeUSec + * + * @param pUSec + * @param pUnsignificantDigits + */ + public void writeUSec(int pUSec, int pUnsignificantDigits) { + int digits = 6 - pUnsignificantDigits; + write(digits, pUSec); + for (int i = 0; i < pUnsignificantDigits; i++) write('*'); + } + + /** + * writeChar + * + * @param pChar + */ + public void write(char pChar) { + this.iBuf.append(pChar); + } + + /** + * write + * + * @param pStr + */ + public void write(String pStr) { + this.iBuf.append(pStr); + } + + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return this.iBuf.toString(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/package.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/package.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cim/package.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cim/package.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CIMClientXML_HelperImpl.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CIMClientXML_HelperImpl.java similarity index 73% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CIMClientXML_HelperImpl.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CIMClientXML_HelperImpl.java index 326bd35..ffc3edd 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CIMClientXML_HelperImpl.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CIMClientXML_HelperImpl.java @@ -1,2635 +1,2706 @@ -/* - (C) Copyright IBM Corp. 2005, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 13521 2004-11-26 thschaef XML Request Composition for static method call is wrong - * 18075 2005-08-11 pineiro5 Can not use method CIMClient.invokeMethod - * 1535756 2006-08-07 lupusalex Make code warning free - * 1365086 2006-10-25 ebak Possible bug in createQualifier - * 1565892 2006-11-16 lupusalex Make SBLIM client JSR48 compliant - * 1610046 2006-12-18 lupusalex Does not escape trailing spaces - * 1610046 2007-01-10 lupusalex Rework: Does not escape trailing spaces - * 1649611 2007-01-31 lupusalex Interop issue: Quotes not escaped by client - * 1671502 2007-02-28 lupusalex Remove dependency from Xerces - * 1660756 2007-03-02 ebak Embedded object support - * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus - * 1669961 2006-04-16 lupusalex CIMTypedElement.getType() =>getDataType() - * 1715027 2007-05-08 lupusalex Make message id random - * 1719991 2007-05-16 ebak FVT: regression ClassCastException in EmbObjHandler - * 1734888 2007-06-11 ebak Wrong reference building in METHODCALL request - * 1827728 2007-11-12 ebak embeddedInstances: attribute EmbeddedObject not set - * 1827728 2007-11-20 ebak rework: embeddedInstances: attribute EmbeddedObject not set - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2845211 2009-08-27 raman_arora Pull Enumeration Feature (SAX Parser) - * 2865222 2009-09-29 raman_arora enumerateQualifierTypes shouldn't require a class name - * 2858933 2009-10-12 raman_arora JSR48 new APIs: associatorClasses & associatorInstances - * 2886829 2009-11-18 raman_arora JSR48 new APIs: referenceClasses & referenceInstances - * 2944219 2010-02-05 blaschke-oss Problem with pull operations using client against EMC CIMOM - * 3027479 2010-07-09 blaschke-oss Dead store to local variable - * 3062747 2010-09-21 blaschke-oss SblimCIMClient does not log all CIM-XML responces. - * 3514537 2012-04-03 blaschke-oss TCK: execQueryInstances requires boolean, not Boolean - * 3521119 2012-04-24 blaschke-oss JSR48 1.0.0: remove CIMObjectPath 2/3/4-parm ctors - * 3527580 2012-05-17 blaschke-oss WBEMClient should not throw IllegalArgumentException - * 3601894 2013-01-23 blaschke-oss Enhance HTTP and CIM-XML tracing - * 2616 2013-02-23 blaschke-oss Add new API WBEMClientSBLIM.sendIndication() - * 2689 2013-10-10 blaschke-oss createMETHODCALL should not add PARAMTYPE attribute - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.io.OutputStream; -import java.util.Iterator; -import java.util.Random; -import java.util.Vector; - -import org.sentrysoftware.wbem.javax.cim.CIMArgument; -import org.sentrysoftware.wbem.javax.cim.CIMClass; -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMInstance; -import org.sentrysoftware.wbem.javax.cim.CIMNamedElementInterface; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import org.sentrysoftware.wbem.javax.cim.CIMProperty; -import org.sentrysoftware.wbem.javax.cim.CIMQualifierType; -import org.sentrysoftware.wbem.javax.cim.CIMValuedElement; -import org.sentrysoftware.wbem.javax.cim.UnsignedInteger32; -import org.sentrysoftware.wbem.javax.wbem.WBEMException; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.TimeStamp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.MOF; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.CIMError; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMAssociatorNamesOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMAssociatorsOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMCreateClassOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMCreateInstanceOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMCreateNameSpaceOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMCreateQualifierTypeOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMDeleteClassOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMDeleteInstanceOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMDeleteQualifierTypeOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMEnumClassNamesOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMEnumClassesOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMEnumInstanceNamesOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMEnumInstancesOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMEnumNameSpaceOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMEnumQualifierTypesOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMExecQueryOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMGetClassOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMGetInstanceOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMGetPropertyOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMGetQualifierTypeOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMInvokeMethodOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMOperation; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMReferenceNamesOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMReferencesOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMSetClassOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMSetInstanceOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMSetPropertyOp; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations.CIMSetQualifierTypeOp; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -/** - * Class CIMClientXML_HelperImpl is responsible for building CIM-XML requests - * and responses. - */ -public class CIMClientXML_HelperImpl { - - private static class Counter { - - private int iCounter; - - protected Counter(int pCounter) { - this.iCounter = pCounter; - } - - protected int incrementAndGet() { - return ++this.iCounter; - } - } - - private static final String VERSION = "1.0"; - - private static final String ASSOCIATOR_NAMES = "AssociatorNames"; - - // Pull Enumeration variables - private static final String ASSOC_CLASS = "AssocClass"; - - private static final String CLASS_NAME = "ClassName"; - - private static final String CONTINUE_ON_ERROR = "ContinueOnError"; - - private static final String DEEP_INHERITANCE = "DeepInheritance"; - - private static final String ENUMERATION_CONTEXT = "EnumerationContext"; - - private static final String FILTER_QUERY_LANGUAGE = "FilterQueryLanguage"; - - private static final String FILTER_QUERY = "FilterQuery"; - - private static final String INCLUDE_CLASS_ORIGIN = "IncludeClassOrigin"; - - private static final String INSTANCE_NAME = "InstanceName"; - - private static final String MAX_OBJECT_COUNT = "MaxObjectCount"; - - private static final String PROPERTY_LIST = "PropertyList"; - - private static final String OPERATION_TIMEOUT = "OperationTimeout"; - - private static final String RESULT_CLASS = "ResultClass"; - - private static final String RETURN_QUERY_RESULT_CLASS = "ReturnQueryResultClass"; - - private static final String QUERY_RESULT_CLASS = "QueryResultClass"; - - private static final String ROLE = "Role"; - - private static final String RESULT_ROLE = "ResultRole"; - - private static final Random RANDOM = new Random(); - - private static final int MAX_ID = 1 << 20; - - private final ThreadLocal iCurrentId = new ThreadLocal(); - - private final DocumentBuilder iBuilder; - - private static String valueStr(CIMValuedElement pE) { - Object o = pE.getValue(); - return o == null ? MOF.NULL : o.toString(); - } - - /** - * Ctor. - * - * @throws ParserConfigurationException - */ - public CIMClientXML_HelperImpl() throws ParserConfigurationException { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - this.iBuilder = factory.newDocumentBuilder(); - } - - /** - * getDocumentBuilder - * - * @return DocumentBuilder - */ - public DocumentBuilder getDocumentBuilder() { - return this.iBuilder; - } - - /** - * newDocument - * - * @return Document - */ - public Document newDocument() { - return this.iBuilder.newDocument(); - } - - /** - * parse - * - * @param pIS - * @return Document - * @throws IOException - * @throws SAXException - */ - public Document parse(InputSource pIS) throws IOException, SAXException { - if (pIS == null) throw new IllegalArgumentException("null input stream argument"); - return this.iBuilder.parse(pIS); - } - - /** - * Serializes a given DOM document as (CIM-)XML to a given output stream - * - * @param pOS - * The output stream - * @param pDoc - * The documents - * @throws IOException - * Whenever something goes wrong - */ - public static void serialize(OutputStream pOS, Document pDoc) throws IOException { - CimXmlSerializer.serialize(pOS, pDoc, false); - } - - /** - * Serializes a given DOM document as (CIM-)XML to a given output stream. - * The document is pretty wrapped and indented and surrounded with markers - * for the begin and end. - * - * @param pOS - * The output stream - * @param pDoc - * The documents - * @throws IOException - */ - public static void dumpDocument(OutputStream pOS, Document pDoc) throws IOException { - dumpDocument(pOS, pDoc, null); - } - - /** - * Serializes a given DOM document as (CIM-)XML to a given output stream. - * The document is pretty wrapped and indented and surrounded with markers - * for the begin and end. - * - * @param pOS - * The output stream - * @param pDoc - * The documents - * @param pOrigin - * The origin of the output stream (request, indication response, - * etc.) - * @throws IOException - */ - public static void dumpDocument(OutputStream pOS, Document pDoc, String pOrigin) - throws IOException { - // debug - if (pOS == null) { return; } - if (pOrigin == null) pOrigin = "unknown"; - pOS.write("<--- ".getBytes()); - pOS.write(pOrigin.getBytes()); - pOS.write(" begin ".getBytes()); - pOS.write(TimeStamp.formatWithMillis(System.currentTimeMillis()).getBytes()); - pOS.write(" -----\n".getBytes()); - CimXmlSerializer.serialize(pOS, pDoc, true); - pOS.write("\n---- ".getBytes()); - pOS.write(pOrigin.getBytes()); - pOS.write(" end ------>\n".getBytes()); - } - - /** - * createCIMMessage - * - * @param pDoc - * @param pRequestE - * @return Element - */ - public Element createCIMMessage(Document pDoc, Element pRequestE) { - Element cimE = CIMXMLBuilderImpl.createCIM(pDoc); - Element messageE = CIMXMLBuilderImpl.createMESSAGE(pDoc, cimE, String.valueOf(getNextId()), - VERSION); - if (pRequestE != null) { - messageE.appendChild(pRequestE); - } - return messageE; - } - - /** - * createMultiReq - * - * @param pDoc - * @return Element - */ - public Element createMultiReq(Document pDoc) { - Element multireqE = CIMXMLBuilderImpl.createMULTIREQ(pDoc); - return multireqE; - } - - /** - * associatorNames_request - * - * @param pDoc - * @param pObjectName - * @param pAssocClass - * @param pResultClass - * @param pRole - * @param pResultRole - * @return Element - * @throws WBEMException - */ - public Element associatorNames_request(Document pDoc, CIMObjectPath pObjectName, - String pAssocClass, String pResultClass, String pRole, String pResultRole) - throws WBEMException { - - // obtain data - String className = pObjectName.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - CIMProperty[] keysA = pObjectName.getKeys(); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - ASSOCIATOR_NAMES); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pObjectName); - - Element iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, "ObjectName"); - Element instancenameE = CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, className); - for (int i = 0; i < keysA.length; i++) { - CIMProperty prop = keysA[i]; - String propName = prop.getName(); - // TODO: check that CIMDataType.toString() satisfies this - String propTypeStr = prop.getDataType().toString(); - String propValueStr = valueStr(prop); - Element keybindingE = CIMXMLBuilderImpl.createKEYBINDING(pDoc, instancenameE, propName); - CIMXMLBuilderImpl.createKEYVALUE(pDoc, keybindingE, propTypeStr, propValueStr); - } - if (pAssocClass != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "AssocClass"); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pAssocClass); - } - if (pResultClass != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultClass"); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); - } - if (pRole != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "Role"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); - } - if (pResultRole != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultRole"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pResultRole); - } - - return simplereqE; - } - - /** - * associatorNames_response - * - * @param pDoc - * @param pPathA - * @return Element - */ - public static Element associatorNames_response(Document pDoc, CIMObjectPath[] pPathA) { - Element simpRspE = CIMXMLBuilderImpl.createSIMPLERSP(pDoc, null); - Element iMethRspE = CIMXMLBuilderImpl.createIMETHODRESPONSE(pDoc, simpRspE, - "associatorNames"); - Element iRetValE = CIMXMLBuilderImpl.createIRETURNVALUE(pDoc, iMethRspE); - try { - for (int i = 0; i < pPathA.length; i++) { - CIMXMLBuilderImpl.createOBJECTPATH(pDoc, iRetValE, pPathA[i]); - } - } catch (WBEMException e) { - throw new RuntimeException(e); - } - return simpRspE; - } - - /** - * associatorInstances_request - * - * @param pDoc - * @param pObjectName - * @param pAssocClass - * @param pResultClass - * @param pRole - * @param pResultRole - * @param pIncludeClassOrigin - * @param pPropertyList - * @return Element - * @throws WBEMException - */ - public Element associatorInstances_request(Document pDoc, CIMObjectPath pObjectName, - String pAssocClass, String pResultClass, String pRole, String pResultRole, - boolean pIncludeClassOrigin, String[] pPropertyList) throws WBEMException { - - String className = pObjectName.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - CIMProperty[] keysA = pObjectName.getKeys(); - - // Make sure keys are populated - if (keysA.length == 0) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "associatorInstances requires keys for the instance to be populated"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "Associators"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pObjectName); - Element iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, "ObjectName"); - Element instancenameE = CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, className); - for (int i = 0; i < keysA.length; i++) { - CIMProperty prop = keysA[i]; - String propName = prop.getName(); - String propTypeStr = prop.getDataType().toString(); - String propValueStr = valueStr(prop); - - Element keybindingE = CIMXMLBuilderImpl.createKEYBINDING(pDoc, instancenameE, propName); - CIMXMLBuilderImpl.createKEYVALUE(pDoc, keybindingE, propTypeStr, propValueStr); - } - if (pAssocClass != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "AssocClass"); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pAssocClass); - } - if (pResultClass != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultClass"); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); - } - if (pRole != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "Role"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); - } - if (pResultRole != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultRole"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pResultRole); - } - - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, "IncludeClassOrigin"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); - - if (pPropertyList != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyList"); - Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); - for (int i = 0; i < pPropertyList.length; i++) { - CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); - } - } - - return simplereqE; - } - - /** - * associatorClasses_request - * - * @param pDoc - * @param pObjectName - * @param pAssocClass - * @param pResultClass - * @param pRole - * @param pResultRole - * @param pIncludeQualifiers - * @param pIncludeClassOrigin - * @param pPropertyList - * @return Element - * @throws WBEMException - */ - public Element associatorClasses_request(Document pDoc, CIMObjectPath pObjectName, - String pAssocClass, String pResultClass, String pRole, String pResultRole, - boolean pIncludeQualifiers, boolean pIncludeClassOrigin, String[] pPropertyList) - throws WBEMException { - - String className = pObjectName.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - // Make sure keys are not populated - if (pObjectName.getKeys().length != 0) throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, - "Keys should not be populated for associatorClasses"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "Associators"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pObjectName); - Element iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, "ObjectName"); - - CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, className); - - if (pAssocClass != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "AssocClass"); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pAssocClass); - } - if (pResultClass != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultClass"); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); - } - if (pRole != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "Role"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); - } - if (pResultRole != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultRole"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pResultRole); - } - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeQualifiers"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeQualifiers); - - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, "IncludeClassOrigin"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); - - if (pPropertyList != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyList"); - Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); - for (int i = 0; i < pPropertyList.length; i++) { - CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); - } - } - - return simplereqE; - } - - /** - * associators_request - * - * @param pDoc - * @param pObjectName - * @param pAssocClass - * @param pResultClass - * @param pRole - * @param pResultRole - * @param pIncludeQualifiers - * @param pIncludeClassOrigin - * @param pPropertyList - * @return Element - * @throws WBEMException - */ - public Element associators_request(Document pDoc, CIMObjectPath pObjectName, - String pAssocClass, String pResultClass, String pRole, String pResultRole, - boolean pIncludeQualifiers, boolean pIncludeClassOrigin, String[] pPropertyList) - throws WBEMException { - - // obtain data - String className = pObjectName.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - CIMProperty[] keysA = pObjectName.getKeys(); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "Associators"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pObjectName); - Element iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, "ObjectName"); - Element instancenameE = CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, className); - for (int i = 0; i < keysA.length; i++) { - CIMProperty prop = keysA[i]; - String propName = prop.getName(); - // TODO: check that CIMDataType.toString() satisfies this - String propTypeStr = prop.getDataType().toString(); - // CIMXMLBuilderImpl.getTypeStr(pValue.getType()); - String propValueStr = valueStr(prop); - - Element keybindingE = CIMXMLBuilderImpl.createKEYBINDING(pDoc, instancenameE, propName); - CIMXMLBuilderImpl.createKEYVALUE(pDoc, keybindingE, propTypeStr, propValueStr); - } - if (pAssocClass != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "AssocClass"); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pAssocClass); - } - if (pResultClass != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultClass"); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); - } - if (pRole != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "Role"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); - } - if (pResultRole != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultRole"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pResultRole); - } - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeQualifiers"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeQualifiers); - - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, "IncludeClassOrigin"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); - - if (pPropertyList != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyList"); // BB - // fixed - Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); - for (int i = 0; i < pPropertyList.length; i++) { - CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); - } - } - - return simplereqE; - } - - /** - * associators_response - * - * @param pDoc - * @param pNamedElementA - * @return Element - */ - public static Element associators_response(Document pDoc, - CIMNamedElementInterface[] pNamedElementA) { - Element simpRspE = CIMXMLBuilderImpl.createSIMPLERSP(pDoc, null); - Element iMethRspE = CIMXMLBuilderImpl.createIMETHODRESPONSE(pDoc, simpRspE, "associators"); - Element iRetValE = CIMXMLBuilderImpl.createIRETURNVALUE(pDoc, iMethRspE); - try { - for (int i = 0; i < pNamedElementA.length; i++) { - CIMNamedElementInterface namedElement = pNamedElementA[i]; - CIMObjectPath op = namedElement.getObjectPath(); - String nameSpace = op == null ? null : op.getNamespace(); - CIMXMLBuilderImpl - .createVALUEOBJECTWITHPATH(pDoc, iRetValE, namedElement, nameSpace); - /* - * CIMXMLBuilderImpl.createCLASSPATH( pDoc, iRetValE, - * pClassA[i].getObjectPath() ); - * CIMXMLBuilderImpl.createCLASS(pDoc, iRetValE, pClassA[i]); - */ - - } - } catch (WBEMException e) { - throw new RuntimeException(e); - } - return simpRspE; - } - - /** - * enumerateInstanceNames_request - * - * @param pDoc - * @param pPath - * @return Element - * @throws WBEMException - */ - public Element enumerateInstanceNames_request(Document pDoc, CIMObjectPath pPath) - throws WBEMException { - // obtain data - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - "EnumerateInstanceNames"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ClassName"); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, className); - - return simplereqE; - } - - /** - * enumerateInstances_request - * - * @param pDoc - * @param pPath - * @param pDeepInheritance - * @param pLocalOnly - * @param pIncludeQualifiers - * @param pIncludeClassOrigin - * @param pPropertyList - * @return Element - * @throws WBEMException - */ - public Element enumerateInstances_request(Document pDoc, CIMObjectPath pPath, - boolean pDeepInheritance, boolean pLocalOnly, boolean pIncludeQualifiers, - boolean pIncludeClassOrigin, String[] pPropertyList) throws WBEMException { - - // obtain data - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - "EnumerateInstances"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ClassName"); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, className); - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "LocalOnly"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pLocalOnly); - - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "DeepInheritance"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pDeepInheritance); - - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeQualifiers"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeQualifiers); - - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, "IncludeClassOrigin"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); - - if (pPropertyList != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyList"); - Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); - for (int i = 0; i < pPropertyList.length; i++) { - CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); - } - } - return simplereqE; - } - - /** - * getInstance_request - * - * @param pDoc - * @param pName - * @param pLocalOnly - * @param pIncludeQualifiers - * @param pIncludeClassOrigin - * @param pPropertyList - * @return Element - * @throws WBEMException - */ - public Element getInstance_request(Document pDoc, CIMObjectPath pName, boolean pLocalOnly, - boolean pIncludeQualifiers, boolean pIncludeClassOrigin, String[] pPropertyList) - throws WBEMException { - // obtain data - String className = pName.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "GetInstance"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pName); - - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - "InstanceName"); - CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, pName); - - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "LocalOnly"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pLocalOnly); - - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeQualifiers"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeQualifiers); - - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, "IncludeClassOrigin"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); - - if (pPropertyList != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyList"); - Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); - for (int i = 0; i < pPropertyList.length; i++) { - CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); - } - } - - return simplereqE; - } - - /** - * deleteInstance_request - * - * @param pDoc - * @param pName - * @return Element - * @throws WBEMException - */ - public Element deleteInstance_request(Document pDoc, CIMObjectPath pName) throws WBEMException { - - // obtain data - String className = pName.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - "DeleteInstance"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pName); - - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - "InstanceName"); - CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, pName); - - return simplereqE; - } - - /** - * getClass_request - * - * @param pDoc - * @param pName - * @param pLocalOnly - * @param pIncludeQualifiers - * @param pIncludeClassOrigin - * @param pPropertyList - * @return Element - * @throws WBEMException - */ - public Element getClass_request(Document pDoc, CIMObjectPath pName, boolean pLocalOnly, - boolean pIncludeQualifiers, boolean pIncludeClassOrigin, String[] pPropertyList) - throws WBEMException { - - // obtain data - String className = pName.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "GetClass"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pName); - - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ClassName"); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, className); - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "LocalOnly"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pLocalOnly); - - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeQualifiers"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeQualifiers); - - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, "IncludeClassOrigin"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); - - if (pPropertyList != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyList"); - Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); - for (int i = 0; i < pPropertyList.length; i++) { - CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); - } - } - - return simplereqE; - } - - /** - * createInstance_request - * - * @param pDoc - * @param pName - * @param pInstance - * @return Element - * @throws WBEMException - */ - public Element createInstance_request(Document pDoc, CIMObjectPath pName, CIMInstance pInstance) - throws WBEMException { - - String className = pInstance.getObjectPath().getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - "CreateInstance"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pName); - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - "NewInstance"); - - CIMXMLBuilderImpl.createINSTANCE(pDoc, iparamvalueE, pInstance); - - return simplereqE; - } - - /** - * invokeMethod_request - * - * @param pDoc - * @param pLocalPath - * @param pMethodName - * @param pInArgs - * @return Element - * @throws WBEMException - */ - public Element invokeMethod_request(Document pDoc, CIMObjectPath pLocalPath, - String pMethodName, CIMArgument[] pInArgs) throws WBEMException { - - // obtain data - String className = pLocalPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - CIMProperty[] keysA = pLocalPath.getKeys(); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element methodcallE = CIMXMLBuilderImpl.createMETHODCALL(pDoc, simplereqE, pMethodName); - - // 13521 - if (keysA.length > 0) { - Element localpathE = CIMXMLBuilderImpl.createLOCALINSTANCEPATH(pDoc, methodcallE); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, localpathE, pLocalPath); // 13521 - CIMXMLBuilderImpl.createINSTANCENAME(pDoc, localpathE, pLocalPath); // 13521 - } else { - CIMXMLBuilderImpl.createLOCALCLASSPATH(pDoc, methodcallE, pLocalPath); - } - - buildParamValues(pDoc, methodcallE, pLocalPath, pInArgs); - - return simplereqE; - } - - /** - * invokeMethod_response - * - * @param pDoc - * @param pMethodName - * @param pLocalPath - * @param pRetVal - * @param pOutArgA - * @return Element - * @throws WBEMException - */ - public static Element invokeMethod_response(Document pDoc, String pMethodName, - CIMObjectPath pLocalPath, Object pRetVal, CIMArgument[] pOutArgA) - throws WBEMException { - if (pMethodName == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null method name"); - Element simpleRspE = CIMXMLBuilderImpl.createSIMPLERSP(pDoc, null); - Element methodRspE = CIMXMLBuilderImpl.createMETHODRESPONSE(pDoc, simpleRspE, pMethodName); - - CIMXMLBuilderImpl.createRETURNVALUE(pDoc, methodRspE, pRetVal); - - buildParamValues(pDoc, methodRspE, pLocalPath, pOutArgA); - return simpleRspE; - } - - /** - * @param pLocalPath - */ - private static void buildParamValues(Document pDoc, Element pParentE, CIMObjectPath pLocalPath, - CIMArgument[] pArgA) throws WBEMException { - if (pArgA == null) return; - for (int i = 0; i < pArgA.length; i++) { - CIMArgument arg = pArgA[i]; - if (arg == null) continue; - CIMXMLBuilderImpl.createPARAMVALUE(pDoc, pParentE, arg); - } - } - - // public CIMResponse createIndication_request(Document doc) throws - // CIMXMLParseException, CIMException { - // Element rootE = doc.getDocumentElement(); - // CIMResponse response = (CIMResponse)xmlParser.parseCIM(rootE); - // response.checkError(); - // return response; - // // Vector v = (Vector)response.getFirstReturnValue(); - // // - // // //TODO: Should we return the whole list of instances or just the first - // instance? - // // //TODO: return the whole vector of indications - // // if (v.size() > 0) - // // return (CIMInstance)v.elementAt(0); - // // else - // // return null; - // } - - /** - * createIndication_response - * - * @param error - * @return Document - */ - public Document createIndication_response(CIMError error) { - - // CIMXMLBuilderImpl.create XML - Document doc = this.iBuilder.newDocument(); - Element cimE = CIMXMLBuilderImpl.createCIM(doc); - Element messageE = CIMXMLBuilderImpl.createMESSAGE(doc, cimE, String.valueOf(getNextId()), - "1.0"); - Element simpleexprspE = CIMXMLBuilderImpl.createSIMPLEEXPRSP(doc, messageE); - Element expmethodresponseE = CIMXMLBuilderImpl.createEXPMETHODRESPONSE(doc, simpleexprspE, - "ExportIndication"); - if (error == null) { - CIMXMLBuilderImpl.createIRETURNVALUE(doc, expmethodresponseE); - } else { - CIMXMLBuilderImpl.createERROR(doc, expmethodresponseE, error); - } - // Element - return doc; - } - - /** - * createClass_request - * - * @param pDoc - * @param pPath - * @param pClass - * @return Element - * @throws WBEMException - */ - public Element createClass_request(Document pDoc, CIMObjectPath pPath, CIMClass pClass) - throws WBEMException { - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "CreateClass"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "NewClass"); - - CIMXMLBuilderImpl.createCLASS(pDoc, iparamvalueE, pClass); - - return simplereqE; - } - - /** - * getQualifier_request - * - * @param pDoc - * @param pPath - * @param pQt - * @return Element - * @throws WBEMException - */ - public Element getQualifier_request(Document pDoc, CIMObjectPath pPath, String pQt) - throws WBEMException { - // obtain data - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl - .createIMETHODCALL(pDoc, simplereqE, "GetQualifier"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - "QualifierName"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pPath.getObjectName()); - - return simplereqE; - } - - /** - * createQualifierType_request : This has been replaced by - * setQualifierType_request - * - * @param pDoc - * @param pPath - * @param pQt - * @return Element - * @throws WBEMException - */ - public Element createQualifierType_request(Document pDoc, CIMObjectPath pPath, - CIMQualifierType pQt) throws WBEMException { - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl - .createIMETHODCALL(pDoc, simplereqE, "SetQualifier"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - "QualifierDeclaration"); - CIMXMLBuilderImpl.createQUALIFIER_DECLARATION(pDoc, iparamvalueE, pQt); - - return simplereqE; - } - - /** - * deleteClass_request - * - * @param pDoc - * @param pPath - * @return Element - * @throws WBEMException - */ - public Element deleteClass_request(Document pDoc, CIMObjectPath pPath) throws WBEMException { - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "DeleteClass"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ClassName"); - - CIMXMLBuilderImpl.createOBJECTNAME(pDoc, iparamvalueE, pPath); - - return simplereqE; - } - - /** - * deleteQualifierType_request - * - * @param pDoc - * @param pPath - * @return Element - * @throws WBEMException - */ - public Element deleteQualifierType_request(Document pDoc, CIMObjectPath pPath) - throws WBEMException { - // obtain data - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - "DeleteQualifier"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - "QualifierName"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pPath.getObjectName()); - return simplereqE; - } - - /** - * enumerateClasses_request - * - * @param pDoc - * @param pPath - * @param pDeepInheritance - * @param pLocalOnly - * @param pIncludeQualifiers - * @param pIncludeClassOrigin - * @return Element - */ - public Element enumerateClasses_request(Document pDoc, CIMObjectPath pPath, - boolean pDeepInheritance, boolean pLocalOnly, boolean pIncludeQualifiers, - boolean pIncludeClassOrigin) { - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - "EnumerateClasses"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE; - if (pPath != null && pPath.getObjectName() != null - && pPath.getObjectName().trim().length() != 0) { - String className = pPath.getObjectName(); - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ClassName"); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, className); - } - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "LocalOnly"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pLocalOnly); - - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "DeepInheritance"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pDeepInheritance); - - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeQualifiers"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeQualifiers); - - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, "IncludeClassOrigin"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); - return simplereqE; - } - - /** - * enumerateClasses_response - * - * @param pDoc - * @param pClA - * @return Element - */ - public static Element enumerateClasses_response(Document pDoc, CIMClass[] pClA) { - Element simpRspE = CIMXMLBuilderImpl.createSIMPLERSP(pDoc, null); - Element iMethRspE = CIMXMLBuilderImpl.createIMETHODRESPONSE(pDoc, simpRspE, - "enumerateClasses"); - Element iRetValE = CIMXMLBuilderImpl.createIRETURNVALUE(pDoc, iMethRspE); - try { - for (int i = 0; i < pClA.length; i++) { - CIMXMLBuilderImpl.createCLASS(pDoc, iRetValE, pClA[i]); - } - } catch (WBEMException e) { - throw new RuntimeException(e); - } - return simpRspE; - } - - /** - * enumerateInstances_response - * - * @param pDoc - * @param pInstA - * @return Element - */ - public static Element enumerateInstances_response(Document pDoc, CIMInstance[] pInstA) { - Element simpRspE = CIMXMLBuilderImpl.createSIMPLERSP(pDoc, null); - Element iMethRspE = CIMXMLBuilderImpl.createIMETHODRESPONSE(pDoc, simpRspE, - "enumerateInstances"); - Element iRetValE = CIMXMLBuilderImpl.createIRETURNVALUE(pDoc, iMethRspE); - try { - for (int i = 0; i < pInstA.length; i++) { - CIMXMLBuilderImpl.createINSTANCE(pDoc, iRetValE, pInstA[i]); - } - } catch (WBEMException e) { - throw new RuntimeException(e); - } - return simpRspE; - } - - /** - * enumerateClassNames_request - * - * @param pDoc - * @param pPath - * @param pDeepInheritance - * @return Element - */ - public Element enumerateClassNames_request(Document pDoc, CIMObjectPath pPath, - boolean pDeepInheritance) { - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - "EnumerateClassNames"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE; - - if (pPath != null && pPath.getObjectName() != null - && pPath.getObjectName().trim().length() != 0) { - String className = pPath.getObjectName(); - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ClassName"); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, className); - } - - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "DeepInheritance"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pDeepInheritance); - - return simplereqE; - } - - /** - * getProperty_request - * - * @param pDoc - * @param pPath - * @param pPropertyName - * @return Element - * @throws WBEMException - */ - public Element getProperty_request(Document pDoc, CIMObjectPath pPath, String pPropertyName) - throws WBEMException { - // obtain data - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "GetProperty"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - "InstanceName"); - CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, pPath); - - if (pPropertyName != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyName"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pPropertyName); - } - - return simplereqE; - } - - /** - * referenceNames_request - * - * @param pDoc - * @param pPath - * @param pResultClass - * @param pRole - * @return Element - * @throws WBEMException - */ - public Element referenceNames_request(Document pDoc, CIMObjectPath pPath, String pResultClass, - String pRole) throws WBEMException { - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - "ReferenceNames"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, "ObjectName"); - CIMXMLBuilderImpl.createOBJECTNAME(pDoc, iparamvalueE, pPath); - - if (pResultClass != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultClass"); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); - } - if (pRole != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "Role"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); - } - - return simplereqE; - } - - /** - * referenceClasses_request - * - * @param pDoc - * @param pPath - * @param pResultClass - * @param pRole - * @param pIncludeQualifiers - * @param pIncludeClassOrigin - * @param pPropertyList - * @return Element - * @throws WBEMException - */ - public Element referenceClasses_request(Document pDoc, CIMObjectPath pPath, - String pResultClass, String pRole, boolean pIncludeQualifiers, - boolean pIncludeClassOrigin, String[] pPropertyList) throws WBEMException { - - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - // Make sure keys are not populated - if (pPath.getKeys().length != 0) throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, - "Keys should not be populated for referenceClasses"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "References"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, "ObjectName"); - // createOBJECTNAME will internally call createINSTANCENAME but as there - // are no keys Element containing keys will not be populated - CIMXMLBuilderImpl.createOBJECTNAME(pDoc, iparamvalueE, pPath); - - if (pResultClass != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultClass"); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); - } - if (pRole != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "Role"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); - } - - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeQualifiers"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeQualifiers); - - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, "IncludeClassOrigin"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); - - if (pPropertyList != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyList"); - Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); - for (int i = 0; i < pPropertyList.length; i++) { - CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); - } - } - return simplereqE; - } - - /** - * referenceInstances_request - * - * @param pDoc - * @param pPath - * @param pResultClass - * @param pRole - * @param pIncludeClassOrigin - * @param pPropertyList - * @return Element - * @throws WBEMException - */ - public Element referenceInstances_request(Document pDoc, CIMObjectPath pPath, - String pResultClass, String pRole, boolean pIncludeClassOrigin, String[] pPropertyList) - throws WBEMException { - - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - // keys are required for CIMInstance - if (pPath.getKeys().length == 0) throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, - "refrenceInstances requires keys for the instance to be populated"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "References"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, "ObjectName"); - // createOBJECTNAME will internally call createINSTANCENAME to populate - // Element containing keys - CIMXMLBuilderImpl.createOBJECTNAME(pDoc, iparamvalueE, pPath); - - if (pResultClass != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultClass"); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); - } - if (pRole != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "Role"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); - } - - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, "IncludeClassOrigin"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); - - if (pPropertyList != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyList"); - Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); - for (int i = 0; i < pPropertyList.length; i++) { - CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); - } - } - return simplereqE; - } - - /** - * references_request - * - * @param pDoc - * @param pPath - * @param pResultClass - * @param pRole - * @param pIncludeQualifiers - * @param pIncludeClassOrigin - * @param pPropertyList - * @return Element - * @throws WBEMException - */ - public Element references_request(Document pDoc, CIMObjectPath pPath, String pResultClass, - String pRole, boolean pIncludeQualifiers, boolean pIncludeClassOrigin, - String[] pPropertyList) throws WBEMException { - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "References"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE; - - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ObjectName"); - CIMXMLBuilderImpl.createOBJECTNAME(pDoc, iparamvalueE, pPath); - - if (pResultClass != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultClass"); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); - } - if (pRole != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "Role"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); - } - - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeQualifiers"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeQualifiers); - - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, "IncludeClassOrigin"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); - - if (pPropertyList != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyList"); - Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); - for (int i = 0; i < pPropertyList.length; i++) { - CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); - } - } - - return simplereqE; - } - - /** - * setClass_request - * - * @param pDoc - * @param pPath - * @param pClass - * @return Element - * @throws WBEMException - */ - public Element setClass_request(Document pDoc, CIMObjectPath pPath, CIMClass pClass) - throws WBEMException { - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "ModifyClass"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - "ModifiedClass"); - CIMXMLBuilderImpl.createCLASS(pDoc, iparamvalueE, pClass); - - return simplereqE; - } - - /** - * setInstance_request - * - * @param pDoc - * @param pPath - * @param pInstance - * @param pIncludeQualifiers - * @param pPropertyList - * @return Element - * @throws WBEMException - */ - public Element setInstance_request(Document pDoc, CIMObjectPath pPath, CIMInstance pInstance, - boolean pIncludeQualifiers, String[] pPropertyList) throws WBEMException { - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - "ModifyInstance"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - "ModifiedInstance"); - CIMXMLBuilderImpl.createVALUENAMEDINSTANCE(pDoc, iparamvalueE, pPath, pInstance); - - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeQualifiers"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeQualifiers); - - if (pPropertyList != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyList"); - Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); - for (int i = 0; i < pPropertyList.length; i++) { - CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); - } - } - - return simplereqE; - } - - /** - * setProperty_request - * - * @param pDoc - * @param pPath - * @param pPropertyName - * @param pNewValue - * @return Element - * @throws WBEMException - */ - public Element setProperty_request(Document pDoc, CIMObjectPath pPath, String pPropertyName, - Object pNewValue) throws WBEMException { - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "SetProperty"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - "InstanceName"); - CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, pPath); - - if (pPropertyName != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyName"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pPropertyName); - } - - if (pNewValue != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "NewValue"); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pNewValue); - } - - return simplereqE; - } - - /** - * setQualifierType_request - * - * @param pDoc - * @param pPath - * @param pQt - * @return Element - * @throws WBEMException - */ - public Element setQualifierType_request(Document pDoc, CIMObjectPath pPath, - CIMQualifierType pQt) throws WBEMException { - // Make sure class name exists, it is required to uniquely identify - // qualifier in namespace - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl - .createIMETHODCALL(pDoc, simplereqE, "SetQualifier"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - "QualifierDeclaration"); - CIMXMLBuilderImpl.createQUALIFIER_DECLARATION(pDoc, iparamvalueE, pQt); - - return simplereqE; - } - - /** - * enumQualifierTypes_request - * - * @param pDoc - * @param pPath - * @return Element - * @throws WBEMException - */ - public Element enumQualifierTypes_request(Document pDoc, CIMObjectPath pPath) - throws WBEMException { - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - "EnumerateQualifiers"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - return simplereqE; - } - - /** - * enumQualifierTypes_response - * - * @param pDoc - * @param pQualiTypeA - * @return Element - * @throws WBEMException - */ - public static Element enumQualifierTypes_response(Document pDoc, - CIMQualifierType[] pQualiTypeA) throws WBEMException { - Element simpRspE = CIMXMLBuilderImpl.createSIMPLERSP(pDoc, null); - Element iMethRspE = CIMXMLBuilderImpl.createIMETHODRESPONSE(pDoc, simpRspE, - "associatorNames"); - Element iRetValE = CIMXMLBuilderImpl.createIRETURNVALUE(pDoc, iMethRspE); - for (int i = 0; i < pQualiTypeA.length; i++) { - CIMXMLBuilderImpl.createQUALIFIER_DECLARATION(pDoc, iRetValE, pQualiTypeA[i]); - } - return simpRspE; - } - - /** - * execQuery_request - * - * @param pDoc - * @param pPath - * @param pQuery - * @param pQueryLanguage - * @return Element - */ - public Element execQuery_request(Document pDoc, CIMObjectPath pPath, String pQuery, - String pQueryLanguage) { - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "ExecQuery"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element querylanguageE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - "QueryLanguage"); - CIMXMLBuilderImpl.createVALUE(pDoc, querylanguageE, pQueryLanguage); - - Element queryE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "Query"); - CIMXMLBuilderImpl.createVALUE(pDoc, queryE, pQuery); - - return simplereqE; - } - - /** - * performBatchOperation_request - * - * @param pDoc - * @param pOperations - * @return Element - * @throws WBEMException - */ - public Element performBatchOperation_request(Document pDoc, Vector pOperations) - throws WBEMException { - - Element messageE = createCIMMessage(pDoc, null); - if (pOperations.size() > 1) { - Element multireqE = createMultiReq(pDoc); - messageE.appendChild(multireqE); - messageE = multireqE; - } - int i = 0; - Iterator iter = pOperations.iterator(); - while (iter.hasNext()) { - CIMOperation op = iter.next(); - try { - Element requestE = null; - - if (op instanceof CIMAssociatorsOp) { - CIMAssociatorsOp associatorsOp = (CIMAssociatorsOp) op; - requestE = associators_request(pDoc, associatorsOp.getObjectName(), - associatorsOp.getAssocClass(), associatorsOp.getResultClass(), - associatorsOp.getRole(), associatorsOp.getResultRole(), associatorsOp - .isIncludeQualifiers(), associatorsOp.isIncludeClassOrigin(), - associatorsOp.getPropertyList()); - } else if (op instanceof CIMAssociatorNamesOp) { - CIMAssociatorNamesOp associatorNamesOp = (CIMAssociatorNamesOp) op; - requestE = associatorNames_request(pDoc, associatorNamesOp.getObjectName(), - associatorNamesOp.getAssocClass(), associatorNamesOp.getResultClass(), - associatorNamesOp.getRole(), associatorNamesOp.getResultRole()); - } else if (op instanceof CIMCreateClassOp) { - CIMCreateClassOp createClassOp = (CIMCreateClassOp) op; - requestE = createClass_request(pDoc, createClassOp.getObjectName(), - createClassOp.getCimClass()); - } else if (op instanceof CIMCreateInstanceOp) { - CIMCreateInstanceOp createInstanceOp = (CIMCreateInstanceOp) op; - requestE = createInstance_request(pDoc, createInstanceOp.getObjectName(), - createInstanceOp.getInstance()); - } else if (op instanceof CIMCreateNameSpaceOp) { - CIMCreateNameSpaceOp createNameSpaceOp = (CIMCreateNameSpaceOp) op; - - String namespace = createNameSpaceOp.getNameSpace(); - int j = namespace.lastIndexOf('/'); - - if (j < 0) throw new WBEMException(WBEMException.CIM_ERR_NOT_FOUND, - "Invalid namespace. Must contain at least /"); - String parentNs = namespace.substring(0, j); - namespace = namespace.substring(j + 1); - - /* - * CIMInstance inst = new CIMInstance(); - * inst.setClassName("CIM_NameSpace"); CIMProperty prop = - * new CIMProperty("NameSpace"); prop.setValue(new - * CIMValue(namespace, CIMDataType - * .getPredefinedType(CIMDataType.STRING))); Vector v = new - * Vector(); v.add(prop); inst.setProperties(v); - */ - - CIMInstance inst = new CIMInstance(new CIMObjectPath(null, null, null, null, - "CIM_NameSpace", null), new CIMProperty[] { new CIMProperty( - "NameSpace", CIMDataType.STRING_T, namespace, true, false, null) }); - CIMObjectPath object = new CIMObjectPath(null, null, null, parentNs, null, null); - - requestE = createInstance_request(pDoc, object, inst); - } else if (op instanceof CIMCreateQualifierTypeOp) { - CIMCreateQualifierTypeOp createQualifierTypeOp = (CIMCreateQualifierTypeOp) op; - requestE = createQualifierType_request(pDoc, createQualifierTypeOp - .getObjectName(), createQualifierTypeOp.getQualifierType()); - } else if (op instanceof CIMDeleteClassOp) { - CIMDeleteClassOp deleteClassOp = (CIMDeleteClassOp) op; - requestE = deleteClass_request(pDoc, deleteClassOp.getObjectName()); - } else if (op instanceof CIMDeleteInstanceOp) { - CIMDeleteInstanceOp deleteInstanceOp = (CIMDeleteInstanceOp) op; - requestE = deleteClass_request(pDoc, deleteInstanceOp.getObjectName()); - } else if (op instanceof CIMDeleteQualifierTypeOp) { - CIMDeleteQualifierTypeOp deleteQualifierTypeOp = (CIMDeleteQualifierTypeOp) op; - requestE = deleteClass_request(pDoc, deleteQualifierTypeOp.getObjectName()); - } else if (op instanceof CIMEnumClassesOp) { - CIMEnumClassesOp enumClassesOp = (CIMEnumClassesOp) op; - requestE = enumerateClasses_request(pDoc, enumClassesOp.getObjectName(), - enumClassesOp.isDeep(), enumClassesOp.isLocalOnly(), enumClassesOp - .isIncludeQualifiers(), enumClassesOp.isIncludeClassOrigin()); - } else if (op instanceof CIMEnumClassNamesOp) { - CIMEnumClassNamesOp enumClassNamesOp = (CIMEnumClassNamesOp) op; - requestE = enumerateClassNames_request(pDoc, enumClassNamesOp.getObjectName(), - enumClassNamesOp.isDeep()); - } else if (op instanceof CIMEnumInstanceNamesOp) { - CIMEnumInstanceNamesOp enumInstanceNamesOp = (CIMEnumInstanceNamesOp) op; - requestE = enumerateInstanceNames_request(pDoc, enumInstanceNamesOp - .getObjectName()); - } else if (op instanceof CIMEnumInstancesOp) { - CIMEnumInstancesOp enumInstancesOp = (CIMEnumInstancesOp) op; - requestE = enumerateInstances_request(pDoc, enumInstancesOp.getObjectName(), - enumInstancesOp.isDeep(), enumInstancesOp.isLocalOnly(), - enumInstancesOp.isIncludeQualifiers(), enumInstancesOp - .isIncludeClassOrigin(), enumInstancesOp.getPropertyList()); - } else if (op instanceof CIMEnumNameSpaceOp) { - CIMEnumNameSpaceOp enumNameSpaceOp = (CIMEnumNameSpaceOp) op; - // ebak: here we have to set CIMObjectPath's objectname - // enumNameSpaceOp.getObjectName().setObjectName("CIM_NameSpace"); - CIMObjectPath objPath = enumNameSpaceOp.getObjectName(); - objPath = new CIMObjectPath(objPath.getScheme(), objPath.getHost(), objPath - .getPort(), objPath.getNamespace(), "CIM_NameSpace", objPath.getKeys()); - requestE = enumerateInstanceNames_request(pDoc, enumNameSpaceOp.getObjectName()); - } else if (op instanceof CIMEnumQualifierTypesOp) { - CIMEnumQualifierTypesOp enumQualifierTypesOp = (CIMEnumQualifierTypesOp) op; - requestE = enumQualifierTypes_request(pDoc, enumQualifierTypesOp - .getObjectName()); - } else if (op instanceof CIMExecQueryOp) { - CIMExecQueryOp execQueryOp = (CIMExecQueryOp) op; - requestE = execQuery_request(pDoc, execQueryOp.getObjectName(), execQueryOp - .getQuery(), execQueryOp.getQueryLanguage()); - } else if (op instanceof CIMGetPropertyOp) { - CIMGetPropertyOp getPropertyOp = (CIMGetPropertyOp) op; - requestE = getInstance_request(pDoc, getPropertyOp.getObjectName(), false, - false, false, new String[] { getPropertyOp.getPropertyName() }); - - } else if (op instanceof CIMGetClassOp) { - CIMGetClassOp getClassOp = (CIMGetClassOp) op; - requestE = getClass_request(pDoc, getClassOp.getObjectName(), getClassOp - .isLocalOnly(), getClassOp.isIncludeQualifiers(), getClassOp - .isIncludeClassOrigin(), getClassOp.getPropertyList()); - } else if (op instanceof CIMGetInstanceOp) { - CIMGetInstanceOp getInstanceOp = (CIMGetInstanceOp) op; - requestE = getInstance_request(pDoc, getInstanceOp.getObjectName(), - getInstanceOp.isLocalOnly(), getInstanceOp.isIncludeQualifiers(), - getInstanceOp.isIncludeClassOrigin(), getInstanceOp.getPropertyList()); - } else if (op instanceof CIMGetQualifierTypeOp) { - CIMGetQualifierTypeOp getQualifierTypeOp = (CIMGetQualifierTypeOp) op; - requestE = getQualifier_request(pDoc, getQualifierTypeOp.getObjectName(), - getQualifierTypeOp.getQualifierType()); - } else if (op instanceof CIMInvokeMethodOp) { - CIMInvokeMethodOp invokeMethodOp = (CIMInvokeMethodOp) op; - requestE = invokeMethod_request(pDoc, invokeMethodOp.getObjectName(), - invokeMethodOp.getMethodCall(), invokeMethodOp.getInParams()); - } else if (op instanceof CIMReferenceNamesOp) { - CIMReferenceNamesOp referenceNamesOp = (CIMReferenceNamesOp) op; - requestE = referenceNames_request(pDoc, referenceNamesOp.getObjectName(), - referenceNamesOp.getResultClass(), referenceNamesOp.getResultRole()); - } else if (op instanceof CIMReferencesOp) { - CIMReferencesOp referencesOp = (CIMReferencesOp) op; - requestE = references_request(pDoc, referencesOp.getObjectName(), referencesOp - .getResultClass(), referencesOp.getRole(), referencesOp - .isIncludeQualifiers(), referencesOp.isIncludeClassOrigin(), - referencesOp.getPropertyList()); - } else if (op instanceof CIMSetClassOp) { - CIMSetClassOp setClassOp = (CIMSetClassOp) op; - requestE = setClass_request(pDoc, setClassOp.getObjectName(), setClassOp - .getCimClass()); - } else if (op instanceof CIMSetInstanceOp) { - CIMSetInstanceOp setInstanceOp = (CIMSetInstanceOp) op; - requestE = setInstance_request(pDoc, setInstanceOp.getObjectName(), - setInstanceOp.getInstance(), setInstanceOp.isIncludeQualifiers(), - setInstanceOp.getPropertyList()); - } else if (op instanceof CIMSetPropertyOp) { - CIMSetPropertyOp setPropertyOp = (CIMSetPropertyOp) op; - requestE = setProperty_request(pDoc, setPropertyOp.getObjectName(), - setPropertyOp.getPropertyName(), setPropertyOp.getCimValue()); - } else if (op instanceof CIMSetQualifierTypeOp) { - CIMSetQualifierTypeOp setQualifierTypeOp = (CIMSetQualifierTypeOp) op; - requestE = setQualifierType_request(pDoc, setQualifierTypeOp.getObjectName(), - setQualifierTypeOp.getQualifierType()); - } - if (requestE == null) throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, "Illegal batch operation number (" - + i + ") " + op.getClass()); - messageE.appendChild(requestE); - } catch (WBEMException e) { - throw e; - } catch (Exception e) { - throw new WBEMException(WBEMException.CIM_ERR_FAILED, "At batch operation (" + i - + ')', null, e); - } - i++; - } - return messageE; - } - - /** - * Sets the message id counter to a given value. For use in units tests - * only. - * - * @param pId - * The new value - */ - public void setId(int pId) { - this.iCurrentId.set(new Counter(pId - 1)); - } - - /** - * Get the next message id. If this method is called for the first time by - * the current thread it will choose a start value randomly. Afterwards the - * id is incremented by 1. Be aware that different threads will have - * distinct id counters. - * - * @return The next message id - */ - private int getNextId() { - if (this.iCurrentId.get() == null) { - this.iCurrentId.set(new Counter(RANDOM.nextInt(MAX_ID))); - } - return this.iCurrentId.get().incrementAndGet(); - } - - /** - * pAssociatorPaths_request - * - * @param pDoc - * @param pPath - * @param pAssocClass - * @param pResultClass - * @param pRole - * @param pResultRole - * @param pFilterQueryLanguage - * @param pFilterQuery - * @param pOperationTimeout - * @param pContinueOnError - * @param pMaxObjectCount - * @return Element - * @throws WBEMException - */ - public Element OpenAssociatorInstancePaths_request(Document pDoc, CIMObjectPath pPath, - String pAssocClass, String pResultClass, String pRole, String pResultRole, - String pFilterQueryLanguage, String pFilterQuery, UnsignedInteger32 pOperationTimeout, - boolean pContinueOnError, UnsignedInteger32 pMaxObjectCount) throws WBEMException { - - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - "OpenAssociatorInstancePaths"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - INSTANCE_NAME); - CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, pPath); - - if (pAssocClass != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, ASSOC_CLASS); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pAssocClass); - } - if (pResultClass != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, RESULT_CLASS); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); - } - if (pRole != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, ROLE); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); - } - if (pResultRole != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, RESULT_ROLE); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pResultRole); - } - if (pFilterQueryLanguage != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - FILTER_QUERY_LANGUAGE); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQueryLanguage); - } - if (pFilterQuery != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, FILTER_QUERY); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQuery); - } - if (pOperationTimeout != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - OPERATION_TIMEOUT); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pOperationTimeout); - } - - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, CONTINUE_ON_ERROR); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pContinueOnError); - - if (pMaxObjectCount != null) { - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, MAX_OBJECT_COUNT); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pMaxObjectCount); - } - - return simplereqE; - } - - /** - * OpenAssociatorInstances_request - * - * @param pDoc - * @param pPath - * @param pAssocClass - * @param pResultClass - * @param pRole - * @param pResultRole - * @param pIncludeClassOrigin - * @param pPropertyList - * @param pFilterQueryLanguage - * @param pFilterQuery - * @param pOperationTimeout - * @param pContinueOnError - * @param pMaxObjectCount - * @return Element OpenAssociatorInstances_request - * @throws WBEMException - */ - public Element OpenAssociatorInstances_request(Document pDoc, CIMObjectPath pPath, - String pAssocClass, String pResultClass, String pRole, String pResultRole, - boolean pIncludeClassOrigin, String[] pPropertyList, String pFilterQueryLanguage, - String pFilterQuery, UnsignedInteger32 pOperationTimeout, boolean pContinueOnError, - UnsignedInteger32 pMaxObjectCount) throws WBEMException { - - String className = pPath.getObjectName(); - - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - "OpenAssociatorInstances"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - INSTANCE_NAME); - // createINSTANCENAME will take care of keyBindings - CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, pPath); - - if (pAssocClass != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, ASSOC_CLASS); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pAssocClass); - } - if (pResultClass != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, RESULT_CLASS); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); - } - if (pRole != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, ROLE); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); - } - if (pResultRole != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, RESULT_ROLE); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pResultRole); - } - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, INCLUDE_CLASS_ORIGIN); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); - - if (pPropertyList != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, PROPERTY_LIST); - Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); - for (int i = 0; i < pPropertyList.length; i++) - CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); - } - if (pFilterQueryLanguage != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - FILTER_QUERY_LANGUAGE); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQueryLanguage); - } - if (pFilterQuery != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, FILTER_QUERY); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQuery); - } - if (pOperationTimeout != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - OPERATION_TIMEOUT); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pOperationTimeout); - } - - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, CONTINUE_ON_ERROR); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pContinueOnError); - - if (pMaxObjectCount != null) { - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, MAX_OBJECT_COUNT); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pMaxObjectCount); - } - - return simplereqE; - } - - /** - * OpenEnumerateInstancePaths_request - * - * @param pDoc - * @param pPath - * @param pFilterQueryLanguage - * @param pFilterQuery - * @param pOperationTimeout - * @param pContinueOnError - * @param pMaxObjectCount - * @return Element - * @throws WBEMException - */ - public Element OpenEnumerateInstancePaths_request(Document pDoc, CIMObjectPath pPath, - String pFilterQueryLanguage, String pFilterQuery, UnsignedInteger32 pOperationTimeout, - boolean pContinueOnError, UnsignedInteger32 pMaxObjectCount) throws WBEMException { - - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - "OpenEnumerateInstancePaths"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, CLASS_NAME); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, className); - - if (pFilterQueryLanguage != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - FILTER_QUERY_LANGUAGE); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQueryLanguage); - } - if (pFilterQuery != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, FILTER_QUERY); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQuery); - } - if (pOperationTimeout != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - OPERATION_TIMEOUT); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pOperationTimeout); - } - - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, CONTINUE_ON_ERROR); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pContinueOnError); - - if (pMaxObjectCount != null) { - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, MAX_OBJECT_COUNT); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pMaxObjectCount); - } - - return simplereqE; - } - - /** - * OpenEnumerateInstances_request - * - * @param pDoc - * @param pPath - * @param pPropertyList - * @param pIncludeClassOrigin - * @param pDeepInheritance - * @param pFilterQueryLanguage - * @param pFilterQuery - * @param pOperationTimeout - * @param pContinueOnError - * @param pMaxObjectCount - * @return Element - * @throws WBEMException - */ - public Element OpenEnumerateInstances_request(Document pDoc, CIMObjectPath pPath, - boolean pDeepInheritance, boolean pIncludeClassOrigin, String[] pPropertyList, - String pFilterQueryLanguage, String pFilterQuery, UnsignedInteger32 pOperationTimeout, - boolean pContinueOnError, UnsignedInteger32 pMaxObjectCount) throws WBEMException { - - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - "OpenEnumerateInstances"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, CLASS_NAME); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, className); - - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, DEEP_INHERITANCE); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pDeepInheritance); - - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, INCLUDE_CLASS_ORIGIN); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); - - if (pPropertyList != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, PROPERTY_LIST); - Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); - for (int i = 0; i < pPropertyList.length; i++) - CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); - } - - if (pFilterQueryLanguage != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - FILTER_QUERY_LANGUAGE); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQueryLanguage); - } - if (pFilterQuery != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, FILTER_QUERY); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQuery); - } - if (pOperationTimeout != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - OPERATION_TIMEOUT); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pOperationTimeout); - } - - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, CONTINUE_ON_ERROR); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pContinueOnError); - - if (pMaxObjectCount != null) { - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, MAX_OBJECT_COUNT); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pMaxObjectCount); - } - - return simplereqE; - } - - /** - * EnumerationCount_request - * - * @param pDoc - * @param pPath - * @param pEnumerationContext - * @return Element - * @throws WBEMException - */ - public Element EnumerationCount_request(Document pDoc, CIMObjectPath pPath, - String pEnumerationContext) throws WBEMException { - - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - "EnumerationCount"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - if (pEnumerationContext != null) { - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - ENUMERATION_CONTEXT); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pEnumerationContext); - } - - return simplereqE; - - } - - /** - * CloseEnumeration_request - * - * @param pDoc - * @param pPath - * @param pEnumerationContext - * @return Element - * @throws WBEMException - */ - public Element CloseEnumeration_request(Document pDoc, CIMObjectPath pPath, - String pEnumerationContext) throws WBEMException { - - String className = pPath.getObjectName(); - - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - "CloseEnumeration"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - if (pEnumerationContext != null) { - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - ENUMERATION_CONTEXT); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pEnumerationContext); - } - return simplereqE; - } - - /** - * referencePaths_request - * - * @param pDoc - * @param pPath - * @param pResultClass - * @param pRole - * @param pFilterQueryLanguage - * @param pFilterQuery - * @param pOperationTimeout - * @param pContinueOnError - * @param pMaxObjectCount - * @return Element referencePaths_request - * @throws WBEMException - */ - public Element OpenReferenceInstancePaths_request(Document pDoc, CIMObjectPath pPath, - String pResultClass, String pRole, String pFilterQueryLanguage, String pFilterQuery, - UnsignedInteger32 pOperationTimeout, boolean pContinueOnError, - UnsignedInteger32 pMaxObjectCount) throws WBEMException { - - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - "OpenReferenceInstancePaths"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - INSTANCE_NAME); - CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, pPath); - - if (pResultClass != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, RESULT_CLASS); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); - } - if (pRole != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, ROLE); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); - } - if (pFilterQueryLanguage != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - FILTER_QUERY_LANGUAGE); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQueryLanguage); - } - if (pFilterQuery != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, FILTER_QUERY); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQuery); - } - if (pOperationTimeout != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - OPERATION_TIMEOUT); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pOperationTimeout); - } - - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, CONTINUE_ON_ERROR); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pContinueOnError); - - if (pMaxObjectCount != null) { - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, MAX_OBJECT_COUNT); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pMaxObjectCount); - } - - return simplereqE; - - } - - /** - * references_request - * - * @param pDoc - * @param pPath - * @param pResultClass - * @param pRole - * @param pIncludeClassOrigin - * @param pPropertyList - * @param pFilterQueryLanguage - * @param pFilterQuery - * @param pOperationTimeout - * @param pContinueOnError - * @param pMaxObjectCount - * @return Element references_request - * @throws WBEMException - */ - public Element OpenReferenceInstances_request(Document pDoc, CIMObjectPath pPath, - String pResultClass, String pRole, boolean pIncludeClassOrigin, String[] pPropertyList, - String pFilterQueryLanguage, String pFilterQuery, UnsignedInteger32 pOperationTimeout, - boolean pContinueOnError, UnsignedInteger32 pMaxObjectCount) throws WBEMException { - - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - "OpenReferenceInstances"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - INSTANCE_NAME); - CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, pPath); - - if (pResultClass != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, RESULT_CLASS); - CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); - } - if (pRole != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, ROLE); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); - } - - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, INCLUDE_CLASS_ORIGIN); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); - - if (pPropertyList != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, PROPERTY_LIST); - Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); - for (int i = 0; i < pPropertyList.length; i++) - CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); - } - - if (pFilterQueryLanguage != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - FILTER_QUERY_LANGUAGE); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQueryLanguage); - } - if (pFilterQuery != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, FILTER_QUERY); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQuery); - } - if (pOperationTimeout != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - OPERATION_TIMEOUT); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pOperationTimeout); - } - - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, CONTINUE_ON_ERROR); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pContinueOnError); - - if (pMaxObjectCount != null) { - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, MAX_OBJECT_COUNT); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pMaxObjectCount); - } - - return simplereqE; - } - - /** - * OpenQueryInstances_request - * - * @param pDoc - * @param pPath - * @param pFilterQuery - * @param pFilterQueryLanguage - * @param pReturnQueryResultClass - * @param pOperationTimeout - * @param pContinueOnError - * @param pMaxObjectCount - * @param pQueryResultClass - * @return Element OpenQueryInstances_request - * @throws WBEMException - */ - public Element OpenQueryInstances_request(Document pDoc, CIMObjectPath pPath, - String pFilterQuery, String pFilterQueryLanguage, boolean pReturnQueryResultClass, - UnsignedInteger32 pOperationTimeout, boolean pContinueOnError, - UnsignedInteger32 pMaxObjectCount, CIMClass pQueryResultClass) throws WBEMException { - - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - "OpenQueryInstances"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE; - - if (pFilterQuery != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, FILTER_QUERY); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQuery); - } - if (pFilterQueryLanguage != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - FILTER_QUERY_LANGUAGE); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQueryLanguage); - } - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - RETURN_QUERY_RESULT_CLASS); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pReturnQueryResultClass); - - if (pOperationTimeout != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - OPERATION_TIMEOUT); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pOperationTimeout); - } - - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, CONTINUE_ON_ERROR); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pContinueOnError); - - if (pMaxObjectCount != null) { - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, MAX_OBJECT_COUNT); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pMaxObjectCount); - } - if (pQueryResultClass != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - QUERY_RESULT_CLASS); - CIMXMLBuilderImpl.createCLASS(pDoc, iparamvalueE, pQueryResultClass); - } - return simplereqE; - } - - /** - * PullInstancesWithPath_request - * - * @param pDoc - * @param pPath - * @param pContext - * @param pMaxObjectCount - * @return Element PullInstancesWithPath_request - * @throws WBEMException - */ - public Element PullInstancesWithPath_request(Document pDoc, CIMObjectPath pPath, - String pContext, UnsignedInteger32 pMaxObjectCount) throws WBEMException { - - String className = pPath.getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - "PullInstancesWithPath"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE; - - if (pContext != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - ENUMERATION_CONTEXT); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pContext); - } - - if (pMaxObjectCount != null) { - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, MAX_OBJECT_COUNT); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pMaxObjectCount); - } - - return simplereqE; - } - - /** - * PullInstancePaths_request - * - * @param pDoc - * @param pPath - * @param pContext - * @param pMaxObjectCount - * @return Element PullInstancePaths - * @throws WBEMException - */ - public Element PullInstancePaths_request(Document pDoc, CIMObjectPath pPath, String pContext, - UnsignedInteger32 pMaxObjectCount) throws WBEMException { - - String className = pPath.getObjectName(); - - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - "PullInstancePaths"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE; - - if (pContext != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - ENUMERATION_CONTEXT); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pContext); - } - - if (pMaxObjectCount != null) { - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, MAX_OBJECT_COUNT); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pMaxObjectCount); - } - - return simplereqE; - } - - /** - * PullInstances_request - * - * @param pDoc - * @param pPath - * @param pContext - * @param pMaxObjectCount - * @return Element PullInstances_request - * @throws WBEMException - */ - public Element PullInstances_request(Document pDoc, CIMObjectPath pPath, String pContext, - UnsignedInteger32 pMaxObjectCount) throws WBEMException { - String className = pPath.getObjectName(); - - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, - "null class name"); - - Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); - Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, - "PullInstances"); - CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); - - Element iparamvalueE; - - if (pContext != null) { - iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, - ENUMERATION_CONTEXT); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pContext); - } - - if (pMaxObjectCount != null) { - iparamvalueE = CIMXMLBuilderImpl - .createIPARAMVALUE(pDoc, imethodcallE, MAX_OBJECT_COUNT); - CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pMaxObjectCount); - } - - return simplereqE; - } - - /** - * sendIndication_request - * - * @param pDoc - * @param pIndication - * @return Element sendIndication_request - * @throws WBEMException - */ - public Element sendIndication_request(Document pDoc, CIMInstance pIndication) - throws WBEMException { - Element simpleexpreqE = CIMXMLBuilderImpl.createSIMPLEEXPREQ(pDoc); - Element expmethodcallE = CIMXMLBuilderImpl.createEXPMETHODCALL(pDoc, simpleexpreqE, - "ExportIndication"); - Element expparamvalueE = CIMXMLBuilderImpl.createEXPPARAMVALUE(pDoc, expmethodcallE, - "NewIndication"); - - CIMXMLBuilderImpl.createINSTANCE(pDoc, expparamvalueE, pIndication); - - return simpleexpreqE; - } -} +/* + (C) Copyright IBM Corp. 2005, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 13521 2004-11-26 thschaef XML Request Composition for static method call is wrong + * 18075 2005-08-11 pineiro5 Can not use method CIMClient.invokeMethod + * 1535756 2006-08-07 lupusalex Make code warning free + * 1365086 2006-10-25 ebak Possible bug in createQualifier + * 1565892 2006-11-16 lupusalex Make SBLIM client JSR48 compliant + * 1610046 2006-12-18 lupusalex Does not escape trailing spaces + * 1610046 2007-01-10 lupusalex Rework: Does not escape trailing spaces + * 1649611 2007-01-31 lupusalex Interop issue: Quotes not escaped by client + * 1671502 2007-02-28 lupusalex Remove dependency from Xerces + * 1660756 2007-03-02 ebak Embedded object support + * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus + * 1669961 2006-04-16 lupusalex CIMTypedElement.getType() =>getDataType() + * 1715027 2007-05-08 lupusalex Make message id random + * 1719991 2007-05-16 ebak FVT: regression ClassCastException in EmbObjHandler + * 1734888 2007-06-11 ebak Wrong reference building in METHODCALL request + * 1827728 2007-11-12 ebak embeddedInstances: attribute EmbeddedObject not set + * 1827728 2007-11-20 ebak rework: embeddedInstances: attribute EmbeddedObject not set + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2845211 2009-08-27 raman_arora Pull Enumeration Feature (SAX Parser) + * 2865222 2009-09-29 raman_arora enumerateQualifierTypes shouldn't require a class name + * 2858933 2009-10-12 raman_arora JSR48 new APIs: associatorClasses & associatorInstances + * 2886829 2009-11-18 raman_arora JSR48 new APIs: referenceClasses & referenceInstances + * 2944219 2010-02-05 blaschke-oss Problem with pull operations using client against EMC CIMOM + * 3027479 2010-07-09 blaschke-oss Dead store to local variable + * 3062747 2010-09-21 blaschke-oss SblimCIMClient does not log all CIM-XML responces. + * 3514537 2012-04-03 blaschke-oss TCK: execQueryInstances requires boolean, not Boolean + * 3521119 2012-04-24 blaschke-oss JSR48 1.0.0: remove CIMObjectPath 2/3/4-parm ctors + * 3527580 2012-05-17 blaschke-oss WBEMClient should not throw IllegalArgumentException + * 3601894 2013-01-23 blaschke-oss Enhance HTTP and CIM-XML tracing + * 2616 2013-02-23 blaschke-oss Add new API WBEMClientSBLIM.sendIndication() + * 2689 2013-10-10 blaschke-oss createMETHODCALL should not add PARAMTYPE attribute + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.io.OutputStream; +import java.util.Iterator; +import java.util.Random; +import java.util.Vector; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import org.metricshub.wbem.javax.cim.CIMArgument; +import org.metricshub.wbem.javax.cim.CIMClass; +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMInstance; +import org.metricshub.wbem.javax.cim.CIMNamedElementInterface; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.cim.CIMProperty; +import org.metricshub.wbem.javax.cim.CIMQualifierType; +import org.metricshub.wbem.javax.cim.CIMValuedElement; +import org.metricshub.wbem.javax.cim.UnsignedInteger32; +import org.metricshub.wbem.javax.wbem.WBEMException; +import org.metricshub.wbem.sblim.cimclient.internal.logging.TimeStamp; +import org.metricshub.wbem.sblim.cimclient.internal.util.MOF; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.CIMError; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMAssociatorNamesOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMAssociatorsOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMCreateClassOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMCreateInstanceOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMCreateNameSpaceOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMCreateQualifierTypeOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMDeleteClassOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMDeleteInstanceOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMDeleteQualifierTypeOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMEnumClassNamesOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMEnumClassesOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMEnumInstanceNamesOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMEnumInstancesOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMEnumNameSpaceOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMEnumQualifierTypesOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMExecQueryOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMGetClassOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMGetInstanceOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMGetPropertyOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMGetQualifierTypeOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMInvokeMethodOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMOperation; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMReferenceNamesOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMReferencesOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMSetClassOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMSetInstanceOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMSetPropertyOp; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.operations.CIMSetQualifierTypeOp; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +/** + * Class CIMClientXML_HelperImpl is responsible for building CIM-XML requests + * and responses. + */ +public class CIMClientXML_HelperImpl { + + private static class Counter { + private int iCounter; + + protected Counter(int pCounter) { + this.iCounter = pCounter; + } + + protected int incrementAndGet() { + return ++this.iCounter; + } + } + + private static final String VERSION = "1.0"; + + private static final String ASSOCIATOR_NAMES = "AssociatorNames"; + + // Pull Enumeration variables + private static final String ASSOC_CLASS = "AssocClass"; + + private static final String CLASS_NAME = "ClassName"; + + private static final String CONTINUE_ON_ERROR = "ContinueOnError"; + + private static final String DEEP_INHERITANCE = "DeepInheritance"; + + private static final String ENUMERATION_CONTEXT = "EnumerationContext"; + + private static final String FILTER_QUERY_LANGUAGE = "FilterQueryLanguage"; + + private static final String FILTER_QUERY = "FilterQuery"; + + private static final String INCLUDE_CLASS_ORIGIN = "IncludeClassOrigin"; + + private static final String INSTANCE_NAME = "InstanceName"; + + private static final String MAX_OBJECT_COUNT = "MaxObjectCount"; + + private static final String PROPERTY_LIST = "PropertyList"; + + private static final String OPERATION_TIMEOUT = "OperationTimeout"; + + private static final String RESULT_CLASS = "ResultClass"; + + private static final String RETURN_QUERY_RESULT_CLASS = "ReturnQueryResultClass"; + + private static final String QUERY_RESULT_CLASS = "QueryResultClass"; + + private static final String ROLE = "Role"; + + private static final String RESULT_ROLE = "ResultRole"; + + private static final Random RANDOM = new Random(); + + private static final int MAX_ID = 1 << 20; + + private final ThreadLocal iCurrentId = new ThreadLocal(); + + private final DocumentBuilder iBuilder; + + private static String valueStr(CIMValuedElement pE) { + Object o = pE.getValue(); + return o == null ? MOF.NULL : o.toString(); + } + + /** + * Ctor. + * + * @throws ParserConfigurationException + */ + public CIMClientXML_HelperImpl() throws ParserConfigurationException { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + this.iBuilder = factory.newDocumentBuilder(); + } + + /** + * getDocumentBuilder + * + * @return DocumentBuilder + */ + public DocumentBuilder getDocumentBuilder() { + return this.iBuilder; + } + + /** + * newDocument + * + * @return Document + */ + public Document newDocument() { + return this.iBuilder.newDocument(); + } + + /** + * parse + * + * @param pIS + * @return Document + * @throws IOException + * @throws SAXException + */ + public Document parse(InputSource pIS) throws IOException, SAXException { + if (pIS == null) throw new IllegalArgumentException("null input stream argument"); + return this.iBuilder.parse(pIS); + } + + /** + * Serializes a given DOM document as (CIM-)XML to a given output stream + * + * @param pOS + * The output stream + * @param pDoc + * The documents + * @throws IOException + * Whenever something goes wrong + */ + public static void serialize(OutputStream pOS, Document pDoc) throws IOException { + CimXmlSerializer.serialize(pOS, pDoc, false); + } + + /** + * Serializes a given DOM document as (CIM-)XML to a given output stream. + * The document is pretty wrapped and indented and surrounded with markers + * for the begin and end. + * + * @param pOS + * The output stream + * @param pDoc + * The documents + * @throws IOException + */ + public static void dumpDocument(OutputStream pOS, Document pDoc) throws IOException { + dumpDocument(pOS, pDoc, null); + } + + /** + * Serializes a given DOM document as (CIM-)XML to a given output stream. + * The document is pretty wrapped and indented and surrounded with markers + * for the begin and end. + * + * @param pOS + * The output stream + * @param pDoc + * The documents + * @param pOrigin + * The origin of the output stream (request, indication response, + * etc.) + * @throws IOException + */ + public static void dumpDocument(OutputStream pOS, Document pDoc, String pOrigin) throws IOException { + // debug + if (pOS == null) { + return; + } + if (pOrigin == null) pOrigin = "unknown"; + pOS.write("<--- ".getBytes()); + pOS.write(pOrigin.getBytes()); + pOS.write(" begin ".getBytes()); + pOS.write(TimeStamp.formatWithMillis(System.currentTimeMillis()).getBytes()); + pOS.write(" -----\n".getBytes()); + CimXmlSerializer.serialize(pOS, pDoc, true); + pOS.write("\n---- ".getBytes()); + pOS.write(pOrigin.getBytes()); + pOS.write(" end ------>\n".getBytes()); + } + + /** + * createCIMMessage + * + * @param pDoc + * @param pRequestE + * @return Element + */ + public Element createCIMMessage(Document pDoc, Element pRequestE) { + Element cimE = CIMXMLBuilderImpl.createCIM(pDoc); + Element messageE = CIMXMLBuilderImpl.createMESSAGE(pDoc, cimE, String.valueOf(getNextId()), VERSION); + if (pRequestE != null) { + messageE.appendChild(pRequestE); + } + return messageE; + } + + /** + * createMultiReq + * + * @param pDoc + * @return Element + */ + public Element createMultiReq(Document pDoc) { + Element multireqE = CIMXMLBuilderImpl.createMULTIREQ(pDoc); + return multireqE; + } + + /** + * associatorNames_request + * + * @param pDoc + * @param pObjectName + * @param pAssocClass + * @param pResultClass + * @param pRole + * @param pResultRole + * @return Element + * @throws WBEMException + */ + public Element associatorNames_request( + Document pDoc, + CIMObjectPath pObjectName, + String pAssocClass, + String pResultClass, + String pRole, + String pResultRole + ) + throws WBEMException { + // obtain data + String className = pObjectName.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + CIMProperty[] keysA = pObjectName.getKeys(); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, ASSOCIATOR_NAMES); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pObjectName); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ObjectName"); + Element instancenameE = CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, className); + for (int i = 0; i < keysA.length; i++) { + CIMProperty prop = keysA[i]; + String propName = prop.getName(); + // TODO: check that CIMDataType.toString() satisfies this + String propTypeStr = prop.getDataType().toString(); + String propValueStr = valueStr(prop); + Element keybindingE = CIMXMLBuilderImpl.createKEYBINDING(pDoc, instancenameE, propName); + CIMXMLBuilderImpl.createKEYVALUE(pDoc, keybindingE, propTypeStr, propValueStr); + } + if (pAssocClass != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "AssocClass"); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pAssocClass); + } + if (pResultClass != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultClass"); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); + } + if (pRole != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "Role"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); + } + if (pResultRole != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultRole"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pResultRole); + } + + return simplereqE; + } + + /** + * associatorNames_response + * + * @param pDoc + * @param pPathA + * @return Element + */ + public static Element associatorNames_response(Document pDoc, CIMObjectPath[] pPathA) { + Element simpRspE = CIMXMLBuilderImpl.createSIMPLERSP(pDoc, null); + Element iMethRspE = CIMXMLBuilderImpl.createIMETHODRESPONSE(pDoc, simpRspE, "associatorNames"); + Element iRetValE = CIMXMLBuilderImpl.createIRETURNVALUE(pDoc, iMethRspE); + try { + for (int i = 0; i < pPathA.length; i++) { + CIMXMLBuilderImpl.createOBJECTPATH(pDoc, iRetValE, pPathA[i]); + } + } catch (WBEMException e) { + throw new RuntimeException(e); + } + return simpRspE; + } + + /** + * associatorInstances_request + * + * @param pDoc + * @param pObjectName + * @param pAssocClass + * @param pResultClass + * @param pRole + * @param pResultRole + * @param pIncludeClassOrigin + * @param pPropertyList + * @return Element + * @throws WBEMException + */ + public Element associatorInstances_request( + Document pDoc, + CIMObjectPath pObjectName, + String pAssocClass, + String pResultClass, + String pRole, + String pResultRole, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException { + String className = pObjectName.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + CIMProperty[] keysA = pObjectName.getKeys(); + + // Make sure keys are populated + if (keysA.length == 0) throw new WBEMException( + WBEMException.CIM_ERR_INVALID_PARAMETER, + "associatorInstances requires keys for the instance to be populated" + ); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "Associators"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pObjectName); + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ObjectName"); + Element instancenameE = CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, className); + for (int i = 0; i < keysA.length; i++) { + CIMProperty prop = keysA[i]; + String propName = prop.getName(); + String propTypeStr = prop.getDataType().toString(); + String propValueStr = valueStr(prop); + + Element keybindingE = CIMXMLBuilderImpl.createKEYBINDING(pDoc, instancenameE, propName); + CIMXMLBuilderImpl.createKEYVALUE(pDoc, keybindingE, propTypeStr, propValueStr); + } + if (pAssocClass != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "AssocClass"); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pAssocClass); + } + if (pResultClass != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultClass"); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); + } + if (pRole != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "Role"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); + } + if (pResultRole != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultRole"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pResultRole); + } + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeClassOrigin"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); + + if (pPropertyList != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyList"); + Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); + for (int i = 0; i < pPropertyList.length; i++) { + CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); + } + } + + return simplereqE; + } + + /** + * associatorClasses_request + * + * @param pDoc + * @param pObjectName + * @param pAssocClass + * @param pResultClass + * @param pRole + * @param pResultRole + * @param pIncludeQualifiers + * @param pIncludeClassOrigin + * @param pPropertyList + * @return Element + * @throws WBEMException + */ + public Element associatorClasses_request( + Document pDoc, + CIMObjectPath pObjectName, + String pAssocClass, + String pResultClass, + String pRole, + String pResultRole, + boolean pIncludeQualifiers, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException { + String className = pObjectName.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + // Make sure keys are not populated + if (pObjectName.getKeys().length != 0) throw new WBEMException( + WBEMException.CIM_ERR_INVALID_PARAMETER, + "Keys should not be populated for associatorClasses" + ); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "Associators"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pObjectName); + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ObjectName"); + + CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, className); + + if (pAssocClass != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "AssocClass"); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pAssocClass); + } + if (pResultClass != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultClass"); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); + } + if (pRole != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "Role"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); + } + if (pResultRole != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultRole"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pResultRole); + } + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeQualifiers"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeQualifiers); + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeClassOrigin"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); + + if (pPropertyList != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyList"); + Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); + for (int i = 0; i < pPropertyList.length; i++) { + CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); + } + } + + return simplereqE; + } + + /** + * associators_request + * + * @param pDoc + * @param pObjectName + * @param pAssocClass + * @param pResultClass + * @param pRole + * @param pResultRole + * @param pIncludeQualifiers + * @param pIncludeClassOrigin + * @param pPropertyList + * @return Element + * @throws WBEMException + */ + public Element associators_request( + Document pDoc, + CIMObjectPath pObjectName, + String pAssocClass, + String pResultClass, + String pRole, + String pResultRole, + boolean pIncludeQualifiers, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException { + // obtain data + String className = pObjectName.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + CIMProperty[] keysA = pObjectName.getKeys(); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "Associators"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pObjectName); + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ObjectName"); + Element instancenameE = CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, className); + for (int i = 0; i < keysA.length; i++) { + CIMProperty prop = keysA[i]; + String propName = prop.getName(); + // TODO: check that CIMDataType.toString() satisfies this + String propTypeStr = prop.getDataType().toString(); + // CIMXMLBuilderImpl.getTypeStr(pValue.getType()); + String propValueStr = valueStr(prop); + + Element keybindingE = CIMXMLBuilderImpl.createKEYBINDING(pDoc, instancenameE, propName); + CIMXMLBuilderImpl.createKEYVALUE(pDoc, keybindingE, propTypeStr, propValueStr); + } + if (pAssocClass != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "AssocClass"); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pAssocClass); + } + if (pResultClass != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultClass"); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); + } + if (pRole != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "Role"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); + } + if (pResultRole != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultRole"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pResultRole); + } + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeQualifiers"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeQualifiers); + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeClassOrigin"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); + + if (pPropertyList != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyList"); // BB + // fixed + Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); + for (int i = 0; i < pPropertyList.length; i++) { + CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); + } + } + + return simplereqE; + } + + /** + * associators_response + * + * @param pDoc + * @param pNamedElementA + * @return Element + */ + public static Element associators_response(Document pDoc, CIMNamedElementInterface[] pNamedElementA) { + Element simpRspE = CIMXMLBuilderImpl.createSIMPLERSP(pDoc, null); + Element iMethRspE = CIMXMLBuilderImpl.createIMETHODRESPONSE(pDoc, simpRspE, "associators"); + Element iRetValE = CIMXMLBuilderImpl.createIRETURNVALUE(pDoc, iMethRspE); + try { + for (int i = 0; i < pNamedElementA.length; i++) { + CIMNamedElementInterface namedElement = pNamedElementA[i]; + CIMObjectPath op = namedElement.getObjectPath(); + String nameSpace = op == null ? null : op.getNamespace(); + CIMXMLBuilderImpl.createVALUEOBJECTWITHPATH(pDoc, iRetValE, namedElement, nameSpace); + /* + * CIMXMLBuilderImpl.createCLASSPATH( pDoc, iRetValE, + * pClassA[i].getObjectPath() ); + * CIMXMLBuilderImpl.createCLASS(pDoc, iRetValE, pClassA[i]); + */ + + } + } catch (WBEMException e) { + throw new RuntimeException(e); + } + return simpRspE; + } + + /** + * enumerateInstanceNames_request + * + * @param pDoc + * @param pPath + * @return Element + * @throws WBEMException + */ + public Element enumerateInstanceNames_request(Document pDoc, CIMObjectPath pPath) throws WBEMException { + // obtain data + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "EnumerateInstanceNames"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ClassName"); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, className); + + return simplereqE; + } + + /** + * enumerateInstances_request + * + * @param pDoc + * @param pPath + * @param pDeepInheritance + * @param pLocalOnly + * @param pIncludeQualifiers + * @param pIncludeClassOrigin + * @param pPropertyList + * @return Element + * @throws WBEMException + */ + public Element enumerateInstances_request( + Document pDoc, + CIMObjectPath pPath, + boolean pDeepInheritance, + boolean pLocalOnly, + boolean pIncludeQualifiers, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException { + // obtain data + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "EnumerateInstances"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ClassName"); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, className); + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "LocalOnly"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pLocalOnly); + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "DeepInheritance"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pDeepInheritance); + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeQualifiers"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeQualifiers); + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeClassOrigin"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); + + if (pPropertyList != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyList"); + Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); + for (int i = 0; i < pPropertyList.length; i++) { + CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); + } + } + return simplereqE; + } + + /** + * getInstance_request + * + * @param pDoc + * @param pName + * @param pLocalOnly + * @param pIncludeQualifiers + * @param pIncludeClassOrigin + * @param pPropertyList + * @return Element + * @throws WBEMException + */ + public Element getInstance_request( + Document pDoc, + CIMObjectPath pName, + boolean pLocalOnly, + boolean pIncludeQualifiers, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException { + // obtain data + String className = pName.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "GetInstance"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pName); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "InstanceName"); + CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, pName); + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "LocalOnly"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pLocalOnly); + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeQualifiers"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeQualifiers); + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeClassOrigin"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); + + if (pPropertyList != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyList"); + Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); + for (int i = 0; i < pPropertyList.length; i++) { + CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); + } + } + + return simplereqE; + } + + /** + * deleteInstance_request + * + * @param pDoc + * @param pName + * @return Element + * @throws WBEMException + */ + public Element deleteInstance_request(Document pDoc, CIMObjectPath pName) throws WBEMException { + // obtain data + String className = pName.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "DeleteInstance"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pName); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "InstanceName"); + CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, pName); + + return simplereqE; + } + + /** + * getClass_request + * + * @param pDoc + * @param pName + * @param pLocalOnly + * @param pIncludeQualifiers + * @param pIncludeClassOrigin + * @param pPropertyList + * @return Element + * @throws WBEMException + */ + public Element getClass_request( + Document pDoc, + CIMObjectPath pName, + boolean pLocalOnly, + boolean pIncludeQualifiers, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException { + // obtain data + String className = pName.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "GetClass"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pName); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ClassName"); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, className); + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "LocalOnly"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pLocalOnly); + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeQualifiers"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeQualifiers); + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeClassOrigin"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); + + if (pPropertyList != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyList"); + Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); + for (int i = 0; i < pPropertyList.length; i++) { + CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); + } + } + + return simplereqE; + } + + /** + * createInstance_request + * + * @param pDoc + * @param pName + * @param pInstance + * @return Element + * @throws WBEMException + */ + public Element createInstance_request(Document pDoc, CIMObjectPath pName, CIMInstance pInstance) + throws WBEMException { + String className = pInstance.getObjectPath().getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "CreateInstance"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pName); + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "NewInstance"); + + CIMXMLBuilderImpl.createINSTANCE(pDoc, iparamvalueE, pInstance); + + return simplereqE; + } + + /** + * invokeMethod_request + * + * @param pDoc + * @param pLocalPath + * @param pMethodName + * @param pInArgs + * @return Element + * @throws WBEMException + */ + public Element invokeMethod_request( + Document pDoc, + CIMObjectPath pLocalPath, + String pMethodName, + CIMArgument[] pInArgs + ) + throws WBEMException { + // obtain data + String className = pLocalPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + CIMProperty[] keysA = pLocalPath.getKeys(); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element methodcallE = CIMXMLBuilderImpl.createMETHODCALL(pDoc, simplereqE, pMethodName); + + // 13521 + if (keysA.length > 0) { + Element localpathE = CIMXMLBuilderImpl.createLOCALINSTANCEPATH(pDoc, methodcallE); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, localpathE, pLocalPath); // 13521 + CIMXMLBuilderImpl.createINSTANCENAME(pDoc, localpathE, pLocalPath); // 13521 + } else { + CIMXMLBuilderImpl.createLOCALCLASSPATH(pDoc, methodcallE, pLocalPath); + } + + buildParamValues(pDoc, methodcallE, pLocalPath, pInArgs); + + return simplereqE; + } + + /** + * invokeMethod_response + * + * @param pDoc + * @param pMethodName + * @param pLocalPath + * @param pRetVal + * @param pOutArgA + * @return Element + * @throws WBEMException + */ + public static Element invokeMethod_response( + Document pDoc, + String pMethodName, + CIMObjectPath pLocalPath, + Object pRetVal, + CIMArgument[] pOutArgA + ) + throws WBEMException { + if (pMethodName == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null method name"); + Element simpleRspE = CIMXMLBuilderImpl.createSIMPLERSP(pDoc, null); + Element methodRspE = CIMXMLBuilderImpl.createMETHODRESPONSE(pDoc, simpleRspE, pMethodName); + + CIMXMLBuilderImpl.createRETURNVALUE(pDoc, methodRspE, pRetVal); + + buildParamValues(pDoc, methodRspE, pLocalPath, pOutArgA); + return simpleRspE; + } + + /** + * @param pLocalPath + */ + private static void buildParamValues( + Document pDoc, + Element pParentE, + CIMObjectPath pLocalPath, + CIMArgument[] pArgA + ) + throws WBEMException { + if (pArgA == null) return; + for (int i = 0; i < pArgA.length; i++) { + CIMArgument arg = pArgA[i]; + if (arg == null) continue; + CIMXMLBuilderImpl.createPARAMVALUE(pDoc, pParentE, arg); + } + } + + // public CIMResponse createIndication_request(Document doc) throws + // CIMXMLParseException, CIMException { + // Element rootE = doc.getDocumentElement(); + // CIMResponse response = (CIMResponse)xmlParser.parseCIM(rootE); + // response.checkError(); + // return response; + // // Vector v = (Vector)response.getFirstReturnValue(); + // // + // // //TODO: Should we return the whole list of instances or just the first + // instance? + // // //TODO: return the whole vector of indications + // // if (v.size() > 0) + // // return (CIMInstance)v.elementAt(0); + // // else + // // return null; + // } + + /** + * createIndication_response + * + * @param error + * @return Document + */ + public Document createIndication_response(CIMError error) { + // CIMXMLBuilderImpl.create XML + Document doc = this.iBuilder.newDocument(); + Element cimE = CIMXMLBuilderImpl.createCIM(doc); + Element messageE = CIMXMLBuilderImpl.createMESSAGE(doc, cimE, String.valueOf(getNextId()), "1.0"); + Element simpleexprspE = CIMXMLBuilderImpl.createSIMPLEEXPRSP(doc, messageE); + Element expmethodresponseE = CIMXMLBuilderImpl.createEXPMETHODRESPONSE(doc, simpleexprspE, "ExportIndication"); + if (error == null) { + CIMXMLBuilderImpl.createIRETURNVALUE(doc, expmethodresponseE); + } else { + CIMXMLBuilderImpl.createERROR(doc, expmethodresponseE, error); + } + // Element + return doc; + } + + /** + * createClass_request + * + * @param pDoc + * @param pPath + * @param pClass + * @return Element + * @throws WBEMException + */ + public Element createClass_request(Document pDoc, CIMObjectPath pPath, CIMClass pClass) throws WBEMException { + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "CreateClass"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "NewClass"); + + CIMXMLBuilderImpl.createCLASS(pDoc, iparamvalueE, pClass); + + return simplereqE; + } + + /** + * getQualifier_request + * + * @param pDoc + * @param pPath + * @param pQt + * @return Element + * @throws WBEMException + */ + public Element getQualifier_request(Document pDoc, CIMObjectPath pPath, String pQt) throws WBEMException { + // obtain data + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "GetQualifier"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "QualifierName"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pPath.getObjectName()); + + return simplereqE; + } + + /** + * createQualifierType_request : This has been replaced by + * setQualifierType_request + * + * @param pDoc + * @param pPath + * @param pQt + * @return Element + * @throws WBEMException + */ + public Element createQualifierType_request(Document pDoc, CIMObjectPath pPath, CIMQualifierType pQt) + throws WBEMException { + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "SetQualifier"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "QualifierDeclaration"); + CIMXMLBuilderImpl.createQUALIFIER_DECLARATION(pDoc, iparamvalueE, pQt); + + return simplereqE; + } + + /** + * deleteClass_request + * + * @param pDoc + * @param pPath + * @return Element + * @throws WBEMException + */ + public Element deleteClass_request(Document pDoc, CIMObjectPath pPath) throws WBEMException { + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "DeleteClass"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ClassName"); + + CIMXMLBuilderImpl.createOBJECTNAME(pDoc, iparamvalueE, pPath); + + return simplereqE; + } + + /** + * deleteQualifierType_request + * + * @param pDoc + * @param pPath + * @return Element + * @throws WBEMException + */ + public Element deleteQualifierType_request(Document pDoc, CIMObjectPath pPath) throws WBEMException { + // obtain data + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "DeleteQualifier"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "QualifierName"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pPath.getObjectName()); + return simplereqE; + } + + /** + * enumerateClasses_request + * + * @param pDoc + * @param pPath + * @param pDeepInheritance + * @param pLocalOnly + * @param pIncludeQualifiers + * @param pIncludeClassOrigin + * @return Element + */ + public Element enumerateClasses_request( + Document pDoc, + CIMObjectPath pPath, + boolean pDeepInheritance, + boolean pLocalOnly, + boolean pIncludeQualifiers, + boolean pIncludeClassOrigin + ) { + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "EnumerateClasses"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE; + if (pPath != null && pPath.getObjectName() != null && pPath.getObjectName().trim().length() != 0) { + String className = pPath.getObjectName(); + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ClassName"); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, className); + } + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "LocalOnly"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pLocalOnly); + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "DeepInheritance"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pDeepInheritance); + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeQualifiers"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeQualifiers); + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeClassOrigin"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); + return simplereqE; + } + + /** + * enumerateClasses_response + * + * @param pDoc + * @param pClA + * @return Element + */ + public static Element enumerateClasses_response(Document pDoc, CIMClass[] pClA) { + Element simpRspE = CIMXMLBuilderImpl.createSIMPLERSP(pDoc, null); + Element iMethRspE = CIMXMLBuilderImpl.createIMETHODRESPONSE(pDoc, simpRspE, "enumerateClasses"); + Element iRetValE = CIMXMLBuilderImpl.createIRETURNVALUE(pDoc, iMethRspE); + try { + for (int i = 0; i < pClA.length; i++) { + CIMXMLBuilderImpl.createCLASS(pDoc, iRetValE, pClA[i]); + } + } catch (WBEMException e) { + throw new RuntimeException(e); + } + return simpRspE; + } + + /** + * enumerateInstances_response + * + * @param pDoc + * @param pInstA + * @return Element + */ + public static Element enumerateInstances_response(Document pDoc, CIMInstance[] pInstA) { + Element simpRspE = CIMXMLBuilderImpl.createSIMPLERSP(pDoc, null); + Element iMethRspE = CIMXMLBuilderImpl.createIMETHODRESPONSE(pDoc, simpRspE, "enumerateInstances"); + Element iRetValE = CIMXMLBuilderImpl.createIRETURNVALUE(pDoc, iMethRspE); + try { + for (int i = 0; i < pInstA.length; i++) { + CIMXMLBuilderImpl.createINSTANCE(pDoc, iRetValE, pInstA[i]); + } + } catch (WBEMException e) { + throw new RuntimeException(e); + } + return simpRspE; + } + + /** + * enumerateClassNames_request + * + * @param pDoc + * @param pPath + * @param pDeepInheritance + * @return Element + */ + public Element enumerateClassNames_request(Document pDoc, CIMObjectPath pPath, boolean pDeepInheritance) { + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "EnumerateClassNames"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE; + + if (pPath != null && pPath.getObjectName() != null && pPath.getObjectName().trim().length() != 0) { + String className = pPath.getObjectName(); + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ClassName"); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, className); + } + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "DeepInheritance"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pDeepInheritance); + + return simplereqE; + } + + /** + * getProperty_request + * + * @param pDoc + * @param pPath + * @param pPropertyName + * @return Element + * @throws WBEMException + */ + public Element getProperty_request(Document pDoc, CIMObjectPath pPath, String pPropertyName) throws WBEMException { + // obtain data + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "GetProperty"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "InstanceName"); + CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, pPath); + + if (pPropertyName != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyName"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pPropertyName); + } + + return simplereqE; + } + + /** + * referenceNames_request + * + * @param pDoc + * @param pPath + * @param pResultClass + * @param pRole + * @return Element + * @throws WBEMException + */ + public Element referenceNames_request(Document pDoc, CIMObjectPath pPath, String pResultClass, String pRole) + throws WBEMException { + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "ReferenceNames"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ObjectName"); + CIMXMLBuilderImpl.createOBJECTNAME(pDoc, iparamvalueE, pPath); + + if (pResultClass != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultClass"); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); + } + if (pRole != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "Role"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); + } + + return simplereqE; + } + + /** + * referenceClasses_request + * + * @param pDoc + * @param pPath + * @param pResultClass + * @param pRole + * @param pIncludeQualifiers + * @param pIncludeClassOrigin + * @param pPropertyList + * @return Element + * @throws WBEMException + */ + public Element referenceClasses_request( + Document pDoc, + CIMObjectPath pPath, + String pResultClass, + String pRole, + boolean pIncludeQualifiers, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException { + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + // Make sure keys are not populated + if (pPath.getKeys().length != 0) throw new WBEMException( + WBEMException.CIM_ERR_INVALID_PARAMETER, + "Keys should not be populated for referenceClasses" + ); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "References"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ObjectName"); + // createOBJECTNAME will internally call createINSTANCENAME but as there + // are no keys Element containing keys will not be populated + CIMXMLBuilderImpl.createOBJECTNAME(pDoc, iparamvalueE, pPath); + + if (pResultClass != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultClass"); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); + } + if (pRole != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "Role"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); + } + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeQualifiers"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeQualifiers); + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeClassOrigin"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); + + if (pPropertyList != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyList"); + Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); + for (int i = 0; i < pPropertyList.length; i++) { + CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); + } + } + return simplereqE; + } + + /** + * referenceInstances_request + * + * @param pDoc + * @param pPath + * @param pResultClass + * @param pRole + * @param pIncludeClassOrigin + * @param pPropertyList + * @return Element + * @throws WBEMException + */ + public Element referenceInstances_request( + Document pDoc, + CIMObjectPath pPath, + String pResultClass, + String pRole, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException { + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + // keys are required for CIMInstance + if (pPath.getKeys().length == 0) throw new WBEMException( + WBEMException.CIM_ERR_INVALID_PARAMETER, + "refrenceInstances requires keys for the instance to be populated" + ); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "References"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ObjectName"); + // createOBJECTNAME will internally call createINSTANCENAME to populate + // Element containing keys + CIMXMLBuilderImpl.createOBJECTNAME(pDoc, iparamvalueE, pPath); + + if (pResultClass != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultClass"); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); + } + if (pRole != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "Role"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); + } + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeClassOrigin"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); + + if (pPropertyList != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyList"); + Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); + for (int i = 0; i < pPropertyList.length; i++) { + CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); + } + } + return simplereqE; + } + + /** + * references_request + * + * @param pDoc + * @param pPath + * @param pResultClass + * @param pRole + * @param pIncludeQualifiers + * @param pIncludeClassOrigin + * @param pPropertyList + * @return Element + * @throws WBEMException + */ + public Element references_request( + Document pDoc, + CIMObjectPath pPath, + String pResultClass, + String pRole, + boolean pIncludeQualifiers, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException { + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "References"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE; + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ObjectName"); + CIMXMLBuilderImpl.createOBJECTNAME(pDoc, iparamvalueE, pPath); + + if (pResultClass != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ResultClass"); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); + } + if (pRole != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "Role"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); + } + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeQualifiers"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeQualifiers); + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeClassOrigin"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); + + if (pPropertyList != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyList"); + Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); + for (int i = 0; i < pPropertyList.length; i++) { + CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); + } + } + + return simplereqE; + } + + /** + * setClass_request + * + * @param pDoc + * @param pPath + * @param pClass + * @return Element + * @throws WBEMException + */ + public Element setClass_request(Document pDoc, CIMObjectPath pPath, CIMClass pClass) throws WBEMException { + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "ModifyClass"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ModifiedClass"); + CIMXMLBuilderImpl.createCLASS(pDoc, iparamvalueE, pClass); + + return simplereqE; + } + + /** + * setInstance_request + * + * @param pDoc + * @param pPath + * @param pInstance + * @param pIncludeQualifiers + * @param pPropertyList + * @return Element + * @throws WBEMException + */ + public Element setInstance_request( + Document pDoc, + CIMObjectPath pPath, + CIMInstance pInstance, + boolean pIncludeQualifiers, + String[] pPropertyList + ) + throws WBEMException { + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "ModifyInstance"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "ModifiedInstance"); + CIMXMLBuilderImpl.createVALUENAMEDINSTANCE(pDoc, iparamvalueE, pPath, pInstance); + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "IncludeQualifiers"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeQualifiers); + + if (pPropertyList != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyList"); + Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); + for (int i = 0; i < pPropertyList.length; i++) { + CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); + } + } + + return simplereqE; + } + + /** + * setProperty_request + * + * @param pDoc + * @param pPath + * @param pPropertyName + * @param pNewValue + * @return Element + * @throws WBEMException + */ + public Element setProperty_request(Document pDoc, CIMObjectPath pPath, String pPropertyName, Object pNewValue) + throws WBEMException { + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "SetProperty"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "InstanceName"); + CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, pPath); + + if (pPropertyName != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "PropertyName"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pPropertyName); + } + + if (pNewValue != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "NewValue"); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pNewValue); + } + + return simplereqE; + } + + /** + * setQualifierType_request + * + * @param pDoc + * @param pPath + * @param pQt + * @return Element + * @throws WBEMException + */ + public Element setQualifierType_request(Document pDoc, CIMObjectPath pPath, CIMQualifierType pQt) + throws WBEMException { + // Make sure class name exists, it is required to uniquely identify + // qualifier in namespace + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "SetQualifier"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "QualifierDeclaration"); + CIMXMLBuilderImpl.createQUALIFIER_DECLARATION(pDoc, iparamvalueE, pQt); + + return simplereqE; + } + + /** + * enumQualifierTypes_request + * + * @param pDoc + * @param pPath + * @return Element + * @throws WBEMException + */ + public Element enumQualifierTypes_request(Document pDoc, CIMObjectPath pPath) throws WBEMException { + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "EnumerateQualifiers"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + return simplereqE; + } + + /** + * enumQualifierTypes_response + * + * @param pDoc + * @param pQualiTypeA + * @return Element + * @throws WBEMException + */ + public static Element enumQualifierTypes_response(Document pDoc, CIMQualifierType[] pQualiTypeA) + throws WBEMException { + Element simpRspE = CIMXMLBuilderImpl.createSIMPLERSP(pDoc, null); + Element iMethRspE = CIMXMLBuilderImpl.createIMETHODRESPONSE(pDoc, simpRspE, "associatorNames"); + Element iRetValE = CIMXMLBuilderImpl.createIRETURNVALUE(pDoc, iMethRspE); + for (int i = 0; i < pQualiTypeA.length; i++) { + CIMXMLBuilderImpl.createQUALIFIER_DECLARATION(pDoc, iRetValE, pQualiTypeA[i]); + } + return simpRspE; + } + + /** + * execQuery_request + * + * @param pDoc + * @param pPath + * @param pQuery + * @param pQueryLanguage + * @return Element + */ + public Element execQuery_request(Document pDoc, CIMObjectPath pPath, String pQuery, String pQueryLanguage) { + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "ExecQuery"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element querylanguageE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "QueryLanguage"); + CIMXMLBuilderImpl.createVALUE(pDoc, querylanguageE, pQueryLanguage); + + Element queryE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, "Query"); + CIMXMLBuilderImpl.createVALUE(pDoc, queryE, pQuery); + + return simplereqE; + } + + /** + * performBatchOperation_request + * + * @param pDoc + * @param pOperations + * @return Element + * @throws WBEMException + */ + public Element performBatchOperation_request(Document pDoc, Vector pOperations) throws WBEMException { + Element messageE = createCIMMessage(pDoc, null); + if (pOperations.size() > 1) { + Element multireqE = createMultiReq(pDoc); + messageE.appendChild(multireqE); + messageE = multireqE; + } + int i = 0; + Iterator iter = pOperations.iterator(); + while (iter.hasNext()) { + CIMOperation op = iter.next(); + try { + Element requestE = null; + + if (op instanceof CIMAssociatorsOp) { + CIMAssociatorsOp associatorsOp = (CIMAssociatorsOp) op; + requestE = + associators_request( + pDoc, + associatorsOp.getObjectName(), + associatorsOp.getAssocClass(), + associatorsOp.getResultClass(), + associatorsOp.getRole(), + associatorsOp.getResultRole(), + associatorsOp.isIncludeQualifiers(), + associatorsOp.isIncludeClassOrigin(), + associatorsOp.getPropertyList() + ); + } else if (op instanceof CIMAssociatorNamesOp) { + CIMAssociatorNamesOp associatorNamesOp = (CIMAssociatorNamesOp) op; + requestE = + associatorNames_request( + pDoc, + associatorNamesOp.getObjectName(), + associatorNamesOp.getAssocClass(), + associatorNamesOp.getResultClass(), + associatorNamesOp.getRole(), + associatorNamesOp.getResultRole() + ); + } else if (op instanceof CIMCreateClassOp) { + CIMCreateClassOp createClassOp = (CIMCreateClassOp) op; + requestE = createClass_request(pDoc, createClassOp.getObjectName(), createClassOp.getCimClass()); + } else if (op instanceof CIMCreateInstanceOp) { + CIMCreateInstanceOp createInstanceOp = (CIMCreateInstanceOp) op; + requestE = createInstance_request(pDoc, createInstanceOp.getObjectName(), createInstanceOp.getInstance()); + } else if (op instanceof CIMCreateNameSpaceOp) { + CIMCreateNameSpaceOp createNameSpaceOp = (CIMCreateNameSpaceOp) op; + + String namespace = createNameSpaceOp.getNameSpace(); + int j = namespace.lastIndexOf('/'); + + if (j < 0) throw new WBEMException( + WBEMException.CIM_ERR_NOT_FOUND, + "Invalid namespace. Must contain at least /" + ); + String parentNs = namespace.substring(0, j); + namespace = namespace.substring(j + 1); + + /* + * CIMInstance inst = new CIMInstance(); + * inst.setClassName("CIM_NameSpace"); CIMProperty prop = + * new CIMProperty("NameSpace"); prop.setValue(new + * CIMValue(namespace, CIMDataType + * .getPredefinedType(CIMDataType.STRING))); Vector v = new + * Vector(); v.add(prop); inst.setProperties(v); + */ + + CIMInstance inst = new CIMInstance( + new CIMObjectPath(null, null, null, null, "CIM_NameSpace", null), + new CIMProperty[] { + new CIMProperty("NameSpace", CIMDataType.STRING_T, namespace, true, false, null) + } + ); + CIMObjectPath object = new CIMObjectPath(null, null, null, parentNs, null, null); + + requestE = createInstance_request(pDoc, object, inst); + } else if (op instanceof CIMCreateQualifierTypeOp) { + CIMCreateQualifierTypeOp createQualifierTypeOp = (CIMCreateQualifierTypeOp) op; + requestE = + createQualifierType_request( + pDoc, + createQualifierTypeOp.getObjectName(), + createQualifierTypeOp.getQualifierType() + ); + } else if (op instanceof CIMDeleteClassOp) { + CIMDeleteClassOp deleteClassOp = (CIMDeleteClassOp) op; + requestE = deleteClass_request(pDoc, deleteClassOp.getObjectName()); + } else if (op instanceof CIMDeleteInstanceOp) { + CIMDeleteInstanceOp deleteInstanceOp = (CIMDeleteInstanceOp) op; + requestE = deleteClass_request(pDoc, deleteInstanceOp.getObjectName()); + } else if (op instanceof CIMDeleteQualifierTypeOp) { + CIMDeleteQualifierTypeOp deleteQualifierTypeOp = (CIMDeleteQualifierTypeOp) op; + requestE = deleteClass_request(pDoc, deleteQualifierTypeOp.getObjectName()); + } else if (op instanceof CIMEnumClassesOp) { + CIMEnumClassesOp enumClassesOp = (CIMEnumClassesOp) op; + requestE = + enumerateClasses_request( + pDoc, + enumClassesOp.getObjectName(), + enumClassesOp.isDeep(), + enumClassesOp.isLocalOnly(), + enumClassesOp.isIncludeQualifiers(), + enumClassesOp.isIncludeClassOrigin() + ); + } else if (op instanceof CIMEnumClassNamesOp) { + CIMEnumClassNamesOp enumClassNamesOp = (CIMEnumClassNamesOp) op; + requestE = enumerateClassNames_request(pDoc, enumClassNamesOp.getObjectName(), enumClassNamesOp.isDeep()); + } else if (op instanceof CIMEnumInstanceNamesOp) { + CIMEnumInstanceNamesOp enumInstanceNamesOp = (CIMEnumInstanceNamesOp) op; + requestE = enumerateInstanceNames_request(pDoc, enumInstanceNamesOp.getObjectName()); + } else if (op instanceof CIMEnumInstancesOp) { + CIMEnumInstancesOp enumInstancesOp = (CIMEnumInstancesOp) op; + requestE = + enumerateInstances_request( + pDoc, + enumInstancesOp.getObjectName(), + enumInstancesOp.isDeep(), + enumInstancesOp.isLocalOnly(), + enumInstancesOp.isIncludeQualifiers(), + enumInstancesOp.isIncludeClassOrigin(), + enumInstancesOp.getPropertyList() + ); + } else if (op instanceof CIMEnumNameSpaceOp) { + CIMEnumNameSpaceOp enumNameSpaceOp = (CIMEnumNameSpaceOp) op; + // ebak: here we have to set CIMObjectPath's objectname + // enumNameSpaceOp.getObjectName().setObjectName("CIM_NameSpace"); + CIMObjectPath objPath = enumNameSpaceOp.getObjectName(); + objPath = + new CIMObjectPath( + objPath.getScheme(), + objPath.getHost(), + objPath.getPort(), + objPath.getNamespace(), + "CIM_NameSpace", + objPath.getKeys() + ); + requestE = enumerateInstanceNames_request(pDoc, enumNameSpaceOp.getObjectName()); + } else if (op instanceof CIMEnumQualifierTypesOp) { + CIMEnumQualifierTypesOp enumQualifierTypesOp = (CIMEnumQualifierTypesOp) op; + requestE = enumQualifierTypes_request(pDoc, enumQualifierTypesOp.getObjectName()); + } else if (op instanceof CIMExecQueryOp) { + CIMExecQueryOp execQueryOp = (CIMExecQueryOp) op; + requestE = + execQuery_request( + pDoc, + execQueryOp.getObjectName(), + execQueryOp.getQuery(), + execQueryOp.getQueryLanguage() + ); + } else if (op instanceof CIMGetPropertyOp) { + CIMGetPropertyOp getPropertyOp = (CIMGetPropertyOp) op; + requestE = + getInstance_request( + pDoc, + getPropertyOp.getObjectName(), + false, + false, + false, + new String[] { getPropertyOp.getPropertyName() } + ); + } else if (op instanceof CIMGetClassOp) { + CIMGetClassOp getClassOp = (CIMGetClassOp) op; + requestE = + getClass_request( + pDoc, + getClassOp.getObjectName(), + getClassOp.isLocalOnly(), + getClassOp.isIncludeQualifiers(), + getClassOp.isIncludeClassOrigin(), + getClassOp.getPropertyList() + ); + } else if (op instanceof CIMGetInstanceOp) { + CIMGetInstanceOp getInstanceOp = (CIMGetInstanceOp) op; + requestE = + getInstance_request( + pDoc, + getInstanceOp.getObjectName(), + getInstanceOp.isLocalOnly(), + getInstanceOp.isIncludeQualifiers(), + getInstanceOp.isIncludeClassOrigin(), + getInstanceOp.getPropertyList() + ); + } else if (op instanceof CIMGetQualifierTypeOp) { + CIMGetQualifierTypeOp getQualifierTypeOp = (CIMGetQualifierTypeOp) op; + requestE = + getQualifier_request(pDoc, getQualifierTypeOp.getObjectName(), getQualifierTypeOp.getQualifierType()); + } else if (op instanceof CIMInvokeMethodOp) { + CIMInvokeMethodOp invokeMethodOp = (CIMInvokeMethodOp) op; + requestE = + invokeMethod_request( + pDoc, + invokeMethodOp.getObjectName(), + invokeMethodOp.getMethodCall(), + invokeMethodOp.getInParams() + ); + } else if (op instanceof CIMReferenceNamesOp) { + CIMReferenceNamesOp referenceNamesOp = (CIMReferenceNamesOp) op; + requestE = + referenceNames_request( + pDoc, + referenceNamesOp.getObjectName(), + referenceNamesOp.getResultClass(), + referenceNamesOp.getResultRole() + ); + } else if (op instanceof CIMReferencesOp) { + CIMReferencesOp referencesOp = (CIMReferencesOp) op; + requestE = + references_request( + pDoc, + referencesOp.getObjectName(), + referencesOp.getResultClass(), + referencesOp.getRole(), + referencesOp.isIncludeQualifiers(), + referencesOp.isIncludeClassOrigin(), + referencesOp.getPropertyList() + ); + } else if (op instanceof CIMSetClassOp) { + CIMSetClassOp setClassOp = (CIMSetClassOp) op; + requestE = setClass_request(pDoc, setClassOp.getObjectName(), setClassOp.getCimClass()); + } else if (op instanceof CIMSetInstanceOp) { + CIMSetInstanceOp setInstanceOp = (CIMSetInstanceOp) op; + requestE = + setInstance_request( + pDoc, + setInstanceOp.getObjectName(), + setInstanceOp.getInstance(), + setInstanceOp.isIncludeQualifiers(), + setInstanceOp.getPropertyList() + ); + } else if (op instanceof CIMSetPropertyOp) { + CIMSetPropertyOp setPropertyOp = (CIMSetPropertyOp) op; + requestE = + setProperty_request( + pDoc, + setPropertyOp.getObjectName(), + setPropertyOp.getPropertyName(), + setPropertyOp.getCimValue() + ); + } else if (op instanceof CIMSetQualifierTypeOp) { + CIMSetQualifierTypeOp setQualifierTypeOp = (CIMSetQualifierTypeOp) op; + requestE = + setQualifierType_request(pDoc, setQualifierTypeOp.getObjectName(), setQualifierTypeOp.getQualifierType()); + } + if (requestE == null) throw new WBEMException( + WBEMException.CIM_ERR_INVALID_PARAMETER, + "Illegal batch operation number (" + i + ") " + op.getClass() + ); + messageE.appendChild(requestE); + } catch (WBEMException e) { + throw e; + } catch (Exception e) { + throw new WBEMException(WBEMException.CIM_ERR_FAILED, "At batch operation (" + i + ')', null, e); + } + i++; + } + return messageE; + } + + /** + * Sets the message id counter to a given value. For use in units tests + * only. + * + * @param pId + * The new value + */ + public void setId(int pId) { + this.iCurrentId.set(new Counter(pId - 1)); + } + + /** + * Get the next message id. If this method is called for the first time by + * the current thread it will choose a start value randomly. Afterwards the + * id is incremented by 1. Be aware that different threads will have + * distinct id counters. + * + * @return The next message id + */ + private int getNextId() { + if (this.iCurrentId.get() == null) { + this.iCurrentId.set(new Counter(RANDOM.nextInt(MAX_ID))); + } + return this.iCurrentId.get().incrementAndGet(); + } + + /** + * pAssociatorPaths_request + * + * @param pDoc + * @param pPath + * @param pAssocClass + * @param pResultClass + * @param pRole + * @param pResultRole + * @param pFilterQueryLanguage + * @param pFilterQuery + * @param pOperationTimeout + * @param pContinueOnError + * @param pMaxObjectCount + * @return Element + * @throws WBEMException + */ + public Element OpenAssociatorInstancePaths_request( + Document pDoc, + CIMObjectPath pPath, + String pAssocClass, + String pResultClass, + String pRole, + String pResultRole, + String pFilterQueryLanguage, + String pFilterQuery, + UnsignedInteger32 pOperationTimeout, + boolean pContinueOnError, + UnsignedInteger32 pMaxObjectCount + ) + throws WBEMException { + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "OpenAssociatorInstancePaths"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, INSTANCE_NAME); + CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, pPath); + + if (pAssocClass != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, ASSOC_CLASS); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pAssocClass); + } + if (pResultClass != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, RESULT_CLASS); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); + } + if (pRole != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, ROLE); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); + } + if (pResultRole != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, RESULT_ROLE); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pResultRole); + } + if (pFilterQueryLanguage != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, FILTER_QUERY_LANGUAGE); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQueryLanguage); + } + if (pFilterQuery != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, FILTER_QUERY); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQuery); + } + if (pOperationTimeout != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, OPERATION_TIMEOUT); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pOperationTimeout); + } + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, CONTINUE_ON_ERROR); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pContinueOnError); + + if (pMaxObjectCount != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, MAX_OBJECT_COUNT); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pMaxObjectCount); + } + + return simplereqE; + } + + /** + * OpenAssociatorInstances_request + * + * @param pDoc + * @param pPath + * @param pAssocClass + * @param pResultClass + * @param pRole + * @param pResultRole + * @param pIncludeClassOrigin + * @param pPropertyList + * @param pFilterQueryLanguage + * @param pFilterQuery + * @param pOperationTimeout + * @param pContinueOnError + * @param pMaxObjectCount + * @return Element OpenAssociatorInstances_request + * @throws WBEMException + */ + public Element OpenAssociatorInstances_request( + Document pDoc, + CIMObjectPath pPath, + String pAssocClass, + String pResultClass, + String pRole, + String pResultRole, + boolean pIncludeClassOrigin, + String[] pPropertyList, + String pFilterQueryLanguage, + String pFilterQuery, + UnsignedInteger32 pOperationTimeout, + boolean pContinueOnError, + UnsignedInteger32 pMaxObjectCount + ) + throws WBEMException { + String className = pPath.getObjectName(); + + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "OpenAssociatorInstances"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, INSTANCE_NAME); + // createINSTANCENAME will take care of keyBindings + CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, pPath); + + if (pAssocClass != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, ASSOC_CLASS); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pAssocClass); + } + if (pResultClass != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, RESULT_CLASS); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); + } + if (pRole != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, ROLE); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); + } + if (pResultRole != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, RESULT_ROLE); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pResultRole); + } + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, INCLUDE_CLASS_ORIGIN); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); + + if (pPropertyList != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, PROPERTY_LIST); + Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); + for (int i = 0; i < pPropertyList.length; i++) CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); + } + if (pFilterQueryLanguage != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, FILTER_QUERY_LANGUAGE); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQueryLanguage); + } + if (pFilterQuery != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, FILTER_QUERY); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQuery); + } + if (pOperationTimeout != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, OPERATION_TIMEOUT); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pOperationTimeout); + } + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, CONTINUE_ON_ERROR); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pContinueOnError); + + if (pMaxObjectCount != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, MAX_OBJECT_COUNT); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pMaxObjectCount); + } + + return simplereqE; + } + + /** + * OpenEnumerateInstancePaths_request + * + * @param pDoc + * @param pPath + * @param pFilterQueryLanguage + * @param pFilterQuery + * @param pOperationTimeout + * @param pContinueOnError + * @param pMaxObjectCount + * @return Element + * @throws WBEMException + */ + public Element OpenEnumerateInstancePaths_request( + Document pDoc, + CIMObjectPath pPath, + String pFilterQueryLanguage, + String pFilterQuery, + UnsignedInteger32 pOperationTimeout, + boolean pContinueOnError, + UnsignedInteger32 pMaxObjectCount + ) + throws WBEMException { + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "OpenEnumerateInstancePaths"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, CLASS_NAME); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, className); + + if (pFilterQueryLanguage != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, FILTER_QUERY_LANGUAGE); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQueryLanguage); + } + if (pFilterQuery != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, FILTER_QUERY); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQuery); + } + if (pOperationTimeout != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, OPERATION_TIMEOUT); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pOperationTimeout); + } + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, CONTINUE_ON_ERROR); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pContinueOnError); + + if (pMaxObjectCount != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, MAX_OBJECT_COUNT); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pMaxObjectCount); + } + + return simplereqE; + } + + /** + * OpenEnumerateInstances_request + * + * @param pDoc + * @param pPath + * @param pPropertyList + * @param pIncludeClassOrigin + * @param pDeepInheritance + * @param pFilterQueryLanguage + * @param pFilterQuery + * @param pOperationTimeout + * @param pContinueOnError + * @param pMaxObjectCount + * @return Element + * @throws WBEMException + */ + public Element OpenEnumerateInstances_request( + Document pDoc, + CIMObjectPath pPath, + boolean pDeepInheritance, + boolean pIncludeClassOrigin, + String[] pPropertyList, + String pFilterQueryLanguage, + String pFilterQuery, + UnsignedInteger32 pOperationTimeout, + boolean pContinueOnError, + UnsignedInteger32 pMaxObjectCount + ) + throws WBEMException { + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "OpenEnumerateInstances"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, CLASS_NAME); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, className); + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, DEEP_INHERITANCE); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pDeepInheritance); + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, INCLUDE_CLASS_ORIGIN); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); + + if (pPropertyList != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, PROPERTY_LIST); + Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); + for (int i = 0; i < pPropertyList.length; i++) CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); + } + + if (pFilterQueryLanguage != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, FILTER_QUERY_LANGUAGE); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQueryLanguage); + } + if (pFilterQuery != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, FILTER_QUERY); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQuery); + } + if (pOperationTimeout != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, OPERATION_TIMEOUT); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pOperationTimeout); + } + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, CONTINUE_ON_ERROR); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pContinueOnError); + + if (pMaxObjectCount != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, MAX_OBJECT_COUNT); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pMaxObjectCount); + } + + return simplereqE; + } + + /** + * EnumerationCount_request + * + * @param pDoc + * @param pPath + * @param pEnumerationContext + * @return Element + * @throws WBEMException + */ + public Element EnumerationCount_request(Document pDoc, CIMObjectPath pPath, String pEnumerationContext) + throws WBEMException { + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "EnumerationCount"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + if (pEnumerationContext != null) { + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, ENUMERATION_CONTEXT); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pEnumerationContext); + } + + return simplereqE; + } + + /** + * CloseEnumeration_request + * + * @param pDoc + * @param pPath + * @param pEnumerationContext + * @return Element + * @throws WBEMException + */ + public Element CloseEnumeration_request(Document pDoc, CIMObjectPath pPath, String pEnumerationContext) + throws WBEMException { + String className = pPath.getObjectName(); + + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "CloseEnumeration"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + if (pEnumerationContext != null) { + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, ENUMERATION_CONTEXT); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pEnumerationContext); + } + return simplereqE; + } + + /** + * referencePaths_request + * + * @param pDoc + * @param pPath + * @param pResultClass + * @param pRole + * @param pFilterQueryLanguage + * @param pFilterQuery + * @param pOperationTimeout + * @param pContinueOnError + * @param pMaxObjectCount + * @return Element referencePaths_request + * @throws WBEMException + */ + public Element OpenReferenceInstancePaths_request( + Document pDoc, + CIMObjectPath pPath, + String pResultClass, + String pRole, + String pFilterQueryLanguage, + String pFilterQuery, + UnsignedInteger32 pOperationTimeout, + boolean pContinueOnError, + UnsignedInteger32 pMaxObjectCount + ) + throws WBEMException { + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "OpenReferenceInstancePaths"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, INSTANCE_NAME); + CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, pPath); + + if (pResultClass != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, RESULT_CLASS); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); + } + if (pRole != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, ROLE); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); + } + if (pFilterQueryLanguage != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, FILTER_QUERY_LANGUAGE); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQueryLanguage); + } + if (pFilterQuery != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, FILTER_QUERY); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQuery); + } + if (pOperationTimeout != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, OPERATION_TIMEOUT); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pOperationTimeout); + } + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, CONTINUE_ON_ERROR); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pContinueOnError); + + if (pMaxObjectCount != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, MAX_OBJECT_COUNT); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pMaxObjectCount); + } + + return simplereqE; + } + + /** + * references_request + * + * @param pDoc + * @param pPath + * @param pResultClass + * @param pRole + * @param pIncludeClassOrigin + * @param pPropertyList + * @param pFilterQueryLanguage + * @param pFilterQuery + * @param pOperationTimeout + * @param pContinueOnError + * @param pMaxObjectCount + * @return Element references_request + * @throws WBEMException + */ + public Element OpenReferenceInstances_request( + Document pDoc, + CIMObjectPath pPath, + String pResultClass, + String pRole, + boolean pIncludeClassOrigin, + String[] pPropertyList, + String pFilterQueryLanguage, + String pFilterQuery, + UnsignedInteger32 pOperationTimeout, + boolean pContinueOnError, + UnsignedInteger32 pMaxObjectCount + ) + throws WBEMException { + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "OpenReferenceInstances"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, INSTANCE_NAME); + CIMXMLBuilderImpl.createINSTANCENAME(pDoc, iparamvalueE, pPath); + + if (pResultClass != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, RESULT_CLASS); + CIMXMLBuilderImpl.createCLASSNAME(pDoc, iparamvalueE, pResultClass); + } + if (pRole != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, ROLE); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pRole); + } + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, INCLUDE_CLASS_ORIGIN); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pIncludeClassOrigin); + + if (pPropertyList != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, PROPERTY_LIST); + Element valuearrayE = CIMXMLBuilderImpl.createVALUEARRAY(pDoc, iparamvalueE); + for (int i = 0; i < pPropertyList.length; i++) CIMXMLBuilderImpl.createVALUE(pDoc, valuearrayE, pPropertyList[i]); + } + + if (pFilterQueryLanguage != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, FILTER_QUERY_LANGUAGE); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQueryLanguage); + } + if (pFilterQuery != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, FILTER_QUERY); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQuery); + } + if (pOperationTimeout != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, OPERATION_TIMEOUT); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pOperationTimeout); + } + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, CONTINUE_ON_ERROR); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pContinueOnError); + + if (pMaxObjectCount != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, MAX_OBJECT_COUNT); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pMaxObjectCount); + } + + return simplereqE; + } + + /** + * OpenQueryInstances_request + * + * @param pDoc + * @param pPath + * @param pFilterQuery + * @param pFilterQueryLanguage + * @param pReturnQueryResultClass + * @param pOperationTimeout + * @param pContinueOnError + * @param pMaxObjectCount + * @param pQueryResultClass + * @return Element OpenQueryInstances_request + * @throws WBEMException + */ + public Element OpenQueryInstances_request( + Document pDoc, + CIMObjectPath pPath, + String pFilterQuery, + String pFilterQueryLanguage, + boolean pReturnQueryResultClass, + UnsignedInteger32 pOperationTimeout, + boolean pContinueOnError, + UnsignedInteger32 pMaxObjectCount, + CIMClass pQueryResultClass + ) + throws WBEMException { + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "OpenQueryInstances"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE; + + if (pFilterQuery != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, FILTER_QUERY); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQuery); + } + if (pFilterQueryLanguage != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, FILTER_QUERY_LANGUAGE); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pFilterQueryLanguage); + } + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, RETURN_QUERY_RESULT_CLASS); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pReturnQueryResultClass); + + if (pOperationTimeout != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, OPERATION_TIMEOUT); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pOperationTimeout); + } + + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, CONTINUE_ON_ERROR); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pContinueOnError); + + if (pMaxObjectCount != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, MAX_OBJECT_COUNT); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pMaxObjectCount); + } + if (pQueryResultClass != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, QUERY_RESULT_CLASS); + CIMXMLBuilderImpl.createCLASS(pDoc, iparamvalueE, pQueryResultClass); + } + return simplereqE; + } + + /** + * PullInstancesWithPath_request + * + * @param pDoc + * @param pPath + * @param pContext + * @param pMaxObjectCount + * @return Element PullInstancesWithPath_request + * @throws WBEMException + */ + public Element PullInstancesWithPath_request( + Document pDoc, + CIMObjectPath pPath, + String pContext, + UnsignedInteger32 pMaxObjectCount + ) + throws WBEMException { + String className = pPath.getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "PullInstancesWithPath"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE; + + if (pContext != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, ENUMERATION_CONTEXT); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pContext); + } + + if (pMaxObjectCount != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, MAX_OBJECT_COUNT); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pMaxObjectCount); + } + + return simplereqE; + } + + /** + * PullInstancePaths_request + * + * @param pDoc + * @param pPath + * @param pContext + * @param pMaxObjectCount + * @return Element PullInstancePaths + * @throws WBEMException + */ + public Element PullInstancePaths_request( + Document pDoc, + CIMObjectPath pPath, + String pContext, + UnsignedInteger32 pMaxObjectCount + ) + throws WBEMException { + String className = pPath.getObjectName(); + + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "PullInstancePaths"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE; + + if (pContext != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, ENUMERATION_CONTEXT); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pContext); + } + + if (pMaxObjectCount != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, MAX_OBJECT_COUNT); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pMaxObjectCount); + } + + return simplereqE; + } + + /** + * PullInstances_request + * + * @param pDoc + * @param pPath + * @param pContext + * @param pMaxObjectCount + * @return Element PullInstances_request + * @throws WBEMException + */ + public Element PullInstances_request( + Document pDoc, + CIMObjectPath pPath, + String pContext, + UnsignedInteger32 pMaxObjectCount + ) + throws WBEMException { + String className = pPath.getObjectName(); + + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); + + Element simplereqE = CIMXMLBuilderImpl.createSIMPLEREQ(pDoc); + Element imethodcallE = CIMXMLBuilderImpl.createIMETHODCALL(pDoc, simplereqE, "PullInstances"); + CIMXMLBuilderImpl.createLOCALNAMESPACEPATH(pDoc, imethodcallE, pPath); + + Element iparamvalueE; + + if (pContext != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, ENUMERATION_CONTEXT); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pContext); + } + + if (pMaxObjectCount != null) { + iparamvalueE = CIMXMLBuilderImpl.createIPARAMVALUE(pDoc, imethodcallE, MAX_OBJECT_COUNT); + CIMXMLBuilderImpl.createVALUE(pDoc, iparamvalueE, pMaxObjectCount); + } + + return simplereqE; + } + + /** + * sendIndication_request + * + * @param pDoc + * @param pIndication + * @return Element sendIndication_request + * @throws WBEMException + */ + public Element sendIndication_request(Document pDoc, CIMInstance pIndication) throws WBEMException { + Element simpleexpreqE = CIMXMLBuilderImpl.createSIMPLEEXPREQ(pDoc); + Element expmethodcallE = CIMXMLBuilderImpl.createEXPMETHODCALL(pDoc, simpleexpreqE, "ExportIndication"); + Element expparamvalueE = CIMXMLBuilderImpl.createEXPPARAMVALUE(pDoc, expmethodcallE, "NewIndication"); + + CIMXMLBuilderImpl.createINSTANCE(pDoc, expparamvalueE, pIndication); + + return simpleexpreqE; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CIMMessage.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CIMMessage.java similarity index 75% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CIMMessage.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CIMMessage.java index b290726..9b091d4 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CIMMessage.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CIMMessage.java @@ -1,199 +1,195 @@ -/* - CIMMessage.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Hashtable; - -import org.w3c.dom.Document; - -/** - * Class CIMMessage is used by the CIM-XML DOM parser. - */ -public class CIMMessage { - - protected Document iDoc; - - protected Hashtable iElements; - - protected String iCimVersion; - - protected String iDtdVersion; - - protected String iId; - - protected String iProtocolVersion; - - protected String iMethod; - - protected boolean iIsCIMExport = false; - - protected boolean iIsSimple = false; - - protected boolean iIsRequest = false; - - protected CIMMessage() { /**/} - - /** - * Ctor. - * - * @param pCimVersion - * @param pDtdVersion - * @param pId - * @param pMethod - */ - public CIMMessage(String pCimVersion, String pDtdVersion, String pId, String pMethod) { - this.iCimVersion = pCimVersion; - this.iDtdVersion = pDtdVersion; - this.iId = pId; - this.iMethod = pMethod; - } - - /** - * getCIMVersion - * - * @return String - */ - public String getCIMVersion() { - return this.iCimVersion; - } - - /** - * getDTDVersion - * - * @return String - */ - public String getDTDVersion() { - return this.iDtdVersion; - } - - /** - * isCIMOperation - * - * @return String - */ - public boolean isCIMOperation() { - return !this.iIsCIMExport; - } - - /** - * isCIMExport - * - * @return String - */ - public boolean isCIMExport() { - return this.iIsCIMExport; - } - - /** - * setId - * - * @param pId - */ - public void setId(String pId) { - this.iId = pId; - } - - /** - * setMethod - * - * @param pMethod - */ - public void setMethod(String pMethod) { - - this.iMethod = pMethod; - this.iIsCIMExport = (pMethod.toUpperCase().endsWith("EXPREQ") || pMethod.toUpperCase() - .endsWith("EXPRSP")); - this.iIsRequest = (pMethod.toUpperCase().endsWith("REQ")); - this.iIsSimple = pMethod.toUpperCase().startsWith("SIMPLE"); - } - - /** - * setCIMVersion - * - * @param pCimVersion - */ - public void setCIMVersion(String pCimVersion) { - this.iCimVersion = pCimVersion; - } - - /** - * setDTDVersion - * - * @param pDtdVersion - */ - public void setDTDVersion(String pDtdVersion) { - this.iDtdVersion = pDtdVersion; - } - - /** - * setIsRequest - * - * @param pValue - */ - public void setIsRequest(boolean pValue) { - this.iIsRequest = pValue; - } - - /** - * getId - * - * @return String - */ - public String getId() { - return this.iId; - } - - /** - * getProtocolVersion - * - * @return String - */ - public String getProtocolVersion() { - return this.iProtocolVersion; - } -} +/* + CIMMessage.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Hashtable; +import org.w3c.dom.Document; + +/** + * Class CIMMessage is used by the CIM-XML DOM parser. + */ +public class CIMMessage { + protected Document iDoc; + + protected Hashtable iElements; + + protected String iCimVersion; + + protected String iDtdVersion; + + protected String iId; + + protected String iProtocolVersion; + + protected String iMethod; + + protected boolean iIsCIMExport = false; + + protected boolean iIsSimple = false; + + protected boolean iIsRequest = false; + + protected CIMMessage() { + /**/ + } + + /** + * Ctor. + * + * @param pCimVersion + * @param pDtdVersion + * @param pId + * @param pMethod + */ + public CIMMessage(String pCimVersion, String pDtdVersion, String pId, String pMethod) { + this.iCimVersion = pCimVersion; + this.iDtdVersion = pDtdVersion; + this.iId = pId; + this.iMethod = pMethod; + } + + /** + * getCIMVersion + * + * @return String + */ + public String getCIMVersion() { + return this.iCimVersion; + } + + /** + * getDTDVersion + * + * @return String + */ + public String getDTDVersion() { + return this.iDtdVersion; + } + + /** + * isCIMOperation + * + * @return String + */ + public boolean isCIMOperation() { + return !this.iIsCIMExport; + } + + /** + * isCIMExport + * + * @return String + */ + public boolean isCIMExport() { + return this.iIsCIMExport; + } + + /** + * setId + * + * @param pId + */ + public void setId(String pId) { + this.iId = pId; + } + + /** + * setMethod + * + * @param pMethod + */ + public void setMethod(String pMethod) { + this.iMethod = pMethod; + this.iIsCIMExport = (pMethod.toUpperCase().endsWith("EXPREQ") || pMethod.toUpperCase().endsWith("EXPRSP")); + this.iIsRequest = (pMethod.toUpperCase().endsWith("REQ")); + this.iIsSimple = pMethod.toUpperCase().startsWith("SIMPLE"); + } + + /** + * setCIMVersion + * + * @param pCimVersion + */ + public void setCIMVersion(String pCimVersion) { + this.iCimVersion = pCimVersion; + } + + /** + * setDTDVersion + * + * @param pDtdVersion + */ + public void setDTDVersion(String pDtdVersion) { + this.iDtdVersion = pDtdVersion; + } + + /** + * setIsRequest + * + * @param pValue + */ + public void setIsRequest(boolean pValue) { + this.iIsRequest = pValue; + } + + /** + * getId + * + * @return String + */ + public String getId() { + return this.iId; + } + + /** + * getProtocolVersion + * + * @return String + */ + public String getProtocolVersion() { + return this.iProtocolVersion; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CIMRequest.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CIMRequest.java similarity index 72% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CIMRequest.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CIMRequest.java index d7af6b1..e5bc5fe 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CIMRequest.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CIMRequest.java @@ -1,168 +1,165 @@ -/* - CIMRequest.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Vector; - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * Class CIMRequest is used by the CIM-XML DOM parser. - * - */ -public class CIMRequest extends CIMMessage { - - protected Vector iRequests = new Vector(0); - - protected Vector iParamValue = new Vector(0); - - protected String iMethodName; - - protected CIMObjectPath iPath; - - protected String iNamespace; - - /** - * Ctor. - */ - public CIMRequest() { /**/} - - /** - * Ctor. - * - * @param pCimVersion - * @param pDtdVersion - * @param pId - * @param pMethod - */ - public CIMRequest(String pCimVersion, String pDtdVersion, String pId, String pMethod) { - super(pCimVersion, pDtdVersion, pId, pMethod); - } - - /** - * addParamValue - * - * @param v - */ - public void addParamValue(Object v) { - if (v instanceof Vector) this.iParamValue.addAll((Vector) v); - else this.iParamValue.add(v); - } - - /** - * addRequest - * - * @param request - */ - public void addRequest(CIMRequest request) { - this.iRequests.add(request); - } - - /** - * getMethodName - * - * @return String - */ - public String getMethodName() { - return this.iMethodName; - } - - /** - * getNameSpace - * - * @return String - */ - public String getNameSpace() { - return this.iNamespace; - } - - /** - * getObjectPath - * - * @return String - */ - public CIMObjectPath getObjectPath() { - return this.iPath; - } - - /** - * getParamValue - * - * @return String - */ - public Vector getParamValue() { - return this.iParamValue; - } - - /** - * setMethodName - * - * @param methodName - */ - public void setMethodName(String methodName) { - this.iMethodName = methodName; - } - - /** - * setNameSpace - * - * @param namespace - */ - public void setNameSpace(String namespace) { - this.iNamespace = namespace; - } - - /** - * setObjectPath - * - * @param path - */ - public void setObjectPath(CIMObjectPath path) { - this.iPath = path; - } -} +/* + CIMRequest.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Vector; +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * Class CIMRequest is used by the CIM-XML DOM parser. + * + */ +public class CIMRequest extends CIMMessage { + protected Vector iRequests = new Vector(0); + + protected Vector iParamValue = new Vector(0); + + protected String iMethodName; + + protected CIMObjectPath iPath; + + protected String iNamespace; + + /** + * Ctor. + */ + public CIMRequest() { + /**/ + } + + /** + * Ctor. + * + * @param pCimVersion + * @param pDtdVersion + * @param pId + * @param pMethod + */ + public CIMRequest(String pCimVersion, String pDtdVersion, String pId, String pMethod) { + super(pCimVersion, pDtdVersion, pId, pMethod); + } + + /** + * addParamValue + * + * @param v + */ + public void addParamValue(Object v) { + if (v instanceof Vector) this.iParamValue.addAll((Vector) v); else this.iParamValue.add(v); + } + + /** + * addRequest + * + * @param request + */ + public void addRequest(CIMRequest request) { + this.iRequests.add(request); + } + + /** + * getMethodName + * + * @return String + */ + public String getMethodName() { + return this.iMethodName; + } + + /** + * getNameSpace + * + * @return String + */ + public String getNameSpace() { + return this.iNamespace; + } + + /** + * getObjectPath + * + * @return String + */ + public CIMObjectPath getObjectPath() { + return this.iPath; + } + + /** + * getParamValue + * + * @return String + */ + public Vector getParamValue() { + return this.iParamValue; + } + + /** + * setMethodName + * + * @param methodName + */ + public void setMethodName(String methodName) { + this.iMethodName = methodName; + } + + /** + * setNameSpace + * + * @param namespace + */ + public void setNameSpace(String namespace) { + this.iNamespace = namespace; + } + + /** + * setObjectPath + * + * @param path + */ + public void setObjectPath(CIMObjectPath path) { + this.iPath = path; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CIMResponse.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CIMResponse.java similarity index 77% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CIMResponse.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CIMResponse.java index 154a94b..7206e5e 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CIMResponse.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CIMResponse.java @@ -1,229 +1,225 @@ -/* - CIMResponse.java - - (C) Copyright IBM Corp. 2005, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 3525135 2012-05-09 blaschke-oss Remove CIMResponse.isSuccessul - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.List; -import java.util.Vector; - -import org.sentrysoftware.wbem.javax.wbem.WBEMException; - -/** - * Represent a CIMReponse message. - */ -public class CIMResponse extends CIMMessage { - - protected Vector iResponses = new Vector(0); - - protected WBEMException iError = null; - - protected Vector iReturnValue = new Vector(); - - protected Vector iParamValue = new Vector(0); - - /** - * Constructs a CIMResponse object. - * - */ - public CIMResponse() { /**/} - - /** - * Constructs a CIMResponse object with the specified CIMVersion, DTDVersion - * and method. - * - * @param pCimVersion - * @param pDtdVersion - * @param pId - * @param pMethod - */ - public CIMResponse(String pCimVersion, String pDtdVersion, String pId, String pMethod) { - super(pCimVersion, pDtdVersion, pId, pMethod); - } - - /** - * Constructs a CIM Response message from a given CIM Request. - * - * @param request - */ - public CIMResponse(CIMRequest request) { - super(); - this.iCimVersion = request.getCIMVersion(); - this.iDtdVersion = request.getDTDVersion(); - } - - /** - * addParamValue - * - * @param o - */ - public void addParamValue(Object o) { - this.iParamValue.add(o); - } - - /** - * addParamValue - * - * @param v - */ - public void addParamValue(Vector v) { - this.iParamValue.addAll(v); - } - - /** - * addResponse - * - * @param response - */ - public void addResponse(CIMResponse response) { - this.iResponses.add(response); - } - - /** - * addReturnValue - * - * @param o - */ - public void addReturnValue(Object o) { - this.iReturnValue.add(o); - } - - /** - * Verify the status code for this CIMResponse. - * - * @throws WBEMException - * if the status code is other than success. - */ - public void checkError() throws WBEMException { - if (this.iError != null) throw this.iError; - } - - /** - * getAllResponses - * - * @return List - */ - public List getAllResponses() { - return this.iResponses; - } - - /** - * getException - * - * @return WBEMException - */ - public WBEMException getException() { - return this.iError; - } - - /** - * isSuccessful - * - * @return boolean - */ - public boolean isSuccessful() { - return this.iError == null; - } - - /** - * getFirstResponse - * - * @return CIMResponse - */ - public CIMResponse getFirstResponse() { - if (this.iResponses != null && this.iResponses.size() > 0) return this.iResponses - .elementAt(0); - return null; - } - - /** - * getParamValues - * - * @return List - */ - public List getParamValues() { - return this.iParamValue; - } - - /** - * getFirstReturnValue - * - * @return List - */ - public List getFirstReturnValue() { - return this.iReturnValue; - } - - /** - * setError - * - * @param error - */ - public void setError(WBEMException error) { - this.iError = error; - } - - /** - * setParamValue - * - * @param paramValue - */ - public void setParamValue(Vector paramValue) { - this.iParamValue = paramValue; - } - - /** - * setReturnValue - * - * @param returnValue - */ - public void setReturnValue(Vector returnValue) { - this.iReturnValue = returnValue; - } - -} +/* + CIMResponse.java + + (C) Copyright IBM Corp. 2005, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 3525135 2012-05-09 blaschke-oss Remove CIMResponse.isSuccessul + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.List; +import java.util.Vector; +import org.metricshub.wbem.javax.wbem.WBEMException; + +/** + * Represent a CIMReponse message. + */ +public class CIMResponse extends CIMMessage { + protected Vector iResponses = new Vector(0); + + protected WBEMException iError = null; + + protected Vector iReturnValue = new Vector(); + + protected Vector iParamValue = new Vector(0); + + /** + * Constructs a CIMResponse object. + * + */ + public CIMResponse() { + /**/ + } + + /** + * Constructs a CIMResponse object with the specified CIMVersion, DTDVersion + * and method. + * + * @param pCimVersion + * @param pDtdVersion + * @param pId + * @param pMethod + */ + public CIMResponse(String pCimVersion, String pDtdVersion, String pId, String pMethod) { + super(pCimVersion, pDtdVersion, pId, pMethod); + } + + /** + * Constructs a CIM Response message from a given CIM Request. + * + * @param request + */ + public CIMResponse(CIMRequest request) { + super(); + this.iCimVersion = request.getCIMVersion(); + this.iDtdVersion = request.getDTDVersion(); + } + + /** + * addParamValue + * + * @param o + */ + public void addParamValue(Object o) { + this.iParamValue.add(o); + } + + /** + * addParamValue + * + * @param v + */ + public void addParamValue(Vector v) { + this.iParamValue.addAll(v); + } + + /** + * addResponse + * + * @param response + */ + public void addResponse(CIMResponse response) { + this.iResponses.add(response); + } + + /** + * addReturnValue + * + * @param o + */ + public void addReturnValue(Object o) { + this.iReturnValue.add(o); + } + + /** + * Verify the status code for this CIMResponse. + * + * @throws WBEMException + * if the status code is other than success. + */ + public void checkError() throws WBEMException { + if (this.iError != null) throw this.iError; + } + + /** + * getAllResponses + * + * @return List + */ + public List getAllResponses() { + return this.iResponses; + } + + /** + * getException + * + * @return WBEMException + */ + public WBEMException getException() { + return this.iError; + } + + /** + * isSuccessful + * + * @return boolean + */ + public boolean isSuccessful() { + return this.iError == null; + } + + /** + * getFirstResponse + * + * @return CIMResponse + */ + public CIMResponse getFirstResponse() { + if (this.iResponses != null && this.iResponses.size() > 0) return this.iResponses.elementAt(0); + return null; + } + + /** + * getParamValues + * + * @return List + */ + public List getParamValues() { + return this.iParamValue; + } + + /** + * getFirstReturnValue + * + * @return List + */ + public List getFirstReturnValue() { + return this.iReturnValue; + } + + /** + * setError + * + * @param error + */ + public void setError(WBEMException error) { + this.iError = error; + } + + /** + * setParamValue + * + * @param paramValue + */ + public void setParamValue(Vector paramValue) { + this.iParamValue = paramValue; + } + + /** + * setReturnValue + * + * @param returnValue + */ + public void setReturnValue(Vector returnValue) { + this.iReturnValue = returnValue; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CIMXMLBuilderImpl.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CIMXMLBuilderImpl.java similarity index 83% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CIMXMLBuilderImpl.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CIMXMLBuilderImpl.java index f96fc44..1d6a179 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CIMXMLBuilderImpl.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CIMXMLBuilderImpl.java @@ -1,2300 +1,2328 @@ -/* - CIMXMLBuilderImpl.java - - (C) Copyright IBM Corp. 2005, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------ - * 16627 2005-04-01 thschaef Correct instantiation for Uint64 - * 17459 2005-06-24 thschaef catch null within createMethod method - * 17459 2005-06-27 thschaef further improvement to createMethod() - * 1535756 2006-08-07 lupusalex Make code warning free - * 1610046 2006-07-12 ebak Does not escape trailing spaces KEYVALUE - * 1631407 2007-01-11 lupusalex VALUE.REFERENCE doesn't handle references without namespace - * 1656285 2007-02-12 ebak IndicationHandler does not accept non-Integer message ID - * 1671505 2007-02-28 lupusalex Wrong escaping of spaces in XML (Undo 1610046) - * 1660756 2007-03-02 ebak Embedded object support - * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus - * 1669961 2006-04-16 lupusalex CIMTypedElement.getType() =>getDataType() - * 1719991 2007-05-16 ebak FVT: regression ClassCastException in EmbObjHandler - * 1737141 2007-06-18 ebak Sync up with JSR48 evolution - * 1820763 2007-10-29 ebak Supporting the EmbeddedInstance qualifier - * 1827728 2007-11-12 ebak embeddedInstances: attribute EmbeddedObject not set - * 1827728 2007-11-20 ebak rework: embeddedInstances: attribute EmbeddedObject not set - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2087969 2008-09-03 blaschke-oss VALUE.ARRAY used in request for array of references - * 2093708 2008-09-10 rgummada HTTP 400 - Bad Request, CIMError: request-not-valid - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2210455 2008-10-30 blaschke-oss Enhance javadoc, fix potential null pointers - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2823494 2009-08-03 rgummada Change Boolean constructor to static - * 2849970 2009-09-03 blaschke-oss createVALUEARRAY fails to create reference array - * 2912490 2010-01-05 rgummada NullPointerException when invoking getInstance - * 2957387 2010-03-03 blaschke-oss EmbededObject XML attribute must not be all uppercases - * 2970881 2010-03-15 blaschke-oss Add property to control EmbeddedObject case - * 3001333 2010-05-19 blaschke-oss CIMMethod class ignores propagated parameter - * 3304058 2011-05-20 blaschke-oss Use same date format in change history - * 3588558 2012-11-26 blaschke-oss An enhancement on Java CIM Client logging - * 2616 2013-02-23 blaschke-oss Add new API WBEMClientSBLIM.sendIndication() - * 2638 2013-05-09 blaschke-oss Do not build empty REFERENCECLASS - * 2689 2013-10-10 blaschke-oss createMETHODCALL should not add PARAMTYPE attribute - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.sentrysoftware.wbem.javax.cim.CIMArgument; -import org.sentrysoftware.wbem.javax.cim.CIMClass; -import org.sentrysoftware.wbem.javax.cim.CIMClassProperty; -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMFlavor; -import org.sentrysoftware.wbem.javax.cim.CIMInstance; -import org.sentrysoftware.wbem.javax.cim.CIMMethod; -import org.sentrysoftware.wbem.javax.cim.CIMNamedElementInterface; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import org.sentrysoftware.wbem.javax.cim.CIMParameter; -import org.sentrysoftware.wbem.javax.cim.CIMProperty; -import org.sentrysoftware.wbem.javax.cim.CIMQualifiedElementInterface; -import org.sentrysoftware.wbem.javax.cim.CIMQualifier; -import org.sentrysoftware.wbem.javax.cim.CIMQualifierType; -import org.sentrysoftware.wbem.javax.cim.CIMScope; -import org.sentrysoftware.wbem.javax.cim.CIMTypedElement; -import org.sentrysoftware.wbem.javax.cim.CIMValuedElement; -import org.sentrysoftware.wbem.javax.wbem.WBEMException; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.CIMQualifiedElementInterfaceImpl; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.MOF; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConfiguration; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.CIMError; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Text; - -/** - * Class CIMXMLBuilderImpl is the core class for building CIM-XML documents. - */ -public class CIMXMLBuilderImpl { - - private static final int MAJOR_CIM_VERSION = 2; - - private static final int MINOR_CIM_VERSION = 0; - - private static final int MAJOR_DTD_VERSION = 2; - - private static final int MINOR_DTD_VERSION = 0; - - /** - * createCIM - * - * @param pDoc - * @return Element - */ - public static Element createCIM(Document pDoc) { - // - // - Element e = pDoc.createElement("CIM"); - e.setAttribute("CIMVERSION", MAJOR_CIM_VERSION + "." + MINOR_CIM_VERSION); - // required - e.setAttribute("DTDVERSION", MAJOR_DTD_VERSION + "." + MINOR_DTD_VERSION); - // required - pDoc.appendChild(e); // root element - return e; - } - - // //////////////////////////////////////////////////////////////////////////////////////// - // Value Elements - // //////////////////////////////////////////////////////////////////////////////////////// - - /** - * createVALUE - * - * @param pDoc - * @param pParentE - * @return Element - */ - public static Element createVALUE(Document pDoc, Element pParentE) { - // - Element e = pDoc.createElement("VALUE"); - pParentE.appendChild(e); - - return e; - } - - /** - * createVALUE - * - * @param pDoc - * @param pParentE - * @param pValue - * @return Element - */ - public static Element createVALUE(Document pDoc, Element pParentE, String pValue) { - // - Element e = pDoc.createElement("VALUE"); - pParentE.appendChild(e); - - Text textE = pDoc.createTextNode(pValue); - e.appendChild(textE); - return e; - } - - /** - * createVALUE - * - * @param pDoc - * @param pParentE - * @param pValue - * @return Element - */ - public static Element createVALUE(Document pDoc, Element pParentE, boolean pValue) { - return createVALUE(pDoc, pParentE, pValue ? MOF.TRUE : MOF.FALSE); - } - - /** - * createVALUEARRAY - * - * @param pDoc - * @param pParentE - * @return Element - */ - public static Element createVALUEARRAY(Document pDoc, Element pParentE) { - // - Element e = pDoc.createElement("VALUE.ARRAY"); - pParentE.appendChild(e); - return e; - } - - /** - * createVALUEREFERENCE - * - * @param pDoc - * @param pParentE - * @return Element - */ - public static Element createVALUEREFERENCE(Document pDoc, Element pParentE) { - // - Element e = pDoc.createElement("VALUE.REFERENCE"); - pParentE.appendChild(e); - return e; - } - - /** - * createVALUEREFARRAY - * - * @param pDoc - * @param pParentE - * @return Element - */ - public static Element createVALUEREFARRAY(Document pDoc, Element pParentE) { - // - Element e = pDoc.createElement("VALUE.REFARRAY"); - pParentE.appendChild(e); - return e; - } - - // //////////////////////////////////////////////////////////////////////////////////////// - // Properties elements - // //////////////////////////////////////////////////////////////////////////////////////// - /** - * createPROPERTY - * - * @param pDoc - * @param pParentE - * @param pName - * @param pType - * @return Element - */ - public static Element createPROPERTY(Document pDoc, Element pParentE, String pName, String pType) { - // - // - - Element e = pDoc.createElement("PROPERTY"); - if (pName != null) e.setAttribute("NAME", pName); - if (pType != null) e.setAttribute("TYPE", pType); - // TODO: ClassOrigin, Propagated - pParentE.appendChild(e); - return e; - } - - /** - * createPROPERTYARRAY - * - * @param pDoc - * @param pParentE - * @param pName - * @param pType - * @return Element - */ - public static Element createPROPERTYARRAY(Document pDoc, Element pParentE, String pName, - String pType) { - // - // - - Element e = pDoc.createElement("PROPERTY.ARRAY"); - if (pName != null) e.setAttribute("NAME", pName); - if (pType != null) e.setAttribute("TYPE", pType); - // TODO: ClassOrigin, Propagated - pParentE.appendChild(e); - return e; - } - - /** - * createPROPERTYREFERENCE - * - * @param pDoc - * @param pParentE - * @param pName - * @param pReferenceclass - * @return Element - */ - public static Element createPROPERTYREFERENCE(Document pDoc, Element pParentE, String pName, - String pReferenceclass) { - // - // - - Element e = pDoc.createElement("PROPERTY.REFERENCE"); - if (pName != null) e.setAttribute("NAME", pName); - if (pReferenceclass != null && pReferenceclass.length() > 0) e.setAttribute( - "REFERENCECLASS", pReferenceclass); - pParentE.appendChild(e); - return e; - } - - // //////////////////////////////////////////////////////////////////////////////////////// - // Naming and Location elements - // //////////////////////////////////////////////////////////////////////////////////////// - - /** - * createNAMESPACE - * - * @param pDoc - * @param pParentE - * @param pName - * @return Element - */ - public static Element createNAMESPACE(Document pDoc, Element pParentE, String pName) { - // - // - Element e = pDoc.createElement("NAMESPACE"); - if (pName != null) { - e.setAttribute("NAME", pName); - } - pParentE.appendChild(e); - return e; - } - - /** - * createLOCALINSTANCEPATH - * - * @param pDoc - * @param pParentE - * @return Element - */ - public static Element createLOCALINSTANCEPATH(Document pDoc, Element pParentE) { - // - Element e = pDoc.createElement("LOCALINSTANCEPATH"); - pParentE.appendChild(e); - return e; - } - - /** - * createCLASSNAME - * - * @param pDoc - * @param pParentE - * @param pName - * @return Element - */ - public static Element createCLASSNAME(Document pDoc, Element pParentE, String pName) { - // - // - Element e = pDoc.createElement("CLASSNAME"); - if (pName != null) { - e.setAttribute("NAME", pName); - - pParentE.appendChild(e); - } - return e; - } - - /** - * createCLASS - * - * @param pDoc - * @param pParentE - * @param pName - * @param pSuperClass - * @return Element - */ - public static Element createCLASS(Document pDoc, Element pParentE, String pName, - String pSuperClass) { - // - // - Element e = pDoc.createElement("CLASS"); - if (pName != null) { - e.setAttribute("NAME", pName); - - } - if (pSuperClass != null && pSuperClass.length() > 0) { - e.setAttribute("SUPERCLASS", pSuperClass); - - } - if (pParentE != null) pParentE.appendChild(e); - return e; - } - - /** - * createINSTANCENAME - * - * @param pDoc - * @param pParentE - * @param pClassName - * @return Element - */ - public static Element createINSTANCENAME(Document pDoc, Element pParentE, String pClassName) { - // - // - Element e = pDoc.createElement("INSTANCENAME"); - if (pClassName != null) { - e.setAttribute("CLASSNAME", pClassName); - } - pParentE.appendChild(e); - return e; - } - - /** - * createKEYBINDING - * - * @param pDoc - * @param pParentE - * @param pName - * @return Element - */ - public static Element createKEYBINDING(Document pDoc, Element pParentE, String pName) { - // - // - Element e = pDoc.createElement("KEYBINDING"); - if (pName != null) { - e.setAttribute("NAME", pName); - } - pParentE.appendChild(e); - return e; - } - - private static final Pattern NUM_PAT = Pattern.compile("^[su]int(8|16|32|64)$", - Pattern.CASE_INSENSITIVE); - - /** - * - * getValueTypeStr - * - * @param pTypeStr - * @return String - */ - private static String getValueTypeStr(String pTypeStr) { - - if (pTypeStr == null || MOF.DT_STR.equalsIgnoreCase(pTypeStr)) return MOF.DT_STR; - if (MOF.DT_BOOL.equalsIgnoreCase(pTypeStr)) return MOF.DT_BOOL; - Matcher m = NUM_PAT.matcher(pTypeStr); - if (m.matches()) return "numeric"; - return MOF.DT_STR; - } - - /** - * createKEYVALUE - * - * @param pDoc - * @param pParentE - * @param pValueType - * @param pValue - * @return KEYVALUE - */ - public static Element createKEYVALUE(Document pDoc, Element pParentE, String pValueType, - String pValue) { - /* - * - */ - if (pValueType == null) pValueType = "string"; - Element e = pDoc.createElement("KEYVALUE"); - // FIXME: ebak: TYPE attrib is more exact, easier to handle - e.setAttribute("TYPE", pValueType); - // ebak: maybe old CIMOMs won't understand the TYPE attrib - e.setAttribute("VALUETYPE", getValueTypeStr(pValueType)); - pParentE.appendChild(e); - Text valueE = pDoc.createTextNode(pValue); - e.appendChild(valueE); - return e; - } - - // //////////////////////////////////////////////////////////////////////////////////////// - // Object Definition Elements - // //////////////////////////////////////////////////////////////////////////////////////// - - /** - * createINSTANCE - * - * @param pDoc - * @param pParentE - * @param pClassName - * @return Element - */ - public static Element createINSTANCE(Document pDoc, Element pParentE, String pClassName) { - // - // - - Element e = pDoc.createElement("INSTANCE"); - if (pClassName != null) { - e.setAttribute("CLASSNAME", pClassName); - } - if (pParentE != null) pParentE.appendChild(e); - return e; - } - - /** - * createQUALIFIER - * - * @param pDoc - * @param pParentE - * @param pName - * @param pType - * @return Element - */ - public static Element createQUALIFIER(Document pDoc, Element pParentE, String pName, - String pType) { - // - // - - Element e = pDoc.createElement("QUALIFIER"); - if (pName != null) { - e.setAttribute("NAME", pName); - // TODO: add additional attributes "propagated", "qualifierFlavod" - } - if (pType != null) e.setAttribute("TYPE", pType); - pParentE.appendChild(e); - return e; - } - - // /////////////////////////////////////////////////////////////////////////////////////////// - // Message Elements - // /////////////////////////////////////////////////////////////////////////////////////////// - - /** - * createMESSAGE - * - * @param pDoc - * @param pParentE - * @param pId - * @param pProtocolVersion - * @return Element - */ - public static Element createMESSAGE(Document pDoc, Element pParentE, String pId, - String pProtocolVersion) { - // - // - Element e = pDoc.createElement("MESSAGE"); - e.setAttribute("ID", pId); // required - e.setAttribute("PROTOCOLVERSION", pProtocolVersion); // required - pParentE.appendChild(e); - return e; - } - - /** - * createSIMPLEREQ - * - * @param pDoc - * @param pParentE - * @return Element - */ - public static Element createSIMPLEREQ(Document pDoc, Element pParentE) { - // - Element e = pDoc.createElement("SIMPLEREQ"); - pParentE.appendChild(e); - return e; - } - - /** - * createSIMPLEREQ - * - * @param pDoc - * @return Element - */ - public static Element createSIMPLEREQ(Document pDoc) { - // - Element e = pDoc.createElement("SIMPLEREQ"); - return e; - } - - /** - * createMULTIREQ - * - * @param pDoc - * @return Element - */ - public static Element createMULTIREQ(Document pDoc) { - // - Element e = pDoc.createElement("MULTIREQ"); - return e; - } - - /** - * createMETHODCALL - * - * @param pDoc - * @param pParentE - * @param pName - * @return Element - */ - public static Element createMETHODCALL(Document pDoc, Element pParentE, String pName) { - // - // - Element e = pDoc.createElement("METHODCALL"); - if (pName != null) { - e.setAttribute("NAME", pName); - } - pParentE.appendChild(e); - return e; - } - - /** - * createPARAMVALUE - * - * @param pDoc - * @param pParentE - * @param pArg - * @return Element - * @throws WBEMException - */ - public static Element createPARAMVALUE(Document pDoc, Element pParentE, CIMArgument pArg) - throws WBEMException { - // ) - // - if (pArg == null) return null; - Element e = pDoc.createElement("PARAMVALUE"); - EmbObjBuilder embObjBuilder = new EmbObjBuilder(pDoc, pArg); - if (pArg.getName() != null) { - e.setAttribute("NAME", pArg.getName()); - } - e.setAttribute("PARAMTYPE", embObjBuilder.getTypeStr()); - embObjBuilder.addSign(e); - embObjBuilder.addValue(e); - pParentE.appendChild(e); - return e; - } - - /** - * createSIMPLERSP - * - * @param pDoc - * @param pParentE - * @return Element - */ - public static Element createSIMPLERSP(Document pDoc, Element pParentE) { - // - Element e = pDoc.createElement("SIMPLERSP"); - - if (pParentE != null) pParentE.appendChild(e); - return e; - } - - /** - * createSIMPLEEXPRSP - * - * @param pDoc - * @param pParentE - * @return Element - */ - public static Element createSIMPLEEXPRSP(Document pDoc, Element pParentE) { - // - Element e = pDoc.createElement("SIMPLEEXPRSP"); - - pParentE.appendChild(e); - return e; - } - - /** - * createMETHODRESPONSE - * - * @param pDoc - * @param pParentE - * @param pName - * @return Element - */ - public static Element createMETHODRESPONSE(Document pDoc, Element pParentE, String pName) { - // - // - - // %CIMName;> - Element e = pDoc.createElement("METHODRESPONSE"); - if (pName != null) { - e.setAttribute("NAME", pName); - } - pParentE.appendChild(e); - return e; - } - - /** - * createIMETHODRESPONSE - * - * @param pDoc - * @param pParentE - * @param pName - * @return Element - */ - public static Element createIMETHODRESPONSE(Document pDoc, Element pParentE, String pName) { - // - // - // %CIMName;> - Element e = pDoc.createElement("IMETHODRESPONSE"); - if (pName != null) { - e.setAttribute("NAME", pName); - } - pParentE.appendChild(e); - return e; - } - - /** - * createEXPMETHODRESPONSE - * - * @param pDoc - * @param pParentE - * @param pName - * @return Element - */ - public static Element createEXPMETHODRESPONSE(Document pDoc, Element pParentE, String pName) { - // - // - Element e = pDoc.createElement("EXPMETHODRESPONSE"); - if (pName != null) { - e.setAttribute("NAME", pName); - } - pParentE.appendChild(e); - return e; - } - - /** - * createIRETURNVALUE - * - * @param pDoc - * @param pParentE - * @return Element - */ - public static Element createIRETURNVALUE(Document pDoc, Element pParentE) { - // - Element e = pDoc.createElement("IRETURNVALUE"); - pParentE.appendChild(e); - return e; - } - - /** - *
      -	 * !ELEMENT RETURNVALUE (VALUE | VALUE.REFERENCE)
      -	 * !ATTLIST RETURNVALUE
      -	 * %ParamType;       #IMPLIED
      -	 * 
      - * - * createRETURNVALUE - * - * @param pDoc - * @param pParentE - * @param pValue - * @return Element - * @throws WBEMException - */ - public static Element createRETURNVALUE(Document pDoc, Element pParentE, Object pValue) - throws WBEMException { - Element retValE = pDoc.createElement("RETURNVALUE"); - CIMDataType type = CIMDataType.getDataType(pValue); - retValE.setAttribute("PARAMTYPE", getTypeStr(type)); - createVALUE(pDoc, retValE, pValue); - pParentE.appendChild(retValE); - return retValE; - } - - /** - * createIMETHODCALL - * - * @param pDoc - * @param pParentE - * @param pName - * @return Element - */ - public static Element createIMETHODCALL(Document pDoc, Element pParentE, String pName) { - // - // - Element e = pDoc.createElement("IMETHODCALL"); - if (pName != null) { - e.setAttribute("NAME", pName); - } - pParentE.appendChild(e); - return e; - } - - /** - * createIPARAMVALUE - * - * @param pDoc - * @param pParentE - * @param pName - * @return Element - */ - public static Element createIPARAMVALUE(Document pDoc, Element pParentE, String pName) { - // ) - // - Element e = pDoc.createElement("IPARAMVALUE"); - if (pName != null) { - e.setAttribute("NAME", pName); - } - pParentE.appendChild(e); - return e; - } - - /** - * createERROR - * - * @param doc - * @param parentE - * @param error - * @return Element - */ - public static Element createERROR(Document doc, Element parentE, CIMError error) { - // - // - Element e = doc.createElement("ERROR"); - int code; - if ((code = error.getCode()) > 0) { - e.setAttribute("CODE", Integer.toString(code)); - } - String description = error.getDescription(); - if (description != null) { - e.setAttribute("DESCRIPTION", description); - } - - parentE.appendChild(e); - return e; - } - - /** - * ENTITY % QualifierFlavor "OVERRIDABLE (true|false) 'true' TOSUBCLASS - * (true|false) 'true' TOINSTANCE (true|false) 'false' TRANSLATABLE - * (true|false) 'false'" - * - * @param pElement - * @param pFlavors - */ - private static void setFlavors(Element pElement, int pFlavors) { - if ((pFlavors & CIMFlavor.TRANSLATE) > 0) { - pElement.setAttribute("TRANSLATABLE", MOF.TRUE); - } - if ((pFlavors & CIMFlavor.DISABLEOVERRIDE) > 0) { - pElement.setAttribute("OVERRIDABLE", MOF.FALSE); - } - if ((pFlavors & CIMFlavor.RESTRICTED) > 0) { - pElement.setAttribute("TOSUBCLASS", MOF.FALSE); - } - /* - * if ((pFlavors & CIMFlavor.RESTRICTED)>0) { - * pElement.setAttribute("TOSUBCLASS", "true"); } - */ - } - - /** - * createQUALIFIER_DECLARATION - * - * @param pDoc - * @param pParentE - * @param pQualifierType - * @return Element - * @throws WBEMException - */ - public static Element createQUALIFIER_DECLARATION(Document pDoc, Element pParentE, - CIMQualifierType pQualifierType) throws WBEMException { - // - // - - String pValueTypeStr = getTypeStr(pQualifierType.getDataType()); - Element qualifierdeclarationE = pDoc.createElement("QUALIFIER.DECLARATION"); - qualifierdeclarationE.setAttribute("NAME", pQualifierType.getName()); - qualifierdeclarationE.setAttribute("TYPE", pValueTypeStr); - qualifierdeclarationE.setAttribute("ISARRAY", - pQualifierType.getDataType().isArray() ? MOF.TRUE : MOF.FALSE); - - setFlavors(qualifierdeclarationE, pQualifierType.getFlavor()); - - int scopes = pQualifierType.getScope(); - if (scopes > 0) { - Element scopeE = pDoc.createElement("SCOPE"); - if ((scopes & CIMScope.CLASS) > 0) scopeE.setAttribute("CLASS", MOF.TRUE); - if ((scopes & CIMScope.ASSOCIATION) > 0) scopeE.setAttribute("ASSOCIATION", MOF.TRUE); - if ((scopes & CIMScope.REFERENCE) > 0) scopeE.setAttribute("REFERENCE", MOF.TRUE); - if ((scopes & CIMScope.PROPERTY) > 0) scopeE.setAttribute("PROPERTY", MOF.TRUE); - if ((scopes & CIMScope.METHOD) > 0) scopeE.setAttribute("METHOD", MOF.TRUE); - if ((scopes & CIMScope.PARAMETER) > 0) scopeE.setAttribute("PARAMETER", MOF.TRUE); - if ((scopes & CIMScope.INDICATION) > 0) scopeE.setAttribute("INDICATION", MOF.TRUE); - qualifierdeclarationE.appendChild(scopeE); - } - - createVALUE(pDoc, qualifierdeclarationE, pQualifierType.getValue()); - - pParentE.appendChild(qualifierdeclarationE); - return qualifierdeclarationE; - } - - /** - * createQUALIFIER - * - * @param pDoc - * @param pParentE - * @param pQualifier - * @return Element - * @throws WBEMException - */ - public static Element createQUALIFIER(Document pDoc, Element pParentE, - CIMQualifier pQualifier) throws WBEMException { - // - // - - Object value = pQualifier.getValue(); - if (value == null) return null; - - Element qualifierE = createQUALIFIER(pDoc, pParentE, pQualifier.getName(), - getTypeStr(pQualifier.getDataType())); - - if (pQualifier.isPropagated()) { - qualifierE.setAttribute("PROPAGATED", "true"); - } - setFlavors(qualifierE, pQualifier.getFlavor()); - - createVALUE(pDoc, qualifierE, value); - - pParentE.appendChild(qualifierE); - return qualifierE; - } - - /** - * createQUALIFIERS - * - * @param pDoc - * @param pParentE - * @param pQualifiersA - * @throws WBEMException - */ - public static void createQUALIFIERS(Document pDoc, Element pParentE, - CIMQualifier[] pQualifiersA) throws WBEMException { - if (pQualifiersA == null) return; - for (int i = 0; i < pQualifiersA.length; i++) { - createQUALIFIER(pDoc, pParentE, pQualifiersA[i]); - } - } - - /** - * createPROPERTIES - * - * @param pDoc - * @param pParentE - * @param pProperties - * @throws WBEMException - */ - public static void createPROPERTIES(Document pDoc, Element pParentE, - CIMProperty[] pProperties) throws WBEMException { - if (pProperties == null) return; - for (int i = 0; i < pProperties.length; i++) { - createPROPERTY(pDoc, pParentE, pProperties[i]); - } - } - - private static final CIMQualifiedElementInterfaceImpl KEYQUALIFIERS_IMPL = new CIMQualifiedElementInterfaceImpl( - null, true); - - static final CIMQualifier EMB_OBJ_QUALI = new CIMQualifier("EmbeddedObject", - CIMDataType.BOOLEAN_T, Boolean.TRUE, CIMFlavor.DISABLEOVERRIDE); - - // ebak: embedded object: CLASS_T or INSTANCE_T? - - /** - * isCIMObject - * - * @param typeCode - * @return boolean - */ - public static boolean isCIMObject(int typeCode) { - return typeCode == CIMDataType.CLASS || typeCode == CIMDataType.OBJECT; - } - - /** - * isCIMObject - * - * @param pType - * @return boolean - */ - public static boolean isCIMObject(CIMDataType pType) { - return pType == null ? false : isCIMObject(pType.getType()); - } - - /** - * getEmbObjTypeStr - * - * @param pType - * @return String - */ - public static String getEmbObjTypeStr(CIMDataType pType) { - return isCIMObject(pType) ? MOF.DT_STR : getTypeStr(pType); - } - - private static Document getDoc() { - try { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder docBuilder = factory.newDocumentBuilder(); - return docBuilder.newDocument(); - } catch (ParserConfigurationException e) { - throw new RuntimeException(e); - } - } - - /** - * cimObjectToXMLString - for embedded object support - * - * @param pObj - * @return String - * @throws WBEMException - */ - public static String cimObjectToXMLString(Object pObj) throws WBEMException { - if (pObj == null) return null; - Document doc; - Element e; - if (pObj instanceof CIMClass) { - doc = getDoc(); - e = createCLASS(doc, null, (CIMClass) pObj); - } else if (pObj instanceof CIMInstance) { - doc = getDoc(); - e = createINSTANCE(doc, null, (CIMInstance) pObj); - } else { - throw new WBEMException(WBEMException.CIM_ERR_FAILED, pObj.getClass().getName() - + " parameter is not suitable for this method!"); - } - doc.appendChild(e); - ByteArrayOutputStream os = new ByteArrayOutputStream(); - try { - CimXmlSerializer.serialize(os, doc.getDocumentElement(), false); - } catch (IOException ex) { - throw new WBEMException(WBEMException.CIM_ERR_FAILED, - "XML serialization failed with IOException!", null, ex); - } - return os.toString(); - } - - /** - * cimObjectArrayToXMLString - for embedded object support - * - * @param pObj - * @return String[] - * @throws WBEMException - */ - public static String[] cimObjectArrayToXMLString(Object pObj) throws WBEMException { - if (pObj == null) return null; - if (!(pObj instanceof Object[])) throw new WBEMException(WBEMException.CIM_ERR_FAILED, - "Object[] parameter is required for this method!"); - Object[] objA = (Object[]) pObj; - String[] strA = new String[objA.length]; - // here we don't deal with the consistency check of the Object[] - for (int i = 0; i < objA.length; i++) - strA[i] = cimObjectToXMLString(objA[i]); - return strA; - } - - static boolean embObjQualified(CIMQualifiedElementInterface pQualid) { - return pQualid.hasQualifier("EmbeddedObject") || pQualid.hasQualifier("EmbeddedInstance"); - } - - static class EmbObjBuilder { - - private static final int ATTRIB_ONLY = 0, EO_QUALI = 1, EO_AND_EI_QUALI = 2; - - private int iSignMethod; - - private Document iDoc; - - private CIMTypedElement iTypedE; - - private boolean iXMLQualified; - - private static final boolean iUpperCaseEmbObjEntities = WBEMConfiguration - .getGlobalConfiguration().upperCaseEmbObjEntities(); - - /** - * Ctor. - * - * @param pDoc - * @param pTypedE - */ - public EmbObjBuilder(Document pDoc, CIMTypedElement pTypedE) { - this(pDoc, pTypedE, false); - } - - /** - * Ctor. - * - * @param pDoc - * @param pTypedE - * @param pXMLQualified - * - e.g. CIMProperty is not qualified in JSR48, but - * qualified in CIM-XML - */ - public EmbObjBuilder(Document pDoc, CIMTypedElement pTypedE, boolean pXMLQualified) { - this.iDoc = pDoc; - this.iTypedE = pTypedE; - this.iXMLQualified = pXMLQualified; - String builderCfg = WBEMConfiguration.getGlobalConfiguration().getCimXmlEmbObjBuilder(); - if ("EmbObjQuali".equalsIgnoreCase(builderCfg)) { - this.iSignMethod = EO_QUALI; - } else if ("EmbObjAndEmbInstQuali".equalsIgnoreCase(builderCfg)) { - this.iSignMethod = EO_AND_EI_QUALI; - } else { - this.iSignMethod = ATTRIB_ONLY; - } - } - - /** - * getTypeStr - * - * @return String - */ - public String getTypeStr() { - return getEmbObjTypeStr(this.iTypedE.getDataType()); - } - - /** - * isArray - * - * @return String - */ - public boolean isArray() { - return this.iTypedE.getDataType().isArray(); - } - - private Object getValue() { - if (!(this.iTypedE instanceof CIMValuedElement)) return null; - return ((CIMValuedElement) this.iTypedE).getValue(); - - } - - /** - * addSign - * - * @param pElement - * @throws WBEMException - */ - public void addSign(Element pElement) throws WBEMException { - if (!isCIMObject(this.iTypedE.getDataType())) return; - CIMQualifiedElementInterface qualified; - if (this.iTypedE instanceof CIMQualifiedElementInterface) { - qualified = (CIMQualifiedElementInterface) this.iTypedE; - if (embObjQualified(qualified)) return; - } else { - qualified = null; - } - if (this.iSignMethod == ATTRIB_ONLY || (qualified == null && !this.iXMLQualified)) { - pElement.setAttribute(iUpperCaseEmbObjEntities ? "EMBEDDEDOBJECT" - : "EmbeddedObject", - this.iTypedE.getDataType().getType() == CIMDataType.OBJECT ? "instance" - : "object"); - } else { - if (this.iSignMethod == EO_AND_EI_QUALI) { - addEmbObjOrEmbInstQuali(pElement); - } else { // EO_QUALI - createQUALIFIER(this.iDoc, pElement, EMB_OBJ_QUALI); - } - } - } - - private void addEmbObjOrEmbInstQuali(Element pElement) throws WBEMException { - CIMQualifier signQuali; - if (this.iTypedE.getDataType().getType() == CIMDataType.OBJECT) { - CIMInstance inst; - if (isArray()) { - CIMInstance[] instA = (CIMInstance[]) getValue(); - inst = instA == null ? null : instA[0]; - } else { - inst = (CIMInstance) getValue(); - } - String className = inst == null ? "" : inst.getClassName(); - signQuali = new CIMQualifier("EmbeddedInstance", CIMDataType.STRING_T, - className, CIMFlavor.DISABLEOVERRIDE); - } else { // class - signQuali = EMB_OBJ_QUALI; - } - createQUALIFIER(this.iDoc, pElement, signQuali); - } - - /** - * addValue - * - * @param pElement - * @throws WBEMException - */ - public void addValue(Element pElement) throws WBEMException { - Object value = getValue(); - if (value == null) return; - if (isCIMObject(this.iTypedE.getDataType())) { - if (isArray()) { - value = cimObjectArrayToXMLString(value); - } else { - value = cimObjectToXMLString(value); - } - } - createVALUE(this.iDoc, pElement, value); - } - - } - - /** - * createPROPERTY - * - * @param pDoc - * @param pParentE - * @param pProperty - * @return Element - * @throws WBEMException - */ - public static Element createPROPERTY(Document pDoc, Element pParentE, CIMProperty pProperty) - throws WBEMException { - CIMDataType propType = pProperty.getDataType(); - Element propertyE; - EmbObjBuilder embObjBuilder = new EmbObjBuilder(pDoc, pProperty, true); - String typeStr = embObjBuilder.getTypeStr(); - if (propType.isArray()) { - propertyE = createPROPERTYARRAY(pDoc, pParentE, pProperty.getName(), typeStr); - } else if (propType.getType() == CIMDataType.REFERENCE) { - propertyE = createPROPERTYREFERENCE(pDoc, pParentE, pProperty.getName(), propType - .getRefClassName()); - } else { - propertyE = createPROPERTY(pDoc, pParentE, pProperty.getName(), typeStr); - } - - String classorigin = pProperty.getOriginClass(); - if (classorigin != null && classorigin.length() > 0) propertyE.setAttribute("CLASSORIGIN", - classorigin); - - if (pProperty.isPropagated()) propertyE.setAttribute("PROPAGATED", MOF.TRUE); - // FIXME: here key qualifier should be added if the property is a key - embObjBuilder.addSign(propertyE); - if (pProperty instanceof CIMClassProperty) { - createQUALIFIERS(pDoc, propertyE, ((CIMClassProperty) pProperty).getQualifiers()); - } else { // CIMProperty - if (pProperty.isKey()) createQUALIFIERS(pDoc, propertyE, KEYQUALIFIERS_IMPL - .getQualifiers()); - } - embObjBuilder.addValue(propertyE); - return propertyE; - } - - /** - * createVALUEARRAY - * - * @param pDoc - * @param pParentE - * @param pValA - * @return Element - * @throws WBEMException - */ - public static Element createVALUEARRAY(Document pDoc, Element pParentE, Object[] pValA) - throws WBEMException { - Element valuearrayE = (pValA != null && pValA.length > 0 && (pValA[0] instanceof CIMObjectPath || pValA[0] instanceof CIMInstance)) ? createVALUEREFARRAY( - pDoc, pParentE) - : createVALUEARRAY(pDoc, pParentE); - - if (pValA != null) for (int i = 0; i < pValA.length; i++) { - createVALUE(pDoc, valuearrayE, pValA[i]); - } - pParentE.appendChild(valuearrayE); - return valuearrayE; - } - - /** - * createVALUE - * - * @param pDoc - * @param pParentE - * @param pArgValue - * @return Element - * @throws WBEMException - */ - public static Element createVALUE(Document pDoc, Element pParentE, Object pArgValue) - throws WBEMException { - if (pArgValue == null) return null; - - Element valueE = null; - if (pArgValue instanceof Object[]) { - valueE = createVALUEARRAY(pDoc, pParentE, (Object[]) pArgValue); - } else { - CIMDataType type = CIMDataType.getDataType(pArgValue); - if (type != null && type.getType() == CIMDataType.REFERENCE) { - valueE = createVALUEREFERENCE(pDoc, pParentE); - - CIMObjectPath op = (CIMObjectPath) pArgValue; - CIMProperty[] keys = op.getKeys(); - if (op.getHost() == null || "".equals(op.getHost())) { - if (op.getNamespace() == null || "".equals(op.getNamespace())) { - if (keys.length > 0) { - createINSTANCENAME(pDoc, valueE, op); - } else { - createCLASSNAME(pDoc, valueE, op.getObjectName()); - } - } else { - if (keys.length > 0) { - createLOCALINSTANCEPATH(pDoc, valueE, op); - } else { - createLOCALCLASSPATH(pDoc, valueE, op); - } - } - } else { - if (keys.length > 0) { - createINSTANCEPATH(pDoc, valueE, op); - } else { - createCLASSPATH(pDoc, valueE, op); - } - } - // createOBJECTPATH(doc, valueE, (CIMObjectPath) obj); - } else { - if (pArgValue instanceof CIMInstance) { - valueE = createVALUEREFERENCE(pDoc, pParentE); - CIMObjectPath cop = ((CIMInstance) pArgValue).getObjectPath(); - createINSTANCENAME(pDoc, valueE, cop); - } else if (pArgValue instanceof CIMClass) { - valueE = createVALUE(pDoc, pParentE); - createCLASS(pDoc, valueE, (CIMClass) pArgValue); - } else { - createVALUE(pDoc, pParentE, pArgValue.toString()); - } - } - } - - return valueE; - } - - /** - * createINSTANCE - * - * @param pDoc - * @param pParentE - * @param pInstance - * @return Element - * @throws WBEMException - */ - public static Element createINSTANCE(Document pDoc, Element pParentE, CIMInstance pInstance) - throws WBEMException { - // - // - - String className = pInstance.getObjectPath().getObjectName(); - if (className == null) throw new WBEMException(WBEMException.CIM_ERR_FAILED, - "null class name"); - - Element instanceE = createINSTANCE(pDoc, pParentE, className); - - // FIXME: in JSR48 CIMInstance doesn't have qualifiers - // createQUALIFIERS(pDoc, instanceE, pInstance.getQualifiers()); - createPROPERTIES(pDoc, instanceE, pInstance.getProperties()); - - if (pParentE != null) pParentE.appendChild(instanceE); - - return instanceE; - } - - /** - * createOBJECTPATH - * - * @param pDoc - * @param pParentE - * @param pPath - * @return Element - * @throws WBEMException - */ - public static Element createOBJECTPATH(Document pDoc, Element pParentE, CIMObjectPath pPath) - throws WBEMException { - Element objectpathE = pDoc.createElement("OBJECTPATH"); - - CIMProperty[] keys = pPath.getKeys(); - if (keys.length > 0) { - createINSTANCEPATH(pDoc, objectpathE, pPath); - } else { - createCLASSPATH(pDoc, objectpathE, pPath); - } - - pParentE.appendChild(objectpathE); - return objectpathE; - } - - /** - * createOBJECTNAME - * - * @param pDoc - * @param pParentE - * @param pPath - * @return Element - * @throws WBEMException - */ - public static Element createOBJECTNAME(Document pDoc, Element pParentE, CIMObjectPath pPath) - throws WBEMException { - - CIMProperty[] keys = pPath.getKeys(); - if (keys.length > 0) { return createINSTANCENAME(pDoc, pParentE, pPath); } - if (pPath.getObjectName() == null) throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); - return createCLASSNAME(pDoc, pParentE, pPath.getObjectName()); - } - - /** - * createLOCALINSTANCEPATH - * - * @param pDoc - * @param pParentE - * @param pPath - * @return Element - * @throws WBEMException - */ - public static Element createLOCALINSTANCEPATH(Document pDoc, Element pParentE, - CIMObjectPath pPath) throws WBEMException { - Element localinstancepathE = pDoc.createElement("LOCALINSTANCEPATH"); - - createLOCALNAMESPACEPATH(pDoc, localinstancepathE, pPath); - createINSTANCENAME(pDoc, localinstancepathE, pPath); - - pParentE.appendChild(localinstancepathE); - return localinstancepathE; - } - - /** - * createLOCALCLASSPATH - * - * @param pDoc - * @param pParentE - * @param pPath - * @return Element - * @throws WBEMException - */ - public static Element createLOCALCLASSPATH(Document pDoc, Element pParentE, CIMObjectPath pPath) - throws WBEMException { - Element localinstancepathE = pDoc.createElement("LOCALCLASSPATH"); - - createLOCALNAMESPACEPATH(pDoc, localinstancepathE, pPath); - - if (pPath.getObjectName() == null) throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, "null class name"); - createCLASSNAME(pDoc, localinstancepathE, pPath.getObjectName()); - - pParentE.appendChild(localinstancepathE); - return localinstancepathE; - } - - /** - * createLOCALOBJECTPATH - * - * @param pDoc - * @param pParentE - * @param pPath - * @return Element - * @throws WBEMException - */ - public static Element createLOCALOBJECTPATH(Document pDoc, Element pParentE, CIMObjectPath pPath) - throws WBEMException { - - CIMProperty[] keys = pPath.getKeys(); - if (keys.length > 0) { return createLOCALINSTANCEPATH(pDoc, pParentE, pPath); } - return createLOCALCLASSPATH(pDoc, pParentE, pPath); - } - - /** - * createVALUEREFERENCE - * - * @param pDoc - * @param pParentE - * @param pPath - * @return Element - * @throws WBEMException - */ - public static Element createVALUEREFERENCE(Document pDoc, Element pParentE, CIMObjectPath pPath) - throws WBEMException { - Element objectpathE = pDoc.createElement("VALUE.REFERENCE"); - - String ns = pPath.getNamespace(); - if (pPath.getHost() == null || "".equals(pPath.getHost())) { - if (pPath.getNamespace() == null || "".equals(ns)) { - createINSTANCENAME(pDoc, objectpathE, pPath); - } else { - createLOCALOBJECTPATH(pDoc, objectpathE, pPath); - } - } else { - CIMProperty[] keys = pPath.getKeys(); - if (keys.length > 0) { - createINSTANCEPATH(pDoc, objectpathE, pPath); - } else { - createCLASSPATH(pDoc, objectpathE, pPath); - } - } - - pParentE.appendChild(objectpathE); - return objectpathE; - } - - /** - * createINSTANCENAME - * - * @param doc - * @param parentE - * @param instanceOP - * @return Element - * @throws WBEMException - */ - public static Element createINSTANCENAME(Document doc, Element parentE, CIMObjectPath instanceOP) - throws WBEMException { - - Element instancenameE = doc.createElement("INSTANCENAME"); - String classname = instanceOP.getObjectName(); - if (classname != null) { - instancenameE.setAttribute("CLASSNAME", classname); - } - - CIMProperty[] keysA = instanceOP.getKeys(); - for (int ii = 0; ii < keysA.length; ii++) { - CIMProperty prop = keysA[ii]; - String propName = prop.getName(); - CIMDataType propType = prop.getDataType(); - Object propValue = prop.getValue(); - // if (_pValue == null) TODO what happened when a KeyBinding has a - // null property value? - /* - * ebak: test support for #1666336 EnumInstance has attributes - * filled from others Handling direct KEYVALUE and - * VALUE.REFERENCE children is difficult, KEYBINDING can wrap them - * -> dropping out KEYVALUE? | VALUE.REFERENCE?. - * - * - * - * - non - * reference values can be null - * - * - reference - * value shouldn't be null - */ - if (propType == null) { throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, - "Type of property or key cannot be a null! " + propName + " in ObjectPath " - + instanceOP.toString() + " has null type."); } - - if (propValue == null) { - if (propType.getType() == CIMDataType.REFERENCE) { throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, - "Value of reference cannot be null! " + propName + " in ObjectPath " - + instanceOP.toString() + " has null value."); } - } - - Element keybindingE = createKEYBINDING(doc, instancenameE, propName); - if (propType.getType() == CIMDataType.REFERENCE) { - CIMObjectPath refOP = (CIMObjectPath) propValue; - - createVALUEREFERENCE(doc, keybindingE, refOP); - } else { - String valueStr = propValue == null ? null : propValue.toString(); - String valueTypeStr = getTypeStr(propType); - createKEYVALUE(doc, keybindingE, valueTypeStr, valueStr); - } - } - - parentE.appendChild(instancenameE); - return instancenameE; - } - - /** - * createCLASSPATH - * - * @param pDoc - * @param pParentE - * @param pPath - * @return Element - */ - public static Element createCLASSPATH(Document pDoc, Element pParentE, CIMObjectPath pPath) { - Element classpathE = pDoc.createElement("CLASSPATH"); - - // ebak: NAMESPACEPATH is necessary - createNAMESPACEPATH(pDoc, classpathE, pPath); - createCLASSNAME(pDoc, classpathE, pPath.getObjectName()); - - pParentE.appendChild(classpathE); - return classpathE; - } - - /** - * createPARAMETERS - * - * @param pDoc - * @param pParentE - * @param pParameters - * @throws WBEMException - */ - public static void createPARAMETERS(Document pDoc, Element pParentE, - CIMParameter[] pParameters) throws WBEMException { - if (pParameters == null) return; - for (int i = 0; i < pParameters.length; i++) { - createPARAMETER(pDoc, pParentE, pParameters[i]); - } - } - - /** - * createPARAMETER - * - * @param pDoc - * @param pParentE - * @param pParameter - * @return Element - * @throws WBEMException - */ - public static Element createPARAMETER(Document pDoc, Element pParentE, - CIMParameter pParameter) throws WBEMException { - Element parameterE; - CIMDataType type = pParameter.getDataType(); - int typeCode = type.getType(); - EmbObjBuilder embObjBuilder = new EmbObjBuilder(pDoc, pParameter); - String typeStr = embObjBuilder.getTypeStr(); - if (type.isArray()) { - if (typeCode == CIMDataType.REFERENCE) { - parameterE = pDoc.createElement("PARAMETER.REFARRAY"); - String refclass = type.getRefClassName(); - if (refclass != null && refclass.length() > 0) parameterE.setAttribute( - "REFERENCECLASS", type.getRefClassName()); - } else { - parameterE = pDoc.createElement("PARAMETER.ARRAY"); - parameterE.setAttribute("TYPE", typeStr); - } - } else { - if (typeCode == CIMDataType.REFERENCE) { - parameterE = pDoc.createElement("PARAMETER.REFERENCE"); - String refclass = type.getRefClassName(); - if (refclass != null && refclass.length() > 0) parameterE.setAttribute( - "REFERENCECLASS", type.getRefClassName()); - } else { - parameterE = pDoc.createElement("PARAMETER"); - parameterE.setAttribute("TYPE", typeStr); - } - } - parameterE.setAttribute("NAME", pParameter.getName()); - embObjBuilder.addSign(parameterE); - createQUALIFIERS(pDoc, parameterE, pParameter.getQualifiers()); - - pParentE.appendChild(parameterE); - return parameterE; - } - - /** - * createMETHODS - * - * @param pDoc - * @param pParentE - * @param pMethods - * @param pClassName - * @throws WBEMException - */ - public static void createMETHODS(Document pDoc, Element pParentE, CIMMethod[] pMethods, - String pClassName) throws WBEMException { - for (int i = 0; i < pMethods.length; i++) { - createMETHOD(pDoc, pParentE, pMethods[i], pClassName); - } - } - - /** - * createMETHOD - * - * @param pDoc - * @param pParentE - * @param pMethod - * @param pClassName - * @return Element - * @throws WBEMException - */ - public static Element createMETHOD(Document pDoc, Element pParentE, CIMMethod pMethod, - String pClassName) throws WBEMException { - Element methodE = pDoc.createElement("METHOD"); - - methodE.setAttribute("NAME", pMethod.getName()); - EmbObjBuilder embObjBuilder = new EmbObjBuilder(pDoc, pMethod); - String typeStr = embObjBuilder.getTypeStr(); - methodE.setAttribute("TYPE", typeStr); - String classorigin = pMethod.getOriginClass(); - - if (classorigin != null && classorigin.length() != 0) methodE.setAttribute("CLASSORIGIN", - classorigin); - - // 17459 - if (pMethod.isPropagated()) { - methodE.setAttribute("PROPAGATED", MOF.TRUE); - } else { - methodE.setAttribute("PROPAGATED", MOF.FALSE); - } - // ebak: embedded object support - embObjBuilder.addSign(methodE); - - createQUALIFIERS(pDoc, methodE, pMethod.getQualifiers()); - createPARAMETERS(pDoc, methodE, pMethod.getParameters()); - - pParentE.appendChild(methodE); - return methodE; - } - - /* - * private static String elementStr(Element pE) { try { - * ByteArrayOutputStream os = new ByteArrayOutputStream(); - * CimXmlSerializer.serialize(os, pE, true); return new - * String(os.toByteArray()); } catch (RuntimeException e) { throw e; } catch - * (Exception e) { throw new RuntimeException(e); } } - */ - - /** - * createCLASS - * - * @param pDoc - * @param pParentE - * @param pClass - * @return Element - * @throws WBEMException - */ - public static Element createCLASS(Document pDoc, Element pParentE, CIMClass pClass) - throws WBEMException { - - Element classE = createCLASS(pDoc, pParentE, pClass.getName(), pClass.getSuperClassName()); - - createQUALIFIERS(pDoc, classE, pClass.getQualifiers()); - createPROPERTIES(pDoc, classE, pClass.getProperties()); - createMETHODS(pDoc, classE, pClass.getMethods(), pClass.getName()); - - // parentE.appendChild(classE); - return classE; - } - - /** - * createHOST - * - * @param pDoc - * @param pParentE - * @param pHost - * @return Element - */ - public static Element createHOST(Document pDoc, Element pParentE, String pHost) { - Element hostE = pDoc.createElement("HOST"); - - Text hostT = pDoc.createTextNode(pHost); - hostE.appendChild(hostT); - - pParentE.appendChild(hostE); - return hostE; - } - - /** - * createNAMESPACEPATH - * - * @param pDoc - * @param pParentE - * @param pPath - * @return Element - */ - public static Element createNAMESPACEPATH(Document pDoc, Element pParentE, CIMObjectPath pPath) { - Element namespacepathE = pDoc.createElement("NAMESPACEPATH"); - - String host = pPath.getHost(); - if (host == null) { - // try { - // host = InetAddress.getLocalHost().getHostAddress(); - // } catch (Exception e) { - // throw new CIMXMLBuilderException("Error while resolving - // hostname"); - // } - host = "unassigned-hostname"; - } - createHOST(pDoc, namespacepathE, host); - createLOCALNAMESPACEPATH(pDoc, namespacepathE, pPath); - - pParentE.appendChild(namespacepathE); - return namespacepathE; - } - - /** - * createINSTANCEPATH - * - * @param pDoc - * @param pParentE - * @param pPath - * @return Element - * @throws WBEMException - */ - public static Element createINSTANCEPATH(Document pDoc, Element pParentE, CIMObjectPath pPath) - throws WBEMException { - Element instancepathE = pDoc.createElement("INSTANCEPATH"); - - createNAMESPACEPATH(pDoc, instancepathE, pPath); - createINSTANCENAME(pDoc, instancepathE, pPath); - pParentE.appendChild(instancepathE); - return instancepathE; - } - - /** - * createVALUENAMEDINSTANCE - * - * @param pDoc - * @param pParentE - * @param pPath - * @param pInst - * @return Element - * @throws WBEMException - */ - public static Element createVALUENAMEDINSTANCE(Document pDoc, Element pParentE, - CIMObjectPath pPath, CIMInstance pInst) throws WBEMException { - Element valuenamedinstanceE = pDoc.createElement("VALUE.NAMEDINSTANCE"); - createINSTANCENAME(pDoc, valuenamedinstanceE, pPath); - createINSTANCE(pDoc, valuenamedinstanceE, pInst); - - pParentE.appendChild(valuenamedinstanceE); - return valuenamedinstanceE; - } - - /** - * createVALUENAMEDINSTANCE - * - * @param pDoc - * @param pParentE - * @param pInst - * @return Element - * @throws WBEMException - */ - public static Element createVALUENAMEDINSTANCE(Document pDoc, Element pParentE, - CIMInstance pInst) throws WBEMException { - Element valuenamedinstanceE = pDoc.createElement("VALUE.NAMEDINSTANCE"); - createINSTANCENAME(pDoc, valuenamedinstanceE, pInst.getObjectPath()); - createINSTANCE(pDoc, valuenamedinstanceE, pInst); - - pParentE.appendChild(valuenamedinstanceE); - return valuenamedinstanceE; - } - - private static CIMObjectPath changeNameSpace(CIMNamedElementInterface pNamedElement, - String pNameSpace) { - CIMObjectPath path = pNamedElement.getObjectPath(); - return new CIMObjectPath(path.getScheme(), path.getHost(), path.getPort(), pNameSpace, path - .getObjectName(), path.getKeys()); - } - - private static CIMClass changeClassNameSpace(CIMClass pClass, String pNameSpace) { - CIMObjectPath newOp = changeNameSpace(pClass, pNameSpace); - return new CIMClass(newOp, pClass.getSuperClassName(), pClass.getQualifiers(), pClass - .getProperties(), pClass.getMethods(), pClass.isAssociation(), pClass.isKeyed()); - } - - private static CIMInstance changeInstanceNameSpace(CIMInstance pInst, String pNameSpace) { - CIMObjectPath newOp = changeNameSpace(pInst, pNameSpace); - return new CIMInstance(newOp, pInst.getProperties()); - } - - /** - * createVALUEOBJECTWITHPATH - * - * @param pDoc - * @param pParentE - * @param pObj - * @param pNameSpace - * @return Element - * @throws WBEMException - */ - public static Element createVALUEOBJECTWITHPATH(Document pDoc, Element pParentE, Object pObj, - String pNameSpace) throws WBEMException { - Element valueobjectwithpathE = pDoc.createElement("VALUE.OBJECTWITHPATH"); - if (pObj instanceof CIMClass) { - CIMClass clazz = (CIMClass) pObj; - - if (clazz.getObjectPath().getNamespace() == null - || clazz.getObjectPath().getNamespace().length() == 0) { - // ebak: changing the namespace in clazz's objectPath - // clazz.getObjectPath().setNameSpace(pNameSpace); - clazz = changeClassNameSpace(clazz, pNameSpace); - } - - createCLASSPATH(pDoc, valueobjectwithpathE, clazz.getObjectPath()); - createCLASS(pDoc, valueobjectwithpathE, clazz); - } else if (pObj instanceof CIMInstance) { - CIMInstance inst = (CIMInstance) pObj; - if (inst.getObjectPath().getNamespace() == null - || inst.getObjectPath().getNamespace().length() == 0) { - // ebak: changing the namespace ins inst's objectPath - // inst.getObjectPath().setNameSpace(pNameSpace); - inst = changeInstanceNameSpace(inst, pNameSpace); - } - createINSTANCEPATH(pDoc, valueobjectwithpathE, inst.getObjectPath()); - createINSTANCE(pDoc, valueobjectwithpathE, inst); - } - - pParentE.appendChild(valueobjectwithpathE); - return valueobjectwithpathE; - } - - /** - * createVALUEOBJECTWITHLOCALPATH - * - * @param pDoc - * @param pParentE - * @param pObj - * @param pNameSpace - * @return Element - * @throws WBEMException - */ - public static Element createVALUEOBJECTWITHLOCALPATH(Document pDoc, Element pParentE, - Object pObj, String pNameSpace) throws WBEMException { - Element valueobjectwithpathE = pDoc.createElement("VALUE.OBJECTWITHLOCALPATH"); - if (pObj instanceof CIMClass) { - CIMClass clazz = (CIMClass) pObj; - - if (clazz.getObjectPath().getNamespace() == null - || clazz.getObjectPath().getNamespace().length() == 0) { - // ebak: changing clazz's objectPath - // clazz.getObjectPath().setNameSpace(pNameSpace); - clazz = changeClassNameSpace(clazz, pNameSpace); - } - createLOCALCLASSPATH(pDoc, valueobjectwithpathE, clazz.getObjectPath()); - createCLASS(pDoc, valueobjectwithpathE, clazz); - } else if (pObj instanceof CIMInstance) { - CIMInstance inst = (CIMInstance) pObj; - if (inst.getObjectPath().getNamespace() == null - || inst.getObjectPath().getNamespace().length() == 0) { - // inst.getObjectPath().setNameSpace(pNameSpace); - inst = changeInstanceNameSpace(inst, pNameSpace); - } - createLOCALINSTANCEPATH(pDoc, valueobjectwithpathE, inst.getObjectPath()); - createINSTANCE(pDoc, valueobjectwithpathE, inst); - } - - pParentE.appendChild(valueobjectwithpathE); - return valueobjectwithpathE; - } - - /** - * createIRETURNVALUE_ERROR - * - * @param doc - * @param parentE - * @param error - * @return Element - */ - public static Element createIRETURNVALUE_ERROR(Document doc, Element parentE, CIMError error) { - Element ireturnvalueE = doc.createElement("IRETURNVALUE"); - - parentE.appendChild(ireturnvalueE); - return ireturnvalueE; - } - - /** - * createIRETURNVALUE_GETINSTANCE - * - * @param pDoc - * @param pParentE - * @param pInst - * @return Element - * @throws WBEMException - */ - public static Element createIRETURNVALUE_GETINSTANCE(Document pDoc, Element pParentE, - CIMInstance pInst) throws WBEMException { - Element ireturnvalueE = pDoc.createElement("IRETURNVALUE"); - createINSTANCENAME(pDoc, ireturnvalueE, pInst.getObjectPath()); - - return ireturnvalueE; - } - - /** - * createIRETURNVALUE_ASSOCIATORS_NAMES - * - * @param pDoc - * @param pParentE - * @param pResultSet - * @return Element - * @throws Exception - */ - public static Element createIRETURNVALUE_ASSOCIATORS_NAMES(Document pDoc, Element pParentE, - CIMObjectPath[] pResultSet) throws Exception { - Element ireturnvalueE = pDoc.createElement("IRETURNVALUE"); - - if (pResultSet != null) { - for (int i = 0; i < pResultSet.length; i++) { - CIMObjectPath path = pResultSet[i]; - - if (path.getHost() == null || "".equals(path.getHost())) createLOCALOBJECTPATH( - pDoc, ireturnvalueE, path); - else createOBJECTPATH(pDoc, ireturnvalueE, path); - } - } - pParentE.appendChild(ireturnvalueE); - return ireturnvalueE; - } - - /** - * createIRETURNVALUE_ASSOCIATORS - * - * @param pDoc - * @param pParentE - * @param pResultSet - * @param pNameSpace - * @return Element - * @throws Exception - */ - public static Element createIRETURNVALUE_ASSOCIATORS(Document pDoc, Element pParentE, - Object[] pResultSet, String pNameSpace) throws Exception { - Element ireturnvalueE = pDoc.createElement("IRETURNVALUE"); - if (pResultSet != null) { - for (int i = 0; i < pResultSet.length; i++) { - Object obj = pResultSet[i]; - CIMObjectPath op = null; - if (obj instanceof CIMClass) { - op = ((CIMClass) obj).getObjectPath(); - } else if (obj instanceof CIMInstance) { - op = ((CIMInstance) obj).getObjectPath(); - } else { - throw new WBEMException(WBEMException.CIM_ERR_FAILED, - "object in result set neither class nor instance!"); - } - if (op.getHost() == null || "".equals(op.getHost())) { - createVALUEOBJECTWITHLOCALPATH(pDoc, ireturnvalueE, obj, pNameSpace); - } else { - createVALUEOBJECTWITHPATH(pDoc, ireturnvalueE, obj, pNameSpace); - } - } - } - pParentE.appendChild(ireturnvalueE); - return ireturnvalueE; - } - - /** - * createIRETURNVALUE_ENUMERATE_INSTANCENAME - * - * @param pDoc - * @param pParentE - * @param pResultSet - * @param pNameSpace - * @return Element - * @throws Exception - */ - public static Element createIRETURNVALUE_ENUMERATE_INSTANCENAME(Document pDoc, - Element pParentE, Object[] pResultSet, String pNameSpace) throws Exception { - Element ireturnvalueE = pDoc.createElement("IRETURNVALUE"); - if (pResultSet != null) { - for (int i = 0; i < pResultSet.length; i++) { - Object obj = pResultSet[i]; - CIMObjectPath op = null; - if (obj instanceof CIMClass) { - op = ((CIMClass) obj).getObjectPath(); - } else if (obj instanceof CIMInstance) { - op = ((CIMInstance) obj).getObjectPath(); - } else { - throw new WBEMException(WBEMException.CIM_ERR_FAILED, - "object in result set neither class nor instance!"); - } - if (op.getHost() == null || "".equals(op.getHost())) { - createVALUEOBJECTWITHLOCALPATH(pDoc, ireturnvalueE, obj, pNameSpace); - } else { - createVALUEOBJECTWITHPATH(pDoc, ireturnvalueE, obj, pNameSpace); - } - } - } - pParentE.appendChild(ireturnvalueE); - return ireturnvalueE; - } - - /** - * createIRETURNVALUE - * - * @param pDoc - * @param pParentE - * @param pResultSet - * @return Element - * @throws WBEMException - */ - public static Element createIRETURNVALUE(Document pDoc, Element pParentE, Object[] pResultSet) - throws WBEMException { - Element ireturnvalueE = pDoc.createElement("IRETURNVALUE"); - if (pResultSet != null && pResultSet.length > 0) { - Object obj = pResultSet[0]; - if (obj instanceof CIMClass) { - for (int i = 0; i < pResultSet.length; i++) { - CIMClass clazz = (CIMClass) pResultSet[i]; - Element classnameE = pDoc.createElement("CLASSNAME"); - ireturnvalueE.appendChild(classnameE); - if (clazz.getName() != null) classnameE.setAttribute("NAME", clazz.getName()); - } - } else if (obj instanceof CIMInstance) { - for (int i = 0; i < pResultSet.length; i++) { - CIMInstance inst = (CIMInstance) pResultSet[i]; - createVALUENAMEDINSTANCE(pDoc, ireturnvalueE, inst); - } - } - } - pParentE.appendChild(ireturnvalueE); - return ireturnvalueE; - } - - /** - * createIRETURNVALUE_ENUMERATE_CLASSNAME - * - * @param pDoc - * @param pParentE - * @param pResultSet - * @return Element - */ - public static Element createIRETURNVALUE_ENUMERATE_CLASSNAME(Document pDoc, Element pParentE, - CIMClass[] pResultSet) { - Element ireturnvalueE = pDoc.createElement("IRETURNVALUE"); - if (pResultSet != null && pResultSet.length > 0) { - for (int i = 0; i < pResultSet.length; i++) { - CIMClass clazz = pResultSet[i]; - - Element classnameE = pDoc.createElement("CLASSNAME"); - ireturnvalueE.appendChild(classnameE); - if (clazz.getName() != null) classnameE.setAttribute("NAME", clazz.getName()); - } - } - pParentE.appendChild(ireturnvalueE); - return ireturnvalueE; - } - - /** - * createIndication_response - * - * @param doc - * @param ID - * @param error - * @return Element - */ - // ebak: [ 1656285 ] IndicationHandler does not accept non-Integer message - // ID - public static Element createIndication_response(Document doc, String ID, CIMError error) { - - // xmlBuilder.create XML - Element cimE = createCIM(doc); - Element messageE = createMESSAGE(doc, cimE, ID, "1.0"); - Element simpleexprspE = createSIMPLEEXPRSP(doc, messageE); - Element expmethodresponseE = createEXPMETHODRESPONSE(doc, simpleexprspE, "ExportIndication"); - if (error == null) { - createIRETURNVALUE(doc, expmethodresponseE); - } else { - createERROR(doc, expmethodresponseE, error); - } - // Element - return cimE; - } - - /** - * createIRETURNVALUE_ENUMERATE_INSTANCE - * - * @param pDoc - * @param pParentE - * @param pResultSet - * @return Element - * @throws WBEMException - */ - public static Element createIRETURNVALUE_ENUMERATE_INSTANCE(Document pDoc, Element pParentE, - CIMInstance[] pResultSet) throws WBEMException { - Element ireturnvalueE = pDoc.createElement("IRETURNVALUE"); - if (pResultSet != null && pResultSet.length > 0) { - for (int i = 0; i < pResultSet.length; i++) { - createVALUENAMEDINSTANCE(pDoc, ireturnvalueE, pResultSet[i]); - } - } - pParentE.appendChild(ireturnvalueE); - return ireturnvalueE; - } - - /** - * getTypeStr - * - * @param pType - * @return String - */ - public static String getTypeStr(CIMDataType pType) { - if (pType == null) return "string"; - if (pType.getType() == CIMDataType.REFERENCE) return MOF.REFERENCE; - return MOF.dataType(pType); - } - - /** - * getOpTypeStr - * - * @param pType - * @return String - */ - public static String getOpTypeStr(CIMDataType pType) { - return getTypeStr(pType); - } - - private static final Pattern NAMESPACE_SPLIT_PATTERN = Pattern.compile("/+"); - - /** - * createLOCALNAMESPACEPATH - * - * @param pDoc - * @param pParentE - * @param pName - * @return Element - */ - public static Element createLOCALNAMESPACEPATH(Document pDoc, Element pParentE, - CIMObjectPath pName) { - if (pName == null) return null; - // TODO: name(ObjectPath) should not be null, should an exception be - // thrown? - // This assumes that the NameSpace does not consist exclusively of - // empties like "////" - Element localnamespacepathE = pDoc.createElement("LOCALNAMESPACEPATH"); - String nameSpace = pName.getNamespace(); - if (nameSpace != null) { - String[] nsA = NAMESPACE_SPLIT_PATTERN.split(nameSpace); - for (int i = 0; i < nsA.length; i++) - if (nsA[i] != null && nsA[i].length() > 0) createNAMESPACE(pDoc, - localnamespacepathE, nsA[i]); - } - pParentE.appendChild(localnamespacepathE); - - return localnamespacepathE; - } - - /** - * createSIMPLEEXPREQ - * - * @param pDoc - * @return Element - */ - public static Element createSIMPLEEXPREQ(Document pDoc) { - // - Element e = pDoc.createElement("SIMPLEEXPREQ"); - return e; - } - - /** - * createEXPMETHODCALL - * - * @param pDoc - * @param pParentE - * @param pName - * @return Element - */ - public static Element createEXPMETHODCALL(Document pDoc, Element pParentE, String pName) { - // - // - Element e = pDoc.createElement("EXPMETHODCALL"); - if (pName != null) { - e.setAttribute("NAME", pName); - } - pParentE.appendChild(e); - return e; - } - - /** - * createEXPPARAMVALUE - * - * @param pDoc - * @param pParentE - * @param pName - * @return Element - */ - public static Element createEXPPARAMVALUE(Document pDoc, Element pParentE, String pName) { - // - // - Element e = pDoc.createElement("EXPPARAMVALUE"); - if (pName != null) { - e.setAttribute("NAME", pName); - } - pParentE.appendChild(e); - return e; - } -} +/* + CIMXMLBuilderImpl.java + + (C) Copyright IBM Corp. 2005, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------ + * 16627 2005-04-01 thschaef Correct instantiation for Uint64 + * 17459 2005-06-24 thschaef catch null within createMethod method + * 17459 2005-06-27 thschaef further improvement to createMethod() + * 1535756 2006-08-07 lupusalex Make code warning free + * 1610046 2006-07-12 ebak Does not escape trailing spaces KEYVALUE + * 1631407 2007-01-11 lupusalex VALUE.REFERENCE doesn't handle references without namespace + * 1656285 2007-02-12 ebak IndicationHandler does not accept non-Integer message ID + * 1671505 2007-02-28 lupusalex Wrong escaping of spaces in XML (Undo 1610046) + * 1660756 2007-03-02 ebak Embedded object support + * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus + * 1669961 2006-04-16 lupusalex CIMTypedElement.getType() =>getDataType() + * 1719991 2007-05-16 ebak FVT: regression ClassCastException in EmbObjHandler + * 1737141 2007-06-18 ebak Sync up with JSR48 evolution + * 1820763 2007-10-29 ebak Supporting the EmbeddedInstance qualifier + * 1827728 2007-11-12 ebak embeddedInstances: attribute EmbeddedObject not set + * 1827728 2007-11-20 ebak rework: embeddedInstances: attribute EmbeddedObject not set + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2087969 2008-09-03 blaschke-oss VALUE.ARRAY used in request for array of references + * 2093708 2008-09-10 rgummada HTTP 400 - Bad Request, CIMError: request-not-valid + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2210455 2008-10-30 blaschke-oss Enhance javadoc, fix potential null pointers + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2823494 2009-08-03 rgummada Change Boolean constructor to static + * 2849970 2009-09-03 blaschke-oss createVALUEARRAY fails to create reference array + * 2912490 2010-01-05 rgummada NullPointerException when invoking getInstance + * 2957387 2010-03-03 blaschke-oss EmbededObject XML attribute must not be all uppercases + * 2970881 2010-03-15 blaschke-oss Add property to control EmbeddedObject case + * 3001333 2010-05-19 blaschke-oss CIMMethod class ignores propagated parameter + * 3304058 2011-05-20 blaschke-oss Use same date format in change history + * 3588558 2012-11-26 blaschke-oss An enhancement on Java CIM Client logging + * 2616 2013-02-23 blaschke-oss Add new API WBEMClientSBLIM.sendIndication() + * 2638 2013-05-09 blaschke-oss Do not build empty REFERENCECLASS + * 2689 2013-10-10 blaschke-oss createMETHODCALL should not add PARAMTYPE attribute + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import org.metricshub.wbem.javax.cim.CIMArgument; +import org.metricshub.wbem.javax.cim.CIMClass; +import org.metricshub.wbem.javax.cim.CIMClassProperty; +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMFlavor; +import org.metricshub.wbem.javax.cim.CIMInstance; +import org.metricshub.wbem.javax.cim.CIMMethod; +import org.metricshub.wbem.javax.cim.CIMNamedElementInterface; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.cim.CIMParameter; +import org.metricshub.wbem.javax.cim.CIMProperty; +import org.metricshub.wbem.javax.cim.CIMQualifiedElementInterface; +import org.metricshub.wbem.javax.cim.CIMQualifier; +import org.metricshub.wbem.javax.cim.CIMQualifierType; +import org.metricshub.wbem.javax.cim.CIMScope; +import org.metricshub.wbem.javax.cim.CIMTypedElement; +import org.metricshub.wbem.javax.cim.CIMValuedElement; +import org.metricshub.wbem.javax.wbem.WBEMException; +import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMQualifiedElementInterfaceImpl; +import org.metricshub.wbem.sblim.cimclient.internal.util.MOF; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfiguration; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.CIMError; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Text; + +/** + * Class CIMXMLBuilderImpl is the core class for building CIM-XML documents. + */ +public class CIMXMLBuilderImpl { + private static final int MAJOR_CIM_VERSION = 2; + + private static final int MINOR_CIM_VERSION = 0; + + private static final int MAJOR_DTD_VERSION = 2; + + private static final int MINOR_DTD_VERSION = 0; + + /** + * createCIM + * + * @param pDoc + * @return Element + */ + public static Element createCIM(Document pDoc) { + // + // + Element e = pDoc.createElement("CIM"); + e.setAttribute("CIMVERSION", MAJOR_CIM_VERSION + "." + MINOR_CIM_VERSION); + // required + e.setAttribute("DTDVERSION", MAJOR_DTD_VERSION + "." + MINOR_DTD_VERSION); + // required + pDoc.appendChild(e); // root element + return e; + } + + // //////////////////////////////////////////////////////////////////////////////////////// + // Value Elements + // //////////////////////////////////////////////////////////////////////////////////////// + + /** + * createVALUE + * + * @param pDoc + * @param pParentE + * @return Element + */ + public static Element createVALUE(Document pDoc, Element pParentE) { + // + Element e = pDoc.createElement("VALUE"); + pParentE.appendChild(e); + + return e; + } + + /** + * createVALUE + * + * @param pDoc + * @param pParentE + * @param pValue + * @return Element + */ + public static Element createVALUE(Document pDoc, Element pParentE, String pValue) { + // + Element e = pDoc.createElement("VALUE"); + pParentE.appendChild(e); + + Text textE = pDoc.createTextNode(pValue); + e.appendChild(textE); + return e; + } + + /** + * createVALUE + * + * @param pDoc + * @param pParentE + * @param pValue + * @return Element + */ + public static Element createVALUE(Document pDoc, Element pParentE, boolean pValue) { + return createVALUE(pDoc, pParentE, pValue ? MOF.TRUE : MOF.FALSE); + } + + /** + * createVALUEARRAY + * + * @param pDoc + * @param pParentE + * @return Element + */ + public static Element createVALUEARRAY(Document pDoc, Element pParentE) { + // + Element e = pDoc.createElement("VALUE.ARRAY"); + pParentE.appendChild(e); + return e; + } + + /** + * createVALUEREFERENCE + * + * @param pDoc + * @param pParentE + * @return Element + */ + public static Element createVALUEREFERENCE(Document pDoc, Element pParentE) { + // + Element e = pDoc.createElement("VALUE.REFERENCE"); + pParentE.appendChild(e); + return e; + } + + /** + * createVALUEREFARRAY + * + * @param pDoc + * @param pParentE + * @return Element + */ + public static Element createVALUEREFARRAY(Document pDoc, Element pParentE) { + // + Element e = pDoc.createElement("VALUE.REFARRAY"); + pParentE.appendChild(e); + return e; + } + + // //////////////////////////////////////////////////////////////////////////////////////// + // Properties elements + // //////////////////////////////////////////////////////////////////////////////////////// + /** + * createPROPERTY + * + * @param pDoc + * @param pParentE + * @param pName + * @param pType + * @return Element + */ + public static Element createPROPERTY(Document pDoc, Element pParentE, String pName, String pType) { + // + // + + Element e = pDoc.createElement("PROPERTY"); + if (pName != null) e.setAttribute("NAME", pName); + if (pType != null) e.setAttribute("TYPE", pType); + // TODO: ClassOrigin, Propagated + pParentE.appendChild(e); + return e; + } + + /** + * createPROPERTYARRAY + * + * @param pDoc + * @param pParentE + * @param pName + * @param pType + * @return Element + */ + public static Element createPROPERTYARRAY(Document pDoc, Element pParentE, String pName, String pType) { + // + // + + Element e = pDoc.createElement("PROPERTY.ARRAY"); + if (pName != null) e.setAttribute("NAME", pName); + if (pType != null) e.setAttribute("TYPE", pType); + // TODO: ClassOrigin, Propagated + pParentE.appendChild(e); + return e; + } + + /** + * createPROPERTYREFERENCE + * + * @param pDoc + * @param pParentE + * @param pName + * @param pReferenceclass + * @return Element + */ + public static Element createPROPERTYREFERENCE(Document pDoc, Element pParentE, String pName, String pReferenceclass) { + // + // + + Element e = pDoc.createElement("PROPERTY.REFERENCE"); + if (pName != null) e.setAttribute("NAME", pName); + if (pReferenceclass != null && pReferenceclass.length() > 0) e.setAttribute("REFERENCECLASS", pReferenceclass); + pParentE.appendChild(e); + return e; + } + + // //////////////////////////////////////////////////////////////////////////////////////// + // Naming and Location elements + // //////////////////////////////////////////////////////////////////////////////////////// + + /** + * createNAMESPACE + * + * @param pDoc + * @param pParentE + * @param pName + * @return Element + */ + public static Element createNAMESPACE(Document pDoc, Element pParentE, String pName) { + // + // + Element e = pDoc.createElement("NAMESPACE"); + if (pName != null) { + e.setAttribute("NAME", pName); + } + pParentE.appendChild(e); + return e; + } + + /** + * createLOCALINSTANCEPATH + * + * @param pDoc + * @param pParentE + * @return Element + */ + public static Element createLOCALINSTANCEPATH(Document pDoc, Element pParentE) { + // + Element e = pDoc.createElement("LOCALINSTANCEPATH"); + pParentE.appendChild(e); + return e; + } + + /** + * createCLASSNAME + * + * @param pDoc + * @param pParentE + * @param pName + * @return Element + */ + public static Element createCLASSNAME(Document pDoc, Element pParentE, String pName) { + // + // + Element e = pDoc.createElement("CLASSNAME"); + if (pName != null) { + e.setAttribute("NAME", pName); + + pParentE.appendChild(e); + } + return e; + } + + /** + * createCLASS + * + * @param pDoc + * @param pParentE + * @param pName + * @param pSuperClass + * @return Element + */ + public static Element createCLASS(Document pDoc, Element pParentE, String pName, String pSuperClass) { + // + // + Element e = pDoc.createElement("CLASS"); + if (pName != null) { + e.setAttribute("NAME", pName); + } + if (pSuperClass != null && pSuperClass.length() > 0) { + e.setAttribute("SUPERCLASS", pSuperClass); + } + if (pParentE != null) pParentE.appendChild(e); + return e; + } + + /** + * createINSTANCENAME + * + * @param pDoc + * @param pParentE + * @param pClassName + * @return Element + */ + public static Element createINSTANCENAME(Document pDoc, Element pParentE, String pClassName) { + // + // + Element e = pDoc.createElement("INSTANCENAME"); + if (pClassName != null) { + e.setAttribute("CLASSNAME", pClassName); + } + pParentE.appendChild(e); + return e; + } + + /** + * createKEYBINDING + * + * @param pDoc + * @param pParentE + * @param pName + * @return Element + */ + public static Element createKEYBINDING(Document pDoc, Element pParentE, String pName) { + // + // + Element e = pDoc.createElement("KEYBINDING"); + if (pName != null) { + e.setAttribute("NAME", pName); + } + pParentE.appendChild(e); + return e; + } + + private static final Pattern NUM_PAT = Pattern.compile("^[su]int(8|16|32|64)$", Pattern.CASE_INSENSITIVE); + + /** + * + * getValueTypeStr + * + * @param pTypeStr + * @return String + */ + private static String getValueTypeStr(String pTypeStr) { + if (pTypeStr == null || MOF.DT_STR.equalsIgnoreCase(pTypeStr)) return MOF.DT_STR; + if (MOF.DT_BOOL.equalsIgnoreCase(pTypeStr)) return MOF.DT_BOOL; + Matcher m = NUM_PAT.matcher(pTypeStr); + if (m.matches()) return "numeric"; + return MOF.DT_STR; + } + + /** + * createKEYVALUE + * + * @param pDoc + * @param pParentE + * @param pValueType + * @param pValue + * @return KEYVALUE + */ + public static Element createKEYVALUE(Document pDoc, Element pParentE, String pValueType, String pValue) { + /* + * + */ + if (pValueType == null) pValueType = "string"; + Element e = pDoc.createElement("KEYVALUE"); + // FIXME: ebak: TYPE attrib is more exact, easier to handle + e.setAttribute("TYPE", pValueType); + // ebak: maybe old CIMOMs won't understand the TYPE attrib + e.setAttribute("VALUETYPE", getValueTypeStr(pValueType)); + pParentE.appendChild(e); + Text valueE = pDoc.createTextNode(pValue); + e.appendChild(valueE); + return e; + } + + // //////////////////////////////////////////////////////////////////////////////////////// + // Object Definition Elements + // //////////////////////////////////////////////////////////////////////////////////////// + + /** + * createINSTANCE + * + * @param pDoc + * @param pParentE + * @param pClassName + * @return Element + */ + public static Element createINSTANCE(Document pDoc, Element pParentE, String pClassName) { + // + // + + Element e = pDoc.createElement("INSTANCE"); + if (pClassName != null) { + e.setAttribute("CLASSNAME", pClassName); + } + if (pParentE != null) pParentE.appendChild(e); + return e; + } + + /** + * createQUALIFIER + * + * @param pDoc + * @param pParentE + * @param pName + * @param pType + * @return Element + */ + public static Element createQUALIFIER(Document pDoc, Element pParentE, String pName, String pType) { + // + // + + Element e = pDoc.createElement("QUALIFIER"); + if (pName != null) { + e.setAttribute("NAME", pName); + // TODO: add additional attributes "propagated", "qualifierFlavod" + } + if (pType != null) e.setAttribute("TYPE", pType); + pParentE.appendChild(e); + return e; + } + + // /////////////////////////////////////////////////////////////////////////////////////////// + // Message Elements + // /////////////////////////////////////////////////////////////////////////////////////////// + + /** + * createMESSAGE + * + * @param pDoc + * @param pParentE + * @param pId + * @param pProtocolVersion + * @return Element + */ + public static Element createMESSAGE(Document pDoc, Element pParentE, String pId, String pProtocolVersion) { + // + // + Element e = pDoc.createElement("MESSAGE"); + e.setAttribute("ID", pId); // required + e.setAttribute("PROTOCOLVERSION", pProtocolVersion); // required + pParentE.appendChild(e); + return e; + } + + /** + * createSIMPLEREQ + * + * @param pDoc + * @param pParentE + * @return Element + */ + public static Element createSIMPLEREQ(Document pDoc, Element pParentE) { + // + Element e = pDoc.createElement("SIMPLEREQ"); + pParentE.appendChild(e); + return e; + } + + /** + * createSIMPLEREQ + * + * @param pDoc + * @return Element + */ + public static Element createSIMPLEREQ(Document pDoc) { + // + Element e = pDoc.createElement("SIMPLEREQ"); + return e; + } + + /** + * createMULTIREQ + * + * @param pDoc + * @return Element + */ + public static Element createMULTIREQ(Document pDoc) { + // + Element e = pDoc.createElement("MULTIREQ"); + return e; + } + + /** + * createMETHODCALL + * + * @param pDoc + * @param pParentE + * @param pName + * @return Element + */ + public static Element createMETHODCALL(Document pDoc, Element pParentE, String pName) { + // + // + Element e = pDoc.createElement("METHODCALL"); + if (pName != null) { + e.setAttribute("NAME", pName); + } + pParentE.appendChild(e); + return e; + } + + /** + * createPARAMVALUE + * + * @param pDoc + * @param pParentE + * @param pArg + * @return Element + * @throws WBEMException + */ + public static Element createPARAMVALUE(Document pDoc, Element pParentE, CIMArgument pArg) throws WBEMException { + // ) + // + if (pArg == null) return null; + Element e = pDoc.createElement("PARAMVALUE"); + EmbObjBuilder embObjBuilder = new EmbObjBuilder(pDoc, pArg); + if (pArg.getName() != null) { + e.setAttribute("NAME", pArg.getName()); + } + e.setAttribute("PARAMTYPE", embObjBuilder.getTypeStr()); + embObjBuilder.addSign(e); + embObjBuilder.addValue(e); + pParentE.appendChild(e); + return e; + } + + /** + * createSIMPLERSP + * + * @param pDoc + * @param pParentE + * @return Element + */ + public static Element createSIMPLERSP(Document pDoc, Element pParentE) { + // + Element e = pDoc.createElement("SIMPLERSP"); + + if (pParentE != null) pParentE.appendChild(e); + return e; + } + + /** + * createSIMPLEEXPRSP + * + * @param pDoc + * @param pParentE + * @return Element + */ + public static Element createSIMPLEEXPRSP(Document pDoc, Element pParentE) { + // + Element e = pDoc.createElement("SIMPLEEXPRSP"); + + pParentE.appendChild(e); + return e; + } + + /** + * createMETHODRESPONSE + * + * @param pDoc + * @param pParentE + * @param pName + * @return Element + */ + public static Element createMETHODRESPONSE(Document pDoc, Element pParentE, String pName) { + // + // + + // %CIMName;> + Element e = pDoc.createElement("METHODRESPONSE"); + if (pName != null) { + e.setAttribute("NAME", pName); + } + pParentE.appendChild(e); + return e; + } + + /** + * createIMETHODRESPONSE + * + * @param pDoc + * @param pParentE + * @param pName + * @return Element + */ + public static Element createIMETHODRESPONSE(Document pDoc, Element pParentE, String pName) { + // + // + // %CIMName;> + Element e = pDoc.createElement("IMETHODRESPONSE"); + if (pName != null) { + e.setAttribute("NAME", pName); + } + pParentE.appendChild(e); + return e; + } + + /** + * createEXPMETHODRESPONSE + * + * @param pDoc + * @param pParentE + * @param pName + * @return Element + */ + public static Element createEXPMETHODRESPONSE(Document pDoc, Element pParentE, String pName) { + // + // + Element e = pDoc.createElement("EXPMETHODRESPONSE"); + if (pName != null) { + e.setAttribute("NAME", pName); + } + pParentE.appendChild(e); + return e; + } + + /** + * createIRETURNVALUE + * + * @param pDoc + * @param pParentE + * @return Element + */ + public static Element createIRETURNVALUE(Document pDoc, Element pParentE) { + // + Element e = pDoc.createElement("IRETURNVALUE"); + pParentE.appendChild(e); + return e; + } + + /** + *
      +	 * !ELEMENT RETURNVALUE (VALUE | VALUE.REFERENCE)
      +	 * !ATTLIST RETURNVALUE
      +	 * %ParamType;       #IMPLIED
      +	 * 
      + * + * createRETURNVALUE + * + * @param pDoc + * @param pParentE + * @param pValue + * @return Element + * @throws WBEMException + */ + public static Element createRETURNVALUE(Document pDoc, Element pParentE, Object pValue) throws WBEMException { + Element retValE = pDoc.createElement("RETURNVALUE"); + CIMDataType type = CIMDataType.getDataType(pValue); + retValE.setAttribute("PARAMTYPE", getTypeStr(type)); + createVALUE(pDoc, retValE, pValue); + pParentE.appendChild(retValE); + return retValE; + } + + /** + * createIMETHODCALL + * + * @param pDoc + * @param pParentE + * @param pName + * @return Element + */ + public static Element createIMETHODCALL(Document pDoc, Element pParentE, String pName) { + // + // + Element e = pDoc.createElement("IMETHODCALL"); + if (pName != null) { + e.setAttribute("NAME", pName); + } + pParentE.appendChild(e); + return e; + } + + /** + * createIPARAMVALUE + * + * @param pDoc + * @param pParentE + * @param pName + * @return Element + */ + public static Element createIPARAMVALUE(Document pDoc, Element pParentE, String pName) { + // ) + // + Element e = pDoc.createElement("IPARAMVALUE"); + if (pName != null) { + e.setAttribute("NAME", pName); + } + pParentE.appendChild(e); + return e; + } + + /** + * createERROR + * + * @param doc + * @param parentE + * @param error + * @return Element + */ + public static Element createERROR(Document doc, Element parentE, CIMError error) { + // + // + Element e = doc.createElement("ERROR"); + int code; + if ((code = error.getCode()) > 0) { + e.setAttribute("CODE", Integer.toString(code)); + } + String description = error.getDescription(); + if (description != null) { + e.setAttribute("DESCRIPTION", description); + } + + parentE.appendChild(e); + return e; + } + + /** + * ENTITY % QualifierFlavor "OVERRIDABLE (true|false) 'true' TOSUBCLASS + * (true|false) 'true' TOINSTANCE (true|false) 'false' TRANSLATABLE + * (true|false) 'false'" + * + * @param pElement + * @param pFlavors + */ + private static void setFlavors(Element pElement, int pFlavors) { + if ((pFlavors & CIMFlavor.TRANSLATE) > 0) { + pElement.setAttribute("TRANSLATABLE", MOF.TRUE); + } + if ((pFlavors & CIMFlavor.DISABLEOVERRIDE) > 0) { + pElement.setAttribute("OVERRIDABLE", MOF.FALSE); + } + if ((pFlavors & CIMFlavor.RESTRICTED) > 0) { + pElement.setAttribute("TOSUBCLASS", MOF.FALSE); + } + /* + * if ((pFlavors & CIMFlavor.RESTRICTED)>0) { + * pElement.setAttribute("TOSUBCLASS", "true"); } + */ + } + + /** + * createQUALIFIER_DECLARATION + * + * @param pDoc + * @param pParentE + * @param pQualifierType + * @return Element + * @throws WBEMException + */ + public static Element createQUALIFIER_DECLARATION( + Document pDoc, + Element pParentE, + CIMQualifierType pQualifierType + ) + throws WBEMException { + // + // + + String pValueTypeStr = getTypeStr(pQualifierType.getDataType()); + Element qualifierdeclarationE = pDoc.createElement("QUALIFIER.DECLARATION"); + qualifierdeclarationE.setAttribute("NAME", pQualifierType.getName()); + qualifierdeclarationE.setAttribute("TYPE", pValueTypeStr); + qualifierdeclarationE.setAttribute("ISARRAY", pQualifierType.getDataType().isArray() ? MOF.TRUE : MOF.FALSE); + + setFlavors(qualifierdeclarationE, pQualifierType.getFlavor()); + + int scopes = pQualifierType.getScope(); + if (scopes > 0) { + Element scopeE = pDoc.createElement("SCOPE"); + if ((scopes & CIMScope.CLASS) > 0) scopeE.setAttribute("CLASS", MOF.TRUE); + if ((scopes & CIMScope.ASSOCIATION) > 0) scopeE.setAttribute("ASSOCIATION", MOF.TRUE); + if ((scopes & CIMScope.REFERENCE) > 0) scopeE.setAttribute("REFERENCE", MOF.TRUE); + if ((scopes & CIMScope.PROPERTY) > 0) scopeE.setAttribute("PROPERTY", MOF.TRUE); + if ((scopes & CIMScope.METHOD) > 0) scopeE.setAttribute("METHOD", MOF.TRUE); + if ((scopes & CIMScope.PARAMETER) > 0) scopeE.setAttribute("PARAMETER", MOF.TRUE); + if ((scopes & CIMScope.INDICATION) > 0) scopeE.setAttribute("INDICATION", MOF.TRUE); + qualifierdeclarationE.appendChild(scopeE); + } + + createVALUE(pDoc, qualifierdeclarationE, pQualifierType.getValue()); + + pParentE.appendChild(qualifierdeclarationE); + return qualifierdeclarationE; + } + + /** + * createQUALIFIER + * + * @param pDoc + * @param pParentE + * @param pQualifier + * @return Element + * @throws WBEMException + */ + public static Element createQUALIFIER(Document pDoc, Element pParentE, CIMQualifier pQualifier) + throws WBEMException { + // + // + + Object value = pQualifier.getValue(); + if (value == null) return null; + + Element qualifierE = createQUALIFIER(pDoc, pParentE, pQualifier.getName(), getTypeStr(pQualifier.getDataType())); + + if (pQualifier.isPropagated()) { + qualifierE.setAttribute("PROPAGATED", "true"); + } + setFlavors(qualifierE, pQualifier.getFlavor()); + + createVALUE(pDoc, qualifierE, value); + + pParentE.appendChild(qualifierE); + return qualifierE; + } + + /** + * createQUALIFIERS + * + * @param pDoc + * @param pParentE + * @param pQualifiersA + * @throws WBEMException + */ + public static void createQUALIFIERS(Document pDoc, Element pParentE, CIMQualifier[] pQualifiersA) + throws WBEMException { + if (pQualifiersA == null) return; + for (int i = 0; i < pQualifiersA.length; i++) { + createQUALIFIER(pDoc, pParentE, pQualifiersA[i]); + } + } + + /** + * createPROPERTIES + * + * @param pDoc + * @param pParentE + * @param pProperties + * @throws WBEMException + */ + public static void createPROPERTIES(Document pDoc, Element pParentE, CIMProperty[] pProperties) + throws WBEMException { + if (pProperties == null) return; + for (int i = 0; i < pProperties.length; i++) { + createPROPERTY(pDoc, pParentE, pProperties[i]); + } + } + + private static final CIMQualifiedElementInterfaceImpl KEYQUALIFIERS_IMPL = new CIMQualifiedElementInterfaceImpl( + null, + true + ); + + static final CIMQualifier EMB_OBJ_QUALI = new CIMQualifier( + "EmbeddedObject", + CIMDataType.BOOLEAN_T, + Boolean.TRUE, + CIMFlavor.DISABLEOVERRIDE + ); + + // ebak: embedded object: CLASS_T or INSTANCE_T? + + /** + * isCIMObject + * + * @param typeCode + * @return boolean + */ + public static boolean isCIMObject(int typeCode) { + return typeCode == CIMDataType.CLASS || typeCode == CIMDataType.OBJECT; + } + + /** + * isCIMObject + * + * @param pType + * @return boolean + */ + public static boolean isCIMObject(CIMDataType pType) { + return pType == null ? false : isCIMObject(pType.getType()); + } + + /** + * getEmbObjTypeStr + * + * @param pType + * @return String + */ + public static String getEmbObjTypeStr(CIMDataType pType) { + return isCIMObject(pType) ? MOF.DT_STR : getTypeStr(pType); + } + + private static Document getDoc() { + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder docBuilder = factory.newDocumentBuilder(); + return docBuilder.newDocument(); + } catch (ParserConfigurationException e) { + throw new RuntimeException(e); + } + } + + /** + * cimObjectToXMLString - for embedded object support + * + * @param pObj + * @return String + * @throws WBEMException + */ + public static String cimObjectToXMLString(Object pObj) throws WBEMException { + if (pObj == null) return null; + Document doc; + Element e; + if (pObj instanceof CIMClass) { + doc = getDoc(); + e = createCLASS(doc, null, (CIMClass) pObj); + } else if (pObj instanceof CIMInstance) { + doc = getDoc(); + e = createINSTANCE(doc, null, (CIMInstance) pObj); + } else { + throw new WBEMException( + WBEMException.CIM_ERR_FAILED, + pObj.getClass().getName() + " parameter is not suitable for this method!" + ); + } + doc.appendChild(e); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + try { + CimXmlSerializer.serialize(os, doc.getDocumentElement(), false); + } catch (IOException ex) { + throw new WBEMException(WBEMException.CIM_ERR_FAILED, "XML serialization failed with IOException!", null, ex); + } + return os.toString(); + } + + /** + * cimObjectArrayToXMLString - for embedded object support + * + * @param pObj + * @return String[] + * @throws WBEMException + */ + public static String[] cimObjectArrayToXMLString(Object pObj) throws WBEMException { + if (pObj == null) return null; + if (!(pObj instanceof Object[])) throw new WBEMException( + WBEMException.CIM_ERR_FAILED, + "Object[] parameter is required for this method!" + ); + Object[] objA = (Object[]) pObj; + String[] strA = new String[objA.length]; + // here we don't deal with the consistency check of the Object[] + for (int i = 0; i < objA.length; i++) strA[i] = cimObjectToXMLString(objA[i]); + return strA; + } + + static boolean embObjQualified(CIMQualifiedElementInterface pQualid) { + return pQualid.hasQualifier("EmbeddedObject") || pQualid.hasQualifier("EmbeddedInstance"); + } + + static class EmbObjBuilder { + private static final int ATTRIB_ONLY = 0, EO_QUALI = 1, EO_AND_EI_QUALI = 2; + + private int iSignMethod; + + private Document iDoc; + + private CIMTypedElement iTypedE; + + private boolean iXMLQualified; + + private static final boolean iUpperCaseEmbObjEntities = WBEMConfiguration + .getGlobalConfiguration() + .upperCaseEmbObjEntities(); + + /** + * Ctor. + * + * @param pDoc + * @param pTypedE + */ + public EmbObjBuilder(Document pDoc, CIMTypedElement pTypedE) { + this(pDoc, pTypedE, false); + } + + /** + * Ctor. + * + * @param pDoc + * @param pTypedE + * @param pXMLQualified + * - e.g. CIMProperty is not qualified in JSR48, but + * qualified in CIM-XML + */ + public EmbObjBuilder(Document pDoc, CIMTypedElement pTypedE, boolean pXMLQualified) { + this.iDoc = pDoc; + this.iTypedE = pTypedE; + this.iXMLQualified = pXMLQualified; + String builderCfg = WBEMConfiguration.getGlobalConfiguration().getCimXmlEmbObjBuilder(); + if ("EmbObjQuali".equalsIgnoreCase(builderCfg)) { + this.iSignMethod = EO_QUALI; + } else if ("EmbObjAndEmbInstQuali".equalsIgnoreCase(builderCfg)) { + this.iSignMethod = EO_AND_EI_QUALI; + } else { + this.iSignMethod = ATTRIB_ONLY; + } + } + + /** + * getTypeStr + * + * @return String + */ + public String getTypeStr() { + return getEmbObjTypeStr(this.iTypedE.getDataType()); + } + + /** + * isArray + * + * @return String + */ + public boolean isArray() { + return this.iTypedE.getDataType().isArray(); + } + + private Object getValue() { + if (!(this.iTypedE instanceof CIMValuedElement)) return null; + return ((CIMValuedElement) this.iTypedE).getValue(); + } + + /** + * addSign + * + * @param pElement + * @throws WBEMException + */ + public void addSign(Element pElement) throws WBEMException { + if (!isCIMObject(this.iTypedE.getDataType())) return; + CIMQualifiedElementInterface qualified; + if (this.iTypedE instanceof CIMQualifiedElementInterface) { + qualified = (CIMQualifiedElementInterface) this.iTypedE; + if (embObjQualified(qualified)) return; + } else { + qualified = null; + } + if (this.iSignMethod == ATTRIB_ONLY || (qualified == null && !this.iXMLQualified)) { + pElement.setAttribute( + iUpperCaseEmbObjEntities ? "EMBEDDEDOBJECT" : "EmbeddedObject", + this.iTypedE.getDataType().getType() == CIMDataType.OBJECT ? "instance" : "object" + ); + } else { + if (this.iSignMethod == EO_AND_EI_QUALI) { + addEmbObjOrEmbInstQuali(pElement); + } else { // EO_QUALI + createQUALIFIER(this.iDoc, pElement, EMB_OBJ_QUALI); + } + } + } + + private void addEmbObjOrEmbInstQuali(Element pElement) throws WBEMException { + CIMQualifier signQuali; + if (this.iTypedE.getDataType().getType() == CIMDataType.OBJECT) { + CIMInstance inst; + if (isArray()) { + CIMInstance[] instA = (CIMInstance[]) getValue(); + inst = instA == null ? null : instA[0]; + } else { + inst = (CIMInstance) getValue(); + } + String className = inst == null ? "" : inst.getClassName(); + signQuali = + new CIMQualifier("EmbeddedInstance", CIMDataType.STRING_T, className, CIMFlavor.DISABLEOVERRIDE); + } else { // class + signQuali = EMB_OBJ_QUALI; + } + createQUALIFIER(this.iDoc, pElement, signQuali); + } + + /** + * addValue + * + * @param pElement + * @throws WBEMException + */ + public void addValue(Element pElement) throws WBEMException { + Object value = getValue(); + if (value == null) return; + if (isCIMObject(this.iTypedE.getDataType())) { + if (isArray()) { + value = cimObjectArrayToXMLString(value); + } else { + value = cimObjectToXMLString(value); + } + } + createVALUE(this.iDoc, pElement, value); + } + } + + /** + * createPROPERTY + * + * @param pDoc + * @param pParentE + * @param pProperty + * @return Element + * @throws WBEMException + */ + public static Element createPROPERTY(Document pDoc, Element pParentE, CIMProperty pProperty) throws WBEMException { + CIMDataType propType = pProperty.getDataType(); + Element propertyE; + EmbObjBuilder embObjBuilder = new EmbObjBuilder(pDoc, pProperty, true); + String typeStr = embObjBuilder.getTypeStr(); + if (propType.isArray()) { + propertyE = createPROPERTYARRAY(pDoc, pParentE, pProperty.getName(), typeStr); + } else if (propType.getType() == CIMDataType.REFERENCE) { + propertyE = createPROPERTYREFERENCE(pDoc, pParentE, pProperty.getName(), propType.getRefClassName()); + } else { + propertyE = createPROPERTY(pDoc, pParentE, pProperty.getName(), typeStr); + } + + String classorigin = pProperty.getOriginClass(); + if (classorigin != null && classorigin.length() > 0) propertyE.setAttribute("CLASSORIGIN", classorigin); + + if (pProperty.isPropagated()) propertyE.setAttribute("PROPAGATED", MOF.TRUE); + // FIXME: here key qualifier should be added if the property is a key + embObjBuilder.addSign(propertyE); + if (pProperty instanceof CIMClassProperty) { + createQUALIFIERS(pDoc, propertyE, ((CIMClassProperty) pProperty).getQualifiers()); + } else { // CIMProperty + if (pProperty.isKey()) createQUALIFIERS(pDoc, propertyE, KEYQUALIFIERS_IMPL.getQualifiers()); + } + embObjBuilder.addValue(propertyE); + return propertyE; + } + + /** + * createVALUEARRAY + * + * @param pDoc + * @param pParentE + * @param pValA + * @return Element + * @throws WBEMException + */ + public static Element createVALUEARRAY(Document pDoc, Element pParentE, Object[] pValA) throws WBEMException { + Element valuearrayE = ( + pValA != null && pValA.length > 0 && (pValA[0] instanceof CIMObjectPath || pValA[0] instanceof CIMInstance) + ) + ? createVALUEREFARRAY(pDoc, pParentE) + : createVALUEARRAY(pDoc, pParentE); + + if (pValA != null) for (int i = 0; i < pValA.length; i++) { + createVALUE(pDoc, valuearrayE, pValA[i]); + } + pParentE.appendChild(valuearrayE); + return valuearrayE; + } + + /** + * createVALUE + * + * @param pDoc + * @param pParentE + * @param pArgValue + * @return Element + * @throws WBEMException + */ + public static Element createVALUE(Document pDoc, Element pParentE, Object pArgValue) throws WBEMException { + if (pArgValue == null) return null; + + Element valueE = null; + if (pArgValue instanceof Object[]) { + valueE = createVALUEARRAY(pDoc, pParentE, (Object[]) pArgValue); + } else { + CIMDataType type = CIMDataType.getDataType(pArgValue); + if (type != null && type.getType() == CIMDataType.REFERENCE) { + valueE = createVALUEREFERENCE(pDoc, pParentE); + + CIMObjectPath op = (CIMObjectPath) pArgValue; + CIMProperty[] keys = op.getKeys(); + if (op.getHost() == null || "".equals(op.getHost())) { + if (op.getNamespace() == null || "".equals(op.getNamespace())) { + if (keys.length > 0) { + createINSTANCENAME(pDoc, valueE, op); + } else { + createCLASSNAME(pDoc, valueE, op.getObjectName()); + } + } else { + if (keys.length > 0) { + createLOCALINSTANCEPATH(pDoc, valueE, op); + } else { + createLOCALCLASSPATH(pDoc, valueE, op); + } + } + } else { + if (keys.length > 0) { + createINSTANCEPATH(pDoc, valueE, op); + } else { + createCLASSPATH(pDoc, valueE, op); + } + } + // createOBJECTPATH(doc, valueE, (CIMObjectPath) obj); + } else { + if (pArgValue instanceof CIMInstance) { + valueE = createVALUEREFERENCE(pDoc, pParentE); + CIMObjectPath cop = ((CIMInstance) pArgValue).getObjectPath(); + createINSTANCENAME(pDoc, valueE, cop); + } else if (pArgValue instanceof CIMClass) { + valueE = createVALUE(pDoc, pParentE); + createCLASS(pDoc, valueE, (CIMClass) pArgValue); + } else { + createVALUE(pDoc, pParentE, pArgValue.toString()); + } + } + } + + return valueE; + } + + /** + * createINSTANCE + * + * @param pDoc + * @param pParentE + * @param pInstance + * @return Element + * @throws WBEMException + */ + public static Element createINSTANCE(Document pDoc, Element pParentE, CIMInstance pInstance) throws WBEMException { + // + // + + String className = pInstance.getObjectPath().getObjectName(); + if (className == null) throw new WBEMException(WBEMException.CIM_ERR_FAILED, "null class name"); + + Element instanceE = createINSTANCE(pDoc, pParentE, className); + + // FIXME: in JSR48 CIMInstance doesn't have qualifiers + // createQUALIFIERS(pDoc, instanceE, pInstance.getQualifiers()); + createPROPERTIES(pDoc, instanceE, pInstance.getProperties()); + + if (pParentE != null) pParentE.appendChild(instanceE); + + return instanceE; + } + + /** + * createOBJECTPATH + * + * @param pDoc + * @param pParentE + * @param pPath + * @return Element + * @throws WBEMException + */ + public static Element createOBJECTPATH(Document pDoc, Element pParentE, CIMObjectPath pPath) throws WBEMException { + Element objectpathE = pDoc.createElement("OBJECTPATH"); + + CIMProperty[] keys = pPath.getKeys(); + if (keys.length > 0) { + createINSTANCEPATH(pDoc, objectpathE, pPath); + } else { + createCLASSPATH(pDoc, objectpathE, pPath); + } + + pParentE.appendChild(objectpathE); + return objectpathE; + } + + /** + * createOBJECTNAME + * + * @param pDoc + * @param pParentE + * @param pPath + * @return Element + * @throws WBEMException + */ + public static Element createOBJECTNAME(Document pDoc, Element pParentE, CIMObjectPath pPath) throws WBEMException { + CIMProperty[] keys = pPath.getKeys(); + if (keys.length > 0) { + return createINSTANCENAME(pDoc, pParentE, pPath); + } + if (pPath.getObjectName() == null) throw new WBEMException( + WBEMException.CIM_ERR_INVALID_PARAMETER, + "null class name" + ); + return createCLASSNAME(pDoc, pParentE, pPath.getObjectName()); + } + + /** + * createLOCALINSTANCEPATH + * + * @param pDoc + * @param pParentE + * @param pPath + * @return Element + * @throws WBEMException + */ + public static Element createLOCALINSTANCEPATH(Document pDoc, Element pParentE, CIMObjectPath pPath) + throws WBEMException { + Element localinstancepathE = pDoc.createElement("LOCALINSTANCEPATH"); + + createLOCALNAMESPACEPATH(pDoc, localinstancepathE, pPath); + createINSTANCENAME(pDoc, localinstancepathE, pPath); + + pParentE.appendChild(localinstancepathE); + return localinstancepathE; + } + + /** + * createLOCALCLASSPATH + * + * @param pDoc + * @param pParentE + * @param pPath + * @return Element + * @throws WBEMException + */ + public static Element createLOCALCLASSPATH(Document pDoc, Element pParentE, CIMObjectPath pPath) + throws WBEMException { + Element localinstancepathE = pDoc.createElement("LOCALCLASSPATH"); + + createLOCALNAMESPACEPATH(pDoc, localinstancepathE, pPath); + + if (pPath.getObjectName() == null) throw new WBEMException( + WBEMException.CIM_ERR_INVALID_PARAMETER, + "null class name" + ); + createCLASSNAME(pDoc, localinstancepathE, pPath.getObjectName()); + + pParentE.appendChild(localinstancepathE); + return localinstancepathE; + } + + /** + * createLOCALOBJECTPATH + * + * @param pDoc + * @param pParentE + * @param pPath + * @return Element + * @throws WBEMException + */ + public static Element createLOCALOBJECTPATH(Document pDoc, Element pParentE, CIMObjectPath pPath) + throws WBEMException { + CIMProperty[] keys = pPath.getKeys(); + if (keys.length > 0) { + return createLOCALINSTANCEPATH(pDoc, pParentE, pPath); + } + return createLOCALCLASSPATH(pDoc, pParentE, pPath); + } + + /** + * createVALUEREFERENCE + * + * @param pDoc + * @param pParentE + * @param pPath + * @return Element + * @throws WBEMException + */ + public static Element createVALUEREFERENCE(Document pDoc, Element pParentE, CIMObjectPath pPath) + throws WBEMException { + Element objectpathE = pDoc.createElement("VALUE.REFERENCE"); + + String ns = pPath.getNamespace(); + if (pPath.getHost() == null || "".equals(pPath.getHost())) { + if (pPath.getNamespace() == null || "".equals(ns)) { + createINSTANCENAME(pDoc, objectpathE, pPath); + } else { + createLOCALOBJECTPATH(pDoc, objectpathE, pPath); + } + } else { + CIMProperty[] keys = pPath.getKeys(); + if (keys.length > 0) { + createINSTANCEPATH(pDoc, objectpathE, pPath); + } else { + createCLASSPATH(pDoc, objectpathE, pPath); + } + } + + pParentE.appendChild(objectpathE); + return objectpathE; + } + + /** + * createINSTANCENAME + * + * @param doc + * @param parentE + * @param instanceOP + * @return Element + * @throws WBEMException + */ + public static Element createINSTANCENAME(Document doc, Element parentE, CIMObjectPath instanceOP) + throws WBEMException { + Element instancenameE = doc.createElement("INSTANCENAME"); + String classname = instanceOP.getObjectName(); + if (classname != null) { + instancenameE.setAttribute("CLASSNAME", classname); + } + + CIMProperty[] keysA = instanceOP.getKeys(); + for (int ii = 0; ii < keysA.length; ii++) { + CIMProperty prop = keysA[ii]; + String propName = prop.getName(); + CIMDataType propType = prop.getDataType(); + Object propValue = prop.getValue(); + // if (_pValue == null) TODO what happened when a KeyBinding has a + // null property value? + /* + * ebak: test support for #1666336 EnumInstance has attributes + * filled from others Handling direct KEYVALUE and + * VALUE.REFERENCE children is difficult, KEYBINDING can wrap them + * -> dropping out KEYVALUE? | VALUE.REFERENCE?. + * + * + * + * - non + * reference values can be null + * + * - reference + * value shouldn't be null + */ + if (propType == null) { + throw new WBEMException( + WBEMException.CIM_ERR_INVALID_PARAMETER, + "Type of property or key cannot be a null! " + + propName + + " in ObjectPath " + + instanceOP.toString() + + " has null type." + ); + } + + if (propValue == null) { + if (propType.getType() == CIMDataType.REFERENCE) { + throw new WBEMException( + WBEMException.CIM_ERR_INVALID_PARAMETER, + "Value of reference cannot be null! " + + propName + + " in ObjectPath " + + instanceOP.toString() + + " has null value." + ); + } + } + + Element keybindingE = createKEYBINDING(doc, instancenameE, propName); + if (propType.getType() == CIMDataType.REFERENCE) { + CIMObjectPath refOP = (CIMObjectPath) propValue; + + createVALUEREFERENCE(doc, keybindingE, refOP); + } else { + String valueStr = propValue == null ? null : propValue.toString(); + String valueTypeStr = getTypeStr(propType); + createKEYVALUE(doc, keybindingE, valueTypeStr, valueStr); + } + } + + parentE.appendChild(instancenameE); + return instancenameE; + } + + /** + * createCLASSPATH + * + * @param pDoc + * @param pParentE + * @param pPath + * @return Element + */ + public static Element createCLASSPATH(Document pDoc, Element pParentE, CIMObjectPath pPath) { + Element classpathE = pDoc.createElement("CLASSPATH"); + + // ebak: NAMESPACEPATH is necessary + createNAMESPACEPATH(pDoc, classpathE, pPath); + createCLASSNAME(pDoc, classpathE, pPath.getObjectName()); + + pParentE.appendChild(classpathE); + return classpathE; + } + + /** + * createPARAMETERS + * + * @param pDoc + * @param pParentE + * @param pParameters + * @throws WBEMException + */ + public static void createPARAMETERS(Document pDoc, Element pParentE, CIMParameter[] pParameters) + throws WBEMException { + if (pParameters == null) return; + for (int i = 0; i < pParameters.length; i++) { + createPARAMETER(pDoc, pParentE, pParameters[i]); + } + } + + /** + * createPARAMETER + * + * @param pDoc + * @param pParentE + * @param pParameter + * @return Element + * @throws WBEMException + */ + public static Element createPARAMETER(Document pDoc, Element pParentE, CIMParameter pParameter) + throws WBEMException { + Element parameterE; + CIMDataType type = pParameter.getDataType(); + int typeCode = type.getType(); + EmbObjBuilder embObjBuilder = new EmbObjBuilder(pDoc, pParameter); + String typeStr = embObjBuilder.getTypeStr(); + if (type.isArray()) { + if (typeCode == CIMDataType.REFERENCE) { + parameterE = pDoc.createElement("PARAMETER.REFARRAY"); + String refclass = type.getRefClassName(); + if (refclass != null && refclass.length() > 0) parameterE.setAttribute( + "REFERENCECLASS", + type.getRefClassName() + ); + } else { + parameterE = pDoc.createElement("PARAMETER.ARRAY"); + parameterE.setAttribute("TYPE", typeStr); + } + } else { + if (typeCode == CIMDataType.REFERENCE) { + parameterE = pDoc.createElement("PARAMETER.REFERENCE"); + String refclass = type.getRefClassName(); + if (refclass != null && refclass.length() > 0) parameterE.setAttribute( + "REFERENCECLASS", + type.getRefClassName() + ); + } else { + parameterE = pDoc.createElement("PARAMETER"); + parameterE.setAttribute("TYPE", typeStr); + } + } + parameterE.setAttribute("NAME", pParameter.getName()); + embObjBuilder.addSign(parameterE); + createQUALIFIERS(pDoc, parameterE, pParameter.getQualifiers()); + + pParentE.appendChild(parameterE); + return parameterE; + } + + /** + * createMETHODS + * + * @param pDoc + * @param pParentE + * @param pMethods + * @param pClassName + * @throws WBEMException + */ + public static void createMETHODS(Document pDoc, Element pParentE, CIMMethod[] pMethods, String pClassName) + throws WBEMException { + for (int i = 0; i < pMethods.length; i++) { + createMETHOD(pDoc, pParentE, pMethods[i], pClassName); + } + } + + /** + * createMETHOD + * + * @param pDoc + * @param pParentE + * @param pMethod + * @param pClassName + * @return Element + * @throws WBEMException + */ + public static Element createMETHOD(Document pDoc, Element pParentE, CIMMethod pMethod, String pClassName) + throws WBEMException { + Element methodE = pDoc.createElement("METHOD"); + + methodE.setAttribute("NAME", pMethod.getName()); + EmbObjBuilder embObjBuilder = new EmbObjBuilder(pDoc, pMethod); + String typeStr = embObjBuilder.getTypeStr(); + methodE.setAttribute("TYPE", typeStr); + String classorigin = pMethod.getOriginClass(); + + if (classorigin != null && classorigin.length() != 0) methodE.setAttribute("CLASSORIGIN", classorigin); + + // 17459 + if (pMethod.isPropagated()) { + methodE.setAttribute("PROPAGATED", MOF.TRUE); + } else { + methodE.setAttribute("PROPAGATED", MOF.FALSE); + } + // ebak: embedded object support + embObjBuilder.addSign(methodE); + + createQUALIFIERS(pDoc, methodE, pMethod.getQualifiers()); + createPARAMETERS(pDoc, methodE, pMethod.getParameters()); + + pParentE.appendChild(methodE); + return methodE; + } + + /* + * private static String elementStr(Element pE) { try { + * ByteArrayOutputStream os = new ByteArrayOutputStream(); + * CimXmlSerializer.serialize(os, pE, true); return new + * String(os.toByteArray()); } catch (RuntimeException e) { throw e; } catch + * (Exception e) { throw new RuntimeException(e); } } + */ + + /** + * createCLASS + * + * @param pDoc + * @param pParentE + * @param pClass + * @return Element + * @throws WBEMException + */ + public static Element createCLASS(Document pDoc, Element pParentE, CIMClass pClass) throws WBEMException { + Element classE = createCLASS(pDoc, pParentE, pClass.getName(), pClass.getSuperClassName()); + + createQUALIFIERS(pDoc, classE, pClass.getQualifiers()); + createPROPERTIES(pDoc, classE, pClass.getProperties()); + createMETHODS(pDoc, classE, pClass.getMethods(), pClass.getName()); + + // parentE.appendChild(classE); + return classE; + } + + /** + * createHOST + * + * @param pDoc + * @param pParentE + * @param pHost + * @return Element + */ + public static Element createHOST(Document pDoc, Element pParentE, String pHost) { + Element hostE = pDoc.createElement("HOST"); + + Text hostT = pDoc.createTextNode(pHost); + hostE.appendChild(hostT); + + pParentE.appendChild(hostE); + return hostE; + } + + /** + * createNAMESPACEPATH + * + * @param pDoc + * @param pParentE + * @param pPath + * @return Element + */ + public static Element createNAMESPACEPATH(Document pDoc, Element pParentE, CIMObjectPath pPath) { + Element namespacepathE = pDoc.createElement("NAMESPACEPATH"); + + String host = pPath.getHost(); + if (host == null) { + // try { + // host = InetAddress.getLocalHost().getHostAddress(); + // } catch (Exception e) { + // throw new CIMXMLBuilderException("Error while resolving + // hostname"); + // } + host = "unassigned-hostname"; + } + createHOST(pDoc, namespacepathE, host); + createLOCALNAMESPACEPATH(pDoc, namespacepathE, pPath); + + pParentE.appendChild(namespacepathE); + return namespacepathE; + } + + /** + * createINSTANCEPATH + * + * @param pDoc + * @param pParentE + * @param pPath + * @return Element + * @throws WBEMException + */ + public static Element createINSTANCEPATH(Document pDoc, Element pParentE, CIMObjectPath pPath) throws WBEMException { + Element instancepathE = pDoc.createElement("INSTANCEPATH"); + + createNAMESPACEPATH(pDoc, instancepathE, pPath); + createINSTANCENAME(pDoc, instancepathE, pPath); + pParentE.appendChild(instancepathE); + return instancepathE; + } + + /** + * createVALUENAMEDINSTANCE + * + * @param pDoc + * @param pParentE + * @param pPath + * @param pInst + * @return Element + * @throws WBEMException + */ + public static Element createVALUENAMEDINSTANCE( + Document pDoc, + Element pParentE, + CIMObjectPath pPath, + CIMInstance pInst + ) + throws WBEMException { + Element valuenamedinstanceE = pDoc.createElement("VALUE.NAMEDINSTANCE"); + createINSTANCENAME(pDoc, valuenamedinstanceE, pPath); + createINSTANCE(pDoc, valuenamedinstanceE, pInst); + + pParentE.appendChild(valuenamedinstanceE); + return valuenamedinstanceE; + } + + /** + * createVALUENAMEDINSTANCE + * + * @param pDoc + * @param pParentE + * @param pInst + * @return Element + * @throws WBEMException + */ + public static Element createVALUENAMEDINSTANCE(Document pDoc, Element pParentE, CIMInstance pInst) + throws WBEMException { + Element valuenamedinstanceE = pDoc.createElement("VALUE.NAMEDINSTANCE"); + createINSTANCENAME(pDoc, valuenamedinstanceE, pInst.getObjectPath()); + createINSTANCE(pDoc, valuenamedinstanceE, pInst); + + pParentE.appendChild(valuenamedinstanceE); + return valuenamedinstanceE; + } + + private static CIMObjectPath changeNameSpace(CIMNamedElementInterface pNamedElement, String pNameSpace) { + CIMObjectPath path = pNamedElement.getObjectPath(); + return new CIMObjectPath( + path.getScheme(), + path.getHost(), + path.getPort(), + pNameSpace, + path.getObjectName(), + path.getKeys() + ); + } + + private static CIMClass changeClassNameSpace(CIMClass pClass, String pNameSpace) { + CIMObjectPath newOp = changeNameSpace(pClass, pNameSpace); + return new CIMClass( + newOp, + pClass.getSuperClassName(), + pClass.getQualifiers(), + pClass.getProperties(), + pClass.getMethods(), + pClass.isAssociation(), + pClass.isKeyed() + ); + } + + private static CIMInstance changeInstanceNameSpace(CIMInstance pInst, String pNameSpace) { + CIMObjectPath newOp = changeNameSpace(pInst, pNameSpace); + return new CIMInstance(newOp, pInst.getProperties()); + } + + /** + * createVALUEOBJECTWITHPATH + * + * @param pDoc + * @param pParentE + * @param pObj + * @param pNameSpace + * @return Element + * @throws WBEMException + */ + public static Element createVALUEOBJECTWITHPATH(Document pDoc, Element pParentE, Object pObj, String pNameSpace) + throws WBEMException { + Element valueobjectwithpathE = pDoc.createElement("VALUE.OBJECTWITHPATH"); + if (pObj instanceof CIMClass) { + CIMClass clazz = (CIMClass) pObj; + + if (clazz.getObjectPath().getNamespace() == null || clazz.getObjectPath().getNamespace().length() == 0) { + // ebak: changing the namespace in clazz's objectPath + // clazz.getObjectPath().setNameSpace(pNameSpace); + clazz = changeClassNameSpace(clazz, pNameSpace); + } + + createCLASSPATH(pDoc, valueobjectwithpathE, clazz.getObjectPath()); + createCLASS(pDoc, valueobjectwithpathE, clazz); + } else if (pObj instanceof CIMInstance) { + CIMInstance inst = (CIMInstance) pObj; + if (inst.getObjectPath().getNamespace() == null || inst.getObjectPath().getNamespace().length() == 0) { + // ebak: changing the namespace ins inst's objectPath + // inst.getObjectPath().setNameSpace(pNameSpace); + inst = changeInstanceNameSpace(inst, pNameSpace); + } + createINSTANCEPATH(pDoc, valueobjectwithpathE, inst.getObjectPath()); + createINSTANCE(pDoc, valueobjectwithpathE, inst); + } + + pParentE.appendChild(valueobjectwithpathE); + return valueobjectwithpathE; + } + + /** + * createVALUEOBJECTWITHLOCALPATH + * + * @param pDoc + * @param pParentE + * @param pObj + * @param pNameSpace + * @return Element + * @throws WBEMException + */ + public static Element createVALUEOBJECTWITHLOCALPATH(Document pDoc, Element pParentE, Object pObj, String pNameSpace) + throws WBEMException { + Element valueobjectwithpathE = pDoc.createElement("VALUE.OBJECTWITHLOCALPATH"); + if (pObj instanceof CIMClass) { + CIMClass clazz = (CIMClass) pObj; + + if (clazz.getObjectPath().getNamespace() == null || clazz.getObjectPath().getNamespace().length() == 0) { + // ebak: changing clazz's objectPath + // clazz.getObjectPath().setNameSpace(pNameSpace); + clazz = changeClassNameSpace(clazz, pNameSpace); + } + createLOCALCLASSPATH(pDoc, valueobjectwithpathE, clazz.getObjectPath()); + createCLASS(pDoc, valueobjectwithpathE, clazz); + } else if (pObj instanceof CIMInstance) { + CIMInstance inst = (CIMInstance) pObj; + if (inst.getObjectPath().getNamespace() == null || inst.getObjectPath().getNamespace().length() == 0) { + // inst.getObjectPath().setNameSpace(pNameSpace); + inst = changeInstanceNameSpace(inst, pNameSpace); + } + createLOCALINSTANCEPATH(pDoc, valueobjectwithpathE, inst.getObjectPath()); + createINSTANCE(pDoc, valueobjectwithpathE, inst); + } + + pParentE.appendChild(valueobjectwithpathE); + return valueobjectwithpathE; + } + + /** + * createIRETURNVALUE_ERROR + * + * @param doc + * @param parentE + * @param error + * @return Element + */ + public static Element createIRETURNVALUE_ERROR(Document doc, Element parentE, CIMError error) { + Element ireturnvalueE = doc.createElement("IRETURNVALUE"); + + parentE.appendChild(ireturnvalueE); + return ireturnvalueE; + } + + /** + * createIRETURNVALUE_GETINSTANCE + * + * @param pDoc + * @param pParentE + * @param pInst + * @return Element + * @throws WBEMException + */ + public static Element createIRETURNVALUE_GETINSTANCE(Document pDoc, Element pParentE, CIMInstance pInst) + throws WBEMException { + Element ireturnvalueE = pDoc.createElement("IRETURNVALUE"); + createINSTANCENAME(pDoc, ireturnvalueE, pInst.getObjectPath()); + + return ireturnvalueE; + } + + /** + * createIRETURNVALUE_ASSOCIATORS_NAMES + * + * @param pDoc + * @param pParentE + * @param pResultSet + * @return Element + * @throws Exception + */ + public static Element createIRETURNVALUE_ASSOCIATORS_NAMES( + Document pDoc, + Element pParentE, + CIMObjectPath[] pResultSet + ) + throws Exception { + Element ireturnvalueE = pDoc.createElement("IRETURNVALUE"); + + if (pResultSet != null) { + for (int i = 0; i < pResultSet.length; i++) { + CIMObjectPath path = pResultSet[i]; + + if (path.getHost() == null || "".equals(path.getHost())) createLOCALOBJECTPATH( + pDoc, + ireturnvalueE, + path + ); else createOBJECTPATH(pDoc, ireturnvalueE, path); + } + } + pParentE.appendChild(ireturnvalueE); + return ireturnvalueE; + } + + /** + * createIRETURNVALUE_ASSOCIATORS + * + * @param pDoc + * @param pParentE + * @param pResultSet + * @param pNameSpace + * @return Element + * @throws Exception + */ + public static Element createIRETURNVALUE_ASSOCIATORS( + Document pDoc, + Element pParentE, + Object[] pResultSet, + String pNameSpace + ) + throws Exception { + Element ireturnvalueE = pDoc.createElement("IRETURNVALUE"); + if (pResultSet != null) { + for (int i = 0; i < pResultSet.length; i++) { + Object obj = pResultSet[i]; + CIMObjectPath op = null; + if (obj instanceof CIMClass) { + op = ((CIMClass) obj).getObjectPath(); + } else if (obj instanceof CIMInstance) { + op = ((CIMInstance) obj).getObjectPath(); + } else { + throw new WBEMException(WBEMException.CIM_ERR_FAILED, "object in result set neither class nor instance!"); + } + if (op.getHost() == null || "".equals(op.getHost())) { + createVALUEOBJECTWITHLOCALPATH(pDoc, ireturnvalueE, obj, pNameSpace); + } else { + createVALUEOBJECTWITHPATH(pDoc, ireturnvalueE, obj, pNameSpace); + } + } + } + pParentE.appendChild(ireturnvalueE); + return ireturnvalueE; + } + + /** + * createIRETURNVALUE_ENUMERATE_INSTANCENAME + * + * @param pDoc + * @param pParentE + * @param pResultSet + * @param pNameSpace + * @return Element + * @throws Exception + */ + public static Element createIRETURNVALUE_ENUMERATE_INSTANCENAME( + Document pDoc, + Element pParentE, + Object[] pResultSet, + String pNameSpace + ) + throws Exception { + Element ireturnvalueE = pDoc.createElement("IRETURNVALUE"); + if (pResultSet != null) { + for (int i = 0; i < pResultSet.length; i++) { + Object obj = pResultSet[i]; + CIMObjectPath op = null; + if (obj instanceof CIMClass) { + op = ((CIMClass) obj).getObjectPath(); + } else if (obj instanceof CIMInstance) { + op = ((CIMInstance) obj).getObjectPath(); + } else { + throw new WBEMException(WBEMException.CIM_ERR_FAILED, "object in result set neither class nor instance!"); + } + if (op.getHost() == null || "".equals(op.getHost())) { + createVALUEOBJECTWITHLOCALPATH(pDoc, ireturnvalueE, obj, pNameSpace); + } else { + createVALUEOBJECTWITHPATH(pDoc, ireturnvalueE, obj, pNameSpace); + } + } + } + pParentE.appendChild(ireturnvalueE); + return ireturnvalueE; + } + + /** + * createIRETURNVALUE + * + * @param pDoc + * @param pParentE + * @param pResultSet + * @return Element + * @throws WBEMException + */ + public static Element createIRETURNVALUE(Document pDoc, Element pParentE, Object[] pResultSet) throws WBEMException { + Element ireturnvalueE = pDoc.createElement("IRETURNVALUE"); + if (pResultSet != null && pResultSet.length > 0) { + Object obj = pResultSet[0]; + if (obj instanceof CIMClass) { + for (int i = 0; i < pResultSet.length; i++) { + CIMClass clazz = (CIMClass) pResultSet[i]; + Element classnameE = pDoc.createElement("CLASSNAME"); + ireturnvalueE.appendChild(classnameE); + if (clazz.getName() != null) classnameE.setAttribute("NAME", clazz.getName()); + } + } else if (obj instanceof CIMInstance) { + for (int i = 0; i < pResultSet.length; i++) { + CIMInstance inst = (CIMInstance) pResultSet[i]; + createVALUENAMEDINSTANCE(pDoc, ireturnvalueE, inst); + } + } + } + pParentE.appendChild(ireturnvalueE); + return ireturnvalueE; + } + + /** + * createIRETURNVALUE_ENUMERATE_CLASSNAME + * + * @param pDoc + * @param pParentE + * @param pResultSet + * @return Element + */ + public static Element createIRETURNVALUE_ENUMERATE_CLASSNAME(Document pDoc, Element pParentE, CIMClass[] pResultSet) { + Element ireturnvalueE = pDoc.createElement("IRETURNVALUE"); + if (pResultSet != null && pResultSet.length > 0) { + for (int i = 0; i < pResultSet.length; i++) { + CIMClass clazz = pResultSet[i]; + + Element classnameE = pDoc.createElement("CLASSNAME"); + ireturnvalueE.appendChild(classnameE); + if (clazz.getName() != null) classnameE.setAttribute("NAME", clazz.getName()); + } + } + pParentE.appendChild(ireturnvalueE); + return ireturnvalueE; + } + + /** + * createIndication_response + * + * @param doc + * @param ID + * @param error + * @return Element + */ + // ebak: [ 1656285 ] IndicationHandler does not accept non-Integer message + // ID + public static Element createIndication_response(Document doc, String ID, CIMError error) { + // xmlBuilder.create XML + Element cimE = createCIM(doc); + Element messageE = createMESSAGE(doc, cimE, ID, "1.0"); + Element simpleexprspE = createSIMPLEEXPRSP(doc, messageE); + Element expmethodresponseE = createEXPMETHODRESPONSE(doc, simpleexprspE, "ExportIndication"); + if (error == null) { + createIRETURNVALUE(doc, expmethodresponseE); + } else { + createERROR(doc, expmethodresponseE, error); + } + // Element + return cimE; + } + + /** + * createIRETURNVALUE_ENUMERATE_INSTANCE + * + * @param pDoc + * @param pParentE + * @param pResultSet + * @return Element + * @throws WBEMException + */ + public static Element createIRETURNVALUE_ENUMERATE_INSTANCE( + Document pDoc, + Element pParentE, + CIMInstance[] pResultSet + ) + throws WBEMException { + Element ireturnvalueE = pDoc.createElement("IRETURNVALUE"); + if (pResultSet != null && pResultSet.length > 0) { + for (int i = 0; i < pResultSet.length; i++) { + createVALUENAMEDINSTANCE(pDoc, ireturnvalueE, pResultSet[i]); + } + } + pParentE.appendChild(ireturnvalueE); + return ireturnvalueE; + } + + /** + * getTypeStr + * + * @param pType + * @return String + */ + public static String getTypeStr(CIMDataType pType) { + if (pType == null) return "string"; + if (pType.getType() == CIMDataType.REFERENCE) return MOF.REFERENCE; + return MOF.dataType(pType); + } + + /** + * getOpTypeStr + * + * @param pType + * @return String + */ + public static String getOpTypeStr(CIMDataType pType) { + return getTypeStr(pType); + } + + private static final Pattern NAMESPACE_SPLIT_PATTERN = Pattern.compile("/+"); + + /** + * createLOCALNAMESPACEPATH + * + * @param pDoc + * @param pParentE + * @param pName + * @return Element + */ + public static Element createLOCALNAMESPACEPATH(Document pDoc, Element pParentE, CIMObjectPath pName) { + if (pName == null) return null; + // TODO: name(ObjectPath) should not be null, should an exception be + // thrown? + // This assumes that the NameSpace does not consist exclusively of + // empties like "////" + Element localnamespacepathE = pDoc.createElement("LOCALNAMESPACEPATH"); + String nameSpace = pName.getNamespace(); + if (nameSpace != null) { + String[] nsA = NAMESPACE_SPLIT_PATTERN.split(nameSpace); + for (int i = 0; i < nsA.length; i++) if (nsA[i] != null && nsA[i].length() > 0) createNAMESPACE( + pDoc, + localnamespacepathE, + nsA[i] + ); + } + pParentE.appendChild(localnamespacepathE); + + return localnamespacepathE; + } + + /** + * createSIMPLEEXPREQ + * + * @param pDoc + * @return Element + */ + public static Element createSIMPLEEXPREQ(Document pDoc) { + // + Element e = pDoc.createElement("SIMPLEEXPREQ"); + return e; + } + + /** + * createEXPMETHODCALL + * + * @param pDoc + * @param pParentE + * @param pName + * @return Element + */ + public static Element createEXPMETHODCALL(Document pDoc, Element pParentE, String pName) { + // + // + Element e = pDoc.createElement("EXPMETHODCALL"); + if (pName != null) { + e.setAttribute("NAME", pName); + } + pParentE.appendChild(e); + return e; + } + + /** + * createEXPPARAMVALUE + * + * @param pDoc + * @param pParentE + * @param pName + * @return Element + */ + public static Element createEXPPARAMVALUE(Document pDoc, Element pParentE, String pName) { + // + // + Element e = pDoc.createElement("EXPPARAMVALUE"); + if (pName != null) { + e.setAttribute("NAME", pName); + } + pParentE.appendChild(e); + return e; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CIMXMLParseException.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CIMXMLParseException.java similarity index 64% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CIMXMLParseException.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CIMXMLParseException.java index 94e3e02..fdd4238 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CIMXMLParseException.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CIMXMLParseException.java @@ -1,74 +1,71 @@ -/* - CIMXMLParseException.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; - -/** - * Class CIMXMLParseException is used by the CIM-XML DOM parser. - * - */ -public class CIMXMLParseException extends IOException { - - private static final long serialVersionUID = 1237082621297618586L; - - /** - * Ctor. - */ - public CIMXMLParseException() { - super(); - } - - /** - * Ctor. - * - * @param reason - */ - public CIMXMLParseException(String reason) { - super(reason); - } -} +/* + CIMXMLParseException.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; + +/** + * Class CIMXMLParseException is used by the CIM-XML DOM parser. + * + */ +public class CIMXMLParseException extends IOException { + private static final long serialVersionUID = 1237082621297618586L; + + /** + * Ctor. + */ + public CIMXMLParseException() { + super(); + } + + /** + * Ctor. + * + * @param reason + */ + public CIMXMLParseException(String reason) { + super(reason); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CIMXMLParserImpl.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CIMXMLParserImpl.java similarity index 79% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CIMXMLParserImpl.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CIMXMLParserImpl.java index 712c74c..aa3cd0e 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CIMXMLParserImpl.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CIMXMLParserImpl.java @@ -1,3884 +1,3981 @@ -/* - CIMXMLParserImpl.java - - (C) Copyright IBM Corp. 2005, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1464860 2006-05-15 lupusalex No default value for VALUETYPE assumed - * 1535756 2006-08-07 lupusalex Make code warning free - * 1547910 2006-09-05 ebak parseIMETHODCALL() CIMObjectPath parsing problem - * 1547908 2006-09-05 ebak parseKEYBINDING() creates incorrect reference type - * 1545915 2006-09-05 ebak Wrong parsing of IMETHODCALL request - * 1660756 2007-03-02 ebak Embedded object support - * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus - * 1669961 2006-04-16 lupusalex CIMTypedElement.getType() =>getDataType() - * 1712656 2007-05-04 ebak Correct type identification for SVC CIMOM - * 1714878 2007-05-08 ebak Empty string property values are parsed as nulls - * 1737141 2007-06-18 ebak Sync up with JSR48 evolution - * 1769504 2007-08-15 ebak Type identification for VALUETYPE="numeric" - * 1783288 2007-09-10 ebak CIMClass.isAssociation() not working for retrieved classes. - * 1820763 2007-10-29 ebak Supporting the EmbeddedInstance qualifier - * 1827728 2007-11-20 ebak rework: embeddedInstances: attribute EmbeddedObject not set - * 1848607 2007-12-11 ebak Strict EmbeddedObject types - * 1944875 2008-05-29 blaschke-oss Indications with embedded objects are not accepted - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2210455 2008-10-30 blaschke-oss Enhance javadoc, fix potential null pointers - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2714989 2009-03-26 blaschke-oss Code cleanup from redundant null check et al - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2823494 2009-08-03 rgummada Change Boolean constructor to static - * 2860081 2009-09-17 raman_arora Pull Enumeration Feature (DOM Parser) - * 2957387 2010-03-03 blaschke-oss EmbededObject XML attribute must not be all uppercases - * 3023143 2010-07-01 blaschke-oss CIMXMLParserImpl uses # constructor instead of valueOf - * 3027479 2010-07-09 blaschke-oss Dead store to local variable - * 3027615 2010-07-12 blaschke-oss Use CLASS_ARRAY_T instead of new CIMDataType(CLASS,0) - * 3293248 2011-05-03 blaschke-oss Support for CIM_ERROR instances within ERROR - * 3297028 2011-05-03 blaschke-oss Instances contain CIMClassProperty with DOM parser - * 3411944 2011-09-20 blaschke-oss createJavaObject exception with hex uint - * 3513353 2012-03-30 blaschke-oss TCK: CIMDataType arrays must have length >= 1 - * 3513349 2012-03-31 blaschke-oss TCK: CIMDataType must not accept null string - * 3466280 2012-04-23 blaschke-oss get instance failure for CIM_IndicationSubscription - * 3521119 2012-04-24 blaschke-oss JSR48 1.0.0: remove CIMObjectPath 2/3/4-parm ctors - * 3526679 2012-05-14 blaschke-oss DOM parser ignores ERROR node CODE - * 3572993 2012-10-01 blaschke-oss parseDouble("2.2250738585072012e-308") DoS vulnerability - * 3598613 2013-01-11 blaschke-oss different data type in cim instance and cim object path - * 2616 2013-02-23 blaschke-oss Add new API WBEMClientSBLIM.sendIndication() - * 2636 2013-05-08 blaschke-oss Nested embedded instances cause CIMXMLParseException - * 2640 2013-05-11 blaschke-oss Multiple CDATA parsing broken in DOM parser - * 2668 2013-09-24 blaschke-oss Potential null pointer exception in parseCIM - * 2669 2013-09-24 blaschke-oss Potential null pointer exception in parseMESSAGE - * 2670 2013-09-25 blaschke-oss NAME attribute not required by DOM parser - * 2671 2013-09-25 blaschke-oss Potential null pointer exception in parseERROR - * 2675 2013-09-27 blaschke-oss CIMXMLParseException messages should contain element name - * 2676 2013-09-27 blaschke-oss parseMULTI(EXP)REQ looking for wrong child elements - * 2678 2013-09-30 blaschke-oss parseMULTI___ allows one SIMPLE___ child element - * 2679 2013-10-01 blaschke-oss parseIMETHODCALL requires one IPARAMVALUE child element - * 2680 2013-10-02 blaschke-oss IPARAMVALUE parsing broken on DOM/SAX - * 2681 2013-10-02 blaschke-oss parseQUALIFIERDECLARATION does not require TYPE attribute - * 2683 2013-10-07 blaschke-oss KEYVALUE VALUETYPE optional, "string" default - * 2684 2013-10-07 blaschke-oss parseEXPMETHODRESPONSE has several issues - * 2685 2013-10-07 blaschke-oss Element.getAttribute returns empty string if no attribute - * 2686 2013-10-10 blaschke-oss parseEXPPARAMVALUE allows 2+ children, prohibits 0 - * 2688 2013-10-10 blaschke-oss parseMETHODCALL looks for CIMName attribute instead of NAME - * 2537 2013-10-17 blaschke-oss Add new data types for PARAMVALUE - * 2691 2013-10-18 blaschke-oss RETURNVALUE should not require PARAMTYPE attribute - * 2694 2013-10-25 blaschke-oss NAME attribute not required by DOM parser (part 2) - * 2695 2013-10-25 blaschke-oss parseMETHODCALL allows LOCALCLASSPATH and LOCALINSTANCEPATH - * 2696 2013-10-29 blaschke-oss parseIRETURNVALUE ignores VALUE and VALUE.ARRAY - * 2699 2013-11-05 blaschke-oss parseQUALIFIER does not require TYPE attribute - * 2700 2013-11-07 blaschke-oss PROPERTY does not require TYPE attribute - * 2701 2013-11-07 blaschke-oss PROPERTY.ARRAY does not require TYPE attribute - * 2702 2013-11-07 blaschke-oss Bad PROPERTY.ARRAY ARRAYSIZE generates NumberFormatException - * 2703 2013-11-08 blaschke-oss MethodNode should not require TYPE attribute - * 2704 2013-11-11 blaschke-oss PARAMETER does not require TYPE attribute - * 2705 2013-11-11 blaschke-oss PARAMETER.ARRAY does not require TYPE attribute - * 2706 2013-11-11 blaschke-oss Bad PARAMETER.REFARRAY ARRAYSIZE generates NumberFormatException - * 2707 2013-11-12 blaschke-oss INSTANCENAME ignores KEYVALUE and VALUE.REFERENCE children - * 2710 2013-11-13 blaschke-oss parseVALUEOBJECTWITH(LOCAL)PATH ignores (LOCAL)CLASSPATH child - * 2711 2013-11-13 blaschke-oss LOCALNAMESPACEPATH allows 0 NAMESPACE children - * 2713 2013-11-22 blaschke-oss Enforce loose validation of CIM-XML documents - * 2715 2013-11-26 blaschke-oss Add VALUE.NULL support - * 2538 2013-11-28 blaschke-oss CR14: Support new CORRELATOR element - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.StringReader; -import java.math.BigInteger; -import java.util.Comparator; -import java.util.HashMap; -import java.util.TreeMap; -import java.util.Vector; -import java.util.logging.Level; - -import org.sentrysoftware.wbem.javax.cim.CIMArgument; -import org.sentrysoftware.wbem.javax.cim.CIMClass; -import org.sentrysoftware.wbem.javax.cim.CIMClassProperty; -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMDateTime; -import org.sentrysoftware.wbem.javax.cim.CIMDateTimeAbsolute; -import org.sentrysoftware.wbem.javax.cim.CIMDateTimeInterval; -import org.sentrysoftware.wbem.javax.cim.CIMFlavor; -import org.sentrysoftware.wbem.javax.cim.CIMInstance; -import org.sentrysoftware.wbem.javax.cim.CIMMethod; -import org.sentrysoftware.wbem.javax.cim.CIMNamedElementInterface; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import org.sentrysoftware.wbem.javax.cim.CIMParameter; -import org.sentrysoftware.wbem.javax.cim.CIMProperty; -import org.sentrysoftware.wbem.javax.cim.CIMQualifier; -import org.sentrysoftware.wbem.javax.cim.CIMQualifierType; -import org.sentrysoftware.wbem.javax.cim.CIMScope; -import org.sentrysoftware.wbem.javax.cim.UnsignedInteger16; -import org.sentrysoftware.wbem.javax.cim.UnsignedInteger32; -import org.sentrysoftware.wbem.javax.cim.UnsignedInteger64; -import org.sentrysoftware.wbem.javax.cim.UnsignedInteger8; -import org.sentrysoftware.wbem.javax.wbem.WBEMException; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.CIMHelper; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.CIMQualifiedElementInterfaceImpl; -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.MOF; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.Util; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConfiguration; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.XMLHostStr; -import org.w3c.dom.Attr; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.Text; -import org.xml.sax.InputSource; - -/** - * Class CIMXMLParserImpl is the main class of CIM-XML DOM parser. - * - */ -public class CIMXMLParserImpl { - - /* - * ebak: local object path - should be used by parseLOCALCLASSPATH(), - * parseLOCALINSTANCEPATH(), parseCLASSNAME(), parseINSTANCENAME(), - * parseCLASS() and parseINSTANCE() - */ - private static LocalPathBuilder cLocalPathBuilder = new LocalPathBuilder(null); - - /** - * setLocalObjectPath - * - * @param pLocalOp - * - empty fields of parsed objectpaths will be substituted by - * fields coming from this parameter - */ - public static void setLocalObjectPath(CIMObjectPath pLocalOp) { - cLocalPathBuilder = new LocalPathBuilder(pLocalOp); - } - - /* - * / local object path - */ - - /** - * parseCIM - * - * @param pCimE - * @return CIMMessage - * @throws CIMXMLParseException - */ - public static CIMMessage parseCIM(Element pCimE) throws CIMXMLParseException { - // - // - Attr cim_cimversionA = (Attr) searchAttribute(pCimE, "CIMVERSION"); - if (cim_cimversionA == null) throw new CIMXMLParseException( - "CIM element missing CIMVERSION attribute!"); - String cimversion = cim_cimversionA.getNodeValue(); - - Attr cim_dtdversionA = (Attr) searchAttribute(pCimE, "DTDVERSION"); - if (cim_dtdversionA == null) throw new CIMXMLParseException( - "CIM element missing DTDVERSION attribute!"); - String dtdversion = cim_dtdversionA.getNodeValue(); - - // MESSAGE - Element messageA[] = searchNodes(pCimE, "MESSAGE", 0, 1, false); - if (messageA != null) { - CIMMessage message = parseMESSAGE(cimversion, dtdversion, messageA[0]); - message.setCIMVersion(cimversion); - message.setDTDVersion(dtdversion); - return message; - } - - // DECLARATION - if (searchNodes(pCimE, "DECLARATION", 0, 1, false) != null) throw new CIMXMLParseException( - "DECLARATION element not supported!"); - - throw new CIMXMLParseException("CIM element missing required child element!"); - } - - // //////////////////////////////////////////////////////////////////////////////////////// - // Value Elements - // //////////////////////////////////////////////////////////////////////////////////////// - - /** - * parseVALUE - supports the non-standard TYPE attribute - * - * @param pValueE - * @return TypedValue, type is null if no TYPE attribute was found, the - * value is always String, the caller method have to convert it. - * @throws CIMXMLParseException - */ - public static TypedValue parseVALUE(Element pValueE) throws CIMXMLParseException { - // - - String typeStr = attribute(pValueE, "TYPE"); - CIMDataType type = typeStr == null ? null : parseScalarTypeStr(typeStr); - // ebak: empty VALUE element is parsed as empty String - NodeList list = pValueE.getChildNodes(); - StringBuilder valueStr = new StringBuilder(); - for (int i = 0; i < list.getLength(); i++) { - Text t = (Text) list.item(i); - if (t != null) { - String nodeValue = t.getNodeValue(); - if (nodeValue != null) valueStr.append(nodeValue); - } - } - return new TypedValue(type, valueStr.toString()); - } - - /** - * parseVALUEARRAY - supports the non-standard TYPE attribute - * - * @param pValueArrayE - * @return TypedValue, type is null if no TYPE attribute was found, the - * value is always String[], the caller method have to convert it. - * @throws CIMXMLParseException - */ - public static TypedValue parseVALUEARRAY(Element pValueArrayE) throws CIMXMLParseException { - // - String typeStr = attribute(pValueArrayE, "TYPE"); - CIMDataType type = typeStr == null ? null : parseArrayTypeStr(typeStr); - - // Process node list here, order of VALUE/VALUE.NULL IS important - NodeList nl = pValueArrayE.getChildNodes(); - if (nl == null || nl.getLength() == 0) return new TypedValue(type, new String[0]); - Vector resStringV = new Vector(); - for (int i = 0; i < nl.getLength(); i++) { - Node n = nl.item(i); - if (n instanceof Text && "".equalsIgnoreCase(n.getNodeValue().trim())) continue; - String name = n.getNodeName(); - if (name.equals("VALUE")) { - resStringV.add((String) parseVALUE((Element) n).getValue()); - } else if (name.equals("VALUE.NULL")) { - resStringV.add(null); - } else if (NODENAME_HASH.containsKey(name)) { throw new CIMXMLParseException( - "VALUE.ARRAY element contains invalid child element " + name + "!"); } - } - return new TypedValue(type, resStringV.toArray(new String[0])); - } - - /** - * parseVALUEREFERENCE - * - * @param pValuereferenceE - * @return CIMObjectPath - * @throws CIMXMLParseException - */ - public static CIMObjectPath parseVALUEREFERENCE(Element pValuereferenceE) - throws CIMXMLParseException { - // - - // CLASSPATH - Element classpathA[] = searchNodes(pValuereferenceE, "CLASSPATH", 0, 1, false); - if (classpathA != null) { - CIMObjectPath op = parseCLASSPATH(classpathA[0]); - return op; - } - - // LOCALCLASSPATH - Element localclasspathA[] = searchNodes(pValuereferenceE, "LOCALCLASSPATH", 0, 1, false); - if (localclasspathA != null) { - CIMObjectPath op = parseLOCALCLASSPATH(localclasspathA[0]); - return op; - } - - // CLASSNAME - Element classnameA[] = searchNodes(pValuereferenceE, "CLASSNAME", 0, 1, false); - if (classnameA != null) { - CIMObjectPath op = parseCLASSNAME(classnameA[0]); - if (op != null && op.getNamespace() != null) { - // LocalPathBuilder includes default namespace in CLASSNAME - // elements, needs to be stripped - op = new CIMObjectPath(op.getScheme(), op.getHost(), op.getPort(), null, op - .getObjectName(), op.getKeys(), op.getXmlSchemaName()); - } - return op; - } - - // INSTANCEPATH - Element instancepathA[] = searchNodes(pValuereferenceE, "INSTANCEPATH", 0, 1, false); - if (instancepathA != null) { - CIMObjectPath op = parseINSTANCEPATH(instancepathA[0]); - return op; - } - - // LOCALINSTANCEPATH - Element localinstancepathA[] = searchNodes(pValuereferenceE, "LOCALINSTANCEPATH", 0, 1, - false); - if (localinstancepathA != null) { - CIMObjectPath op = parseLOCALINSTANCEPATH(localinstancepathA[0]); - return op; - } - - // INSTANCENAME - Element instancenameA[] = searchNodes(pValuereferenceE, "INSTANCENAME", 0, 1, false); - if (instancenameA != null) { - CIMObjectPath op = parseINSTANCENAME(instancenameA[0]); - if (op != null && op.getNamespace() != null) { - // LocalPathBuilder includes default namespace in INSTANCENAME - // elements, needs to be stripped - op = new CIMObjectPath(op.getScheme(), op.getHost(), op.getPort(), null, op - .getObjectName(), op.getKeys(), op.getXmlSchemaName()); - } - return op; - } - - throw new CIMXMLParseException("VALUE.REFERENCE element missing required child element!"); - } - - /** - * parseVALUEREFARRAY - * - * @param pValueRefArrayE - * @return CIMObjectPath[] - * @throws CIMXMLParseException - */ - public static CIMObjectPath[] parseVALUEREFARRAY(Element pValueRefArrayE) - throws CIMXMLParseException { - // - - // Process node list here, order of VALUE.REFERENCE/VALUE.NULL IS - // important - NodeList nl = pValueRefArrayE.getChildNodes(); - if (nl == null || nl.getLength() == 0) return new CIMObjectPath[0]; - Vector resObjectPathV = new Vector(); - for (int i = 0; i < nl.getLength(); i++) { - Node n = nl.item(i); - if (n instanceof Text && "".equalsIgnoreCase(n.getNodeValue().trim())) continue; - String name = n.getNodeName(); - if (name.equals("VALUE.REFERENCE")) { - resObjectPathV.add(parseVALUEREFERENCE((Element) n)); - } else if (name.equals("VALUE.NULL")) { - resObjectPathV.add(null); - } else if (NODENAME_HASH.containsKey(name)) { throw new CIMXMLParseException( - "VALUE.REFARRAY element contains invalid child element " + name + "!"); } - } - return resObjectPathV.toArray(new CIMObjectPath[0]); - } - - /** - * parseVALUEOBJECT - * - * @param pValueObjectE - * @return CIMNamedElementInterface (CIMClass|CIMInstance) - * @throws CIMXMLParseException - */ - public static CIMNamedElementInterface parseVALUEOBJECT(Element pValueObjectE) - throws CIMXMLParseException { - // - - // CLASS - Element classA[] = searchNodes(pValueObjectE, "CLASS", 0, 1, false); - if (classA != null) { - CIMClass obj = parseCLASS(classA[0]); - return obj; - } - - // INSTANCE - Element instanceA[] = searchNodes(pValueObjectE, "INSTANCE", 0, 1, false); - if (instanceA != null) { - CIMInstance obj = parseINSTANCE(instanceA[0]); - return obj; - } - - throw new CIMXMLParseException("VALUE.OBJECT element missing required child element!"); - } - - private static final String nodesVALUENAMEDINSTANCE[] = { "INSTANCENAME", "INSTANCE" }; - - /** - * parseVALUENAMEDINSTANCE - * - * @param pValueNamedInstanceE - * @return CIMInstance - * @throws CIMXMLParseException - */ - public static CIMInstance parseVALUENAMEDINSTANCE(Element pValueNamedInstanceE) - throws CIMXMLParseException { - // - - // INSTANCENAME - Element instancenameA[] = searchNodes(pValueNamedInstanceE, "INSTANCENAME", 1, 1, true); - if (instancenameA == null) { throw new CIMXMLParseException( - "VALUE.NAMEDINSTANCE element missing INSTANCENAME child element!"); } - CIMObjectPath op = parseINSTANCENAME(instancenameA[0]); - - // INSTANCE - Element instanceA[] = searchNodes(pValueNamedInstanceE, "INSTANCE", 1, 1, true); - if (instanceA == null) { throw new CIMXMLParseException( - "VALUE.NAMEDINSTANCE element missing INSTANCE child element!"); } - CIMInstance inst = parseINSTANCE(instanceA[0], op); // BB mod - checkOtherNodes(pValueNamedInstanceE, nodesVALUENAMEDINSTANCE); - return inst; - } - - private static final String nodesVALUEINSTANCEWITHPATH[] = { "INSTANCEPATH", "INSTANCE" }; - - /** - * parseVALUEINSTANCEWITHPATH - * - * @param pValueNamedInstanceE - * @return CIMInstance - * @throws CIMXMLParseException - */ - public static CIMInstance parseVALUEINSTANCEWITHPATH(Element pValueNamedInstanceE) - throws CIMXMLParseException { - // - - // INSTANCEPATH - Element instancepathA[] = searchNodes(pValueNamedInstanceE, "INSTANCEPATH", 1, 1, true); - if (instancepathA == null) { throw new CIMXMLParseException( - "VALUE.INSTANCEWITHPATH element missing INSTANCEPATH child element!"); } - CIMObjectPath op = parseINSTANCEPATH(instancepathA[0]); - - // INSTANCE - Element instanceA[] = searchNodes(pValueNamedInstanceE, "INSTANCE", 1, 1, true); - if (instanceA == null) { throw new CIMXMLParseException( - "VALUE.INSTANCEWITHPATH element missing INSTANCE child element!"); } - CIMInstance inst = parseINSTANCE(instanceA[0], op); // BB mod - checkOtherNodes(pValueNamedInstanceE, nodesVALUEINSTANCEWITHPATH); - return inst; - } - - private static final String nodesVALUENAMEDOBJECTi[] = { "INSTANCENAME", "INSTANCE" }; - - /** - * parseVALUENAMEDOBJECT - * - * @param pValueNamedObjectE - * @return CIMNamedElementInterface - * @throws CIMXMLParseException - */ - public static CIMNamedElementInterface parseVALUENAMEDOBJECT(Element pValueNamedObjectE) - throws CIMXMLParseException { - // - - // CLASS - Element classA[] = searchNodes(pValueNamedObjectE, "CLASS", 0, 1, false); - if (classA != null) { - CIMClass obj = parseCLASS(classA[0]); - // checkOtherNodes(pValueNamedObjectE, nodesVALUENAMEDOBJECTc); - return obj; - } - - // INSTANCENAME - Element instancenameA[] = searchNodes(pValueNamedObjectE, "INSTANCENAME", 0, 1, true); - if (instancenameA != null) { - CIMObjectPath op = parseINSTANCENAME(instancenameA[0]); - - // INSTANCE - Element instanceA[] = searchNodes(pValueNamedObjectE, "INSTANCE", 0, 1, true); - if (instanceA == null) { throw new CIMXMLParseException( - "VALUE.NAMEDOBJECT element missing INSTANCE child element!"); } - CIMInstance inst = parseINSTANCE(instanceA[0], op); // BB mod - checkOtherNodes(pValueNamedObjectE, nodesVALUENAMEDOBJECTi); - return inst; - } - - throw new CIMXMLParseException("VALUE.NAMEDOBJECT element missing required child element!"); - } - - private static final String nodesVALUEOBJECTWITHPATHcls[] = { "CLASSPATH", "CLASS" }; - - private static final String nodesVALUEOBJECTWITHPATHins[] = { "INSTANCEPATH", "INSTANCE" }; - - /** - * parseVALUEOBJECTWITHPATH - * - * @param pValueObjectWithPathE - * @return CIMNamedElementInterface - * @throws CIMXMLParseException - */ - public static CIMNamedElementInterface parseVALUEOBJECTWITHPATH(Element pValueObjectWithPathE) - throws CIMXMLParseException { - // - - // CLASSPATH - Element classpathA[] = searchNodes(pValueObjectWithPathE, "CLASSPATH", 0, 1, true); - if (classpathA != null) { - CIMObjectPath op = parseCLASSPATH(classpathA[0]); - - // CLASS - Element classA[] = searchNodes(pValueObjectWithPathE, "CLASS", 0, 1, true); - if (classA == null) { throw new CIMXMLParseException( - "VALUE.OBJECTWITHPATH element missing CLASS child element!"); } - - CIMClass obj = parseCLASS(classA[0], op); - checkOtherNodes(pValueObjectWithPathE, nodesVALUEOBJECTWITHPATHcls); - return obj; - } - - // INSTANCEPATH - Element instancepathA[] = searchNodes(pValueObjectWithPathE, "INSTANCEPATH", 0, 1, true); - if (instancepathA != null) { - CIMObjectPath op = parseINSTANCEPATH(instancepathA[0]); - - // INSTANCE - Element instanceA[] = searchNodes(pValueObjectWithPathE, "INSTANCE", 0, 1, true); - if (instanceA == null) { throw new CIMXMLParseException( - "VALUE.OBJECTWITHPATH element missing INSTANCE child element!"); } - CIMInstance inst = parseINSTANCE(instanceA[0], op); // BB mod - checkOtherNodes(pValueObjectWithPathE, nodesVALUEOBJECTWITHPATHins); - return inst; - } - - throw new CIMXMLParseException( - "VALUE.OBJECTWITHPATH element missing required child element!"); - } - - private static final String nodesVALUEOBJECTWITHLOCALPATHcls[] = { "LOCALCLASSPATH", "CLASS" }; - - private static final String nodesVALUEOBJECTWITHLOCALPATHins[] = { "LOCALINSTANCEPATH", - "INSTANCE" }; - - /** - * parseVALUEOBJECTWITHLOCALPATH - * - * @param pValueObjectWithLocalPathE - * @return CIMNamedElementInterface - * @throws CIMXMLParseException - */ - public static CIMNamedElementInterface parseVALUEOBJECTWITHLOCALPATH( - Element pValueObjectWithLocalPathE) throws CIMXMLParseException { - // - - // LOCALCLASSPATH - Element localclasspathA[] = searchNodes(pValueObjectWithLocalPathE, "LOCALCLASSPATH", 0, 1, - true); - if (localclasspathA != null) { - CIMObjectPath op = parseLOCALCLASSPATH(localclasspathA[0]); - - // CLASS - Element classA[] = searchNodes(pValueObjectWithLocalPathE, "CLASS", 0, 1, true); - if (classA == null) { throw new CIMXMLParseException( - "VALUE.OBJECTWITHLOCALPATH element missing CLASS child element!"); } - - CIMClass obj = parseCLASS(classA[0], op); - checkOtherNodes(pValueObjectWithLocalPathE, nodesVALUEOBJECTWITHLOCALPATHcls); - return obj; - } - - // LOCALINSTANCEPATH - Element localinstancepathA[] = searchNodes(pValueObjectWithLocalPathE, "LOCALINSTANCEPATH", - 0, 1, true); - if (localinstancepathA != null) { - CIMObjectPath op = parseLOCALINSTANCEPATH(localinstancepathA[0]); - - // INSTANCE - Element instanceA[] = searchNodes(pValueObjectWithLocalPathE, "INSTANCE", 0, 1, true); - if (instanceA == null) { throw new CIMXMLParseException( - "VALUE.OBJECTWITHLOCALPATH element missing INSTANCE child element!"); } - CIMInstance inst = parseINSTANCE(instanceA[0], op); // BB mod - checkOtherNodes(pValueObjectWithLocalPathE, nodesVALUEOBJECTWITHLOCALPATHins); - return inst; - } - - throw new CIMXMLParseException( - "VALUE.OBJECTWITHLOCALPATH element missing required child element!"); - } - - // //////////////////////////////////////////////////////////////////////////////////////// - // Naming and Location elements - // //////////////////////////////////////////////////////////////////////////////////////// - - private static final String nodesNAMESPACEPATH[] = { "HOST", "LOCALNAMESPACEPATH" }; - - /** - * parseNAMESPACEPATH - * - * @param pNameSpacePathE - * @return CIMObjectPath - * @throws CIMXMLParseException - */ - public static CIMObjectPath parseNAMESPACEPATH(Element pNameSpacePathE) - throws CIMXMLParseException { - // - // HOST - Element hostA[] = searchNodes(pNameSpacePathE, "HOST", 1, 1, true); - if (hostA == null) { throw new CIMXMLParseException( - "NAMESPACEPATH element missing HOST child element!"); } - XMLHostStr xmlHostStr = new XMLHostStr(parseHOST(hostA[0])); - // LOCALNAMESPACE - Element localnamespacepathA[] = searchNodes(pNameSpacePathE, "LOCALNAMESPACEPATH", 1, 1, - true); - if (localnamespacepathA == null) { throw new CIMXMLParseException( - "NAMESPACEPATH element missing LOCALNAMESPACEPATH child element!"); } - String nameSpace = parseLOCALNAMESPACEPATH(localnamespacepathA[0]); - /* - * CIMObjectPath( String scheme, String host, String port, String - * namespace, String objectName, CIMProperty[] keys ) - */ - checkOtherNodes(pNameSpacePathE, nodesNAMESPACEPATH); - return new CIMObjectPath(xmlHostStr.getProtocol(), xmlHostStr.getHost(), xmlHostStr - .getPort(), nameSpace, null, null); - } - - /** - * parseLOCALNAMESPACEPATH - * - * @param pLocalNameSpaceE - * @return String - * @throws CIMXMLParseException - */ - public static String parseLOCALNAMESPACEPATH(Element pLocalNameSpaceE) - throws CIMXMLParseException { - // - - Element[] nameSpaceElementA = searchNodes(pLocalNameSpaceE, "NAMESPACE", 1, - Integer.MAX_VALUE, false); - if (nameSpaceElementA == null) { - if (WBEMConfiguration.getGlobalConfiguration().allowEmptyLocalNameSpacePath() - && cLocalPathBuilder != null) return cLocalPathBuilder.getBasePath() - .getNamespace(); - throw new CIMXMLParseException( - "LOCALNAMESPACEPATH element missing NAMESPACE child element!"); - } - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < nameSpaceElementA.length; i++) { - Element namespaceE = nameSpaceElementA[i]; - String s = parseNAMESPACE(namespaceE); - if (i > 0) sb.append("/" + s); - else sb.append(s); - } - return sb.toString(); - } - - /** - * parseHOST - * - * @param pHostE - * @return String - */ - public static String parseHOST(Element pHostE) { - // - - Text valueT = (Text) searchFirstChild(pHostE); - String host = valueT.getNodeValue(); - return host; - } - - private static final String nodesNAMESPACE[] = {}; - - /** - * parseNAMESPACE - * - * @param pNameSpaceE - * @return String - * @throws CIMXMLParseException - */ - public static String parseNAMESPACE(Element pNameSpaceE) throws CIMXMLParseException { - // - // - - Attr namespace_nameA = (Attr) searchAttribute(pNameSpaceE, "NAME"); - if (namespace_nameA == null) throw new CIMXMLParseException( - "NAMESPACE element missing NAME attribute!"); - String n = namespace_nameA.getValue(); - checkOtherNodes(pNameSpaceE, nodesNAMESPACE); - return n; - } - - private static final String nodesCLASSPATH[] = { "NAMESPACEPATH", "CLASSNAME" }; - - /** - * parseCLASSPATH - * - * @param pClassPathE - * @return CIMObjectPath - * @throws CIMXMLParseException - */ - public static CIMObjectPath parseCLASSPATH(Element pClassPathE) throws CIMXMLParseException { - // - - // NAMESPACEPATH - Element namespacepathA[] = searchNodes(pClassPathE, "NAMESPACEPATH", 1, 1, true); - if (namespacepathA == null) { throw new CIMXMLParseException( - "CLASSPATH element missing NAMESPACEPATH child element!"); } - CIMObjectPath nsPath = parseNAMESPACEPATH(namespacepathA[0]); - // CLASSNAME - Element classnameA[] = searchNodes(pClassPathE, "CLASSNAME", 1, 1, true); - if (classnameA == null) { throw new CIMXMLParseException( - "CLASSPATH element missing CLASSNAME child element!"); } - String className = parseClassName(classnameA[0]); - /* - * CIMObjectPath( String scheme, String host, String port, String - * namespace, String objectName, CIMProperty[] keys ) - */ - checkOtherNodes(pClassPathE, nodesCLASSPATH); - return new CIMObjectPath(nsPath.getScheme(), nsPath.getHost(), nsPath.getPort(), nsPath - .getNamespace(), className, null); - } - - private static final String nodesLOCALCLASSPATH[] = { "LOCALNAMESPACEPATH", "CLASSNAME" }; - - /** - * parseLOCALCLASSPATH - * - * @param pClassPathE - * @return CIMObjectPath - * @throws CIMXMLParseException - */ - public static CIMObjectPath parseLOCALCLASSPATH(Element pClassPathE) - throws CIMXMLParseException { - // - - // NAMESPACEPATH - Element localnamespacepathA[] = searchNodes(pClassPathE, "LOCALNAMESPACEPATH", 1, 1, true); - if (localnamespacepathA == null) { throw new CIMXMLParseException( - "LOCALCLASSPATH element missing LOCALNAMESPACEPATH child element!"); } - String nameSpace = parseLOCALNAMESPACEPATH(localnamespacepathA[0]); - - // CLASSNAME - Element classnameA[] = searchNodes(pClassPathE, "CLASSNAME", 1, 1, true); - if (classnameA == null) { throw new CIMXMLParseException( - "LOCALCLASSPATH element missing CLASSNAME child element!"); } - CIMObjectPath op = parseCLASSNAME(classnameA[0]); - checkOtherNodes(pClassPathE, nodesLOCALCLASSPATH); - return cLocalPathBuilder.build(op.getObjectName(), nameSpace); - } - - private static final String nodesCLASSNAME[] = {}; - - /** - * parseClassName - * - * @param pClassNameE - * @return String - * @throws CIMXMLParseException - */ - public static String parseClassName(Element pClassNameE) throws CIMXMLParseException { - // - // - Attr classname_nameA = (Attr) searchAttribute(pClassNameE, "NAME"); - if (classname_nameA == null) throw new CIMXMLParseException( - "CLASSNAME element missing NAME attribute!"); - checkOtherNodes(pClassNameE, nodesCLASSNAME); - return classname_nameA.getNodeValue(); - } - - /** - * parseCLASSNAME - * - * @param pClassNameE - * @return CIMObjectPath - * @throws CIMXMLParseException - */ - public static CIMObjectPath parseCLASSNAME(Element pClassNameE) throws CIMXMLParseException { - return cLocalPathBuilder.build(parseClassName(pClassNameE), null); - } - - private static final String nodesINSTANCEPATH[] = { "NAMESPACEPATH", "INSTANCENAME" }; - - /** - * parseINSTANCEPATH - * - * @param pInstancePathE - * @return CIMObjectPath - * @throws CIMXMLParseException - */ - public static CIMObjectPath parseINSTANCEPATH(Element pInstancePathE) - throws CIMXMLParseException { - // - - // NAMESPACEPATH - Element namespacepathA[] = searchNodes(pInstancePathE, "NAMESPACEPATH", 1, 1, true); - if (namespacepathA == null) { throw new CIMXMLParseException( - "INSTANCEPATH element missing NAMESPACEPATH child element!"); } - CIMObjectPath nsPath = parseNAMESPACEPATH(namespacepathA[0]); - // INSTANCENAME - Element instancenameA[] = searchNodes(pInstancePathE, "INSTANCENAME", 1, 1, true); - if (instancenameA == null) { throw new CIMXMLParseException( - "INSTANCEPATH element missing INSTANCENAME child element!"); } - CIMObjectPath op = parseINSTANCENAME(instancenameA[0]); - // ebak: change host and namespace - checkOtherNodes(pInstancePathE, nodesINSTANCEPATH); - return new CIMObjectPath(nsPath.getScheme(), nsPath.getHost(), nsPath.getPort(), nsPath - .getNamespace(), op.getObjectName(), op.getKeys()); - } - - private static final String nodesLOCALINSTANCEPATH[] = { "LOCALNAMESPACEPATH", "INSTANCENAME" }; - - /** - * parseLOCALINSTANCEPATH - * - * @param pLocalInstancePathE - * @return CIMObjectPath - * @throws CIMXMLParseException - */ - public static CIMObjectPath parseLOCALINSTANCEPATH(Element pLocalInstancePathE) - throws CIMXMLParseException { - // - - // LOCALNAMESPACEPATH - Element localnamespacepathA[] = searchNodes(pLocalInstancePathE, "LOCALNAMESPACEPATH", 1, - 1, true); - if (localnamespacepathA == null) { throw new CIMXMLParseException( - "LOCALINSTANCEPATH element missing LOCALNAMESPACEPATH child element!"); } - String nameSpace = parseLOCALNAMESPACEPATH(localnamespacepathA[0]); - - // INSTANCENAME - Element instancenameA[] = searchNodes(pLocalInstancePathE, "INSTANCENAME", 1, 1, true); - if (instancenameA == null) { throw new CIMXMLParseException( - "LOCALINSTANCEPATH element missing INSTANCENAME child element!"); } - CIMObjectPath op = parseINSTANCENAME(instancenameA[0]); - /* - * CIMObjectPath(String objectName, String namespace, CIMProperty[] - * keys) - */ - checkOtherNodes(pLocalInstancePathE, nodesLOCALINSTANCEPATH); - return cLocalPathBuilder.build(op.getObjectName(), nameSpace, op.getKeys()); - } - - private static final String nodesINSTANCENAME[] = { "KEYBINDING", "KEYVALUE", "VALUE.REFERENCE" }; - - /** - * parseINSTANCENAME - * - * @param pInstanceNameE - * @return CIMObjectPath - * @throws CIMXMLParseException - */ - public static CIMObjectPath parseINSTANCENAME(Element pInstanceNameE) - throws CIMXMLParseException { - // - // - Attr instance_classnameA = (Attr) searchAttribute(pInstanceNameE, "CLASSNAME"); - if (instance_classnameA == null) throw new CIMXMLParseException( - "INSTANCENAME element missing CLASSNAME attribute!"); - String opClassName = instance_classnameA.getNodeValue(); - - // KEYBINDING - Element[] keyBindingElementA = searchNodes(pInstanceNameE, "KEYBINDING", 0, - Integer.MAX_VALUE, false); - if (keyBindingElementA != null) { - CIMProperty[] keys = new CIMProperty[keyBindingElementA.length]; - for (int i = 0; i < keyBindingElementA.length; i++) { - Element keybindingE = keyBindingElementA[i]; - keys[i] = parseKEYBINDING(keybindingE); - } - return cLocalPathBuilder.build(opClassName, null, keys); - } - - // KEYVALUE - Element keyvalueA[] = searchNodes(pInstanceNameE, "KEYVALUE", 0, 1, false); - if (keyvalueA != null) { - CIMProperty[] keys = new CIMProperty[1]; - TypedValue propTypedVal = parseKEYVALUE(keyvalueA[0]); - keys[0] = new CIMProperty("", propTypedVal.getType(), propTypedVal.getValue(), - true, false, null); - return cLocalPathBuilder.build(opClassName, null, keys); - } - - // VALUE.REFERENCE - Element valuereferenceA[] = searchNodes(pInstanceNameE, "VALUE.REFERENCE", 0, 1, false); - if (valuereferenceA != null) { - CIMProperty[] keys = new CIMProperty[1]; - CIMObjectPath op = parseVALUEREFERENCE(valuereferenceA[0]); - keys[0] = new CIMProperty("", new CIMDataType(op.getObjectName()), op, - true, false, null); - return cLocalPathBuilder.build(opClassName, null, keys); - } - - checkOtherNodes(pInstanceNameE, nodesINSTANCENAME); - - return new CIMObjectPath(null, null, null, null, opClassName, null); - } - - /** - * parseOBJECTPATH - * - * @param pObjectPathE - * @return CIMObjectPath - * @throws CIMXMLParseException - */ - public static CIMObjectPath parseOBJECTPATH(Element pObjectPathE) throws CIMXMLParseException { - // - - // INSTANCEPATH - Element instancepathA[] = searchNodes(pObjectPathE, "INSTANCEPATH", 0, 1, false); - if (instancepathA != null) { - CIMObjectPath op = parseINSTANCEPATH(instancepathA[0]); - return op; - } - - // CLASSPATH - Element classpathA[] = searchNodes(pObjectPathE, "CLASSPATH", 0, 1, false); - if (classpathA != null) { - CIMObjectPath op = parseCLASSPATH(classpathA[0]); - return op; - } - - throw new CIMXMLParseException("OBJECTPATH element missing required child element!"); - } - - /** - * parseKEYBINDING - * - * @param pKeyBindingE - * @return CIMProperty - * @throws CIMXMLParseException - */ - public static CIMProperty parseKEYBINDING(Element pKeyBindingE) throws CIMXMLParseException { - // - // - - Attr keybinding_nameA = (Attr) searchAttribute(pKeyBindingE, "NAME"); - if (keybinding_nameA == null) throw new CIMXMLParseException( - "KEYBINDING element missing NAME attribute!"); - String propName = keybinding_nameA.getValue(); - - // KEYVALUE - Element keyvalueA[] = searchNodes(pKeyBindingE, "KEYVALUE", 0, 1, false); - if (keyvalueA != null) { - TypedValue propTypedVal = parseKEYVALUE(keyvalueA[0]); - return new CIMProperty(propName, propTypedVal.getType(), propTypedVal - .getValue(), true, false, null); - } - - // VALUE.REFERENCE - Element valuereferenceA[] = searchNodes(pKeyBindingE, "VALUE.REFERENCE", 0, 1, false); - if (valuereferenceA != null) { - CIMObjectPath op = parseVALUEREFERENCE(valuereferenceA[0]); - return new CIMProperty(propName, new CIMDataType(op.getObjectName()), - op, true, false, null); - } - - throw new CIMXMLParseException("KEYBINDING element missing required child element!"); - } - - private static final TreeMap TYPESTR_MAP = new TreeMap( - new Comparator() { - - public int compare(Object pO1, Object pO2) { - return ((String) pO1).compareToIgnoreCase((String) pO2); - } - - }); - - static { - TYPESTR_MAP.put(MOF.DT_UINT8, CIMDataType.UINT8_T); - TYPESTR_MAP.put(MOF.DT_UINT16, CIMDataType.UINT16_T); - TYPESTR_MAP.put(MOF.DT_UINT32, CIMDataType.UINT32_T); - TYPESTR_MAP.put(MOF.DT_UINT64, CIMDataType.UINT64_T); - TYPESTR_MAP.put(MOF.DT_SINT8, CIMDataType.SINT8_T); - TYPESTR_MAP.put(MOF.DT_SINT16, CIMDataType.SINT16_T); - TYPESTR_MAP.put(MOF.DT_SINT32, CIMDataType.SINT32_T); - TYPESTR_MAP.put(MOF.DT_SINT64, CIMDataType.SINT64_T); - TYPESTR_MAP.put(MOF.DT_REAL32, CIMDataType.REAL32_T); - TYPESTR_MAP.put(MOF.DT_REAL64, CIMDataType.REAL64_T); - TYPESTR_MAP.put(MOF.DT_CHAR16, CIMDataType.CHAR16_T); - TYPESTR_MAP.put(MOF.DT_STR, CIMDataType.STRING_T); - TYPESTR_MAP.put(MOF.DT_BOOL, CIMDataType.BOOLEAN_T); - TYPESTR_MAP.put(MOF.DT_DATETIME, CIMDataType.DATETIME_T); - // FIXME: ebak: What to do with those types which are not specified by - // MOF's BNF? - TYPESTR_MAP.put(MOF.INVALID, CIMDataType.INVALID_T); - // FIXME: ebak: What is the string representation of OBJECT? - TYPESTR_MAP.put("object", CIMDataType.OBJECT_T); - TYPESTR_MAP.put(MOF.CLASS, CIMDataType.CLASS_T); - TYPESTR_MAP.put(MOF.REFERENCE, new CIMDataType("")); - } - - /** - * parseScalarTypeStr - * - * @param pTypeStr - * @return CIMDataType - * @throws CIMXMLParseException - */ - public static CIMDataType parseScalarTypeStr(String pTypeStr) throws CIMXMLParseException { - return parseTypeStr(pTypeStr, false); - } - - /** - * parseArrayTypeStr - * - * @param pTypeStr - * @return CIMDataType - * @throws CIMXMLParseException - */ - public static CIMDataType parseArrayTypeStr(String pTypeStr) throws CIMXMLParseException { - return parseTypeStr(pTypeStr, true); - } - - /** - * parseTypeStr - * - * @param pTypeStr - * @param pArray - * @return CIMDataType - * @throws CIMXMLParseException - */ - public static CIMDataType parseTypeStr(String pTypeStr, boolean pArray) - throws CIMXMLParseException { - if (pTypeStr == null) return pArray ? CIMDataType.STRING_ARRAY_T : CIMDataType.STRING_T; - CIMDataType type = TYPESTR_MAP.get(pTypeStr); - if (type == null) throw new CIMXMLParseException("Unknown TYPE string:" + pTypeStr); - if (pArray) { - if (type.getType() == CIMDataType.REFERENCE) return new CIMDataType(type - .getRefClassName(), 0); - return CIMHelper.UnboundedArrayDataType(type.getType()); - } - return type; - } - - /** - * parseKEYVALUE - * - * @param pKeyValueE - * @return TypedValue - * @throws CIMXMLParseException - */ - public static TypedValue parseKEYVALUE(Element pKeyValueE) throws CIMXMLParseException { - /* - * - */ - // ebak: if TYPE attribute is included there is no need to deal with - // VALUETYPE attribute - String typeStr = attribute(pKeyValueE, "TYPE"); - - Text valueT = (Text) searchFirstChild(pKeyValueE); - String valueStr = valueT == null ? null : valueT.getNodeValue(); - - if (typeStr == null) { - String valueTypeStr = attribute(pKeyValueE, "VALUETYPE"); - if (valueTypeStr == null) valueTypeStr = "string"; - ValueTypeHandler vtHandler = new ValueTypeHandler(valueTypeStr, valueStr); - return new TypedValue(vtHandler.getType(), vtHandler.getValue()); - } - Object value = valueStr == null ? "" : createJavaObject(typeStr, valueStr); - return new TypedValue(parseScalarTypeStr(typeStr), value); - } - - /** - * Class ValueTypeHandler determines the value and type of a KEYVALUE XML - * element, when the VALUETYPE attribute is provided instead of the exact - * TYPE attribute. There is a very similar code section in the PULL and SAX - * parser, but that section wasn't made common since in ideal case the DOM - * parser will be removed. - */ - private static class ValueTypeHandler { - - private CIMDataType iType; - - private Object iValue; - - /** - * - * Ctor. - * - * @param pValueTypeStr - * @param pValueStr - * @throws CIMXMLParseException - */ - public ValueTypeHandler(String pValueTypeStr, String pValueStr) throws CIMXMLParseException { - - if (pValueTypeStr == null) throw new CIMXMLParseException( - "KEYVALUE element missing VALUETYPE attribute!"); - - if (pValueTypeStr.equals("numeric")) { - if (!setUInt64(pValueStr) && !setSInt64(pValueStr) && !setReal64(pValueStr)) throw new CIMXMLParseException( - "Unparseable \"number\" value: " + pValueStr + " !"); - } else if (pValueTypeStr.equals(MOF.DT_STR)) { - if (!setDTAbsolute(pValueStr) && !setDTInterval(pValueStr)) { - this.iValue = pValueStr; - this.iType = CIMDataType.STRING_T; - } - } else if (pValueTypeStr.equals(MOF.DT_BOOL)) { - if (!setBoolean(pValueStr)) throw new CIMXMLParseException( - "Unparseable \"boolean\" value: " + pValueStr + " !"); - } else { - throw new CIMXMLParseException("KEYVALUE element's VALUETYPE attribute must be " - + MOF.DT_STR + ", " + MOF.DT_BOOL + " or numeric! " + pValueStr - + " is not allowed!"); - } - } - - /** - * - * getType - * - * @return CIMDataType - */ - public CIMDataType getType() { - return this.iType; - } - - /** - * - * getValue - * - * @return Object - */ - public Object getValue() { - return this.iValue; - } - - private boolean setUInt64(String pValue) { - try { - this.iValue = new UnsignedInteger64(pValue); - } catch (NumberFormatException e) { - return false; - } - this.iType = CIMDataType.UINT64_T; - return true; - } - - private boolean setSInt64(String pValue) { - try { - this.iValue = new Long(pValue); - } catch (NumberFormatException e) { - return false; - } - this.iType = CIMDataType.SINT64_T; - return true; - } - - private boolean setReal64(String pValue) { - try { - if (WBEMConfiguration.getGlobalConfiguration().verifyJavaLangDoubleStrings()) { - if (Util.isBadDoubleString(pValue)) return false; - } - this.iValue = new Double(pValue); - } catch (NumberFormatException e) { - return false; - } - this.iType = CIMDataType.REAL64_T; - return true; - } - - private boolean setBoolean(String pValue) { - this.iValue = Boolean.valueOf(pValue); - this.iType = CIMDataType.BOOLEAN_T; - return true; - } - - private boolean setDTAbsolute(String pValue) { - try { - this.iValue = new CIMDateTimeAbsolute(pValue); - } catch (IllegalArgumentException e) { - return false; - } - this.iType = CIMDataType.DATETIME_T; - return true; - } - - private boolean setDTInterval(String pValue) { - try { - this.iValue = new CIMDateTimeInterval(pValue); - } catch (IllegalArgumentException e) { - return false; - } - this.iType = CIMDataType.DATETIME_T; - return true; - } - } - - // //////////////////////////////////////////////////////////////////////////////////////// - // Object Definition Elements - // //////////////////////////////////////////////////////////////////////////////////////// - - private static String attribute(Element pElement, String pName) { - String attrib = pElement.getAttribute(pName); - if (attrib == null || attrib.length() == 0) return null; - return attrib; - } - - private static final String[] nodesCLASS = { "QUALIFIER", "PROPERTY", "PROPERTY.ARRAY", - "PROPERTY.REFERENCE", "METHOD" }; - - /** - * parseCLASS - * - * @param pClassE - * @return CIMClass - * @throws CIMXMLParseException - */ - public static CIMClass parseCLASS(Element pClassE) throws CIMXMLParseException { - return parseCLASS(pClassE, null); - } - - /** - * parseCLASS - * - * @param pClassE - * @param pObjectPath - * @return CIMClass - * @throws CIMXMLParseException - */ - public static CIMClass parseCLASS(Element pClassE, CIMObjectPath pObjectPath) - throws CIMXMLParseException { - // - // - - Attr class_nameA = (Attr) searchAttribute(pClassE, "NAME"); - if (class_nameA == null) throw new CIMXMLParseException( - "CLASS element missing NAME attribute!"); - String name = class_nameA.getNodeValue(); - - // Attr superclass_nameA = (Attr)searchAttribute(classE, "SUPERCLASS"); - // String supername = superclass_nameA.getNodeValue(); - - String superClass = attribute(pClassE, "SUPERCLASS"); - - // QUALIFIER - CIMQualifier[] qualis = parseQUALIFIERS(pClassE); - - // PROPERTY - CIMClassProperty[] props = parseCLASSPROPERTIES(pClassE); - - // METHOD - Element[] methodElementA = searchNodes(pClassE, "METHOD", 0, Integer.MAX_VALUE, true); - CIMMethod[] methods; - if (methodElementA != null) { - methods = new CIMMethod[methodElementA.length]; - for (int i = 0; i < methodElementA.length; i++) { - Element methodE = methodElementA[i]; - methods[i] = parseMETHOD(methodE); - } - } else { - methods = null; - } - - /* - * CIMClass( String name, String superclass, CIMQualifier[] qualifiers, - * CIMClassProperty[] props, CIMMethod[] methods ) - * - * return new CIMClass( name, superClass, qualis, props, methods ); - * - * This constructor can provide localPath info. CIMClass( CIMObjectPath - * path, String superclass, CIMQualifier[] qualifiers, - * CIMClassProperty[] props, CIMMethod[] pMethods, boolean - * pIsAssociation, boolean pIsKeyed ) - */ - checkOtherNodes(pClassE, nodesCLASS); - - return new CIMClass( - pObjectPath == null ? cLocalPathBuilder.build(name, null) : pObjectPath, - superClass, qualis, props, methods, hasAssocQuali(qualis), hasKeyProp(props)); - } - - private static boolean hasAssocQuali(CIMQualifier[] pQualis) { - if (pQualis == null) return false; - for (int i = 0; i < pQualis.length; i++) { - CIMQualifier quali = pQualis[i]; - if ("ASSOCIATION".equalsIgnoreCase(quali.getName()) - && Boolean.TRUE.equals(quali.getValue())) return true; - } - return false; - } - - private static boolean hasKeyProp(CIMProperty[] pProps) { - if (pProps == null) return false; - for (int i = 0; i < pProps.length; i++) - if (pProps[i].isKey()) return true; - return false; - } - - private static CIMParameter[] parseParameters(Element pMethodE) throws CIMXMLParseException { - // PARAMETER - Vector> paramV = new Vector>(); - Element[] paramElementA = searchNodes(pMethodE, "PARAMETER"); - if (paramElementA != null) { - for (int i = 0; i < paramElementA.length; i++) { - Element parameterE = paramElementA[i]; - CIMParameter p = parsePARAMETER(parameterE); - paramV.add(p); - } - } - - Element[] paramRefElementA = searchNodes(pMethodE, "PARAMETER.REFERENCE"); - if (paramRefElementA != null) { - for (int i = 0; i < paramRefElementA.length; i++) { - Element parameterE = paramRefElementA[i]; - CIMParameter p = parsePARAMETERREFERENCE(parameterE); - paramV.add(p); - } - } - - Element[] paramArrayElementA = searchNodes(pMethodE, "PARAMETER.ARRAY"); - if (paramArrayElementA != null) { - for (int i = 0; i < paramArrayElementA.length; i++) { - Element parameterE = paramArrayElementA[i]; - CIMParameter p = parsePARAMETERARRAY(parameterE); - paramV.add(p); - } - } - - Element[] paramRefArrayElementA = searchNodes(pMethodE, "PARAMETER.REFARRAY"); - if (paramRefArrayElementA != null) { - for (int i = 0; i < paramRefArrayElementA.length; i++) { - Element parameterE = paramRefArrayElementA[i]; - CIMParameter p = parsePARAMETERREFARRAY(parameterE); - paramV.add(p); - } - } - - return paramV.toArray(new CIMParameter[0]); - } - - private static final String nodesMETHOD[] = { "QUALIFIER", "PARAMETER", "PARAMETER.REFERENCE", - "PARAMETER.ARRAY", "PARAMETER.REFARRAY" }; - - /** - * parseMETHOD - * - * @param pMethodE - * @return CIMMethod - * @throws CIMXMLParseException - */ - public static CIMMethod parseMETHOD(Element pMethodE) throws CIMXMLParseException { - // - // - - String name = attribute(pMethodE, "NAME"); - if (name == null) throw new CIMXMLParseException("METHOD element missing NAME attribute!"); - EmbObjHandler embObjHandler = new EmbObjHandler(pMethodE); - CIMDataType type = embObjHandler.getType(); - if (type != null && type.isArray()) throw new CIMXMLParseException( - "Method's type cannot be Array!"); - String classOrigin = attribute(pMethodE, "CLASSORIGIN"); - String propagatedStr = pMethodE.getAttribute("PROPAGATED"); - boolean propagated = "true".equalsIgnoreCase(propagatedStr); - - checkOtherNodes(pMethodE, nodesMETHOD); - - // PARAMETERS - CIMParameter[] params = parseParameters(pMethodE); - // CIMMethod(String name, CIMDataType type, CIMQualifier[] qualifiers, - // CIMParameter[] parameters, boolean propagated, String originClass) - return new CIMMethod(name, type, embObjHandler.getQualifiers(), params, propagated, - classOrigin); - } - - private static final String nodesPARAMETER[] = { "QUALIFIER" }; - - /** - * parsePARAMETER - * - * @param pParamE - * @return CIMParameter - * @throws CIMXMLParseException - */ - public static CIMParameter parsePARAMETER(Element pParamE) throws CIMXMLParseException { - String name = attribute(pParamE, "NAME"); - if (name == null) throw new CIMXMLParseException( - "PARAMETER element missing NAME attribute!"); - if (attribute(pParamE, "TYPE") == null) throw new CIMXMLParseException( - "PARAMETER element missing TYPE attribute!"); - checkOtherNodes(pParamE, nodesPARAMETER); - EmbObjHandler iEmbObjHandler = new EmbObjHandler(pParamE); - // CIMParameter(String name, CIMDataType type, CIMQualifier[] - // qualifiers) - return new CIMParameter(name, iEmbObjHandler.getType(), iEmbObjHandler - .getQualifiers()); - } - - private static final String nodesPARAMETERREFERENCE[] = { "QUALIFIER" }; - - /** - * parsePARAMETERREFERENCE - * - * @param pParamE - * @return CIMParameter - * @throws CIMXMLParseException - */ - public static CIMParameter parsePARAMETERREFERENCE(Element pParamE) - throws CIMXMLParseException { - String name = attribute(pParamE, "NAME"); - if (name == null) throw new CIMXMLParseException( - "PARAMETER.REFERENCE element missing NAME attribute!"); - String referenceClass = attribute(pParamE, "REFERENCECLASS"); - CIMDataType type = new CIMDataType(referenceClass != null ? referenceClass : ""); - checkOtherNodes(pParamE, nodesPARAMETERREFERENCE); - // QUALIFIER - CIMQualifier[] qualis = parseQUALIFIERS(pParamE); - return new CIMParameter(name, type, qualis); - } - - private static final String nodesPARAMETERARRAY[] = { "QUALIFIER" }; - - /** - * parsePARAMETERARRAY - * - * @param pParamE - * @return CIMParameter - * @throws CIMXMLParseException - */ - public static CIMParameter parsePARAMETERARRAY(Element pParamE) - throws CIMXMLParseException { - String name = attribute(pParamE, "NAME"); - if (name == null) throw new CIMXMLParseException( - "PARAMETER.ARRAY element missing NAME attribute!"); - if (attribute(pParamE, "TYPE") == null) throw new CIMXMLParseException( - "PARAMETER.ARRAY element missing TYPE attribute!"); - String arraySizeStr = pParamE.getAttribute("ARRAYSIZE"); - try { - if (arraySizeStr.length() > 0) Integer.parseInt(arraySizeStr); - } catch (NumberFormatException e) { - throw new CIMXMLParseException(arraySizeStr - + " is not a valid ARRAYSIZE attribute for PARAMETER.ARRAY!"); - } - checkOtherNodes(pParamE, nodesPARAMETERARRAY); - EmbObjHandler iEmbObjHandler = new EmbObjHandler(pParamE); - return new CIMParameter(name, iEmbObjHandler.getArrayType(), iEmbObjHandler - .getQualifiers()); - } - - private static final String nodesPARAMETERREFARRAY[] = { "QUALIFIER" }; - - /** - * parsePARAMETERREFARRAY - * - * @param pParamE - * @return CIMParameter - * @throws CIMXMLParseException - */ - public static CIMParameter parsePARAMETERREFARRAY(Element pParamE) - throws CIMXMLParseException { - String name = attribute(pParamE, "NAME"); - if (name == null) throw new CIMXMLParseException( - "PARAMETER.REFARRAY element missing NAME attribute!"); - - String referenceClass = attribute(pParamE, "REFERENCECLASS"); - - int arraySize = 0; // unlimited - String arraySizeStr = pParamE.getAttribute("ARRAYSIZE"); - try { - if (arraySizeStr.length() > 0) arraySize = Integer.parseInt(arraySizeStr); - } catch (NumberFormatException e) { - throw new CIMXMLParseException(arraySizeStr - + " is not a valid ARRAYSIZE attribute for PARAMETER.REFARRAY!"); - } - - CIMDataType type = new CIMDataType((referenceClass != null) ? referenceClass : "", - arraySize); - - // QUALIFIER - checkOtherNodes(pParamE, nodesPARAMETERREFARRAY); - CIMQualifier[] qualis = parseQUALIFIERS(pParamE); - return new CIMParameter(name, type, qualis); - } - - /** - * parseINSTANCE - * - * @param pInstanceE - * @return CIMInstance - * @throws CIMXMLParseException - */ - public static CIMInstance parseINSTANCE(Element pInstanceE) throws CIMXMLParseException { - return parseINSTANCE(pInstanceE, null); - } - - private static final String[] nodesINSTANCE = { "QUALIFIER", "PROPERTY", "PROPERTY.ARRAY", - "PROPERTY.REFERENCE" }; - - /** - * parseINSTANCE - * - * @param pInstanceE - * @param pObjPath - * @return CIMInstance - * @throws CIMXMLParseException - */ - public static CIMInstance parseINSTANCE(Element pInstanceE, CIMObjectPath pObjPath) - throws CIMXMLParseException { - // - // - - // BB mod CIMInstance inst = new CIMInstance(); - String className = attribute(pInstanceE, "CLASSNAME"); - if (className == null) throw new CIMXMLParseException( - "INSTANCE element missing CLASSNAME attribute!"); - // QUALIFIER - // FIXME: in JSR48 CIMInstance doesn't have qualifiers - // CIMQualifier[] qualis = parseQUALIFIERS(pInstanceE); - // PROPERTY - CIMProperty[] props = parsePROPERTIES(pInstanceE); - - checkOtherNodes(pInstanceE, nodesINSTANCE); - - if (pObjPath == null) return new CIMInstance(cLocalPathBuilder.build(className, null), - props); - if (WBEMConfiguration.getGlobalConfiguration().synchronizeNumericKeyDataTypes()) return CIMHelper - .CIMInstanceWithSynchonizedNumericKeyDataTypes(pObjPath, props); - return new CIMInstance(pObjPath, props); - } - - /** - * ebak: Access to enclosing method parseQUALIFIERS(Element) from the type - * CIMXMLParserImpl is emulated by a synthetic accessor method. Increasing - * its visibility will improve your performance - * - * @param pElement - * @return CIMQualifier[] - * @throws CIMXMLParseException - */ - public static CIMQualifier[] parseQUALIFIERS(Element pElement) throws CIMXMLParseException { - Element[] qualiElementA = searchNodes(pElement, "QUALIFIER"); - CIMQualifier[] qualis; - if (qualiElementA != null) { - qualis = new CIMQualifier[qualiElementA.length]; - for (int i = 0; i < qualiElementA.length; i++) { - Element qualifierE = qualiElementA[i]; - qualis[i] = parseQUALIFIER(qualifierE); - } - } else qualis = null; - return qualis; - } - - /** - *
      -	 *  ENTITY % QualifierFlavor "
      -	 *  OVERRIDABLE    (true|false)  'true'
      -	 *  TOSUBCLASS     (true|false)  'true'
      -	 *  TOINSTANCE     (true|false)  'false'
      -	 *  TRANSLATABLE   (true|false)  'false'"
      -	 * 
      - * - * @param pElement - * @return int - CIMFlavor bit mixture - */ - private static int parseFLAVORS(Element pElement) { - int flavors = 0; - if (!getBoolAttribute(pElement, "OVERRIDABLE", true)) flavors |= CIMFlavor.DISABLEOVERRIDE; - if (!getBoolAttribute(pElement, "TOSUBCLASS", true)) flavors |= CIMFlavor.RESTRICTED; - if (getBoolAttribute(pElement, "TRANSLATABLE", false)) flavors |= CIMFlavor.TRANSLATE; - return flavors; - } - - private static TypedValue parseSingleValue(Element pElement) throws CIMXMLParseException { - return parseSingleValue(pElement, VALUE | VALUEA); - } - - private static final int VALUE = 1, VALUEA = 2, VALUEREF = 4, VALUEREFA = 8; - - private static TypedValue parseSingleValue(Element pElement, int pMask) - throws CIMXMLParseException { - boolean foundSingleValue = false; - String typeStr = attribute(pElement, "TYPE"); - // ebak: there was an ESS fix in the base implementation - if (typeStr == null) typeStr = attribute(pElement, "PARAMTYPE"); - CIMDataType type = null; - Object value = null; - if ((pMask & VALUE) > 0) { - Element valueE = (Element) searchFirstNode(pElement, "VALUE"); - if (valueE != null) { - TypedValue tVal = parseVALUE(valueE); - String valueStr = (String) tVal.getValue(); - type = typeStr == null ? tVal.getType() : parseScalarTypeStr(typeStr); - value = createJavaObject(type == null ? null : type.toString(), valueStr); - foundSingleValue = true; - } - } - if (!foundSingleValue && (pMask & VALUEREF) > 0) { - // VALUE.REFERENCE - Element valuereferenceE = (Element) searchFirstNode(pElement, "VALUE.REFERENCE"); - if (valuereferenceE != null) { - CIMObjectPath op = parseVALUEREFERENCE(valuereferenceE); - value = op; - type = new CIMDataType(op.getObjectName()); - foundSingleValue = true; - } - } - if (!foundSingleValue && (pMask & VALUEA) > 0) { - // VALUE.ARRAY - Element valuearrayE = (Element) searchFirstNode(pElement, "VALUE.ARRAY"); - if (valuearrayE != null) { - TypedValue tValA = parseVALUEARRAY(valuearrayE); - type = typeStr == null ? tValA.getType() : parseArrayTypeStr(typeStr); - String[] valStrA = (String[]) tValA.getValue(); - if (valStrA != null) { - Object[] values = new Object[valStrA.length]; - for (int i = 0; i < valStrA.length; i++) { - values[i] = createJavaObject(type == null ? null : type.toString(), - valStrA[i]); - } - value = values; - } - foundSingleValue = true; - } - } - if (!foundSingleValue && (pMask & VALUEREFA) > 0) { - // VALUE.REFARRAY - Element valueRefArrayE = (Element) searchFirstNode(pElement, "VALUE.REFARRAY"); - if (valueRefArrayE != null) { - type = new CIMDataType("", 0); - CIMObjectPath[] opA = parseVALUEREFARRAY(valueRefArrayE); - value = opA; - foundSingleValue = true; - } - } - if (!foundSingleValue) { - if (value instanceof Object[]) type = CIMDataType.STRING_ARRAY_T; - else if (value != null) type = CIMDataType.STRING_T; - else type = CIMDataType.STRING_T; // /throw new - // CIMXMLParseException("null - // type with null value!"); - } - return new TypedValue(type, value); - } - - private static final String nodesQUALIFIER[] = { "VALUE", "VALUE.ARRAY" }; - - /** - * parseQUALIFIER - * - * @param pQualifierE - * @return CIMQualifier - * @throws CIMXMLParseException - */ - public static CIMQualifier parseQUALIFIER(Element pQualifierE) throws CIMXMLParseException { - // - // - - String name = attribute(pQualifierE, "NAME"); - if (name == null) throw new CIMXMLParseException( - "QUALIFIER element missing NAME attribute!"); - String typeStr = attribute(pQualifierE, "TYPE"); - if (typeStr == null && !hasTypeAttrsInNodes(pQualifierE)) throw new CIMXMLParseException( - "QUALIFIER element missing TYPE attribute!"); - boolean propagated = MOF.TRUE.equalsIgnoreCase(pQualifierE.getAttribute("PROPAGATED")); - // FLAVORS - int flavors = parseFLAVORS(pQualifierE); - // VALUE - if (searchNodes(pQualifierE, "VALUE", 0, 1, false) != null - || searchNodes(pQualifierE, "VALUE.ARRAY", 0, 1, false) != null) { - TypedValue typedValue = parseSingleValue(pQualifierE); - if (typedValue.getType() == null) throw new CIMXMLParseException( - "Qualifier's type is null!"); - // CIMQualifier(String pName, CIMDataType pType, Object pValue, int - // pFlavor) - return new CIMQualifier(name, typedValue.getType(), typedValue.getValue(), - flavors, propagated); - } - checkOtherNodes(pQualifierE, nodesQUALIFIER); - - CIMDataType type = parseScalarTypeStr(typeStr); - return new CIMQualifier(name, type != null ? type : CIMDataType.STRING_T, null, - flavors, propagated); - } - - /** - * parseQUALIFIERDECLARATION - * - * @param pQualifierTypeE - * @return CIMQualifierType - * @throws CIMXMLParseException - */ - public static CIMQualifierType parseQUALIFIERDECLARATION(Element pQualifierTypeE) - throws CIMXMLParseException { - // - // - - String name = attribute(pQualifierTypeE, "NAME"); - if (name == null) throw new CIMXMLParseException( - "QUALIFIER.DECLARATION element missing NAME attribute!"); - String type = attribute(pQualifierTypeE, "TYPE"); - if (type == null && !hasTypeAttrsInNodes(pQualifierTypeE)) throw new CIMXMLParseException( - "QUALIFIER.DECLARATION element missing TYPE attribute!"); - - // SCOPES - // ebak: there should be only 1 scope node - Element scopeElementA[] = searchNodes(pQualifierTypeE, "SCOPE", 0, 1, true); - int scopes = scopeElementA == null ? 0 : parseSCOPES(scopeElementA[0]); - // QUALIFIERS - // CIMQualifier[] qualis = parseQUALIFIERS(pQualifierTypeE); - - CIMDataType qdType; - Object qdValue; - - String nodes[] = null; - - if (searchNodes(pQualifierTypeE, "VALUE", 0, 1, true) != null) { - nodes = new String[] { "SCOPE", "VALUE" }; - } else if (searchNodes(pQualifierTypeE, "VALUE.ARRAY", 0, 1, true) != null) { - nodes = new String[] { "SCOPE", "VALUE.ARRAY" }; - } - - // VALUE - if (nodes != null) { - TypedValue typedValue = parseSingleValue(pQualifierTypeE); - qdType = typedValue.getType(); - qdValue = typedValue.getValue(); - boolean isArray = hasTrueAttribute(pQualifierTypeE, "ISARRAY"); - String arraySizeStr = attribute(pQualifierTypeE, "ARRAYSIZE"); - try { - int arraySize = (arraySizeStr == null ? (isArray ? 0 : -1) : Integer - .parseInt(arraySizeStr)); - if (isArray || arraySize >= 0) { - qdType = (arraySize > 0) ? new CIMDataType(qdType.getType(), arraySize) - : CIMHelper.UnboundedArrayDataType(qdType.getType()); - } - } catch (NumberFormatException e) { - throw new CIMXMLParseException(arraySizeStr - + " is not a valid ARRAYSIZE attribute for QUALIFIER.DECLARATION!"); - } - } else { - nodes = new String[] { "SCOPE" }; - qdType = parseScalarTypeStr(type); - if (qdType == null) qdType = CIMDataType.STRING_T; - qdValue = null; - } - checkOtherNodes(pQualifierTypeE, nodes); - - // FIXME: ebak: what about the flavors? - return new CIMQualifierType(new CIMObjectPath(null, null, null, null, name, null), - qdType, qdValue, scopes, 0); - } - - private static boolean hasTrueAttribute(Element pElement, String pName) { - String valueStr = pElement.getAttribute(pName); - return MOF.TRUE.equalsIgnoreCase(valueStr); - } - - private static boolean getBoolAttribute(Element pElement, String pName, boolean pDefVal) { - String val = pElement.getAttribute(pName); - if (MOF.TRUE.equalsIgnoreCase(val)) return true; - if (MOF.FALSE.equalsIgnoreCase(val)) return false; - return pDefVal; - } - - /** - * parseSCOPES - * - * @param pScopeE - * @return int - */ - public static int parseSCOPES(Element pScopeE) { - int scopes = 0; - if (hasTrueAttribute(pScopeE, "CLASS")) scopes |= CIMScope.CLASS; - if (hasTrueAttribute(pScopeE, "ASSOCIATION")) scopes |= CIMScope.ASSOCIATION; - if (hasTrueAttribute(pScopeE, "REFERENCE")) scopes |= CIMScope.REFERENCE; - if (hasTrueAttribute(pScopeE, "PROPERTY")) scopes |= CIMScope.PROPERTY; - if (hasTrueAttribute(pScopeE, "METHOD")) scopes |= CIMScope.METHOD; - if (hasTrueAttribute(pScopeE, "PARAMETER")) scopes |= CIMScope.PARAMETER; - if (hasTrueAttribute(pScopeE, "INDICATION")) scopes |= CIMScope.INDICATION; - return scopes; - } - - private static Vector> parseClassPropsToVec(Element pElement) - throws CIMXMLParseException { - Element[] propElementA = searchNodes(pElement, "PROPERTY"); - Vector> propVec = new Vector>(); - if (propElementA != null) { - for (int i = 0; i < propElementA.length; i++) { - Element propertyE = propElementA[i]; - propVec.add(parseCLASSPROPERTY(propertyE)); - - } - } - - // PROPERTY.ARRAY - Element[] propArrayElementA = searchNodes(pElement, "PROPERTY.ARRAY"); - if (propArrayElementA != null) { - for (int i = 0; i < propArrayElementA.length; i++) { - Element propertyarrayE = propArrayElementA[i]; - propVec.add(parseCLASSPROPERTYARRAY(propertyarrayE)); - } - } - - // PROPERTY.REFERENCE - Element[] propRefElementA = searchNodes(pElement, "PROPERTY.REFERENCE"); - if (propRefElementA != null) { - for (int i = 0; i < propRefElementA.length; i++) { - Element propertyreferenceE = propRefElementA[i]; - propVec.add(parseCLASSPROPERTYREFERENCE(propertyreferenceE)); - } - } - return propVec; - } - - /** - * parsePROPERTIES - * - * @param pElement - * @return CIMProperty[] - * @throws CIMXMLParseException - */ - public static CIMProperty[] parsePROPERTIES(Element pElement) throws CIMXMLParseException { - Vector> classPropVec = parseClassPropsToVec(pElement); - // The following does not convert Vector to - // CIMProperty[], it is still CIMClassProperty[]!!! You can treat it - // like a CIMProperty (property.getValue(), etc.) but (property - // instanceof CIMProperty) will return false! - // return classPropVec.toArray(new CIMProperty[0]); - - int arraySize = classPropVec.size(); - CIMProperty[] retA = new CIMProperty[arraySize]; - for (int i = 0; i < arraySize; i++) { - CIMClassProperty prop = classPropVec.get(i); - retA[i] = new CIMProperty(prop.getName(), prop.getDataType(), prop.getValue(), - prop.isKey(), prop.isPropagated(), prop.getOriginClass()); - } - return retA; - } - - /** - * parseCLASSPROPERTIES - * - * @param pElement - * @return CIMClassProperty[] - * @throws CIMXMLParseException - */ - public static CIMClassProperty[] parseCLASSPROPERTIES(Element pElement) - throws CIMXMLParseException { - Vector> classPropVec = parseClassPropsToVec(pElement); - return classPropVec.toArray(new CIMClassProperty[0]); - } - - /** - * parsePROPERTY - * - * @param pPropertyE - * @return CIMProperty - * @throws CIMXMLParseException - */ - public static CIMProperty parsePROPERTY(Element pPropertyE) throws CIMXMLParseException { - return parseCLASSPROPERTY(pPropertyE); - } - - private static class EmbObjHandler { - - private CIMQualifier[] iQualiA; - - private boolean iHasEmbObjAttr, iHasEmbInstAttr, iHasEmbObjQuali, iHasEmbInstQuali, iKeyed; - - private CIMDataType iRawType, iType; - - private Object iRawValue, iValue; - - private Element iElement; - - private boolean iStrictParsing = WBEMConfiguration.getGlobalConfiguration() - .strictEmbObjTypes(); - - /** - * Ctor. - * - * @param pElement - * @throws CIMXMLParseException - */ - public EmbObjHandler(Element pElement) throws CIMXMLParseException { - this.iElement = pElement; - handleQualis(); - handleAttribs(); - Element valueE = (Element) searchFirstNode(pElement, "VALUE"); - if (valueE != null) { - TypedValue tv = parseVALUE(valueE); - if (this.iRawType == null) this.iRawType = tv.getType(); - if (this.iRawType == null) this.iRawType = CIMDataType.STRING_T; - this.iRawValue = tv.getValue(); - } else { - valueE = (Element) searchFirstNode(pElement, "VALUE.ARRAY"); - if (valueE != null) { - TypedValue tv = parseVALUEARRAY(valueE); - if (this.iRawType == null) this.iRawType = tv.getType(); - if (this.iRawType == null) this.iRawType = CIMDataType.STRING_ARRAY_T; - this.iRawValue = tv.getValue(); - } - } - } - - private void handleQualis() throws CIMXMLParseException { - this.iQualiA = parseQUALIFIERS(this.iElement); - if (this.iQualiA != null) { - for (int idx = 0; idx < this.iQualiA.length; idx++) { - String qualiName = this.iQualiA[idx].getName(); - if ("EmbeddedObject".equalsIgnoreCase(qualiName)) { - this.iHasEmbObjQuali = true; - } else if ("EMBEDDEDINSTANCE".equalsIgnoreCase(qualiName)) { - this.iHasEmbInstQuali = true; - } else if ("KEY".equalsIgnoreCase(qualiName)) { - this.iKeyed = true; - } - if ((this.iHasEmbObjQuali || this.iHasEmbInstQuali) && this.iKeyed) return; - } - } - } - - private void handleAttribs() throws CIMXMLParseException { - String typeStr = this.iElement.getAttribute("TYPE"); - if (typeStr == null || typeStr.length() == 0) { - typeStr = this.iElement.getAttribute("PARAMTYPE"); - if (typeStr == null || typeStr.length() == 0) { - /* - * throw new CIMXMLParseException( iElement.getNodeName()+" - * must contain a TYPE or PARAMTYPE attribute!" ); - */ - /* - * ebak: Workaround for SVC's TYPE attribute in VALUE and - * VALUE.ARRAY element. - */ - typeStr = null; - } - } - // ebak: iRawType can be filled from contained VALUE or VALUE.ARRAY - // element (SVC) - if (typeStr != null) this.iRawType = parseScalarTypeStr(typeStr); - - // DSPs call for EmbeddedObject AND XML is case sensitive, BUT there - // are probably CIMOMs out there that still use EMBEDDEDOBJECT - String embObjAttrStr = this.iElement.getAttribute("EmbeddedObject"); - if (embObjAttrStr == null || embObjAttrStr.length() == 0) { - embObjAttrStr = this.iElement.getAttribute("EMBEDDEDOBJECT"); - } - if (embObjAttrStr == null || embObjAttrStr.length() == 0) { - this.iHasEmbObjAttr = this.iHasEmbInstAttr = false; - } else if ("object".equalsIgnoreCase(embObjAttrStr)) { - this.iHasEmbObjAttr = true; - this.iHasEmbInstAttr = false; - } else if ("instance".equalsIgnoreCase(embObjAttrStr)) { - this.iHasEmbObjAttr = false; - this.iHasEmbInstAttr = true; - } else throw new CIMXMLParseException("EmbeddedObject attribute cannot contain \"" - + embObjAttrStr + "\" value!"); - } - - /** - * getQualifiers - * - * @return CIMQualifier[] - * @throws CIMXMLParseException - */ - public CIMQualifier[] getQualifiers() throws CIMXMLParseException { - transform(); - CIMQualifiedElementInterfaceImpl qualiImpl = new CIMQualifiedElementInterfaceImpl( - this.iQualiA, isKeyed(), this.iType == null - || this.iType.getType() == CIMDataType.STRING); - return qualiImpl.getQualifiers(); - } - - /** - * isKeyed - * - * @return boolean - */ - public boolean isKeyed() { - return this.iKeyed; - } - - /** - * isEmbeddedObject - * - * @return boolean - */ - private boolean isEmbeddedObject() { - return this.iHasEmbObjAttr || this.iHasEmbInstAttr || this.iHasEmbObjQuali - || this.iHasEmbInstQuali; - } - - /** - * isEmbeddedClass - * - * @return boolean - */ - private boolean isEmbeddedClass() { - return this.iHasEmbObjAttr || this.iHasEmbObjQuali; - } - - /** - * isEmbeddedInstance - * - * @return boolean - */ - private boolean isEmbeddedInstance() { - return this.iHasEmbInstAttr || this.iHasEmbInstQuali; - } - - /** - * getType - * - * @return CIMDataType - * @throws CIMXMLParseException - */ - public CIMDataType getType() throws CIMXMLParseException { - transform(); - return this.iType; - } - - /** - * getArrayType - * - * @return CIMDataType - * @throws CIMXMLParseException - */ - public CIMDataType getArrayType() throws CIMXMLParseException { - transform(); - return this.iType.isArray() ? this.iType : CIMHelper.UnboundedArrayDataType(this.iType - .getType()); - } - - /** - * getValue - * - * @return Object - * @throws CIMXMLParseException - */ - public Object getValue() throws CIMXMLParseException { - transform(); - return this.iValue; - } - - private void transform() throws CIMXMLParseException { - if (this.iType != null) return; - if (this.iRawValue == null) { - if (isEmbeddedObject()) { - if (this.iRawType != CIMDataType.STRING_T) throw new CIMXMLParseException( - "Embedded Object CIM-XML element's type must be string. " - + this.iRawType + " is invalid!"); - if (this.iStrictParsing) { - /* - * In case of strict parsing Object means CIMClass, - * Instance means CIMInstance. Pegasus 2.7.0 seems to - * handle it this way. - */ - this.iType = isEmbeddedInstance() ? CIMDataType.OBJECT_T - : CIMDataType.CLASS_T; - } else { - /* - * for valueless EmbeddedObject="object" the type is - * undeterminable since Pegasus's CIMObject can contain - * both CIMClass and CIMInstance - */ - this.iType = isEmbeddedInstance() ? CIMDataType.OBJECT_T - : CIMDataType.STRING_T; - } - } else { - this.iType = this.iRawType; - } - this.iValue = null; - } else { - if (isEmbeddedObject()) { - transformEmbObj(); - } else { - transformNormObj(); - } - } - } - - private void transformEmbObj() throws CIMXMLParseException { - if (this.iRawValue instanceof String) { - this.iValue = parseXmlStr((String) this.iRawValue); - this.iType = getCIMObjType(this.iValue); - } else { - this.iValue = parseXmlStrA((String[]) this.iRawValue); - this.iType = getCIMObjAType((Object[]) this.iValue); - } - if (isEmbeddedInstance() && this.iType.getType() != CIMDataType.OBJECT) throw new CIMXMLParseException( - this.iElement.getNodeName() - + " element is an EmbeddedInstance with non INSTANCE value. " - + "It's not valid!"); - if (isEmbeddedClass() && this.iType.getType() != CIMDataType.CLASS - && this.iType.getType() != CIMDataType.OBJECT) throw new CIMXMLParseException( - this.iElement.getNodeName() - + " element is an EmbeddedObject with non CLASS/INSTANCE value. It's not valid!"); - } - - private void transformNormObj() throws CIMXMLParseException { - if (this.iRawValue instanceof String) { - this.iType = this.iRawType; - this.iValue = createJavaObject(this.iType == null ? null : this.iType.toString(), - (String) this.iRawValue); - } else { - String[] rawValueA = (String[]) this.iRawValue; - String typeStr = this.iRawType.toString(); - Object[] objA = new Object[rawValueA.length]; - for (int i = 0; i < objA.length; i++) - objA[i] = createJavaObject(typeStr, rawValueA[i]); - this.iType = CIMHelper.UnboundedArrayDataType(this.iRawType.getType()); - this.iValue = objA; - } - } - - /** - * parseXmlStr - * - * @param pXmlStr - * @return CIMClass or CIMInstance - * @throws CIMXMLParseException - */ - public static Object parseXmlStr(String pXmlStr) throws CIMXMLParseException { - // ebak: workaround for null array elements -> parse empty EmbObj - // string as null - if (pXmlStr == null || pXmlStr.length() == 0) return null; - try { - CIMClientXML_HelperImpl builder = new CIMClientXML_HelperImpl(); - Document doc = builder.parse(new InputSource(new StringReader(pXmlStr))); - return parseObject(doc.getDocumentElement()); - } catch (CIMXMLParseException e) { - throw e; - } catch (Exception e) { - throw new CIMXMLParseException(e.getMessage() + "\npXmlStr=" + pXmlStr); - } - } - - /** - * parseXmlStrA - * - * @param pXmlStrA - * @return Object[] - * @throws CIMXMLParseException - */ - public static Object[] parseXmlStrA(String[] pXmlStrA) throws CIMXMLParseException { - if (pXmlStrA == null || pXmlStrA.length == 0) return null; - Object[] objA = new Object[pXmlStrA.length]; - for (int i = 0; i < objA.length; i++) { - String xmlStr = pXmlStrA[i]; - objA[i] = xmlStr == null ? null : parseXmlStr(xmlStr); - } - return objA; - } - - /** - * getCIMObjType - * - * @param pCIMObj - * @return CIMDataType - * @throws CIMXMLParseException - */ - public static CIMDataType getCIMObjType(Object pCIMObj) throws CIMXMLParseException { - if (pCIMObj == null) throw new CIMXMLParseException( - "cannot have null CIM object! (CIMClass or CIMInstance)"); - if (pCIMObj instanceof CIMInstance) return CIMDataType.OBJECT_T; - if (pCIMObj instanceof CIMClass) return CIMDataType.CLASS_T; - throw new CIMXMLParseException(pCIMObj.getClass().getName() - + " is not a CIM object! (CIMClass or CIMInstance)"); - } - - /** - * getCIMObjAType - * - * @param pCIMObjA - * @return CIMDataType - * @throws CIMXMLParseException - */ - public static CIMDataType getCIMObjAType(Object[] pCIMObjA) throws CIMXMLParseException { - if (pCIMObjA == null || pCIMObjA.length == 0) return CIMDataType.STRING_ARRAY_T; - CIMDataType type = null; - for (int i = 0; i < pCIMObjA.length; i++) { - if (pCIMObjA[i] == null) continue; - CIMDataType currType = getCIMObjType(pCIMObjA[i]); - if (type == null) { - type = currType; - } else if (type != currType) { throw new CIMXMLParseException( - "Embedded Object arrays with different types are not supported"); } - } - if (type == CIMDataType.OBJECT_T) return CIMDataType.OBJECT_ARRAY_T; - if (type == CIMDataType.CLASS_T) return CIMDataType.CLASS_ARRAY_T; - return CIMDataType.STRING_ARRAY_T; - } - - } - - private static final String nodesPROPERTY[] = { "QUALIFIER", "VALUE" }; - - /** - * parseCLASSPROPERTY - * - * @param pPropertyE - * @return CIMClassProperty - * @throws CIMXMLParseException - */ - public static CIMClassProperty parseCLASSPROPERTY(Element pPropertyE) - throws CIMXMLParseException { - // - // - - Attr property_nameA = (Attr) searchAttribute(pPropertyE, "NAME"); - if (property_nameA == null) throw new CIMXMLParseException( - "PROPERTY element missing NAME attribute!"); - String name = property_nameA.getNodeValue(); - if (attribute(pPropertyE, "TYPE") == null && !hasTypeAttrsInNodes(pPropertyE)) throw new CIMXMLParseException( - "PROPERTY element missing TYPE attribute!"); - - String classOrigin = pPropertyE.getAttribute("CLASSORIGIN"); - if (classOrigin != null && classOrigin.length() == 0) classOrigin = null; - - String propagatedStr = pPropertyE.getAttribute("PROPAGATED"); - boolean propagated = MOF.TRUE.equalsIgnoreCase(propagatedStr); - - // only QUALIFIER(s) and 0/1 VALUE - searchNodes(pPropertyE, "VALUE", 0, 1, true); - checkOtherNodes(pPropertyE, nodesPROPERTY); - - // QUALIFIER - // ebak: EmbeddedObject support - EmbObjHandler embObjHandler = new EmbObjHandler(pPropertyE); - /* - * CIMClassProperty(String pName, CIMDataType pType, Object pValue, - * CIMQualifier[] pQualifiers, boolean pKey, boolean propagated, String - * originClass) - */ - return new CIMClassProperty(name, embObjHandler.getType(), - embObjHandler.getValue(), embObjHandler.getQualifiers(), embObjHandler.isKeyed(), - propagated, classOrigin); - } - - /** - * parsePROPERTYARRAY - * - * @param pPropertyArrayE - * @return CIMProperty - * @throws CIMXMLParseException - */ - public static CIMProperty parsePROPERTYARRAY(Element pPropertyArrayE) - throws CIMXMLParseException { - return parseCLASSPROPERTYARRAY(pPropertyArrayE); - } - - private static final String nodesPROPERTYARRAY[] = { "QUALIFIER", "VALUE.ARRAY" }; - - /** - * parseCLASSPROPERTYARRAY - * - * @param pPropArrayE - * @return CIMClassProperty - * @throws CIMXMLParseException - */ - public static CIMClassProperty parseCLASSPROPERTYARRAY(Element pPropArrayE) - throws CIMXMLParseException { - // - // - - String name = attribute(pPropArrayE, "NAME"); - if (name == null) throw new CIMXMLParseException( - "PROPERTY.ARRAY element missing NAME attribute!"); - if (attribute(pPropArrayE, "TYPE") == null && !hasTypeAttrsInNodes(pPropArrayE)) throw new CIMXMLParseException( - "PROPERTY.ARRAY element missing TYPE attribute!"); - - String valueArraysizeStr = pPropArrayE.getAttribute("ARRAYSIZE"); - try { - if (valueArraysizeStr.length() > 0) Integer.parseInt(valueArraysizeStr); - } catch (NumberFormatException e) { - throw new CIMXMLParseException(valueArraysizeStr - + " is not a valid ARRAYSIZE attribute for VALUE.ARRAY!"); - } - - String classOrigin = pPropArrayE.getAttribute("CLASSORIGIN"); - if (classOrigin != null && classOrigin.length() == 0) classOrigin = null; - - String valuePropagatedStr = pPropArrayE.getAttribute("PROPAGATED"); - boolean propagated = (valuePropagatedStr != null && valuePropagatedStr - .equalsIgnoreCase(MOF.TRUE)); - - // only QUALIFIER(s) and 0/1 VALUE.ARRAY - searchNodes(pPropArrayE, "VALUE.ARRAY", 0, 1, true); - checkOtherNodes(pPropArrayE, nodesPROPERTYARRAY); - - // QUALIFIER - // ebak: EmbeddedObject support - EmbObjHandler embObjHandler = new EmbObjHandler(pPropArrayE); - return new CIMClassProperty(name, embObjHandler.getArrayType(), embObjHandler - .getValue(), embObjHandler.getQualifiers(), embObjHandler.isKeyed(), propagated, - classOrigin); - } - - /** - * parsePROPERTYREFERENCE - * - * @param pPropRefE - * @return CIMProperty - * @throws CIMXMLParseException - */ - public static CIMProperty parsePROPERTYREFERENCE(Element pPropRefE) - throws CIMXMLParseException { - return parseCLASSPROPERTYREFERENCE(pPropRefE); - } - - private static final String nodesPROPERTYREFERENCE[] = { "QUALIFIER", "VALUE.REFERENCE" }; - - /** - * parseCLASSPROPERTYREFERENCE - * - * @param pPropRefE - * @return CIMClassProperty - * @throws CIMXMLParseException - */ - public static CIMClassProperty parseCLASSPROPERTYREFERENCE(Element pPropRefE) - throws CIMXMLParseException { - // - // - - String name = attribute(pPropRefE, "NAME"); - if (name == null) throw new CIMXMLParseException( - "PROPERTY.REFERENCE element missing NAME attribute!"); - - String classOrigin = pPropRefE.getAttribute("CLASSORIGIN"); - if (classOrigin != null && classOrigin.length() == 0) classOrigin = null; - - String referenceClass = pPropRefE.getAttribute("REFERENCECLASS"); - - String propagatedStr = pPropRefE.getAttribute("PROPAGATED"); - boolean propagated = MOF.TRUE.equalsIgnoreCase(propagatedStr); - - // QUALIFIER - CIMQualifier[] qualis = parseQUALIFIERS(pPropRefE); - - CIMDataType type = new CIMDataType(referenceClass != null ? referenceClass : ""); - // VALUE.REFERENCE - Element valueRefA[] = searchNodes(pPropRefE, "VALUE.REFERENCE", 0, 1, true); - Object value = valueRefA != null ? parseVALUEREFERENCE(valueRefA[0]) : null; - - // return a CIMProperty without a CIMValue - checkOtherNodes(pPropRefE, nodesPROPERTYREFERENCE); - CIMQualifiedElementInterfaceImpl qualiImpl = new CIMQualifiedElementInterfaceImpl(qualis); - return new CIMClassProperty(name, type, value, qualis, qualiImpl.isKeyed(), - propagated, classOrigin); - } - - /** - * parseMESSAGE - * - * @param pCimVersion - * @param pDtdVersion - * @param pMessageE - * @return CIMMessage - * @throws CIMXMLParseException - */ - public static CIMMessage parseMESSAGE(String pCimVersion, String pDtdVersion, Element pMessageE) - throws CIMXMLParseException { - // - // - - Attr idA = (Attr) searchAttribute(pMessageE, "ID"); - if (idA == null) throw new CIMXMLParseException("MESSAGE element missing ID attribute!"); - String id = idA.getNodeValue(); - - Attr protocolA = (Attr) searchAttribute(pMessageE, "PROTOCOLVERSION"); - if (protocolA == null) throw new CIMXMLParseException( - "MESSAGE element missing PROTOCOLVERSION attribute!"); - // TODO - if (pCimVersion.equals("2.0") && pDtdVersion.equals("2.0")) { - - // Attr message_idA = (Attr)searchAttribute(messageE, "ID"); - // String messadeID = message_idA.getNodeValue(); - - // Attr message_protocolversionA = (Attr)searchAttribute(messageE, - // "PROTOCOLVERSION"); - // String protocolversion = message_protocolversionA.getNodeValue(); - - // SIMPLERSP - Element simplerspA[] = searchNodes(pMessageE, "SIMPLERSP", 0, 1, false); - if (simplerspA != null) { - CIMResponse response = parseSIMPLERSP(simplerspA[0]); - response.setMethod("SIMPLERSP"); - response.setId(id); - return response; - } - Element multirspA[] = searchNodes(pMessageE, "MULTIRSP", 0, 1, false); - if (multirspA != null) { - CIMResponse response = parseMULTIRSP(multirspA[0]); - response.setMethod("MULTIRSP"); - response.setId(id); - return response; - } - // SIMPLEEXPREQ - Element simpleexpreqA[] = searchNodes(pMessageE, "SIMPLEEXPREQ", 0, 1, false); - if (simpleexpreqA != null) { - CIMRequest request = parseSIMPLEEXPREQ(simpleexpreqA[0]); - request.setMethod("SIMPLEEXPREQ"); - request.setId(id); - return request; - } - - // MULTIEXPREQ - Element multiexpreqA[] = searchNodes(pMessageE, "MULTIEXPREQ", 0, 1, false); - if (multiexpreqA != null) { - CIMRequest request = parseMULTIEXPREQ(multiexpreqA[0]); - request.setMethod("MULTIEXPREQ"); - request.setId(id); - return request; - } - // SIMPLEEXPRSP - Element simpleexprspA[] = searchNodes(pMessageE, "SIMPLEEXPRSP", 0, 1, false); - if (simpleexprspA != null) { - CIMResponse response = parseSIMPLEEXPRSP(simpleexprspA[0]); - response.setMethod("SIMPLEEXPRSP"); - response.setId(id); - return response; - } - // MULTIEXPRSP - Element multiexprspA[] = searchNodes(pMessageE, "MULTIEXPRSP", 0, 1, false); - if (multiexprspA != null) { - CIMResponse response = parseMULTIEXPRSP(multiexprspA[0]); - response.setMethod("MULTIEXPRSP"); - response.setId(id); - return response; - } - - // SIMPLEREQ - Element simplereqA[] = searchNodes(pMessageE, "SIMPLEREQ", 0, 1, false); - if (simplereqA != null) { - CIMRequest request = parseSIMPLEREQ(simplereqA[0]); - request.setMethod("SIMPLEREQ"); - request.setId(id); - return request; - } - - // MULTIREQ - Element multireqA[] = searchNodes(pMessageE, "MULTIREQ", 0, 1, false); - if (multireqA != null) { - CIMRequest request = parseMULTIREQ(multireqA[0]); - request.setMethod("MULTIREQ"); - request.setId(id); - return request; - } - throw new CIMXMLParseException("MESSAGE element missing required child element!"); - } - // TODO, look for the specific error message in the spec - throw new CIMXMLParseException("DTD not supported"); - } - - private static final String nodesPARAMVALUE[] = { "VALUE", "VALUE.REFERENCE", "VALUE.ARRAY", - "VALUE.REFARRAY", "CLASSNAME", "INSTANCENAME", "CLASS", "INSTANCE", - "VALUE.NAMEDINSTANCE" }; - - /** - * parsePARAMVALUE - * - * @param pParamValueE - * @return CIMArgument - * @throws CIMXMLParseException - */ - public static CIMArgument parsePARAMVALUE(Element pParamValueE) - throws CIMXMLParseException { - // ) - // - String name = attribute(pParamValueE, "NAME"); - if (name == null) throw new CIMXMLParseException( - "PARAMVALUE element missing NAME attribute!"); - // FIXME: ebak: The base implementation didn't contain VALUE.REFARRAY - // handling. Why? - // ebak: embedded object support, different parsing for VALUE and - // VALUE.ARRAY sub elements - if (searchNodes(pParamValueE, "VALUE.REFERENCE", 0, 1, false) != null - || searchNodes(pParamValueE, "VALUE.REFARRAY", 0, 1, false) != null) { - TypedValue typedValue = parseSingleValue(pParamValueE, VALUEREF | VALUEREFA); - CIMDataType type = typedValue.getType(); - Object value = typedValue.getValue(); - if (type == null) throw new CIMXMLParseException("PARAMVALUE element type is null!"); - return new CIMArgument(name, type, value); - } - if (searchNodes(pParamValueE, "VALUE", 0, 1, false) != null - || searchNodes(pParamValueE, "VALUE.ARRAY", 0, 1, false) != null - || !hasNodes(pParamValueE)) { - EmbObjHandler embObjHandler = new EmbObjHandler(pParamValueE); - return new CIMArgument(name, embObjHandler.getType(), embObjHandler.getValue()); - } - - // CLASSNAME - Element classNameA[] = searchNodes(pParamValueE, "CLASSNAME", 0, 1, false); - if (classNameA != null) { - CIMObjectPath op = parseCLASSNAME(classNameA[0]); - CIMDataType type = new CIMDataType(op.getObjectName()); - return new CIMArgument(name, type, op); - } - - // INSTANCENAME - Element instNameA[] = searchNodes(pParamValueE, "INSTANCENAME", 0, 1, false); - if (instNameA != null) { - CIMObjectPath op = parseINSTANCENAME(instNameA[0]); - CIMDataType type = new CIMDataType(op.getObjectName()); - return new CIMArgument(name, type, op); - } - - // CLASS - Element classA[] = searchNodes(pParamValueE, "CLASS", 0, 1, false); - if (classA != null) { - CIMClass cl = parseCLASS(classA[0]); - return new CIMArgument(name, CIMDataType.CLASS_T, cl); - } - - // INSTANCE - Element instanceA[] = searchNodes(pParamValueE, "INSTANCE", 0, 1, false); - if (instanceA != null) { - CIMInstance inst = parseINSTANCE(instanceA[0]); - return new CIMArgument(name, CIMDataType.OBJECT_T, inst); - } - - // VALUE.NAMEDINSTANCE - Element valuenamedisntanceA[] = searchNodes(pParamValueE, "VALUE.NAMEDINSTANCE", 0, 1, - false); - if (valuenamedisntanceA != null) { - CIMInstance inst = parseVALUENAMEDINSTANCE(valuenamedisntanceA[0]); - return new CIMArgument(name, CIMDataType.OBJECT_T, inst); - } - checkOtherNodes(pParamValueE, nodesPARAMVALUE); - return new CIMArgument(name, CIMDataType.STRING_T, null); - } - - private static final String nodesIPARAMVALUE[] = { "VALUE", "VALUE.ARRAY", "VALUE.REFERENCE", - "CLASSNAME", "INSTANCENAME", "QUALIFIER.DECLARATION", "CLASS", "INSTANCE", - "VALUE.NAMEDINSTANCE" }; - - /** - * parseIPARAMVALUE - * - * @param pParamValueE - * @return CIMArgument - * @throws CIMXMLParseException - */ - public static CIMArgument parseIPARAMVALUE(Element pParamValueE) - throws CIMXMLParseException { - // - // - - String name = attribute(pParamValueE, "NAME"); - if (name == null) throw new CIMXMLParseException( - "IPARAMVALUE element missing NAME attribute!"); - // this can parse VALUE, VALUE.ARRAY and VALUE.REFERENCE - if (searchNodes(pParamValueE, "VALUE", 0, 1, false) != null - || searchNodes(pParamValueE, "VALUE.ARRAY", 0, 1, false) != null - || searchNodes(pParamValueE, "VALUE.REFERENCE", 0, 1, false) != null) { - TypedValue typedValue = parseSingleValue(pParamValueE, VALUE | VALUEA | VALUEREF); - if (typedValue.getType() != null) { return new CIMArgument(name, typedValue - .getType(), typedValue.getValue()); } - } - // we can have different types too which cannot be handled by - // parseSingleValue() - - // INSTANCENAME - Element instNameA[] = searchNodes(pParamValueE, "INSTANCENAME", 0, 1, false); - if (instNameA != null) { - CIMObjectPath op = parseINSTANCENAME(instNameA[0]); - CIMDataType type = new CIMDataType(op.getObjectName()); - return new CIMArgument(name, type, op); - } - - // CLASSNAME - Element classNameA[] = searchNodes(pParamValueE, "CLASSNAME", 0, 1, false); - if (classNameA != null) { - CIMObjectPath op = parseCLASSNAME(classNameA[0]); - CIMDataType type = new CIMDataType(op.getObjectName()); - return new CIMArgument(name, type, op); - } - - // QUALIFIER.DECLARATION - Element qualiDeclarationA[] = searchNodes(pParamValueE, "QUALIFIER.DECLARATION", 0, 1, - false); - if (qualiDeclarationA != null) { - CIMQualifierType qualiType = parseQUALIFIERDECLARATION(qualiDeclarationA[0]); - // FIXME: ebak: Does it surely have to be mapped to type: - // REFERENCE???? - return new CIMArgument(name, new CIMDataType(qualiType.getName()), qualiType); - } - - // CLASS - Element classA[] = searchNodes(pParamValueE, "CLASS", 0, 1, false); - if (classA != null) { - CIMClass cl = parseCLASS(classA[0]); - return new CIMArgument(name, CIMDataType.CLASS_T, cl); - } - - // INSTANCE - Element instanceA[] = searchNodes(pParamValueE, "INSTANCE", 0, 1, false); - if (instanceA != null) { - CIMInstance inst = parseINSTANCE(instanceA[0]); - return new CIMArgument(name, CIMDataType.OBJECT_T, inst); - } - - // VALUE.NAMEDINSTANCE - Element valuenamedisntanceA[] = searchNodes(pParamValueE, "VALUE.NAMEDINSTANCE", 0, 1, - false); - if (valuenamedisntanceA != null) { - CIMInstance inst = parseVALUENAMEDINSTANCE(valuenamedisntanceA[0]); - return new CIMArgument(name, CIMDataType.OBJECT_T, inst); - } - - checkOtherNodes(pParamValueE, nodesIPARAMVALUE); - return new CIMArgument(name, CIMDataType.STRING_T, null); - } - - /** - * parseSIMPLERSP - * - * @param pSimpleRspE - * @return CIMResponse - * @throws CIMXMLParseException - */ - public static CIMResponse parseSIMPLERSP(Element pSimpleRspE) throws CIMXMLParseException { - // - - // METHODRESPONSE - Element methodresponseA[] = searchNodes(pSimpleRspE, "METHODRESPONSE", 0, 1, false); - if (methodresponseA != null) { - - return parseMETHODRESPONSE(methodresponseA[0]); } - - // IMETHODRESPONSE - Element imethodresponseA[] = searchNodes(pSimpleRspE, "IMETHODRESPONSE", 0, 1, false); - if (imethodresponseA != null) { return parseIMETHODRESPONSE(imethodresponseA[0]); } - - throw new CIMXMLParseException("SIMPLERSP element missing required child element!"); - } - - /** - * parseMULTIRSP - * - * @param pSimpleRspE - * @return CIMResponse - * @throws CIMXMLParseException - */ - public static CIMResponse parseMULTIRSP(Element pSimpleRspE) throws CIMXMLParseException { - // - - Element[] multiRespElementA = searchNodes(pSimpleRspE, "SIMPLERSP", 2, Integer.MAX_VALUE, - false); - if (multiRespElementA != null) { - CIMResponse multiRsp = new CIMResponse(); - for (int i = 0; i < multiRespElementA.length; i++) { - Element methodresponseE = multiRespElementA[i]; - CIMResponse rsp = parseSIMPLERSP(methodresponseE); - rsp.setMethod("SIMPLERSP"); - multiRsp.addResponse(rsp); - } - return multiRsp; - } - - throw new CIMXMLParseException("MULTIRSP element missing SIMPLERSP child element!"); - } - - private static final String nodesSIMPLEREQ[] = { "CORRELATOR", "METHODCALL", "IMETHODCALL" }; - - /** - * parseSIMPLEREQ - * - * @param pSimpleReqE - * @return CIMRequest - * @throws CIMXMLParseException - */ - public static CIMRequest parseSIMPLEREQ(Element pSimpleReqE) throws CIMXMLParseException { - // - CIMRequest request = null; - - // METHODCALL - Element methodcallA[] = searchNodes(pSimpleReqE, "METHODCALL", 0, 1, true); - if (methodcallA != null) { - request = parseMETHODCALL(methodcallA[0]); - } - - // IMETHODCALL - Element imethodcallA[] = searchNodes(pSimpleReqE, "IMETHODCALL", 0, 1, true); - if (imethodcallA != null) { - if (request != null) { throw new CIMXMLParseException( - "SIMPLEREQ element cannot have METHODCALL and IMETHODCALL child elements!"); } - request = parseIMETHODCALL(imethodcallA[0]); - } - - if (request == null) throw new CIMXMLParseException( - "SIMPLEREQ element missing required child element!"); - - // CORRELATOR - Element[] correlatorA = searchNodes(pSimpleReqE, "CORRELATOR", 0, Integer.MAX_VALUE, true); - if (correlatorA != null) { - for (int i = 0; i < correlatorA.length; i++) - // TODO: return to WBEMClient API if JSR48 changes - parseCORRELATOR(correlatorA[i]); - } - - checkOtherNodes(pSimpleReqE, nodesSIMPLEREQ); - return request; - } - - /** - * parseMULTIREQ - * - * @param pMultiReqE - * @return CIMRequest - * @throws CIMXMLParseException - */ - public static CIMRequest parseMULTIREQ(Element pMultiReqE) throws CIMXMLParseException { - // - - Element[] methodReqElementA = searchNodes(pMultiReqE, "SIMPLEREQ", 2, Integer.MAX_VALUE, - false); - if (methodReqElementA != null) { - CIMRequest multiReq = new CIMRequest(); - for (int i = 0; i < methodReqElementA.length; i++) { - Element methodrequestE = methodReqElementA[i]; - CIMRequest req = parseSIMPLEREQ(methodrequestE); - req.setMethod("SIMPLEREQ"); - - multiReq.addRequest(req); - } - return multiReq; - } - throw new CIMXMLParseException("MULTIREQ element missing SIMPLEREQ child element!"); - } - - private static final String nodesMETHODCALL[] = { "LOCALCLASSPATH", "LOCALINSTANCEPATH", - "PARAMVALUE" }; - - /** - * parseMETHODCALL - * - * @param pMethodCallE - * @return CIMRequest - * @throws CIMXMLParseException - */ - public static CIMRequest parseMETHODCALL(Element pMethodCallE) throws CIMXMLParseException { - // - // - - CIMRequest request = new CIMRequest(); - String methodname = attribute(pMethodCallE, "NAME"); - if (methodname == null) throw new CIMXMLParseException( - "METHODCALL element missing NAME attribute!"); - request.setMethodName(methodname); - - // EXPMETHODCALL - boolean localclasspathFound = false; - Element localclasspathA[] = searchNodes(pMethodCallE, "LOCALCLASSPATH", 0, 1, true); - if (localclasspathA != null) { - CIMObjectPath path = parseLOCALCLASSPATH(localclasspathA[0]); - - request.setObjectPath(path); - localclasspathFound = true; - } - - Element localinstancepathA[] = searchNodes(pMethodCallE, "LOCALINSTANCEPATH", 0, 1, true); - if (localinstancepathA != null) { - if (localclasspathFound) throw new CIMXMLParseException( - "METHODCALL element cannot have both LOCALCLASSPATH and LOCALINSTANCEPATH child elements!"); - - CIMObjectPath path = parseLOCALINSTANCEPATH(localinstancepathA[0]); - - request.setObjectPath(path); - } else { - if (!localclasspathFound) throw new CIMXMLParseException( - "METHODCALL element missing required child element!"); - } - - Element[] paramValueElementA = searchNodes(pMethodCallE, "PARAMVALUE", 0, - Integer.MAX_VALUE, true); - - if (paramValueElementA != null) { - CIMArgument[] argA = new CIMArgument[paramValueElementA.length]; - for (int i = 0; i < paramValueElementA.length; i++) { - Element paramvalueE = paramValueElementA[i]; - argA[i] = parsePARAMVALUE(paramvalueE); - } - request.addParamValue(argA); - } - - checkOtherNodes(pMethodCallE, nodesMETHODCALL); - return request; - } - - private static final String nodesIMETHODCALL[] = { "LOCALNAMESPACEPATH", "IPARAMVALUE" }; - - /** - * parseIMETHODCALL - * - * @param pIMethodCallE - * @return CIMRequest - * @throws CIMXMLParseException - */ - public static CIMRequest parseIMETHODCALL(Element pIMethodCallE) throws CIMXMLParseException { - // - // - - CIMRequest request = new CIMRequest(); - String methodname = attribute(pIMethodCallE, "NAME"); // ebak: - // CIMName->NAME - if (methodname == null) throw new CIMXMLParseException( - "IMETHODCALL element missing NAME attribute!"); - request.setMethodName(methodname); - - // METHODCALL - Element localnamespacepathA[] = searchNodes(pIMethodCallE, "LOCALNAMESPACEPATH", 1, 1, true); - if (localnamespacepathA != null) { - String nameSpace = parseLOCALNAMESPACEPATH(localnamespacepathA[0]); - request.setNameSpace(nameSpace); - } - - Element[] iParamValElementA = searchNodes(pIMethodCallE, "IPARAMVALUE", 0, - Integer.MAX_VALUE, true); // ebak: - // PARAMVALUE->IPARAMVALUE - - if (iParamValElementA != null) { - CIMArgument[] argA = new CIMArgument[iParamValElementA.length]; - for (int i = 0; i < iParamValElementA.length; i++) { - Element paramvalueE = iParamValElementA[i]; - CIMArgument arg = parseIPARAMVALUE(paramvalueE); - /* - * ebak: local nameSpacePath should be added to those reference - * arguments which don't contain namespace - */ - Object value = arg.getValue(); - if (value instanceof CIMObjectPath) { - CIMObjectPath op = (CIMObjectPath) value; - if (op.getNamespace() == null || op.getNamespace().length() == 0) { - arg = new CIMArgument(arg.getName(), arg.getDataType(), - // CIMObjectPath(String scheme, String host, String - // port, String namespace, String objectName, - // CIMProperty[] keys) - new CIMObjectPath(op.getScheme(), op.getHost(), op.getPort(), - request.getNameSpace(), op.getObjectName(), op.getKeys())); - } - } - argA[i] = arg; - } - request.addParamValue(argA); - } - - checkOtherNodes(pIMethodCallE, nodesIMETHODCALL); - return request; - } - - private static final String nodesSIMPLEEXPREQ[] = { "CORRELATOR", "EXPMETHODCALL" }; - - /** - * parseSIMPLEEXPREQ - * - * @param pSimpleExpReqE - * @return CIMRequest - * @throws CIMXMLParseException - */ - public static CIMRequest parseSIMPLEEXPREQ(Element pSimpleExpReqE) throws CIMXMLParseException { - // - CIMRequest request = null; - - // EXPMETHODCALL - Element[] expmethodcallA = searchNodes(pSimpleExpReqE, "EXPMETHODCALL", 1, 1, true); - if (expmethodcallA != null) { - request = parseEXPMETHODCALL(expmethodcallA[0]); - } else { - throw new CIMXMLParseException( - "SIMPLEEXPREQ element missing EXPMETHODCALL child element!"); - } - - // CORRELATOR - Element[] correlatorA = searchNodes(pSimpleExpReqE, "CORRELATOR", 0, Integer.MAX_VALUE, - true); - if (correlatorA != null) { - for (int i = 0; i < correlatorA.length; i++) - // TODO: return to WBEMClient API if JSR48 changes - parseCORRELATOR(correlatorA[i]); - } - - checkOtherNodes(pSimpleExpReqE, nodesSIMPLEEXPREQ); - return request; - } - - /** - * parseMULTIEXPREQ - * - * @param pMultiExpReqE - * @return CIMRequest - * @throws CIMXMLParseException - */ - public static CIMRequest parseMULTIEXPREQ(Element pMultiExpReqE) throws CIMXMLParseException { - // - - Element[] methodReqElementA = searchNodes(pMultiExpReqE, "SIMPLEEXPREQ", 2, - Integer.MAX_VALUE, false); - if (methodReqElementA != null) { - CIMRequest multiReq = new CIMRequest(); - for (int i = 0; i < methodReqElementA.length; i++) { - Element methodrequestE = methodReqElementA[i]; - CIMRequest req = parseSIMPLEEXPREQ(methodrequestE); - req.setMethod("SIMPLEEXPREQ"); - - multiReq.addRequest(req); - } - return multiReq; - } - throw new CIMXMLParseException("MULTIEXPREQ element missing SIMPLEEXPREQ child element!"); - } - - private static final String nodesEXPMETHODCALL[] = { "EXPPARAMVALUE" }; - - /** - * parseEXPMETHODCALL - * - * @param pExpMethodCallE - * @return CIMRequest - * @throws CIMXMLParseException - */ - public static CIMRequest parseEXPMETHODCALL(Element pExpMethodCallE) - throws CIMXMLParseException { - // - - // EXPMETHODCALL - CIMRequest request = new CIMRequest(); - String methodname = attribute(pExpMethodCallE, "NAME"); - if (methodname == null) throw new CIMXMLParseException( - "EXPMETHODCALL element missing NAME attribute!"); - request.setMethodName(methodname); - - Element[] paramValElementA = searchNodes(pExpMethodCallE, "EXPPARAMVALUE", 0, - Integer.MAX_VALUE, false); - Vector v = new Vector(); - if (paramValElementA != null) { - for (int i = 0; i < paramValElementA.length; i++) { - Element expparamvalueE = paramValElementA[i]; - CIMInstance inst = parseEXPPARAMVALUE(expparamvalueE); - v.add(inst); - } - } - request.addParamValue(v); - checkOtherNodes(pExpMethodCallE, nodesEXPMETHODCALL); - return request; - } - - private static final String nodesEXPPARAMVALUE[] = { "INSTANCE" }; - - /** - * parseEXPPARAMVALUE - * - * @param pExpParamValueE - * @return CIMInstance - * @throws CIMXMLParseException - */ - public static CIMInstance parseEXPPARAMVALUE(Element pExpParamValueE) - throws CIMXMLParseException { - // - // - // INSTANCE - if (attribute(pExpParamValueE, "NAME") == null) throw new CIMXMLParseException( - "EXPPARAMVALUE element missing NAME attribute!"); - - Element[] instanceA = searchNodes(pExpParamValueE, "INSTANCE", 0, 1, false); - if (instanceA != null) { - CIMInstance inst = parseINSTANCE(instanceA[0]); - return inst; - } - - checkOtherNodes(pExpParamValueE, nodesEXPPARAMVALUE); - - return null; - } - - private static final String nodesMETHODRESPONSE[] = { "ERROR", "RETURNVALUE", "PARAMVALUE" }; - - /** - * parseMETHODRESPONSE - * - * @param pMethodResponseE - * @return CIMResponse - * @throws CIMXMLParseException - */ - public static CIMResponse parseMETHODRESPONSE(Element pMethodResponseE) - throws CIMXMLParseException { - // - if (attribute(pMethodResponseE, "NAME") == null) throw new CIMXMLParseException( - "METHODRESPONSE element missing NAME attribute!"); - - CIMResponse response = new CIMResponse(); - - // ERROR - Element errorA[] = searchNodes(pMethodResponseE, "ERROR", 0, 1, false); - if (errorA != null) { - WBEMException exception = parseERROR(errorA[0]); - response.setError(exception); - return response; - } - - // RETURNVALUE - Element[] retValElementA = searchNodes(pMethodResponseE, "RETURNVALUE", 0, 1, true); - if (retValElementA != null) { - Vector v = new Vector(); - for (int i = 0; i < retValElementA.length; i++) { - Element returnvalueE = retValElementA[i]; - v.add(parseRETURNVALUE(returnvalueE)); - } - response.setReturnValue(v); - } - - // PARAMVALUE - Element[] paramValElementA = searchNodes(pMethodResponseE, "PARAMVALUE", 0, - Integer.MAX_VALUE, true); - if (paramValElementA != null) { - Vector v = new Vector(); - for (int i = 0; i < paramValElementA.length; i++) { - Element paramvalueE = paramValElementA[i]; - CIMArgument arg = parsePARAMVALUE(paramvalueE); - v.add(arg); - } - response.addParamValue(v); - } - - // PARAMVALUE (ESS fix) - if (retValElementA != null) { - for (int i = 0; i < retValElementA.length; i++) { - Element retValE = retValElementA[i]; - - paramValElementA = searchNodes(retValE, "PARAMVALUE"); - if (paramValElementA != null) { - Vector> v = new Vector>(); - for (int j = 0; j < paramValElementA.length; j++) { - Element paramvalueE = paramValElementA[j]; - CIMArgument arg = parsePARAMVALUE(paramvalueE); - v.add(arg); - } - response.addParamValue(v); - } - } - } - checkOtherNodes(pMethodResponseE, nodesMETHODRESPONSE); - - return response; - } - - private static final String nodesIMETHODRESPONSE[] = { "ERROR", "IRETURNVALUE", "PARAMVALUE" }; - - /** - * parseIMETHODRESPONSE - * - * @param pIMethodResponseE - * @return CIMResponse - * @throws CIMXMLParseException - */ - public static CIMResponse parseIMETHODRESPONSE(Element pIMethodResponseE) - throws CIMXMLParseException { - // - if (attribute(pIMethodResponseE, "NAME") == null) throw new CIMXMLParseException( - "IMETHODRESPONSE element missing NAME attribute!"); - - CIMResponse response = new CIMResponse(); - // ERROR - Element[] errorA = searchNodes(pIMethodResponseE, "ERROR", 0, 1, false); - if (errorA != null) { - WBEMException exception = parseERROR(errorA[0]); - response.setError(exception); - return response; - } - - // IRETURNVALUE - Element[] retValElementA = searchNodes(pIMethodResponseE, "IRETURNVALUE", 0, 1, true); - if (retValElementA != null) { - for (int i = 0; i < retValElementA.length; i++) { - Element ireturnvalueE = retValElementA[i]; - - Vector rtnV = parseIRETURNVALUE(ireturnvalueE); - response.setReturnValue(rtnV); - } - } - - // PARAMVALUE - Element[] paramValElementA = searchNodes(pIMethodResponseE, "PARAMVALUE", 0, - Integer.MAX_VALUE, true); - if (paramValElementA != null) { - Vector v = new Vector(); - for (int i = 0; i < paramValElementA.length; i++) { - Element paramvalueE = paramValElementA[i]; - CIMArgument arg = parsePARAMVALUE(paramvalueE); - v.add(arg); - } - response.addParamValue(v); - } - checkOtherNodes(pIMethodResponseE, nodesIMETHODRESPONSE); - - return response; - } - - private static final String nodesERROR[] = { "INSTANCE" }; - - /** - * parseERROR - * - * @param pErrorE - * @return WBEMException - * @throws CIMXMLParseException - */ - public static WBEMException parseERROR(Element pErrorE) throws CIMXMLParseException { - // - // - - Attr error_codeA = (Attr) searchAttribute(pErrorE, "CODE"); - if (error_codeA == null) throw new CIMXMLParseException( - "ERROR element missing CODE attribute!"); - String code = error_codeA.getNodeValue(); - int errorCode = 0; - try { - if (code.length() > 0) errorCode = Integer.parseInt(code); - } catch (Exception e) { - LogAndTraceBroker.getBroker().trace(Level.WARNING, - "exception while parsing error code from XML", e); - errorCode = WBEMException.CIM_ERR_FAILED; - } - Attr error_descriptionA = (Attr) searchAttribute(pErrorE, "DESCRIPTION"); - String description = ""; - if (error_descriptionA != null) { - description = error_descriptionA.getNodeValue(); - } - - Vector rtnV = new Vector(); - - // INSTANCE - Element[] instElementA = searchNodes(pErrorE, "INSTANCE", 0, Integer.MAX_VALUE, false); - if (instElementA != null) { - for (int i = 0; i < instElementA.length; i++) { - Element instanceE = instElementA[i]; - CIMInstance inst = parseINSTANCE(instanceE); - rtnV.add(inst); - } - } - checkOtherNodes(pErrorE, nodesERROR); - - // throw new CIMException(CIMException.getErrorName(errorCode), - // description.substring(description.indexOf(':')+1)); - if (!rtnV.isEmpty()) return new WBEMException(errorCode, "ErrorCode:" + errorCode - + " description:" + description, rtnV.toArray(new CIMInstance[0])); - return new WBEMException(errorCode, "ErrorCode:" + errorCode + " description:" - + description); - } - - private static final String nodesRETURNVALUE[] = { "VALUE", "VALUE.REFERENCE" }; - - /** - * parseRETURNVALUE - * - * @param pRetValE - * @return Object - * @throws CIMXMLParseException - */ - public static Object parseRETURNVALUE(Element pRetValE) throws CIMXMLParseException { - // - // - // ebak: embedded object support: different parsing of VALUE sub element - checkOtherNodes(pRetValE, nodesRETURNVALUE); - if (searchNodes(pRetValE, "VALUE", 0, 1, false) != null) { - EmbObjHandler embObjHandler = new EmbObjHandler(pRetValE); - return embObjHandler.getValue(); - } - if (searchNodes(pRetValE, "VALUE.REFERENCE", 0, 1, false) != null) { - TypedValue typedVal = parseSingleValue(pRetValE, VALUEREF); - Object value = typedVal.getValue(); - return value; - } - checkOtherNodes(pRetValE, nodesRETURNVALUE); - return null; - } - - private static final String nodesIRETURNVALUE[] = { "CLASSNAME", "INSTANCENAME", "VALUE", - "VALUE.OBJECTWITHPATH", "VALUE.OBJECTWITHLOCALPATH", "VALUE.OBJECT", "OBJECTPATH", - "QUALIFIER.DECLARATION", "VALUE.ARRAY", "VALUE.REFERENCE", "CLASS", "INSTANCE", - "INSTANCEPATH", "VALUE.NAMEDINSTANCE" }; - - /** - * parseIRETURNVALUE - * - * @param pIRetValE - * @return Vector - * @throws CIMXMLParseException - */ - public static Vector parseIRETURNVALUE(Element pIRetValE) throws CIMXMLParseException { - // - - Vector rtnV = new Vector(); - - // CLASS - Element[] classElementA = searchNodes(pIRetValE, "CLASS", 0, Integer.MAX_VALUE, false); - if (classElementA != null) { - for (int i = 0; i < classElementA.length; i++) { - Element classE = classElementA[i]; - CIMClass c = parseCLASS(classE); - rtnV.add(c); - } - return rtnV; - } - - // INSTANCE - Element[] instElementA = searchNodes(pIRetValE, "INSTANCE", 0, Integer.MAX_VALUE, false); - if (instElementA != null) { - for (int i = 0; i < instElementA.length; i++) { - Element instanceE = instElementA[i]; - CIMInstance inst = parseINSTANCE(instanceE); - rtnV.add(inst); - } - return rtnV; - } - - // CLASSNAME - Element[] classNameElementA = searchNodes(pIRetValE, "CLASSNAME", 0, Integer.MAX_VALUE, - false); - if (classNameElementA != null) { - for (int i = 0; i < classNameElementA.length; i++) { - Element classnameE = classNameElementA[i]; - CIMObjectPath op = parseCLASSNAME(classnameE); - rtnV.add(op); - } - return rtnV; - } - - // INSTANCENAME - Element[] instNameElementA = searchNodes(pIRetValE, "INSTANCENAME", 0, Integer.MAX_VALUE, - false); - if (instNameElementA != null) { - for (int i = 0; i < instNameElementA.length; i++) { - Element instancenameE = instNameElementA[i]; - CIMObjectPath op = parseINSTANCENAME(instancenameE); - rtnV.add(op); - } - return rtnV; - } - - // INSTANCEPATH - Element[] instpathElementA = searchNodes(pIRetValE, "INSTANCEPATH", 0, Integer.MAX_VALUE, - false); - if (instpathElementA != null) { - for (int i = 0; i < instpathElementA.length; i++) { - Element instancePathE = instpathElementA[i]; - CIMObjectPath op = parseINSTANCEPATH(instancePathE); - rtnV.add(op); - } - return rtnV; - } - - // OBJECTPATH - Element[] objPathElementA = searchNodes(pIRetValE, "OBJECTPATH", 0, Integer.MAX_VALUE, - false); - if (objPathElementA != null) { - for (int i = 0; i < objPathElementA.length; i++) { - Element objectpathE = objPathElementA[i]; - CIMObjectPath op = parseOBJECTPATH(objectpathE); - rtnV.add(op); - } - return rtnV; - } - - // VALUE - Element[] valueElementA = searchNodes(pIRetValE, "VALUE", 0, Integer.MAX_VALUE, false); - if (valueElementA != null) { - for (int i = 0; i < valueElementA.length; i++) { - Element valueE = valueElementA[i]; - TypedValue tv = parseVALUE(valueE); - rtnV.add(tv.getValue()); - } - return rtnV; - } - - // VALUE.ARRAY - Element[] valueArrayElementA = searchNodes(pIRetValE, "VALUE.ARRAY", 0, 1, false); - if (valueArrayElementA != null) { - Element valuearrayE = valueArrayElementA[0]; - TypedValue tv = parseVALUEARRAY(valuearrayE); - rtnV.add(tv.getValue()); - return rtnV; - } - - // VALUE.REFERENCE - Element[] valRefElementA = searchNodes(pIRetValE, "VALUE.REFERENCE", 0, 1, false); - if (valRefElementA != null) { - Element valuereferenceE = valRefElementA[0]; - CIMObjectPath op = parseVALUEREFERENCE(valuereferenceE); - rtnV.add(op); - return rtnV; - } - - // VALUE.OBJECT - Element[] valObjElementA = searchNodes(pIRetValE, "VALUE.OBJECT", 0, Integer.MAX_VALUE, - false); - if (valObjElementA != null) { - for (int i = 0; i < valObjElementA.length; i++) { - Element valueobjectE = valObjElementA[i]; - CIMNamedElementInterface obj = parseVALUEOBJECT(valueobjectE); - rtnV.add(obj); - } - return rtnV; - } - - // VALUE.NAMEDINSTANCE - Element[] valNamedInstElementA = searchNodes(pIRetValE, "VALUE.NAMEDINSTANCE", 0, - Integer.MAX_VALUE, false); - if (valNamedInstElementA != null) { - for (int i = 0; i < valNamedInstElementA.length; i++) { - Element valuenamedisntanceE = valNamedInstElementA[i]; - CIMInstance inst = parseVALUENAMEDINSTANCE(valuenamedisntanceE); - rtnV.add(inst); - } - return rtnV; - } - - // VALUE.INSTANCEWITHPATH - Element[] valInstWithPathElementA = searchNodes(pIRetValE, "VALUE.INSTANCEWITHPATH", 0, - Integer.MAX_VALUE, false); - if (valInstWithPathElementA != null) { - for (int i = 0; i < valInstWithPathElementA.length; i++) { - Element valueinstancewithpathE = valInstWithPathElementA[i]; - CIMInstance inst = parseVALUEINSTANCEWITHPATH(valueinstancewithpathE); - rtnV.add(inst); - } - return rtnV; - } - - // VALUE.OBJECTWITHPATH - Element[] valObjWithPathElementA = searchNodes(pIRetValE, "VALUE.OBJECTWITHPATH", 0, - Integer.MAX_VALUE, false); - if (valObjWithPathElementA != null) { - for (int i = 0; i < valObjWithPathElementA.length; i++) { - Element valueobjectwithpathE = valObjWithPathElementA[i]; - CIMNamedElementInterface namedIF = parseVALUEOBJECTWITHPATH(valueobjectwithpathE); - rtnV.add(namedIF); - } - return rtnV; - } - - // VALUE.OBJECTWITHLOCALPATH - Element[] valObjWithLocalPathElementA = searchNodes(pIRetValE, "VALUE.OBJECTWITHLOCALPATH", - 0, Integer.MAX_VALUE, false); - if (valObjWithLocalPathElementA != null) { - for (int i = 0; i < valObjWithLocalPathElementA.length; i++) { - Element valueobjectwithlocalpathE = valObjWithLocalPathElementA[i]; - CIMNamedElementInterface namedIF = parseVALUEOBJECTWITHLOCALPATH(valueobjectwithlocalpathE); - rtnV.add(namedIF); - } - return rtnV; - } - - // QUALIFIER.DECLARATION - Element[] qualiDeclElementA = searchNodes(pIRetValE, "QUALIFIER.DECLARATION", 0, - Integer.MAX_VALUE, false); - if (qualiDeclElementA != null) { - for (int i = 0; i < qualiDeclElementA.length; i++) { - Element qualifierdeclarationE = qualiDeclElementA[i]; - CIMQualifierType o = parseQUALIFIERDECLARATION(qualifierdeclarationE); - rtnV.add(o); - } - return rtnV; - } - checkOtherNodes(pIRetValE, nodesIRETURNVALUE); - return rtnV; - } - - /** - * parseObject - * - * @param pRootE - * @return Object - * @throws CIMXMLParseException - */ - public static Object parseObject(Element pRootE) throws CIMXMLParseException { - Object o = null; - String nodeName = pRootE.getNodeName(); - if (nodeName.equalsIgnoreCase("INSTANCE")) { - o = parseINSTANCE(pRootE); - } else if (nodeName.equalsIgnoreCase("VALUE.NAMEDINSTANCE")) { - o = parseVALUENAMEDINSTANCE(pRootE); - } else if (nodeName.equalsIgnoreCase("VALUE.NAMEDOBJECT")) { - o = parseVALUENAMEDOBJECT(pRootE); - } else if (nodeName.equalsIgnoreCase("VALUE.OBJECTWITHPATH")) { - o = parseVALUEOBJECTWITHPATH(pRootE); - } else if (nodeName.equalsIgnoreCase("VALUE.OBJECTWITHLOCALPATH")) { - o = parseVALUEOBJECTWITHLOCALPATH(pRootE); - } else if (nodeName.equalsIgnoreCase("CLASS")) { - o = parseCLASS(pRootE); - } else if (nodeName.equalsIgnoreCase("CLASSPATH")) { - o = parseCLASSPATH(pRootE); - } else if (nodeName.equalsIgnoreCase("LOCALCLASSPATH")) { - o = parseLOCALCLASSPATH(pRootE); - } else if (nodeName.equalsIgnoreCase("OBJECTPATH")) { - o = parseOBJECTPATH(pRootE); - } else if (nodeName.equalsIgnoreCase("CLASSNAME")) { - o = parseCLASSNAME(pRootE); - } else if (nodeName.equalsIgnoreCase("INSTANCEPATH")) { - o = parseINSTANCEPATH(pRootE); - } else if (nodeName.equalsIgnoreCase("LOCALINSTANCEPATH")) { - o = parseLOCALINSTANCEPATH(pRootE); - } else if (nodeName.equalsIgnoreCase("INSTANCENAME")) { - o = parseINSTANCENAME(pRootE); - } else if (nodeName.equalsIgnoreCase("QUALIFIER")) { - o = parseQUALIFIER(pRootE); - } else if (nodeName.equalsIgnoreCase("PROPERTY")) { - o = parsePROPERTY(pRootE); - } else if (nodeName.equalsIgnoreCase("PROPERTY.ARRAY")) { - o = parsePROPERTYARRAY(pRootE); - } else if (nodeName.equalsIgnoreCase("PROPERTY.REFERENCE")) { - o = parsePROPERTYREFERENCE(pRootE); - } else if (nodeName.equalsIgnoreCase("METHOD")) { - o = parseMETHOD(pRootE); - } else if (nodeName.equalsIgnoreCase("PARAMETER")) { - o = parsePARAMETER(pRootE); - } else if (nodeName.equalsIgnoreCase("PARAMETER.REFERENCE")) { - o = parsePARAMETERREFERENCE(pRootE); - } else if (nodeName.equalsIgnoreCase("PARAMETER.ARRAY")) { - o = parsePARAMETERARRAY(pRootE); - } else if (nodeName.equalsIgnoreCase("PARAMETER.REFARRAY")) { - o = parsePARAMETERREFARRAY(pRootE); - } - return o; - } - - // /////////////////////////////////////////////////////////////////////////////////////////// - - /** - * hasNodes - * - * @param pParentE - * @return boolean - */ - private static boolean hasNodes(Element pParentE) { - NodeList nl = pParentE.getChildNodes(); - if (nl == null || nl.getLength() == 0) return false; - for (int i = 0; i < nl.getLength(); i++) { - Node n = nl.item(i); - if (!(n instanceof Text) || !("".equalsIgnoreCase(n.getNodeValue().trim()))) return true; - } - return false; - } - - /** - * hasTypeAttrsInNodes - * - * SVC CIMOM sends typed CIM-XML elements in a non-standard way. The TYPE - * attribute is included in the VALUE or VALUE.ARRAY element not in the - * enclosing element as the standard says. - * - * @param pParentE - * @return boolean - */ - private static boolean hasTypeAttrsInNodes(Element pParentE) { - NodeList nl = pParentE.getChildNodes(); - if (nl == null || nl.getLength() == 0) return false; - for (int i = 0; i < nl.getLength(); i++) { - Node n = nl.item(i); - String name = n.getNodeName(); - if ("VALUE".equalsIgnoreCase(name) || "VALUE.ARRAY".equalsIgnoreCase(name)) { - NamedNodeMap nm = n.getAttributes(); - if (nm != null - && (nm.getNamedItem("TYPE") != null || nm.getNamedItem("PARAMTYPE") != null)) return true; - } - } - return false; - } - - private static final HashMap NODENAME_HASH = new HashMap(); - - private static void initNodeNameHash(String[] pEnumA) { - for (int i = 0; i < pEnumA.length; i++) - NODENAME_HASH.put(pEnumA[i], pEnumA[i]); - } - - static { - initNodeNameHash(new String[] { "CIM", "DECLARATION", "DECLGROUP", "DECLGROUP.WITHNAME", - "DECLGROUP.WITHPATH", "QUALIFIER.DECLARATION", "SCOPE", "VALUE", "VALUE.ARRAY", - "VALUE.REFERENCE", "VALUE.REFARRAY", "VALUE.OBJECT", "VALUE.NAMEDINSTANCE", - "VALUE.NAMEDOBJECT", "VALUE.OBJECTWITHLOCALPATH", "VALUE.OBJECTWITHPATH", - "VALUE.NULL", "VALUE.INSTANCEWITHPATH", "NAMESPACEPATH", "LOCALNAMESPACEPATH", - "HOST", "NAMESPACE", "CLASSPATH", "LOCALCLASSPATH", "CLASSNAME", "INSTANCEPATH", - "LOCALINSTANCEPATH", "INSTANCENAME", "OBJECTPATH", "KEYBINDING", "KEYVALUE", - "CLASS", "INSTANCE", "QUALIFIER", "PROPERTY", "PROPERTY.ARRAY", - "PROPERTY.REFERENCE", "METHOD", "PARAMETER", "PARAMETER.REFERENCE", - "PARAMETER.ARRAY", "PARAMETER.REFARRAY", "MESSAGE", "MULTIREQ", "MULTIEXPREQ", - "SIMPLEREQ", "SIMPLEEXPREQ", "IMETHODCALL", "METHODCALL", "EXPMETHODCALL", - "PARAMVALUE", "IPARAMVALUE", "EXPPARAMVALUE", "MULTIRSP", "MULTIEXPRSP", - "SIMPLERSP", "SIMPLEEXPRSP", "METHODRESPONSE", "EXPMETHODRESPONSE", - "IMETHODRESPONSE", "ERROR", "RETURNVALUE", "IRETURNVALUE", "CORRELATOR" }); - } - - /** - * checkOtherNodes - * - * @param pParentE - * @param pAllowedChildNodes - */ - private static void checkOtherNodes(Element pParentE, String[] pAllowedChildNodes) - throws CIMXMLParseException { - NodeList nl = pParentE.getChildNodes(); - if (nl == null || nl.getLength() == 0) return; - for (int i = 0; i < nl.getLength(); i++) { - Node n = nl.item(i); - if (n instanceof Text && "".equalsIgnoreCase(n.getNodeValue().trim())) continue; - boolean found = false; - String name = n.getNodeName().toUpperCase(); - for (int j = 0; j < pAllowedChildNodes.length; j++) { - if (pAllowedChildNodes[j].equalsIgnoreCase(name)) { - found = true; - break; - } - } - if (!found && NODENAME_HASH.containsKey(name)) throw new CIMXMLParseException(pParentE - .getNodeName() - + " element contains invalid child element " + name + "!"); - } - } - - /** - * searchNodes - * - * @param pParentE - * @param pTagName - * @return Element[] - */ - public static Element[] searchNodes(Element pParentE, String pTagName) { - // return all of child nodes immediately below the parent - // return null if not found - NodeList nl = pParentE.getChildNodes(); - if (nl == null || nl.getLength() == 0) return null; - Vector resElementV = new Vector(); - for (int i = 0; i < nl.getLength(); i++) { - Node n = nl.item(i); - if (n.getNodeName().equals(pTagName)) { - resElementV.add(n); - } - } - return resElementV.toArray(new Element[0]); - } - - /** - * searchNodes - * - * @param pParentE - * @param pTagName - * @param pMin - * @param pMax - * @param pAllowOtherNodes - * @return Element[] - * @throws CIMXMLParseException - */ - public static Element[] searchNodes(Element pParentE, String pTagName, int pMin, int pMax, - boolean pAllowOtherNodes) throws CIMXMLParseException { - // return all child nodes immediately below parent, null if none found - - NodeList nl = pParentE.getChildNodes(); - if (nl == null || nl.getLength() == 0) { - if (pMin > 0) throw new CIMXMLParseException(pParentE.getNodeName() - + " element must have at least " + pMin + " " + pTagName + " child element(s)!"); - return null; - } - - String otherNode = null; - Vector resElementV = new Vector(); - for (int i = 0; i < nl.getLength(); i++) { - Node n = nl.item(i); - String name = n.getNodeName().toUpperCase(); - if (name.equals(pTagName)) { - resElementV.add(n); - } else if (NODENAME_HASH.containsKey(name)) { - otherNode = name; - } - } - - if (resElementV.size() < pMin) throw new CIMXMLParseException(pParentE.getNodeName() - + " element must have at least " + pMin + " " + pTagName + " child element(s)!"); - if (resElementV.size() > pMax) throw new CIMXMLParseException(pParentE.getNodeName() - + " element can have no more than " + pMax + " " + pTagName + " child element(s)!"); - if (resElementV.size() > 0 && !pAllowOtherNodes && otherNode != null) throw new CIMXMLParseException( - pParentE.getNodeName() + " element cannot have " + otherNode - + " child element(s) when it already has " + pTagName + " element(s)!"); - if (resElementV.size() == 0) return null; - - return resElementV.toArray(new Element[0]); - } - - /** - * searchFirstNode - * - * @param pParentE - * @param pTagName - * @return Node - */ - public static Node searchFirstNode(Element pParentE, String pTagName) { - // return the first node which matches to the specific name - // return null if not found - NodeList nl = pParentE.getChildNodes(); - for (int i = 0; i < nl.getLength(); i++) { - Node n = nl.item(i); - if (n.getNodeName().equals(pTagName)) { return n; } - } - return null; - } - - /** - * searchAttribute - * - * @param pParentN - * @param pAttrName - * @return Node - */ - public static Node searchAttribute(Node pParentN, String pAttrName) { - // return the attribute node with the specific name - NamedNodeMap nnm = pParentN.getAttributes(); - return nnm.getNamedItem(pAttrName); - } - - /** - * searchFirstChild - * - * @param pParentE - * @return Node - */ - public static Node searchFirstChild(Element pParentE) { - // return the first node which matches to the specific name - // return null if not found - return pParentE.getFirstChild(); - } - - /** - * createJavaObject - * - * @param pTypeStr - * @param pValue - * @return Object - * @throws CIMXMLParseException - */ - public static Object createJavaObject(String pTypeStr, String pValue) - throws CIMXMLParseException { - // return a java object with the specific type - if (pTypeStr == null) pTypeStr = MOF.DT_STR; - if (MOF.NULL.equalsIgnoreCase(pTypeStr)) return null; - Object o = null; - CIMDataType cimType = parseTypeStr(pTypeStr, false); - int radix = 10; - - if (pTypeStr.toLowerCase().startsWith("sint") || pTypeStr.toLowerCase().startsWith("uint")) { - pValue = pValue.toLowerCase(); - if (pValue.startsWith("0x") || pValue.startsWith("+0x") || pValue.startsWith("-0x")) { - radix = 16; - if (pValue.startsWith("-")) pValue = "-" + pValue.substring(3); - else pValue = pValue.substring(pValue.indexOf('x') + 1); - } - } - - switch (cimType.getType()) { - case CIMDataType.UINT8: - o = new UnsignedInteger8(Short.parseShort(pValue, radix)); - break; - case CIMDataType.UINT16: - o = new UnsignedInteger16(Integer.parseInt(pValue, radix)); - break; - case CIMDataType.UINT32: - o = new UnsignedInteger32(Long.parseLong(pValue, radix)); - break; - case CIMDataType.UINT64: - o = new UnsignedInteger64(new BigInteger(pValue, radix)); - break; - case CIMDataType.SINT8: - o = Byte.valueOf(pValue, radix); - break; - case CIMDataType.SINT16: - o = Short.valueOf(pValue, radix); - break; - case CIMDataType.SINT32: - o = Integer.valueOf(pValue, radix); - break; - case CIMDataType.SINT64: - o = Long.valueOf(pValue, radix); - break; - case CIMDataType.STRING: - o = pValue; - break; - case CIMDataType.BOOLEAN: - o = Boolean.valueOf(pValue); - break; - case CIMDataType.REAL32: - o = new Float(pValue); - break; - case CIMDataType.REAL64: - if (WBEMConfiguration.getGlobalConfiguration().verifyJavaLangDoubleStrings()) { - if (Util.isBadDoubleString(pValue)) throw new IllegalArgumentException( - "Double value string hangs older JVMs!\n" + pValue); - } - o = new Double(pValue); - break; - case CIMDataType.DATETIME: - o = getDateTime(pValue); - break; - case CIMDataType.REFERENCE: - o = new CIMObjectPath(pValue); - break; - case CIMDataType.CHAR16: - o = Character.valueOf(pValue.charAt(0)); - break; - // case CIMDataType.OBJECT: o = new CIMInstance(); break; //TODO - // case CIMDataType.CLASS: o = new CIMClass(value); break; //TODO - } - return o; - } - - private static CIMDateTime getDateTime(String pValue) throws CIMXMLParseException { - try { - return new CIMDateTimeAbsolute(pValue); - } catch (IllegalArgumentException eAbs) { - try { - return new CIMDateTimeInterval(pValue); - } catch (IllegalArgumentException eInt) { - throw new CIMXMLParseException("Failed to parse dateTime string: " + pValue + "!\n" - + "CIMDateTimeAbsolute parsing error:\n" + eAbs.getMessage() + "\n" - + "CIMDateTimeInterval parsing error:\n" + eInt.getMessage()); - } - } - } - - /** - * parseSIMPLEEXPRSP - * - * @param pSimpleExpRspE - * @return CIMResponse - * @throws CIMXMLParseException - */ - public static CIMResponse parseSIMPLEEXPRSP(Element pSimpleExpRspE) throws CIMXMLParseException { - // - - // EXPMETHODRESPONSE - Element[] expmethodresponseA = searchNodes(pSimpleExpRspE, "EXPMETHODRESPONSE", 1, 1, false); - if (expmethodresponseA != null) return parseEXPMETHODRESPONSE(expmethodresponseA[0]); - - throw new CIMXMLParseException( - "SIMPLEEXPRSP element missing EXPMETHODRESPONSE child element!"); - } - - /** - * parseMULTIEXPRSP - * - * @param pMultiExpRspE - * @return CIMResponse - * @throws CIMXMLParseException - */ - public static CIMResponse parseMULTIEXPRSP(Element pMultiExpRspE) throws CIMXMLParseException { - // - - Element[] multiExpRespElementA = searchNodes(pMultiExpRspE, "SIMPLEEXPRSP", 2, - Integer.MAX_VALUE, false); - if (multiExpRespElementA != null) { - CIMResponse multiExpRsp = new CIMResponse(); - for (int i = 0; i < multiExpRespElementA.length; i++) { - Element methodresponseE = multiExpRespElementA[i]; - CIMResponse rsp = parseSIMPLEEXPRSP(methodresponseE); - rsp.setMethod("SIMPLEEXPRSP"); - multiExpRsp.addResponse(rsp); - } - return multiExpRsp; - } - - throw new CIMXMLParseException("MULTIEXPRSP element missing SIMPLEEXPRSP child element!"); - } - - private static final String[] nodesEXPMETHODRESPONSE = { "ERROR", "IRETURNVALUE" }; - - /** - * parseEXPMETHODRESPONSE - * - * @param pExpMethodResponseE - * @return CIMResponse - * @throws CIMXMLParseException - */ - public static CIMResponse parseEXPMETHODRESPONSE(Element pExpMethodResponseE) - throws CIMXMLParseException { - // - - CIMResponse response = new CIMResponse(); - - if (attribute(pExpMethodResponseE, "NAME") == null) throw new CIMXMLParseException( - "EXPMETHODRESPONSE element missing NAME attribute!"); - - // ERROR - Element[] errorA = searchNodes(pExpMethodResponseE, "ERROR", 0, 1, false); - if (errorA != null) { - WBEMException exception = parseERROR(errorA[0]); - response.setError(exception); - return response; - } - - // RETURNVALUE - Element[] retValElementA = searchNodes(pExpMethodResponseE, "IRETURNVALUE", 0, 1, false); - if (retValElementA != null) { - Vector v = new Vector(); - Element returnvalueE = retValElementA[0]; - v.add(parseIRETURNVALUE(returnvalueE)); - response.setReturnValue(v); - return response; - } - - checkOtherNodes(pExpMethodResponseE, nodesEXPMETHODRESPONSE); - - return response; - } - - private static final String nodesCORRELATOR[] = { "VALUE" }; - - /** - * parseCORRELATOR - * - * @param pCorrelatorE - * @throws CIMXMLParseException - * */ - public static void parseCORRELATOR(Element pCorrelatorE) throws CIMXMLParseException { - // - // - String name = attribute(pCorrelatorE, "NAME"); - if (name == null) throw new CIMXMLParseException( - "CORRELATOR element missing NAME attribute!"); - String type = attribute(pCorrelatorE, "TYPE"); - if (type == null) throw new CIMXMLParseException( - "CORRELATOR element missing TYPE attribute!"); - - // VALUE - Element[] valueA = searchNodes(pCorrelatorE, "VALUE", 1, 1, false); - if (valueA != null) { - // TypedValue tVal = parseVALUE(valueA[0]); - } - - checkOtherNodes(pCorrelatorE, nodesCORRELATOR); - } -} +/* + CIMXMLParserImpl.java + + (C) Copyright IBM Corp. 2005, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1464860 2006-05-15 lupusalex No default value for VALUETYPE assumed + * 1535756 2006-08-07 lupusalex Make code warning free + * 1547910 2006-09-05 ebak parseIMETHODCALL() CIMObjectPath parsing problem + * 1547908 2006-09-05 ebak parseKEYBINDING() creates incorrect reference type + * 1545915 2006-09-05 ebak Wrong parsing of IMETHODCALL request + * 1660756 2007-03-02 ebak Embedded object support + * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus + * 1669961 2006-04-16 lupusalex CIMTypedElement.getType() =>getDataType() + * 1712656 2007-05-04 ebak Correct type identification for SVC CIMOM + * 1714878 2007-05-08 ebak Empty string property values are parsed as nulls + * 1737141 2007-06-18 ebak Sync up with JSR48 evolution + * 1769504 2007-08-15 ebak Type identification for VALUETYPE="numeric" + * 1783288 2007-09-10 ebak CIMClass.isAssociation() not working for retrieved classes. + * 1820763 2007-10-29 ebak Supporting the EmbeddedInstance qualifier + * 1827728 2007-11-20 ebak rework: embeddedInstances: attribute EmbeddedObject not set + * 1848607 2007-12-11 ebak Strict EmbeddedObject types + * 1944875 2008-05-29 blaschke-oss Indications with embedded objects are not accepted + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2210455 2008-10-30 blaschke-oss Enhance javadoc, fix potential null pointers + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2714989 2009-03-26 blaschke-oss Code cleanup from redundant null check et al + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2823494 2009-08-03 rgummada Change Boolean constructor to static + * 2860081 2009-09-17 raman_arora Pull Enumeration Feature (DOM Parser) + * 2957387 2010-03-03 blaschke-oss EmbededObject XML attribute must not be all uppercases + * 3023143 2010-07-01 blaschke-oss CIMXMLParserImpl uses # constructor instead of valueOf + * 3027479 2010-07-09 blaschke-oss Dead store to local variable + * 3027615 2010-07-12 blaschke-oss Use CLASS_ARRAY_T instead of new CIMDataType(CLASS,0) + * 3293248 2011-05-03 blaschke-oss Support for CIM_ERROR instances within ERROR + * 3297028 2011-05-03 blaschke-oss Instances contain CIMClassProperty with DOM parser + * 3411944 2011-09-20 blaschke-oss createJavaObject exception with hex uint + * 3513353 2012-03-30 blaschke-oss TCK: CIMDataType arrays must have length >= 1 + * 3513349 2012-03-31 blaschke-oss TCK: CIMDataType must not accept null string + * 3466280 2012-04-23 blaschke-oss get instance failure for CIM_IndicationSubscription + * 3521119 2012-04-24 blaschke-oss JSR48 1.0.0: remove CIMObjectPath 2/3/4-parm ctors + * 3526679 2012-05-14 blaschke-oss DOM parser ignores ERROR node CODE + * 3572993 2012-10-01 blaschke-oss parseDouble("2.2250738585072012e-308") DoS vulnerability + * 3598613 2013-01-11 blaschke-oss different data type in cim instance and cim object path + * 2616 2013-02-23 blaschke-oss Add new API WBEMClientSBLIM.sendIndication() + * 2636 2013-05-08 blaschke-oss Nested embedded instances cause CIMXMLParseException + * 2640 2013-05-11 blaschke-oss Multiple CDATA parsing broken in DOM parser + * 2668 2013-09-24 blaschke-oss Potential null pointer exception in parseCIM + * 2669 2013-09-24 blaschke-oss Potential null pointer exception in parseMESSAGE + * 2670 2013-09-25 blaschke-oss NAME attribute not required by DOM parser + * 2671 2013-09-25 blaschke-oss Potential null pointer exception in parseERROR + * 2675 2013-09-27 blaschke-oss CIMXMLParseException messages should contain element name + * 2676 2013-09-27 blaschke-oss parseMULTI(EXP)REQ looking for wrong child elements + * 2678 2013-09-30 blaschke-oss parseMULTI___ allows one SIMPLE___ child element + * 2679 2013-10-01 blaschke-oss parseIMETHODCALL requires one IPARAMVALUE child element + * 2680 2013-10-02 blaschke-oss IPARAMVALUE parsing broken on DOM/SAX + * 2681 2013-10-02 blaschke-oss parseQUALIFIERDECLARATION does not require TYPE attribute + * 2683 2013-10-07 blaschke-oss KEYVALUE VALUETYPE optional, "string" default + * 2684 2013-10-07 blaschke-oss parseEXPMETHODRESPONSE has several issues + * 2685 2013-10-07 blaschke-oss Element.getAttribute returns empty string if no attribute + * 2686 2013-10-10 blaschke-oss parseEXPPARAMVALUE allows 2+ children, prohibits 0 + * 2688 2013-10-10 blaschke-oss parseMETHODCALL looks for CIMName attribute instead of NAME + * 2537 2013-10-17 blaschke-oss Add new data types for PARAMVALUE + * 2691 2013-10-18 blaschke-oss RETURNVALUE should not require PARAMTYPE attribute + * 2694 2013-10-25 blaschke-oss NAME attribute not required by DOM parser (part 2) + * 2695 2013-10-25 blaschke-oss parseMETHODCALL allows LOCALCLASSPATH and LOCALINSTANCEPATH + * 2696 2013-10-29 blaschke-oss parseIRETURNVALUE ignores VALUE and VALUE.ARRAY + * 2699 2013-11-05 blaschke-oss parseQUALIFIER does not require TYPE attribute + * 2700 2013-11-07 blaschke-oss PROPERTY does not require TYPE attribute + * 2701 2013-11-07 blaschke-oss PROPERTY.ARRAY does not require TYPE attribute + * 2702 2013-11-07 blaschke-oss Bad PROPERTY.ARRAY ARRAYSIZE generates NumberFormatException + * 2703 2013-11-08 blaschke-oss MethodNode should not require TYPE attribute + * 2704 2013-11-11 blaschke-oss PARAMETER does not require TYPE attribute + * 2705 2013-11-11 blaschke-oss PARAMETER.ARRAY does not require TYPE attribute + * 2706 2013-11-11 blaschke-oss Bad PARAMETER.REFARRAY ARRAYSIZE generates NumberFormatException + * 2707 2013-11-12 blaschke-oss INSTANCENAME ignores KEYVALUE and VALUE.REFERENCE children + * 2710 2013-11-13 blaschke-oss parseVALUEOBJECTWITH(LOCAL)PATH ignores (LOCAL)CLASSPATH child + * 2711 2013-11-13 blaschke-oss LOCALNAMESPACEPATH allows 0 NAMESPACE children + * 2713 2013-11-22 blaschke-oss Enforce loose validation of CIM-XML documents + * 2715 2013-11-26 blaschke-oss Add VALUE.NULL support + * 2538 2013-11-28 blaschke-oss CR14: Support new CORRELATOR element + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.StringReader; +import java.math.BigInteger; +import java.util.Comparator; +import java.util.HashMap; +import java.util.TreeMap; +import java.util.Vector; +import java.util.logging.Level; +import org.metricshub.wbem.javax.cim.CIMArgument; +import org.metricshub.wbem.javax.cim.CIMClass; +import org.metricshub.wbem.javax.cim.CIMClassProperty; +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMDateTime; +import org.metricshub.wbem.javax.cim.CIMDateTimeAbsolute; +import org.metricshub.wbem.javax.cim.CIMDateTimeInterval; +import org.metricshub.wbem.javax.cim.CIMFlavor; +import org.metricshub.wbem.javax.cim.CIMInstance; +import org.metricshub.wbem.javax.cim.CIMMethod; +import org.metricshub.wbem.javax.cim.CIMNamedElementInterface; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.cim.CIMParameter; +import org.metricshub.wbem.javax.cim.CIMProperty; +import org.metricshub.wbem.javax.cim.CIMQualifier; +import org.metricshub.wbem.javax.cim.CIMQualifierType; +import org.metricshub.wbem.javax.cim.CIMScope; +import org.metricshub.wbem.javax.cim.UnsignedInteger16; +import org.metricshub.wbem.javax.cim.UnsignedInteger32; +import org.metricshub.wbem.javax.cim.UnsignedInteger64; +import org.metricshub.wbem.javax.cim.UnsignedInteger8; +import org.metricshub.wbem.javax.wbem.WBEMException; +import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMHelper; +import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMQualifiedElementInterfaceImpl; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; +import org.metricshub.wbem.sblim.cimclient.internal.util.MOF; +import org.metricshub.wbem.sblim.cimclient.internal.util.Util; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfiguration; +import org.metricshub.wbem.sblim.cimclient.internal.util.XMLHostStr; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; +import org.xml.sax.InputSource; + +/** + * Class CIMXMLParserImpl is the main class of CIM-XML DOM parser. + * + */ +public class CIMXMLParserImpl { + /* + * ebak: local object path - should be used by parseLOCALCLASSPATH(), + * parseLOCALINSTANCEPATH(), parseCLASSNAME(), parseINSTANCENAME(), + * parseCLASS() and parseINSTANCE() + */ + private static LocalPathBuilder cLocalPathBuilder = new LocalPathBuilder(null); + + /** + * setLocalObjectPath + * + * @param pLocalOp + * - empty fields of parsed objectpaths will be substituted by + * fields coming from this parameter + */ + public static void setLocalObjectPath(CIMObjectPath pLocalOp) { + cLocalPathBuilder = new LocalPathBuilder(pLocalOp); + } + + /* + * / local object path + */ + + /** + * parseCIM + * + * @param pCimE + * @return CIMMessage + * @throws CIMXMLParseException + */ + public static CIMMessage parseCIM(Element pCimE) throws CIMXMLParseException { + // + // + Attr cim_cimversionA = (Attr) searchAttribute(pCimE, "CIMVERSION"); + if (cim_cimversionA == null) throw new CIMXMLParseException("CIM element missing CIMVERSION attribute!"); + String cimversion = cim_cimversionA.getNodeValue(); + + Attr cim_dtdversionA = (Attr) searchAttribute(pCimE, "DTDVERSION"); + if (cim_dtdversionA == null) throw new CIMXMLParseException("CIM element missing DTDVERSION attribute!"); + String dtdversion = cim_dtdversionA.getNodeValue(); + + // MESSAGE + Element messageA[] = searchNodes(pCimE, "MESSAGE", 0, 1, false); + if (messageA != null) { + CIMMessage message = parseMESSAGE(cimversion, dtdversion, messageA[0]); + message.setCIMVersion(cimversion); + message.setDTDVersion(dtdversion); + return message; + } + + // DECLARATION + if (searchNodes(pCimE, "DECLARATION", 0, 1, false) != null) throw new CIMXMLParseException( + "DECLARATION element not supported!" + ); + + throw new CIMXMLParseException("CIM element missing required child element!"); + } + + // //////////////////////////////////////////////////////////////////////////////////////// + // Value Elements + // //////////////////////////////////////////////////////////////////////////////////////// + + /** + * parseVALUE - supports the non-standard TYPE attribute + * + * @param pValueE + * @return TypedValue, type is null if no TYPE attribute was found, the + * value is always String, the caller method have to convert it. + * @throws CIMXMLParseException + */ + public static TypedValue parseVALUE(Element pValueE) throws CIMXMLParseException { + // + + String typeStr = attribute(pValueE, "TYPE"); + CIMDataType type = typeStr == null ? null : parseScalarTypeStr(typeStr); + // ebak: empty VALUE element is parsed as empty String + NodeList list = pValueE.getChildNodes(); + StringBuilder valueStr = new StringBuilder(); + for (int i = 0; i < list.getLength(); i++) { + Text t = (Text) list.item(i); + if (t != null) { + String nodeValue = t.getNodeValue(); + if (nodeValue != null) valueStr.append(nodeValue); + } + } + return new TypedValue(type, valueStr.toString()); + } + + /** + * parseVALUEARRAY - supports the non-standard TYPE attribute + * + * @param pValueArrayE + * @return TypedValue, type is null if no TYPE attribute was found, the + * value is always String[], the caller method have to convert it. + * @throws CIMXMLParseException + */ + public static TypedValue parseVALUEARRAY(Element pValueArrayE) throws CIMXMLParseException { + // + String typeStr = attribute(pValueArrayE, "TYPE"); + CIMDataType type = typeStr == null ? null : parseArrayTypeStr(typeStr); + + // Process node list here, order of VALUE/VALUE.NULL IS important + NodeList nl = pValueArrayE.getChildNodes(); + if (nl == null || nl.getLength() == 0) return new TypedValue(type, new String[0]); + Vector resStringV = new Vector(); + for (int i = 0; i < nl.getLength(); i++) { + Node n = nl.item(i); + if (n instanceof Text && "".equalsIgnoreCase(n.getNodeValue().trim())) continue; + String name = n.getNodeName(); + if (name.equals("VALUE")) { + resStringV.add((String) parseVALUE((Element) n).getValue()); + } else if (name.equals("VALUE.NULL")) { + resStringV.add(null); + } else if (NODENAME_HASH.containsKey(name)) { + throw new CIMXMLParseException("VALUE.ARRAY element contains invalid child element " + name + "!"); + } + } + return new TypedValue(type, resStringV.toArray(new String[0])); + } + + /** + * parseVALUEREFERENCE + * + * @param pValuereferenceE + * @return CIMObjectPath + * @throws CIMXMLParseException + */ + public static CIMObjectPath parseVALUEREFERENCE(Element pValuereferenceE) throws CIMXMLParseException { + // + + // CLASSPATH + Element classpathA[] = searchNodes(pValuereferenceE, "CLASSPATH", 0, 1, false); + if (classpathA != null) { + CIMObjectPath op = parseCLASSPATH(classpathA[0]); + return op; + } + + // LOCALCLASSPATH + Element localclasspathA[] = searchNodes(pValuereferenceE, "LOCALCLASSPATH", 0, 1, false); + if (localclasspathA != null) { + CIMObjectPath op = parseLOCALCLASSPATH(localclasspathA[0]); + return op; + } + + // CLASSNAME + Element classnameA[] = searchNodes(pValuereferenceE, "CLASSNAME", 0, 1, false); + if (classnameA != null) { + CIMObjectPath op = parseCLASSNAME(classnameA[0]); + if (op != null && op.getNamespace() != null) { + // LocalPathBuilder includes default namespace in CLASSNAME + // elements, needs to be stripped + op = + new CIMObjectPath( + op.getScheme(), + op.getHost(), + op.getPort(), + null, + op.getObjectName(), + op.getKeys(), + op.getXmlSchemaName() + ); + } + return op; + } + + // INSTANCEPATH + Element instancepathA[] = searchNodes(pValuereferenceE, "INSTANCEPATH", 0, 1, false); + if (instancepathA != null) { + CIMObjectPath op = parseINSTANCEPATH(instancepathA[0]); + return op; + } + + // LOCALINSTANCEPATH + Element localinstancepathA[] = searchNodes(pValuereferenceE, "LOCALINSTANCEPATH", 0, 1, false); + if (localinstancepathA != null) { + CIMObjectPath op = parseLOCALINSTANCEPATH(localinstancepathA[0]); + return op; + } + + // INSTANCENAME + Element instancenameA[] = searchNodes(pValuereferenceE, "INSTANCENAME", 0, 1, false); + if (instancenameA != null) { + CIMObjectPath op = parseINSTANCENAME(instancenameA[0]); + if (op != null && op.getNamespace() != null) { + // LocalPathBuilder includes default namespace in INSTANCENAME + // elements, needs to be stripped + op = + new CIMObjectPath( + op.getScheme(), + op.getHost(), + op.getPort(), + null, + op.getObjectName(), + op.getKeys(), + op.getXmlSchemaName() + ); + } + return op; + } + + throw new CIMXMLParseException("VALUE.REFERENCE element missing required child element!"); + } + + /** + * parseVALUEREFARRAY + * + * @param pValueRefArrayE + * @return CIMObjectPath[] + * @throws CIMXMLParseException + */ + public static CIMObjectPath[] parseVALUEREFARRAY(Element pValueRefArrayE) throws CIMXMLParseException { + // + + // Process node list here, order of VALUE.REFERENCE/VALUE.NULL IS + // important + NodeList nl = pValueRefArrayE.getChildNodes(); + if (nl == null || nl.getLength() == 0) return new CIMObjectPath[0]; + Vector resObjectPathV = new Vector(); + for (int i = 0; i < nl.getLength(); i++) { + Node n = nl.item(i); + if (n instanceof Text && "".equalsIgnoreCase(n.getNodeValue().trim())) continue; + String name = n.getNodeName(); + if (name.equals("VALUE.REFERENCE")) { + resObjectPathV.add(parseVALUEREFERENCE((Element) n)); + } else if (name.equals("VALUE.NULL")) { + resObjectPathV.add(null); + } else if (NODENAME_HASH.containsKey(name)) { + throw new CIMXMLParseException("VALUE.REFARRAY element contains invalid child element " + name + "!"); + } + } + return resObjectPathV.toArray(new CIMObjectPath[0]); + } + + /** + * parseVALUEOBJECT + * + * @param pValueObjectE + * @return CIMNamedElementInterface (CIMClass|CIMInstance) + * @throws CIMXMLParseException + */ + public static CIMNamedElementInterface parseVALUEOBJECT(Element pValueObjectE) throws CIMXMLParseException { + // + + // CLASS + Element classA[] = searchNodes(pValueObjectE, "CLASS", 0, 1, false); + if (classA != null) { + CIMClass obj = parseCLASS(classA[0]); + return obj; + } + + // INSTANCE + Element instanceA[] = searchNodes(pValueObjectE, "INSTANCE", 0, 1, false); + if (instanceA != null) { + CIMInstance obj = parseINSTANCE(instanceA[0]); + return obj; + } + + throw new CIMXMLParseException("VALUE.OBJECT element missing required child element!"); + } + + private static final String nodesVALUENAMEDINSTANCE[] = { "INSTANCENAME", "INSTANCE" }; + + /** + * parseVALUENAMEDINSTANCE + * + * @param pValueNamedInstanceE + * @return CIMInstance + * @throws CIMXMLParseException + */ + public static CIMInstance parseVALUENAMEDINSTANCE(Element pValueNamedInstanceE) throws CIMXMLParseException { + // + + // INSTANCENAME + Element instancenameA[] = searchNodes(pValueNamedInstanceE, "INSTANCENAME", 1, 1, true); + if (instancenameA == null) { + throw new CIMXMLParseException("VALUE.NAMEDINSTANCE element missing INSTANCENAME child element!"); + } + CIMObjectPath op = parseINSTANCENAME(instancenameA[0]); + + // INSTANCE + Element instanceA[] = searchNodes(pValueNamedInstanceE, "INSTANCE", 1, 1, true); + if (instanceA == null) { + throw new CIMXMLParseException("VALUE.NAMEDINSTANCE element missing INSTANCE child element!"); + } + CIMInstance inst = parseINSTANCE(instanceA[0], op); // BB mod + checkOtherNodes(pValueNamedInstanceE, nodesVALUENAMEDINSTANCE); + return inst; + } + + private static final String nodesVALUEINSTANCEWITHPATH[] = { "INSTANCEPATH", "INSTANCE" }; + + /** + * parseVALUEINSTANCEWITHPATH + * + * @param pValueNamedInstanceE + * @return CIMInstance + * @throws CIMXMLParseException + */ + public static CIMInstance parseVALUEINSTANCEWITHPATH(Element pValueNamedInstanceE) throws CIMXMLParseException { + // + + // INSTANCEPATH + Element instancepathA[] = searchNodes(pValueNamedInstanceE, "INSTANCEPATH", 1, 1, true); + if (instancepathA == null) { + throw new CIMXMLParseException("VALUE.INSTANCEWITHPATH element missing INSTANCEPATH child element!"); + } + CIMObjectPath op = parseINSTANCEPATH(instancepathA[0]); + + // INSTANCE + Element instanceA[] = searchNodes(pValueNamedInstanceE, "INSTANCE", 1, 1, true); + if (instanceA == null) { + throw new CIMXMLParseException("VALUE.INSTANCEWITHPATH element missing INSTANCE child element!"); + } + CIMInstance inst = parseINSTANCE(instanceA[0], op); // BB mod + checkOtherNodes(pValueNamedInstanceE, nodesVALUEINSTANCEWITHPATH); + return inst; + } + + private static final String nodesVALUENAMEDOBJECTi[] = { "INSTANCENAME", "INSTANCE" }; + + /** + * parseVALUENAMEDOBJECT + * + * @param pValueNamedObjectE + * @return CIMNamedElementInterface + * @throws CIMXMLParseException + */ + public static CIMNamedElementInterface parseVALUENAMEDOBJECT(Element pValueNamedObjectE) throws CIMXMLParseException { + // + + // CLASS + Element classA[] = searchNodes(pValueNamedObjectE, "CLASS", 0, 1, false); + if (classA != null) { + CIMClass obj = parseCLASS(classA[0]); + // checkOtherNodes(pValueNamedObjectE, nodesVALUENAMEDOBJECTc); + return obj; + } + + // INSTANCENAME + Element instancenameA[] = searchNodes(pValueNamedObjectE, "INSTANCENAME", 0, 1, true); + if (instancenameA != null) { + CIMObjectPath op = parseINSTANCENAME(instancenameA[0]); + + // INSTANCE + Element instanceA[] = searchNodes(pValueNamedObjectE, "INSTANCE", 0, 1, true); + if (instanceA == null) { + throw new CIMXMLParseException("VALUE.NAMEDOBJECT element missing INSTANCE child element!"); + } + CIMInstance inst = parseINSTANCE(instanceA[0], op); // BB mod + checkOtherNodes(pValueNamedObjectE, nodesVALUENAMEDOBJECTi); + return inst; + } + + throw new CIMXMLParseException("VALUE.NAMEDOBJECT element missing required child element!"); + } + + private static final String nodesVALUEOBJECTWITHPATHcls[] = { "CLASSPATH", "CLASS" }; + + private static final String nodesVALUEOBJECTWITHPATHins[] = { "INSTANCEPATH", "INSTANCE" }; + + /** + * parseVALUEOBJECTWITHPATH + * + * @param pValueObjectWithPathE + * @return CIMNamedElementInterface + * @throws CIMXMLParseException + */ + public static CIMNamedElementInterface parseVALUEOBJECTWITHPATH(Element pValueObjectWithPathE) + throws CIMXMLParseException { + // + + // CLASSPATH + Element classpathA[] = searchNodes(pValueObjectWithPathE, "CLASSPATH", 0, 1, true); + if (classpathA != null) { + CIMObjectPath op = parseCLASSPATH(classpathA[0]); + + // CLASS + Element classA[] = searchNodes(pValueObjectWithPathE, "CLASS", 0, 1, true); + if (classA == null) { + throw new CIMXMLParseException("VALUE.OBJECTWITHPATH element missing CLASS child element!"); + } + + CIMClass obj = parseCLASS(classA[0], op); + checkOtherNodes(pValueObjectWithPathE, nodesVALUEOBJECTWITHPATHcls); + return obj; + } + + // INSTANCEPATH + Element instancepathA[] = searchNodes(pValueObjectWithPathE, "INSTANCEPATH", 0, 1, true); + if (instancepathA != null) { + CIMObjectPath op = parseINSTANCEPATH(instancepathA[0]); + + // INSTANCE + Element instanceA[] = searchNodes(pValueObjectWithPathE, "INSTANCE", 0, 1, true); + if (instanceA == null) { + throw new CIMXMLParseException("VALUE.OBJECTWITHPATH element missing INSTANCE child element!"); + } + CIMInstance inst = parseINSTANCE(instanceA[0], op); // BB mod + checkOtherNodes(pValueObjectWithPathE, nodesVALUEOBJECTWITHPATHins); + return inst; + } + + throw new CIMXMLParseException("VALUE.OBJECTWITHPATH element missing required child element!"); + } + + private static final String nodesVALUEOBJECTWITHLOCALPATHcls[] = { "LOCALCLASSPATH", "CLASS" }; + + private static final String nodesVALUEOBJECTWITHLOCALPATHins[] = { "LOCALINSTANCEPATH", "INSTANCE" }; + + /** + * parseVALUEOBJECTWITHLOCALPATH + * + * @param pValueObjectWithLocalPathE + * @return CIMNamedElementInterface + * @throws CIMXMLParseException + */ + public static CIMNamedElementInterface parseVALUEOBJECTWITHLOCALPATH(Element pValueObjectWithLocalPathE) + throws CIMXMLParseException { + // + + // LOCALCLASSPATH + Element localclasspathA[] = searchNodes(pValueObjectWithLocalPathE, "LOCALCLASSPATH", 0, 1, true); + if (localclasspathA != null) { + CIMObjectPath op = parseLOCALCLASSPATH(localclasspathA[0]); + + // CLASS + Element classA[] = searchNodes(pValueObjectWithLocalPathE, "CLASS", 0, 1, true); + if (classA == null) { + throw new CIMXMLParseException("VALUE.OBJECTWITHLOCALPATH element missing CLASS child element!"); + } + + CIMClass obj = parseCLASS(classA[0], op); + checkOtherNodes(pValueObjectWithLocalPathE, nodesVALUEOBJECTWITHLOCALPATHcls); + return obj; + } + + // LOCALINSTANCEPATH + Element localinstancepathA[] = searchNodes(pValueObjectWithLocalPathE, "LOCALINSTANCEPATH", 0, 1, true); + if (localinstancepathA != null) { + CIMObjectPath op = parseLOCALINSTANCEPATH(localinstancepathA[0]); + + // INSTANCE + Element instanceA[] = searchNodes(pValueObjectWithLocalPathE, "INSTANCE", 0, 1, true); + if (instanceA == null) { + throw new CIMXMLParseException("VALUE.OBJECTWITHLOCALPATH element missing INSTANCE child element!"); + } + CIMInstance inst = parseINSTANCE(instanceA[0], op); // BB mod + checkOtherNodes(pValueObjectWithLocalPathE, nodesVALUEOBJECTWITHLOCALPATHins); + return inst; + } + + throw new CIMXMLParseException("VALUE.OBJECTWITHLOCALPATH element missing required child element!"); + } + + // //////////////////////////////////////////////////////////////////////////////////////// + // Naming and Location elements + // //////////////////////////////////////////////////////////////////////////////////////// + + private static final String nodesNAMESPACEPATH[] = { "HOST", "LOCALNAMESPACEPATH" }; + + /** + * parseNAMESPACEPATH + * + * @param pNameSpacePathE + * @return CIMObjectPath + * @throws CIMXMLParseException + */ + public static CIMObjectPath parseNAMESPACEPATH(Element pNameSpacePathE) throws CIMXMLParseException { + // + // HOST + Element hostA[] = searchNodes(pNameSpacePathE, "HOST", 1, 1, true); + if (hostA == null) { + throw new CIMXMLParseException("NAMESPACEPATH element missing HOST child element!"); + } + XMLHostStr xmlHostStr = new XMLHostStr(parseHOST(hostA[0])); + // LOCALNAMESPACE + Element localnamespacepathA[] = searchNodes(pNameSpacePathE, "LOCALNAMESPACEPATH", 1, 1, true); + if (localnamespacepathA == null) { + throw new CIMXMLParseException("NAMESPACEPATH element missing LOCALNAMESPACEPATH child element!"); + } + String nameSpace = parseLOCALNAMESPACEPATH(localnamespacepathA[0]); + /* + * CIMObjectPath( String scheme, String host, String port, String + * namespace, String objectName, CIMProperty[] keys ) + */ + checkOtherNodes(pNameSpacePathE, nodesNAMESPACEPATH); + return new CIMObjectPath( + xmlHostStr.getProtocol(), + xmlHostStr.getHost(), + xmlHostStr.getPort(), + nameSpace, + null, + null + ); + } + + /** + * parseLOCALNAMESPACEPATH + * + * @param pLocalNameSpaceE + * @return String + * @throws CIMXMLParseException + */ + public static String parseLOCALNAMESPACEPATH(Element pLocalNameSpaceE) throws CIMXMLParseException { + // + + Element[] nameSpaceElementA = searchNodes(pLocalNameSpaceE, "NAMESPACE", 1, Integer.MAX_VALUE, false); + if (nameSpaceElementA == null) { + if ( + WBEMConfiguration.getGlobalConfiguration().allowEmptyLocalNameSpacePath() && cLocalPathBuilder != null + ) return cLocalPathBuilder.getBasePath().getNamespace(); + throw new CIMXMLParseException("LOCALNAMESPACEPATH element missing NAMESPACE child element!"); + } + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < nameSpaceElementA.length; i++) { + Element namespaceE = nameSpaceElementA[i]; + String s = parseNAMESPACE(namespaceE); + if (i > 0) sb.append("/" + s); else sb.append(s); + } + return sb.toString(); + } + + /** + * parseHOST + * + * @param pHostE + * @return String + */ + public static String parseHOST(Element pHostE) { + // + + Text valueT = (Text) searchFirstChild(pHostE); + String host = valueT.getNodeValue(); + return host; + } + + private static final String nodesNAMESPACE[] = {}; + + /** + * parseNAMESPACE + * + * @param pNameSpaceE + * @return String + * @throws CIMXMLParseException + */ + public static String parseNAMESPACE(Element pNameSpaceE) throws CIMXMLParseException { + // + // + + Attr namespace_nameA = (Attr) searchAttribute(pNameSpaceE, "NAME"); + if (namespace_nameA == null) throw new CIMXMLParseException("NAMESPACE element missing NAME attribute!"); + String n = namespace_nameA.getValue(); + checkOtherNodes(pNameSpaceE, nodesNAMESPACE); + return n; + } + + private static final String nodesCLASSPATH[] = { "NAMESPACEPATH", "CLASSNAME" }; + + /** + * parseCLASSPATH + * + * @param pClassPathE + * @return CIMObjectPath + * @throws CIMXMLParseException + */ + public static CIMObjectPath parseCLASSPATH(Element pClassPathE) throws CIMXMLParseException { + // + + // NAMESPACEPATH + Element namespacepathA[] = searchNodes(pClassPathE, "NAMESPACEPATH", 1, 1, true); + if (namespacepathA == null) { + throw new CIMXMLParseException("CLASSPATH element missing NAMESPACEPATH child element!"); + } + CIMObjectPath nsPath = parseNAMESPACEPATH(namespacepathA[0]); + // CLASSNAME + Element classnameA[] = searchNodes(pClassPathE, "CLASSNAME", 1, 1, true); + if (classnameA == null) { + throw new CIMXMLParseException("CLASSPATH element missing CLASSNAME child element!"); + } + String className = parseClassName(classnameA[0]); + /* + * CIMObjectPath( String scheme, String host, String port, String + * namespace, String objectName, CIMProperty[] keys ) + */ + checkOtherNodes(pClassPathE, nodesCLASSPATH); + return new CIMObjectPath( + nsPath.getScheme(), + nsPath.getHost(), + nsPath.getPort(), + nsPath.getNamespace(), + className, + null + ); + } + + private static final String nodesLOCALCLASSPATH[] = { "LOCALNAMESPACEPATH", "CLASSNAME" }; + + /** + * parseLOCALCLASSPATH + * + * @param pClassPathE + * @return CIMObjectPath + * @throws CIMXMLParseException + */ + public static CIMObjectPath parseLOCALCLASSPATH(Element pClassPathE) throws CIMXMLParseException { + // + + // NAMESPACEPATH + Element localnamespacepathA[] = searchNodes(pClassPathE, "LOCALNAMESPACEPATH", 1, 1, true); + if (localnamespacepathA == null) { + throw new CIMXMLParseException("LOCALCLASSPATH element missing LOCALNAMESPACEPATH child element!"); + } + String nameSpace = parseLOCALNAMESPACEPATH(localnamespacepathA[0]); + + // CLASSNAME + Element classnameA[] = searchNodes(pClassPathE, "CLASSNAME", 1, 1, true); + if (classnameA == null) { + throw new CIMXMLParseException("LOCALCLASSPATH element missing CLASSNAME child element!"); + } + CIMObjectPath op = parseCLASSNAME(classnameA[0]); + checkOtherNodes(pClassPathE, nodesLOCALCLASSPATH); + return cLocalPathBuilder.build(op.getObjectName(), nameSpace); + } + + private static final String nodesCLASSNAME[] = {}; + + /** + * parseClassName + * + * @param pClassNameE + * @return String + * @throws CIMXMLParseException + */ + public static String parseClassName(Element pClassNameE) throws CIMXMLParseException { + // + // + Attr classname_nameA = (Attr) searchAttribute(pClassNameE, "NAME"); + if (classname_nameA == null) throw new CIMXMLParseException("CLASSNAME element missing NAME attribute!"); + checkOtherNodes(pClassNameE, nodesCLASSNAME); + return classname_nameA.getNodeValue(); + } + + /** + * parseCLASSNAME + * + * @param pClassNameE + * @return CIMObjectPath + * @throws CIMXMLParseException + */ + public static CIMObjectPath parseCLASSNAME(Element pClassNameE) throws CIMXMLParseException { + return cLocalPathBuilder.build(parseClassName(pClassNameE), null); + } + + private static final String nodesINSTANCEPATH[] = { "NAMESPACEPATH", "INSTANCENAME" }; + + /** + * parseINSTANCEPATH + * + * @param pInstancePathE + * @return CIMObjectPath + * @throws CIMXMLParseException + */ + public static CIMObjectPath parseINSTANCEPATH(Element pInstancePathE) throws CIMXMLParseException { + // + + // NAMESPACEPATH + Element namespacepathA[] = searchNodes(pInstancePathE, "NAMESPACEPATH", 1, 1, true); + if (namespacepathA == null) { + throw new CIMXMLParseException("INSTANCEPATH element missing NAMESPACEPATH child element!"); + } + CIMObjectPath nsPath = parseNAMESPACEPATH(namespacepathA[0]); + // INSTANCENAME + Element instancenameA[] = searchNodes(pInstancePathE, "INSTANCENAME", 1, 1, true); + if (instancenameA == null) { + throw new CIMXMLParseException("INSTANCEPATH element missing INSTANCENAME child element!"); + } + CIMObjectPath op = parseINSTANCENAME(instancenameA[0]); + // ebak: change host and namespace + checkOtherNodes(pInstancePathE, nodesINSTANCEPATH); + return new CIMObjectPath( + nsPath.getScheme(), + nsPath.getHost(), + nsPath.getPort(), + nsPath.getNamespace(), + op.getObjectName(), + op.getKeys() + ); + } + + private static final String nodesLOCALINSTANCEPATH[] = { "LOCALNAMESPACEPATH", "INSTANCENAME" }; + + /** + * parseLOCALINSTANCEPATH + * + * @param pLocalInstancePathE + * @return CIMObjectPath + * @throws CIMXMLParseException + */ + public static CIMObjectPath parseLOCALINSTANCEPATH(Element pLocalInstancePathE) throws CIMXMLParseException { + // + + // LOCALNAMESPACEPATH + Element localnamespacepathA[] = searchNodes(pLocalInstancePathE, "LOCALNAMESPACEPATH", 1, 1, true); + if (localnamespacepathA == null) { + throw new CIMXMLParseException("LOCALINSTANCEPATH element missing LOCALNAMESPACEPATH child element!"); + } + String nameSpace = parseLOCALNAMESPACEPATH(localnamespacepathA[0]); + + // INSTANCENAME + Element instancenameA[] = searchNodes(pLocalInstancePathE, "INSTANCENAME", 1, 1, true); + if (instancenameA == null) { + throw new CIMXMLParseException("LOCALINSTANCEPATH element missing INSTANCENAME child element!"); + } + CIMObjectPath op = parseINSTANCENAME(instancenameA[0]); + /* + * CIMObjectPath(String objectName, String namespace, CIMProperty[] + * keys) + */ + checkOtherNodes(pLocalInstancePathE, nodesLOCALINSTANCEPATH); + return cLocalPathBuilder.build(op.getObjectName(), nameSpace, op.getKeys()); + } + + private static final String nodesINSTANCENAME[] = { "KEYBINDING", "KEYVALUE", "VALUE.REFERENCE" }; + + /** + * parseINSTANCENAME + * + * @param pInstanceNameE + * @return CIMObjectPath + * @throws CIMXMLParseException + */ + public static CIMObjectPath parseINSTANCENAME(Element pInstanceNameE) throws CIMXMLParseException { + // + // + Attr instance_classnameA = (Attr) searchAttribute(pInstanceNameE, "CLASSNAME"); + if (instance_classnameA == null) throw new CIMXMLParseException( + "INSTANCENAME element missing CLASSNAME attribute!" + ); + String opClassName = instance_classnameA.getNodeValue(); + + // KEYBINDING + Element[] keyBindingElementA = searchNodes(pInstanceNameE, "KEYBINDING", 0, Integer.MAX_VALUE, false); + if (keyBindingElementA != null) { + CIMProperty[] keys = new CIMProperty[keyBindingElementA.length]; + for (int i = 0; i < keyBindingElementA.length; i++) { + Element keybindingE = keyBindingElementA[i]; + keys[i] = parseKEYBINDING(keybindingE); + } + return cLocalPathBuilder.build(opClassName, null, keys); + } + + // KEYVALUE + Element keyvalueA[] = searchNodes(pInstanceNameE, "KEYVALUE", 0, 1, false); + if (keyvalueA != null) { + CIMProperty[] keys = new CIMProperty[1]; + TypedValue propTypedVal = parseKEYVALUE(keyvalueA[0]); + keys[0] = new CIMProperty("", propTypedVal.getType(), propTypedVal.getValue(), true, false, null); + return cLocalPathBuilder.build(opClassName, null, keys); + } + + // VALUE.REFERENCE + Element valuereferenceA[] = searchNodes(pInstanceNameE, "VALUE.REFERENCE", 0, 1, false); + if (valuereferenceA != null) { + CIMProperty[] keys = new CIMProperty[1]; + CIMObjectPath op = parseVALUEREFERENCE(valuereferenceA[0]); + keys[0] = new CIMProperty("", new CIMDataType(op.getObjectName()), op, true, false, null); + return cLocalPathBuilder.build(opClassName, null, keys); + } + + checkOtherNodes(pInstanceNameE, nodesINSTANCENAME); + + return new CIMObjectPath(null, null, null, null, opClassName, null); + } + + /** + * parseOBJECTPATH + * + * @param pObjectPathE + * @return CIMObjectPath + * @throws CIMXMLParseException + */ + public static CIMObjectPath parseOBJECTPATH(Element pObjectPathE) throws CIMXMLParseException { + // + + // INSTANCEPATH + Element instancepathA[] = searchNodes(pObjectPathE, "INSTANCEPATH", 0, 1, false); + if (instancepathA != null) { + CIMObjectPath op = parseINSTANCEPATH(instancepathA[0]); + return op; + } + + // CLASSPATH + Element classpathA[] = searchNodes(pObjectPathE, "CLASSPATH", 0, 1, false); + if (classpathA != null) { + CIMObjectPath op = parseCLASSPATH(classpathA[0]); + return op; + } + + throw new CIMXMLParseException("OBJECTPATH element missing required child element!"); + } + + /** + * parseKEYBINDING + * + * @param pKeyBindingE + * @return CIMProperty + * @throws CIMXMLParseException + */ + public static CIMProperty parseKEYBINDING(Element pKeyBindingE) throws CIMXMLParseException { + // + // + + Attr keybinding_nameA = (Attr) searchAttribute(pKeyBindingE, "NAME"); + if (keybinding_nameA == null) throw new CIMXMLParseException("KEYBINDING element missing NAME attribute!"); + String propName = keybinding_nameA.getValue(); + + // KEYVALUE + Element keyvalueA[] = searchNodes(pKeyBindingE, "KEYVALUE", 0, 1, false); + if (keyvalueA != null) { + TypedValue propTypedVal = parseKEYVALUE(keyvalueA[0]); + return new CIMProperty(propName, propTypedVal.getType(), propTypedVal.getValue(), true, false, null); + } + + // VALUE.REFERENCE + Element valuereferenceA[] = searchNodes(pKeyBindingE, "VALUE.REFERENCE", 0, 1, false); + if (valuereferenceA != null) { + CIMObjectPath op = parseVALUEREFERENCE(valuereferenceA[0]); + return new CIMProperty(propName, new CIMDataType(op.getObjectName()), op, true, false, null); + } + + throw new CIMXMLParseException("KEYBINDING element missing required child element!"); + } + + private static final TreeMap TYPESTR_MAP = new TreeMap( + new Comparator() { + + public int compare(Object pO1, Object pO2) { + return ((String) pO1).compareToIgnoreCase((String) pO2); + } + } + ); + + static { + TYPESTR_MAP.put(MOF.DT_UINT8, CIMDataType.UINT8_T); + TYPESTR_MAP.put(MOF.DT_UINT16, CIMDataType.UINT16_T); + TYPESTR_MAP.put(MOF.DT_UINT32, CIMDataType.UINT32_T); + TYPESTR_MAP.put(MOF.DT_UINT64, CIMDataType.UINT64_T); + TYPESTR_MAP.put(MOF.DT_SINT8, CIMDataType.SINT8_T); + TYPESTR_MAP.put(MOF.DT_SINT16, CIMDataType.SINT16_T); + TYPESTR_MAP.put(MOF.DT_SINT32, CIMDataType.SINT32_T); + TYPESTR_MAP.put(MOF.DT_SINT64, CIMDataType.SINT64_T); + TYPESTR_MAP.put(MOF.DT_REAL32, CIMDataType.REAL32_T); + TYPESTR_MAP.put(MOF.DT_REAL64, CIMDataType.REAL64_T); + TYPESTR_MAP.put(MOF.DT_CHAR16, CIMDataType.CHAR16_T); + TYPESTR_MAP.put(MOF.DT_STR, CIMDataType.STRING_T); + TYPESTR_MAP.put(MOF.DT_BOOL, CIMDataType.BOOLEAN_T); + TYPESTR_MAP.put(MOF.DT_DATETIME, CIMDataType.DATETIME_T); + // FIXME: ebak: What to do with those types which are not specified by + // MOF's BNF? + TYPESTR_MAP.put(MOF.INVALID, CIMDataType.INVALID_T); + // FIXME: ebak: What is the string representation of OBJECT? + TYPESTR_MAP.put("object", CIMDataType.OBJECT_T); + TYPESTR_MAP.put(MOF.CLASS, CIMDataType.CLASS_T); + TYPESTR_MAP.put(MOF.REFERENCE, new CIMDataType("")); + } + + /** + * parseScalarTypeStr + * + * @param pTypeStr + * @return CIMDataType + * @throws CIMXMLParseException + */ + public static CIMDataType parseScalarTypeStr(String pTypeStr) throws CIMXMLParseException { + return parseTypeStr(pTypeStr, false); + } + + /** + * parseArrayTypeStr + * + * @param pTypeStr + * @return CIMDataType + * @throws CIMXMLParseException + */ + public static CIMDataType parseArrayTypeStr(String pTypeStr) throws CIMXMLParseException { + return parseTypeStr(pTypeStr, true); + } + + /** + * parseTypeStr + * + * @param pTypeStr + * @param pArray + * @return CIMDataType + * @throws CIMXMLParseException + */ + public static CIMDataType parseTypeStr(String pTypeStr, boolean pArray) throws CIMXMLParseException { + if (pTypeStr == null) return pArray ? CIMDataType.STRING_ARRAY_T : CIMDataType.STRING_T; + CIMDataType type = TYPESTR_MAP.get(pTypeStr); + if (type == null) throw new CIMXMLParseException("Unknown TYPE string:" + pTypeStr); + if (pArray) { + if (type.getType() == CIMDataType.REFERENCE) return new CIMDataType(type.getRefClassName(), 0); + return CIMHelper.UnboundedArrayDataType(type.getType()); + } + return type; + } + + /** + * parseKEYVALUE + * + * @param pKeyValueE + * @return TypedValue + * @throws CIMXMLParseException + */ + public static TypedValue parseKEYVALUE(Element pKeyValueE) throws CIMXMLParseException { + /* + * + */ + // ebak: if TYPE attribute is included there is no need to deal with + // VALUETYPE attribute + String typeStr = attribute(pKeyValueE, "TYPE"); + + Text valueT = (Text) searchFirstChild(pKeyValueE); + String valueStr = valueT == null ? null : valueT.getNodeValue(); + + if (typeStr == null) { + String valueTypeStr = attribute(pKeyValueE, "VALUETYPE"); + if (valueTypeStr == null) valueTypeStr = "string"; + ValueTypeHandler vtHandler = new ValueTypeHandler(valueTypeStr, valueStr); + return new TypedValue(vtHandler.getType(), vtHandler.getValue()); + } + Object value = valueStr == null ? "" : createJavaObject(typeStr, valueStr); + return new TypedValue(parseScalarTypeStr(typeStr), value); + } + + /** + * Class ValueTypeHandler determines the value and type of a KEYVALUE XML + * element, when the VALUETYPE attribute is provided instead of the exact + * TYPE attribute. There is a very similar code section in the PULL and SAX + * parser, but that section wasn't made common since in ideal case the DOM + * parser will be removed. + */ + private static class ValueTypeHandler { + private CIMDataType iType; + + private Object iValue; + + /** + * + * Ctor. + * + * @param pValueTypeStr + * @param pValueStr + * @throws CIMXMLParseException + */ + public ValueTypeHandler(String pValueTypeStr, String pValueStr) throws CIMXMLParseException { + if (pValueTypeStr == null) throw new CIMXMLParseException("KEYVALUE element missing VALUETYPE attribute!"); + + if (pValueTypeStr.equals("numeric")) { + if (!setUInt64(pValueStr) && !setSInt64(pValueStr) && !setReal64(pValueStr)) throw new CIMXMLParseException( + "Unparseable \"number\" value: " + pValueStr + " !" + ); + } else if (pValueTypeStr.equals(MOF.DT_STR)) { + if (!setDTAbsolute(pValueStr) && !setDTInterval(pValueStr)) { + this.iValue = pValueStr; + this.iType = CIMDataType.STRING_T; + } + } else if (pValueTypeStr.equals(MOF.DT_BOOL)) { + if (!setBoolean(pValueStr)) throw new CIMXMLParseException( + "Unparseable \"boolean\" value: " + pValueStr + " !" + ); + } else { + throw new CIMXMLParseException( + "KEYVALUE element's VALUETYPE attribute must be " + + MOF.DT_STR + + ", " + + MOF.DT_BOOL + + " or numeric! " + + pValueStr + + " is not allowed!" + ); + } + } + + /** + * + * getType + * + * @return CIMDataType + */ + public CIMDataType getType() { + return this.iType; + } + + /** + * + * getValue + * + * @return Object + */ + public Object getValue() { + return this.iValue; + } + + private boolean setUInt64(String pValue) { + try { + this.iValue = new UnsignedInteger64(pValue); + } catch (NumberFormatException e) { + return false; + } + this.iType = CIMDataType.UINT64_T; + return true; + } + + private boolean setSInt64(String pValue) { + try { + this.iValue = new Long(pValue); + } catch (NumberFormatException e) { + return false; + } + this.iType = CIMDataType.SINT64_T; + return true; + } + + private boolean setReal64(String pValue) { + try { + if (WBEMConfiguration.getGlobalConfiguration().verifyJavaLangDoubleStrings()) { + if (Util.isBadDoubleString(pValue)) return false; + } + this.iValue = new Double(pValue); + } catch (NumberFormatException e) { + return false; + } + this.iType = CIMDataType.REAL64_T; + return true; + } + + private boolean setBoolean(String pValue) { + this.iValue = Boolean.valueOf(pValue); + this.iType = CIMDataType.BOOLEAN_T; + return true; + } + + private boolean setDTAbsolute(String pValue) { + try { + this.iValue = new CIMDateTimeAbsolute(pValue); + } catch (IllegalArgumentException e) { + return false; + } + this.iType = CIMDataType.DATETIME_T; + return true; + } + + private boolean setDTInterval(String pValue) { + try { + this.iValue = new CIMDateTimeInterval(pValue); + } catch (IllegalArgumentException e) { + return false; + } + this.iType = CIMDataType.DATETIME_T; + return true; + } + } + + // //////////////////////////////////////////////////////////////////////////////////////// + // Object Definition Elements + // //////////////////////////////////////////////////////////////////////////////////////// + + private static String attribute(Element pElement, String pName) { + String attrib = pElement.getAttribute(pName); + if (attrib == null || attrib.length() == 0) return null; + return attrib; + } + + private static final String[] nodesCLASS = { + "QUALIFIER", + "PROPERTY", + "PROPERTY.ARRAY", + "PROPERTY.REFERENCE", + "METHOD" + }; + + /** + * parseCLASS + * + * @param pClassE + * @return CIMClass + * @throws CIMXMLParseException + */ + public static CIMClass parseCLASS(Element pClassE) throws CIMXMLParseException { + return parseCLASS(pClassE, null); + } + + /** + * parseCLASS + * + * @param pClassE + * @param pObjectPath + * @return CIMClass + * @throws CIMXMLParseException + */ + public static CIMClass parseCLASS(Element pClassE, CIMObjectPath pObjectPath) throws CIMXMLParseException { + // + // + + Attr class_nameA = (Attr) searchAttribute(pClassE, "NAME"); + if (class_nameA == null) throw new CIMXMLParseException("CLASS element missing NAME attribute!"); + String name = class_nameA.getNodeValue(); + + // Attr superclass_nameA = (Attr)searchAttribute(classE, "SUPERCLASS"); + // String supername = superclass_nameA.getNodeValue(); + + String superClass = attribute(pClassE, "SUPERCLASS"); + + // QUALIFIER + CIMQualifier[] qualis = parseQUALIFIERS(pClassE); + + // PROPERTY + CIMClassProperty[] props = parseCLASSPROPERTIES(pClassE); + + // METHOD + Element[] methodElementA = searchNodes(pClassE, "METHOD", 0, Integer.MAX_VALUE, true); + CIMMethod[] methods; + if (methodElementA != null) { + methods = new CIMMethod[methodElementA.length]; + for (int i = 0; i < methodElementA.length; i++) { + Element methodE = methodElementA[i]; + methods[i] = parseMETHOD(methodE); + } + } else { + methods = null; + } + + /* + * CIMClass( String name, String superclass, CIMQualifier[] qualifiers, + * CIMClassProperty[] props, CIMMethod[] methods ) + * + * return new CIMClass( name, superClass, qualis, props, methods ); + * + * This constructor can provide localPath info. CIMClass( CIMObjectPath + * path, String superclass, CIMQualifier[] qualifiers, + * CIMClassProperty[] props, CIMMethod[] pMethods, boolean + * pIsAssociation, boolean pIsKeyed ) + */ + checkOtherNodes(pClassE, nodesCLASS); + + return new CIMClass( + pObjectPath == null ? cLocalPathBuilder.build(name, null) : pObjectPath, + superClass, + qualis, + props, + methods, + hasAssocQuali(qualis), + hasKeyProp(props) + ); + } + + private static boolean hasAssocQuali(CIMQualifier[] pQualis) { + if (pQualis == null) return false; + for (int i = 0; i < pQualis.length; i++) { + CIMQualifier quali = pQualis[i]; + if ("ASSOCIATION".equalsIgnoreCase(quali.getName()) && Boolean.TRUE.equals(quali.getValue())) return true; + } + return false; + } + + private static boolean hasKeyProp(CIMProperty[] pProps) { + if (pProps == null) return false; + for (int i = 0; i < pProps.length; i++) if (pProps[i].isKey()) return true; + return false; + } + + private static CIMParameter[] parseParameters(Element pMethodE) throws CIMXMLParseException { + // PARAMETER + Vector> paramV = new Vector>(); + Element[] paramElementA = searchNodes(pMethodE, "PARAMETER"); + if (paramElementA != null) { + for (int i = 0; i < paramElementA.length; i++) { + Element parameterE = paramElementA[i]; + CIMParameter p = parsePARAMETER(parameterE); + paramV.add(p); + } + } + + Element[] paramRefElementA = searchNodes(pMethodE, "PARAMETER.REFERENCE"); + if (paramRefElementA != null) { + for (int i = 0; i < paramRefElementA.length; i++) { + Element parameterE = paramRefElementA[i]; + CIMParameter p = parsePARAMETERREFERENCE(parameterE); + paramV.add(p); + } + } + + Element[] paramArrayElementA = searchNodes(pMethodE, "PARAMETER.ARRAY"); + if (paramArrayElementA != null) { + for (int i = 0; i < paramArrayElementA.length; i++) { + Element parameterE = paramArrayElementA[i]; + CIMParameter p = parsePARAMETERARRAY(parameterE); + paramV.add(p); + } + } + + Element[] paramRefArrayElementA = searchNodes(pMethodE, "PARAMETER.REFARRAY"); + if (paramRefArrayElementA != null) { + for (int i = 0; i < paramRefArrayElementA.length; i++) { + Element parameterE = paramRefArrayElementA[i]; + CIMParameter p = parsePARAMETERREFARRAY(parameterE); + paramV.add(p); + } + } + + return paramV.toArray(new CIMParameter[0]); + } + + private static final String nodesMETHOD[] = { + "QUALIFIER", + "PARAMETER", + "PARAMETER.REFERENCE", + "PARAMETER.ARRAY", + "PARAMETER.REFARRAY" + }; + + /** + * parseMETHOD + * + * @param pMethodE + * @return CIMMethod + * @throws CIMXMLParseException + */ + public static CIMMethod parseMETHOD(Element pMethodE) throws CIMXMLParseException { + // + // + + String name = attribute(pMethodE, "NAME"); + if (name == null) throw new CIMXMLParseException("METHOD element missing NAME attribute!"); + EmbObjHandler embObjHandler = new EmbObjHandler(pMethodE); + CIMDataType type = embObjHandler.getType(); + if (type != null && type.isArray()) throw new CIMXMLParseException("Method's type cannot be Array!"); + String classOrigin = attribute(pMethodE, "CLASSORIGIN"); + String propagatedStr = pMethodE.getAttribute("PROPAGATED"); + boolean propagated = "true".equalsIgnoreCase(propagatedStr); + + checkOtherNodes(pMethodE, nodesMETHOD); + + // PARAMETERS + CIMParameter[] params = parseParameters(pMethodE); + // CIMMethod(String name, CIMDataType type, CIMQualifier[] qualifiers, + // CIMParameter[] parameters, boolean propagated, String originClass) + return new CIMMethod(name, type, embObjHandler.getQualifiers(), params, propagated, classOrigin); + } + + private static final String nodesPARAMETER[] = { "QUALIFIER" }; + + /** + * parsePARAMETER + * + * @param pParamE + * @return CIMParameter + * @throws CIMXMLParseException + */ + public static CIMParameter parsePARAMETER(Element pParamE) throws CIMXMLParseException { + String name = attribute(pParamE, "NAME"); + if (name == null) throw new CIMXMLParseException("PARAMETER element missing NAME attribute!"); + if (attribute(pParamE, "TYPE") == null) throw new CIMXMLParseException("PARAMETER element missing TYPE attribute!"); + checkOtherNodes(pParamE, nodesPARAMETER); + EmbObjHandler iEmbObjHandler = new EmbObjHandler(pParamE); + // CIMParameter(String name, CIMDataType type, CIMQualifier[] + // qualifiers) + return new CIMParameter(name, iEmbObjHandler.getType(), iEmbObjHandler.getQualifiers()); + } + + private static final String nodesPARAMETERREFERENCE[] = { "QUALIFIER" }; + + /** + * parsePARAMETERREFERENCE + * + * @param pParamE + * @return CIMParameter + * @throws CIMXMLParseException + */ + public static CIMParameter parsePARAMETERREFERENCE(Element pParamE) throws CIMXMLParseException { + String name = attribute(pParamE, "NAME"); + if (name == null) throw new CIMXMLParseException("PARAMETER.REFERENCE element missing NAME attribute!"); + String referenceClass = attribute(pParamE, "REFERENCECLASS"); + CIMDataType type = new CIMDataType(referenceClass != null ? referenceClass : ""); + checkOtherNodes(pParamE, nodesPARAMETERREFERENCE); + // QUALIFIER + CIMQualifier[] qualis = parseQUALIFIERS(pParamE); + return new CIMParameter(name, type, qualis); + } + + private static final String nodesPARAMETERARRAY[] = { "QUALIFIER" }; + + /** + * parsePARAMETERARRAY + * + * @param pParamE + * @return CIMParameter + * @throws CIMXMLParseException + */ + public static CIMParameter parsePARAMETERARRAY(Element pParamE) throws CIMXMLParseException { + String name = attribute(pParamE, "NAME"); + if (name == null) throw new CIMXMLParseException("PARAMETER.ARRAY element missing NAME attribute!"); + if (attribute(pParamE, "TYPE") == null) throw new CIMXMLParseException( + "PARAMETER.ARRAY element missing TYPE attribute!" + ); + String arraySizeStr = pParamE.getAttribute("ARRAYSIZE"); + try { + if (arraySizeStr.length() > 0) Integer.parseInt(arraySizeStr); + } catch (NumberFormatException e) { + throw new CIMXMLParseException(arraySizeStr + " is not a valid ARRAYSIZE attribute for PARAMETER.ARRAY!"); + } + checkOtherNodes(pParamE, nodesPARAMETERARRAY); + EmbObjHandler iEmbObjHandler = new EmbObjHandler(pParamE); + return new CIMParameter(name, iEmbObjHandler.getArrayType(), iEmbObjHandler.getQualifiers()); + } + + private static final String nodesPARAMETERREFARRAY[] = { "QUALIFIER" }; + + /** + * parsePARAMETERREFARRAY + * + * @param pParamE + * @return CIMParameter + * @throws CIMXMLParseException + */ + public static CIMParameter parsePARAMETERREFARRAY(Element pParamE) throws CIMXMLParseException { + String name = attribute(pParamE, "NAME"); + if (name == null) throw new CIMXMLParseException("PARAMETER.REFARRAY element missing NAME attribute!"); + + String referenceClass = attribute(pParamE, "REFERENCECLASS"); + + int arraySize = 0; // unlimited + String arraySizeStr = pParamE.getAttribute("ARRAYSIZE"); + try { + if (arraySizeStr.length() > 0) arraySize = Integer.parseInt(arraySizeStr); + } catch (NumberFormatException e) { + throw new CIMXMLParseException(arraySizeStr + " is not a valid ARRAYSIZE attribute for PARAMETER.REFARRAY!"); + } + + CIMDataType type = new CIMDataType((referenceClass != null) ? referenceClass : "", arraySize); + + // QUALIFIER + checkOtherNodes(pParamE, nodesPARAMETERREFARRAY); + CIMQualifier[] qualis = parseQUALIFIERS(pParamE); + return new CIMParameter(name, type, qualis); + } + + /** + * parseINSTANCE + * + * @param pInstanceE + * @return CIMInstance + * @throws CIMXMLParseException + */ + public static CIMInstance parseINSTANCE(Element pInstanceE) throws CIMXMLParseException { + return parseINSTANCE(pInstanceE, null); + } + + private static final String[] nodesINSTANCE = { "QUALIFIER", "PROPERTY", "PROPERTY.ARRAY", "PROPERTY.REFERENCE" }; + + /** + * parseINSTANCE + * + * @param pInstanceE + * @param pObjPath + * @return CIMInstance + * @throws CIMXMLParseException + */ + public static CIMInstance parseINSTANCE(Element pInstanceE, CIMObjectPath pObjPath) throws CIMXMLParseException { + // + // + + // BB mod CIMInstance inst = new CIMInstance(); + String className = attribute(pInstanceE, "CLASSNAME"); + if (className == null) throw new CIMXMLParseException("INSTANCE element missing CLASSNAME attribute!"); + // QUALIFIER + // FIXME: in JSR48 CIMInstance doesn't have qualifiers + // CIMQualifier[] qualis = parseQUALIFIERS(pInstanceE); + // PROPERTY + CIMProperty[] props = parsePROPERTIES(pInstanceE); + + checkOtherNodes(pInstanceE, nodesINSTANCE); + + if (pObjPath == null) return new CIMInstance(cLocalPathBuilder.build(className, null), props); + if ( + WBEMConfiguration.getGlobalConfiguration().synchronizeNumericKeyDataTypes() + ) return CIMHelper.CIMInstanceWithSynchonizedNumericKeyDataTypes(pObjPath, props); + return new CIMInstance(pObjPath, props); + } + + /** + * ebak: Access to enclosing method parseQUALIFIERS(Element) from the type + * CIMXMLParserImpl is emulated by a synthetic accessor method. Increasing + * its visibility will improve your performance + * + * @param pElement + * @return CIMQualifier[] + * @throws CIMXMLParseException + */ + public static CIMQualifier[] parseQUALIFIERS(Element pElement) throws CIMXMLParseException { + Element[] qualiElementA = searchNodes(pElement, "QUALIFIER"); + CIMQualifier[] qualis; + if (qualiElementA != null) { + qualis = new CIMQualifier[qualiElementA.length]; + for (int i = 0; i < qualiElementA.length; i++) { + Element qualifierE = qualiElementA[i]; + qualis[i] = parseQUALIFIER(qualifierE); + } + } else qualis = null; + return qualis; + } + + /** + *
      +	 *  ENTITY % QualifierFlavor "
      +	 *  OVERRIDABLE    (true|false)  'true'
      +	 *  TOSUBCLASS     (true|false)  'true'
      +	 *  TOINSTANCE     (true|false)  'false'
      +	 *  TRANSLATABLE   (true|false)  'false'"
      +	 * 
      + * + * @param pElement + * @return int - CIMFlavor bit mixture + */ + private static int parseFLAVORS(Element pElement) { + int flavors = 0; + if (!getBoolAttribute(pElement, "OVERRIDABLE", true)) flavors |= CIMFlavor.DISABLEOVERRIDE; + if (!getBoolAttribute(pElement, "TOSUBCLASS", true)) flavors |= CIMFlavor.RESTRICTED; + if (getBoolAttribute(pElement, "TRANSLATABLE", false)) flavors |= CIMFlavor.TRANSLATE; + return flavors; + } + + private static TypedValue parseSingleValue(Element pElement) throws CIMXMLParseException { + return parseSingleValue(pElement, VALUE | VALUEA); + } + + private static final int VALUE = 1, VALUEA = 2, VALUEREF = 4, VALUEREFA = 8; + + private static TypedValue parseSingleValue(Element pElement, int pMask) throws CIMXMLParseException { + boolean foundSingleValue = false; + String typeStr = attribute(pElement, "TYPE"); + // ebak: there was an ESS fix in the base implementation + if (typeStr == null) typeStr = attribute(pElement, "PARAMTYPE"); + CIMDataType type = null; + Object value = null; + if ((pMask & VALUE) > 0) { + Element valueE = (Element) searchFirstNode(pElement, "VALUE"); + if (valueE != null) { + TypedValue tVal = parseVALUE(valueE); + String valueStr = (String) tVal.getValue(); + type = typeStr == null ? tVal.getType() : parseScalarTypeStr(typeStr); + value = createJavaObject(type == null ? null : type.toString(), valueStr); + foundSingleValue = true; + } + } + if (!foundSingleValue && (pMask & VALUEREF) > 0) { + // VALUE.REFERENCE + Element valuereferenceE = (Element) searchFirstNode(pElement, "VALUE.REFERENCE"); + if (valuereferenceE != null) { + CIMObjectPath op = parseVALUEREFERENCE(valuereferenceE); + value = op; + type = new CIMDataType(op.getObjectName()); + foundSingleValue = true; + } + } + if (!foundSingleValue && (pMask & VALUEA) > 0) { + // VALUE.ARRAY + Element valuearrayE = (Element) searchFirstNode(pElement, "VALUE.ARRAY"); + if (valuearrayE != null) { + TypedValue tValA = parseVALUEARRAY(valuearrayE); + type = typeStr == null ? tValA.getType() : parseArrayTypeStr(typeStr); + String[] valStrA = (String[]) tValA.getValue(); + if (valStrA != null) { + Object[] values = new Object[valStrA.length]; + for (int i = 0; i < valStrA.length; i++) { + values[i] = createJavaObject(type == null ? null : type.toString(), valStrA[i]); + } + value = values; + } + foundSingleValue = true; + } + } + if (!foundSingleValue && (pMask & VALUEREFA) > 0) { + // VALUE.REFARRAY + Element valueRefArrayE = (Element) searchFirstNode(pElement, "VALUE.REFARRAY"); + if (valueRefArrayE != null) { + type = new CIMDataType("", 0); + CIMObjectPath[] opA = parseVALUEREFARRAY(valueRefArrayE); + value = opA; + foundSingleValue = true; + } + } + if (!foundSingleValue) { + if (value instanceof Object[]) type = CIMDataType.STRING_ARRAY_T; else if (value != null) type = + CIMDataType.STRING_T; else type = CIMDataType.STRING_T; // /throw new + // CIMXMLParseException("null + // type with null value!"); + } + return new TypedValue(type, value); + } + + private static final String nodesQUALIFIER[] = { "VALUE", "VALUE.ARRAY" }; + + /** + * parseQUALIFIER + * + * @param pQualifierE + * @return CIMQualifier + * @throws CIMXMLParseException + */ + public static CIMQualifier parseQUALIFIER(Element pQualifierE) throws CIMXMLParseException { + // + // + + String name = attribute(pQualifierE, "NAME"); + if (name == null) throw new CIMXMLParseException("QUALIFIER element missing NAME attribute!"); + String typeStr = attribute(pQualifierE, "TYPE"); + if (typeStr == null && !hasTypeAttrsInNodes(pQualifierE)) throw new CIMXMLParseException( + "QUALIFIER element missing TYPE attribute!" + ); + boolean propagated = MOF.TRUE.equalsIgnoreCase(pQualifierE.getAttribute("PROPAGATED")); + // FLAVORS + int flavors = parseFLAVORS(pQualifierE); + // VALUE + if ( + searchNodes(pQualifierE, "VALUE", 0, 1, false) != null || + searchNodes(pQualifierE, "VALUE.ARRAY", 0, 1, false) != null + ) { + TypedValue typedValue = parseSingleValue(pQualifierE); + if (typedValue.getType() == null) throw new CIMXMLParseException("Qualifier's type is null!"); + // CIMQualifier(String pName, CIMDataType pType, Object pValue, int + // pFlavor) + return new CIMQualifier(name, typedValue.getType(), typedValue.getValue(), flavors, propagated); + } + checkOtherNodes(pQualifierE, nodesQUALIFIER); + + CIMDataType type = parseScalarTypeStr(typeStr); + return new CIMQualifier(name, type != null ? type : CIMDataType.STRING_T, null, flavors, propagated); + } + + /** + * parseQUALIFIERDECLARATION + * + * @param pQualifierTypeE + * @return CIMQualifierType + * @throws CIMXMLParseException + */ + public static CIMQualifierType parseQUALIFIERDECLARATION(Element pQualifierTypeE) + throws CIMXMLParseException { + // + // + + String name = attribute(pQualifierTypeE, "NAME"); + if (name == null) throw new CIMXMLParseException("QUALIFIER.DECLARATION element missing NAME attribute!"); + String type = attribute(pQualifierTypeE, "TYPE"); + if (type == null && !hasTypeAttrsInNodes(pQualifierTypeE)) throw new CIMXMLParseException( + "QUALIFIER.DECLARATION element missing TYPE attribute!" + ); + + // SCOPES + // ebak: there should be only 1 scope node + Element scopeElementA[] = searchNodes(pQualifierTypeE, "SCOPE", 0, 1, true); + int scopes = scopeElementA == null ? 0 : parseSCOPES(scopeElementA[0]); + // QUALIFIERS + // CIMQualifier[] qualis = parseQUALIFIERS(pQualifierTypeE); + + CIMDataType qdType; + Object qdValue; + + String nodes[] = null; + + if (searchNodes(pQualifierTypeE, "VALUE", 0, 1, true) != null) { + nodes = new String[] { "SCOPE", "VALUE" }; + } else if (searchNodes(pQualifierTypeE, "VALUE.ARRAY", 0, 1, true) != null) { + nodes = new String[] { "SCOPE", "VALUE.ARRAY" }; + } + + // VALUE + if (nodes != null) { + TypedValue typedValue = parseSingleValue(pQualifierTypeE); + qdType = typedValue.getType(); + qdValue = typedValue.getValue(); + boolean isArray = hasTrueAttribute(pQualifierTypeE, "ISARRAY"); + String arraySizeStr = attribute(pQualifierTypeE, "ARRAYSIZE"); + try { + int arraySize = (arraySizeStr == null ? (isArray ? 0 : -1) : Integer.parseInt(arraySizeStr)); + if (isArray || arraySize >= 0) { + qdType = + (arraySize > 0) + ? new CIMDataType(qdType.getType(), arraySize) + : CIMHelper.UnboundedArrayDataType(qdType.getType()); + } + } catch (NumberFormatException e) { + throw new CIMXMLParseException(arraySizeStr + " is not a valid ARRAYSIZE attribute for QUALIFIER.DECLARATION!"); + } + } else { + nodes = new String[] { "SCOPE" }; + qdType = parseScalarTypeStr(type); + if (qdType == null) qdType = CIMDataType.STRING_T; + qdValue = null; + } + checkOtherNodes(pQualifierTypeE, nodes); + + // FIXME: ebak: what about the flavors? + return new CIMQualifierType( + new CIMObjectPath(null, null, null, null, name, null), + qdType, + qdValue, + scopes, + 0 + ); + } + + private static boolean hasTrueAttribute(Element pElement, String pName) { + String valueStr = pElement.getAttribute(pName); + return MOF.TRUE.equalsIgnoreCase(valueStr); + } + + private static boolean getBoolAttribute(Element pElement, String pName, boolean pDefVal) { + String val = pElement.getAttribute(pName); + if (MOF.TRUE.equalsIgnoreCase(val)) return true; + if (MOF.FALSE.equalsIgnoreCase(val)) return false; + return pDefVal; + } + + /** + * parseSCOPES + * + * @param pScopeE + * @return int + */ + public static int parseSCOPES(Element pScopeE) { + int scopes = 0; + if (hasTrueAttribute(pScopeE, "CLASS")) scopes |= CIMScope.CLASS; + if (hasTrueAttribute(pScopeE, "ASSOCIATION")) scopes |= CIMScope.ASSOCIATION; + if (hasTrueAttribute(pScopeE, "REFERENCE")) scopes |= CIMScope.REFERENCE; + if (hasTrueAttribute(pScopeE, "PROPERTY")) scopes |= CIMScope.PROPERTY; + if (hasTrueAttribute(pScopeE, "METHOD")) scopes |= CIMScope.METHOD; + if (hasTrueAttribute(pScopeE, "PARAMETER")) scopes |= CIMScope.PARAMETER; + if (hasTrueAttribute(pScopeE, "INDICATION")) scopes |= CIMScope.INDICATION; + return scopes; + } + + private static Vector> parseClassPropsToVec(Element pElement) throws CIMXMLParseException { + Element[] propElementA = searchNodes(pElement, "PROPERTY"); + Vector> propVec = new Vector>(); + if (propElementA != null) { + for (int i = 0; i < propElementA.length; i++) { + Element propertyE = propElementA[i]; + propVec.add(parseCLASSPROPERTY(propertyE)); + } + } + + // PROPERTY.ARRAY + Element[] propArrayElementA = searchNodes(pElement, "PROPERTY.ARRAY"); + if (propArrayElementA != null) { + for (int i = 0; i < propArrayElementA.length; i++) { + Element propertyarrayE = propArrayElementA[i]; + propVec.add(parseCLASSPROPERTYARRAY(propertyarrayE)); + } + } + + // PROPERTY.REFERENCE + Element[] propRefElementA = searchNodes(pElement, "PROPERTY.REFERENCE"); + if (propRefElementA != null) { + for (int i = 0; i < propRefElementA.length; i++) { + Element propertyreferenceE = propRefElementA[i]; + propVec.add(parseCLASSPROPERTYREFERENCE(propertyreferenceE)); + } + } + return propVec; + } + + /** + * parsePROPERTIES + * + * @param pElement + * @return CIMProperty[] + * @throws CIMXMLParseException + */ + public static CIMProperty[] parsePROPERTIES(Element pElement) throws CIMXMLParseException { + Vector> classPropVec = parseClassPropsToVec(pElement); + // The following does not convert Vector to + // CIMProperty[], it is still CIMClassProperty[]!!! You can treat it + // like a CIMProperty (property.getValue(), etc.) but (property + // instanceof CIMProperty) will return false! + // return classPropVec.toArray(new CIMProperty[0]); + + int arraySize = classPropVec.size(); + CIMProperty[] retA = new CIMProperty[arraySize]; + for (int i = 0; i < arraySize; i++) { + CIMClassProperty prop = classPropVec.get(i); + retA[i] = + new CIMProperty( + prop.getName(), + prop.getDataType(), + prop.getValue(), + prop.isKey(), + prop.isPropagated(), + prop.getOriginClass() + ); + } + return retA; + } + + /** + * parseCLASSPROPERTIES + * + * @param pElement + * @return CIMClassProperty[] + * @throws CIMXMLParseException + */ + public static CIMClassProperty[] parseCLASSPROPERTIES(Element pElement) throws CIMXMLParseException { + Vector> classPropVec = parseClassPropsToVec(pElement); + return classPropVec.toArray(new CIMClassProperty[0]); + } + + /** + * parsePROPERTY + * + * @param pPropertyE + * @return CIMProperty + * @throws CIMXMLParseException + */ + public static CIMProperty parsePROPERTY(Element pPropertyE) throws CIMXMLParseException { + return parseCLASSPROPERTY(pPropertyE); + } + + private static class EmbObjHandler { + private CIMQualifier[] iQualiA; + + private boolean iHasEmbObjAttr, iHasEmbInstAttr, iHasEmbObjQuali, iHasEmbInstQuali, iKeyed; + + private CIMDataType iRawType, iType; + + private Object iRawValue, iValue; + + private Element iElement; + + private boolean iStrictParsing = WBEMConfiguration.getGlobalConfiguration().strictEmbObjTypes(); + + /** + * Ctor. + * + * @param pElement + * @throws CIMXMLParseException + */ + public EmbObjHandler(Element pElement) throws CIMXMLParseException { + this.iElement = pElement; + handleQualis(); + handleAttribs(); + Element valueE = (Element) searchFirstNode(pElement, "VALUE"); + if (valueE != null) { + TypedValue tv = parseVALUE(valueE); + if (this.iRawType == null) this.iRawType = tv.getType(); + if (this.iRawType == null) this.iRawType = CIMDataType.STRING_T; + this.iRawValue = tv.getValue(); + } else { + valueE = (Element) searchFirstNode(pElement, "VALUE.ARRAY"); + if (valueE != null) { + TypedValue tv = parseVALUEARRAY(valueE); + if (this.iRawType == null) this.iRawType = tv.getType(); + if (this.iRawType == null) this.iRawType = CIMDataType.STRING_ARRAY_T; + this.iRawValue = tv.getValue(); + } + } + } + + private void handleQualis() throws CIMXMLParseException { + this.iQualiA = parseQUALIFIERS(this.iElement); + if (this.iQualiA != null) { + for (int idx = 0; idx < this.iQualiA.length; idx++) { + String qualiName = this.iQualiA[idx].getName(); + if ("EmbeddedObject".equalsIgnoreCase(qualiName)) { + this.iHasEmbObjQuali = true; + } else if ("EMBEDDEDINSTANCE".equalsIgnoreCase(qualiName)) { + this.iHasEmbInstQuali = true; + } else if ("KEY".equalsIgnoreCase(qualiName)) { + this.iKeyed = true; + } + if ((this.iHasEmbObjQuali || this.iHasEmbInstQuali) && this.iKeyed) return; + } + } + } + + private void handleAttribs() throws CIMXMLParseException { + String typeStr = this.iElement.getAttribute("TYPE"); + if (typeStr == null || typeStr.length() == 0) { + typeStr = this.iElement.getAttribute("PARAMTYPE"); + if (typeStr == null || typeStr.length() == 0) { + /* + * throw new CIMXMLParseException( iElement.getNodeName()+" + * must contain a TYPE or PARAMTYPE attribute!" ); + */ + /* + * ebak: Workaround for SVC's TYPE attribute in VALUE and + * VALUE.ARRAY element. + */ + typeStr = null; + } + } + // ebak: iRawType can be filled from contained VALUE or VALUE.ARRAY + // element (SVC) + if (typeStr != null) this.iRawType = parseScalarTypeStr(typeStr); + + // DSPs call for EmbeddedObject AND XML is case sensitive, BUT there + // are probably CIMOMs out there that still use EMBEDDEDOBJECT + String embObjAttrStr = this.iElement.getAttribute("EmbeddedObject"); + if (embObjAttrStr == null || embObjAttrStr.length() == 0) { + embObjAttrStr = this.iElement.getAttribute("EMBEDDEDOBJECT"); + } + if (embObjAttrStr == null || embObjAttrStr.length() == 0) { + this.iHasEmbObjAttr = this.iHasEmbInstAttr = false; + } else if ("object".equalsIgnoreCase(embObjAttrStr)) { + this.iHasEmbObjAttr = true; + this.iHasEmbInstAttr = false; + } else if ("instance".equalsIgnoreCase(embObjAttrStr)) { + this.iHasEmbObjAttr = false; + this.iHasEmbInstAttr = true; + } else throw new CIMXMLParseException("EmbeddedObject attribute cannot contain \"" + embObjAttrStr + "\" value!"); + } + + /** + * getQualifiers + * + * @return CIMQualifier[] + * @throws CIMXMLParseException + */ + public CIMQualifier[] getQualifiers() throws CIMXMLParseException { + transform(); + CIMQualifiedElementInterfaceImpl qualiImpl = new CIMQualifiedElementInterfaceImpl( + this.iQualiA, + isKeyed(), + this.iType == null || this.iType.getType() == CIMDataType.STRING + ); + return qualiImpl.getQualifiers(); + } + + /** + * isKeyed + * + * @return boolean + */ + public boolean isKeyed() { + return this.iKeyed; + } + + /** + * isEmbeddedObject + * + * @return boolean + */ + private boolean isEmbeddedObject() { + return this.iHasEmbObjAttr || this.iHasEmbInstAttr || this.iHasEmbObjQuali || this.iHasEmbInstQuali; + } + + /** + * isEmbeddedClass + * + * @return boolean + */ + private boolean isEmbeddedClass() { + return this.iHasEmbObjAttr || this.iHasEmbObjQuali; + } + + /** + * isEmbeddedInstance + * + * @return boolean + */ + private boolean isEmbeddedInstance() { + return this.iHasEmbInstAttr || this.iHasEmbInstQuali; + } + + /** + * getType + * + * @return CIMDataType + * @throws CIMXMLParseException + */ + public CIMDataType getType() throws CIMXMLParseException { + transform(); + return this.iType; + } + + /** + * getArrayType + * + * @return CIMDataType + * @throws CIMXMLParseException + */ + public CIMDataType getArrayType() throws CIMXMLParseException { + transform(); + return this.iType.isArray() ? this.iType : CIMHelper.UnboundedArrayDataType(this.iType.getType()); + } + + /** + * getValue + * + * @return Object + * @throws CIMXMLParseException + */ + public Object getValue() throws CIMXMLParseException { + transform(); + return this.iValue; + } + + private void transform() throws CIMXMLParseException { + if (this.iType != null) return; + if (this.iRawValue == null) { + if (isEmbeddedObject()) { + if (this.iRawType != CIMDataType.STRING_T) throw new CIMXMLParseException( + "Embedded Object CIM-XML element's type must be string. " + this.iRawType + " is invalid!" + ); + if (this.iStrictParsing) { + /* + * In case of strict parsing Object means CIMClass, + * Instance means CIMInstance. Pegasus 2.7.0 seems to + * handle it this way. + */ + this.iType = isEmbeddedInstance() ? CIMDataType.OBJECT_T : CIMDataType.CLASS_T; + } else { + /* + * for valueless EmbeddedObject="object" the type is + * undeterminable since Pegasus's CIMObject can contain + * both CIMClass and CIMInstance + */ + this.iType = isEmbeddedInstance() ? CIMDataType.OBJECT_T : CIMDataType.STRING_T; + } + } else { + this.iType = this.iRawType; + } + this.iValue = null; + } else { + if (isEmbeddedObject()) { + transformEmbObj(); + } else { + transformNormObj(); + } + } + } + + private void transformEmbObj() throws CIMXMLParseException { + if (this.iRawValue instanceof String) { + this.iValue = parseXmlStr((String) this.iRawValue); + this.iType = getCIMObjType(this.iValue); + } else { + this.iValue = parseXmlStrA((String[]) this.iRawValue); + this.iType = getCIMObjAType((Object[]) this.iValue); + } + if (isEmbeddedInstance() && this.iType.getType() != CIMDataType.OBJECT) throw new CIMXMLParseException( + this.iElement.getNodeName() + " element is an EmbeddedInstance with non INSTANCE value. " + "It's not valid!" + ); + if ( + isEmbeddedClass() && this.iType.getType() != CIMDataType.CLASS && this.iType.getType() != CIMDataType.OBJECT + ) throw new CIMXMLParseException( + this.iElement.getNodeName() + " element is an EmbeddedObject with non CLASS/INSTANCE value. It's not valid!" + ); + } + + private void transformNormObj() throws CIMXMLParseException { + if (this.iRawValue instanceof String) { + this.iType = this.iRawType; + this.iValue = createJavaObject(this.iType == null ? null : this.iType.toString(), (String) this.iRawValue); + } else { + String[] rawValueA = (String[]) this.iRawValue; + String typeStr = this.iRawType.toString(); + Object[] objA = new Object[rawValueA.length]; + for (int i = 0; i < objA.length; i++) objA[i] = createJavaObject(typeStr, rawValueA[i]); + this.iType = CIMHelper.UnboundedArrayDataType(this.iRawType.getType()); + this.iValue = objA; + } + } + + /** + * parseXmlStr + * + * @param pXmlStr + * @return CIMClass or CIMInstance + * @throws CIMXMLParseException + */ + public static Object parseXmlStr(String pXmlStr) throws CIMXMLParseException { + // ebak: workaround for null array elements -> parse empty EmbObj + // string as null + if (pXmlStr == null || pXmlStr.length() == 0) return null; + try { + CIMClientXML_HelperImpl builder = new CIMClientXML_HelperImpl(); + Document doc = builder.parse(new InputSource(new StringReader(pXmlStr))); + return parseObject(doc.getDocumentElement()); + } catch (CIMXMLParseException e) { + throw e; + } catch (Exception e) { + throw new CIMXMLParseException(e.getMessage() + "\npXmlStr=" + pXmlStr); + } + } + + /** + * parseXmlStrA + * + * @param pXmlStrA + * @return Object[] + * @throws CIMXMLParseException + */ + public static Object[] parseXmlStrA(String[] pXmlStrA) throws CIMXMLParseException { + if (pXmlStrA == null || pXmlStrA.length == 0) return null; + Object[] objA = new Object[pXmlStrA.length]; + for (int i = 0; i < objA.length; i++) { + String xmlStr = pXmlStrA[i]; + objA[i] = xmlStr == null ? null : parseXmlStr(xmlStr); + } + return objA; + } + + /** + * getCIMObjType + * + * @param pCIMObj + * @return CIMDataType + * @throws CIMXMLParseException + */ + public static CIMDataType getCIMObjType(Object pCIMObj) throws CIMXMLParseException { + if (pCIMObj == null) throw new CIMXMLParseException("cannot have null CIM object! (CIMClass or CIMInstance)"); + if (pCIMObj instanceof CIMInstance) return CIMDataType.OBJECT_T; + if (pCIMObj instanceof CIMClass) return CIMDataType.CLASS_T; + throw new CIMXMLParseException(pCIMObj.getClass().getName() + " is not a CIM object! (CIMClass or CIMInstance)"); + } + + /** + * getCIMObjAType + * + * @param pCIMObjA + * @return CIMDataType + * @throws CIMXMLParseException + */ + public static CIMDataType getCIMObjAType(Object[] pCIMObjA) throws CIMXMLParseException { + if (pCIMObjA == null || pCIMObjA.length == 0) return CIMDataType.STRING_ARRAY_T; + CIMDataType type = null; + for (int i = 0; i < pCIMObjA.length; i++) { + if (pCIMObjA[i] == null) continue; + CIMDataType currType = getCIMObjType(pCIMObjA[i]); + if (type == null) { + type = currType; + } else if (type != currType) { + throw new CIMXMLParseException("Embedded Object arrays with different types are not supported"); + } + } + if (type == CIMDataType.OBJECT_T) return CIMDataType.OBJECT_ARRAY_T; + if (type == CIMDataType.CLASS_T) return CIMDataType.CLASS_ARRAY_T; + return CIMDataType.STRING_ARRAY_T; + } + } + + private static final String nodesPROPERTY[] = { "QUALIFIER", "VALUE" }; + + /** + * parseCLASSPROPERTY + * + * @param pPropertyE + * @return CIMClassProperty + * @throws CIMXMLParseException + */ + public static CIMClassProperty parseCLASSPROPERTY(Element pPropertyE) throws CIMXMLParseException { + // + // + + Attr property_nameA = (Attr) searchAttribute(pPropertyE, "NAME"); + if (property_nameA == null) throw new CIMXMLParseException("PROPERTY element missing NAME attribute!"); + String name = property_nameA.getNodeValue(); + if (attribute(pPropertyE, "TYPE") == null && !hasTypeAttrsInNodes(pPropertyE)) throw new CIMXMLParseException( + "PROPERTY element missing TYPE attribute!" + ); + + String classOrigin = pPropertyE.getAttribute("CLASSORIGIN"); + if (classOrigin != null && classOrigin.length() == 0) classOrigin = null; + + String propagatedStr = pPropertyE.getAttribute("PROPAGATED"); + boolean propagated = MOF.TRUE.equalsIgnoreCase(propagatedStr); + + // only QUALIFIER(s) and 0/1 VALUE + searchNodes(pPropertyE, "VALUE", 0, 1, true); + checkOtherNodes(pPropertyE, nodesPROPERTY); + + // QUALIFIER + // ebak: EmbeddedObject support + EmbObjHandler embObjHandler = new EmbObjHandler(pPropertyE); + /* + * CIMClassProperty(String pName, CIMDataType pType, Object pValue, + * CIMQualifier[] pQualifiers, boolean pKey, boolean propagated, String + * originClass) + */ + return new CIMClassProperty( + name, + embObjHandler.getType(), + embObjHandler.getValue(), + embObjHandler.getQualifiers(), + embObjHandler.isKeyed(), + propagated, + classOrigin + ); + } + + /** + * parsePROPERTYARRAY + * + * @param pPropertyArrayE + * @return CIMProperty + * @throws CIMXMLParseException + */ + public static CIMProperty parsePROPERTYARRAY(Element pPropertyArrayE) throws CIMXMLParseException { + return parseCLASSPROPERTYARRAY(pPropertyArrayE); + } + + private static final String nodesPROPERTYARRAY[] = { "QUALIFIER", "VALUE.ARRAY" }; + + /** + * parseCLASSPROPERTYARRAY + * + * @param pPropArrayE + * @return CIMClassProperty + * @throws CIMXMLParseException + */ + public static CIMClassProperty parseCLASSPROPERTYARRAY(Element pPropArrayE) throws CIMXMLParseException { + // + // + + String name = attribute(pPropArrayE, "NAME"); + if (name == null) throw new CIMXMLParseException("PROPERTY.ARRAY element missing NAME attribute!"); + if (attribute(pPropArrayE, "TYPE") == null && !hasTypeAttrsInNodes(pPropArrayE)) throw new CIMXMLParseException( + "PROPERTY.ARRAY element missing TYPE attribute!" + ); + + String valueArraysizeStr = pPropArrayE.getAttribute("ARRAYSIZE"); + try { + if (valueArraysizeStr.length() > 0) Integer.parseInt(valueArraysizeStr); + } catch (NumberFormatException e) { + throw new CIMXMLParseException(valueArraysizeStr + " is not a valid ARRAYSIZE attribute for VALUE.ARRAY!"); + } + + String classOrigin = pPropArrayE.getAttribute("CLASSORIGIN"); + if (classOrigin != null && classOrigin.length() == 0) classOrigin = null; + + String valuePropagatedStr = pPropArrayE.getAttribute("PROPAGATED"); + boolean propagated = (valuePropagatedStr != null && valuePropagatedStr.equalsIgnoreCase(MOF.TRUE)); + + // only QUALIFIER(s) and 0/1 VALUE.ARRAY + searchNodes(pPropArrayE, "VALUE.ARRAY", 0, 1, true); + checkOtherNodes(pPropArrayE, nodesPROPERTYARRAY); + + // QUALIFIER + // ebak: EmbeddedObject support + EmbObjHandler embObjHandler = new EmbObjHandler(pPropArrayE); + return new CIMClassProperty( + name, + embObjHandler.getArrayType(), + embObjHandler.getValue(), + embObjHandler.getQualifiers(), + embObjHandler.isKeyed(), + propagated, + classOrigin + ); + } + + /** + * parsePROPERTYREFERENCE + * + * @param pPropRefE + * @return CIMProperty + * @throws CIMXMLParseException + */ + public static CIMProperty parsePROPERTYREFERENCE(Element pPropRefE) throws CIMXMLParseException { + return parseCLASSPROPERTYREFERENCE(pPropRefE); + } + + private static final String nodesPROPERTYREFERENCE[] = { "QUALIFIER", "VALUE.REFERENCE" }; + + /** + * parseCLASSPROPERTYREFERENCE + * + * @param pPropRefE + * @return CIMClassProperty + * @throws CIMXMLParseException + */ + public static CIMClassProperty parseCLASSPROPERTYREFERENCE(Element pPropRefE) throws CIMXMLParseException { + // + // + + String name = attribute(pPropRefE, "NAME"); + if (name == null) throw new CIMXMLParseException("PROPERTY.REFERENCE element missing NAME attribute!"); + + String classOrigin = pPropRefE.getAttribute("CLASSORIGIN"); + if (classOrigin != null && classOrigin.length() == 0) classOrigin = null; + + String referenceClass = pPropRefE.getAttribute("REFERENCECLASS"); + + String propagatedStr = pPropRefE.getAttribute("PROPAGATED"); + boolean propagated = MOF.TRUE.equalsIgnoreCase(propagatedStr); + + // QUALIFIER + CIMQualifier[] qualis = parseQUALIFIERS(pPropRefE); + + CIMDataType type = new CIMDataType(referenceClass != null ? referenceClass : ""); + // VALUE.REFERENCE + Element valueRefA[] = searchNodes(pPropRefE, "VALUE.REFERENCE", 0, 1, true); + Object value = valueRefA != null ? parseVALUEREFERENCE(valueRefA[0]) : null; + + // return a CIMProperty without a CIMValue + checkOtherNodes(pPropRefE, nodesPROPERTYREFERENCE); + CIMQualifiedElementInterfaceImpl qualiImpl = new CIMQualifiedElementInterfaceImpl(qualis); + return new CIMClassProperty(name, type, value, qualis, qualiImpl.isKeyed(), propagated, classOrigin); + } + + /** + * parseMESSAGE + * + * @param pCimVersion + * @param pDtdVersion + * @param pMessageE + * @return CIMMessage + * @throws CIMXMLParseException + */ + public static CIMMessage parseMESSAGE(String pCimVersion, String pDtdVersion, Element pMessageE) + throws CIMXMLParseException { + // + // + + Attr idA = (Attr) searchAttribute(pMessageE, "ID"); + if (idA == null) throw new CIMXMLParseException("MESSAGE element missing ID attribute!"); + String id = idA.getNodeValue(); + + Attr protocolA = (Attr) searchAttribute(pMessageE, "PROTOCOLVERSION"); + if (protocolA == null) throw new CIMXMLParseException("MESSAGE element missing PROTOCOLVERSION attribute!"); + // TODO + if (pCimVersion.equals("2.0") && pDtdVersion.equals("2.0")) { + // Attr message_idA = (Attr)searchAttribute(messageE, "ID"); + // String messadeID = message_idA.getNodeValue(); + + // Attr message_protocolversionA = (Attr)searchAttribute(messageE, + // "PROTOCOLVERSION"); + // String protocolversion = message_protocolversionA.getNodeValue(); + + // SIMPLERSP + Element simplerspA[] = searchNodes(pMessageE, "SIMPLERSP", 0, 1, false); + if (simplerspA != null) { + CIMResponse response = parseSIMPLERSP(simplerspA[0]); + response.setMethod("SIMPLERSP"); + response.setId(id); + return response; + } + Element multirspA[] = searchNodes(pMessageE, "MULTIRSP", 0, 1, false); + if (multirspA != null) { + CIMResponse response = parseMULTIRSP(multirspA[0]); + response.setMethod("MULTIRSP"); + response.setId(id); + return response; + } + // SIMPLEEXPREQ + Element simpleexpreqA[] = searchNodes(pMessageE, "SIMPLEEXPREQ", 0, 1, false); + if (simpleexpreqA != null) { + CIMRequest request = parseSIMPLEEXPREQ(simpleexpreqA[0]); + request.setMethod("SIMPLEEXPREQ"); + request.setId(id); + return request; + } + + // MULTIEXPREQ + Element multiexpreqA[] = searchNodes(pMessageE, "MULTIEXPREQ", 0, 1, false); + if (multiexpreqA != null) { + CIMRequest request = parseMULTIEXPREQ(multiexpreqA[0]); + request.setMethod("MULTIEXPREQ"); + request.setId(id); + return request; + } + // SIMPLEEXPRSP + Element simpleexprspA[] = searchNodes(pMessageE, "SIMPLEEXPRSP", 0, 1, false); + if (simpleexprspA != null) { + CIMResponse response = parseSIMPLEEXPRSP(simpleexprspA[0]); + response.setMethod("SIMPLEEXPRSP"); + response.setId(id); + return response; + } + // MULTIEXPRSP + Element multiexprspA[] = searchNodes(pMessageE, "MULTIEXPRSP", 0, 1, false); + if (multiexprspA != null) { + CIMResponse response = parseMULTIEXPRSP(multiexprspA[0]); + response.setMethod("MULTIEXPRSP"); + response.setId(id); + return response; + } + + // SIMPLEREQ + Element simplereqA[] = searchNodes(pMessageE, "SIMPLEREQ", 0, 1, false); + if (simplereqA != null) { + CIMRequest request = parseSIMPLEREQ(simplereqA[0]); + request.setMethod("SIMPLEREQ"); + request.setId(id); + return request; + } + + // MULTIREQ + Element multireqA[] = searchNodes(pMessageE, "MULTIREQ", 0, 1, false); + if (multireqA != null) { + CIMRequest request = parseMULTIREQ(multireqA[0]); + request.setMethod("MULTIREQ"); + request.setId(id); + return request; + } + throw new CIMXMLParseException("MESSAGE element missing required child element!"); + } + // TODO, look for the specific error message in the spec + throw new CIMXMLParseException("DTD not supported"); + } + + private static final String nodesPARAMVALUE[] = { + "VALUE", + "VALUE.REFERENCE", + "VALUE.ARRAY", + "VALUE.REFARRAY", + "CLASSNAME", + "INSTANCENAME", + "CLASS", + "INSTANCE", + "VALUE.NAMEDINSTANCE" + }; + + /** + * parsePARAMVALUE + * + * @param pParamValueE + * @return CIMArgument + * @throws CIMXMLParseException + */ + public static CIMArgument parsePARAMVALUE(Element pParamValueE) throws CIMXMLParseException { + // ) + // + String name = attribute(pParamValueE, "NAME"); + if (name == null) throw new CIMXMLParseException("PARAMVALUE element missing NAME attribute!"); + // FIXME: ebak: The base implementation didn't contain VALUE.REFARRAY + // handling. Why? + // ebak: embedded object support, different parsing for VALUE and + // VALUE.ARRAY sub elements + if ( + searchNodes(pParamValueE, "VALUE.REFERENCE", 0, 1, false) != null || + searchNodes(pParamValueE, "VALUE.REFARRAY", 0, 1, false) != null + ) { + TypedValue typedValue = parseSingleValue(pParamValueE, VALUEREF | VALUEREFA); + CIMDataType type = typedValue.getType(); + Object value = typedValue.getValue(); + if (type == null) throw new CIMXMLParseException("PARAMVALUE element type is null!"); + return new CIMArgument(name, type, value); + } + if ( + searchNodes(pParamValueE, "VALUE", 0, 1, false) != null || + searchNodes(pParamValueE, "VALUE.ARRAY", 0, 1, false) != null || + !hasNodes(pParamValueE) + ) { + EmbObjHandler embObjHandler = new EmbObjHandler(pParamValueE); + return new CIMArgument(name, embObjHandler.getType(), embObjHandler.getValue()); + } + + // CLASSNAME + Element classNameA[] = searchNodes(pParamValueE, "CLASSNAME", 0, 1, false); + if (classNameA != null) { + CIMObjectPath op = parseCLASSNAME(classNameA[0]); + CIMDataType type = new CIMDataType(op.getObjectName()); + return new CIMArgument(name, type, op); + } + + // INSTANCENAME + Element instNameA[] = searchNodes(pParamValueE, "INSTANCENAME", 0, 1, false); + if (instNameA != null) { + CIMObjectPath op = parseINSTANCENAME(instNameA[0]); + CIMDataType type = new CIMDataType(op.getObjectName()); + return new CIMArgument(name, type, op); + } + + // CLASS + Element classA[] = searchNodes(pParamValueE, "CLASS", 0, 1, false); + if (classA != null) { + CIMClass cl = parseCLASS(classA[0]); + return new CIMArgument(name, CIMDataType.CLASS_T, cl); + } + + // INSTANCE + Element instanceA[] = searchNodes(pParamValueE, "INSTANCE", 0, 1, false); + if (instanceA != null) { + CIMInstance inst = parseINSTANCE(instanceA[0]); + return new CIMArgument(name, CIMDataType.OBJECT_T, inst); + } + + // VALUE.NAMEDINSTANCE + Element valuenamedisntanceA[] = searchNodes(pParamValueE, "VALUE.NAMEDINSTANCE", 0, 1, false); + if (valuenamedisntanceA != null) { + CIMInstance inst = parseVALUENAMEDINSTANCE(valuenamedisntanceA[0]); + return new CIMArgument(name, CIMDataType.OBJECT_T, inst); + } + checkOtherNodes(pParamValueE, nodesPARAMVALUE); + return new CIMArgument(name, CIMDataType.STRING_T, null); + } + + private static final String nodesIPARAMVALUE[] = { + "VALUE", + "VALUE.ARRAY", + "VALUE.REFERENCE", + "CLASSNAME", + "INSTANCENAME", + "QUALIFIER.DECLARATION", + "CLASS", + "INSTANCE", + "VALUE.NAMEDINSTANCE" + }; + + /** + * parseIPARAMVALUE + * + * @param pParamValueE + * @return CIMArgument + * @throws CIMXMLParseException + */ + public static CIMArgument parseIPARAMVALUE(Element pParamValueE) throws CIMXMLParseException { + // + // + + String name = attribute(pParamValueE, "NAME"); + if (name == null) throw new CIMXMLParseException("IPARAMVALUE element missing NAME attribute!"); + // this can parse VALUE, VALUE.ARRAY and VALUE.REFERENCE + if ( + searchNodes(pParamValueE, "VALUE", 0, 1, false) != null || + searchNodes(pParamValueE, "VALUE.ARRAY", 0, 1, false) != null || + searchNodes(pParamValueE, "VALUE.REFERENCE", 0, 1, false) != null + ) { + TypedValue typedValue = parseSingleValue(pParamValueE, VALUE | VALUEA | VALUEREF); + if (typedValue.getType() != null) { + return new CIMArgument(name, typedValue.getType(), typedValue.getValue()); + } + } + // we can have different types too which cannot be handled by + // parseSingleValue() + + // INSTANCENAME + Element instNameA[] = searchNodes(pParamValueE, "INSTANCENAME", 0, 1, false); + if (instNameA != null) { + CIMObjectPath op = parseINSTANCENAME(instNameA[0]); + CIMDataType type = new CIMDataType(op.getObjectName()); + return new CIMArgument(name, type, op); + } + + // CLASSNAME + Element classNameA[] = searchNodes(pParamValueE, "CLASSNAME", 0, 1, false); + if (classNameA != null) { + CIMObjectPath op = parseCLASSNAME(classNameA[0]); + CIMDataType type = new CIMDataType(op.getObjectName()); + return new CIMArgument(name, type, op); + } + + // QUALIFIER.DECLARATION + Element qualiDeclarationA[] = searchNodes(pParamValueE, "QUALIFIER.DECLARATION", 0, 1, false); + if (qualiDeclarationA != null) { + CIMQualifierType qualiType = parseQUALIFIERDECLARATION(qualiDeclarationA[0]); + // FIXME: ebak: Does it surely have to be mapped to type: + // REFERENCE???? + return new CIMArgument(name, new CIMDataType(qualiType.getName()), qualiType); + } + + // CLASS + Element classA[] = searchNodes(pParamValueE, "CLASS", 0, 1, false); + if (classA != null) { + CIMClass cl = parseCLASS(classA[0]); + return new CIMArgument(name, CIMDataType.CLASS_T, cl); + } + + // INSTANCE + Element instanceA[] = searchNodes(pParamValueE, "INSTANCE", 0, 1, false); + if (instanceA != null) { + CIMInstance inst = parseINSTANCE(instanceA[0]); + return new CIMArgument(name, CIMDataType.OBJECT_T, inst); + } + + // VALUE.NAMEDINSTANCE + Element valuenamedisntanceA[] = searchNodes(pParamValueE, "VALUE.NAMEDINSTANCE", 0, 1, false); + if (valuenamedisntanceA != null) { + CIMInstance inst = parseVALUENAMEDINSTANCE(valuenamedisntanceA[0]); + return new CIMArgument(name, CIMDataType.OBJECT_T, inst); + } + + checkOtherNodes(pParamValueE, nodesIPARAMVALUE); + return new CIMArgument(name, CIMDataType.STRING_T, null); + } + + /** + * parseSIMPLERSP + * + * @param pSimpleRspE + * @return CIMResponse + * @throws CIMXMLParseException + */ + public static CIMResponse parseSIMPLERSP(Element pSimpleRspE) throws CIMXMLParseException { + // + + // METHODRESPONSE + Element methodresponseA[] = searchNodes(pSimpleRspE, "METHODRESPONSE", 0, 1, false); + if (methodresponseA != null) { + return parseMETHODRESPONSE(methodresponseA[0]); + } + + // IMETHODRESPONSE + Element imethodresponseA[] = searchNodes(pSimpleRspE, "IMETHODRESPONSE", 0, 1, false); + if (imethodresponseA != null) { + return parseIMETHODRESPONSE(imethodresponseA[0]); + } + + throw new CIMXMLParseException("SIMPLERSP element missing required child element!"); + } + + /** + * parseMULTIRSP + * + * @param pSimpleRspE + * @return CIMResponse + * @throws CIMXMLParseException + */ + public static CIMResponse parseMULTIRSP(Element pSimpleRspE) throws CIMXMLParseException { + // + + Element[] multiRespElementA = searchNodes(pSimpleRspE, "SIMPLERSP", 2, Integer.MAX_VALUE, false); + if (multiRespElementA != null) { + CIMResponse multiRsp = new CIMResponse(); + for (int i = 0; i < multiRespElementA.length; i++) { + Element methodresponseE = multiRespElementA[i]; + CIMResponse rsp = parseSIMPLERSP(methodresponseE); + rsp.setMethod("SIMPLERSP"); + multiRsp.addResponse(rsp); + } + return multiRsp; + } + + throw new CIMXMLParseException("MULTIRSP element missing SIMPLERSP child element!"); + } + + private static final String nodesSIMPLEREQ[] = { "CORRELATOR", "METHODCALL", "IMETHODCALL" }; + + /** + * parseSIMPLEREQ + * + * @param pSimpleReqE + * @return CIMRequest + * @throws CIMXMLParseException + */ + public static CIMRequest parseSIMPLEREQ(Element pSimpleReqE) throws CIMXMLParseException { + // + CIMRequest request = null; + + // METHODCALL + Element methodcallA[] = searchNodes(pSimpleReqE, "METHODCALL", 0, 1, true); + if (methodcallA != null) { + request = parseMETHODCALL(methodcallA[0]); + } + + // IMETHODCALL + Element imethodcallA[] = searchNodes(pSimpleReqE, "IMETHODCALL", 0, 1, true); + if (imethodcallA != null) { + if (request != null) { + throw new CIMXMLParseException("SIMPLEREQ element cannot have METHODCALL and IMETHODCALL child elements!"); + } + request = parseIMETHODCALL(imethodcallA[0]); + } + + if (request == null) throw new CIMXMLParseException("SIMPLEREQ element missing required child element!"); + + // CORRELATOR + Element[] correlatorA = searchNodes(pSimpleReqE, "CORRELATOR", 0, Integer.MAX_VALUE, true); + if (correlatorA != null) { + for (int i = 0; i < correlatorA.length; i++) // TODO: return to WBEMClient API if JSR48 changes + parseCORRELATOR(correlatorA[i]); + } + + checkOtherNodes(pSimpleReqE, nodesSIMPLEREQ); + return request; + } + + /** + * parseMULTIREQ + * + * @param pMultiReqE + * @return CIMRequest + * @throws CIMXMLParseException + */ + public static CIMRequest parseMULTIREQ(Element pMultiReqE) throws CIMXMLParseException { + // + + Element[] methodReqElementA = searchNodes(pMultiReqE, "SIMPLEREQ", 2, Integer.MAX_VALUE, false); + if (methodReqElementA != null) { + CIMRequest multiReq = new CIMRequest(); + for (int i = 0; i < methodReqElementA.length; i++) { + Element methodrequestE = methodReqElementA[i]; + CIMRequest req = parseSIMPLEREQ(methodrequestE); + req.setMethod("SIMPLEREQ"); + + multiReq.addRequest(req); + } + return multiReq; + } + throw new CIMXMLParseException("MULTIREQ element missing SIMPLEREQ child element!"); + } + + private static final String nodesMETHODCALL[] = { "LOCALCLASSPATH", "LOCALINSTANCEPATH", "PARAMVALUE" }; + + /** + * parseMETHODCALL + * + * @param pMethodCallE + * @return CIMRequest + * @throws CIMXMLParseException + */ + public static CIMRequest parseMETHODCALL(Element pMethodCallE) throws CIMXMLParseException { + // + // + + CIMRequest request = new CIMRequest(); + String methodname = attribute(pMethodCallE, "NAME"); + if (methodname == null) throw new CIMXMLParseException("METHODCALL element missing NAME attribute!"); + request.setMethodName(methodname); + + // EXPMETHODCALL + boolean localclasspathFound = false; + Element localclasspathA[] = searchNodes(pMethodCallE, "LOCALCLASSPATH", 0, 1, true); + if (localclasspathA != null) { + CIMObjectPath path = parseLOCALCLASSPATH(localclasspathA[0]); + + request.setObjectPath(path); + localclasspathFound = true; + } + + Element localinstancepathA[] = searchNodes(pMethodCallE, "LOCALINSTANCEPATH", 0, 1, true); + if (localinstancepathA != null) { + if (localclasspathFound) throw new CIMXMLParseException( + "METHODCALL element cannot have both LOCALCLASSPATH and LOCALINSTANCEPATH child elements!" + ); + + CIMObjectPath path = parseLOCALINSTANCEPATH(localinstancepathA[0]); + + request.setObjectPath(path); + } else { + if (!localclasspathFound) throw new CIMXMLParseException("METHODCALL element missing required child element!"); + } + + Element[] paramValueElementA = searchNodes(pMethodCallE, "PARAMVALUE", 0, Integer.MAX_VALUE, true); + + if (paramValueElementA != null) { + CIMArgument[] argA = new CIMArgument[paramValueElementA.length]; + for (int i = 0; i < paramValueElementA.length; i++) { + Element paramvalueE = paramValueElementA[i]; + argA[i] = parsePARAMVALUE(paramvalueE); + } + request.addParamValue(argA); + } + + checkOtherNodes(pMethodCallE, nodesMETHODCALL); + return request; + } + + private static final String nodesIMETHODCALL[] = { "LOCALNAMESPACEPATH", "IPARAMVALUE" }; + + /** + * parseIMETHODCALL + * + * @param pIMethodCallE + * @return CIMRequest + * @throws CIMXMLParseException + */ + public static CIMRequest parseIMETHODCALL(Element pIMethodCallE) throws CIMXMLParseException { + // + // + + CIMRequest request = new CIMRequest(); + String methodname = attribute(pIMethodCallE, "NAME"); // ebak: + // CIMName->NAME + if (methodname == null) throw new CIMXMLParseException("IMETHODCALL element missing NAME attribute!"); + request.setMethodName(methodname); + + // METHODCALL + Element localnamespacepathA[] = searchNodes(pIMethodCallE, "LOCALNAMESPACEPATH", 1, 1, true); + if (localnamespacepathA != null) { + String nameSpace = parseLOCALNAMESPACEPATH(localnamespacepathA[0]); + request.setNameSpace(nameSpace); + } + + Element[] iParamValElementA = searchNodes(pIMethodCallE, "IPARAMVALUE", 0, Integer.MAX_VALUE, true); // ebak: + // PARAMVALUE->IPARAMVALUE + + if (iParamValElementA != null) { + CIMArgument[] argA = new CIMArgument[iParamValElementA.length]; + for (int i = 0; i < iParamValElementA.length; i++) { + Element paramvalueE = iParamValElementA[i]; + CIMArgument arg = parseIPARAMVALUE(paramvalueE); + /* + * ebak: local nameSpacePath should be added to those reference + * arguments which don't contain namespace + */ + Object value = arg.getValue(); + if (value instanceof CIMObjectPath) { + CIMObjectPath op = (CIMObjectPath) value; + if (op.getNamespace() == null || op.getNamespace().length() == 0) { + arg = + new CIMArgument( + arg.getName(), + arg.getDataType(), + // CIMObjectPath(String scheme, String host, String + // port, String namespace, String objectName, + // CIMProperty[] keys) + new CIMObjectPath( + op.getScheme(), + op.getHost(), + op.getPort(), + request.getNameSpace(), + op.getObjectName(), + op.getKeys() + ) + ); + } + } + argA[i] = arg; + } + request.addParamValue(argA); + } + + checkOtherNodes(pIMethodCallE, nodesIMETHODCALL); + return request; + } + + private static final String nodesSIMPLEEXPREQ[] = { "CORRELATOR", "EXPMETHODCALL" }; + + /** + * parseSIMPLEEXPREQ + * + * @param pSimpleExpReqE + * @return CIMRequest + * @throws CIMXMLParseException + */ + public static CIMRequest parseSIMPLEEXPREQ(Element pSimpleExpReqE) throws CIMXMLParseException { + // + CIMRequest request = null; + + // EXPMETHODCALL + Element[] expmethodcallA = searchNodes(pSimpleExpReqE, "EXPMETHODCALL", 1, 1, true); + if (expmethodcallA != null) { + request = parseEXPMETHODCALL(expmethodcallA[0]); + } else { + throw new CIMXMLParseException("SIMPLEEXPREQ element missing EXPMETHODCALL child element!"); + } + + // CORRELATOR + Element[] correlatorA = searchNodes(pSimpleExpReqE, "CORRELATOR", 0, Integer.MAX_VALUE, true); + if (correlatorA != null) { + for (int i = 0; i < correlatorA.length; i++) // TODO: return to WBEMClient API if JSR48 changes + parseCORRELATOR(correlatorA[i]); + } + + checkOtherNodes(pSimpleExpReqE, nodesSIMPLEEXPREQ); + return request; + } + + /** + * parseMULTIEXPREQ + * + * @param pMultiExpReqE + * @return CIMRequest + * @throws CIMXMLParseException + */ + public static CIMRequest parseMULTIEXPREQ(Element pMultiExpReqE) throws CIMXMLParseException { + // + + Element[] methodReqElementA = searchNodes(pMultiExpReqE, "SIMPLEEXPREQ", 2, Integer.MAX_VALUE, false); + if (methodReqElementA != null) { + CIMRequest multiReq = new CIMRequest(); + for (int i = 0; i < methodReqElementA.length; i++) { + Element methodrequestE = methodReqElementA[i]; + CIMRequest req = parseSIMPLEEXPREQ(methodrequestE); + req.setMethod("SIMPLEEXPREQ"); + + multiReq.addRequest(req); + } + return multiReq; + } + throw new CIMXMLParseException("MULTIEXPREQ element missing SIMPLEEXPREQ child element!"); + } + + private static final String nodesEXPMETHODCALL[] = { "EXPPARAMVALUE" }; + + /** + * parseEXPMETHODCALL + * + * @param pExpMethodCallE + * @return CIMRequest + * @throws CIMXMLParseException + */ + public static CIMRequest parseEXPMETHODCALL(Element pExpMethodCallE) throws CIMXMLParseException { + // + + // EXPMETHODCALL + CIMRequest request = new CIMRequest(); + String methodname = attribute(pExpMethodCallE, "NAME"); + if (methodname == null) throw new CIMXMLParseException("EXPMETHODCALL element missing NAME attribute!"); + request.setMethodName(methodname); + + Element[] paramValElementA = searchNodes(pExpMethodCallE, "EXPPARAMVALUE", 0, Integer.MAX_VALUE, false); + Vector v = new Vector(); + if (paramValElementA != null) { + for (int i = 0; i < paramValElementA.length; i++) { + Element expparamvalueE = paramValElementA[i]; + CIMInstance inst = parseEXPPARAMVALUE(expparamvalueE); + v.add(inst); + } + } + request.addParamValue(v); + checkOtherNodes(pExpMethodCallE, nodesEXPMETHODCALL); + return request; + } + + private static final String nodesEXPPARAMVALUE[] = { "INSTANCE" }; + + /** + * parseEXPPARAMVALUE + * + * @param pExpParamValueE + * @return CIMInstance + * @throws CIMXMLParseException + */ + public static CIMInstance parseEXPPARAMVALUE(Element pExpParamValueE) throws CIMXMLParseException { + // + // + // INSTANCE + if (attribute(pExpParamValueE, "NAME") == null) throw new CIMXMLParseException( + "EXPPARAMVALUE element missing NAME attribute!" + ); + + Element[] instanceA = searchNodes(pExpParamValueE, "INSTANCE", 0, 1, false); + if (instanceA != null) { + CIMInstance inst = parseINSTANCE(instanceA[0]); + return inst; + } + + checkOtherNodes(pExpParamValueE, nodesEXPPARAMVALUE); + + return null; + } + + private static final String nodesMETHODRESPONSE[] = { "ERROR", "RETURNVALUE", "PARAMVALUE" }; + + /** + * parseMETHODRESPONSE + * + * @param pMethodResponseE + * @return CIMResponse + * @throws CIMXMLParseException + */ + public static CIMResponse parseMETHODRESPONSE(Element pMethodResponseE) throws CIMXMLParseException { + // + if (attribute(pMethodResponseE, "NAME") == null) throw new CIMXMLParseException( + "METHODRESPONSE element missing NAME attribute!" + ); + + CIMResponse response = new CIMResponse(); + + // ERROR + Element errorA[] = searchNodes(pMethodResponseE, "ERROR", 0, 1, false); + if (errorA != null) { + WBEMException exception = parseERROR(errorA[0]); + response.setError(exception); + return response; + } + + // RETURNVALUE + Element[] retValElementA = searchNodes(pMethodResponseE, "RETURNVALUE", 0, 1, true); + if (retValElementA != null) { + Vector v = new Vector(); + for (int i = 0; i < retValElementA.length; i++) { + Element returnvalueE = retValElementA[i]; + v.add(parseRETURNVALUE(returnvalueE)); + } + response.setReturnValue(v); + } + + // PARAMVALUE + Element[] paramValElementA = searchNodes(pMethodResponseE, "PARAMVALUE", 0, Integer.MAX_VALUE, true); + if (paramValElementA != null) { + Vector v = new Vector(); + for (int i = 0; i < paramValElementA.length; i++) { + Element paramvalueE = paramValElementA[i]; + CIMArgument arg = parsePARAMVALUE(paramvalueE); + v.add(arg); + } + response.addParamValue(v); + } + + // PARAMVALUE (ESS fix) + if (retValElementA != null) { + for (int i = 0; i < retValElementA.length; i++) { + Element retValE = retValElementA[i]; + + paramValElementA = searchNodes(retValE, "PARAMVALUE"); + if (paramValElementA != null) { + Vector> v = new Vector>(); + for (int j = 0; j < paramValElementA.length; j++) { + Element paramvalueE = paramValElementA[j]; + CIMArgument arg = parsePARAMVALUE(paramvalueE); + v.add(arg); + } + response.addParamValue(v); + } + } + } + checkOtherNodes(pMethodResponseE, nodesMETHODRESPONSE); + + return response; + } + + private static final String nodesIMETHODRESPONSE[] = { "ERROR", "IRETURNVALUE", "PARAMVALUE" }; + + /** + * parseIMETHODRESPONSE + * + * @param pIMethodResponseE + * @return CIMResponse + * @throws CIMXMLParseException + */ + public static CIMResponse parseIMETHODRESPONSE(Element pIMethodResponseE) throws CIMXMLParseException { + // + if (attribute(pIMethodResponseE, "NAME") == null) throw new CIMXMLParseException( + "IMETHODRESPONSE element missing NAME attribute!" + ); + + CIMResponse response = new CIMResponse(); + // ERROR + Element[] errorA = searchNodes(pIMethodResponseE, "ERROR", 0, 1, false); + if (errorA != null) { + WBEMException exception = parseERROR(errorA[0]); + response.setError(exception); + return response; + } + + // IRETURNVALUE + Element[] retValElementA = searchNodes(pIMethodResponseE, "IRETURNVALUE", 0, 1, true); + if (retValElementA != null) { + for (int i = 0; i < retValElementA.length; i++) { + Element ireturnvalueE = retValElementA[i]; + + Vector rtnV = parseIRETURNVALUE(ireturnvalueE); + response.setReturnValue(rtnV); + } + } + + // PARAMVALUE + Element[] paramValElementA = searchNodes(pIMethodResponseE, "PARAMVALUE", 0, Integer.MAX_VALUE, true); + if (paramValElementA != null) { + Vector v = new Vector(); + for (int i = 0; i < paramValElementA.length; i++) { + Element paramvalueE = paramValElementA[i]; + CIMArgument arg = parsePARAMVALUE(paramvalueE); + v.add(arg); + } + response.addParamValue(v); + } + checkOtherNodes(pIMethodResponseE, nodesIMETHODRESPONSE); + + return response; + } + + private static final String nodesERROR[] = { "INSTANCE" }; + + /** + * parseERROR + * + * @param pErrorE + * @return WBEMException + * @throws CIMXMLParseException + */ + public static WBEMException parseERROR(Element pErrorE) throws CIMXMLParseException { + // + // + + Attr error_codeA = (Attr) searchAttribute(pErrorE, "CODE"); + if (error_codeA == null) throw new CIMXMLParseException("ERROR element missing CODE attribute!"); + String code = error_codeA.getNodeValue(); + int errorCode = 0; + try { + if (code.length() > 0) errorCode = Integer.parseInt(code); + } catch (Exception e) { + LogAndTraceBroker.getBroker().trace(Level.WARNING, "exception while parsing error code from XML", e); + errorCode = WBEMException.CIM_ERR_FAILED; + } + Attr error_descriptionA = (Attr) searchAttribute(pErrorE, "DESCRIPTION"); + String description = ""; + if (error_descriptionA != null) { + description = error_descriptionA.getNodeValue(); + } + + Vector rtnV = new Vector(); + + // INSTANCE + Element[] instElementA = searchNodes(pErrorE, "INSTANCE", 0, Integer.MAX_VALUE, false); + if (instElementA != null) { + for (int i = 0; i < instElementA.length; i++) { + Element instanceE = instElementA[i]; + CIMInstance inst = parseINSTANCE(instanceE); + rtnV.add(inst); + } + } + checkOtherNodes(pErrorE, nodesERROR); + + // throw new CIMException(CIMException.getErrorName(errorCode), + // description.substring(description.indexOf(':')+1)); + if (!rtnV.isEmpty()) return new WBEMException( + errorCode, + "ErrorCode:" + errorCode + " description:" + description, + rtnV.toArray(new CIMInstance[0]) + ); + return new WBEMException(errorCode, "ErrorCode:" + errorCode + " description:" + description); + } + + private static final String nodesRETURNVALUE[] = { "VALUE", "VALUE.REFERENCE" }; + + /** + * parseRETURNVALUE + * + * @param pRetValE + * @return Object + * @throws CIMXMLParseException + */ + public static Object parseRETURNVALUE(Element pRetValE) throws CIMXMLParseException { + // + // + // ebak: embedded object support: different parsing of VALUE sub element + checkOtherNodes(pRetValE, nodesRETURNVALUE); + if (searchNodes(pRetValE, "VALUE", 0, 1, false) != null) { + EmbObjHandler embObjHandler = new EmbObjHandler(pRetValE); + return embObjHandler.getValue(); + } + if (searchNodes(pRetValE, "VALUE.REFERENCE", 0, 1, false) != null) { + TypedValue typedVal = parseSingleValue(pRetValE, VALUEREF); + Object value = typedVal.getValue(); + return value; + } + checkOtherNodes(pRetValE, nodesRETURNVALUE); + return null; + } + + private static final String nodesIRETURNVALUE[] = { + "CLASSNAME", + "INSTANCENAME", + "VALUE", + "VALUE.OBJECTWITHPATH", + "VALUE.OBJECTWITHLOCALPATH", + "VALUE.OBJECT", + "OBJECTPATH", + "QUALIFIER.DECLARATION", + "VALUE.ARRAY", + "VALUE.REFERENCE", + "CLASS", + "INSTANCE", + "INSTANCEPATH", + "VALUE.NAMEDINSTANCE" + }; + + /** + * parseIRETURNVALUE + * + * @param pIRetValE + * @return Vector + * @throws CIMXMLParseException + */ + public static Vector parseIRETURNVALUE(Element pIRetValE) throws CIMXMLParseException { + // + + Vector rtnV = new Vector(); + + // CLASS + Element[] classElementA = searchNodes(pIRetValE, "CLASS", 0, Integer.MAX_VALUE, false); + if (classElementA != null) { + for (int i = 0; i < classElementA.length; i++) { + Element classE = classElementA[i]; + CIMClass c = parseCLASS(classE); + rtnV.add(c); + } + return rtnV; + } + + // INSTANCE + Element[] instElementA = searchNodes(pIRetValE, "INSTANCE", 0, Integer.MAX_VALUE, false); + if (instElementA != null) { + for (int i = 0; i < instElementA.length; i++) { + Element instanceE = instElementA[i]; + CIMInstance inst = parseINSTANCE(instanceE); + rtnV.add(inst); + } + return rtnV; + } + + // CLASSNAME + Element[] classNameElementA = searchNodes(pIRetValE, "CLASSNAME", 0, Integer.MAX_VALUE, false); + if (classNameElementA != null) { + for (int i = 0; i < classNameElementA.length; i++) { + Element classnameE = classNameElementA[i]; + CIMObjectPath op = parseCLASSNAME(classnameE); + rtnV.add(op); + } + return rtnV; + } + + // INSTANCENAME + Element[] instNameElementA = searchNodes(pIRetValE, "INSTANCENAME", 0, Integer.MAX_VALUE, false); + if (instNameElementA != null) { + for (int i = 0; i < instNameElementA.length; i++) { + Element instancenameE = instNameElementA[i]; + CIMObjectPath op = parseINSTANCENAME(instancenameE); + rtnV.add(op); + } + return rtnV; + } + + // INSTANCEPATH + Element[] instpathElementA = searchNodes(pIRetValE, "INSTANCEPATH", 0, Integer.MAX_VALUE, false); + if (instpathElementA != null) { + for (int i = 0; i < instpathElementA.length; i++) { + Element instancePathE = instpathElementA[i]; + CIMObjectPath op = parseINSTANCEPATH(instancePathE); + rtnV.add(op); + } + return rtnV; + } + + // OBJECTPATH + Element[] objPathElementA = searchNodes(pIRetValE, "OBJECTPATH", 0, Integer.MAX_VALUE, false); + if (objPathElementA != null) { + for (int i = 0; i < objPathElementA.length; i++) { + Element objectpathE = objPathElementA[i]; + CIMObjectPath op = parseOBJECTPATH(objectpathE); + rtnV.add(op); + } + return rtnV; + } + + // VALUE + Element[] valueElementA = searchNodes(pIRetValE, "VALUE", 0, Integer.MAX_VALUE, false); + if (valueElementA != null) { + for (int i = 0; i < valueElementA.length; i++) { + Element valueE = valueElementA[i]; + TypedValue tv = parseVALUE(valueE); + rtnV.add(tv.getValue()); + } + return rtnV; + } + + // VALUE.ARRAY + Element[] valueArrayElementA = searchNodes(pIRetValE, "VALUE.ARRAY", 0, 1, false); + if (valueArrayElementA != null) { + Element valuearrayE = valueArrayElementA[0]; + TypedValue tv = parseVALUEARRAY(valuearrayE); + rtnV.add(tv.getValue()); + return rtnV; + } + + // VALUE.REFERENCE + Element[] valRefElementA = searchNodes(pIRetValE, "VALUE.REFERENCE", 0, 1, false); + if (valRefElementA != null) { + Element valuereferenceE = valRefElementA[0]; + CIMObjectPath op = parseVALUEREFERENCE(valuereferenceE); + rtnV.add(op); + return rtnV; + } + + // VALUE.OBJECT + Element[] valObjElementA = searchNodes(pIRetValE, "VALUE.OBJECT", 0, Integer.MAX_VALUE, false); + if (valObjElementA != null) { + for (int i = 0; i < valObjElementA.length; i++) { + Element valueobjectE = valObjElementA[i]; + CIMNamedElementInterface obj = parseVALUEOBJECT(valueobjectE); + rtnV.add(obj); + } + return rtnV; + } + + // VALUE.NAMEDINSTANCE + Element[] valNamedInstElementA = searchNodes(pIRetValE, "VALUE.NAMEDINSTANCE", 0, Integer.MAX_VALUE, false); + if (valNamedInstElementA != null) { + for (int i = 0; i < valNamedInstElementA.length; i++) { + Element valuenamedisntanceE = valNamedInstElementA[i]; + CIMInstance inst = parseVALUENAMEDINSTANCE(valuenamedisntanceE); + rtnV.add(inst); + } + return rtnV; + } + + // VALUE.INSTANCEWITHPATH + Element[] valInstWithPathElementA = searchNodes(pIRetValE, "VALUE.INSTANCEWITHPATH", 0, Integer.MAX_VALUE, false); + if (valInstWithPathElementA != null) { + for (int i = 0; i < valInstWithPathElementA.length; i++) { + Element valueinstancewithpathE = valInstWithPathElementA[i]; + CIMInstance inst = parseVALUEINSTANCEWITHPATH(valueinstancewithpathE); + rtnV.add(inst); + } + return rtnV; + } + + // VALUE.OBJECTWITHPATH + Element[] valObjWithPathElementA = searchNodes(pIRetValE, "VALUE.OBJECTWITHPATH", 0, Integer.MAX_VALUE, false); + if (valObjWithPathElementA != null) { + for (int i = 0; i < valObjWithPathElementA.length; i++) { + Element valueobjectwithpathE = valObjWithPathElementA[i]; + CIMNamedElementInterface namedIF = parseVALUEOBJECTWITHPATH(valueobjectwithpathE); + rtnV.add(namedIF); + } + return rtnV; + } + + // VALUE.OBJECTWITHLOCALPATH + Element[] valObjWithLocalPathElementA = searchNodes( + pIRetValE, + "VALUE.OBJECTWITHLOCALPATH", + 0, + Integer.MAX_VALUE, + false + ); + if (valObjWithLocalPathElementA != null) { + for (int i = 0; i < valObjWithLocalPathElementA.length; i++) { + Element valueobjectwithlocalpathE = valObjWithLocalPathElementA[i]; + CIMNamedElementInterface namedIF = parseVALUEOBJECTWITHLOCALPATH(valueobjectwithlocalpathE); + rtnV.add(namedIF); + } + return rtnV; + } + + // QUALIFIER.DECLARATION + Element[] qualiDeclElementA = searchNodes(pIRetValE, "QUALIFIER.DECLARATION", 0, Integer.MAX_VALUE, false); + if (qualiDeclElementA != null) { + for (int i = 0; i < qualiDeclElementA.length; i++) { + Element qualifierdeclarationE = qualiDeclElementA[i]; + CIMQualifierType o = parseQUALIFIERDECLARATION(qualifierdeclarationE); + rtnV.add(o); + } + return rtnV; + } + checkOtherNodes(pIRetValE, nodesIRETURNVALUE); + return rtnV; + } + + /** + * parseObject + * + * @param pRootE + * @return Object + * @throws CIMXMLParseException + */ + public static Object parseObject(Element pRootE) throws CIMXMLParseException { + Object o = null; + String nodeName = pRootE.getNodeName(); + if (nodeName.equalsIgnoreCase("INSTANCE")) { + o = parseINSTANCE(pRootE); + } else if (nodeName.equalsIgnoreCase("VALUE.NAMEDINSTANCE")) { + o = parseVALUENAMEDINSTANCE(pRootE); + } else if (nodeName.equalsIgnoreCase("VALUE.NAMEDOBJECT")) { + o = parseVALUENAMEDOBJECT(pRootE); + } else if (nodeName.equalsIgnoreCase("VALUE.OBJECTWITHPATH")) { + o = parseVALUEOBJECTWITHPATH(pRootE); + } else if (nodeName.equalsIgnoreCase("VALUE.OBJECTWITHLOCALPATH")) { + o = parseVALUEOBJECTWITHLOCALPATH(pRootE); + } else if (nodeName.equalsIgnoreCase("CLASS")) { + o = parseCLASS(pRootE); + } else if (nodeName.equalsIgnoreCase("CLASSPATH")) { + o = parseCLASSPATH(pRootE); + } else if (nodeName.equalsIgnoreCase("LOCALCLASSPATH")) { + o = parseLOCALCLASSPATH(pRootE); + } else if (nodeName.equalsIgnoreCase("OBJECTPATH")) { + o = parseOBJECTPATH(pRootE); + } else if (nodeName.equalsIgnoreCase("CLASSNAME")) { + o = parseCLASSNAME(pRootE); + } else if (nodeName.equalsIgnoreCase("INSTANCEPATH")) { + o = parseINSTANCEPATH(pRootE); + } else if (nodeName.equalsIgnoreCase("LOCALINSTANCEPATH")) { + o = parseLOCALINSTANCEPATH(pRootE); + } else if (nodeName.equalsIgnoreCase("INSTANCENAME")) { + o = parseINSTANCENAME(pRootE); + } else if (nodeName.equalsIgnoreCase("QUALIFIER")) { + o = parseQUALIFIER(pRootE); + } else if (nodeName.equalsIgnoreCase("PROPERTY")) { + o = parsePROPERTY(pRootE); + } else if (nodeName.equalsIgnoreCase("PROPERTY.ARRAY")) { + o = parsePROPERTYARRAY(pRootE); + } else if (nodeName.equalsIgnoreCase("PROPERTY.REFERENCE")) { + o = parsePROPERTYREFERENCE(pRootE); + } else if (nodeName.equalsIgnoreCase("METHOD")) { + o = parseMETHOD(pRootE); + } else if (nodeName.equalsIgnoreCase("PARAMETER")) { + o = parsePARAMETER(pRootE); + } else if (nodeName.equalsIgnoreCase("PARAMETER.REFERENCE")) { + o = parsePARAMETERREFERENCE(pRootE); + } else if (nodeName.equalsIgnoreCase("PARAMETER.ARRAY")) { + o = parsePARAMETERARRAY(pRootE); + } else if (nodeName.equalsIgnoreCase("PARAMETER.REFARRAY")) { + o = parsePARAMETERREFARRAY(pRootE); + } + return o; + } + + // /////////////////////////////////////////////////////////////////////////////////////////// + + /** + * hasNodes + * + * @param pParentE + * @return boolean + */ + private static boolean hasNodes(Element pParentE) { + NodeList nl = pParentE.getChildNodes(); + if (nl == null || nl.getLength() == 0) return false; + for (int i = 0; i < nl.getLength(); i++) { + Node n = nl.item(i); + if (!(n instanceof Text) || !("".equalsIgnoreCase(n.getNodeValue().trim()))) return true; + } + return false; + } + + /** + * hasTypeAttrsInNodes + * + * SVC CIMOM sends typed CIM-XML elements in a non-standard way. The TYPE + * attribute is included in the VALUE or VALUE.ARRAY element not in the + * enclosing element as the standard says. + * + * @param pParentE + * @return boolean + */ + private static boolean hasTypeAttrsInNodes(Element pParentE) { + NodeList nl = pParentE.getChildNodes(); + if (nl == null || nl.getLength() == 0) return false; + for (int i = 0; i < nl.getLength(); i++) { + Node n = nl.item(i); + String name = n.getNodeName(); + if ("VALUE".equalsIgnoreCase(name) || "VALUE.ARRAY".equalsIgnoreCase(name)) { + NamedNodeMap nm = n.getAttributes(); + if (nm != null && (nm.getNamedItem("TYPE") != null || nm.getNamedItem("PARAMTYPE") != null)) return true; + } + } + return false; + } + + private static final HashMap NODENAME_HASH = new HashMap(); + + private static void initNodeNameHash(String[] pEnumA) { + for (int i = 0; i < pEnumA.length; i++) NODENAME_HASH.put(pEnumA[i], pEnumA[i]); + } + + static { + initNodeNameHash( + new String[] { + "CIM", + "DECLARATION", + "DECLGROUP", + "DECLGROUP.WITHNAME", + "DECLGROUP.WITHPATH", + "QUALIFIER.DECLARATION", + "SCOPE", + "VALUE", + "VALUE.ARRAY", + "VALUE.REFERENCE", + "VALUE.REFARRAY", + "VALUE.OBJECT", + "VALUE.NAMEDINSTANCE", + "VALUE.NAMEDOBJECT", + "VALUE.OBJECTWITHLOCALPATH", + "VALUE.OBJECTWITHPATH", + "VALUE.NULL", + "VALUE.INSTANCEWITHPATH", + "NAMESPACEPATH", + "LOCALNAMESPACEPATH", + "HOST", + "NAMESPACE", + "CLASSPATH", + "LOCALCLASSPATH", + "CLASSNAME", + "INSTANCEPATH", + "LOCALINSTANCEPATH", + "INSTANCENAME", + "OBJECTPATH", + "KEYBINDING", + "KEYVALUE", + "CLASS", + "INSTANCE", + "QUALIFIER", + "PROPERTY", + "PROPERTY.ARRAY", + "PROPERTY.REFERENCE", + "METHOD", + "PARAMETER", + "PARAMETER.REFERENCE", + "PARAMETER.ARRAY", + "PARAMETER.REFARRAY", + "MESSAGE", + "MULTIREQ", + "MULTIEXPREQ", + "SIMPLEREQ", + "SIMPLEEXPREQ", + "IMETHODCALL", + "METHODCALL", + "EXPMETHODCALL", + "PARAMVALUE", + "IPARAMVALUE", + "EXPPARAMVALUE", + "MULTIRSP", + "MULTIEXPRSP", + "SIMPLERSP", + "SIMPLEEXPRSP", + "METHODRESPONSE", + "EXPMETHODRESPONSE", + "IMETHODRESPONSE", + "ERROR", + "RETURNVALUE", + "IRETURNVALUE", + "CORRELATOR" + } + ); + } + + /** + * checkOtherNodes + * + * @param pParentE + * @param pAllowedChildNodes + */ + private static void checkOtherNodes(Element pParentE, String[] pAllowedChildNodes) throws CIMXMLParseException { + NodeList nl = pParentE.getChildNodes(); + if (nl == null || nl.getLength() == 0) return; + for (int i = 0; i < nl.getLength(); i++) { + Node n = nl.item(i); + if (n instanceof Text && "".equalsIgnoreCase(n.getNodeValue().trim())) continue; + boolean found = false; + String name = n.getNodeName().toUpperCase(); + for (int j = 0; j < pAllowedChildNodes.length; j++) { + if (pAllowedChildNodes[j].equalsIgnoreCase(name)) { + found = true; + break; + } + } + if (!found && NODENAME_HASH.containsKey(name)) throw new CIMXMLParseException( + pParentE.getNodeName() + " element contains invalid child element " + name + "!" + ); + } + } + + /** + * searchNodes + * + * @param pParentE + * @param pTagName + * @return Element[] + */ + public static Element[] searchNodes(Element pParentE, String pTagName) { + // return all of child nodes immediately below the parent + // return null if not found + NodeList nl = pParentE.getChildNodes(); + if (nl == null || nl.getLength() == 0) return null; + Vector resElementV = new Vector(); + for (int i = 0; i < nl.getLength(); i++) { + Node n = nl.item(i); + if (n.getNodeName().equals(pTagName)) { + resElementV.add(n); + } + } + return resElementV.toArray(new Element[0]); + } + + /** + * searchNodes + * + * @param pParentE + * @param pTagName + * @param pMin + * @param pMax + * @param pAllowOtherNodes + * @return Element[] + * @throws CIMXMLParseException + */ + public static Element[] searchNodes(Element pParentE, String pTagName, int pMin, int pMax, boolean pAllowOtherNodes) + throws CIMXMLParseException { + // return all child nodes immediately below parent, null if none found + + NodeList nl = pParentE.getChildNodes(); + if (nl == null || nl.getLength() == 0) { + if (pMin > 0) throw new CIMXMLParseException( + pParentE.getNodeName() + " element must have at least " + pMin + " " + pTagName + " child element(s)!" + ); + return null; + } + + String otherNode = null; + Vector resElementV = new Vector(); + for (int i = 0; i < nl.getLength(); i++) { + Node n = nl.item(i); + String name = n.getNodeName().toUpperCase(); + if (name.equals(pTagName)) { + resElementV.add(n); + } else if (NODENAME_HASH.containsKey(name)) { + otherNode = name; + } + } + + if (resElementV.size() < pMin) throw new CIMXMLParseException( + pParentE.getNodeName() + " element must have at least " + pMin + " " + pTagName + " child element(s)!" + ); + if (resElementV.size() > pMax) throw new CIMXMLParseException( + pParentE.getNodeName() + " element can have no more than " + pMax + " " + pTagName + " child element(s)!" + ); + if (resElementV.size() > 0 && !pAllowOtherNodes && otherNode != null) throw new CIMXMLParseException( + pParentE.getNodeName() + + " element cannot have " + + otherNode + + " child element(s) when it already has " + + pTagName + + " element(s)!" + ); + if (resElementV.size() == 0) return null; + + return resElementV.toArray(new Element[0]); + } + + /** + * searchFirstNode + * + * @param pParentE + * @param pTagName + * @return Node + */ + public static Node searchFirstNode(Element pParentE, String pTagName) { + // return the first node which matches to the specific name + // return null if not found + NodeList nl = pParentE.getChildNodes(); + for (int i = 0; i < nl.getLength(); i++) { + Node n = nl.item(i); + if (n.getNodeName().equals(pTagName)) { + return n; + } + } + return null; + } + + /** + * searchAttribute + * + * @param pParentN + * @param pAttrName + * @return Node + */ + public static Node searchAttribute(Node pParentN, String pAttrName) { + // return the attribute node with the specific name + NamedNodeMap nnm = pParentN.getAttributes(); + return nnm.getNamedItem(pAttrName); + } + + /** + * searchFirstChild + * + * @param pParentE + * @return Node + */ + public static Node searchFirstChild(Element pParentE) { + // return the first node which matches to the specific name + // return null if not found + return pParentE.getFirstChild(); + } + + /** + * createJavaObject + * + * @param pTypeStr + * @param pValue + * @return Object + * @throws CIMXMLParseException + */ + public static Object createJavaObject(String pTypeStr, String pValue) throws CIMXMLParseException { + // return a java object with the specific type + if (pTypeStr == null) pTypeStr = MOF.DT_STR; + if (MOF.NULL.equalsIgnoreCase(pTypeStr)) return null; + Object o = null; + CIMDataType cimType = parseTypeStr(pTypeStr, false); + int radix = 10; + + if (pTypeStr.toLowerCase().startsWith("sint") || pTypeStr.toLowerCase().startsWith("uint")) { + pValue = pValue.toLowerCase(); + if (pValue.startsWith("0x") || pValue.startsWith("+0x") || pValue.startsWith("-0x")) { + radix = 16; + if (pValue.startsWith("-")) pValue = "-" + pValue.substring(3); else pValue = + pValue.substring(pValue.indexOf('x') + 1); + } + } + + switch (cimType.getType()) { + case CIMDataType.UINT8: + o = new UnsignedInteger8(Short.parseShort(pValue, radix)); + break; + case CIMDataType.UINT16: + o = new UnsignedInteger16(Integer.parseInt(pValue, radix)); + break; + case CIMDataType.UINT32: + o = new UnsignedInteger32(Long.parseLong(pValue, radix)); + break; + case CIMDataType.UINT64: + o = new UnsignedInteger64(new BigInteger(pValue, radix)); + break; + case CIMDataType.SINT8: + o = Byte.valueOf(pValue, radix); + break; + case CIMDataType.SINT16: + o = Short.valueOf(pValue, radix); + break; + case CIMDataType.SINT32: + o = Integer.valueOf(pValue, radix); + break; + case CIMDataType.SINT64: + o = Long.valueOf(pValue, radix); + break; + case CIMDataType.STRING: + o = pValue; + break; + case CIMDataType.BOOLEAN: + o = Boolean.valueOf(pValue); + break; + case CIMDataType.REAL32: + o = new Float(pValue); + break; + case CIMDataType.REAL64: + if (WBEMConfiguration.getGlobalConfiguration().verifyJavaLangDoubleStrings()) { + if (Util.isBadDoubleString(pValue)) throw new IllegalArgumentException( + "Double value string hangs older JVMs!\n" + pValue + ); + } + o = new Double(pValue); + break; + case CIMDataType.DATETIME: + o = getDateTime(pValue); + break; + case CIMDataType.REFERENCE: + o = new CIMObjectPath(pValue); + break; + case CIMDataType.CHAR16: + o = Character.valueOf(pValue.charAt(0)); + break; + // case CIMDataType.OBJECT: o = new CIMInstance(); break; //TODO + // case CIMDataType.CLASS: o = new CIMClass(value); break; //TODO + } + return o; + } + + private static CIMDateTime getDateTime(String pValue) throws CIMXMLParseException { + try { + return new CIMDateTimeAbsolute(pValue); + } catch (IllegalArgumentException eAbs) { + try { + return new CIMDateTimeInterval(pValue); + } catch (IllegalArgumentException eInt) { + throw new CIMXMLParseException( + "Failed to parse dateTime string: " + + pValue + + "!\n" + + "CIMDateTimeAbsolute parsing error:\n" + + eAbs.getMessage() + + "\n" + + "CIMDateTimeInterval parsing error:\n" + + eInt.getMessage() + ); + } + } + } + + /** + * parseSIMPLEEXPRSP + * + * @param pSimpleExpRspE + * @return CIMResponse + * @throws CIMXMLParseException + */ + public static CIMResponse parseSIMPLEEXPRSP(Element pSimpleExpRspE) throws CIMXMLParseException { + // + + // EXPMETHODRESPONSE + Element[] expmethodresponseA = searchNodes(pSimpleExpRspE, "EXPMETHODRESPONSE", 1, 1, false); + if (expmethodresponseA != null) return parseEXPMETHODRESPONSE(expmethodresponseA[0]); + + throw new CIMXMLParseException("SIMPLEEXPRSP element missing EXPMETHODRESPONSE child element!"); + } + + /** + * parseMULTIEXPRSP + * + * @param pMultiExpRspE + * @return CIMResponse + * @throws CIMXMLParseException + */ + public static CIMResponse parseMULTIEXPRSP(Element pMultiExpRspE) throws CIMXMLParseException { + // + + Element[] multiExpRespElementA = searchNodes(pMultiExpRspE, "SIMPLEEXPRSP", 2, Integer.MAX_VALUE, false); + if (multiExpRespElementA != null) { + CIMResponse multiExpRsp = new CIMResponse(); + for (int i = 0; i < multiExpRespElementA.length; i++) { + Element methodresponseE = multiExpRespElementA[i]; + CIMResponse rsp = parseSIMPLEEXPRSP(methodresponseE); + rsp.setMethod("SIMPLEEXPRSP"); + multiExpRsp.addResponse(rsp); + } + return multiExpRsp; + } + + throw new CIMXMLParseException("MULTIEXPRSP element missing SIMPLEEXPRSP child element!"); + } + + private static final String[] nodesEXPMETHODRESPONSE = { "ERROR", "IRETURNVALUE" }; + + /** + * parseEXPMETHODRESPONSE + * + * @param pExpMethodResponseE + * @return CIMResponse + * @throws CIMXMLParseException + */ + public static CIMResponse parseEXPMETHODRESPONSE(Element pExpMethodResponseE) throws CIMXMLParseException { + // + + CIMResponse response = new CIMResponse(); + + if (attribute(pExpMethodResponseE, "NAME") == null) throw new CIMXMLParseException( + "EXPMETHODRESPONSE element missing NAME attribute!" + ); + + // ERROR + Element[] errorA = searchNodes(pExpMethodResponseE, "ERROR", 0, 1, false); + if (errorA != null) { + WBEMException exception = parseERROR(errorA[0]); + response.setError(exception); + return response; + } + + // RETURNVALUE + Element[] retValElementA = searchNodes(pExpMethodResponseE, "IRETURNVALUE", 0, 1, false); + if (retValElementA != null) { + Vector v = new Vector(); + Element returnvalueE = retValElementA[0]; + v.add(parseIRETURNVALUE(returnvalueE)); + response.setReturnValue(v); + return response; + } + + checkOtherNodes(pExpMethodResponseE, nodesEXPMETHODRESPONSE); + + return response; + } + + private static final String nodesCORRELATOR[] = { "VALUE" }; + + /** + * parseCORRELATOR + * + * @param pCorrelatorE + * @throws CIMXMLParseException + * */ + public static void parseCORRELATOR(Element pCorrelatorE) throws CIMXMLParseException { + // + // + String name = attribute(pCorrelatorE, "NAME"); + if (name == null) throw new CIMXMLParseException("CORRELATOR element missing NAME attribute!"); + String type = attribute(pCorrelatorE, "TYPE"); + if (type == null) throw new CIMXMLParseException("CORRELATOR element missing TYPE attribute!"); + + // VALUE + Element[] valueA = searchNodes(pCorrelatorE, "VALUE", 1, 1, false); + if (valueA != null) { + // TypedValue tVal = parseVALUE(valueA[0]); + } + + checkOtherNodes(pCorrelatorE, nodesCORRELATOR); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CimXmlSerializer.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CimXmlSerializer.java similarity index 84% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CimXmlSerializer.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CimXmlSerializer.java index 9953896..1cd1c92 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/CimXmlSerializer.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/CimXmlSerializer.java @@ -1,393 +1,388 @@ -/* - (C) Copyright IBM Corp. 2007, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1671502 2007-02-08 lupusalex Remove dependency from Xerces - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 3510321 2012-03-23 blaschke-oss Handle CDATA in CimXmlSerializer - * 3513357 2012-04-01 blaschke-oss Handle multiple CDATAs in CimXmlSerializer - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.BufferedWriter; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.nio.charset.Charset; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConstants; -import org.w3c.dom.Document; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - -/** - * Class CimXmlSerializer implements a XML serializer for DOM documents that is - * specialized for CIM-XML. It might not be used as a general purpose serializer - * since it doesn't support any DOM or XML features not required by CIM-XML. - * - */ -public class CimXmlSerializer { - - /** - * Class XmlWriter implements a writer on an output stream that escapes XML - * values according to the CIM-XML requirements. - * - */ - private static class XmlWriter { - - private BufferedWriter iWriter; - - /** - * Ctor. - * - * @param pOut - * The output stream the serialized document is written to - * @param pCharsetName - * The encoding the use for the output stream - */ - public XmlWriter(OutputStream pOut, String pCharsetName) { - this.iWriter = new BufferedWriter(new OutputStreamWriter(pOut, Charset.forName( - pCharsetName).newEncoder())); - } - - /** - * Writes text to the stream - * - * @param pText - * The text - * @throws IOException - */ - public void write(String pText) throws IOException { - if (pText != null) this.iWriter.write(pText); - } - - /** - * Closes the stream - * - * @throws IOException - */ - public void close() throws IOException { - this.iWriter.close(); - } - - /** - * Flushes the buffer to the stream - * - * @throws IOException - */ - public void flush() throws IOException { - this.iWriter.flush(); - } - - /** - * Writes a XML value (either attribute or text node). The value is - * escaped as follows:
      - *
      - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
      charresult
      < space&#xnn;
      > ~unchanged (UTF-8)
      spaceunchanged or &#x20;
      - * (First leading, last trailing and every other space are escaped)
      <&lt;
      >&gt;
      &&amp;
      "&quot;
      '&apos;
      otherunchanged
      - * - * @param pText - * The text - * @throws IOException - */ - public void writeValue(final String pText) throws IOException { - if (pText == null) { return; } - boolean escapeSpace = true; - final int oneBeforeLast = pText.length() - 2; - for (int i = 0; i < pText.length(); ++i) { - - char currentChar = pText.charAt(i); - boolean isSpace = false; - - if (isHighSurrogate(currentChar)) { - if (i > oneBeforeLast || !isLowSurrogate(pText.charAt(i + 1))) { throw new IOException( - "Illegal Unicode character"); } - this.iWriter.write(pText, i++, 2); - } else if (currentChar < ' ') { - writeAsHex(currentChar); - } else if (currentChar > '~') { - this.iWriter.write(currentChar); - } else { - switch (currentChar) { - case ' ': - isSpace = true; - if (escapeSpace) { - writeAsHex(currentChar); - } else { - this.iWriter.write(currentChar); - } - break; - case '<': - this.iWriter.write("<"); - break; - case '>': - this.iWriter.write(">"); - break; - case '&': - this.iWriter.write("&"); - break; - case '"': - this.iWriter.write("""); - break; - case '\'': - this.iWriter.write("'"); - break; - default: - this.iWriter.write(currentChar); - } - } - escapeSpace = (isSpace && !escapeSpace) || (i == oneBeforeLast); - } - } - - private void writeAsHex(char pChar) throws IOException { - this.iWriter.write("&#x" + Integer.toHexString(pChar) + ";"); - } - - private boolean isHighSurrogate(char pChar) { - return pChar >= WBEMConstants.UTF16_MIN_HIGH_SURROGATE - && pChar <= WBEMConstants.UTF16_MAX_HIGH_SURROGATE; - } - - private boolean isLowSurrogate(char pChar) { - return pChar >= WBEMConstants.UTF16_MIN_LOW_SURROGATE - && pChar <= WBEMConstants.UTF16_MAX_LOW_SURROGATE; - } - - } - - private boolean iPretty; - - private int iIndent = 0; - - private boolean iLastClosed = false; - - private final String CDATA_START = ""; - - private CimXmlSerializer(boolean pPretty) { - this.iPretty = pPretty; - } - - /** - * Serializes a given DOM document as (CIM-)XML to a given output stream. - * The method writes first - * <?xml version="1.0" encoding="UTF-8"?> - * and then serializes the document node. If you want to suppress this - * header just call {@link #serialize(OutputStream, Node, boolean)} on the - * document node. - * - * @param pOS - * The output stream - * @param pDoc - * The document - * @param pPretty - * If true the XML is nicely wrapped and indented, - * otherwise it's all in one line - * @throws IOException - * Whenever something goes wrong - */ - public static void serialize(OutputStream pOS, Document pDoc, boolean pPretty) - throws IOException { - - try { - XmlWriter writer = new XmlWriter(pOS, WBEMConstants.UTF8); - writer.write("\n"); - new CimXmlSerializer(pPretty).serializeNode(writer, pDoc.getDocumentElement()); - writer.flush(); - } catch (IOException ioe) { - throw ioe; - } catch (Exception e) { - throw new IOException(e.getMessage()); - } - } - - /** - * Serializes a given DOM node as (CIM-)XML to a given output stream - * - * @param pOS - * The output stream - * @param pNode - * The node - * @param pPretty - * If true the XML is nicely wrapped and indented, - * otherwise it's all in one line - * @throws IOException - * Whenever something goes wrong - */ - public static void serialize(OutputStream pOS, Node pNode, boolean pPretty) throws IOException { - - try { - XmlWriter writer = new XmlWriter(pOS, WBEMConstants.UTF8); - new CimXmlSerializer(pPretty).serializeNode(writer, pNode); - writer.flush(); - } catch (IOException ioe) { - throw ioe; - } catch (Exception e) { - throw new IOException(e.getMessage()); - } - } - - private void serializeNode(XmlWriter pWriter, Node pNode) throws IOException { - switch (pNode.getNodeType()) { - case Node.ELEMENT_NODE: - pWriter.write(indent()); - pWriter.write("<"); - pWriter.write(pNode.getNodeName()); - NamedNodeMap attributes = pNode.getAttributes(); - if (attributes != null) { - for (int i = 0; i < attributes.getLength(); ++i) { - pWriter.write(" "); - serializeNode(pWriter, attributes.item(i)); - } - } - Node child = pNode.getFirstChild(); - if (child == null) { - pWriter.write("/>"); - this.iLastClosed = true; - break; - } - pWriter.write(">"); - ++this.iIndent; - this.iLastClosed = false; - while (child != null) { - serializeNode(pWriter, child); - child = child.getNextSibling(); - } - --this.iIndent; - if (this.iLastClosed) { - pWriter.write(indent()); - } - pWriter.write(""); - this.iLastClosed = true; - break; - case Node.ATTRIBUTE_NODE: - pWriter.write(pNode.getNodeName()); - pWriter.write("=\""); - pWriter.writeValue(pNode.getNodeValue()); - pWriter.write("\""); - break; - case Node.TEXT_NODE: - String value = pNode.getNodeValue(); - if (value != null) { - int idx = 0; - int len = value.length(); - - while (idx < len) { - int cdata = value.indexOf(this.CDATA_START, idx); - - // rest of string not CDATA, write all (escaped) - if (cdata == -1) { - pWriter.writeValue(value.substring(idx)); - break; - } - - // write characters before CDATA (escaped) - if (idx < cdata) { - pWriter.writeValue(value.substring(idx, cdata)); - idx = cdata; - } - - int end = value.indexOf(this.CDATA_END, idx); - - // invalid CDATA - if (end == -1) { throw new IOException("CDATA section not closed: " + value); } - - // write CDATA (not escaped) - pWriter.write(value.substring(idx, end + this.CDATA_END.length())); - idx = end + this.CDATA_END.length(); - } - } - } - } - - private String indent() { - if (!this.iPretty) { return ""; } - StringBuffer result = new StringBuffer(); - result.append('\n'); - for (int i = 0; i < this.iIndent; ++i) { - result.append(' '); - } - return result.toString(); - } -} +/* + (C) Copyright IBM Corp. 2007, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1671502 2007-02-08 lupusalex Remove dependency from Xerces + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 3510321 2012-03-23 blaschke-oss Handle CDATA in CimXmlSerializer + * 3513357 2012-04-01 blaschke-oss Handle multiple CDATAs in CimXmlSerializer + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.nio.charset.Charset; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConstants; +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; + +/** + * Class CimXmlSerializer implements a XML serializer for DOM documents that is + * specialized for CIM-XML. It might not be used as a general purpose serializer + * since it doesn't support any DOM or XML features not required by CIM-XML. + * + */ +public class CimXmlSerializer { + + /** + * Class XmlWriter implements a writer on an output stream that escapes XML + * values according to the CIM-XML requirements. + * + */ + private static class XmlWriter { + private BufferedWriter iWriter; + + /** + * Ctor. + * + * @param pOut + * The output stream the serialized document is written to + * @param pCharsetName + * The encoding the use for the output stream + */ + public XmlWriter(OutputStream pOut, String pCharsetName) { + this.iWriter = new BufferedWriter(new OutputStreamWriter(pOut, Charset.forName(pCharsetName).newEncoder())); + } + + /** + * Writes text to the stream + * + * @param pText + * The text + * @throws IOException + */ + public void write(String pText) throws IOException { + if (pText != null) this.iWriter.write(pText); + } + + /** + * Closes the stream + * + * @throws IOException + */ + public void close() throws IOException { + this.iWriter.close(); + } + + /** + * Flushes the buffer to the stream + * + * @throws IOException + */ + public void flush() throws IOException { + this.iWriter.flush(); + } + + /** + * Writes a XML value (either attribute or text node). The value is + * escaped as follows:
      + *
      + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
      charresult
      < space&#xnn;
      > ~unchanged (UTF-8)
      spaceunchanged or &#x20;
      + * (First leading, last trailing and every other space are escaped)
      <&lt;
      >&gt;
      &&amp;
      "&quot;
      '&apos;
      otherunchanged
      + * + * @param pText + * The text + * @throws IOException + */ + public void writeValue(final String pText) throws IOException { + if (pText == null) { + return; + } + boolean escapeSpace = true; + final int oneBeforeLast = pText.length() - 2; + for (int i = 0; i < pText.length(); ++i) { + char currentChar = pText.charAt(i); + boolean isSpace = false; + + if (isHighSurrogate(currentChar)) { + if (i > oneBeforeLast || !isLowSurrogate(pText.charAt(i + 1))) { + throw new IOException("Illegal Unicode character"); + } + this.iWriter.write(pText, i++, 2); + } else if (currentChar < ' ') { + writeAsHex(currentChar); + } else if (currentChar > '~') { + this.iWriter.write(currentChar); + } else { + switch (currentChar) { + case ' ': + isSpace = true; + if (escapeSpace) { + writeAsHex(currentChar); + } else { + this.iWriter.write(currentChar); + } + break; + case '<': + this.iWriter.write("<"); + break; + case '>': + this.iWriter.write(">"); + break; + case '&': + this.iWriter.write("&"); + break; + case '"': + this.iWriter.write("""); + break; + case '\'': + this.iWriter.write("'"); + break; + default: + this.iWriter.write(currentChar); + } + } + escapeSpace = (isSpace && !escapeSpace) || (i == oneBeforeLast); + } + } + + private void writeAsHex(char pChar) throws IOException { + this.iWriter.write("&#x" + Integer.toHexString(pChar) + ";"); + } + + private boolean isHighSurrogate(char pChar) { + return pChar >= WBEMConstants.UTF16_MIN_HIGH_SURROGATE && pChar <= WBEMConstants.UTF16_MAX_HIGH_SURROGATE; + } + + private boolean isLowSurrogate(char pChar) { + return pChar >= WBEMConstants.UTF16_MIN_LOW_SURROGATE && pChar <= WBEMConstants.UTF16_MAX_LOW_SURROGATE; + } + } + + private boolean iPretty; + + private int iIndent = 0; + + private boolean iLastClosed = false; + + private final String CDATA_START = ""; + + private CimXmlSerializer(boolean pPretty) { + this.iPretty = pPretty; + } + + /** + * Serializes a given DOM document as (CIM-)XML to a given output stream. + * The method writes first + * <?xml version="1.0" encoding="UTF-8"?> + * and then serializes the document node. If you want to suppress this + * header just call {@link #serialize(OutputStream, Node, boolean)} on the + * document node. + * + * @param pOS + * The output stream + * @param pDoc + * The document + * @param pPretty + * If true the XML is nicely wrapped and indented, + * otherwise it's all in one line + * @throws IOException + * Whenever something goes wrong + */ + public static void serialize(OutputStream pOS, Document pDoc, boolean pPretty) throws IOException { + try { + XmlWriter writer = new XmlWriter(pOS, WBEMConstants.UTF8); + writer.write("\n"); + new CimXmlSerializer(pPretty).serializeNode(writer, pDoc.getDocumentElement()); + writer.flush(); + } catch (IOException ioe) { + throw ioe; + } catch (Exception e) { + throw new IOException(e.getMessage()); + } + } + + /** + * Serializes a given DOM node as (CIM-)XML to a given output stream + * + * @param pOS + * The output stream + * @param pNode + * The node + * @param pPretty + * If true the XML is nicely wrapped and indented, + * otherwise it's all in one line + * @throws IOException + * Whenever something goes wrong + */ + public static void serialize(OutputStream pOS, Node pNode, boolean pPretty) throws IOException { + try { + XmlWriter writer = new XmlWriter(pOS, WBEMConstants.UTF8); + new CimXmlSerializer(pPretty).serializeNode(writer, pNode); + writer.flush(); + } catch (IOException ioe) { + throw ioe; + } catch (Exception e) { + throw new IOException(e.getMessage()); + } + } + + private void serializeNode(XmlWriter pWriter, Node pNode) throws IOException { + switch (pNode.getNodeType()) { + case Node.ELEMENT_NODE: + pWriter.write(indent()); + pWriter.write("<"); + pWriter.write(pNode.getNodeName()); + NamedNodeMap attributes = pNode.getAttributes(); + if (attributes != null) { + for (int i = 0; i < attributes.getLength(); ++i) { + pWriter.write(" "); + serializeNode(pWriter, attributes.item(i)); + } + } + Node child = pNode.getFirstChild(); + if (child == null) { + pWriter.write("/>"); + this.iLastClosed = true; + break; + } + pWriter.write(">"); + ++this.iIndent; + this.iLastClosed = false; + while (child != null) { + serializeNode(pWriter, child); + child = child.getNextSibling(); + } + --this.iIndent; + if (this.iLastClosed) { + pWriter.write(indent()); + } + pWriter.write(""); + this.iLastClosed = true; + break; + case Node.ATTRIBUTE_NODE: + pWriter.write(pNode.getNodeName()); + pWriter.write("=\""); + pWriter.writeValue(pNode.getNodeValue()); + pWriter.write("\""); + break; + case Node.TEXT_NODE: + String value = pNode.getNodeValue(); + if (value != null) { + int idx = 0; + int len = value.length(); + + while (idx < len) { + int cdata = value.indexOf(this.CDATA_START, idx); + + // rest of string not CDATA, write all (escaped) + if (cdata == -1) { + pWriter.writeValue(value.substring(idx)); + break; + } + + // write characters before CDATA (escaped) + if (idx < cdata) { + pWriter.writeValue(value.substring(idx, cdata)); + idx = cdata; + } + + int end = value.indexOf(this.CDATA_END, idx); + + // invalid CDATA + if (end == -1) { + throw new IOException("CDATA section not closed: " + value); + } + + // write CDATA (not escaped) + pWriter.write(value.substring(idx, end + this.CDATA_END.length())); + idx = end + this.CDATA_END.length(); + } + } + } + } + + private String indent() { + if (!this.iPretty) { + return ""; + } + StringBuffer result = new StringBuffer(); + result.append('\n'); + for (int i = 0; i < this.iIndent; ++i) { + result.append(' '); + } + return result.toString(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/LocalPathBuilder.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/LocalPathBuilder.java similarity index 62% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/LocalPathBuilder.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/LocalPathBuilder.java index 47f2a01..11402e0 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/LocalPathBuilder.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/LocalPathBuilder.java @@ -1,214 +1,240 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import org.sentrysoftware.wbem.javax.cim.CIMProperty; - -/** - * Class LocalPathBuilder helps CIM-XML parsers to build local CIMObjectPathes. - */ -public class LocalPathBuilder { - - private CIMObjectPath iBasePath; - - /** - * Ctor. - * - * @param pBasePath - */ - public LocalPathBuilder(CIMObjectPath pBasePath) { - this.iBasePath = pBasePath; - } - - /** - * getBasePath - * - * @return CIMObjectPath - */ - public CIMObjectPath getBasePath() { - return this.iBasePath; - } - - /** - * build - * - * @param pObjPathStr - * @return CIMObjectPath - */ - public CIMObjectPath build(String pObjPathStr) { - return build(this.iBasePath, pObjPathStr); - } - - /** - * build - * - * @param pObjName - * @param pNameSpace - * @return CIMObjectPath - */ - public CIMObjectPath build(String pObjName, String pNameSpace) { - return build(this.iBasePath, pObjName, pNameSpace); - } - - /** - * build - * - * @param pObjName - * @param pNameSpace - * @param pKeys - * @return CIMObjectPath - */ - public CIMObjectPath build(String pObjName, String pNameSpace, CIMProperty[] pKeys) { - return build(this.iBasePath, pObjName, pNameSpace, pKeys); - } - - /** - * build - * - * @param pHost - * @param pNameSpace - * @param pObjName - * @param pKeys - * @return CIMObjectPath - */ - public CIMObjectPath build(String pHost, String pNameSpace, String pObjName, - CIMProperty[] pKeys) { - return build(this.iBasePath, pHost, pNameSpace, pObjName, pKeys); - } - - /** - * build - * - * @param pScheme - * @param pHost - * @param pPort - * @param pNameSpace - * @param pObjName - * @param pKeys - * @return CIMObjectPath - */ - public CIMObjectPath build(String pScheme, String pHost, String pPort, String pNameSpace, - String pObjName, CIMProperty[] pKeys) { - return build(this.iBasePath, pScheme, pHost, pPort, pNameSpace, pObjName, pKeys); - } - - /** - * build - * - * @param pBasePath - * @param pObjPathStr - * @return CIMObjectPath - */ - public static CIMObjectPath build(CIMObjectPath pBasePath, String pObjPathStr) { - CIMObjectPath path = new CIMObjectPath(pObjPathStr); - return build(pBasePath, path.getScheme(), path.getHost(), path.getPort(), path - .getNamespace(), path.getObjectName(), path.getKeys()); - } - - /** - * build - * - * @param pBasePath - * @param pObjName - * @param pNameSpace - * @return CIMObjectPath - */ - public static CIMObjectPath build(CIMObjectPath pBasePath, String pObjName, String pNameSpace) { - return build(pBasePath, null, null, null, pNameSpace, pObjName, null); - } - - /** - * build - * - * @param pBasePath - * @param pObjName - * @param pNameSpace - * @param pKeys - * @return CIMObjectPath - */ - public static CIMObjectPath build(CIMObjectPath pBasePath, String pObjName, String pNameSpace, - CIMProperty[] pKeys) { - return build(pBasePath, null, null, null, pNameSpace, pObjName, pKeys); - } - - /** - * build - * - * @param pBasePath - * @param pHost - * @param pNameSpace - * @param pObjName - * @param pKeys - * @return CIMObjectPath - */ - public static CIMObjectPath build(CIMObjectPath pBasePath, String pHost, String pNameSpace, - String pObjName, CIMProperty[] pKeys) { - return build(pBasePath, null, pHost, null, pNameSpace, pObjName, pKeys); - } - - /** - * build - * - * @param pBasePath - * @param pScheme - * @param pHost - * @param pPort - * @param pNameSpace - * @param pObjName - * @param pKeys - * @return CIMObjectPath - */ - public static CIMObjectPath build(CIMObjectPath pBasePath, String pScheme, String pHost, - String pPort, String pNameSpace, String pObjName, CIMProperty[] pKeys) { - if (pBasePath == null) return new CIMObjectPath(pScheme, pHost, pPort, pNameSpace, - pObjName, pKeys); - return new CIMObjectPath(pScheme == null ? pBasePath.getScheme() : pScheme, - pHost == null ? pBasePath.getHost() : pHost, pPort == null ? pBasePath.getPort() - : pPort, pNameSpace == null ? pBasePath.getNamespace() : pNameSpace, - pObjName == null ? pBasePath.getObjectName() : pObjName, pKeys // local - // objectpath shouldn't contain keys - ); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.cim.CIMProperty; + +/** + * Class LocalPathBuilder helps CIM-XML parsers to build local CIMObjectPathes. + */ +public class LocalPathBuilder { + private CIMObjectPath iBasePath; + + /** + * Ctor. + * + * @param pBasePath + */ + public LocalPathBuilder(CIMObjectPath pBasePath) { + this.iBasePath = pBasePath; + } + + /** + * getBasePath + * + * @return CIMObjectPath + */ + public CIMObjectPath getBasePath() { + return this.iBasePath; + } + + /** + * build + * + * @param pObjPathStr + * @return CIMObjectPath + */ + public CIMObjectPath build(String pObjPathStr) { + return build(this.iBasePath, pObjPathStr); + } + + /** + * build + * + * @param pObjName + * @param pNameSpace + * @return CIMObjectPath + */ + public CIMObjectPath build(String pObjName, String pNameSpace) { + return build(this.iBasePath, pObjName, pNameSpace); + } + + /** + * build + * + * @param pObjName + * @param pNameSpace + * @param pKeys + * @return CIMObjectPath + */ + public CIMObjectPath build(String pObjName, String pNameSpace, CIMProperty[] pKeys) { + return build(this.iBasePath, pObjName, pNameSpace, pKeys); + } + + /** + * build + * + * @param pHost + * @param pNameSpace + * @param pObjName + * @param pKeys + * @return CIMObjectPath + */ + public CIMObjectPath build(String pHost, String pNameSpace, String pObjName, CIMProperty[] pKeys) { + return build(this.iBasePath, pHost, pNameSpace, pObjName, pKeys); + } + + /** + * build + * + * @param pScheme + * @param pHost + * @param pPort + * @param pNameSpace + * @param pObjName + * @param pKeys + * @return CIMObjectPath + */ + public CIMObjectPath build( + String pScheme, + String pHost, + String pPort, + String pNameSpace, + String pObjName, + CIMProperty[] pKeys + ) { + return build(this.iBasePath, pScheme, pHost, pPort, pNameSpace, pObjName, pKeys); + } + + /** + * build + * + * @param pBasePath + * @param pObjPathStr + * @return CIMObjectPath + */ + public static CIMObjectPath build(CIMObjectPath pBasePath, String pObjPathStr) { + CIMObjectPath path = new CIMObjectPath(pObjPathStr); + return build( + pBasePath, + path.getScheme(), + path.getHost(), + path.getPort(), + path.getNamespace(), + path.getObjectName(), + path.getKeys() + ); + } + + /** + * build + * + * @param pBasePath + * @param pObjName + * @param pNameSpace + * @return CIMObjectPath + */ + public static CIMObjectPath build(CIMObjectPath pBasePath, String pObjName, String pNameSpace) { + return build(pBasePath, null, null, null, pNameSpace, pObjName, null); + } + + /** + * build + * + * @param pBasePath + * @param pObjName + * @param pNameSpace + * @param pKeys + * @return CIMObjectPath + */ + public static CIMObjectPath build( + CIMObjectPath pBasePath, + String pObjName, + String pNameSpace, + CIMProperty[] pKeys + ) { + return build(pBasePath, null, null, null, pNameSpace, pObjName, pKeys); + } + + /** + * build + * + * @param pBasePath + * @param pHost + * @param pNameSpace + * @param pObjName + * @param pKeys + * @return CIMObjectPath + */ + public static CIMObjectPath build( + CIMObjectPath pBasePath, + String pHost, + String pNameSpace, + String pObjName, + CIMProperty[] pKeys + ) { + return build(pBasePath, null, pHost, null, pNameSpace, pObjName, pKeys); + } + + /** + * build + * + * @param pBasePath + * @param pScheme + * @param pHost + * @param pPort + * @param pNameSpace + * @param pObjName + * @param pKeys + * @return CIMObjectPath + */ + public static CIMObjectPath build( + CIMObjectPath pBasePath, + String pScheme, + String pHost, + String pPort, + String pNameSpace, + String pObjName, + CIMProperty[] pKeys + ) { + if (pBasePath == null) return new CIMObjectPath(pScheme, pHost, pPort, pNameSpace, pObjName, pKeys); + return new CIMObjectPath( + pScheme == null ? pBasePath.getScheme() : pScheme, + pHost == null ? pBasePath.getHost() : pHost, + pPort == null ? pBasePath.getPort() : pPort, + pNameSpace == null ? pBasePath.getNamespace() : pNameSpace, + pObjName == null ? pBasePath.getObjectName() : pObjName, + pKeys // local + // objectpath shouldn't contain keys + ); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/TypedValue.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/TypedValue.java similarity index 62% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/TypedValue.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/TypedValue.java index a14c883..aaadb82 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/TypedValue.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/TypedValue.java @@ -1,85 +1,81 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; - -/** - * Class TypedValue is required for the CIM-XML DOM parser. - * - */ -public class TypedValue { - - private CIMDataType iType; - - private Object iValue; - - /** - * Ctor. - * - * @param pType - * @param pValue - */ - public TypedValue(CIMDataType pType, Object pValue) { - this.iType = pType; - this.iValue = pValue; - } - - /** - * getType - * - * @return CIMDataType - */ - public CIMDataType getType() { - return this.iType; - } - - /** - * getValue - * - * @return Object - */ - public Object getValue() { - return this.iValue; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMDataType; + +/** + * Class TypedValue is required for the CIM-XML DOM parser. + * + */ +public class TypedValue { + private CIMDataType iType; + + private Object iValue; + + /** + * Ctor. + * + * @param pType + * @param pValue + */ + public TypedValue(CIMDataType pType, Object pValue) { + this.iType = pType; + this.iValue = pValue; + } + + /** + * getType + * + * @return CIMDataType + */ + public CIMDataType getType() { + return this.iType; + } + + /** + * getValue + * + * @return Object + */ + public Object getValue() { + return this.iValue; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/package.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/package.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/package.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/package.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/CIMObjectFactory.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/CIMObjectFactory.java similarity index 57% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/CIMObjectFactory.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/CIMObjectFactory.java index c83df7a..417d268 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/CIMObjectFactory.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/CIMObjectFactory.java @@ -1,592 +1,638 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus - * 1735693 2007-06-12 ebak Empty VALUE.ARRAY elements are parsed as nulls - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2823494 2009-08-03 rgummada Change Boolean constructor to static - * 3023340 2010-07-02 blaschke-oss CIMObjectFactory uses # constructor instead of valueOf - * 3027615 2010-07-12 blaschke-oss Use CLASS_ARRAY_T instead of new CIMDataType(CLASS,0) - * 3513349 2012-03-31 blaschke-oss TCK: CIMDataType must not accept null string - * 3572993 2012-10-01 blaschke-oss parseDouble("2.2250738585072012e-308") DoS vulnerability - * 2693 2013-10-21 blaschke-oss ReturnValueNode allows invalid PARAMTYPE attribute - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.ByteArrayInputStream; -import java.util.ArrayList; -import java.util.HashMap; - -import org.sentrysoftware.wbem.javax.cim.CIMClass; -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMDateTime; -import org.sentrysoftware.wbem.javax.cim.CIMDateTimeAbsolute; -import org.sentrysoftware.wbem.javax.cim.CIMDateTimeInterval; -import org.sentrysoftware.wbem.javax.cim.CIMInstance; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import org.sentrysoftware.wbem.javax.cim.UnsignedInteger16; -import org.sentrysoftware.wbem.javax.cim.UnsignedInteger32; -import org.sentrysoftware.wbem.javax.cim.UnsignedInteger64; -import org.sentrysoftware.wbem.javax.cim.UnsignedInteger8; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node.ClassNode; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node.InstanceNode; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node.Node; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node.ValueArrayNode; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node.ValueNode; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.MOF; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.Util; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConfiguration; -import org.xml.sax.SAXException; - -/** - * Class CIMObjectFactory is responsible for type String and value String - * parsing. - */ -public class CIMObjectFactory { - - /** - * getEmbbeddedObjectA - * - * @param pType - * @param pValueArrayNode - * @param pSession - * @return CIMInstance[], CIMClass[], String[] or null - * @throws SAXException - */ - public static Object[] getEmbeddedObjA(CIMDataType pType, ValueArrayNode pValueArrayNode, - SAXSession pSession) throws SAXException { - if (pValueArrayNode == null) return null; - return getEmbeddedObjA(pType, (String[]) pValueArrayNode.getValue(), pSession); - } - - /** - * getEmbeddedObjectA - * - * @param pType - * @param pValueStrA - * @param pSession - * @return CIMInstance[], CIMClass[], String[] or null - * @throws SAXException - */ - public static Object[] getEmbeddedObjA(CIMDataType pType, String[] pValueStrA, - SAXSession pSession) throws SAXException { - embeddedObjTypeCheck(pType); - if (pValueStrA == null || pValueStrA.length == 0) return null; - CIMDataType type = null; - ArrayList objAL = new ArrayList(pValueStrA.length); - for (int i = 0; i < pValueStrA.length; i++) { - Object obj = parseEmbeddedObj(pValueStrA[i], pSession); - if (type == null) { - type = getCIMObjScalarType(obj, false); - } else { - CIMDataType type2 = getCIMObjScalarType(obj, false); - if (type2 != null && type != type2) throw new SAXException( - "Embedded Object array contains both Instance and Class objects. " - + "This is not handled!"); - } - objAL.add(obj); - } - if (type == CIMDataType.OBJECT_T) { - return objAL.toArray(EMPTY_INST_A); - } else if (type == CIMDataType.CLASS_T) { return objAL.toArray(EMPTY_CLASS_A); } - return objAL.toArray(EMPTY_STR_A); - } - - /** - * getEmbeddedObject - * - * @param pType - * @param pValueStr - * @param pSession - * @return CIMInstance, CIMClass or null - * @throws SAXException - */ - public static Object getEmbeddedObj(CIMDataType pType, String pValueStr, SAXSession pSession) - throws SAXException { - embeddedObjTypeCheck(pType); - return parseEmbeddedObj(pValueStr, pSession); - } - - /** - * getEmbeddedObj - * - * @param pType - * @param pValObj - * @param pSession - * @return Object CIMClass, CIMInstance, String, CIMClass[], CIMInstance[], - * String[] or null - * @throws SAXException - */ - public static Object getEmbeddedObj(CIMDataType pType, Object pValObj, SAXSession pSession) - throws SAXException { - if (pValObj instanceof String) { return getEmbeddedObj(pType, (String) pValObj, pSession); } - return getEmbeddedObjA(pType, (String[]) pValObj, pSession); - } - - /** - * @param pType - * @param pAL - * @return Object[] - */ - public static Object[] getObjectArray(CIMDataType pType, ArrayList pAL) { - createValFactoryA(); - // if (pType==null) pType=CIMDataType.STRING_T; - ValueFactory factory = cValFactoryA[pType.getType()]; - return factory.make(pAL); - } - - /** - * getObject - * - * @param pType - * @param pValueStr - * @return Object - * @throws SAXException - */ - public static Object getObject(CIMDataType pType, String pValueStr) throws SAXException { - if (pValueStr == null) return null; - createValFactoryA(); - ValueFactory factory = cValFactoryA[pType.getType()]; - try { - return factory.make(pValueStr); - } catch (NumberFormatException e) { - throw new SAXException(e); - } - } - - /** - * getObject - * - * @param pType - * @param pValueNode - * @return Object - * @throws SAXException - */ - public static Object getObject(CIMDataType pType, ValueNode pValueNode) throws SAXException { - if (pValueNode == null) return null; - return getObject(pType, (String) pValueNode.getValue()); - } - - /** - * getObject - * - * @param pType - * @param pValueArrayNode - * @return Object - * @throws SAXException - */ - public static Object getObject(CIMDataType pType, ValueArrayNode pValueArrayNode) - throws SAXException { - if (pValueArrayNode == null) return null; - ArrayList objAL = new ArrayList(pValueArrayNode.size()); - for (int i = 0; i < pValueArrayNode.size(); i++) - objAL.add(getObject(pType, (String) pValueArrayNode.elementAt(i))); - return getObjectArray(pType, objAL); - } - - /** - * getCIMObjType - * - * @param pObj - * @param pNullToString - * @return CIMDataType OBJECT_T, CLASS_T, STRING_T - * @throws SAXException - */ - public static CIMDataType getCIMObjScalarType(Object pObj, boolean pNullToString) - throws SAXException { - if (pObj == null) return pNullToString ? CIMDataType.STRING_T : null; - if (pObj instanceof CIMInstance) { - return CIMDataType.OBJECT_T; - } else if (pObj instanceof CIMClass) { - return CIMDataType.CLASS_T; - } else if (pObj instanceof String) { return CIMDataType.STRING_T; } - throw new SAXException(pObj.getClass().getName() + " is not a CIMObject!"); - } - - /** - * getCIMObjType - * - * @param pObj - * @return CIMDataType OBJECT_T, OBJECT_ARRAY_T - * @throws SAXException - */ - public static CIMDataType getCIMObjScalarType(Object pObj) throws SAXException { - return getCIMObjScalarType(pObj, true); - } - - /** - * getCIMObjArrayType - * - * @param pObj - * @return CIMDataType: OBJECT_ARRAY_T, CLASS_T array, STRING_ARRAY_T - * @throws SAXException - */ - public static CIMDataType getCIMObjArrayType(Object pObj) throws SAXException { - return getCIMObjArrayType(pObj, true); - } - - /** - * getArrayCIMObjType - * - * @param pObj - * @param pNullToString - * @return CIMDataType: OBJECT_ARRAY_T, CLASS_T array, STRING_ARRAY_T or - * null - * @throws SAXException - */ - public static CIMDataType getCIMObjArrayType(Object pObj, boolean pNullToString) - throws SAXException { - if (pObj == null) return pNullToString ? CIMDataType.STRING_ARRAY_T : null; - if (pObj instanceof CIMInstance[]) { - return CIMDataType.OBJECT_ARRAY_T; - } else if (pObj instanceof CIMClass[]) { - return CIMDataType.CLASS_ARRAY_T; - } else if (pObj instanceof String[]) { return CIMDataType.STRING_ARRAY_T; } - throw new SAXException(pObj.getClass().getName() + " is not a CIMObject array!"); - } - - /** - * getType - * - * @param pTypeStr - * @return CIMDataType - * @throws SAXException - */ - public static CIMDataType getType(String pTypeStr) throws SAXException { - if (pTypeStr == null) return null; - createTypeStrMap(); - CIMDataType type = cTypeStrMap.get(pTypeStr); - if (type == null && !cTypeStrMap.containsKey(pTypeStr)) throw new SAXException(pTypeStr - + " is invalid PARAMTYPE!"); - return type; - } - - static final CIMInstance[] EMPTY_INST_A = new CIMInstance[0]; - - static final CIMClass[] EMPTY_CLASS_A = new CIMClass[0]; - - static final String[] EMPTY_STR_A = new String[0]; - - static final UnsignedInteger8[] EMPTY_UINT8_A = new UnsignedInteger8[0]; - - static final UnsignedInteger16[] EMPTY_UINT16_A = new UnsignedInteger16[0]; - - static final UnsignedInteger32[] EMPTY_UINT32_A = new UnsignedInteger32[0]; - - static final UnsignedInteger64[] EMPTY_UINT64_A = new UnsignedInteger64[0]; - - static final Byte[] EMPTY_BYTE_A = new Byte[0]; - - static final Short[] EMPTY_SHORT_A = new Short[0]; - - static final Integer[] EMPTY_INT_A = new Integer[0]; - - static final Long[] EMPTY_LONG_A = new Long[0]; - - static final Float[] EMPTY_FLOAT_A = new Float[0]; - - static final Double[] EMPTY_DOUBLE_A = new Double[0]; - - static final Character[] EMPTY_CHAR_A = new Character[0]; - - static final Boolean[] EMPTY_BOOL_A = new Boolean[0]; - - static final CIMDateTime[] EMPTY_DT_A = new CIMDateTime[0]; - - static final CIMObjectPath[] EMPTY_OP_A = new CIMObjectPath[0]; - - private static void embeddedObjTypeCheck(CIMDataType pType) throws SAXException { - if (pType.getType() != CIMDataType.STRING) throw new SAXException( - "TYPE attribute should be 'string' for EmbeddedObjects!"); - } - - private static Object parseEmbeddedObj(String pValueStr, SAXSession pSession) - throws SAXException { - if (pValueStr == null || pValueStr.length() == 0) return null; - XMLDefaultHandlerImpl ourHandler = new XMLDefaultHandlerImpl(pSession, true); - // XML String of embedded Object is parsed by the SAX parser - SAXParserFactory factory = SAXParserFactory.newInstance(); - try { - SAXParser saxParser = factory.newSAXParser(); - saxParser.parse(new ByteArrayInputStream(pValueStr.getBytes()), ourHandler); - } catch (SAXException se) { - throw se; - } catch (Exception e) { - throw new SAXException("Exception occurred during embedded object parsing!", e); - } - Node node = ourHandler.getRootNode(); - if (node instanceof InstanceNode) { return ((InstanceNode) node).getCIMInstance(); } - if (node instanceof ClassNode) { return ((ClassNode) node).getCIMClass(); } - throw new SAXException(node.getNodeName() - + " root element is unexpected for Embedded Object XML String!"); - } - - private static HashMap cTypeStrMap; - - private synchronized static void createTypeStrMap() { - if (cTypeStrMap != null) return; - cTypeStrMap = new HashMap(); - cTypeStrMap.put(MOF.DT_UINT8, CIMDataType.UINT8_T); - cTypeStrMap.put(MOF.DT_UINT16, CIMDataType.UINT16_T); - cTypeStrMap.put(MOF.DT_UINT32, CIMDataType.UINT32_T); - cTypeStrMap.put(MOF.DT_UINT64, CIMDataType.UINT64_T); - cTypeStrMap.put(MOF.DT_SINT8, CIMDataType.SINT8_T); - cTypeStrMap.put(MOF.DT_SINT16, CIMDataType.SINT16_T); - cTypeStrMap.put(MOF.DT_SINT32, CIMDataType.SINT32_T); - cTypeStrMap.put(MOF.DT_SINT64, CIMDataType.SINT64_T); - cTypeStrMap.put(MOF.DT_REAL32, CIMDataType.REAL32_T); - cTypeStrMap.put(MOF.DT_REAL64, CIMDataType.REAL64_T); - cTypeStrMap.put(MOF.DT_CHAR16, CIMDataType.CHAR16_T); - cTypeStrMap.put(MOF.DT_STR, CIMDataType.STRING_T); - cTypeStrMap.put(MOF.DT_BOOL, CIMDataType.BOOLEAN_T); - cTypeStrMap.put(MOF.DT_DATETIME, CIMDataType.DATETIME_T); - cTypeStrMap.put(MOF.REFERENCE, new CIMDataType("")); - } - - private interface ValueFactory { - - /** - * make - * - * @param pStr - * @return Object - */ - Object make(String pStr); - - /** - * make - * - * @param pAL - * @return Object[] - */ - Object[] make(ArrayList pAL); - } - - private static ValueFactory[] cValFactoryA; - - private static void putFactory(int pTypeCode, ValueFactory pFactory) { - cValFactoryA[pTypeCode] = pFactory; - } - - private synchronized static void createValFactoryA() { - if (cValFactoryA != null) return; - cValFactoryA = new ValueFactory[64]; - // unsigned integers - putFactory(CIMDataType.UINT8, new ValueFactory() { - - public Object make(String pStr) { - return new UnsignedInteger8(pStr); - } - - public Object[] make(ArrayList pAL) { - return pAL.toArray(EMPTY_UINT8_A); - } - }); - putFactory(CIMDataType.UINT16, new ValueFactory() { - - public Object make(String pStr) { - return new UnsignedInteger16(pStr); - } - - public Object[] make(ArrayList pAL) { - return pAL.toArray(EMPTY_UINT16_A); - } - }); - putFactory(CIMDataType.UINT32, new ValueFactory() { - - public Object make(String pStr) { - return new UnsignedInteger32(pStr); - } - - public Object[] make(ArrayList pAL) { - return pAL.toArray(EMPTY_UINT32_A); - } - }); - putFactory(CIMDataType.UINT64, new ValueFactory() { - - public Object make(String pStr) { - return new UnsignedInteger64(pStr); - } - - public Object[] make(ArrayList pAL) { - return pAL.toArray(EMPTY_UINT64_A); - } - }); - // signed integers - putFactory(CIMDataType.SINT8, new ValueFactory() { - - public Object make(String pStr) { - return new Byte(pStr); - } - - public Object[] make(ArrayList pAL) { - return pAL.toArray(EMPTY_BYTE_A); - } - }); - putFactory(CIMDataType.SINT16, new ValueFactory() { - - public Object make(String pStr) { - return new Short(pStr); - } - - public Object[] make(ArrayList pAL) { - return pAL.toArray(EMPTY_SHORT_A); - } - }); - putFactory(CIMDataType.SINT32, new ValueFactory() { - - public Object make(String pStr) { - return new Integer(pStr); - } - - public Object[] make(ArrayList pAL) { - return pAL.toArray(EMPTY_INT_A); - } - }); - putFactory(CIMDataType.SINT64, new ValueFactory() { - - public Object make(String pStr) { - return new Long(pStr); - } - - public Object[] make(ArrayList pAL) { - return pAL.toArray(EMPTY_LONG_A); - } - }); - // floats - putFactory(CIMDataType.REAL32, new ValueFactory() { - - public Object make(String pStr) { - return new Float(pStr); - } - - public Object[] make(ArrayList pAL) { - return pAL.toArray(EMPTY_FLOAT_A); - } - }); - putFactory(CIMDataType.REAL64, new ValueFactory() { - - public Object make(String pStr) { - if (WBEMConfiguration.getGlobalConfiguration().verifyJavaLangDoubleStrings()) { - if (Util.isBadDoubleString(pStr)) throw new IllegalArgumentException( - "Double value string hangs older JVMs!\n" + pStr); - } - return new Double(pStr); - } - - public Object[] make(ArrayList pAL) { - return pAL.toArray(EMPTY_DOUBLE_A); - } - }); - // char - putFactory(CIMDataType.CHAR16, new ValueFactory() { - - public Object make(String pStr) { - if (pStr == null || pStr.length() == 0) throw new IllegalArgumentException( - "Cannot make Character from empty String!"); - return Character.valueOf(pStr.charAt(0)); - } - - public Object[] make(ArrayList pAL) { - return pAL.toArray(EMPTY_CHAR_A); - } - }); - // string - putFactory(CIMDataType.STRING, new ValueFactory() { - - public Object make(String pStr) { - return pStr; - } - - public Object[] make(ArrayList pAL) { - return pAL.toArray(EMPTY_STR_A); - } - }); - // boolean - putFactory(CIMDataType.BOOLEAN, new ValueFactory() { - - public Object make(String pStr) { - return Boolean.valueOf(pStr); - } - - public Object[] make(ArrayList pAL) { - return pAL.toArray(EMPTY_BOOL_A); - } - }); - // datetime - putFactory(CIMDataType.DATETIME, new ValueFactory() { - - public Object make(String pStr) { - try { - return new CIMDateTimeAbsolute(pStr); - } catch (IllegalArgumentException eA) { - try { - return new CIMDateTimeInterval(pStr); - } catch (IllegalArgumentException eI) { - throw new IllegalArgumentException("CIMDataTimeAbsolute:" + eA.getMessage() - + "\nCIMDateTimeInterval:" + eI.getMessage()); - } - } - } - - public Object[] make(ArrayList pAL) { - return pAL.toArray(EMPTY_DT_A); - } - }); - // reference - putFactory(CIMDataType.REFERENCE, new ValueFactory() { - - public Object make(String pStr) { - return new CIMObjectPath(pStr); - } - - public Object[] make(ArrayList pAL) { - return pAL.toArray(EMPTY_OP_A); - } - }); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus + * 1735693 2007-06-12 ebak Empty VALUE.ARRAY elements are parsed as nulls + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2823494 2009-08-03 rgummada Change Boolean constructor to static + * 3023340 2010-07-02 blaschke-oss CIMObjectFactory uses # constructor instead of valueOf + * 3027615 2010-07-12 blaschke-oss Use CLASS_ARRAY_T instead of new CIMDataType(CLASS,0) + * 3513349 2012-03-31 blaschke-oss TCK: CIMDataType must not accept null string + * 3572993 2012-10-01 blaschke-oss parseDouble("2.2250738585072012e-308") DoS vulnerability + * 2693 2013-10-21 blaschke-oss ReturnValueNode allows invalid PARAMTYPE attribute + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.ByteArrayInputStream; +import java.util.ArrayList; +import java.util.HashMap; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import org.metricshub.wbem.javax.cim.CIMClass; +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMDateTime; +import org.metricshub.wbem.javax.cim.CIMDateTimeAbsolute; +import org.metricshub.wbem.javax.cim.CIMDateTimeInterval; +import org.metricshub.wbem.javax.cim.CIMInstance; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.cim.UnsignedInteger16; +import org.metricshub.wbem.javax.cim.UnsignedInteger32; +import org.metricshub.wbem.javax.cim.UnsignedInteger64; +import org.metricshub.wbem.javax.cim.UnsignedInteger8; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node.ClassNode; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node.InstanceNode; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node.Node; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node.ValueArrayNode; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node.ValueNode; +import org.metricshub.wbem.sblim.cimclient.internal.util.MOF; +import org.metricshub.wbem.sblim.cimclient.internal.util.Util; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfiguration; +import org.xml.sax.SAXException; + +/** + * Class CIMObjectFactory is responsible for type String and value String + * parsing. + */ +public class CIMObjectFactory { + + /** + * getEmbbeddedObjectA + * + * @param pType + * @param pValueArrayNode + * @param pSession + * @return CIMInstance[], CIMClass[], String[] or null + * @throws SAXException + */ + public static Object[] getEmbeddedObjA(CIMDataType pType, ValueArrayNode pValueArrayNode, SAXSession pSession) + throws SAXException { + if (pValueArrayNode == null) return null; + return getEmbeddedObjA(pType, (String[]) pValueArrayNode.getValue(), pSession); + } + + /** + * getEmbeddedObjectA + * + * @param pType + * @param pValueStrA + * @param pSession + * @return CIMInstance[], CIMClass[], String[] or null + * @throws SAXException + */ + public static Object[] getEmbeddedObjA(CIMDataType pType, String[] pValueStrA, SAXSession pSession) + throws SAXException { + embeddedObjTypeCheck(pType); + if (pValueStrA == null || pValueStrA.length == 0) return null; + CIMDataType type = null; + ArrayList objAL = new ArrayList(pValueStrA.length); + for (int i = 0; i < pValueStrA.length; i++) { + Object obj = parseEmbeddedObj(pValueStrA[i], pSession); + if (type == null) { + type = getCIMObjScalarType(obj, false); + } else { + CIMDataType type2 = getCIMObjScalarType(obj, false); + if (type2 != null && type != type2) throw new SAXException( + "Embedded Object array contains both Instance and Class objects. " + "This is not handled!" + ); + } + objAL.add(obj); + } + if (type == CIMDataType.OBJECT_T) { + return objAL.toArray(EMPTY_INST_A); + } else if (type == CIMDataType.CLASS_T) { + return objAL.toArray(EMPTY_CLASS_A); + } + return objAL.toArray(EMPTY_STR_A); + } + + /** + * getEmbeddedObject + * + * @param pType + * @param pValueStr + * @param pSession + * @return CIMInstance, CIMClass or null + * @throws SAXException + */ + public static Object getEmbeddedObj(CIMDataType pType, String pValueStr, SAXSession pSession) throws SAXException { + embeddedObjTypeCheck(pType); + return parseEmbeddedObj(pValueStr, pSession); + } + + /** + * getEmbeddedObj + * + * @param pType + * @param pValObj + * @param pSession + * @return Object CIMClass, CIMInstance, String, CIMClass[], CIMInstance[], + * String[] or null + * @throws SAXException + */ + public static Object getEmbeddedObj(CIMDataType pType, Object pValObj, SAXSession pSession) throws SAXException { + if (pValObj instanceof String) { + return getEmbeddedObj(pType, (String) pValObj, pSession); + } + return getEmbeddedObjA(pType, (String[]) pValObj, pSession); + } + + /** + * @param pType + * @param pAL + * @return Object[] + */ + public static Object[] getObjectArray(CIMDataType pType, ArrayList pAL) { + createValFactoryA(); + // if (pType==null) pType=CIMDataType.STRING_T; + ValueFactory factory = cValFactoryA[pType.getType()]; + return factory.make(pAL); + } + + /** + * getObject + * + * @param pType + * @param pValueStr + * @return Object + * @throws SAXException + */ + public static Object getObject(CIMDataType pType, String pValueStr) throws SAXException { + if (pValueStr == null) return null; + createValFactoryA(); + ValueFactory factory = cValFactoryA[pType.getType()]; + try { + return factory.make(pValueStr); + } catch (NumberFormatException e) { + throw new SAXException(e); + } + } + + /** + * getObject + * + * @param pType + * @param pValueNode + * @return Object + * @throws SAXException + */ + public static Object getObject(CIMDataType pType, ValueNode pValueNode) throws SAXException { + if (pValueNode == null) return null; + return getObject(pType, (String) pValueNode.getValue()); + } + + /** + * getObject + * + * @param pType + * @param pValueArrayNode + * @return Object + * @throws SAXException + */ + public static Object getObject(CIMDataType pType, ValueArrayNode pValueArrayNode) throws SAXException { + if (pValueArrayNode == null) return null; + ArrayList objAL = new ArrayList(pValueArrayNode.size()); + for (int i = 0; i < pValueArrayNode.size(); i++) objAL.add(getObject(pType, (String) pValueArrayNode.elementAt(i))); + return getObjectArray(pType, objAL); + } + + /** + * getCIMObjType + * + * @param pObj + * @param pNullToString + * @return CIMDataType OBJECT_T, CLASS_T, STRING_T + * @throws SAXException + */ + public static CIMDataType getCIMObjScalarType(Object pObj, boolean pNullToString) throws SAXException { + if (pObj == null) return pNullToString ? CIMDataType.STRING_T : null; + if (pObj instanceof CIMInstance) { + return CIMDataType.OBJECT_T; + } else if (pObj instanceof CIMClass) { + return CIMDataType.CLASS_T; + } else if (pObj instanceof String) { + return CIMDataType.STRING_T; + } + throw new SAXException(pObj.getClass().getName() + " is not a CIMObject!"); + } + + /** + * getCIMObjType + * + * @param pObj + * @return CIMDataType OBJECT_T, OBJECT_ARRAY_T + * @throws SAXException + */ + public static CIMDataType getCIMObjScalarType(Object pObj) throws SAXException { + return getCIMObjScalarType(pObj, true); + } + + /** + * getCIMObjArrayType + * + * @param pObj + * @return CIMDataType: OBJECT_ARRAY_T, CLASS_T array, STRING_ARRAY_T + * @throws SAXException + */ + public static CIMDataType getCIMObjArrayType(Object pObj) throws SAXException { + return getCIMObjArrayType(pObj, true); + } + + /** + * getArrayCIMObjType + * + * @param pObj + * @param pNullToString + * @return CIMDataType: OBJECT_ARRAY_T, CLASS_T array, STRING_ARRAY_T or + * null + * @throws SAXException + */ + public static CIMDataType getCIMObjArrayType(Object pObj, boolean pNullToString) throws SAXException { + if (pObj == null) return pNullToString ? CIMDataType.STRING_ARRAY_T : null; + if (pObj instanceof CIMInstance[]) { + return CIMDataType.OBJECT_ARRAY_T; + } else if (pObj instanceof CIMClass[]) { + return CIMDataType.CLASS_ARRAY_T; + } else if (pObj instanceof String[]) { + return CIMDataType.STRING_ARRAY_T; + } + throw new SAXException(pObj.getClass().getName() + " is not a CIMObject array!"); + } + + /** + * getType + * + * @param pTypeStr + * @return CIMDataType + * @throws SAXException + */ + public static CIMDataType getType(String pTypeStr) throws SAXException { + if (pTypeStr == null) return null; + createTypeStrMap(); + CIMDataType type = cTypeStrMap.get(pTypeStr); + if (type == null && !cTypeStrMap.containsKey(pTypeStr)) throw new SAXException(pTypeStr + " is invalid PARAMTYPE!"); + return type; + } + + static final CIMInstance[] EMPTY_INST_A = new CIMInstance[0]; + + static final CIMClass[] EMPTY_CLASS_A = new CIMClass[0]; + + static final String[] EMPTY_STR_A = new String[0]; + + static final UnsignedInteger8[] EMPTY_UINT8_A = new UnsignedInteger8[0]; + + static final UnsignedInteger16[] EMPTY_UINT16_A = new UnsignedInteger16[0]; + + static final UnsignedInteger32[] EMPTY_UINT32_A = new UnsignedInteger32[0]; + + static final UnsignedInteger64[] EMPTY_UINT64_A = new UnsignedInteger64[0]; + + static final Byte[] EMPTY_BYTE_A = new Byte[0]; + + static final Short[] EMPTY_SHORT_A = new Short[0]; + + static final Integer[] EMPTY_INT_A = new Integer[0]; + + static final Long[] EMPTY_LONG_A = new Long[0]; + + static final Float[] EMPTY_FLOAT_A = new Float[0]; + + static final Double[] EMPTY_DOUBLE_A = new Double[0]; + + static final Character[] EMPTY_CHAR_A = new Character[0]; + + static final Boolean[] EMPTY_BOOL_A = new Boolean[0]; + + static final CIMDateTime[] EMPTY_DT_A = new CIMDateTime[0]; + + static final CIMObjectPath[] EMPTY_OP_A = new CIMObjectPath[0]; + + private static void embeddedObjTypeCheck(CIMDataType pType) throws SAXException { + if (pType.getType() != CIMDataType.STRING) throw new SAXException( + "TYPE attribute should be 'string' for EmbeddedObjects!" + ); + } + + private static Object parseEmbeddedObj(String pValueStr, SAXSession pSession) throws SAXException { + if (pValueStr == null || pValueStr.length() == 0) return null; + XMLDefaultHandlerImpl ourHandler = new XMLDefaultHandlerImpl(pSession, true); + // XML String of embedded Object is parsed by the SAX parser + SAXParserFactory factory = SAXParserFactory.newInstance(); + try { + SAXParser saxParser = factory.newSAXParser(); + saxParser.parse(new ByteArrayInputStream(pValueStr.getBytes()), ourHandler); + } catch (SAXException se) { + throw se; + } catch (Exception e) { + throw new SAXException("Exception occurred during embedded object parsing!", e); + } + Node node = ourHandler.getRootNode(); + if (node instanceof InstanceNode) { + return ((InstanceNode) node).getCIMInstance(); + } + if (node instanceof ClassNode) { + return ((ClassNode) node).getCIMClass(); + } + throw new SAXException(node.getNodeName() + " root element is unexpected for Embedded Object XML String!"); + } + + private static HashMap cTypeStrMap; + + private static synchronized void createTypeStrMap() { + if (cTypeStrMap != null) return; + cTypeStrMap = new HashMap(); + cTypeStrMap.put(MOF.DT_UINT8, CIMDataType.UINT8_T); + cTypeStrMap.put(MOF.DT_UINT16, CIMDataType.UINT16_T); + cTypeStrMap.put(MOF.DT_UINT32, CIMDataType.UINT32_T); + cTypeStrMap.put(MOF.DT_UINT64, CIMDataType.UINT64_T); + cTypeStrMap.put(MOF.DT_SINT8, CIMDataType.SINT8_T); + cTypeStrMap.put(MOF.DT_SINT16, CIMDataType.SINT16_T); + cTypeStrMap.put(MOF.DT_SINT32, CIMDataType.SINT32_T); + cTypeStrMap.put(MOF.DT_SINT64, CIMDataType.SINT64_T); + cTypeStrMap.put(MOF.DT_REAL32, CIMDataType.REAL32_T); + cTypeStrMap.put(MOF.DT_REAL64, CIMDataType.REAL64_T); + cTypeStrMap.put(MOF.DT_CHAR16, CIMDataType.CHAR16_T); + cTypeStrMap.put(MOF.DT_STR, CIMDataType.STRING_T); + cTypeStrMap.put(MOF.DT_BOOL, CIMDataType.BOOLEAN_T); + cTypeStrMap.put(MOF.DT_DATETIME, CIMDataType.DATETIME_T); + cTypeStrMap.put(MOF.REFERENCE, new CIMDataType("")); + } + + private interface ValueFactory { + /** + * make + * + * @param pStr + * @return Object + */ + Object make(String pStr); + + /** + * make + * + * @param pAL + * @return Object[] + */ + Object[] make(ArrayList pAL); + } + + private static ValueFactory[] cValFactoryA; + + private static void putFactory(int pTypeCode, ValueFactory pFactory) { + cValFactoryA[pTypeCode] = pFactory; + } + + private static synchronized void createValFactoryA() { + if (cValFactoryA != null) return; + cValFactoryA = new ValueFactory[64]; + // unsigned integers + putFactory( + CIMDataType.UINT8, + new ValueFactory() { + + public Object make(String pStr) { + return new UnsignedInteger8(pStr); + } + + public Object[] make(ArrayList pAL) { + return pAL.toArray(EMPTY_UINT8_A); + } + } + ); + putFactory( + CIMDataType.UINT16, + new ValueFactory() { + + public Object make(String pStr) { + return new UnsignedInteger16(pStr); + } + + public Object[] make(ArrayList pAL) { + return pAL.toArray(EMPTY_UINT16_A); + } + } + ); + putFactory( + CIMDataType.UINT32, + new ValueFactory() { + + public Object make(String pStr) { + return new UnsignedInteger32(pStr); + } + + public Object[] make(ArrayList pAL) { + return pAL.toArray(EMPTY_UINT32_A); + } + } + ); + putFactory( + CIMDataType.UINT64, + new ValueFactory() { + + public Object make(String pStr) { + return new UnsignedInteger64(pStr); + } + + public Object[] make(ArrayList pAL) { + return pAL.toArray(EMPTY_UINT64_A); + } + } + ); + // signed integers + putFactory( + CIMDataType.SINT8, + new ValueFactory() { + + public Object make(String pStr) { + return new Byte(pStr); + } + + public Object[] make(ArrayList pAL) { + return pAL.toArray(EMPTY_BYTE_A); + } + } + ); + putFactory( + CIMDataType.SINT16, + new ValueFactory() { + + public Object make(String pStr) { + return new Short(pStr); + } + + public Object[] make(ArrayList pAL) { + return pAL.toArray(EMPTY_SHORT_A); + } + } + ); + putFactory( + CIMDataType.SINT32, + new ValueFactory() { + + public Object make(String pStr) { + return new Integer(pStr); + } + + public Object[] make(ArrayList pAL) { + return pAL.toArray(EMPTY_INT_A); + } + } + ); + putFactory( + CIMDataType.SINT64, + new ValueFactory() { + + public Object make(String pStr) { + return new Long(pStr); + } + + public Object[] make(ArrayList pAL) { + return pAL.toArray(EMPTY_LONG_A); + } + } + ); + // floats + putFactory( + CIMDataType.REAL32, + new ValueFactory() { + + public Object make(String pStr) { + return new Float(pStr); + } + + public Object[] make(ArrayList pAL) { + return pAL.toArray(EMPTY_FLOAT_A); + } + } + ); + putFactory( + CIMDataType.REAL64, + new ValueFactory() { + + public Object make(String pStr) { + if (WBEMConfiguration.getGlobalConfiguration().verifyJavaLangDoubleStrings()) { + if (Util.isBadDoubleString(pStr)) throw new IllegalArgumentException( + "Double value string hangs older JVMs!\n" + pStr + ); + } + return new Double(pStr); + } + + public Object[] make(ArrayList pAL) { + return pAL.toArray(EMPTY_DOUBLE_A); + } + } + ); + // char + putFactory( + CIMDataType.CHAR16, + new ValueFactory() { + + public Object make(String pStr) { + if (pStr == null || pStr.length() == 0) throw new IllegalArgumentException( + "Cannot make Character from empty String!" + ); + return Character.valueOf(pStr.charAt(0)); + } + + public Object[] make(ArrayList pAL) { + return pAL.toArray(EMPTY_CHAR_A); + } + } + ); + // string + putFactory( + CIMDataType.STRING, + new ValueFactory() { + + public Object make(String pStr) { + return pStr; + } + + public Object[] make(ArrayList pAL) { + return pAL.toArray(EMPTY_STR_A); + } + } + ); + // boolean + putFactory( + CIMDataType.BOOLEAN, + new ValueFactory() { + + public Object make(String pStr) { + return Boolean.valueOf(pStr); + } + + public Object[] make(ArrayList pAL) { + return pAL.toArray(EMPTY_BOOL_A); + } + } + ); + // datetime + putFactory( + CIMDataType.DATETIME, + new ValueFactory() { + + public Object make(String pStr) { + try { + return new CIMDateTimeAbsolute(pStr); + } catch (IllegalArgumentException eA) { + try { + return new CIMDateTimeInterval(pStr); + } catch (IllegalArgumentException eI) { + throw new IllegalArgumentException( + "CIMDataTimeAbsolute:" + eA.getMessage() + "\nCIMDateTimeInterval:" + eI.getMessage() + ); + } + } + } + + public Object[] make(ArrayList pAL) { + return pAL.toArray(EMPTY_DT_A); + } + } + ); + // reference + putFactory( + CIMDataType.REFERENCE, + new ValueFactory() { + + public Object make(String pStr) { + return new CIMObjectPath(pStr); + } + + public Object[] make(ArrayList pAL) { + return pAL.toArray(EMPTY_OP_A); + } + } + ); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/EmbObjHandler.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/EmbObjHandler.java similarity index 68% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/EmbObjHandler.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/EmbObjHandler.java index f6b35fc..e5dda83 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/EmbObjHandler.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/EmbObjHandler.java @@ -1,351 +1,359 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus - * 1712656 2007-05-04 ebak Correct type identification for SVC CIMOM - * 1719991 2007-05-16 ebak FVT: regression ClassCastException in EmbObjHandler - * 1820763 2007-10-29 ebak Supporting the EmbeddedInstance qualifier - * 1848607 2007-12-11 ebak Strict EmbeddedObject types - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2957387 2010-03-03 blaschke-oss EmbededObject XML attribute must not be all uppercases - * 3281781 2011-04-11 blaschke-oss fail to parse Embedded Instance parameter - * 3513353 2012-03-30 blaschke-oss TCK: CIMDataType arrays must have length >= 1 - * 3513349 2012-03-31 blaschke-oss TCK: CIMDataType must not accept null string - * 2691 2013-10-18 blaschke-oss RETURNVALUE should not require PARAMTYPE attribute - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.CIMHelper; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node.AbstractValueNode; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node.ArrayIf; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node.Node; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node.QualifiedNodeHandler; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node.ValueArrayNode; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node.ValueNode; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * EmbObjHandler helps the parsing of embedded object elements. - */ - -public class EmbObjHandler { - - private String iNodeName; - - private CIMDataType iRawType; - - private boolean iHasEmbObjAttr, iHasEmbInstAttr; - - private SAXSession iSession; - - private CIMDataType iType; - - private Object iValue; - - private QualifiedNodeHandler iQualiHandler; - - private AbstractValueNode iAbsValNode; - - /** - * Generic initialization. - * - * @param pHandler - * @param pNodeName - * @param pAttribs - * @param pSession - * @param pQNodeHandler - * @param pCheckEmbObjAttrib - * @return EmbObjHandler - * @throws SAXException - */ - public static EmbObjHandler init(EmbObjHandler pHandler, String pNodeName, Attributes pAttribs, - SAXSession pSession, QualifiedNodeHandler pQNodeHandler, boolean pCheckEmbObjAttrib) - throws SAXException { - if (pHandler == null) pHandler = new EmbObjHandler(); - pHandler.initInst(pNodeName, pAttribs, pSession, pQNodeHandler, pCheckEmbObjAttrib); - return pHandler; - } - - private EmbObjHandler() { - // init() used for instantiation - } - - /** - * Generic instance initialization. - * - * @param pNodeName - * @param pAttribs - * @param pSession - * @param pQNodeHandler - * @param pCheckEmbObjAttrib - * @throws SAXException - */ - public void initInst(String pNodeName, Attributes pAttribs, SAXSession pSession, - QualifiedNodeHandler pQNodeHandler, boolean pCheckEmbObjAttrib) throws SAXException { - this.iSession = pSession; - this.iNodeName = pNodeName; - this.iQualiHandler = pQNodeHandler; - this.iType = null; - this.iValue = null; - this.iAbsValNode = null; - this.iRawType = Node.getCIMType(pAttribs, true); - if (this.iRawType == null) { - this.iRawType = Node.getParamType(pAttribs); - /* - * if (iRawType==null) throw new SAXException( iNodeName+" must - * contain a TYPE or a PARAMTYPE attribute!" ); - */ - /* - * SVC CIMOM doesn't add TYPE attribute for the RETURNVALUE element, - * but it adds it to the VALUE element. - */ - } - - if (pCheckEmbObjAttrib) { - // DSPs call for EmbeddedObject AND XML is case sensitive, BUT there - // are probably CIMOMs out there that still use EMBEDDEDOBJECT - String embObjStr = pAttribs.getValue("EmbeddedObject"); - if (embObjStr == null) { - embObjStr = pAttribs.getValue("EMBEDDEDOBJECT"); - } - if (embObjStr == null) { - this.iHasEmbInstAttr = this.iHasEmbObjAttr = false; - } else if ("instance".equalsIgnoreCase(embObjStr)) { - this.iHasEmbInstAttr = true; - this.iHasEmbObjAttr = false; - } else if ("object".equalsIgnoreCase(embObjStr)) { - this.iHasEmbInstAttr = false; - this.iHasEmbObjAttr = true; - } else { - throw new SAXException( - "EmbeddedObject attribute's value must be \"object\" or \"instance\". " - + embObjStr + " is invalid!"); - } - } else { - this.iHasEmbInstAttr = this.iHasEmbObjAttr = false; - } - } - - /** - * isEmbeddedObject For this function Object means CLASS or INSTANCE. Object - * can have other meanings at different places !!! :( - * - * @return boolean - */ - private boolean isEmbeddedObject() { - return this.iHasEmbInstAttr - || this.iHasEmbObjAttr - || (this.iQualiHandler != null && (this.iQualiHandler.isEmbeddedObject() || this.iQualiHandler - .isEmbeddedInstance())); - } - - /** - * isEmbeddedClass - * - * @return boolean - */ - private boolean isEmbeddedClass() { - return this.iHasEmbObjAttr - || (this.iQualiHandler != null && this.iQualiHandler.isEmbeddedObject()); - } - - /** - * isEmbeddedInstance - * - * @return boolean - */ - private boolean isEmbeddedInstance() { - return this.iHasEmbInstAttr - || (this.iQualiHandler != null && this.iQualiHandler.isEmbeddedInstance()); - } - - /** - * getValue - * - * @return Object - * @throws SAXException - */ - public Object getValue() throws SAXException { - transform(); - return this.iValue; - } - - /** - * getType - * - * @return Object - * @throws SAXException - */ - public CIMDataType getType() throws SAXException { - transform(); - return this.iType; - } - - /** - * getRawType - * - * @return the type which is retrieved from the XML attributes - */ - public CIMDataType getRawType() { - return this.iRawType; - } - - /** - * getArrayType useful e.g. for PROPERTY.ARRAY - * - * @return CIMDataType - * @throws SAXException - */ - public CIMDataType getArrayType() throws SAXException { - transform(); - return this.iType.isArray() ? this.iType : CIMHelper.UnboundedArrayDataType(this.iType - .getType()); - } - - /** - * addValueNode - * - * @param pValueNode - * - can be ValueNode ore ValueArrayNode for Embedded Objects - */ - public void addValueNode(AbstractValueNode pValueNode) { - if (isEmbeddedObject() - && !(pValueNode == null || pValueNode instanceof ValueNode || pValueNode instanceof ValueArrayNode)) throw new IllegalArgumentException( - "pValueNode's type can be ValueNode or ValueArrayNode or it can be null. " - + pValueNode.getClass().getName() + " is an invalid type!"); - this.iAbsValNode = pValueNode; - } - - private void transform() throws SAXException { - if (this.iType != null) return; - if (this.iAbsValNode == null) { - if (isEmbeddedObject()) { - if (this.iRawType != CIMDataType.STRING_T) throw new SAXException( - "Embedded Object CIM-XML element's type must be string. " + this.iRawType - + " is invalid!"); - if (this.iSession.strictEmbObjParsing()) { - /* - * Here the assumption is that Object = CLASS, Instance = - * INSTANCE. - */ - this.iType = isEmbeddedInstance() ? CIMDataType.OBJECT_T : CIMDataType.CLASS_T; - } else { - /* - * for valueless EmbeddedObject="object" the type can not be - * determined since Pegasus's CIMObject can contain both - * CIMClass and CIMInstance. Is it true for Pegasus 2.7.0 - * too? - */ - this.iType = isEmbeddedInstance() ? CIMDataType.OBJECT_T : CIMDataType.STRING_T; - } - } else { - this.iType = this.iRawType; - } - this.iValue = null; - } else { - setType(); - if (isEmbeddedObject()) { - transformEmbObj(); - } else { - transformNormObj(); - } - } - } - - private void transformEmbObj() throws SAXException { - if (this.iAbsValNode instanceof ValueNode) { - String valueStr = (String) ((ValueNode) this.iAbsValNode).getValue(); - this.iValue = CIMObjectFactory.getEmbeddedObj(this.iRawType, valueStr, this.iSession); - this.iType = CIMObjectFactory.getCIMObjScalarType(this.iValue); - } else { // ValueArrayNode - this.iValue = CIMObjectFactory.getEmbeddedObjA(this.iRawType, - (ValueArrayNode) this.iAbsValNode, this.iSession); - this.iType = CIMObjectFactory.getCIMObjArrayType(this.iValue); - } - if (isEmbeddedInstance() && this.iType.getType() != CIMDataType.OBJECT) throw new SAXException( - this.iNodeName + " element is an EmbeddedInstance with non INSTANCE value. " - + "It's not valid!"); - if (isEmbeddedClass() && this.iType.getType() != CIMDataType.CLASS - && this.iType.getType() != CIMDataType.OBJECT) throw new SAXException( - this.iNodeName - + " element is an EmbeddedObject with non CLASS/INSTANCE value. It's not valid!"); - } - - private void transformNormObj() throws SAXException { - if (this.iAbsValNode instanceof ValueNode) { - this.iType = this.iRawType; - this.iValue = CIMObjectFactory.getObject(this.iType, (ValueNode) this.iAbsValNode); - } else if (this.iAbsValNode instanceof ValueArrayNode) { - this.iType = CIMHelper.UnboundedArrayDataType(this.iRawType.getType()); - this.iValue = CIMObjectFactory.getObject(this.iRawType, - (ValueArrayNode) this.iAbsValNode); - } else { - this.iValue = this.iAbsValNode.getValue(); - if (this.iAbsValNode instanceof ArrayIf) { - if (this.iValue instanceof CIMObjectPath[]) this.iType = new CIMDataType("", 0); - } else { - if (this.iValue instanceof CIMObjectPath) { - this.iType = new CIMDataType(((CIMObjectPath) this.iValue).getObjectName()); - } else { - this.iType = this.iRawType; - } - } - } - } - - /** - * Required to handle the output XML of some non-standard CIMOMs like SVC - * which adds the TYPE attribute to the sub VALUE or VALUE.ARRAY XML - * element. - * - * @throws SAXException - */ - private void setType() throws SAXException { - if (this.iType != null || this.iRawType != null) return; - this.iRawType = this.iAbsValNode.getType(); - if (this.iRawType == null) this.iRawType = (this.iAbsValNode instanceof ArrayIf ? CIMDataType.STRING_ARRAY_T - : CIMDataType.STRING_T); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus + * 1712656 2007-05-04 ebak Correct type identification for SVC CIMOM + * 1719991 2007-05-16 ebak FVT: regression ClassCastException in EmbObjHandler + * 1820763 2007-10-29 ebak Supporting the EmbeddedInstance qualifier + * 1848607 2007-12-11 ebak Strict EmbeddedObject types + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2957387 2010-03-03 blaschke-oss EmbededObject XML attribute must not be all uppercases + * 3281781 2011-04-11 blaschke-oss fail to parse Embedded Instance parameter + * 3513353 2012-03-30 blaschke-oss TCK: CIMDataType arrays must have length >= 1 + * 3513349 2012-03-31 blaschke-oss TCK: CIMDataType must not accept null string + * 2691 2013-10-18 blaschke-oss RETURNVALUE should not require PARAMTYPE attribute + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMHelper; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node.AbstractValueNode; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node.ArrayIf; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node.Node; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node.QualifiedNodeHandler; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node.ValueArrayNode; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node.ValueNode; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * EmbObjHandler helps the parsing of embedded object elements. + */ + +public class EmbObjHandler { + private String iNodeName; + + private CIMDataType iRawType; + + private boolean iHasEmbObjAttr, iHasEmbInstAttr; + + private SAXSession iSession; + + private CIMDataType iType; + + private Object iValue; + + private QualifiedNodeHandler iQualiHandler; + + private AbstractValueNode iAbsValNode; + + /** + * Generic initialization. + * + * @param pHandler + * @param pNodeName + * @param pAttribs + * @param pSession + * @param pQNodeHandler + * @param pCheckEmbObjAttrib + * @return EmbObjHandler + * @throws SAXException + */ + public static EmbObjHandler init( + EmbObjHandler pHandler, + String pNodeName, + Attributes pAttribs, + SAXSession pSession, + QualifiedNodeHandler pQNodeHandler, + boolean pCheckEmbObjAttrib + ) + throws SAXException { + if (pHandler == null) pHandler = new EmbObjHandler(); + pHandler.initInst(pNodeName, pAttribs, pSession, pQNodeHandler, pCheckEmbObjAttrib); + return pHandler; + } + + private EmbObjHandler() { + // init() used for instantiation + } + + /** + * Generic instance initialization. + * + * @param pNodeName + * @param pAttribs + * @param pSession + * @param pQNodeHandler + * @param pCheckEmbObjAttrib + * @throws SAXException + */ + public void initInst( + String pNodeName, + Attributes pAttribs, + SAXSession pSession, + QualifiedNodeHandler pQNodeHandler, + boolean pCheckEmbObjAttrib + ) + throws SAXException { + this.iSession = pSession; + this.iNodeName = pNodeName; + this.iQualiHandler = pQNodeHandler; + this.iType = null; + this.iValue = null; + this.iAbsValNode = null; + this.iRawType = Node.getCIMType(pAttribs, true); + if (this.iRawType == null) { + this.iRawType = Node.getParamType(pAttribs); + /* + * if (iRawType==null) throw new SAXException( iNodeName+" must + * contain a TYPE or a PARAMTYPE attribute!" ); + */ + /* + * SVC CIMOM doesn't add TYPE attribute for the RETURNVALUE element, + * but it adds it to the VALUE element. + */ + } + + if (pCheckEmbObjAttrib) { + // DSPs call for EmbeddedObject AND XML is case sensitive, BUT there + // are probably CIMOMs out there that still use EMBEDDEDOBJECT + String embObjStr = pAttribs.getValue("EmbeddedObject"); + if (embObjStr == null) { + embObjStr = pAttribs.getValue("EMBEDDEDOBJECT"); + } + if (embObjStr == null) { + this.iHasEmbInstAttr = this.iHasEmbObjAttr = false; + } else if ("instance".equalsIgnoreCase(embObjStr)) { + this.iHasEmbInstAttr = true; + this.iHasEmbObjAttr = false; + } else if ("object".equalsIgnoreCase(embObjStr)) { + this.iHasEmbInstAttr = false; + this.iHasEmbObjAttr = true; + } else { + throw new SAXException( + "EmbeddedObject attribute's value must be \"object\" or \"instance\". " + embObjStr + " is invalid!" + ); + } + } else { + this.iHasEmbInstAttr = this.iHasEmbObjAttr = false; + } + } + + /** + * isEmbeddedObject For this function Object means CLASS or INSTANCE. Object + * can have other meanings at different places !!! :( + * + * @return boolean + */ + private boolean isEmbeddedObject() { + return ( + this.iHasEmbInstAttr || + this.iHasEmbObjAttr || + (this.iQualiHandler != null && (this.iQualiHandler.isEmbeddedObject() || this.iQualiHandler.isEmbeddedInstance())) + ); + } + + /** + * isEmbeddedClass + * + * @return boolean + */ + private boolean isEmbeddedClass() { + return this.iHasEmbObjAttr || (this.iQualiHandler != null && this.iQualiHandler.isEmbeddedObject()); + } + + /** + * isEmbeddedInstance + * + * @return boolean + */ + private boolean isEmbeddedInstance() { + return this.iHasEmbInstAttr || (this.iQualiHandler != null && this.iQualiHandler.isEmbeddedInstance()); + } + + /** + * getValue + * + * @return Object + * @throws SAXException + */ + public Object getValue() throws SAXException { + transform(); + return this.iValue; + } + + /** + * getType + * + * @return Object + * @throws SAXException + */ + public CIMDataType getType() throws SAXException { + transform(); + return this.iType; + } + + /** + * getRawType + * + * @return the type which is retrieved from the XML attributes + */ + public CIMDataType getRawType() { + return this.iRawType; + } + + /** + * getArrayType useful e.g. for PROPERTY.ARRAY + * + * @return CIMDataType + * @throws SAXException + */ + public CIMDataType getArrayType() throws SAXException { + transform(); + return this.iType.isArray() ? this.iType : CIMHelper.UnboundedArrayDataType(this.iType.getType()); + } + + /** + * addValueNode + * + * @param pValueNode + * - can be ValueNode ore ValueArrayNode for Embedded Objects + */ + public void addValueNode(AbstractValueNode pValueNode) { + if ( + isEmbeddedObject() && + !(pValueNode == null || pValueNode instanceof ValueNode || pValueNode instanceof ValueArrayNode) + ) throw new IllegalArgumentException( + "pValueNode's type can be ValueNode or ValueArrayNode or it can be null. " + + pValueNode.getClass().getName() + + " is an invalid type!" + ); + this.iAbsValNode = pValueNode; + } + + private void transform() throws SAXException { + if (this.iType != null) return; + if (this.iAbsValNode == null) { + if (isEmbeddedObject()) { + if (this.iRawType != CIMDataType.STRING_T) throw new SAXException( + "Embedded Object CIM-XML element's type must be string. " + this.iRawType + " is invalid!" + ); + if (this.iSession.strictEmbObjParsing()) { + /* + * Here the assumption is that Object = CLASS, Instance = + * INSTANCE. + */ + this.iType = isEmbeddedInstance() ? CIMDataType.OBJECT_T : CIMDataType.CLASS_T; + } else { + /* + * for valueless EmbeddedObject="object" the type can not be + * determined since Pegasus's CIMObject can contain both + * CIMClass and CIMInstance. Is it true for Pegasus 2.7.0 + * too? + */ + this.iType = isEmbeddedInstance() ? CIMDataType.OBJECT_T : CIMDataType.STRING_T; + } + } else { + this.iType = this.iRawType; + } + this.iValue = null; + } else { + setType(); + if (isEmbeddedObject()) { + transformEmbObj(); + } else { + transformNormObj(); + } + } + } + + private void transformEmbObj() throws SAXException { + if (this.iAbsValNode instanceof ValueNode) { + String valueStr = (String) ((ValueNode) this.iAbsValNode).getValue(); + this.iValue = CIMObjectFactory.getEmbeddedObj(this.iRawType, valueStr, this.iSession); + this.iType = CIMObjectFactory.getCIMObjScalarType(this.iValue); + } else { // ValueArrayNode + this.iValue = CIMObjectFactory.getEmbeddedObjA(this.iRawType, (ValueArrayNode) this.iAbsValNode, this.iSession); + this.iType = CIMObjectFactory.getCIMObjArrayType(this.iValue); + } + if (isEmbeddedInstance() && this.iType.getType() != CIMDataType.OBJECT) throw new SAXException( + this.iNodeName + " element is an EmbeddedInstance with non INSTANCE value. " + "It's not valid!" + ); + if ( + isEmbeddedClass() && this.iType.getType() != CIMDataType.CLASS && this.iType.getType() != CIMDataType.OBJECT + ) throw new SAXException( + this.iNodeName + " element is an EmbeddedObject with non CLASS/INSTANCE value. It's not valid!" + ); + } + + private void transformNormObj() throws SAXException { + if (this.iAbsValNode instanceof ValueNode) { + this.iType = this.iRawType; + this.iValue = CIMObjectFactory.getObject(this.iType, (ValueNode) this.iAbsValNode); + } else if (this.iAbsValNode instanceof ValueArrayNode) { + this.iType = CIMHelper.UnboundedArrayDataType(this.iRawType.getType()); + this.iValue = CIMObjectFactory.getObject(this.iRawType, (ValueArrayNode) this.iAbsValNode); + } else { + this.iValue = this.iAbsValNode.getValue(); + if (this.iAbsValNode instanceof ArrayIf) { + if (this.iValue instanceof CIMObjectPath[]) this.iType = new CIMDataType("", 0); + } else { + if (this.iValue instanceof CIMObjectPath) { + this.iType = new CIMDataType(((CIMObjectPath) this.iValue).getObjectName()); + } else { + this.iType = this.iRawType; + } + } + } + } + + /** + * Required to handle the output XML of some non-standard CIMOMs like SVC + * which adds the TYPE attribute to the sub VALUE or VALUE.ARRAY XML + * element. + * + * @throws SAXException + */ + private void setType() throws SAXException { + if (this.iType != null || this.iRawType != null) return; + this.iRawType = this.iAbsValNode.getType(); + if (this.iRawType == null) this.iRawType = + (this.iAbsValNode instanceof ArrayIf ? CIMDataType.STRING_ARRAY_T : CIMDataType.STRING_T); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/NodeConstIf.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/NodeConstIf.java similarity index 87% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/NodeConstIf.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/NodeConstIf.java index ed613e4..4f82cc2 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/NodeConstIf.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/NodeConstIf.java @@ -1,929 +1,926 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2210455 2008-10-30 blaschke-oss Enhance javadoc, fix potential null pointers - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2845211 2009-08-27 raman_arora Pull Enumeration Feature (SAX Parser) - * 2666 2013-09-19 blaschke-oss CR12: Remove ENUMERATIONCONTEXT - * 2672 2013-09-26 blaschke-oss Remove SIMPLEREQACK support - * 2690 2013-10-11 blaschke-oss Remove RESPONSEDESTINATION support - * 2538 2013-11-28 blaschke-oss CR14: Support new CORRELATOR element - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * Class NodeConstIf - * - */ -public interface NodeConstIf { - - /** - * The CIM element is the root element of every XML Document that is valid - * with respect to this schema.
      - * - * - * <!ELEMENT CIM (MESSAGE|DECLARATION)> - * <!ATTLIST CIM - * CIMVERSION CDATA #REQUIRED - * DTDVERSION CDATA #REQUIRED> - * - * - * @see String - */ - public static final String CIM = "CIM"; - - /** - * The DECLARATION element defines a set of one or more declarations of CIM - * objects.
      - * - * - * - * <!ELEMENT DECLARATION (DECLGROUP|DECLGROUP.WITHNAME|DECLGROUP.WITHPATH)+> - * - * - * @see String - */ - public static final String DECLARATION = "DECLARATION"; - - /** - * The DECLGROUP element defines a logical set of CIM Class, Instance and - * Qualifier declarations.
      - * - * - * <!ELEMENT DECLGROUP ((LOCALNAMESPACEPATH|NAMESPACEPATH)?,QUALIFIER.DECLARATION*,VALUE.OBJECT*)> - * - * - * @see String - */ - public static final String DECLGROUP = "DECLGROUP"; - - /** - * The DECLGROUP.WITHNAME element defines a logical set of CIM Class, - * Instance and Qualifier declarations.
      - * - * - * <!ELEMENT DECLGROUP.WITHNAME ((LOCALNAMESPACEPATH|NAMESPACEPATH)?,QUALIFIER.DECLARATION*,VALUE.NAMEDOBJECT*)> - * - * - * @see String - */ - public static final String DECLGROUP_WITHNAME = "DECLGROUP.WITHNAME"; - - /** - * The DECLGROUP.WITHPATH element defines a logical set of CIM Class and - * Instance declarations.
      - * - * - * <!ELEMENT DECLGROUP.WITHPATH (VALUE.OBJECTWITHPATH|VALUE.OBJECTWITHLOCALPATH)*> - * - * - * @see String - */ - public static final String DECLGROUP_WITHPATH = "DECLGROUP.WITHPATH"; - - /** - * The QUALIFIER.DECLARATION element defines a single CIM Qualifier - * declaration.
      - * - * - * <!ELEMENT QUALIFIER.DECLARATION (SCOPE?,(VALUE|VALUE.ARRAY)?)> - * <!ATTLIST QUALIFIER.DECLARATION - * %CIMName; - * %CIMType; #REQUIRED - * ISARRAY (true|false) #IMPLIED - * %ArraySize; - * %QualifierFlavor;> - * - * - * @see String - */ - public static final String QUALIFIER_DECLARATION = "QUALIFIER.DECLARATION"; - - /** - * The SCOPE element defines the scope of a QUALIFIER.DECLARATION in the - * case that there are restrictions on the scope of the Qualifier - * declaration.
      - * - * - * <!ELEMENT SCOPE EMPTY> - * <!ATTLIST SCOPE - * CLASS (true|false) "false" - * ASSOCIATION (true|false) "false" - * REFERENCE (true|false) "false" - * PROPERTY (true|false) "false" - * METHOD (true|false) "false" - * PARAMETER (true|false) "false" - * INDICATION (true|false) "false"> - * - * - * @see String - */ - public static final String SCOPE = "SCOPE"; - - /** - * The VALUE element is used to define a single (non-array) non-reference - * non-NULL CIM Property value, CIM Qualifier value, CIM Method return - * value, or CIM Method Parameter value.
      - * - * - * <!ELEMENT VALUE (#PCDATA)> - * - * - * @see String - */ - public static final String VALUE = "VALUE"; - - /** - * The VALUE.ARRAY element is used to represent the value of a CIM Property - * or Qualifier that has an array type.
      - * - * - * - * <!ELEMENT VALUE.ARRAY (VALUE|VALUE.NULL)*> - * - * - * @see String - */ - public static final String VALUE_ARRAY = "VALUE.ARRAY"; - - /** - * The VALUE.REFERENCE element is used to define a single CIM reference - * Property value.
      - * - * - * <!ELEMENT VALUE.REFERENCE (CLASSPATH|LOCALCLASSPATH|CLASSNAME|INSTANCEPATH|LOCALINSTANCEPATH|INSTANCENAME)> - * - * - * @see String - */ - public static final String VALUE_REFERENCE = "VALUE.REFERENCE"; - - /** - * The VALUE.REFARRAY element is used to represent the value of an array of - * CIM references.
      - * - * - * <!ELEMENT VALUE.REFARRAY (VALUE.REFERENCE|VALUE.NULL)*> - * - * - * @see String - */ - public static final String VALUE_REFARRAY = "VALUE.REFARRAY"; - - /** - * The VALUE.OBJECT element is used to define a value which is comprised of - * a single CIM Class or Instance definition.
      - * - * - * <!ELEMENT VALUE.OBJECT (CLASS|INSTANCE)> - * - * - * @see String - */ - public static final String VALUE_OBJECT = "VALUE.OBJECT"; - - /** - * The VALUE.NAMEDINSTANCE element is used to define a value which is - * comprised of a single named CIM Instance definition.
      - * - * - * - * <!ELEMENT VALUE.NAMEDINSTANCE (INSTANCENAME,INSTANCE)> - * - * - * @see String - */ - public static final String VALUE_NAMEDINSTANCE = "VALUE.NAMEDINSTANCE"; - - /** - * The VALUE.NAMEDOBJECT element is used to define a value which is - * comprised of a single named CIM Class or Instance definition.
      - * - * - * <!ELEMENT VALUE.NAMEDOBJECT (CLASS|(INSTANCENAME,INSTANCE))> - * - * - * @see String - */ - public static final String VALUE_NAMEDOBJECT = "VALUE.NAMEDOBJECT"; - - /** - * The VALUE.OBJECTWITHLOCALPATH element is used to define a value which is - * comprised of a single CIM Object (Class or Instance) definition with - * additional information that defines the local path to that Object.
      - * - * - * <!ELEMENT VALUE.OBJECTWITHLOCALPATH ((LOCALCLASSPATH,CLASS)|(LOCALINSTANCEPATH,INSTANCE))> - * - * - * @see String - */ - public static final String VALUE_OBJECTWITHLOCALPATH = "VALUE.OBJECTWITHLOCALPATH"; - - /** - * The VALUE.OBJECTWITHPATH element is used to define a value which is - * comprised of a single CIM Object (Class or Instance) definition with - * additional information that defines the absolute path to that Object.
      - * - * - * <!ELEMENT VALUE.OBJECTWITHPATH ((CLASSPATH,CLASS)|(INSTANCEPATH,INSTANCE))> - * - * - * @see String - */ - public static final String VALUE_OBJECTWITHPATH = "VALUE.OBJECTWITHPATH"; - - /** - * The VALUE.NULL element is used to represent a NULL value.
      - * - * - * <!ELEMENT VALUE.NULL EMPTY> - * - * - * @see String - */ - public static final String VALUE_NULL = "VALUE.NULL"; - - /** - * The VALUE.INSTANCEWITHPATH element is used to define value that comprises - * a single CIM instance definition with additional information that defines - * the absolute path to that object.
      - * - * - * <!ELEMENT VALUE.INSTANCEWITHPATH (INSTANCEPATH, INSTANCE)> - * - * - * @see String - */ - public static final String VALUE_INSTANCEWITHPATH = "VALUE.INSTANCEWITHPATH"; - - /** - * The NAMESPACEPATH element is used to define a Namespace Path.
      - * - * - * <!ELEMENT NAMESPACEPATH (HOST,LOCALNAMESPACEPATH)> - * - * - * @see String - */ - public static final String NAMESPACEPATH = "NAMESPACEPATH"; - - /** - * The LOCALNAMESPACEPATH element is used to define a local Namespace path - * (one without a Host component).
      - * - * - * <!ELEMENT LOCALNAMESPACEPATH (NAMESPACE+)> - * - * - * @see String - */ - public static final String LOCALNAMESPACEPATH = "LOCALNAMESPACEPATH"; - - /** - * The HOST element is used to define a single Host.
      - * - * - * <!ELEMENT HOST (#PCDATA)> - * - * - * @see String - */ - public static final String HOST = "HOST"; - - /** - * The NAMESPACE element is used to define a single Namespace component of a - * Namespace path.
      - * - * - * <!ELEMENT NAMESPACE EMPTY> - * <!ATTLIST NAMESPACE - * %CIMName;> - * - * - * @see String - */ - public static final String NAMESPACE = "NAMESPACE"; - - /** - * The CLASSPATH element defines the absolute path to a CIM Class.
      - * - * - * <!ELEMENT CLASSPATH (NAMESPACEPATH,CLASSNAME)> - * - * - * @see String - */ - public static final String CLASSPATH = "CLASSPATH"; - - /** - * The LOCALCLASSPATH element defines the a local path to a CIM Class.
      - * - * - * - * <!ELEMENT LOCALCLASSPATH (LOCALNAMESPACEPATH, CLASSNAME)> - * - * - * - * @see String - */ - public static final String LOCALCLASSPATH = "LOCALCLASSPATH"; - - /** - * The CLASSNAME element defines the qualifying name of a CIM Class.
      - * - * - * <!ELEMENT CLASSNAME EMPTY> - * <!ATTLIST CLASSNAME - * %CIMName;> - * - * - * @see String - */ - public static final String CLASSNAME = "CLASSNAME"; - - /** - * The INSTANCEPATH element defines the absolute path to a CIM Instance.
      - * - * - * <!ELEMENT INSTANCEPATH (NAMESPACEPATH,INSTANCENAME)> - * - * - * @see String - */ - public static final String INSTANCEPATH = "INSTANCEPATH"; - - /** - * The LOCALINSTANCEPATH element defines the local path to a CIM Instance.
      - * - * - * <!ELEMENT LOCALINSTANCEPATH (LOCALNAMESPACEPATH,INSTANCENAME)> - * - * - * @see String - */ - public static final String LOCALINSTANCEPATH = "LOCALINSTANCEPATH"; - - /** - * The INSTANCENAME element defines the location of a CIM Instance within a - * Namespace.
      - * - * - * <!ELEMENT INSTANCENAME (KEYBINDING*|KEYVALUE?|VALUE.REFERENCE?)> - * <!ATTLIST INSTANCENAME - * %ClassName;> - * - * - * @see String - */ - public static final String INSTANCENAME = "INSTANCENAME"; - - /** - * The OBJECTPATH element is used to define a full path to a single CIM - * Object (Class or Instance).
      - * - * - * <!ELEMENT OBJECTPATH (INSTANCEPATH|CLASSPATH)> - * - * - * @see String - */ - public static final String OBJECTPATH = "OBJECTPATH"; - - /** - * The KEYBINDING element defines a single key property value binding.
      - * - * - * <!ELEMENT KEYBINDING (KEYVALUE|VALUE.REFERENCE)> - * <!ATTLIST KEYBINDING - * %CIMName;> - * - * - * @see String - */ - public static final String KEYBINDING = "KEYBINDING"; - - /** - * The KEYVALUE element defines a single property key value when the key - * property is a non-reference type.
      - * - * - * <!ELEMENT KEYVALUE (#PCDATA)> - * <!ATTLIST KEYVALUE - * VALUETYPE (string|boolean|numeric) "string" - * %CIMType; #IMPLIED> - * - * - * @see String - */ - public static final String KEYVALUE = "KEYVALUE"; - - /** - * The CLASS element defines a single CIM Class.
      - * - * - * <!ELEMENT CLASS (QUALIFIER*,(PROPERTY|PROPERTY.ARRAY|PROPERTY.REFERENCE)*,METHOD*)> - * <!ATTLIST CLASS - * %CIMName; - * %SuperClass;> - * - * - * @see String - */ - public static final String CLASS = "CLASS"; - - /** - * The INSTANCE element defines a single CIM Instance of a CIM Class.
      - * - * - * <!ELEMENT INSTANCE (QUALIFIER*,(PROPERTY|PROPERTY.ARRAY|PROPERTY.REFERENCE)*)> - * <!ATTLIST INSTANCE - * %ClassName; - * xml:lang NMTOKEN #IMPLIED> - * - * - * @see String - */ - public static final String INSTANCE = "INSTANCE"; - - /** - * The QUALIFIER element defines a single CIM Qualifier.
      - * - * - * <!ELEMENT QUALIFIER ((VALUE|VALUE.ARRAY)?)> - * <!ATTLIST QUALIFIER - * %CIMName; - * %CIMType; #REQUIRED - * %Propagated; - * %QualifierFlavor; - * xml:lang NMTOKEN #IMPLIED> - * - * - * @see String - */ - public static final String QUALIFIER = "QUALIFIER"; - - /** - * The PROPERTY element defines the value in a CIM Instance or the - * definition in a CIM Class of a single (non-array) CIM Property that is - * not a reference.
      - * - * - * <!ELEMENT PROPERTY (QUALIFIER*,VALUE?)> - * <!ATTLIST PROPERTY - * %CIMName; - * %CIMType; #REQUIRED - * %ClassOrigin; - * %Propagated; - * %EmbeddedObject; - * xml:lang NMTOKEN #IMPLIED> - * - * - * @see String - */ - public static final String PROPERTY = "PROPERTY"; - - /** - * The PROPERTY.ARRAY element defines the value in a CIM Instance or the - * definition in a CIM Class of a single CIM Property with an array type.
      - * - * - * <!ELEMENT PROPERTY.ARRAY (QUALIFIER*,VALUE.ARRAY?)> - * <!ATTLIST PROPERTY.ARRAY - * %CIMName; - * %CIMType; #REQUIRED - * %ArraySize; - * %ClassOrigin; - * %Propagated; - * %EmbeddedObject; - * xml:lang NMTOKEN #IMPLIED> - * - * - * @see String - */ - public static final String PROPERTY_ARRAY = "PROPERTY.ARRAY"; - - /** - * The PROPERTY.REFERENCE element defines the value in a CIM Instance or the - * definition in a CIM Class of a single CIM Property with reference - * semantics.
      - * - * - * <!ELEMENT PROPERTY.REFERENCE (QUALIFIER*,VALUE.REFERENCE?)> - * <!ATTLIST PROPERTY.REFERENCE - * %CIMName; - * %ReferenceClass; - * %ClassOrigin; - * %Propagated;> - * - * - * @see String - */ - public static final String PROPERTY_REFERENCE = "PROPERTY.REFERENCE"; - - /** - * - * The METHOD element defines a single CIM Method.
      - * - * - * <!ELEMENT METHOD (QUALIFIER*,(PARAMETER|PARAMETER.REFERENCE|PARAMETER.ARRAY|PARAMETER.REFARRAY)*)> - * <!ATTLIST METHOD - * %CIMName; - * %CIMType; #IMPLIED - * %ClassOrigin; - * %Propagated;> - * - * - * @see String - */ - public static final String METHOD = "METHOD"; - - /** - * The PARAMETER element defines a single (non-array, non-reference) - * Parameter to a CIM Method.
      - * - * - * <!ELEMENT PARAMETER (QUALIFIER*)> - * <!ATTLIST PARAMETER - * %CIMName; - * %CIMType; #REQUIRED> - * - * - * @see String - */ - public static final String PARAMETER = "PARAMETER"; - - /** - * The PARAMETER.REFERENCE element defines a single reference Parameter to a - * CIM Method.
      - * - * - * <!ELEMENT PARAMETER.REFERENCE (QUALIFIER*)> - * <!ATTLIST PARAMETER.REFERENCE - * %CIMName; - * %ReferenceClass;> - * - * - * @see String - */ - public static final String PARAMETER_REFERENCE = "PARAMETER.REFERENCE"; - - /** - * The PARAMETER.ARRAY element defines a single Parameter to a CIM Method - * that has an array type.
      - * - * - * <!ELEMENT PARAMETER.ARRAY (QUALIFIER*)> - * <!ATTLIST PARAMETER.ARRAY - * %CIMName; - * %CIMType; #REQUIRED - * %ArraySize;> - * - * - * @see String - */ - public static final String PARAMETER_ARRAY = "PARAMETER.ARRAY"; - - /** - * The PARAMETER.REFARRAY element defines a single Parameter to a CIM Method - * that has an array of references type.
      - * - * - * <!ELEMENT PARAMETER.REFARRAY (QUALIFIER*)> - * <!ATTLIST PARAMETER.REFARRAY - * %CIMName; - * %ReferenceClass; - * %ArraySize;> - * - * - * @see String - */ - public static final String PARAMETER_REFARRAY = "PARAMETER.REFARRAY"; - - /* - * TABLE stuff is missing yet - */ - - /** - * The MESSAGE element models a single CIM message.
      - * - * - * <!ELEMENT MESSAGE (SIMPLEREQ|MULTIREQ|SIMPLERSP|MULTIRSP|SIMPLEEXPREQ|MULTIEXPREQ|SIMPLEEXPRSP|MULTIEXPRSP)> - * <!ATTLIST MESSAGE - * ID CDATA #REQUIRED - * PROTOCOLVERSION CDATA #REQUIRED>> - * - * - * @see String - */ - public static final String MESSAGE = "MESSAGE"; - - /** - * The MULTIREQ element defines a Multiple CIM Operation request.
      - * - * - * <!ELEMENT MULTIREQ (SIMPLEREQ,SIMPLEREQ+)> - * - * - * @see String - */ - public static final String MULTIREQ = "MULTIREQ"; - - /** - * The MULTIEXPREQ element defines a Multiple CIM Export request.
      - * - * - * <!ELEMENT MULTIEXPREQ (SIMPLEEXPREQ,SIMPLEEXPREQ+)> - * - * - * @see String - */ - public static final String MULTIEXPREQ = "MULTIEXPREQ"; - - /** - * The SIMPLEREQ element defines a Simple CIM Operation request.
      - * - * - * <!ELEMENT SIMPLEREQ (METHODCALL|IMETHODCALL)> - * - * - * @see String - */ - public static final String SIMPLEREQ = "SIMPLEREQ"; - - /** - * The SIMPLEEXPREQ element defines a Simple CIM Export request.
      - * - * - * <!ELEMENT SIMPLEEXPREQ (EXPMETHODCALL)> - * - * - * @see String - */ - public static final String SIMPLEEXPREQ = "SIMPLEEXPREQ"; - - /** - * The IMETHODCALL element defines a single intrinsic method invocation.
      - * - * - * <!ELEMENT IMETHODCALL (LOCALNAMESPACEPATH,IPARAMVALUE*)> - * <!ATTLIST IMETHODCALL - * %CIMName;> - * - * - * @see String - */ - public static final String IMETHODCALL = "IMETHODCALL"; - - /** - * The METHODCALL element defines a single method invocation on a Class or - * Instance.
      - * - * - * <!ELEMENT METHODCALL ((LOCALCLASSPATH|LOCALINSTANCEPATH),PARAMVALUE*)> - * <!ATTLIST METHODCALL - * %CIMName;> - * - * - * @see String - */ - public static final String METHODCALL = "METHODCALL"; - - /** - * The EXPMETHODCALL element defines a single export method invocation.
      - * - * - * <!ELEMENT EXPMETHODCALL (EXPPARAMVALUE*)> - * <!ATTLIST EXPMETHODCALL - * %CIMName;> - * - * - * @see String - */ - public static final String EXPMETHODCALL = "EXPMETHODCALL"; - - /** - * The PARAMVALUE element defines a single extrinsic method named parameter - * value.
      - * - * - * <!ELEMENT PARAMVALUE (VALUE|VALUE.REFERENCE|VALUE.ARRAY|VALUE.REFARRAY)?> - * <!ATTLIST PARAMVALUE - * %CIMName; - * %ParamType; #IMPLIED - * %EmbeddedObject;> - * - * - * @see String - */ - public static final String PARAMVALUE = "PARAMVALUE"; - - /** - * The IPARAMVALUE element defines a single intrinsic method named parameter - * value.
      - * - * - * <!ELEMENT IPARAMVALUE (VALUE|VALUE.ARRAY|VALUE.REFERENCE|CLASSNAME|INSTANCENAME|QUALIFIER.DECLARATION|CLASS|INSTANCE|VALUE.NAMEDINSTANCE)?> - * <!ATTLIST IPARAMVALUE - * %CIMName;> - * - * - * @see String - */ - public static final String IPARAMVALUE = "IPARAMVALUE"; - - /** - * The EXPPARAMVALUE element defines a single export method named parameter - * value.
      - * - * - * <!ELEMENT EXPPARAMVALUE (INSTANCE?)> - * <!ATTLIST EXPPARAMVALUE - * %CIMName;> - * - * - * @see String - */ - public static final String EXPPARAMVALUE = "EXPPARAMVALUE"; - - /** - * The MULTIRSP element defines a Multiple CIM Operation response.
      - * - * - * <!ELEMENT MULTIRSP (SIMPLERSP,SIMPLERSP+)> - * - * - * @see String - */ - public static final String MULTIRSP = "MULTIRSP"; - - /** - * The MULTIEXPRSP element defines a Multiple CIM Export response.
      - * - * - * <!ELEMENT MULTIEXPRSP (SIMPLEEXPRSP,SIMPLEEXPRSP+)> - * - * - * @see String - */ - public static final String MULTIEXPRSP = "MULTIEXPRSP"; - - /** - * The SIMPLERSP element defines a Simple CIM Operation response.
      - * - * - * <!ELEMENT SIMPLERSP (METHODRESPONSE|IMETHODRESPONSE)> - * - * - * @see String - */ - public static final String SIMPLERSP = "SIMPLERSP"; - - /** - * The SIMPLEEXPRSP element defines a Simple CIM Export response.
      - * - * - * <!ELEMENT SIMPLEEXPRSP (EXPMETHODRESPONSE)> - * - * - * @see String - */ - public static final String SIMPLEEXPRSP = "SIMPLEEXPRSP"; - - /** - * The METHODRESPONSE defines the response to a single CIM extrinsic method - * invocation.
      - * - * - * - * <!ELEMENT METHODRESPONSE (ERROR|(RETURNVALUE?,PARAMVALUE*))> - * <!ATTLIST METHODRESPONSE %CIMName;> - * - * - * - * @see String - */ - public static final String METHODRESPONSE = "METHODRESPONSE"; - - /** - * The EXPMETHODRESPONSE defines the response to a single export method - * invocation.
      - * - * - * <!ELEMENT EXPMETHODRESPONSE (ERROR|IRETURNVALUE?)> - * <!ATTLIST EXPMETHODRESPONSE - * %CIMName;> - * - * - * @see String - */ - public static final String EXPMETHODRESPONSE = "EXPMETHODRESPONSE"; - - /** - * The IMETHODRESPONSE defines the response to a single intrinsic CIM method - * invocation.
      - * - * - * <!ELEMENT IMETHODRESPONSE (ERROR|IRETURNVALUE?)> - * <!ATTLIST IMETHODRESPONSE - * %CIMName;> - * - * - * @see String - */ - public static final String IMETHODRESPONSE = "IMETHODRESPONSE"; - - /** - * The ERROR element is used to define a fundamental error which prevented a - * method from executing normally.
      - * - * - * <!ELEMENT ERROR (INSTANCE*) - * <!ATTLIST ERROR - * CODE CDATA #REQUIRED - * DESCRIPTION CDATA #IMPLIED> - * - * - * @see String - */ - public static final String ERROR = "ERROR"; - - /** - * The RETURNVALUE element specifies the value returned from an extrinsic - * method call.
      - * - * - * <!ELEMENT RETURNVALUE (VALUE|VALUE.REFERENCE)?> - * <!ATTLIST RETURNVALUE - * %EmbeddedObject; - * %ParamType; #IMPLIED> - * - * - * @see String - */ - public static final String RETURNVALUE = "RETURNVALUE"; - - /** - * The IRETURNVALUE element specifies the value returned from an intrinsic - * method call.
      - * - * - * <!ELEMENT IRETURNVALUE (CLASSNAME*|INSTANCENAME*|VALUE*|VALUE.OBJECTWITHPATH*|VALUE.OBJECTWITHLOCALPATH*VALUE.OBJECT*|OBJECTPATH*|QUALIFIER.DECLARATION*|VALUE.ARRAY?|VALUE.REFERENCE?|CLASS*|INSTANCE*|VALUE.NAMEDINSTANCE*)> - * - * - * @see String - */ - public static final String IRETURNVALUE = "IRETURNVALUE"; - - /** - * The CORRELATOR element represents a server-defined operation correlator.
      - * - * - * <!ELEMENT CORRELATOR (VALUE)> - * <!ATTLIST CORRELATOR - * %CIMName; - * %CIMType; #REQUIRED> - * - * - * @see String - */ - public static final String CORRELATOR = "CORRELATOR"; -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2210455 2008-10-30 blaschke-oss Enhance javadoc, fix potential null pointers + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2845211 2009-08-27 raman_arora Pull Enumeration Feature (SAX Parser) + * 2666 2013-09-19 blaschke-oss CR12: Remove ENUMERATIONCONTEXT + * 2672 2013-09-26 blaschke-oss Remove SIMPLEREQACK support + * 2690 2013-10-11 blaschke-oss Remove RESPONSEDESTINATION support + * 2538 2013-11-28 blaschke-oss CR14: Support new CORRELATOR element + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * Class NodeConstIf + * + */ +public interface NodeConstIf { + /** + * The CIM element is the root element of every XML Document that is valid + * with respect to this schema.
      + * + * + * <!ELEMENT CIM (MESSAGE|DECLARATION)> + * <!ATTLIST CIM + * CIMVERSION CDATA #REQUIRED + * DTDVERSION CDATA #REQUIRED> + * + * + * @see String + */ + public static final String CIM = "CIM"; + + /** + * The DECLARATION element defines a set of one or more declarations of CIM + * objects.
      + * + * + * + * <!ELEMENT DECLARATION (DECLGROUP|DECLGROUP.WITHNAME|DECLGROUP.WITHPATH)+> + * + * + * @see String + */ + public static final String DECLARATION = "DECLARATION"; + + /** + * The DECLGROUP element defines a logical set of CIM Class, Instance and + * Qualifier declarations.
      + * + * + * <!ELEMENT DECLGROUP ((LOCALNAMESPACEPATH|NAMESPACEPATH)?,QUALIFIER.DECLARATION*,VALUE.OBJECT*)> + * + * + * @see String + */ + public static final String DECLGROUP = "DECLGROUP"; + + /** + * The DECLGROUP.WITHNAME element defines a logical set of CIM Class, + * Instance and Qualifier declarations.
      + * + * + * <!ELEMENT DECLGROUP.WITHNAME ((LOCALNAMESPACEPATH|NAMESPACEPATH)?,QUALIFIER.DECLARATION*,VALUE.NAMEDOBJECT*)> + * + * + * @see String + */ + public static final String DECLGROUP_WITHNAME = "DECLGROUP.WITHNAME"; + + /** + * The DECLGROUP.WITHPATH element defines a logical set of CIM Class and + * Instance declarations.
      + * + * + * <!ELEMENT DECLGROUP.WITHPATH (VALUE.OBJECTWITHPATH|VALUE.OBJECTWITHLOCALPATH)*> + * + * + * @see String + */ + public static final String DECLGROUP_WITHPATH = "DECLGROUP.WITHPATH"; + + /** + * The QUALIFIER.DECLARATION element defines a single CIM Qualifier + * declaration.
      + * + * + * <!ELEMENT QUALIFIER.DECLARATION (SCOPE?,(VALUE|VALUE.ARRAY)?)> + * <!ATTLIST QUALIFIER.DECLARATION + * %CIMName; + * %CIMType; #REQUIRED + * ISARRAY (true|false) #IMPLIED + * %ArraySize; + * %QualifierFlavor;> + * + * + * @see String + */ + public static final String QUALIFIER_DECLARATION = "QUALIFIER.DECLARATION"; + + /** + * The SCOPE element defines the scope of a QUALIFIER.DECLARATION in the + * case that there are restrictions on the scope of the Qualifier + * declaration.
      + * + * + * <!ELEMENT SCOPE EMPTY> + * <!ATTLIST SCOPE + * CLASS (true|false) "false" + * ASSOCIATION (true|false) "false" + * REFERENCE (true|false) "false" + * PROPERTY (true|false) "false" + * METHOD (true|false) "false" + * PARAMETER (true|false) "false" + * INDICATION (true|false) "false"> + * + * + * @see String + */ + public static final String SCOPE = "SCOPE"; + + /** + * The VALUE element is used to define a single (non-array) non-reference + * non-NULL CIM Property value, CIM Qualifier value, CIM Method return + * value, or CIM Method Parameter value.
      + * + * + * <!ELEMENT VALUE (#PCDATA)> + * + * + * @see String + */ + public static final String VALUE = "VALUE"; + + /** + * The VALUE.ARRAY element is used to represent the value of a CIM Property + * or Qualifier that has an array type.
      + * + * + * + * <!ELEMENT VALUE.ARRAY (VALUE|VALUE.NULL)*> + * + * + * @see String + */ + public static final String VALUE_ARRAY = "VALUE.ARRAY"; + + /** + * The VALUE.REFERENCE element is used to define a single CIM reference + * Property value.
      + * + * + * <!ELEMENT VALUE.REFERENCE (CLASSPATH|LOCALCLASSPATH|CLASSNAME|INSTANCEPATH|LOCALINSTANCEPATH|INSTANCENAME)> + * + * + * @see String + */ + public static final String VALUE_REFERENCE = "VALUE.REFERENCE"; + + /** + * The VALUE.REFARRAY element is used to represent the value of an array of + * CIM references.
      + * + * + * <!ELEMENT VALUE.REFARRAY (VALUE.REFERENCE|VALUE.NULL)*> + * + * + * @see String + */ + public static final String VALUE_REFARRAY = "VALUE.REFARRAY"; + + /** + * The VALUE.OBJECT element is used to define a value which is comprised of + * a single CIM Class or Instance definition.
      + * + * + * <!ELEMENT VALUE.OBJECT (CLASS|INSTANCE)> + * + * + * @see String + */ + public static final String VALUE_OBJECT = "VALUE.OBJECT"; + + /** + * The VALUE.NAMEDINSTANCE element is used to define a value which is + * comprised of a single named CIM Instance definition.
      + * + * + * + * <!ELEMENT VALUE.NAMEDINSTANCE (INSTANCENAME,INSTANCE)> + * + * + * @see String + */ + public static final String VALUE_NAMEDINSTANCE = "VALUE.NAMEDINSTANCE"; + + /** + * The VALUE.NAMEDOBJECT element is used to define a value which is + * comprised of a single named CIM Class or Instance definition.
      + * + * + * <!ELEMENT VALUE.NAMEDOBJECT (CLASS|(INSTANCENAME,INSTANCE))> + * + * + * @see String + */ + public static final String VALUE_NAMEDOBJECT = "VALUE.NAMEDOBJECT"; + + /** + * The VALUE.OBJECTWITHLOCALPATH element is used to define a value which is + * comprised of a single CIM Object (Class or Instance) definition with + * additional information that defines the local path to that Object.
      + * + * + * <!ELEMENT VALUE.OBJECTWITHLOCALPATH ((LOCALCLASSPATH,CLASS)|(LOCALINSTANCEPATH,INSTANCE))> + * + * + * @see String + */ + public static final String VALUE_OBJECTWITHLOCALPATH = "VALUE.OBJECTWITHLOCALPATH"; + + /** + * The VALUE.OBJECTWITHPATH element is used to define a value which is + * comprised of a single CIM Object (Class or Instance) definition with + * additional information that defines the absolute path to that Object.
      + * + * + * <!ELEMENT VALUE.OBJECTWITHPATH ((CLASSPATH,CLASS)|(INSTANCEPATH,INSTANCE))> + * + * + * @see String + */ + public static final String VALUE_OBJECTWITHPATH = "VALUE.OBJECTWITHPATH"; + + /** + * The VALUE.NULL element is used to represent a NULL value.
      + * + * + * <!ELEMENT VALUE.NULL EMPTY> + * + * + * @see String + */ + public static final String VALUE_NULL = "VALUE.NULL"; + + /** + * The VALUE.INSTANCEWITHPATH element is used to define value that comprises + * a single CIM instance definition with additional information that defines + * the absolute path to that object.
      + * + * + * <!ELEMENT VALUE.INSTANCEWITHPATH (INSTANCEPATH, INSTANCE)> + * + * + * @see String + */ + public static final String VALUE_INSTANCEWITHPATH = "VALUE.INSTANCEWITHPATH"; + + /** + * The NAMESPACEPATH element is used to define a Namespace Path.
      + * + * + * <!ELEMENT NAMESPACEPATH (HOST,LOCALNAMESPACEPATH)> + * + * + * @see String + */ + public static final String NAMESPACEPATH = "NAMESPACEPATH"; + + /** + * The LOCALNAMESPACEPATH element is used to define a local Namespace path + * (one without a Host component).
      + * + * + * <!ELEMENT LOCALNAMESPACEPATH (NAMESPACE+)> + * + * + * @see String + */ + public static final String LOCALNAMESPACEPATH = "LOCALNAMESPACEPATH"; + + /** + * The HOST element is used to define a single Host.
      + * + * + * <!ELEMENT HOST (#PCDATA)> + * + * + * @see String + */ + public static final String HOST = "HOST"; + + /** + * The NAMESPACE element is used to define a single Namespace component of a + * Namespace path.
      + * + * + * <!ELEMENT NAMESPACE EMPTY> + * <!ATTLIST NAMESPACE + * %CIMName;> + * + * + * @see String + */ + public static final String NAMESPACE = "NAMESPACE"; + + /** + * The CLASSPATH element defines the absolute path to a CIM Class.
      + * + * + * <!ELEMENT CLASSPATH (NAMESPACEPATH,CLASSNAME)> + * + * + * @see String + */ + public static final String CLASSPATH = "CLASSPATH"; + + /** + * The LOCALCLASSPATH element defines the a local path to a CIM Class.
      + * + * + * + * <!ELEMENT LOCALCLASSPATH (LOCALNAMESPACEPATH, CLASSNAME)> + * + * + * + * @see String + */ + public static final String LOCALCLASSPATH = "LOCALCLASSPATH"; + + /** + * The CLASSNAME element defines the qualifying name of a CIM Class.
      + * + * + * <!ELEMENT CLASSNAME EMPTY> + * <!ATTLIST CLASSNAME + * %CIMName;> + * + * + * @see String + */ + public static final String CLASSNAME = "CLASSNAME"; + + /** + * The INSTANCEPATH element defines the absolute path to a CIM Instance.
      + * + * + * <!ELEMENT INSTANCEPATH (NAMESPACEPATH,INSTANCENAME)> + * + * + * @see String + */ + public static final String INSTANCEPATH = "INSTANCEPATH"; + + /** + * The LOCALINSTANCEPATH element defines the local path to a CIM Instance.
      + * + * + * <!ELEMENT LOCALINSTANCEPATH (LOCALNAMESPACEPATH,INSTANCENAME)> + * + * + * @see String + */ + public static final String LOCALINSTANCEPATH = "LOCALINSTANCEPATH"; + + /** + * The INSTANCENAME element defines the location of a CIM Instance within a + * Namespace.
      + * + * + * <!ELEMENT INSTANCENAME (KEYBINDING*|KEYVALUE?|VALUE.REFERENCE?)> + * <!ATTLIST INSTANCENAME + * %ClassName;> + * + * + * @see String + */ + public static final String INSTANCENAME = "INSTANCENAME"; + + /** + * The OBJECTPATH element is used to define a full path to a single CIM + * Object (Class or Instance).
      + * + * + * <!ELEMENT OBJECTPATH (INSTANCEPATH|CLASSPATH)> + * + * + * @see String + */ + public static final String OBJECTPATH = "OBJECTPATH"; + + /** + * The KEYBINDING element defines a single key property value binding.
      + * + * + * <!ELEMENT KEYBINDING (KEYVALUE|VALUE.REFERENCE)> + * <!ATTLIST KEYBINDING + * %CIMName;> + * + * + * @see String + */ + public static final String KEYBINDING = "KEYBINDING"; + + /** + * The KEYVALUE element defines a single property key value when the key + * property is a non-reference type.
      + * + * + * <!ELEMENT KEYVALUE (#PCDATA)> + * <!ATTLIST KEYVALUE + * VALUETYPE (string|boolean|numeric) "string" + * %CIMType; #IMPLIED> + * + * + * @see String + */ + public static final String KEYVALUE = "KEYVALUE"; + + /** + * The CLASS element defines a single CIM Class.
      + * + * + * <!ELEMENT CLASS (QUALIFIER*,(PROPERTY|PROPERTY.ARRAY|PROPERTY.REFERENCE)*,METHOD*)> + * <!ATTLIST CLASS + * %CIMName; + * %SuperClass;> + * + * + * @see String + */ + public static final String CLASS = "CLASS"; + + /** + * The INSTANCE element defines a single CIM Instance of a CIM Class.
      + * + * + * <!ELEMENT INSTANCE (QUALIFIER*,(PROPERTY|PROPERTY.ARRAY|PROPERTY.REFERENCE)*)> + * <!ATTLIST INSTANCE + * %ClassName; + * xml:lang NMTOKEN #IMPLIED> + * + * + * @see String + */ + public static final String INSTANCE = "INSTANCE"; + + /** + * The QUALIFIER element defines a single CIM Qualifier.
      + * + * + * <!ELEMENT QUALIFIER ((VALUE|VALUE.ARRAY)?)> + * <!ATTLIST QUALIFIER + * %CIMName; + * %CIMType; #REQUIRED + * %Propagated; + * %QualifierFlavor; + * xml:lang NMTOKEN #IMPLIED> + * + * + * @see String + */ + public static final String QUALIFIER = "QUALIFIER"; + + /** + * The PROPERTY element defines the value in a CIM Instance or the + * definition in a CIM Class of a single (non-array) CIM Property that is + * not a reference.
      + * + * + * <!ELEMENT PROPERTY (QUALIFIER*,VALUE?)> + * <!ATTLIST PROPERTY + * %CIMName; + * %CIMType; #REQUIRED + * %ClassOrigin; + * %Propagated; + * %EmbeddedObject; + * xml:lang NMTOKEN #IMPLIED> + * + * + * @see String + */ + public static final String PROPERTY = "PROPERTY"; + + /** + * The PROPERTY.ARRAY element defines the value in a CIM Instance or the + * definition in a CIM Class of a single CIM Property with an array type.
      + * + * + * <!ELEMENT PROPERTY.ARRAY (QUALIFIER*,VALUE.ARRAY?)> + * <!ATTLIST PROPERTY.ARRAY + * %CIMName; + * %CIMType; #REQUIRED + * %ArraySize; + * %ClassOrigin; + * %Propagated; + * %EmbeddedObject; + * xml:lang NMTOKEN #IMPLIED> + * + * + * @see String + */ + public static final String PROPERTY_ARRAY = "PROPERTY.ARRAY"; + + /** + * The PROPERTY.REFERENCE element defines the value in a CIM Instance or the + * definition in a CIM Class of a single CIM Property with reference + * semantics.
      + * + * + * <!ELEMENT PROPERTY.REFERENCE (QUALIFIER*,VALUE.REFERENCE?)> + * <!ATTLIST PROPERTY.REFERENCE + * %CIMName; + * %ReferenceClass; + * %ClassOrigin; + * %Propagated;> + * + * + * @see String + */ + public static final String PROPERTY_REFERENCE = "PROPERTY.REFERENCE"; + + /** + * + * The METHOD element defines a single CIM Method.
      + * + * + * <!ELEMENT METHOD (QUALIFIER*,(PARAMETER|PARAMETER.REFERENCE|PARAMETER.ARRAY|PARAMETER.REFARRAY)*)> + * <!ATTLIST METHOD + * %CIMName; + * %CIMType; #IMPLIED + * %ClassOrigin; + * %Propagated;> + * + * + * @see String + */ + public static final String METHOD = "METHOD"; + + /** + * The PARAMETER element defines a single (non-array, non-reference) + * Parameter to a CIM Method.
      + * + * + * <!ELEMENT PARAMETER (QUALIFIER*)> + * <!ATTLIST PARAMETER + * %CIMName; + * %CIMType; #REQUIRED> + * + * + * @see String + */ + public static final String PARAMETER = "PARAMETER"; + + /** + * The PARAMETER.REFERENCE element defines a single reference Parameter to a + * CIM Method.
      + * + * + * <!ELEMENT PARAMETER.REFERENCE (QUALIFIER*)> + * <!ATTLIST PARAMETER.REFERENCE + * %CIMName; + * %ReferenceClass;> + * + * + * @see String + */ + public static final String PARAMETER_REFERENCE = "PARAMETER.REFERENCE"; + + /** + * The PARAMETER.ARRAY element defines a single Parameter to a CIM Method + * that has an array type.
      + * + * + * <!ELEMENT PARAMETER.ARRAY (QUALIFIER*)> + * <!ATTLIST PARAMETER.ARRAY + * %CIMName; + * %CIMType; #REQUIRED + * %ArraySize;> + * + * + * @see String + */ + public static final String PARAMETER_ARRAY = "PARAMETER.ARRAY"; + + /** + * The PARAMETER.REFARRAY element defines a single Parameter to a CIM Method + * that has an array of references type.
      + * + * + * <!ELEMENT PARAMETER.REFARRAY (QUALIFIER*)> + * <!ATTLIST PARAMETER.REFARRAY + * %CIMName; + * %ReferenceClass; + * %ArraySize;> + * + * + * @see String + */ + public static final String PARAMETER_REFARRAY = "PARAMETER.REFARRAY"; + + /* + * TABLE stuff is missing yet + */ + + /** + * The MESSAGE element models a single CIM message.
      + * + * + * <!ELEMENT MESSAGE (SIMPLEREQ|MULTIREQ|SIMPLERSP|MULTIRSP|SIMPLEEXPREQ|MULTIEXPREQ|SIMPLEEXPRSP|MULTIEXPRSP)> + * <!ATTLIST MESSAGE + * ID CDATA #REQUIRED + * PROTOCOLVERSION CDATA #REQUIRED>> + * + * + * @see String + */ + public static final String MESSAGE = "MESSAGE"; + + /** + * The MULTIREQ element defines a Multiple CIM Operation request.
      + * + * + * <!ELEMENT MULTIREQ (SIMPLEREQ,SIMPLEREQ+)> + * + * + * @see String + */ + public static final String MULTIREQ = "MULTIREQ"; + + /** + * The MULTIEXPREQ element defines a Multiple CIM Export request.
      + * + * + * <!ELEMENT MULTIEXPREQ (SIMPLEEXPREQ,SIMPLEEXPREQ+)> + * + * + * @see String + */ + public static final String MULTIEXPREQ = "MULTIEXPREQ"; + + /** + * The SIMPLEREQ element defines a Simple CIM Operation request.
      + * + * + * <!ELEMENT SIMPLEREQ (METHODCALL|IMETHODCALL)> + * + * + * @see String + */ + public static final String SIMPLEREQ = "SIMPLEREQ"; + + /** + * The SIMPLEEXPREQ element defines a Simple CIM Export request.
      + * + * + * <!ELEMENT SIMPLEEXPREQ (EXPMETHODCALL)> + * + * + * @see String + */ + public static final String SIMPLEEXPREQ = "SIMPLEEXPREQ"; + + /** + * The IMETHODCALL element defines a single intrinsic method invocation.
      + * + * + * <!ELEMENT IMETHODCALL (LOCALNAMESPACEPATH,IPARAMVALUE*)> + * <!ATTLIST IMETHODCALL + * %CIMName;> + * + * + * @see String + */ + public static final String IMETHODCALL = "IMETHODCALL"; + + /** + * The METHODCALL element defines a single method invocation on a Class or + * Instance.
      + * + * + * <!ELEMENT METHODCALL ((LOCALCLASSPATH|LOCALINSTANCEPATH),PARAMVALUE*)> + * <!ATTLIST METHODCALL + * %CIMName;> + * + * + * @see String + */ + public static final String METHODCALL = "METHODCALL"; + + /** + * The EXPMETHODCALL element defines a single export method invocation.
      + * + * + * <!ELEMENT EXPMETHODCALL (EXPPARAMVALUE*)> + * <!ATTLIST EXPMETHODCALL + * %CIMName;> + * + * + * @see String + */ + public static final String EXPMETHODCALL = "EXPMETHODCALL"; + + /** + * The PARAMVALUE element defines a single extrinsic method named parameter + * value.
      + * + * + * <!ELEMENT PARAMVALUE (VALUE|VALUE.REFERENCE|VALUE.ARRAY|VALUE.REFARRAY)?> + * <!ATTLIST PARAMVALUE + * %CIMName; + * %ParamType; #IMPLIED + * %EmbeddedObject;> + * + * + * @see String + */ + public static final String PARAMVALUE = "PARAMVALUE"; + + /** + * The IPARAMVALUE element defines a single intrinsic method named parameter + * value.
      + * + * + * <!ELEMENT IPARAMVALUE (VALUE|VALUE.ARRAY|VALUE.REFERENCE|CLASSNAME|INSTANCENAME|QUALIFIER.DECLARATION|CLASS|INSTANCE|VALUE.NAMEDINSTANCE)?> + * <!ATTLIST IPARAMVALUE + * %CIMName;> + * + * + * @see String + */ + public static final String IPARAMVALUE = "IPARAMVALUE"; + + /** + * The EXPPARAMVALUE element defines a single export method named parameter + * value.
      + * + * + * <!ELEMENT EXPPARAMVALUE (INSTANCE?)> + * <!ATTLIST EXPPARAMVALUE + * %CIMName;> + * + * + * @see String + */ + public static final String EXPPARAMVALUE = "EXPPARAMVALUE"; + + /** + * The MULTIRSP element defines a Multiple CIM Operation response.
      + * + * + * <!ELEMENT MULTIRSP (SIMPLERSP,SIMPLERSP+)> + * + * + * @see String + */ + public static final String MULTIRSP = "MULTIRSP"; + + /** + * The MULTIEXPRSP element defines a Multiple CIM Export response.
      + * + * + * <!ELEMENT MULTIEXPRSP (SIMPLEEXPRSP,SIMPLEEXPRSP+)> + * + * + * @see String + */ + public static final String MULTIEXPRSP = "MULTIEXPRSP"; + + /** + * The SIMPLERSP element defines a Simple CIM Operation response.
      + * + * + * <!ELEMENT SIMPLERSP (METHODRESPONSE|IMETHODRESPONSE)> + * + * + * @see String + */ + public static final String SIMPLERSP = "SIMPLERSP"; + + /** + * The SIMPLEEXPRSP element defines a Simple CIM Export response.
      + * + * + * <!ELEMENT SIMPLEEXPRSP (EXPMETHODRESPONSE)> + * + * + * @see String + */ + public static final String SIMPLEEXPRSP = "SIMPLEEXPRSP"; + + /** + * The METHODRESPONSE defines the response to a single CIM extrinsic method + * invocation.
      + * + * + * + * <!ELEMENT METHODRESPONSE (ERROR|(RETURNVALUE?,PARAMVALUE*))> + * <!ATTLIST METHODRESPONSE %CIMName;> + * + * + * + * @see String + */ + public static final String METHODRESPONSE = "METHODRESPONSE"; + + /** + * The EXPMETHODRESPONSE defines the response to a single export method + * invocation.
      + * + * + * <!ELEMENT EXPMETHODRESPONSE (ERROR|IRETURNVALUE?)> + * <!ATTLIST EXPMETHODRESPONSE + * %CIMName;> + * + * + * @see String + */ + public static final String EXPMETHODRESPONSE = "EXPMETHODRESPONSE"; + + /** + * The IMETHODRESPONSE defines the response to a single intrinsic CIM method + * invocation.
      + * + * + * <!ELEMENT IMETHODRESPONSE (ERROR|IRETURNVALUE?)> + * <!ATTLIST IMETHODRESPONSE + * %CIMName;> + * + * + * @see String + */ + public static final String IMETHODRESPONSE = "IMETHODRESPONSE"; + + /** + * The ERROR element is used to define a fundamental error which prevented a + * method from executing normally.
      + * + * + * <!ELEMENT ERROR (INSTANCE*) + * <!ATTLIST ERROR + * CODE CDATA #REQUIRED + * DESCRIPTION CDATA #IMPLIED> + * + * + * @see String + */ + public static final String ERROR = "ERROR"; + + /** + * The RETURNVALUE element specifies the value returned from an extrinsic + * method call.
      + * + * + * <!ELEMENT RETURNVALUE (VALUE|VALUE.REFERENCE)?> + * <!ATTLIST RETURNVALUE + * %EmbeddedObject; + * %ParamType; #IMPLIED> + * + * + * @see String + */ + public static final String RETURNVALUE = "RETURNVALUE"; + + /** + * The IRETURNVALUE element specifies the value returned from an intrinsic + * method call.
      + * + * + * <!ELEMENT IRETURNVALUE (CLASSNAME*|INSTANCENAME*|VALUE*|VALUE.OBJECTWITHPATH*|VALUE.OBJECTWITHLOCALPATH*VALUE.OBJECT*|OBJECTPATH*|QUALIFIER.DECLARATION*|VALUE.ARRAY?|VALUE.REFERENCE?|CLASS*|INSTANCE*|VALUE.NAMEDINSTANCE*)> + * + * + * @see String + */ + public static final String IRETURNVALUE = "IRETURNVALUE"; + + /** + * The CORRELATOR element represents a server-defined operation correlator.
      + * + * + * <!ELEMENT CORRELATOR (VALUE)> + * <!ATTLIST CORRELATOR + * %CIMName; + * %CIMType; #REQUIRED> + * + * + * @see String + */ + public static final String CORRELATOR = "CORRELATOR"; +} diff --git a/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/NodeFactory.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/NodeFactory.java new file mode 100644 index 0000000..53c7d7c --- /dev/null +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/NodeFactory.java @@ -0,0 +1,714 @@ +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2845211 2009-08-27 raman_arora Pull Enumeration Feature (SAX Parser) + * 3498482 2012-03-09 blaschke-oss Red Hat: Possible XML Hash DoS in sblim + * 3535383 2012-08-01 blaschke-oss HashDoS fix 3498482 + * 2672 2013-09-26 blaschke-oss Remove SIMPLEREQACK support + * 2690 2013-10-11 blaschke-oss Remove RESPONSEDESTINATION support + * 2538 2013-11-28 blaschke-oss CR14: Support new CORRELATOR element + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.HashMap; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node.*; + +/** + * Class NodeFactory is responsible for Node instance construction. + * + */ +public class NodeFactory implements NodeConstIf { + + /** + * getNodeInstance + * + * @param pNodeName + * Should be an XML element name constant which is defined in + * NodeConstIf + * @return the Node subclass which implements the parsing of pNodeName named + * XML Element. + */ + public static Node getNodeInstance(String pNodeName) { + createParserMap(); + return cParserMap.get(pNodeName).create(); + } + + /** + * getEnum + * + * @param pNodeName + * @return The corresponding String constant for an XML element name. It + * must be used, because the Node subclasses use reference based + * equals comparisons (==). + */ + public static String getEnum(String pNodeName) { + return NODENAME_HASH.get(pNodeName); + } + + private static HashMap cParserMap; + + private interface FactoryEntry { + /** + * create + * + * @return Node + */ + public Node create(); + } + + private static synchronized void createParserMap() { + if (cParserMap != null) return; + cParserMap = new HashMap(); + cParserMap.put( + CIM, + new FactoryEntry() { + + public Node create() { + return new CIMNode(); + } + } + ); + // DECLARATION - not implemented + // DECLGROUP - not implemented + // DECLGROUP.WITHNAME - not implemented + // DECLGROUP.WITHPATH - not implemented + cParserMap.put( + QUALIFIER_DECLARATION, + new FactoryEntry() { + + public Node create() { + return new QualiDeclNode(); + } + } + ); + cParserMap.put( + SCOPE, + new FactoryEntry() { + + public Node create() { + return new ScopeNode(); + } + } + ); + cParserMap.put( + VALUE, + new FactoryEntry() { + + public Node create() { + return new ValueNode(); + } + } + ); + cParserMap.put( + VALUE_ARRAY, + new FactoryEntry() { + + public Node create() { + return new ValueArrayNode(); + } + } + ); + cParserMap.put( + VALUE_REFERENCE, + new FactoryEntry() { + + public Node create() { + return new ValueReferenceNode(); + } + } + ); + cParserMap.put( + VALUE_REFARRAY, + new FactoryEntry() { + + public Node create() { + return new ValueRefArrayNode(); + } + } + ); + cParserMap.put( + VALUE_OBJECT, + new FactoryEntry() { + + public Node create() { + return new ValueObjectNode(); + } + } + ); + cParserMap.put( + VALUE_NAMEDINSTANCE, + new FactoryEntry() { + + public Node create() { + return new ValueNamedInstanceNode(); + } + } + ); + cParserMap.put( + VALUE_OBJECTWITHLOCALPATH, + new FactoryEntry() { + + public Node create() { + return new ValueObjectWithLocalPathNode(); + } + } + ); + cParserMap.put( + VALUE_OBJECTWITHPATH, + new FactoryEntry() { + + public Node create() { + return new ValueObjectWithPathNode(); + } + } + ); + cParserMap.put( + VALUE_NULL, + new FactoryEntry() { + + public Node create() { + return new ValueNullNode(); + } + } + ); + cParserMap.put( + VALUE_INSTANCEWITHPATH, + new FactoryEntry() { + + public Node create() { + return new ValueInstanceWithPathNode(); + } + } + ); + cParserMap.put( + NAMESPACEPATH, + new FactoryEntry() { + + public Node create() { + return new NameSpacePathNode(); + } + } + ); + cParserMap.put( + LOCALNAMESPACEPATH, + new FactoryEntry() { + + public Node create() { + return new LocalNameSpacePathNode(); + } + } + ); + cParserMap.put( + HOST, + new FactoryEntry() { + + public Node create() { + return new HostNode(); + } + } + ); + cParserMap.put( + NAMESPACE, + new FactoryEntry() { + + public Node create() { + return new NameSpaceNode(); + } + } + ); + cParserMap.put( + CLASSPATH, + new FactoryEntry() { + + public Node create() { + return new ClassPathNode(); + } + } + ); + cParserMap.put( + LOCALCLASSPATH, + new FactoryEntry() { + + public Node create() { + return new LocalClassPathNode(); + } + } + ); + cParserMap.put( + CLASSNAME, + new FactoryEntry() { + + public Node create() { + return new ClassNameNode(); + } + } + ); + cParserMap.put( + INSTANCEPATH, + new FactoryEntry() { + + public Node create() { + return new InstancePathNode(); + } + } + ); + cParserMap.put( + LOCALINSTANCEPATH, + new FactoryEntry() { + + public Node create() { + return new LocalInstancePathNode(); + } + } + ); + cParserMap.put( + INSTANCENAME, + new FactoryEntry() { + + public Node create() { + return new InstanceNameNode(); + } + } + ); + cParserMap.put( + OBJECTPATH, + new FactoryEntry() { + + public Node create() { + return new ObjectPathNode(); + } + } + ); + cParserMap.put( + KEYBINDING, + new FactoryEntry() { + + public Node create() { + return new KeyBindingNode(); + } + } + ); + cParserMap.put( + KEYVALUE, + new FactoryEntry() { + + public Node create() { + return new KeyValueNode(); + } + } + ); + cParserMap.put( + CLASS, + new FactoryEntry() { + + public Node create() { + return new ClassNode(); + } + } + ); + cParserMap.put( + INSTANCE, + new FactoryEntry() { + + public Node create() { + return new InstanceNode(); + } + } + ); + cParserMap.put( + QUALIFIER, + new FactoryEntry() { + + public Node create() { + return new QualifierNode(); + } + } + ); + cParserMap.put( + PROPERTY, + new FactoryEntry() { + + public Node create() { + return new PropertyNode(); + } + } + ); + cParserMap.put( + PROPERTY_ARRAY, + new FactoryEntry() { + + public Node create() { + return new PropertyArrayNode(); + } + } + ); + cParserMap.put( + PROPERTY_REFERENCE, + new FactoryEntry() { + + public Node create() { + return new PropertyReferenceNode(); + } + } + ); + cParserMap.put( + METHOD, + new FactoryEntry() { + + public Node create() { + return new MethodNode(); + } + } + ); + cParserMap.put( + PARAMETER, + new FactoryEntry() { + + public Node create() { + return new ParameterNode(); + } + } + ); + cParserMap.put( + PARAMETER_REFERENCE, + new FactoryEntry() { + + public Node create() { + return new ParameterReferenceNode(); + } + } + ); + cParserMap.put( + PARAMETER_ARRAY, + new FactoryEntry() { + + public Node create() { + return new ParameterArrayNode(); + } + } + ); + cParserMap.put( + PARAMETER_REFARRAY, + new FactoryEntry() { + + public Node create() { + return new ParameterRefArrayNode(); + } + } + ); + cParserMap.put( + MESSAGE, + new FactoryEntry() { + + public Node create() { + return new MessageNode(); + } + } + ); + cParserMap.put( + MULTIREQ, + new FactoryEntry() { + + public Node create() { + return new MultiReqNode(); + } + } + ); + cParserMap.put( + MULTIEXPREQ, + new FactoryEntry() { + + public Node create() { + return new MultiExpReqNode(); + } + } + ); + cParserMap.put( + SIMPLEREQ, + new FactoryEntry() { + + public Node create() { + return new SimpleReqNode(); + } + } + ); + cParserMap.put( + SIMPLEEXPREQ, + new FactoryEntry() { + + public Node create() { + return new SimpleExpReqNode(); + } + } + ); + cParserMap.put( + IMETHODCALL, + new FactoryEntry() { + + public Node create() { + return new IMethodCallNode(); + } + } + ); + cParserMap.put( + METHODCALL, + new FactoryEntry() { + + public Node create() { + return new MethodCallNode(); + } + } + ); + cParserMap.put( + EXPMETHODCALL, + new FactoryEntry() { + + public Node create() { + return new ExpMethodCallNode(); + } + } + ); + cParserMap.put( + PARAMVALUE, + new FactoryEntry() { + + public Node create() { + return new ParamValueNode(); + } + } + ); + cParserMap.put( + IPARAMVALUE, + new FactoryEntry() { + + public Node create() { + return new IParamValueNode(); + } + } + ); + cParserMap.put( + EXPPARAMVALUE, + new FactoryEntry() { + + public Node create() { + return new ExpParamValueNode(); + } + } + ); + cParserMap.put( + MULTIRSP, + new FactoryEntry() { + + public Node create() { + return new MultiRspNode(); + } + } + ); + cParserMap.put( + MULTIEXPRSP, + new FactoryEntry() { + + public Node create() { + return new MultiExpRspNode(); + } + } + ); + cParserMap.put( + SIMPLERSP, + new FactoryEntry() { + + public Node create() { + return new SimpleRspNode(); + } + } + ); + cParserMap.put( + SIMPLEEXPRSP, + new FactoryEntry() { + + public Node create() { + return new SimpleExpRspNode(); + } + } + ); + cParserMap.put( + METHODRESPONSE, + new FactoryEntry() { + + public Node create() { + return new MethodResponseNode(); + } + } + ); + cParserMap.put( + EXPMETHODRESPONSE, + new FactoryEntry() { + + public Node create() { + return new ExpMethodResponseNode(); + } + } + ); + cParserMap.put( + IMETHODRESPONSE, + new FactoryEntry() { + + public Node create() { + return new IMethodResponseNode(); + } + } + ); + cParserMap.put( + ERROR, + new FactoryEntry() { + + public Node create() { + return new ErrorNode(); + } + } + ); + cParserMap.put( + RETURNVALUE, + new FactoryEntry() { + + public Node create() { + return new ReturnValueNode(); + } + } + ); + cParserMap.put( + IRETURNVALUE, + new FactoryEntry() { + + public Node create() { + return new IReturnValueNode(); + } + } + ); + cParserMap.put( + CORRELATOR, + new FactoryEntry() { + + public Node create() { + return new CorrelatorNode(); + } + } + ); + } + + private static final HashMap NODENAME_HASH = new HashMap(); + + private static void initNodeNameHash(String[] pEnumA) { + for (int i = 0; i < pEnumA.length; i++) NODENAME_HASH.put(pEnumA[i], pEnumA[i]); + } + + static { + initNodeNameHash( + new String[] { + CIM, + DECLARATION, + DECLGROUP, + DECLGROUP_WITHNAME, + DECLGROUP_WITHPATH, + QUALIFIER_DECLARATION, + SCOPE, + VALUE, + VALUE_ARRAY, + VALUE_REFERENCE, + VALUE_REFARRAY, + VALUE_OBJECT, + VALUE_NAMEDINSTANCE, + VALUE_NAMEDOBJECT, + VALUE_OBJECTWITHLOCALPATH, + VALUE_OBJECTWITHPATH, + VALUE_NULL, + VALUE_INSTANCEWITHPATH, + NAMESPACEPATH, + LOCALNAMESPACEPATH, + HOST, + NAMESPACE, + CLASSPATH, + LOCALCLASSPATH, + CLASSNAME, + INSTANCEPATH, + LOCALINSTANCEPATH, + INSTANCENAME, + OBJECTPATH, + KEYBINDING, + KEYVALUE, + CLASS, + INSTANCE, + QUALIFIER, + PROPERTY, + PROPERTY_ARRAY, + PROPERTY_REFERENCE, + METHOD, + PARAMETER, + PARAMETER_REFERENCE, + PARAMETER_ARRAY, + PARAMETER_REFARRAY, + /* + * TABLE stuff is missing yet + */ + MESSAGE, + MULTIREQ, + MULTIEXPREQ, + SIMPLEREQ, + SIMPLEEXPREQ, + IMETHODCALL, + METHODCALL, + EXPMETHODCALL, + PARAMVALUE, + IPARAMVALUE, + EXPPARAMVALUE, + MULTIRSP, + MULTIEXPRSP, + SIMPLERSP, + SIMPLEEXPRSP, + METHODRESPONSE, + EXPMETHODRESPONSE, + IMETHODRESPONSE, + ERROR, + RETURNVALUE, + IRETURNVALUE, + CORRELATOR + } + ); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/NodePool.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/NodePool.java similarity index 72% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/NodePool.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/NodePool.java index 7562925..4263f02 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/NodePool.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/NodePool.java @@ -1,161 +1,153 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1663270 2007-02-19 ebak Minor performance problems - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.HashMap; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node.Node; - -/** - * NodePool is used by XMLDefaultHandlerImpl to store unused Node instances - * which can be reused later without instantiating new ones. - */ -public class NodePool { - - private HashMap iPoolMap = new HashMap(512); - - private int iHitCnt = 0; - - private int iMissCnt = 0; - - /** - * addNode - * - * @param pNode - */ - public void addNode(Node pNode) { - PoolStack ps = this.iPoolMap.get(pNode.getNodeName()); - if (ps == null) { - this.iPoolMap.put(pNode.getNodeName(), new PoolStack(pNode)); - return; - } - ps.put(pNode); - } - - /** - * getNode - * - * @param pNodeName - * @return Node - */ - public Node getNode(String pNodeName) { - PoolStack ps = this.iPoolMap.get(pNodeName); - if (ps == null) { - ++this.iMissCnt; - return null; - } - Node node = ps.get(); - if (node == null) ++this.iMissCnt; - else ++this.iHitCnt; - return node; - } - - /** - * getHitCnt - * - * @return int - */ - public int getHitCnt() { - return this.iHitCnt; - } - - /** - * getMissCnt - * - * @return int - */ - public int getMissCnt() { - return this.iMissCnt; - } - -} - -class PoolStack { - - private static final int CAPACITY = 8, MAX_USECNT = CAPACITY - 1, MAX_IDX = MAX_USECNT; - - private Node[] iNodeA = new Node[CAPACITY]; - - private int iIdx = 0, iUseCnt = 0; - - /** - * Ctor. - * - * @param pNode - */ - public PoolStack(Node pNode) { - put(pNode); - } - - /** - * put - * - * @param pNode - */ - public void put(Node pNode) { - if (this.iUseCnt < MAX_USECNT) ++this.iUseCnt; - this.iNodeA[this.iIdx] = pNode; - incIdx(); - } - - /** - * get - * - * @return Node - */ - public Node get() { - if (this.iUseCnt == 0) return null; - --this.iUseCnt; - decIdx(); - return this.iNodeA[this.iIdx]; - } - - private void decIdx() { - this.iIdx = (this.iIdx == 0 ? MAX_IDX : this.iIdx - 1); - } - - private void incIdx() { - this.iIdx = (this.iIdx == MAX_IDX ? 0 : this.iIdx + 1); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1663270 2007-02-19 ebak Minor performance problems + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.HashMap; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node.Node; + +/** + * NodePool is used by XMLDefaultHandlerImpl to store unused Node instances + * which can be reused later without instantiating new ones. + */ +public class NodePool { + private HashMap iPoolMap = new HashMap(512); + + private int iHitCnt = 0; + + private int iMissCnt = 0; + + /** + * addNode + * + * @param pNode + */ + public void addNode(Node pNode) { + PoolStack ps = this.iPoolMap.get(pNode.getNodeName()); + if (ps == null) { + this.iPoolMap.put(pNode.getNodeName(), new PoolStack(pNode)); + return; + } + ps.put(pNode); + } + + /** + * getNode + * + * @param pNodeName + * @return Node + */ + public Node getNode(String pNodeName) { + PoolStack ps = this.iPoolMap.get(pNodeName); + if (ps == null) { + ++this.iMissCnt; + return null; + } + Node node = ps.get(); + if (node == null) ++this.iMissCnt; else ++this.iHitCnt; + return node; + } + + /** + * getHitCnt + * + * @return int + */ + public int getHitCnt() { + return this.iHitCnt; + } + + /** + * getMissCnt + * + * @return int + */ + public int getMissCnt() { + return this.iMissCnt; + } +} + +class PoolStack { + private static final int CAPACITY = 8, MAX_USECNT = CAPACITY - 1, MAX_IDX = MAX_USECNT; + + private Node[] iNodeA = new Node[CAPACITY]; + + private int iIdx = 0, iUseCnt = 0; + + /** + * Ctor. + * + * @param pNode + */ + public PoolStack(Node pNode) { + put(pNode); + } + + /** + * put + * + * @param pNode + */ + public void put(Node pNode) { + if (this.iUseCnt < MAX_USECNT) ++this.iUseCnt; + this.iNodeA[this.iIdx] = pNode; + incIdx(); + } + + /** + * get + * + * @return Node + */ + public Node get() { + if (this.iUseCnt == 0) return null; + --this.iUseCnt; + decIdx(); + return this.iNodeA[this.iIdx]; + } + + private void decIdx() { + this.iIdx = (this.iIdx == 0 ? MAX_IDX : this.iIdx - 1); + } + + private void incIdx() { + this.iIdx = (this.iIdx == MAX_IDX ? 0 : this.iIdx + 1); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/SAXHelper.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/SAXHelper.java similarity index 58% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/SAXHelper.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/SAXHelper.java index f22baf1..f1d8265 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/SAXHelper.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/SAXHelper.java @@ -1,105 +1,102 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1660756 2007-02-22 ebak Embedded object support - * 1688273 2007-04-16 ebak Full support of HTTP trailers - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.InputStreamReader; - -import org.sentrysoftware.wbem.javax.cim.CIMArgument; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import org.sentrysoftware.wbem.javax.wbem.WBEMException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node.AbstractMessageNode; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node.CIMNode; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node.MessageNode; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node.SimpleRspNode; -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.io.TrailerException; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.CIMError; -import org.xml.sax.InputSource; - -/** - * Class SAXHelper stores methods to help high level CIM-XML pull and SAX - * parsing. - */ -public class SAXHelper { - - /** - * parseInvokeMethodResponse - * - * @param pIs - * @param pOutArgs - * @param pDefPath - * @return Object, any kind of JSR48 value class - * @throws Exception - */ - public static Object parseInvokeMethodResponse(InputStreamReader pIs, - CIMArgument[] pOutArgs, CIMObjectPath pDefPath) throws Exception { - XMLDefaultHandlerImpl hndlr = new XMLDefaultHandlerImpl(pDefPath); - SAXParserFactory factory = SAXParserFactory.newInstance(); - SAXParser saxParser = factory.newSAXParser(); - try { - saxParser.parse(new InputSource(pIs), hndlr); - } catch (TrailerException e) { - throw e.getWBEMException(); - } - - CIMNode cimNode = hndlr.getCIMNode(); - MessageNode msgNode = cimNode.getMessageNode(); - AbstractMessageNode absMsgNode = msgNode.getAbstractMessageNode(); - SimpleRspNode simpRspNode = (SimpleRspNode) absMsgNode; - CIMError cimErr = simpRspNode.getCIMError(); - if (cimErr != null) throw new WBEMException(cimErr.getCode(), cimErr.getDescription(), - cimErr.getCIMInstances()); - CIMArgument[] outArgs = simpRspNode.getCIMArguments(); - if (pOutArgs != null && outArgs != null) { - int len = Math.min(pOutArgs.length, outArgs.length); - for (int i = 0; i < len; i++) - pOutArgs[i] = outArgs[i]; - } - return simpRspNode.getReturnValueCount() == 0 ? null : simpRspNode.readReturnValue(); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1660756 2007-02-22 ebak Embedded object support + * 1688273 2007-04-16 ebak Full support of HTTP trailers + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.InputStreamReader; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import org.metricshub.wbem.javax.cim.CIMArgument; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.wbem.WBEMException; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node.AbstractMessageNode; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node.CIMNode; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node.MessageNode; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node.SimpleRspNode; +import org.metricshub.wbem.sblim.cimclient.internal.http.io.TrailerException; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.CIMError; +import org.xml.sax.InputSource; + +/** + * Class SAXHelper stores methods to help high level CIM-XML pull and SAX + * parsing. + */ +public class SAXHelper { + + /** + * parseInvokeMethodResponse + * + * @param pIs + * @param pOutArgs + * @param pDefPath + * @return Object, any kind of JSR48 value class + * @throws Exception + */ + public static Object parseInvokeMethodResponse( + InputStreamReader pIs, + CIMArgument[] pOutArgs, + CIMObjectPath pDefPath + ) + throws Exception { + XMLDefaultHandlerImpl hndlr = new XMLDefaultHandlerImpl(pDefPath); + SAXParserFactory factory = SAXParserFactory.newInstance(); + SAXParser saxParser = factory.newSAXParser(); + try { + saxParser.parse(new InputSource(pIs), hndlr); + } catch (TrailerException e) { + throw e.getWBEMException(); + } + + CIMNode cimNode = hndlr.getCIMNode(); + MessageNode msgNode = cimNode.getMessageNode(); + AbstractMessageNode absMsgNode = msgNode.getAbstractMessageNode(); + SimpleRspNode simpRspNode = (SimpleRspNode) absMsgNode; + CIMError cimErr = simpRspNode.getCIMError(); + if (cimErr != null) throw new WBEMException(cimErr.getCode(), cimErr.getDescription(), cimErr.getCIMInstances()); + CIMArgument[] outArgs = simpRspNode.getCIMArguments(); + if (pOutArgs != null && outArgs != null) { + int len = Math.min(pOutArgs.length, outArgs.length); + for (int i = 0; i < len; i++) pOutArgs[i] = outArgs[i]; + } + return simpRspNode.getReturnValueCount() == 0 ? null : simpRspNode.readReturnValue(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/SAXSession.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/SAXSession.java similarity index 62% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/SAXSession.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/SAXSession.java index a44f727..6d2cb2e 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/SAXSession.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/SAXSession.java @@ -1,87 +1,81 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1660756 2007-02-22 ebak Embedded object support - * 1848607 2007-12-11 ebak Strict EmbeddedObject types - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConfiguration; - -/** - * This class is intended to store variables which are common for a whole - * CIM-XML SAX parsing session. - */ -public class SAXSession { - - private CIMObjectPath iDefLocalPath; - - private boolean iStrictEmbObjParsing = WBEMConfiguration.getGlobalConfiguration() - .strictEmbObjTypes(); - - /** - * Ctor. - * - * @param pDefLocalPath - */ - public SAXSession(CIMObjectPath pDefLocalPath) { - this.iDefLocalPath = pDefLocalPath; - } - - /** - * getDefLocalPath - * - * @return CIMObjectPath - */ - public CIMObjectPath getDefLocalPath() { - return this.iDefLocalPath; - } - - /** - * strictEmbObjParsing - * - * @return boolean - */ - public boolean strictEmbObjParsing() { - return this.iStrictEmbObjParsing; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1660756 2007-02-22 ebak Embedded object support + * 1848607 2007-12-11 ebak Strict EmbeddedObject types + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfiguration; + +/** + * This class is intended to store variables which are common for a whole + * CIM-XML SAX parsing session. + */ +public class SAXSession { + private CIMObjectPath iDefLocalPath; + + private boolean iStrictEmbObjParsing = WBEMConfiguration.getGlobalConfiguration().strictEmbObjTypes(); + + /** + * Ctor. + * + * @param pDefLocalPath + */ + public SAXSession(CIMObjectPath pDefLocalPath) { + this.iDefLocalPath = pDefLocalPath; + } + + /** + * getDefLocalPath + * + * @return CIMObjectPath + */ + public CIMObjectPath getDefLocalPath() { + return this.iDefLocalPath; + } + + /** + * strictEmbObjParsing + * + * @return boolean + */ + public boolean strictEmbObjParsing() { + return this.iStrictEmbObjParsing; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/XMLDefaultHandlerImpl.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/XMLDefaultHandlerImpl.java similarity index 77% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/XMLDefaultHandlerImpl.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/XMLDefaultHandlerImpl.java index 51123c5..6dddad2 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/XMLDefaultHandlerImpl.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/XMLDefaultHandlerImpl.java @@ -1,296 +1,288 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2713 2013-11-22 blaschke-oss Enforce loose validation of CIM-XML documents - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; -import java.util.logging.Level; - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node.CIMNode; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node.Node; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node.NonVolatileIf; -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -/** - * Class XMLDefaultHandlerImpl is DefaultHandler implementation which is used - * for SAX and PULL style XML parsing. - */ -public class XMLDefaultHandlerImpl extends DefaultHandler { - - private Node iRootNode; - - private NodeStack iNodeStack = new NodeStack(); - - private NodePool iNodePool = new NodePool(); - - private StringBuffer iStrBuf; - - private SAXSession iSession; - - private boolean iAnyRoot; - - /** - * NodeStack - */ - static class NodeStack { - - private ArrayList iAL = new ArrayList(); - - /** - * push - * - * @param pNode - */ - public void push(Node pNode) { - this.iAL.add(pNode); - } - - /** - * pop - * - * @return Node - */ - public Node pop() { - if (this.iAL.size() == 0) return null; - return this.iAL.remove(this.iAL.size() - 1); - } - - /** - * peek - * - * @return Node - */ - public Node peek() { - if (this.iAL.size() == 0) return null; - return this.iAL.get(this.iAL.size() - 1); - } - - } - - /** - * Ctor. - * - * @param pSession - * - stores common variables for the whole parsing session - * @param pAnyRoot - * - if true any CIM-XML element can be the root element of the - * XML stream - */ - public XMLDefaultHandlerImpl(SAXSession pSession, boolean pAnyRoot) { - this.iSession = pSession; - this.iAnyRoot = pAnyRoot; - } - - /** - * Ctor. - * - * @param pLocalPath - * - CIMObjectPathes without local paths will be extended by this - * value - * @param pAnyRoot - * - if true any CIM-XML element can be the root element of the - * XML stream - */ - public XMLDefaultHandlerImpl(CIMObjectPath pLocalPath, boolean pAnyRoot) { - this(new SAXSession(pLocalPath), pAnyRoot); - } - - /** - * Ctor. - * - * @param pLocalPath - * - CIMObjectPathes without local paths will be extended by this - * value - */ - public XMLDefaultHandlerImpl(CIMObjectPath pLocalPath) { - this(pLocalPath, false); - } - - /** - * Ctor. - */ - public XMLDefaultHandlerImpl() { - this((CIMObjectPath) null, false); - } - - /** - * @param uri - * @param localName - */ - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) - throws SAXException { - this.iStrBuf = null; - String nodeNameEnum = NodeFactory.getEnum(qName); - if (nodeNameEnum == null) { - LogAndTraceBroker.getBroker() - .trace( - Level.FINEST, - "Ignoring unrecognized starting CIM-XML element found during parsing: " - + qName); - return; - } - - Node parentNode = getPeekNode(); - if (parentNode == null) { - if (!this.iAnyRoot && nodeNameEnum != NodeConstIf.CIM) throw new SAXException( - "First node of CIM-XML document must be CIM! " + nodeNameEnum + " is invalid!"); - } - if (parentNode != null) parentNode.testChild(nodeNameEnum); - // let's look for a Node instance in the pool - Node node = this.iNodePool.getNode(nodeNameEnum); - // create an instance if pool didn't give us one - if (node == null) { - node = NodeFactory.getNodeInstance(nodeNameEnum); - } - if (parentNode != null) { - if (parentNode instanceof NonVolatileIf) ((NonVolatileIf) parentNode).addChild(node); - } else { - this.iRootNode = node; - } - this.iNodeStack.push(node); - node.init(attributes, this.iSession); - } - - @Override - public void characters(char ch[], int start, int length) { - String str = new String(ch, start, length); - // System.out.println("str("+str.length()+")="+str); - if (this.iStrBuf == null) { - this.iStrBuf = new StringBuffer(str); - } else { - this.iStrBuf.append(str); - } - } - - /** - * @param uri - * @param localName - */ - @Override - public void endElement(String uri, String localName, String qName) throws SAXException { - String nodeNameEnum = NodeFactory.getEnum(qName); - if (nodeNameEnum == null) { - LogAndTraceBroker.getBroker().trace(Level.FINEST, - "Ignoring unrecognized ending CIM-XML element found during parsing: " + qName); - return; - } - Node peekNode = this.iNodeStack.pop(); - try { - // pass character data - if (this.iStrBuf != null) { - peekNode.parseData(this.iStrBuf.toString()); - this.iStrBuf = null; - } - // completeness check - peekNode.testCompletness(); - - // call parent's childParsed() - Node parentNode = this.iNodeStack.peek(); - if (parentNode != null) { - parentNode.childParsed(peekNode); - } - } finally { - peekNode.setCompleted(); - // if peekNode is reusable place it into the NodePool - if (!(peekNode instanceof NonVolatileIf)) { - this.iNodePool.addNode(peekNode); - } - } - } - - @Override - public void endDocument() { - String msg = "hits : " + getNodePoolHits() + "\nmisses : " + getNodePoolMisses(); - LogAndTraceBroker.getBroker().trace(Level.FINE, msg); - } - - /** - * getCIMNode - * - * @return CIMNode, the root Element of the parsed CIM-XML document - */ - public CIMNode getCIMNode() { - return this.iRootNode instanceof CIMNode ? (CIMNode) this.iRootNode : null; - } - - /** - * getRootNode - * - * @return Node, the root element of the parsed CIM-XML stream - */ - public Node getRootNode() { - return this.iRootNode; - } - - /** - * getNodePoolHits - * - * @return int - */ - public int getNodePoolHits() { - return this.iNodePool.getHitCnt(); - } - - /** - * getNodePoolMisses - * - * @return int - */ - public int getNodePoolMisses() { - return this.iNodePool.getMissCnt(); - } - - private Node getPeekNode() { - return this.iNodeStack.peek(); - } -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2713 2013-11-22 blaschke-oss Enforce loose validation of CIM-XML documents + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import java.util.logging.Level; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node.CIMNode; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node.Node; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node.NonVolatileIf; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +/** + * Class XMLDefaultHandlerImpl is DefaultHandler implementation which is used + * for SAX and PULL style XML parsing. + */ +public class XMLDefaultHandlerImpl extends DefaultHandler { + private Node iRootNode; + + private NodeStack iNodeStack = new NodeStack(); + + private NodePool iNodePool = new NodePool(); + + private StringBuffer iStrBuf; + + private SAXSession iSession; + + private boolean iAnyRoot; + + /** + * NodeStack + */ + static class NodeStack { + private ArrayList iAL = new ArrayList(); + + /** + * push + * + * @param pNode + */ + public void push(Node pNode) { + this.iAL.add(pNode); + } + + /** + * pop + * + * @return Node + */ + public Node pop() { + if (this.iAL.size() == 0) return null; + return this.iAL.remove(this.iAL.size() - 1); + } + + /** + * peek + * + * @return Node + */ + public Node peek() { + if (this.iAL.size() == 0) return null; + return this.iAL.get(this.iAL.size() - 1); + } + } + + /** + * Ctor. + * + * @param pSession + * - stores common variables for the whole parsing session + * @param pAnyRoot + * - if true any CIM-XML element can be the root element of the + * XML stream + */ + public XMLDefaultHandlerImpl(SAXSession pSession, boolean pAnyRoot) { + this.iSession = pSession; + this.iAnyRoot = pAnyRoot; + } + + /** + * Ctor. + * + * @param pLocalPath + * - CIMObjectPathes without local paths will be extended by this + * value + * @param pAnyRoot + * - if true any CIM-XML element can be the root element of the + * XML stream + */ + public XMLDefaultHandlerImpl(CIMObjectPath pLocalPath, boolean pAnyRoot) { + this(new SAXSession(pLocalPath), pAnyRoot); + } + + /** + * Ctor. + * + * @param pLocalPath + * - CIMObjectPathes without local paths will be extended by this + * value + */ + public XMLDefaultHandlerImpl(CIMObjectPath pLocalPath) { + this(pLocalPath, false); + } + + /** + * Ctor. + */ + public XMLDefaultHandlerImpl() { + this((CIMObjectPath) null, false); + } + + /** + * @param uri + * @param localName + */ + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + this.iStrBuf = null; + String nodeNameEnum = NodeFactory.getEnum(qName); + if (nodeNameEnum == null) { + LogAndTraceBroker + .getBroker() + .trace(Level.FINEST, "Ignoring unrecognized starting CIM-XML element found during parsing: " + qName); + return; + } + + Node parentNode = getPeekNode(); + if (parentNode == null) { + if (!this.iAnyRoot && nodeNameEnum != NodeConstIf.CIM) throw new SAXException( + "First node of CIM-XML document must be CIM! " + nodeNameEnum + " is invalid!" + ); + } + if (parentNode != null) parentNode.testChild(nodeNameEnum); + // let's look for a Node instance in the pool + Node node = this.iNodePool.getNode(nodeNameEnum); + // create an instance if pool didn't give us one + if (node == null) { + node = NodeFactory.getNodeInstance(nodeNameEnum); + } + if (parentNode != null) { + if (parentNode instanceof NonVolatileIf) ((NonVolatileIf) parentNode).addChild(node); + } else { + this.iRootNode = node; + } + this.iNodeStack.push(node); + node.init(attributes, this.iSession); + } + + @Override + public void characters(char ch[], int start, int length) { + String str = new String(ch, start, length); + // System.out.println("str("+str.length()+")="+str); + if (this.iStrBuf == null) { + this.iStrBuf = new StringBuffer(str); + } else { + this.iStrBuf.append(str); + } + } + + /** + * @param uri + * @param localName + */ + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + String nodeNameEnum = NodeFactory.getEnum(qName); + if (nodeNameEnum == null) { + LogAndTraceBroker + .getBroker() + .trace(Level.FINEST, "Ignoring unrecognized ending CIM-XML element found during parsing: " + qName); + return; + } + Node peekNode = this.iNodeStack.pop(); + try { + // pass character data + if (this.iStrBuf != null) { + peekNode.parseData(this.iStrBuf.toString()); + this.iStrBuf = null; + } + // completeness check + peekNode.testCompletness(); + + // call parent's childParsed() + Node parentNode = this.iNodeStack.peek(); + if (parentNode != null) { + parentNode.childParsed(peekNode); + } + } finally { + peekNode.setCompleted(); + // if peekNode is reusable place it into the NodePool + if (!(peekNode instanceof NonVolatileIf)) { + this.iNodePool.addNode(peekNode); + } + } + } + + @Override + public void endDocument() { + String msg = "hits : " + getNodePoolHits() + "\nmisses : " + getNodePoolMisses(); + LogAndTraceBroker.getBroker().trace(Level.FINE, msg); + } + + /** + * getCIMNode + * + * @return CIMNode, the root Element of the parsed CIM-XML document + */ + public CIMNode getCIMNode() { + return this.iRootNode instanceof CIMNode ? (CIMNode) this.iRootNode : null; + } + + /** + * getRootNode + * + * @return Node, the root element of the parsed CIM-XML stream + */ + public Node getRootNode() { + return this.iRootNode; + } + + /** + * getNodePoolHits + * + * @return int + */ + public int getNodePoolHits() { + return this.iNodePool.getHitCnt(); + } + + /** + * getNodePoolMisses + * + * @return int + */ + public int getNodePoolMisses() { + return this.iNodePool.getMissCnt(); + } + + private Node getPeekNode() { + return this.iNodeStack.peek(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractArrayValueNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractArrayValueNode.java similarity index 63% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractArrayValueNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractArrayValueNode.java index ee7af8d..a368cce 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractArrayValueNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractArrayValueNode.java @@ -1,60 +1,57 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1719991 2007-05-16 ebak FVT: regression ClassCastException in EmbObjHandler - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * Class AbstractArrayValueNode is the superclass of all VALUE.ARRAY style - * nodes. - */ -public abstract class AbstractArrayValueNode extends AbstractValueNode implements ArrayIf { - - /** - * Ctor. - * - * @param pNameEnum - */ - public AbstractArrayValueNode(String pNameEnum) { - super(pNameEnum); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1719991 2007-05-16 ebak FVT: regression ClassCastException in EmbObjHandler + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * Class AbstractArrayValueNode is the superclass of all VALUE.ARRAY style + * nodes. + */ +public abstract class AbstractArrayValueNode extends AbstractValueNode implements ArrayIf { + + /** + * Ctor. + * + * @param pNameEnum + */ + public AbstractArrayValueNode(String pNameEnum) { + super(pNameEnum); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractMessageNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractMessageNode.java similarity index 64% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractMessageNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractMessageNode.java index 62239e2..5e79fa0 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractMessageNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractMessageNode.java @@ -1,69 +1,66 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * Class AbstractMessageNode is the superclass of AbstractResponseNode and - * AbstractRequestNode classes. - */ -public abstract class AbstractMessageNode extends Node implements NonVolatileIf { - - /** - * Ctor. - * - * @param pNameEnum - */ - public AbstractMessageNode(String pNameEnum) { - super(pNameEnum); - } - - /** - * @param pChild - */ - @Override - public void childParsed(Node pChild) { - // not needed - } - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * Class AbstractMessageNode is the superclass of AbstractResponseNode and + * AbstractRequestNode classes. + */ +public abstract class AbstractMessageNode extends Node implements NonVolatileIf { + + /** + * Ctor. + * + * @param pNameEnum + */ + public AbstractMessageNode(String pNameEnum) { + super(pNameEnum); + } + + /** + * @param pChild + */ + @Override + public void childParsed(Node pChild) { + // not needed + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractMethodCallNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractMethodCallNode.java similarity index 77% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractMethodCallNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractMethodCallNode.java index 15b5533..14499e4 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractMethodCallNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractMethodCallNode.java @@ -1,209 +1,202 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1686000 2007-04-20 ebak modifyInstance() missing from WBEMClient - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - * 2682 2013-10-02 blaschke-oss (I)MethodCallNode allows no LOCAL*PATH - * 2690 2013-10-11 blaschke-oss Remove RESPONSEDESTINATION support - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; - -import org.sentrysoftware.wbem.javax.cim.CIMArgument; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.CIMElementSorter; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT IMETHODCALL (LOCALNAMESPACEPATH, IPARAMVALUE*)
      - * ATTLIST IMETHODCALL
      - *   %CIMName;
      - *   
      - * ELEMENT METHODCALL ((LOCALINSTANCEPATH | LOCALCLASSPATH), PARAMVALUE*)
      - * ATTLIST METHODCALL
      - *   %CIMName;
      - * 
      - */ -public abstract class AbstractMethodCallNode extends Node implements NonVolatileIf, ObjectPathIf { - - private String iName; - - protected CIMObjectPath iPath; - - /** - * (IPARAMVALUE | PARAMVALUE)* -> ArrayList of CIMArgument - */ - private ArrayList> iArgAL; - - /** - * Sorted array of CIMArguments - */ - private CIMArgument[] iArgA; - - /** - * Ctor. - * - * @param pNameEnum - */ - public AbstractMethodCallNode(String pNameEnum) { - super(pNameEnum); - } - - /** - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iName = getCIMName(pAttribs); - this.iPath = null; - this.iArgAL = null; - this.iArgA = null; - } - - /** - * @param pChild - */ - public void addChild(Node pChild) { - // nothing to do - } - - @Override - public void childParsed(Node pChild) { - if (pChild instanceof AbstractPathNode) { - this.iPath = ((AbstractPathNode) pChild).getCIMObjectPath(); - } else if (pChild instanceof AbstractParamValueNode) { - if (this.iArgAL == null) this.iArgAL = new ArrayList>(); - this.iArgAL.add(((AbstractParamValueNode) pChild).getCIMArgument()); - } - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - protected abstract void testSpecChild(String pNodeNameEnum) throws SAXException; - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - testSpecChild(pNodeNameEnum); - } - - /** - * getName - * - * @return String, name of the called method - */ - public String getName() { - return this.iName; - } - - public CIMObjectPath getCIMObjectPath() { - return this.iPath; - } - - private static final CIMArgument[] EMPTY_ARG_A = new CIMArgument[0]; - - /** - * getCIMArguments - * - * @return CIMArgument[] - */ - public CIMArgument[] getCIMArguments() { - if (this.iArgA != null) return this.iArgA; - this.iArgA = this.iArgAL == null ? null : (CIMArgument[]) this.iArgAL.toArray(EMPTY_ARG_A); - return (CIMArgument[]) CIMElementSorter.sort(this.iArgA); - } - - /** - * getArgumentCount - * - * @return int - */ - public int getArgumentCount() { - getCIMArguments(); - return this.iArgA == null ? 0 : this.iArgA.length; - } - - /** - * getArgument - * - * @param pName - * @return CIMArgument - */ - public CIMArgument getArgument(String pName) { - getCIMArguments(); - return (CIMArgument) CIMElementSorter.find(this.iArgA, pName); - } - - /** - * getArgument - * - * @param pIdx - * @return CIMArgument - */ - public CIMArgument getArgument(int pIdx) { - getCIMArguments(); - return this.iArgA == null ? null : this.iArgA[pIdx]; - } - - @Override - public String toString() { - StringBuffer buf = new StringBuffer("Name: " + getName() + "\nPath: " + getCIMObjectPath() - + "\nParamValues:\n"); - for (int i = 0; i < getArgumentCount(); i++) { - buf.append(" " + getArgument(i) + "\n"); - } - return buf.toString(); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1686000 2007-04-20 ebak modifyInstance() missing from WBEMClient + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + * 2682 2013-10-02 blaschke-oss (I)MethodCallNode allows no LOCAL*PATH + * 2690 2013-10-11 blaschke-oss Remove RESPONSEDESTINATION support + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import org.metricshub.wbem.javax.cim.CIMArgument; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMElementSorter; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT IMETHODCALL (LOCALNAMESPACEPATH, IPARAMVALUE*)
      + * ATTLIST IMETHODCALL
      + *   %CIMName;
      + *
      + * ELEMENT METHODCALL ((LOCALINSTANCEPATH | LOCALCLASSPATH), PARAMVALUE*)
      + * ATTLIST METHODCALL
      + *   %CIMName;
      + * 
      + */ +public abstract class AbstractMethodCallNode extends Node implements NonVolatileIf, ObjectPathIf { + private String iName; + + protected CIMObjectPath iPath; + + /** + * (IPARAMVALUE | PARAMVALUE)* -> ArrayList of CIMArgument + */ + private ArrayList> iArgAL; + + /** + * Sorted array of CIMArguments + */ + private CIMArgument[] iArgA; + + /** + * Ctor. + * + * @param pNameEnum + */ + public AbstractMethodCallNode(String pNameEnum) { + super(pNameEnum); + } + + /** + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iName = getCIMName(pAttribs); + this.iPath = null; + this.iArgAL = null; + this.iArgA = null; + } + + /** + * @param pChild + */ + public void addChild(Node pChild) { + // nothing to do + } + + @Override + public void childParsed(Node pChild) { + if (pChild instanceof AbstractPathNode) { + this.iPath = ((AbstractPathNode) pChild).getCIMObjectPath(); + } else if (pChild instanceof AbstractParamValueNode) { + if (this.iArgAL == null) this.iArgAL = new ArrayList>(); + this.iArgAL.add(((AbstractParamValueNode) pChild).getCIMArgument()); + } + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + protected abstract void testSpecChild(String pNodeNameEnum) throws SAXException; + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + testSpecChild(pNodeNameEnum); + } + + /** + * getName + * + * @return String, name of the called method + */ + public String getName() { + return this.iName; + } + + public CIMObjectPath getCIMObjectPath() { + return this.iPath; + } + + private static final CIMArgument[] EMPTY_ARG_A = new CIMArgument[0]; + + /** + * getCIMArguments + * + * @return CIMArgument[] + */ + public CIMArgument[] getCIMArguments() { + if (this.iArgA != null) return this.iArgA; + this.iArgA = this.iArgAL == null ? null : (CIMArgument[]) this.iArgAL.toArray(EMPTY_ARG_A); + return (CIMArgument[]) CIMElementSorter.sort(this.iArgA); + } + + /** + * getArgumentCount + * + * @return int + */ + public int getArgumentCount() { + getCIMArguments(); + return this.iArgA == null ? 0 : this.iArgA.length; + } + + /** + * getArgument + * + * @param pName + * @return CIMArgument + */ + public CIMArgument getArgument(String pName) { + getCIMArguments(); + return (CIMArgument) CIMElementSorter.find(this.iArgA, pName); + } + + /** + * getArgument + * + * @param pIdx + * @return CIMArgument + */ + public CIMArgument getArgument(int pIdx) { + getCIMArguments(); + return this.iArgA == null ? null : this.iArgA[pIdx]; + } + + @Override + public String toString() { + StringBuffer buf = new StringBuffer("Name: " + getName() + "\nPath: " + getCIMObjectPath() + "\nParamValues:\n"); + for (int i = 0; i < getArgumentCount(); i++) { + buf.append(" " + getArgument(i) + "\n"); + } + return buf.toString(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractMultiRspNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractMultiRspNode.java similarity index 66% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractMultiRspNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractMultiRspNode.java index 2452d9f..4577636 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractMultiRspNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractMultiRspNode.java @@ -1,74 +1,71 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * Class AbstractMultiRspNode is superclass of MultiRsp style Node classes. - */ -public abstract class AbstractMultiRspNode extends AbstractResponseNode { - - /** - * Ctor. - * - * @param pNameEnum - */ - public AbstractMultiRspNode(String pNameEnum) { - super(pNameEnum); - } - - /** - * getResponseCount - * - * @return the number of retrievable responses - */ - public abstract int getResponseCount(); - - /** - * readResponse - * - * @return AbstractSimpleRspNode - */ - public abstract AbstractSimpleRspNode readResponse(); - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * Class AbstractMultiRspNode is superclass of MultiRsp style Node classes. + */ +public abstract class AbstractMultiRspNode extends AbstractResponseNode { + + /** + * Ctor. + * + * @param pNameEnum + */ + public AbstractMultiRspNode(String pNameEnum) { + super(pNameEnum); + } + + /** + * getResponseCount + * + * @return the number of retrievable responses + */ + public abstract int getResponseCount(); + + /** + * readResponse + * + * @return AbstractSimpleRspNode + */ + public abstract AbstractSimpleRspNode readResponse(); +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractObjectNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractObjectNode.java similarity index 61% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractObjectNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractObjectNode.java index b0bdda3..88829f8 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractObjectNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractObjectNode.java @@ -1,64 +1,60 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1660756 2007-02-22 ebak Embedded object support - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * Class AbstractObjectNode is the superclass of ClassNode and InstanceNode - * classes. - */ -public abstract class AbstractObjectNode extends Node implements ValueIf { - - protected CIMObjectPath iLocalPath; - - /** - * Ctor. - * - * @param pNameEnum - */ - public AbstractObjectNode(String pNameEnum) { - super(pNameEnum); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1660756 2007-02-22 ebak Embedded object support + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * Class AbstractObjectNode is the superclass of ClassNode and InstanceNode + * classes. + */ +public abstract class AbstractObjectNode extends Node implements ValueIf { + protected CIMObjectPath iLocalPath; + + /** + * Ctor. + * + * @param pNameEnum + */ + public AbstractObjectNode(String pNameEnum) { + super(pNameEnum); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractObjectPathNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractObjectPathNode.java similarity index 60% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractObjectPathNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractObjectPathNode.java index 8c2d950..31b1785 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractObjectPathNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractObjectPathNode.java @@ -1,59 +1,56 @@ -/** - * (C) Copyright IBM Corp. 2006, 2009 - * - * THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - * - * You can obtain a current copy of the Eclipse Public License from - * http://www.opensource.org/licenses/eclipse-1.0.php - * - * @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * Class AbstractObjectPathNode is the superclass of ClassPathNode, - * InstancePathNode LocalClassPathNode and LocalInstancePathNode classes. - */ -public abstract class AbstractObjectPathNode extends AbstractPathNode { - - /** - * Ctor. - * - * @param pNameEnum - */ - public AbstractObjectPathNode(String pNameEnum) { - super(pNameEnum); - } - -} +/** + * (C) Copyright IBM Corp. 2006, 2009 + * + * THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + * + * You can obtain a current copy of the Eclipse Public License from + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * Class AbstractObjectPathNode is the superclass of ClassPathNode, + * InstancePathNode LocalClassPathNode and LocalInstancePathNode classes. + */ +public abstract class AbstractObjectPathNode extends AbstractPathNode { + + /** + * Ctor. + * + * @param pNameEnum + */ + public AbstractObjectPathNode(String pNameEnum) { + super(pNameEnum); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractParamValueNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractParamValueNode.java similarity index 64% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractParamValueNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractParamValueNode.java index 66175aa..74e96e5 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractParamValueNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractParamValueNode.java @@ -1,70 +1,67 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1686000 2007-04-19 ebak modifyInstance() missing from WBEMClient - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMArgument; - -/** - * Class AbstractParamValueNode is the superclass of IParamValueNode and - * ParamValueNode classes. - */ -public abstract class AbstractParamValueNode extends Node implements TypedIf, ValueIf { - - /** - * Ctor. - * - * @param pNameEnum - */ - public AbstractParamValueNode(String pNameEnum) { - super(pNameEnum); - } - - /** - * getCIMArgument - * - * @return CIMArgument - */ - public abstract CIMArgument getCIMArgument(); - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1686000 2007-04-19 ebak modifyInstance() missing from WBEMClient + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMArgument; + +/** + * Class AbstractParamValueNode is the superclass of IParamValueNode and + * ParamValueNode classes. + */ +public abstract class AbstractParamValueNode extends Node implements TypedIf, ValueIf { + + /** + * Ctor. + * + * @param pNameEnum + */ + public AbstractParamValueNode(String pNameEnum) { + super(pNameEnum); + } + + /** + * getCIMArgument + * + * @return CIMArgument + */ + public abstract CIMArgument getCIMArgument(); +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractParameterNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractParameterNode.java similarity index 69% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractParameterNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractParameterNode.java index 1c690a2..a498461 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractParameterNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractParameterNode.java @@ -1,126 +1,125 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1820763 2007-10-29 ebak Supporting the EmbeddedInstance qualifier - * 1848607 2007-12-11 ebak Strict EmbeddedObject types - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMParameter; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * Class AbstractParameterNode is the superclass of ParameterArrayNode, - * ParameterNode, ParameterRefArrayNode and ParameterReferenceNode classes. - */ -public abstract class AbstractParameterNode extends Node implements TypedIf { - - private String iName; - - protected QualifiedNodeHandler iQualiHandler; - - protected SAXSession iSession; - - /** - * Ctor. - * - * @param pNameEnum - */ - public AbstractParameterNode(String pNameEnum) { - super(pNameEnum); - } - - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iSession = pSession; - this.iQualiHandler = QualifiedNodeHandler.init(this.iQualiHandler); - this.iName = getCIMName(pAttribs); - specificInit(pAttribs); - } - - protected abstract void specificInit(Attributes pAttribs) throws SAXException; - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum != QUALIFIER) throw new SAXException(getNodeName() + " cannot have " - + pNodeNameEnum + " child node!"); - } - - @Override - public void childParsed(Node pChild) { - this.iQualiHandler.addQualifierNode(pChild); - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - /** - * getCIMParameter - * - * @return CIMParameter - */ - public CIMParameter getCIMParameter() { - /* - * CIMParameter(String name, CIMDataType type, CIMQualifier[] - * qualifiers) - * - * Not dealing with embedded object is faster. Here we don't have to do - * anything with embedded object qualifier, since parameter doesn't have - * value. - * - * Strict embObj type parsing requires different behavior. - */ - return new CIMParameter(this.iName, getType(), this.iQualiHandler - .getQualis(!this.iSession.strictEmbObjParsing())); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1820763 2007-10-29 ebak Supporting the EmbeddedInstance qualifier + * 1848607 2007-12-11 ebak Strict EmbeddedObject types + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMParameter; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * Class AbstractParameterNode is the superclass of ParameterArrayNode, + * ParameterNode, ParameterRefArrayNode and ParameterReferenceNode classes. + */ +public abstract class AbstractParameterNode extends Node implements TypedIf { + private String iName; + + protected QualifiedNodeHandler iQualiHandler; + + protected SAXSession iSession; + + /** + * Ctor. + * + * @param pNameEnum + */ + public AbstractParameterNode(String pNameEnum) { + super(pNameEnum); + } + + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iSession = pSession; + this.iQualiHandler = QualifiedNodeHandler.init(this.iQualiHandler); + this.iName = getCIMName(pAttribs); + specificInit(pAttribs); + } + + protected abstract void specificInit(Attributes pAttribs) throws SAXException; + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum != QUALIFIER) throw new SAXException( + getNodeName() + " cannot have " + pNodeNameEnum + " child node!" + ); + } + + @Override + public void childParsed(Node pChild) { + this.iQualiHandler.addQualifierNode(pChild); + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + /** + * getCIMParameter + * + * @return CIMParameter + */ + public CIMParameter getCIMParameter() { + /* + * CIMParameter(String name, CIMDataType type, CIMQualifier[] + * qualifiers) + * + * Not dealing with embedded object is faster. Here we don't have to do + * anything with embedded object qualifier, since parameter doesn't have + * value. + * + * Strict embObj type parsing requires different behavior. + */ + return new CIMParameter( + this.iName, + getType(), + this.iQualiHandler.getQualis(!this.iSession.strictEmbObjParsing()) + ); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractPathNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractPathNode.java similarity index 64% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractPathNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractPathNode.java index c57bedd..67979e0 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractPathNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractPathNode.java @@ -1,67 +1,64 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * Class AbstractPathNode is the superclass of AbstractObjectPathNode, - * ClassNameNode, InstanceNameNode and ObjectPathNode classes. - */ -public abstract class AbstractPathNode extends Node implements ObjectPathIf, ValueIf { - - /** - * Ctor. - * - * @param pNameEnum - */ - public AbstractPathNode(String pNameEnum) { - super(pNameEnum); - } - - /** - * @see ValueIf#getValue() - * @return CIMObjectPath - */ - public Object getValue() { - return getCIMObjectPath(); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * Class AbstractPathNode is the superclass of AbstractObjectPathNode, + * ClassNameNode, InstanceNameNode and ObjectPathNode classes. + */ +public abstract class AbstractPathNode extends Node implements ObjectPathIf, ValueIf { + + /** + * Ctor. + * + * @param pNameEnum + */ + public AbstractPathNode(String pNameEnum) { + super(pNameEnum); + } + + /** + * @see ValueIf#getValue() + * @return CIMObjectPath + */ + public Object getValue() { + return getCIMObjectPath(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractPropertyNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractPropertyNode.java similarity index 68% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractPropertyNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractPropertyNode.java index 9e4e10c..3aab3e1 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractPropertyNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractPropertyNode.java @@ -1,164 +1,173 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus - * 1714878 2007-05-08 ebak Empty string property values are parsed as null - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMClassProperty; -import org.sentrysoftware.wbem.javax.cim.CIMProperty; -import org.sentrysoftware.wbem.javax.cim.CIMQualifier; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * AbstractPropertyNode is superclass of PropertyArrayNode, PropertyNode and - * PropertyReferenceNode classes. - */ -public abstract class AbstractPropertyNode extends Node implements TypedIf, ValueIf { - - // common attributes - private String iName; - - private String iClassOrigin; - - private boolean iPropagated; - - protected QualifiedNodeHandler iQualiHandler; - - /** - * Ctor. - * - * @param pNameEnum - */ - public AbstractPropertyNode(String pNameEnum) { - super(pNameEnum); - } - - /** - * hasValue - * - * @return true if it has a value child node - */ - protected abstract boolean hasValueNode(); - - protected abstract void childValueNodeParsed(Node pChild) throws SAXException; - - protected abstract void specificInit(Attributes pAttribs, SAXSession pSession) - throws SAXException; - - protected abstract String getChildValueNodeNameEnum(); - - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iQualiHandler = QualifiedNodeHandler.init(this.iQualiHandler); - this.iName = getCIMName(pAttribs); - this.iClassOrigin = getClassOrigin(pAttribs); - this.iPropagated = getPropagated(pAttribs); - specificInit(pAttribs, pSession); - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - String valueNodeNameEnum = getChildValueNodeNameEnum(); - if (pNodeNameEnum == valueNodeNameEnum) { - if (hasValueNode()) throw new SAXException(getNodeName() + " node can have only one " - + valueNodeNameEnum + " child node!"); - } else if (pNodeNameEnum != QUALIFIER) throw new SAXException(getNodeName() - + " node cannot have " + pNodeNameEnum + " child node!"); - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void childParsed(Node pChild) throws SAXException { - if (!this.iQualiHandler.addQualifierNode(pChild)) { - childValueNodeParsed(pChild); - } - } - - protected CIMQualifier[] getQualis() { - // not dealing with embedded object qualifier is faster - return this.iQualiHandler.getQualis(true); - } - - /** - * getCIMProperty - * - * @return CIMProperty - */ - public CIMProperty getCIMProperty() { - /* - * CIMProperty( String name, CIMDataType type, Object value, boolean - * key, boolean propagated, String originClass ) - */ - return new CIMProperty(this.iName, getType(), getValue(), this.iQualiHandler - .isKeyed(), this.iPropagated, this.iClassOrigin); - } - - /** - * getCIMClassProperty - * - * @return CIMClassProperty - */ - public CIMClassProperty getCIMClassProperty() { - /* - * CIMClassProperty( String pName, CIMDataType pType, Object pValue, - * CIMQualifier[] pQualifiers, boolean pKey, boolean propagated, String - * originClass) ); - */ - return new CIMClassProperty(this.iName, getType(), getValue(), getQualis(), - this.iQualiHandler.isKeyed(), this.iPropagated, this.iClassOrigin); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus + * 1714878 2007-05-08 ebak Empty string property values are parsed as null + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMClassProperty; +import org.metricshub.wbem.javax.cim.CIMProperty; +import org.metricshub.wbem.javax.cim.CIMQualifier; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * AbstractPropertyNode is superclass of PropertyArrayNode, PropertyNode and + * PropertyReferenceNode classes. + */ +public abstract class AbstractPropertyNode extends Node implements TypedIf, ValueIf { + // common attributes + private String iName; + + private String iClassOrigin; + + private boolean iPropagated; + + protected QualifiedNodeHandler iQualiHandler; + + /** + * Ctor. + * + * @param pNameEnum + */ + public AbstractPropertyNode(String pNameEnum) { + super(pNameEnum); + } + + /** + * hasValue + * + * @return true if it has a value child node + */ + protected abstract boolean hasValueNode(); + + protected abstract void childValueNodeParsed(Node pChild) throws SAXException; + + protected abstract void specificInit(Attributes pAttribs, SAXSession pSession) throws SAXException; + + protected abstract String getChildValueNodeNameEnum(); + + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iQualiHandler = QualifiedNodeHandler.init(this.iQualiHandler); + this.iName = getCIMName(pAttribs); + this.iClassOrigin = getClassOrigin(pAttribs); + this.iPropagated = getPropagated(pAttribs); + specificInit(pAttribs, pSession); + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + String valueNodeNameEnum = getChildValueNodeNameEnum(); + if (pNodeNameEnum == valueNodeNameEnum) { + if (hasValueNode()) throw new SAXException( + getNodeName() + " node can have only one " + valueNodeNameEnum + " child node!" + ); + } else if (pNodeNameEnum != QUALIFIER) throw new SAXException( + getNodeName() + " node cannot have " + pNodeNameEnum + " child node!" + ); + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void childParsed(Node pChild) throws SAXException { + if (!this.iQualiHandler.addQualifierNode(pChild)) { + childValueNodeParsed(pChild); + } + } + + protected CIMQualifier[] getQualis() { + // not dealing with embedded object qualifier is faster + return this.iQualiHandler.getQualis(true); + } + + /** + * getCIMProperty + * + * @return CIMProperty + */ + public CIMProperty getCIMProperty() { + /* + * CIMProperty( String name, CIMDataType type, Object value, boolean + * key, boolean propagated, String originClass ) + */ + return new CIMProperty( + this.iName, + getType(), + getValue(), + this.iQualiHandler.isKeyed(), + this.iPropagated, + this.iClassOrigin + ); + } + + /** + * getCIMClassProperty + * + * @return CIMClassProperty + */ + public CIMClassProperty getCIMClassProperty() { + /* + * CIMClassProperty( String pName, CIMDataType pType, Object pValue, + * CIMQualifier[] pQualifiers, boolean pKey, boolean propagated, String + * originClass) ); + */ + return new CIMClassProperty( + this.iName, + getType(), + getValue(), + getQualis(), + this.iQualiHandler.isKeyed(), + this.iPropagated, + this.iClassOrigin + ); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractResponseNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractResponseNode.java similarity index 61% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractResponseNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractResponseNode.java index 731bc70..9573537 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractResponseNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractResponseNode.java @@ -1,59 +1,56 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * Class AbstractResponseNode is superclass of AbstractMulitRspNode and - * AbstractSimpleRspNode classes. - */ -public abstract class AbstractResponseNode extends AbstractMessageNode { - - /** - * Ctor. - * - * @param pNameEnum - */ - public AbstractResponseNode(String pNameEnum) { - super(pNameEnum); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * Class AbstractResponseNode is superclass of AbstractMulitRspNode and + * AbstractSimpleRspNode classes. + */ +public abstract class AbstractResponseNode extends AbstractMessageNode { + + /** + * Ctor. + * + * @param pNameEnum + */ + public AbstractResponseNode(String pNameEnum) { + super(pNameEnum); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractScalarValueNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractScalarValueNode.java similarity index 65% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractScalarValueNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractScalarValueNode.java index 3d1b5d9..9ec5aeb 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractScalarValueNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractScalarValueNode.java @@ -1,62 +1,59 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1719991 2007-05-16 ebak FVT: regression ClassCastException in EmbObjHandler - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * Class AbstractScalarValueNode is superclass of KeyValueNode, - * ValueNamedInstanceNode, ValueNode, ValueNullNode, ValueObjectNode, - * ValueObjectWithLocalPathNode, ValueObjectWithPathNode and ValueReferenceNode - * classes. - */ -public abstract class AbstractScalarValueNode extends AbstractValueNode { - - /** - * Ctor. - * - * @param pNameEnum - */ - public AbstractScalarValueNode(String pNameEnum) { - super(pNameEnum); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1719991 2007-05-16 ebak FVT: regression ClassCastException in EmbObjHandler + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * Class AbstractScalarValueNode is superclass of KeyValueNode, + * ValueNamedInstanceNode, ValueNode, ValueNullNode, ValueObjectNode, + * ValueObjectWithLocalPathNode, ValueObjectWithPathNode and ValueReferenceNode + * classes. + */ +public abstract class AbstractScalarValueNode extends AbstractValueNode { + + /** + * Ctor. + * + * @param pNameEnum + */ + public AbstractScalarValueNode(String pNameEnum) { + super(pNameEnum); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractSimpleRspNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractSimpleRspNode.java similarity index 60% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractSimpleRspNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractSimpleRspNode.java index ed5c1ef..66d0282 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractSimpleRspNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractSimpleRspNode.java @@ -1,74 +1,69 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMArgument; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.CIMError; - -/** - * Class AbstractSimpleRspNode is the superclass of SimpleExpRspNode and - * SimpleRspNode classes. - */ -public abstract class AbstractSimpleRspNode extends AbstractResponseNode implements ErrorIf, - RetValPipeIf { - - /** - * Ctor. - * - * @param pNameEnum - */ - public AbstractSimpleRspNode(String pNameEnum) { - super(pNameEnum); - } - - public abstract CIMError getCIMError(); - - /** - * getCIMArguments - * - * @return CIMArgument[] - */ - public abstract CIMArgument[] getCIMArguments(); - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMArgument; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.CIMError; + +/** + * Class AbstractSimpleRspNode is the superclass of SimpleExpRspNode and + * SimpleRspNode classes. + */ +public abstract class AbstractSimpleRspNode extends AbstractResponseNode implements ErrorIf, RetValPipeIf { + + /** + * Ctor. + * + * @param pNameEnum + */ + public AbstractSimpleRspNode(String pNameEnum) { + super(pNameEnum); + } + + public abstract CIMError getCIMError(); + + /** + * getCIMArguments + * + * @return CIMArgument[] + */ + public abstract CIMArgument[] getCIMArguments(); +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractValueNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractValueNode.java similarity index 63% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractValueNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractValueNode.java index 4ab8be9..5ed3995 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractValueNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/AbstractValueNode.java @@ -1,60 +1,57 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1719991 2007-05-16 ebak FVT: regression ClassCastException in EmbObjHandler - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * Class AbstractValueNode is the superclass of AbstractArrayValueNode and - * AbstractScalarValueNode classes. - */ -public abstract class AbstractValueNode extends Node implements TypedIf, ValueIf { - - /** - * Ctor. - * - * @param pNameEnum - */ - public AbstractValueNode(String pNameEnum) { - super(pNameEnum); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1719991 2007-05-16 ebak FVT: regression ClassCastException in EmbObjHandler + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * Class AbstractValueNode is the superclass of AbstractArrayValueNode and + * AbstractScalarValueNode classes. + */ +public abstract class AbstractValueNode extends Node implements TypedIf, ValueIf { + + /** + * Ctor. + * + * @param pNameEnum + */ + public AbstractValueNode(String pNameEnum) { + super(pNameEnum); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ArrayIf.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ArrayIf.java similarity index 60% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ArrayIf.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ArrayIf.java index 814805f..7a6f2e3 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ArrayIf.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ArrayIf.java @@ -1,64 +1,60 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * It is implemented by the AbstractArrayValueNode class. - */ -public interface ArrayIf { - - /** - * size - * - * @return int - */ - public int size(); - - /** - * elementAt - * - * @param pIdx - * @return Object - */ - public Object elementAt(int pIdx); - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * It is implemented by the AbstractArrayValueNode class. + */ +public interface ArrayIf { + /** + * size + * + * @return int + */ + public int size(); + + /** + * elementAt + * + * @param pIdx + * @return Object + */ + public Object elementAt(int pIdx); +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/CIMNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/CIMNode.java similarity index 67% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/CIMNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/CIMNode.java index 765f441..4be78ce 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/CIMNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/CIMNode.java @@ -1,157 +1,156 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - * 2604 2013-07-01 blaschke-oss SAXException messages should contain node name - * 2708 2013-11-12 blaschke-oss CIMNode quietly ignores DECLARATION child - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT CIM (MESSAGE | DECLARATION)
      - * ATTLIST CIM
      - * 	CIMVERSION CDATA #REQUIRED
      - * DTDVERSION CDATA #REQUIRED
      - * 
      - */ -public class CIMNode extends Node implements NonVolatileIf { - - /** - * Ctor. - */ - public CIMNode() { - super(CIM); - } - - private Node iContent; - - private String iCimVersion, iDtdVersion; - - public void addChild(Node pChild) { - this.iContent = pChild; - } - - /** - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iCimVersion = pAttribs.getValue("CIMVERSION"); - if (this.iCimVersion == null) { throw new SAXException( - "CIMVERSION attribute is mandatory for " + getNodeName() + " node!"); } - this.iDtdVersion = pAttribs.getValue("DTDVERSION"); - if (this.iDtdVersion == null) { throw new SAXException( - "DTDVERSION attribute is mandatory for " + getNodeName() + " node!"); } - this.iContent = null; - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - return; - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (this.iContent != null) { - String msg = "CIM node also has a " + this.iContent.getNodeName() + " child node!"; - throw new SAXException(msg); - } - if (pNodeNameEnum == MESSAGE) return; - String msg = (pNodeNameEnum == DECLARATION) ? "DECLARATION child node not supported by CIM node!" - : pNodeNameEnum + " cannot be a child node of CIM node!"; - throw new SAXException(msg); - } - - @Override - public void testCompletness() throws SAXException { - if (this.iContent == null) throw new SAXException( - "CIM node must have a MESSAGE or a DECLARATION child!"); - } - - /** - * @param pChild - */ - @Override - public void childParsed(Node pChild) { - // nothing to do here - } - - /** - * getCimVersion - * - * @return String - */ - public String getCimVersion() { - return this.iCimVersion; - } - - /** - * getDtdVersion - * - * @return String - */ - public String getDtdVersion() { - return this.iDtdVersion; - } - - /** - * getMessageNode - * - * @return MessageNode or null - */ - public MessageNode getMessageNode() { - return (this.iContent instanceof MessageNode) ? (MessageNode) this.iContent : null; - } - - // not implemented yet - // public DeclarationNode getDeclarationNode() {} - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + * 2604 2013-07-01 blaschke-oss SAXException messages should contain node name + * 2708 2013-11-12 blaschke-oss CIMNode quietly ignores DECLARATION child + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT CIM (MESSAGE | DECLARATION)
      + * ATTLIST CIM
      + * 	CIMVERSION CDATA #REQUIRED
      + * DTDVERSION CDATA #REQUIRED
      + * 
      + */ +public class CIMNode extends Node implements NonVolatileIf { + + /** + * Ctor. + */ + public CIMNode() { + super(CIM); + } + + private Node iContent; + + private String iCimVersion, iDtdVersion; + + public void addChild(Node pChild) { + this.iContent = pChild; + } + + /** + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iCimVersion = pAttribs.getValue("CIMVERSION"); + if (this.iCimVersion == null) { + throw new SAXException("CIMVERSION attribute is mandatory for " + getNodeName() + " node!"); + } + this.iDtdVersion = pAttribs.getValue("DTDVERSION"); + if (this.iDtdVersion == null) { + throw new SAXException("DTDVERSION attribute is mandatory for " + getNodeName() + " node!"); + } + this.iContent = null; + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + return; + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (this.iContent != null) { + String msg = "CIM node also has a " + this.iContent.getNodeName() + " child node!"; + throw new SAXException(msg); + } + if (pNodeNameEnum == MESSAGE) return; + String msg = (pNodeNameEnum == DECLARATION) + ? "DECLARATION child node not supported by CIM node!" + : pNodeNameEnum + " cannot be a child node of CIM node!"; + throw new SAXException(msg); + } + + @Override + public void testCompletness() throws SAXException { + if (this.iContent == null) throw new SAXException("CIM node must have a MESSAGE or a DECLARATION child!"); + } + + /** + * @param pChild + */ + @Override + public void childParsed(Node pChild) { + // nothing to do here + } + + /** + * getCimVersion + * + * @return String + */ + public String getCimVersion() { + return this.iCimVersion; + } + + /** + * getDtdVersion + * + * @return String + */ + public String getDtdVersion() { + return this.iDtdVersion; + } + + /** + * getMessageNode + * + * @return MessageNode or null + */ + public MessageNode getMessageNode() { + return (this.iContent instanceof MessageNode) ? (MessageNode) this.iContent : null; + } + // not implemented yet + // public DeclarationNode getDeclarationNode() {} + +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ClassNameNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ClassNameNode.java similarity index 67% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ClassNameNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ClassNameNode.java index f454266..6913c93 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ClassNameNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ClassNameNode.java @@ -1,122 +1,117 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.LocalPathBuilder; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT CLASSNAME EMPTY
      - *   ATTLIST CLASSNAME
      - *   %CIMName;
      - * 
      - */ -public class ClassNameNode extends AbstractPathNode { - - private String iClassName; - - private CIMObjectPath iLocalPath; - - /** - * Ctor. - */ - public ClassNameNode() { - super(CLASSNAME); - } - - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iLocalPath = pSession.getDefLocalPath(); - this.iClassName = getCIMName(pAttribs); - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - /** - * @param pNodeNameEnum - */ - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - throw new SAXException("CLASSNAME node cannot have any child node!"); - } - - @Override - public void testCompletness() { - // no child nodes to test - } - - /** - * @param pChild - */ - @Override - public void childParsed(Node pChild) { - // nothing to do - } - - /** - * getClassName - * - * @return String - */ - public String getClassName() { - return this.iClassName; - } - - public CIMObjectPath getCIMObjectPath() { - return LocalPathBuilder.build(this.iLocalPath, this.iClassName, null); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.LocalPathBuilder; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT CLASSNAME EMPTY
      + *   ATTLIST CLASSNAME
      + *   %CIMName;
      + * 
      + */ +public class ClassNameNode extends AbstractPathNode { + private String iClassName; + + private CIMObjectPath iLocalPath; + + /** + * Ctor. + */ + public ClassNameNode() { + super(CLASSNAME); + } + + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iLocalPath = pSession.getDefLocalPath(); + this.iClassName = getCIMName(pAttribs); + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + /** + * @param pNodeNameEnum + */ + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + throw new SAXException("CLASSNAME node cannot have any child node!"); + } + + @Override + public void testCompletness() { + // no child nodes to test + } + + /** + * @param pChild + */ + @Override + public void childParsed(Node pChild) { + // nothing to do + } + + /** + * getClassName + * + * @return String + */ + public String getClassName() { + return this.iClassName; + } + + public CIMObjectPath getCIMObjectPath() { + return LocalPathBuilder.build(this.iLocalPath, this.iClassName, null); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ClassNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ClassNode.java similarity index 66% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ClassNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ClassNode.java index 3df3285..b5c1f00 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ClassNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ClassNode.java @@ -1,184 +1,186 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 1783288 2007-09-10 ebak CIMClass.isAssociation() not working for retrieved classes. - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 3500619 2012-03-16 blaschke-oss JSR48 1.0.0: CIMClass association/key clean up - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; - -import org.sentrysoftware.wbem.javax.cim.CIMClass; -import org.sentrysoftware.wbem.javax.cim.CIMClassProperty; -import org.sentrysoftware.wbem.javax.cim.CIMMethod; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -import org.sentrysoftware.wbem.sblim.cimclient.GenericExts; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.LocalPathBuilder; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT CLASS (QUALIFIER*, (PROPERTY | PROPERTY.ARRAY | PROPERTY.REFERENCE)*, METHOD*)
      - * ATTLIST CLASS
      - * %CIMName; 
      - * %SuperClass;
      - * 
      - */ -public class ClassNode extends AbstractObjectNode { - - private String iName; - - private String iSuperClass; - - private QualifiedNodeHandler iQualiHandler; - - private ArrayList> iCIMClassPropAL; - - private boolean iKeyed; - - private ArrayList> iCIMMethodAL; - - /** - * Ctor. - */ - public ClassNode() { - super(CLASS); - } - - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iLocalPath = pSession.getDefLocalPath(); - this.iQualiHandler = QualifiedNodeHandler.init(this.iQualiHandler); - this.iCIMClassPropAL = GenericExts.initClearArrayList(this.iCIMClassPropAL); - this.iKeyed = false; - this.iCIMMethodAL = GenericExts.initClearArrayList(this.iCIMMethodAL); - this.iName = getCIMName(pAttribs); - this.iSuperClass = pAttribs.getValue("SUPERCLASS"); // not mandatory - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - private static final String[] ALLOWED_CHILDREN = { QUALIFIER, PROPERTY, PROPERTY_ARRAY, - PROPERTY_REFERENCE, METHOD }; - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - for (int i = 0; i < ALLOWED_CHILDREN.length; i++) - if (ALLOWED_CHILDREN[i] == pNodeNameEnum) return; - throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum - + " child node!"); - } - - @Override - public void childParsed(Node pChild) { - if (this.iQualiHandler.addQualifierNode(pChild)) return; - if (pChild instanceof AbstractPropertyNode) { - if (this.iCIMClassPropAL == null) this.iCIMClassPropAL = new ArrayList>(); - CIMClassProperty prop = ((AbstractPropertyNode) pChild).getCIMClassProperty(); - if (prop.isKey()) this.iKeyed = true; - this.iCIMClassPropAL.add(prop); - } else { - if (this.iCIMMethodAL == null) this.iCIMMethodAL = new ArrayList>(); - this.iCIMMethodAL.add(((MethodNode) pChild).getCIMMethod()); - } - } - - @Override - public void testCompletness() { - // all child nodes are optional - } - - /** - * getCIMClass - * - * @return CIMClass - */ - public CIMClass getCIMClass() { - /* - * ebak: this constructor can add localPath info to the class CIMClass( - * CIMObjectPath path, String superclass, CIMQualifier[] qualifiers, - * CIMClassProperty[] props, CIMMethod[] pMethods, boolean - * pIsAssociation, boolean pIsKeyed ) - */ - return new CIMClass(LocalPathBuilder.build(this.iLocalPath, this.iName, null), - this.iSuperClass, this.iQualiHandler.getQualis(), this.iCIMClassPropAL - .toArray(EMPTY_PA), this.iCIMMethodAL.toArray(EMPTY_MA), this.iQualiHandler - .isAssociation(), this.iKeyed); - } - - private static final CIMMethod[] EMPTY_MA = new CIMMethod[0]; - - private static final CIMClassProperty[] EMPTY_PA = new CIMClassProperty[0]; - - /** - * getCIMClass - * - * @param pObjPath - * @return CIMClass with the provided object path - */ - public CIMClass getCIMClass(CIMObjectPath pObjPath) { - return new CIMClass(pObjPath, this.iSuperClass, this.iQualiHandler.getQualis(), - this.iCIMClassPropAL.toArray(EMPTY_PA), this.iCIMMethodAL.toArray(EMPTY_MA), - this.iQualiHandler.isAssociation(), this.iKeyed); - } - - /** - * @see ValueIf#getValue() - * @return CIMClass - */ - public Object getValue() { - return getCIMClass(); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 1783288 2007-09-10 ebak CIMClass.isAssociation() not working for retrieved classes. + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 3500619 2012-03-16 blaschke-oss JSR48 1.0.0: CIMClass association/key clean up + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import org.metricshub.wbem.javax.cim.CIMClass; +import org.metricshub.wbem.javax.cim.CIMClassProperty; +import org.metricshub.wbem.javax.cim.CIMMethod; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.sblim.cimclient.GenericExts; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.LocalPathBuilder; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT CLASS (QUALIFIER*, (PROPERTY | PROPERTY.ARRAY | PROPERTY.REFERENCE)*, METHOD*)
      + * ATTLIST CLASS
      + * %CIMName;
      + * %SuperClass;
      + * 
      + */ +public class ClassNode extends AbstractObjectNode { + private String iName; + + private String iSuperClass; + + private QualifiedNodeHandler iQualiHandler; + + private ArrayList> iCIMClassPropAL; + + private boolean iKeyed; + + private ArrayList> iCIMMethodAL; + + /** + * Ctor. + */ + public ClassNode() { + super(CLASS); + } + + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iLocalPath = pSession.getDefLocalPath(); + this.iQualiHandler = QualifiedNodeHandler.init(this.iQualiHandler); + this.iCIMClassPropAL = GenericExts.initClearArrayList(this.iCIMClassPropAL); + this.iKeyed = false; + this.iCIMMethodAL = GenericExts.initClearArrayList(this.iCIMMethodAL); + this.iName = getCIMName(pAttribs); + this.iSuperClass = pAttribs.getValue("SUPERCLASS"); // not mandatory + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + private static final String[] ALLOWED_CHILDREN = { QUALIFIER, PROPERTY, PROPERTY_ARRAY, PROPERTY_REFERENCE, METHOD }; + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + for (int i = 0; i < ALLOWED_CHILDREN.length; i++) if (ALLOWED_CHILDREN[i] == pNodeNameEnum) return; + throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!"); + } + + @Override + public void childParsed(Node pChild) { + if (this.iQualiHandler.addQualifierNode(pChild)) return; + if (pChild instanceof AbstractPropertyNode) { + if (this.iCIMClassPropAL == null) this.iCIMClassPropAL = new ArrayList>(); + CIMClassProperty prop = ((AbstractPropertyNode) pChild).getCIMClassProperty(); + if (prop.isKey()) this.iKeyed = true; + this.iCIMClassPropAL.add(prop); + } else { + if (this.iCIMMethodAL == null) this.iCIMMethodAL = new ArrayList>(); + this.iCIMMethodAL.add(((MethodNode) pChild).getCIMMethod()); + } + } + + @Override + public void testCompletness() { + // all child nodes are optional + } + + /** + * getCIMClass + * + * @return CIMClass + */ + public CIMClass getCIMClass() { + /* + * ebak: this constructor can add localPath info to the class CIMClass( + * CIMObjectPath path, String superclass, CIMQualifier[] qualifiers, + * CIMClassProperty[] props, CIMMethod[] pMethods, boolean + * pIsAssociation, boolean pIsKeyed ) + */ + return new CIMClass( + LocalPathBuilder.build(this.iLocalPath, this.iName, null), + this.iSuperClass, + this.iQualiHandler.getQualis(), + this.iCIMClassPropAL.toArray(EMPTY_PA), + this.iCIMMethodAL.toArray(EMPTY_MA), + this.iQualiHandler.isAssociation(), + this.iKeyed + ); + } + + private static final CIMMethod[] EMPTY_MA = new CIMMethod[0]; + + private static final CIMClassProperty[] EMPTY_PA = new CIMClassProperty[0]; + + /** + * getCIMClass + * + * @param pObjPath + * @return CIMClass with the provided object path + */ + public CIMClass getCIMClass(CIMObjectPath pObjPath) { + return new CIMClass( + pObjPath, + this.iSuperClass, + this.iQualiHandler.getQualis(), + this.iCIMClassPropAL.toArray(EMPTY_PA), + this.iCIMMethodAL.toArray(EMPTY_MA), + this.iQualiHandler.isAssociation(), + this.iKeyed + ); + } + + /** + * @see ValueIf#getValue() + * @return CIMClass + */ + public Object getValue() { + return getCIMClass(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ClassPathNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ClassPathNode.java similarity index 61% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ClassPathNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ClassPathNode.java index 616824b..3c4accf 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ClassPathNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ClassPathNode.java @@ -1,140 +1,141 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 1742873 2007-06-25 ebak IPv6 ready cim-client - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - * 3602604 2013-01-29 blaschke-oss Clean up SAXException messages - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.XMLHostStr; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT CLASSPATH (NAMESPACEPATH, CLASSNAME) - */ -public class ClassPathNode extends AbstractObjectPathNode { - - // child nodes: - private boolean iHasNameSpacePath, iHasClassName; - - private String iLocalNameSpacePathStr; - - private XMLHostStr iHostStr; - - private String iClassNameStr; - - /** - * Ctor. - */ - public ClassPathNode() { - super(CLASSPATH); - } - - /** - * @param pAttribs - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - // reset - this.iHasNameSpacePath = this.iHasClassName = false; - this.iLocalNameSpacePathStr = this.iClassNameStr = null; - this.iHostStr = new XMLHostStr(); - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum == NAMESPACEPATH) { - if (this.iHasNameSpacePath) throw new SAXException( - "CLASSPATH node already has a NAMESPACEPATH child node!"); - } else if (pNodeNameEnum == CLASSNAME) { - if (this.iHasClassName) throw new SAXException( - "CLASSPATH node already has a CLASSNAME child node!"); - } else throw new SAXException("CLASSPATH node cannot have " + pNodeNameEnum - + " child node!" + " It can have NAMESPACEPATH and CLASSNAME child nodes only!"); - } - - @Override - public void childParsed(Node pChild) { - if (pChild instanceof NameSpacePathNode) { - NameSpacePathNode nsPathNode = (NameSpacePathNode) pChild; - this.iLocalNameSpacePathStr = nsPathNode.getLocalNameSpacePath(); - this.iHostStr.set(nsPathNode.getHostStr()); - this.iHasNameSpacePath = true; - } else { - this.iClassNameStr = ((ClassNameNode) pChild).getClassName(); - this.iHasClassName = true; - } - } - - @Override - public void testCompletness() throws SAXException { - if (!this.iHasNameSpacePath) throw new SAXException( - "NAMESPACEPATH child node is mandatory for CLASSPATH node!"); - if (!this.iHasClassName) throw new SAXException( - "CLASSNAME child node is mandatory for CLASSPATH node!"); - } - - public CIMObjectPath getCIMObjectPath() { - /* - * CIMObjectPath( String scheme, String host, String port, String - * namespace, String objectName, CIMProperty[] keys ) - */ - return new CIMObjectPath(this.iHostStr.getProtocol(), this.iHostStr.getHost(), - this.iHostStr.getPort(), this.iLocalNameSpacePathStr, this.iClassNameStr, null); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 1742873 2007-06-25 ebak IPv6 ready cim-client + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + * 3602604 2013-01-29 blaschke-oss Clean up SAXException messages + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.metricshub.wbem.sblim.cimclient.internal.util.XMLHostStr; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT CLASSPATH (NAMESPACEPATH, CLASSNAME) + */ +public class ClassPathNode extends AbstractObjectPathNode { + // child nodes: + private boolean iHasNameSpacePath, iHasClassName; + + private String iLocalNameSpacePathStr; + + private XMLHostStr iHostStr; + + private String iClassNameStr; + + /** + * Ctor. + */ + public ClassPathNode() { + super(CLASSPATH); + } + + /** + * @param pAttribs + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + // reset + this.iHasNameSpacePath = this.iHasClassName = false; + this.iLocalNameSpacePathStr = this.iClassNameStr = null; + this.iHostStr = new XMLHostStr(); + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum == NAMESPACEPATH) { + if (this.iHasNameSpacePath) throw new SAXException("CLASSPATH node already has a NAMESPACEPATH child node!"); + } else if (pNodeNameEnum == CLASSNAME) { + if (this.iHasClassName) throw new SAXException("CLASSPATH node already has a CLASSNAME child node!"); + } else throw new SAXException( + "CLASSPATH node cannot have " + + pNodeNameEnum + + " child node!" + + " It can have NAMESPACEPATH and CLASSNAME child nodes only!" + ); + } + + @Override + public void childParsed(Node pChild) { + if (pChild instanceof NameSpacePathNode) { + NameSpacePathNode nsPathNode = (NameSpacePathNode) pChild; + this.iLocalNameSpacePathStr = nsPathNode.getLocalNameSpacePath(); + this.iHostStr.set(nsPathNode.getHostStr()); + this.iHasNameSpacePath = true; + } else { + this.iClassNameStr = ((ClassNameNode) pChild).getClassName(); + this.iHasClassName = true; + } + } + + @Override + public void testCompletness() throws SAXException { + if (!this.iHasNameSpacePath) throw new SAXException("NAMESPACEPATH child node is mandatory for CLASSPATH node!"); + if (!this.iHasClassName) throw new SAXException("CLASSNAME child node is mandatory for CLASSPATH node!"); + } + + public CIMObjectPath getCIMObjectPath() { + /* + * CIMObjectPath( String scheme, String host, String port, String + * namespace, String objectName, CIMProperty[] keys ) + */ + return new CIMObjectPath( + this.iHostStr.getProtocol(), + this.iHostStr.getHost(), + this.iHostStr.getPort(), + this.iLocalNameSpacePathStr, + this.iClassNameStr, + null + ); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/CorrelatorNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/CorrelatorNode.java similarity index 60% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/CorrelatorNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/CorrelatorNode.java index 427792d..3589d30 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/CorrelatorNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/CorrelatorNode.java @@ -1,120 +1,114 @@ -/* - (C) Copyright IBM Corp. 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Dave Blaschke, blaschke@us.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 2538 2013-11-28 blaschke-oss CR14: Support new CORRELATOR element - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT CORRELATOR (VALUE)
      - * ATTLIST CORRELATOR
      - *   %CIMName;
      - *   %CIMType; #REQUIRED
      - * 
      - */ -public class CorrelatorNode extends Node implements TypedIf, ValueIf { - - // private String iName; - - private CIMDataType iType; - - private Object iValue; - - private boolean iHasValue; - - /** - * Ctor. - */ - public CorrelatorNode() { - super(CORRELATOR); - } - - /** - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - /* this.iName = */getCIMName(pAttribs); - this.iType = getCIMType(pAttribs, false); - this.iValue = null; - this.iHasValue = false; - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum != VALUE) throw new SAXException(pNodeNameEnum - + " cannot be the child node of " + getNodeName() + " node!"); - if (this.iHasValue) throw new SAXException(getNodeName() - + " node can have only one child node!"); - } - - @Override - public void childParsed(Node pChild) { - if (pChild instanceof ValueNode) this.iHasValue = true; - this.iValue = ((ValueNode) pChild).getValue(); - } - - @Override - public void testCompletness() throws SAXException { - if (!this.iHasValue) throw new SAXException(getNodeName() - + " node must have one VALUE child node!"); - } - - public CIMDataType getType() { - return this.iType; - } - - public Object getValue() { - return this.iValue; - } - -} +/* + (C) Copyright IBM Corp. 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Dave Blaschke, blaschke@us.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 2538 2013-11-28 blaschke-oss CR14: Support new CORRELATOR element + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT CORRELATOR (VALUE)
      + * ATTLIST CORRELATOR
      + *   %CIMName;
      + *   %CIMType; #REQUIRED
      + * 
      + */ +public class CorrelatorNode extends Node implements TypedIf, ValueIf { + // private String iName; + + private CIMDataType iType; + + private Object iValue; + + private boolean iHasValue; + + /** + * Ctor. + */ + public CorrelatorNode() { + super(CORRELATOR); + } + + /** + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + /* this.iName = */getCIMName(pAttribs); + this.iType = getCIMType(pAttribs, false); + this.iValue = null; + this.iHasValue = false; + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum != VALUE) throw new SAXException( + pNodeNameEnum + " cannot be the child node of " + getNodeName() + " node!" + ); + if (this.iHasValue) throw new SAXException(getNodeName() + " node can have only one child node!"); + } + + @Override + public void childParsed(Node pChild) { + if (pChild instanceof ValueNode) this.iHasValue = true; + this.iValue = ((ValueNode) pChild).getValue(); + } + + @Override + public void testCompletness() throws SAXException { + if (!this.iHasValue) throw new SAXException(getNodeName() + " node must have one VALUE child node!"); + } + + public CIMDataType getType() { + return this.iType; + } + + public Object getValue() { + return this.iValue; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ErrorIf.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ErrorIf.java similarity index 57% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ErrorIf.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ErrorIf.java index c3a230f..2ae221e 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ErrorIf.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ErrorIf.java @@ -1,58 +1,54 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.CIMError; - -/** - * This interface is implemented by Nodes which can provide CIMError info. - */ -public interface ErrorIf { - - /** - * getCIMError - * - * @return CIMError - */ - public CIMError getCIMError(); - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.sblim.cimclient.internal.wbem.CIMError; + +/** + * This interface is implemented by Nodes which can provide CIMError info. + */ +public interface ErrorIf { + /** + * getCIMError + * + * @return CIMError + */ + public CIMError getCIMError(); +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ErrorNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ErrorNode.java similarity index 65% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ErrorNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ErrorNode.java index adf00aa..35f50bf 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ErrorNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ErrorNode.java @@ -1,134 +1,128 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 3293248 2011-05-03 blaschke-oss Support for CIM_ERROR instances within ERROR - * 2604 2013-07-01 blaschke-oss SAXException messages should contain node name - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; - -import org.sentrysoftware.wbem.javax.cim.CIMInstance; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.CIMError; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT ERROR (INSTANCE*)
      - * ATTLIST ERROR
      - *   CODE CDATA #REQUIRED
      - *   DESCRIPTION CDATA #IMPLIED
      - * 
      - */ -public class ErrorNode extends Node implements ErrorIf { - - private int iCode; - - private String iDesc; - - private ArrayList iCIMInstAL; - - /** - * Ctor. - */ - public ErrorNode() { - super(ERROR); - } - - /** - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iCIMInstAL = null; - String code = pAttribs.getValue("CODE"); - if (code == null) throw new SAXException(getNodeName() - + " node must have a CODE attribute!"); - try { - this.iCode = Integer.parseInt(code); - } catch (NumberFormatException e) { - throw new SAXException("Failed to parse CODE attribute in " + getNodeName() + " node!", - e); - } - this.iDesc = pAttribs.getValue("DESCRIPTION"); - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum != INSTANCE) throw new SAXException(getNodeName() + " node cannot have " - + pNodeNameEnum + " child node!"); - } - - @Override - public void childParsed(Node pChild) { - if (this.iCIMInstAL == null) this.iCIMInstAL = new ArrayList(); - this.iCIMInstAL.add(((InstanceNode) pChild).getCIMInstance()); - } - - @Override - public void testCompletness() { - // no mandatory child nodes - } - - private static final CIMInstance[] EMPTY_IA = new CIMInstance[0]; - - public CIMError getCIMError() { - if (this.iCIMInstAL != null) { return new CIMError(this.iCode, this.iDesc, this.iCIMInstAL - .toArray(EMPTY_IA)); } - return new CIMError(this.iCode, this.iDesc); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 3293248 2011-05-03 blaschke-oss Support for CIM_ERROR instances within ERROR + * 2604 2013-07-01 blaschke-oss SAXException messages should contain node name + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import org.metricshub.wbem.javax.cim.CIMInstance; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.CIMError; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT ERROR (INSTANCE*)
      + * ATTLIST ERROR
      + *   CODE CDATA #REQUIRED
      + *   DESCRIPTION CDATA #IMPLIED
      + * 
      + */ +public class ErrorNode extends Node implements ErrorIf { + private int iCode; + + private String iDesc; + + private ArrayList iCIMInstAL; + + /** + * Ctor. + */ + public ErrorNode() { + super(ERROR); + } + + /** + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iCIMInstAL = null; + String code = pAttribs.getValue("CODE"); + if (code == null) throw new SAXException(getNodeName() + " node must have a CODE attribute!"); + try { + this.iCode = Integer.parseInt(code); + } catch (NumberFormatException e) { + throw new SAXException("Failed to parse CODE attribute in " + getNodeName() + " node!", e); + } + this.iDesc = pAttribs.getValue("DESCRIPTION"); + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum != INSTANCE) throw new SAXException( + getNodeName() + " node cannot have " + pNodeNameEnum + " child node!" + ); + } + + @Override + public void childParsed(Node pChild) { + if (this.iCIMInstAL == null) this.iCIMInstAL = new ArrayList(); + this.iCIMInstAL.add(((InstanceNode) pChild).getCIMInstance()); + } + + @Override + public void testCompletness() { + // no mandatory child nodes + } + + private static final CIMInstance[] EMPTY_IA = new CIMInstance[0]; + + public CIMError getCIMError() { + if (this.iCIMInstAL != null) { + return new CIMError(this.iCode, this.iDesc, this.iCIMInstAL.toArray(EMPTY_IA)); + } + return new CIMError(this.iCode, this.iDesc); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ExpMethodCallNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ExpMethodCallNode.java similarity index 68% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ExpMethodCallNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ExpMethodCallNode.java index 518590d..a701e89 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ExpMethodCallNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ExpMethodCallNode.java @@ -1,131 +1,126 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT EXPMETHODCALL (EXPPARAMVALUE*)
      - * ATTLIST EXPMETHODCALL
      - *   %CIMName;
      - * 
      - */ -/** - * Class ExpMethodCallNode is responsible for - * - */ -public class ExpMethodCallNode extends Node implements NonVolatileIf { - - private String iName; - - private ArrayList iExpParamValNodeAList; - - /** - * Ctor. - */ - public ExpMethodCallNode() { - super(EXPMETHODCALL); - } - - public void addChild(Node pChild) { - if (this.iExpParamValNodeAList == null) this.iExpParamValNodeAList = new ArrayList(); - this.iExpParamValNodeAList.add(pChild); - } - - /** - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iName = getCIMName(pAttribs); - if (this.iExpParamValNodeAList != null) this.iExpParamValNodeAList.clear(); - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum != EXPPARAMVALUE) throw new SAXException(getNodeName() - + " node can have " + EXPPARAMVALUE + " child only! " + pNodeNameEnum - + " is invalid!"); - } - - /** - * @param pChild - */ - @Override - public void childParsed(Node pChild) { - // nothing to do yet - - } - - @Override - public void testCompletness() { - // no mandatory child - } - - /** - * getName - * - * @return String - */ - public String getName() { - return this.iName; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT EXPMETHODCALL (EXPPARAMVALUE*)
      + * ATTLIST EXPMETHODCALL
      + *   %CIMName;
      + * 
      + */ +/** + * Class ExpMethodCallNode is responsible for + * + */ +public class ExpMethodCallNode extends Node implements NonVolatileIf { + private String iName; + + private ArrayList iExpParamValNodeAList; + + /** + * Ctor. + */ + public ExpMethodCallNode() { + super(EXPMETHODCALL); + } + + public void addChild(Node pChild) { + if (this.iExpParamValNodeAList == null) this.iExpParamValNodeAList = new ArrayList(); + this.iExpParamValNodeAList.add(pChild); + } + + /** + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iName = getCIMName(pAttribs); + if (this.iExpParamValNodeAList != null) this.iExpParamValNodeAList.clear(); + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum != EXPPARAMVALUE) throw new SAXException( + getNodeName() + " node can have " + EXPPARAMVALUE + " child only! " + pNodeNameEnum + " is invalid!" + ); + } + + /** + * @param pChild + */ + @Override + public void childParsed(Node pChild) { + // nothing to do yet + + } + + @Override + public void testCompletness() { + // no mandatory child + } + + /** + * getName + * + * @return String + */ + public String getName() { + return this.iName; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ExpMethodResponseNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ExpMethodResponseNode.java similarity index 66% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ExpMethodResponseNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ExpMethodResponseNode.java index 1f3384d..a0af686 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ExpMethodResponseNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ExpMethodResponseNode.java @@ -1,146 +1,146 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.CIMError; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT EXPMETHODRESPONSE (ERROR|IRETURNVALUE?)
      - * ATTLIST EXPMETHODRESPONSE
      - *   %CIMName;
      - * 
      - */ -public class ExpMethodResponseNode extends Node implements ErrorIf, RetValPipeIf, NonVolatileIf { - - private String iName; - - private ErrorNode iErrorNode; - - private IReturnValueNode iRetValNode; - - /** - * Ctor. - */ - public ExpMethodResponseNode() { - super(EXPMETHODRESPONSE); - } - - public void addChild(Node pChild) { - if (pChild instanceof ErrorNode) this.iErrorNode = (ErrorNode) pChild; - else this.iRetValNode = (IReturnValueNode) pChild; - } - - /** - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iName = getCIMName(pAttribs); - this.iErrorNode = null; - this.iRetValNode = null; - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum == ERROR || pNodeNameEnum == IRETURNVALUE) { - Node node; - if (this.iErrorNode != null) node = this.iErrorNode; - else if (this.iRetValNode != null) node = this.iRetValNode; - else node = null; - if (node != null) throw new SAXException(pNodeNameEnum + " child node is invalid for " - + getNodeName() + " node, since it already has a " + node.getNodeName() - + " child node!"); - } else throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum - + " child node!"); - } - - /** - * @param pChild - */ - @Override - public void childParsed(Node pChild) { - // nothing to do yet - } - - @Override - public void testCompletness() { - // no mandatory child nodes - } - - public CIMError getCIMError() { - return this.iErrorNode == null ? null : this.iErrorNode.getCIMError(); - } - - public int getReturnValueCount() { - return this.iRetValNode == null ? 0 : this.iRetValNode.getReturnValueCount(); - } - - public Object readReturnValue() { - return this.iRetValNode.readReturnValue(); - } - - /** - * getName - * - * @return String - */ - public String getName() { - return this.iName; - } -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.CIMError; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT EXPMETHODRESPONSE (ERROR|IRETURNVALUE?)
      + * ATTLIST EXPMETHODRESPONSE
      + *   %CIMName;
      + * 
      + */ +public class ExpMethodResponseNode extends Node implements ErrorIf, RetValPipeIf, NonVolatileIf { + private String iName; + + private ErrorNode iErrorNode; + + private IReturnValueNode iRetValNode; + + /** + * Ctor. + */ + public ExpMethodResponseNode() { + super(EXPMETHODRESPONSE); + } + + public void addChild(Node pChild) { + if (pChild instanceof ErrorNode) this.iErrorNode = (ErrorNode) pChild; else this.iRetValNode = + (IReturnValueNode) pChild; + } + + /** + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iName = getCIMName(pAttribs); + this.iErrorNode = null; + this.iRetValNode = null; + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum == ERROR || pNodeNameEnum == IRETURNVALUE) { + Node node; + if (this.iErrorNode != null) node = this.iErrorNode; else if (this.iRetValNode != null) node = + this.iRetValNode; else node = null; + if (node != null) throw new SAXException( + pNodeNameEnum + + " child node is invalid for " + + getNodeName() + + " node, since it already has a " + + node.getNodeName() + + " child node!" + ); + } else throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!"); + } + + /** + * @param pChild + */ + @Override + public void childParsed(Node pChild) { + // nothing to do yet + } + + @Override + public void testCompletness() { + // no mandatory child nodes + } + + public CIMError getCIMError() { + return this.iErrorNode == null ? null : this.iErrorNode.getCIMError(); + } + + public int getReturnValueCount() { + return this.iRetValNode == null ? 0 : this.iRetValNode.getReturnValueCount(); + } + + public Object readReturnValue() { + return this.iRetValNode.readReturnValue(); + } + + /** + * getName + * + * @return String + */ + public String getName() { + return this.iName; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ExpParamValueNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ExpParamValueNode.java similarity index 67% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ExpParamValueNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ExpParamValueNode.java index 8eea5b3..10d703d 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ExpParamValueNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ExpParamValueNode.java @@ -1,124 +1,120 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - * 2687 2013-10-10 blaschke-oss ExpParamValueNode allows VALUE, (I)METHODRESPONSE children - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT EXPPARAMVALUE (INSTANCE?)
      - * ATTLIST EXPPARAMVALUE
      - *   %CIMName;
      - * 
      - */ -public class ExpParamValueNode extends Node implements NonVolatileIf { - - private String iName; - - private Node iChildNode; - - /** - * Ctor. - */ - public ExpParamValueNode() { - super(EXPPARAMVALUE); - } - - public void addChild(Node pChild) { - this.iChildNode = pChild; - } - - /** - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iName = getCIMName(pAttribs); - this.iChildNode = null; - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (this.iChildNode != null) throw new SAXException(getNodeName() - + " node can have only one child node!"); - if (pNodeNameEnum != INSTANCE) throw new SAXException(getNodeName() + " node cannot have " - + pNodeNameEnum + " child node!"); - } - - /** - * @param pChild - */ - @Override - public void childParsed(Node pChild) { - // nothing to do yet - } - - @Override - public void testCompletness() { - // child node is optional - } - - /** - * getName - * - * @return String - */ - public String getName() { - return this.iName; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + * 2687 2013-10-10 blaschke-oss ExpParamValueNode allows VALUE, (I)METHODRESPONSE children + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT EXPPARAMVALUE (INSTANCE?)
      + * ATTLIST EXPPARAMVALUE
      + *   %CIMName;
      + * 
      + */ +public class ExpParamValueNode extends Node implements NonVolatileIf { + private String iName; + + private Node iChildNode; + + /** + * Ctor. + */ + public ExpParamValueNode() { + super(EXPPARAMVALUE); + } + + public void addChild(Node pChild) { + this.iChildNode = pChild; + } + + /** + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iName = getCIMName(pAttribs); + this.iChildNode = null; + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (this.iChildNode != null) throw new SAXException(getNodeName() + " node can have only one child node!"); + if (pNodeNameEnum != INSTANCE) throw new SAXException( + getNodeName() + " node cannot have " + pNodeNameEnum + " child node!" + ); + } + + /** + * @param pChild + */ + @Override + public void childParsed(Node pChild) { + // nothing to do yet + } + + @Override + public void testCompletness() { + // child node is optional + } + + /** + * getName + * + * @return String + */ + public String getName() { + return this.iName; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/HostNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/HostNode.java similarity index 67% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/HostNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/HostNode.java index 658f841..e19ecc0 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/HostNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/HostNode.java @@ -1,113 +1,108 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 1742873 2007-06-25 ebak IPv6 ready cim-client - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT HOST (#PCDATA) - */ -public class HostNode extends Node { - - private String iHost; - - /** - * Ctor. - */ - public HostNode() { - super(HOST); - } - - /** - * @param pAttribs - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - this.iHost = null; - // no attributes - } - - @Override - public void parseData(String pData) { - this.iHost = pData; - } - - /** - * @param pNodeNameEnum - */ - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - throw new SAXException("HOST node cannot have any child node!"); - } - - /** - * @param pChild - */ - @Override - public void childParsed(Node pChild) { - // no child node - - } - - @Override - public void testCompletness() throws SAXException { - if (this.iHost == null) throw new SAXException( - "HOST node must contain the host name as #PCDATA!"); - } - - /** - * getHostStr - * - * @return String which may contain the protocol, host and port - */ - public String getHostStr() { - return this.iHost; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 1742873 2007-06-25 ebak IPv6 ready cim-client + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT HOST (#PCDATA) + */ +public class HostNode extends Node { + private String iHost; + + /** + * Ctor. + */ + public HostNode() { + super(HOST); + } + + /** + * @param pAttribs + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + this.iHost = null; + // no attributes + } + + @Override + public void parseData(String pData) { + this.iHost = pData; + } + + /** + * @param pNodeNameEnum + */ + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + throw new SAXException("HOST node cannot have any child node!"); + } + + /** + * @param pChild + */ + @Override + public void childParsed(Node pChild) { + // no child node + + } + + @Override + public void testCompletness() throws SAXException { + if (this.iHost == null) throw new SAXException("HOST node must contain the host name as #PCDATA!"); + } + + /** + * getHostStr + * + * @return String which may contain the protocol, host and port + */ + public String getHostStr() { + return this.iHost; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/IMethodCallNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/IMethodCallNode.java similarity index 62% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/IMethodCallNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/IMethodCallNode.java index 0c214a3..ca11707 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/IMethodCallNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/IMethodCallNode.java @@ -1,79 +1,77 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1686000 2007-04-20 ebak modifyInstance() missing from WBEMClient - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2682 2013-10-02 blaschke-oss (I)MethodCallNode allows no LOCAL*PATH - * 2690 2013-10-11 blaschke-oss Remove RESPONSEDESTINATION support - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.xml.sax.SAXException; - -/** - * ELEMENT IMETHODCALL (LOCALNAMESPACEPATH, IPARAMVALUE*) ATTLIST IMETHODCALL - * %CIMName; - */ -public class IMethodCallNode extends AbstractMethodCallNode { - - /** - * Ctor. - */ - public IMethodCallNode() { - super(IMETHODCALL); - } - - @Override - protected void testSpecChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum == LOCALNAMESPACEPATH) { - if (this.iPath != null) throw new SAXException(getNodeName() - + " node can have only one " + pNodeNameEnum + " child node!"); - } else if (pNodeNameEnum != IPARAMVALUE) throw new SAXException(getNodeName() - + " node cannot have " + pNodeNameEnum + " child node!"); - } - - @Override - public void testCompletness() throws SAXException { - if (this.iPath == null) throw new SAXException( - "IMETHODCALL node must have a LOCALNAMESPACEPATH child node!"); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1686000 2007-04-20 ebak modifyInstance() missing from WBEMClient + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2682 2013-10-02 blaschke-oss (I)MethodCallNode allows no LOCAL*PATH + * 2690 2013-10-11 blaschke-oss Remove RESPONSEDESTINATION support + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.xml.sax.SAXException; + +/** + * ELEMENT IMETHODCALL (LOCALNAMESPACEPATH, IPARAMVALUE*) ATTLIST IMETHODCALL + * %CIMName; + */ +public class IMethodCallNode extends AbstractMethodCallNode { + + /** + * Ctor. + */ + public IMethodCallNode() { + super(IMETHODCALL); + } + + @Override + protected void testSpecChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum == LOCALNAMESPACEPATH) { + if (this.iPath != null) throw new SAXException( + getNodeName() + " node can have only one " + pNodeNameEnum + " child node!" + ); + } else if (pNodeNameEnum != IPARAMVALUE) throw new SAXException( + getNodeName() + " node cannot have " + pNodeNameEnum + " child node!" + ); + } + + @Override + public void testCompletness() throws SAXException { + if (this.iPath == null) throw new SAXException("IMETHODCALL node must have a LOCALNAMESPACEPATH child node!"); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/IMethodResponseNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/IMethodResponseNode.java similarity index 66% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/IMethodResponseNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/IMethodResponseNode.java index b608dba..d9f22c6 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/IMethodResponseNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/IMethodResponseNode.java @@ -1,206 +1,209 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2845211 2009-08-27 raman_arora Pull Enumeration Feature (SAX Parser) - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - * 2697 2012-10-30 blaschke-oss (I)MethodResponseNode allows ERROR with PARAMVALUE - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; - -import org.sentrysoftware.wbem.javax.cim.CIMArgument; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.CIMError; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT IMETHODRESPONSE (ERROR|IRETURNVALUE?)
      - * ATTLIST IMETHODRESPONSE
      - *   %CIMName; 
      - * 
      - */ -/** - * Class IMethodResponseNode is responsible for - * - */ -public class IMethodResponseNode extends Node implements ErrorIf, RetValPipeIf, NonVolatileIf { - - private String iName; - - private ErrorNode iErrorNode; - - private IReturnValueNode iRetValNode; - - private ArrayList> iCIMArgAL; - - private static final CIMArgument[] EMPTY_ARG_A = new CIMArgument[0]; - - private boolean iHasError; - - private boolean iHasRetVal; - - /** - * Ctor. - */ - public IMethodResponseNode() { - super(IMETHODRESPONSE); - } - - public void addChild(Node pChild) { - if (pChild instanceof IReturnValueNode) { - this.iRetValNode = (IReturnValueNode) pChild; - } else if (pChild instanceof ErrorNode) { - this.iErrorNode = (ErrorNode) pChild; - } - } - - /** - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iName = getCIMName(pAttribs); - this.iErrorNode = null; - this.iRetValNode = null; - if (this.iCIMArgAL != null) this.iCIMArgAL.clear(); - this.iHasError = false; - this.iHasRetVal = false; - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum == ERROR) { - String ownedNodeName; - if (this.iHasRetVal) ownedNodeName = IRETURNVALUE; - else if (this.iHasError) ownedNodeName = ERROR; - else if (this.iCIMArgAL != null && this.iCIMArgAL.size() > 0) ownedNodeName = PARAMVALUE; - else ownedNodeName = null; - if (ownedNodeName != null) throw new SAXException(pNodeNameEnum - + " child node is invalid for " + getNodeName() - + " node, since it already has a " + ownedNodeName + " child node!"); - } else if (pNodeNameEnum == IRETURNVALUE) { - String ownedNodeName; - if (this.iHasRetVal) ownedNodeName = IRETURNVALUE; - else if (this.iHasError) ownedNodeName = ERROR; - else ownedNodeName = null; - if (ownedNodeName != null) throw new SAXException(pNodeNameEnum - + " child node is invalid for " + getNodeName() - + " node, since it already has a " + ownedNodeName + " child node!"); - } else if (pNodeNameEnum == PARAMVALUE) { - if (this.iHasError) throw new SAXException(pNodeNameEnum - + " child node is invalid for " + getNodeName() - + " node, since it already has an ERROR child node!"); - } else throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum - + " child node!"); - } - - /** - * @param pChild - */ - @Override - public void childParsed(Node pChild) { - if (pChild instanceof ErrorNode) { - this.iHasError = true; - this.iErrorNode = (ErrorNode) pChild; - } else if (pChild instanceof IReturnValueNode) { - this.iHasRetVal = true; - this.iRetValNode = (IReturnValueNode) pChild; - } else - // Values of parameters should be stored in array - if (pChild instanceof ParamValueNode) { - if (this.iCIMArgAL == null) this.iCIMArgAL = new ArrayList>(); - this.iCIMArgAL.add(((ParamValueNode) pChild).getCIMArgument()); - } - } - - @Override - public void testCompletness() { - // no mandatory child nodes - } - - public CIMError getCIMError() { - return this.iErrorNode == null ? null : this.iErrorNode.getCIMError(); - } - - public int getReturnValueCount() { - return this.iRetValNode == null ? 0 : this.iRetValNode.getReturnValueCount(); - } - - public Object readReturnValue() { - return this.iRetValNode.readReturnValue(); - } - - /** - * getName - * - * @return String - */ - public String getName() { - return this.iName; - } - - /** - * getCIMArguments : returns the array of parsed parameters and their values - * : String name, CIMDataType type, Object value - * - * @return CIMArgument<?>[] - */ - public CIMArgument[] getCIMArguments() { - if (this.iCIMArgAL == null || this.iCIMArgAL.size() == 0) return null; - return this.iCIMArgAL.toArray(EMPTY_ARG_A); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2845211 2009-08-27 raman_arora Pull Enumeration Feature (SAX Parser) + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + * 2697 2012-10-30 blaschke-oss (I)MethodResponseNode allows ERROR with PARAMVALUE + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import org.metricshub.wbem.javax.cim.CIMArgument; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.CIMError; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT IMETHODRESPONSE (ERROR|IRETURNVALUE?)
      + * ATTLIST IMETHODRESPONSE
      + *   %CIMName;
      + * 
      + */ +/** + * Class IMethodResponseNode is responsible for + * + */ +public class IMethodResponseNode extends Node implements ErrorIf, RetValPipeIf, NonVolatileIf { + private String iName; + + private ErrorNode iErrorNode; + + private IReturnValueNode iRetValNode; + + private ArrayList> iCIMArgAL; + + private static final CIMArgument[] EMPTY_ARG_A = new CIMArgument[0]; + + private boolean iHasError; + + private boolean iHasRetVal; + + /** + * Ctor. + */ + public IMethodResponseNode() { + super(IMETHODRESPONSE); + } + + public void addChild(Node pChild) { + if (pChild instanceof IReturnValueNode) { + this.iRetValNode = (IReturnValueNode) pChild; + } else if (pChild instanceof ErrorNode) { + this.iErrorNode = (ErrorNode) pChild; + } + } + + /** + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iName = getCIMName(pAttribs); + this.iErrorNode = null; + this.iRetValNode = null; + if (this.iCIMArgAL != null) this.iCIMArgAL.clear(); + this.iHasError = false; + this.iHasRetVal = false; + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum == ERROR) { + String ownedNodeName; + if (this.iHasRetVal) ownedNodeName = IRETURNVALUE; else if (this.iHasError) ownedNodeName = ERROR; else if ( + this.iCIMArgAL != null && this.iCIMArgAL.size() > 0 + ) ownedNodeName = PARAMVALUE; else ownedNodeName = null; + if (ownedNodeName != null) throw new SAXException( + pNodeNameEnum + + " child node is invalid for " + + getNodeName() + + " node, since it already has a " + + ownedNodeName + + " child node!" + ); + } else if (pNodeNameEnum == IRETURNVALUE) { + String ownedNodeName; + if (this.iHasRetVal) ownedNodeName = IRETURNVALUE; else if (this.iHasError) ownedNodeName = + ERROR; else ownedNodeName = null; + if (ownedNodeName != null) throw new SAXException( + pNodeNameEnum + + " child node is invalid for " + + getNodeName() + + " node, since it already has a " + + ownedNodeName + + " child node!" + ); + } else if (pNodeNameEnum == PARAMVALUE) { + if (this.iHasError) throw new SAXException( + pNodeNameEnum + + " child node is invalid for " + + getNodeName() + + " node, since it already has an ERROR child node!" + ); + } else throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!"); + } + + /** + * @param pChild + */ + @Override + public void childParsed(Node pChild) { + if (pChild instanceof ErrorNode) { + this.iHasError = true; + this.iErrorNode = (ErrorNode) pChild; + } else if (pChild instanceof IReturnValueNode) { + this.iHasRetVal = true; + this.iRetValNode = (IReturnValueNode) pChild; + } else // Values of parameters should be stored in array + if (pChild instanceof ParamValueNode) { + if (this.iCIMArgAL == null) this.iCIMArgAL = new ArrayList>(); + this.iCIMArgAL.add(((ParamValueNode) pChild).getCIMArgument()); + } + } + + @Override + public void testCompletness() { + // no mandatory child nodes + } + + public CIMError getCIMError() { + return this.iErrorNode == null ? null : this.iErrorNode.getCIMError(); + } + + public int getReturnValueCount() { + return this.iRetValNode == null ? 0 : this.iRetValNode.getReturnValueCount(); + } + + public Object readReturnValue() { + return this.iRetValNode.readReturnValue(); + } + + /** + * getName + * + * @return String + */ + public String getName() { + return this.iName; + } + + /** + * getCIMArguments : returns the array of parsed parameters and their values + * : String name, CIMDataType type, Object value + * + * @return CIMArgument<?>[] + */ + public CIMArgument[] getCIMArguments() { + if (this.iCIMArgAL == null || this.iCIMArgAL.size() == 0) return null; + return this.iCIMArgAL.toArray(EMPTY_ARG_A); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/IParamValueNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/IParamValueNode.java similarity index 65% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/IParamValueNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/IParamValueNode.java index dcf8244..f7865fe 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/IParamValueNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/IParamValueNode.java @@ -1,169 +1,169 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1686000 2007-04-20 ebak modifyInstance() missing from WBEMClient - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2680 2013-10-02 blaschke-oss IPARAMVALUE parsing broken on DOM/SAX - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMArgument; -import org.sentrysoftware.wbem.javax.cim.CIMDataType; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * FIXME: Why hasn't it got TYPE attribute? For VALUE and VALUE.ARRAY it would - * be necessary. - * - *
      - * 
      - * ELEMENT IPARAMVALUE (VALUE | VALUE.ARRAY | VALUE.REFERENCE | INSTANCENAME | CLASSNAME |
      - *   QUALIFIER.DECLARATION | CLASS | INSTANCE | VALUE.NAMEDINSTANCE)?
      - * ATTLIST IPARAMVALUE
      - *   %CIMName;
      - * 
      - */ -public class IParamValueNode extends AbstractParamValueNode { - - private String iName; - - /** - * child element - */ - private Object iValue; - - private boolean iIsArray; - - private CIMDataType iType; - - /** - * Ctor. - */ - public IParamValueNode() { - super(IPARAMVALUE); - } - - /** - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iValue = null; - this.iType = null; - this.iName = getCIMName(pAttribs); - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - private static final String[] ALLOWED_CHILDREN = { VALUE, VALUE_ARRAY, VALUE_REFERENCE, - INSTANCENAME, CLASSNAME, QUALIFIER_DECLARATION, CLASS, INSTANCE, VALUE_NAMEDINSTANCE }; - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - boolean allowed = false; - for (int i = 0; i < ALLOWED_CHILDREN.length; i++) { - if (ALLOWED_CHILDREN[i] == pNodeNameEnum) { - allowed = true; - break; - } - } - if (!allowed) throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum - + " child node!"); - /* - * this kind of check is not so strict (ValueNode.getValue() can return - * null) - */ - if (this.iValue != null) throw new SAXException(getNodeName() - + " node cannot have more than one child node!"); - - } - - @Override - public void childParsed(Node pChild) { - this.iValue = ((ValueIf) pChild).getValue(); - this.iIsArray = pChild instanceof ArrayIf; - if (pChild instanceof TypedIf) this.iType = ((TypedIf) pChild).getType(); - else if (pChild instanceof ObjectPathIf) this.iType = CIMDataType - .getDataType(((ObjectPathIf) pChild).getCIMObjectPath()); - else if (pChild instanceof ValueIf) this.iType = CIMDataType.getDataType(((ValueIf) pChild) - .getValue()); - } - - @Override - public void testCompletness() { - // child node is optional - } - - @Override - public CIMArgument getCIMArgument() { - return new CIMArgument(this.iName, getType(), this.iValue); - } - - /** - * getName - * - * @return String - */ - public String getName() { - return this.iName; - } - - public CIMDataType getType() { - return this.iType == null ? (this.iIsArray ? CIMDataType.STRING_ARRAY_T - : CIMDataType.STRING_T) : this.iType; - } - - public Object getValue() { - return this.iValue; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1686000 2007-04-20 ebak modifyInstance() missing from WBEMClient + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2680 2013-10-02 blaschke-oss IPARAMVALUE parsing broken on DOM/SAX + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMArgument; +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * FIXME: Why hasn't it got TYPE attribute? For VALUE and VALUE.ARRAY it would + * be necessary. + * + *
      + *
      + * ELEMENT IPARAMVALUE (VALUE | VALUE.ARRAY | VALUE.REFERENCE | INSTANCENAME | CLASSNAME |
      + *   QUALIFIER.DECLARATION | CLASS | INSTANCE | VALUE.NAMEDINSTANCE)?
      + * ATTLIST IPARAMVALUE
      + *   %CIMName;
      + * 
      + */ +public class IParamValueNode extends AbstractParamValueNode { + private String iName; + + /** + * child element + */ + private Object iValue; + + private boolean iIsArray; + + private CIMDataType iType; + + /** + * Ctor. + */ + public IParamValueNode() { + super(IPARAMVALUE); + } + + /** + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iValue = null; + this.iType = null; + this.iName = getCIMName(pAttribs); + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + private static final String[] ALLOWED_CHILDREN = { + VALUE, + VALUE_ARRAY, + VALUE_REFERENCE, + INSTANCENAME, + CLASSNAME, + QUALIFIER_DECLARATION, + CLASS, + INSTANCE, + VALUE_NAMEDINSTANCE + }; + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + boolean allowed = false; + for (int i = 0; i < ALLOWED_CHILDREN.length; i++) { + if (ALLOWED_CHILDREN[i] == pNodeNameEnum) { + allowed = true; + break; + } + } + if (!allowed) throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!"); + /* + * this kind of check is not so strict (ValueNode.getValue() can return + * null) + */ + if (this.iValue != null) throw new SAXException(getNodeName() + " node cannot have more than one child node!"); + } + + @Override + public void childParsed(Node pChild) { + this.iValue = ((ValueIf) pChild).getValue(); + this.iIsArray = pChild instanceof ArrayIf; + if (pChild instanceof TypedIf) this.iType = ((TypedIf) pChild).getType(); else if ( + pChild instanceof ObjectPathIf + ) this.iType = CIMDataType.getDataType(((ObjectPathIf) pChild).getCIMObjectPath()); else if ( + pChild instanceof ValueIf + ) this.iType = CIMDataType.getDataType(((ValueIf) pChild).getValue()); + } + + @Override + public void testCompletness() { + // child node is optional + } + + @Override + public CIMArgument getCIMArgument() { + return new CIMArgument(this.iName, getType(), this.iValue); + } + + /** + * getName + * + * @return String + */ + public String getName() { + return this.iName; + } + + public CIMDataType getType() { + return this.iType == null ? (this.iIsArray ? CIMDataType.STRING_ARRAY_T : CIMDataType.STRING_T) : this.iType; + } + + public Object getValue() { + return this.iValue; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/IReturnValueNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/IReturnValueNode.java similarity index 68% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/IReturnValueNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/IReturnValueNode.java index fd3e0e5..4e41fbd 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/IReturnValueNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/IReturnValueNode.java @@ -1,157 +1,171 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2845211 2009-08-27 raman_arora Pull Enumeration Feature (SAX Parser) - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.LinkedList; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * 
      - * ELEMENT IRETURNVALUE (
      - *   CLASSNAME* | INSTANCENAME* | VALUE* | VALUE.OBJECTWITHPATH* | VALUE.OBJECTWITHLOCALPATH* |
      - *   VALUE.OBJECT* | OBJECTPATH* | QUALIFIER.DECLARATION* | VALUE.ARRAY? | VALUE.REFERENCE? |
      - *   CLASS* | INSTANCE* | VALUE.NAMEDINSTANCE*
      - * )
      - * 
      - */ -public class IReturnValueNode extends Node implements RetValPipeIf, NonVolatileIf { - - private String iChildNameEnum; - - private LinkedList iChildValueLL; - - /** - * Ctor. - */ - public IReturnValueNode() { - super(IRETURNVALUE); - } - - /** - * @param pChild - */ - public void addChild(Node pChild) { /* we don't need it here */} - - /** - * @param pAttribs - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - // currently it's not really necessary here, since the Node is - // NonVolatile - this.iChildNameEnum = null; - this.iChildValueLL = null; - // no attribs - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - private static final String[] ALLOWED_CHILDREN = { CLASSNAME, INSTANCENAME, INSTANCEPATH, - VALUE, VALUE_OBJECTWITHPATH, VALUE_OBJECTWITHLOCALPATH, VALUE_OBJECT, OBJECTPATH, - QUALIFIER_DECLARATION, VALUE_ARRAY, VALUE_REFERENCE, CLASS, INSTANCE, - VALUE_NAMEDINSTANCE, VALUE_INSTANCEWITHPATH }; - - // private static final String[] SINGLE_CHILDREN = { VALUE_ARRAY, - // VALUE_REFERENCE }; - - /** - * @see Node#testChild(java.lang.String) - */ - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (this.iChildNameEnum != null) { - if (pNodeNameEnum != this.iChildNameEnum) throw new SAXException(getNodeName() - + " node cannot have " + pNodeNameEnum + " child node, since it already has " - + this.iChildNameEnum + " child node(s)!"); - if (this.iChildNameEnum == VALUE_ARRAY || this.iChildNameEnum == VALUE_REFERENCE) throw new SAXException( - getNodeName() + " node can have only one " + this.iChildNameEnum - + " child node!"); - } else { - boolean found = false; - for (int i = 0; i < ALLOWED_CHILDREN.length; i++) { - if ((found = (pNodeNameEnum == ALLOWED_CHILDREN[i])) == true) break; - } - if (!found) throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum - + " child node!"); - } - } - - @Override - public void childParsed(Node pChild) { - if (this.iChildValueLL == null) { - this.iChildNameEnum = pChild.getNodeName(); - this.iChildValueLL = new LinkedList(); - } - this.iChildValueLL.add(((ValueIf) pChild).getValue()); - } - - @Override - public void testCompletness() { - // child nodes are optional - } - - public int getReturnValueCount() { - return this.iChildValueLL == null ? 0 : this.iChildValueLL.size(); - } - - public Object readReturnValue() { - return this.iChildValueLL == null ? null : this.iChildValueLL.removeFirst(); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2845211 2009-08-27 raman_arora Pull Enumeration Feature (SAX Parser) + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.LinkedList; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + *
      + * ELEMENT IRETURNVALUE (
      + *   CLASSNAME* | INSTANCENAME* | VALUE* | VALUE.OBJECTWITHPATH* | VALUE.OBJECTWITHLOCALPATH* |
      + *   VALUE.OBJECT* | OBJECTPATH* | QUALIFIER.DECLARATION* | VALUE.ARRAY? | VALUE.REFERENCE? |
      + *   CLASS* | INSTANCE* | VALUE.NAMEDINSTANCE*
      + * )
      + * 
      + */ +public class IReturnValueNode extends Node implements RetValPipeIf, NonVolatileIf { + private String iChildNameEnum; + + private LinkedList iChildValueLL; + + /** + * Ctor. + */ + public IReturnValueNode() { + super(IRETURNVALUE); + } + + /** + * @param pChild + */ + public void addChild(Node pChild) { + /* we don't need it here */ + } + + /** + * @param pAttribs + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + // currently it's not really necessary here, since the Node is + // NonVolatile + this.iChildNameEnum = null; + this.iChildValueLL = null; + // no attribs + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + private static final String[] ALLOWED_CHILDREN = { + CLASSNAME, + INSTANCENAME, + INSTANCEPATH, + VALUE, + VALUE_OBJECTWITHPATH, + VALUE_OBJECTWITHLOCALPATH, + VALUE_OBJECT, + OBJECTPATH, + QUALIFIER_DECLARATION, + VALUE_ARRAY, + VALUE_REFERENCE, + CLASS, + INSTANCE, + VALUE_NAMEDINSTANCE, + VALUE_INSTANCEWITHPATH + }; + + // private static final String[] SINGLE_CHILDREN = { VALUE_ARRAY, + // VALUE_REFERENCE }; + + /** + * @see Node#testChild(java.lang.String) + */ + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (this.iChildNameEnum != null) { + if (pNodeNameEnum != this.iChildNameEnum) throw new SAXException( + getNodeName() + + " node cannot have " + + pNodeNameEnum + + " child node, since it already has " + + this.iChildNameEnum + + " child node(s)!" + ); + if (this.iChildNameEnum == VALUE_ARRAY || this.iChildNameEnum == VALUE_REFERENCE) throw new SAXException( + getNodeName() + " node can have only one " + this.iChildNameEnum + " child node!" + ); + } else { + boolean found = false; + for (int i = 0; i < ALLOWED_CHILDREN.length; i++) { + if ((found = (pNodeNameEnum == ALLOWED_CHILDREN[i])) == true) break; + } + if (!found) throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!"); + } + } + + @Override + public void childParsed(Node pChild) { + if (this.iChildValueLL == null) { + this.iChildNameEnum = pChild.getNodeName(); + this.iChildValueLL = new LinkedList(); + } + this.iChildValueLL.add(((ValueIf) pChild).getValue()); + } + + @Override + public void testCompletness() { + // child nodes are optional + } + + public int getReturnValueCount() { + return this.iChildValueLL == null ? 0 : this.iChildValueLL.size(); + } + + public Object readReturnValue() { + return this.iChildValueLL == null ? null : this.iChildValueLL.removeFirst(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/InstanceNameNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/InstanceNameNode.java similarity index 62% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/InstanceNameNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/InstanceNameNode.java index 18c3d0d..476915e 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/InstanceNameNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/InstanceNameNode.java @@ -1,164 +1,165 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2707 2013-11-12 blaschke-oss INSTANCENAME ignores KEYVALUE and VALUE.REFERENCE children - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import org.sentrysoftware.wbem.javax.cim.CIMProperty; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.LocalPathBuilder; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * perhaps it's a documentation mistake: ELEMENT INSTANCENAME (KEYBINDING* | KEYVALUE? | VALUE.REFERENCE?)
      - * ELEMENT INSTANCENAME (KEYBINDING*)
      - * ATTLIST INSTANCENAME
      - *  %ClassName;
      - * 
      - */ -public class InstanceNameNode extends AbstractPathNode { - - private String iClassName; - - private ArrayList> iCIMPropAL; - - private CIMObjectPath iLocalPath; - - private String iNodeName; - - /** - * Ctor. - */ - public InstanceNameNode() { - super(INSTANCENAME); - } - - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iLocalPath = pSession.getDefLocalPath(); - if (this.iCIMPropAL != null) this.iCIMPropAL.clear(); - this.iClassName = getClassName(pAttribs); - this.iNodeName = null; - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - private static final String[] ALLOWED_CHILDREN = { KEYBINDING, KEYVALUE, VALUE_REFERENCE }; - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - for (int i = 0; i < ALLOWED_CHILDREN.length; i++) - if (ALLOWED_CHILDREN[i] == pNodeNameEnum) { - if (this.iNodeName != null && this.iNodeName != pNodeNameEnum) throw new SAXException( - getNodeName() + " node cannot have " + pNodeNameEnum - + " child node, it already has a " + this.iNodeName + "!"); - if (pNodeNameEnum != KEYBINDING) { - if (this.iNodeName != null) throw new SAXException(getNodeName() - + " node can have only one " + pNodeNameEnum + " child node!"); - } - this.iNodeName = pNodeNameEnum; - return; - } - throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum - + " child node!"); - } - - @Override - public void childParsed(Node pChild) { - if (this.iCIMPropAL == null) this.iCIMPropAL = new ArrayList>(); - if (pChild instanceof KeyBindingNode) this.iCIMPropAL.add(((KeyBindingNode) pChild) - .getCIMProperty()); - else this.iCIMPropAL.add(new CIMProperty("", ((AbstractScalarValueNode) pChild) - .getType(), ((AbstractScalarValueNode) pChild).getValue(), true, false, null)); - } - - @Override - public void testCompletness() { - // no mandatory child nodes - } - - /** - * getClassName - * - * @return String - */ - public String getClassName() { - return this.iClassName; - } - - private static final CIMProperty[] EMPTY_PA = new CIMProperty[0]; - - /** - * getKeys - * - * @return CIMProperty[] - */ - public CIMProperty[] getKeys() { - if (this.iCIMPropAL == null || this.iCIMPropAL.size() == 0) return null; - return this.iCIMPropAL.toArray(EMPTY_PA); - } - - public CIMObjectPath getCIMObjectPath() { - /* - * CIMObjectPath(String objectName, String namespace, CIMProperty[] - * keys) - */ - return LocalPathBuilder.build(this.iLocalPath, this.iClassName, null, getKeys()); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2707 2013-11-12 blaschke-oss INSTANCENAME ignores KEYVALUE and VALUE.REFERENCE children + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.cim.CIMProperty; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.LocalPathBuilder; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * perhaps it's a documentation mistake: ELEMENT INSTANCENAME (KEYBINDING* | KEYVALUE? | VALUE.REFERENCE?)
      + * ELEMENT INSTANCENAME (KEYBINDING*)
      + * ATTLIST INSTANCENAME
      + *  %ClassName;
      + * 
      + */ +public class InstanceNameNode extends AbstractPathNode { + private String iClassName; + + private ArrayList> iCIMPropAL; + + private CIMObjectPath iLocalPath; + + private String iNodeName; + + /** + * Ctor. + */ + public InstanceNameNode() { + super(INSTANCENAME); + } + + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iLocalPath = pSession.getDefLocalPath(); + if (this.iCIMPropAL != null) this.iCIMPropAL.clear(); + this.iClassName = getClassName(pAttribs); + this.iNodeName = null; + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + private static final String[] ALLOWED_CHILDREN = { KEYBINDING, KEYVALUE, VALUE_REFERENCE }; + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + for (int i = 0; i < ALLOWED_CHILDREN.length; i++) if (ALLOWED_CHILDREN[i] == pNodeNameEnum) { + if (this.iNodeName != null && this.iNodeName != pNodeNameEnum) throw new SAXException( + getNodeName() + " node cannot have " + pNodeNameEnum + " child node, it already has a " + this.iNodeName + "!" + ); + if (pNodeNameEnum != KEYBINDING) { + if (this.iNodeName != null) throw new SAXException( + getNodeName() + " node can have only one " + pNodeNameEnum + " child node!" + ); + } + this.iNodeName = pNodeNameEnum; + return; + } + throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!"); + } + + @Override + public void childParsed(Node pChild) { + if (this.iCIMPropAL == null) this.iCIMPropAL = new ArrayList>(); + if (pChild instanceof KeyBindingNode) this.iCIMPropAL.add( + ((KeyBindingNode) pChild).getCIMProperty() + ); else this.iCIMPropAL.add( + new CIMProperty( + "", + ((AbstractScalarValueNode) pChild).getType(), + ((AbstractScalarValueNode) pChild).getValue(), + true, + false, + null + ) + ); + } + + @Override + public void testCompletness() { + // no mandatory child nodes + } + + /** + * getClassName + * + * @return String + */ + public String getClassName() { + return this.iClassName; + } + + private static final CIMProperty[] EMPTY_PA = new CIMProperty[0]; + + /** + * getKeys + * + * @return CIMProperty[] + */ + public CIMProperty[] getKeys() { + if (this.iCIMPropAL == null || this.iCIMPropAL.size() == 0) return null; + return this.iCIMPropAL.toArray(EMPTY_PA); + } + + public CIMObjectPath getCIMObjectPath() { + /* + * CIMObjectPath(String objectName, String namespace, CIMProperty[] + * keys) + */ + return LocalPathBuilder.build(this.iLocalPath, this.iClassName, null, getKeys()); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/InstanceNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/InstanceNode.java similarity index 66% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/InstanceNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/InstanceNode.java index 62f4a73..a2b33f6 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/InstanceNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/InstanceNode.java @@ -1,166 +1,157 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 3598613 2013-01-11 blaschke-oss different data type in cim instance and cim object path - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; - -import org.sentrysoftware.wbem.javax.cim.CIMInstance; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import org.sentrysoftware.wbem.javax.cim.CIMProperty; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.CIMHelper; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.LocalPathBuilder; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConfiguration; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT INSTANCE (QUALIFIER*, (PROPERTY | PROPERTY.ARRAY | PROPERTY.REFERENCE)*)
      - * ATTLIST INSTANCE
      - *   %ClassName;
      - *   xml:lang   NMTOKEN      #IMPLIED
      - * 
      - */ -public class InstanceNode extends AbstractObjectNode { - - private String iClassName; - - /** - * FIXME: What to do with the qualifiers? JSR48 doesn't specify qualifiers - * for CIMInstance! - */ - private QualifiedNodeHandler iQualiHandler; - - private ArrayList> iCIMPropAL; - - /** - * Ctor. - */ - public InstanceNode() { - super(INSTANCE); - } - - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iLocalPath = pSession.getDefLocalPath(); - this.iQualiHandler = new QualifiedNodeHandler(); - this.iCIMPropAL = null; - this.iClassName = getClassName(pAttribs); - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - private static final String[] ALLOWED_CHILDREN = { QUALIFIER, PROPERTY, PROPERTY_ARRAY, - PROPERTY_REFERENCE }; - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - for (int i = 0; i < ALLOWED_CHILDREN.length; i++) - if (ALLOWED_CHILDREN[i] == pNodeNameEnum) return; - throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum - + " child node!"); - } - - @Override - public void childParsed(Node pChild) { - if (this.iQualiHandler.addQualifierNode(pChild)) return; - if (this.iCIMPropAL == null) this.iCIMPropAL = new ArrayList>(); - this.iCIMPropAL.add(((AbstractPropertyNode) pChild).getCIMProperty()); - } - - @Override - public void testCompletness() { - // all child nodes are optional - } - - /** - * getCIMInstance - * - * @return CIMInstance - */ - public CIMInstance getCIMInstance() { - return new CIMInstance(LocalPathBuilder.build(this.iLocalPath, this.iClassName, null), - getProps()); - } - - /** - * getCIMInstance - * - * @param pObjPath - * @return CIMInstance with the provided object path - */ - public CIMInstance getCIMInstance(CIMObjectPath pObjPath) { - if (WBEMConfiguration.getGlobalConfiguration().synchronizeNumericKeyDataTypes()) return CIMHelper - .CIMInstanceWithSynchonizedNumericKeyDataTypes(pObjPath, getProps()); - return new CIMInstance(pObjPath, getProps()); - } - - /** - * @see ValueIf#getValue() - * @return CIMInstance - */ - public Object getValue() { - return getCIMInstance(); - } - - private static final CIMProperty[] EMPTY_PA = new CIMProperty[0]; - - private CIMProperty[] getProps() { - if (this.iCIMPropAL == null) return null; - return this.iCIMPropAL.toArray(EMPTY_PA); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 3598613 2013-01-11 blaschke-oss different data type in cim instance and cim object path + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import org.metricshub.wbem.javax.cim.CIMInstance; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.cim.CIMProperty; +import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMHelper; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.LocalPathBuilder; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfiguration; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT INSTANCE (QUALIFIER*, (PROPERTY | PROPERTY.ARRAY | PROPERTY.REFERENCE)*)
      + * ATTLIST INSTANCE
      + *   %ClassName;
      + *   xml:lang   NMTOKEN      #IMPLIED
      + * 
      + */ +public class InstanceNode extends AbstractObjectNode { + private String iClassName; + + /** + * FIXME: What to do with the qualifiers? JSR48 doesn't specify qualifiers + * for CIMInstance! + */ + private QualifiedNodeHandler iQualiHandler; + + private ArrayList> iCIMPropAL; + + /** + * Ctor. + */ + public InstanceNode() { + super(INSTANCE); + } + + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iLocalPath = pSession.getDefLocalPath(); + this.iQualiHandler = new QualifiedNodeHandler(); + this.iCIMPropAL = null; + this.iClassName = getClassName(pAttribs); + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + private static final String[] ALLOWED_CHILDREN = { QUALIFIER, PROPERTY, PROPERTY_ARRAY, PROPERTY_REFERENCE }; + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + for (int i = 0; i < ALLOWED_CHILDREN.length; i++) if (ALLOWED_CHILDREN[i] == pNodeNameEnum) return; + throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!"); + } + + @Override + public void childParsed(Node pChild) { + if (this.iQualiHandler.addQualifierNode(pChild)) return; + if (this.iCIMPropAL == null) this.iCIMPropAL = new ArrayList>(); + this.iCIMPropAL.add(((AbstractPropertyNode) pChild).getCIMProperty()); + } + + @Override + public void testCompletness() { + // all child nodes are optional + } + + /** + * getCIMInstance + * + * @return CIMInstance + */ + public CIMInstance getCIMInstance() { + return new CIMInstance(LocalPathBuilder.build(this.iLocalPath, this.iClassName, null), getProps()); + } + + /** + * getCIMInstance + * + * @param pObjPath + * @return CIMInstance with the provided object path + */ + public CIMInstance getCIMInstance(CIMObjectPath pObjPath) { + if ( + WBEMConfiguration.getGlobalConfiguration().synchronizeNumericKeyDataTypes() + ) return CIMHelper.CIMInstanceWithSynchonizedNumericKeyDataTypes(pObjPath, getProps()); + return new CIMInstance(pObjPath, getProps()); + } + + /** + * @see ValueIf#getValue() + * @return CIMInstance + */ + public Object getValue() { + return getCIMInstance(); + } + + private static final CIMProperty[] EMPTY_PA = new CIMProperty[0]; + + private CIMProperty[] getProps() { + if (this.iCIMPropAL == null) return null; + return this.iCIMPropAL.toArray(EMPTY_PA); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/InstancePathNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/InstancePathNode.java similarity index 64% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/InstancePathNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/InstancePathNode.java index 70b75fe..b911b7a 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/InstancePathNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/InstancePathNode.java @@ -1,149 +1,146 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 1742873 2007-06-25 ebak IPv6 ready cim-client - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import org.sentrysoftware.wbem.javax.cim.CIMProperty; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.XMLHostStr; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT INSTANCEPATH (NAMESPACEPATH, INSTANCENAME) - */ -public class InstancePathNode extends AbstractObjectPathNode { - - // INSTANCEPATH - private boolean iHasInstancePath; - - private String iLocalNameSpacePathStr; - - private XMLHostStr iHostStr; - - // INSTANCENAME - private boolean iHasInstanceName; - - private String iClassNameStr; - - private CIMProperty[] iKeys; - - /** - * Ctor. - */ - public InstancePathNode() { - super(INSTANCEPATH); - } - - /** - * @param pAttribs - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - this.iHasInstanceName = this.iHasInstancePath = false; - this.iLocalNameSpacePathStr = this.iClassNameStr = null; - this.iHostStr = new XMLHostStr(); - this.iKeys = null; - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum == NAMESPACEPATH) { - if (this.iHasInstancePath) throw new SAXException( - "INSTANCEPATH node can have only one NAMESPACEPATH child node!"); - } else if (pNodeNameEnum == INSTANCENAME) { - if (this.iHasInstanceName) throw new SAXException( - "INSTANCEPATH node can have only one INSTANCENAME child node!"); - } else throw new SAXException("INSTANCEPATH node cannot have " + pNodeNameEnum - + " child node!"); - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void childParsed(Node pChild) { - if (pChild instanceof NameSpacePathNode) { - NameSpacePathNode nsPathNode = (NameSpacePathNode) pChild; - this.iHostStr.set(nsPathNode.getHostStr()); - this.iLocalNameSpacePathStr = nsPathNode.getLocalNameSpacePath(); - this.iHasInstancePath = true; - } else { - InstanceNameNode instNameNode = (InstanceNameNode) pChild; - this.iClassNameStr = instNameNode.getClassName(); - this.iKeys = instNameNode.getKeys(); - this.iHasInstanceName = true; - } - } - - @Override - public void testCompletness() throws SAXException { - if (!this.iHasInstancePath) throw new SAXException( - "INSTANCEPATH node must have a NAMESPACEPATH child node!"); - if (!this.iHasInstanceName) throw new SAXException( - "INSTANCEPATH node must have an INSTANCENAME child node!"); - } - - public CIMObjectPath getCIMObjectPath() { - /* - * CIMObjectPath( String scheme, String host, String port, String - * namespace, String objectName, CIMProperty[] keys ) - */ - return new CIMObjectPath(this.iHostStr.getProtocol(), this.iHostStr.getHost(), - this.iHostStr.getPort(), this.iLocalNameSpacePathStr, this.iClassNameStr, - this.iKeys); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 1742873 2007-06-25 ebak IPv6 ready cim-client + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.cim.CIMProperty; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.metricshub.wbem.sblim.cimclient.internal.util.XMLHostStr; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT INSTANCEPATH (NAMESPACEPATH, INSTANCENAME) + */ +public class InstancePathNode extends AbstractObjectPathNode { + // INSTANCEPATH + private boolean iHasInstancePath; + + private String iLocalNameSpacePathStr; + + private XMLHostStr iHostStr; + + // INSTANCENAME + private boolean iHasInstanceName; + + private String iClassNameStr; + + private CIMProperty[] iKeys; + + /** + * Ctor. + */ + public InstancePathNode() { + super(INSTANCEPATH); + } + + /** + * @param pAttribs + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + this.iHasInstanceName = this.iHasInstancePath = false; + this.iLocalNameSpacePathStr = this.iClassNameStr = null; + this.iHostStr = new XMLHostStr(); + this.iKeys = null; + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum == NAMESPACEPATH) { + if (this.iHasInstancePath) throw new SAXException( + "INSTANCEPATH node can have only one NAMESPACEPATH child node!" + ); + } else if (pNodeNameEnum == INSTANCENAME) { + if (this.iHasInstanceName) throw new SAXException("INSTANCEPATH node can have only one INSTANCENAME child node!"); + } else throw new SAXException("INSTANCEPATH node cannot have " + pNodeNameEnum + " child node!"); + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void childParsed(Node pChild) { + if (pChild instanceof NameSpacePathNode) { + NameSpacePathNode nsPathNode = (NameSpacePathNode) pChild; + this.iHostStr.set(nsPathNode.getHostStr()); + this.iLocalNameSpacePathStr = nsPathNode.getLocalNameSpacePath(); + this.iHasInstancePath = true; + } else { + InstanceNameNode instNameNode = (InstanceNameNode) pChild; + this.iClassNameStr = instNameNode.getClassName(); + this.iKeys = instNameNode.getKeys(); + this.iHasInstanceName = true; + } + } + + @Override + public void testCompletness() throws SAXException { + if (!this.iHasInstancePath) throw new SAXException("INSTANCEPATH node must have a NAMESPACEPATH child node!"); + if (!this.iHasInstanceName) throw new SAXException("INSTANCEPATH node must have an INSTANCENAME child node!"); + } + + public CIMObjectPath getCIMObjectPath() { + /* + * CIMObjectPath( String scheme, String host, String port, String + * namespace, String objectName, CIMProperty[] keys ) + */ + return new CIMObjectPath( + this.iHostStr.getProtocol(), + this.iHostStr.getHost(), + this.iHostStr.getPort(), + this.iLocalNameSpacePathStr, + this.iClassNameStr, + this.iKeys + ); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/KeyBindingNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/KeyBindingNode.java similarity index 69% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/KeyBindingNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/KeyBindingNode.java index 60a5ac6..1fc4c54 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/KeyBindingNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/KeyBindingNode.java @@ -1,130 +1,124 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 3602604 2013-01-29 blaschke-oss Clean up SAXException messages - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMProperty; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT KEYBINDING (KEYVALUE | VALUE.REFERENCE) ATTLIST KEYBINDING %CIMName; - */ -public class KeyBindingNode extends Node { - - private String iName; - - // child element - private boolean iHasChild; - - private CIMDataType iType; - - private Object iValue; - - /** - * Ctor. - */ - public KeyBindingNode() { - super(KEYBINDING); - } - - /** - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iHasChild = false; - this.iValue = null; - this.iName = getCIMName(pAttribs); - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (this.iHasChild) throw new SAXException("KEYBINDING node can only have one child node!"); - if (pNodeNameEnum != KEYVALUE && pNodeNameEnum != VALUE_REFERENCE) throw new SAXException( - "KEYBINDING node's child node can be KEYVALUE or VALUE_REFERENCE but not " - + pNodeNameEnum); - } - - @Override - public void childParsed(Node pChild) { - AbstractScalarValueNode abstScalarValNode = (AbstractScalarValueNode) pChild; - this.iType = abstScalarValNode.getType(); - this.iValue = abstScalarValNode.getValue(); - this.iHasChild = true; - } - - @Override - public void testCompletness() throws SAXException { - if (!this.iHasChild) throw new SAXException( - "KEYBINDING node must have a KEYVALUE or VALUE_REFERENCE child node!"); - } - - /** - * getCIMProperty - * - * @return CIMProperty - */ - public CIMProperty getCIMProperty() { - // CIMProperty( - // String name, CIMDataType type, Object value, boolean key, boolean - // propagated, String originClass - // ) - return new CIMProperty(this.iName, this.iType, this.iValue, true, false, null); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 3602604 2013-01-29 blaschke-oss Clean up SAXException messages + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMProperty; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT KEYBINDING (KEYVALUE | VALUE.REFERENCE) ATTLIST KEYBINDING %CIMName; + */ +public class KeyBindingNode extends Node { + private String iName; + + // child element + private boolean iHasChild; + + private CIMDataType iType; + + private Object iValue; + + /** + * Ctor. + */ + public KeyBindingNode() { + super(KEYBINDING); + } + + /** + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iHasChild = false; + this.iValue = null; + this.iName = getCIMName(pAttribs); + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (this.iHasChild) throw new SAXException("KEYBINDING node can only have one child node!"); + if (pNodeNameEnum != KEYVALUE && pNodeNameEnum != VALUE_REFERENCE) throw new SAXException( + "KEYBINDING node's child node can be KEYVALUE or VALUE_REFERENCE but not " + pNodeNameEnum + ); + } + + @Override + public void childParsed(Node pChild) { + AbstractScalarValueNode abstScalarValNode = (AbstractScalarValueNode) pChild; + this.iType = abstScalarValNode.getType(); + this.iValue = abstScalarValNode.getValue(); + this.iHasChild = true; + } + + @Override + public void testCompletness() throws SAXException { + if (!this.iHasChild) throw new SAXException("KEYBINDING node must have a KEYVALUE or VALUE_REFERENCE child node!"); + } + + /** + * getCIMProperty + * + * @return CIMProperty + */ + public CIMProperty getCIMProperty() { + // CIMProperty( + // String name, CIMDataType type, Object value, boolean key, boolean + // propagated, String originClass + // ) + return new CIMProperty(this.iName, this.iType, this.iValue, true, false, null); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/KeyValueNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/KeyValueNode.java similarity index 72% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/KeyValueNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/KeyValueNode.java index 7a5f6d3..e075e32 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/KeyValueNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/KeyValueNode.java @@ -1,224 +1,228 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1714878 2007-05-08 ebak Empty string property values are parsed as nulls - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 1769504 2007-08-08 ebak Type identification for VALUETYPE="numeric" - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2823494 2009-08-03 rgummada Change Boolean constructor to static - * 3572993 2012-10-01 blaschke-oss parseDouble("2.2250738585072012e-308") DoS vulnerability - * 3602604 2013-01-29 blaschke-oss Clean up SAXException messages - * 2604 2013-07-01 blaschke-oss SAXException messages should contain node name - * 2683 2013-10-07 blaschke-oss KEYVALUE VALUETYPE optional, "string" default - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMDateTimeAbsolute; -import org.sentrysoftware.wbem.javax.cim.CIMDateTimeInterval; -import org.sentrysoftware.wbem.javax.cim.UnsignedInteger64; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.CIMObjectFactory; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.MOF; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.Util; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConfiguration; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT KEYVALUE (#PCDATA) ATTLIST KEYVALUE VALUETYPE (string | boolean | - * numeric) "string" %CIMType; #IMPLIED - */ -public class KeyValueNode extends AbstractScalarValueNode { - - private CIMDataType iType; - - private String iValueTypeStr; - - private Object iValue; - - /** - * Ctor. - */ - public KeyValueNode() { - super(KEYVALUE); - } - - /** - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iType = getCIMType(pAttribs, true); - this.iValue = null; - if (this.iType != null) { - if (this.iType.isArray()) throw new SAXException("KEYVALUE node cannot be array typed!"); - return; - } - // let's see the VALUETYPE attribute - this.iValueTypeStr = pAttribs.getValue("VALUETYPE"); - if (this.iValueTypeStr == null) this.iValueTypeStr = "string"; - } - - @Override - public void parseData(String pData) throws SAXException { - if (this.iType == null) { - setTypeAndValue(pData); - } else { - this.iValue = CIMObjectFactory.getObject(this.iType, pData); - } - } - - /** - * @param pNodeNameEnum - */ - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - throw new SAXException("KEYVALUE node cannot have any child nodes!"); - } - - /** - * @param pChild - */ - @Override - public void childParsed(Node pChild) { - // no child - } - - @Override - public void testCompletness() { - // nothing to do - } - - public Object getValue() { - /* - * null key values are not allowed, empty #PCDATA means empty String - */ - return this.iValue == null ? "" : this.iValue; - } - - public CIMDataType getType() { - return this.iType; - } - - private void setTypeAndValue(String pValue) throws SAXException { - // determine iType from iValueTypeStr if required - if (this.iType != null) return; - - if (this.iValueTypeStr.equals("numeric")) { - if (!setUInt64(pValue) && !setSInt64(pValue) && !setReal64(pValue)) throw new SAXException( - "Unparseable \"number\" value in " + getNodeName() + " node: " + pValue + "!"); - } else if (this.iValueTypeStr.equals(MOF.DT_STR)) { - if (!setDTAbsolute(pValue) && !setDTInterval(pValue)) { - this.iValue = pValue; - this.iType = CIMDataType.STRING_T; - } - } else if (this.iValueTypeStr.equals(MOF.DT_BOOL)) { - if (!setBoolean(pValue)) throw new SAXException("Unparseable \"boolean\" value in " - + getNodeName() + " node: " + pValue + "!"); - } else { - throw new SAXException("KEYVALUE node's VALUETYPE attribute must be " + MOF.DT_STR - + ", " + MOF.DT_BOOL + " or numeric! " + pValue + " is not allowed!"); - } - } - - private boolean setUInt64(String pValue) { - try { - this.iValue = new UnsignedInteger64(pValue); - } catch (NumberFormatException e) { - return false; - } - this.iType = CIMDataType.UINT64_T; - return true; - } - - private boolean setSInt64(String pValue) { - try { - this.iValue = new Long(pValue); - } catch (NumberFormatException e) { - return false; - } - this.iType = CIMDataType.SINT64_T; - return true; - } - - private boolean setReal64(String pValue) { - try { - if (WBEMConfiguration.getGlobalConfiguration().verifyJavaLangDoubleStrings()) { - if (Util.isBadDoubleString(pValue)) return false; - } - this.iValue = new Double(pValue); - } catch (NumberFormatException e) { - return false; - } - this.iType = CIMDataType.REAL64_T; - return true; - } - - private boolean setBoolean(String pValue) { - this.iValue = Boolean.valueOf(pValue); - this.iType = CIMDataType.BOOLEAN_T; - return true; - } - - private boolean setDTAbsolute(String pValue) { - try { - this.iValue = new CIMDateTimeAbsolute(pValue); - } catch (IllegalArgumentException e) { - return false; - } - this.iType = CIMDataType.DATETIME_T; - return true; - } - - private boolean setDTInterval(String pValue) { - try { - this.iValue = new CIMDateTimeInterval(pValue); - } catch (IllegalArgumentException e) { - return false; - } - this.iType = CIMDataType.DATETIME_T; - return true; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1714878 2007-05-08 ebak Empty string property values are parsed as nulls + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 1769504 2007-08-08 ebak Type identification for VALUETYPE="numeric" + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2823494 2009-08-03 rgummada Change Boolean constructor to static + * 3572993 2012-10-01 blaschke-oss parseDouble("2.2250738585072012e-308") DoS vulnerability + * 3602604 2013-01-29 blaschke-oss Clean up SAXException messages + * 2604 2013-07-01 blaschke-oss SAXException messages should contain node name + * 2683 2013-10-07 blaschke-oss KEYVALUE VALUETYPE optional, "string" default + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMDateTimeAbsolute; +import org.metricshub.wbem.javax.cim.CIMDateTimeInterval; +import org.metricshub.wbem.javax.cim.UnsignedInteger64; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.CIMObjectFactory; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.metricshub.wbem.sblim.cimclient.internal.util.MOF; +import org.metricshub.wbem.sblim.cimclient.internal.util.Util; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfiguration; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT KEYVALUE (#PCDATA) ATTLIST KEYVALUE VALUETYPE (string | boolean | + * numeric) "string" %CIMType; #IMPLIED + */ +public class KeyValueNode extends AbstractScalarValueNode { + private CIMDataType iType; + + private String iValueTypeStr; + + private Object iValue; + + /** + * Ctor. + */ + public KeyValueNode() { + super(KEYVALUE); + } + + /** + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iType = getCIMType(pAttribs, true); + this.iValue = null; + if (this.iType != null) { + if (this.iType.isArray()) throw new SAXException("KEYVALUE node cannot be array typed!"); + return; + } + // let's see the VALUETYPE attribute + this.iValueTypeStr = pAttribs.getValue("VALUETYPE"); + if (this.iValueTypeStr == null) this.iValueTypeStr = "string"; + } + + @Override + public void parseData(String pData) throws SAXException { + if (this.iType == null) { + setTypeAndValue(pData); + } else { + this.iValue = CIMObjectFactory.getObject(this.iType, pData); + } + } + + /** + * @param pNodeNameEnum + */ + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + throw new SAXException("KEYVALUE node cannot have any child nodes!"); + } + + /** + * @param pChild + */ + @Override + public void childParsed(Node pChild) { + // no child + } + + @Override + public void testCompletness() { + // nothing to do + } + + public Object getValue() { + /* + * null key values are not allowed, empty #PCDATA means empty String + */ + return this.iValue == null ? "" : this.iValue; + } + + public CIMDataType getType() { + return this.iType; + } + + private void setTypeAndValue(String pValue) throws SAXException { + // determine iType from iValueTypeStr if required + if (this.iType != null) return; + + if (this.iValueTypeStr.equals("numeric")) { + if (!setUInt64(pValue) && !setSInt64(pValue) && !setReal64(pValue)) throw new SAXException( + "Unparseable \"number\" value in " + getNodeName() + " node: " + pValue + "!" + ); + } else if (this.iValueTypeStr.equals(MOF.DT_STR)) { + if (!setDTAbsolute(pValue) && !setDTInterval(pValue)) { + this.iValue = pValue; + this.iType = CIMDataType.STRING_T; + } + } else if (this.iValueTypeStr.equals(MOF.DT_BOOL)) { + if (!setBoolean(pValue)) throw new SAXException( + "Unparseable \"boolean\" value in " + getNodeName() + " node: " + pValue + "!" + ); + } else { + throw new SAXException( + "KEYVALUE node's VALUETYPE attribute must be " + + MOF.DT_STR + + ", " + + MOF.DT_BOOL + + " or numeric! " + + pValue + + " is not allowed!" + ); + } + } + + private boolean setUInt64(String pValue) { + try { + this.iValue = new UnsignedInteger64(pValue); + } catch (NumberFormatException e) { + return false; + } + this.iType = CIMDataType.UINT64_T; + return true; + } + + private boolean setSInt64(String pValue) { + try { + this.iValue = new Long(pValue); + } catch (NumberFormatException e) { + return false; + } + this.iType = CIMDataType.SINT64_T; + return true; + } + + private boolean setReal64(String pValue) { + try { + if (WBEMConfiguration.getGlobalConfiguration().verifyJavaLangDoubleStrings()) { + if (Util.isBadDoubleString(pValue)) return false; + } + this.iValue = new Double(pValue); + } catch (NumberFormatException e) { + return false; + } + this.iType = CIMDataType.REAL64_T; + return true; + } + + private boolean setBoolean(String pValue) { + this.iValue = Boolean.valueOf(pValue); + this.iType = CIMDataType.BOOLEAN_T; + return true; + } + + private boolean setDTAbsolute(String pValue) { + try { + this.iValue = new CIMDateTimeAbsolute(pValue); + } catch (IllegalArgumentException e) { + return false; + } + this.iType = CIMDataType.DATETIME_T; + return true; + } + + private boolean setDTInterval(String pValue) { + try { + this.iValue = new CIMDateTimeInterval(pValue); + } catch (IllegalArgumentException e) { + return false; + } + this.iType = CIMDataType.DATETIME_T; + return true; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/LocalClassPathNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/LocalClassPathNode.java similarity index 65% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/LocalClassPathNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/LocalClassPathNode.java index 3aa8a67..9cacb6e 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/LocalClassPathNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/LocalClassPathNode.java @@ -1,136 +1,134 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1686000 2007-04-20 ebak modifyInstance() missing from WBEMClient - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2974884 2010-04-20 blaschke-oss Exception when attaching 2 CDRoms with invoke method - * 3602604 2013-01-29 blaschke-oss Clean up SAXException messages - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.LocalPathBuilder; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT LOCALCLASSPATH (LOCALNAMESPACEPATH, CLASSNAME) - */ -public class LocalClassPathNode extends AbstractObjectPathNode { - - // LOCALNAMESPACEPATH - private boolean iHasLocalNameSpacePath, iHasClassName; - - private String iNameSpaceStr; - - // CLASSNAME - private String iClassNameStr; - - // --- - private CIMObjectPath iLocalPath; - - /** - * Ctor. - */ - public LocalClassPathNode() { - super(LOCALCLASSPATH); - } - - /** - * @param pAttribs - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - this.iLocalPath = pSession.getDefLocalPath(); - this.iHasLocalNameSpacePath = this.iHasClassName = false; - this.iNameSpaceStr = this.iClassNameStr = null; - // no attributes - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum == LOCALNAMESPACEPATH) { - if (this.iHasLocalNameSpacePath) throw new SAXException( - "LOCALCLASSPATH node already has a LOCALNAMESPACEPATH child node!"); - } else if (pNodeNameEnum == CLASSNAME) { - if (this.iHasClassName) throw new SAXException( - "LOCALCLASSPATH node already has a CLASSNAME child node!"); - } else throw new SAXException("LOCALCLASSPATH node cannot have " + pNodeNameEnum - + " child node!" - + " It can have LOCALNAMESPACEPATH and CLASSNAME child nodes only!"); - } - - @Override - public void childParsed(Node pChild) { - if (pChild instanceof LocalNameSpacePathNode) { - this.iNameSpaceStr = ((LocalNameSpacePathNode) pChild).getNameSpace(); - this.iHasLocalNameSpacePath = true; - } else { - this.iClassNameStr = ((ClassNameNode) pChild).getClassName(); - this.iHasClassName = true; - } - } - - @Override - public void testCompletness() throws SAXException { - if (!this.iHasLocalNameSpacePath) throw new SAXException( - "LOCALNAMESPACE child node is mandatory for LOCALCLASSPATH node!"); - if (!this.iHasClassName) throw new SAXException( - "CLASSNAME child node is mandatory for LOCALCLASSPATH node!"); - } - - public CIMObjectPath getCIMObjectPath() { - return LocalPathBuilder.build(this.iLocalPath, this.iClassNameStr, this.iNameSpaceStr); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1686000 2007-04-20 ebak modifyInstance() missing from WBEMClient + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2974884 2010-04-20 blaschke-oss Exception when attaching 2 CDRoms with invoke method + * 3602604 2013-01-29 blaschke-oss Clean up SAXException messages + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.LocalPathBuilder; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT LOCALCLASSPATH (LOCALNAMESPACEPATH, CLASSNAME) + */ +public class LocalClassPathNode extends AbstractObjectPathNode { + // LOCALNAMESPACEPATH + private boolean iHasLocalNameSpacePath, iHasClassName; + + private String iNameSpaceStr; + + // CLASSNAME + private String iClassNameStr; + + // --- + private CIMObjectPath iLocalPath; + + /** + * Ctor. + */ + public LocalClassPathNode() { + super(LOCALCLASSPATH); + } + + /** + * @param pAttribs + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + this.iLocalPath = pSession.getDefLocalPath(); + this.iHasLocalNameSpacePath = this.iHasClassName = false; + this.iNameSpaceStr = this.iClassNameStr = null; + // no attributes + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum == LOCALNAMESPACEPATH) { + if (this.iHasLocalNameSpacePath) throw new SAXException( + "LOCALCLASSPATH node already has a LOCALNAMESPACEPATH child node!" + ); + } else if (pNodeNameEnum == CLASSNAME) { + if (this.iHasClassName) throw new SAXException("LOCALCLASSPATH node already has a CLASSNAME child node!"); + } else throw new SAXException( + "LOCALCLASSPATH node cannot have " + + pNodeNameEnum + + " child node!" + + " It can have LOCALNAMESPACEPATH and CLASSNAME child nodes only!" + ); + } + + @Override + public void childParsed(Node pChild) { + if (pChild instanceof LocalNameSpacePathNode) { + this.iNameSpaceStr = ((LocalNameSpacePathNode) pChild).getNameSpace(); + this.iHasLocalNameSpacePath = true; + } else { + this.iClassNameStr = ((ClassNameNode) pChild).getClassName(); + this.iHasClassName = true; + } + } + + @Override + public void testCompletness() throws SAXException { + if (!this.iHasLocalNameSpacePath) throw new SAXException( + "LOCALNAMESPACE child node is mandatory for LOCALCLASSPATH node!" + ); + if (!this.iHasClassName) throw new SAXException("CLASSNAME child node is mandatory for LOCALCLASSPATH node!"); + } + + public CIMObjectPath getCIMObjectPath() { + return LocalPathBuilder.build(this.iLocalPath, this.iClassNameStr, this.iNameSpaceStr); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/LocalInstancePathNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/LocalInstancePathNode.java similarity index 66% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/LocalInstancePathNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/LocalInstancePathNode.java index 0624ef6..74b4c91 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/LocalInstancePathNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/LocalInstancePathNode.java @@ -1,145 +1,140 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import org.sentrysoftware.wbem.javax.cim.CIMProperty; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.LocalPathBuilder; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT LOCALINSTANCEPATH (LOCALNAMESPACEPATH, INSTANCENAME) - */ -public class LocalInstancePathNode extends AbstractObjectPathNode { - - // LOCALNAMESPACEPATH - private boolean iHasLocalNameSpacePath; - - private String iNameSpaceStr; - - // INSTANCENAME - private boolean iHasInstanceName; - - private String iClassNameStr; - - private CIMProperty[] iKeys; - - // base localpath - private CIMObjectPath iLocalPath; - - /** - * Ctor. - */ - public LocalInstancePathNode() { - super(LOCALINSTANCEPATH); - } - - /** - * @param pAttribs - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - this.iLocalPath = pSession.getDefLocalPath(); - this.iHasLocalNameSpacePath = this.iHasInstanceName = false; - this.iNameSpaceStr = this.iClassNameStr = null; - this.iKeys = null; - // no attributes - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum == LOCALNAMESPACEPATH) { - if (this.iHasLocalNameSpacePath) throw new SAXException(getNodeName() - + " node can have only one LOCALNAMESPACEPATH child node!"); - } else if (pNodeNameEnum == INSTANCENAME) { - if (this.iHasInstanceName) throw new SAXException(getNodeName() - + " node can have only one INSTANCENAME child node!"); - } else throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum - + " child node!"); - } - - @Override - public void childParsed(Node pChild) { - if (pChild instanceof LocalNameSpacePathNode) { - this.iHasLocalNameSpacePath = true; - this.iNameSpaceStr = ((LocalNameSpacePathNode) pChild).getNameSpace(); - } else { - this.iHasInstanceName = true; - InstanceNameNode instNameNode = (InstanceNameNode) pChild; - this.iClassNameStr = instNameNode.getClassName(); - this.iKeys = instNameNode.getKeys(); - } - } - - @Override - public void testCompletness() throws SAXException { - if (!this.iHasLocalNameSpacePath) throw new SAXException(getNodeName() - + " node must have a LOCALNAMESPACEPATH child node!"); - if (!this.iHasInstanceName) throw new SAXException(getNodeName() - + " node must have a INSTANCENAME child node!"); - } - - public CIMObjectPath getCIMObjectPath() { - // CIMObjectPath(String objectName, String namespace, CIMProperty[] - // keys) - return LocalPathBuilder.build(this.iLocalPath, this.iClassNameStr, this.iNameSpaceStr, - this.iKeys); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.cim.CIMProperty; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.LocalPathBuilder; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT LOCALINSTANCEPATH (LOCALNAMESPACEPATH, INSTANCENAME) + */ +public class LocalInstancePathNode extends AbstractObjectPathNode { + // LOCALNAMESPACEPATH + private boolean iHasLocalNameSpacePath; + + private String iNameSpaceStr; + + // INSTANCENAME + private boolean iHasInstanceName; + + private String iClassNameStr; + + private CIMProperty[] iKeys; + + // base localpath + private CIMObjectPath iLocalPath; + + /** + * Ctor. + */ + public LocalInstancePathNode() { + super(LOCALINSTANCEPATH); + } + + /** + * @param pAttribs + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + this.iLocalPath = pSession.getDefLocalPath(); + this.iHasLocalNameSpacePath = this.iHasInstanceName = false; + this.iNameSpaceStr = this.iClassNameStr = null; + this.iKeys = null; + // no attributes + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum == LOCALNAMESPACEPATH) { + if (this.iHasLocalNameSpacePath) throw new SAXException( + getNodeName() + " node can have only one LOCALNAMESPACEPATH child node!" + ); + } else if (pNodeNameEnum == INSTANCENAME) { + if (this.iHasInstanceName) throw new SAXException( + getNodeName() + " node can have only one INSTANCENAME child node!" + ); + } else throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!"); + } + + @Override + public void childParsed(Node pChild) { + if (pChild instanceof LocalNameSpacePathNode) { + this.iHasLocalNameSpacePath = true; + this.iNameSpaceStr = ((LocalNameSpacePathNode) pChild).getNameSpace(); + } else { + this.iHasInstanceName = true; + InstanceNameNode instNameNode = (InstanceNameNode) pChild; + this.iClassNameStr = instNameNode.getClassName(); + this.iKeys = instNameNode.getKeys(); + } + } + + @Override + public void testCompletness() throws SAXException { + if (!this.iHasLocalNameSpacePath) throw new SAXException( + getNodeName() + " node must have a LOCALNAMESPACEPATH child node!" + ); + if (!this.iHasInstanceName) throw new SAXException(getNodeName() + " node must have a INSTANCENAME child node!"); + } + + public CIMObjectPath getCIMObjectPath() { + // CIMObjectPath(String objectName, String namespace, CIMProperty[] + // keys) + return LocalPathBuilder.build(this.iLocalPath, this.iClassNameStr, this.iNameSpaceStr, this.iKeys); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/LocalNameSpacePathNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/LocalNameSpacePathNode.java similarity index 64% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/LocalNameSpacePathNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/LocalNameSpacePathNode.java index 1f6e362..dd12394 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/LocalNameSpacePathNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/LocalNameSpacePathNode.java @@ -1,141 +1,140 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1686000 2007-04-20 ebak modifyInstance() missing from WBEMClient - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 3521119 2012-04-24 blaschke-oss JSR48 1.0.0: remove CIMObjectPath 2/3/4-parm ctors - * 2711 2013-11-13 blaschke-oss LOCALNAMESPACEPATH allows 0 NAMESPACE children - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConfiguration; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT LOCALNAMESPACEPATH (NAMESPACE+) - */ -public class LocalNameSpacePathNode extends AbstractPathNode { - - private StringBuffer iNameSpaceStrBuf; - - private String iNameSpaceStr; - - private CIMObjectPath iNameSpacePath; - - private CIMObjectPath iLocalPath; - - /** - * Ctor. - */ - public LocalNameSpacePathNode() { - super(LOCALNAMESPACEPATH); - } - - /** - * @param pAttribs - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - this.iLocalPath = pSession.getDefLocalPath(); - this.iNameSpaceStrBuf = null; - this.iNameSpaceStr = null; - this.iNameSpacePath = null; - // no attributes - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum != NAMESPACE) throw new SAXException(getNodeName() - + " node can have NAMESPACE child node only! " + pNodeNameEnum - + " child node is invalid!"); - } - - @Override - public void childParsed(Node pChild) { - String nsStr = ((NameSpaceNode) pChild).getNameSpace(); - if (this.iNameSpaceStrBuf == null) { - this.iNameSpaceStrBuf = new StringBuffer(nsStr); - } else { - this.iNameSpaceStrBuf.append('/' + nsStr); - } - } - - @Override - public void testCompletness() throws SAXException { - if (this.iNameSpaceStrBuf == null) { - if (WBEMConfiguration.getGlobalConfiguration().allowEmptyLocalNameSpacePath() - && this.iLocalPath != null && this.iLocalPath.getNamespace() != null) return; - throw new SAXException(getNodeName() - + " node must have at least one NAMESPACE child node!"); - } - } - - /** - * getNameSpace - * - * @return String - */ - public String getNameSpace() { - if (this.iNameSpaceStr != null) return this.iNameSpaceStr; - return this.iNameSpaceStr = (this.iNameSpaceStrBuf == null ? this.iLocalPath.getNamespace() - : this.iNameSpaceStrBuf.toString()); - } - - public CIMObjectPath getCIMObjectPath() { - if (this.iNameSpacePath != null) return this.iNameSpacePath; - return this.iNameSpacePath = new CIMObjectPath(null, null, null, getNameSpace(), null, null); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1686000 2007-04-20 ebak modifyInstance() missing from WBEMClient + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 3521119 2012-04-24 blaschke-oss JSR48 1.0.0: remove CIMObjectPath 2/3/4-parm ctors + * 2711 2013-11-13 blaschke-oss LOCALNAMESPACEPATH allows 0 NAMESPACE children + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfiguration; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT LOCALNAMESPACEPATH (NAMESPACE+) + */ +public class LocalNameSpacePathNode extends AbstractPathNode { + private StringBuffer iNameSpaceStrBuf; + + private String iNameSpaceStr; + + private CIMObjectPath iNameSpacePath; + + private CIMObjectPath iLocalPath; + + /** + * Ctor. + */ + public LocalNameSpacePathNode() { + super(LOCALNAMESPACEPATH); + } + + /** + * @param pAttribs + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + this.iLocalPath = pSession.getDefLocalPath(); + this.iNameSpaceStrBuf = null; + this.iNameSpaceStr = null; + this.iNameSpacePath = null; + // no attributes + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum != NAMESPACE) throw new SAXException( + getNodeName() + " node can have NAMESPACE child node only! " + pNodeNameEnum + " child node is invalid!" + ); + } + + @Override + public void childParsed(Node pChild) { + String nsStr = ((NameSpaceNode) pChild).getNameSpace(); + if (this.iNameSpaceStrBuf == null) { + this.iNameSpaceStrBuf = new StringBuffer(nsStr); + } else { + this.iNameSpaceStrBuf.append('/' + nsStr); + } + } + + @Override + public void testCompletness() throws SAXException { + if (this.iNameSpaceStrBuf == null) { + if ( + WBEMConfiguration.getGlobalConfiguration().allowEmptyLocalNameSpacePath() && + this.iLocalPath != null && + this.iLocalPath.getNamespace() != null + ) return; + throw new SAXException(getNodeName() + " node must have at least one NAMESPACE child node!"); + } + } + + /** + * getNameSpace + * + * @return String + */ + public String getNameSpace() { + if (this.iNameSpaceStr != null) return this.iNameSpaceStr; + return ( + this.iNameSpaceStr = + (this.iNameSpaceStrBuf == null ? this.iLocalPath.getNamespace() : this.iNameSpaceStrBuf.toString()) + ); + } + + public CIMObjectPath getCIMObjectPath() { + if (this.iNameSpacePath != null) return this.iNameSpacePath; + return this.iNameSpacePath = new CIMObjectPath(null, null, null, getNameSpace(), null, null); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MessageNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MessageNode.java similarity index 65% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MessageNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MessageNode.java index aecabf6..6b297da 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MessageNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MessageNode.java @@ -1,136 +1,138 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT MESSAGE (SIMPLEREQ | MULTIREQ | SIMPLERSP | MULTIRSP | SIMPLEEXPREQ | MULTIEXPREQ |
      - *    SIMPLEEXPRSP | MULTIEXPRSP)
      - * ATTLIST MESSAGE
      - *    ID CDATA #REQUIRED
      - *    PROTOCOLVERSION CDATA #REQUIRED
      - * 
      - */ -public class MessageNode extends Node implements NonVolatileIf { - - private String iID; - - private String iProtocolVersion; - - private AbstractMessageNode iAbstractMsgNode; - - /** - * Ctor. - */ - public MessageNode() { - super(MESSAGE); - } - - public void addChild(Node pChild) { - this.iAbstractMsgNode = (AbstractMessageNode) pChild; - } - - /** - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iID = pAttribs.getValue("ID"); - if (this.iID == null) throw new SAXException("ID attribute is mandatory for MESSAGE node!"); - this.iProtocolVersion = pAttribs.getValue("PROTOCOLVERSION"); - if (this.iProtocolVersion == null) throw new SAXException( - "PROTOCOLVERSION attribute is mandatory for MESSAGE node!"); - this.iAbstractMsgNode = null; - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - private static final String[] ALLOWED_CHILDREN = { SIMPLEREQ, MULTIREQ, SIMPLERSP, MULTIRSP, - SIMPLEEXPREQ, MULTIEXPREQ, SIMPLEEXPRSP, MULTIEXPRSP }; - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (this.iAbstractMsgNode != null) throw new SAXException( - "MESSAGE node can have only one child node!"); - for (int i = 0; i < ALLOWED_CHILDREN.length; i++) - if (pNodeNameEnum == ALLOWED_CHILDREN[i]) return; - throw new SAXException("MESSAGE node cannot have " + pNodeNameEnum + " child node!"); - } - - /** - * @param pChild - */ - @Override - public void childParsed(Node pChild) { - // nothing to do - } - - @Override - public void testCompletness() throws SAXException { - if (this.iAbstractMsgNode == null) throw new SAXException( - "MESSAGE node must have a child node!"); - } - - /** - * getAbstractMessageNode - * - * @return AbstractMessageNode - */ - public AbstractMessageNode getAbstractMessageNode() { - return this.iAbstractMsgNode; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT MESSAGE (SIMPLEREQ | MULTIREQ | SIMPLERSP | MULTIRSP | SIMPLEEXPREQ | MULTIEXPREQ |
      + *    SIMPLEEXPRSP | MULTIEXPRSP)
      + * ATTLIST MESSAGE
      + *    ID CDATA #REQUIRED
      + *    PROTOCOLVERSION CDATA #REQUIRED
      + * 
      + */ +public class MessageNode extends Node implements NonVolatileIf { + private String iID; + + private String iProtocolVersion; + + private AbstractMessageNode iAbstractMsgNode; + + /** + * Ctor. + */ + public MessageNode() { + super(MESSAGE); + } + + public void addChild(Node pChild) { + this.iAbstractMsgNode = (AbstractMessageNode) pChild; + } + + /** + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iID = pAttribs.getValue("ID"); + if (this.iID == null) throw new SAXException("ID attribute is mandatory for MESSAGE node!"); + this.iProtocolVersion = pAttribs.getValue("PROTOCOLVERSION"); + if (this.iProtocolVersion == null) throw new SAXException( + "PROTOCOLVERSION attribute is mandatory for MESSAGE node!" + ); + this.iAbstractMsgNode = null; + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + private static final String[] ALLOWED_CHILDREN = { + SIMPLEREQ, + MULTIREQ, + SIMPLERSP, + MULTIRSP, + SIMPLEEXPREQ, + MULTIEXPREQ, + SIMPLEEXPRSP, + MULTIEXPRSP + }; + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (this.iAbstractMsgNode != null) throw new SAXException("MESSAGE node can have only one child node!"); + for (int i = 0; i < ALLOWED_CHILDREN.length; i++) if (pNodeNameEnum == ALLOWED_CHILDREN[i]) return; + throw new SAXException("MESSAGE node cannot have " + pNodeNameEnum + " child node!"); + } + + /** + * @param pChild + */ + @Override + public void childParsed(Node pChild) { + // nothing to do + } + + @Override + public void testCompletness() throws SAXException { + if (this.iAbstractMsgNode == null) throw new SAXException("MESSAGE node must have a child node!"); + } + + /** + * getAbstractMessageNode + * + * @return AbstractMessageNode + */ + public AbstractMessageNode getAbstractMessageNode() { + return this.iAbstractMsgNode; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MethodCallNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MethodCallNode.java similarity index 64% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MethodCallNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MethodCallNode.java index a4c8963..ec3d8d6 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MethodCallNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MethodCallNode.java @@ -1,79 +1,79 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1686000 2007-04-20 ebak modifyInstance() missing from WBEMClient - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2682 2013-10-02 blaschke-oss (I)MethodCallNode allows no LOCAL*PATH - * 2690 2013-10-11 blaschke-oss Remove RESPONSEDESTINATION support - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.xml.sax.SAXException; - -/** - * ELEMENT METHODCALL ((LOCALINSTANCEPATH | LOCALCLASSPATH), PARAMVALUE*) - * ATTLIST METHODCALL %CIMName; - */ -public class MethodCallNode extends AbstractMethodCallNode { - - /** - * Ctor. - */ - public MethodCallNode() { - super(METHODCALL); - } - - @Override - protected void testSpecChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum == LOCALCLASSPATH || pNodeNameEnum == LOCALINSTANCEPATH) { - if (this.iPath != null) throw new SAXException(getNodeName() - + " node can have only one LOCALINSTANCEPATH or LOCALCLASSPATH child node!"); - } else if (pNodeNameEnum != PARAMVALUE) throw new SAXException(getNodeName() - + " node cannot have " + pNodeNameEnum + " child node!"); - } - - @Override - public void testCompletness() throws SAXException { - if (this.iPath == null) throw new SAXException( - "METHODCALL node must have a LOCALINSTANCEPATH or LOCALCLASSPATH child node!"); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1686000 2007-04-20 ebak modifyInstance() missing from WBEMClient + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2682 2013-10-02 blaschke-oss (I)MethodCallNode allows no LOCAL*PATH + * 2690 2013-10-11 blaschke-oss Remove RESPONSEDESTINATION support + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.xml.sax.SAXException; + +/** + * ELEMENT METHODCALL ((LOCALINSTANCEPATH | LOCALCLASSPATH), PARAMVALUE*) + * ATTLIST METHODCALL %CIMName; + */ +public class MethodCallNode extends AbstractMethodCallNode { + + /** + * Ctor. + */ + public MethodCallNode() { + super(METHODCALL); + } + + @Override + protected void testSpecChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum == LOCALCLASSPATH || pNodeNameEnum == LOCALINSTANCEPATH) { + if (this.iPath != null) throw new SAXException( + getNodeName() + " node can have only one LOCALINSTANCEPATH or LOCALCLASSPATH child node!" + ); + } else if (pNodeNameEnum != PARAMVALUE) throw new SAXException( + getNodeName() + " node cannot have " + pNodeNameEnum + " child node!" + ); + } + + @Override + public void testCompletness() throws SAXException { + if (this.iPath == null) throw new SAXException( + "METHODCALL node must have a LOCALINSTANCEPATH or LOCALCLASSPATH child node!" + ); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MethodNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MethodNode.java similarity index 66% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MethodNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MethodNode.java index e9979f1..2914ee6 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MethodNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MethodNode.java @@ -1,178 +1,179 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 1848607 2007-12-11 ebak Strict EmbeddedObject types - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 3602604 2013-01-29 blaschke-oss Clean up SAXException messages - * 2703 2013-11-08 blaschke-oss MethodNode should not require TYPE attribute - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMMethod; -import org.sentrysoftware.wbem.javax.cim.CIMParameter; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.EmbObjHandler; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * 
      - * ELEMENT METHOD (QUALIFIER*, (PARAMETER | PARAMETER.REFERENCE | PARAMETER.ARRAY | PARAMETER.REFARRAY)*)
      - * ATTLIST METHOD
      - *   %CIMName;
      - *   %CIMType;              #IMPLIED
      - *   %ClassOrigin;
      - *   %Propagated;>
      - * 
      - */ -public class MethodNode extends Node { - - private String iName; - - private CIMDataType iType; - - private String iClassOrigin; - - private boolean iPropagated; - - private QualifiedNodeHandler iQualiHandler; - - private EmbObjHandler iEmbObjHandler; - - private SAXSession iSession; - - /** - * PARAMETER.XXX*, AbstractParameterNode* - */ - private ArrayList> iCIMParamAL; - - /** - * Ctor. - */ - public MethodNode() { - super(METHOD); - } - - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iSession = pSession; - this.iQualiHandler = QualifiedNodeHandler.init(this.iQualiHandler); - this.iEmbObjHandler = EmbObjHandler.init(this.iEmbObjHandler, getNodeName(), pAttribs, - this.iSession, this.iQualiHandler, true); - - if (this.iCIMParamAL != null) this.iCIMParamAL.clear(); - - this.iName = getCIMName(pAttribs); - - this.iType = getCIMType(pAttribs, true); - if (this.iType != null && this.iType.isArray()) throw new SAXException( - "METHOD node's TYPE cannot be an array!"); - this.iClassOrigin = getClassOrigin(pAttribs); - this.iPropagated = getPropagated(pAttribs); - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - private static final String[] ALLOWED_CHILDREN = { QUALIFIER, PARAMETER, PARAMETER_REFERENCE, - PARAMETER_ARRAY, PARAMETER_REFARRAY }; - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - for (int i = 0; i < ALLOWED_CHILDREN.length; i++) - if (pNodeNameEnum.equalsIgnoreCase(ALLOWED_CHILDREN[i])) return; - throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum - + " child node!"); - } - - @Override - public void childParsed(Node pChild) { - if (this.iQualiHandler.addQualifierNode(pChild)) return; - if (this.iCIMParamAL == null) this.iCIMParamAL = new ArrayList>(); - this.iCIMParamAL.add(((AbstractParameterNode) pChild).getCIMParameter()); - } - - @Override - public void testCompletness() throws SAXException { - this.iType = this.iEmbObjHandler.getType(); - if (this.iType != null && this.iType.isArray()) throw new SAXException( - "METHOD node's TYPE attribute cannot be an array!"); - } - - /** - * getCIMMethod - * - * @return CIMMethod - */ - public CIMMethod getCIMMethod() { - /* - * CIMMethod( String name, CIMDataType type, CIMQualifier[] qualifiers, - * CIMParameter[] parameters, boolean propagated, String originClass ); - * - * EmbeddedObject qualifier mustn't be removed. Return type cannot be - * changed. - * - * The situation changed by the introduction of the strict embedded - * object type parsing. - */ - return new CIMMethod(this.iName, this.iType, this.iQualiHandler - .getQualis(!this.iSession.strictEmbObjParsing()), this.iCIMParamAL == null ? null - : (CIMParameter[]) this.iCIMParamAL.toArray(EMPTY_PA), this.iPropagated, - this.iClassOrigin); - } - - private static final CIMParameter[] EMPTY_PA = new CIMParameter[0]; - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 1848607 2007-12-11 ebak Strict EmbeddedObject types + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 3602604 2013-01-29 blaschke-oss Clean up SAXException messages + * 2703 2013-11-08 blaschke-oss MethodNode should not require TYPE attribute + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMMethod; +import org.metricshub.wbem.javax.cim.CIMParameter; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.EmbObjHandler; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + *
      + * ELEMENT METHOD (QUALIFIER*, (PARAMETER | PARAMETER.REFERENCE | PARAMETER.ARRAY | PARAMETER.REFARRAY)*)
      + * ATTLIST METHOD
      + *   %CIMName;
      + *   %CIMType;              #IMPLIED
      + *   %ClassOrigin;
      + *   %Propagated;>
      + * 
      + */ +public class MethodNode extends Node { + private String iName; + + private CIMDataType iType; + + private String iClassOrigin; + + private boolean iPropagated; + + private QualifiedNodeHandler iQualiHandler; + + private EmbObjHandler iEmbObjHandler; + + private SAXSession iSession; + + /** + * PARAMETER.XXX*, AbstractParameterNode* + */ + private ArrayList> iCIMParamAL; + + /** + * Ctor. + */ + public MethodNode() { + super(METHOD); + } + + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iSession = pSession; + this.iQualiHandler = QualifiedNodeHandler.init(this.iQualiHandler); + this.iEmbObjHandler = + EmbObjHandler.init(this.iEmbObjHandler, getNodeName(), pAttribs, this.iSession, this.iQualiHandler, true); + + if (this.iCIMParamAL != null) this.iCIMParamAL.clear(); + + this.iName = getCIMName(pAttribs); + + this.iType = getCIMType(pAttribs, true); + if (this.iType != null && this.iType.isArray()) throw new SAXException("METHOD node's TYPE cannot be an array!"); + this.iClassOrigin = getClassOrigin(pAttribs); + this.iPropagated = getPropagated(pAttribs); + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + private static final String[] ALLOWED_CHILDREN = { + QUALIFIER, + PARAMETER, + PARAMETER_REFERENCE, + PARAMETER_ARRAY, + PARAMETER_REFARRAY + }; + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + for (int i = 0; i < ALLOWED_CHILDREN.length; i++) if (pNodeNameEnum.equalsIgnoreCase(ALLOWED_CHILDREN[i])) return; + throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!"); + } + + @Override + public void childParsed(Node pChild) { + if (this.iQualiHandler.addQualifierNode(pChild)) return; + if (this.iCIMParamAL == null) this.iCIMParamAL = new ArrayList>(); + this.iCIMParamAL.add(((AbstractParameterNode) pChild).getCIMParameter()); + } + + @Override + public void testCompletness() throws SAXException { + this.iType = this.iEmbObjHandler.getType(); + if (this.iType != null && this.iType.isArray()) throw new SAXException( + "METHOD node's TYPE attribute cannot be an array!" + ); + } + + /** + * getCIMMethod + * + * @return CIMMethod + */ + public CIMMethod getCIMMethod() { + /* + * CIMMethod( String name, CIMDataType type, CIMQualifier[] qualifiers, + * CIMParameter[] parameters, boolean propagated, String originClass ); + * + * EmbeddedObject qualifier mustn't be removed. Return type cannot be + * changed. + * + * The situation changed by the introduction of the strict embedded + * object type parsing. + */ + return new CIMMethod( + this.iName, + this.iType, + this.iQualiHandler.getQualis(!this.iSession.strictEmbObjParsing()), + this.iCIMParamAL == null ? null : (CIMParameter[]) this.iCIMParamAL.toArray(EMPTY_PA), + this.iPropagated, + this.iClassOrigin + ); + } + + private static final CIMParameter[] EMPTY_PA = new CIMParameter[0]; +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MethodResponseNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MethodResponseNode.java similarity index 66% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MethodResponseNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MethodResponseNode.java index b3736b9..8d23e10 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MethodResponseNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MethodResponseNode.java @@ -1,200 +1,204 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2845211 2009-08-27 raman_arora Pull Enumeration Feature (SAX Parser) - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - * 2697 2012-10-30 blaschke-oss (I)MethodResponseNode allows ERROR with PARAMVALUE - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; - -import org.sentrysoftware.wbem.javax.cim.CIMArgument; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.CIMError; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT METHODRESPONSE (ERROR|(RETURNVALUE?,PARAMVALUE*))
      - * ATTLIST METHODRESPONSE
      - *   %CIMName;
      - * 
      - */ -public class MethodResponseNode extends Node implements ErrorIf, RetValPipeIf, NonVolatileIf { - - private String iName; - - private CIMError iError; - - private Object iRetVal; - - private ArrayList> iCIMArgAL; - - private boolean iHasError; - - private boolean iHasRetVal; - - /** - * Ctor. - */ - public MethodResponseNode() { - super(METHODRESPONSE); - } - - /** - * @param pChild - */ - public void addChild(Node pChild) { - // nothing to do - } - - /** - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iName = getCIMName(pAttribs); - this.iError = null; - this.iRetVal = null; - if (this.iCIMArgAL != null) this.iCIMArgAL.clear(); - this.iHasError = false; - this.iHasRetVal = false; - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum == ERROR) { - String ownedNodeName; - if (this.iHasRetVal) ownedNodeName = RETURNVALUE; - else if (this.iHasError) ownedNodeName = ERROR; - else if (this.iCIMArgAL != null && this.iCIMArgAL.size() > 0) ownedNodeName = PARAMVALUE; - else ownedNodeName = null; - if (ownedNodeName != null) throw new SAXException(pNodeNameEnum - + " child node is invalid for " + getNodeName() - + " node, since it already has a " + ownedNodeName + " child node!"); - } else if (pNodeNameEnum == RETURNVALUE) { - String ownedNodeName; - if (this.iHasRetVal) ownedNodeName = RETURNVALUE; - else if (this.iHasError) ownedNodeName = ERROR; - else ownedNodeName = null; - if (ownedNodeName != null) throw new SAXException(pNodeNameEnum - + " child node is invalid for " + getNodeName() - + " node, since it already has a " + ownedNodeName + " child node!"); - } else if (pNodeNameEnum == PARAMVALUE) { - if (this.iHasError) throw new SAXException(pNodeNameEnum - + " child node is invalid for " + getNodeName() - + " node, since it already has an ERROR child node!"); - } else throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum - + " child node!"); - } - - @Override - public void childParsed(Node pChild) { - if (pChild instanceof ErrorNode) { - this.iHasError = true; - this.iError = ((ErrorNode) pChild).getCIMError(); - } else if (pChild instanceof ReturnValueNode) { - this.iHasRetVal = true; - this.iRetVal = ((ReturnValueNode) pChild).getValue(); - } else if (pChild instanceof ParamValueNode) { - if (this.iCIMArgAL == null) this.iCIMArgAL = new ArrayList>(); - this.iCIMArgAL.add(((ParamValueNode) pChild).getCIMArgument()); - } - } - - @Override - public void testCompletness() { - // no mandatory child - } - - public CIMError getCIMError() { - return this.iError; - } - - private static final CIMArgument[] EMPTY_ARG_A = new CIMArgument[0]; - - /** - * getCIMArguments : returns the array of parsed parameters and their values - * : String name, CIMDataType type, Object value - * - * @return CIMArgument<?>[] - */ - public CIMArgument[] getCIMArguments() { - if (this.iCIMArgAL == null || this.iCIMArgAL.size() == 0) return null; - return this.iCIMArgAL.toArray(EMPTY_ARG_A); - } - - public int getReturnValueCount() { - return this.iRetVal == null ? 0 : 1; - } - - public Object readReturnValue() { - Object val = this.iRetVal; - this.iRetVal = null; - return val; - } - - /** - * getName - * - * @return String - */ - public String getName() { - return this.iName; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2845211 2009-08-27 raman_arora Pull Enumeration Feature (SAX Parser) + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + * 2697 2012-10-30 blaschke-oss (I)MethodResponseNode allows ERROR with PARAMVALUE + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import org.metricshub.wbem.javax.cim.CIMArgument; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.CIMError; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT METHODRESPONSE (ERROR|(RETURNVALUE?,PARAMVALUE*))
      + * ATTLIST METHODRESPONSE
      + *   %CIMName;
      + * 
      + */ +public class MethodResponseNode extends Node implements ErrorIf, RetValPipeIf, NonVolatileIf { + private String iName; + + private CIMError iError; + + private Object iRetVal; + + private ArrayList> iCIMArgAL; + + private boolean iHasError; + + private boolean iHasRetVal; + + /** + * Ctor. + */ + public MethodResponseNode() { + super(METHODRESPONSE); + } + + /** + * @param pChild + */ + public void addChild(Node pChild) { + // nothing to do + } + + /** + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iName = getCIMName(pAttribs); + this.iError = null; + this.iRetVal = null; + if (this.iCIMArgAL != null) this.iCIMArgAL.clear(); + this.iHasError = false; + this.iHasRetVal = false; + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum == ERROR) { + String ownedNodeName; + if (this.iHasRetVal) ownedNodeName = RETURNVALUE; else if (this.iHasError) ownedNodeName = ERROR; else if ( + this.iCIMArgAL != null && this.iCIMArgAL.size() > 0 + ) ownedNodeName = PARAMVALUE; else ownedNodeName = null; + if (ownedNodeName != null) throw new SAXException( + pNodeNameEnum + + " child node is invalid for " + + getNodeName() + + " node, since it already has a " + + ownedNodeName + + " child node!" + ); + } else if (pNodeNameEnum == RETURNVALUE) { + String ownedNodeName; + if (this.iHasRetVal) ownedNodeName = RETURNVALUE; else if (this.iHasError) ownedNodeName = + ERROR; else ownedNodeName = null; + if (ownedNodeName != null) throw new SAXException( + pNodeNameEnum + + " child node is invalid for " + + getNodeName() + + " node, since it already has a " + + ownedNodeName + + " child node!" + ); + } else if (pNodeNameEnum == PARAMVALUE) { + if (this.iHasError) throw new SAXException( + pNodeNameEnum + + " child node is invalid for " + + getNodeName() + + " node, since it already has an ERROR child node!" + ); + } else throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!"); + } + + @Override + public void childParsed(Node pChild) { + if (pChild instanceof ErrorNode) { + this.iHasError = true; + this.iError = ((ErrorNode) pChild).getCIMError(); + } else if (pChild instanceof ReturnValueNode) { + this.iHasRetVal = true; + this.iRetVal = ((ReturnValueNode) pChild).getValue(); + } else if (pChild instanceof ParamValueNode) { + if (this.iCIMArgAL == null) this.iCIMArgAL = new ArrayList>(); + this.iCIMArgAL.add(((ParamValueNode) pChild).getCIMArgument()); + } + } + + @Override + public void testCompletness() { + // no mandatory child + } + + public CIMError getCIMError() { + return this.iError; + } + + private static final CIMArgument[] EMPTY_ARG_A = new CIMArgument[0]; + + /** + * getCIMArguments : returns the array of parsed parameters and their values + * : String name, CIMDataType type, Object value + * + * @return CIMArgument<?>[] + */ + public CIMArgument[] getCIMArguments() { + if (this.iCIMArgAL == null || this.iCIMArgAL.size() == 0) return null; + return this.iCIMArgAL.toArray(EMPTY_ARG_A); + } + + public int getReturnValueCount() { + return this.iRetVal == null ? 0 : 1; + } + + public Object readReturnValue() { + Object val = this.iRetVal; + this.iRetVal = null; + return val; + } + + /** + * getName + * + * @return String + */ + public String getName() { + return this.iName; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiExpReqNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiExpReqNode.java similarity index 68% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiExpReqNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiExpReqNode.java index 2578cdd..bd522a5 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiExpReqNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiExpReqNode.java @@ -1,105 +1,101 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT MULTIEXPREQ (SIMPLEEXPREQ, SIMPLEEXPREQ+) - */ -public class MultiExpReqNode extends AbstractMessageNode { - - private ArrayList iSimpleExpReqAList; - - /** - * Ctor. - */ - public MultiExpReqNode() { - super(MULTIEXPREQ); - } - - public void addChild(Node pChild) { - if (this.iSimpleExpReqAList == null) this.iSimpleExpReqAList = new ArrayList(); - this.iSimpleExpReqAList.add(pChild); - } - - /** - * @param pAttribs - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - if (this.iSimpleExpReqAList != null) this.iSimpleExpReqAList.clear(); - // no attributes - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum != SIMPLEEXPREQ) throw new SAXException( - "MULTIEXPREQ node can have SIMPLEEXPREQ child nodes only! " + pNodeNameEnum - + " child node is invalid!"); - } - - @Override - public void testCompletness() throws SAXException { - if (this.iSimpleExpReqAList == null || this.iSimpleExpReqAList.size() < 2) throw new SAXException( - "MULTIEXPREQ node must have at least two SIMPLEEXPREQ child nodes!"); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT MULTIEXPREQ (SIMPLEEXPREQ, SIMPLEEXPREQ+) + */ +public class MultiExpReqNode extends AbstractMessageNode { + private ArrayList iSimpleExpReqAList; + + /** + * Ctor. + */ + public MultiExpReqNode() { + super(MULTIEXPREQ); + } + + public void addChild(Node pChild) { + if (this.iSimpleExpReqAList == null) this.iSimpleExpReqAList = new ArrayList(); + this.iSimpleExpReqAList.add(pChild); + } + + /** + * @param pAttribs + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + if (this.iSimpleExpReqAList != null) this.iSimpleExpReqAList.clear(); + // no attributes + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum != SIMPLEEXPREQ) throw new SAXException( + "MULTIEXPREQ node can have SIMPLEEXPREQ child nodes only! " + pNodeNameEnum + " child node is invalid!" + ); + } + + @Override + public void testCompletness() throws SAXException { + if (this.iSimpleExpReqAList == null || this.iSimpleExpReqAList.size() < 2) throw new SAXException( + "MULTIEXPREQ node must have at least two SIMPLEEXPREQ child nodes!" + ); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiExpRspNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiExpRspNode.java similarity index 67% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiExpRspNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiExpRspNode.java index 662481c..5d5450b 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiExpRspNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiExpRspNode.java @@ -1,106 +1,102 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT MULTIEXPRSP (SIMPLEEXPRSP, SIMPLEEXPRSP+) - */ -public class MultiExpRspNode extends AbstractMessageNode { - - private ArrayList iSimpleExpRspAList; - - /** - * Ctor. - */ - public MultiExpRspNode() { - super(MULTIEXPRSP); - } - - public void addChild(Node pChild) { - if (this.iSimpleExpRspAList == null) this.iSimpleExpRspAList = new ArrayList(); - this.iSimpleExpRspAList.add(pChild); - } - - /** - * @param pAttribs - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - if (this.iSimpleExpRspAList != null) this.iSimpleExpRspAList.clear(); - // no attributes - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum != SIMPLEEXPRSP) throw new SAXException(getNodeName() - + " node can have SIMPLEEXPRSP child node only! " + pNodeNameEnum - + " child node is invalid!"); - } - - @Override - public void testCompletness() throws SAXException { - if (this.iSimpleExpRspAList == null || this.iSimpleExpRspAList.size() < 2) throw new SAXException( - getNodeName() + " node must have at least two SIMPLEEXPRSP child nodes!"); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT MULTIEXPRSP (SIMPLEEXPRSP, SIMPLEEXPRSP+) + */ +public class MultiExpRspNode extends AbstractMessageNode { + private ArrayList iSimpleExpRspAList; + + /** + * Ctor. + */ + public MultiExpRspNode() { + super(MULTIEXPRSP); + } + + public void addChild(Node pChild) { + if (this.iSimpleExpRspAList == null) this.iSimpleExpRspAList = new ArrayList(); + this.iSimpleExpRspAList.add(pChild); + } + + /** + * @param pAttribs + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + if (this.iSimpleExpRspAList != null) this.iSimpleExpRspAList.clear(); + // no attributes + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum != SIMPLEEXPRSP) throw new SAXException( + getNodeName() + " node can have SIMPLEEXPRSP child node only! " + pNodeNameEnum + " child node is invalid!" + ); + } + + @Override + public void testCompletness() throws SAXException { + if (this.iSimpleExpRspAList == null || this.iSimpleExpRspAList.size() < 2) throw new SAXException( + getNodeName() + " node must have at least two SIMPLEEXPRSP child nodes!" + ); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiReqNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiReqNode.java similarity index 69% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiReqNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiReqNode.java index 903bcd2..e82fd9b 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiReqNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiReqNode.java @@ -1,114 +1,110 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT MULTIREQ (SIMPLEREQ, SIMPLEREQ+) - */ -public class MultiReqNode extends AbstractMessageNode { - - private ArrayList iSimpleReqAList; - - /** - * Ctor. - */ - public MultiReqNode() { - super(MULTIREQ); - } - - public void addChild(Node pChild) { - if (this.iSimpleReqAList == null) this.iSimpleReqAList = new ArrayList(); - this.iSimpleReqAList.add(pChild); - } - - /** - * @param pAttribs - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - if (this.iSimpleReqAList != null) this.iSimpleReqAList.clear(); - // no attributes - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum != SIMPLEREQ) throw new SAXException( - "MULTIREQ node can have SIMPLEREQ child nodes only! " + pNodeNameEnum - + " child node is invalid!"); - } - - @Override - public void testCompletness() throws SAXException { - if (this.iSimpleReqAList == null || this.iSimpleReqAList.size() < 2) throw new SAXException( - "MULTIREQ node must have at least 2 SIMPLEREQ child nodes!"); - } - - /** - * size - * - * @return int - */ - public int size() { - return this.iSimpleReqAList == null ? 0 : this.iSimpleReqAList.size(); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT MULTIREQ (SIMPLEREQ, SIMPLEREQ+) + */ +public class MultiReqNode extends AbstractMessageNode { + private ArrayList iSimpleReqAList; + + /** + * Ctor. + */ + public MultiReqNode() { + super(MULTIREQ); + } + + public void addChild(Node pChild) { + if (this.iSimpleReqAList == null) this.iSimpleReqAList = new ArrayList(); + this.iSimpleReqAList.add(pChild); + } + + /** + * @param pAttribs + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + if (this.iSimpleReqAList != null) this.iSimpleReqAList.clear(); + // no attributes + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum != SIMPLEREQ) throw new SAXException( + "MULTIREQ node can have SIMPLEREQ child nodes only! " + pNodeNameEnum + " child node is invalid!" + ); + } + + @Override + public void testCompletness() throws SAXException { + if (this.iSimpleReqAList == null || this.iSimpleReqAList.size() < 2) throw new SAXException( + "MULTIREQ node must have at least 2 SIMPLEREQ child nodes!" + ); + } + + /** + * size + * + * @return int + */ + public int size() { + return this.iSimpleReqAList == null ? 0 : this.iSimpleReqAList.size(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiRspNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiRspNode.java similarity index 67% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiRspNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiRspNode.java index 1ca4564..be11eae 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiRspNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/MultiRspNode.java @@ -1,105 +1,102 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT MULTIRSP (SIMPLERSP, SIMPLERSP+) - */ -public class MultiRspNode extends AbstractMessageNode { - - private ArrayList iSimpleRspAList; - - /** - * Ctor. - */ - public MultiRspNode() { - super(MULTIRSP); - } - - public void addChild(Node pChild) { - if (this.iSimpleRspAList == null) this.iSimpleRspAList = new ArrayList(); - this.iSimpleRspAList.add(pChild); - } - - /** - * @param pAttribs - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - if (this.iSimpleRspAList != null) this.iSimpleRspAList.clear(); - // no attribs - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum != SIMPLERSP) throw new SAXException(getNodeName() + " node cannot have " - + pNodeNameEnum + " child node!"); - } - - @Override - public void testCompletness() throws SAXException { - if (this.iSimpleRspAList == null || this.iSimpleRspAList.size() < 2) throw new SAXException( - getNodeName() + " node must have at least two SIMPLERSP child nodes!"); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT MULTIRSP (SIMPLERSP, SIMPLERSP+) + */ +public class MultiRspNode extends AbstractMessageNode { + private ArrayList iSimpleRspAList; + + /** + * Ctor. + */ + public MultiRspNode() { + super(MULTIRSP); + } + + public void addChild(Node pChild) { + if (this.iSimpleRspAList == null) this.iSimpleRspAList = new ArrayList(); + this.iSimpleRspAList.add(pChild); + } + + /** + * @param pAttribs + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + if (this.iSimpleRspAList != null) this.iSimpleRspAList.clear(); + // no attribs + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum != SIMPLERSP) throw new SAXException( + getNodeName() + " node cannot have " + pNodeNameEnum + " child node!" + ); + } + + @Override + public void testCompletness() throws SAXException { + if (this.iSimpleRspAList == null || this.iSimpleRspAList.size() < 2) throw new SAXException( + getNodeName() + " node must have at least two SIMPLERSP child nodes!" + ); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/NameSpaceNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/NameSpaceNode.java similarity index 70% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/NameSpaceNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/NameSpaceNode.java index 31c707a..48bf4f2 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/NameSpaceNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/NameSpaceNode.java @@ -1,114 +1,110 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2604 2013-07-01 blaschke-oss SAXException messages should contain node name - * 2673 2013-09-26 blaschke-oss NameSpaceNode does not need testCompletness() - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT NAMESPACE EMPTY ATTRLIST NAMESPACE %CIMName; - * - */ -public class NameSpaceNode extends Node { - - private String iNameSpaceValue; - - /** - * Ctor. - */ - public NameSpaceNode() { - super(NAMESPACE); - } - - /** - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iNameSpaceValue = getCIMName(pAttribs); - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - /** - * @param pNodeNameEnum - */ - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - throw new SAXException("NAMESPACE node cannot have any child node!"); - } - - /** - * @param pChild - */ - @Override - public void childParsed(Node pChild) { - // no child - } - - @Override - public void testCompletness() { - // no child - } - - /** - * getNameSpace - * - * @return String - */ - public String getNameSpace() { - return this.iNameSpaceValue; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2604 2013-07-01 blaschke-oss SAXException messages should contain node name + * 2673 2013-09-26 blaschke-oss NameSpaceNode does not need testCompletness() + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT NAMESPACE EMPTY ATTRLIST NAMESPACE %CIMName; + * + */ +public class NameSpaceNode extends Node { + private String iNameSpaceValue; + + /** + * Ctor. + */ + public NameSpaceNode() { + super(NAMESPACE); + } + + /** + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iNameSpaceValue = getCIMName(pAttribs); + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + /** + * @param pNodeNameEnum + */ + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + throw new SAXException("NAMESPACE node cannot have any child node!"); + } + + /** + * @param pChild + */ + @Override + public void childParsed(Node pChild) { + // no child + } + + @Override + public void testCompletness() { + // no child + } + + /** + * getNameSpace + * + * @return String + */ + public String getNameSpace() { + return this.iNameSpaceValue; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/NameSpacePathNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/NameSpacePathNode.java similarity index 69% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/NameSpacePathNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/NameSpacePathNode.java index 9900892..bf83b8d 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/NameSpacePathNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/NameSpacePathNode.java @@ -1,144 +1,139 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 1742873 2007-06-25 ebak IPv6 ready cim-client - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT NAMESPACEPATH (HOST, LOCALNAMESPACEPATH) - */ -public class NameSpacePathNode extends Node { - - // HOST - private boolean iHasHost; - - private String iHostStr; - - // LOCALNAMESPACEPATH - private boolean iHasLocalNameSpacePath; - - private String iLocalNameSpacePathStr; - - /** - * Ctor. - */ - public NameSpacePathNode() { - super(NAMESPACEPATH); - } - - /** - * @param pAttribs - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - this.iHasHost = this.iHasLocalNameSpacePath = false; - this.iHostStr = this.iLocalNameSpacePathStr = null; - // no attributes - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum == HOST) { - if (this.iHasHost) throw new SAXException(getNodeName() - + " node can have only one HOST child node!"); - } else if (pNodeNameEnum == LOCALNAMESPACEPATH) { - if (this.iHasLocalNameSpacePath) throw new SAXException(getNodeName() - + " node can have only one LOCALNAMESPACEPATH child node!"); - } else throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum - + " child node!"); - } - - @Override - public void childParsed(Node pChild) { - if (pChild instanceof HostNode) { - this.iHasHost = true; - this.iHostStr = ((HostNode) pChild).getHostStr(); - } else { - this.iHasLocalNameSpacePath = true; - this.iLocalNameSpacePathStr = ((LocalNameSpacePathNode) pChild).getNameSpace(); - } - } - - @Override - public void testCompletness() throws SAXException { - if (!this.iHasHost) throw new SAXException("HOST child node is mandatory for " - + getNodeName() + " node!"); - if (!this.iHasLocalNameSpacePath) throw new SAXException( - "LOCALNAMESPACEPATH child node is mandatory for " + getNodeName() + " node!"); - } - - /** - * getHostStr - * - * @return String which may contain the protocol, host and port - */ - public String getHostStr() { - return this.iHostStr; - } - - /** - * getLocalNameSpacePath - * - * @return String - */ - public String getLocalNameSpacePath() { - return this.iLocalNameSpacePathStr; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 1742873 2007-06-25 ebak IPv6 ready cim-client + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT NAMESPACEPATH (HOST, LOCALNAMESPACEPATH) + */ +public class NameSpacePathNode extends Node { + // HOST + private boolean iHasHost; + + private String iHostStr; + + // LOCALNAMESPACEPATH + private boolean iHasLocalNameSpacePath; + + private String iLocalNameSpacePathStr; + + /** + * Ctor. + */ + public NameSpacePathNode() { + super(NAMESPACEPATH); + } + + /** + * @param pAttribs + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + this.iHasHost = this.iHasLocalNameSpacePath = false; + this.iHostStr = this.iLocalNameSpacePathStr = null; + // no attributes + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum == HOST) { + if (this.iHasHost) throw new SAXException(getNodeName() + " node can have only one HOST child node!"); + } else if (pNodeNameEnum == LOCALNAMESPACEPATH) { + if (this.iHasLocalNameSpacePath) throw new SAXException( + getNodeName() + " node can have only one LOCALNAMESPACEPATH child node!" + ); + } else throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!"); + } + + @Override + public void childParsed(Node pChild) { + if (pChild instanceof HostNode) { + this.iHasHost = true; + this.iHostStr = ((HostNode) pChild).getHostStr(); + } else { + this.iHasLocalNameSpacePath = true; + this.iLocalNameSpacePathStr = ((LocalNameSpacePathNode) pChild).getNameSpace(); + } + } + + @Override + public void testCompletness() throws SAXException { + if (!this.iHasHost) throw new SAXException("HOST child node is mandatory for " + getNodeName() + " node!"); + if (!this.iHasLocalNameSpacePath) throw new SAXException( + "LOCALNAMESPACEPATH child node is mandatory for " + getNodeName() + " node!" + ); + } + + /** + * getHostStr + * + * @return String which may contain the protocol, host and port + */ + public String getHostStr() { + return this.iHostStr; + } + + /** + * getLocalNameSpacePath + * + * @return String + */ + public String getLocalNameSpacePath() { + return this.iLocalNameSpacePathStr; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/Node.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/Node.java similarity index 82% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/Node.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/Node.java index 08ecdda..a7f9d9c 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/Node.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/Node.java @@ -1,395 +1,394 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 1735614 2007-06-12 ebak Wrong ARRAYSIZE attribute handling in SAX/PULL - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2038305 2008-08-14 blaschke-oss SAXException SBLIM Java Client V2.0.7 - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 3513353 2012-03-30 blaschke-oss TCK: CIMDataType arrays must have length >= 1 - * 3602604 2013-01-29 blaschke-oss Clean up SAXException messages - * 2605 2013-03-20 buccella SAX parser throws wrong exception - * 2693 2013-10-21 blaschke-oss ReturnValueNode allows invalid PARAMTYPE attribute - * 2702 2013-11-07 blaschke-oss Bad PROPERTY.ARRAY ARRAYSIZE generates NumberFormatException - * 2706 2013-11-11 blaschke-oss Bad PARAMETER.REFARRAY ARRAYSIZE generates NumberFormatException - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMFlavor; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.CIMHelper; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.CIMObjectFactory; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.NodeConstIf; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.MOF; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * Class Node is the abstract base class of all parseable XML elements. It - * contains helper functions for the implementations. - */ -public abstract class Node implements NodeConstIf { - - private String iNameEnum; - - private boolean iCompleted; - - /** - * Ctor. - * - * @param pNameEnum - * The name of the node which must be a String constant which is - * defined inside this class (because the implementation compares - * by reference). - */ - public Node(String pNameEnum) { - this.iNameEnum = pNameEnum; - } - - /** - * getNodeName - * - * @return The name of the node. This name have to be one of the String - * constant defined in the class. - */ - public String getNodeName() { - return this.iNameEnum; - } - - /** - * The SAX ContentHandler implementation calls this method after testChild() - * and addChild() calls. The implementation must reset it's instance unless - * it implements NonVolatileIf - * - * @param pAttribs - * @param pSession - * - stores variables which are common for the whole SAX parsing - * session - * @throws SAXException - */ - public abstract void init(Attributes pAttribs, SAXSession pSession) throws SAXException; - - /** - * XML element's data have to be passed - * - * @param pData - * - String which is concatenated in SAX's - * DefaultHandler.characters() implementation. - * @throws SAXException - */ - public abstract void parseData(String pData) throws SAXException; - - /** - * It have to be called by SAX's DefaultHandler implementation when it - * detects a new child element (startElement()). - * - * @param pNodeNameEnum - * - the name of the child element, it must be one of the String - * constant defined in class Node, because the implementer - * subclasses uses reference based equals comparisons (==) - * @throws SAXException - * - It have to be thrown when the Node cannot have - * pNodeNameEnum named child Node. - */ - public abstract void testChild(String pNodeNameEnum) throws SAXException; - - /** - * It have to be called by SAX's DefaultHandler.endElement(). It's task is - * to check that the Element is built up correctly. The implementer function - * can do some post processing here. testCompletness - * - * @throws SAXException - * It must be thrown when the Node is not valid. - */ - public abstract void testCompletness() throws SAXException; - - /** - * Have to be called by SAX's DefaultHandler.endElement() - * - * @param pChild - * @throws SAXException - * - parent Nodes can make conversions here (e.g. type string - * into CIMDataType), failed operation should throw - * SAXException) - */ - public abstract void childParsed(Node pChild) throws SAXException; - - /** - * completed - * - * @return true if the parsing of the node is completed - */ - public boolean isCompleted() { - return this.iCompleted; - } - - /** - * Have to be called by SAX's DefaultHandler at endElement(), after calling - * testCompletness(). - */ - public void setCompleted() { - this.iCompleted = true; - } - - /** - * When a Node instance is going to be reused, this function must be called - * before. - */ - public void clearCompleted() { - this.iCompleted = false; - } - - /** - * ENTITY % CIMName "NAME CDATA #REQUIRED" - * - * @param pAttribs - * @return String - * @throws SAXException - */ - public static String getCIMName(Attributes pAttribs) throws SAXException { - String name = pAttribs.getValue("NAME"); - if (name == null) throw new SAXException("NAME attribute not found!"); - return name; - } - - /** - * ENTITY % ClassName "CLASSNAME CDATA #REQUIRED" - * - * @param pAttribs - * @return String - * @throws SAXException - */ - public static String getClassName(Attributes pAttribs) throws SAXException { - String name = pAttribs.getValue("CLASSNAME"); - if (name == null) throw new SAXException("CLASSNAME attribute not found!"); - return name; - } - - /** - * ENTITY % ReferenceClass "REFERENCECLASS CDATA #IMPLIED" - * - * @param pAttribs - * @return String - */ - public static String getReferenceClass(Attributes pAttribs) { - return pAttribs.getValue("REFERENCECLASS"); - } - - /** - * ENTITY % ClassOrigin "CLASSORIGIN CDATA #IMPLIED - * - * @param pAttribs - * @return String - */ - public static String getClassOrigin(Attributes pAttribs) { - return pAttribs.getValue("CLASSORIGIN"); - } - - /** - * ENTITY % Propagated "PROPAGATED (true|false) 'false'" getPropagated - * - * @param pAttribs - * @return boolean - */ - public static boolean getPropagated(Attributes pAttribs) { - String str = pAttribs.getValue("PROPAGATED"); - return MOF.TRUE.equalsIgnoreCase(str); - } - - /** - * ENTITY % ArraySize "ARRAYSIZE CDATA #IMPLIED" - * - * @param pAttribs - * @return int - * @throws SAXException - */ - public static int getArraySize(Attributes pAttribs) throws SAXException { - String arraySizeStr = pAttribs.getValue("ARRAYSIZE"); - // 0 - unbounded size - int size = 0; - try { - size = arraySizeStr == null || arraySizeStr.length() == 0 ? 0 : Integer - .parseInt(arraySizeStr); - } catch (NumberFormatException e) { - throw new SAXException(arraySizeStr + " is not a valid ARRAYSIZE attribute!"); - } - if (size < 0) throw new SAXException("ARRAYSIZE cannot be " + size + "!"); - return size; - } - - /** - * ENTITY % CIMType "TYPE - * (boolean|string|char16|uint8|sint8|uint16|sint16|uint32 - * |sint32|uint64|sint64|datetime|real32|real64)" getCIMType - * - * @param pAttribs - * @param pOptional - * @return CIMDataType - * @throws SAXException - */ - public static CIMDataType getCIMType(Attributes pAttribs, boolean pOptional) - throws SAXException { - String typeStr = pAttribs.getValue("TYPE"); - if (typeStr == null) { - if (pOptional) return null; - throw new SAXException("TYPE attribute not found!"); - } - CIMDataType type = CIMObjectFactory.getType(typeStr); - if (type == null) throw new SAXException(typeStr + " is not a valid TYPE attribute!"); - if (type.getType() == CIMDataType.REFERENCE) throw new SAXException( - "TYPE attribute cannot be \"reference\"!"); - // Is it array? - // Yes if ISARRAY is true or ARRAYSIZE>-1. - boolean isArray = hasTrueAttribute(pAttribs, "ISARRAY"); - String arraySizeStr = pAttribs.getValue("ARRAYSIZE"); - int arraySize; - try { - arraySize = (arraySizeStr == null || arraySizeStr.length() == 0 ? (isArray ? 0 : -1) - : Integer.parseInt(arraySizeStr)); - } catch (NumberFormatException e) { - throw new SAXException(arraySizeStr + " is not a valid ARRAYSIZE attribute!"); - } - if (isArray || arraySize >= 0) { - if (arraySize > 0) return new CIMDataType(type.getType(), arraySize); - return CIMHelper.UnboundedArrayDataType(type.getType()); - } - return type; - } - - /** - * getCIMType(pAttribs, pOptional=false); - * - * @param pAttribs - * @return CIMDataType - * @throws SAXException - */ - public static CIMDataType getCIMType(Attributes pAttribs) throws SAXException { - return getCIMType(pAttribs, false); - } - - /** - * ENTITY % ParamType "PARAMTYPE ( - * boolean|string|char16|uint8|sint8|uint16|sint16 - * |uint32|sint32|uint64|sint64|datetime| real32|real64|reference) - * - * @param pAttribs - * @return CIMDataType - * @throws SAXException - */ - public static CIMDataType getParamType(Attributes pAttribs) throws SAXException { - String typeStr = pAttribs.getValue("PARAMTYPE"); - return CIMObjectFactory.getType(typeStr); - } - - /** - *
      -	 * ENTITY % QualifierFlavor "
      -	 * OVERRIDABLE    (true|false)  'true'
      -	 * TOSUBCLASS     (true|false)  'true'
      -	 * TOINSTANCE     (true|false)  'false'
      -	 * TRANSLATABLE   (true|false)  'false'"
      -	 * 
      - * - * @param pAttribs - * @return int - CIMFlavor bit mixture - */ - public int getQualifierFlavor(Attributes pAttribs) { - int flavors = 0; - if (!getBoolAttribute(pAttribs, "OVERRIDABLE", true)) flavors |= CIMFlavor.DISABLEOVERRIDE; - if (!getBoolAttribute(pAttribs, "TOSUBCLASS", true)) flavors |= CIMFlavor.RESTRICTED; - if (getBoolAttribute(pAttribs, "TRANSLATABLE", false)) flavors |= CIMFlavor.TRANSLATE; - return flavors; - } - - /** - * hasTrueAttribute - * - * @param pAttribs - * @param pName - * @return boolean - */ - public static boolean hasTrueAttribute(Attributes pAttribs, String pName) { - return MOF.TRUE.equalsIgnoreCase(pAttribs.getValue(pName)); - } - - /** - * getBoolAttribute - * - * @param pAttribs - * @param pName - * @param pDefVal - * @return boolean - */ - public static boolean getBoolAttribute(Attributes pAttribs, String pName, boolean pDefVal) { - String val = pAttribs.getValue(pName); - if (MOF.TRUE.equalsIgnoreCase(val)) return true; - if (MOF.FALSE.equalsIgnoreCase(val)) return false; - return pDefVal; - } - - /** - * duplicatedNode - * - * @param pParsedNodeName - * @param pNewNodeName - * @throws SAXException - */ - public void duplicatedNode(String pParsedNodeName, String pNewNodeName) throws SAXException { - throw new SAXException(getNodeName() + " has a " + pParsedNodeName - + " child node which disallows an additional " + pNewNodeName + " child node!"); - } - - /** - * illegalChildNodePair - * - * @param pNodeName0 - * @param pNodeName1 - * @throws SAXException - */ - public void illegalChildNodePair(String pNodeName0, String pNodeName1) throws SAXException { - throw new SAXException(pNodeName0 + ", " + pNodeName1 + " child node pair is illegal for " - + getNodeName() + " node!"); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 1735614 2007-06-12 ebak Wrong ARRAYSIZE attribute handling in SAX/PULL + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2038305 2008-08-14 blaschke-oss SAXException SBLIM Java Client V2.0.7 + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 3513353 2012-03-30 blaschke-oss TCK: CIMDataType arrays must have length >= 1 + * 3602604 2013-01-29 blaschke-oss Clean up SAXException messages + * 2605 2013-03-20 buccella SAX parser throws wrong exception + * 2693 2013-10-21 blaschke-oss ReturnValueNode allows invalid PARAMTYPE attribute + * 2702 2013-11-07 blaschke-oss Bad PROPERTY.ARRAY ARRAYSIZE generates NumberFormatException + * 2706 2013-11-11 blaschke-oss Bad PARAMETER.REFARRAY ARRAYSIZE generates NumberFormatException + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMFlavor; +import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMHelper; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.CIMObjectFactory; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.NodeConstIf; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.metricshub.wbem.sblim.cimclient.internal.util.MOF; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * Class Node is the abstract base class of all parseable XML elements. It + * contains helper functions for the implementations. + */ +public abstract class Node implements NodeConstIf { + private String iNameEnum; + + private boolean iCompleted; + + /** + * Ctor. + * + * @param pNameEnum + * The name of the node which must be a String constant which is + * defined inside this class (because the implementation compares + * by reference). + */ + public Node(String pNameEnum) { + this.iNameEnum = pNameEnum; + } + + /** + * getNodeName + * + * @return The name of the node. This name have to be one of the String + * constant defined in the class. + */ + public String getNodeName() { + return this.iNameEnum; + } + + /** + * The SAX ContentHandler implementation calls this method after testChild() + * and addChild() calls. The implementation must reset it's instance unless + * it implements NonVolatileIf + * + * @param pAttribs + * @param pSession + * - stores variables which are common for the whole SAX parsing + * session + * @throws SAXException + */ + public abstract void init(Attributes pAttribs, SAXSession pSession) throws SAXException; + + /** + * XML element's data have to be passed + * + * @param pData + * - String which is concatenated in SAX's + * DefaultHandler.characters() implementation. + * @throws SAXException + */ + public abstract void parseData(String pData) throws SAXException; + + /** + * It have to be called by SAX's DefaultHandler implementation when it + * detects a new child element (startElement()). + * + * @param pNodeNameEnum + * - the name of the child element, it must be one of the String + * constant defined in class Node, because the implementer + * subclasses uses reference based equals comparisons (==) + * @throws SAXException + * - It have to be thrown when the Node cannot have + * pNodeNameEnum named child Node. + */ + public abstract void testChild(String pNodeNameEnum) throws SAXException; + + /** + * It have to be called by SAX's DefaultHandler.endElement(). It's task is + * to check that the Element is built up correctly. The implementer function + * can do some post processing here. testCompletness + * + * @throws SAXException + * It must be thrown when the Node is not valid. + */ + public abstract void testCompletness() throws SAXException; + + /** + * Have to be called by SAX's DefaultHandler.endElement() + * + * @param pChild + * @throws SAXException + * - parent Nodes can make conversions here (e.g. type string + * into CIMDataType), failed operation should throw + * SAXException) + */ + public abstract void childParsed(Node pChild) throws SAXException; + + /** + * completed + * + * @return true if the parsing of the node is completed + */ + public boolean isCompleted() { + return this.iCompleted; + } + + /** + * Have to be called by SAX's DefaultHandler at endElement(), after calling + * testCompletness(). + */ + public void setCompleted() { + this.iCompleted = true; + } + + /** + * When a Node instance is going to be reused, this function must be called + * before. + */ + public void clearCompleted() { + this.iCompleted = false; + } + + /** + * ENTITY % CIMName "NAME CDATA #REQUIRED" + * + * @param pAttribs + * @return String + * @throws SAXException + */ + public static String getCIMName(Attributes pAttribs) throws SAXException { + String name = pAttribs.getValue("NAME"); + if (name == null) throw new SAXException("NAME attribute not found!"); + return name; + } + + /** + * ENTITY % ClassName "CLASSNAME CDATA #REQUIRED" + * + * @param pAttribs + * @return String + * @throws SAXException + */ + public static String getClassName(Attributes pAttribs) throws SAXException { + String name = pAttribs.getValue("CLASSNAME"); + if (name == null) throw new SAXException("CLASSNAME attribute not found!"); + return name; + } + + /** + * ENTITY % ReferenceClass "REFERENCECLASS CDATA #IMPLIED" + * + * @param pAttribs + * @return String + */ + public static String getReferenceClass(Attributes pAttribs) { + return pAttribs.getValue("REFERENCECLASS"); + } + + /** + * ENTITY % ClassOrigin "CLASSORIGIN CDATA #IMPLIED + * + * @param pAttribs + * @return String + */ + public static String getClassOrigin(Attributes pAttribs) { + return pAttribs.getValue("CLASSORIGIN"); + } + + /** + * ENTITY % Propagated "PROPAGATED (true|false) 'false'" getPropagated + * + * @param pAttribs + * @return boolean + */ + public static boolean getPropagated(Attributes pAttribs) { + String str = pAttribs.getValue("PROPAGATED"); + return MOF.TRUE.equalsIgnoreCase(str); + } + + /** + * ENTITY % ArraySize "ARRAYSIZE CDATA #IMPLIED" + * + * @param pAttribs + * @return int + * @throws SAXException + */ + public static int getArraySize(Attributes pAttribs) throws SAXException { + String arraySizeStr = pAttribs.getValue("ARRAYSIZE"); + // 0 - unbounded size + int size = 0; + try { + size = arraySizeStr == null || arraySizeStr.length() == 0 ? 0 : Integer.parseInt(arraySizeStr); + } catch (NumberFormatException e) { + throw new SAXException(arraySizeStr + " is not a valid ARRAYSIZE attribute!"); + } + if (size < 0) throw new SAXException("ARRAYSIZE cannot be " + size + "!"); + return size; + } + + /** + * ENTITY % CIMType "TYPE + * (boolean|string|char16|uint8|sint8|uint16|sint16|uint32 + * |sint32|uint64|sint64|datetime|real32|real64)" getCIMType + * + * @param pAttribs + * @param pOptional + * @return CIMDataType + * @throws SAXException + */ + public static CIMDataType getCIMType(Attributes pAttribs, boolean pOptional) throws SAXException { + String typeStr = pAttribs.getValue("TYPE"); + if (typeStr == null) { + if (pOptional) return null; + throw new SAXException("TYPE attribute not found!"); + } + CIMDataType type = CIMObjectFactory.getType(typeStr); + if (type == null) throw new SAXException(typeStr + " is not a valid TYPE attribute!"); + if (type.getType() == CIMDataType.REFERENCE) throw new SAXException("TYPE attribute cannot be \"reference\"!"); + // Is it array? + // Yes if ISARRAY is true or ARRAYSIZE>-1. + boolean isArray = hasTrueAttribute(pAttribs, "ISARRAY"); + String arraySizeStr = pAttribs.getValue("ARRAYSIZE"); + int arraySize; + try { + arraySize = + (arraySizeStr == null || arraySizeStr.length() == 0 ? (isArray ? 0 : -1) : Integer.parseInt(arraySizeStr)); + } catch (NumberFormatException e) { + throw new SAXException(arraySizeStr + " is not a valid ARRAYSIZE attribute!"); + } + if (isArray || arraySize >= 0) { + if (arraySize > 0) return new CIMDataType(type.getType(), arraySize); + return CIMHelper.UnboundedArrayDataType(type.getType()); + } + return type; + } + + /** + * getCIMType(pAttribs, pOptional=false); + * + * @param pAttribs + * @return CIMDataType + * @throws SAXException + */ + public static CIMDataType getCIMType(Attributes pAttribs) throws SAXException { + return getCIMType(pAttribs, false); + } + + /** + * ENTITY % ParamType "PARAMTYPE ( + * boolean|string|char16|uint8|sint8|uint16|sint16 + * |uint32|sint32|uint64|sint64|datetime| real32|real64|reference) + * + * @param pAttribs + * @return CIMDataType + * @throws SAXException + */ + public static CIMDataType getParamType(Attributes pAttribs) throws SAXException { + String typeStr = pAttribs.getValue("PARAMTYPE"); + return CIMObjectFactory.getType(typeStr); + } + + /** + *
      +	 * ENTITY % QualifierFlavor "
      +	 * OVERRIDABLE    (true|false)  'true'
      +	 * TOSUBCLASS     (true|false)  'true'
      +	 * TOINSTANCE     (true|false)  'false'
      +	 * TRANSLATABLE   (true|false)  'false'"
      +	 * 
      + * + * @param pAttribs + * @return int - CIMFlavor bit mixture + */ + public int getQualifierFlavor(Attributes pAttribs) { + int flavors = 0; + if (!getBoolAttribute(pAttribs, "OVERRIDABLE", true)) flavors |= CIMFlavor.DISABLEOVERRIDE; + if (!getBoolAttribute(pAttribs, "TOSUBCLASS", true)) flavors |= CIMFlavor.RESTRICTED; + if (getBoolAttribute(pAttribs, "TRANSLATABLE", false)) flavors |= CIMFlavor.TRANSLATE; + return flavors; + } + + /** + * hasTrueAttribute + * + * @param pAttribs + * @param pName + * @return boolean + */ + public static boolean hasTrueAttribute(Attributes pAttribs, String pName) { + return MOF.TRUE.equalsIgnoreCase(pAttribs.getValue(pName)); + } + + /** + * getBoolAttribute + * + * @param pAttribs + * @param pName + * @param pDefVal + * @return boolean + */ + public static boolean getBoolAttribute(Attributes pAttribs, String pName, boolean pDefVal) { + String val = pAttribs.getValue(pName); + if (MOF.TRUE.equalsIgnoreCase(val)) return true; + if (MOF.FALSE.equalsIgnoreCase(val)) return false; + return pDefVal; + } + + /** + * duplicatedNode + * + * @param pParsedNodeName + * @param pNewNodeName + * @throws SAXException + */ + public void duplicatedNode(String pParsedNodeName, String pNewNodeName) throws SAXException { + throw new SAXException( + getNodeName() + + " has a " + + pParsedNodeName + + " child node which disallows an additional " + + pNewNodeName + + " child node!" + ); + } + + /** + * illegalChildNodePair + * + * @param pNodeName0 + * @param pNodeName1 + * @throws SAXException + */ + public void illegalChildNodePair(String pNodeName0, String pNodeName1) throws SAXException { + throw new SAXException( + pNodeName0 + ", " + pNodeName1 + " child node pair is illegal for " + getNodeName() + " node!" + ); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/NonVolatileIf.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/NonVolatileIf.java similarity index 62% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/NonVolatileIf.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/NonVolatileIf.java index 63304a4..1c597a5 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/NonVolatileIf.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/NonVolatileIf.java @@ -1,59 +1,55 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1663270 2007-02-19 ebak Minor performance problems - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * This interface have to be implemented by those Node classes which instances - * cannot be reused. (e.g. CIM, MESSAGE, SIMPLERSP, IMETHODRESPONSE, - * IRETURNVALUE) - */ -public interface NonVolatileIf { - - /** - * Have to be called by SAX's DefaultHandler.startElement() after - * testChild() call. - * - * @param pChild - */ - public abstract void addChild(Node pChild); - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1663270 2007-02-19 ebak Minor performance problems + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * This interface have to be implemented by those Node classes which instances + * cannot be reused. (e.g. CIM, MESSAGE, SIMPLERSP, IMETHODRESPONSE, + * IRETURNVALUE) + */ +public interface NonVolatileIf { + /** + * Have to be called by SAX's DefaultHandler.startElement() after + * testChild() call. + * + * @param pChild + */ + public abstract void addChild(Node pChild); +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ObjectPathIf.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ObjectPathIf.java similarity index 58% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ObjectPathIf.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ObjectPathIf.java index 45c449b..9a3e8a4 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ObjectPathIf.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ObjectPathIf.java @@ -1,57 +1,54 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * It's implemented by Nodes which can construct a CIMObjectPath. - */ -public interface ObjectPathIf { - - /** - * getCIMObjectPath - * - * @return CIMObjectPath - */ - CIMObjectPath getCIMObjectPath(); -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * It's implemented by Nodes which can construct a CIMObjectPath. + */ +public interface ObjectPathIf { + /** + * getCIMObjectPath + * + * @return CIMObjectPath + */ + CIMObjectPath getCIMObjectPath(); +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ObjectPathNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ObjectPathNode.java similarity index 61% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ObjectPathNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ObjectPathNode.java index 771540d..3ab39c4 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ObjectPathNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ObjectPathNode.java @@ -1,114 +1,114 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2677 2013-09-30 blaschke-oss ObjectPathNode allows all child nodes - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT OBJECTPATH (INSTANCEPATH | CLASSPATH) - */ -public class ObjectPathNode extends AbstractPathNode { - - // (INSTANCEPATH | CLASSPATH) - private CIMObjectPath iObjPath; - - // private AbstractObjectPathNode iChildNode; - - /** - * Ctor. - */ - public ObjectPathNode() { - super(OBJECTPATH); - } - - /** - * @param pAttribs - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - this.iObjPath = null; - // no attributes - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (this.iObjPath != null) throw new SAXException(getNodeName() - + " node can have only one INSTANCEPATH or CLASSPATH child node!" + " Additional " - + pNodeNameEnum + " child node is invalid!"); - if (pNodeNameEnum != CLASSPATH && pNodeNameEnum != INSTANCEPATH) throw new SAXException( - getNodeName() + " node child node can be CLASSPATH or INSTANCEPATH but a " - + pNodeNameEnum + " node was found!"); - } - - @Override - public void childParsed(Node pChild) { - this.iObjPath = ((AbstractObjectPathNode) pChild).getCIMObjectPath(); - } - - @Override - public void testCompletness() throws SAXException { - if (this.iObjPath == null) throw new SAXException(getNodeName() - + " node must have a INSTANCEPATH or CLASSPATH child node!"); - } - - public CIMObjectPath getCIMObjectPath() { - return this.iObjPath; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2677 2013-09-30 blaschke-oss ObjectPathNode allows all child nodes + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT OBJECTPATH (INSTANCEPATH | CLASSPATH) + */ +public class ObjectPathNode extends AbstractPathNode { + // (INSTANCEPATH | CLASSPATH) + private CIMObjectPath iObjPath; + + // private AbstractObjectPathNode iChildNode; + + /** + * Ctor. + */ + public ObjectPathNode() { + super(OBJECTPATH); + } + + /** + * @param pAttribs + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + this.iObjPath = null; + // no attributes + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (this.iObjPath != null) throw new SAXException( + getNodeName() + + " node can have only one INSTANCEPATH or CLASSPATH child node!" + + " Additional " + + pNodeNameEnum + + " child node is invalid!" + ); + if (pNodeNameEnum != CLASSPATH && pNodeNameEnum != INSTANCEPATH) throw new SAXException( + getNodeName() + " node child node can be CLASSPATH or INSTANCEPATH but a " + pNodeNameEnum + " node was found!" + ); + } + + @Override + public void childParsed(Node pChild) { + this.iObjPath = ((AbstractObjectPathNode) pChild).getCIMObjectPath(); + } + + @Override + public void testCompletness() throws SAXException { + if (this.iObjPath == null) throw new SAXException( + getNodeName() + " node must have a INSTANCEPATH or CLASSPATH child node!" + ); + } + + public CIMObjectPath getCIMObjectPath() { + return this.iObjPath; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ParamValueNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ParamValueNode.java similarity index 67% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ParamValueNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ParamValueNode.java index 9bb19fe..e890107 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ParamValueNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ParamValueNode.java @@ -1,182 +1,187 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus - * 1719991 2007-05-16 ebak FVT: regression ClassCastException in EmbObjHandler - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2605 2013-03-20 buccella SAX parser throws wrong exception - * 2537 2013-10-17 blaschke-oss Add new data types for PARAMVALUE - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMArgument; -import org.sentrysoftware.wbem.javax.cim.CIMDataType; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.EmbObjHandler; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT PARAMVALUE (VALUE | VALUE.REFERENCE | VALUE.ARRAY | VALUE.REFARRAY | - * CLASSNAME | INSTANCENAME | CLASS | INSTANCE | VALUE.NAMEDINSTANCE)? ATTLIST - * PARAMVALUE %CIMName; %ParamType; #IMPLIED %EmbeddedObject; #IMPLIED - new - */ -public class ParamValueNode extends AbstractParamValueNode { - - private String iName; - - private EmbObjHandler iEmbObjHandler; - - private CIMDataType iType; - - // VALUE.xxx node - private boolean iHasChild; - - private boolean iHasTypeValue; - - private Object iValue; - - /** - * Ctor. - */ - public ParamValueNode() { - super(PARAMVALUE); - } - - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iEmbObjHandler = EmbObjHandler.init(this.iEmbObjHandler, getNodeName(), pAttribs, - pSession, null, true); - this.iHasChild = false; - this.iHasTypeValue = false; - this.iName = getCIMName(pAttribs); - this.iType = null; - this.iValue = null; - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - private static final String[] ALLOWED_CHILDREN = { VALUE, VALUE_REFERENCE, VALUE_ARRAY, - VALUE_REFARRAY, CLASSNAME, INSTANCENAME, CLASS, INSTANCE, VALUE_NAMEDINSTANCE }; - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - boolean allowed = false; - for (int i = 0; i < ALLOWED_CHILDREN.length; i++) { - if (ALLOWED_CHILDREN[i] == pNodeNameEnum) { - allowed = true; - break; - } - } - if (!allowed) throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum - + " child node!"); - if (this.iHasChild) throw new SAXException(getNodeName() - + " node cannot have more than one child node!"); - // type check - CIMDataType rawType = this.iEmbObjHandler.getRawType(); - if (rawType != null) { - if (pNodeNameEnum == VALUE_REFERENCE || pNodeNameEnum == VALUE_REFARRAY) { - if (rawType.getType() != CIMDataType.REFERENCE) throw new SAXException( - "PARAMVALUE node's PARAMTYPE attribute is not reference (" + rawType - + "), but a " + pNodeNameEnum + " child node is found!"); - } - } - } - - @Override - public void childParsed(Node pChild) { - if (pChild instanceof AbstractValueNode) { - this.iEmbObjHandler.addValueNode((AbstractValueNode) pChild); - } else { - this.iValue = ((ValueIf) pChild).getValue(); - if (pChild instanceof TypedIf) this.iType = ((TypedIf) pChild).getType(); - else if (pChild instanceof ObjectPathIf) this.iType = CIMDataType - .getDataType(((ObjectPathIf) pChild).getCIMObjectPath()); - else if (pChild instanceof ValueIf) this.iType = CIMDataType - .getDataType(((ValueIf) pChild).getValue()); - this.iHasTypeValue = true; - } - this.iHasChild = true; - } - - @Override - public void testCompletness() throws SAXException { - if (!this.iHasTypeValue) { - // here is a type and value conversion - this.iType = this.iEmbObjHandler.getType(); - this.iValue = this.iEmbObjHandler.getValue(); - } - } - - public CIMDataType getType() { - return this.iType; - } - - /** - * getCIMArgument - * - * @return CIMArgument - */ - @Override - public CIMArgument getCIMArgument() { - /* - * CIMArgument(String name, CIMDataType type, Object value) - */ - return new CIMArgument(this.iName, this.iType, this.iValue); - } - - /** - * @see ValueIf#getValue() - */ - public Object getValue() { - return this.iValue; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus + * 1719991 2007-05-16 ebak FVT: regression ClassCastException in EmbObjHandler + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2605 2013-03-20 buccella SAX parser throws wrong exception + * 2537 2013-10-17 blaschke-oss Add new data types for PARAMVALUE + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMArgument; +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.EmbObjHandler; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT PARAMVALUE (VALUE | VALUE.REFERENCE | VALUE.ARRAY | VALUE.REFARRAY | + * CLASSNAME | INSTANCENAME | CLASS | INSTANCE | VALUE.NAMEDINSTANCE)? ATTLIST + * PARAMVALUE %CIMName; %ParamType; #IMPLIED %EmbeddedObject; #IMPLIED - new + */ +public class ParamValueNode extends AbstractParamValueNode { + private String iName; + + private EmbObjHandler iEmbObjHandler; + + private CIMDataType iType; + + // VALUE.xxx node + private boolean iHasChild; + + private boolean iHasTypeValue; + + private Object iValue; + + /** + * Ctor. + */ + public ParamValueNode() { + super(PARAMVALUE); + } + + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iEmbObjHandler = EmbObjHandler.init(this.iEmbObjHandler, getNodeName(), pAttribs, pSession, null, true); + this.iHasChild = false; + this.iHasTypeValue = false; + this.iName = getCIMName(pAttribs); + this.iType = null; + this.iValue = null; + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + private static final String[] ALLOWED_CHILDREN = { + VALUE, + VALUE_REFERENCE, + VALUE_ARRAY, + VALUE_REFARRAY, + CLASSNAME, + INSTANCENAME, + CLASS, + INSTANCE, + VALUE_NAMEDINSTANCE + }; + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + boolean allowed = false; + for (int i = 0; i < ALLOWED_CHILDREN.length; i++) { + if (ALLOWED_CHILDREN[i] == pNodeNameEnum) { + allowed = true; + break; + } + } + if (!allowed) throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!"); + if (this.iHasChild) throw new SAXException(getNodeName() + " node cannot have more than one child node!"); + // type check + CIMDataType rawType = this.iEmbObjHandler.getRawType(); + if (rawType != null) { + if (pNodeNameEnum == VALUE_REFERENCE || pNodeNameEnum == VALUE_REFARRAY) { + if (rawType.getType() != CIMDataType.REFERENCE) throw new SAXException( + "PARAMVALUE node's PARAMTYPE attribute is not reference (" + + rawType + + "), but a " + + pNodeNameEnum + + " child node is found!" + ); + } + } + } + + @Override + public void childParsed(Node pChild) { + if (pChild instanceof AbstractValueNode) { + this.iEmbObjHandler.addValueNode((AbstractValueNode) pChild); + } else { + this.iValue = ((ValueIf) pChild).getValue(); + if (pChild instanceof TypedIf) this.iType = ((TypedIf) pChild).getType(); else if ( + pChild instanceof ObjectPathIf + ) this.iType = CIMDataType.getDataType(((ObjectPathIf) pChild).getCIMObjectPath()); else if ( + pChild instanceof ValueIf + ) this.iType = CIMDataType.getDataType(((ValueIf) pChild).getValue()); + this.iHasTypeValue = true; + } + this.iHasChild = true; + } + + @Override + public void testCompletness() throws SAXException { + if (!this.iHasTypeValue) { + // here is a type and value conversion + this.iType = this.iEmbObjHandler.getType(); + this.iValue = this.iEmbObjHandler.getValue(); + } + } + + public CIMDataType getType() { + return this.iType; + } + + /** + * getCIMArgument + * + * @return CIMArgument + */ + @Override + public CIMArgument getCIMArgument() { + /* + * CIMArgument(String name, CIMDataType type, Object value) + */ + return new CIMArgument(this.iName, this.iType, this.iValue); + } + + /** + * @see ValueIf#getValue() + */ + public Object getValue() { + return this.iValue; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterArrayNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterArrayNode.java similarity index 63% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterArrayNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterArrayNode.java index 67a2fce..7837af3 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterArrayNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterArrayNode.java @@ -1,92 +1,86 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 1820763 2007-10-29 ebak Supporting the EmbeddedInstance qualifier - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2705 2013-11-11 blaschke-oss PARAMETER.ARRAY does not require TYPE attribute - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.EmbObjHandler; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT PARAMETER.ARRAY (QUALIFIER*)
      - * ATTLIST PARAMETER.ARRAY
      - *   %CIMName;
      - *   %CIMType;              #REQUIRED
      - *   %ArraySize;
      - * 
      - */ -public class ParameterArrayNode extends AbstractParameterNode { - - private CIMDataType iType; - - private EmbObjHandler iEmbObjHandler; - - /** - * Ctor. - */ - public ParameterArrayNode() { - super(PARAMETER_ARRAY); - } - - @Override - protected void specificInit(Attributes pAttribs) throws SAXException { - if (getCIMType(pAttribs, true) == null) throw new SAXException( - "PARAMETER.ARRAY element missing TYPE attribute!"); - this.iEmbObjHandler = EmbObjHandler.init(this.iEmbObjHandler, getNodeName(), pAttribs, - this.iSession, this.iQualiHandler, true); - } - - @Override - public void testCompletness() throws SAXException { - this.iType = this.iEmbObjHandler.getArrayType(); - } - - public CIMDataType getType() { - return this.iType; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 1820763 2007-10-29 ebak Supporting the EmbeddedInstance qualifier + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2705 2013-11-11 blaschke-oss PARAMETER.ARRAY does not require TYPE attribute + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.EmbObjHandler; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT PARAMETER.ARRAY (QUALIFIER*)
      + * ATTLIST PARAMETER.ARRAY
      + *   %CIMName;
      + *   %CIMType;              #REQUIRED
      + *   %ArraySize;
      + * 
      + */ +public class ParameterArrayNode extends AbstractParameterNode { + private CIMDataType iType; + + private EmbObjHandler iEmbObjHandler; + + /** + * Ctor. + */ + public ParameterArrayNode() { + super(PARAMETER_ARRAY); + } + + @Override + protected void specificInit(Attributes pAttribs) throws SAXException { + if (getCIMType(pAttribs, true) == null) throw new SAXException("PARAMETER.ARRAY element missing TYPE attribute!"); + this.iEmbObjHandler = + EmbObjHandler.init(this.iEmbObjHandler, getNodeName(), pAttribs, this.iSession, this.iQualiHandler, true); + } + + @Override + public void testCompletness() throws SAXException { + this.iType = this.iEmbObjHandler.getArrayType(); + } + + public CIMDataType getType() { + return this.iType; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterNode.java similarity index 60% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterNode.java index 44cdcf5..2b98633 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterNode.java @@ -1,88 +1,81 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 1820763 2007-10-29 ebak Supporting the EmbeddedInstance qualifier - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2704 2013-11-11 blaschke-oss PARAMETER does not require TYPE attribute - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.EmbObjHandler; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT PARAMETER (QUALIFIER*) ATTLIST PARAMETER %CIMName; %CIMType; - */ -public class ParameterNode extends AbstractParameterNode { - - private CIMDataType iType; - - private EmbObjHandler iEmbObjHandler; - - /** - * Ctor. - */ - public ParameterNode() { - super(PARAMETER); - } - - @Override - protected void specificInit(Attributes pAttribs) throws SAXException { - if (getCIMType(pAttribs, true) == null) throw new SAXException( - "PARAMETER element missing TYPE attribute!"); - this.iEmbObjHandler = EmbObjHandler.init(this.iEmbObjHandler, getNodeName(), pAttribs, - this.iSession, this.iQualiHandler, true); - } - - @Override - public void testCompletness() throws SAXException { - this.iType = this.iEmbObjHandler.getType(); - if (this.iType.isArray()) throw new SAXException( - "PARAMETER node's TYPE attribute cannot be an array!"); - } - - public CIMDataType getType() { - return this.iType; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 1820763 2007-10-29 ebak Supporting the EmbeddedInstance qualifier + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2704 2013-11-11 blaschke-oss PARAMETER does not require TYPE attribute + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.EmbObjHandler; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT PARAMETER (QUALIFIER*) ATTLIST PARAMETER %CIMName; %CIMType; + */ +public class ParameterNode extends AbstractParameterNode { + private CIMDataType iType; + + private EmbObjHandler iEmbObjHandler; + + /** + * Ctor. + */ + public ParameterNode() { + super(PARAMETER); + } + + @Override + protected void specificInit(Attributes pAttribs) throws SAXException { + if (getCIMType(pAttribs, true) == null) throw new SAXException("PARAMETER element missing TYPE attribute!"); + this.iEmbObjHandler = + EmbObjHandler.init(this.iEmbObjHandler, getNodeName(), pAttribs, this.iSession, this.iQualiHandler, true); + } + + @Override + public void testCompletness() throws SAXException { + this.iType = this.iEmbObjHandler.getType(); + if (this.iType.isArray()) throw new SAXException("PARAMETER node's TYPE attribute cannot be an array!"); + } + + public CIMDataType getType() { + return this.iType; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterRefArrayNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterRefArrayNode.java similarity index 70% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterRefArrayNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterRefArrayNode.java index b7dd3fb..9a3add4 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterRefArrayNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterRefArrayNode.java @@ -1,89 +1,85 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 1735614 2007-06-12 ebak Wrong ARRAYSIZE attribute handling in SAX/PULL - * 1820763 2007-10-29 ebak Supporting the EmbeddedInstance qualifier - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2433593 2008-12-18 rgummada isArray returns true for method parameters of type reference - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2605 2013-03-20 buccella SAX parser throws wrong exception - * 2636 2013-05-08 blaschke-oss Nested embedded instances cause CIMXMLParseException - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; - -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT PARAMETER.REFARRAY (QUALIFIER*)
      - * ATTLIST PARAMETER.REFARRAY
      - *   %CIMName;
      - *   %ReferenceClass;
      - *   %ArraySize;
      - * 
      - */ -public class ParameterRefArrayNode extends AbstractParameterNode { - - private CIMDataType iType; - - /** - * Ctor. - */ - public ParameterRefArrayNode() { - super(PARAMETER_REFARRAY); - } - - @Override - protected void specificInit(Attributes pAttribs) throws SAXException { - String refClass = getReferenceClass(pAttribs); - this.iType = new CIMDataType(refClass != null ? refClass : "", getArraySize(pAttribs)); - - } - - @Override - public void testCompletness() { /* */} - - public CIMDataType getType() { - return this.iType; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 1735614 2007-06-12 ebak Wrong ARRAYSIZE attribute handling in SAX/PULL + * 1820763 2007-10-29 ebak Supporting the EmbeddedInstance qualifier + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2433593 2008-12-18 rgummada isArray returns true for method parameters of type reference + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2605 2013-03-20 buccella SAX parser throws wrong exception + * 2636 2013-05-08 blaschke-oss Nested embedded instances cause CIMXMLParseException + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT PARAMETER.REFARRAY (QUALIFIER*)
      + * ATTLIST PARAMETER.REFARRAY
      + *   %CIMName;
      + *   %ReferenceClass;
      + *   %ArraySize;
      + * 
      + */ +public class ParameterRefArrayNode extends AbstractParameterNode { + private CIMDataType iType; + + /** + * Ctor. + */ + public ParameterRefArrayNode() { + super(PARAMETER_REFARRAY); + } + + @Override + protected void specificInit(Attributes pAttribs) throws SAXException { + String refClass = getReferenceClass(pAttribs); + this.iType = new CIMDataType(refClass != null ? refClass : "", getArraySize(pAttribs)); + } + + @Override + public void testCompletness() { + /* */ + } + + public CIMDataType getType() { + return this.iType; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterReferenceNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterReferenceNode.java similarity index 66% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterReferenceNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterReferenceNode.java index a59b476..37603db 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterReferenceNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ParameterReferenceNode.java @@ -1,83 +1,80 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 1820763 2007-10-29 ebak Supporting the EmbeddedInstance qualifier - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2636 2013-05-08 blaschke-oss Nested embedded instances cause CIMXMLParseException - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; - -import org.xml.sax.Attributes; - -/** - *
      - * ELEMENT PARAMETER.REFERENCE (QUALIFIER*)
      - * ATTLIST PARAMETER.REFERENCE
      - *   %CIMName;
      - *   %ReferenceClass;
      - * 
      - */ -public class ParameterReferenceNode extends AbstractParameterNode { - - private CIMDataType iType; - - /** - * Ctor. - */ - public ParameterReferenceNode() { - super(PARAMETER_REFERENCE); - } - - @Override - protected void specificInit(Attributes pAttribs) { - String refClass = getReferenceClass(pAttribs); - this.iType = new CIMDataType(refClass != null ? refClass : ""); - } - - @Override - public void testCompletness() { /* */} - - public CIMDataType getType() { - return this.iType; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 1820763 2007-10-29 ebak Supporting the EmbeddedInstance qualifier + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2636 2013-05-08 blaschke-oss Nested embedded instances cause CIMXMLParseException + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.xml.sax.Attributes; + +/** + *
      + * ELEMENT PARAMETER.REFERENCE (QUALIFIER*)
      + * ATTLIST PARAMETER.REFERENCE
      + *   %CIMName;
      + *   %ReferenceClass;
      + * 
      + */ +public class ParameterReferenceNode extends AbstractParameterNode { + private CIMDataType iType; + + /** + * Ctor. + */ + public ParameterReferenceNode() { + super(PARAMETER_REFERENCE); + } + + @Override + protected void specificInit(Attributes pAttribs) { + String refClass = getReferenceClass(pAttribs); + this.iType = new CIMDataType(refClass != null ? refClass : ""); + } + + @Override + public void testCompletness() { + /* */ + } + + public CIMDataType getType() { + return this.iType; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/PropertyArrayNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/PropertyArrayNode.java similarity index 71% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/PropertyArrayNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/PropertyArrayNode.java index 8383e9c..ffcb26c 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/PropertyArrayNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/PropertyArrayNode.java @@ -1,142 +1,138 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus - * 1714878 2007-05-08 ebak Empty string property values are parsed as nulls - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2701 2013-11-07 blaschke-oss PROPERTY.ARRAY does not require TYPE attribute - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMQualifier; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.EmbObjHandler; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT PROPERTY.ARRAY (QUALIFIER*, VALUE.ARRAY?)
      - * ATTLIST PROPERTY.ARRAY 
      - *   %CIMName;
      - *   %CIMType;              #REQUIRED
      - *   %ArraySize;
      - *   %ClassOrigin;
      - *   %Propagated;
      - *   %EmbeddedObject;    	#IMPLIED - new
      - *   xml:lang   NMTOKEN     #IMPLIED
      - * 
      - */ -public class PropertyArrayNode extends AbstractPropertyNode { - - // VALUE.ARRAY - // required for super.testChild() - private boolean iHasValueArray; - - private boolean iHasTypeAttribute; - - private CIMDataType iType; - - private Object iValue; - - private EmbObjHandler iEmbObjHandler; - - /** - * Ctor. - */ - public PropertyArrayNode() { - super(PROPERTY_ARRAY); - } - - @Override - protected void specificInit(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iHasTypeAttribute = (getCIMType(pAttribs, true) != null); - this.iEmbObjHandler = EmbObjHandler.init(this.iEmbObjHandler, getNodeName(), pAttribs, - pSession, this.iQualiHandler, true); - this.iHasValueArray = false; - } - - @Override - protected void childValueNodeParsed(Node pChild) throws SAXException { - if (!this.iHasTypeAttribute && ((ValueArrayNode) pChild).getType() == null) throw new SAXException( - "PROPERTY.ARRAY element missing TYPE attribute!"); - this.iEmbObjHandler.addValueNode((ValueArrayNode) pChild); - this.iHasValueArray = true; - } - - @Override - public void testCompletness() throws SAXException { - /* - * Value and type conversion are placed here. It can throw Exception. - */ - this.iType = this.iEmbObjHandler.getArrayType(); - this.iValue = this.iEmbObjHandler.getValue(); - } - - public CIMDataType getType() { - return this.iType; - } - - @Override - protected String getChildValueNodeNameEnum() { - return VALUE_ARRAY; - } - - public Object getValue() { - // if iHasValueArray is false iObjA is null, since nulled in init() - return this.iValue; - } - - @Override - protected boolean hasValueNode() { - return this.iHasValueArray; - } - - @Override - protected CIMQualifier[] getQualis() { - return this.iQualiHandler.getQualis(this.iType == CIMDataType.STRING_ARRAY_T); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus + * 1714878 2007-05-08 ebak Empty string property values are parsed as nulls + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2701 2013-11-07 blaschke-oss PROPERTY.ARRAY does not require TYPE attribute + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMQualifier; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.EmbObjHandler; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT PROPERTY.ARRAY (QUALIFIER*, VALUE.ARRAY?)
      + * ATTLIST PROPERTY.ARRAY
      + *   %CIMName;
      + *   %CIMType;              #REQUIRED
      + *   %ArraySize;
      + *   %ClassOrigin;
      + *   %Propagated;
      + *   %EmbeddedObject;    	#IMPLIED - new
      + *   xml:lang   NMTOKEN     #IMPLIED
      + * 
      + */ +public class PropertyArrayNode extends AbstractPropertyNode { + // VALUE.ARRAY + // required for super.testChild() + private boolean iHasValueArray; + + private boolean iHasTypeAttribute; + + private CIMDataType iType; + + private Object iValue; + + private EmbObjHandler iEmbObjHandler; + + /** + * Ctor. + */ + public PropertyArrayNode() { + super(PROPERTY_ARRAY); + } + + @Override + protected void specificInit(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iHasTypeAttribute = (getCIMType(pAttribs, true) != null); + this.iEmbObjHandler = + EmbObjHandler.init(this.iEmbObjHandler, getNodeName(), pAttribs, pSession, this.iQualiHandler, true); + this.iHasValueArray = false; + } + + @Override + protected void childValueNodeParsed(Node pChild) throws SAXException { + if (!this.iHasTypeAttribute && ((ValueArrayNode) pChild).getType() == null) throw new SAXException( + "PROPERTY.ARRAY element missing TYPE attribute!" + ); + this.iEmbObjHandler.addValueNode((ValueArrayNode) pChild); + this.iHasValueArray = true; + } + + @Override + public void testCompletness() throws SAXException { + /* + * Value and type conversion are placed here. It can throw Exception. + */ + this.iType = this.iEmbObjHandler.getArrayType(); + this.iValue = this.iEmbObjHandler.getValue(); + } + + public CIMDataType getType() { + return this.iType; + } + + @Override + protected String getChildValueNodeNameEnum() { + return VALUE_ARRAY; + } + + public Object getValue() { + // if iHasValueArray is false iObjA is null, since nulled in init() + return this.iValue; + } + + @Override + protected boolean hasValueNode() { + return this.iHasValueArray; + } + + @Override + protected CIMQualifier[] getQualis() { + return this.iQualiHandler.getQualis(this.iType == CIMDataType.STRING_ARRAY_T); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/PropertyNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/PropertyNode.java similarity index 70% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/PropertyNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/PropertyNode.java index 830e030..092158c 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/PropertyNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/PropertyNode.java @@ -1,139 +1,135 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus - * 1714878 2007-05-08 ebak Empty string property values are parsed as nulls - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2700 2013-11-07 blaschke-oss PROPERTY does not require TYPE attribute - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMQualifier; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.EmbObjHandler; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT PROPERTY (QUALIFIER*, VALUE?)
      - * ATTLIST PROPERTY 
      - *   %CIMName;
      - *   %ClassOrigin;
      - *   %Propagated;
      - *   %CIMType;              #REQUIRED
      - *   %EmbeddedObject;       #IMPLIED  - new
      - *   xml:lang   NMTOKEN     #IMPLIED
      - * 
      - */ -public class PropertyNode extends AbstractPropertyNode { - - private CIMDataType iType; - - // VALUE element - private boolean iHasValue; - - private boolean iHasTypeAttribute; - - private Object iValue; - - private EmbObjHandler iEmbObjHandler; - - /** - * Ctor. - */ - public PropertyNode() { - super(PROPERTY); - } - - @Override - protected void specificInit(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iHasTypeAttribute = (getCIMType(pAttribs, true) != null); - this.iEmbObjHandler = EmbObjHandler.init(this.iEmbObjHandler, getNodeName(), pAttribs, - pSession, this.iQualiHandler, true); - this.iHasValue = false; - } - - @Override - public void childValueNodeParsed(Node pChild) throws SAXException { - this.iHasValue = true; - if (!this.iHasTypeAttribute && ((ValueNode) pChild).getType() == null) throw new SAXException( - "PROPERTY element missing TYPE attribute!"); - this.iEmbObjHandler.addValueNode((ValueNode) pChild); - } - - @Override - protected String getChildValueNodeNameEnum() { - return VALUE; - } - - @Override - protected boolean hasValueNode() { - return this.iHasValue; - } - - @Override - protected CIMQualifier[] getQualis() { - return this.iQualiHandler.getQualis(getType() == CIMDataType.STRING_T); - } - - @Override - public void testCompletness() throws SAXException { - /* - * Value and type conversion are placed here. It can throw Exception. - */ - this.iType = this.iEmbObjHandler.getType(); - this.iValue = this.iEmbObjHandler.getValue(); - } - - public CIMDataType getType() { - return this.iType; - } - - public Object getValue() { - return this.iValue; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus + * 1714878 2007-05-08 ebak Empty string property values are parsed as nulls + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2700 2013-11-07 blaschke-oss PROPERTY does not require TYPE attribute + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMQualifier; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.EmbObjHandler; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT PROPERTY (QUALIFIER*, VALUE?)
      + * ATTLIST PROPERTY
      + *   %CIMName;
      + *   %ClassOrigin;
      + *   %Propagated;
      + *   %CIMType;              #REQUIRED
      + *   %EmbeddedObject;       #IMPLIED  - new
      + *   xml:lang   NMTOKEN     #IMPLIED
      + * 
      + */ +public class PropertyNode extends AbstractPropertyNode { + private CIMDataType iType; + + // VALUE element + private boolean iHasValue; + + private boolean iHasTypeAttribute; + + private Object iValue; + + private EmbObjHandler iEmbObjHandler; + + /** + * Ctor. + */ + public PropertyNode() { + super(PROPERTY); + } + + @Override + protected void specificInit(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iHasTypeAttribute = (getCIMType(pAttribs, true) != null); + this.iEmbObjHandler = + EmbObjHandler.init(this.iEmbObjHandler, getNodeName(), pAttribs, pSession, this.iQualiHandler, true); + this.iHasValue = false; + } + + @Override + public void childValueNodeParsed(Node pChild) throws SAXException { + this.iHasValue = true; + if (!this.iHasTypeAttribute && ((ValueNode) pChild).getType() == null) throw new SAXException( + "PROPERTY element missing TYPE attribute!" + ); + this.iEmbObjHandler.addValueNode((ValueNode) pChild); + } + + @Override + protected String getChildValueNodeNameEnum() { + return VALUE; + } + + @Override + protected boolean hasValueNode() { + return this.iHasValue; + } + + @Override + protected CIMQualifier[] getQualis() { + return this.iQualiHandler.getQualis(getType() == CIMDataType.STRING_T); + } + + @Override + public void testCompletness() throws SAXException { + /* + * Value and type conversion are placed here. It can throw Exception. + */ + this.iType = this.iEmbObjHandler.getType(); + this.iValue = this.iEmbObjHandler.getValue(); + } + + public CIMDataType getType() { + return this.iType; + } + + public Object getValue() { + return this.iValue; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/PropertyReferenceNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/PropertyReferenceNode.java similarity index 72% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/PropertyReferenceNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/PropertyReferenceNode.java index 2719b7a..95f2844 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/PropertyReferenceNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/PropertyReferenceNode.java @@ -1,121 +1,116 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus - * 1714878 2007-05-08 ebak Empty string property values are parsed as nulls - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2636 2013-05-08 blaschke-oss Nested embedded instances cause CIMXMLParseException - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; - -/** - *
      - * 
      - * ELEMENT PROPERTY.REFERENCE (QUALIFIER*, (VALUE.REFERENCE)?)
      - * ATTLIST PROPERTY.REFERENCE
      - *   %CIMName; 
      - *   %ReferenceClass; 
      - *   %ClassOrigin;
      - *   %Propagated;
      - * 
      - */ -public class PropertyReferenceNode extends AbstractPropertyNode { - - private String iRefClassName; - - // VALUE.REFERENCE - private boolean iHasValueRef; - - private Object iValue; - - /** - * Ctor. - */ - public PropertyReferenceNode() { - super(PROPERTY_REFERENCE); - } - - @Override - protected void childValueNodeParsed(Node pChild) { - this.iValue = ((ValueReferenceNode) pChild).getValue(); - this.iHasValueRef = true; - } - - @Override - protected String getChildValueNodeNameEnum() { - return VALUE_REFERENCE; - } - - public Object getValue() { - return this.iHasValueRef ? this.iValue : null; - } - - @Override - protected boolean hasValueNode() { - return this.iHasValueRef; - } - - /** - * @param pSession - */ - @Override - protected void specificInit(Attributes pAttribs, SAXSession pSession) { - this.iHasValueRef = false; - this.iRefClassName = getReferenceClass(pAttribs); - } - - @Override - public void testCompletness() { - // - } - - public CIMDataType getType() { - return new CIMDataType(this.iRefClassName != null ? this.iRefClassName : ""); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus + * 1714878 2007-05-08 ebak Empty string property values are parsed as nulls + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2636 2013-05-08 blaschke-oss Nested embedded instances cause CIMXMLParseException + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; + +/** + *
      + *
      + * ELEMENT PROPERTY.REFERENCE (QUALIFIER*, (VALUE.REFERENCE)?)
      + * ATTLIST PROPERTY.REFERENCE
      + *   %CIMName;
      + *   %ReferenceClass;
      + *   %ClassOrigin;
      + *   %Propagated;
      + * 
      + */ +public class PropertyReferenceNode extends AbstractPropertyNode { + private String iRefClassName; + + // VALUE.REFERENCE + private boolean iHasValueRef; + + private Object iValue; + + /** + * Ctor. + */ + public PropertyReferenceNode() { + super(PROPERTY_REFERENCE); + } + + @Override + protected void childValueNodeParsed(Node pChild) { + this.iValue = ((ValueReferenceNode) pChild).getValue(); + this.iHasValueRef = true; + } + + @Override + protected String getChildValueNodeNameEnum() { + return VALUE_REFERENCE; + } + + public Object getValue() { + return this.iHasValueRef ? this.iValue : null; + } + + @Override + protected boolean hasValueNode() { + return this.iHasValueRef; + } + + /** + * @param pSession + */ + @Override + protected void specificInit(Attributes pAttribs, SAXSession pSession) { + this.iHasValueRef = false; + this.iRefClassName = getReferenceClass(pAttribs); + } + + @Override + public void testCompletness() { + // + } + + public CIMDataType getType() { + return new CIMDataType(this.iRefClassName != null ? this.iRefClassName : ""); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/QualiDeclNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/QualiDeclNode.java similarity index 67% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/QualiDeclNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/QualiDeclNode.java index b2e4671..dafadd8 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/QualiDeclNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/QualiDeclNode.java @@ -1,223 +1,229 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1712656 2007-05-04 ebak Correct type identification for SVC CIMOM - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - * 3513353 2012-03-30 blaschke-oss TCK: CIMDataType arrays must have length >= 1 - * 3521119 2012-04-24 blaschke-oss JSR48 1.0.0: remove CIMObjectPath 2/3/4-parm ctors - * 2604 2013-07-01 blaschke-oss SAXException messages should contain node name - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import org.sentrysoftware.wbem.javax.cim.CIMQualifierType; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.CIMHelper; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.CIMObjectFactory; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT QUALIFIER.DECLARATION (SCOPE?, (VALUE | VALUE.ARRAY)?)
      - * ATTLIST QUALIFIER.DECLARATION 
      - * 	%CIMName;               
      - * 	%CIMType;               #REQUIRED
      - * 	ISARRAY    (true|false) #IMPLIED
      - * 	%ArraySize;
      - * 	%QualifierFlavor;
      - * 
      - */ -public class QualiDeclNode extends Node implements TypedIf, ValueIf { - - // child nodes - // SCOPE - private boolean iHasScope; - - private int iScope; - - // VALUE - private String iValueNodeName; - - private Object iValue; - - // attributes - private String iName; - - private CIMDataType iType; - - private int iFlavor; - - /** - * Ctor. - */ - public QualiDeclNode() { - super(QUALIFIER_DECLARATION); - } - - /** - * getName - * - * @return String - */ - public String getName() { - return this.iName; - } - - public CIMDataType getType() { - return this.iType; - } - - /** - * getFlavor - * - * @return int - CIMFlavor bitset - */ - public int getFlavor() { - return this.iFlavor; - } - - /** - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iHasScope = false; - this.iScope = 0; - this.iValueNodeName = null; - this.iValue = null; - this.iName = getCIMName(pAttribs); - this.iType = getCIMType(pAttribs, true); - this.iFlavor = getQualifierFlavor(pAttribs); - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum == VALUE || pNodeNameEnum == VALUE_ARRAY) { - if (this.iValueNodeName != null) throw new SAXException("Cannot add " + pNodeNameEnum - + " node, this " + getNodeName() + " node has already got a " - + this.iValueNodeName + " node!"); - } else if (pNodeNameEnum == SCOPE) { - if (this.iHasScope) throw new SAXException("Cannot add " + pNodeNameEnum - + " node, this " + getNodeName() + " node has already got one!"); - } else throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum - + " child node!"); - } - - /** - * Required to handle the output XML of some non-standard CIMOMs like SVC - * which adds the TYPE attribute to the sub VALUE or VALUE.ARRAY XML - * element. - * - * @param pTypedIf - * @throws SAXException - */ - private void setType(TypedIf pTypedIf) throws SAXException { - if (this.iType != null) return; - this.iType = pTypedIf.getType(); - if (this.iType == null) throw new SAXException("Unknown type for Qualifier declaration in " - + getNodeName() + " node!"); - } - - @Override - public void childParsed(Node pChild) throws SAXException { - if (pChild instanceof ScopeNode) { - this.iHasScope = true; - this.iScope = ((ScopeNode) pChild).getScope(); - } else { - this.iValueNodeName = pChild.getNodeName(); - if (pChild instanceof ValueArrayNode) { - ValueArrayNode valAChild = (ValueArrayNode) pChild; - setType(valAChild); - this.iValue = CIMObjectFactory.getObject(this.iType, valAChild); - // making array type - if (!this.iType.isArray()) this.iType = CIMHelper.UnboundedArrayDataType(this.iType - .getType()); - } else if (pChild instanceof ValueNode) { - ValueNode valChild = (ValueNode) pChild; - setType(valChild); - this.iValue = CIMObjectFactory.getObject(this.iType, valChild); - } else { - this.iValue = null; - } - } - - } - - @Override - public void testCompletness() throws SAXException { - if (this.iType == null) throw new SAXException("Unknown type for Qualifier declaration in " - + getNodeName() + " node!"); - } - - /** - * getCIMQualifierType - * - * @return CIMQualifierType - */ - public CIMQualifierType getCIMQualifierType() { - /* - * CIMQualifierType( CIMObjectPath pPath, CIMDataType pType, Object - * pValue, int pScope, int pFlavor ) - */ - return new CIMQualifierType(new CIMObjectPath(null, null, null, null, this.iName, - null), this.iType, this.iValue, this.iScope, this.iFlavor); - } - - public Object getValue() { - return getCIMQualifierType(); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1712656 2007-05-04 ebak Correct type identification for SVC CIMOM + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + * 3513353 2012-03-30 blaschke-oss TCK: CIMDataType arrays must have length >= 1 + * 3521119 2012-04-24 blaschke-oss JSR48 1.0.0: remove CIMObjectPath 2/3/4-parm ctors + * 2604 2013-07-01 blaschke-oss SAXException messages should contain node name + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.cim.CIMQualifierType; +import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMHelper; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.CIMObjectFactory; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT QUALIFIER.DECLARATION (SCOPE?, (VALUE | VALUE.ARRAY)?)
      + * ATTLIST QUALIFIER.DECLARATION
      + * 	%CIMName;
      + * 	%CIMType;               #REQUIRED
      + * 	ISARRAY    (true|false) #IMPLIED
      + * 	%ArraySize;
      + * 	%QualifierFlavor;
      + * 
      + */ +public class QualiDeclNode extends Node implements TypedIf, ValueIf { + // child nodes + // SCOPE + private boolean iHasScope; + + private int iScope; + + // VALUE + private String iValueNodeName; + + private Object iValue; + + // attributes + private String iName; + + private CIMDataType iType; + + private int iFlavor; + + /** + * Ctor. + */ + public QualiDeclNode() { + super(QUALIFIER_DECLARATION); + } + + /** + * getName + * + * @return String + */ + public String getName() { + return this.iName; + } + + public CIMDataType getType() { + return this.iType; + } + + /** + * getFlavor + * + * @return int - CIMFlavor bitset + */ + public int getFlavor() { + return this.iFlavor; + } + + /** + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iHasScope = false; + this.iScope = 0; + this.iValueNodeName = null; + this.iValue = null; + this.iName = getCIMName(pAttribs); + this.iType = getCIMType(pAttribs, true); + this.iFlavor = getQualifierFlavor(pAttribs); + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum == VALUE || pNodeNameEnum == VALUE_ARRAY) { + if (this.iValueNodeName != null) throw new SAXException( + "Cannot add " + + pNodeNameEnum + + " node, this " + + getNodeName() + + " node has already got a " + + this.iValueNodeName + + " node!" + ); + } else if (pNodeNameEnum == SCOPE) { + if (this.iHasScope) throw new SAXException( + "Cannot add " + pNodeNameEnum + " node, this " + getNodeName() + " node has already got one!" + ); + } else throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child node!"); + } + + /** + * Required to handle the output XML of some non-standard CIMOMs like SVC + * which adds the TYPE attribute to the sub VALUE or VALUE.ARRAY XML + * element. + * + * @param pTypedIf + * @throws SAXException + */ + private void setType(TypedIf pTypedIf) throws SAXException { + if (this.iType != null) return; + this.iType = pTypedIf.getType(); + if (this.iType == null) throw new SAXException( + "Unknown type for Qualifier declaration in " + getNodeName() + " node!" + ); + } + + @Override + public void childParsed(Node pChild) throws SAXException { + if (pChild instanceof ScopeNode) { + this.iHasScope = true; + this.iScope = ((ScopeNode) pChild).getScope(); + } else { + this.iValueNodeName = pChild.getNodeName(); + if (pChild instanceof ValueArrayNode) { + ValueArrayNode valAChild = (ValueArrayNode) pChild; + setType(valAChild); + this.iValue = CIMObjectFactory.getObject(this.iType, valAChild); + // making array type + if (!this.iType.isArray()) this.iType = CIMHelper.UnboundedArrayDataType(this.iType.getType()); + } else if (pChild instanceof ValueNode) { + ValueNode valChild = (ValueNode) pChild; + setType(valChild); + this.iValue = CIMObjectFactory.getObject(this.iType, valChild); + } else { + this.iValue = null; + } + } + } + + @Override + public void testCompletness() throws SAXException { + if (this.iType == null) throw new SAXException( + "Unknown type for Qualifier declaration in " + getNodeName() + " node!" + ); + } + + /** + * getCIMQualifierType + * + * @return CIMQualifierType + */ + public CIMQualifierType getCIMQualifierType() { + /* + * CIMQualifierType( CIMObjectPath pPath, CIMDataType pType, Object + * pValue, int pScope, int pFlavor ) + */ + return new CIMQualifierType( + new CIMObjectPath(null, null, null, null, this.iName, null), + this.iType, + this.iValue, + this.iScope, + this.iFlavor + ); + } + + public Object getValue() { + return getCIMQualifierType(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/QualifiedNodeHandler.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/QualifiedNodeHandler.java similarity index 76% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/QualifiedNodeHandler.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/QualifiedNodeHandler.java index 01ac197..3c94404 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/QualifiedNodeHandler.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/QualifiedNodeHandler.java @@ -1,200 +1,195 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1783288 2007-09-10 ebak CIMClass.isAssociation() not working for retrieved classes. - * 1820763 2007-10-29 ebak Supporting the EmbeddedInstance qualifier - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2013628 2008-07-30 rgummada SAXException when listing classes - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2823494 2009-08-03 rgummada Change Boolean constructor to static - * 2957387 2010-03-03 blaschke-oss EmbededObject XML attribute must not be all uppercases - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMQualifier; - -import org.sentrysoftware.wbem.sblim.cimclient.GenericExts; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.CIMQualifiedElementInterfaceImpl; - -/** - * Class QualifiedNodeHandler helps parsing XML elements with QUALIFIER child - * elements. - */ -public class QualifiedNodeHandler { - - private static final Boolean TRUE = Boolean.TRUE; - - private ArrayList> iQualiAL; - - private CIMQualifiedElementInterfaceImpl iQualiImpl; - - private boolean iHasEmbObjQuali, iHasEmbInstQuali; - - private boolean iHasKeyQuali, iHasAssocQuali; - - /** - * init - * - * @param pQNH - * - if it's null it returns with a new instance otherwise it - * inits and returns pQNH - * @return a QualifiedNodeHandler instance - */ - public static QualifiedNodeHandler init(QualifiedNodeHandler pQNH) { - if (pQNH == null) pQNH = new QualifiedNodeHandler(); - pQNH.init(); - return pQNH; - } - - /** - * init - for reusing an existing QualifiedNodeHandler instance - */ - public void init() { - this.iQualiAL = GenericExts.initClearArrayList(this.iQualiAL); - this.iHasEmbObjQuali = this.iHasEmbInstQuali = this.iHasKeyQuali = this.iHasAssocQuali = false; - this.iQualiImpl = null; - } - - /** - * addQualifierNode - * - * @param pNode - * @return false if pNode is not instance of QualifierNode - */ - public boolean addQualifierNode(Node pNode) { - if (!(pNode instanceof QualifierNode)) return false; - if (this.iQualiAL == null) this.iQualiAL = new ArrayList>(); - CIMQualifier quali = ((QualifierNode) pNode).getQualifier(); - if (quali != null) { - // check for null, - // because it can be null if child node is not populated - if (CIMDataType.BOOLEAN_T.equals(quali.getDataType()) && TRUE.equals(quali.getValue())) { - if ("EmbeddedObject".equalsIgnoreCase(quali.getName())) { - this.iHasEmbObjQuali = true; - } else if ("KEY".equalsIgnoreCase(quali.getName())) { - this.iHasKeyQuali = true; - } else if ("ASSOCIATION".equalsIgnoreCase(quali.getName())) { - this.iHasAssocQuali = true; - } - } else if (CIMDataType.STRING_T.equals(quali.getDataType()) - && "EMBEDDEDINSTANCE".equalsIgnoreCase(quali.getName())) { - this.iHasEmbInstQuali = true; - } - this.iQualiAL.add(quali); - } - return true; - } - - /** - * getQualis - * - * @return CIMQualifier[] - */ - public CIMQualifier[] getQualis() { - return getQualis(false); - } - - /** - * getQualis - * - * @param pIncludeEmbObj - * @return CIMQualifier[] - */ - public CIMQualifier[] getQualis(boolean pIncludeEmbObj) { - makeQualiImpl(pIncludeEmbObj); - return this.iQualiImpl.getQualifiers(); - } - - /** - * isKeyed - * - * @return boolean - */ - public boolean isKeyed() { - return this.iHasKeyQuali; - } - - /** - * isAssociation - * - * @return boolean - */ - public boolean isAssociation() { - return this.iHasAssocQuali; - } - - /** - * isEmbeddedObject - * - * @return boolean - */ - public boolean isEmbeddedObject() { - return this.iHasEmbObjQuali; - } - - /** - * isEmbeddedInstance - * - * @return boolean - */ - public boolean isEmbeddedInstance() { - return this.iHasEmbInstQuali; - } - - private static final CIMQualifier[] EMPTY_QA = new CIMQualifier[0]; - - private void makeQualiImpl(boolean pIncludeEmbObj) { - if (this.iQualiImpl != null) return; - if (this.iQualiAL == null) { - this.iQualiImpl = new CIMQualifiedElementInterfaceImpl(null); - return; - } - this.iQualiImpl = new CIMQualifiedElementInterfaceImpl(this.iQualiAL.toArray(EMPTY_QA), - this.iHasKeyQuali, pIncludeEmbObj); - this.iQualiAL = null; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1783288 2007-09-10 ebak CIMClass.isAssociation() not working for retrieved classes. + * 1820763 2007-10-29 ebak Supporting the EmbeddedInstance qualifier + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2013628 2008-07-30 rgummada SAXException when listing classes + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2823494 2009-08-03 rgummada Change Boolean constructor to static + * 2957387 2010-03-03 blaschke-oss EmbededObject XML attribute must not be all uppercases + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMQualifier; +import org.metricshub.wbem.sblim.cimclient.GenericExts; +import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMQualifiedElementInterfaceImpl; + +/** + * Class QualifiedNodeHandler helps parsing XML elements with QUALIFIER child + * elements. + */ +public class QualifiedNodeHandler { + private static final Boolean TRUE = Boolean.TRUE; + + private ArrayList> iQualiAL; + + private CIMQualifiedElementInterfaceImpl iQualiImpl; + + private boolean iHasEmbObjQuali, iHasEmbInstQuali; + + private boolean iHasKeyQuali, iHasAssocQuali; + + /** + * init + * + * @param pQNH + * - if it's null it returns with a new instance otherwise it + * inits and returns pQNH + * @return a QualifiedNodeHandler instance + */ + public static QualifiedNodeHandler init(QualifiedNodeHandler pQNH) { + if (pQNH == null) pQNH = new QualifiedNodeHandler(); + pQNH.init(); + return pQNH; + } + + /** + * init - for reusing an existing QualifiedNodeHandler instance + */ + public void init() { + this.iQualiAL = GenericExts.initClearArrayList(this.iQualiAL); + this.iHasEmbObjQuali = this.iHasEmbInstQuali = this.iHasKeyQuali = this.iHasAssocQuali = false; + this.iQualiImpl = null; + } + + /** + * addQualifierNode + * + * @param pNode + * @return false if pNode is not instance of QualifierNode + */ + public boolean addQualifierNode(Node pNode) { + if (!(pNode instanceof QualifierNode)) return false; + if (this.iQualiAL == null) this.iQualiAL = new ArrayList>(); + CIMQualifier quali = ((QualifierNode) pNode).getQualifier(); + if (quali != null) { + // check for null, + // because it can be null if child node is not populated + if (CIMDataType.BOOLEAN_T.equals(quali.getDataType()) && TRUE.equals(quali.getValue())) { + if ("EmbeddedObject".equalsIgnoreCase(quali.getName())) { + this.iHasEmbObjQuali = true; + } else if ("KEY".equalsIgnoreCase(quali.getName())) { + this.iHasKeyQuali = true; + } else if ("ASSOCIATION".equalsIgnoreCase(quali.getName())) { + this.iHasAssocQuali = true; + } + } else if ( + CIMDataType.STRING_T.equals(quali.getDataType()) && "EMBEDDEDINSTANCE".equalsIgnoreCase(quali.getName()) + ) { + this.iHasEmbInstQuali = true; + } + this.iQualiAL.add(quali); + } + return true; + } + + /** + * getQualis + * + * @return CIMQualifier[] + */ + public CIMQualifier[] getQualis() { + return getQualis(false); + } + + /** + * getQualis + * + * @param pIncludeEmbObj + * @return CIMQualifier[] + */ + public CIMQualifier[] getQualis(boolean pIncludeEmbObj) { + makeQualiImpl(pIncludeEmbObj); + return this.iQualiImpl.getQualifiers(); + } + + /** + * isKeyed + * + * @return boolean + */ + public boolean isKeyed() { + return this.iHasKeyQuali; + } + + /** + * isAssociation + * + * @return boolean + */ + public boolean isAssociation() { + return this.iHasAssocQuali; + } + + /** + * isEmbeddedObject + * + * @return boolean + */ + public boolean isEmbeddedObject() { + return this.iHasEmbObjQuali; + } + + /** + * isEmbeddedInstance + * + * @return boolean + */ + public boolean isEmbeddedInstance() { + return this.iHasEmbInstQuali; + } + + private static final CIMQualifier[] EMPTY_QA = new CIMQualifier[0]; + + private void makeQualiImpl(boolean pIncludeEmbObj) { + if (this.iQualiImpl != null) return; + if (this.iQualiAL == null) { + this.iQualiImpl = new CIMQualifiedElementInterfaceImpl(null); + return; + } + this.iQualiImpl = + new CIMQualifiedElementInterfaceImpl(this.iQualiAL.toArray(EMPTY_QA), this.iHasKeyQuali, pIncludeEmbObj); + this.iQualiAL = null; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/QualifierNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/QualifierNode.java similarity index 69% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/QualifierNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/QualifierNode.java index e23b8f0..0e91c22 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/QualifierNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/QualifierNode.java @@ -1,189 +1,185 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1712656 2007-05-04 ebak Correct type identification for SVC CIMOM - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 1737141 2007-06-18 ebak Sync up with JSR48 evolution - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2013628 2008-07-30 rgummada SAXException when listing classes - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 3513353 2012-03-30 blaschke-oss TCK: CIMDataType arrays must have length >= 1 - * 2604 2013-07-01 blaschke-oss SAXException messages should contain node name - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMQualifier; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.CIMHelper; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.CIMObjectFactory; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT QUALIFIER ((VALUE | VALUE.ARRAY)?)
      - * ATTLIST QUALIFIER 
      - *  %CIMName;
      - *  %CIMType;              #REQUIRED
      - *  %Propagated;
      - *  %QualifierFlavor;
      - *  xml:lang   NMTOKEN     #IMPLIED
      - * 
      - */ -public class QualifierNode extends Node { - - private String iName; - - private CIMDataType iType; - - private boolean iPropagated; - - private int iFlavor; - - // (VALUE | VALUE.ARRAY) - // it can be built when child is available - private CIMQualifier iQuali; - - /** - * Ctor. - */ - public QualifierNode() { - super(QUALIFIER); - } - - /** - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iQuali = null; - this.iName = getCIMName(pAttribs); - /* - * non-standard CIMOM can supply the type info in the sub Node - */ - this.iType = getCIMType(pAttribs, true); - - this.iPropagated = getPropagated(pAttribs); - this.iFlavor = getQualifierFlavor(pAttribs); - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (this.iQuali != null) throw new SAXException(getNodeName() - + " node can have only one VALUE or VALUE.ARRAY child node!"); - if (pNodeNameEnum != VALUE && pNodeNameEnum != VALUE_ARRAY) throw new SAXException( - pNodeNameEnum + " child node is not valid for " + getNodeName() + " node!"); - } - - @Override - public void childParsed(Node pChild) throws SAXException { - AbstractValueNode absValNode = (AbstractValueNode) pChild; - Object value; - CIMDataType type; - if (absValNode instanceof ValueArrayNode) { - ValueArrayNode valANode = (ValueArrayNode) absValNode; - setType(valANode); - // create array value - value = CIMObjectFactory.getObject(this.iType, valANode); - // constructs array type - type = this.iType.isArray() ? this.iType : CIMHelper.UnboundedArrayDataType(this.iType - .getType()); - } else if (absValNode instanceof ValueNode) { - ValueNode valNode = (ValueNode) absValNode; - setType(valNode); - String valueStr = (String) valNode.getValue(); - type = this.iType; - value = CIMObjectFactory.getObject(type, valueStr); - } else { - type = CIMDataType.STRING_T; - value = null; - } - this.iQuali = new CIMQualifier(this.iName, type, value, this.iFlavor, - this.iPropagated); - } - - @Override - public void testCompletness() { - // child node is optional, hence commented to support - // servers that do not implement default value to qualifier node - /* - * if (iQuali == null) throw new SAXException(getNodeName() + " must have a - * VALUE or VALUE.ARRAY child node!"); - */ - } - - /** - * getQualifier - * - * @return CIMQualifier - */ - public CIMQualifier getQualifier() { - return this.iQuali; - } - - /** - * Required to handle the output XML of some non-standard CIMOMs like SVC - * which adds the TYPE attribute to the sub VALUE or VALUE.ARRAY XML - * element. - * - * @param pTypedIf - * @throws SAXException - */ - private void setType(TypedIf pTypedIf) throws SAXException { - if (this.iType != null) return; - this.iType = pTypedIf.getType(); - if (this.iType == null) throw new SAXException("Unknown type for Qualifier declaration in " - + getNodeName() + " node!"); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1712656 2007-05-04 ebak Correct type identification for SVC CIMOM + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 1737141 2007-06-18 ebak Sync up with JSR48 evolution + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2013628 2008-07-30 rgummada SAXException when listing classes + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 3513353 2012-03-30 blaschke-oss TCK: CIMDataType arrays must have length >= 1 + * 2604 2013-07-01 blaschke-oss SAXException messages should contain node name + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMQualifier; +import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMHelper; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.CIMObjectFactory; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT QUALIFIER ((VALUE | VALUE.ARRAY)?)
      + * ATTLIST QUALIFIER
      + *  %CIMName;
      + *  %CIMType;              #REQUIRED
      + *  %Propagated;
      + *  %QualifierFlavor;
      + *  xml:lang   NMTOKEN     #IMPLIED
      + * 
      + */ +public class QualifierNode extends Node { + private String iName; + + private CIMDataType iType; + + private boolean iPropagated; + + private int iFlavor; + + // (VALUE | VALUE.ARRAY) + // it can be built when child is available + private CIMQualifier iQuali; + + /** + * Ctor. + */ + public QualifierNode() { + super(QUALIFIER); + } + + /** + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iQuali = null; + this.iName = getCIMName(pAttribs); + /* + * non-standard CIMOM can supply the type info in the sub Node + */ + this.iType = getCIMType(pAttribs, true); + + this.iPropagated = getPropagated(pAttribs); + this.iFlavor = getQualifierFlavor(pAttribs); + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (this.iQuali != null) throw new SAXException( + getNodeName() + " node can have only one VALUE or VALUE.ARRAY child node!" + ); + if (pNodeNameEnum != VALUE && pNodeNameEnum != VALUE_ARRAY) throw new SAXException( + pNodeNameEnum + " child node is not valid for " + getNodeName() + " node!" + ); + } + + @Override + public void childParsed(Node pChild) throws SAXException { + AbstractValueNode absValNode = (AbstractValueNode) pChild; + Object value; + CIMDataType type; + if (absValNode instanceof ValueArrayNode) { + ValueArrayNode valANode = (ValueArrayNode) absValNode; + setType(valANode); + // create array value + value = CIMObjectFactory.getObject(this.iType, valANode); + // constructs array type + type = this.iType.isArray() ? this.iType : CIMHelper.UnboundedArrayDataType(this.iType.getType()); + } else if (absValNode instanceof ValueNode) { + ValueNode valNode = (ValueNode) absValNode; + setType(valNode); + String valueStr = (String) valNode.getValue(); + type = this.iType; + value = CIMObjectFactory.getObject(type, valueStr); + } else { + type = CIMDataType.STRING_T; + value = null; + } + this.iQuali = new CIMQualifier(this.iName, type, value, this.iFlavor, this.iPropagated); + } + + @Override + public void testCompletness() { + // child node is optional, hence commented to support + // servers that do not implement default value to qualifier node + /* + * if (iQuali == null) throw new SAXException(getNodeName() + " must have a + * VALUE or VALUE.ARRAY child node!"); + */ + } + + /** + * getQualifier + * + * @return CIMQualifier + */ + public CIMQualifier getQualifier() { + return this.iQuali; + } + + /** + * Required to handle the output XML of some non-standard CIMOMs like SVC + * which adds the TYPE attribute to the sub VALUE or VALUE.ARRAY XML + * element. + * + * @param pTypedIf + * @throws SAXException + */ + private void setType(TypedIf pTypedIf) throws SAXException { + if (this.iType != null) return; + this.iType = pTypedIf.getType(); + if (this.iType == null) throw new SAXException( + "Unknown type for Qualifier declaration in " + getNodeName() + " node!" + ); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/RetValPipeIf.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/RetValPipeIf.java similarity index 62% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/RetValPipeIf.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/RetValPipeIf.java index 7bda54b..6dbfdce 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/RetValPipeIf.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/RetValPipeIf.java @@ -1,63 +1,59 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-05 ebak Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * RetValPipeIf is a FIFO interface which helps PULL parsing. - */ -public interface RetValPipeIf { - - /** - * getReturnValueCount - * - * @return the currently available return values - */ - public abstract int getReturnValueCount(); - - /** - * readReturnValue - * - * @return a return value Object from a FIFO - */ - public abstract Object readReturnValue(); - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-05 ebak Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * RetValPipeIf is a FIFO interface which helps PULL parsing. + */ +public interface RetValPipeIf { + /** + * getReturnValueCount + * + * @return the currently available return values + */ + public abstract int getReturnValueCount(); + + /** + * readReturnValue + * + * @return a return value Object from a FIFO + */ + public abstract Object readReturnValue(); +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ReturnValueNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ReturnValueNode.java similarity index 70% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ReturnValueNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ReturnValueNode.java index efe742f..e5aa07c 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ReturnValueNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ReturnValueNode.java @@ -1,145 +1,141 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 1742873 2007-06-25 ebak IPv6 ready cim-client - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 3194700 2011-03-01 blaschke-oss Exception thrown on extrinsic methods - * 3602604 2013-01-29 blaschke-oss Clean up SAXException messages - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.EmbObjHandler; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT RETURNVALUE (VALUE | VALUE.REFERENCE)?
      - * ATTLIST RETURNVALUE
      - *   %ParamType;       #IMPLIED
      - *   %EmbeddedObject;  #IMPLIED - new
      - * 
      - */ -public class ReturnValueNode extends Node implements TypedIf, ValueIf { - - private EmbObjHandler iEmbObjHandler; - - private CIMDataType iType; - - // (VALUE | VALUE.REFERENCE) - private boolean iHasValue; - - private Object iValue; - - /** - * Ctor. - */ - public ReturnValueNode() { - super(RETURNVALUE); - } - - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iType = null; - this.iValue = null; - this.iEmbObjHandler = EmbObjHandler.init(this.iEmbObjHandler, getNodeName(), pAttribs, - pSession, null, true); - this.iHasValue = false; - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum == VALUE || pNodeNameEnum == VALUE_REFERENCE) { - if (this.iHasValue) throw new SAXException(getNodeName() - + " node can have only one child node!"); - } else throw new SAXException(pNodeNameEnum + " cannot be the child node of " - + getNodeName() + " node!"); - } - - @Override - public void childParsed(Node pChild) throws SAXException { - AbstractValueNode valNode = (AbstractValueNode) pChild; - if (valNode instanceof ValueReferenceNode) { - if (this.iType != null && this.iType.getType() != CIMDataType.REFERENCE) throw new SAXException( - getNodeName() + " node's child node is VALUE.REFERENCE " - + "but its type based on PARAMTYPE attribute is " + this.iType + "!"); - ValueReferenceNode valRefNode = (ValueReferenceNode) valNode; - this.iValue = valRefNode.getCIMObjectPath(); - this.iType = valRefNode.getType(); - } else { // VALUE node - this.iEmbObjHandler.addValueNode((ValueNode) pChild); - } - this.iHasValue = true; - } - - @Override - public void testCompletness() throws SAXException { - // DSP0203 v2.3 changed these from required to optional - // if (!this.iHasValue) throw new SAXException(getNodeName() - // + " node must have a VALUE or VALUE.REFERENCE child node!"); - if (this.iType == null) { - this.iType = this.iEmbObjHandler.getType(); - this.iValue = this.iEmbObjHandler.getValue(); - } - } - - public CIMDataType getType() { - return this.iType; - } - - public Object getValue() { - return this.iValue; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1689085 2007-04-10 ebak Embedded object enhancements for Pegasus + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 1742873 2007-06-25 ebak IPv6 ready cim-client + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 3194700 2011-03-01 blaschke-oss Exception thrown on extrinsic methods + * 3602604 2013-01-29 blaschke-oss Clean up SAXException messages + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.EmbObjHandler; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT RETURNVALUE (VALUE | VALUE.REFERENCE)?
      + * ATTLIST RETURNVALUE
      + *   %ParamType;       #IMPLIED
      + *   %EmbeddedObject;  #IMPLIED - new
      + * 
      + */ +public class ReturnValueNode extends Node implements TypedIf, ValueIf { + private EmbObjHandler iEmbObjHandler; + + private CIMDataType iType; + + // (VALUE | VALUE.REFERENCE) + private boolean iHasValue; + + private Object iValue; + + /** + * Ctor. + */ + public ReturnValueNode() { + super(RETURNVALUE); + } + + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iType = null; + this.iValue = null; + this.iEmbObjHandler = EmbObjHandler.init(this.iEmbObjHandler, getNodeName(), pAttribs, pSession, null, true); + this.iHasValue = false; + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum == VALUE || pNodeNameEnum == VALUE_REFERENCE) { + if (this.iHasValue) throw new SAXException(getNodeName() + " node can have only one child node!"); + } else throw new SAXException(pNodeNameEnum + " cannot be the child node of " + getNodeName() + " node!"); + } + + @Override + public void childParsed(Node pChild) throws SAXException { + AbstractValueNode valNode = (AbstractValueNode) pChild; + if (valNode instanceof ValueReferenceNode) { + if (this.iType != null && this.iType.getType() != CIMDataType.REFERENCE) throw new SAXException( + getNodeName() + + " node's child node is VALUE.REFERENCE " + + "but its type based on PARAMTYPE attribute is " + + this.iType + + "!" + ); + ValueReferenceNode valRefNode = (ValueReferenceNode) valNode; + this.iValue = valRefNode.getCIMObjectPath(); + this.iType = valRefNode.getType(); + } else { // VALUE node + this.iEmbObjHandler.addValueNode((ValueNode) pChild); + } + this.iHasValue = true; + } + + @Override + public void testCompletness() throws SAXException { + // DSP0203 v2.3 changed these from required to optional + // if (!this.iHasValue) throw new SAXException(getNodeName() + // + " node must have a VALUE or VALUE.REFERENCE child node!"); + if (this.iType == null) { + this.iType = this.iEmbObjHandler.getType(); + this.iValue = this.iEmbObjHandler.getValue(); + } + } + + public CIMDataType getType() { + return this.iType; + } + + public Object getValue() { + return this.iValue; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ScopeNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ScopeNode.java similarity index 73% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ScopeNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ScopeNode.java index c8a1061..a505987 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ScopeNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ScopeNode.java @@ -1,130 +1,125 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMScope; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT SCOPE EMPTY
      - * ATTLIST SCOPE
      - *     CLASS (true | false) "false"
      - *     ASSOCIATION (true | false) "false"
      - *     REFERENCE (true | false) "false"
      - *     PROPERTY (true | false) "false"
      - *     METHOD (true | false) "false"
      - *     PARAMETER (true | false) "false"
      - *     INDICATION (true | false) "false"
      - * 
      - */ -public class ScopeNode extends Node { - - private int iScope; - - /** - * Ctor. - */ - public ScopeNode() { - super(SCOPE); - } - - /** - * getScope - * - * @return int - set of CIMScope bits - */ - public int getScope() { - return this.iScope; - } - - /** - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - this.iScope = 0; - if (hasTrueAttribute(pAttribs, "CLASS")) this.iScope |= CIMScope.CLASS; - if (hasTrueAttribute(pAttribs, "ASSOCIATION")) this.iScope |= CIMScope.ASSOCIATION; - if (hasTrueAttribute(pAttribs, "REFERENCE")) this.iScope |= CIMScope.REFERENCE; - if (hasTrueAttribute(pAttribs, "PROPERTY")) this.iScope |= CIMScope.PROPERTY; - if (hasTrueAttribute(pAttribs, "METHOD")) this.iScope |= CIMScope.METHOD; - if (hasTrueAttribute(pAttribs, "PARAMETER")) this.iScope |= CIMScope.PARAMETER; - if (hasTrueAttribute(pAttribs, "INDICATION")) this.iScope |= CIMScope.INDICATION; - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - /** - * @param pNodeNameEnum - */ - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - throw new SAXException("SCOPE node cannot have any child node!"); - } - - /** - * @param pChild - */ - @Override - public void childParsed(Node pChild) { - // no child - } - - @Override - public void testCompletness() { - // Nothing to test, since it doesn't have any child node. - } - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMScope; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT SCOPE EMPTY
      + * ATTLIST SCOPE
      + *     CLASS (true | false) "false"
      + *     ASSOCIATION (true | false) "false"
      + *     REFERENCE (true | false) "false"
      + *     PROPERTY (true | false) "false"
      + *     METHOD (true | false) "false"
      + *     PARAMETER (true | false) "false"
      + *     INDICATION (true | false) "false"
      + * 
      + */ +public class ScopeNode extends Node { + private int iScope; + + /** + * Ctor. + */ + public ScopeNode() { + super(SCOPE); + } + + /** + * getScope + * + * @return int - set of CIMScope bits + */ + public int getScope() { + return this.iScope; + } + + /** + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + this.iScope = 0; + if (hasTrueAttribute(pAttribs, "CLASS")) this.iScope |= CIMScope.CLASS; + if (hasTrueAttribute(pAttribs, "ASSOCIATION")) this.iScope |= CIMScope.ASSOCIATION; + if (hasTrueAttribute(pAttribs, "REFERENCE")) this.iScope |= CIMScope.REFERENCE; + if (hasTrueAttribute(pAttribs, "PROPERTY")) this.iScope |= CIMScope.PROPERTY; + if (hasTrueAttribute(pAttribs, "METHOD")) this.iScope |= CIMScope.METHOD; + if (hasTrueAttribute(pAttribs, "PARAMETER")) this.iScope |= CIMScope.PARAMETER; + if (hasTrueAttribute(pAttribs, "INDICATION")) this.iScope |= CIMScope.INDICATION; + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + /** + * @param pNodeNameEnum + */ + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + throw new SAXException("SCOPE node cannot have any child node!"); + } + + /** + * @param pChild + */ + @Override + public void childParsed(Node pChild) { + // no child + } + + @Override + public void testCompletness() { + // Nothing to test, since it doesn't have any child node. + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleExpReqNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleExpReqNode.java similarity index 69% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleExpReqNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleExpReqNode.java index 6469e0d..97b47d2 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleExpReqNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleExpReqNode.java @@ -1,108 +1,103 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - * 2538 2013-11-28 blaschke-oss CR14: Support new CORRELATOR element - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT SIMPLEEXPREQ (CORRELATOR*, EXPMETHODCALL) - */ -public class SimpleExpReqNode extends AbstractMessageNode { - - private ExpMethodCallNode iMethodCallNode; - - /** - * Ctor. - */ - public SimpleExpReqNode() { - super(SIMPLEEXPREQ); - } - - public void addChild(Node pChild) { - if (pChild instanceof ExpMethodCallNode) { - this.iMethodCallNode = (ExpMethodCallNode) pChild; - } else if (pChild instanceof CorrelatorNode) { - // TODO: return to WBEMClient API if JSR48 changes - } - } - - /** - * @param pAttribs - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - this.iMethodCallNode = null; - // no attributes - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum == EXPMETHODCALL) { - if (this.iMethodCallNode != null) throw new SAXException(getNodeName() - + " node can have only one child node!"); - } else if (pNodeNameEnum != CORRELATOR) throw new SAXException(getNodeName() - + " node cannot have " + pNodeNameEnum + " child node!"); - } - - @Override - public void testCompletness() throws SAXException { - if (this.iMethodCallNode == null) throw new SAXException(getNodeName() - + " node must have a child node!"); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + * 2538 2013-11-28 blaschke-oss CR14: Support new CORRELATOR element + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT SIMPLEEXPREQ (CORRELATOR*, EXPMETHODCALL) + */ +public class SimpleExpReqNode extends AbstractMessageNode { + private ExpMethodCallNode iMethodCallNode; + + /** + * Ctor. + */ + public SimpleExpReqNode() { + super(SIMPLEEXPREQ); + } + + public void addChild(Node pChild) { + if (pChild instanceof ExpMethodCallNode) { + this.iMethodCallNode = (ExpMethodCallNode) pChild; + } else if (pChild instanceof CorrelatorNode) { + // TODO: return to WBEMClient API if JSR48 changes + } + } + + /** + * @param pAttribs + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + this.iMethodCallNode = null; + // no attributes + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum == EXPMETHODCALL) { + if (this.iMethodCallNode != null) throw new SAXException(getNodeName() + " node can have only one child node!"); + } else if (pNodeNameEnum != CORRELATOR) throw new SAXException( + getNodeName() + " node cannot have " + pNodeNameEnum + " child node!" + ); + } + + @Override + public void testCompletness() throws SAXException { + if (this.iMethodCallNode == null) throw new SAXException(getNodeName() + " node must have a child node!"); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleExpRspNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleExpRspNode.java similarity index 68% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleExpRspNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleExpRspNode.java index d097f89..c7a366d 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleExpRspNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleExpRspNode.java @@ -1,132 +1,127 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - * 3602604 2013-01-29 blaschke-oss Clean up SAXException messages - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMArgument; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.CIMError; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT SIMPLEEXPRSP (EXPMETHODRESPONSE)
      - * ELEMENT EXPMETHODRESPONSE (ERROR|IRETURNVALUE?)
      - * 
      - */ -public class SimpleExpRspNode extends AbstractSimpleRspNode { - - private ExpMethodResponseNode iExpMethodRspNode; - - /** - * Ctor. - */ - public SimpleExpRspNode() { - super(SIMPLEEXPRSP); - } - - public void addChild(Node pChild) { - this.iExpMethodRspNode = (ExpMethodResponseNode) pChild; - } - - /** - * @param pAttribs - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - this.iExpMethodRspNode = null; - // no attribs - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (this.iExpMethodRspNode != null) throw new SAXException(getNodeName() - + " node can have only one child node!"); - if (pNodeNameEnum != EXPMETHODRESPONSE) throw new SAXException(getNodeName() - + " node's child node can be EXPMETHODRESPONSE only! " + pNodeNameEnum - + " is invalid!"); - } - - @Override - public void testCompletness() throws SAXException { - if (this.iExpMethodRspNode == null) throw new SAXException(getNodeName() - + " node must have an EXPMETHODRESPONSE child node!"); - } - - @Override - public CIMError getCIMError() { - // can be null if it's value was read out before - if (this.iExpMethodRspNode == null) return null; - return this.iExpMethodRspNode.getCIMError(); - } - - @Override - public CIMArgument[] getCIMArguments() { - // no out arguments - return null; - } - - public int getReturnValueCount() { - return this.iExpMethodRspNode == null ? 0 : this.iExpMethodRspNode.getReturnValueCount(); - } - - public Object readReturnValue() { - return this.iExpMethodRspNode == null ? null : this.iExpMethodRspNode.readReturnValue(); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + * 3602604 2013-01-29 blaschke-oss Clean up SAXException messages + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMArgument; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.CIMError; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT SIMPLEEXPRSP (EXPMETHODRESPONSE)
      + * ELEMENT EXPMETHODRESPONSE (ERROR|IRETURNVALUE?)
      + * 
      + */ +public class SimpleExpRspNode extends AbstractSimpleRspNode { + private ExpMethodResponseNode iExpMethodRspNode; + + /** + * Ctor. + */ + public SimpleExpRspNode() { + super(SIMPLEEXPRSP); + } + + public void addChild(Node pChild) { + this.iExpMethodRspNode = (ExpMethodResponseNode) pChild; + } + + /** + * @param pAttribs + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + this.iExpMethodRspNode = null; + // no attribs + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (this.iExpMethodRspNode != null) throw new SAXException(getNodeName() + " node can have only one child node!"); + if (pNodeNameEnum != EXPMETHODRESPONSE) throw new SAXException( + getNodeName() + " node's child node can be EXPMETHODRESPONSE only! " + pNodeNameEnum + " is invalid!" + ); + } + + @Override + public void testCompletness() throws SAXException { + if (this.iExpMethodRspNode == null) throw new SAXException( + getNodeName() + " node must have an EXPMETHODRESPONSE child node!" + ); + } + + @Override + public CIMError getCIMError() { + // can be null if it's value was read out before + if (this.iExpMethodRspNode == null) return null; + return this.iExpMethodRspNode.getCIMError(); + } + + @Override + public CIMArgument[] getCIMArguments() { + // no out arguments + return null; + } + + public int getReturnValueCount() { + return this.iExpMethodRspNode == null ? 0 : this.iExpMethodRspNode.getReturnValueCount(); + } + + public Object readReturnValue() { + return this.iExpMethodRspNode == null ? null : this.iExpMethodRspNode.readReturnValue(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleReqNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleReqNode.java similarity index 69% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleReqNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleReqNode.java index 3003998..bc25437 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleReqNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleReqNode.java @@ -1,122 +1,117 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1686000 2007-04-20 ebak modifyInstance() missing from WBEMClient - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - * 2712 2013-11-14 blaschke-oss SimpleReqNode allows any CIM element as child - * 2538 2013-11-28 blaschke-oss CR14: Support new CORRELATOR element - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT SIMPLEREQ (CORRELATOR*, (METHODCALL | IMETHODCALL)) - */ -public class SimpleReqNode extends AbstractMessageNode { - - private AbstractMethodCallNode iMethodCallNode; - - /** - * Ctor. - */ - public SimpleReqNode() { - super(SIMPLEREQ); - } - - public void addChild(Node pChild) { - if (pChild instanceof AbstractMethodCallNode) { - this.iMethodCallNode = (AbstractMethodCallNode) pChild; - } else if (pChild instanceof CorrelatorNode) { - // TODO: return to WBEMClient API if JSR48 changes - } - } - - /** - * @param pAttribs - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - this.iMethodCallNode = null; - // no attributes - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - /** - * @param pNodeNameEnum - */ - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum == IMETHODCALL || pNodeNameEnum == METHODCALL) { - if (this.iMethodCallNode != null) throw new SAXException( - "SIMPLEREQ node can have only one child node!"); - } else if (pNodeNameEnum != CORRELATOR) throw new SAXException( - "SIMPLEREQ node cannot have " + pNodeNameEnum + " child node!"); - } - - @Override - public void testCompletness() throws SAXException { - if (this.iMethodCallNode == null) throw new SAXException( - "SIMPLEREQ node must have a child node!"); - } - - /** - * getAbstractMethodCallNode - * - * @return AbstractMethodCallNode - */ - public AbstractMethodCallNode getAbstractMethodCallNode() { - return this.iMethodCallNode; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1686000 2007-04-20 ebak modifyInstance() missing from WBEMClient + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + * 2712 2013-11-14 blaschke-oss SimpleReqNode allows any CIM element as child + * 2538 2013-11-28 blaschke-oss CR14: Support new CORRELATOR element + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT SIMPLEREQ (CORRELATOR*, (METHODCALL | IMETHODCALL)) + */ +public class SimpleReqNode extends AbstractMessageNode { + private AbstractMethodCallNode iMethodCallNode; + + /** + * Ctor. + */ + public SimpleReqNode() { + super(SIMPLEREQ); + } + + public void addChild(Node pChild) { + if (pChild instanceof AbstractMethodCallNode) { + this.iMethodCallNode = (AbstractMethodCallNode) pChild; + } else if (pChild instanceof CorrelatorNode) { + // TODO: return to WBEMClient API if JSR48 changes + } + } + + /** + * @param pAttribs + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + this.iMethodCallNode = null; + // no attributes + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + /** + * @param pNodeNameEnum + */ + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum == IMETHODCALL || pNodeNameEnum == METHODCALL) { + if (this.iMethodCallNode != null) throw new SAXException("SIMPLEREQ node can have only one child node!"); + } else if (pNodeNameEnum != CORRELATOR) throw new SAXException( + "SIMPLEREQ node cannot have " + pNodeNameEnum + " child node!" + ); + } + + @Override + public void testCompletness() throws SAXException { + if (this.iMethodCallNode == null) throw new SAXException("SIMPLEREQ node must have a child node!"); + } + + /** + * getAbstractMethodCallNode + * + * @return AbstractMethodCallNode + */ + public AbstractMethodCallNode getAbstractMethodCallNode() { + return this.iMethodCallNode; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleRspNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleRspNode.java similarity index 65% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleRspNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleRspNode.java index 9c6c913..2feccaf 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleRspNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/SimpleRspNode.java @@ -1,144 +1,142 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - * 2845211 2009-08-27 raman_arora Pull Enumeration Feature (SAX Parser) - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - * 2672 2013-09-26 blaschke-oss Remove SIMPLEREQACK support - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMArgument; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.CIMError; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT SIMPLERSP (METHODRESPONSE | IMETHODRESPONSE)
      - * 
      - * ELEMENT METHODRESPONSE (ERROR|(RETURNVALUE?,PARAMVALUE*))
      - * ELEMENT IMETHODRESPONSE (ERROR|IRETURNVALUE?) *
      - * 
      - */ -public class SimpleRspNode extends AbstractSimpleRspNode { - - private Node iChildNode; - - /** - * Ctor. - */ - public SimpleRspNode() { - super(SIMPLERSP); - } - - public void addChild(Node pChild) { - this.iChildNode = pChild; - } - - /** - * @param pAttribs - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - this.iChildNode = null; - // no attributes - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (this.iChildNode != null) throw new SAXException(getNodeName() - + " node can have only one child node!"); - if (pNodeNameEnum != METHODRESPONSE && pNodeNameEnum != IMETHODRESPONSE) throw new SAXException( - getNodeName() + " node cannot have " + pNodeNameEnum + " child node!"); - } - - @Override - public void testCompletness() throws SAXException { - if (this.iChildNode == null) throw new SAXException(getNodeName() - + " node must have a child node!"); - } - - @Override - public CIMError getCIMError() { - if (this.iChildNode instanceof ErrorIf) { return ((ErrorIf) this.iChildNode).getCIMError(); } - return null; - } - - /** - * getCIMArguments : returns the array of parsed parameters and their values - * : String name, CIMDataType type, Object value - * - * @return CIMArgument<?>[] - */ - @Override - public CIMArgument[] getCIMArguments() { - if (this.iChildNode instanceof MethodResponseNode) return ((MethodResponseNode) this.iChildNode) - .getCIMArguments(); - else if (this.iChildNode instanceof IMethodResponseNode) return ((IMethodResponseNode) this.iChildNode) - .getCIMArguments(); - return null; - } - - public int getReturnValueCount() { - if (this.iChildNode instanceof RetValPipeIf) { return ((RetValPipeIf) this.iChildNode) - .getReturnValueCount(); } - return 0; - } - - public Object readReturnValue() { - return ((RetValPipeIf) this.iChildNode).readReturnValue(); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2845211 2009-08-27 raman_arora Pull Enumeration Feature (SAX Parser) + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + * 2672 2013-09-26 blaschke-oss Remove SIMPLEREQACK support + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMArgument; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.CIMError; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT SIMPLERSP (METHODRESPONSE | IMETHODRESPONSE)
      + *
      + * ELEMENT METHODRESPONSE (ERROR|(RETURNVALUE?,PARAMVALUE*))
      + * ELEMENT IMETHODRESPONSE (ERROR|IRETURNVALUE?) *
      + * 
      + */ +public class SimpleRspNode extends AbstractSimpleRspNode { + private Node iChildNode; + + /** + * Ctor. + */ + public SimpleRspNode() { + super(SIMPLERSP); + } + + public void addChild(Node pChild) { + this.iChildNode = pChild; + } + + /** + * @param pAttribs + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + this.iChildNode = null; + // no attributes + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (this.iChildNode != null) throw new SAXException(getNodeName() + " node can have only one child node!"); + if (pNodeNameEnum != METHODRESPONSE && pNodeNameEnum != IMETHODRESPONSE) throw new SAXException( + getNodeName() + " node cannot have " + pNodeNameEnum + " child node!" + ); + } + + @Override + public void testCompletness() throws SAXException { + if (this.iChildNode == null) throw new SAXException(getNodeName() + " node must have a child node!"); + } + + @Override + public CIMError getCIMError() { + if (this.iChildNode instanceof ErrorIf) { + return ((ErrorIf) this.iChildNode).getCIMError(); + } + return null; + } + + /** + * getCIMArguments : returns the array of parsed parameters and their values + * : String name, CIMDataType type, Object value + * + * @return CIMArgument<?>[] + */ + @Override + public CIMArgument[] getCIMArguments() { + if (this.iChildNode instanceof MethodResponseNode) return ( + (MethodResponseNode) this.iChildNode + ).getCIMArguments(); else if (this.iChildNode instanceof IMethodResponseNode) return ( + (IMethodResponseNode) this.iChildNode + ).getCIMArguments(); + return null; + } + + public int getReturnValueCount() { + if (this.iChildNode instanceof RetValPipeIf) { + return ((RetValPipeIf) this.iChildNode).getReturnValueCount(); + } + return 0; + } + + public Object readReturnValue() { + return ((RetValPipeIf) this.iChildNode).readReturnValue(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/TypedIf.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/TypedIf.java similarity index 59% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/TypedIf.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/TypedIf.java index 62f19e8..a32d70e 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/TypedIf.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/TypedIf.java @@ -1,57 +1,54 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; - -/** - * TypedIf is implemented by those classes which can provide a CIMDataType. - */ -public interface TypedIf { - - /** - * getType - * - * @return null if the type is unknown - */ - public CIMDataType getType(); -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMDataType; + +/** + * TypedIf is implemented by those classes which can provide a CIMDataType. + */ +public interface TypedIf { + /** + * getType + * + * @return null if the type is unknown + */ + public CIMDataType getType(); +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueArrayNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueArrayNode.java similarity index 71% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueArrayNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueArrayNode.java index 21ad628..0dbd832 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueArrayNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueArrayNode.java @@ -1,157 +1,151 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1712656 2007-05-04 ebak Correct type identification for SVC CIMOM - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 1735693 2007-06-12 ebak Empty VALUE.ARRAY elements are parsed as nulls - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 3513353 2012-03-30 blaschke-oss TCK: CIMDataType arrays must have length >= 1 - * 2715 2013-11-26 blaschke-oss Add VALUE.NULL support - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; - -import org.sentrysoftware.wbem.sblim.cimclient.GenericExts; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.CIMHelper; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT VALUE.ARRAY (VALUE|VALUE.NULL)*
      - * For non-standard CIMOMs the TYPE and PARAMTYPE attributes are handled. - */ -public class ValueArrayNode extends AbstractArrayValueNode { - - // VALUE * - private ArrayList iValueAL; - - private CIMDataType iType; - - /** - * Ctor. - */ - public ValueArrayNode() { - super(VALUE_ARRAY); - } - - /** - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iValueAL = GenericExts.initClearArrayList(this.iValueAL); - /* - * For supporting non-standard CIMOMs TYPE and PARAMTYPE attributes are - * handled - */ - CIMDataType scalarType = getCIMType(pAttribs, true); - if (scalarType == null) scalarType = getParamType(pAttribs); - // make array type - this.iType = scalarType == null ? null : CIMHelper.UnboundedArrayDataType(scalarType - .getType()); - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum != VALUE && pNodeNameEnum != VALUE_NULL) throw new SAXException( - "Only VALUE and VALUE.NULL nodes can be added to VALUE.ARRAY nodes but " - + pNodeNameEnum + " found!"); - } - - @Override - public void childParsed(Node pChild) { - if (this.iValueAL == null) this.iValueAL = new ArrayList(); - if (pChild instanceof ValueNode) this.iValueAL.add(((ValueNode) pChild).getValue()); - else if (pChild instanceof ValueNullNode) this.iValueAL.add(null); - } - - @Override - public void testCompletness() { - // Nothing to test, since it is OK if it doesn't have child node. - } - - /** - * @see ArrayIf#elementAt(int) - * @return String value of VALUE child node - */ - public Object elementAt(int pIdx) { - return this.iValueAL.get(pIdx); - } - - public int size() { - return this.iValueAL == null ? 0 : this.iValueAL.size(); - } - - /** - * @see TypedIf#getType() - * @return usually null, because the type is unknown, but can return - * non-null in case of non-standard CIMOM. - */ - public CIMDataType getType() { - return this.iType; - } - - private static final String[] EMPTY_SA = new String[0]; - - /** - * @see ValueIf#getValue() If - * the getType() returns non-null value, the container Node have to - * convert the String into the corresponding Java object. - * @return String[] - */ - public Object getValue() { - return this.iValueAL == null ? EMPTY_SA : this.iValueAL.toArray(EMPTY_SA); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1712656 2007-05-04 ebak Correct type identification for SVC CIMOM + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 1735693 2007-06-12 ebak Empty VALUE.ARRAY elements are parsed as nulls + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 3513353 2012-03-30 blaschke-oss TCK: CIMDataType arrays must have length >= 1 + * 2715 2013-11-26 blaschke-oss Add VALUE.NULL support + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.sblim.cimclient.GenericExts; +import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMHelper; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT VALUE.ARRAY (VALUE|VALUE.NULL)*
      + * For non-standard CIMOMs the TYPE and PARAMTYPE attributes are handled. + */ +public class ValueArrayNode extends AbstractArrayValueNode { + // VALUE * + private ArrayList iValueAL; + + private CIMDataType iType; + + /** + * Ctor. + */ + public ValueArrayNode() { + super(VALUE_ARRAY); + } + + /** + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iValueAL = GenericExts.initClearArrayList(this.iValueAL); + /* + * For supporting non-standard CIMOMs TYPE and PARAMTYPE attributes are + * handled + */ + CIMDataType scalarType = getCIMType(pAttribs, true); + if (scalarType == null) scalarType = getParamType(pAttribs); + // make array type + this.iType = scalarType == null ? null : CIMHelper.UnboundedArrayDataType(scalarType.getType()); + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum != VALUE && pNodeNameEnum != VALUE_NULL) throw new SAXException( + "Only VALUE and VALUE.NULL nodes can be added to VALUE.ARRAY nodes but " + pNodeNameEnum + " found!" + ); + } + + @Override + public void childParsed(Node pChild) { + if (this.iValueAL == null) this.iValueAL = new ArrayList(); + if (pChild instanceof ValueNode) this.iValueAL.add(((ValueNode) pChild).getValue()); else if ( + pChild instanceof ValueNullNode + ) this.iValueAL.add(null); + } + + @Override + public void testCompletness() { + // Nothing to test, since it is OK if it doesn't have child node. + } + + /** + * @see ArrayIf#elementAt(int) + * @return String value of VALUE child node + */ + public Object elementAt(int pIdx) { + return this.iValueAL.get(pIdx); + } + + public int size() { + return this.iValueAL == null ? 0 : this.iValueAL.size(); + } + + /** + * @see TypedIf#getType() + * @return usually null, because the type is unknown, but can return + * non-null in case of non-standard CIMOM. + */ + public CIMDataType getType() { + return this.iType; + } + + private static final String[] EMPTY_SA = new String[0]; + + /** + * @see ValueIf#getValue() If + * the getType() returns non-null value, the container Node have to + * convert the String into the corresponding Java object. + * @return String[] + */ + public Object getValue() { + return this.iValueAL == null ? EMPTY_SA : this.iValueAL.toArray(EMPTY_SA); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueIf.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueIf.java similarity index 62% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueIf.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueIf.java index fae702d..2bc89e8 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueIf.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueIf.java @@ -1,58 +1,55 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * ValueIf should be implemented by Nodes which are able to return JSR48 value - * objects. (like: CIMDataTime, Integer, String, CIMClass, CIMInstance, - * UnsignetInteger8, ...) - * - */ -public interface ValueIf { - - /** - * getValue - * - * @return if type is unknown it returns a String - */ - public Object getValue(); -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * ValueIf should be implemented by Nodes which are able to return JSR48 value + * objects. (like: CIMDataTime, Integer, String, CIMClass, CIMInstance, + * UnsignetInteger8, ...) + * + */ +public interface ValueIf { + /** + * getValue + * + * @return if type is unknown it returns a String + */ + public Object getValue(); +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueInstanceWithPathNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueInstanceWithPathNode.java similarity index 62% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueInstanceWithPathNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueInstanceWithPathNode.java index e00cbf2..5339d5f 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueInstanceWithPathNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueInstanceWithPathNode.java @@ -1,149 +1,150 @@ -/* - (C) Copyright IBM Corp. 2009, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Ramandeep S Arora, IBM, arorar@us.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 2845211 2009-08-27 raman_arora Pull Enumeration Feature (SAX Parser) - * 3598613 2013-01-11 blaschke-oss different data type in cim instance and cim object path - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMInstance; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.CIMHelper; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConfiguration; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT VALUE.INSTANCEWITHPATH (INSTANCEPATH, INSTANCE)
      - * 
      - * ELEMENT INSTANCEPATH (NAMESPACEPATH,INSTANCENAME)
      - *    
      - * ELEMENT INSTANCE (QUALIFIER*, (PROPERTY | PROPERTY.ARRAY | PROPERTY.REFERENCE)*)
      - * ATTLIST INSTANCE
      - *   %ClassName;
      - *   xml:lang   NMTOKEN      #IMPLIED
      - * 
      - */ -public class ValueInstanceWithPathNode extends AbstractScalarValueNode { - - // INSTANCEPATH - private CIMObjectPath iCIMInstPath; - - // INSTANCE - private CIMInstance iCIMInstance; - - /** - * Ctor. - */ - public ValueInstanceWithPathNode() { - super(VALUE_INSTANCEWITHPATH); - } - - /** - * @param pAttribs - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - // no attribute - this.iCIMInstPath = null; - this.iCIMInstance = null; - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum == INSTANCEPATH) { - if (this.iCIMInstPath != null) throw new SAXException( - "VALUE.INSTANCEWITHPATH node can have only one INSTANCEPATH node, but another one was found!"); - } else if (pNodeNameEnum == INSTANCE) { - if (this.iCIMInstance != null) throw new SAXException( - "VALUE.INSTANCEWITHPATH node can have only one INSTANCE node, but another one was found!"); - } else { - throw new SAXException("VALUE.INSTANCEWITHPATH node cannot have " + pNodeNameEnum - + " child node!"); - } - } - - @Override - public void childParsed(Node pChild) { - if (pChild instanceof InstancePathNode) { - this.iCIMInstPath = ((InstancePathNode) pChild).getCIMObjectPath(); - } else { - this.iCIMInstance = ((InstanceNode) pChild).getCIMInstance(); - } - } - - @Override - public void testCompletness() throws SAXException { - if (this.iCIMInstPath == null) throw new SAXException( - "VALUE.INSTANCEWITHPATH node must have an INSTANCEPATH child node!"); - if (this.iCIMInstance == null) throw new SAXException( - "VALUE.INSTANCEWITHPATH node must have an INSTANCE child node!"); - } - - /** - * @see ValueIf#getValue() - * @return CIMInstance - */ - public Object getValue() { - /* - * INSTANCENAME contains the key properties only, INSTANCE contains - * non-key properties too. - */ - if (WBEMConfiguration.getGlobalConfiguration().synchronizeNumericKeyDataTypes()) return CIMHelper - .CIMInstanceWithSynchonizedNumericKeyDataTypes(this.iCIMInstPath, this.iCIMInstance - .getProperties()); - return new CIMInstance(this.iCIMInstPath, this.iCIMInstance.getProperties()); - } - - public CIMDataType getType() { - return CIMDataType.OBJECT_T; - } - -} +/* + (C) Copyright IBM Corp. 2009, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Ramandeep S Arora, IBM, arorar@us.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 2845211 2009-08-27 raman_arora Pull Enumeration Feature (SAX Parser) + * 3598613 2013-01-11 blaschke-oss different data type in cim instance and cim object path + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMInstance; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMHelper; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfiguration; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT VALUE.INSTANCEWITHPATH (INSTANCEPATH, INSTANCE)
      + *
      + * ELEMENT INSTANCEPATH (NAMESPACEPATH,INSTANCENAME)
      + *
      + * ELEMENT INSTANCE (QUALIFIER*, (PROPERTY | PROPERTY.ARRAY | PROPERTY.REFERENCE)*)
      + * ATTLIST INSTANCE
      + *   %ClassName;
      + *   xml:lang   NMTOKEN      #IMPLIED
      + * 
      + */ +public class ValueInstanceWithPathNode extends AbstractScalarValueNode { + // INSTANCEPATH + private CIMObjectPath iCIMInstPath; + + // INSTANCE + private CIMInstance iCIMInstance; + + /** + * Ctor. + */ + public ValueInstanceWithPathNode() { + super(VALUE_INSTANCEWITHPATH); + } + + /** + * @param pAttribs + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + // no attribute + this.iCIMInstPath = null; + this.iCIMInstance = null; + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum == INSTANCEPATH) { + if (this.iCIMInstPath != null) throw new SAXException( + "VALUE.INSTANCEWITHPATH node can have only one INSTANCEPATH node, but another one was found!" + ); + } else if (pNodeNameEnum == INSTANCE) { + if (this.iCIMInstance != null) throw new SAXException( + "VALUE.INSTANCEWITHPATH node can have only one INSTANCE node, but another one was found!" + ); + } else { + throw new SAXException("VALUE.INSTANCEWITHPATH node cannot have " + pNodeNameEnum + " child node!"); + } + } + + @Override + public void childParsed(Node pChild) { + if (pChild instanceof InstancePathNode) { + this.iCIMInstPath = ((InstancePathNode) pChild).getCIMObjectPath(); + } else { + this.iCIMInstance = ((InstanceNode) pChild).getCIMInstance(); + } + } + + @Override + public void testCompletness() throws SAXException { + if (this.iCIMInstPath == null) throw new SAXException( + "VALUE.INSTANCEWITHPATH node must have an INSTANCEPATH child node!" + ); + if (this.iCIMInstance == null) throw new SAXException( + "VALUE.INSTANCEWITHPATH node must have an INSTANCE child node!" + ); + } + + /** + * @see ValueIf#getValue() + * @return CIMInstance + */ + public Object getValue() { + /* + * INSTANCENAME contains the key properties only, INSTANCE contains + * non-key properties too. + */ + if ( + WBEMConfiguration.getGlobalConfiguration().synchronizeNumericKeyDataTypes() + ) return CIMHelper.CIMInstanceWithSynchonizedNumericKeyDataTypes( + this.iCIMInstPath, + this.iCIMInstance.getProperties() + ); + return new CIMInstance(this.iCIMInstPath, this.iCIMInstance.getProperties()); + } + + public CIMDataType getType() { + return CIMDataType.OBJECT_T; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueNamedInstanceNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueNamedInstanceNode.java similarity index 64% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueNamedInstanceNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueNamedInstanceNode.java index 790fe3b..1026448 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueNamedInstanceNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueNamedInstanceNode.java @@ -1,161 +1,160 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 3598613 2013-01-11 blaschke-oss different data type in cim instance and cim object path - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMInstance; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cim.CIMHelper; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConfiguration; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - *
      - * ELEMENT VALUE.NAMEDINSTANCE (INSTANCENAME, INSTANCE)
      - * 
      - * ELEMENT INSTANCENAME (KEYBINDING* | KEYVALUE? | VALUE.REFERENCE?)
      - * ATTLIST INSTANCENAME
      - *   %ClassName;
      - *   
      - * ELEMENT INSTANCE (QUALIFIER*, (PROPERTY | PROPERTY.ARRAY | PROPERTY.REFERENCE)*)
      - * ATTLIST INSTANCE
      - *   %ClassName;
      - *   xml:lang   NMTOKEN      #IMPLIED 
      - * FIXME: Why INSTANCE has qualifiers? CIMInstance doesn't have!
      - * FIXME: InstanceName and instance provides redundant information. Why?
      - * 
      - */ -public class ValueNamedInstanceNode extends AbstractScalarValueNode { - - // INSTANCENAME - private CIMObjectPath iCIMInstPath; - - // INSTANCE - private CIMInstance iCIMInstance; - - /** - * Ctor. - */ - public ValueNamedInstanceNode() { - super(VALUE_NAMEDINSTANCE); - } - - /** - * @param pAttribs - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - this.iCIMInstPath = null; - this.iCIMInstance = null; - // no attribute - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum == INSTANCENAME) { - if (this.iCIMInstPath != null) throw new SAXException( - "VALUE.NAMEDINSTANCE node can have only one INSTANCENAME node, but another one was found!"); - } else if (pNodeNameEnum == INSTANCE) { - if (this.iCIMInstance != null) throw new SAXException( - "VALUE.NAMEDINSTANCE node can have only one INSTANCE node, but another one was found!"); - } else { - throw new SAXException("VALUE.NAMEDINSTANCE node cannot have " + pNodeNameEnum - + " child node!"); - } - } - - @Override - public void childParsed(Node pChild) { - if (pChild instanceof InstanceNameNode) { - this.iCIMInstPath = ((InstanceNameNode) pChild).getCIMObjectPath(); - } else { - this.iCIMInstance = ((InstanceNode) pChild).getCIMInstance(); - } - } - - @Override - public void testCompletness() throws SAXException { - if (this.iCIMInstPath == null) throw new SAXException( - "VALUE.NAMEDINSTANCE node must have an INSTANCENAME child node!"); - if (this.iCIMInstance == null) throw new SAXException( - "VALUE.NAMEDINSTANCE node must have an INSTANCE child node!"); - } - - /** - * @see ValueIf#getValue() - * @return CIMInstance - */ - public Object getValue() { - // CIMObjectPath op=iInstanceNameNode.getCIMObjectPath(); - /* - * INSTANCENAME contains the key properties only, INSTANCE contains the - * non-key properties too. - */ - if (WBEMConfiguration.getGlobalConfiguration().synchronizeNumericKeyDataTypes()) return CIMHelper - .CIMInstanceWithSynchonizedNumericKeyDataTypes(this.iCIMInstPath, this.iCIMInstance - .getProperties()); - return new CIMInstance(this.iCIMInstPath, this.iCIMInstance.getProperties()); - } - - public CIMDataType getType() { - return CIMDataType.OBJECT_T; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 3598613 2013-01-11 blaschke-oss different data type in cim instance and cim object path + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMInstance; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMHelper; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfiguration; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + *
      + * ELEMENT VALUE.NAMEDINSTANCE (INSTANCENAME, INSTANCE)
      + *
      + * ELEMENT INSTANCENAME (KEYBINDING* | KEYVALUE? | VALUE.REFERENCE?)
      + * ATTLIST INSTANCENAME
      + *   %ClassName;
      + *
      + * ELEMENT INSTANCE (QUALIFIER*, (PROPERTY | PROPERTY.ARRAY | PROPERTY.REFERENCE)*)
      + * ATTLIST INSTANCE
      + *   %ClassName;
      + *   xml:lang   NMTOKEN      #IMPLIED
      + * FIXME: Why INSTANCE has qualifiers? CIMInstance doesn't have!
      + * FIXME: InstanceName and instance provides redundant information. Why?
      + * 
      + */ +public class ValueNamedInstanceNode extends AbstractScalarValueNode { + // INSTANCENAME + private CIMObjectPath iCIMInstPath; + + // INSTANCE + private CIMInstance iCIMInstance; + + /** + * Ctor. + */ + public ValueNamedInstanceNode() { + super(VALUE_NAMEDINSTANCE); + } + + /** + * @param pAttribs + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + this.iCIMInstPath = null; + this.iCIMInstance = null; + // no attribute + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum == INSTANCENAME) { + if (this.iCIMInstPath != null) throw new SAXException( + "VALUE.NAMEDINSTANCE node can have only one INSTANCENAME node, but another one was found!" + ); + } else if (pNodeNameEnum == INSTANCE) { + if (this.iCIMInstance != null) throw new SAXException( + "VALUE.NAMEDINSTANCE node can have only one INSTANCE node, but another one was found!" + ); + } else { + throw new SAXException("VALUE.NAMEDINSTANCE node cannot have " + pNodeNameEnum + " child node!"); + } + } + + @Override + public void childParsed(Node pChild) { + if (pChild instanceof InstanceNameNode) { + this.iCIMInstPath = ((InstanceNameNode) pChild).getCIMObjectPath(); + } else { + this.iCIMInstance = ((InstanceNode) pChild).getCIMInstance(); + } + } + + @Override + public void testCompletness() throws SAXException { + if (this.iCIMInstPath == null) throw new SAXException( + "VALUE.NAMEDINSTANCE node must have an INSTANCENAME child node!" + ); + if (this.iCIMInstance == null) throw new SAXException("VALUE.NAMEDINSTANCE node must have an INSTANCE child node!"); + } + + /** + * @see ValueIf#getValue() + * @return CIMInstance + */ + public Object getValue() { + // CIMObjectPath op=iInstanceNameNode.getCIMObjectPath(); + /* + * INSTANCENAME contains the key properties only, INSTANCE contains the + * non-key properties too. + */ + if ( + WBEMConfiguration.getGlobalConfiguration().synchronizeNumericKeyDataTypes() + ) return CIMHelper.CIMInstanceWithSynchonizedNumericKeyDataTypes( + this.iCIMInstPath, + this.iCIMInstance.getProperties() + ); + return new CIMInstance(this.iCIMInstPath, this.iCIMInstance.getProperties()); + } + + public CIMDataType getType() { + return CIMDataType.OBJECT_T; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueNode.java similarity index 75% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueNode.java index 9c08fbe..3f3be50 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueNode.java @@ -1,134 +1,129 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1712656 2007-05-04 ebak Correct type identification for SVC CIMOM - * 1714878 2007-05-08 ebak Empty string property values are parsed as nulls - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT VALUE (#PCDATA)
      - * For non-standard CIMOMs the TYPE and PARAMTYPE attributes are supported. - */ -public class ValueNode extends AbstractScalarValueNode { - - private CIMDataType iType; - - private String iData; - - /** - * Ctor. - */ - public ValueNode() { - super(VALUE); - } - - /** - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { - this.iData = null; - /* - * For supporting non-standard CIMOMs TYPE and PARAMTYPE attributes are - * handled - */ - this.iType = getCIMType(pAttribs, true); - if (this.iType == null) this.iType = getParamType(pAttribs); - } - - @Override - public void parseData(String pData) { - this.iData = pData; - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - throw new SAXException("VALUE node cannot have any child node! (" + pNodeNameEnum + ")"); - } - - /** - * @param pChild - */ - @Override - public void childParsed(Node pChild) { - // no child - } - - @Override - public void testCompletness() { - // no child nodes - } - - /** - * @see ValueIf#getValue() If - * the getType() returns non-null value, the container Node have to - * convert the String into the corresponding Java object. - * @return String - */ - public Object getValue() { - /* - * If iData is null we return empty String. If null values have to be - * represented by avoiding the VALUE element, or placing VALUE.NULLs - * into VALUE.ARRAYs. - */ - return this.iData == null ? "" : this.iData; - } - - /** - * @see TypedIf#getType() - * @return usually null, because the type is unknown, but can return - * non-null in case of non-standard CIMOM. - */ - public CIMDataType getType() { - return this.iType; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1712656 2007-05-04 ebak Correct type identification for SVC CIMOM + * 1714878 2007-05-08 ebak Empty string property values are parsed as nulls + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT VALUE (#PCDATA)
      + * For non-standard CIMOMs the TYPE and PARAMTYPE attributes are supported. + */ +public class ValueNode extends AbstractScalarValueNode { + private CIMDataType iType; + + private String iData; + + /** + * Ctor. + */ + public ValueNode() { + super(VALUE); + } + + /** + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) throws SAXException { + this.iData = null; + /* + * For supporting non-standard CIMOMs TYPE and PARAMTYPE attributes are + * handled + */ + this.iType = getCIMType(pAttribs, true); + if (this.iType == null) this.iType = getParamType(pAttribs); + } + + @Override + public void parseData(String pData) { + this.iData = pData; + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + throw new SAXException("VALUE node cannot have any child node! (" + pNodeNameEnum + ")"); + } + + /** + * @param pChild + */ + @Override + public void childParsed(Node pChild) { + // no child + } + + @Override + public void testCompletness() { + // no child nodes + } + + /** + * @see ValueIf#getValue() If + * the getType() returns non-null value, the container Node have to + * convert the String into the corresponding Java object. + * @return String + */ + public Object getValue() { + /* + * If iData is null we return empty String. If null values have to be + * represented by avoiding the VALUE element, or placing VALUE.NULLs + * into VALUE.ARRAYs. + */ + return this.iData == null ? "" : this.iData; + } + + /** + * @see TypedIf#getType() + * @return usually null, because the type is unknown, but can return + * non-null in case of non-standard CIMOM. + */ + public CIMDataType getType() { + return this.iType; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueNullNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueNullNode.java similarity index 67% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueNullNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueNullNode.java index 6f2d735..3e1217b 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueNullNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueNullNode.java @@ -1,116 +1,112 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT VALUE.NULL EMPTY - */ -public class ValueNullNode extends AbstractScalarValueNode { - - /** - * Ctor. - */ - public ValueNullNode() { - super(VALUE_NULL); - } - - /** - * @param pAttribs - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - // no attributes - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - /** - * @param pNodeNameEnum - */ - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - throw new SAXException("VALUE.NULL node cannot have any child node!"); - } - - /** - * @param pChild - */ - @Override - public void childParsed(Node pChild) { - // no child - } - - @Override - public void testCompletness() { - // nothing to test - } - - /** - * @see ValueIf#getValue() - * @return null - */ - public Object getValue() { - return null; - } - - public CIMDataType getType() { - // type is unknown - return null; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT VALUE.NULL EMPTY + */ +public class ValueNullNode extends AbstractScalarValueNode { + + /** + * Ctor. + */ + public ValueNullNode() { + super(VALUE_NULL); + } + + /** + * @param pAttribs + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + // no attributes + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + /** + * @param pNodeNameEnum + */ + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + throw new SAXException("VALUE.NULL node cannot have any child node!"); + } + + /** + * @param pChild + */ + @Override + public void childParsed(Node pChild) { + // no child + } + + @Override + public void testCompletness() { + // nothing to test + } + + /** + * @see ValueIf#getValue() + * @return null + */ + public Object getValue() { + return null; + } + + public CIMDataType getType() { + // type is unknown + return null; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueObjectNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueObjectNode.java similarity index 62% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueObjectNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueObjectNode.java index 803de02..28412ec 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueObjectNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueObjectNode.java @@ -1,127 +1,121 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1679534 2007-03-13 ebak wrong ValueObjectNode.testChild() - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 3602604 2013-01-29 blaschke-oss Clean up SAXException messages - * 2604 2013-07-01 blaschke-oss SAXException messages should contain node name - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMClass; -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMNamedElementInterface; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT VALUE.OBJECT (CLASS | INSTANCE) - */ -public class ValueObjectNode extends AbstractScalarValueNode { - - private CIMNamedElementInterface iCIMObject; - - /** - * Ctor. - */ - public ValueObjectNode() { - super(VALUE_OBJECT); - } - - /** - * @param pAttribs - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - this.iCIMObject = null; - // no attributes - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (this.iCIMObject != null) throw new SAXException("This " + getNodeName() - + " node can have only one child but an additional " + pNodeNameEnum - + " node found!"); - if (pNodeNameEnum != CLASS && pNodeNameEnum != INSTANCE) throw new SAXException( - getNodeName() + " node child node can be CLASS or INSTANCE but a " + pNodeNameEnum - + " node was found!"); - } - - @Override - public void childParsed(Node pChild) { - AbstractObjectNode objNode = (AbstractObjectNode) pChild; - if (objNode instanceof ClassNode) this.iCIMObject = ((ClassNode) objNode).getCIMClass(); - else this.iCIMObject = ((InstanceNode) objNode).getCIMInstance(); - } - - @Override - public void testCompletness() throws SAXException { - if (this.iCIMObject == null) throw new SAXException( - "VALUE.OBJECT node must have a CLASS or INSTANCE child node!"); - } - - /** - * @seeValueIf#getValue() - * @return CIMClass or CIMInstance - */ - public Object getValue() { - return this.iCIMObject; - } - - public CIMDataType getType() { - if (this.iCIMObject instanceof CIMClass) return CIMDataType.CLASS_T; - return CIMDataType.OBJECT_T; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1679534 2007-03-13 ebak wrong ValueObjectNode.testChild() + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 3602604 2013-01-29 blaschke-oss Clean up SAXException messages + * 2604 2013-07-01 blaschke-oss SAXException messages should contain node name + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMClass; +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMNamedElementInterface; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT VALUE.OBJECT (CLASS | INSTANCE) + */ +public class ValueObjectNode extends AbstractScalarValueNode { + private CIMNamedElementInterface iCIMObject; + + /** + * Ctor. + */ + public ValueObjectNode() { + super(VALUE_OBJECT); + } + + /** + * @param pAttribs + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + this.iCIMObject = null; + // no attributes + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (this.iCIMObject != null) throw new SAXException( + "This " + getNodeName() + " node can have only one child but an additional " + pNodeNameEnum + " node found!" + ); + if (pNodeNameEnum != CLASS && pNodeNameEnum != INSTANCE) throw new SAXException( + getNodeName() + " node child node can be CLASS or INSTANCE but a " + pNodeNameEnum + " node was found!" + ); + } + + @Override + public void childParsed(Node pChild) { + AbstractObjectNode objNode = (AbstractObjectNode) pChild; + if (objNode instanceof ClassNode) this.iCIMObject = ((ClassNode) objNode).getCIMClass(); else this.iCIMObject = + ((InstanceNode) objNode).getCIMInstance(); + } + + @Override + public void testCompletness() throws SAXException { + if (this.iCIMObject == null) throw new SAXException("VALUE.OBJECT node must have a CLASS or INSTANCE child node!"); + } + + /** + * @seeValueIf#getValue() + * @return CIMClass or CIMInstance + */ + public Object getValue() { + return this.iCIMObject; + } + + public CIMDataType getType() { + if (this.iCIMObject instanceof CIMClass) return CIMDataType.CLASS_T; + return CIMDataType.OBJECT_T; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueObjectWithLocalPathNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueObjectWithLocalPathNode.java similarity index 68% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueObjectWithLocalPathNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueObjectWithLocalPathNode.java index 8fafce5..ec9fc4c 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueObjectWithLocalPathNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueObjectWithLocalPathNode.java @@ -1,162 +1,155 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMClass; -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMNamedElementInterface; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT VALUE.OBJECTWITHLOCALPATH ((LOCALCLASSPATH, CLASS) | - * (LOCALINSTANCEPATH, INSTANCE)) - */ -public class ValueObjectWithLocalPathNode extends AbstractScalarValueNode { - - // ObjectPath element - private String iPathNodeNameEnum; - - private CIMObjectPath iObjPath; - - // Object element - private String iObjNodeNameEnum; - - private CIMNamedElementInterface iCIMObj; - - /** - * Ctor. - */ - public ValueObjectWithLocalPathNode() { - super(VALUE_OBJECTWITHLOCALPATH); - } - - /** - * @param pAttribs - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - this.iPathNodeNameEnum = this.iObjNodeNameEnum = null; - this.iObjPath = null; - this.iCIMObj = null; - // no attributes - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum == LOCALCLASSPATH) { - if (this.iPathNodeNameEnum != null) duplicatedNode(this.iPathNodeNameEnum, - LOCALCLASSPATH); - if (this.iObjNodeNameEnum == INSTANCE) illegalChildNodePair(LOCALCLASSPATH, INSTANCE); - } else if (pNodeNameEnum == CLASS) { - if (this.iObjNodeNameEnum != null) duplicatedNode(this.iObjNodeNameEnum, CLASS); - if (this.iPathNodeNameEnum == LOCALINSTANCEPATH) illegalChildNodePair( - LOCALINSTANCEPATH, CLASS); - } else if (pNodeNameEnum == LOCALINSTANCEPATH) { - if (this.iPathNodeNameEnum != null) duplicatedNode(this.iPathNodeNameEnum, - LOCALINSTANCEPATH); - if (this.iObjNodeNameEnum == CLASS) illegalChildNodePair(LOCALINSTANCEPATH, CLASS); - } else if (pNodeNameEnum == INSTANCE) { - if (this.iObjNodeNameEnum != null) duplicatedNode(this.iObjNodeNameEnum, INSTANCE); - if (this.iPathNodeNameEnum == LOCALCLASSPATH) illegalChildNodePair(LOCALCLASSPATH, - INSTANCE); - } else throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum - + " child!"); - } - - @Override - public void childParsed(Node pChild) throws SAXException { - if (pChild instanceof AbstractObjectPathNode) { - this.iPathNodeNameEnum = pChild.getNodeName(); - this.iObjPath = ((AbstractObjectPathNode) pChild).getCIMObjectPath(); - } else { // ClassNode or InstanceNode, iObjPath must be available - // here - this.iObjNodeNameEnum = pChild.getNodeName(); - if (this.iPathNodeNameEnum == null) throw new SAXException(getNodeName() - + " first child should contain an object path!"); - if (pChild instanceof ClassNode) { - this.iCIMObj = ((ClassNode) pChild).getCIMClass(this.iObjPath); - } else { - this.iCIMObj = ((InstanceNode) pChild).getCIMInstance(this.iObjPath); - } - } - } - - @Override - public void testCompletness() throws SAXException { - if (this.iPathNodeNameEnum == null) throw new SAXException(getNodeName() - + " node must have a LOCALCLASSPATH or a LOCALINSTANCEPATH child node!"); - if (this.iObjNodeNameEnum == null) throw new SAXException(getNodeName() - + " node must have a CLASS or INSTANCE child node!"); - } - - /** - * @see ValueIf#getValue() - * @return CIMClass or CIMInstance - */ - public Object getValue() { - return this.iCIMObj; - } - - public CIMDataType getType() { - if (this.iCIMObj instanceof CIMClass) return CIMDataType.CLASS_T; - return CIMDataType.OBJECT_T; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMClass; +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMNamedElementInterface; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT VALUE.OBJECTWITHLOCALPATH ((LOCALCLASSPATH, CLASS) | + * (LOCALINSTANCEPATH, INSTANCE)) + */ +public class ValueObjectWithLocalPathNode extends AbstractScalarValueNode { + // ObjectPath element + private String iPathNodeNameEnum; + + private CIMObjectPath iObjPath; + + // Object element + private String iObjNodeNameEnum; + + private CIMNamedElementInterface iCIMObj; + + /** + * Ctor. + */ + public ValueObjectWithLocalPathNode() { + super(VALUE_OBJECTWITHLOCALPATH); + } + + /** + * @param pAttribs + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + this.iPathNodeNameEnum = this.iObjNodeNameEnum = null; + this.iObjPath = null; + this.iCIMObj = null; + // no attributes + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum == LOCALCLASSPATH) { + if (this.iPathNodeNameEnum != null) duplicatedNode(this.iPathNodeNameEnum, LOCALCLASSPATH); + if (this.iObjNodeNameEnum == INSTANCE) illegalChildNodePair(LOCALCLASSPATH, INSTANCE); + } else if (pNodeNameEnum == CLASS) { + if (this.iObjNodeNameEnum != null) duplicatedNode(this.iObjNodeNameEnum, CLASS); + if (this.iPathNodeNameEnum == LOCALINSTANCEPATH) illegalChildNodePair(LOCALINSTANCEPATH, CLASS); + } else if (pNodeNameEnum == LOCALINSTANCEPATH) { + if (this.iPathNodeNameEnum != null) duplicatedNode(this.iPathNodeNameEnum, LOCALINSTANCEPATH); + if (this.iObjNodeNameEnum == CLASS) illegalChildNodePair(LOCALINSTANCEPATH, CLASS); + } else if (pNodeNameEnum == INSTANCE) { + if (this.iObjNodeNameEnum != null) duplicatedNode(this.iObjNodeNameEnum, INSTANCE); + if (this.iPathNodeNameEnum == LOCALCLASSPATH) illegalChildNodePair(LOCALCLASSPATH, INSTANCE); + } else throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child!"); + } + + @Override + public void childParsed(Node pChild) throws SAXException { + if (pChild instanceof AbstractObjectPathNode) { + this.iPathNodeNameEnum = pChild.getNodeName(); + this.iObjPath = ((AbstractObjectPathNode) pChild).getCIMObjectPath(); + } else { // ClassNode or InstanceNode, iObjPath must be available + // here + this.iObjNodeNameEnum = pChild.getNodeName(); + if (this.iPathNodeNameEnum == null) throw new SAXException( + getNodeName() + " first child should contain an object path!" + ); + if (pChild instanceof ClassNode) { + this.iCIMObj = ((ClassNode) pChild).getCIMClass(this.iObjPath); + } else { + this.iCIMObj = ((InstanceNode) pChild).getCIMInstance(this.iObjPath); + } + } + } + + @Override + public void testCompletness() throws SAXException { + if (this.iPathNodeNameEnum == null) throw new SAXException( + getNodeName() + " node must have a LOCALCLASSPATH or a LOCALINSTANCEPATH child node!" + ); + if (this.iObjNodeNameEnum == null) throw new SAXException( + getNodeName() + " node must have a CLASS or INSTANCE child node!" + ); + } + + /** + * @see ValueIf#getValue() + * @return CIMClass or CIMInstance + */ + public Object getValue() { + return this.iCIMObj; + } + + public CIMDataType getType() { + if (this.iCIMObj instanceof CIMClass) return CIMDataType.CLASS_T; + return CIMDataType.OBJECT_T; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueObjectWithPathNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueObjectWithPathNode.java similarity index 71% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueObjectWithPathNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueObjectWithPathNode.java index 22dab7b..48fdfe6 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueObjectWithPathNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueObjectWithPathNode.java @@ -1,158 +1,154 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMClass; -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMNamedElementInterface; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT VALUE.OBJECTWITHPATH ((CLASSPATH, CLASS) | (INSTANCEPATH, INSTANCE)) - */ -public class ValueObjectWithPathNode extends AbstractScalarValueNode { - - // ObjectPath element - private String iPathNodeNameEnum; - - private CIMObjectPath iObjPath; - - // CIMObject element - private String iObjNodeNameEnum; - - private CIMNamedElementInterface iCIMObj; - - /** - * Ctor. - */ - public ValueObjectWithPathNode() { - super(VALUE_OBJECTWITHPATH); - } - - /** - * @param pAttribs - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - this.iPathNodeNameEnum = this.iObjNodeNameEnum = null; - this.iObjPath = null; - this.iCIMObj = null; - // no attributes - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum == CLASSPATH) { - if (this.iPathNodeNameEnum != null) duplicatedNode(this.iPathNodeNameEnum, CLASSPATH); - if (this.iObjNodeNameEnum == INSTANCE) illegalChildNodePair(CLASSPATH, INSTANCE); - } else if (pNodeNameEnum == CLASS) { - if (this.iObjNodeNameEnum != null) duplicatedNode(this.iObjNodeNameEnum, CLASS); - if (this.iPathNodeNameEnum == INSTANCEPATH) illegalChildNodePair(INSTANCEPATH, CLASS); - } else if (pNodeNameEnum == INSTANCEPATH) { - if (this.iPathNodeNameEnum != null) duplicatedNode(this.iPathNodeNameEnum, INSTANCEPATH); - if (this.iObjNodeNameEnum == CLASS) illegalChildNodePair(INSTANCEPATH, CLASS); - } else if (pNodeNameEnum == INSTANCE) { - if (this.iObjNodeNameEnum != null) duplicatedNode(this.iObjNodeNameEnum, INSTANCE); - if (this.iPathNodeNameEnum == CLASSPATH) illegalChildNodePair(CLASSPATH, INSTANCE); - } else throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum - + " child!"); - - } - - @Override - public void childParsed(Node pChild) throws SAXException { - if (pChild instanceof AbstractObjectPathNode) { - this.iPathNodeNameEnum = pChild.getNodeName(); - this.iObjPath = ((AbstractObjectPathNode) pChild).getCIMObjectPath(); - } else { // ClassNode or InstanceNode, iObjPath must be available - // here - this.iObjNodeNameEnum = pChild.getNodeName(); - if (this.iPathNodeNameEnum == null) throw new SAXException(getNodeName() - + " first child should contain an object path!"); - if (pChild instanceof ClassNode) { - this.iCIMObj = ((ClassNode) pChild).getCIMClass(this.iObjPath); - } else { - this.iCIMObj = ((InstanceNode) pChild).getCIMInstance(this.iObjPath); - } - } - } - - @Override - public void testCompletness() throws SAXException { - if (this.iPathNodeNameEnum == null) throw new SAXException(getNodeName() - + " node must have a CLASSPATH or a INSTANCEPATH child node!"); - if (this.iObjNodeNameEnum == null) throw new SAXException(getNodeName() - + " node must have a CLASS or INSTANCE child node!"); - } - - /** - * @see ValueIf#getValue() - * @return CIMClass or CIMInstance - */ - public Object getValue() { - return this.iCIMObj; - } - - public CIMDataType getType() { - if (this.iCIMObj instanceof CIMClass) return CIMDataType.CLASS_T; - return CIMDataType.OBJECT_T; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMClass; +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMNamedElementInterface; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT VALUE.OBJECTWITHPATH ((CLASSPATH, CLASS) | (INSTANCEPATH, INSTANCE)) + */ +public class ValueObjectWithPathNode extends AbstractScalarValueNode { + // ObjectPath element + private String iPathNodeNameEnum; + + private CIMObjectPath iObjPath; + + // CIMObject element + private String iObjNodeNameEnum; + + private CIMNamedElementInterface iCIMObj; + + /** + * Ctor. + */ + public ValueObjectWithPathNode() { + super(VALUE_OBJECTWITHPATH); + } + + /** + * @param pAttribs + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + this.iPathNodeNameEnum = this.iObjNodeNameEnum = null; + this.iObjPath = null; + this.iCIMObj = null; + // no attributes + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum == CLASSPATH) { + if (this.iPathNodeNameEnum != null) duplicatedNode(this.iPathNodeNameEnum, CLASSPATH); + if (this.iObjNodeNameEnum == INSTANCE) illegalChildNodePair(CLASSPATH, INSTANCE); + } else if (pNodeNameEnum == CLASS) { + if (this.iObjNodeNameEnum != null) duplicatedNode(this.iObjNodeNameEnum, CLASS); + if (this.iPathNodeNameEnum == INSTANCEPATH) illegalChildNodePair(INSTANCEPATH, CLASS); + } else if (pNodeNameEnum == INSTANCEPATH) { + if (this.iPathNodeNameEnum != null) duplicatedNode(this.iPathNodeNameEnum, INSTANCEPATH); + if (this.iObjNodeNameEnum == CLASS) illegalChildNodePair(INSTANCEPATH, CLASS); + } else if (pNodeNameEnum == INSTANCE) { + if (this.iObjNodeNameEnum != null) duplicatedNode(this.iObjNodeNameEnum, INSTANCE); + if (this.iPathNodeNameEnum == CLASSPATH) illegalChildNodePair(CLASSPATH, INSTANCE); + } else throw new SAXException(getNodeName() + " node cannot have " + pNodeNameEnum + " child!"); + } + + @Override + public void childParsed(Node pChild) throws SAXException { + if (pChild instanceof AbstractObjectPathNode) { + this.iPathNodeNameEnum = pChild.getNodeName(); + this.iObjPath = ((AbstractObjectPathNode) pChild).getCIMObjectPath(); + } else { // ClassNode or InstanceNode, iObjPath must be available + // here + this.iObjNodeNameEnum = pChild.getNodeName(); + if (this.iPathNodeNameEnum == null) throw new SAXException( + getNodeName() + " first child should contain an object path!" + ); + if (pChild instanceof ClassNode) { + this.iCIMObj = ((ClassNode) pChild).getCIMClass(this.iObjPath); + } else { + this.iCIMObj = ((InstanceNode) pChild).getCIMInstance(this.iObjPath); + } + } + } + + @Override + public void testCompletness() throws SAXException { + if (this.iPathNodeNameEnum == null) throw new SAXException( + getNodeName() + " node must have a CLASSPATH or a INSTANCEPATH child node!" + ); + if (this.iObjNodeNameEnum == null) throw new SAXException( + getNodeName() + " node must have a CLASS or INSTANCE child node!" + ); + } + + /** + * @see ValueIf#getValue() + * @return CIMClass or CIMInstance + */ + public Object getValue() { + return this.iCIMObj; + } + + public CIMDataType getType() { + if (this.iCIMObj instanceof CIMClass) return CIMDataType.CLASS_T; + return CIMDataType.OBJECT_T; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueRefArrayNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueRefArrayNode.java similarity index 68% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueRefArrayNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueRefArrayNode.java index 5cb05c1..509f9e7 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueRefArrayNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueRefArrayNode.java @@ -1,143 +1,136 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - * 3513349 2012-03-31 blaschke-oss TCK: CIMDataType must not accept null string - * 3602604 2013-01-29 blaschke-oss Clean up SAXException messages - * 2604 2013-07-01 blaschke-oss SAXException messages should contain node name - * 2715 2013-11-26 blaschke-oss Add VALUE.NULL support - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -import org.sentrysoftware.wbem.sblim.cimclient.GenericExts; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT VALUE.REFARRAY (VALUE.REFERENCE|VALUE.NULL)* - */ -public class ValueRefArrayNode extends AbstractArrayValueNode { - - private ArrayList iCIMObjPathAL; - - /** - * Ctor. - */ - public ValueRefArrayNode() { - super(VALUE_REFARRAY); - } - - /** - * @param pAttribs - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - this.iCIMObjPathAL = GenericExts.initClearArrayList(this.iCIMObjPathAL); - // no attributes - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // no data - } - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (pNodeNameEnum != VALUE_REFERENCE && pNodeNameEnum != VALUE_NULL) throw new SAXException( - getNodeName() - + " node child node can be VALUE.REFERENCE or VALUE.NULL only while it is " - + pNodeNameEnum + "!"); - } - - @Override - public void childParsed(Node pChild) { - if (this.iCIMObjPathAL == null) this.iCIMObjPathAL = new ArrayList(); - if (pChild instanceof ValueReferenceNode) this.iCIMObjPathAL - .add(((ValueReferenceNode) pChild).getCIMObjectPath()); - else if (pChild instanceof ValueNullNode) this.iCIMObjPathAL.add(null); - } - - @Override - public void testCompletness() { - // child nodes are not mandatory - } - - /** - * @see ArrayIf#elementAt(int) - * @return CIMObjectPath - */ - public Object elementAt(int pIdx) { - return this.iCIMObjPathAL == null ? null : this.iCIMObjPathAL.get(pIdx); - } - - public int size() { - return this.iCIMObjPathAL == null ? 0 : this.iCIMObjPathAL.size(); - } - - public CIMDataType getType() { - return new CIMDataType("", 0); - } - - private static final CIMObjectPath[] EMPTY_OPA = new CIMObjectPath[0]; - - /** - * @see ValueIf#getValue() - * @return CIMObjectPath[] - */ - public Object getValue() { - return size() == 0 ? null : this.iCIMObjPathAL.toArray(EMPTY_OPA); - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + * 3513349 2012-03-31 blaschke-oss TCK: CIMDataType must not accept null string + * 3602604 2013-01-29 blaschke-oss Clean up SAXException messages + * 2604 2013-07-01 blaschke-oss SAXException messages should contain node name + * 2715 2013-11-26 blaschke-oss Add VALUE.NULL support + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.sblim.cimclient.GenericExts; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT VALUE.REFARRAY (VALUE.REFERENCE|VALUE.NULL)* + */ +public class ValueRefArrayNode extends AbstractArrayValueNode { + private ArrayList iCIMObjPathAL; + + /** + * Ctor. + */ + public ValueRefArrayNode() { + super(VALUE_REFARRAY); + } + + /** + * @param pAttribs + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + this.iCIMObjPathAL = GenericExts.initClearArrayList(this.iCIMObjPathAL); + // no attributes + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // no data + } + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (pNodeNameEnum != VALUE_REFERENCE && pNodeNameEnum != VALUE_NULL) throw new SAXException( + getNodeName() + " node child node can be VALUE.REFERENCE or VALUE.NULL only while it is " + pNodeNameEnum + "!" + ); + } + + @Override + public void childParsed(Node pChild) { + if (this.iCIMObjPathAL == null) this.iCIMObjPathAL = new ArrayList(); + if (pChild instanceof ValueReferenceNode) this.iCIMObjPathAL.add( + ((ValueReferenceNode) pChild).getCIMObjectPath() + ); else if (pChild instanceof ValueNullNode) this.iCIMObjPathAL.add(null); + } + + @Override + public void testCompletness() { + // child nodes are not mandatory + } + + /** + * @see ArrayIf#elementAt(int) + * @return CIMObjectPath + */ + public Object elementAt(int pIdx) { + return this.iCIMObjPathAL == null ? null : this.iCIMObjPathAL.get(pIdx); + } + + public int size() { + return this.iCIMObjPathAL == null ? 0 : this.iCIMObjPathAL.size(); + } + + public CIMDataType getType() { + return new CIMDataType("", 0); + } + + private static final CIMObjectPath[] EMPTY_OPA = new CIMObjectPath[0]; + + /** + * @see ValueIf#getValue() + * @return CIMObjectPath[] + */ + public Object getValue() { + return size() == 0 ? null : this.iCIMObjPathAL.toArray(EMPTY_OPA); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueReferenceNode.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueReferenceNode.java similarity index 56% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueReferenceNode.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueReferenceNode.java index 65e04db..139ba0f 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueReferenceNode.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/ValueReferenceNode.java @@ -1,147 +1,160 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant - * 1663270 2007-02-19 ebak Minor performance problems - * 1660756 2007-02-22 ebak Embedded object support - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly - * 3466280 2012-04-23 blaschke-oss get instance failure for CIM_IndicationSubscription - * 2604 2013-07-01 blaschke-oss SAXException messages should contain node name - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ELEMENT VALUE.REFERENCE (CLASSPATH | LOCALCLASSPATH | CLASSNAME | - * INSTANCEPATH | LOCALINSTANCEPATH | INSTANCENAME) - */ -public class ValueReferenceNode extends AbstractScalarValueNode implements ObjectPathIf { - - private CIMObjectPath iCIMObjPath; - - private String iChildNodeName = null; - - /** - * Ctor. - */ - public ValueReferenceNode() { - super(VALUE_REFERENCE); - } - - @Override - public void childParsed(Node pChild) { - this.iCIMObjPath = ((AbstractPathNode) pChild).getCIMObjectPath(); - if ((CLASSNAME.equalsIgnoreCase(this.iChildNodeName) || INSTANCENAME - .equalsIgnoreCase(this.iChildNodeName)) - && this.iCIMObjPath.getNamespace() != null) { - // LocalPathBuilder includes default namespace in CLASSNAME and - // INSTANCENAME elements, needs to be stripped - this.iCIMObjPath = new CIMObjectPath(this.iCIMObjPath.getScheme(), this.iCIMObjPath - .getHost(), this.iCIMObjPath.getPort(), null, this.iCIMObjPath.getObjectName(), - this.iCIMObjPath.getKeys(), this.iCIMObjPath.getXmlSchemaName()); - } - } - - /** - * @param pAttribs - * @param pSession - */ - @Override - public void init(Attributes pAttribs, SAXSession pSession) { - this.iCIMObjPath = null; - this.iChildNodeName = null; - // no attributes - } - - /** - * @param pData - */ - @Override - public void parseData(String pData) { - // there is no data - } - - private static final String[] ALLOWED_CHILDREN = { CLASSPATH, LOCALCLASSPATH, CLASSNAME, - INSTANCEPATH, LOCALINSTANCEPATH, INSTANCENAME }; - - @Override - public void testChild(String pNodeNameEnum) throws SAXException { - if (this.iCIMObjPath != null) throw new SAXException("Child node " + pNodeNameEnum - + " is illegal, since VALUE.REFERENCE already has a child!"); - for (int i = 0; i < ALLOWED_CHILDREN.length; i++) - if (ALLOWED_CHILDREN[i] == pNodeNameEnum) { - this.iChildNodeName = pNodeNameEnum; - return; - } - throw new SAXException("Invalid child node in " + getNodeName() + " node: " + pNodeNameEnum - + "! Valid nodes are CLASSPATH, LOCALCLASSPATH, CLASSNAME, " - + "INSTANCEPATH, LOCALINSTANCEPATH, INSTANCENAME"); - } - - @Override - public void testCompletness() throws SAXException { - if (this.iCIMObjPath == null) throw new SAXException( - "VALUE.REFERENCE node must have a child node!"); - } - - /** - * @see ValueIf#getValue() - * @return CIMObjectPath - */ - public Object getValue() { - return this.iCIMObjPath; - } - - public CIMDataType getType() { - return this.iCIMObjPath == null ? null : new CIMDataType(this.iCIMObjPath.getObjectName()); - } - - public CIMObjectPath getCIMObjectPath() { - return this.iCIMObjPath; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-12-04 ebak Make SBLIM client JSR48 compliant + * 1663270 2007-02-19 ebak Minor performance problems + * 1660756 2007-02-22 ebak Embedded object support + * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 3511454 2012-03-27 blaschke-oss SAX nodes not reinitialized properly + * 3466280 2012-04-23 blaschke-oss get instance failure for CIM_IndicationSubscription + * 2604 2013-07-01 blaschke-oss SAXException messages should contain node name + */ + +package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXSession; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * ELEMENT VALUE.REFERENCE (CLASSPATH | LOCALCLASSPATH | CLASSNAME | + * INSTANCEPATH | LOCALINSTANCEPATH | INSTANCENAME) + */ +public class ValueReferenceNode extends AbstractScalarValueNode implements ObjectPathIf { + private CIMObjectPath iCIMObjPath; + + private String iChildNodeName = null; + + /** + * Ctor. + */ + public ValueReferenceNode() { + super(VALUE_REFERENCE); + } + + @Override + public void childParsed(Node pChild) { + this.iCIMObjPath = ((AbstractPathNode) pChild).getCIMObjectPath(); + if ( + (CLASSNAME.equalsIgnoreCase(this.iChildNodeName) || INSTANCENAME.equalsIgnoreCase(this.iChildNodeName)) && + this.iCIMObjPath.getNamespace() != null + ) { + // LocalPathBuilder includes default namespace in CLASSNAME and + // INSTANCENAME elements, needs to be stripped + this.iCIMObjPath = + new CIMObjectPath( + this.iCIMObjPath.getScheme(), + this.iCIMObjPath.getHost(), + this.iCIMObjPath.getPort(), + null, + this.iCIMObjPath.getObjectName(), + this.iCIMObjPath.getKeys(), + this.iCIMObjPath.getXmlSchemaName() + ); + } + } + + /** + * @param pAttribs + * @param pSession + */ + @Override + public void init(Attributes pAttribs, SAXSession pSession) { + this.iCIMObjPath = null; + this.iChildNodeName = null; + // no attributes + } + + /** + * @param pData + */ + @Override + public void parseData(String pData) { + // there is no data + } + + private static final String[] ALLOWED_CHILDREN = { + CLASSPATH, + LOCALCLASSPATH, + CLASSNAME, + INSTANCEPATH, + LOCALINSTANCEPATH, + INSTANCENAME + }; + + @Override + public void testChild(String pNodeNameEnum) throws SAXException { + if (this.iCIMObjPath != null) throw new SAXException( + "Child node " + pNodeNameEnum + " is illegal, since VALUE.REFERENCE already has a child!" + ); + for (int i = 0; i < ALLOWED_CHILDREN.length; i++) if (ALLOWED_CHILDREN[i] == pNodeNameEnum) { + this.iChildNodeName = pNodeNameEnum; + return; + } + throw new SAXException( + "Invalid child node in " + + getNodeName() + + " node: " + + pNodeNameEnum + + "! Valid nodes are CLASSPATH, LOCALCLASSPATH, CLASSNAME, " + + "INSTANCEPATH, LOCALINSTANCEPATH, INSTANCENAME" + ); + } + + @Override + public void testCompletness() throws SAXException { + if (this.iCIMObjPath == null) throw new SAXException("VALUE.REFERENCE node must have a child node!"); + } + + /** + * @see ValueIf#getValue() + * @return CIMObjectPath + */ + public Object getValue() { + return this.iCIMObjPath; + } + + public CIMDataType getType() { + return this.iCIMObjPath == null ? null : new CIMDataType(this.iCIMObjPath.getObjectName()); + } + + public CIMObjectPath getCIMObjectPath() { + return this.iCIMObjPath; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/package.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/package.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/node/package.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/node/package.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/package.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/package.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/package.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/cimxml/sax/package.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/discovery/package.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/discovery/package.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/discovery/package.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/discovery/package.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/discovery/slp/DiscovererSLP.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/discovery/slp/DiscovererSLP.java similarity index 71% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/discovery/slp/DiscovererSLP.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/discovery/slp/DiscovererSLP.java index cf25c9e..d4b9775 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/discovery/slp/DiscovererSLP.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/discovery/slp/DiscovererSLP.java @@ -1,256 +1,251 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1678915 2007-03-12 lupusalex Integrated WBEM service discovery via SLP - * 1729361 2007-06-04 lupusalex Multicast discovery is broken in DiscovererSLP - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1892103 2008-02-13 ebak SLP improvements - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.discovery.slp; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.net.InetAddress; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Vector; -import java.util.logging.Level; - -import org.sentrysoftware.wbem.sblim.cimclient.discovery.Discoverer; -import org.sentrysoftware.wbem.sblim.cimclient.discovery.WBEMServiceAdvertisement; -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; -import org.sentrysoftware.wbem.sblim.slp.Locator; -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationManager; -import org.sentrysoftware.wbem.sblim.slp.ServiceType; -import org.sentrysoftware.wbem.sblim.slp.ServiceURL; -import org.sentrysoftware.wbem.sblim.slp.internal.SLPDefaults; - -/** - * Class DiscovererSLP is the SLP specific implementation of the Discoverer - * interface. - * - * @since 2.0.2 - */ -public class DiscovererSLP extends Object implements Discoverer { - - private static final String SERVICE_WBEM = "service:wbem"; - - private static final ServiceType SERVICE_TYPE = new ServiceType(SERVICE_WBEM); - - private static final Vector ATTRIBUTES = new Vector(); - - private Locale iLocale; - - private Vector iScopes; - - /** - * Ctor. - * - * @param pLocale - * The locale setting to use for the Locator - */ - public DiscovererSLP(Locale pLocale) { - this.iLocale = pLocale; - this.iScopes = new Vector(); - this.iScopes.add(SLPDefaults.DEFAULT_SCOPE); - } - - /** - * Returns locale - * - * @return The value of locale. - */ - public Locale getLocale() { - return this.iLocale; - } - - /** - * Sets locale - * - * @param pLocale - * The new value of locale. - */ - public void setLocale(Locale pLocale) { - this.iLocale = pLocale; - } - - /** - * Returns scopes - * - * @return The value of scopes. - */ - public Vector getScopes() { - return this.iScopes; - } - - /** - * Sets scopes - * - * @param pScopes - * The new value of scopes. - */ - public void setScopes(Vector pScopes) { - this.iScopes = pScopes; - } - - /* - * (non-Javadoc) - * - * @see org.sblim.cimclient.discovery.Discoverer#findWbemServices(String[]) - */ - public WBEMServiceAdvertisement[] findWbemServices(final String[] pDirectoryUrls) { - - List advertisements = new ArrayList(); - - if (pDirectoryUrls != null && pDirectoryUrls.length > 0) { - for (int i = 0; i < pDirectoryUrls.length; ++i) { - advertisements.addAll(findWbemServices(pDirectoryUrls[i])); - } - } else { - advertisements.addAll(findWbemServices((String) null)); - } - - return advertisements.toArray(new WBEMServiceAdvertisement[advertisements.size()]); - } - - private List findWbemServices(final String pDA) { - final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - logger.trace(Level.FINEST, "SLP discovery started on DA " + pDA); - try { - - Vector agents; - if (pDA != null) { - agents = new Vector(); - InetAddress address = InetAddress.getByName(pDA); - if (address == null) { return new LinkedList(); } - agents.add(address); - } else { - agents = null; - } - - final Locator locator = ServiceLocationManager.getLocator(this.iLocale); - - List advertisements = new ArrayList(); - Enumeration serviceEnum = locator.findServices(SERVICE_TYPE, this.iScopes, "", - agents); - - while (serviceEnum != null && serviceEnum.hasMoreElements()) { - ServiceURL url; - try { - url = (ServiceURL) serviceEnum.nextElement(); - } catch (RuntimeException e) { - logger.trace(Level.FINE, e.getMessage(), e); - continue; - } - Enumeration attributeEnum = locator.findAttributes(url, this.iScopes, - ATTRIBUTES, agents); - List attributes = new ArrayList(); - while (attributeEnum != null && attributeEnum.hasMoreElements()) { - try { - attributes.add(attributeEnum.nextElement().toString()); - } catch (RuntimeException e) { - logger.trace(Level.FINE, e.getMessage(), e); - continue; - } - } - advertisements.add(new WBEMServiceAdvertisementSLP(pDA, url, attributes)); - } - logger.trace(Level.FINEST, "SLP discovery completed on DA " + pDA + ". " - + advertisements.size() + " WBEM services found"); - logger.exit(); - return advertisements; - - } catch (ServiceLocationException e) { - LogAndTraceBroker.getBroker().trace(Level.FINE, "SLP discovery failed with error", e); - } catch (Exception e) { - LogAndTraceBroker.getBroker() - .trace(Level.FINE, "Exception during service discovery", e); - } - logger.exit(); - return new LinkedList(); - } - - public String[] findDirectoryServices() { - final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - try { - ArrayList agents = new ArrayList(); - - final Locator locator = ServiceLocationManager.getLocator(this.iLocale); - - Enumeration serviceEnum = locator.findServices(SLPDefaults.DA_SERVICE_TYPE, - this.iScopes, ""); - - while (serviceEnum != null && serviceEnum.hasMoreElements()) { - ServiceURL url = (ServiceURL) serviceEnum.nextElement(); - agents.add(url.getHost()); - } - - logger.trace(Level.FINER, "SLP DA discovery completed in local subnet. " - + agents.size() + " DAs found:" + agents.toString()); - if (agents.size() == 0) { - serviceEnum = locator.findServices(SLPDefaults.SA_SERVICE_TYPE, this.iScopes, ""); - - while (serviceEnum != null && serviceEnum.hasMoreElements()) { - ServiceURL url = (ServiceURL) serviceEnum.nextElement(); - agents.add(url.getHost()); - } - logger.trace(Level.FINER, "SLP SA discovery completed in local subnet. " - + agents.size() + " SAs found:" + agents.toString()); - } - - logger.exit(); - return agents.toArray(new String[agents.size()]); - - } catch (ServiceLocationException e) { - LogAndTraceBroker.getBroker().trace(Level.FINE, "SLP discovery failed with error", e); - } catch (Exception e) { - LogAndTraceBroker.getBroker() - .trace(Level.FINE, "Exception during service discovery", e); - } - logger.exit(); - return new String[0]; - } -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1678915 2007-03-12 lupusalex Integrated WBEM service discovery via SLP + * 1729361 2007-06-04 lupusalex Multicast discovery is broken in DiscovererSLP + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1892103 2008-02-13 ebak SLP improvements + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + */ + +package org.metricshub.wbem.sblim.cimclient.internal.discovery.slp; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.net.InetAddress; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Vector; +import java.util.logging.Level; +import org.metricshub.wbem.sblim.cimclient.discovery.Discoverer; +import org.metricshub.wbem.sblim.cimclient.discovery.WBEMServiceAdvertisement; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; +import org.metricshub.wbem.sblim.slp.Locator; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; +import org.metricshub.wbem.sblim.slp.ServiceLocationManager; +import org.metricshub.wbem.sblim.slp.ServiceType; +import org.metricshub.wbem.sblim.slp.ServiceURL; +import org.metricshub.wbem.sblim.slp.internal.SLPDefaults; + +/** + * Class DiscovererSLP is the SLP specific implementation of the Discoverer + * interface. + * + * @since 2.0.2 + */ +public class DiscovererSLP implements Discoverer { + private static final String SERVICE_WBEM = "service:wbem"; + + private static final ServiceType SERVICE_TYPE = new ServiceType(SERVICE_WBEM); + + private static final Vector ATTRIBUTES = new Vector(); + + private Locale iLocale; + + private Vector iScopes; + + /** + * Ctor. + * + * @param pLocale + * The locale setting to use for the Locator + */ + public DiscovererSLP(Locale pLocale) { + this.iLocale = pLocale; + this.iScopes = new Vector(); + this.iScopes.add(SLPDefaults.DEFAULT_SCOPE); + } + + /** + * Returns locale + * + * @return The value of locale. + */ + public Locale getLocale() { + return this.iLocale; + } + + /** + * Sets locale + * + * @param pLocale + * The new value of locale. + */ + public void setLocale(Locale pLocale) { + this.iLocale = pLocale; + } + + /** + * Returns scopes + * + * @return The value of scopes. + */ + public Vector getScopes() { + return this.iScopes; + } + + /** + * Sets scopes + * + * @param pScopes + * The new value of scopes. + */ + public void setScopes(Vector pScopes) { + this.iScopes = pScopes; + } + + /* + * (non-Javadoc) + * + * @see org.sblim.cimclient.discovery.Discoverer#findWbemServices(String[]) + */ + public WBEMServiceAdvertisement[] findWbemServices(final String[] pDirectoryUrls) { + List advertisements = new ArrayList(); + + if (pDirectoryUrls != null && pDirectoryUrls.length > 0) { + for (int i = 0; i < pDirectoryUrls.length; ++i) { + advertisements.addAll(findWbemServices(pDirectoryUrls[i])); + } + } else { + advertisements.addAll(findWbemServices((String) null)); + } + + return advertisements.toArray(new WBEMServiceAdvertisement[advertisements.size()]); + } + + private List findWbemServices(final String pDA) { + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + logger.trace(Level.FINEST, "SLP discovery started on DA " + pDA); + try { + Vector agents; + if (pDA != null) { + agents = new Vector(); + InetAddress address = InetAddress.getByName(pDA); + if (address == null) { + return new LinkedList(); + } + agents.add(address); + } else { + agents = null; + } + + final Locator locator = ServiceLocationManager.getLocator(this.iLocale); + + List advertisements = new ArrayList(); + Enumeration serviceEnum = locator.findServices(SERVICE_TYPE, this.iScopes, "", agents); + + while (serviceEnum != null && serviceEnum.hasMoreElements()) { + ServiceURL url; + try { + url = (ServiceURL) serviceEnum.nextElement(); + } catch (RuntimeException e) { + logger.trace(Level.FINE, e.getMessage(), e); + continue; + } + Enumeration attributeEnum = locator.findAttributes(url, this.iScopes, ATTRIBUTES, agents); + List attributes = new ArrayList(); + while (attributeEnum != null && attributeEnum.hasMoreElements()) { + try { + attributes.add(attributeEnum.nextElement().toString()); + } catch (RuntimeException e) { + logger.trace(Level.FINE, e.getMessage(), e); + continue; + } + } + advertisements.add(new WBEMServiceAdvertisementSLP(pDA, url, attributes)); + } + logger.trace( + Level.FINEST, + "SLP discovery completed on DA " + pDA + ". " + advertisements.size() + " WBEM services found" + ); + logger.exit(); + return advertisements; + } catch (ServiceLocationException e) { + LogAndTraceBroker.getBroker().trace(Level.FINE, "SLP discovery failed with error", e); + } catch (Exception e) { + LogAndTraceBroker.getBroker().trace(Level.FINE, "Exception during service discovery", e); + } + logger.exit(); + return new LinkedList(); + } + + public String[] findDirectoryServices() { + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + try { + ArrayList agents = new ArrayList(); + + final Locator locator = ServiceLocationManager.getLocator(this.iLocale); + + Enumeration serviceEnum = locator.findServices(SLPDefaults.DA_SERVICE_TYPE, this.iScopes, ""); + + while (serviceEnum != null && serviceEnum.hasMoreElements()) { + ServiceURL url = (ServiceURL) serviceEnum.nextElement(); + agents.add(url.getHost()); + } + + logger.trace( + Level.FINER, + "SLP DA discovery completed in local subnet. " + agents.size() + " DAs found:" + agents.toString() + ); + if (agents.size() == 0) { + serviceEnum = locator.findServices(SLPDefaults.SA_SERVICE_TYPE, this.iScopes, ""); + + while (serviceEnum != null && serviceEnum.hasMoreElements()) { + ServiceURL url = (ServiceURL) serviceEnum.nextElement(); + agents.add(url.getHost()); + } + logger.trace( + Level.FINER, + "SLP SA discovery completed in local subnet. " + agents.size() + " SAs found:" + agents.toString() + ); + } + + logger.exit(); + return agents.toArray(new String[agents.size()]); + } catch (ServiceLocationException e) { + LogAndTraceBroker.getBroker().trace(Level.FINE, "SLP discovery failed with error", e); + } catch (Exception e) { + LogAndTraceBroker.getBroker().trace(Level.FINE, "Exception during service discovery", e); + } + logger.exit(); + return new String[0]; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/discovery/slp/WBEMServiceAdvertisementSLP.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/discovery/slp/WBEMServiceAdvertisementSLP.java similarity index 75% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/discovery/slp/WBEMServiceAdvertisementSLP.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/discovery/slp/WBEMServiceAdvertisementSLP.java index 0617404..a7d3916 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/discovery/slp/WBEMServiceAdvertisementSLP.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/discovery/slp/WBEMServiceAdvertisementSLP.java @@ -1,295 +1,294 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1678915 2007-03-12 lupusalex Integrated WBEM service discovery via SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.discovery.slp; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; -import java.util.Map.Entry; -import java.util.logging.Level; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import javax.security.auth.Subject; -import org.sentrysoftware.wbem.javax.wbem.client.WBEMClient; -import org.sentrysoftware.wbem.javax.wbem.client.WBEMClientFactory; - -import org.sentrysoftware.wbem.sblim.cimclient.discovery.WBEMServiceAdvertisement; -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; -import org.sentrysoftware.wbem.sblim.slp.ServiceURL; - -/** - * Class WBEMServiceAdvertisementSLP is the SLP specific implementation if the - * WBEMServiceAdvertisement interface. - * - * - * @since 2.0.2 - */ -public class WBEMServiceAdvertisementSLP implements WBEMServiceAdvertisement { - - private static final Pattern ATTR_PATTERN = Pattern.compile("[(]?(.+)=([^)]+)[)]?"); - - private String iDA; - - private ServiceURL iServiceUrl; - - private Map iAttributeMap; - - private boolean iExpired = false; - - /** - * Ctor. - * - * @param pDA - * The Directory Agent from which this advertisement was received - * @param pUrl - * The SLP service url returned by Locator.findServices(). - * @param pAttributes - * The attribute list (List<String>) where each entry looks - * either like this key=value or this - * (key=value). - */ - public WBEMServiceAdvertisementSLP(String pDA, ServiceURL pUrl, List pAttributes) { - if (pDA == null || pUrl == null) throw new IllegalArgumentException( - "Directory and URL must not be null"); - this.iDA = pDA; - this.iServiceUrl = pUrl; - parseAttributes(pAttributes); - - } - - private void parseAttributes(List pAttributes) { - this.iAttributeMap = new HashMap(); - Iterator iter = pAttributes.iterator(); - while (iter.hasNext()) { - String attribute = iter.next(); - Matcher matcher = ATTR_PATTERN.matcher(attribute); - if (matcher.matches()) { - String key = matcher.group(1).trim(); - String value = matcher.group(2).trim(); - this.iAttributeMap.put(key, value); - } else { - LogAndTraceBroker.getBroker().trace(Level.FINE, - "SLP discovery returned invalid attribute: " + attribute); - } - } - } - - /* - * (non-Javadoc) - * - * @see - * org.sblim.cimclient.discovery.WbemService#getAttribute(java.lang.String) - */ - public String getAttribute(String pAttributeName) { - return this.iAttributeMap.get(pAttributeName); - } - - /* - * (non-Javadoc) - * - * @see org.sblim.cimclient.discovery.WbemService#getAttributes() - */ - public Set> getAttributes() { - return this.iAttributeMap.entrySet(); - } - - /* - * (non-Javadoc) - * - * @see org.sblim.cimclient.discovery.WbemService#getConcreteServiceType() - */ - public String getConcreteServiceType() { - return this.iServiceUrl.getServiceType().getConcreteTypeName(); - } - - /* - * (non-Javadoc) - * - * @see org.sblim.cimclient.discovery.WbemService#getServiceUrl() - */ - public String getServiceUrl() { - return getConcreteServiceType() + "://" + this.iServiceUrl.getHost() + ":" - + String.valueOf(this.iServiceUrl.getPort()); - } - - /* - * (non-Javadoc) - * - * @see - * org.sblim.cimclient.discovery.WBEMServiceAdvertisement#createClient(javax - * .security.auth.Subject, java.util.Locale[]) - */ - public WBEMClient createClient(Subject pSubject, Locale[] pLocales) throws Exception { - String communication = getAttribute(COMM_MECHANISM); - if (communication.equalsIgnoreCase("OTHER")) { - communication = getAttribute(OTHER_COMM_MECHN_DESC); - } - WBEMClient client = WBEMClientFactory.getClient(communication); - CIMObjectPath path = new CIMObjectPath(this.iServiceUrl.getServiceType() - .getConcreteTypeName(), this.iServiceUrl.getHost(), String.valueOf(this.iServiceUrl - .getPort()), null, null, null); - client.initialize(path, pSubject, pLocales); - return client; - } - - public String getDirectory() { - return this.iDA; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - StringBuffer buffer = new StringBuffer(); - // buffer.append(iServiceUrl.getServiceType()); - // buffer.append("://"); - // buffer.append(iServiceUrl.getHost()); - buffer.append(getServiceUrl()); - buffer.append("{slp da=\""); - buffer.append(this.iDA); - buffer.append("\", attributes=["); - Iterator> iter = this.iAttributeMap.entrySet().iterator(); - while (iter.hasNext()) { - Entry entry = iter.next(); - buffer.append("\""); - buffer.append(entry.getKey()); - buffer.append("="); - buffer.append(entry.getValue()); - buffer.append("\""); - if (iter.hasNext()) buffer.append(", "); - } - buffer.append("]}"); - return buffer.toString(); - } - - public String[] getInteropNamespaces() { - return parseCommaSeparatedList(getAttribute(INTEROP_NS)); - } - - private String[] parseCommaSeparatedList(String pAttribute) { - String[] split = pAttribute.split("[,\\n]"); - int emptyCount = 0; - for (int i = 0; i < split.length; ++i) { - split[i] = split[i].trim(); - if (split[i].length() == 0) { - ++emptyCount; - } - } - if (emptyCount > 0) { - String[] result = new String[split.length - emptyCount]; - int j = 0; - for (int i = 0; i < split.length; ++i) { - if (split[i].length() > 0) { - result[j++] = split[i]; - } - } - return result; - } - return split; - } - - /* - * (non-Javadoc) - * - * @see - * org.sblim.cimclient.discovery.WBEMServiceAdvertisement#getServiceId() - */ - public String getServiceId() { - return getAttribute(SERVICE_ID); - } - - /* - * (non-Javadoc) - * - * @see org.sblim.cimclient.discovery.WBEMServiceAdvertisement#isExpired() - */ - public boolean isExpired() { - return this.iExpired; - } - - /* - * (non-Javadoc) - * - * @see - * org.sblim.cimclient.discovery.WBEMServiceAdvertisement#setExpired(boolean - * ) - */ - public void setExpired(boolean pExpired) { - this.iExpired = pExpired; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object pObj) { - if (pObj == this) { return true; } - if (pObj != null && pObj instanceof WBEMServiceAdvertisement) { - WBEMServiceAdvertisement that = (WBEMServiceAdvertisement) pObj; - return getServiceUrl().equals(that.getServiceUrl()) - && getDirectory().equals(that.getDirectory()); - } - return false; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - return this.iServiceUrl.hashCode() + this.iDA.hashCode(); - } -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1678915 2007-03-12 lupusalex Integrated WBEM service discovery via SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.discovery.slp; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.logging.Level; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import javax.security.auth.Subject; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.wbem.client.WBEMClient; +import org.metricshub.wbem.javax.wbem.client.WBEMClientFactory; +import org.metricshub.wbem.sblim.cimclient.discovery.WBEMServiceAdvertisement; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; +import org.metricshub.wbem.sblim.slp.ServiceURL; + +/** + * Class WBEMServiceAdvertisementSLP is the SLP specific implementation if the + * WBEMServiceAdvertisement interface. + * + * + * @since 2.0.2 + */ +public class WBEMServiceAdvertisementSLP implements WBEMServiceAdvertisement { + private static final Pattern ATTR_PATTERN = Pattern.compile("[(]?(.+)=([^)]+)[)]?"); + + private String iDA; + + private ServiceURL iServiceUrl; + + private Map iAttributeMap; + + private boolean iExpired = false; + + /** + * Ctor. + * + * @param pDA + * The Directory Agent from which this advertisement was received + * @param pUrl + * The SLP service url returned by Locator.findServices(). + * @param pAttributes + * The attribute list (List<String>) where each entry looks + * either like this key=value or this + * (key=value). + */ + public WBEMServiceAdvertisementSLP(String pDA, ServiceURL pUrl, List pAttributes) { + if (pDA == null || pUrl == null) throw new IllegalArgumentException("Directory and URL must not be null"); + this.iDA = pDA; + this.iServiceUrl = pUrl; + parseAttributes(pAttributes); + } + + private void parseAttributes(List pAttributes) { + this.iAttributeMap = new HashMap(); + Iterator iter = pAttributes.iterator(); + while (iter.hasNext()) { + String attribute = iter.next(); + Matcher matcher = ATTR_PATTERN.matcher(attribute); + if (matcher.matches()) { + String key = matcher.group(1).trim(); + String value = matcher.group(2).trim(); + this.iAttributeMap.put(key, value); + } else { + LogAndTraceBroker.getBroker().trace(Level.FINE, "SLP discovery returned invalid attribute: " + attribute); + } + } + } + + /* + * (non-Javadoc) + * + * @see + * org.sblim.cimclient.discovery.WbemService#getAttribute(java.lang.String) + */ + public String getAttribute(String pAttributeName) { + return this.iAttributeMap.get(pAttributeName); + } + + /* + * (non-Javadoc) + * + * @see org.sblim.cimclient.discovery.WbemService#getAttributes() + */ + public Set> getAttributes() { + return this.iAttributeMap.entrySet(); + } + + /* + * (non-Javadoc) + * + * @see org.sblim.cimclient.discovery.WbemService#getConcreteServiceType() + */ + public String getConcreteServiceType() { + return this.iServiceUrl.getServiceType().getConcreteTypeName(); + } + + /* + * (non-Javadoc) + * + * @see org.sblim.cimclient.discovery.WbemService#getServiceUrl() + */ + public String getServiceUrl() { + return ( + getConcreteServiceType() + "://" + this.iServiceUrl.getHost() + ":" + String.valueOf(this.iServiceUrl.getPort()) + ); + } + + /* + * (non-Javadoc) + * + * @see + * org.sblim.cimclient.discovery.WBEMServiceAdvertisement#createClient(javax + * .security.auth.Subject, java.util.Locale[]) + */ + public WBEMClient createClient(Subject pSubject, Locale[] pLocales) throws Exception { + String communication = getAttribute(COMM_MECHANISM); + if (communication.equalsIgnoreCase("OTHER")) { + communication = getAttribute(OTHER_COMM_MECHN_DESC); + } + WBEMClient client = WBEMClientFactory.getClient(communication); + CIMObjectPath path = new CIMObjectPath( + this.iServiceUrl.getServiceType().getConcreteTypeName(), + this.iServiceUrl.getHost(), + String.valueOf(this.iServiceUrl.getPort()), + null, + null, + null + ); + client.initialize(path, pSubject, pLocales); + return client; + } + + public String getDirectory() { + return this.iDA; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuffer buffer = new StringBuffer(); + // buffer.append(iServiceUrl.getServiceType()); + // buffer.append("://"); + // buffer.append(iServiceUrl.getHost()); + buffer.append(getServiceUrl()); + buffer.append("{slp da=\""); + buffer.append(this.iDA); + buffer.append("\", attributes=["); + Iterator> iter = this.iAttributeMap.entrySet().iterator(); + while (iter.hasNext()) { + Entry entry = iter.next(); + buffer.append("\""); + buffer.append(entry.getKey()); + buffer.append("="); + buffer.append(entry.getValue()); + buffer.append("\""); + if (iter.hasNext()) buffer.append(", "); + } + buffer.append("]}"); + return buffer.toString(); + } + + public String[] getInteropNamespaces() { + return parseCommaSeparatedList(getAttribute(INTEROP_NS)); + } + + private String[] parseCommaSeparatedList(String pAttribute) { + String[] split = pAttribute.split("[,\\n]"); + int emptyCount = 0; + for (int i = 0; i < split.length; ++i) { + split[i] = split[i].trim(); + if (split[i].length() == 0) { + ++emptyCount; + } + } + if (emptyCount > 0) { + String[] result = new String[split.length - emptyCount]; + int j = 0; + for (int i = 0; i < split.length; ++i) { + if (split[i].length() > 0) { + result[j++] = split[i]; + } + } + return result; + } + return split; + } + + /* + * (non-Javadoc) + * + * @see + * org.sblim.cimclient.discovery.WBEMServiceAdvertisement#getServiceId() + */ + public String getServiceId() { + return getAttribute(SERVICE_ID); + } + + /* + * (non-Javadoc) + * + * @see org.sblim.cimclient.discovery.WBEMServiceAdvertisement#isExpired() + */ + public boolean isExpired() { + return this.iExpired; + } + + /* + * (non-Javadoc) + * + * @see + * org.sblim.cimclient.discovery.WBEMServiceAdvertisement#setExpired(boolean + * ) + */ + public void setExpired(boolean pExpired) { + this.iExpired = pExpired; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object pObj) { + if (pObj == this) { + return true; + } + if (pObj != null && pObj instanceof WBEMServiceAdvertisement) { + WBEMServiceAdvertisement that = (WBEMServiceAdvertisement) pObj; + return getServiceUrl().equals(that.getServiceUrl()) && getDirectory().equals(that.getDirectory()); + } + return false; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return this.iServiceUrl.hashCode() + this.iDA.hashCode(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/discovery/slp/package.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/discovery/slp/package.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/discovery/slp/package.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/discovery/slp/package.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/AuthorizationHandler.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/AuthorizationHandler.java similarity index 71% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/AuthorizationHandler.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/AuthorizationHandler.java index de5deb2..50a417c 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/AuthorizationHandler.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/AuthorizationHandler.java @@ -1,121 +1,130 @@ -/* - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 1516242 2006-11-27 lupusalex Support of OpenPegasus local authentication - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; -import java.util.Iterator; - -/** - * Class AuthorizationHandler manages AdAuthorizationInfo instances - * - */ -public class AuthorizationHandler { - - private ArrayList iAuthList = new ArrayList(); - - /** - * Adds an AuthorizationInfo to the handler - * - * @param pAuthorizationInfo - * The AuthorizationInfo to add - */ - public synchronized void addAuthorizationInfo(AuthorizationInfo pAuthorizationInfo) { - this.iAuthList.add(pAuthorizationInfo); - } - - /** - * Returns the corresponding AuthorizationInfo for a given set of parameters - * - * @param pAuthorizationModule - * The authorization module - * @param pProxy - * Proxy authentication ? - * @param pAddr - * Host address - * @param pPort - * Host port - * @param pProtocol - * Protocol - * @param pRealm - * Realm - * @param pScheme - * Scheme - * @return The AuthorizationInfo or null if none fits - */ - public synchronized AuthorizationInfo getAuthorizationInfo(String pAuthorizationModule, - Boolean pProxy, String pAddr, int pPort, String pProtocol, String pRealm, String pScheme) { - - AuthorizationInfo request = AuthorizationInfo.createAuthorizationInfo(pAuthorizationModule, - pProxy, pAddr, pPort, pProtocol, pRealm, pScheme); - - Iterator iter = this.iAuthList.iterator(); - while (iter.hasNext()) { - AuthorizationInfo authInfo = iter.next(); - - if (authInfo.match(request)) return authInfo; - - } - return null; - } - - /** - * Returns the AuthorizationInfo at a given index - * - * @param pIndex - * The index - * @return The AuthorizationInfo - */ - public synchronized AuthorizationInfo getAuthorizationInfo(int pIndex) { - return this.iAuthList.get(pIndex); - } - - @Override - public String toString() { - return "AuthorizationHandler=[AuthInfoList=" + this.iAuthList + "]"; - } -} +/* + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 1516242 2006-11-27 lupusalex Support of OpenPegasus local authentication + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import java.util.Iterator; + +/** + * Class AuthorizationHandler manages AdAuthorizationInfo instances + * + */ +public class AuthorizationHandler { + private ArrayList iAuthList = new ArrayList(); + + /** + * Adds an AuthorizationInfo to the handler + * + * @param pAuthorizationInfo + * The AuthorizationInfo to add + */ + public synchronized void addAuthorizationInfo(AuthorizationInfo pAuthorizationInfo) { + this.iAuthList.add(pAuthorizationInfo); + } + + /** + * Returns the corresponding AuthorizationInfo for a given set of parameters + * + * @param pAuthorizationModule + * The authorization module + * @param pProxy + * Proxy authentication ? + * @param pAddr + * Host address + * @param pPort + * Host port + * @param pProtocol + * Protocol + * @param pRealm + * Realm + * @param pScheme + * Scheme + * @return The AuthorizationInfo or null if none fits + */ + public synchronized AuthorizationInfo getAuthorizationInfo( + String pAuthorizationModule, + Boolean pProxy, + String pAddr, + int pPort, + String pProtocol, + String pRealm, + String pScheme + ) { + AuthorizationInfo request = AuthorizationInfo.createAuthorizationInfo( + pAuthorizationModule, + pProxy, + pAddr, + pPort, + pProtocol, + pRealm, + pScheme + ); + + Iterator iter = this.iAuthList.iterator(); + while (iter.hasNext()) { + AuthorizationInfo authInfo = iter.next(); + + if (authInfo.match(request)) return authInfo; + } + return null; + } + + /** + * Returns the AuthorizationInfo at a given index + * + * @param pIndex + * The index + * @return The AuthorizationInfo + */ + public synchronized AuthorizationInfo getAuthorizationInfo(int pIndex) { + return this.iAuthList.get(pIndex); + } + + @Override + public String toString() { + return "AuthorizationHandler=[AuthInfoList=" + this.iAuthList + "]"; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/AuthorizationInfo.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/AuthorizationInfo.java similarity index 78% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/AuthorizationInfo.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/AuthorizationInfo.java index 9101121..eb4fdb0 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/AuthorizationInfo.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/AuthorizationInfo.java @@ -1,515 +1,518 @@ -/* - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 17970 2005-08-11 pineiro5 Logon from z/OS not possible - * 1516242 2006-07-05 lupusalex Support of OpenPegasus local authentication - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.net.PasswordAuthentication; -import java.net.URI; -import java.security.NoSuchAlgorithmException; -import java.util.logging.Level; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.Messages; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConfiguration; - -/** - * Abstract superclass for HTTP authorization information. - * - * @see WwwAuthInfo - * @see PegasusLocalAuthInfo - */ -public abstract class AuthorizationInfo { - - protected String iAddr; - - protected int iPort; - - protected String iProtocol; - - protected String iRealm; - - protected String iScheme; - - protected PasswordAuthentication iCredentials; - - protected long iNc = 1; - - protected String iCnonce; - - protected String iOpaque; - - protected String iAlgorithm; - - protected String iUri; - - protected String iNonce; - - protected String iQop; - - protected String iA1; - - protected String iResponse; - - // protected byte[] iDigest; - - /** - * Initialize - * - * @param pProxy - * Proxy authentication ? - * @param pAddress - * Server address - * @param pPort - * Server port - * @param pProtocol - * Protocol - * @param pRealm - * Realm - * @param pScheme - * Scheme - */ - public void init(Boolean pProxy, String pAddress, int pPort, String pProtocol, String pRealm, - String pScheme) { - this.iAddr = pAddress; - this.iPort = pPort; - this.iProtocol = pProtocol; - this.iRealm = pRealm; - this.iScheme = pScheme; - } - - /** - * Sets opaque - * - * @param opaque - * new Value - */ - public void setOpaque(String opaque) { - this.iOpaque = opaque; - } - - /** - * Returns opaque - * - * @return Opaque - */ - public String getOpaque() { - return this.iOpaque; - } - - /** - * Returns Qop - * - * @return Qop - */ - public String getQop() { - return this.iQop; - } - - /** - * Sets Qop - * - * @param qop - * New value - */ - public void setQop(String qop) { - this.iQop = qop; - } - - /** - * Returns nc - * - * @return nc - */ - public long getNc() { - return this.iNc; - } - - /** - * Sets nc - * - * @param nc - * New value - */ - public void setNc(long nc) { - this.iNc = nc; - } - - /** - * Sets nonce - * - * @param nonce - * New Value - */ - public void setNonce(String nonce) { - this.iNonce = nonce; - } - - /** - * Returns nonce - * - * @return nonce - */ - public String getNonce() { - return this.iNonce; - } - - /** - * Set cnonce - * - * @param cnonce - * New value - */ - public void setCnonce(String cnonce) { - this.iCnonce = cnonce; - } - - /** - * Returns cnonce - * - * @return cnonce - */ - public String getCnonce() { - return this.iCnonce; - } - - /** - * Set algorithm - * - * @param algorithm - * New value - */ - public void setAlgorithm(String algorithm) { - this.iAlgorithm = algorithm; - } - - /** - * Returns algorithm - * - * @return algorithm - */ - public String getAlgorithm() { - return this.iAlgorithm; - } - - /** - * Returns A1 - * - * @return A1 - */ - public String getA1() { - return this.iA1; - } - - /** - * Sets A1 - * - * @param A1 - * New value - */ - public void setA1(String A1) { - this.iA1 = A1; - } - - /** - * Sets response - * - * @param response - * New value - */ - public void setResponse(String response) { - this.iResponse = response; - } - - /** - * Returns response - * - * @return New value - */ - public String getResponse() { - return this.iResponse; - } - - /** - * Returns URI - * - * @return URI - */ - public String getURI() { - return this.iUri; - } - - /** - * Sets URI - * - * @param uri - * New value - */ - public void setURI(String uri) { - this.iUri = uri; - } - - /** - * Sets credentials - * - * @param credentials - * New value - */ - public void setCredentials(PasswordAuthentication credentials) { - this.iCredentials = credentials; - } - - /** - * Returns the address - * - * @return The server address - */ - public String getAddr() { - return this.iAddr; - } - - /** - * Returns the port - * - * @return The server port - */ - public int getPort() { - return this.iPort; - } - - /** - * Returns the protocol - * - * @return The protocol - */ - public String getProtocol() { - return this.iProtocol; - } - - /** - * Returns the realm - * - * @return The realm - */ - public String getRealm() { - return this.iRealm; - } - - /** - * Sets the realm - * - * @param realm - * New value - */ - public void setRealm(String realm) { - this.iRealm = realm; - } - - /** - * Returns the scheme - * - * @return The scheme - */ - public String getScheme() { - return this.iScheme; - } - - /** - * Sets the scheme - * - * @param scheme - * New value - */ - public void setScheme(String scheme) { - this.iScheme = scheme; - } - - /** - * Returns the credentials - * - * @return The credentials - */ - public PasswordAuthentication getCredentials() { - return this.iCredentials; - } - - /** - * Compares two authorization informations. - * - * @param obj - * The other authorization information - * @return true if type, realm, scheme, address, protocol and - * port of both authorization informations are equal, - * false otherwise. - */ - public boolean match(Object obj) { - if (obj == null || !(obj instanceof AuthorizationInfo)) return false; - AuthorizationInfo that = (AuthorizationInfo) obj; - - boolean type = getClass().equals(that.getClass()); - // boolean prxt = (iProxy == null || that.iProxy == null)? - // true:iProxy.equals(that.iProxy); - boolean prmpt = (this.iRealm == null || that.iRealm == null) ? true : this.iRealm - .equals(that.iRealm); - boolean schm = (this.iScheme == null || that.iScheme == null) ? true : this.iScheme - .equals(that.iScheme); - boolean adr = (this.iAddr == null || that.iAddr == null) ? true : this.iAddr - .equals(that.iAddr); - boolean prot = (this.iProtocol == null || that.iProtocol == null) ? true : this.iProtocol - .equals(that.iProtocol); - boolean prt = (this.iPort <= 0 || that.iPort <= 0) ? true : (this.iPort == that.iPort); - return (type && prmpt && schm && adr && prot && prt); - } - - /** - * Updates the authorization information according to a received challenge. - * - * @param challenge - * The received challenge - * @param authenticate - * The authenticate header field - * @param url - * The url of the CIM server - * @param requestMethod - * The HTTP request method (POST or MPOST) - * @throws NoSuchAlgorithmException - */ - public abstract void updateAuthenticationInfo(Challenge challenge, String authenticate, - URI url, String requestMethod) throws NoSuchAlgorithmException; - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - @Override - public abstract String toString(); - - /** - * Gets the HTTP header field name for this authentication information - * - * @return The field name - */ - public abstract String getHeaderFieldName(); - - /** - * Determines if the authorization information is already sent on the very - * first http request or after the "401 Unauthorized" response - * - * @return true or false - */ - public abstract boolean isSentOnFirstRequest(); - - /** - * Determines if the connection is kept alive after the "401 Unauthorized" - * response - * - * @return true or false - */ - public abstract boolean isKeptAlive(); - - /** - * Factory method for AuthorizationInfo objects. Returns an instance of a - * subclass according to the requested type. - * - * @param pModule - * The authorization info type to be constructed - * @param pProxy - * Proxy authentication ? - * @param pAddress - * Server address - * @param pPort - * Server port - * @param pProtocol - * Protocol (http/https) - * @param pRealm - * Realm - * @param pScheme - * Scheme (e.g. Basic, Digest) - * @return An instance of a AuthorizationInfo subclass or null - * @see WBEMConfiguration#getHttpAuthenticationModule() - * @see WwwAuthInfo - * @see PegasusLocalAuthInfo - */ - public static AuthorizationInfo createAuthorizationInfo(String pModule, Boolean pProxy, - String pAddress, int pPort, String pProtocol, String pRealm, String pScheme) { - - AuthorizationInfo info = createAuthorizationInfo(pModule); - - if (info != null) { - info.init(pProxy, pAddress, pPort, pProtocol, pRealm, pScheme); - } - - return info; - - } - - /** - * Factory method for AuthorizationInfo objects. Returns an instance of a - * subclass according to the requested type. - * - * @param pModule - * The authorization info type to be constructed - * @return An instance of a AuthorizationInfo subclass or null - */ - public static AuthorizationInfo createAuthorizationInfo(String pModule) { - - if (WwwAuthInfo.class.getName().equals(pModule)) { return new WwwAuthInfo(); } - if (PegasusLocalAuthInfo.class.getName().equals(pModule)) { return new PegasusLocalAuthInfo(); } - - try { - Class module = Class.forName(pModule); - AuthorizationInfo info = (AuthorizationInfo) module.newInstance(); - return info; - } catch (Exception e) { - LogAndTraceBroker.getBroker().trace(Level.FINER, - "Exception while loading authentication module", e); - LogAndTraceBroker.getBroker().message(Messages.HTTP_AUTH_MODULE_INVALID, pModule); - } - return null; - } -} +/* + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 17970 2005-08-11 pineiro5 Logon from z/OS not possible + * 1516242 2006-07-05 lupusalex Support of OpenPegasus local authentication + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + */ + +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.net.PasswordAuthentication; +import java.net.URI; +import java.security.NoSuchAlgorithmException; +import java.util.logging.Level; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; +import org.metricshub.wbem.sblim.cimclient.internal.logging.Messages; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfiguration; + +/** + * Abstract superclass for HTTP authorization information. + * + * @see WwwAuthInfo + * @see PegasusLocalAuthInfo + */ +public abstract class AuthorizationInfo { + protected String iAddr; + + protected int iPort; + + protected String iProtocol; + + protected String iRealm; + + protected String iScheme; + + protected PasswordAuthentication iCredentials; + + protected long iNc = 1; + + protected String iCnonce; + + protected String iOpaque; + + protected String iAlgorithm; + + protected String iUri; + + protected String iNonce; + + protected String iQop; + + protected String iA1; + + protected String iResponse; + + // protected byte[] iDigest; + + /** + * Initialize + * + * @param pProxy + * Proxy authentication ? + * @param pAddress + * Server address + * @param pPort + * Server port + * @param pProtocol + * Protocol + * @param pRealm + * Realm + * @param pScheme + * Scheme + */ + public void init(Boolean pProxy, String pAddress, int pPort, String pProtocol, String pRealm, String pScheme) { + this.iAddr = pAddress; + this.iPort = pPort; + this.iProtocol = pProtocol; + this.iRealm = pRealm; + this.iScheme = pScheme; + } + + /** + * Sets opaque + * + * @param opaque + * new Value + */ + public void setOpaque(String opaque) { + this.iOpaque = opaque; + } + + /** + * Returns opaque + * + * @return Opaque + */ + public String getOpaque() { + return this.iOpaque; + } + + /** + * Returns Qop + * + * @return Qop + */ + public String getQop() { + return this.iQop; + } + + /** + * Sets Qop + * + * @param qop + * New value + */ + public void setQop(String qop) { + this.iQop = qop; + } + + /** + * Returns nc + * + * @return nc + */ + public long getNc() { + return this.iNc; + } + + /** + * Sets nc + * + * @param nc + * New value + */ + public void setNc(long nc) { + this.iNc = nc; + } + + /** + * Sets nonce + * + * @param nonce + * New Value + */ + public void setNonce(String nonce) { + this.iNonce = nonce; + } + + /** + * Returns nonce + * + * @return nonce + */ + public String getNonce() { + return this.iNonce; + } + + /** + * Set cnonce + * + * @param cnonce + * New value + */ + public void setCnonce(String cnonce) { + this.iCnonce = cnonce; + } + + /** + * Returns cnonce + * + * @return cnonce + */ + public String getCnonce() { + return this.iCnonce; + } + + /** + * Set algorithm + * + * @param algorithm + * New value + */ + public void setAlgorithm(String algorithm) { + this.iAlgorithm = algorithm; + } + + /** + * Returns algorithm + * + * @return algorithm + */ + public String getAlgorithm() { + return this.iAlgorithm; + } + + /** + * Returns A1 + * + * @return A1 + */ + public String getA1() { + return this.iA1; + } + + /** + * Sets A1 + * + * @param A1 + * New value + */ + public void setA1(String A1) { + this.iA1 = A1; + } + + /** + * Sets response + * + * @param response + * New value + */ + public void setResponse(String response) { + this.iResponse = response; + } + + /** + * Returns response + * + * @return New value + */ + public String getResponse() { + return this.iResponse; + } + + /** + * Returns URI + * + * @return URI + */ + public String getURI() { + return this.iUri; + } + + /** + * Sets URI + * + * @param uri + * New value + */ + public void setURI(String uri) { + this.iUri = uri; + } + + /** + * Sets credentials + * + * @param credentials + * New value + */ + public void setCredentials(PasswordAuthentication credentials) { + this.iCredentials = credentials; + } + + /** + * Returns the address + * + * @return The server address + */ + public String getAddr() { + return this.iAddr; + } + + /** + * Returns the port + * + * @return The server port + */ + public int getPort() { + return this.iPort; + } + + /** + * Returns the protocol + * + * @return The protocol + */ + public String getProtocol() { + return this.iProtocol; + } + + /** + * Returns the realm + * + * @return The realm + */ + public String getRealm() { + return this.iRealm; + } + + /** + * Sets the realm + * + * @param realm + * New value + */ + public void setRealm(String realm) { + this.iRealm = realm; + } + + /** + * Returns the scheme + * + * @return The scheme + */ + public String getScheme() { + return this.iScheme; + } + + /** + * Sets the scheme + * + * @param scheme + * New value + */ + public void setScheme(String scheme) { + this.iScheme = scheme; + } + + /** + * Returns the credentials + * + * @return The credentials + */ + public PasswordAuthentication getCredentials() { + return this.iCredentials; + } + + /** + * Compares two authorization informations. + * + * @param obj + * The other authorization information + * @return true if type, realm, scheme, address, protocol and + * port of both authorization informations are equal, + * false otherwise. + */ + public boolean match(Object obj) { + if (obj == null || !(obj instanceof AuthorizationInfo)) return false; + AuthorizationInfo that = (AuthorizationInfo) obj; + + boolean type = getClass().equals(that.getClass()); + // boolean prxt = (iProxy == null || that.iProxy == null)? + // true:iProxy.equals(that.iProxy); + boolean prmpt = (this.iRealm == null || that.iRealm == null) ? true : this.iRealm.equals(that.iRealm); + boolean schm = (this.iScheme == null || that.iScheme == null) ? true : this.iScheme.equals(that.iScheme); + boolean adr = (this.iAddr == null || that.iAddr == null) ? true : this.iAddr.equals(that.iAddr); + boolean prot = (this.iProtocol == null || that.iProtocol == null) ? true : this.iProtocol.equals(that.iProtocol); + boolean prt = (this.iPort <= 0 || that.iPort <= 0) ? true : (this.iPort == that.iPort); + return (type && prmpt && schm && adr && prot && prt); + } + + /** + * Updates the authorization information according to a received challenge. + * + * @param challenge + * The received challenge + * @param authenticate + * The authenticate header field + * @param url + * The url of the CIM server + * @param requestMethod + * The HTTP request method (POST or MPOST) + * @throws NoSuchAlgorithmException + */ + public abstract void updateAuthenticationInfo( + Challenge challenge, + String authenticate, + URI url, + String requestMethod + ) + throws NoSuchAlgorithmException; + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public abstract String toString(); + + /** + * Gets the HTTP header field name for this authentication information + * + * @return The field name + */ + public abstract String getHeaderFieldName(); + + /** + * Determines if the authorization information is already sent on the very + * first http request or after the "401 Unauthorized" response + * + * @return true or false + */ + public abstract boolean isSentOnFirstRequest(); + + /** + * Determines if the connection is kept alive after the "401 Unauthorized" + * response + * + * @return true or false + */ + public abstract boolean isKeptAlive(); + + /** + * Factory method for AuthorizationInfo objects. Returns an instance of a + * subclass according to the requested type. + * + * @param pModule + * The authorization info type to be constructed + * @param pProxy + * Proxy authentication ? + * @param pAddress + * Server address + * @param pPort + * Server port + * @param pProtocol + * Protocol (http/https) + * @param pRealm + * Realm + * @param pScheme + * Scheme (e.g. Basic, Digest) + * @return An instance of a AuthorizationInfo subclass or null + * @see WBEMConfiguration#getHttpAuthenticationModule() + * @see WwwAuthInfo + * @see PegasusLocalAuthInfo + */ + public static AuthorizationInfo createAuthorizationInfo( + String pModule, + Boolean pProxy, + String pAddress, + int pPort, + String pProtocol, + String pRealm, + String pScheme + ) { + AuthorizationInfo info = createAuthorizationInfo(pModule); + + if (info != null) { + info.init(pProxy, pAddress, pPort, pProtocol, pRealm, pScheme); + } + + return info; + } + + /** + * Factory method for AuthorizationInfo objects. Returns an instance of a + * subclass according to the requested type. + * + * @param pModule + * The authorization info type to be constructed + * @return An instance of a AuthorizationInfo subclass or null + */ + public static AuthorizationInfo createAuthorizationInfo(String pModule) { + if (WwwAuthInfo.class.getName().equals(pModule)) { + return new WwwAuthInfo(); + } + if (PegasusLocalAuthInfo.class.getName().equals(pModule)) { + return new PegasusLocalAuthInfo(); + } + + try { + Class module = Class.forName(pModule); + AuthorizationInfo info = (AuthorizationInfo) module.newInstance(); + return info; + } catch (Exception e) { + LogAndTraceBroker.getBroker().trace(Level.FINER, "Exception while loading authentication module", e); + LogAndTraceBroker.getBroker().message(Messages.HTTP_AUTH_MODULE_INVALID, pModule); + } + return null; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/BASE64Encoder.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/BASE64Encoder.java similarity index 73% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/BASE64Encoder.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/BASE64Encoder.java index f728a81..2bed79c 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/BASE64Encoder.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/BASE64Encoder.java @@ -1,143 +1,201 @@ -/* - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 17970 2005-08-11 pineiro5 Logon from z/OS not possible - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.UnsupportedEncodingException; - -/** - * Class BASE64Encoder implements the BASE64 encoding algorithm - * - */ -public final class BASE64Encoder { - - private static byte BASE64_ALPHABET[] = { 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, - 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, - 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, - 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47 }; - - private BASE64Encoder() { - // no instances - } - - /** - * Encodes a given byte array - * - * @param pPlain - * The raw bytes - * @return The encoded bytes - */ - public static String encode(byte[] pPlain) { - byte encoded[]; - int totalBits = pPlain.length << 3; - int remainder = totalBits % 24; - int totalEncoded = totalBits / 24; - - int size = totalEncoded; - if (remainder > 0) size++; - - encoded = new byte[size << 2]; - - short highBits = 0; - short lowBits = 0; - short byte1 = 0; - short byte2 = 0; - short byte3 = 0; - int dest = 0; - int source = 0; - for (int i = 0; i < totalEncoded; i++) { - byte1 = (short) (pPlain[source++] & 0xFF); - byte2 = (short) (pPlain[source++] & 0xFF); - byte3 = (short) (pPlain[source++] & 0xFF); - - highBits = (short) (byte1 & 0x03); - lowBits = (short) (byte2 & 0x0F); - - short val1 = (short) (byte1 >> 2); - short val2 = (short) (byte2 >> 4); - short val3 = (short) (byte3 >> 6); - - encoded[dest++] = BASE64_ALPHABET[val1]; - encoded[dest++] = BASE64_ALPHABET[val2 | (highBits << 4)]; - encoded[dest++] = BASE64_ALPHABET[(lowBits << 2) | val3]; - encoded[dest++] = BASE64_ALPHABET[byte3 & 0x3f]; - } - - if (remainder == 8) { - byte1 = (short) (pPlain[source] & 0xFF); - highBits = (short) (byte1 & 0x03); - short val1 = (short) (byte1 >> 2); - encoded[dest++] = BASE64_ALPHABET[val1]; - encoded[dest++] = BASE64_ALPHABET[highBits << 4]; - encoded[dest++] = (byte) 61; // '=' - encoded[dest++] = (byte) 61; // '=' - } else if (remainder == 16) { - byte1 = (short) (pPlain[source++] & 0xFF); - byte2 = (short) (pPlain[source++] & 0xFF); - highBits = (short) (byte1 & 0x03); - lowBits = (short) (byte2 & 0x0F); - - short val1 = (short) (byte1 >> 2); - short val2 = (short) (byte2 >> 4); - - encoded[dest++] = BASE64_ALPHABET[val1]; - encoded[dest++] = BASE64_ALPHABET[val2 | (highBits << 4)]; - encoded[dest++] = BASE64_ALPHABET[lowBits << 2]; - encoded[dest++] = (byte) 61; // '=' - } - String res; - try { - res = new String(encoded, "ASCII"); - } catch (UnsupportedEncodingException e) { - try { - res = new String(encoded, "UTF-8"); - } catch (UnsupportedEncodingException e1) { - res = new String(encoded); - } - } - return res; - } - -} +/* + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 17970 2005-08-11 pineiro5 Logon from z/OS not possible + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.UnsupportedEncodingException; + +/** + * Class BASE64Encoder implements the BASE64 encoding algorithm + * + */ +public final class BASE64Encoder { + private static byte BASE64_ALPHABET[] = { + 65, + 66, + 67, + 68, + 69, + 70, + 71, + 72, + 73, + 74, + 75, + 76, + 77, + 78, + 79, + 80, + 81, + 82, + 83, + 84, + 85, + 86, + 87, + 88, + 89, + 90, + 97, + 98, + 99, + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110, + 111, + 112, + 113, + 114, + 115, + 116, + 117, + 118, + 119, + 120, + 121, + 122, + 48, + 49, + 50, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + 43, + 47 + }; + + private BASE64Encoder() { + // no instances + } + + /** + * Encodes a given byte array + * + * @param pPlain + * The raw bytes + * @return The encoded bytes + */ + public static String encode(byte[] pPlain) { + byte encoded[]; + int totalBits = pPlain.length << 3; + int remainder = totalBits % 24; + int totalEncoded = totalBits / 24; + + int size = totalEncoded; + if (remainder > 0) size++; + + encoded = new byte[size << 2]; + + short highBits = 0; + short lowBits = 0; + short byte1 = 0; + short byte2 = 0; + short byte3 = 0; + int dest = 0; + int source = 0; + for (int i = 0; i < totalEncoded; i++) { + byte1 = (short) (pPlain[source++] & 0xFF); + byte2 = (short) (pPlain[source++] & 0xFF); + byte3 = (short) (pPlain[source++] & 0xFF); + + highBits = (short) (byte1 & 0x03); + lowBits = (short) (byte2 & 0x0F); + + short val1 = (short) (byte1 >> 2); + short val2 = (short) (byte2 >> 4); + short val3 = (short) (byte3 >> 6); + + encoded[dest++] = BASE64_ALPHABET[val1]; + encoded[dest++] = BASE64_ALPHABET[val2 | (highBits << 4)]; + encoded[dest++] = BASE64_ALPHABET[(lowBits << 2) | val3]; + encoded[dest++] = BASE64_ALPHABET[byte3 & 0x3f]; + } + + if (remainder == 8) { + byte1 = (short) (pPlain[source] & 0xFF); + highBits = (short) (byte1 & 0x03); + short val1 = (short) (byte1 >> 2); + encoded[dest++] = BASE64_ALPHABET[val1]; + encoded[dest++] = BASE64_ALPHABET[highBits << 4]; + encoded[dest++] = (byte) 61; // '=' + encoded[dest++] = (byte) 61; // '=' + } else if (remainder == 16) { + byte1 = (short) (pPlain[source++] & 0xFF); + byte2 = (short) (pPlain[source++] & 0xFF); + highBits = (short) (byte1 & 0x03); + lowBits = (short) (byte2 & 0x0F); + + short val1 = (short) (byte1 >> 2); + short val2 = (short) (byte2 >> 4); + + encoded[dest++] = BASE64_ALPHABET[val1]; + encoded[dest++] = BASE64_ALPHABET[val2 | (highBits << 4)]; + encoded[dest++] = BASE64_ALPHABET[lowBits << 2]; + encoded[dest++] = (byte) 61; // '=' + } + String res; + try { + res = new String(encoded, "ASCII"); + } catch (UnsupportedEncodingException e) { + try { + res = new String(encoded, "UTF-8"); + } catch (UnsupportedEncodingException e1) { + res = new String(encoded); + } + } + return res; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/Challenge.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/Challenge.java similarity index 75% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/Challenge.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/Challenge.java index 41d3c59..3d1df69 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/Challenge.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/Challenge.java @@ -1,282 +1,266 @@ -/* - (C) Copyright IBM Corp. 2005, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 3596303 2013-01-04 blaschke-oss windows http response WWW-Authenticate: Negotiate fails - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Vector; - -/** - * Class Challenge holds a http authentication challenge - * - */ -public class Challenge { - - private String iScheme; - - private HttpHeader iParams; - - private Challenge() { - // hidden ctor - } - - /** - * Returns the parameters - * - * @return The parameters - */ - public HttpHeader getParams() { - return this.iParams; - } - - /** - * Returns the scheme - * - * @return The scheme - */ - public String getScheme() { - return this.iScheme; - } - - /** - * Returns the realm - * - * @return The realm - */ - public String getRealm() { - return this.iParams.getField("realm"); - } - - /** - * Parses the challenge as received from the host. RFC 2617 defines the - * following syntax for a challenge: - * - *
      -	 * challenge = auth-scheme 1*SP 1#auth-param 
      -	 * auth-scheme = token 
      -	 * auth-param = token "=" ( token | quoted-string )
      -	 * 
      - * - * @param pLine - * The challenge string - * @return The parsed challenge - * @throws HttpParseException - * If the challenge string is ill-formed - */ - public static Challenge[] parseChallenge(String pLine) throws HttpParseException { - if (pLine == null || pLine.length() == 0) throw new IllegalArgumentException( - "Invalid challenge, empty"); - pLine = pLine.trim(); - if (pLine.length() == 0) throw new IllegalArgumentException("Invalid challenge, empty"); - - Vector challenges = new Vector(); - - try { - int start = 0, end = 0; - - // Break up comma-separated list into tokens - Vector tokensBetweenCommas = new Vector(); - while ((end = indexOfOutsideQuotedString(pLine, ',', start)) > 0) { - tokensBetweenCommas.add(removeWhitespace(pLine.substring(start, end))); - start = end + 1; - } - if (start < pLine.length()) tokensBetweenCommas.add(removeWhitespace(pLine - .substring(start))); - - // Break up tokens into auth-scheme and auth-param - Vector tokens = new Vector(); - for (int i = 0; i < tokensBetweenCommas.size(); i++) { - String token = tokensBetweenCommas.elementAt(i); - - if (token.length() == 0) continue; - - start = 0; - end = indexOfOutsideQuotedString(token, ' ', start); - - if (end == -1) { - tokens.add(token); - } else { - tokens.add(token.substring(0, end)); - start = end + 1; - end = indexOfOutsideQuotedString(token, ' ', start); - - if (end == -1) { - // RFC 2617 indicates this token should be of the - // name=value format, but at least one old CIMOM (SVC - // ICAT) does not follow this rule. The Client - // effectively ignores this token, and so must continue - // to do so. - if (indexOfOutsideQuotedString(token, '=', start) == -1) { - // throw new - // HttpParseException("Invalid challenge, second token must be name=value in " - // + token); - } else { - tokens.add(token.substring(start)); - } - } else { - throw new HttpParseException("Invalid challenge, too many tokens in " - + token); - } - } - } - - Challenge challenge = new Challenge(); - challenge.iScheme = null; - challenge.iParams = new HttpHeader(); - - for (int i = 0; i < tokens.size(); i++) { - String token = tokens.elementAt(i); - - int equalSign = indexOfOutsideQuotedString(token, '=', 0); - if (equalSign == 0) { - throw new HttpParseException( - "Invalid challenge, no token before equal sign in " + token); - } else if (equalSign > 0) { - // param - if (challenge.iScheme == null) throw new HttpParseException( - "Invalid challenge, param without scheme"); - String name = token.substring(0, equalSign); - String value = token.substring(equalSign + 1); - if (value.length() == 0) { - throw new HttpParseException( - "Invalid challenge, no token after equal sign in " + token); - } else if (value.startsWith("\"") && value.endsWith("\"") && value.length() > 1) { - challenge.iParams.addField(name, value.substring(1, value.length() - 1)); - } else { - challenge.iParams.addField(name, value); - } - } else { - // scheme - if (challenge.iScheme != null) { - // new scheme - challenges.add(challenge); - - challenge = new Challenge(); - challenge.iParams = new HttpHeader(); - } - challenge.iScheme = new String(token); - } - } - - if (challenge.iScheme != null) { - challenges.add(challenge); - } - } catch (HttpParseException e) { - throw e; - } catch (Exception e) { - throw new HttpParseException("Invalid challenge, " + e.getMessage()); - } - - return challenges.toArray(new Challenge[challenges.size()]); - - } - - /* - * Removes unnecessary whitespace from a challenge such that - * " scheme name = value " becomes "scheme name=value" - */ - private static String removeWhitespace(String str) throws HttpParseException { - char inBuf[] = str.trim().toCharArray(); - StringBuilder outStr = new StringBuilder(); - boolean inQuotes = false; - - for (int inIdx = 0; inIdx < inBuf.length; inIdx++) { - if (inQuotes || !Character.isSpaceChar(inBuf[inIdx])) { - if (inBuf[inIdx] == '=' && outStr.length() == 0) throw new HttpParseException( - "Invalid challenge, no token before equal sign in " + str); - - outStr.append(inBuf[inIdx]); - } else { - // Whitespace not within quoted string - int i = skipSpaces(inBuf, inIdx + 1); - if (i >= inBuf.length) throw new HttpParseException( - "Invalid challenge, no token after space in " + str); - - if (inBuf[i] == '=') { - // auth-param, remove all whitespace up to next token - i = skipSpaces(inBuf, i + 1); - if (i >= inBuf.length) throw new HttpParseException( - "Invalid challenge, no token after equal sign in " + str); - outStr.append('='); - } else { - // another token, combine all whitespace up to next token - // into single space - outStr.append(' '); - } - outStr.append(inBuf[i]); - inIdx = i; - } - if (inBuf[inIdx] == '\"') inQuotes = !inQuotes; - } - if (inQuotes) throw new HttpParseException( - "Invalid challenge, quoted string not terminated in " + str); - return outStr.toString(); - } - - private static int skipSpaces(char[] buf, int pos) { - while (pos < buf.length && Character.isSpaceChar(buf[pos])) - pos++; - return pos; - } - - private static int indexOfOutsideQuotedString(String str, int ch, int pos) - throws HttpParseException { - int len = str.length(); - boolean inQuotes = false; - - while (pos < len) { - if (str.charAt(pos) == '\"') { - inQuotes = !inQuotes; - } else if (str.charAt(pos) == ch) { - if (!inQuotes) return pos; - } - pos++; - } - if (inQuotes) throw new HttpParseException( - "Invalid callenge, quoted string not terminated in " + str); - return -1; - } - -} +/* + (C) Copyright IBM Corp. 2005, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 3596303 2013-01-04 blaschke-oss windows http response WWW-Authenticate: Negotiate fails + */ + +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Vector; + +/** + * Class Challenge holds a http authentication challenge + * + */ +public class Challenge { + private String iScheme; + + private HttpHeader iParams; + + private Challenge() { + // hidden ctor + } + + /** + * Returns the parameters + * + * @return The parameters + */ + public HttpHeader getParams() { + return this.iParams; + } + + /** + * Returns the scheme + * + * @return The scheme + */ + public String getScheme() { + return this.iScheme; + } + + /** + * Returns the realm + * + * @return The realm + */ + public String getRealm() { + return this.iParams.getField("realm"); + } + + /** + * Parses the challenge as received from the host. RFC 2617 defines the + * following syntax for a challenge: + * + *
      +	 * challenge = auth-scheme 1*SP 1#auth-param
      +	 * auth-scheme = token
      +	 * auth-param = token "=" ( token | quoted-string )
      +	 * 
      + * + * @param pLine + * The challenge string + * @return The parsed challenge + * @throws HttpParseException + * If the challenge string is ill-formed + */ + public static Challenge[] parseChallenge(String pLine) throws HttpParseException { + if (pLine == null || pLine.length() == 0) throw new IllegalArgumentException("Invalid challenge, empty"); + pLine = pLine.trim(); + if (pLine.length() == 0) throw new IllegalArgumentException("Invalid challenge, empty"); + + Vector challenges = new Vector(); + + try { + int start = 0, end = 0; + + // Break up comma-separated list into tokens + Vector tokensBetweenCommas = new Vector(); + while ((end = indexOfOutsideQuotedString(pLine, ',', start)) > 0) { + tokensBetweenCommas.add(removeWhitespace(pLine.substring(start, end))); + start = end + 1; + } + if (start < pLine.length()) tokensBetweenCommas.add(removeWhitespace(pLine.substring(start))); + + // Break up tokens into auth-scheme and auth-param + Vector tokens = new Vector(); + for (int i = 0; i < tokensBetweenCommas.size(); i++) { + String token = tokensBetweenCommas.elementAt(i); + + if (token.length() == 0) continue; + + start = 0; + end = indexOfOutsideQuotedString(token, ' ', start); + + if (end == -1) { + tokens.add(token); + } else { + tokens.add(token.substring(0, end)); + start = end + 1; + end = indexOfOutsideQuotedString(token, ' ', start); + + if (end == -1) { + // RFC 2617 indicates this token should be of the + // name=value format, but at least one old CIMOM (SVC + // ICAT) does not follow this rule. The Client + // effectively ignores this token, and so must continue + // to do so. + if (indexOfOutsideQuotedString(token, '=', start) == -1) { + // throw new + // HttpParseException("Invalid challenge, second token must be name=value in " + // + token); + } else { + tokens.add(token.substring(start)); + } + } else { + throw new HttpParseException("Invalid challenge, too many tokens in " + token); + } + } + } + + Challenge challenge = new Challenge(); + challenge.iScheme = null; + challenge.iParams = new HttpHeader(); + + for (int i = 0; i < tokens.size(); i++) { + String token = tokens.elementAt(i); + + int equalSign = indexOfOutsideQuotedString(token, '=', 0); + if (equalSign == 0) { + throw new HttpParseException("Invalid challenge, no token before equal sign in " + token); + } else if (equalSign > 0) { + // param + if (challenge.iScheme == null) throw new HttpParseException("Invalid challenge, param without scheme"); + String name = token.substring(0, equalSign); + String value = token.substring(equalSign + 1); + if (value.length() == 0) { + throw new HttpParseException("Invalid challenge, no token after equal sign in " + token); + } else if (value.startsWith("\"") && value.endsWith("\"") && value.length() > 1) { + challenge.iParams.addField(name, value.substring(1, value.length() - 1)); + } else { + challenge.iParams.addField(name, value); + } + } else { + // scheme + if (challenge.iScheme != null) { + // new scheme + challenges.add(challenge); + + challenge = new Challenge(); + challenge.iParams = new HttpHeader(); + } + challenge.iScheme = new String(token); + } + } + + if (challenge.iScheme != null) { + challenges.add(challenge); + } + } catch (HttpParseException e) { + throw e; + } catch (Exception e) { + throw new HttpParseException("Invalid challenge, " + e.getMessage()); + } + + return challenges.toArray(new Challenge[challenges.size()]); + } + + /* + * Removes unnecessary whitespace from a challenge such that + * " scheme name = value " becomes "scheme name=value" + */ + private static String removeWhitespace(String str) throws HttpParseException { + char inBuf[] = str.trim().toCharArray(); + StringBuilder outStr = new StringBuilder(); + boolean inQuotes = false; + + for (int inIdx = 0; inIdx < inBuf.length; inIdx++) { + if (inQuotes || !Character.isSpaceChar(inBuf[inIdx])) { + if (inBuf[inIdx] == '=' && outStr.length() == 0) throw new HttpParseException( + "Invalid challenge, no token before equal sign in " + str + ); + + outStr.append(inBuf[inIdx]); + } else { + // Whitespace not within quoted string + int i = skipSpaces(inBuf, inIdx + 1); + if (i >= inBuf.length) throw new HttpParseException("Invalid challenge, no token after space in " + str); + + if (inBuf[i] == '=') { + // auth-param, remove all whitespace up to next token + i = skipSpaces(inBuf, i + 1); + if (i >= inBuf.length) throw new HttpParseException("Invalid challenge, no token after equal sign in " + str); + outStr.append('='); + } else { + // another token, combine all whitespace up to next token + // into single space + outStr.append(' '); + } + outStr.append(inBuf[i]); + inIdx = i; + } + if (inBuf[inIdx] == '\"') inQuotes = !inQuotes; + } + if (inQuotes) throw new HttpParseException("Invalid challenge, quoted string not terminated in " + str); + return outStr.toString(); + } + + private static int skipSpaces(char[] buf, int pos) { + while (pos < buf.length && Character.isSpaceChar(buf[pos])) pos++; + return pos; + } + + private static int indexOfOutsideQuotedString(String str, int ch, int pos) throws HttpParseException { + int len = str.length(); + boolean inQuotes = false; + + while (pos < len) { + if (str.charAt(pos) == '\"') { + inQuotes = !inQuotes; + } else if (str.charAt(pos) == ch) { + if (!inQuotes) return pos; + } + pos++; + } + if (inQuotes) throw new HttpParseException("Invalid callenge, quoted string not terminated in " + str); + return -1; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpClient.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpClient.java similarity index 74% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpClient.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpClient.java index 02752bf..a28b673 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpClient.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpClient.java @@ -1,1290 +1,1344 @@ -/* - HttpClient.java - - (C) Copyright IBM Corp. 2005, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 13799 2004-12-07 thschaef Fix chunking support - * 17620 2005-06-29 thschaef eliminate ASCIIPrintStream1 in import statement - * 17970 2005-08-11 pineiro5 Logon from z/OS not possible - * 1353168 2005-11-24 fiuczy Possible NullPointerExcection in HttpClient.streamFinished() - * 1422316 2006-05-15 lupusalex Disable delayed acknowledgement - * 1486379 2006-05-29 lupusalex CIM client retries twice when HTTP/1.1 401 is returned - * 1498130 2006-05-31 lupusalex Selection of xml parser on a per connection basis - * 1516244 2006-07-10 ebak GCJ support - * 1536711 2006-08-15 lupusalex NullPointerException causes client call to never return - * 1535756 2006-08-07 lupusalex Make code warning free - * 1565091 2006-10-17 ebak ssl handshake exception - * 1516242 2006-11-27 lupusalex Support of OpenPegasus local authentication - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 1604329 2006-12-18 lupusalex Fix OpenPegasus auth module - * 1620526 2007-01-08 lupusalex Socket Leak in HTTPClient.getResponseCode() - * 1627832 2007-01-08 lupuslaex Incorrect retry behaviour on HTTP 401 - * 1637546 2007-01-27 lupusalex CIMEnumerationImpl has faulty close function - * 1647148 2007-01-29 lupusalex HttpClient.resetSocket() doesn't set socket timeout - * 1647159 2007-01-29 lupusalex HttpClientPool runs out of HttpClients - * 1649595 2007-02-01 lupusalex No chunkig requested - * 1660743 2007-02-15 lupusalex SSLContext is static - * 1702832 2007-04-18 lupusalex WBEMClientCIMXL.setCustomSocketFactory() not implemented - * 1715511 2007-05-09 lupusalex FVT: Wrong HTTP header values - * 1892046 2008-02-13 blaschke-oss Basic/digest authentication problem for Japanese users - * 1931216 2008-04-01 blaschke-oss In HTTPClient need to get status before closing connection - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2372030 2008-12-01 blaschke-oss Add property to control synchronized SSL handshaking - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2714989 2009-03-26 blaschke-oss Code cleanup from redundant null check et al - * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2817962 2009-08-05 blaschke-oss socket creation connects w/o a timeout - * 2994776 2010-05-05 blaschke-oss http 401 gives CIM_ERR_FAILED instead of CIM_ERR_ACCESS_DENIED - * 2997865 2010-05-07 blaschke-oss Infinite loop in HttpClient - * 3004762 2010-06-16 blaschke-oss HTTPClient infinite loop for HTTP 407 - * 3022554 2010-06-30 blaschke-oss Flushing socket ignores skip() return code - * 3046073 2010-09-07 blaschke-oss Performance hit due to socket conn. creation with timeout - * 3195069 2011-02-28 blaschke-oss Need support to disable SSL Handshake - * 3235440 2011-03-22 blaschke-oss NullPointerException when socket factory returns null - * 3323310 2011-06-20 blaschke-oss Need the ability to override certain Global Properties - * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues - * 3444912 2011-11-29 blaschke-oss Client delay during SSL handshake - * 3492224 2012-02-23 blaschke-oss Need two different timeouts for Socket connections - * 3504304 2012-03-14 blaschke-oss Rename socket timeout variables - * 3523918 2012-05-06 blaschke-oss "java.io.IOException: Unexpected EOF" returned as HTTP 401 - * 3524050 2012-06-06 blaschke-oss Improve WWW-Authenticate in HTTPClient.java - * 3557283 2012-11-05 blaschke-oss Print full response when get EOF from CIMOM - * 3601894 2013-01-23 blaschke-oss Enhance HTTP and CIM-XML tracing - * 2619 2013-02-22 blaschke-oss Host should contain port when not 5988/5989 - * 2621 2013-02-23 blaschke-oss Not all chunked input has trailers - * 2618 2013-02-27 blaschke-oss Need to add property to disable weak cipher suites for the secure indication - * 2642 2013-05-21 blaschke-oss Seperate properties needed for cim client and listener to filter out ciphers - * 2654 2013-07-29 blaschke-oss Check jcc idle time with CIMOM keepalive timeout to avoid EOF - * 2655 2013-08-14 blaschke-oss Content-length must be ignored when Transfer-encoding present - * 2151 2013-08-20 blaschke-oss gzip compression not supported - * 2709 2013-11-13 blaschke-oss Lower the level of the EOF message to FINE - */ -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.net.SocketTimeoutException; -import java.net.URI; -import java.security.AccessController; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.security.PrivilegedAction; -import java.util.Arrays; -import java.util.Iterator; -import java.util.StringTokenizer; -import java.util.Vector; -import java.util.Map.Entry; -import java.util.logging.Level; -import java.util.zip.GZIPInputStream; - -import javax.net.SocketFactory; -import javax.net.ssl.HandshakeCompletedEvent; -import javax.net.ssl.HandshakeCompletedListener; -import javax.net.ssl.SSLSession; -import javax.net.ssl.SSLSocket; -import javax.net.ssl.SSLSocketFactory; - -import org.sentrysoftware.wbem.sblim.cimclient.WBEMConfigurationProperties; -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.HttpHeader.HeaderEntry; -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.io.ASCIIPrintStream; -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.io.BoundedInputStream; -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.io.ChunkedInputStream; -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.io.KeepAliveInputStream; -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.io.PersistentInputStream; -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.Messages; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConstants; - -/** - * Class HttpClient implements a HTTP client - * - */ -public class HttpClient implements HandshakeCompletedListener { - - private static class HostPortPair { - - String iHost; - - /** - * Ctor. - * - * @param url - * The url - */ - public HostPortPair(URI url) { - this.iHost = url.getScheme().toLowerCase() + ':' + url.getHost().toLowerCase() + ':' - + url.getPort(); - } - - @Override - public boolean equals(Object o) { - if (!(o instanceof HostPortPair)) return false; - - return this.iHost.equals(((HostPortPair) o).iHost); - } - - @Override - public int hashCode() { - return this.iHost.hashCode(); - } - - @Override - public String toString() { - return "HostPortPair=[+" + this.iHost + "]"; - } - } - - private static class GetProperty implements PrivilegedAction { - - String iPropertyName; - - GetProperty(String propertyName) { - this.iPropertyName = propertyName; - } - - public Object run() { - return System.getProperty(this.iPropertyName); - } - } - - private static String iEncoding; - - static { - try { - iEncoding = (String) AccessController.doPrivileged(new PrivilegedAction() { - - public Object run() { - return System.getProperty("file.encoding", "ISO8859_1"); - } - }); - if (!isASCIISuperset(iEncoding)) iEncoding = "ISO8859_1"; - } catch (Exception exception) { - iEncoding = "ISO8859_1"; - } - } - - /** - * Converts a byte array to a String of hex digits - * - * @param digest - * The byte array - * @return The hex string - */ - public static String convertToHexString(byte[] digest) { - char hexDigit[] = "0123456789abcdef".toCharArray(); - - StringBuffer buf = new StringBuffer(); - for (int i = 0; i < digest.length; i++) { - int b = digest[i]; - buf.append(hexDigit[(b >> 4) & 0xF]); - buf.append(hexDigit[(b) & 0xF]); - } - return buf.toString(); - } - - /** - * Returns a client from a http client pool - * - * @param url - * The url to connect to - * @param clientPool - * The client pool - * @param auth_handler - * The authentication handler to use - * @return A http client from the pool - */ - public static HttpClient getClient(URI url, HttpClientPool clientPool, - AuthorizationHandler auth_handler) { - - return clientPool.retrieveAvailableConnectionFromPool(url, auth_handler); - } - - protected static String dequote(String str) { - int len = str.length(); - if (len > 1 && str.charAt(0) == '\"' && str.charAt(len - 1) == '\"') return str.substring( - 1, len - 1); - return str; - } - - protected static void handleRsp(String authInfo, AuthorizationInfo prevAuthInfo) - throws IOException { - if (authInfo != null) { - HttpHeader params = HttpHeader.parse(authInfo); - - String nonce = params.getField("nextnonce"); - if (nonce != null) { - prevAuthInfo.setNonce(nonce); - prevAuthInfo.setNc(0); - } else { - nonce = prevAuthInfo.getNonce(); - } - String qop = params.getField("qop"); - if (qop != null) { - if (!"auth".equalsIgnoreCase(qop) && !"auth-int".equalsIgnoreCase(qop)) { - // TODO - throw new IOException( - "Authentication Digest with integrity check not supported"); - } - byte[] rspauth; - String rspauthStr = dequote(params.getField("rspauth")); - if (rspauthStr != null) { - rspauth = parseHex(rspauthStr); - - String cnonce = dequote(params.getField("cnonce")); - if (cnonce != null && !cnonce.equals(prevAuthInfo.getCnonce())) { throw new IOException( - "Digest authentication: Invalid nonce counter"); } - String ncStr = params.getField("nc"); - if (ncStr != null) { - try { - long nc = Long.parseLong(ncStr, 16); - if (nc != prevAuthInfo.getNc()) { throw new IOException(); } - } catch (Exception e) { - throw new IOException("Digest authentication: Invalid nonce counter"); - } - } - - String HA1, HA2; - MessageDigest md5; - try { - md5 = MessageDigest.getInstance("MD5"); - md5.reset(); - byte[] bytes = prevAuthInfo.getA1().getBytes("UTF-8"); - md5.update(bytes); - HA1 = convertToHexString(md5.digest()); - if ("MD5-sess".equalsIgnoreCase(params.getField("algorithm"))) { - md5.reset(); - md5.update((HA1 + ":" + nonce + ":" + cnonce).getBytes("UTF-8")); - HA1 = convertToHexString(md5.digest()); - } - - HA2 = ":" + prevAuthInfo.getURI(); - if ("auth-int".equalsIgnoreCase(qop)) { - md5.reset(); - md5.update(new byte[] {}); - HA2 += ":" + convertToHexString(md5.digest()); - } - md5.reset(); - md5.update(HA2.getBytes("UTF-8")); - HA2 = convertToHexString(md5.digest()); - - md5.reset(); - md5.update((HA1 + ":" + nonce + ":" + ncStr + ":" + cnonce + ":" + qop - + ":" + HA2).getBytes("UTF-8")); - String hsh = convertToHexString(md5.digest()); - byte[] hash = parseHex(hsh); - - if (!Arrays.equals(hash, rspauth)) throw new IOException( - "Digest Authentication failed!"); - - } catch (NoSuchAlgorithmException e1) { - throw new IOException( - "Unable to validate Authentication response: NoSuchAlgorithmException"); - } - } - } else { - // TODO compute md5 of the entity-body - } - } - } - - protected static byte[] parseHex(String hex) { - byte[] value = new byte[hex.length() >> 1]; - int n = 0; - for (int i = 0; i < value.length; i++) { - value[i] = (byte) (0xff & Integer.parseInt(hex.substring(n, n + 1), 16)); - n += 2; - } - return value; - } - - private static boolean isASCIISuperset(String charset) throws Exception { - String asciiSuperSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.!~*'();/?:@&=+$,"; - byte abyte0[] = { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, - 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, - 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, - 116, 117, 118, 119, 120, 121, 122, 45, 95, 46, 33, 126, 42, 39, 40, 41, 59, 47, 63, - 58, 64, 38, 61, 43, 36, 44 }; - byte convertedArray[] = asciiSuperSet.getBytes(charset); - return Arrays.equals(convertedArray, abyte0); - } - - private boolean iConnected = false; - - private HttpClientPool iHttpClientPool; - - private AuthorizationHandler iAuth_handler; - - private SSLSession iSession; - - private InputStream iIStream; - - private boolean iUseHttp11 = true; - - private boolean iKeepAlive = true; - - private HttpClientMethod iMethod; - - private OutputStream iOStream; - - private AuthorizationInfo iPrevAuthInfo; - - private AuthorizationInfo iPrevProxy; - - private HttpHeader iRequestHeaders = new HttpHeader(); - - private String iRequestMethod = "POST"; - - private boolean iReset = true; - - private HttpClientMethod iResponse; - - private HttpHeader iResponseHeaders = new HttpHeader(); - - private InputStream iServerInput; - - private ByteArrayOutputStream iServerOutput; - - private Socket iSocket; - - private URI iUrl; - - private long iPreviousResponseTime = -1; - - /** - * Ctor. - * - * @param url - * The url to connect to - * @param clientPool - * The associated client pool - * @param auth_handler - * The authentication handler - */ - public HttpClient(URI url, HttpClientPool clientPool, AuthorizationHandler auth_handler) { - this.iUrl = url; - this.iAuth_handler = auth_handler; - this.iHttpClientPool = clientPool; - } - - /** - * Connects to the http server - * - * @throws IOException - */ - public void connect() throws IOException { - LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - try { - this.iReset = true; - this.iResponse = null; - this.iConnected = true; - this.iServerOutput = null; - resetSocket(); - } finally { - logger.exit(); - } - } - - /** - * Disconnects the session - */ - public synchronized void disconnect() { - LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - this.iConnected = false; - if (this.iSocket != null) { - try { - this.iSocket.close(); - } catch (IOException e) { - logger.trace(Level.FINE, "Unexpected problem closing http socket", e); - } - this.iSocket = null; - this.iServerInput = null; - this.iReset = true; - this.iResponse = null; - } - logger.exit(); - } - - @Override - protected void finalize() throws Throwable { - try { - this.iSocket.close(); - } catch (IOException e) { - // bad luck - } finally { - super.finalize(); - } - } - - /** - * Returns the http header field value for a given index - * - * @param index - * The index - * @return The header field value - */ - public synchronized String getHeaderFieldValue(int index) { - - if (index < 0) throw new IllegalArgumentException(); - if (index == 0) return this.iResponse.toString(); - - Iterator> iterator = this.iResponseHeaders.iterator(); - while (iterator.hasNext() && --index >= 0) { - Entry entry = iterator.next(); - if (index == 0) return entry.getValue().toString(); - } - return null; - } - - /** - * Returns the http header field for a given name - * - * @param name - * The name - * @return The header field - */ - public synchronized String getHeaderField(String name) { - return this.iResponseHeaders.getField(name); - } - - /** - * Return the http header field name for a given index - * - * @param index - * The index - * @return The name - */ - public synchronized String getHeaderFieldName(int index) { - if (index < 0) throw new IllegalArgumentException(); - if (index == 0) return null; - - Iterator> iterator = this.iResponseHeaders.iterator(); - while (iterator.hasNext() && --index >= 0) { - Entry entry = iterator.next(); - if (index == 0) return entry.getKey().toString(); - } - return null; - } - - /** - * Returns the input stream of this http connection - * - * @return The input stream - * @throws IOException - */ - public synchronized InputStream getInputStream() throws IOException { - if (getResponseCode() < 500 && this.iResponse != null && this.iServerInput != null) return this.iServerInput; - - throw new IOException("Failed to open an input stream from server: HTTPResponse " - + getResponseCode()); - } - - /** - * Returns the output stream of this http connection - * - * @return The output stream - */ - public synchronized OutputStream getOutputStream() { - if (this.iServerOutput == null) { - this.iServerOutput = new ByteArrayOutputStream(); - } - return this.iServerOutput; - } - - /** - * Returns the request method - * - * @return The request method - */ - public String getRequestMethod() { - return this.iRequestMethod; - } - - /** - * Returns the request property for a given key - * - * @param key - * The key - * @return The property - */ - public String getRequestProperty(String key) { - return this.iRequestHeaders.getField(key); - } - - /** - * Returns the response code - * - * @return The response code - * @throws IOException - */ - public synchronized int getResponseCode() throws IOException { - LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - try { - long ResponseTime = -1; - Exception delayedException = null; - if (this.iReset && this.iResponse == null) { - boolean authFailed = false; - int IoRetry = 1; - int AuthentificationRetry = 1; - do { - logger.trace(Level.FINER, "Attempting http request (retry counters:" + IoRetry - + "/" + AuthentificationRetry + ")"); - long RequestTime = System.currentTimeMillis(); - - if (this.iPreviousResponseTime != -1) { - long time = RequestTime - this.iPreviousResponseTime; - long maxTime = this.iHttpClientPool.getConfigurationContext() - .getSocketIdleTimeout(); - if (maxTime > 0 && time > maxTime) { - logger.trace(Level.FINER, "Closing socket after " + time - + "ms of idle time"); - - if (this.iSocket != null && !this.iSocket.isClosed()) { - try { - this.iSocket.close(); - } catch (IOException e) { - logger.trace(Level.FINER, - "Exception caught while closing socket", e); - } - } - this.iSocket = null; - this.iReset = true; - this.iResponse = null; - } - } - - ResponseTime = -1; - resetSocket(); - this.iReset = false; - try { - ASCIIPrintStream out = (ASCIIPrintStream) this.iOStream; - if (out == null) throw new IOException("could not open output stream"); - - String file = this.iUrl.getPath(); - if (file == null || file.length() == 0) file = "/"; - String query = this.iUrl.getQuery(); - if (query != null) file = file + '?' + query; - - this.iMethod = new HttpClientMethod(this.iRequestMethod, this.iUrl - .getPath(), 1, this.iUseHttp11 ? 1 : 0); - logger.trace(Level.FINER, "HTTP Operation= " + this.iMethod); - - this.iMethod.write(out); - - StringBuilder hostField = new StringBuilder(this.iUrl.getHost()); - if (this.iUrl.getPort() > 0 - && ((WBEMConstants.HTTPS.equalsIgnoreCase(this.iUrl.getScheme()) && this.iUrl - .getPort() != WBEMConstants.DEFAULT_WBEM_SECURE_PORT) || (WBEMConstants.HTTP - .equalsIgnoreCase(this.iUrl.getScheme()) && this.iUrl - .getPort() != WBEMConstants.DEFAULT_WBEM_PORT))) { - hostField.append(':'); - hostField.append(this.iUrl.getPort()); - } - this.iRequestHeaders.addField("Host", hostField.toString()); - - if (this.iServerOutput != null) this.iRequestHeaders.addField( - "Content-length", "" + this.iServerOutput.size()); - else this.iRequestHeaders.addField("Content-length", "0"); - if (this.iHttpClientPool.getConfigurationContext().isHttpChunked()) { - this.iRequestHeaders.addField("TE", "trailers"); - } - - if (iUseHttp11 && !iHttpClientPool.getConfigurationContext().useKeepAliveStrictMode()) { - // AMMO-863 Systematic use of the Keep-alive - // header is not recommended with HTTP/1.1 - // And may cause issues with EMC's VAPP appliances - // so we made the header available only when - // new strict mode is disabled - logger.trace(Level.INFO, - "HTTP 1.1 protocol and 'Connection=Keep-alive' strict mode disabled, we add the header"); - iRequestHeaders.addField("Connection", "Keep-alive"); - } - - if (this.iPrevAuthInfo == null) { - AuthorizationInfo authInfo = this.iAuth_handler.getAuthorizationInfo(0); - String authenticate = this.iHttpClientPool.getConfigurationContext() - .getHttpWwwAuthenticateInfo(); - - if (authInfo.isSentOnFirstRequest()) { - this.iRequestHeaders.addField(authInfo.getHeaderFieldName(), - authInfo.toString()); - } else if (authenticate != null) { - try { - this.iPrevAuthInfo = getAuthentication(false, - this.iPrevAuthInfo, authenticate); - if (this.iPrevAuthInfo != null) { - this.iRequestHeaders.addField(this.iPrevAuthInfo - .getHeaderFieldName(), this.iPrevAuthInfo - .toString()); - } - } catch (NoSuchAlgorithmException e) { - logger.trace(Level.FINER, "Unable to find digest algorithm", e); - } catch (IllegalArgumentException e) { - logger - .trace( - Level.FINER, - WBEMConfigurationProperties.HTTP_WWW_AUTHENTICATE_INFO - + " did not contain WWW-Authenticate information", - e); - } catch (HttpParseException e) { - logger - .trace( - Level.FINER, - WBEMConfigurationProperties.HTTP_WWW_AUTHENTICATE_INFO - + " did not contain valid WWW-Authenticate information", - e); - } - } - } else { - this.iRequestHeaders.addField(this.iPrevAuthInfo.getHeaderFieldName(), - this.iPrevAuthInfo.toString()); - } - - if (this.iPrevProxy != null) this.iRequestHeaders.addField( - "Proxy-authorization", this.iPrevProxy.toString()); - - boolean isGzipped = false; - if (this.iHttpClientPool.getConfigurationContext().isGzipEncodingEnabled()) { - isGzipped = true; - this.iRequestHeaders.addField("Accept-Encoding", "gzip,identity;q=0.5"); - } - - this.iRequestHeaders.write(out); - - logger.trace(Level.FINER, "Request HTTP Headers= " + this.iRequestHeaders); - - if (out.checkError() != null) { - delayedException = out.checkError(); - logger.trace(Level.FINER, - "Exception caught while writing to the http output stream.", - delayedException); - if (this.iSocket != null && !this.iSocket.isClosed()) { - try { - this.iSocket.close(); - } catch (IOException e) { - logger.trace(Level.FINER, - "Exception caught while closing socket", e); - } - } - this.iSocket = null; - this.iReset = true; - this.iResponse = null; - --IoRetry; - continue; - } - if (this.iServerOutput != null) { - this.iServerOutput.writeTo(out); - } - out.flush(); - - // byte[] header = new byte[8]; - // istream.mark(8); - // int totalRead; - // int k; - // for (totalRead = 0; totalRead < 8; totalRead += k) { - // k = istream.read(header, totalRead, 8 - totalRead); - // if (k < 0) - // break; - // } - // - // if (header[0] != 72 // HTTP1. - // || header[1] != 84 - // || header[2] != 84 - // || header[3] != 80 - // || header[4] != 47 - // || header[5] != 49 - // || header[6] != 46 - // || totalRead != 8) { - // retry = 0; - // throw new IOException("Unexpected end of file from - // server. Header does not match HTTP header: "+new - // String(header)); - // } - // - // istream.reset(); - - this.iResponse = new HttpClientMethod(this.iIStream); - logger.trace(Level.FINER, "HTTP Response= " + this.iResponse); - ResponseTime = System.currentTimeMillis(); - - this.iResponseHeaders = new HttpHeader(this.iIStream); - logger.trace(Level.FINER, "Response HTTP Headers= " - + this.iResponseHeaders.toString()); - this.iKeepAlive = false; - if ("Keep-alive".equalsIgnoreCase(this.iResponseHeaders - .getField("Connection")) - || (this.iResponse.getMajorVersion() == 1 && this.iResponse - .getMinorVersion() == 1) - || this.iResponseHeaders.getField("Keep-alive") != null) { - this.iKeepAlive = true; - } - - this.iServerInput = new PersistentInputStream(this.iIStream); - // String keepAliveHdr = - // iResponseHeaders.getField("Keep-Alive"); - - String contentLength = this.iResponseHeaders.getField("Content-length"); - long length = -1; - try { - if (contentLength != null && contentLength.length() > 0) length = Long - .parseLong(contentLength); - } catch (Exception e) { - logger.trace(Level.FINER, - "Exception while parsing the content length of http response", - e); - } - this.iKeepAlive = (length >= 0 || this.iResponse.getStatus() == 304 || this.iResponse - .getStatus() == 204); - - if (isGzipped) { - String contentEncoding = this.iResponseHeaders - .getField("Content-Encoding"); - if (contentEncoding != null - && contentEncoding.toLowerCase().contains("gzip")) { - length = -1; // ignore Content-length - this.iServerInput = new GZIPInputStream(this.iServerInput); - } - } - - String transferEncoding = this.iResponseHeaders - .getField("Transfer-encoding"); - if (transferEncoding != null) { - length = -1; // ignore Content-length - if (transferEncoding.toLowerCase().endsWith("chunked")) { - this.iServerInput = new ChunkedInputStream(this.iServerInput, - this.iResponseHeaders.getField("Trailer"), "Response"); - this.iKeepAlive = true; - } - } - - if (length >= 0) this.iServerInput = new BoundedInputStream( - this.iServerInput, length); - - logger.trace(Level.FINER, "KeepAlive=" - + (this.iKeepAlive ? "true" : "false")); - - if (this.iKeepAlive) { - this.iServerInput = new KeepAliveInputStream(this.iServerInput, this); - } - - switch (this.iResponse.getStatus()) { - case 100: { - continue; - } - case HttpURLConnection.HTTP_OK: - String authInfo = this.iResponseHeaders - .getField("Authentication-Info"); - handleRsp(authInfo, this.iPrevAuthInfo); - - authInfo = this.iResponseHeaders.getField("Authentication-Proxy"); - handleRsp(authInfo, this.iPrevProxy); - - if (this.iServerOutput != null) this.iServerOutput = null; - - this.iPreviousResponseTime = ResponseTime; - return HttpURLConnection.HTTP_OK; - - case HttpURLConnection.HTTP_UNAUTHORIZED: - --AuthentificationRetry; - String authenticate = this.iResponseHeaders - .getField("WWW-Authenticate"); - try { - this.iPrevAuthInfo = getAuthentication(false, - this.iPrevAuthInfo, authenticate); - if (this.iPrevAuthInfo != null) { - this.iRequestHeaders.addField(this.iPrevAuthInfo - .getHeaderFieldName(), this.iPrevAuthInfo - .toString()); - } - } catch (NoSuchAlgorithmException e) { - logger.trace(Level.FINER, "Unable to find digest algorithm", e); - } catch (IllegalArgumentException e) { - logger - .trace( - Level.FINER, - "HTTP 401 response did not contain WWW-Authenticate information", - e); - } catch (HttpParseException e) { - logger - .trace( - Level.FINER, - "HTTP 401 response did not contain valid WWW-Authenticate information", - e); - } - - if (!authFailed) { - authFailed = true; - logger - .trace(Level.FINER, - "Authorization failed, retrying with authorization info."); - } - if (this.iPrevAuthInfo != null && this.iPrevAuthInfo.isKeptAlive()) { - this.iKeepAlive = true; - } - break; - case HttpURLConnection.HTTP_PROXY_AUTH: - --AuthentificationRetry; - logger.message(Messages.HTTP_PROXY_AUTH_UNSUPPORTED, this.iUrl); - - // TODO implement http proxy authentication - /* - * authenticate = - * responseHeaders.getField("Proxy-Authenticate" - * ); prevProxy = getAuthentication(true, - * prevProxy, authenticate, this); if - * (prevAuthInfo != null) - * requestHeaders.addField - * ("Proxy-Authorization", - * prevProxy.toString()); - * - * while ((total = serverInput.available()) > 0) - * { serverInput.skip(total); } break; - */ - break; - default: - int status = this.iResponse.getStatus(); - if (!this.iKeepAlive) closeConnection(); - else this.iServerInput.close(); - this.iPreviousResponseTime = ResponseTime; - return status; - } - } catch (SocketTimeoutException e) { - throw e; - } catch (IOException e) { - logger.message(Messages.HTTP_CONNECTION_FAILED, new Object[] { this.iUrl, - e.getMessage() }); - StringBuilder msg = new StringBuilder("Http connection failed "); - if (ResponseTime != -1) { - msg.append("after"); - msg.append(ResponseTime - RequestTime); - msg.append(" milliseconds"); - } else { - msg.append("before response received"); - } - if (this.iPreviousResponseTime != -1) { - msg.append(", "); - msg.append(System.currentTimeMillis() - this.iPreviousResponseTime); - msg.append(" milliseconds after previous response on same socket"); - } - logger.trace(Level.FINE, msg.toString(), e); - delayedException = e; - if (this.iSocket != null && !this.iSocket.isClosed()) { - try { - this.iSocket.close(); - } catch (IOException e2) { - logger.trace(Level.FINER, "Exception caught while closing socket", - e2); - } - } - this.iSocket = null; - this.iReset = true; - this.iResponse = null; - --IoRetry; - } - - } while (AuthentificationRetry >= 0 && IoRetry >= 0); - } - - if (this.iResponse != null) { - logger.trace(Level.FINER, "http response code=" + this.iResponse.getStatus()); - if (ResponseTime != -1) this.iPreviousResponseTime = ResponseTime; - return this.iResponse.getStatus(); - } - throw (IOException) (delayedException != null ? delayedException : new Exception( - "Unable to get response after maximum retries")); - } finally { - logger.exit(); - } - } - - /** - * Returns the response message - * - * @return The response message - */ - public String getResponseMessage() { - if (this.iResponse != null) return this.iResponse.getResponseMessage(); - return null; - } - - public void handshakeCompleted(HandshakeCompletedEvent event) { - LogAndTraceBroker.getBroker().trace(Level.FINER, "Http handshake completed."); - this.iSession = event.getSession(); - } - - /** - * Resets state - */ - public void reset() { - this.iRequestHeaders.clear(); - this.iResponseHeaders.clear(); - this.iResponse = null; - this.iReset = true; - } - - /** - * Sets the request method - * - * @param method - * The request method - */ - public void setRequestMethod(String method) { - this.iRequestMethod = method; - } - - /** - * Sets the request property - * - * @param key - * The property name - * @param value - * The value - */ - public void setRequestProperty(String key, String value) { - this.iRequestHeaders.addField(key, value); - } - - /** - * Releases the client and returns it to the pool - */ - public void streamFinished() { - streamFinished(true); - } - - /** - * Releases the client and returns it to the pool - * - * @param keep - * if true return to the pool, if false - * drop. - */ - public void streamFinished(boolean keep) { - - LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - - HostPortPair hpp = new HostPortPair(this.iUrl); - if (keep) { // TODO configurable from property file - logger.trace(Level.FINER, "Adding http client to pool (" + hpp + ")"); - this.iHttpClientPool.returnAvailableConnectionToPool(this); - } else { - logger.trace(Level.FINER, "Disconnectiong http client (" + hpp + ")"); - this.iHttpClientPool.removeConnectionFromPool(this); - disconnect(); - } - logger.exit(); - } - - /** - * Enables/Disables use of http 1.1 - * - * @param bool - * if true http 1.1 is enabled. - */ - public void useHttp11(boolean bool) { - this.iUseHttp11 = bool; - } - - /** - * Returns if a proxy is used - * - * @return true if a proxy is used - */ - public boolean usingProxy() { - // TODO Auto-generated method stub - return false; - } - - protected AuthorizationInfo getAuthentication(boolean proxy, AuthorizationInfo prevAuthInfo, - String authenticate) throws HttpParseException, NoSuchAlgorithmException { - Challenge[] challenges = Challenge.parseChallenge(authenticate); - - // AuthorizationHandler auth_handler = - // AuthorizationHandler.getInstance(); - int cntr = 0; - prevAuthInfo = null; - while (cntr < challenges.length) { - Challenge challenge = challenges[cntr]; - cntr++; - // if (challenge.getScheme().equalsIgnoreCase("Digest")) { - // HttpHeader headers = challenge.getParams(); - // String stale = headers.getField("stale"); - // } - prevAuthInfo = this.iAuth_handler.getAuthorizationInfo(this.iHttpClientPool - .getConfigurationContext().getHttpAuthenticationModule(), proxy ? Boolean.TRUE - : Boolean.FALSE, this.iUrl.getHost(), this.iUrl.getPort(), this.iUrl - .getScheme(), challenge.getRealm(), challenge.getScheme()); - - if (prevAuthInfo != null) { - prevAuthInfo.updateAuthenticationInfo(challenge, authenticate, this.iUrl, - this.iRequestMethod); - return prevAuthInfo; - } - } - return null; - } - - private void closeConnection() { - LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - if (this.iSocket != null) { - try { - this.iSocket.close(); - } catch (IOException e) { - logger.trace(Level.FINER, "Exception while closing the socket", e); - } - this.iSocket = null; - this.iServerInput = null; - // response = null; - } - logger.exit(); - } - - private String[] parseProperty(String propertyName) { - String s = (String) AccessController.doPrivileged(new GetProperty(propertyName)); - String as[]; - if (s == null || s.length() == 0) { - as = null; - } else { - Vector vector = new Vector(); - for (StringTokenizer stringtokenizer = new StringTokenizer(s, ","); stringtokenizer - .hasMoreElements(); vector.addElement(stringtokenizer.nextElement())) { - // add each token to vector - } - as = new String[vector.size()]; - for (int i1 = 0; i1 < as.length; i1++) - as[i1] = (String) vector.elementAt(i1); - } - return as; - } - - private void resetSocket() throws IOException { - LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - if (!this.iKeepAlive) { - logger.trace(Level.FINER, "KeepAlive=false, closing http connection..."); - closeConnection(); - } - - int httpTimeout = this.iHttpClientPool.getConfigurationContext().getHttpTimeout(); - logger.trace(Level.FINER, "Setting http timeout=" + httpTimeout); - - if (this.iSocket == null) { - // Determine whether we need to connect with a timeout or not - boolean socketConnectWithTimeout = this.iHttpClientPool.getConfigurationContext() - .socketConnectWithTimeout(); - logger.trace(Level.FINER, "Socket=null, creating http socket " - + (socketConnectWithTimeout ? "with" : "without") + " timeout."); - - // On Java 5+ InetSocketAddress(String,int) constructor will call - // any security manager's checkConnect method - if (!socketConnectWithTimeout) { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkConnect(this.iUrl.getHost(), this.iUrl.getPort()); - } - } - - SocketFactory factory = this.iHttpClientPool.getConfigurationContext() - .getCustomSocketFactory(); - if (factory == null) { - factory = HttpSocketFactory - .getInstance() - .getClientSocketFactory( - WBEMConstants.HTTPS.equalsIgnoreCase(this.iUrl.getScheme()) ? this.iHttpClientPool - .getSslContext() - : null); - if (factory == null) { - logger.message(Messages.HTTP_NO_SOCKET_FACTORY, this.iUrl.getScheme()); - throw new IllegalStateException("Unable to load socket factory:" - + this.iUrl.getScheme()); - } - } - logger.trace(Level.FINER, "Creating new http for url " + this.iUrl.toString()); - if (socketConnectWithTimeout) { - int connectTimeout = this.iHttpClientPool.getConfigurationContext() - .getSocketConnectTimeout(); - logger.trace(Level.FINER, "Setting socket connect timeout=" + connectTimeout); - - if (factory instanceof SSLSocketFactory) { - Socket sock = new Socket(); - sock.connect(new InetSocketAddress(this.iUrl.getHost(), this.iUrl.getPort()), - connectTimeout); - this.iSocket = ((SSLSocketFactory) factory).createSocket(sock, this.iUrl - .getHost(), this.iUrl.getPort(), true); - - } else { - this.iSocket = factory.createSocket(); - if (this.iSocket != null) this.iSocket.connect(new InetSocketAddress(this.iUrl - .getHost(), this.iUrl.getPort()), connectTimeout); - } - } else { - this.iSocket = factory.createSocket(this.iUrl.getHost(), this.iUrl.getPort()); - } - if (this.iSocket == null) { - logger.trace(Level.WARNING, "Socket factory " + factory.getClass().getName() - + " returned null socket"); - throw new IOException("Socket factory did not create socket"); - } - - this.iPreviousResponseTime = -1; - this.iSocket.setTcpNoDelay(true); - this.iSocket.setKeepAlive(true); - this.iSocket.setSoTimeout(httpTimeout); - - if (this.iSocket instanceof SSLSocket) { - // Determine whether we need to perform SSL handshake or not - boolean performHandshake = this.iHttpClientPool.getConfigurationContext() - .performSslHandshake(); - logger.trace(Level.FINER, "SSL socket created, handshake " - + (performHandshake ? "will" : "will not") + " be performed."); - - if (performHandshake) { - SSLSocket sk = (SSLSocket) this.iSocket; - - String protocols[] = parseProperty("https.protocols"); - if (protocols != null) { - logger.trace(Level.FINER, - "Setting SSLSocket.setEnabledProtocols() from \"https.protocols\"=" - + String.valueOf(Arrays.asList(protocols))); - sk.setEnabledProtocols(protocols); - } - - String ciphersuites[] = parseProperty("https.cipherSuites"); - if (ciphersuites != null) { - logger.trace(Level.FINER, - "Setting SSLSocket.setEnableCipheSuites() from \"https.cipherSuites\"=" - + String.valueOf(Arrays.asList(ciphersuites))); - sk.setEnabledCipherSuites(ciphersuites); - } - - String disableCipherSuites = this.iHttpClientPool.getConfigurationContext() - .getSslClientCipherSuitesToDisable(); - if (disableCipherSuites != null) { - sk.setEnabledCipherSuites(this.iHttpClientPool.getUpdatedCipherSuites(sk - .getEnabledCipherSuites(), disableCipherSuites)); - } - - // Determine whether we need to perform synchronized SSL - // handshake or not - boolean synchronizedHandshake = this.iHttpClientPool.getConfigurationContext() - .synchronizedSslHandshake(); - logger.trace(Level.FINER, "Starting " - + (synchronizedHandshake ? "synchronized" : "unsynchronized") - + " http handshake."); - - sk.addHandshakeCompletedListener(this); - if (synchronizedHandshake) { - synchronized (SSLSocket.class) { - sk.startHandshake(); - } - } else { - sk.startHandshake(); - } - } - } - - this.iIStream = new BufferedInputStream(this.iSocket.getInputStream()); - this.iOStream = new ASCIIPrintStream(new BufferedOutputStream(this.iSocket - .getOutputStream(), 1024), false, iEncoding); - this.iServerInput = null; - } else { - if (this.iServerInput != null && !(this.iServerInput instanceof KeepAliveInputStream)) { - logger.trace(Level.FINER, "Socket!=null, flushing the stream..."); - long totalBytes = 0; - long total; - while ((total = this.iServerInput.available()) > 0) { - total = this.iServerInput.skip(total); - if (total >= 0) totalBytes += total; - } - logger.trace(Level.FINER, "total bytes on the stream=" + totalBytes); - } - this.iSocket.setSoTimeout(httpTimeout); - } - } - - /** - * Returns connected - * - * @return The value of connected. - */ - public boolean isConnected() { - return this.iConnected; - } - - @Override - public String toString() { - StringBuffer result = new StringBuffer(); - result.append('['); - result.append("URI="); - result.append(this.iUrl); - result.append(", "); - result.append(this.iConnected ? "connected" : "not connected"); - result.append(", "); - result.append(this.iKeepAlive ? "kept alive" : "not kept alive"); - result.append(", "); - result.append(this.iUseHttp11 ? "HTTP 1.1" : "HTTP 1.0"); - result.append(", "); - result.append("Method="); - result.append(this.iMethod); - result.append(", "); - result.append("Request Method="); - result.append(this.iRequestMethod); - result.append(", "); - result.append("Protocol="); - result.append(this.iSession != null ? this.iSession.getProtocol() : "http"); - result.append(", "); - result.append("CipherSuite="); - result.append(this.iSession != null ? this.iSession.getCipherSuite() : "n/a"); - result.append(']'); - return result.toString(); - } -} +/* + HttpClient.java + + (C) Copyright IBM Corp. 2005, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 13799 2004-12-07 thschaef Fix chunking support + * 17620 2005-06-29 thschaef eliminate ASCIIPrintStream1 in import statement + * 17970 2005-08-11 pineiro5 Logon from z/OS not possible + * 1353168 2005-11-24 fiuczy Possible NullPointerExcection in HttpClient.streamFinished() + * 1422316 2006-05-15 lupusalex Disable delayed acknowledgement + * 1486379 2006-05-29 lupusalex CIM client retries twice when HTTP/1.1 401 is returned + * 1498130 2006-05-31 lupusalex Selection of xml parser on a per connection basis + * 1516244 2006-07-10 ebak GCJ support + * 1536711 2006-08-15 lupusalex NullPointerException causes client call to never return + * 1535756 2006-08-07 lupusalex Make code warning free + * 1565091 2006-10-17 ebak ssl handshake exception + * 1516242 2006-11-27 lupusalex Support of OpenPegasus local authentication + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 1604329 2006-12-18 lupusalex Fix OpenPegasus auth module + * 1620526 2007-01-08 lupusalex Socket Leak in HTTPClient.getResponseCode() + * 1627832 2007-01-08 lupuslaex Incorrect retry behaviour on HTTP 401 + * 1637546 2007-01-27 lupusalex CIMEnumerationImpl has faulty close function + * 1647148 2007-01-29 lupusalex HttpClient.resetSocket() doesn't set socket timeout + * 1647159 2007-01-29 lupusalex HttpClientPool runs out of HttpClients + * 1649595 2007-02-01 lupusalex No chunkig requested + * 1660743 2007-02-15 lupusalex SSLContext is static + * 1702832 2007-04-18 lupusalex WBEMClientCIMXL.setCustomSocketFactory() not implemented + * 1715511 2007-05-09 lupusalex FVT: Wrong HTTP header values + * 1892046 2008-02-13 blaschke-oss Basic/digest authentication problem for Japanese users + * 1931216 2008-04-01 blaschke-oss In HTTPClient need to get status before closing connection + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2372030 2008-12-01 blaschke-oss Add property to control synchronized SSL handshaking + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2714989 2009-03-26 blaschke-oss Code cleanup from redundant null check et al + * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2817962 2009-08-05 blaschke-oss socket creation connects w/o a timeout + * 2994776 2010-05-05 blaschke-oss http 401 gives CIM_ERR_FAILED instead of CIM_ERR_ACCESS_DENIED + * 2997865 2010-05-07 blaschke-oss Infinite loop in HttpClient + * 3004762 2010-06-16 blaschke-oss HTTPClient infinite loop for HTTP 407 + * 3022554 2010-06-30 blaschke-oss Flushing socket ignores skip() return code + * 3046073 2010-09-07 blaschke-oss Performance hit due to socket conn. creation with timeout + * 3195069 2011-02-28 blaschke-oss Need support to disable SSL Handshake + * 3235440 2011-03-22 blaschke-oss NullPointerException when socket factory returns null + * 3323310 2011-06-20 blaschke-oss Need the ability to override certain Global Properties + * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues + * 3444912 2011-11-29 blaschke-oss Client delay during SSL handshake + * 3492224 2012-02-23 blaschke-oss Need two different timeouts for Socket connections + * 3504304 2012-03-14 blaschke-oss Rename socket timeout variables + * 3523918 2012-05-06 blaschke-oss "java.io.IOException: Unexpected EOF" returned as HTTP 401 + * 3524050 2012-06-06 blaschke-oss Improve WWW-Authenticate in HTTPClient.java + * 3557283 2012-11-05 blaschke-oss Print full response when get EOF from CIMOM + * 3601894 2013-01-23 blaschke-oss Enhance HTTP and CIM-XML tracing + * 2619 2013-02-22 blaschke-oss Host should contain port when not 5988/5989 + * 2621 2013-02-23 blaschke-oss Not all chunked input has trailers + * 2618 2013-02-27 blaschke-oss Need to add property to disable weak cipher suites for the secure indication + * 2642 2013-05-21 blaschke-oss Seperate properties needed for cim client and listener to filter out ciphers + * 2654 2013-07-29 blaschke-oss Check jcc idle time with CIMOM keepalive timeout to avoid EOF + * 2655 2013-08-14 blaschke-oss Content-length must be ignored when Transfer-encoding present + * 2151 2013-08-20 blaschke-oss gzip compression not supported + * 2709 2013-11-13 blaschke-oss Lower the level of the EOF message to FINE + */ +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.net.SocketTimeoutException; +import java.net.URI; +import java.security.AccessController; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.security.PrivilegedAction; +import java.util.Arrays; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.StringTokenizer; +import java.util.Vector; +import java.util.logging.Level; +import java.util.zip.GZIPInputStream; +import javax.net.SocketFactory; +import javax.net.ssl.HandshakeCompletedEvent; +import javax.net.ssl.HandshakeCompletedListener; +import javax.net.ssl.SSLSession; +import javax.net.ssl.SSLSocket; +import javax.net.ssl.SSLSocketFactory; +import org.metricshub.wbem.sblim.cimclient.WBEMConfigurationProperties; +import org.metricshub.wbem.sblim.cimclient.internal.http.HttpHeader.HeaderEntry; +import org.metricshub.wbem.sblim.cimclient.internal.http.io.ASCIIPrintStream; +import org.metricshub.wbem.sblim.cimclient.internal.http.io.BoundedInputStream; +import org.metricshub.wbem.sblim.cimclient.internal.http.io.ChunkedInputStream; +import org.metricshub.wbem.sblim.cimclient.internal.http.io.KeepAliveInputStream; +import org.metricshub.wbem.sblim.cimclient.internal.http.io.PersistentInputStream; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; +import org.metricshub.wbem.sblim.cimclient.internal.logging.Messages; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConstants; + +/** + * Class HttpClient implements a HTTP client + * + */ +public class HttpClient implements HandshakeCompletedListener { + + private static class HostPortPair { + String iHost; + + /** + * Ctor. + * + * @param url + * The url + */ + public HostPortPair(URI url) { + this.iHost = url.getScheme().toLowerCase() + ':' + url.getHost().toLowerCase() + ':' + url.getPort(); + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof HostPortPair)) return false; + + return this.iHost.equals(((HostPortPair) o).iHost); + } + + @Override + public int hashCode() { + return this.iHost.hashCode(); + } + + @Override + public String toString() { + return "HostPortPair=[+" + this.iHost + "]"; + } + } + + private static class GetProperty implements PrivilegedAction { + String iPropertyName; + + GetProperty(String propertyName) { + this.iPropertyName = propertyName; + } + + public Object run() { + return System.getProperty(this.iPropertyName); + } + } + + private static String iEncoding; + + static { + try { + iEncoding = + (String) AccessController.doPrivileged( + new PrivilegedAction() { + + public Object run() { + return System.getProperty("file.encoding", "ISO8859_1"); + } + } + ); + if (!isASCIISuperset(iEncoding)) iEncoding = "ISO8859_1"; + } catch (Exception exception) { + iEncoding = "ISO8859_1"; + } + } + + /** + * Converts a byte array to a String of hex digits + * + * @param digest + * The byte array + * @return The hex string + */ + public static String convertToHexString(byte[] digest) { + char hexDigit[] = "0123456789abcdef".toCharArray(); + + StringBuffer buf = new StringBuffer(); + for (int i = 0; i < digest.length; i++) { + int b = digest[i]; + buf.append(hexDigit[(b >> 4) & 0xF]); + buf.append(hexDigit[(b) & 0xF]); + } + return buf.toString(); + } + + /** + * Returns a client from a http client pool + * + * @param url + * The url to connect to + * @param clientPool + * The client pool + * @param auth_handler + * The authentication handler to use + * @return A http client from the pool + */ + public static HttpClient getClient(URI url, HttpClientPool clientPool, AuthorizationHandler auth_handler) { + return clientPool.retrieveAvailableConnectionFromPool(url, auth_handler); + } + + protected static String dequote(String str) { + int len = str.length(); + if (len > 1 && str.charAt(0) == '\"' && str.charAt(len - 1) == '\"') return str.substring(1, len - 1); + return str; + } + + protected static void handleRsp(String authInfo, AuthorizationInfo prevAuthInfo) throws IOException { + if (authInfo != null) { + HttpHeader params = HttpHeader.parse(authInfo); + + String nonce = params.getField("nextnonce"); + if (nonce != null) { + prevAuthInfo.setNonce(nonce); + prevAuthInfo.setNc(0); + } else { + nonce = prevAuthInfo.getNonce(); + } + String qop = params.getField("qop"); + if (qop != null) { + if (!"auth".equalsIgnoreCase(qop) && !"auth-int".equalsIgnoreCase(qop)) { + // TODO + throw new IOException("Authentication Digest with integrity check not supported"); + } + byte[] rspauth; + String rspauthStr = dequote(params.getField("rspauth")); + if (rspauthStr != null) { + rspauth = parseHex(rspauthStr); + + String cnonce = dequote(params.getField("cnonce")); + if (cnonce != null && !cnonce.equals(prevAuthInfo.getCnonce())) { + throw new IOException("Digest authentication: Invalid nonce counter"); + } + String ncStr = params.getField("nc"); + if (ncStr != null) { + try { + long nc = Long.parseLong(ncStr, 16); + if (nc != prevAuthInfo.getNc()) { + throw new IOException(); + } + } catch (Exception e) { + throw new IOException("Digest authentication: Invalid nonce counter"); + } + } + + String HA1, HA2; + MessageDigest md5; + try { + md5 = MessageDigest.getInstance("MD5"); + md5.reset(); + byte[] bytes = prevAuthInfo.getA1().getBytes("UTF-8"); + md5.update(bytes); + HA1 = convertToHexString(md5.digest()); + if ("MD5-sess".equalsIgnoreCase(params.getField("algorithm"))) { + md5.reset(); + md5.update((HA1 + ":" + nonce + ":" + cnonce).getBytes("UTF-8")); + HA1 = convertToHexString(md5.digest()); + } + + HA2 = ":" + prevAuthInfo.getURI(); + if ("auth-int".equalsIgnoreCase(qop)) { + md5.reset(); + md5.update(new byte[] {}); + HA2 += ":" + convertToHexString(md5.digest()); + } + md5.reset(); + md5.update(HA2.getBytes("UTF-8")); + HA2 = convertToHexString(md5.digest()); + + md5.reset(); + md5.update((HA1 + ":" + nonce + ":" + ncStr + ":" + cnonce + ":" + qop + ":" + HA2).getBytes("UTF-8")); + String hsh = convertToHexString(md5.digest()); + byte[] hash = parseHex(hsh); + + if (!Arrays.equals(hash, rspauth)) throw new IOException("Digest Authentication failed!"); + } catch (NoSuchAlgorithmException e1) { + throw new IOException("Unable to validate Authentication response: NoSuchAlgorithmException"); + } + } + } else { + // TODO compute md5 of the entity-body + } + } + } + + protected static byte[] parseHex(String hex) { + byte[] value = new byte[hex.length() >> 1]; + int n = 0; + for (int i = 0; i < value.length; i++) { + value[i] = (byte) (0xff & Integer.parseInt(hex.substring(n, n + 1), 16)); + n += 2; + } + return value; + } + + private static boolean isASCIISuperset(String charset) throws Exception { + String asciiSuperSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.!~*'();/?:@&=+$,"; + byte abyte0[] = { + 48, + 49, + 50, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + 65, + 66, + 67, + 68, + 69, + 70, + 71, + 72, + 73, + 74, + 75, + 76, + 77, + 78, + 79, + 80, + 81, + 82, + 83, + 84, + 85, + 86, + 87, + 88, + 89, + 90, + 97, + 98, + 99, + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110, + 111, + 112, + 113, + 114, + 115, + 116, + 117, + 118, + 119, + 120, + 121, + 122, + 45, + 95, + 46, + 33, + 126, + 42, + 39, + 40, + 41, + 59, + 47, + 63, + 58, + 64, + 38, + 61, + 43, + 36, + 44 + }; + byte convertedArray[] = asciiSuperSet.getBytes(charset); + return Arrays.equals(convertedArray, abyte0); + } + + private boolean iConnected = false; + + private HttpClientPool iHttpClientPool; + + private AuthorizationHandler iAuth_handler; + + private SSLSession iSession; + + private InputStream iIStream; + + private boolean iUseHttp11 = true; + + private boolean iKeepAlive = true; + + private HttpClientMethod iMethod; + + private OutputStream iOStream; + + private AuthorizationInfo iPrevAuthInfo; + + private AuthorizationInfo iPrevProxy; + + private HttpHeader iRequestHeaders = new HttpHeader(); + + private String iRequestMethod = "POST"; + + private boolean iReset = true; + + private HttpClientMethod iResponse; + + private HttpHeader iResponseHeaders = new HttpHeader(); + + private InputStream iServerInput; + + private ByteArrayOutputStream iServerOutput; + + private Socket iSocket; + + private URI iUrl; + + private long iPreviousResponseTime = -1; + + /** + * Ctor. + * + * @param url + * The url to connect to + * @param clientPool + * The associated client pool + * @param auth_handler + * The authentication handler + */ + public HttpClient(URI url, HttpClientPool clientPool, AuthorizationHandler auth_handler) { + this.iUrl = url; + this.iAuth_handler = auth_handler; + this.iHttpClientPool = clientPool; + } + + /** + * Connects to the http server + * + * @throws IOException + */ + public void connect() throws IOException { + LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + try { + this.iReset = true; + this.iResponse = null; + this.iConnected = true; + this.iServerOutput = null; + resetSocket(); + } finally { + logger.exit(); + } + } + + /** + * Disconnects the session + */ + public synchronized void disconnect() { + LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + this.iConnected = false; + if (this.iSocket != null) { + try { + this.iSocket.close(); + } catch (IOException e) { + logger.trace(Level.FINE, "Unexpected problem closing http socket", e); + } + this.iSocket = null; + this.iServerInput = null; + this.iReset = true; + this.iResponse = null; + } + logger.exit(); + } + + @Override + protected void finalize() throws Throwable { + try { + this.iSocket.close(); + } catch (IOException e) { + // bad luck + } finally { + super.finalize(); + } + } + + /** + * Returns the http header field value for a given index + * + * @param index + * The index + * @return The header field value + */ + public synchronized String getHeaderFieldValue(int index) { + if (index < 0) throw new IllegalArgumentException(); + if (index == 0) return this.iResponse.toString(); + + Iterator> iterator = this.iResponseHeaders.iterator(); + while (iterator.hasNext() && --index >= 0) { + Entry entry = iterator.next(); + if (index == 0) return entry.getValue().toString(); + } + return null; + } + + /** + * Returns the http header field for a given name + * + * @param name + * The name + * @return The header field + */ + public synchronized String getHeaderField(String name) { + return this.iResponseHeaders.getField(name); + } + + /** + * Return the http header field name for a given index + * + * @param index + * The index + * @return The name + */ + public synchronized String getHeaderFieldName(int index) { + if (index < 0) throw new IllegalArgumentException(); + if (index == 0) return null; + + Iterator> iterator = this.iResponseHeaders.iterator(); + while (iterator.hasNext() && --index >= 0) { + Entry entry = iterator.next(); + if (index == 0) return entry.getKey().toString(); + } + return null; + } + + /** + * Returns the input stream of this http connection + * + * @return The input stream + * @throws IOException + */ + public synchronized InputStream getInputStream() throws IOException { + if (getResponseCode() < 500 && this.iResponse != null && this.iServerInput != null) return this.iServerInput; + + throw new IOException("Failed to open an input stream from server: HTTPResponse " + getResponseCode()); + } + + /** + * Returns the output stream of this http connection + * + * @return The output stream + */ + public synchronized OutputStream getOutputStream() { + if (this.iServerOutput == null) { + this.iServerOutput = new ByteArrayOutputStream(); + } + return this.iServerOutput; + } + + /** + * Returns the request method + * + * @return The request method + */ + public String getRequestMethod() { + return this.iRequestMethod; + } + + /** + * Returns the request property for a given key + * + * @param key + * The key + * @return The property + */ + public String getRequestProperty(String key) { + return this.iRequestHeaders.getField(key); + } + + /** + * Returns the response code + * + * @return The response code + * @throws IOException + */ + public synchronized int getResponseCode() throws IOException { + LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + try { + long ResponseTime = -1; + Exception delayedException = null; + if (this.iReset && this.iResponse == null) { + boolean authFailed = false; + int IoRetry = 1; + int AuthentificationRetry = 1; + do { + logger.trace( + Level.FINER, + "Attempting http request (retry counters:" + IoRetry + "/" + AuthentificationRetry + ")" + ); + long RequestTime = System.currentTimeMillis(); + + if (this.iPreviousResponseTime != -1) { + long time = RequestTime - this.iPreviousResponseTime; + long maxTime = this.iHttpClientPool.getConfigurationContext().getSocketIdleTimeout(); + if (maxTime > 0 && time > maxTime) { + logger.trace(Level.FINER, "Closing socket after " + time + "ms of idle time"); + + if (this.iSocket != null && !this.iSocket.isClosed()) { + try { + this.iSocket.close(); + } catch (IOException e) { + logger.trace(Level.FINER, "Exception caught while closing socket", e); + } + } + this.iSocket = null; + this.iReset = true; + this.iResponse = null; + } + } + + ResponseTime = -1; + resetSocket(); + this.iReset = false; + try { + ASCIIPrintStream out = (ASCIIPrintStream) this.iOStream; + if (out == null) throw new IOException("could not open output stream"); + + String file = this.iUrl.getPath(); + if (file == null || file.length() == 0) file = "/"; + String query = this.iUrl.getQuery(); + if (query != null) file = file + '?' + query; + + this.iMethod = new HttpClientMethod(this.iRequestMethod, this.iUrl.getPath(), 1, this.iUseHttp11 ? 1 : 0); + logger.trace(Level.FINER, "HTTP Operation= " + this.iMethod); + + this.iMethod.write(out); + + StringBuilder hostField = new StringBuilder(this.iUrl.getHost()); + if ( + this.iUrl.getPort() > 0 && + ( + ( + WBEMConstants.HTTPS.equalsIgnoreCase(this.iUrl.getScheme()) && + this.iUrl.getPort() != WBEMConstants.DEFAULT_WBEM_SECURE_PORT + ) || + ( + WBEMConstants.HTTP.equalsIgnoreCase(this.iUrl.getScheme()) && + this.iUrl.getPort() != WBEMConstants.DEFAULT_WBEM_PORT + ) + ) + ) { + hostField.append(':'); + hostField.append(this.iUrl.getPort()); + } + this.iRequestHeaders.addField("Host", hostField.toString()); + + if (this.iServerOutput != null) this.iRequestHeaders.addField( + "Content-length", + "" + this.iServerOutput.size() + ); else this.iRequestHeaders.addField("Content-length", "0"); + if (this.iHttpClientPool.getConfigurationContext().isHttpChunked()) { + this.iRequestHeaders.addField("TE", "trailers"); + } + + if (iUseHttp11 && !iHttpClientPool.getConfigurationContext().useKeepAliveStrictMode()) { + // AMMO-863 Systematic use of the Keep-alive + // header is not recommended with HTTP/1.1 + // And may cause issues with EMC's VAPP appliances + // so we made the header available only when + // new strict mode is disabled + logger.trace( + Level.INFO, + "HTTP 1.1 protocol and 'Connection=Keep-alive' strict mode disabled, we add the header" + ); + iRequestHeaders.addField("Connection", "Keep-alive"); + } + + if (this.iPrevAuthInfo == null) { + AuthorizationInfo authInfo = this.iAuth_handler.getAuthorizationInfo(0); + String authenticate = this.iHttpClientPool.getConfigurationContext().getHttpWwwAuthenticateInfo(); + + if (authInfo.isSentOnFirstRequest()) { + this.iRequestHeaders.addField(authInfo.getHeaderFieldName(), authInfo.toString()); + } else if (authenticate != null) { + try { + this.iPrevAuthInfo = getAuthentication(false, this.iPrevAuthInfo, authenticate); + if (this.iPrevAuthInfo != null) { + this.iRequestHeaders.addField( + this.iPrevAuthInfo.getHeaderFieldName(), + this.iPrevAuthInfo.toString() + ); + } + } catch (NoSuchAlgorithmException e) { + logger.trace(Level.FINER, "Unable to find digest algorithm", e); + } catch (IllegalArgumentException e) { + logger.trace( + Level.FINER, + WBEMConfigurationProperties.HTTP_WWW_AUTHENTICATE_INFO + + " did not contain WWW-Authenticate information", + e + ); + } catch (HttpParseException e) { + logger.trace( + Level.FINER, + WBEMConfigurationProperties.HTTP_WWW_AUTHENTICATE_INFO + + " did not contain valid WWW-Authenticate information", + e + ); + } + } + } else { + this.iRequestHeaders.addField(this.iPrevAuthInfo.getHeaderFieldName(), this.iPrevAuthInfo.toString()); + } + + if (this.iPrevProxy != null) this.iRequestHeaders.addField( + "Proxy-authorization", + this.iPrevProxy.toString() + ); + + boolean isGzipped = false; + if (this.iHttpClientPool.getConfigurationContext().isGzipEncodingEnabled()) { + isGzipped = true; + this.iRequestHeaders.addField("Accept-Encoding", "gzip,identity;q=0.5"); + } + + this.iRequestHeaders.write(out); + + logger.trace(Level.FINER, "Request HTTP Headers= " + this.iRequestHeaders); + + if (out.checkError() != null) { + delayedException = out.checkError(); + logger.trace(Level.FINER, "Exception caught while writing to the http output stream.", delayedException); + if (this.iSocket != null && !this.iSocket.isClosed()) { + try { + this.iSocket.close(); + } catch (IOException e) { + logger.trace(Level.FINER, "Exception caught while closing socket", e); + } + } + this.iSocket = null; + this.iReset = true; + this.iResponse = null; + --IoRetry; + continue; + } + if (this.iServerOutput != null) { + this.iServerOutput.writeTo(out); + } + out.flush(); + + // byte[] header = new byte[8]; + // istream.mark(8); + // int totalRead; + // int k; + // for (totalRead = 0; totalRead < 8; totalRead += k) { + // k = istream.read(header, totalRead, 8 - totalRead); + // if (k < 0) + // break; + // } + // + // if (header[0] != 72 // HTTP1. + // || header[1] != 84 + // || header[2] != 84 + // || header[3] != 80 + // || header[4] != 47 + // || header[5] != 49 + // || header[6] != 46 + // || totalRead != 8) { + // retry = 0; + // throw new IOException("Unexpected end of file from + // server. Header does not match HTTP header: "+new + // String(header)); + // } + // + // istream.reset(); + + this.iResponse = new HttpClientMethod(this.iIStream); + logger.trace(Level.FINER, "HTTP Response= " + this.iResponse); + ResponseTime = System.currentTimeMillis(); + + this.iResponseHeaders = new HttpHeader(this.iIStream); + logger.trace(Level.FINER, "Response HTTP Headers= " + this.iResponseHeaders.toString()); + this.iKeepAlive = false; + if ( + "Keep-alive".equalsIgnoreCase(this.iResponseHeaders.getField("Connection")) || + (this.iResponse.getMajorVersion() == 1 && this.iResponse.getMinorVersion() == 1) || + this.iResponseHeaders.getField("Keep-alive") != null + ) { + this.iKeepAlive = true; + } + + this.iServerInput = new PersistentInputStream(this.iIStream); + // String keepAliveHdr = + // iResponseHeaders.getField("Keep-Alive"); + + String contentLength = this.iResponseHeaders.getField("Content-length"); + long length = -1; + try { + if (contentLength != null && contentLength.length() > 0) length = Long.parseLong(contentLength); + } catch (Exception e) { + logger.trace(Level.FINER, "Exception while parsing the content length of http response", e); + } + this.iKeepAlive = (length >= 0 || this.iResponse.getStatus() == 304 || this.iResponse.getStatus() == 204); + + if (isGzipped) { + String contentEncoding = this.iResponseHeaders.getField("Content-Encoding"); + if (contentEncoding != null && contentEncoding.toLowerCase().contains("gzip")) { + length = -1; // ignore Content-length + this.iServerInput = new GZIPInputStream(this.iServerInput); + } + } + + String transferEncoding = this.iResponseHeaders.getField("Transfer-encoding"); + if (transferEncoding != null) { + length = -1; // ignore Content-length + if (transferEncoding.toLowerCase().endsWith("chunked")) { + this.iServerInput = + new ChunkedInputStream(this.iServerInput, this.iResponseHeaders.getField("Trailer"), "Response"); + this.iKeepAlive = true; + } + } + + if (length >= 0) this.iServerInput = new BoundedInputStream(this.iServerInput, length); + + logger.trace(Level.FINER, "KeepAlive=" + (this.iKeepAlive ? "true" : "false")); + + if (this.iKeepAlive) { + this.iServerInput = new KeepAliveInputStream(this.iServerInput, this); + } + + switch (this.iResponse.getStatus()) { + case 100: { + continue; + } + case HttpURLConnection.HTTP_OK: + String authInfo = this.iResponseHeaders.getField("Authentication-Info"); + handleRsp(authInfo, this.iPrevAuthInfo); + + authInfo = this.iResponseHeaders.getField("Authentication-Proxy"); + handleRsp(authInfo, this.iPrevProxy); + + if (this.iServerOutput != null) this.iServerOutput = null; + + this.iPreviousResponseTime = ResponseTime; + return HttpURLConnection.HTTP_OK; + case HttpURLConnection.HTTP_UNAUTHORIZED: + --AuthentificationRetry; + String authenticate = this.iResponseHeaders.getField("WWW-Authenticate"); + try { + this.iPrevAuthInfo = getAuthentication(false, this.iPrevAuthInfo, authenticate); + if (this.iPrevAuthInfo != null) { + this.iRequestHeaders.addField( + this.iPrevAuthInfo.getHeaderFieldName(), + this.iPrevAuthInfo.toString() + ); + } + } catch (NoSuchAlgorithmException e) { + logger.trace(Level.FINER, "Unable to find digest algorithm", e); + } catch (IllegalArgumentException e) { + logger.trace(Level.FINER, "HTTP 401 response did not contain WWW-Authenticate information", e); + } catch (HttpParseException e) { + logger.trace(Level.FINER, "HTTP 401 response did not contain valid WWW-Authenticate information", e); + } + + if (!authFailed) { + authFailed = true; + logger.trace(Level.FINER, "Authorization failed, retrying with authorization info."); + } + if (this.iPrevAuthInfo != null && this.iPrevAuthInfo.isKeptAlive()) { + this.iKeepAlive = true; + } + break; + case HttpURLConnection.HTTP_PROXY_AUTH: + --AuthentificationRetry; + logger.message(Messages.HTTP_PROXY_AUTH_UNSUPPORTED, this.iUrl); + + // TODO implement http proxy authentication + /* + * authenticate = + * responseHeaders.getField("Proxy-Authenticate" + * ); prevProxy = getAuthentication(true, + * prevProxy, authenticate, this); if + * (prevAuthInfo != null) + * requestHeaders.addField + * ("Proxy-Authorization", + * prevProxy.toString()); + * + * while ((total = serverInput.available()) > 0) + * { serverInput.skip(total); } break; + */ + break; + default: + int status = this.iResponse.getStatus(); + if (!this.iKeepAlive) closeConnection(); else this.iServerInput.close(); + this.iPreviousResponseTime = ResponseTime; + return status; + } + } catch (SocketTimeoutException e) { + throw e; + } catch (IOException e) { + logger.message(Messages.HTTP_CONNECTION_FAILED, new Object[] { this.iUrl, e.getMessage() }); + StringBuilder msg = new StringBuilder("Http connection failed "); + if (ResponseTime != -1) { + msg.append("after"); + msg.append(ResponseTime - RequestTime); + msg.append(" milliseconds"); + } else { + msg.append("before response received"); + } + if (this.iPreviousResponseTime != -1) { + msg.append(", "); + msg.append(System.currentTimeMillis() - this.iPreviousResponseTime); + msg.append(" milliseconds after previous response on same socket"); + } + logger.trace(Level.FINE, msg.toString(), e); + delayedException = e; + if (this.iSocket != null && !this.iSocket.isClosed()) { + try { + this.iSocket.close(); + } catch (IOException e2) { + logger.trace(Level.FINER, "Exception caught while closing socket", e2); + } + } + this.iSocket = null; + this.iReset = true; + this.iResponse = null; + --IoRetry; + } + } while (AuthentificationRetry >= 0 && IoRetry >= 0); + } + + if (this.iResponse != null) { + logger.trace(Level.FINER, "http response code=" + this.iResponse.getStatus()); + if (ResponseTime != -1) this.iPreviousResponseTime = ResponseTime; + return this.iResponse.getStatus(); + } + throw (IOException) ( + delayedException != null ? delayedException : new Exception("Unable to get response after maximum retries") + ); + } finally { + logger.exit(); + } + } + + /** + * Returns the response message + * + * @return The response message + */ + public String getResponseMessage() { + if (this.iResponse != null) return this.iResponse.getResponseMessage(); + return null; + } + + public void handshakeCompleted(HandshakeCompletedEvent event) { + LogAndTraceBroker.getBroker().trace(Level.FINER, "Http handshake completed."); + this.iSession = event.getSession(); + } + + /** + * Resets state + */ + public void reset() { + this.iRequestHeaders.clear(); + this.iResponseHeaders.clear(); + this.iResponse = null; + this.iReset = true; + } + + /** + * Sets the request method + * + * @param method + * The request method + */ + public void setRequestMethod(String method) { + this.iRequestMethod = method; + } + + /** + * Sets the request property + * + * @param key + * The property name + * @param value + * The value + */ + public void setRequestProperty(String key, String value) { + this.iRequestHeaders.addField(key, value); + } + + /** + * Releases the client and returns it to the pool + */ + public void streamFinished() { + streamFinished(true); + } + + /** + * Releases the client and returns it to the pool + * + * @param keep + * if true return to the pool, if false + * drop. + */ + public void streamFinished(boolean keep) { + LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + HostPortPair hpp = new HostPortPair(this.iUrl); + if (keep) { // TODO configurable from property file + logger.trace(Level.FINER, "Adding http client to pool (" + hpp + ")"); + this.iHttpClientPool.returnAvailableConnectionToPool(this); + } else { + logger.trace(Level.FINER, "Disconnectiong http client (" + hpp + ")"); + this.iHttpClientPool.removeConnectionFromPool(this); + disconnect(); + } + logger.exit(); + } + + /** + * Enables/Disables use of http 1.1 + * + * @param bool + * if true http 1.1 is enabled. + */ + public void useHttp11(boolean bool) { + this.iUseHttp11 = bool; + } + + /** + * Returns if a proxy is used + * + * @return true if a proxy is used + */ + public boolean usingProxy() { + // TODO Auto-generated method stub + return false; + } + + protected AuthorizationInfo getAuthentication(boolean proxy, AuthorizationInfo prevAuthInfo, String authenticate) + throws HttpParseException, NoSuchAlgorithmException { + Challenge[] challenges = Challenge.parseChallenge(authenticate); + + // AuthorizationHandler auth_handler = + // AuthorizationHandler.getInstance(); + int cntr = 0; + prevAuthInfo = null; + while (cntr < challenges.length) { + Challenge challenge = challenges[cntr]; + cntr++; + // if (challenge.getScheme().equalsIgnoreCase("Digest")) { + // HttpHeader headers = challenge.getParams(); + // String stale = headers.getField("stale"); + // } + prevAuthInfo = + this.iAuth_handler.getAuthorizationInfo( + this.iHttpClientPool.getConfigurationContext().getHttpAuthenticationModule(), + proxy ? Boolean.TRUE : Boolean.FALSE, + this.iUrl.getHost(), + this.iUrl.getPort(), + this.iUrl.getScheme(), + challenge.getRealm(), + challenge.getScheme() + ); + + if (prevAuthInfo != null) { + prevAuthInfo.updateAuthenticationInfo(challenge, authenticate, this.iUrl, this.iRequestMethod); + return prevAuthInfo; + } + } + return null; + } + + private void closeConnection() { + LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + if (this.iSocket != null) { + try { + this.iSocket.close(); + } catch (IOException e) { + logger.trace(Level.FINER, "Exception while closing the socket", e); + } + this.iSocket = null; + this.iServerInput = null; + // response = null; + } + logger.exit(); + } + + private String[] parseProperty(String propertyName) { + String s = (String) AccessController.doPrivileged(new GetProperty(propertyName)); + String as[]; + if (s == null || s.length() == 0) { + as = null; + } else { + Vector vector = new Vector(); + for ( + StringTokenizer stringtokenizer = new StringTokenizer(s, ","); + stringtokenizer.hasMoreElements(); + vector.addElement(stringtokenizer.nextElement()) + ) { + // add each token to vector + } + as = new String[vector.size()]; + for (int i1 = 0; i1 < as.length; i1++) as[i1] = (String) vector.elementAt(i1); + } + return as; + } + + private void resetSocket() throws IOException { + LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + if (!this.iKeepAlive) { + logger.trace(Level.FINER, "KeepAlive=false, closing http connection..."); + closeConnection(); + } + + int httpTimeout = this.iHttpClientPool.getConfigurationContext().getHttpTimeout(); + logger.trace(Level.FINER, "Setting http timeout=" + httpTimeout); + + if (this.iSocket == null) { + // Determine whether we need to connect with a timeout or not + boolean socketConnectWithTimeout = this.iHttpClientPool.getConfigurationContext().socketConnectWithTimeout(); + logger.trace( + Level.FINER, + "Socket=null, creating http socket " + (socketConnectWithTimeout ? "with" : "without") + " timeout." + ); + + // On Java 5+ InetSocketAddress(String,int) constructor will call + // any security manager's checkConnect method + if (!socketConnectWithTimeout) { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkConnect(this.iUrl.getHost(), this.iUrl.getPort()); + } + } + + SocketFactory factory = this.iHttpClientPool.getConfigurationContext().getCustomSocketFactory(); + if (factory == null) { + factory = + HttpSocketFactory + .getInstance() + .getClientSocketFactory( + WBEMConstants.HTTPS.equalsIgnoreCase(this.iUrl.getScheme()) ? this.iHttpClientPool.getSslContext() : null + ); + if (factory == null) { + logger.message(Messages.HTTP_NO_SOCKET_FACTORY, this.iUrl.getScheme()); + throw new IllegalStateException("Unable to load socket factory:" + this.iUrl.getScheme()); + } + } + logger.trace(Level.FINER, "Creating new http for url " + this.iUrl.toString()); + if (socketConnectWithTimeout) { + int connectTimeout = this.iHttpClientPool.getConfigurationContext().getSocketConnectTimeout(); + logger.trace(Level.FINER, "Setting socket connect timeout=" + connectTimeout); + + if (factory instanceof SSLSocketFactory) { + Socket sock = new Socket(); + sock.connect(new InetSocketAddress(this.iUrl.getHost(), this.iUrl.getPort()), connectTimeout); + this.iSocket = + ((SSLSocketFactory) factory).createSocket(sock, this.iUrl.getHost(), this.iUrl.getPort(), true); + } else { + this.iSocket = factory.createSocket(); + if (this.iSocket != null) this.iSocket.connect( + new InetSocketAddress(this.iUrl.getHost(), this.iUrl.getPort()), + connectTimeout + ); + } + } else { + this.iSocket = factory.createSocket(this.iUrl.getHost(), this.iUrl.getPort()); + } + if (this.iSocket == null) { + logger.trace(Level.WARNING, "Socket factory " + factory.getClass().getName() + " returned null socket"); + throw new IOException("Socket factory did not create socket"); + } + + this.iPreviousResponseTime = -1; + this.iSocket.setTcpNoDelay(true); + this.iSocket.setKeepAlive(true); + this.iSocket.setSoTimeout(httpTimeout); + + if (this.iSocket instanceof SSLSocket) { + // Determine whether we need to perform SSL handshake or not + boolean performHandshake = this.iHttpClientPool.getConfigurationContext().performSslHandshake(); + logger.trace( + Level.FINER, + "SSL socket created, handshake " + (performHandshake ? "will" : "will not") + " be performed." + ); + + if (performHandshake) { + SSLSocket sk = (SSLSocket) this.iSocket; + + String protocols[] = parseProperty("https.protocols"); + if (protocols != null) { + logger.trace( + Level.FINER, + "Setting SSLSocket.setEnabledProtocols() from \"https.protocols\"=" + + String.valueOf(Arrays.asList(protocols)) + ); + sk.setEnabledProtocols(protocols); + } + + String ciphersuites[] = parseProperty("https.cipherSuites"); + if (ciphersuites != null) { + logger.trace( + Level.FINER, + "Setting SSLSocket.setEnableCipheSuites() from \"https.cipherSuites\"=" + + String.valueOf(Arrays.asList(ciphersuites)) + ); + sk.setEnabledCipherSuites(ciphersuites); + } + + String disableCipherSuites = + this.iHttpClientPool.getConfigurationContext().getSslClientCipherSuitesToDisable(); + if (disableCipherSuites != null) { + sk.setEnabledCipherSuites( + this.iHttpClientPool.getUpdatedCipherSuites(sk.getEnabledCipherSuites(), disableCipherSuites) + ); + } + + // Determine whether we need to perform synchronized SSL + // handshake or not + boolean synchronizedHandshake = this.iHttpClientPool.getConfigurationContext().synchronizedSslHandshake(); + logger.trace( + Level.FINER, + "Starting " + (synchronizedHandshake ? "synchronized" : "unsynchronized") + " http handshake." + ); + + sk.addHandshakeCompletedListener(this); + if (synchronizedHandshake) { + synchronized (SSLSocket.class) { + sk.startHandshake(); + } + } else { + sk.startHandshake(); + } + } + } + + this.iIStream = new BufferedInputStream(this.iSocket.getInputStream()); + this.iOStream = + new ASCIIPrintStream(new BufferedOutputStream(this.iSocket.getOutputStream(), 1024), false, iEncoding); + this.iServerInput = null; + } else { + if (this.iServerInput != null && !(this.iServerInput instanceof KeepAliveInputStream)) { + logger.trace(Level.FINER, "Socket!=null, flushing the stream..."); + long totalBytes = 0; + long total; + while ((total = this.iServerInput.available()) > 0) { + total = this.iServerInput.skip(total); + if (total >= 0) totalBytes += total; + } + logger.trace(Level.FINER, "total bytes on the stream=" + totalBytes); + } + this.iSocket.setSoTimeout(httpTimeout); + } + } + + /** + * Returns connected + * + * @return The value of connected. + */ + public boolean isConnected() { + return this.iConnected; + } + + @Override + public String toString() { + StringBuffer result = new StringBuffer(); + result.append('['); + result.append("URI="); + result.append(this.iUrl); + result.append(", "); + result.append(this.iConnected ? "connected" : "not connected"); + result.append(", "); + result.append(this.iKeepAlive ? "kept alive" : "not kept alive"); + result.append(", "); + result.append(this.iUseHttp11 ? "HTTP 1.1" : "HTTP 1.0"); + result.append(", "); + result.append("Method="); + result.append(this.iMethod); + result.append(", "); + result.append("Request Method="); + result.append(this.iRequestMethod); + result.append(", "); + result.append("Protocol="); + result.append(this.iSession != null ? this.iSession.getProtocol() : "http"); + result.append(", "); + result.append("CipherSuite="); + result.append(this.iSession != null ? this.iSession.getCipherSuite() : "n/a"); + result.append(']'); + return result.toString(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpClientMethod.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpClientMethod.java similarity index 79% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpClientMethod.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpClientMethod.java index c54b70f..1275ff0 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpClientMethod.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpClientMethod.java @@ -1,201 +1,198 @@ -/* - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.io.ASCIIPrintStream; - -/** - * Class HttpClientMethod encapsulates a http client method - * - */ -public class HttpClientMethod extends HttpMethod { - - private boolean iIncomming = true; - - private String iHttpHeader; - - private int iMinor, iMajor; - - private int iStatus; - - private String iMethod; - - private String iRequest; - - private String iResponse; - - /** - * Ctor. Creates an outgoing http method - * - * @param pMethod - * The method - * @param pRequest - * The request - * @param pMajor - * The major version - * @param pMinor - * The minor version - */ - public HttpClientMethod(String pMethod, String pRequest, int pMajor, int pMinor) { - this.iMinor = pMinor; - this.iMajor = pMajor; - this.iRequest = pRequest; - this.iMethod = pMethod; - this.iIncomming = false; - } - - /** - * Ctor. Parses an incoming http method from a given input stream - * - * @param pReader - * The input stream - * @throws IOException - */ - public HttpClientMethod(InputStream pReader) throws IOException { - String line = null; - - do { - line = readLine(pReader); - } while (line == null || line.length() == 0); - int rqt = line.indexOf(' '); - int prev = 0; - if (rqt > -1) { // Parse the header - int next = rqt; - this.iHttpHeader = line.substring(prev, next).toUpperCase(); - - prev = this.iHttpHeader.indexOf('/'); - if (prev > 0 && this.iHttpHeader.substring(0, prev).equalsIgnoreCase("HTTP")) { - next = this.iHttpHeader.indexOf('.', prev + 1); - try { - this.iMajor = Integer.parseInt(this.iHttpHeader.substring(prev + 1, next)); - this.iMinor = Integer.parseInt(this.iHttpHeader.substring(next + 1)); - } catch (Exception e) { - throw new HttpException(HttpURLConnection.HTTP_BAD_METHOD, "Bad method"); - } - prev = rqt; - rqt = line.indexOf(' ', prev + 1); - if (rqt > -1) { - try { - this.iStatus = Integer.parseInt(line.substring(prev + 1, rqt)); - } catch (Exception e) { - throw new HttpException(HttpURLConnection.HTTP_BAD_METHOD, "Bad method"); - } - this.iResponse = line.substring(rqt + 1); - return; - } - } else throw new HttpException(HttpURLConnection.HTTP_BAD_METHOD, "Bad method"); - } - throw new HttpException(HttpURLConnection.HTTP_BAD_METHOD, "Bad method"); - } - - /** - * Returns the major version - * - * @return The major version - */ - public int getMajorVersion() { - return this.iMajor; - } - - /** - * Returns the minor version - * - * @return The minor version - */ - public int getMinorVersion() { - return this.iMinor; - } - - /** - * Returns the method name - * - * @return The method name - */ - public String getMethodName() { - return this.iMethod; - } - - /** - * Return the status - * - * @return The status - */ - public int getStatus() { - return this.iStatus; - } - - /** - * Writes the method to a given stream - * - * @param pStream - * The stream - */ - public void write(ASCIIPrintStream pStream) { - pStream.print(this.iMethod + " " + this.iRequest + " HTTP/" + this.iMajor + "." - + this.iMinor + "\r\n"); - } - - /** - * Returns the response message - * - * @return The response message - */ - public String getResponseMessage() { - return this.iResponse; - } - - @Override - public String toString() { - if (this.iIncomming) { return this.iHttpHeader + " " + this.iStatus + " " + this.iResponse; } - return this.iMethod + " " + this.iRequest + " HTTP/" + this.iMajor + "." + this.iMinor; - } -} +/* + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + */ + +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import org.metricshub.wbem.sblim.cimclient.internal.http.io.ASCIIPrintStream; + +/** + * Class HttpClientMethod encapsulates a http client method + * + */ +public class HttpClientMethod extends HttpMethod { + private boolean iIncomming = true; + + private String iHttpHeader; + + private int iMinor, iMajor; + + private int iStatus; + + private String iMethod; + + private String iRequest; + + private String iResponse; + + /** + * Ctor. Creates an outgoing http method + * + * @param pMethod + * The method + * @param pRequest + * The request + * @param pMajor + * The major version + * @param pMinor + * The minor version + */ + public HttpClientMethod(String pMethod, String pRequest, int pMajor, int pMinor) { + this.iMinor = pMinor; + this.iMajor = pMajor; + this.iRequest = pRequest; + this.iMethod = pMethod; + this.iIncomming = false; + } + + /** + * Ctor. Parses an incoming http method from a given input stream + * + * @param pReader + * The input stream + * @throws IOException + */ + public HttpClientMethod(InputStream pReader) throws IOException { + String line = null; + + do { + line = readLine(pReader); + } while (line == null || line.length() == 0); + int rqt = line.indexOf(' '); + int prev = 0; + if (rqt > -1) { // Parse the header + int next = rqt; + this.iHttpHeader = line.substring(prev, next).toUpperCase(); + + prev = this.iHttpHeader.indexOf('/'); + if (prev > 0 && this.iHttpHeader.substring(0, prev).equalsIgnoreCase("HTTP")) { + next = this.iHttpHeader.indexOf('.', prev + 1); + try { + this.iMajor = Integer.parseInt(this.iHttpHeader.substring(prev + 1, next)); + this.iMinor = Integer.parseInt(this.iHttpHeader.substring(next + 1)); + } catch (Exception e) { + throw new HttpException(HttpURLConnection.HTTP_BAD_METHOD, "Bad method"); + } + prev = rqt; + rqt = line.indexOf(' ', prev + 1); + if (rqt > -1) { + try { + this.iStatus = Integer.parseInt(line.substring(prev + 1, rqt)); + } catch (Exception e) { + throw new HttpException(HttpURLConnection.HTTP_BAD_METHOD, "Bad method"); + } + this.iResponse = line.substring(rqt + 1); + return; + } + } else throw new HttpException(HttpURLConnection.HTTP_BAD_METHOD, "Bad method"); + } + throw new HttpException(HttpURLConnection.HTTP_BAD_METHOD, "Bad method"); + } + + /** + * Returns the major version + * + * @return The major version + */ + public int getMajorVersion() { + return this.iMajor; + } + + /** + * Returns the minor version + * + * @return The minor version + */ + public int getMinorVersion() { + return this.iMinor; + } + + /** + * Returns the method name + * + * @return The method name + */ + public String getMethodName() { + return this.iMethod; + } + + /** + * Return the status + * + * @return The status + */ + public int getStatus() { + return this.iStatus; + } + + /** + * Writes the method to a given stream + * + * @param pStream + * The stream + */ + public void write(ASCIIPrintStream pStream) { + pStream.print(this.iMethod + " " + this.iRequest + " HTTP/" + this.iMajor + "." + this.iMinor + "\r\n"); + } + + /** + * Returns the response message + * + * @return The response message + */ + public String getResponseMessage() { + return this.iResponse; + } + + @Override + public String toString() { + if (this.iIncomming) { + return this.iHttpHeader + " " + this.iStatus + " " + this.iResponse; + } + return this.iMethod + " " + this.iRequest + " HTTP/" + this.iMajor + "." + this.iMinor; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpClientPool.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpClientPool.java similarity index 76% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpClientPool.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpClientPool.java index f5f046e..a94aa88 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpClientPool.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpClientPool.java @@ -1,332 +1,334 @@ -/* - (C) Copyright IBM Corp. 2005, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1353168 2005-11-24 fiuczy Possible NullPointerExcection in HttpClient.streamFinished() - * 1498130 2006-05-31 lupusalex Selection of xml parser on a per connection basis - * 1535756 2006-08-07 lupusalex Make code warning free - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 1646434 2007-01-28 lupusalex CIMClient close() invalidates all it's enumerations - * 1647159 2007-01-29 lupusalex HttpClientPool runs out of HttpClients - * 1660743 2007-02-15 lupusalex SSLContext is static - * 1714902 2007-05-08 lupusalex Threading related weak spots - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues - * 2618 2013-02-27 blaschke-oss Need to add property to disable weak cipher suites for the secure indication - * 2642 2013-05-21 blaschke-oss Seperate properties needed for cim client and listener to filter out ciphers - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.net.URI; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.logging.Level; - -import javax.net.ssl.SSLContext; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.Util; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConfiguration; - -/** - * Class HttpClientPool implements a pool for http client connections - * - */ -public class HttpClientPool { - - /** - * Guarded by "this" - */ - private List iAllConnections; - - /** - * Guarded by "this" - */ - private List iAvailableConnections; - - /** - * Guarded by "this" - */ - private boolean iClosed = false; - - private final int iPoolSize; - - private final WBEMConfiguration iConfiguration; - - /** - * Guarded by "this" - */ - private SSLContext iSslContext; - - private String[] iEnabledCipherSuites = null; - - /** - * Ctor. - * - * @param pConfiguration - * The configuration for this session. Must be non-null. - */ - public HttpClientPool(WBEMConfiguration pConfiguration) { - super(); - this.iConfiguration = pConfiguration; - this.iAllConnections = new ArrayList(pConfiguration.getHttpPoolSize()); - this.iAvailableConnections = new ArrayList(pConfiguration.getHttpPoolSize()); - this.iPoolSize = pConfiguration.getHttpPoolSize(); - this.iSslContext = null; - this.iEnabledCipherSuites = null; - } - - /** - * Returns the number of connections in this pool that are available/free - * for (re-)use. - * - * @return number of available/free connections in pool - */ - public synchronized int getNumberOfAllConnections() { - return this.iAllConnections.size(); - } - - /** - * Returns the number of all connections in this pool. - * - * @return number of all connections in pool - */ - public synchronized int getNumberOfAvailableConnections() { - return this.iAvailableConnections.size(); - } - - /** - * Returns the configuration context of this pool - * - * @return The configuration - */ - public WBEMConfiguration getConfigurationContext() { - return this.iConfiguration; - } - - /** - * Returns the SSL context for the clients in this pool. The context is - * initialized on the first call of this method (lazy initialization). - * - * @return The SSL context - */ - public synchronized SSLContext getSslContext() { - if (this.iSslContext == null) { - this.iSslContext = HttpSocketFactory.getInstance().getClientSSLContext( - this.iConfiguration); - } - return this.iSslContext; - } - - /** - * Returns the available connections of this pool for a given - * URI&AuthorizationHandler - * - * @param pUri - * The uri - * @param pHandler - * The authorization handler - * @return A connection if one is available, null otherwise - */ - public synchronized HttpClient retrieveAvailableConnectionFromPool(URI pUri, - AuthorizationHandler pHandler) { - if (this.iClosed) { - LogAndTraceBroker.getBroker().trace(Level.FINE, - "Attempt to get client from closed http client pool,"); - throw new IllegalStateException("HttpClientPool is closed. Retrieve connection failed."); - } - if (getNumberOfAvailableConnections() > 0) { - LogAndTraceBroker.getBroker().trace( - Level.FINE, - "Reusing client (" + pUri.toString() + ", max: " + getPoolSize() + ", current:" - + getNumberOfAvailableConnections()); - - return this.iAvailableConnections.remove(0); - } - - LogAndTraceBroker.getBroker().trace( - Level.FINE, - "New client (" + pUri.toString() + ", max: " + getPoolSize() + ", current:" - + getNumberOfAvailableConnections()); - HttpClient client = new HttpClient(pUri, this, pHandler); - addConnectionToPool(client); - return client; - } - - /** - * Add the connection to the pool. Connection is added as available - * connection. Use method {@link #addConnectionToPool(HttpClient)} to add - * the connection without being available for reuse. - * - * @param httpClient - * connection that is to be added to the pool - * @return true if connection was added otherwise false - */ - public synchronized boolean returnAvailableConnectionToPool(HttpClient httpClient) { - if (httpClient == null) { return false; } - - if (this.iClosed) { - this.iAllConnections.remove(httpClient); - httpClient.disconnect(); - return false; - } - - if (getPoolSize() > this.iAvailableConnections.size()) { - if (!this.iAvailableConnections.contains(httpClient)) { - // ensure that the connection exists in allConnections owned by - // pool - addConnectionToPool(httpClient); - this.iAvailableConnections.add(httpClient); - return true; - } - } else { - LogAndTraceBroker.getBroker().trace(Level.FINE, - "Http pool size reached, discarding client."); - this.iAllConnections.remove(httpClient); - this.iAvailableConnections.remove(httpClient); - httpClient.disconnect(); - } - return false; // connection was not added to pool - } - - /** - * Add the connection to the pool, but does NOT add it as available - * connection. Use method - * {@link #returnAvailableConnectionToPool(HttpClient)} to also add the - * connection to the available connections. - * - * @param httpClient - * connection that is to be added to the pool - * @return true if connection was added otherwise false - */ - public synchronized boolean addConnectionToPool(HttpClient httpClient) { - if (this.iClosed) { - LogAndTraceBroker.getBroker().trace(Level.FINE, - "Attempt to add client to closed http client pool,"); - throw new IllegalStateException("HttpClientPool is closed. Add connection failed."); - } - if (httpClient != null && !this.iAllConnections.contains(httpClient)) { - // if connection is not in pool add it - this.iAllConnections.add(httpClient); - return true; - } - return false; - } - - /** - * Removes a connection completely from the pool. - * - * @param httpClient - * connection that is to be removed from the pool - * @return true if connection was removed otherwise false - */ - public synchronized boolean removeConnectionFromPool(HttpClient httpClient) { - if (httpClient != null) { - this.iAvailableConnections.remove(httpClient); - if (this.iAllConnections.remove(httpClient)) { return true; } - return false; // connection was not in pool! - } - return false; // no connection given - } - - /** - * Closes the pool. This will disconnect all clients in the pool. - */ - public synchronized void closePool() { - this.iClosed = true; - Iterator iter = this.iAvailableConnections.iterator(); - while (iter.hasNext()) { - HttpClient httpClient = iter.next(); - this.iAllConnections.remove(httpClient); - httpClient.disconnect(); - } - this.iAvailableConnections.clear(); - } - - @Override - protected void finalize() throws Throwable { - closePool(); - super.finalize(); - } - - /** - * Returns poolSize - * - * @return The value of poolSize. - */ - public int getPoolSize() { - return this.iPoolSize; - } - - /** - * Returns updated array of cipher suites which is current cipher suites - * less any cipher suites listed to be disabled - * - * NOTE: The updated array is generated only upon first invocation and then - * saved, effectively making this a lazy initialization of the cipher suites - * on a HttpClientPool basis - it has to be done here and not in WBEMClient - * where it belongs because socket characteristics are not known to - * WBEMClient - * - * @param pCurrentCipherSuites - * The currently enabled cipher suites - * @param pDisableCipherSuites - * The list of cipher suites to be disabled - * @return The updated enabled cipher suites - */ - public synchronized String[] getUpdatedCipherSuites(String[] pCurrentCipherSuites, - String pDisableCipherSuites) { - if (this.iEnabledCipherSuites == null) { - this.iEnabledCipherSuites = Util.getFilteredStringArray(pCurrentCipherSuites, - pDisableCipherSuites); - int before = pCurrentCipherSuites.length; - int after = this.iEnabledCipherSuites.length; - if (before > 0 && after == 0) LogAndTraceBroker.getBroker().trace(Level.WARNING, - "All cipher suites disabled for client!"); - else if (before > after) LogAndTraceBroker.getBroker().trace(Level.FINE, - "Some (" + (before - after) + ") cipher suites disabled for client"); - else if (before == after) LogAndTraceBroker.getBroker().trace(Level.FINER, - "No cipher suites disabled for client"); - } - return this.iEnabledCipherSuites; - } -} +/* + (C) Copyright IBM Corp. 2005, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1353168 2005-11-24 fiuczy Possible NullPointerExcection in HttpClient.streamFinished() + * 1498130 2006-05-31 lupusalex Selection of xml parser on a per connection basis + * 1535756 2006-08-07 lupusalex Make code warning free + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 1646434 2007-01-28 lupusalex CIMClient close() invalidates all it's enumerations + * 1647159 2007-01-29 lupusalex HttpClientPool runs out of HttpClients + * 1660743 2007-02-15 lupusalex SSLContext is static + * 1714902 2007-05-08 lupusalex Threading related weak spots + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues + * 2618 2013-02-27 blaschke-oss Need to add property to disable weak cipher suites for the secure indication + * 2642 2013-05-21 blaschke-oss Seperate properties needed for cim client and listener to filter out ciphers + */ + +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.net.URI; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.logging.Level; +import javax.net.ssl.SSLContext; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; +import org.metricshub.wbem.sblim.cimclient.internal.util.Util; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfiguration; + +/** + * Class HttpClientPool implements a pool for http client connections + * + */ +public class HttpClientPool { + /** + * Guarded by "this" + */ + private List iAllConnections; + + /** + * Guarded by "this" + */ + private List iAvailableConnections; + + /** + * Guarded by "this" + */ + private boolean iClosed = false; + + private final int iPoolSize; + + private final WBEMConfiguration iConfiguration; + + /** + * Guarded by "this" + */ + private SSLContext iSslContext; + + private String[] iEnabledCipherSuites = null; + + /** + * Ctor. + * + * @param pConfiguration + * The configuration for this session. Must be non-null. + */ + public HttpClientPool(WBEMConfiguration pConfiguration) { + super(); + this.iConfiguration = pConfiguration; + this.iAllConnections = new ArrayList(pConfiguration.getHttpPoolSize()); + this.iAvailableConnections = new ArrayList(pConfiguration.getHttpPoolSize()); + this.iPoolSize = pConfiguration.getHttpPoolSize(); + this.iSslContext = null; + this.iEnabledCipherSuites = null; + } + + /** + * Returns the number of connections in this pool that are available/free + * for (re-)use. + * + * @return number of available/free connections in pool + */ + public synchronized int getNumberOfAllConnections() { + return this.iAllConnections.size(); + } + + /** + * Returns the number of all connections in this pool. + * + * @return number of all connections in pool + */ + public synchronized int getNumberOfAvailableConnections() { + return this.iAvailableConnections.size(); + } + + /** + * Returns the configuration context of this pool + * + * @return The configuration + */ + public WBEMConfiguration getConfigurationContext() { + return this.iConfiguration; + } + + /** + * Returns the SSL context for the clients in this pool. The context is + * initialized on the first call of this method (lazy initialization). + * + * @return The SSL context + */ + public synchronized SSLContext getSslContext() { + if (this.iSslContext == null) { + this.iSslContext = HttpSocketFactory.getInstance().getClientSSLContext(this.iConfiguration); + } + return this.iSslContext; + } + + /** + * Returns the available connections of this pool for a given + * URI&AuthorizationHandler + * + * @param pUri + * The uri + * @param pHandler + * The authorization handler + * @return A connection if one is available, null otherwise + */ + public synchronized HttpClient retrieveAvailableConnectionFromPool(URI pUri, AuthorizationHandler pHandler) { + if (this.iClosed) { + LogAndTraceBroker.getBroker().trace(Level.FINE, "Attempt to get client from closed http client pool,"); + throw new IllegalStateException("HttpClientPool is closed. Retrieve connection failed."); + } + if (getNumberOfAvailableConnections() > 0) { + LogAndTraceBroker + .getBroker() + .trace( + Level.FINE, + "Reusing client (" + + pUri.toString() + + ", max: " + + getPoolSize() + + ", current:" + + getNumberOfAvailableConnections() + ); + + return this.iAvailableConnections.remove(0); + } + + LogAndTraceBroker + .getBroker() + .trace( + Level.FINE, + "New client (" + pUri.toString() + ", max: " + getPoolSize() + ", current:" + getNumberOfAvailableConnections() + ); + HttpClient client = new HttpClient(pUri, this, pHandler); + addConnectionToPool(client); + return client; + } + + /** + * Add the connection to the pool. Connection is added as available + * connection. Use method {@link #addConnectionToPool(HttpClient)} to add + * the connection without being available for reuse. + * + * @param httpClient + * connection that is to be added to the pool + * @return true if connection was added otherwise false + */ + public synchronized boolean returnAvailableConnectionToPool(HttpClient httpClient) { + if (httpClient == null) { + return false; + } + + if (this.iClosed) { + this.iAllConnections.remove(httpClient); + httpClient.disconnect(); + return false; + } + + if (getPoolSize() > this.iAvailableConnections.size()) { + if (!this.iAvailableConnections.contains(httpClient)) { + // ensure that the connection exists in allConnections owned by + // pool + addConnectionToPool(httpClient); + this.iAvailableConnections.add(httpClient); + return true; + } + } else { + LogAndTraceBroker.getBroker().trace(Level.FINE, "Http pool size reached, discarding client."); + this.iAllConnections.remove(httpClient); + this.iAvailableConnections.remove(httpClient); + httpClient.disconnect(); + } + return false; // connection was not added to pool + } + + /** + * Add the connection to the pool, but does NOT add it as available + * connection. Use method + * {@link #returnAvailableConnectionToPool(HttpClient)} to also add the + * connection to the available connections. + * + * @param httpClient + * connection that is to be added to the pool + * @return true if connection was added otherwise false + */ + public synchronized boolean addConnectionToPool(HttpClient httpClient) { + if (this.iClosed) { + LogAndTraceBroker.getBroker().trace(Level.FINE, "Attempt to add client to closed http client pool,"); + throw new IllegalStateException("HttpClientPool is closed. Add connection failed."); + } + if (httpClient != null && !this.iAllConnections.contains(httpClient)) { + // if connection is not in pool add it + this.iAllConnections.add(httpClient); + return true; + } + return false; + } + + /** + * Removes a connection completely from the pool. + * + * @param httpClient + * connection that is to be removed from the pool + * @return true if connection was removed otherwise false + */ + public synchronized boolean removeConnectionFromPool(HttpClient httpClient) { + if (httpClient != null) { + this.iAvailableConnections.remove(httpClient); + if (this.iAllConnections.remove(httpClient)) { + return true; + } + return false; // connection was not in pool! + } + return false; // no connection given + } + + /** + * Closes the pool. This will disconnect all clients in the pool. + */ + public synchronized void closePool() { + this.iClosed = true; + Iterator iter = this.iAvailableConnections.iterator(); + while (iter.hasNext()) { + HttpClient httpClient = iter.next(); + this.iAllConnections.remove(httpClient); + httpClient.disconnect(); + } + this.iAvailableConnections.clear(); + } + + @Override + protected void finalize() throws Throwable { + closePool(); + super.finalize(); + } + + /** + * Returns poolSize + * + * @return The value of poolSize. + */ + public int getPoolSize() { + return this.iPoolSize; + } + + /** + * Returns updated array of cipher suites which is current cipher suites + * less any cipher suites listed to be disabled + * + * NOTE: The updated array is generated only upon first invocation and then + * saved, effectively making this a lazy initialization of the cipher suites + * on a HttpClientPool basis - it has to be done here and not in WBEMClient + * where it belongs because socket characteristics are not known to + * WBEMClient + * + * @param pCurrentCipherSuites + * The currently enabled cipher suites + * @param pDisableCipherSuites + * The list of cipher suites to be disabled + * @return The updated enabled cipher suites + */ + public synchronized String[] getUpdatedCipherSuites(String[] pCurrentCipherSuites, String pDisableCipherSuites) { + if (this.iEnabledCipherSuites == null) { + this.iEnabledCipherSuites = Util.getFilteredStringArray(pCurrentCipherSuites, pDisableCipherSuites); + int before = pCurrentCipherSuites.length; + int after = this.iEnabledCipherSuites.length; + if (before > 0 && after == 0) LogAndTraceBroker + .getBroker() + .trace(Level.WARNING, "All cipher suites disabled for client!"); else if (before > after) LogAndTraceBroker + .getBroker() + .trace(Level.FINE, "Some (" + (before - after) + ") cipher suites disabled for client"); else if ( + before == after + ) LogAndTraceBroker.getBroker().trace(Level.FINER, "No cipher suites disabled for client"); + } + return this.iEnabledCipherSuites; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpConnectionHandler.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpConnectionHandler.java similarity index 67% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpConnectionHandler.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpConnectionHandler.java index 517375f..7a81a0c 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpConnectionHandler.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpConnectionHandler.java @@ -1,286 +1,291 @@ -/* - (C) Copyright IBM Corp. 2005, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 17931 2005-07-28 thschaef Add InetAddress to CIM Event - * 1535756 2006-08-07 lupusalex Make code warning free - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 1649779 2007-02-01 lupusalex Indication listener threads freeze - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 3185818 2011-02-18 blaschke-oss indicationOccured URL incorrect - * 3495662 2012-02-29 blaschke-oss Invalid HTML from HttpConnectionHandler.writeError - * 2635 2013-05-16 blaschke-oss Slowloris DoS attack for CIM indication listener port - * 2657 2013-08-20 blaschke-oss Potential null pointer exception in handleConnection - */ -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.InetAddress; -import java.net.Socket; -import java.net.SocketTimeoutException; -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Level; - -import javax.net.ssl.SSLSocket; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.io.ASCIIPrintStream; -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConfiguration; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConstants; - -/** - * Class HttpConnectionHandler is responsible for handling an incoming - * connection - * - */ -public class HttpConnectionHandler { - - /** - * MAJOR_VERSION - */ - public static final int MAJOR_VERSION = 1; - - /** - * MINOR_VERSION - */ - public static final int MINOR_VERSION = 1; - - HttpContentHandler iHandler; - - private int iHeaderTimeout; - - private int iMaxAllowedTimeouts; - - private Map iSuspectIPs = new HashMap(); - - private StringBuilder iBlockedIPs = null; - - /** - * Ctor. - * - * @param pHandler - * The content handler - * @param pProperties - * The configuration properties - */ - public HttpConnectionHandler(HttpContentHandler pHandler, WBEMConfiguration pProperties) { - this.iHandler = pHandler; - this.iHeaderTimeout = pProperties.getListenerHttpHeaderTimeout(); - this.iMaxAllowedTimeouts = pProperties.getListenerMaxAllowedTimeouts(); - } - - private synchronized void addSuspectIP(String pSuspectIP) { - if (this.iMaxAllowedTimeouts == 0) return; - - Integer times = this.iSuspectIPs.get(pSuspectIP); - if (times == null) { - this.iSuspectIPs.put(pSuspectIP, Integer.valueOf(1)); - } else { - int timesVal = times.intValue() + 1; - this.iSuspectIPs.put(pSuspectIP, Integer.valueOf(timesVal)); - if (timesVal >= this.iMaxAllowedTimeouts) { - boolean newIP = false; - if (this.iBlockedIPs == null) { - this.iBlockedIPs = new StringBuilder(pSuspectIP); - newIP = true; - } else if (this.iBlockedIPs.indexOf(pSuspectIP) == -1) { - this.iBlockedIPs.append(','); - this.iBlockedIPs.append(pSuspectIP); - newIP = true; - } - if (newIP) LogAndTraceBroker.getBroker().trace( - Level.WARNING, - "Maximum allowable timeouts exceeded, all future connections ignored from " - + pSuspectIP); - } - } - } - - private synchronized boolean isBlockedIP(Socket socket) { - return (this.iBlockedIPs != null && this.iBlockedIPs.indexOf(socket.getInetAddress() - .getHostAddress()) != -1); - } - - /** - * Handles the incoming connection and forwards to the content handler - * - * @param socket - * The socket of the connection - */ - public void handleConnection(Socket socket) { - InputStream is = null; - OutputStream os = null; - if (isBlockedIP(socket)) { - LogAndTraceBroker.getBroker().trace( - Level.FINEST, - "Incoming connection ignored from blocked IP " - + socket.getInetAddress().getHostAddress()); - } else try { - is = socket.getInputStream(); - os = socket.getOutputStream(); - do { // handle persistent connections - MessageReader reader = new MessageReader(is, this.iHeaderTimeout); - boolean persistent = reader.isPersistentConnectionSupported(); - persistent = false; - boolean chunk = reader.isChunkSupported(); - - HttpServerMethod readerMethod = reader.getMethod(); - if (readerMethod.getMethodName().equals("POST") - || readerMethod.getMethodName().equals("M-POST")) { - // TODO: validate authorization - - MessageWriter writer = new MessageWriter(os, persistent, chunk); - try { - StringBuilder localURL = new StringBuilder( - socket instanceof SSLSocket ? "https://" : "http://"); - InetAddress localAddress = socket.getLocalAddress(); - if (localAddress != null) { - localURL.append(localAddress.getHostAddress()); - int port = socket.getLocalPort(); - if (port > 0) { - localURL.append(":"); - localURL.append(port); - } - } - - // 17931 - this.iHandler.handleContent(reader, writer, socket.getInetAddress(), - localURL.toString()); - writer.setMethod(new HttpServerMethod(readerMethod.getMajorVersion(), - readerMethod.getMinorVersion(), 200, "OK")); - } catch (HttpException e) { - writer.setMethod(new HttpServerMethod(readerMethod.getMajorVersion(), - readerMethod.getMinorVersion(), e.getStatus(), e.getMessage())); - } catch (Throwable t) { - writer.setMethod(new HttpServerMethod(readerMethod.getMajorVersion(), - readerMethod.getMinorVersion(), 501, "Not Implemented")); - // TODO: define the correct error description - writer.reset(); - // TODO: report an specific error - writeError(writer.getOutputStream(), "error", "error"); - } finally { - try { - writer.close(); - } catch (IOException e) { - LogAndTraceBroker.getBroker().trace(Level.FINER, - "Exception while closing output stream from server socket", e); - } - } - } else { - persistent = false; - MessageWriter writer = new MessageWriter(os, false, false); - HttpHeader header = new HttpHeader(); - writer.setHeader(header); - // header.addField("Connection", persistent? - // "Keep-Alive","close"); - writer.setMethod(new HttpServerMethod(readerMethod.getMajorVersion(), - readerMethod.getMinorVersion(), 501, "Not Implemented")); - writeError(writer.getOutputStream(), "", ""); - try { - writer.close(); - } catch (IOException e) { - LogAndTraceBroker.getBroker().trace(Level.FINER, - "Exception while closing output stream from server socket", e); - } - } - - if (!persistent) break; - try { - reader.close(); - } catch (IOException e) { - LogAndTraceBroker.getBroker().trace(Level.FINER, - "Exception while closing input stream from server socket", e); - } - } while (true); - } catch (IOException e) { - LogAndTraceBroker.getBroker().trace(Level.FINER, - "Exception while reading from server socket", e); - - if (e instanceof SocketTimeoutException - || WBEMConstants.INDICATION_DOS_EXCEPTION_MESSAGE.equalsIgnoreCase(e - .getMessage())) { - addSuspectIP(socket.getInetAddress().getHostAddress()); - } - } - try { - socket.close(); - } catch (IOException e) { - LogAndTraceBroker.getBroker().trace(Level.FINER, - "Exception while closing server socket", e); - } - } - - /** - * Closes the handler. Will also close the content handler. - */ - public void close() { - this.iHandler.close(); - } - - private void writeError(ASCIIPrintStream dos, String title, String body) { - dos.print(" " + title + "" + body - + ""); - - } - - /** - * Get the IPs blocked by the listener associated with the specified port. - * - * @return The comma-separated list of blocked IPs. - */ - public synchronized String getBlockedIPs() { - return (this.iBlockedIPs == null) ? null : this.iBlockedIPs.toString(); - } - - /** - * Set the IPs to be blocked by the listener associated with the specified - * port. - * - * @param pIPs - * The comma-separated list of blocked IPs. - */ - public synchronized void setBlockedIPs(String pIPs) { - this.iBlockedIPs = (pIPs == null || pIPs.trim().length() == 0) ? null : new StringBuilder( - pIPs); - } -} +/* + (C) Copyright IBM Corp. 2005, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 17931 2005-07-28 thschaef Add InetAddress to CIM Event + * 1535756 2006-08-07 lupusalex Make code warning free + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 1649779 2007-02-01 lupusalex Indication listener threads freeze + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 3185818 2011-02-18 blaschke-oss indicationOccured URL incorrect + * 3495662 2012-02-29 blaschke-oss Invalid HTML from HttpConnectionHandler.writeError + * 2635 2013-05-16 blaschke-oss Slowloris DoS attack for CIM indication listener port + * 2657 2013-08-20 blaschke-oss Potential null pointer exception in handleConnection + */ +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.InetAddress; +import java.net.Socket; +import java.net.SocketTimeoutException; +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Level; +import javax.net.ssl.SSLSocket; +import org.metricshub.wbem.sblim.cimclient.internal.http.io.ASCIIPrintStream; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfiguration; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConstants; + +/** + * Class HttpConnectionHandler is responsible for handling an incoming + * connection + * + */ +public class HttpConnectionHandler { + /** + * MAJOR_VERSION + */ + public static final int MAJOR_VERSION = 1; + + /** + * MINOR_VERSION + */ + public static final int MINOR_VERSION = 1; + + HttpContentHandler iHandler; + + private int iHeaderTimeout; + + private int iMaxAllowedTimeouts; + + private Map iSuspectIPs = new HashMap(); + + private StringBuilder iBlockedIPs = null; + + /** + * Ctor. + * + * @param pHandler + * The content handler + * @param pProperties + * The configuration properties + */ + public HttpConnectionHandler(HttpContentHandler pHandler, WBEMConfiguration pProperties) { + this.iHandler = pHandler; + this.iHeaderTimeout = pProperties.getListenerHttpHeaderTimeout(); + this.iMaxAllowedTimeouts = pProperties.getListenerMaxAllowedTimeouts(); + } + + private synchronized void addSuspectIP(String pSuspectIP) { + if (this.iMaxAllowedTimeouts == 0) return; + + Integer times = this.iSuspectIPs.get(pSuspectIP); + if (times == null) { + this.iSuspectIPs.put(pSuspectIP, Integer.valueOf(1)); + } else { + int timesVal = times.intValue() + 1; + this.iSuspectIPs.put(pSuspectIP, Integer.valueOf(timesVal)); + if (timesVal >= this.iMaxAllowedTimeouts) { + boolean newIP = false; + if (this.iBlockedIPs == null) { + this.iBlockedIPs = new StringBuilder(pSuspectIP); + newIP = true; + } else if (this.iBlockedIPs.indexOf(pSuspectIP) == -1) { + this.iBlockedIPs.append(','); + this.iBlockedIPs.append(pSuspectIP); + newIP = true; + } + if (newIP) LogAndTraceBroker + .getBroker() + .trace( + Level.WARNING, + "Maximum allowable timeouts exceeded, all future connections ignored from " + pSuspectIP + ); + } + } + } + + private synchronized boolean isBlockedIP(Socket socket) { + return (this.iBlockedIPs != null && this.iBlockedIPs.indexOf(socket.getInetAddress().getHostAddress()) != -1); + } + + /** + * Handles the incoming connection and forwards to the content handler + * + * @param socket + * The socket of the connection + */ + public void handleConnection(Socket socket) { + InputStream is = null; + OutputStream os = null; + if (isBlockedIP(socket)) { + LogAndTraceBroker + .getBroker() + .trace(Level.FINEST, "Incoming connection ignored from blocked IP " + socket.getInetAddress().getHostAddress()); + } else try { + is = socket.getInputStream(); + os = socket.getOutputStream(); + do { // handle persistent connections + MessageReader reader = new MessageReader(is, this.iHeaderTimeout); + boolean persistent = reader.isPersistentConnectionSupported(); + persistent = false; + boolean chunk = reader.isChunkSupported(); + + HttpServerMethod readerMethod = reader.getMethod(); + if (readerMethod.getMethodName().equals("POST") || readerMethod.getMethodName().equals("M-POST")) { + // TODO: validate authorization + + MessageWriter writer = new MessageWriter(os, persistent, chunk); + try { + StringBuilder localURL = new StringBuilder(socket instanceof SSLSocket ? "https://" : "http://"); + InetAddress localAddress = socket.getLocalAddress(); + if (localAddress != null) { + localURL.append(localAddress.getHostAddress()); + int port = socket.getLocalPort(); + if (port > 0) { + localURL.append(":"); + localURL.append(port); + } + } + + // 17931 + this.iHandler.handleContent(reader, writer, socket.getInetAddress(), localURL.toString()); + writer.setMethod( + new HttpServerMethod(readerMethod.getMajorVersion(), readerMethod.getMinorVersion(), 200, "OK") + ); + } catch (HttpException e) { + writer.setMethod( + new HttpServerMethod( + readerMethod.getMajorVersion(), + readerMethod.getMinorVersion(), + e.getStatus(), + e.getMessage() + ) + ); + } catch (Throwable t) { + writer.setMethod( + new HttpServerMethod( + readerMethod.getMajorVersion(), + readerMethod.getMinorVersion(), + 501, + "Not Implemented" + ) + ); + // TODO: define the correct error description + writer.reset(); + // TODO: report an specific error + writeError(writer.getOutputStream(), "error", "error"); + } finally { + try { + writer.close(); + } catch (IOException e) { + LogAndTraceBroker + .getBroker() + .trace(Level.FINER, "Exception while closing output stream from server socket", e); + } + } + } else { + persistent = false; + MessageWriter writer = new MessageWriter(os, false, false); + HttpHeader header = new HttpHeader(); + writer.setHeader(header); + // header.addField("Connection", persistent? + // "Keep-Alive","close"); + writer.setMethod( + new HttpServerMethod(readerMethod.getMajorVersion(), readerMethod.getMinorVersion(), 501, "Not Implemented") + ); + writeError(writer.getOutputStream(), "", ""); + try { + writer.close(); + } catch (IOException e) { + LogAndTraceBroker + .getBroker() + .trace(Level.FINER, "Exception while closing output stream from server socket", e); + } + } + + if (!persistent) break; + try { + reader.close(); + } catch (IOException e) { + LogAndTraceBroker + .getBroker() + .trace(Level.FINER, "Exception while closing input stream from server socket", e); + } + } while (true); + } catch (IOException e) { + LogAndTraceBroker.getBroker().trace(Level.FINER, "Exception while reading from server socket", e); + + if ( + e instanceof SocketTimeoutException || + WBEMConstants.INDICATION_DOS_EXCEPTION_MESSAGE.equalsIgnoreCase(e.getMessage()) + ) { + addSuspectIP(socket.getInetAddress().getHostAddress()); + } + } + try { + socket.close(); + } catch (IOException e) { + LogAndTraceBroker.getBroker().trace(Level.FINER, "Exception while closing server socket", e); + } + } + + /** + * Closes the handler. Will also close the content handler. + */ + public void close() { + this.iHandler.close(); + } + + private void writeError(ASCIIPrintStream dos, String title, String body) { + dos.print(" " + title + "" + body + ""); + } + + /** + * Get the IPs blocked by the listener associated with the specified port. + * + * @return The comma-separated list of blocked IPs. + */ + public synchronized String getBlockedIPs() { + return (this.iBlockedIPs == null) ? null : this.iBlockedIPs.toString(); + } + + /** + * Set the IPs to be blocked by the listener associated with the specified + * port. + * + * @param pIPs + * The comma-separated list of blocked IPs. + */ + public synchronized void setBlockedIPs(String pIPs) { + this.iBlockedIPs = (pIPs == null || pIPs.trim().length() == 0) ? null : new StringBuilder(pIPs); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpContentHandler.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpContentHandler.java similarity index 65% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpContentHandler.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpContentHandler.java index 561e0d6..76b571d 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpContentHandler.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpContentHandler.java @@ -1,80 +1,83 @@ -/* - (C) Copyright IBM Corp. 2005, 2011 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 17931 2005-07-28 thschaef Add InetAddress to CIM Event - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 3185818 2011-02-18 blaschke-oss indicationOccured URL incorrect - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.net.InetAddress; - -/** - * Class HttpContentHandler is responsible for handling the content of an http - * connection. - * - */ -public abstract class HttpContentHandler { - - /** - * Handles the content of a given connection - * - * @param pMessageReader - * The reader of the connection - * @param pMessageWriter - * The writer of the connection - * @param pInetAddress - * The remote network address - * @param pLocalAddress - * The local network address - * @throws HttpException - * @throws IOException - */ - public abstract void handleContent(MessageReader pMessageReader, MessageWriter pMessageWriter, - InetAddress pInetAddress, String pLocalAddress) throws HttpException, IOException; - - /** - * Closes the handler - */ - public abstract void close(); -} +/* + (C) Copyright IBM Corp. 2005, 2011 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 17931 2005-07-28 thschaef Add InetAddress to CIM Event + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 3185818 2011-02-18 blaschke-oss indicationOccured URL incorrect + */ + +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.net.InetAddress; + +/** + * Class HttpContentHandler is responsible for handling the content of an http + * connection. + * + */ +public abstract class HttpContentHandler { + + /** + * Handles the content of a given connection + * + * @param pMessageReader + * The reader of the connection + * @param pMessageWriter + * The writer of the connection + * @param pInetAddress + * The remote network address + * @param pLocalAddress + * The local network address + * @throws HttpException + * @throws IOException + */ + public abstract void handleContent( + MessageReader pMessageReader, + MessageWriter pMessageWriter, + InetAddress pInetAddress, + String pLocalAddress + ) + throws HttpException, IOException; + + /** + * Closes the handler + */ + public abstract void close(); +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpException.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpException.java similarity index 73% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpException.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpException.java index 65bb6c1..f371c5d 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpException.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpException.java @@ -1,117 +1,114 @@ -/* - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; - -/** - * Class HttpException represents HTTP related problems - * - */ -public class HttpException extends IOException { - - private static final long serialVersionUID = 934925248736106630L; - - int iStatus; - - /** - * Ctor. Equivalent to HttpException(-1, null, null) - */ - public HttpException() { - this(-1, null, null); - } - - /** - * Ctor. Equivalent to HttpException(-1, reason, null) - * - * @param reason - * The reason - */ - public HttpException(String reason) { - this(-1, reason, null); - } - - /** - * Ctor. Equivalent to HttpException(-1, reason, null) - * - * @param status - * The status - * @param reason - * The reason - */ - public HttpException(int status, String reason) { - this(status, reason, null); - } - - /** - * Ctor. Equivalent to HttpException(-1, reason, null) - * - * @param status - * The status - * @param reason - * The reason - * @param cimError - * The CIM error - */ - public HttpException(int status, String reason, String cimError) { - super(reason); - this.iStatus = status; - } - - /** - * Returns the status - * - * @return The status - */ - public int getStatus() { - return this.iStatus; - } - - @Override - public String toString() { - return super.toString() + "(status:" + this.iStatus + ")"; - } -} +/* + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; + +/** + * Class HttpException represents HTTP related problems + * + */ +public class HttpException extends IOException { + private static final long serialVersionUID = 934925248736106630L; + + int iStatus; + + /** + * Ctor. Equivalent to HttpException(-1, null, null) + */ + public HttpException() { + this(-1, null, null); + } + + /** + * Ctor. Equivalent to HttpException(-1, reason, null) + * + * @param reason + * The reason + */ + public HttpException(String reason) { + this(-1, reason, null); + } + + /** + * Ctor. Equivalent to HttpException(-1, reason, null) + * + * @param status + * The status + * @param reason + * The reason + */ + public HttpException(int status, String reason) { + this(status, reason, null); + } + + /** + * Ctor. Equivalent to HttpException(-1, reason, null) + * + * @param status + * The status + * @param reason + * The reason + * @param cimError + * The CIM error + */ + public HttpException(int status, String reason, String cimError) { + super(reason); + this.iStatus = status; + } + + /** + * Returns the status + * + * @return The status + */ + public int getStatus() { + return this.iStatus; + } + + @Override + public String toString() { + return super.toString() + "(status:" + this.iStatus + ")"; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpHeader.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpHeader.java similarity index 82% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpHeader.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpHeader.java index 123e5fd..c3db780 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpHeader.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpHeader.java @@ -1,538 +1,525 @@ -/* - (C) Copyright IBM Corp. 2005, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 17970 2005-08-11 pineiro5 Logon from z/OS not possible - * 1353138 2005-11-24 fiuczy CIMObject element in HTTP header wrong encoded - * 1535756 2006-08-07 lupusalex Make code warning free - * 1516242 2006-11-27 lupusalex Support of OpenPegasus local authentication - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 1688273 2007-04-19 lupusalex Full support of HTTP trailers - * 1715612 2007-05-09 lupusalex FVT: Status 0 in trailer is parsed as error - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2641758 2009-02-27 blaschke-oss CIM Client does not recognize HTTP extension headers - * 3304058 2011-05-20 blaschke-oss Use same date format in change history - * 3553858 2012-08-06 blaschke-oss Append duplicate HTTP header fields instead of replace - * 3601894 2013-01-23 blaschke-oss Enhance HTTP and CIM-XML tracing - * 2635 2013-05-16 blaschke-oss Slowloris DoS attack for CIM indication listener port - * 2718 2013-11-29 blaschke-oss Bad CIMStatusCode generates NumberFormatException - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.BufferedWriter; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStreamWriter; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.BitSet; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.logging.Level; - -import org.sentrysoftware.wbem.javax.wbem.WBEMException; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.io.ASCIIPrintStream; -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.io.TrailerException; -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.Messages; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConstants; - -/** - * Class HttpHeader represents a http header block - * - */ -public class HttpHeader { - - private static BitSet cDontNeedEncoding; - - private static final String HEX_STR = "0123456789ABCDEF"; - - private static String cDfltEncName = null; - - static { - cDontNeedEncoding = new BitSet(256); - int i; - for (i = 'a'; i <= 'z'; i++) { - cDontNeedEncoding.set(i); - } - for (i = 'A'; i <= 'Z'; i++) { - cDontNeedEncoding.set(i); - } - for (i = '0'; i <= '9'; i++) { - cDontNeedEncoding.set(i); - } - cDontNeedEncoding.set(' '); - cDontNeedEncoding.set('-'); - cDontNeedEncoding.set('_'); - cDontNeedEncoding.set('/'); - cDontNeedEncoding.set('.'); - cDontNeedEncoding.set('*'); - - } - - private Hashtable iFields = new Hashtable(); - - /** - * Ctor. - */ - public HttpHeader() { - // empty - } - - /** - * Ctor. Parses the header from an input stream - * - * @param pReader - * The input stream - * @throws IOException - */ - public HttpHeader(InputStream pReader) throws IOException { - this(pReader, 0); - } - - /** - * Ctor. Parses the header from an input stream - * - * @param pReader - * The input stream - * @param pTimeout - * Maximum allowable time to read header - * @throws IOException - */ - public HttpHeader(InputStream pReader, long pTimeout) throws IOException { - String line = null; - long timeStart = System.currentTimeMillis(); - // TODO: this needs to be optimized!!! - while (((line = HttpMethod.readLine(pReader)) != null) && (line.length() > 0)) { - // get the header - if (pTimeout > 0 && (System.currentTimeMillis() - timeStart > pTimeout)) { throw new IOException( - WBEMConstants.INDICATION_DOS_EXCEPTION_MESSAGE); } - try { - int separator; - if ((separator = line.indexOf(':')) > -1) { - String header; - String value; - int headerStartIndex = 0; - - // Ignore prefix-match from HTTP extension (RFC 2774), it'll - // look like "nn-" - if (line.indexOf('-') == 2 && Character.isDigit(line.charAt(0)) - && Character.isDigit(line.charAt(1))) { - headerStartIndex = 3; - } - - header = line.substring(headerStartIndex, separator); - value = line.substring(separator + 1); - // TODO validate header and value, they must not be empty - // entries - if (value.length() > 0 && value.startsWith(" ")) addParsedField(header, value - .substring(1)); - else addParsedField(header, value); - } else { - LogAndTraceBroker.getBroker().message(Messages.HTTP_INVALID_HEADER, line); - } - } catch (Exception e) { - LogAndTraceBroker.getBroker().trace(Level.FINER, - "Exception while parsing http header", e); - LogAndTraceBroker.getBroker().message(Messages.HTTP_INVALID_HEADER, line); - } - } - return; - } - - /** - * Adds a header field for client output (this means duplicate header - * entries are replaced) - * - * @param pName - * The name of the header field - * @param pValue - * The value - */ - public void addField(String pName, String pValue) { - if (pName == null || pName.length() == 0) return; - - if (pValue != null) { - this.iFields.put(new HeaderEntry(pName), pValue); - } else { - this.iFields.remove(new HeaderEntry(pName)); - } - } - - /** - * Adds a header field from parsed server input (this means duplicate header - * entries are appended in comma-separated list as defined by RFC 2616) - * - * @param pName - * The name of the header field - * @param pValue - * The value - */ - public void addParsedField(String pName, String pValue) { - if (pName == null || pName.length() == 0) return; - - if (pValue != null) { - String oldValue = this.iFields.put(new HeaderEntry(pName), pValue); - if (oldValue != null) { - // Field already exists, so append value to existing value; it - // is done checking put() return code, instead of checking get() - // return code prior to put(), because typical user case does - // not include duplicate fields - StringBuilder combinedValue = new StringBuilder(oldValue); - combinedValue.append(','); - combinedValue.append(pValue); - this.iFields.put(new HeaderEntry(pName), combinedValue.toString()); - } - } else { - this.iFields.remove(new HeaderEntry(pName)); - } - } - - /** - * Clears all header fields - */ - public void clear() { - this.iFields.clear(); - } - - /** - * Return an iterator over the header fields - * - * @return The iterator - */ - public Iterator> iterator() { - return this.iFields.entrySet().iterator(); - } - - /** - * Parses a line from a header block - * - * @param pLine - * The line - * @return The http header - */ - public static HttpHeader parse(String pLine) { - int prev = 0; - int next = 0; - HttpHeader header = new HttpHeader(); - if (pLine != null && pLine.length() > 0) { - next = pLine.indexOf(','); - while (next > -1) { - String hdr = pLine.substring(prev, next); - int separator = hdr.indexOf('='); - if (separator > -1) { - String key; - String value; - key = hdr.substring(0, separator); - value = hdr.substring(separator + 1); - - header.addParsedField(key, value); - } else { - // something goes wrong. no separator found - } - prev = next + 1; - while (Character.isSpaceChar(pLine.charAt(prev))) - prev++; - next = pLine.indexOf(',', prev); - } - String hdr = pLine.substring(prev); - int separator = hdr.indexOf('='); - if (separator > -1) { - header.addParsedField(hdr.substring(0, separator), hdr.substring(separator + 1)); - } - } - - return header; - } - - @Override - public String toString() { - StringBuffer buf = new StringBuffer(); - int i = 0; - Iterator> iterator = this.iFields.entrySet().iterator(); - while (iterator.hasNext()) { - if (i++ > 0) buf.append(','); - Entry entry = iterator.next(); - buf.append(entry.getKey().toString()); - buf.append(": "); - buf.append(entry.getValue().toString()); - } - return buf.toString(); - } - - /** - * Removes a field from the header - * - * @param pName - * The name of the field - */ - public void removeField(String pName) { - this.iFields.remove(new HeaderEntry(pName)); - } - - /** - * Returns a field from the header - * - * @param pName - * The name of the field - * @return The value - */ - public String getField(String pName) { - return this.iFields.get(new HeaderEntry(pName)); - } - - /** - * Writes a header block to a stream - * - * @param pWriter - * The stream - */ - public void write(ASCIIPrintStream pWriter) { - - Iterator> iterator = this.iFields.entrySet().iterator(); - while (iterator.hasNext()) { - Entry entry = iterator.next(); - pWriter.print(entry.getKey().toString()); - pWriter.print(": "); - pWriter.print(entry.getValue().toString()); - pWriter.print("\r\n"); - } - pWriter.print("\r\n"); - } - - /** - * Encodes raw data - * - * @param pData - * The raw data - * @return The encoded data - */ - public static synchronized String encode(byte[] pData) { - String str = null; - try { - if (cDfltEncName == null) cDfltEncName = (String) AccessController - .doPrivileged(new GetProperty("file.encoding")); - str = encode(pData, cDfltEncName); - } catch (UnsupportedEncodingException e) { - LogAndTraceBroker.getBroker().trace(Level.FINER, - "Exception while encoding http header data", e); - } - return str; - } - - /** - * Encodes raw data for a given character set - * - * @param pData - * The raw data - * @param pEnc - * The character set - * @return The encoded data - * @throws UnsupportedEncodingException - */ - public static String encode(byte[] pData, String pEnc) throws UnsupportedEncodingException { - - int maxBytesPerChar = 10; - // BufferedWriter validates encoding - ByteArrayOutputStream buf = new ByteArrayOutputStream(maxBytesPerChar); - new BufferedWriter(new OutputStreamWriter(buf, pEnc)); - StringBuffer out = new StringBuffer(pData.length); - - for (int i = 0; i < pData.length; i++) { - int c = pData[i] & 0xFF; - if (cDontNeedEncoding.get(c)) { - if (c == ' ') { - out.append("%20"); - } else { - out.append((char) c); - } - } else { - out.append('%'); - out.append(HEX_STR.charAt((c >> 4) & 0x0f)); - out.append(HEX_STR.charAt(c & 0x0f)); - } - } - - return out.toString(); - } - - /** - * Encodes a given string for a given character set - * - * @param pData - * The source string - * @param pSourceEnc - * The source character set - * @param pTargetEnc - * The target character set - * @return The encoded string - * @throws UnsupportedEncodingException - */ - public static String encode(String pData, String pSourceEnc, String pTargetEnc) - throws UnsupportedEncodingException { - - return encode(pData.getBytes(pSourceEnc), pTargetEnc); - } - - /** - * Class HeaderEntry represents a single header field - * - */ - public static class HeaderEntry { - - String iHeader; - - int iHashcode; - - /** - * Ctor. - * - * @param pName - * The name of the header field - */ - public HeaderEntry(String pName) { - this.iHeader = pName; - this.iHashcode = pName.toUpperCase().hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj == null || !(obj instanceof HeaderEntry)) return false; - return this.iHeader.equalsIgnoreCase(((HeaderEntry) obj).iHeader); - } - - @Override - public String toString() { - return this.iHeader; - } - - @Override - public int hashCode() { - return this.iHashcode; - } - } - - /** - * Class GetProperty implements privileged access to system properties - * - */ - private static class GetProperty implements PrivilegedAction { - - String iPropertyName; - - GetProperty(String propertyName) { - this.iPropertyName = propertyName; - } - - public Object run() { - return System.getProperty(this.iPropertyName); - } - } - - /** - * Throws a TrailerException if it contains recognized CIM errors in http - * trailer entries. - * - * @throws TrailerException - */ - public void examineTrailer() throws TrailerException { - examineTrailer(null); - } - - /** - * Throws a TrailerException if it contains recognized CIM errors in http - * trailer entries. - * - * @param pOrigin - * The origin of the trailer (response, request, etc.) - * @throws TrailerException - */ - public void examineTrailer(String pOrigin) throws TrailerException { - Iterator> itr = this.iterator(); - int code = 0, i = 0; - String desc = null; - StringBuilder hdrs = null; - if (LogAndTraceBroker.getBroker().isLoggableTrace(Level.FINER)) hdrs = new StringBuilder(); - while (itr.hasNext()) { - Entry ent = itr.next(); - String keyStr = ent.getKey().toString(); - if (hdrs != null) { - if (i++ > 0) hdrs.append(','); - hdrs.append(keyStr); - hdrs.append(": "); - hdrs.append(this.getField(keyStr)); - } - try { - if (keyStr.equalsIgnoreCase(WBEMConstants.HTTP_TRAILER_STATUS_CODE)) { - String valStr = URLDecoder.decode(this.getField(keyStr), WBEMConstants.UTF8); - try { - code = Integer.parseInt(valStr); - } catch (NumberFormatException e) { - String msg = new String(WBEMConstants.HTTP_TRAILER_STATUS_CODE + " \"" - + valStr + "\" invalid, setting to CIM_ERR_FAILED"); - LogAndTraceBroker.getBroker().trace(Level.FINER, msg, e); - code = WBEMException.CIM_ERR_FAILED; - if (desc == null) desc = msg; - } - } else if (keyStr.equalsIgnoreCase(WBEMConstants.HTTP_TRAILER_STATUS_DESCRIPTION)) { - desc = URLDecoder.decode(this.getField(keyStr), WBEMConstants.UTF8); - } - } catch (UnsupportedEncodingException e) { - // if UTF-8 isn't supported we're in real trouble - throw new Error(e); - } - } - if (hdrs != null && hdrs.length() > 0) LogAndTraceBroker.getBroker().trace( - Level.FINER, - (pOrigin == null ? "Unknown" : pOrigin) + " HTTP Trailer Headers= " - + hdrs.toString()); - if (code > 0) { - if (desc != null) { throw new TrailerException(new WBEMException(code, desc)); } - throw new TrailerException(new WBEMException(code)); - } - } -} +/* + (C) Copyright IBM Corp. 2005, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 17970 2005-08-11 pineiro5 Logon from z/OS not possible + * 1353138 2005-11-24 fiuczy CIMObject element in HTTP header wrong encoded + * 1535756 2006-08-07 lupusalex Make code warning free + * 1516242 2006-11-27 lupusalex Support of OpenPegasus local authentication + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 1688273 2007-04-19 lupusalex Full support of HTTP trailers + * 1715612 2007-05-09 lupusalex FVT: Status 0 in trailer is parsed as error + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2641758 2009-02-27 blaschke-oss CIM Client does not recognize HTTP extension headers + * 3304058 2011-05-20 blaschke-oss Use same date format in change history + * 3553858 2012-08-06 blaschke-oss Append duplicate HTTP header fields instead of replace + * 3601894 2013-01-23 blaschke-oss Enhance HTTP and CIM-XML tracing + * 2635 2013-05-16 blaschke-oss Slowloris DoS attack for CIM indication listener port + * 2718 2013-11-29 blaschke-oss Bad CIMStatusCode generates NumberFormatException + */ + +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.BufferedWriter; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.BitSet; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.logging.Level; +import org.metricshub.wbem.javax.wbem.WBEMException; +import org.metricshub.wbem.sblim.cimclient.internal.http.io.ASCIIPrintStream; +import org.metricshub.wbem.sblim.cimclient.internal.http.io.TrailerException; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; +import org.metricshub.wbem.sblim.cimclient.internal.logging.Messages; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConstants; + +/** + * Class HttpHeader represents a http header block + * + */ +public class HttpHeader { + private static BitSet cDontNeedEncoding; + + private static final String HEX_STR = "0123456789ABCDEF"; + + private static String cDfltEncName = null; + + static { + cDontNeedEncoding = new BitSet(256); + int i; + for (i = 'a'; i <= 'z'; i++) { + cDontNeedEncoding.set(i); + } + for (i = 'A'; i <= 'Z'; i++) { + cDontNeedEncoding.set(i); + } + for (i = '0'; i <= '9'; i++) { + cDontNeedEncoding.set(i); + } + cDontNeedEncoding.set(' '); + cDontNeedEncoding.set('-'); + cDontNeedEncoding.set('_'); + cDontNeedEncoding.set('/'); + cDontNeedEncoding.set('.'); + cDontNeedEncoding.set('*'); + } + + private Hashtable iFields = new Hashtable(); + + /** + * Ctor. + */ + public HttpHeader() { + // empty + } + + /** + * Ctor. Parses the header from an input stream + * + * @param pReader + * The input stream + * @throws IOException + */ + public HttpHeader(InputStream pReader) throws IOException { + this(pReader, 0); + } + + /** + * Ctor. Parses the header from an input stream + * + * @param pReader + * The input stream + * @param pTimeout + * Maximum allowable time to read header + * @throws IOException + */ + public HttpHeader(InputStream pReader, long pTimeout) throws IOException { + String line = null; + long timeStart = System.currentTimeMillis(); + // TODO: this needs to be optimized!!! + while (((line = HttpMethod.readLine(pReader)) != null) && (line.length() > 0)) { + // get the header + if (pTimeout > 0 && (System.currentTimeMillis() - timeStart > pTimeout)) { + throw new IOException(WBEMConstants.INDICATION_DOS_EXCEPTION_MESSAGE); + } + try { + int separator; + if ((separator = line.indexOf(':')) > -1) { + String header; + String value; + int headerStartIndex = 0; + + // Ignore prefix-match from HTTP extension (RFC 2774), it'll + // look like "nn-" + if (line.indexOf('-') == 2 && Character.isDigit(line.charAt(0)) && Character.isDigit(line.charAt(1))) { + headerStartIndex = 3; + } + + header = line.substring(headerStartIndex, separator); + value = line.substring(separator + 1); + // TODO validate header and value, they must not be empty + // entries + if (value.length() > 0 && value.startsWith(" ")) addParsedField( + header, + value.substring(1) + ); else addParsedField(header, value); + } else { + LogAndTraceBroker.getBroker().message(Messages.HTTP_INVALID_HEADER, line); + } + } catch (Exception e) { + LogAndTraceBroker.getBroker().trace(Level.FINER, "Exception while parsing http header", e); + LogAndTraceBroker.getBroker().message(Messages.HTTP_INVALID_HEADER, line); + } + } + return; + } + + /** + * Adds a header field for client output (this means duplicate header + * entries are replaced) + * + * @param pName + * The name of the header field + * @param pValue + * The value + */ + public void addField(String pName, String pValue) { + if (pName == null || pName.length() == 0) return; + + if (pValue != null) { + this.iFields.put(new HeaderEntry(pName), pValue); + } else { + this.iFields.remove(new HeaderEntry(pName)); + } + } + + /** + * Adds a header field from parsed server input (this means duplicate header + * entries are appended in comma-separated list as defined by RFC 2616) + * + * @param pName + * The name of the header field + * @param pValue + * The value + */ + public void addParsedField(String pName, String pValue) { + if (pName == null || pName.length() == 0) return; + + if (pValue != null) { + String oldValue = this.iFields.put(new HeaderEntry(pName), pValue); + if (oldValue != null) { + // Field already exists, so append value to existing value; it + // is done checking put() return code, instead of checking get() + // return code prior to put(), because typical user case does + // not include duplicate fields + StringBuilder combinedValue = new StringBuilder(oldValue); + combinedValue.append(','); + combinedValue.append(pValue); + this.iFields.put(new HeaderEntry(pName), combinedValue.toString()); + } + } else { + this.iFields.remove(new HeaderEntry(pName)); + } + } + + /** + * Clears all header fields + */ + public void clear() { + this.iFields.clear(); + } + + /** + * Return an iterator over the header fields + * + * @return The iterator + */ + public Iterator> iterator() { + return this.iFields.entrySet().iterator(); + } + + /** + * Parses a line from a header block + * + * @param pLine + * The line + * @return The http header + */ + public static HttpHeader parse(String pLine) { + int prev = 0; + int next = 0; + HttpHeader header = new HttpHeader(); + if (pLine != null && pLine.length() > 0) { + next = pLine.indexOf(','); + while (next > -1) { + String hdr = pLine.substring(prev, next); + int separator = hdr.indexOf('='); + if (separator > -1) { + String key; + String value; + key = hdr.substring(0, separator); + value = hdr.substring(separator + 1); + + header.addParsedField(key, value); + } else { + // something goes wrong. no separator found + } + prev = next + 1; + while (Character.isSpaceChar(pLine.charAt(prev))) prev++; + next = pLine.indexOf(',', prev); + } + String hdr = pLine.substring(prev); + int separator = hdr.indexOf('='); + if (separator > -1) { + header.addParsedField(hdr.substring(0, separator), hdr.substring(separator + 1)); + } + } + + return header; + } + + @Override + public String toString() { + StringBuffer buf = new StringBuffer(); + int i = 0; + Iterator> iterator = this.iFields.entrySet().iterator(); + while (iterator.hasNext()) { + if (i++ > 0) buf.append(','); + Entry entry = iterator.next(); + buf.append(entry.getKey().toString()); + buf.append(": "); + buf.append(entry.getValue().toString()); + } + return buf.toString(); + } + + /** + * Removes a field from the header + * + * @param pName + * The name of the field + */ + public void removeField(String pName) { + this.iFields.remove(new HeaderEntry(pName)); + } + + /** + * Returns a field from the header + * + * @param pName + * The name of the field + * @return The value + */ + public String getField(String pName) { + return this.iFields.get(new HeaderEntry(pName)); + } + + /** + * Writes a header block to a stream + * + * @param pWriter + * The stream + */ + public void write(ASCIIPrintStream pWriter) { + Iterator> iterator = this.iFields.entrySet().iterator(); + while (iterator.hasNext()) { + Entry entry = iterator.next(); + pWriter.print(entry.getKey().toString()); + pWriter.print(": "); + pWriter.print(entry.getValue().toString()); + pWriter.print("\r\n"); + } + pWriter.print("\r\n"); + } + + /** + * Encodes raw data + * + * @param pData + * The raw data + * @return The encoded data + */ + public static synchronized String encode(byte[] pData) { + String str = null; + try { + if (cDfltEncName == null) cDfltEncName = (String) AccessController.doPrivileged(new GetProperty("file.encoding")); + str = encode(pData, cDfltEncName); + } catch (UnsupportedEncodingException e) { + LogAndTraceBroker.getBroker().trace(Level.FINER, "Exception while encoding http header data", e); + } + return str; + } + + /** + * Encodes raw data for a given character set + * + * @param pData + * The raw data + * @param pEnc + * The character set + * @return The encoded data + * @throws UnsupportedEncodingException + */ + public static String encode(byte[] pData, String pEnc) throws UnsupportedEncodingException { + int maxBytesPerChar = 10; + // BufferedWriter validates encoding + ByteArrayOutputStream buf = new ByteArrayOutputStream(maxBytesPerChar); + new BufferedWriter(new OutputStreamWriter(buf, pEnc)); + StringBuffer out = new StringBuffer(pData.length); + + for (int i = 0; i < pData.length; i++) { + int c = pData[i] & 0xFF; + if (cDontNeedEncoding.get(c)) { + if (c == ' ') { + out.append("%20"); + } else { + out.append((char) c); + } + } else { + out.append('%'); + out.append(HEX_STR.charAt((c >> 4) & 0x0f)); + out.append(HEX_STR.charAt(c & 0x0f)); + } + } + + return out.toString(); + } + + /** + * Encodes a given string for a given character set + * + * @param pData + * The source string + * @param pSourceEnc + * The source character set + * @param pTargetEnc + * The target character set + * @return The encoded string + * @throws UnsupportedEncodingException + */ + public static String encode(String pData, String pSourceEnc, String pTargetEnc) throws UnsupportedEncodingException { + return encode(pData.getBytes(pSourceEnc), pTargetEnc); + } + + /** + * Class HeaderEntry represents a single header field + * + */ + public static class HeaderEntry { + String iHeader; + + int iHashcode; + + /** + * Ctor. + * + * @param pName + * The name of the header field + */ + public HeaderEntry(String pName) { + this.iHeader = pName; + this.iHashcode = pName.toUpperCase().hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == null || !(obj instanceof HeaderEntry)) return false; + return this.iHeader.equalsIgnoreCase(((HeaderEntry) obj).iHeader); + } + + @Override + public String toString() { + return this.iHeader; + } + + @Override + public int hashCode() { + return this.iHashcode; + } + } + + /** + * Class GetProperty implements privileged access to system properties + * + */ + private static class GetProperty implements PrivilegedAction { + String iPropertyName; + + GetProperty(String propertyName) { + this.iPropertyName = propertyName; + } + + public Object run() { + return System.getProperty(this.iPropertyName); + } + } + + /** + * Throws a TrailerException if it contains recognized CIM errors in http + * trailer entries. + * + * @throws TrailerException + */ + public void examineTrailer() throws TrailerException { + examineTrailer(null); + } + + /** + * Throws a TrailerException if it contains recognized CIM errors in http + * trailer entries. + * + * @param pOrigin + * The origin of the trailer (response, request, etc.) + * @throws TrailerException + */ + public void examineTrailer(String pOrigin) throws TrailerException { + Iterator> itr = this.iterator(); + int code = 0, i = 0; + String desc = null; + StringBuilder hdrs = null; + if (LogAndTraceBroker.getBroker().isLoggableTrace(Level.FINER)) hdrs = new StringBuilder(); + while (itr.hasNext()) { + Entry ent = itr.next(); + String keyStr = ent.getKey().toString(); + if (hdrs != null) { + if (i++ > 0) hdrs.append(','); + hdrs.append(keyStr); + hdrs.append(": "); + hdrs.append(this.getField(keyStr)); + } + try { + if (keyStr.equalsIgnoreCase(WBEMConstants.HTTP_TRAILER_STATUS_CODE)) { + String valStr = URLDecoder.decode(this.getField(keyStr), WBEMConstants.UTF8); + try { + code = Integer.parseInt(valStr); + } catch (NumberFormatException e) { + String msg = new String( + WBEMConstants.HTTP_TRAILER_STATUS_CODE + " \"" + valStr + "\" invalid, setting to CIM_ERR_FAILED" + ); + LogAndTraceBroker.getBroker().trace(Level.FINER, msg, e); + code = WBEMException.CIM_ERR_FAILED; + if (desc == null) desc = msg; + } + } else if (keyStr.equalsIgnoreCase(WBEMConstants.HTTP_TRAILER_STATUS_DESCRIPTION)) { + desc = URLDecoder.decode(this.getField(keyStr), WBEMConstants.UTF8); + } + } catch (UnsupportedEncodingException e) { + // if UTF-8 isn't supported we're in real trouble + throw new Error(e); + } + } + if (hdrs != null && hdrs.length() > 0) LogAndTraceBroker + .getBroker() + .trace(Level.FINER, (pOrigin == null ? "Unknown" : pOrigin) + " HTTP Trailer Headers= " + hdrs.toString()); + if (code > 0) { + if (desc != null) { + throw new TrailerException(new WBEMException(code, desc)); + } + throw new TrailerException(new WBEMException(code)); + } + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpHeaderParser.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpHeaderParser.java similarity index 78% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpHeaderParser.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpHeaderParser.java index f4a7ffc..86949b9 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpHeaderParser.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpHeaderParser.java @@ -1,245 +1,240 @@ -/* - (C) Copyright IBM Corp. 2005, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al - * 3001353 2010-05-18 blaschke-oss HttpHeaderParser ignores return value of toLowerCase() - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Vector; - -/** - * Class HttpHeaderParser parses http headers - * - */ -public class HttpHeaderParser { - - String iRaw; - - Vector iNameValuePair; - - /** - * Ctor. - * - * @param pHeader - * The header block - */ - public HttpHeaderParser(String pHeader) { - this.iRaw = pHeader; - this.iNameValuePair = new Vector(); - if (this.iRaw != null) { - this.iRaw = this.iRaw.trim(); - char charArray[] = this.iRaw.toCharArray(); - int startPosValue = 0; - int currentPos = 0; - boolean isName = true; - boolean withinQuote = false; - int len = charArray.length; - String nvp[] = new String[2]; - do { - char c = charArray[currentPos]; - if (c == '=') { - nvp[0] = (new String(charArray, startPosValue, currentPos - startPosValue)) - .toLowerCase(); - isName = false; - startPosValue = ++currentPos; - } else if (c == '"') { - if (withinQuote) { - nvp[1] = new String(charArray, startPosValue, currentPos - startPosValue); - this.iNameValuePair.add(nvp); - nvp = new String[2]; - withinQuote = false; - while (++currentPos < len - && (charArray[currentPos] == ' ' || charArray[currentPos] == ',' || charArray[currentPos] == ';')) { - // ignore spaces and preceding comma - } - isName = true; - startPosValue = currentPos; - } else { - withinQuote = true; - startPosValue = ++currentPos; - } - } else if (c == ' ' || c == ',' || c == ';') { - if (withinQuote) { - currentPos++; - } else { - if (isName) { - nvp[0] = (new String(charArray, startPosValue, currentPos - - startPosValue)).toLowerCase(); - this.iNameValuePair.add(nvp); - nvp = new String[2]; - } else { - nvp[1] = new String(charArray, startPosValue, currentPos - - startPosValue); - this.iNameValuePair.add(nvp); - nvp = new String[2]; - } - - while (++currentPos < len - && (charArray[currentPos] == ' ' || charArray[currentPos] == ',' || charArray[currentPos] == ';')) { - // ignore spaces and preceding comma - } - isName = true; - startPosValue = currentPos; - } - } else { - currentPos++; - } - } while (currentPos < len); - - if (--currentPos > startPosValue) { - if (!isName) { - if (charArray[currentPos] == '"') { - nvp[1] = new String(charArray, startPosValue, currentPos - startPosValue); - this.iNameValuePair.add(nvp); - nvp = new String[2]; - } else { - nvp[1] = new String(charArray, startPosValue, - (currentPos - startPosValue) + 1); - this.iNameValuePair.add(nvp); - nvp = new String[2]; - } - } else { - nvp[0] = (new String(charArray, startPosValue, (currentPos - startPosValue) + 1)) - .toLowerCase(); - } - this.iNameValuePair.add(nvp); - } else if (currentPos == startPosValue) { - if (!isName) { - if (charArray[currentPos] == '"') { - nvp[1] = String.valueOf(charArray[currentPos - 1]); - this.iNameValuePair.add(nvp); - nvp = new String[2]; - } else { - nvp[1] = String.valueOf(charArray[currentPos]); - this.iNameValuePair.add(nvp); - nvp = new String[2]; - } - } else { - nvp[0] = String.valueOf(charArray[currentPos]).toLowerCase(); - } - this.iNameValuePair.add(nvp); - } - } - } - - /** - * Returns the header field at a given index - * - * @param pIndex - * The index - * @return The field name - */ - public String getField(int pIndex) { - if (pIndex < 0 || pIndex > this.iNameValuePair.size()) return null; - return this.iNameValuePair.elementAt(pIndex)[0]; - } - - /** - * Returns the value of a header field at a given index - * - * @param pIndex - * @return The value - */ - public String getValue(int pIndex) { - if (pIndex < 0 || pIndex > this.iNameValuePair.size()) return null; - return this.iNameValuePair.elementAt(pIndex)[1]; - } - - /** - * Returns the value of a header field for a given name - * - * @param pName - * The name - * @return The value - */ - public String getValue(String pName) { - return getValue(pName, null); - } - - /** - * Returns the value of a header field for a given name specifying a - * default. - * - * @param pName - * The name of the header field - * @param pDefault - * The value returned if no field of the given name exists - * @return The value - */ - public String getValue(String pName, String pDefault) { - if (pName == null) return pDefault; - pName = pName.toLowerCase(); - for (int i = 0; i < this.iNameValuePair.size(); i++) { - if (this.iNameValuePair.elementAt(i)[0] == null) return pDefault; - if (pName.equals(this.iNameValuePair.elementAt(i)[0])) return this.iNameValuePair - .elementAt(i)[1]; - } - return pDefault; - } - - /** - * Returns the value of a numeric header field for a given name specifying a - * default. - * - * @param pName - * The name of the header field - * @param pDefault - * The value returned if no field of the given name exists - * @return The value - */ - public int getIntValue(String pName, int pDefault) { - try { - return Integer.parseInt(getValue(pName, String.valueOf(pDefault))); - } catch (Exception e) { - return pDefault; - } - } - - @Override - public String toString() { - return "raw:" + this.iRaw; - } -} +/* + (C) Copyright IBM Corp. 2005, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al + * 3001353 2010-05-18 blaschke-oss HttpHeaderParser ignores return value of toLowerCase() + */ + +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Vector; + +/** + * Class HttpHeaderParser parses http headers + * + */ +public class HttpHeaderParser { + String iRaw; + + Vector iNameValuePair; + + /** + * Ctor. + * + * @param pHeader + * The header block + */ + public HttpHeaderParser(String pHeader) { + this.iRaw = pHeader; + this.iNameValuePair = new Vector(); + if (this.iRaw != null) { + this.iRaw = this.iRaw.trim(); + char charArray[] = this.iRaw.toCharArray(); + int startPosValue = 0; + int currentPos = 0; + boolean isName = true; + boolean withinQuote = false; + int len = charArray.length; + String nvp[] = new String[2]; + do { + char c = charArray[currentPos]; + if (c == '=') { + nvp[0] = (new String(charArray, startPosValue, currentPos - startPosValue)).toLowerCase(); + isName = false; + startPosValue = ++currentPos; + } else if (c == '"') { + if (withinQuote) { + nvp[1] = new String(charArray, startPosValue, currentPos - startPosValue); + this.iNameValuePair.add(nvp); + nvp = new String[2]; + withinQuote = false; + while ( + ++currentPos < len && + (charArray[currentPos] == ' ' || charArray[currentPos] == ',' || charArray[currentPos] == ';') + ) { + // ignore spaces and preceding comma + } + isName = true; + startPosValue = currentPos; + } else { + withinQuote = true; + startPosValue = ++currentPos; + } + } else if (c == ' ' || c == ',' || c == ';') { + if (withinQuote) { + currentPos++; + } else { + if (isName) { + nvp[0] = (new String(charArray, startPosValue, currentPos - startPosValue)).toLowerCase(); + this.iNameValuePair.add(nvp); + nvp = new String[2]; + } else { + nvp[1] = new String(charArray, startPosValue, currentPos - startPosValue); + this.iNameValuePair.add(nvp); + nvp = new String[2]; + } + + while ( + ++currentPos < len && + (charArray[currentPos] == ' ' || charArray[currentPos] == ',' || charArray[currentPos] == ';') + ) { + // ignore spaces and preceding comma + } + isName = true; + startPosValue = currentPos; + } + } else { + currentPos++; + } + } while (currentPos < len); + + if (--currentPos > startPosValue) { + if (!isName) { + if (charArray[currentPos] == '"') { + nvp[1] = new String(charArray, startPosValue, currentPos - startPosValue); + this.iNameValuePair.add(nvp); + nvp = new String[2]; + } else { + nvp[1] = new String(charArray, startPosValue, (currentPos - startPosValue) + 1); + this.iNameValuePair.add(nvp); + nvp = new String[2]; + } + } else { + nvp[0] = (new String(charArray, startPosValue, (currentPos - startPosValue) + 1)).toLowerCase(); + } + this.iNameValuePair.add(nvp); + } else if (currentPos == startPosValue) { + if (!isName) { + if (charArray[currentPos] == '"') { + nvp[1] = String.valueOf(charArray[currentPos - 1]); + this.iNameValuePair.add(nvp); + nvp = new String[2]; + } else { + nvp[1] = String.valueOf(charArray[currentPos]); + this.iNameValuePair.add(nvp); + nvp = new String[2]; + } + } else { + nvp[0] = String.valueOf(charArray[currentPos]).toLowerCase(); + } + this.iNameValuePair.add(nvp); + } + } + } + + /** + * Returns the header field at a given index + * + * @param pIndex + * The index + * @return The field name + */ + public String getField(int pIndex) { + if (pIndex < 0 || pIndex > this.iNameValuePair.size()) return null; + return this.iNameValuePair.elementAt(pIndex)[0]; + } + + /** + * Returns the value of a header field at a given index + * + * @param pIndex + * @return The value + */ + public String getValue(int pIndex) { + if (pIndex < 0 || pIndex > this.iNameValuePair.size()) return null; + return this.iNameValuePair.elementAt(pIndex)[1]; + } + + /** + * Returns the value of a header field for a given name + * + * @param pName + * The name + * @return The value + */ + public String getValue(String pName) { + return getValue(pName, null); + } + + /** + * Returns the value of a header field for a given name specifying a + * default. + * + * @param pName + * The name of the header field + * @param pDefault + * The value returned if no field of the given name exists + * @return The value + */ + public String getValue(String pName, String pDefault) { + if (pName == null) return pDefault; + pName = pName.toLowerCase(); + for (int i = 0; i < this.iNameValuePair.size(); i++) { + if (this.iNameValuePair.elementAt(i)[0] == null) return pDefault; + if (pName.equals(this.iNameValuePair.elementAt(i)[0])) return this.iNameValuePair.elementAt(i)[1]; + } + return pDefault; + } + + /** + * Returns the value of a numeric header field for a given name specifying a + * default. + * + * @param pName + * The name of the header field + * @param pDefault + * The value returned if no field of the given name exists + * @return The value + */ + public int getIntValue(String pName, int pDefault) { + try { + return Integer.parseInt(getValue(pName, String.valueOf(pDefault))); + } catch (Exception e) { + return pDefault; + } + } + + @Override + public String toString() { + return "raw:" + this.iRaw; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpMethod.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpMethod.java similarity index 73% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpMethod.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpMethod.java index 22cd891..6525315 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpMethod.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpMethod.java @@ -1,120 +1,116 @@ -/* - (C) Copyright IBM Corp. 2005, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 12917 2004-11-11 thschaef HTTP Header parsing does not work for UNIX line delimitor - * 1535756 2006-08-07 lupusalex Make code warning free - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al - * 3557283 2012-11-05 blaschke-oss Print full response when get EOF from CIMOM - * 2709 2013-11-13 blaschke-oss Lower the level of the EOF message to FINE - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.io.InputStream; -import java.util.logging.Level; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; - -/** - * Class HttpMethod provides a method to read a line from a given input stream - * - */ -public abstract class HttpMethod { - - /** - * Reads a line from a given input stream - * - * @param pStream - * The input stream - * @return The line - * @throws IOException - */ - public static String readLine(InputStream pStream) throws IOException { - - if (pStream == null) return null; - - char buffer[] = new char[16]; - int used = 0; - int prevChar; - boolean flag = true; - - for (; (prevChar = pStream.read()) >= 0; buffer[used++] = (char) prevChar) { - - flag = false; - - // @12917 - thschaef - // see http://www.w3.org/Protocols/HTTP/AsImplemented.html for - // details - // Lines shall be delimited by an optional carriage return followed - // by a mandatory line feed character. - // The client should not assume that the carriage return will be - // present. Lines may be of any length. - // Well-behaved servers should restrict line length to 80 characters - // excluding the CR LF pair. - - // if (prevChar == 13) continue; - if (prevChar == 10) break; - - if (used >= buffer.length) { - char tmp[] = new char[buffer.length << 1]; - System.arraycopy(buffer, 0, tmp, 0, used); - buffer = tmp; - } - } - if (flag) { - LogAndTraceBroker - .getBroker() - .trace( - Level.FINE, - "Unexpected EOF trying to read line from input stream - CIMOM closed its end of socket, check it for connection issues"); - throw new IOException("Unexpected EOF"); - } - - for (; used > 0 && buffer[used - 1] <= ' '; used--) { - // back up over blanks and non-printables at end of line - } - - return String.copyValueOf(buffer, 0, used); - } -} +/* + (C) Copyright IBM Corp. 2005, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 12917 2004-11-11 thschaef HTTP Header parsing does not work for UNIX line delimitor + * 1535756 2006-08-07 lupusalex Make code warning free + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2750520 2009-04-10 blaschke-oss Code cleanup from empty statement et al + * 3557283 2012-11-05 blaschke-oss Print full response when get EOF from CIMOM + * 2709 2013-11-13 blaschke-oss Lower the level of the EOF message to FINE + */ + +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.io.InputStream; +import java.util.logging.Level; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; + +/** + * Class HttpMethod provides a method to read a line from a given input stream + * + */ +public abstract class HttpMethod { + + /** + * Reads a line from a given input stream + * + * @param pStream + * The input stream + * @return The line + * @throws IOException + */ + public static String readLine(InputStream pStream) throws IOException { + if (pStream == null) return null; + + char buffer[] = new char[16]; + int used = 0; + int prevChar; + boolean flag = true; + + for (; (prevChar = pStream.read()) >= 0; buffer[used++] = (char) prevChar) { + flag = false; + + // @12917 - thschaef + // see http://www.w3.org/Protocols/HTTP/AsImplemented.html for + // details + // Lines shall be delimited by an optional carriage return followed + // by a mandatory line feed character. + // The client should not assume that the carriage return will be + // present. Lines may be of any length. + // Well-behaved servers should restrict line length to 80 characters + // excluding the CR LF pair. + + // if (prevChar == 13) continue; + if (prevChar == 10) break; + + if (used >= buffer.length) { + char tmp[] = new char[buffer.length << 1]; + System.arraycopy(buffer, 0, tmp, 0, used); + buffer = tmp; + } + } + if (flag) { + LogAndTraceBroker + .getBroker() + .trace( + Level.FINE, + "Unexpected EOF trying to read line from input stream - CIMOM closed its end of socket, check it for connection issues" + ); + throw new IOException("Unexpected EOF"); + } + + for (; used > 0 && buffer[used - 1] <= ' '; used--) { + // back up over blanks and non-printables at end of line + } + + return String.copyValueOf(buffer, 0, used); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpParseException.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpParseException.java similarity index 65% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpParseException.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpParseException.java index fa0e013..b10d459 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpParseException.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpParseException.java @@ -1,72 +1,69 @@ -/* - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * Class HttpParseException represents problems parsing http challenges - * - */ -public class HttpParseException extends HttpException { - - private static final long serialVersionUID = -6546559439537187479L; - - /** - * Ctor. - */ - public HttpParseException() { - super(); - } - - /** - * Ctor. - * - * @param pReason - * The reason - */ - public HttpParseException(String pReason) { - super(pReason); - } -} +/* + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * Class HttpParseException represents problems parsing http challenges + * + */ +public class HttpParseException extends HttpException { + private static final long serialVersionUID = -6546559439537187479L; + + /** + * Ctor. + */ + public HttpParseException() { + super(); + } + + /** + * Ctor. + * + * @param pReason + * The reason + */ + public HttpParseException(String pReason) { + super(pReason); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpServerConnection.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpServerConnection.java similarity index 70% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpServerConnection.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpServerConnection.java index deb2604..45d3c53 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpServerConnection.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpServerConnection.java @@ -1,444 +1,439 @@ -/* - (C) Copyright IBM Corp. 2005, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1422316 2005-05-08 lupusalex Disable delayed acknowledgment - * 1483270 2006-05-15 lupusalex Using Several Cim Clients cause an indication problem - * 1498130 2006-05-31 lupusalex Selection of xml parser on a per connection basis - * 1535756 2006-08-07 lupusalex Make code warning free - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 1649779 2007-02-01 lupusalex Indication listener threads freeze - * 1660743 2007-02-15 lupusalex SSLContext is static - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2210455 2008-10-30 blaschke-oss Enhance javadoc, fix potential null pointers - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 3027392 2010-07-09 blaschke-oss Nullcheck of value previously dereferenced - * 3206904 2011-03-11 lupusalex Indication listener deadlock causes JVM to run out sockets - * 3536399 2012-08-25 hellerda Add client/listener peer authentication properties - * 2618 2013-02-27 blaschke-oss Need to add property to disable weak cipher suites for the secure indication - * 2642 2013-05-21 blaschke-oss Seperate properties needed for cim client and listener to filter out ciphers - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.net.InetAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.SocketException; -import java.net.UnknownHostException; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; - -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLServerSocket; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.ThreadPool; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.Util; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConfiguration; - -/** - * Class HttpServerConnection implements the outer shell of a HTTP server. It - * accepts incoming connections and puts them in a queue to be serviced by an - * independent thread - * - */ -public class HttpServerConnection implements Runnable { - - private int iPort; - - private ServerSocket iServerSocket; - - private HttpConnectionHandler iHandler; - - private HttpConnectionDispatcher iDispatcher; - - private volatile boolean iClose = true; - - private String iServerName; - - private boolean iSsl; - - private Thread iRunner; - - private WBEMConfiguration iSessionProperties; - - private final int iTimeout; - - /** - * Ctor. - * - * @param pHandler - * The connection handler - * @param pLocalAddress - * The local address to bind the port to. If null the port is - * bound to all local addresses. For use on multi-homed systems - * @param pPort - * The local port. If zero any free port will be chosen. - * @param pSsl - * SSL secured connection ? - * @param pProperties - * The configuration context - * @throws IOException - */ - public HttpServerConnection(HttpConnectionHandler pHandler, String pLocalAddress, int pPort, - boolean pSsl, WBEMConfiguration pProperties) throws IOException { - - final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - - this.iPort = pPort; - this.iHandler = pHandler; - this.iSsl = pSsl; - this.iServerName = pSsl ? "HTTPS Server" : "HTTP Server"; - this.iSessionProperties = (pProperties != null) ? pProperties : WBEMConfiguration - .getGlobalConfiguration(); - SSLContext sslContext = pSsl ? HttpSocketFactory.getInstance().getServerSSLContext( - this.iSessionProperties) : null; - this.iServerSocket = (pLocalAddress != null && pLocalAddress.length() > 0) ? HttpSocketFactory - .getInstance().getServerSocketFactory(sslContext).createServerSocket(pPort, 50, - InetAddress.getByName(pLocalAddress)) - : HttpSocketFactory.getInstance().getServerSocketFactory(sslContext) - .createServerSocket(pPort); - if (this.iServerSocket instanceof SSLServerSocket) { - if (this.iSessionProperties.getSslListenerPeerVerification().equalsIgnoreCase("ignore")) { - logger.trace(Level.FINER, "Listener peer verification: ignore"); - ((SSLServerSocket) this.iServerSocket).setNeedClientAuth(false); - } else if (this.iSessionProperties.getSslListenerPeerVerification().equalsIgnoreCase( - "accept")) { - logger.trace(Level.FINER, "Listener peer verification: accept"); - ((SSLServerSocket) this.iServerSocket).setWantClientAuth(true); - } else { - logger.trace(Level.FINER, "Listener peer verification: require"); - ((SSLServerSocket) this.iServerSocket).setNeedClientAuth(true); - } - - String disableCipherSuites = this.iSessionProperties - .getSslListenerCipherSuitesToDisable(); - if (disableCipherSuites != null) { - SSLServerSocket sslSock = (SSLServerSocket) this.iServerSocket; - String[] currentCipherSuites = sslSock.getEnabledCipherSuites(); - String[] updatedCipherSuites = Util.getFilteredStringArray(currentCipherSuites, - disableCipherSuites); - sslSock.setEnabledCipherSuites(updatedCipherSuites); - int before = currentCipherSuites.length; - int after = updatedCipherSuites.length; - if (before > 0 && after == 0) logger.trace(Level.WARNING, - "All cipher suites disabled for listener!"); - else if (before > after) logger.trace(Level.FINE, "Some (" + (before - after) - + ") cipher suites disabled for listener"); - else if (before == after) logger.trace(Level.FINER, - "No cipher suites disabled for listener"); - } - } - this.iTimeout = this.iSessionProperties.getListenerHttpTimeout(); - logger.exit(); - } - - /** - * Set the name of the thread - * - * @param pName - * The new value - */ - public void setName(String pName) { - if (this.iRunner != null) this.iRunner.setName(pName); - } - - /** - * Returns the port - * - * @return The port - */ - public int getPort() { - return this.iServerSocket.getLocalPort(); - } - - /** - * Returns the local ip address the socket is bound to - * - * @return The ip address - * @throws UnknownHostException - */ - public String getLocalIp() throws UnknownHostException { - String ip = this.iServerSocket.getInetAddress().getHostAddress(); - String localhost = InetAddress.getLocalHost().getHostAddress(); - return "0.0.0.0".equals(ip) ? localhost : ip; - } - - /** - * Returns the local hostname the socket is bound to - * - * @return The host name - * @throws UnknownHostException - */ - public String getLocalHostName() throws UnknownHostException { - String ip = this.iServerSocket.getInetAddress().getHostName(); - String localhost = InetAddress.getLocalHost().getHostName(); - return "0.0.0.0".equals(ip) ? localhost : ip; - } - - /** - * Return whether this connection is SSL secured - * - * @return true if SSL is enabled, false otherwise - */ - public boolean isSSL() { - return this.iSsl; - } - - /** - * Starts a thread that waits for incoming connections - */ - public void start() { - if (this.iClose) { - this.iClose = false; - ThreadGroup group = new ThreadGroup("CIMListener on port " + String.valueOf(this.iPort)); - this.iDispatcher = new HttpConnectionDispatcher(group, this.iHandler, new ThreadPool( - this.iSessionProperties.getListenerMinPoolSize(), this.iSessionProperties - .getListenerMaxPoolSize(), - this.iSessionProperties.getListenerBacklog(), this.iSessionProperties - .getListenerMaxIdle(), group, "Handler "), this.iSessionProperties - .getListenerMaxQueueSize()); - this.iDispatcher.start(); - this.iRunner = new Thread(group, this, this.iServerName); - this.iRunner.setDaemon(true); - - this.iRunner.start(); - } - } - - public void run() { - while (!this.iClose) { - try { - Socket socket = this.iServerSocket.accept(); - try { - socket.setTcpNoDelay(true); - socket.setSoTimeout(this.iTimeout); - } catch (IOException e) { - LogAndTraceBroker.getBroker().trace(Level.FINE, - "Exception while adjusting socket options", e); - } - boolean dispatched = this.iDispatcher.dispatch(socket); - if (!dispatched) { - MessageWriter writer = new MessageWriter(socket.getOutputStream(), false, false); - try { - writer.setMethod(new HttpServerMethod(1, 1, 503, - "Service temporarily overloaded")); - writer.getHeader().addField("Retry-After", "10"); - writer.close(); - } catch (IOException e) { - LogAndTraceBroker.getBroker().trace(Level.FINE, - "Exception while sending HTTP 503", e); - } finally { - socket.close(); - } - LogAndTraceBroker - .getBroker() - .trace(Level.FINE, - "HttpServerConnection failed to dispatch incoming connection, sent 503"); - } else { - LogAndTraceBroker.getBroker().trace(Level.FINE, - "HttpServerConnection dispatched incoming connection"); - } - } catch (Throwable t) { - if (t instanceof SocketException && this.iClose) { - break; - } - try { - LogAndTraceBroker.getBroker().trace(Level.FINE, - "Exception while waiting for incoming http connections"); - } catch (Throwable t2) { - // just give up - } - } - } - - // shutdown - - try { - LogAndTraceBroker.getBroker().trace(Level.FINE, - "Shutting down CIMListener on port " + this.iPort); - } catch (Throwable t) { - // do nothing - } - try { - // give the handlers a chance to process all already accepted - // connections before complete shutdown - Thread.sleep(5000); - } catch (InterruptedException e) { - // just ignore - } - try { - this.iDispatcher.close(); - } catch (Exception e) { - LogAndTraceBroker.getBroker().trace(Level.FINE, - "Exception while closing http connection dispatcher", e); - } - this.iDispatcher = null; - this.iRunner = null; - } - - /** - * Closes the socket and shuts down the listening threads - */ - public void close() { - if (!this.iClose) { - this.iClose = true; - try { - this.iServerSocket.close(); - this.iServerSocket = null; - } catch (Exception e) { - LogAndTraceBroker.getBroker().trace(Level.FINE, - "Exception while closing server socket", e); - } - } - } - - /** - * Class HttpConnectionDispatcher is responsible for dispatching the - * incoming connections to the handlers. It doesn't execute the handler - * directly but creates a runnable that is submitted to a thread pool which - * takes care of execution. - * - */ - private static class HttpConnectionDispatcher extends Thread { - - private BlockingQueue iConnectionPool; - - private volatile boolean iAlive = true; - - private HttpConnectionHandler iHandler; - - private ThreadPool iThreadPool; - - /** - * Ctor. - * - * @param pGroup - * The thread group to use for this thread and it's children - * @param pHandler - * The connection handler - * @param pPool - * The thread pool - * @param pQueueSize - * The fixed capacity for the queue of pending connections - */ - public HttpConnectionDispatcher(ThreadGroup pGroup, HttpConnectionHandler pHandler, - ThreadPool pPool, int pQueueSize) { - super(pGroup, "Connection Dispatcher"); - setDaemon(true); - this.iConnectionPool = new ArrayBlockingQueue(pQueueSize > 0 ? pQueueSize : 1); - this.iHandler = pHandler; - this.iThreadPool = pPool; - } - - /** - * Dispatches a connection - * - * @param pSocket - * The socket of the connection - * @return true if dispatch was successful - */ - public boolean dispatch(Socket pSocket) { - try { - return this.iConnectionPool.offer(pSocket, 20, TimeUnit.MILLISECONDS); - } catch (InterruptedException e) { - /* */ - } - return false; - } - - /** - * Gets the next pending connection - * - * @return The socket of the connection - */ - public Socket getConnection() { - try { - return this.iConnectionPool.poll(100, TimeUnit.MILLISECONDS); - } catch (InterruptedException e) { - // just ignore it, it is expected - } - return null; - } - - @Override - public void run() { - while (this.iAlive) { - try { - Socket socket = getConnection(); - if (socket != null) { - this.iThreadPool.execute(new HttpServerWorker(this.iHandler, socket)); - } - } catch (Throwable t) { - try { - LogAndTraceBroker.getBroker().trace(Level.FINE, - "Exception while submitting worker to thread pool", t); - } catch (Throwable t1) { - // forget it - } - } - } - try { - this.iHandler.close(); - } catch (Exception e) { - LogAndTraceBroker.getBroker().trace(Level.FINE, - "Exception while closing http connection handler", e); - } - try { - this.iThreadPool.shutdown(); - } catch (Exception e) { - LogAndTraceBroker.getBroker().trace(Level.FINE, - "Exception during shut down of thread pool", e); - } - } - - /** - * Closes the dispatcher - */ - public void close() { - this.iAlive = false; - } - } -} +/* + (C) Copyright IBM Corp. 2005, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1422316 2005-05-08 lupusalex Disable delayed acknowledgment + * 1483270 2006-05-15 lupusalex Using Several Cim Clients cause an indication problem + * 1498130 2006-05-31 lupusalex Selection of xml parser on a per connection basis + * 1535756 2006-08-07 lupusalex Make code warning free + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 1649779 2007-02-01 lupusalex Indication listener threads freeze + * 1660743 2007-02-15 lupusalex SSLContext is static + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2210455 2008-10-30 blaschke-oss Enhance javadoc, fix potential null pointers + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 3027392 2010-07-09 blaschke-oss Nullcheck of value previously dereferenced + * 3206904 2011-03-11 lupusalex Indication listener deadlock causes JVM to run out sockets + * 3536399 2012-08-25 hellerda Add client/listener peer authentication properties + * 2618 2013-02-27 blaschke-oss Need to add property to disable weak cipher suites for the secure indication + * 2642 2013-05-21 blaschke-oss Seperate properties needed for cim client and listener to filter out ciphers + */ + +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.TimeUnit; +import java.util.logging.Level; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLServerSocket; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; +import org.metricshub.wbem.sblim.cimclient.internal.util.ThreadPool; +import org.metricshub.wbem.sblim.cimclient.internal.util.Util; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfiguration; + +/** + * Class HttpServerConnection implements the outer shell of a HTTP server. It + * accepts incoming connections and puts them in a queue to be serviced by an + * independent thread + * + */ +public class HttpServerConnection implements Runnable { + private int iPort; + + private ServerSocket iServerSocket; + + private HttpConnectionHandler iHandler; + + private HttpConnectionDispatcher iDispatcher; + + private volatile boolean iClose = true; + + private String iServerName; + + private boolean iSsl; + + private Thread iRunner; + + private WBEMConfiguration iSessionProperties; + + private final int iTimeout; + + /** + * Ctor. + * + * @param pHandler + * The connection handler + * @param pLocalAddress + * The local address to bind the port to. If null the port is + * bound to all local addresses. For use on multi-homed systems + * @param pPort + * The local port. If zero any free port will be chosen. + * @param pSsl + * SSL secured connection ? + * @param pProperties + * The configuration context + * @throws IOException + */ + public HttpServerConnection( + HttpConnectionHandler pHandler, + String pLocalAddress, + int pPort, + boolean pSsl, + WBEMConfiguration pProperties + ) + throws IOException { + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + this.iPort = pPort; + this.iHandler = pHandler; + this.iSsl = pSsl; + this.iServerName = pSsl ? "HTTPS Server" : "HTTP Server"; + this.iSessionProperties = (pProperties != null) ? pProperties : WBEMConfiguration.getGlobalConfiguration(); + SSLContext sslContext = pSsl ? HttpSocketFactory.getInstance().getServerSSLContext(this.iSessionProperties) : null; + this.iServerSocket = + (pLocalAddress != null && pLocalAddress.length() > 0) + ? HttpSocketFactory + .getInstance() + .getServerSocketFactory(sslContext) + .createServerSocket(pPort, 50, InetAddress.getByName(pLocalAddress)) + : HttpSocketFactory.getInstance().getServerSocketFactory(sslContext).createServerSocket(pPort); + if (this.iServerSocket instanceof SSLServerSocket) { + if (this.iSessionProperties.getSslListenerPeerVerification().equalsIgnoreCase("ignore")) { + logger.trace(Level.FINER, "Listener peer verification: ignore"); + ((SSLServerSocket) this.iServerSocket).setNeedClientAuth(false); + } else if (this.iSessionProperties.getSslListenerPeerVerification().equalsIgnoreCase("accept")) { + logger.trace(Level.FINER, "Listener peer verification: accept"); + ((SSLServerSocket) this.iServerSocket).setWantClientAuth(true); + } else { + logger.trace(Level.FINER, "Listener peer verification: require"); + ((SSLServerSocket) this.iServerSocket).setNeedClientAuth(true); + } + + String disableCipherSuites = this.iSessionProperties.getSslListenerCipherSuitesToDisable(); + if (disableCipherSuites != null) { + SSLServerSocket sslSock = (SSLServerSocket) this.iServerSocket; + String[] currentCipherSuites = sslSock.getEnabledCipherSuites(); + String[] updatedCipherSuites = Util.getFilteredStringArray(currentCipherSuites, disableCipherSuites); + sslSock.setEnabledCipherSuites(updatedCipherSuites); + int before = currentCipherSuites.length; + int after = updatedCipherSuites.length; + if (before > 0 && after == 0) logger.trace(Level.WARNING, "All cipher suites disabled for listener!"); else if ( + before > after + ) logger.trace(Level.FINE, "Some (" + (before - after) + ") cipher suites disabled for listener"); else if ( + before == after + ) logger.trace(Level.FINER, "No cipher suites disabled for listener"); + } + } + this.iTimeout = this.iSessionProperties.getListenerHttpTimeout(); + logger.exit(); + } + + /** + * Set the name of the thread + * + * @param pName + * The new value + */ + public void setName(String pName) { + if (this.iRunner != null) this.iRunner.setName(pName); + } + + /** + * Returns the port + * + * @return The port + */ + public int getPort() { + return this.iServerSocket.getLocalPort(); + } + + /** + * Returns the local ip address the socket is bound to + * + * @return The ip address + * @throws UnknownHostException + */ + public String getLocalIp() throws UnknownHostException { + String ip = this.iServerSocket.getInetAddress().getHostAddress(); + String localhost = InetAddress.getLocalHost().getHostAddress(); + return "0.0.0.0".equals(ip) ? localhost : ip; + } + + /** + * Returns the local hostname the socket is bound to + * + * @return The host name + * @throws UnknownHostException + */ + public String getLocalHostName() throws UnknownHostException { + String ip = this.iServerSocket.getInetAddress().getHostName(); + String localhost = InetAddress.getLocalHost().getHostName(); + return "0.0.0.0".equals(ip) ? localhost : ip; + } + + /** + * Return whether this connection is SSL secured + * + * @return true if SSL is enabled, false otherwise + */ + public boolean isSSL() { + return this.iSsl; + } + + /** + * Starts a thread that waits for incoming connections + */ + public void start() { + if (this.iClose) { + this.iClose = false; + ThreadGroup group = new ThreadGroup("CIMListener on port " + String.valueOf(this.iPort)); + this.iDispatcher = + new HttpConnectionDispatcher( + group, + this.iHandler, + new ThreadPool( + this.iSessionProperties.getListenerMinPoolSize(), + this.iSessionProperties.getListenerMaxPoolSize(), + this.iSessionProperties.getListenerBacklog(), + this.iSessionProperties.getListenerMaxIdle(), + group, + "Handler " + ), + this.iSessionProperties.getListenerMaxQueueSize() + ); + this.iDispatcher.start(); + this.iRunner = new Thread(group, this, this.iServerName); + this.iRunner.setDaemon(true); + + this.iRunner.start(); + } + } + + public void run() { + while (!this.iClose) { + try { + Socket socket = this.iServerSocket.accept(); + try { + socket.setTcpNoDelay(true); + socket.setSoTimeout(this.iTimeout); + } catch (IOException e) { + LogAndTraceBroker.getBroker().trace(Level.FINE, "Exception while adjusting socket options", e); + } + boolean dispatched = this.iDispatcher.dispatch(socket); + if (!dispatched) { + MessageWriter writer = new MessageWriter(socket.getOutputStream(), false, false); + try { + writer.setMethod(new HttpServerMethod(1, 1, 503, "Service temporarily overloaded")); + writer.getHeader().addField("Retry-After", "10"); + writer.close(); + } catch (IOException e) { + LogAndTraceBroker.getBroker().trace(Level.FINE, "Exception while sending HTTP 503", e); + } finally { + socket.close(); + } + LogAndTraceBroker + .getBroker() + .trace(Level.FINE, "HttpServerConnection failed to dispatch incoming connection, sent 503"); + } else { + LogAndTraceBroker.getBroker().trace(Level.FINE, "HttpServerConnection dispatched incoming connection"); + } + } catch (Throwable t) { + if (t instanceof SocketException && this.iClose) { + break; + } + try { + LogAndTraceBroker.getBroker().trace(Level.FINE, "Exception while waiting for incoming http connections"); + } catch (Throwable t2) { + // just give up + } + } + } + + // shutdown + + try { + LogAndTraceBroker.getBroker().trace(Level.FINE, "Shutting down CIMListener on port " + this.iPort); + } catch (Throwable t) { + // do nothing + } + try { + // give the handlers a chance to process all already accepted + // connections before complete shutdown + Thread.sleep(5000); + } catch (InterruptedException e) { + // just ignore + } + try { + this.iDispatcher.close(); + } catch (Exception e) { + LogAndTraceBroker.getBroker().trace(Level.FINE, "Exception while closing http connection dispatcher", e); + } + this.iDispatcher = null; + this.iRunner = null; + } + + /** + * Closes the socket and shuts down the listening threads + */ + public void close() { + if (!this.iClose) { + this.iClose = true; + try { + this.iServerSocket.close(); + this.iServerSocket = null; + } catch (Exception e) { + LogAndTraceBroker.getBroker().trace(Level.FINE, "Exception while closing server socket", e); + } + } + } + + /** + * Class HttpConnectionDispatcher is responsible for dispatching the + * incoming connections to the handlers. It doesn't execute the handler + * directly but creates a runnable that is submitted to a thread pool which + * takes care of execution. + * + */ + private static class HttpConnectionDispatcher extends Thread { + private BlockingQueue iConnectionPool; + + private volatile boolean iAlive = true; + + private HttpConnectionHandler iHandler; + + private ThreadPool iThreadPool; + + /** + * Ctor. + * + * @param pGroup + * The thread group to use for this thread and it's children + * @param pHandler + * The connection handler + * @param pPool + * The thread pool + * @param pQueueSize + * The fixed capacity for the queue of pending connections + */ + public HttpConnectionDispatcher( + ThreadGroup pGroup, + HttpConnectionHandler pHandler, + ThreadPool pPool, + int pQueueSize + ) { + super(pGroup, "Connection Dispatcher"); + setDaemon(true); + this.iConnectionPool = new ArrayBlockingQueue(pQueueSize > 0 ? pQueueSize : 1); + this.iHandler = pHandler; + this.iThreadPool = pPool; + } + + /** + * Dispatches a connection + * + * @param pSocket + * The socket of the connection + * @return true if dispatch was successful + */ + public boolean dispatch(Socket pSocket) { + try { + return this.iConnectionPool.offer(pSocket, 20, TimeUnit.MILLISECONDS); + } catch (InterruptedException e) { + /* */ + } + return false; + } + + /** + * Gets the next pending connection + * + * @return The socket of the connection + */ + public Socket getConnection() { + try { + return this.iConnectionPool.poll(100, TimeUnit.MILLISECONDS); + } catch (InterruptedException e) { + // just ignore it, it is expected + } + return null; + } + + @Override + public void run() { + while (this.iAlive) { + try { + Socket socket = getConnection(); + if (socket != null) { + this.iThreadPool.execute(new HttpServerWorker(this.iHandler, socket)); + } + } catch (Throwable t) { + try { + LogAndTraceBroker.getBroker().trace(Level.FINE, "Exception while submitting worker to thread pool", t); + } catch (Throwable t1) { + // forget it + } + } + } + try { + this.iHandler.close(); + } catch (Exception e) { + LogAndTraceBroker.getBroker().trace(Level.FINE, "Exception while closing http connection handler", e); + } + try { + this.iThreadPool.shutdown(); + } catch (Exception e) { + LogAndTraceBroker.getBroker().trace(Level.FINE, "Exception during shut down of thread pool", e); + } + } + + /** + * Closes the dispatcher + */ + public void close() { + this.iAlive = false; + } + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpServerMethod.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpServerMethod.java similarity index 78% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpServerMethod.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpServerMethod.java index 412cf78..c6fce4b 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpServerMethod.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpServerMethod.java @@ -1,179 +1,174 @@ -/* - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.io.ASCIIPrintStream; - -/** - * Class HttpServerMethod is responsible for - * - */ -public class HttpServerMethod extends HttpMethod { - - private String iMethodName; - - private String iFile; - - private String iProtocol; - - private int iMinor, iMajor; - - private int iStatus; - - private String iReason; - - /** - * Ctor. - * - * @param pMajor - * Major version - * @param pMinor - * Minor version - * @param pStatus - * Status - * @param pReason - * Reason - */ - public HttpServerMethod(int pMajor, int pMinor, int pStatus, String pReason) { - this.iMinor = pMinor; - this.iMajor = pMajor; - this.iStatus = pStatus; - this.iReason = pReason; - } - - /** - * Ctor. - * - * @param pReader - * Inputstream - * @throws IOException - * @throws HttpException - */ - public HttpServerMethod(InputStream pReader) throws IOException, HttpException { - String line; - - do { - line = HttpMethod.readLine(pReader); - } while (line == null || line.length() == 0); - int next = line.indexOf(' '); - int prev = 0; - if (next > -1) { - this.iMethodName = line.substring(0, next).toUpperCase(); - if (this.iMethodName.equals("GET") && (line.indexOf(' ', next + 1) == -1)) { // Simple - // request - this.iFile = line.substring(next + 1); - } else { // FullRequest - prev = next + 1; - next = line.indexOf(' ', prev); - this.iFile = line.substring(prev, next); - - prev = next + 1; - this.iProtocol = line.substring(prev).toUpperCase(); - - prev = this.iProtocol.indexOf('/'); - next = this.iProtocol.indexOf('.', prev + 1); - try { - this.iMajor = Integer.parseInt(this.iProtocol.substring(prev + 1, next)); - this.iMinor = Integer.parseInt(this.iProtocol.substring(next + 1)); - } catch (Exception e) { - throw new HttpException(HttpURLConnection.HTTP_BAD_METHOD, "Bad method"); - } - } - } else throw new HttpException(HttpURLConnection.HTTP_BAD_METHOD, "Bad method"); - } - - /** - * Returns the major version - * - * @return The major version - */ - public int getMajorVersion() { - return this.iMajor; - } - - /** - * Returns the minor version - * - * @return The minor version - */ - public int getMinorVersion() { - return this.iMinor; - } - - /** - * Returns the method name - * - * @return The method name - */ - public String getMethodName() { - return this.iMethodName; - } - - /** - * Returns the file - * - * @return The file - */ - public String getFile() { - return this.iFile; - } - - /** - * Write to a given output stream - * - * @param pStream - * the output stream - */ - public void write(ASCIIPrintStream pStream) { - pStream.print("HTTP/" + this.iMajor + "." + this.iMinor + " " + this.iStatus + " " - + this.iReason + "\r\n"); - } -} +/* + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import org.metricshub.wbem.sblim.cimclient.internal.http.io.ASCIIPrintStream; + +/** + * Class HttpServerMethod is responsible for + * + */ +public class HttpServerMethod extends HttpMethod { + private String iMethodName; + + private String iFile; + + private String iProtocol; + + private int iMinor, iMajor; + + private int iStatus; + + private String iReason; + + /** + * Ctor. + * + * @param pMajor + * Major version + * @param pMinor + * Minor version + * @param pStatus + * Status + * @param pReason + * Reason + */ + public HttpServerMethod(int pMajor, int pMinor, int pStatus, String pReason) { + this.iMinor = pMinor; + this.iMajor = pMajor; + this.iStatus = pStatus; + this.iReason = pReason; + } + + /** + * Ctor. + * + * @param pReader + * Inputstream + * @throws IOException + * @throws HttpException + */ + public HttpServerMethod(InputStream pReader) throws IOException, HttpException { + String line; + + do { + line = HttpMethod.readLine(pReader); + } while (line == null || line.length() == 0); + int next = line.indexOf(' '); + int prev = 0; + if (next > -1) { + this.iMethodName = line.substring(0, next).toUpperCase(); + if (this.iMethodName.equals("GET") && (line.indexOf(' ', next + 1) == -1)) { // Simple + // request + this.iFile = line.substring(next + 1); + } else { // FullRequest + prev = next + 1; + next = line.indexOf(' ', prev); + this.iFile = line.substring(prev, next); + + prev = next + 1; + this.iProtocol = line.substring(prev).toUpperCase(); + + prev = this.iProtocol.indexOf('/'); + next = this.iProtocol.indexOf('.', prev + 1); + try { + this.iMajor = Integer.parseInt(this.iProtocol.substring(prev + 1, next)); + this.iMinor = Integer.parseInt(this.iProtocol.substring(next + 1)); + } catch (Exception e) { + throw new HttpException(HttpURLConnection.HTTP_BAD_METHOD, "Bad method"); + } + } + } else throw new HttpException(HttpURLConnection.HTTP_BAD_METHOD, "Bad method"); + } + + /** + * Returns the major version + * + * @return The major version + */ + public int getMajorVersion() { + return this.iMajor; + } + + /** + * Returns the minor version + * + * @return The minor version + */ + public int getMinorVersion() { + return this.iMinor; + } + + /** + * Returns the method name + * + * @return The method name + */ + public String getMethodName() { + return this.iMethodName; + } + + /** + * Returns the file + * + * @return The file + */ + public String getFile() { + return this.iFile; + } + + /** + * Write to a given output stream + * + * @param pStream + * the output stream + */ + public void write(ASCIIPrintStream pStream) { + pStream.print("HTTP/" + this.iMajor + "." + this.iMinor + " " + this.iStatus + " " + this.iReason + "\r\n"); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpServerWorker.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpServerWorker.java similarity index 65% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpServerWorker.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpServerWorker.java index 0223773..7eead34 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpServerWorker.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpServerWorker.java @@ -1,84 +1,80 @@ -/* - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1498927 2006-06-01 lupusalex Fill gaps in logging coverage - * 1535756 2006-08-07 lupusalex Make code warning free - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.net.Socket; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.Messages; - -/** - * Class HttpServerWorker forwards incoming connections to a handler - * - */ -public class HttpServerWorker implements Runnable { - - HttpConnectionHandler iHandler; - - Socket iSocket; - - /** - * Ctor. - * - * @param pHandler - * The handler - * @param pSocket - * The socket - */ - public HttpServerWorker(HttpConnectionHandler pHandler, Socket pSocket) { - this.iHandler = pHandler; - this.iSocket = pSocket; - } - - public void run() { - try { - this.iHandler.handleConnection(this.iSocket); - } catch (Exception e) { - LogAndTraceBroker.getBroker().message(Messages.HTTP_HANDLE_CONNECTION_FAILED, e); - } - } -} +/* + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1498927 2006-06-01 lupusalex Fill gaps in logging coverage + * 1535756 2006-08-07 lupusalex Make code warning free + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.net.Socket; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; +import org.metricshub.wbem.sblim.cimclient.internal.logging.Messages; + +/** + * Class HttpServerWorker forwards incoming connections to a handler + * + */ +public class HttpServerWorker implements Runnable { + HttpConnectionHandler iHandler; + + Socket iSocket; + + /** + * Ctor. + * + * @param pHandler + * The handler + * @param pSocket + * The socket + */ + public HttpServerWorker(HttpConnectionHandler pHandler, Socket pSocket) { + this.iHandler = pHandler; + this.iSocket = pSocket; + } + + public void run() { + try { + this.iHandler.handleConnection(this.iSocket); + } catch (Exception e) { + LogAndTraceBroker.getBroker().message(Messages.HTTP_HANDLE_CONNECTION_FAILED, e); + } + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpSocketFactory.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpSocketFactory.java similarity index 81% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpSocketFactory.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpSocketFactory.java index ad545b3..9b1510f 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpSocketFactory.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpSocketFactory.java @@ -1,497 +1,492 @@ -/* - (C) Copyright IBM Corp. 2005, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1498130 2006-05-31 lupusalex Selection of xml parser on a per connection basis - * 1535756 2006-08-07 lupusalex Make code warning free - * 1558663 2006-09-14 lupusalex Support custom socket factories in client connections - * 1573723 2006-10-09 lupusalex Selection of JSSE provider via properties file not feasible - * 1573723 2006-10-30 lupusalex rework: Selection of JSSE provider via properties file not feasible - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 1660743 2007-02-15 lupusalex SSLContext is static - * 1711092 2006-05-02 lupusalex Some fixes/additions of log&trace messages - * 1815707 2007-10-18 ebak TLS support - * 1815707 2007-10-30 ebak rework: TLS support - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 3001345 2010-05-18 blaschke-oss File handle leaks in HttpSocketFactory and LogAndTraceBroker - * 3027618 2010-07-14 blaschke-oss Close files/readers in finally blocks - * 3111718 2010-11-18 blaschke-oss org.sblim.cimclient SSL Code is using the wrong SSL Property - * 3536399 2012-08-25 hellerda Add client/listener peer authentication properties - * 2647 2013-07-01 blaschke-oss Add two ssl protocol properties for http server and client - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.net.Socket; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.Principal; -import java.security.PrivateKey; -import java.security.Provider; -import java.security.Security; -import java.security.UnrecoverableKeyException; -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; -import java.util.logging.Level; - -import javax.net.ServerSocketFactory; -import javax.net.SocketFactory; -import javax.net.ssl.KeyManager; -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; -import javax.net.ssl.TrustManager; -import javax.net.ssl.TrustManagerFactory; -import javax.net.ssl.X509KeyManager; -import javax.net.ssl.X509TrustManager; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.Messages; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConfiguration; - -/** - * Class HttpSocketFactory manages socket factories - * - */ -public class HttpSocketFactory { - - private static HttpSocketFactory cInstance = new HttpSocketFactory(); - - private HttpSocketFactory() { - // empty - } - - /** - * Returns the singleton instance - * - * @return The instance - */ - public static HttpSocketFactory getInstance() { - return cInstance; - } - - /** - * Returns a server socket factory - * - * @param pContext - * The corresponding SSL context or null for - * insecure connections - * - * @return The factory - */ - public ServerSocketFactory getServerSocketFactory(SSLContext pContext) { - return pContext != null ? pContext.getServerSocketFactory() : ServerSocketFactory - .getDefault(); - } - - /** - * Returns a client socket factory - * - * @param pContext - * The SSL context or null for insecure connections - * @return The factory - */ - public SocketFactory getClientSocketFactory(SSLContext pContext) { - return pContext != null ? pContext.getSocketFactory() : SocketFactory.getDefault(); - } - - /** - * Returns a SSLContext for client sockets corresponding to a given set of - * configuration properties - * - * @param pProperties - * The configuration to apply - * @return The SSL context - */ - public SSLContext getClientSSLContext(final WBEMConfiguration pProperties) { - return getSSLContext(pProperties, false); - } - - /** - * Returns a SSLContext for server sockets corresponding to a given set of - * configuration properties - * - * @param pProperties - * The configuration to apply - * @return The SSL context - */ - public SSLContext getServerSSLContext(final WBEMConfiguration pProperties) { - return getSSLContext(pProperties, true); - } - - /** - * Returns a SSLContext corresponding to a given set of configuration - * properties - * - * @param pProperties - * The configuration to apply - * @param pIsServer - * true if a server socket context is requested, - * false otherwise - * @return The SSL context - */ - private SSLContext getSSLContext(final WBEMConfiguration pProperties, boolean pIsServer) { - - final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - - final String provider = pIsServer ? pProperties.getSslServerSocketProvider() : pProperties - .getSslSocketProvider(); - logger.trace(Level.FINER, "Loading JSSE provider:" + provider); - - final Provider securityProvider; - - try { - Class providerClass = Class.forName(provider); - securityProvider = (java.security.Provider) providerClass.newInstance(); - if (Security.getProvider(securityProvider.getName()) == null) { - Security.addProvider(securityProvider); - } - } catch (Exception e) { - logger.trace(Level.FINER, "Exception while loading JSSE provider", e); - logger.message(Messages.SSL_JSSE_PROVIDER_LOAD_FAILED, provider); - logger.exit(); - throw new RuntimeException(e); - } - - try { - KeyManager[] keyManager = loadKeystore(pProperties, securityProvider, pIsServer); - - TrustManager[] trustManager = loadTruststore(pProperties, securityProvider, pIsServer); - - String sslProtocol = pIsServer ? pProperties.getSslListenerProtocol() : pProperties - .getSslClientProtocol(); - - SSLContext sslContext = SSLContext.getInstance(sslProtocol != null ? sslProtocol - : pProperties.getSslProtocol(), securityProvider); - - sslContext.init(keyManager, trustManager, null); - - logger.exit(); - - return sslContext; - - } catch (Exception e) { - logger.trace(Level.FINER, "Exception while initializing SSL context (provider:" - + provider + ")", e); - logger.message(Messages.SSL_CONTEXT_INIT_FAILED); - logger.exit(); - return null; - } - } - - private TrustManager[] loadTruststore(final WBEMConfiguration pProperties, - final Provider pSecurityProvider, boolean pIsServer) { - - final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - - final TrustManager[] trustAll = new X509TrustManager[] { new AllTrustManager() }; - final TrustManager[] trustNone = new X509TrustManager[] { new NoTrustManager() }; - TrustManager[] trustManager = trustNone; - - final String truststorePath = pProperties.getSslTrustStorePath(); - final char[] truststorePassword = pProperties.getSslTrustStorePassword().toCharArray(); - final String truststoreType = pProperties.getSslTrustStoreType(); - final String trustManagerAlgorithm = pProperties.getSslTrustManagerAlgorithm(); - final boolean clientPeerVerification = pProperties.getSslClientPeerVerification(); - final String listenerPeerVerification = pProperties.getSslListenerPeerVerification(); - - logger.trace(Level.FINER, "Using SSL truststore \"" + truststorePath + "\" (" - + truststoreType + "/" + trustManagerAlgorithm + ")"); - - if (pIsServer && listenerPeerVerification.equalsIgnoreCase("ignore") - || (!pIsServer && !clientPeerVerification)) { - trustManager = trustAll; - if (truststorePath == null || truststorePath.trim().length() == 0) { - logger.trace(Level.FINER, "Peer verification disabled for " - + (pIsServer ? "Listener" : "Client")); - } else { - logger.message(Messages.SSL_TRUSTSTORE_INACTIVE); - } - } else { - if (truststorePath == null || truststorePath.trim().length() == 0) { - logger.trace(Level.FINER, "Peer verification enabled for " - + (pIsServer ? "Listener" : "Client") + " but no truststore specified!"); - logger.message(Messages.SSL_TRUSTSTORE_NULL); - } else { - logger.trace(Level.FINER, "Peer verification enabled for " - + (pIsServer ? "Listener" : "Client")); - FileInputStream fis = null; - try { - final KeyStore trustStore = KeyStore.getInstance(truststoreType); - fis = new FileInputStream(truststorePath); - trustStore.load(fis, truststorePassword); - final TrustManagerFactory trustManagerFactory = TrustManagerFactory - .getInstance(trustManagerAlgorithm, pSecurityProvider); - trustManagerFactory.init(trustStore); - trustManager = trustManagerFactory.getTrustManagers(); - logger.trace(Level.FINER, "Truststore successfully loaded for " - + (pIsServer ? "Listener" : "Client")); - } catch (FileNotFoundException e) { - logger.trace(Level.FINER, "Exception while loading truststore", e); - logger.message(Messages.SSL_TRUSTSTORE_NOT_FOUND, truststorePath); - } catch (IOException e) { - logger.trace(Level.FINER, "Exception while loading truststore", e); - logger.message(Messages.SSL_TRUSTSTORE_NOT_READABLE, truststorePath); - } catch (NoSuchAlgorithmException e) { - logger.trace(Level.FINER, "Exception while loading truststore", e); - logger - .message(Messages.SSL_TRUSTSTORE_INVALID_ALGORITHM, - trustManagerAlgorithm); - } catch (CertificateException e) { - logger.trace(Level.FINER, "Exception while loading truststore", e); - logger.message(Messages.SSL_TRUSTSTORE_INVALID_CERT, truststorePath); - } catch (KeyStoreException e) { - logger.trace(Level.FINER, "Exception while loading truststore", e); - logger.message(Messages.SSL_TRUSTSTORE_INVALID, truststoreType); - } catch (Exception e) { - logger.trace(Level.FINER, "Exception while loading truststore", e); - logger.message(Messages.SSL_TRUSTSTORE_OTHER, truststorePath); - } finally { - if (fis != null) { - try { - fis.close(); - } catch (IOException e) { - logger.trace(Level.FINER, "Exception while closing truststore", e); - } - } - } - } - } - - if (trustManager == trustAll) { - logger.message(Messages.SSL_TRUSTSTORE_FALLBACK); - } else if (trustManager == trustNone) { - logger.message(Messages.SSL_TRUSTSTORE_FALLBACK_NOTRUST); - } else { - logger.message(Messages.SSL_TRUSTSTORE_ACTIVE); - } - - logger.exit(); - return trustManager; - } - - private KeyManager[] loadKeystore(final WBEMConfiguration pProperties, - final Provider pSecurityProvider, boolean pIsServer) { - - final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - - final KeyManager[] noKeys = new KeyManager[] { new EmptyKeyManager() }; - KeyManager[] keyManager = noKeys; - - final String keystorePath = pProperties.getSslKeyStorePath(); - final char[] keystorePassword = pProperties.getSslKeyStorePassword().toCharArray(); - final String keystoreType = pProperties.getSslKeyStoreType(); - final String keyManagerAlgorithm = pProperties.getSslKeyManagerAlgorithm(); - - logger.trace(Level.FINER, "Using SSL keystore \"" + keystorePath + "\" (" + keystoreType - + "/" + keyManagerAlgorithm + ")"); - - if (keystorePath == null || keystorePath.trim().length() == 0) { - logger.trace(Level.FINER, "Keystore not specified for " - + (pIsServer ? "Listener" : "Client")); - logger.message(Messages.SSL_KEYSTORE_NULL); - } else { - logger.trace(Level.FINER, "Keystore specified and activated for " - + (pIsServer ? "Listener" : "Client")); - FileInputStream fis = null; - try { - final KeyStore keystore = KeyStore.getInstance(keystoreType); - fis = new FileInputStream(keystorePath); - keystore.load(fis, keystorePassword); - - final KeyManagerFactory keymanagerfactory = KeyManagerFactory.getInstance( - keyManagerAlgorithm, pSecurityProvider); - keymanagerfactory.init(keystore, keystorePassword); - keyManager = keymanagerfactory.getKeyManagers(); - logger.trace(Level.FINER, "Keystore successfully loaded for " - + (pIsServer ? "Listener" : "Client")); - } catch (FileNotFoundException e) { - logger.trace(Level.FINER, "Exception while loading keystore", e); - logger.message(Messages.SSL_KEYSTORE_NOT_FOUND, keystorePath); - } catch (IOException e) { - logger.trace(Level.FINER, "Exception while loading keystore", e); - logger.message(Messages.SSL_KEYSTORE_NOT_READABLE, keystorePath); - } catch (NoSuchAlgorithmException e) { - logger.trace(Level.FINER, "Exception while loading keystore", e); - logger.message(Messages.SSL_KEYSTORE_INVALID_ALGORITHM, keyManagerAlgorithm); - } catch (CertificateException e) { - logger.trace(Level.FINER, "Exception while loading keystore", e); - logger.message(Messages.SSL_KEYSTORE_INVALID_CERT, keystorePath); - } catch (UnrecoverableKeyException e) { - logger.trace(Level.FINER, "Exception while loading keystore", e); - logger.message(Messages.SSL_KEYSTORE_UNRECOVERABLE_KEY, keystorePath); - } catch (KeyStoreException e) { - logger.trace(Level.FINER, "Exception while loading keystore", e); - logger.message(Messages.SSL_KEYSTORE_INVALID, keystoreType); - } catch (Exception e) { - logger.trace(Level.FINER, "Exception while loading keystore", e); - logger.message(Messages.SSL_KEYSTORE_OTHER, keystorePath); - } finally { - if (fis != null) { - try { - fis.close(); - } catch (IOException e) { - logger.trace(Level.FINER, "Exception while closing keystore", e); - } - } - } - } - - if (keyManager == noKeys) { - logger.message(Messages.SSL_KEYSTORE_FALLBACK); - } - - logger.exit(); - return keyManager; - } - -} - -class AllTrustManager implements X509TrustManager { - - /** - * @param arg0 - * @param arg1 - */ - public void checkClientTrusted(X509Certificate[] arg0, String arg1) { - return; - } - - /** - * @param arg0 - * @param arg1 - */ - public void checkServerTrusted(X509Certificate[] arg0, String arg1) { - return; - } - - public X509Certificate[] getAcceptedIssuers() { - return null; - } -} - -class NoTrustManager implements X509TrustManager { - - /** - * @param arg0 - * @param arg1 - * @throws CertificateException - */ - public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { - throw new CertificateException(); - } - - /** - * @param arg0 - * @param arg1 - * @throws CertificateException - */ - public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { - throw new CertificateException(); - } - - public X509Certificate[] getAcceptedIssuers() { - return null; - } -} - -class EmptyKeyManager implements X509KeyManager { - - /** - * @param keyType - * @param issuers - * @param socket - * @return String chooseClientAlias - */ - public String chooseClientAlias(String[] keyType, Principal[] issuers, Socket socket) { - return null; - } - - /** - * @param keyType - * @param issuers - * @param socket - * @return String chooseServerAlias - */ - public String chooseServerAlias(String keyType, Principal[] issuers, Socket socket) { - return null; - } - - /** - * @param alias - * @return X509Certificate[] - */ - public X509Certificate[] getCertificateChain(String alias) { - return null; - } - - /** - * @param keyType - * @param issuers - * @return String[] - */ - public String[] getClientAliases(String keyType, Principal[] issuers) { - return null; - } - - /** - * @param alias - * @return PrivateKey - */ - public PrivateKey getPrivateKey(String alias) { - return null; - } - - /** - * @param keyType - * @param issuers - * @return String[] - */ - public String[] getServerAliases(String keyType, Principal[] issuers) { - return null; - } -} +/* + (C) Copyright IBM Corp. 2005, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1498130 2006-05-31 lupusalex Selection of xml parser on a per connection basis + * 1535756 2006-08-07 lupusalex Make code warning free + * 1558663 2006-09-14 lupusalex Support custom socket factories in client connections + * 1573723 2006-10-09 lupusalex Selection of JSSE provider via properties file not feasible + * 1573723 2006-10-30 lupusalex rework: Selection of JSSE provider via properties file not feasible + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 1660743 2007-02-15 lupusalex SSLContext is static + * 1711092 2006-05-02 lupusalex Some fixes/additions of log&trace messages + * 1815707 2007-10-18 ebak TLS support + * 1815707 2007-10-30 ebak rework: TLS support + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 3001345 2010-05-18 blaschke-oss File handle leaks in HttpSocketFactory and LogAndTraceBroker + * 3027618 2010-07-14 blaschke-oss Close files/readers in finally blocks + * 3111718 2010-11-18 blaschke-oss org.sblim.cimclient SSL Code is using the wrong SSL Property + * 3536399 2012-08-25 hellerda Add client/listener peer authentication properties + * 2647 2013-07-01 blaschke-oss Add two ssl protocol properties for http server and client + */ + +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.Socket; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.Principal; +import java.security.PrivateKey; +import java.security.Provider; +import java.security.Security; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.logging.Level; +import javax.net.ServerSocketFactory; +import javax.net.SocketFactory; +import javax.net.ssl.KeyManager; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactory; +import javax.net.ssl.X509KeyManager; +import javax.net.ssl.X509TrustManager; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; +import org.metricshub.wbem.sblim.cimclient.internal.logging.Messages; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfiguration; + +/** + * Class HttpSocketFactory manages socket factories + * + */ +public class HttpSocketFactory { + private static HttpSocketFactory cInstance = new HttpSocketFactory(); + + private HttpSocketFactory() { + // empty + } + + /** + * Returns the singleton instance + * + * @return The instance + */ + public static HttpSocketFactory getInstance() { + return cInstance; + } + + /** + * Returns a server socket factory + * + * @param pContext + * The corresponding SSL context or null for + * insecure connections + * + * @return The factory + */ + public ServerSocketFactory getServerSocketFactory(SSLContext pContext) { + return pContext != null ? pContext.getServerSocketFactory() : ServerSocketFactory.getDefault(); + } + + /** + * Returns a client socket factory + * + * @param pContext + * The SSL context or null for insecure connections + * @return The factory + */ + public SocketFactory getClientSocketFactory(SSLContext pContext) { + return pContext != null ? pContext.getSocketFactory() : SocketFactory.getDefault(); + } + + /** + * Returns a SSLContext for client sockets corresponding to a given set of + * configuration properties + * + * @param pProperties + * The configuration to apply + * @return The SSL context + */ + public SSLContext getClientSSLContext(final WBEMConfiguration pProperties) { + return getSSLContext(pProperties, false); + } + + /** + * Returns a SSLContext for server sockets corresponding to a given set of + * configuration properties + * + * @param pProperties + * The configuration to apply + * @return The SSL context + */ + public SSLContext getServerSSLContext(final WBEMConfiguration pProperties) { + return getSSLContext(pProperties, true); + } + + /** + * Returns a SSLContext corresponding to a given set of configuration + * properties + * + * @param pProperties + * The configuration to apply + * @param pIsServer + * true if a server socket context is requested, + * false otherwise + * @return The SSL context + */ + private SSLContext getSSLContext(final WBEMConfiguration pProperties, boolean pIsServer) { + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + final String provider = pIsServer ? pProperties.getSslServerSocketProvider() : pProperties.getSslSocketProvider(); + logger.trace(Level.FINER, "Loading JSSE provider:" + provider); + + final Provider securityProvider; + + try { + Class providerClass = Class.forName(provider); + securityProvider = (java.security.Provider) providerClass.newInstance(); + if (Security.getProvider(securityProvider.getName()) == null) { + Security.addProvider(securityProvider); + } + } catch (Exception e) { + logger.trace(Level.FINER, "Exception while loading JSSE provider", e); + logger.message(Messages.SSL_JSSE_PROVIDER_LOAD_FAILED, provider); + logger.exit(); + throw new RuntimeException(e); + } + + try { + KeyManager[] keyManager = loadKeystore(pProperties, securityProvider, pIsServer); + + TrustManager[] trustManager = loadTruststore(pProperties, securityProvider, pIsServer); + + String sslProtocol = pIsServer ? pProperties.getSslListenerProtocol() : pProperties.getSslClientProtocol(); + + SSLContext sslContext = SSLContext.getInstance( + sslProtocol != null ? sslProtocol : pProperties.getSslProtocol(), + securityProvider + ); + + sslContext.init(keyManager, trustManager, null); + + logger.exit(); + + return sslContext; + } catch (Exception e) { + logger.trace(Level.FINER, "Exception while initializing SSL context (provider:" + provider + ")", e); + logger.message(Messages.SSL_CONTEXT_INIT_FAILED); + logger.exit(); + return null; + } + } + + private TrustManager[] loadTruststore( + final WBEMConfiguration pProperties, + final Provider pSecurityProvider, + boolean pIsServer + ) { + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + final TrustManager[] trustAll = new X509TrustManager[] { new AllTrustManager() }; + final TrustManager[] trustNone = new X509TrustManager[] { new NoTrustManager() }; + TrustManager[] trustManager = trustNone; + + final String truststorePath = pProperties.getSslTrustStorePath(); + final char[] truststorePassword = pProperties.getSslTrustStorePassword().toCharArray(); + final String truststoreType = pProperties.getSslTrustStoreType(); + final String trustManagerAlgorithm = pProperties.getSslTrustManagerAlgorithm(); + final boolean clientPeerVerification = pProperties.getSslClientPeerVerification(); + final String listenerPeerVerification = pProperties.getSslListenerPeerVerification(); + + logger.trace( + Level.FINER, + "Using SSL truststore \"" + truststorePath + "\" (" + truststoreType + "/" + trustManagerAlgorithm + ")" + ); + + if (pIsServer && listenerPeerVerification.equalsIgnoreCase("ignore") || (!pIsServer && !clientPeerVerification)) { + trustManager = trustAll; + if (truststorePath == null || truststorePath.trim().length() == 0) { + logger.trace(Level.FINER, "Peer verification disabled for " + (pIsServer ? "Listener" : "Client")); + } else { + logger.message(Messages.SSL_TRUSTSTORE_INACTIVE); + } + } else { + if (truststorePath == null || truststorePath.trim().length() == 0) { + logger.trace( + Level.FINER, + "Peer verification enabled for " + (pIsServer ? "Listener" : "Client") + " but no truststore specified!" + ); + logger.message(Messages.SSL_TRUSTSTORE_NULL); + } else { + logger.trace(Level.FINER, "Peer verification enabled for " + (pIsServer ? "Listener" : "Client")); + FileInputStream fis = null; + try { + final KeyStore trustStore = KeyStore.getInstance(truststoreType); + fis = new FileInputStream(truststorePath); + trustStore.load(fis, truststorePassword); + final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance( + trustManagerAlgorithm, + pSecurityProvider + ); + trustManagerFactory.init(trustStore); + trustManager = trustManagerFactory.getTrustManagers(); + logger.trace(Level.FINER, "Truststore successfully loaded for " + (pIsServer ? "Listener" : "Client")); + } catch (FileNotFoundException e) { + logger.trace(Level.FINER, "Exception while loading truststore", e); + logger.message(Messages.SSL_TRUSTSTORE_NOT_FOUND, truststorePath); + } catch (IOException e) { + logger.trace(Level.FINER, "Exception while loading truststore", e); + logger.message(Messages.SSL_TRUSTSTORE_NOT_READABLE, truststorePath); + } catch (NoSuchAlgorithmException e) { + logger.trace(Level.FINER, "Exception while loading truststore", e); + logger.message(Messages.SSL_TRUSTSTORE_INVALID_ALGORITHM, trustManagerAlgorithm); + } catch (CertificateException e) { + logger.trace(Level.FINER, "Exception while loading truststore", e); + logger.message(Messages.SSL_TRUSTSTORE_INVALID_CERT, truststorePath); + } catch (KeyStoreException e) { + logger.trace(Level.FINER, "Exception while loading truststore", e); + logger.message(Messages.SSL_TRUSTSTORE_INVALID, truststoreType); + } catch (Exception e) { + logger.trace(Level.FINER, "Exception while loading truststore", e); + logger.message(Messages.SSL_TRUSTSTORE_OTHER, truststorePath); + } finally { + if (fis != null) { + try { + fis.close(); + } catch (IOException e) { + logger.trace(Level.FINER, "Exception while closing truststore", e); + } + } + } + } + } + + if (trustManager == trustAll) { + logger.message(Messages.SSL_TRUSTSTORE_FALLBACK); + } else if (trustManager == trustNone) { + logger.message(Messages.SSL_TRUSTSTORE_FALLBACK_NOTRUST); + } else { + logger.message(Messages.SSL_TRUSTSTORE_ACTIVE); + } + + logger.exit(); + return trustManager; + } + + private KeyManager[] loadKeystore( + final WBEMConfiguration pProperties, + final Provider pSecurityProvider, + boolean pIsServer + ) { + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + final KeyManager[] noKeys = new KeyManager[] { new EmptyKeyManager() }; + KeyManager[] keyManager = noKeys; + + final String keystorePath = pProperties.getSslKeyStorePath(); + final char[] keystorePassword = pProperties.getSslKeyStorePassword().toCharArray(); + final String keystoreType = pProperties.getSslKeyStoreType(); + final String keyManagerAlgorithm = pProperties.getSslKeyManagerAlgorithm(); + + logger.trace( + Level.FINER, + "Using SSL keystore \"" + keystorePath + "\" (" + keystoreType + "/" + keyManagerAlgorithm + ")" + ); + + if (keystorePath == null || keystorePath.trim().length() == 0) { + logger.trace(Level.FINER, "Keystore not specified for " + (pIsServer ? "Listener" : "Client")); + logger.message(Messages.SSL_KEYSTORE_NULL); + } else { + logger.trace(Level.FINER, "Keystore specified and activated for " + (pIsServer ? "Listener" : "Client")); + FileInputStream fis = null; + try { + final KeyStore keystore = KeyStore.getInstance(keystoreType); + fis = new FileInputStream(keystorePath); + keystore.load(fis, keystorePassword); + + final KeyManagerFactory keymanagerfactory = KeyManagerFactory.getInstance( + keyManagerAlgorithm, + pSecurityProvider + ); + keymanagerfactory.init(keystore, keystorePassword); + keyManager = keymanagerfactory.getKeyManagers(); + logger.trace(Level.FINER, "Keystore successfully loaded for " + (pIsServer ? "Listener" : "Client")); + } catch (FileNotFoundException e) { + logger.trace(Level.FINER, "Exception while loading keystore", e); + logger.message(Messages.SSL_KEYSTORE_NOT_FOUND, keystorePath); + } catch (IOException e) { + logger.trace(Level.FINER, "Exception while loading keystore", e); + logger.message(Messages.SSL_KEYSTORE_NOT_READABLE, keystorePath); + } catch (NoSuchAlgorithmException e) { + logger.trace(Level.FINER, "Exception while loading keystore", e); + logger.message(Messages.SSL_KEYSTORE_INVALID_ALGORITHM, keyManagerAlgorithm); + } catch (CertificateException e) { + logger.trace(Level.FINER, "Exception while loading keystore", e); + logger.message(Messages.SSL_KEYSTORE_INVALID_CERT, keystorePath); + } catch (UnrecoverableKeyException e) { + logger.trace(Level.FINER, "Exception while loading keystore", e); + logger.message(Messages.SSL_KEYSTORE_UNRECOVERABLE_KEY, keystorePath); + } catch (KeyStoreException e) { + logger.trace(Level.FINER, "Exception while loading keystore", e); + logger.message(Messages.SSL_KEYSTORE_INVALID, keystoreType); + } catch (Exception e) { + logger.trace(Level.FINER, "Exception while loading keystore", e); + logger.message(Messages.SSL_KEYSTORE_OTHER, keystorePath); + } finally { + if (fis != null) { + try { + fis.close(); + } catch (IOException e) { + logger.trace(Level.FINER, "Exception while closing keystore", e); + } + } + } + } + + if (keyManager == noKeys) { + logger.message(Messages.SSL_KEYSTORE_FALLBACK); + } + + logger.exit(); + return keyManager; + } +} + +class AllTrustManager implements X509TrustManager { + + /** + * @param arg0 + * @param arg1 + */ + public void checkClientTrusted(X509Certificate[] arg0, String arg1) { + return; + } + + /** + * @param arg0 + * @param arg1 + */ + public void checkServerTrusted(X509Certificate[] arg0, String arg1) { + return; + } + + public X509Certificate[] getAcceptedIssuers() { + return null; + } +} + +class NoTrustManager implements X509TrustManager { + + /** + * @param arg0 + * @param arg1 + * @throws CertificateException + */ + public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { + throw new CertificateException(); + } + + /** + * @param arg0 + * @param arg1 + * @throws CertificateException + */ + public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { + throw new CertificateException(); + } + + public X509Certificate[] getAcceptedIssuers() { + return null; + } +} + +class EmptyKeyManager implements X509KeyManager { + + /** + * @param keyType + * @param issuers + * @param socket + * @return String chooseClientAlias + */ + public String chooseClientAlias(String[] keyType, Principal[] issuers, Socket socket) { + return null; + } + + /** + * @param keyType + * @param issuers + * @param socket + * @return String chooseServerAlias + */ + public String chooseServerAlias(String keyType, Principal[] issuers, Socket socket) { + return null; + } + + /** + * @param alias + * @return X509Certificate[] + */ + public X509Certificate[] getCertificateChain(String alias) { + return null; + } + + /** + * @param keyType + * @param issuers + * @return String[] + */ + public String[] getClientAliases(String keyType, Principal[] issuers) { + return null; + } + + /** + * @param alias + * @return PrivateKey + */ + public PrivateKey getPrivateKey(String alias) { + return null; + } + + /** + * @param keyType + * @param issuers + * @return String[] + */ + public String[] getServerAliases(String keyType, Principal[] issuers) { + return null; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpUrlConnection.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpUrlConnection.java similarity index 82% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpUrlConnection.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpUrlConnection.java index 54cbcc9..9068487 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/HttpUrlConnection.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/HttpUrlConnection.java @@ -1,271 +1,272 @@ -/* - (C) Copyright IBM Corp. 2005, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1353168 2005-11-24 fiuczy Possible NullPointerExcection in HttpClient.streamFinished() - * 1488924 2006-05-15 lupusalex Intermittent connection loss - * 1535756 2006-08-07 lupusalex Make code warning free - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 3026360 2010-07-07 blaschke-oss Handle unwritten fields - */ -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.SocketPermission; -import java.net.URI; -import java.security.Permission; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; - -/** - * Class HttpUrlConnection encapsulates a http connection - * - */ -public class HttpUrlConnection extends HttpURLConnection { - - private boolean iConnected; - - private HttpClient iHttpClient; - - protected URI iUrl; - - private HttpClientPool iHttpClientPool; - - AuthorizationHandler iAuthHandler; - - /** - * Ctor. - * - * @param pUri - * The host URI - * @param pHttpClientPool - * The client pool - * @param pAuthHandler - * The authentication handler - */ - public HttpUrlConnection(URI pUri, HttpClientPool pHttpClientPool, - AuthorizationHandler pAuthHandler) { - super(null); - this.iUrl = pUri; - this.iHttpClientPool = pHttpClientPool; - this.iAuthHandler = pAuthHandler; - // iLogger = GlobalProperties.getLogger(); - } - - @Override - public String toString() { - return "HttpUrlConnection=[url=" + this.iUrl + ",PoolSize=" - + this.iHttpClientPool.getNumberOfAvailableConnections() + "," + this.iAuthHandler - + "]"; - } - - @Override - public Permission getPermission() { - int port = this.iUrl.getPort(); - port = port < 0 ? 80 : port; - String host = this.iUrl.getHost() + ":" + port; - Permission permission = new SocketPermission(host, "connect"); - return permission; - } - - @Override - public synchronized void connect() throws IOException { - if (!this.iConnected) getClient(); - this.iHttpClient.connect(); - } - - private synchronized void getClient() { - if (this.iConnected) return; - - this.iHttpClient = HttpClient.getClient(this.iUrl, this.iHttpClientPool, this.iAuthHandler); - this.iHttpClient.reset(); - this.iConnected = true; - } - - @Override - public synchronized void setRequestMethod(String pMethod) { - if (!this.iConnected) getClient(); - this.iHttpClient.setRequestMethod(pMethod); - this.method = pMethod; - } - - @Override - public synchronized void setRequestProperty(String key, String value) { - if (!this.iConnected) getClient(); - this.iHttpClient.setRequestProperty(key, value); - } - - @Override - public synchronized void disconnect() { - LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - - if (this.iConnected) { - this.iConnected = false; - this.iHttpClient.disconnect(); - if (this.iHttpClientPool != null) { - this.iHttpClientPool.removeConnectionFromPool(this.iHttpClient); - this.iHttpClient = null; - } - } - logger.exit(); - } - - /** - * Closes the client pool - */ - public synchronized void close() { - LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - - if (this.iHttpClientPool != null) { - synchronized (this.iHttpClientPool) { - this.iHttpClientPool.closePool(); - this.iHttpClientPool = null; - } - } - logger.exit(); - } - - @Override - public synchronized InputStream getInputStream() throws IOException { - if (!this.iConnected) getClient(); - try { - return this.iHttpClient.getInputStream(); - } catch (RuntimeException e) { - disconnect(); - throw e; - } catch (IOException e) { - disconnect(); - throw e; - } - } - - @Override - public synchronized OutputStream getOutputStream() throws RuntimeException { - if (!this.iConnected) getClient(); - try { - return this.iHttpClient.getOutputStream(); - } catch (RuntimeException e) { - disconnect(); - throw e; - } - } - - @Override - public boolean usingProxy() { - return false; - } - - /** - * Returns the http client - * - * @return The http client - */ - public synchronized HttpClient getHttpClient() { - if (!this.iConnected) getClient(); - return this.iHttpClient; - } - - @Override - public synchronized String getHeaderField(String name) { - if (!this.iConnected) getClient(); - return this.iHttpClient.getHeaderField(name); - } - - @Override - public synchronized String getHeaderFieldKey(int index) { - if (!this.iConnected) getClient(); - return this.iHttpClient.getHeaderFieldName(index); - } - - @Override - public synchronized String getHeaderField(int index) { - if (!this.iConnected) getClient(); - return this.iHttpClient.getHeaderFieldValue(index); - } - - @Override - public synchronized String getRequestProperty(String key) { - if (!this.iConnected) getClient(); - return this.iHttpClient.getRequestProperty(key); - } - - @Override - public synchronized String getRequestMethod() { - if (!this.iConnected) getClient(); - return this.iHttpClient.getRequestMethod(); - } - - /** - * Resets the http client - */ - public synchronized void reset() { - if (!this.iConnected) getClient(); - this.iHttpClient.reset(); - } - - @Override - public synchronized int getResponseCode() throws IOException { - if (!this.iConnected) getClient(); - return this.iHttpClient.getResponseCode(); - } - - @Override - public synchronized String getResponseMessage() { - if (!this.iConnected) getClient(); - return this.iHttpClient.getResponseMessage(); - } - - /** - * Enables/Disables the use of http 1.1 - * - * @param pUse11 - * If true http 1.1 is enabled. - */ - public synchronized void useHttp11(boolean pUse11) { - if (!this.iConnected) getClient(); - this.iHttpClient.useHttp11(pUse11); - } -} +/* + (C) Copyright IBM Corp. 2005, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1353168 2005-11-24 fiuczy Possible NullPointerExcection in HttpClient.streamFinished() + * 1488924 2006-05-15 lupusalex Intermittent connection loss + * 1535756 2006-08-07 lupusalex Make code warning free + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 3026360 2010-07-07 blaschke-oss Handle unwritten fields + */ +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.SocketPermission; +import java.net.URI; +import java.security.Permission; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; + +/** + * Class HttpUrlConnection encapsulates a http connection + * + */ +public class HttpUrlConnection extends HttpURLConnection { + private boolean iConnected; + + private HttpClient iHttpClient; + + protected URI iUrl; + + private HttpClientPool iHttpClientPool; + + AuthorizationHandler iAuthHandler; + + /** + * Ctor. + * + * @param pUri + * The host URI + * @param pHttpClientPool + * The client pool + * @param pAuthHandler + * The authentication handler + */ + public HttpUrlConnection(URI pUri, HttpClientPool pHttpClientPool, AuthorizationHandler pAuthHandler) { + super(null); + this.iUrl = pUri; + this.iHttpClientPool = pHttpClientPool; + this.iAuthHandler = pAuthHandler; + // iLogger = GlobalProperties.getLogger(); + } + + @Override + public String toString() { + return ( + "HttpUrlConnection=[url=" + + this.iUrl + + ",PoolSize=" + + this.iHttpClientPool.getNumberOfAvailableConnections() + + "," + + this.iAuthHandler + + "]" + ); + } + + @Override + public Permission getPermission() { + int port = this.iUrl.getPort(); + port = port < 0 ? 80 : port; + String host = this.iUrl.getHost() + ":" + port; + Permission permission = new SocketPermission(host, "connect"); + return permission; + } + + @Override + public synchronized void connect() throws IOException { + if (!this.iConnected) getClient(); + this.iHttpClient.connect(); + } + + private synchronized void getClient() { + if (this.iConnected) return; + + this.iHttpClient = HttpClient.getClient(this.iUrl, this.iHttpClientPool, this.iAuthHandler); + this.iHttpClient.reset(); + this.iConnected = true; + } + + @Override + public synchronized void setRequestMethod(String pMethod) { + if (!this.iConnected) getClient(); + this.iHttpClient.setRequestMethod(pMethod); + this.method = pMethod; + } + + @Override + public synchronized void setRequestProperty(String key, String value) { + if (!this.iConnected) getClient(); + this.iHttpClient.setRequestProperty(key, value); + } + + @Override + public synchronized void disconnect() { + LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + if (this.iConnected) { + this.iConnected = false; + this.iHttpClient.disconnect(); + if (this.iHttpClientPool != null) { + this.iHttpClientPool.removeConnectionFromPool(this.iHttpClient); + this.iHttpClient = null; + } + } + logger.exit(); + } + + /** + * Closes the client pool + */ + public synchronized void close() { + LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + if (this.iHttpClientPool != null) { + synchronized (this.iHttpClientPool) { + this.iHttpClientPool.closePool(); + this.iHttpClientPool = null; + } + } + logger.exit(); + } + + @Override + public synchronized InputStream getInputStream() throws IOException { + if (!this.iConnected) getClient(); + try { + return this.iHttpClient.getInputStream(); + } catch (RuntimeException e) { + disconnect(); + throw e; + } catch (IOException e) { + disconnect(); + throw e; + } + } + + @Override + public synchronized OutputStream getOutputStream() throws RuntimeException { + if (!this.iConnected) getClient(); + try { + return this.iHttpClient.getOutputStream(); + } catch (RuntimeException e) { + disconnect(); + throw e; + } + } + + @Override + public boolean usingProxy() { + return false; + } + + /** + * Returns the http client + * + * @return The http client + */ + public synchronized HttpClient getHttpClient() { + if (!this.iConnected) getClient(); + return this.iHttpClient; + } + + @Override + public synchronized String getHeaderField(String name) { + if (!this.iConnected) getClient(); + return this.iHttpClient.getHeaderField(name); + } + + @Override + public synchronized String getHeaderFieldKey(int index) { + if (!this.iConnected) getClient(); + return this.iHttpClient.getHeaderFieldName(index); + } + + @Override + public synchronized String getHeaderField(int index) { + if (!this.iConnected) getClient(); + return this.iHttpClient.getHeaderFieldValue(index); + } + + @Override + public synchronized String getRequestProperty(String key) { + if (!this.iConnected) getClient(); + return this.iHttpClient.getRequestProperty(key); + } + + @Override + public synchronized String getRequestMethod() { + if (!this.iConnected) getClient(); + return this.iHttpClient.getRequestMethod(); + } + + /** + * Resets the http client + */ + public synchronized void reset() { + if (!this.iConnected) getClient(); + this.iHttpClient.reset(); + } + + @Override + public synchronized int getResponseCode() throws IOException { + if (!this.iConnected) getClient(); + return this.iHttpClient.getResponseCode(); + } + + @Override + public synchronized String getResponseMessage() { + if (!this.iConnected) getClient(); + return this.iHttpClient.getResponseMessage(); + } + + /** + * Enables/Disables the use of http 1.1 + * + * @param pUse11 + * If true http 1.1 is enabled. + */ + public synchronized void useHttp11(boolean pUse11) { + if (!this.iConnected) getClient(); + this.iHttpClient.useHttp11(pUse11); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/MessageReader.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/MessageReader.java similarity index 74% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/MessageReader.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/MessageReader.java index 85414d8..1134f6c 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/MessageReader.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/MessageReader.java @@ -1,202 +1,197 @@ -/* - (C) Copyright IBM Corp. 2005, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 3027479 2010-07-09 blaschke-oss Dead store to local variable - * 3601894 2013-01-23 blaschke-oss Enhance HTTP and CIM-XML tracing - * 2621 2013-02-23 blaschke-oss Not all chunked input has trailers - * 2635 2013-05-16 blaschke-oss Slowloris DoS attack for CIM indication listener port - * 2655 2013-08-14 blaschke-oss Content-length must be ignored when Transfer-encoding present - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.io.InputStream; -import java.util.logging.Level; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.io.BoundedInputStream; -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.io.ChunkedInputStream; -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.io.PersistentInputStream; -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; - -/** - * Class MessageReader is responsible for reading http messages - * - */ -public class MessageReader { - - HttpHeader iHeader; - - HttpServerMethod iMethod; - - private boolean iChunked = false; - - private String iEncoding = "UTF-8"; - - InputStream iContent; - - /** - * Ctor. - * - * @param pStream - * The input stream - * @param pTimeout - * The timeout for reading in entire header - * @throws IOException - * @throws HttpException - */ - public MessageReader(InputStream pStream, int pTimeout) throws IOException, HttpException { - this.iMethod = new HttpServerMethod(pStream); - this.iHeader = new HttpHeader(pStream, pTimeout); - - String encoding = this.iHeader.getField("Transfer-Encoding"); - if ((encoding != null) && (encoding.toLowerCase().endsWith("chunked"))) { - this.iChunked = true; - } - String length = this.iHeader.getField("Content-Length"); - int contentLength = -1; - if (length != null && length.length() > 0) { - try { - contentLength = Integer.parseInt(length); - } catch (Exception e) { - LogAndTraceBroker.getBroker().trace(Level.FINER, - "Exception while parsing http content-length", e); - } - } - String contentType = this.iHeader.getField("Content-Type"); - if (contentType != null) { - try { - HttpHeaderParser contentTypeHeader = new HttpHeaderParser(contentType); - encoding = contentTypeHeader.getValue("charset"); - } catch (Exception e) { - encoding = "UTF-8"; // TODO is this the default character - // encoding? - LogAndTraceBroker.getBroker().trace(Level.FINER, - "Exception while parsing http content-type", e); - } - this.iEncoding = encoding; - } - - this.iContent = new PersistentInputStream(pStream, isPersistentConnectionSupported()); - if (this.iChunked) { - this.iContent = new ChunkedInputStream(this.iContent, this.iHeader.getField("Trailer"), - "Indication Request"); - } else if (contentLength >= 0) { - this.iContent = new BoundedInputStream(this.iContent, contentLength); - } - } - - /** - * Returns the character encoding - * - * @return The character encoding - */ - public String getCharacterEncoding() { - return this.iEncoding; - } - - /** - * Returns the http header - * - * @return The http header - */ - public HttpHeader getHeader() { - return this.iHeader; - } - - /** - * Returns the http server method - * - * @return The http server method - */ - public HttpServerMethod getMethod() { - return this.iMethod; - } - - /** - * Returns the input stream - * - * @return The input stream - */ - public InputStream getInputStream() { - return this.iContent; - } - - /** - * Returns the persistent connection support state - * - * @return true if persistent connection is supported - */ - public boolean isPersistentConnectionSupported() { - String conn = this.iHeader.getField("Connection"); - if (conn != null) { - if (conn.equalsIgnoreCase("close")) return false; - if (conn.equalsIgnoreCase("Keep-Alive")) return true; - } - - return ((this.iMethod.getMajorVersion() >= 1) && (this.iMethod.getMinorVersion() >= 1)); - } - - /** - * Returns the chunking support state - * - * @return true if chunking is supported - */ - public boolean isChunkSupported() { - // TODO: make sure this is the correct way to test for chunk support - if ((this.iMethod.getMajorVersion() >= 1) && (this.iMethod.getMinorVersion() >= 1)) { - String TE; - if ((TE = this.iHeader.getField("TE")) != null && (TE.equalsIgnoreCase("trailers"))) { return true; } - } - return false; - } - - /** - * Closes the stream - * - * @throws IOException - */ - public void close() throws IOException { - this.iContent.close(); - } -} +/* + (C) Copyright IBM Corp. 2005, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 3027479 2010-07-09 blaschke-oss Dead store to local variable + * 3601894 2013-01-23 blaschke-oss Enhance HTTP and CIM-XML tracing + * 2621 2013-02-23 blaschke-oss Not all chunked input has trailers + * 2635 2013-05-16 blaschke-oss Slowloris DoS attack for CIM indication listener port + * 2655 2013-08-14 blaschke-oss Content-length must be ignored when Transfer-encoding present + */ + +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.io.InputStream; +import java.util.logging.Level; +import org.metricshub.wbem.sblim.cimclient.internal.http.io.BoundedInputStream; +import org.metricshub.wbem.sblim.cimclient.internal.http.io.ChunkedInputStream; +import org.metricshub.wbem.sblim.cimclient.internal.http.io.PersistentInputStream; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; + +/** + * Class MessageReader is responsible for reading http messages + * + */ +public class MessageReader { + HttpHeader iHeader; + + HttpServerMethod iMethod; + + private boolean iChunked = false; + + private String iEncoding = "UTF-8"; + + InputStream iContent; + + /** + * Ctor. + * + * @param pStream + * The input stream + * @param pTimeout + * The timeout for reading in entire header + * @throws IOException + * @throws HttpException + */ + public MessageReader(InputStream pStream, int pTimeout) throws IOException, HttpException { + this.iMethod = new HttpServerMethod(pStream); + this.iHeader = new HttpHeader(pStream, pTimeout); + + String encoding = this.iHeader.getField("Transfer-Encoding"); + if ((encoding != null) && (encoding.toLowerCase().endsWith("chunked"))) { + this.iChunked = true; + } + String length = this.iHeader.getField("Content-Length"); + int contentLength = -1; + if (length != null && length.length() > 0) { + try { + contentLength = Integer.parseInt(length); + } catch (Exception e) { + LogAndTraceBroker.getBroker().trace(Level.FINER, "Exception while parsing http content-length", e); + } + } + String contentType = this.iHeader.getField("Content-Type"); + if (contentType != null) { + try { + HttpHeaderParser contentTypeHeader = new HttpHeaderParser(contentType); + encoding = contentTypeHeader.getValue("charset"); + } catch (Exception e) { + encoding = "UTF-8"; // TODO is this the default character + // encoding? + LogAndTraceBroker.getBroker().trace(Level.FINER, "Exception while parsing http content-type", e); + } + this.iEncoding = encoding; + } + + this.iContent = new PersistentInputStream(pStream, isPersistentConnectionSupported()); + if (this.iChunked) { + this.iContent = new ChunkedInputStream(this.iContent, this.iHeader.getField("Trailer"), "Indication Request"); + } else if (contentLength >= 0) { + this.iContent = new BoundedInputStream(this.iContent, contentLength); + } + } + + /** + * Returns the character encoding + * + * @return The character encoding + */ + public String getCharacterEncoding() { + return this.iEncoding; + } + + /** + * Returns the http header + * + * @return The http header + */ + public HttpHeader getHeader() { + return this.iHeader; + } + + /** + * Returns the http server method + * + * @return The http server method + */ + public HttpServerMethod getMethod() { + return this.iMethod; + } + + /** + * Returns the input stream + * + * @return The input stream + */ + public InputStream getInputStream() { + return this.iContent; + } + + /** + * Returns the persistent connection support state + * + * @return true if persistent connection is supported + */ + public boolean isPersistentConnectionSupported() { + String conn = this.iHeader.getField("Connection"); + if (conn != null) { + if (conn.equalsIgnoreCase("close")) return false; + if (conn.equalsIgnoreCase("Keep-Alive")) return true; + } + + return ((this.iMethod.getMajorVersion() >= 1) && (this.iMethod.getMinorVersion() >= 1)); + } + + /** + * Returns the chunking support state + * + * @return true if chunking is supported + */ + public boolean isChunkSupported() { + // TODO: make sure this is the correct way to test for chunk support + if ((this.iMethod.getMajorVersion() >= 1) && (this.iMethod.getMinorVersion() >= 1)) { + String TE; + if ((TE = this.iHeader.getField("TE")) != null && (TE.equalsIgnoreCase("trailers"))) { + return true; + } + } + return false; + } + + /** + * Closes the stream + * + * @throws IOException + */ + public void close() throws IOException { + this.iContent.close(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/MessageWriter.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/MessageWriter.java similarity index 66% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/MessageWriter.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/MessageWriter.java index 134847c..08fb514 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/MessageWriter.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/MessageWriter.java @@ -1,201 +1,199 @@ -/* - (C) Copyright IBM Corp. 2005, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 17620 2005-06-29 thschaef eliminate ASCIIPrintStream1 in import statement - * 1535756 2006-08-07 lupusalex Make code warning free - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 3304058 2011-05-20 blaschke-oss Use same date format in change history - * 3601894 2013-01-23 blaschke-oss Enhance HTTP and CIM-XML tracing - * 2620 2013-02-23 blaschke-oss Chunked output broken - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.logging.Level; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.io.ASCIIPrintStream; -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.io.ChunkedOutputStream; -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.io.PersistentOutputStream; -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; - -/** - * Class MessageWriter is responsible for creating http messages - * - */ -public class MessageWriter { - - HttpHeader iHeader = null; - - HttpServerMethod iMethod = null; - - HttpHeader iTrailer = null; - - boolean iChunked = false; - - boolean iPersistent = false; - - ASCIIPrintStream iRealOS; - - ASCIIPrintStream iClientOS; - - ByteArrayOutputStream iBufferedOS; - - /** - * Ctor. - * - * @param pStream - * @param pPersistent - * @param pChunked - */ - public MessageWriter(OutputStream pStream, boolean pPersistent, boolean pChunked) { - this.iRealOS = new ASCIIPrintStream(pStream); - this.iChunked = pChunked; - this.iPersistent = pPersistent; - this.iBufferedOS = new ByteArrayOutputStream(); - if (pChunked) { - this.iClientOS = new ASCIIPrintStream(new ChunkedOutputStream( - new PersistentOutputStream(this.iBufferedOS, pPersistent), 512)); - } else { - this.iClientOS = new ASCIIPrintStream(new PersistentOutputStream(this.iBufferedOS, - pPersistent)); - } - this.iHeader = new HttpHeader(); - this.iMethod = new HttpServerMethod(HttpConnectionHandler.MAJOR_VERSION, - HttpConnectionHandler.MINOR_VERSION, 200, "OK"); - } - - /** - * Resets the stream - */ - public void reset() { - this.iBufferedOS.reset(); - } - - /** - * Sets the http header - * - * @param header - * The new value - */ - public void setHeader(HttpHeader header) { - this.iHeader = header; - } - - /** - * Sets the http server method - * - * @param method - * The new value - */ - public void setMethod(HttpServerMethod method) { - this.iMethod = method; - } - - /** - * Returns the http header - * - * @return The http header - */ - public HttpHeader getHeader() { - return this.iHeader; - } - - /** - * Returns the http server method - * - * @return The http server method - */ - public HttpServerMethod getMethod() { - return this.iMethod; - } - - /** - * Returns the output stream - * - * @return The output stream - */ - public ASCIIPrintStream getOutputStream() { - return this.iClientOS; - } - - /** - * Write the message and flushes the streams - * - * @throws IOException - */ - public void close() throws IOException { - this.iMethod.write(this.iRealOS); - this.iRealOS.flush(); - if (!this.iChunked) this.iHeader.removeField("Transfer-Encoding"); - else this.iHeader.addField("Transfer-Encoding", "chunked"); - if (this.iPersistent) this.iHeader.addField("Connection", "Keep-iAlive"); - else this.iHeader.addField("Connection", "close"); - - this.iHeader.addField("Content-Type", "application/xml;charset=\"utf-8\""); - if (!this.iChunked) this.iHeader.addField("Content-length", Integer - .toString(this.iBufferedOS.size())); - LogAndTraceBroker.getBroker().trace(Level.FINER, - "Indication Response HTTP Headers= " + this.iHeader.toString()); - this.iHeader.write(this.iRealOS); - this.iRealOS.flush(); - if (this.iChunked) this.iClientOS.close(); - this.iBufferedOS.writeTo(this.iRealOS); - if (this.iChunked && (this.iTrailer != null)) { - LogAndTraceBroker.getBroker().trace(Level.FINER, - "Indication Response HTTP Trailer Headers= " + this.iTrailer.toString()); - this.iTrailer.write(this.iRealOS); - } - this.iRealOS.flush(); - } - - /** - * Sets the trailer - * - * @param pTrailer - * The new value - */ - public void setTrailer(HttpHeader pTrailer) { - this.iTrailer = pTrailer; - } -} +/* + (C) Copyright IBM Corp. 2005, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 17620 2005-06-29 thschaef eliminate ASCIIPrintStream1 in import statement + * 1535756 2006-08-07 lupusalex Make code warning free + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 3304058 2011-05-20 blaschke-oss Use same date format in change history + * 3601894 2013-01-23 blaschke-oss Enhance HTTP and CIM-XML tracing + * 2620 2013-02-23 blaschke-oss Chunked output broken + */ + +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.logging.Level; +import org.metricshub.wbem.sblim.cimclient.internal.http.io.ASCIIPrintStream; +import org.metricshub.wbem.sblim.cimclient.internal.http.io.ChunkedOutputStream; +import org.metricshub.wbem.sblim.cimclient.internal.http.io.PersistentOutputStream; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; + +/** + * Class MessageWriter is responsible for creating http messages + * + */ +public class MessageWriter { + HttpHeader iHeader = null; + + HttpServerMethod iMethod = null; + + HttpHeader iTrailer = null; + + boolean iChunked = false; + + boolean iPersistent = false; + + ASCIIPrintStream iRealOS; + + ASCIIPrintStream iClientOS; + + ByteArrayOutputStream iBufferedOS; + + /** + * Ctor. + * + * @param pStream + * @param pPersistent + * @param pChunked + */ + public MessageWriter(OutputStream pStream, boolean pPersistent, boolean pChunked) { + this.iRealOS = new ASCIIPrintStream(pStream); + this.iChunked = pChunked; + this.iPersistent = pPersistent; + this.iBufferedOS = new ByteArrayOutputStream(); + if (pChunked) { + this.iClientOS = + new ASCIIPrintStream(new ChunkedOutputStream(new PersistentOutputStream(this.iBufferedOS, pPersistent), 512)); + } else { + this.iClientOS = new ASCIIPrintStream(new PersistentOutputStream(this.iBufferedOS, pPersistent)); + } + this.iHeader = new HttpHeader(); + this.iMethod = + new HttpServerMethod(HttpConnectionHandler.MAJOR_VERSION, HttpConnectionHandler.MINOR_VERSION, 200, "OK"); + } + + /** + * Resets the stream + */ + public void reset() { + this.iBufferedOS.reset(); + } + + /** + * Sets the http header + * + * @param header + * The new value + */ + public void setHeader(HttpHeader header) { + this.iHeader = header; + } + + /** + * Sets the http server method + * + * @param method + * The new value + */ + public void setMethod(HttpServerMethod method) { + this.iMethod = method; + } + + /** + * Returns the http header + * + * @return The http header + */ + public HttpHeader getHeader() { + return this.iHeader; + } + + /** + * Returns the http server method + * + * @return The http server method + */ + public HttpServerMethod getMethod() { + return this.iMethod; + } + + /** + * Returns the output stream + * + * @return The output stream + */ + public ASCIIPrintStream getOutputStream() { + return this.iClientOS; + } + + /** + * Write the message and flushes the streams + * + * @throws IOException + */ + public void close() throws IOException { + this.iMethod.write(this.iRealOS); + this.iRealOS.flush(); + if (!this.iChunked) this.iHeader.removeField("Transfer-Encoding"); else this.iHeader.addField( + "Transfer-Encoding", + "chunked" + ); + if (this.iPersistent) this.iHeader.addField("Connection", "Keep-iAlive"); else this.iHeader.addField( + "Connection", + "close" + ); + + this.iHeader.addField("Content-Type", "application/xml;charset=\"utf-8\""); + if (!this.iChunked) this.iHeader.addField("Content-length", Integer.toString(this.iBufferedOS.size())); + LogAndTraceBroker.getBroker().trace(Level.FINER, "Indication Response HTTP Headers= " + this.iHeader.toString()); + this.iHeader.write(this.iRealOS); + this.iRealOS.flush(); + if (this.iChunked) this.iClientOS.close(); + this.iBufferedOS.writeTo(this.iRealOS); + if (this.iChunked && (this.iTrailer != null)) { + LogAndTraceBroker + .getBroker() + .trace(Level.FINER, "Indication Response HTTP Trailer Headers= " + this.iTrailer.toString()); + this.iTrailer.write(this.iRealOS); + } + this.iRealOS.flush(); + } + + /** + * Sets the trailer + * + * @param pTrailer + * The new value + */ + public void setTrailer(HttpHeader pTrailer) { + this.iTrailer = pTrailer; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/PegasusLocalAuthInfo.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/PegasusLocalAuthInfo.java similarity index 67% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/PegasusLocalAuthInfo.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/PegasusLocalAuthInfo.java index 0d4e040..4fb7662 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/PegasusLocalAuthInfo.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/PegasusLocalAuthInfo.java @@ -1,182 +1,172 @@ -/* - (C) Copyright IBM Corp. 2006, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1516242 2006-07-05 lupusalex Support of OpenPegasus local authentication - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 1710066 2007-04-30 lupsualex LocalAuth fails for z/OS Pegasus - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 3027618 2010-07-14 blaschke-oss Close files/readers in finally blocks - */ -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.URI; -import java.util.logging.Level; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.Messages; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConstants; - -/** - * Implements OpenPegasus local authentication - */ -public class PegasusLocalAuthInfo extends AuthorizationInfo { - - private boolean iChallenged = false; - - /** - * Default ctor. - */ - public PegasusLocalAuthInfo() { - super(); - } - - /* - * (non-Javadoc) - * - * @see - * org.sblim.cimclient.internal.http.AuthorizationInfo#updateAuthenticationInfo - * (org.sblim.cimclient.internal.http.Challenge, java.net.URI, - * java.lang.String) - */ - /** - * @param challenge - * @param authenticate - * @param url - * @param requestMethod - */ - @Override - public void updateAuthenticationInfo(Challenge challenge, String authenticate, URI url, - String requestMethod) { - this.iChallenged = true; - this.iResponse = authenticate; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - - if (this.iChallenged && this.iResponse != null && this.iResponse.startsWith("Local ")) { - - String fileName = ""; - BufferedReader in = null; - - try { - - fileName = this.iResponse.substring(7, this.iResponse.length() - 1); - - if (fileName.length() == 0) throw new IOException( - "No local authorization file specified"); - - File authorizationFile = new File(fileName); - - if (!authorizationFile.canRead()) throw new IOException( - "Local authorization file not accessible"); - - in = WBEMConstants.Z_OS.equals(System.getProperty(WBEMConstants.OS_NAME)) ? new BufferedReader( - new InputStreamReader(new FileInputStream(authorizationFile), - WBEMConstants.ISO_8859_1)) - : new BufferedReader(new FileReader(authorizationFile)); - - StringBuffer buffer = new StringBuffer(); - String line; - - while (true) { - line = in.readLine(); - if (line == null) break; - buffer.append(line); - } - - StringBuffer header = new StringBuffer(); - header.append("Local \""); - header.append(getCredentials().getUserName()); - header.append(':'); - header.append(fileName); - header.append(':'); - header.append(buffer); - header.append('"'); - - return header.toString(); - - } catch (IOException e) { - LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.trace(Level.FINER, - "Exception while reading OpenPegasus local authorization file", e); - logger.message(Messages.HTTP_PEGASUS_LOCAL_AUTH_READ, fileName); - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException e) { - LogAndTraceBroker.getBroker().trace(Level.FINER, - "Exception while closing OpenPegasus local authorization file", e); - } - } - } - } - - return "Local \"" + getCredentials().getUserName() + "\""; - } - - @Override - public String getHeaderFieldName() { - return "PegasusAuthorization"; - } - - @Override - public boolean isSentOnFirstRequest() { - return true; - } - - @Override - public boolean isKeptAlive() { - return true; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1516242 2006-07-05 lupusalex Support of OpenPegasus local authentication + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 1710066 2007-04-30 lupsualex LocalAuth fails for z/OS Pegasus + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 3027618 2010-07-14 blaschke-oss Close files/readers in finally blocks + */ +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URI; +import java.util.logging.Level; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; +import org.metricshub.wbem.sblim.cimclient.internal.logging.Messages; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConstants; + +/** + * Implements OpenPegasus local authentication + */ +public class PegasusLocalAuthInfo extends AuthorizationInfo { + private boolean iChallenged = false; + + /** + * Default ctor. + */ + public PegasusLocalAuthInfo() { + super(); + } + + /* + * (non-Javadoc) + * + * @see + * org.sblim.cimclient.internal.http.AuthorizationInfo#updateAuthenticationInfo + * (org.sblim.cimclient.internal.http.Challenge, java.net.URI, + * java.lang.String) + */ + /** + * @param challenge + * @param authenticate + * @param url + * @param requestMethod + */ + @Override + public void updateAuthenticationInfo(Challenge challenge, String authenticate, URI url, String requestMethod) { + this.iChallenged = true; + this.iResponse = authenticate; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + if (this.iChallenged && this.iResponse != null && this.iResponse.startsWith("Local ")) { + String fileName = ""; + BufferedReader in = null; + + try { + fileName = this.iResponse.substring(7, this.iResponse.length() - 1); + + if (fileName.length() == 0) throw new IOException("No local authorization file specified"); + + File authorizationFile = new File(fileName); + + if (!authorizationFile.canRead()) throw new IOException("Local authorization file not accessible"); + + in = + WBEMConstants.Z_OS.equals(System.getProperty(WBEMConstants.OS_NAME)) + ? new BufferedReader( + new InputStreamReader(new FileInputStream(authorizationFile), WBEMConstants.ISO_8859_1) + ) + : new BufferedReader(new FileReader(authorizationFile)); + + StringBuffer buffer = new StringBuffer(); + String line; + + while (true) { + line = in.readLine(); + if (line == null) break; + buffer.append(line); + } + + StringBuffer header = new StringBuffer(); + header.append("Local \""); + header.append(getCredentials().getUserName()); + header.append(':'); + header.append(fileName); + header.append(':'); + header.append(buffer); + header.append('"'); + + return header.toString(); + } catch (IOException e) { + LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.trace(Level.FINER, "Exception while reading OpenPegasus local authorization file", e); + logger.message(Messages.HTTP_PEGASUS_LOCAL_AUTH_READ, fileName); + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException e) { + LogAndTraceBroker + .getBroker() + .trace(Level.FINER, "Exception while closing OpenPegasus local authorization file", e); + } + } + } + } + + return "Local \"" + getCredentials().getUserName() + "\""; + } + + @Override + public String getHeaderFieldName() { + return "PegasusAuthorization"; + } + + @Override + public boolean isSentOnFirstRequest() { + return true; + } + + @Override + public boolean isKeptAlive() { + return true; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/WwwAuthInfo.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/WwwAuthInfo.java similarity index 79% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/WwwAuthInfo.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/WwwAuthInfo.java index c0eabdc..30d50b1 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/WwwAuthInfo.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/WwwAuthInfo.java @@ -1,361 +1,385 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1536711 2006-08-15 lupusalex NullPointerException causes client call to never return - * 1516242 2006-11-27 lupusalex Support of OpenPegasus local authentication - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 1627832 2007-01-08 lupuslaex Incorrect retry behaviour on HTTP 401 - * 1892046 2008-02-13 blaschke-oss Basic/digest authentication problem for Japanese users - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2714989 2009-03-26 blaschke-oss Code cleanup from redundant null check et al - */ -package org.sentrysoftware.wbem.sblim.cimclient.internal.http; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.UnsupportedEncodingException; -import java.net.PasswordAuthentication; -import java.net.URI; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Vector; - -/** - * Implements HTTP basic and digest authentication - */ -public class WwwAuthInfo extends AuthorizationInfo { - - /** - * Default ctor. - */ - public WwwAuthInfo() { - super(); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - StringBuffer result = new StringBuffer(); - - String _nc = Long.toHexString(this.iNc); - - if (this.iScheme.equalsIgnoreCase("Digest")) { - - if (this.iRealm == null) { // support for some ICAT CIMOMs buggy - // Digest authentication - try { - MessageDigest messageDigest = null; - messageDigest = MessageDigest.getInstance("MD5"); - - messageDigest.update(getBytes((this.iCredentials != null && this.iCredentials - .getUserName() != null) ? String.valueOf(this.iCredentials - .getPassword()) : "null", "UTF-8")); - String pass = HttpClient.convertToHexString(messageDigest.digest()); - return "Digest username=" - + ((this.iCredentials != null && this.iCredentials.getUserName() != null) ? this.iCredentials - .getUserName() - : "null") + ", response=" + pass; - } catch (NoSuchAlgorithmException e) { - // TODO log - e.printStackTrace(); - } - } - - result.append(this.iScheme); - result.append(" username=\""); - result - .append((this.iCredentials != null && this.iCredentials.getUserName() != null) ? this.iCredentials - .getUserName() - : "null"); - result.append("\""); - if (this.iRealm != null) { - result.append(", realm=\""); - result.append(this.iRealm); - result.append("\""); - } - if (this.iNonce != null) { - result.append(", nonce=\""); - result.append(this.iNonce); - result.append("\""); - } - result.append(", uri=\""); - result.append(this.iUri); - result.append("\", response=\""); - result.append(this.iResponse); - result.append("\""); - // if (algorithm != null) { - // result.append(", algorithm="); - // result.append(algorithm); - // } - if (this.iCnonce != null) { - result.append(", cnonce=\""); - result.append(this.iCnonce); - result.append("\""); - } - if (this.iOpaque != null) { - result.append(", opaque=\""); - result.append(this.iOpaque); - result.append("\""); - } - if (this.iQop != null) { - result.append(", qop="); - result.append(this.iQop); - } - if (this.iNc > -1) { - result.append(", nc="); - result.append("00000000".substring(_nc.length())); - result.append(_nc); - } - } else if (this.iScheme.equalsIgnoreCase("Basic")) { - - result.append("Basic "); - - StringBuffer tmp = new StringBuffer(); - tmp - .append((this.iCredentials != null && this.iCredentials.getUserName() != null) ? this.iCredentials - .getUserName() - : "null"); - tmp.append(':'); - tmp - .append((this.iCredentials != null && this.iCredentials.getPassword() != null) ? String - .valueOf(this.iCredentials.getPassword()) - : "null"); - - result.append(BASE64Encoder.encode(getBytes(tmp.toString(), "UTF-8"))); - } - return result.toString(); - } - - /** - * Splits a comma-separated string into multiple substrings - * - * @param pLine - * The comma-separated string - * @return The array of substrings (excluding commas) - */ - public static String[] split(String pLine) { - Vector elem = new Vector(); - int start = 0; - int end; - while ((end = pLine.indexOf(',')) > -1) { - elem.add(pLine.substring(start, end)); - start = end + 1; - } - if (end < pLine.length()) elem.add(pLine.substring(start)); - String[] result = new String[elem.size()]; - elem.toArray(result); - return result; - } - - private static byte[] getBytes(String str, String encoding) { - byte[] bytes; - try { - bytes = str.getBytes(encoding); - } catch (UnsupportedEncodingException e) { - bytes = str.getBytes(); - } - return bytes; - } - - /* - * (non-Javadoc) - * - * @see - * org.sblim.cimclient.internal.http.AuthorizationInfo#updateAuthenticationInfo - * (org.sblim.cimclient.internal.http.Challenge, java.net.URI, - * java.lang.String) - */ - /** - * @param authenticate - */ - @Override - public void updateAuthenticationInfo(Challenge challenge, String authenticate, URI url, - String requestMethod) throws NoSuchAlgorithmException { - - setURI(url.getPath()); - HttpHeader params = challenge.getParams(); - - this.iScheme = challenge.getScheme(); - - if (!this.iScheme.equalsIgnoreCase("Digest")) { return; } - - this.iRealm = params.getField("realm"); - - String algorithm = params.getField("algorithm"); - String opaque = params.getField("opaque"); - String nonce = params.getField("nonce"); - String qop = params.getField("qop"); - - this.iAlgorithm = (algorithm != null) ? algorithm : this.iAlgorithm; - this.iOpaque = (opaque != null) ? opaque : this.iOpaque; - this.iNonce = (nonce != null) ? nonce : this.iNonce; - this.iQop = (qop != null) ? qop : this.iQop; - - MessageDigest messageDigest = null; - - messageDigest = MessageDigest.getInstance("MD5"); - - if (qop != null || ("md5-sess".equalsIgnoreCase(algorithm))) { - long time = System.currentTimeMillis(); - byte[] b = new byte[8]; - - b[0] = (byte) ((time >> 0) & 0xFF); - b[1] = (byte) ((time >> 8) & 0xFF); - b[2] = (byte) ((time >> 16) & 0xFF); - b[3] = (byte) ((time >> 24) & 0xFF); - b[4] = (byte) ((time >> 32) & 0xFF); - b[5] = (byte) ((time >> 40) & 0xFF); - b[6] = (byte) ((time >> 48) & 0xFF); - b[7] = (byte) ((time >> 56) & 0xFF); - - messageDigest.reset(); - messageDigest.update(b); - - this.iCnonce = HttpClient.convertToHexString(messageDigest.digest()); - } - if (qop != null) { - String[] list_qop = split(qop); - for (int i = 0; i < list_qop.length; i++) { - if (list_qop[i].equalsIgnoreCase("auth-int")) { - qop = "auth-int"; // this one has higher priority - break; - } - if ((list_qop[i].equalsIgnoreCase("auth"))) qop = "auth"; - } - setQop(qop); - } - String nc1 = params.getField("nc"); - long challengeNc = 1; - if (nc1 != null) { - try { - challengeNc = Long.parseLong(nc1, 16); - } catch (Exception e) { - // Logger logger = SessionProperties.getGlobalProperties() - // .getLogger(); - // if (logger.isLoggable(Level.WARNING)) { - // logger.log(Level.WARNING, - // "exception while parsing challenge NC", e); - // } - } - if (getNc() == challengeNc) { - setNc(++challengeNc); - } - } else { - setNc(challengeNc = 1); - } - - messageDigest.reset(); - PasswordAuthentication credentials1 = getCredentials(); - this.iA1 = credentials1.getUserName() + ":" + getRealm() + ":" - + String.valueOf(credentials1.getPassword()); - // System.out.println("Base:"+A1); - messageDigest.update(getBytes(this.iA1, "UTF-8")); - - if ("md5-sess".equalsIgnoreCase(algorithm)) { - messageDigest.update(getBytes((":" + getNonce() + ":" + getCnonce()), "UTF-8")); - - } - - byte[] digest1 = messageDigest.digest(); - String sessionKey = HttpClient.convertToHexString(digest1); - - // System.out.println("A1:"+sessionKey); - String method = requestMethod; - - // if (con instanceof HttpURLConnection) - // method = ((HttpURLConnection) con).getRequestMethod(); - - String A2 = method + ":" + getURI(); - - if ("auth-int".equalsIgnoreCase(qop)) { - messageDigest.reset(); - // messageDigest.update(readFully(con)); //TODO - messageDigest.update(new byte[] {}); // TODO this must be the - // entity body, not the - // message body - A2 = A2 + ":" + HttpClient.convertToHexString(messageDigest.digest()); - } - messageDigest.reset(); - messageDigest.update(getBytes(A2, "UTF-8")); - A2 = HttpClient.convertToHexString(messageDigest.digest()); - - messageDigest.reset(); - if (qop == null) { - messageDigest.update(getBytes((sessionKey + ":" + nonce + ":" + A2), "UTF-8")); - } else { - String _nc = Long.toHexString(challengeNc); - messageDigest.update(getBytes((sessionKey + ":" + nonce + ":" - + "00000000".substring(_nc.length()) + _nc + ":" + getCnonce() + ":" + qop - + ":" + A2), "UTF-8")); - } - this.iResponse = HttpClient.convertToHexString(messageDigest.digest()); - - // TODO handle digest-required header - } - - /* - * (non-Javadoc) - * - * @see - * org.sblim.cimclient.internal.http.AuthorizationInfo#getHeaderFieldName() - */ - @Override - public String getHeaderFieldName() { - return "Authorization"; - } - - /* - * (non-Javadoc) - * - * @see - * org.sblim.cimclient.internal.http.AuthorizationInfo#isSentOnFirstRequest - * () - */ - @Override - public boolean isSentOnFirstRequest() { - return false; - } - - @Override - public boolean isKeptAlive() { - return true; - } -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1536711 2006-08-15 lupusalex NullPointerException causes client call to never return + * 1516242 2006-11-27 lupusalex Support of OpenPegasus local authentication + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 1627832 2007-01-08 lupuslaex Incorrect retry behaviour on HTTP 401 + * 1892046 2008-02-13 blaschke-oss Basic/digest authentication problem for Japanese users + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2714989 2009-03-26 blaschke-oss Code cleanup from redundant null check et al + */ +package org.metricshub.wbem.sblim.cimclient.internal.http; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.UnsupportedEncodingException; +import java.net.PasswordAuthentication; +import java.net.URI; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Vector; + +/** + * Implements HTTP basic and digest authentication + */ +public class WwwAuthInfo extends AuthorizationInfo { + + /** + * Default ctor. + */ + public WwwAuthInfo() { + super(); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuffer result = new StringBuffer(); + + String _nc = Long.toHexString(this.iNc); + + if (this.iScheme.equalsIgnoreCase("Digest")) { + if (this.iRealm == null) { // support for some ICAT CIMOMs buggy + // Digest authentication + try { + MessageDigest messageDigest = null; + messageDigest = MessageDigest.getInstance("MD5"); + + messageDigest.update( + getBytes( + (this.iCredentials != null && this.iCredentials.getUserName() != null) + ? String.valueOf(this.iCredentials.getPassword()) + : "null", + "UTF-8" + ) + ); + String pass = HttpClient.convertToHexString(messageDigest.digest()); + return ( + "Digest username=" + + ( + (this.iCredentials != null && this.iCredentials.getUserName() != null) + ? this.iCredentials.getUserName() + : "null" + ) + + ", response=" + + pass + ); + } catch (NoSuchAlgorithmException e) { + // TODO log + e.printStackTrace(); + } + } + + result.append(this.iScheme); + result.append(" username=\""); + result.append( + (this.iCredentials != null && this.iCredentials.getUserName() != null) + ? this.iCredentials.getUserName() + : "null" + ); + result.append("\""); + if (this.iRealm != null) { + result.append(", realm=\""); + result.append(this.iRealm); + result.append("\""); + } + if (this.iNonce != null) { + result.append(", nonce=\""); + result.append(this.iNonce); + result.append("\""); + } + result.append(", uri=\""); + result.append(this.iUri); + result.append("\", response=\""); + result.append(this.iResponse); + result.append("\""); + // if (algorithm != null) { + // result.append(", algorithm="); + // result.append(algorithm); + // } + if (this.iCnonce != null) { + result.append(", cnonce=\""); + result.append(this.iCnonce); + result.append("\""); + } + if (this.iOpaque != null) { + result.append(", opaque=\""); + result.append(this.iOpaque); + result.append("\""); + } + if (this.iQop != null) { + result.append(", qop="); + result.append(this.iQop); + } + if (this.iNc > -1) { + result.append(", nc="); + result.append("00000000".substring(_nc.length())); + result.append(_nc); + } + } else if (this.iScheme.equalsIgnoreCase("Basic")) { + result.append("Basic "); + + StringBuffer tmp = new StringBuffer(); + tmp.append( + (this.iCredentials != null && this.iCredentials.getUserName() != null) + ? this.iCredentials.getUserName() + : "null" + ); + tmp.append(':'); + tmp.append( + (this.iCredentials != null && this.iCredentials.getPassword() != null) + ? String.valueOf(this.iCredentials.getPassword()) + : "null" + ); + + result.append(BASE64Encoder.encode(getBytes(tmp.toString(), "UTF-8"))); + } + return result.toString(); + } + + /** + * Splits a comma-separated string into multiple substrings + * + * @param pLine + * The comma-separated string + * @return The array of substrings (excluding commas) + */ + public static String[] split(String pLine) { + Vector elem = new Vector(); + int start = 0; + int end; + while ((end = pLine.indexOf(',')) > -1) { + elem.add(pLine.substring(start, end)); + start = end + 1; + } + if (end < pLine.length()) elem.add(pLine.substring(start)); + String[] result = new String[elem.size()]; + elem.toArray(result); + return result; + } + + private static byte[] getBytes(String str, String encoding) { + byte[] bytes; + try { + bytes = str.getBytes(encoding); + } catch (UnsupportedEncodingException e) { + bytes = str.getBytes(); + } + return bytes; + } + + /* + * (non-Javadoc) + * + * @see + * org.sblim.cimclient.internal.http.AuthorizationInfo#updateAuthenticationInfo + * (org.sblim.cimclient.internal.http.Challenge, java.net.URI, + * java.lang.String) + */ + /** + * @param authenticate + */ + @Override + public void updateAuthenticationInfo(Challenge challenge, String authenticate, URI url, String requestMethod) + throws NoSuchAlgorithmException { + setURI(url.getPath()); + HttpHeader params = challenge.getParams(); + + this.iScheme = challenge.getScheme(); + + if (!this.iScheme.equalsIgnoreCase("Digest")) { + return; + } + + this.iRealm = params.getField("realm"); + + String algorithm = params.getField("algorithm"); + String opaque = params.getField("opaque"); + String nonce = params.getField("nonce"); + String qop = params.getField("qop"); + + this.iAlgorithm = (algorithm != null) ? algorithm : this.iAlgorithm; + this.iOpaque = (opaque != null) ? opaque : this.iOpaque; + this.iNonce = (nonce != null) ? nonce : this.iNonce; + this.iQop = (qop != null) ? qop : this.iQop; + + MessageDigest messageDigest = null; + + messageDigest = MessageDigest.getInstance("MD5"); + + if (qop != null || ("md5-sess".equalsIgnoreCase(algorithm))) { + long time = System.currentTimeMillis(); + byte[] b = new byte[8]; + + b[0] = (byte) ((time >> 0) & 0xFF); + b[1] = (byte) ((time >> 8) & 0xFF); + b[2] = (byte) ((time >> 16) & 0xFF); + b[3] = (byte) ((time >> 24) & 0xFF); + b[4] = (byte) ((time >> 32) & 0xFF); + b[5] = (byte) ((time >> 40) & 0xFF); + b[6] = (byte) ((time >> 48) & 0xFF); + b[7] = (byte) ((time >> 56) & 0xFF); + + messageDigest.reset(); + messageDigest.update(b); + + this.iCnonce = HttpClient.convertToHexString(messageDigest.digest()); + } + if (qop != null) { + String[] list_qop = split(qop); + for (int i = 0; i < list_qop.length; i++) { + if (list_qop[i].equalsIgnoreCase("auth-int")) { + qop = "auth-int"; // this one has higher priority + break; + } + if ((list_qop[i].equalsIgnoreCase("auth"))) qop = "auth"; + } + setQop(qop); + } + String nc1 = params.getField("nc"); + long challengeNc = 1; + if (nc1 != null) { + try { + challengeNc = Long.parseLong(nc1, 16); + } catch (Exception e) { + // Logger logger = SessionProperties.getGlobalProperties() + // .getLogger(); + // if (logger.isLoggable(Level.WARNING)) { + // logger.log(Level.WARNING, + // "exception while parsing challenge NC", e); + // } + } + if (getNc() == challengeNc) { + setNc(++challengeNc); + } + } else { + setNc(challengeNc = 1); + } + + messageDigest.reset(); + PasswordAuthentication credentials1 = getCredentials(); + this.iA1 = credentials1.getUserName() + ":" + getRealm() + ":" + String.valueOf(credentials1.getPassword()); + // System.out.println("Base:"+A1); + messageDigest.update(getBytes(this.iA1, "UTF-8")); + + if ("md5-sess".equalsIgnoreCase(algorithm)) { + messageDigest.update(getBytes((":" + getNonce() + ":" + getCnonce()), "UTF-8")); + } + + byte[] digest1 = messageDigest.digest(); + String sessionKey = HttpClient.convertToHexString(digest1); + + // System.out.println("A1:"+sessionKey); + String method = requestMethod; + + // if (con instanceof HttpURLConnection) + // method = ((HttpURLConnection) con).getRequestMethod(); + + String A2 = method + ":" + getURI(); + + if ("auth-int".equalsIgnoreCase(qop)) { + messageDigest.reset(); + // messageDigest.update(readFully(con)); //TODO + messageDigest.update(new byte[] {}); // TODO this must be the + // entity body, not the + // message body + A2 = A2 + ":" + HttpClient.convertToHexString(messageDigest.digest()); + } + messageDigest.reset(); + messageDigest.update(getBytes(A2, "UTF-8")); + A2 = HttpClient.convertToHexString(messageDigest.digest()); + + messageDigest.reset(); + if (qop == null) { + messageDigest.update(getBytes((sessionKey + ":" + nonce + ":" + A2), "UTF-8")); + } else { + String _nc = Long.toHexString(challengeNc); + messageDigest.update( + getBytes( + ( + sessionKey + + ":" + + nonce + + ":" + + "00000000".substring(_nc.length()) + + _nc + + ":" + + getCnonce() + + ":" + + qop + + ":" + + A2 + ), + "UTF-8" + ) + ); + } + this.iResponse = HttpClient.convertToHexString(messageDigest.digest()); + // TODO handle digest-required header + } + + /* + * (non-Javadoc) + * + * @see + * org.sblim.cimclient.internal.http.AuthorizationInfo#getHeaderFieldName() + */ + @Override + public String getHeaderFieldName() { + return "Authorization"; + } + + /* + * (non-Javadoc) + * + * @see + * org.sblim.cimclient.internal.http.AuthorizationInfo#isSentOnFirstRequest + * () + */ + @Override + public boolean isSentOnFirstRequest() { + return false; + } + + @Override + public boolean isKeptAlive() { + return true; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/ASCIIPrintStream.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/ASCIIPrintStream.java similarity index 83% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/ASCIIPrintStream.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/ASCIIPrintStream.java index 0558eb0..6b4c495 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/ASCIIPrintStream.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/ASCIIPrintStream.java @@ -1,429 +1,425 @@ -/* - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 18045 2005-08-10 pineiro5 Some code clean up in multiple points - * 1535756 2006-08-07 lupusalex Make code warning free - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2714989 2009-03-26 blaschke-oss Code cleanup from redundant null check et al - */ -package org.sentrysoftware.wbem.sblim.cimclient.internal.http.io; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.BufferedWriter; -import java.io.FilterOutputStream; -import java.io.IOException; -import java.io.InterruptedIOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; - -/** - * Class ASCIIPrintStream implement a stream with ASCII charset - * - */ -public class ASCIIPrintStream extends FilterOutputStream { - - private boolean iAutoFlush = false; - - private Exception iTrouble = null; - - private BufferedWriter iTextOut; - - private ASCIIPrintStream(boolean autoFlush, OutputStream pOut) { - super(pOut); - if (pOut == null) throw new NullPointerException("Null output stream"); - this.iAutoFlush = autoFlush; - } - - /** - * Ctor. - * - * @param pStream - * The underlying stream - */ - public ASCIIPrintStream(OutputStream pStream) { - this(pStream, false); - init(new OutputStreamWriter(this)); - } - - /** - * Ctor. - * - * @param pStream - * The underlying stream - * @param pAutoFlush - * If true the stream is automatically flushed after - * write. - */ - public ASCIIPrintStream(OutputStream pStream, boolean pAutoFlush) { - this(pAutoFlush, pStream); - init(new OutputStreamWriter(this.out)); - } - - /** - * Ctor. - * - * @param pStream - * The underlying stream - * @param pAutoFlush - * If true the stream is automatically flushed after - * write. - * @param pEncoding - * Ignored - */ - public ASCIIPrintStream(OutputStream pStream, boolean pAutoFlush, String pEncoding) { - this(pStream, pAutoFlush); - } - - private void init(OutputStreamWriter osw) { - this.iTextOut = new BufferedWriter(osw); - } - - private void write(String str) { - int stringLength = str.length(); - char charArray[] = new char[stringLength]; - byte asciiArray[] = new byte[stringLength]; - str.getChars(0, stringLength, charArray, 0); - for (int i = 0; i < stringLength; i++) - asciiArray[i] = charArray[i] >= '\u0100' ? 63 : (byte) charArray[i]; - - write(asciiArray, 0, stringLength); - } - - /** - * Prints a boolean value - * - * @param pValue - * The value - */ - public void print(boolean pValue) { - write(pValue ? "true" : "false"); - } - - /** - * Prints a single character - * - * @param c - * The character - */ - public void print(char c) { - write(String.valueOf(c)); - } - - /** - * Prints an integer value - * - * @param i - * The value - */ - public void print(int i) { - write(String.valueOf(i)); - } - - /** - * Prints a long value - * - * @param l - * The value - */ - public void print(long l) { - write(String.valueOf(l)); - } - - /** - * Prints a float value - * - * @param f - * The value - */ - public void print(float f) { - write(String.valueOf(f)); - } - - /** - * Prints a double value - * - * @param d - * The value - */ - public void print(double d) { - write(String.valueOf(d)); - } - - /** - * Prints a character array - * - * @param pArray - * The array - */ - public void print(char pArray[]) { - write(String.valueOf(pArray)); - } - - /** - * Prints a string - * - * @param s - * The string - */ - public void print(String s) { - write(s == null ? "null" : s); - } - - /** - * Prints an object - * - * @param pObj - * The object - */ - public void print(Object pObj) { - write(String.valueOf(pObj)); - } - - /** - * Prints a newline - */ - public void println() { - newLine(); - } - - /** - * println - * - * @param flag - */ - public void println(boolean flag) { - synchronized (this) { - print(flag); - newLine(); - } - } - - /** - * println - * - * @param c - */ - public void println(char c) { - synchronized (this) { - print(c); - newLine(); - } - } - - /** - * println - * - * @param i - */ - public void println(int i) { - synchronized (this) { - print(i); - newLine(); - } - } - - /** - * println - * - * @param l - */ - public void println(long l) { - synchronized (this) { - print(l); - newLine(); - } - } - - /** - * println - * - * @param f - */ - public void println(float f) { - synchronized (this) { - print(f); - newLine(); - } - } - - /** - * println - * - * @param d - */ - public void println(double d) { - synchronized (this) { - print(d); - newLine(); - } - } - - /** - * println - * - * @param ac - */ - public void println(char ac[]) { - synchronized (this) { - print(ac); - newLine(); - } - } - - /** - * println - * - * @param s - */ - public void println(String s) { - synchronized (this) { - print(s); - newLine(); - } - } - - /** - * println - * - * @param obj - */ - public void println(Object obj) { - synchronized (this) { - print(obj); - newLine(); - } - } - - private void newLine() { - try { - synchronized (this) { - ensureOpen(); - this.iTextOut.newLine(); - if (this.iAutoFlush) this.out.flush(); - } - } catch (InterruptedIOException x) { - Thread.currentThread().interrupt(); - } catch (IOException x) { - this.iTrouble = x; - } - } - - @Override - public void write(byte buf[], int off, int len) { - try { - synchronized (this) { - ensureOpen(); - this.out.write(buf, off, len); - // i ++; - if (this.iAutoFlush) this.out.flush(); - } - // System.out.println("TOTAL:"+i); - } catch (InterruptedIOException x) { - Thread.currentThread().interrupt(); - } catch (IOException x) { - this.iTrouble = x; - } - } - - @Override - public void write(int b) { - try { - synchronized (this) { - ensureOpen(); - this.out.write(b); - if ((b == '\n') && this.iAutoFlush) this.out.flush(); - } - } catch (InterruptedIOException x) { - Thread.currentThread().interrupt(); - } catch (IOException x) { - this.iTrouble = x; - } - } - - protected void setError() { - // trouble = x; - } - - /** - * Returns the last exception caught - * - * @return The exception - */ - public Exception checkError() { - if (this.out != null) flush(); - return this.iTrouble; - } - - @Override - public void close() { - synchronized (this) { - if (!this.closing) { - this.closing = true; - try { - this.iTextOut.close(); - this.out.close(); - } catch (IOException x) { - this.iTrouble = x; - } - this.iTextOut = null; - // iCharOut = null; - this.out = null; - } - } - } - - @Override - public void flush() { - synchronized (this) { - try { - ensureOpen(); - this.out.flush(); - } catch (IOException x) { - this.iTrouble = x; - } - } - } - - private boolean closing = false; - - private void ensureOpen() throws IOException { - if (this.out == null) throw new IOException("Stream closed"); - } -} +/* + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 18045 2005-08-10 pineiro5 Some code clean up in multiple points + * 1535756 2006-08-07 lupusalex Make code warning free + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2714989 2009-03-26 blaschke-oss Code cleanup from redundant null check et al + */ +package org.metricshub.wbem.sblim.cimclient.internal.http.io; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.BufferedWriter; +import java.io.FilterOutputStream; +import java.io.IOException; +import java.io.InterruptedIOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; + +/** + * Class ASCIIPrintStream implement a stream with ASCII charset + * + */ +public class ASCIIPrintStream extends FilterOutputStream { + private boolean iAutoFlush = false; + + private Exception iTrouble = null; + + private BufferedWriter iTextOut; + + private ASCIIPrintStream(boolean autoFlush, OutputStream pOut) { + super(pOut); + if (pOut == null) throw new NullPointerException("Null output stream"); + this.iAutoFlush = autoFlush; + } + + /** + * Ctor. + * + * @param pStream + * The underlying stream + */ + public ASCIIPrintStream(OutputStream pStream) { + this(pStream, false); + init(new OutputStreamWriter(this)); + } + + /** + * Ctor. + * + * @param pStream + * The underlying stream + * @param pAutoFlush + * If true the stream is automatically flushed after + * write. + */ + public ASCIIPrintStream(OutputStream pStream, boolean pAutoFlush) { + this(pAutoFlush, pStream); + init(new OutputStreamWriter(this.out)); + } + + /** + * Ctor. + * + * @param pStream + * The underlying stream + * @param pAutoFlush + * If true the stream is automatically flushed after + * write. + * @param pEncoding + * Ignored + */ + public ASCIIPrintStream(OutputStream pStream, boolean pAutoFlush, String pEncoding) { + this(pStream, pAutoFlush); + } + + private void init(OutputStreamWriter osw) { + this.iTextOut = new BufferedWriter(osw); + } + + private void write(String str) { + int stringLength = str.length(); + char charArray[] = new char[stringLength]; + byte asciiArray[] = new byte[stringLength]; + str.getChars(0, stringLength, charArray, 0); + for (int i = 0; i < stringLength; i++) asciiArray[i] = charArray[i] >= '\u0100' ? 63 : (byte) charArray[i]; + + write(asciiArray, 0, stringLength); + } + + /** + * Prints a boolean value + * + * @param pValue + * The value + */ + public void print(boolean pValue) { + write(pValue ? "true" : "false"); + } + + /** + * Prints a single character + * + * @param c + * The character + */ + public void print(char c) { + write(String.valueOf(c)); + } + + /** + * Prints an integer value + * + * @param i + * The value + */ + public void print(int i) { + write(String.valueOf(i)); + } + + /** + * Prints a long value + * + * @param l + * The value + */ + public void print(long l) { + write(String.valueOf(l)); + } + + /** + * Prints a float value + * + * @param f + * The value + */ + public void print(float f) { + write(String.valueOf(f)); + } + + /** + * Prints a double value + * + * @param d + * The value + */ + public void print(double d) { + write(String.valueOf(d)); + } + + /** + * Prints a character array + * + * @param pArray + * The array + */ + public void print(char pArray[]) { + write(String.valueOf(pArray)); + } + + /** + * Prints a string + * + * @param s + * The string + */ + public void print(String s) { + write(s == null ? "null" : s); + } + + /** + * Prints an object + * + * @param pObj + * The object + */ + public void print(Object pObj) { + write(String.valueOf(pObj)); + } + + /** + * Prints a newline + */ + public void println() { + newLine(); + } + + /** + * println + * + * @param flag + */ + public void println(boolean flag) { + synchronized (this) { + print(flag); + newLine(); + } + } + + /** + * println + * + * @param c + */ + public void println(char c) { + synchronized (this) { + print(c); + newLine(); + } + } + + /** + * println + * + * @param i + */ + public void println(int i) { + synchronized (this) { + print(i); + newLine(); + } + } + + /** + * println + * + * @param l + */ + public void println(long l) { + synchronized (this) { + print(l); + newLine(); + } + } + + /** + * println + * + * @param f + */ + public void println(float f) { + synchronized (this) { + print(f); + newLine(); + } + } + + /** + * println + * + * @param d + */ + public void println(double d) { + synchronized (this) { + print(d); + newLine(); + } + } + + /** + * println + * + * @param ac + */ + public void println(char ac[]) { + synchronized (this) { + print(ac); + newLine(); + } + } + + /** + * println + * + * @param s + */ + public void println(String s) { + synchronized (this) { + print(s); + newLine(); + } + } + + /** + * println + * + * @param obj + */ + public void println(Object obj) { + synchronized (this) { + print(obj); + newLine(); + } + } + + private void newLine() { + try { + synchronized (this) { + ensureOpen(); + this.iTextOut.newLine(); + if (this.iAutoFlush) this.out.flush(); + } + } catch (InterruptedIOException x) { + Thread.currentThread().interrupt(); + } catch (IOException x) { + this.iTrouble = x; + } + } + + @Override + public void write(byte buf[], int off, int len) { + try { + synchronized (this) { + ensureOpen(); + this.out.write(buf, off, len); + // i ++; + if (this.iAutoFlush) this.out.flush(); + } + // System.out.println("TOTAL:"+i); + } catch (InterruptedIOException x) { + Thread.currentThread().interrupt(); + } catch (IOException x) { + this.iTrouble = x; + } + } + + @Override + public void write(int b) { + try { + synchronized (this) { + ensureOpen(); + this.out.write(b); + if ((b == '\n') && this.iAutoFlush) this.out.flush(); + } + } catch (InterruptedIOException x) { + Thread.currentThread().interrupt(); + } catch (IOException x) { + this.iTrouble = x; + } + } + + protected void setError() { + // trouble = x; + } + + /** + * Returns the last exception caught + * + * @return The exception + */ + public Exception checkError() { + if (this.out != null) flush(); + return this.iTrouble; + } + + @Override + public void close() { + synchronized (this) { + if (!this.closing) { + this.closing = true; + try { + this.iTextOut.close(); + this.out.close(); + } catch (IOException x) { + this.iTrouble = x; + } + this.iTextOut = null; + // iCharOut = null; + this.out = null; + } + } + } + + @Override + public void flush() { + synchronized (this) { + try { + ensureOpen(); + this.out.flush(); + } catch (IOException x) { + this.iTrouble = x; + } + } + } + + private boolean closing = false; + + private void ensureOpen() throws IOException { + if (this.out == null) throw new IOException("Stream closed"); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/BoundedInputStream.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/BoundedInputStream.java similarity index 77% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/BoundedInputStream.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/BoundedInputStream.java index 5d2ac61..b6c2615 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/BoundedInputStream.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/BoundedInputStream.java @@ -1,156 +1,155 @@ -/* - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.http.io; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.*; - -/** - * Class BoundedInputStream implements an input stream with a maximum byte - * count. - * - */ -public class BoundedInputStream extends FilterInputStream { - - private long maxLen, used; - - private boolean closed = false; - - /** - * Ctor. Creates the stream with unlimited length. - * - * @param pStream - * The stream this one is build upon - */ - public BoundedInputStream(InputStream pStream) { - this(pStream, -1); - } - - /** - * Ctor. - * - * @param pStream - * The stream this one is build upon - * @param pMaximumLength - * The maximum number of bytes that can be read from this stream. - * A value of -1 represents unlimited mode. - */ - public BoundedInputStream(InputStream pStream, long pMaximumLength) { - super(pStream); - this.maxLen = pMaximumLength; - this.used = 0; - this.in = pStream; - } - - @Override - public int read() throws IOException { - if (this.maxLen > -1) { - if (this.used >= this.maxLen) return -1; - - int value = this.in.read(); - if (value > -1) this.used++; - return value; - } - return this.in.read(); - } - - @Override - public int read(byte buf[]) throws IOException { - return read(buf, 0, buf.length); - } - - @Override - public int read(byte buf[], int off, int len) throws IOException { - if (this.closed) throw new IOException("I/O error - the stream is closed"); - - if (this.maxLen > -1) { - if (this.used >= this.maxLen) return -1; - - long min = ((this.used + len) > this.maxLen) ? this.maxLen - this.used : len; - int total = this.in.read(buf, off, (int) min); - if (total > -1) this.used += total; - return total; - } - return this.in.read(buf, off, len); - } - - @Override - public long skip(long len) throws IOException { - if (this.maxLen > -1) { - if (len >= 0) { - long min = ((this.used + len) > this.maxLen) ? this.maxLen - this.used : len; - long total = this.in.skip(min); - if (total > -1) { - this.used += total; - } - return total; - } - return -1; - } - return this.in.skip(len); - } - - @Override - public int available() throws IOException { - if (this.maxLen > -1) { return (int) (this.maxLen - this.used); } - return this.in.available(); - } - - @Override - public synchronized void close() throws IOException { - if (this.maxLen > -1) { - if (!this.closed) { - byte[] buf = new byte[512]; - while (read(buf, 0, buf.length) > -1) { - // empty - } - this.closed = true; - } - // else - // throw new IOException(); - } else { - this.in.close(); - } - } -} +/* + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.http.io; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.*; + +/** + * Class BoundedInputStream implements an input stream with a maximum byte + * count. + * + */ +public class BoundedInputStream extends FilterInputStream { + private long maxLen, used; + + private boolean closed = false; + + /** + * Ctor. Creates the stream with unlimited length. + * + * @param pStream + * The stream this one is build upon + */ + public BoundedInputStream(InputStream pStream) { + this(pStream, -1); + } + + /** + * Ctor. + * + * @param pStream + * The stream this one is build upon + * @param pMaximumLength + * The maximum number of bytes that can be read from this stream. + * A value of -1 represents unlimited mode. + */ + public BoundedInputStream(InputStream pStream, long pMaximumLength) { + super(pStream); + this.maxLen = pMaximumLength; + this.used = 0; + this.in = pStream; + } + + @Override + public int read() throws IOException { + if (this.maxLen > -1) { + if (this.used >= this.maxLen) return -1; + + int value = this.in.read(); + if (value > -1) this.used++; + return value; + } + return this.in.read(); + } + + @Override + public int read(byte buf[]) throws IOException { + return read(buf, 0, buf.length); + } + + @Override + public int read(byte buf[], int off, int len) throws IOException { + if (this.closed) throw new IOException("I/O error - the stream is closed"); + + if (this.maxLen > -1) { + if (this.used >= this.maxLen) return -1; + + long min = ((this.used + len) > this.maxLen) ? this.maxLen - this.used : len; + int total = this.in.read(buf, off, (int) min); + if (total > -1) this.used += total; + return total; + } + return this.in.read(buf, off, len); + } + + @Override + public long skip(long len) throws IOException { + if (this.maxLen > -1) { + if (len >= 0) { + long min = ((this.used + len) > this.maxLen) ? this.maxLen - this.used : len; + long total = this.in.skip(min); + if (total > -1) { + this.used += total; + } + return total; + } + return -1; + } + return this.in.skip(len); + } + + @Override + public int available() throws IOException { + if (this.maxLen > -1) { + return (int) (this.maxLen - this.used); + } + return this.in.available(); + } + + @Override + public synchronized void close() throws IOException { + if (this.maxLen > -1) { + if (!this.closed) { + byte[] buf = new byte[512]; + while (read(buf, 0, buf.length) > -1) { + // empty + } + this.closed = true; + } + // else + // throw new IOException(); + } else { + this.in.close(); + } + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/ChunkedInputStream.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/ChunkedInputStream.java similarity index 75% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/ChunkedInputStream.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/ChunkedInputStream.java index ae4bc6c..942b1fb 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/ChunkedInputStream.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/ChunkedInputStream.java @@ -1,217 +1,213 @@ -/* - (C) Copyright IBM Corp. 2005, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 13799 2004-12-07 thschaef Fixes on chunking - * 1535756 2006-08-07 lupusalex Make code warning free - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 1660575 2007-02-15 lupusalex Chunking broken on SUN JRE - * 1688273 2007-04-16 ebak Full support of HTTP trailers - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 3304058 2011-05-20 blaschke-oss Use same date format in change history - * 3557283 2012-11-05 blaschke-oss Print full response when get EOF from CIMOM - * 3601894 2013-01-23 blaschke-oss Enhance HTTP and CIM-XML tracing - * 2621 2013-02-23 blaschke-oss Not all chunked input has trailers - * 2709 2013-11-13 blaschke-oss Lower the level of the EOF message to FINE - */ -package org.sentrysoftware.wbem.sblim.cimclient.internal.http.io; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; -import java.util.logging.Level; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.HttpHeader; -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.HttpMethod; -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; - -/** - * Class ChunkedInputStream implements an input stream for chunked messages - * - */ -public class ChunkedInputStream extends InputStream { - - private InputStream iIn; - - private String iTrailerFields; - - private String iOrigin; - - private long iChunkSize = 0; - - private boolean iEof = false; - - private HttpHeader iTrailers = new HttpHeader(); - - private boolean iClosed = false; - - private byte[] iTmp = new byte[1]; - - /** - * Ctor. - * - * @param pStream - * The stream to create this one upon - * @param pTrailerFields - * The names of trailer fields - */ - public ChunkedInputStream(InputStream pStream, String pTrailerFields) { - this(pStream, pTrailerFields, null); - } - - /** - * Ctor. - * - * @param pStream - * The stream to create this one upon - * @param pTrailerFields - * The names of trailer fields - * @param pOrigin - * The origin of the stream (response, indication request, etc.) - */ - public ChunkedInputStream(InputStream pStream, String pTrailerFields, String pOrigin) { - this.iIn = pStream; - this.iTrailerFields = pTrailerFields; - this.iOrigin = pOrigin == null ? "Unknown" : pOrigin; - } - - @Override - public synchronized int read() throws IOException { - return (read(this.iTmp, 0, 1) > 0) ? (this.iTmp[0] & 0xFF) : -1; - } - - @Override - public synchronized int read(byte[] buf, int off, int len) throws IOException { - int total = 0; - if (this.iEof || this.iClosed) return -1; // 13799 (return -1 if closed, - // not if !closed) - - if (this.iChunkSize == 0) { - String line = HttpMethod.readLine(this.iIn); // TODO read line using - // valid character encoding - - if ("".equals(line)) { - // 13799 The chunked data is ending with - // CRLF, so the first line read after it - // results "" - line = HttpMethod.readLine(this.iIn); - // 13799 Except first chunk, the - // above only read the CRLF ! - } - // TODO - get rid of ";*" suffix - try { - this.iChunkSize = Long.parseLong(line, 16); - } catch (Exception e) { - LogAndTraceBroker.getBroker().trace(Level.FINER, - "Invalid chunk size on HTTP stream", e); - this.iEof = true; - throw new IOException("Invalid chunk size"); - } - } - if (this.iChunkSize > 0) { - total = this.iIn.read(buf, off, (this.iChunkSize < len) ? (int) this.iChunkSize - : (int) len); - if (total > 0) { - this.iChunkSize -= total; - } - if (total == -1) { - LogAndTraceBroker.getBroker().trace( - Level.FINE, - "Unexpected EOF trying to read " - + (this.iChunkSize < len ? this.iChunkSize : len) - + " bytes from HTTP chunk with remaining length of " - + this.iChunkSize); - throw new EOFException("Unexpected EOF reading chunk"); - } - } else { - // read trailer - this.iEof = true; - if (this.iTrailerFields != null && this.iTrailerFields.trim().length() > 0) { - try { - this.iTrailers = new HttpHeader(this.iIn); - // ebak: http trailers - this.iTrailers.examineTrailer(this.iOrigin); - } catch (IOException e) { - LogAndTraceBroker.getBroker().trace( - Level.FINE, - "Unexpected EOF reading trailer, expected fields were " - + this.iTrailerFields); - throw new EOFException("Unexpected EOF reading trailer"); - } - } - } - return total > 0 ? total : -1; - } - - /** - * Return the http header trailers - * - * @return The trailers - */ - public synchronized HttpHeader getTrailers() { - return this.iTrailers; - } - - @Override - public synchronized long skip(long total) throws IOException { - byte[] tmp = new byte[(int) total]; - return read(tmp, 0, (int) total); - } - - /** - * @return int - * - */ - @Override - public synchronized int available() { - return (this.iEof ? 0 : (this.iChunkSize > 0 ? (int) this.iChunkSize : 1)); - } - - @Override - public void close() throws IOException { - if (!this.iClosed) { - this.iClosed = true; - byte[] buf = new byte[512]; - while (read(buf, 0, buf.length) > -1) { - // empty - } - this.iIn.close(); - } else throw new IOException("Error while closing stream"); - } -} +/* + (C) Copyright IBM Corp. 2005, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 13799 2004-12-07 thschaef Fixes on chunking + * 1535756 2006-08-07 lupusalex Make code warning free + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 1660575 2007-02-15 lupusalex Chunking broken on SUN JRE + * 1688273 2007-04-16 ebak Full support of HTTP trailers + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 3304058 2011-05-20 blaschke-oss Use same date format in change history + * 3557283 2012-11-05 blaschke-oss Print full response when get EOF from CIMOM + * 3601894 2013-01-23 blaschke-oss Enhance HTTP and CIM-XML tracing + * 2621 2013-02-23 blaschke-oss Not all chunked input has trailers + * 2709 2013-11-13 blaschke-oss Lower the level of the EOF message to FINE + */ +package org.metricshub.wbem.sblim.cimclient.internal.http.io; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.EOFException; +import java.io.IOException; +import java.io.InputStream; +import java.util.logging.Level; +import org.metricshub.wbem.sblim.cimclient.internal.http.HttpHeader; +import org.metricshub.wbem.sblim.cimclient.internal.http.HttpMethod; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; + +/** + * Class ChunkedInputStream implements an input stream for chunked messages + * + */ +public class ChunkedInputStream extends InputStream { + private InputStream iIn; + + private String iTrailerFields; + + private String iOrigin; + + private long iChunkSize = 0; + + private boolean iEof = false; + + private HttpHeader iTrailers = new HttpHeader(); + + private boolean iClosed = false; + + private byte[] iTmp = new byte[1]; + + /** + * Ctor. + * + * @param pStream + * The stream to create this one upon + * @param pTrailerFields + * The names of trailer fields + */ + public ChunkedInputStream(InputStream pStream, String pTrailerFields) { + this(pStream, pTrailerFields, null); + } + + /** + * Ctor. + * + * @param pStream + * The stream to create this one upon + * @param pTrailerFields + * The names of trailer fields + * @param pOrigin + * The origin of the stream (response, indication request, etc.) + */ + public ChunkedInputStream(InputStream pStream, String pTrailerFields, String pOrigin) { + this.iIn = pStream; + this.iTrailerFields = pTrailerFields; + this.iOrigin = pOrigin == null ? "Unknown" : pOrigin; + } + + @Override + public synchronized int read() throws IOException { + return (read(this.iTmp, 0, 1) > 0) ? (this.iTmp[0] & 0xFF) : -1; + } + + @Override + public synchronized int read(byte[] buf, int off, int len) throws IOException { + int total = 0; + if (this.iEof || this.iClosed) return -1; // 13799 (return -1 if closed, + // not if !closed) + + if (this.iChunkSize == 0) { + String line = HttpMethod.readLine(this.iIn); // TODO read line using + // valid character encoding + + if ("".equals(line)) { + // 13799 The chunked data is ending with + // CRLF, so the first line read after it + // results "" + line = HttpMethod.readLine(this.iIn); + // 13799 Except first chunk, the + // above only read the CRLF ! + } + // TODO - get rid of ";*" suffix + try { + this.iChunkSize = Long.parseLong(line, 16); + } catch (Exception e) { + LogAndTraceBroker.getBroker().trace(Level.FINER, "Invalid chunk size on HTTP stream", e); + this.iEof = true; + throw new IOException("Invalid chunk size"); + } + } + if (this.iChunkSize > 0) { + total = this.iIn.read(buf, off, (this.iChunkSize < len) ? (int) this.iChunkSize : (int) len); + if (total > 0) { + this.iChunkSize -= total; + } + if (total == -1) { + LogAndTraceBroker + .getBroker() + .trace( + Level.FINE, + "Unexpected EOF trying to read " + + (this.iChunkSize < len ? this.iChunkSize : len) + + " bytes from HTTP chunk with remaining length of " + + this.iChunkSize + ); + throw new EOFException("Unexpected EOF reading chunk"); + } + } else { + // read trailer + this.iEof = true; + if (this.iTrailerFields != null && this.iTrailerFields.trim().length() > 0) { + try { + this.iTrailers = new HttpHeader(this.iIn); + // ebak: http trailers + this.iTrailers.examineTrailer(this.iOrigin); + } catch (IOException e) { + LogAndTraceBroker + .getBroker() + .trace(Level.FINE, "Unexpected EOF reading trailer, expected fields were " + this.iTrailerFields); + throw new EOFException("Unexpected EOF reading trailer"); + } + } + } + return total > 0 ? total : -1; + } + + /** + * Return the http header trailers + * + * @return The trailers + */ + public synchronized HttpHeader getTrailers() { + return this.iTrailers; + } + + @Override + public synchronized long skip(long total) throws IOException { + byte[] tmp = new byte[(int) total]; + return read(tmp, 0, (int) total); + } + + /** + * @return int + * + */ + @Override + public synchronized int available() { + return (this.iEof ? 0 : (this.iChunkSize > 0 ? (int) this.iChunkSize : 1)); + } + + @Override + public void close() throws IOException { + if (!this.iClosed) { + this.iClosed = true; + byte[] buf = new byte[512]; + while (read(buf, 0, buf.length) > -1) { + // empty + } + this.iIn.close(); + } else throw new IOException("Error while closing stream"); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/ChunkedOutputStream.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/ChunkedOutputStream.java similarity index 76% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/ChunkedOutputStream.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/ChunkedOutputStream.java index 1926020..e30138a 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/ChunkedOutputStream.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/ChunkedOutputStream.java @@ -1,123 +1,118 @@ -/* - (C) Copyright IBM Corp. 2005, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2620 2013-02-23 blaschke-oss Chunked output broken - */ -package org.sentrysoftware.wbem.sblim.cimclient.internal.http.io; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -/** - * Class ChunkedOutputStream implements an output stream for chunked messages - * - */ -public class ChunkedOutputStream extends OutputStream { - - DataOutputStream iOs; - - byte[] iBuffer; - - int iUsed; - - /** - * Ctor. - * - * @param pStream - * The stream to create this one upon - * @param pBufferLength - * The buffer length. When this value is exceeded a new chunk - * will be started. - */ - public ChunkedOutputStream(OutputStream pStream, int pBufferLength) { - this.iOs = new DataOutputStream(pStream); - this.iBuffer = new byte[pBufferLength]; - this.iUsed = 0; - } - - @Override - public void close() throws IOException { - flush(); - this.iOs.writeBytes(Integer.toHexString(0) + "\r\n"); - this.iOs.flush(); - } - - @Override - public void flush() throws IOException { - if (this.iUsed > 0) { - this.iOs.writeBytes(Integer.toHexString(this.iUsed) + "\r\n"); - this.iOs.write(this.iBuffer, 0, this.iUsed); - this.iOs.writeBytes("\r\n"); - this.iOs.flush(); - } - this.iUsed = 0; - } - - /** - * @param offset - */ - @Override - public void write(byte source[], int offset, int len) throws IOException { - int copied = 0; - while (len > 0) { - int total = (this.iBuffer.length - this.iUsed < len) ? (this.iBuffer.length - this.iUsed) - : len; - if (total > 0) { - System.arraycopy(source, copied, this.iBuffer, this.iUsed, total); - len -= total; - this.iUsed += total; - copied += total; - } - if (this.iUsed == this.iBuffer.length) flush(); - } - } - - @Override - public void write(int i) throws IOException { - if (this.iBuffer.length == this.iUsed) flush(); - this.iBuffer[this.iUsed++] = (byte) (0xFF & i); - } - -} +/* + (C) Copyright IBM Corp. 2005, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2620 2013-02-23 blaschke-oss Chunked output broken + */ +package org.metricshub.wbem.sblim.cimclient.internal.http.io; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +/** + * Class ChunkedOutputStream implements an output stream for chunked messages + * + */ +public class ChunkedOutputStream extends OutputStream { + DataOutputStream iOs; + + byte[] iBuffer; + + int iUsed; + + /** + * Ctor. + * + * @param pStream + * The stream to create this one upon + * @param pBufferLength + * The buffer length. When this value is exceeded a new chunk + * will be started. + */ + public ChunkedOutputStream(OutputStream pStream, int pBufferLength) { + this.iOs = new DataOutputStream(pStream); + this.iBuffer = new byte[pBufferLength]; + this.iUsed = 0; + } + + @Override + public void close() throws IOException { + flush(); + this.iOs.writeBytes(Integer.toHexString(0) + "\r\n"); + this.iOs.flush(); + } + + @Override + public void flush() throws IOException { + if (this.iUsed > 0) { + this.iOs.writeBytes(Integer.toHexString(this.iUsed) + "\r\n"); + this.iOs.write(this.iBuffer, 0, this.iUsed); + this.iOs.writeBytes("\r\n"); + this.iOs.flush(); + } + this.iUsed = 0; + } + + /** + * @param offset + */ + @Override + public void write(byte source[], int offset, int len) throws IOException { + int copied = 0; + while (len > 0) { + int total = (this.iBuffer.length - this.iUsed < len) ? (this.iBuffer.length - this.iUsed) : len; + if (total > 0) { + System.arraycopy(source, copied, this.iBuffer, this.iUsed, total); + len -= total; + this.iUsed += total; + copied += total; + } + if (this.iUsed == this.iBuffer.length) flush(); + } + } + + @Override + public void write(int i) throws IOException { + if (this.iBuffer.length == this.iUsed) flush(); + this.iBuffer[this.iUsed++] = (byte) (0xFF & i); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/DebugInputStream.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/DebugInputStream.java similarity index 76% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/DebugInputStream.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/DebugInputStream.java index c78818a..2578038 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/DebugInputStream.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/DebugInputStream.java @@ -1,172 +1,172 @@ -/* - (C) Copyright IBM Corp. 2005, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 3062747 2010-09-21 blaschke-oss SblimCIMClient does not log all CIM-XML responces. - * 3185833 2011-02-18 blaschke-oss missing newline when logging request/response - * 3554738 2012-08-16 blaschke-oss dump CIM xml by LogAndTraceBroker.trace() - * 3601894 2013-01-23 blaschke-oss Enhance HTTP and CIM-XML tracing - */ -package org.sentrysoftware.wbem.sblim.cimclient.internal.http.io; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.logging.Level; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.TimeStamp; - -/** - * Class DebugInputStream is for debugging purposes - * - */ -public class DebugInputStream extends FilterInputStream { - - private byte[] iBuf; - - private boolean iBuffered; - - private int iCur = 0; - - private int iMaxLen = 0; - - private OutputStream iStream; - - private String iOrigin; - - /** - * Ctor. - * - * @param is - * @param os - */ - public DebugInputStream(InputStream is, OutputStream os) { - this(is, os, null); - } - - /** - * Ctor. - * - * @param is - * @param os - * @param pOrigin - */ - public DebugInputStream(InputStream is, OutputStream os, String pOrigin) { - super(is); - this.iBuf = new byte[512]; - this.iBuffered = false; - this.iStream = os; - this.iOrigin = pOrigin == null ? "unknown" : pOrigin; - } - - private void buffer() throws IOException { - this.iBuffered = true; - int total; - try { - while ((total = this.in.read(this.iBuf, this.iMaxLen, this.iBuf.length - this.iMaxLen)) > -1) { - this.iMaxLen += total; - if (this.iMaxLen == this.iBuf.length) { - byte b[] = new byte[this.iBuf.length << 1]; - System.arraycopy(this.iBuf, 0, b, 0, this.iBuf.length); - this.iBuf = b; - } - } - } catch (TrailerException e) { - // TrailerException indicates complete response BUT error in trailer - writeBuffer(this.iOrigin + " begin (TrailerException occurred)"); - throw e; - } - writeBuffer(this.iOrigin + " begin"); - } - - private void writeBuffer(String header) throws IOException { - StringBuilder outStr = new StringBuilder("<--- "); - outStr.append(header); - outStr.append(' '); - outStr.append(TimeStamp.formatWithMillis(System.currentTimeMillis())); - outStr.append(" ----\n"); - outStr.append(new String(this.iBuf, 0, this.iMaxLen)); - if (this.iMaxLen > 0 && this.iBuf[this.iMaxLen - 1] != '\n') outStr.append('\n'); - outStr.append("---- "); - outStr.append(this.iOrigin); - outStr.append(" end ----->\n"); - if (this.iStream != null) this.iStream.write(outStr.toString().getBytes()); - if (LogAndTraceBroker.getBroker().isLoggableCIMXMLTrace(Level.FINEST)) LogAndTraceBroker - .getBroker().traceCIMXML(Level.FINEST, outStr.toString(), false); - } - - @Override - public synchronized int read() throws IOException { - if (!this.iBuffered) buffer(); - - if (this.iCur >= this.iMaxLen) return -1; - return this.iBuf[this.iCur++]; - } - - @Override - public synchronized int read(byte b[], int off, int len) throws IOException { - if (b == null) { - throw new NullPointerException(); - } else if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) - || ((off + len) < 0)) { - throw new IndexOutOfBoundsException(); - } else if (len == 0) { return 0; } - - int c = read(); - if (c == -1) { return -1; } - b[off] = (byte) c; - - int i = 1; - for (; i < len; i++) { - c = read(); - if (c == -1) { - break; - } - if (b != null) { - b[off + i] = (byte) c; - } - } - return i; - } -} +/* + (C) Copyright IBM Corp. 2005, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 3062747 2010-09-21 blaschke-oss SblimCIMClient does not log all CIM-XML responces. + * 3185833 2011-02-18 blaschke-oss missing newline when logging request/response + * 3554738 2012-08-16 blaschke-oss dump CIM xml by LogAndTraceBroker.trace() + * 3601894 2013-01-23 blaschke-oss Enhance HTTP and CIM-XML tracing + */ +package org.metricshub.wbem.sblim.cimclient.internal.http.io; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.FilterInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.logging.Level; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; +import org.metricshub.wbem.sblim.cimclient.internal.logging.TimeStamp; + +/** + * Class DebugInputStream is for debugging purposes + * + */ +public class DebugInputStream extends FilterInputStream { + private byte[] iBuf; + + private boolean iBuffered; + + private int iCur = 0; + + private int iMaxLen = 0; + + private OutputStream iStream; + + private String iOrigin; + + /** + * Ctor. + * + * @param is + * @param os + */ + public DebugInputStream(InputStream is, OutputStream os) { + this(is, os, null); + } + + /** + * Ctor. + * + * @param is + * @param os + * @param pOrigin + */ + public DebugInputStream(InputStream is, OutputStream os, String pOrigin) { + super(is); + this.iBuf = new byte[512]; + this.iBuffered = false; + this.iStream = os; + this.iOrigin = pOrigin == null ? "unknown" : pOrigin; + } + + private void buffer() throws IOException { + this.iBuffered = true; + int total; + try { + while ((total = this.in.read(this.iBuf, this.iMaxLen, this.iBuf.length - this.iMaxLen)) > -1) { + this.iMaxLen += total; + if (this.iMaxLen == this.iBuf.length) { + byte b[] = new byte[this.iBuf.length << 1]; + System.arraycopy(this.iBuf, 0, b, 0, this.iBuf.length); + this.iBuf = b; + } + } + } catch (TrailerException e) { + // TrailerException indicates complete response BUT error in trailer + writeBuffer(this.iOrigin + " begin (TrailerException occurred)"); + throw e; + } + writeBuffer(this.iOrigin + " begin"); + } + + private void writeBuffer(String header) throws IOException { + StringBuilder outStr = new StringBuilder("<--- "); + outStr.append(header); + outStr.append(' '); + outStr.append(TimeStamp.formatWithMillis(System.currentTimeMillis())); + outStr.append(" ----\n"); + outStr.append(new String(this.iBuf, 0, this.iMaxLen)); + if (this.iMaxLen > 0 && this.iBuf[this.iMaxLen - 1] != '\n') outStr.append('\n'); + outStr.append("---- "); + outStr.append(this.iOrigin); + outStr.append(" end ----->\n"); + if (this.iStream != null) this.iStream.write(outStr.toString().getBytes()); + if (LogAndTraceBroker.getBroker().isLoggableCIMXMLTrace(Level.FINEST)) LogAndTraceBroker + .getBroker() + .traceCIMXML(Level.FINEST, outStr.toString(), false); + } + + @Override + public synchronized int read() throws IOException { + if (!this.iBuffered) buffer(); + + if (this.iCur >= this.iMaxLen) return -1; + return this.iBuf[this.iCur++]; + } + + @Override + public synchronized int read(byte b[], int off, int len) throws IOException { + if (b == null) { + throw new NullPointerException(); + } else if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0)) { + throw new IndexOutOfBoundsException(); + } else if (len == 0) { + return 0; + } + + int c = read(); + if (c == -1) { + return -1; + } + b[off] = (byte) c; + + int i = 1; + for (; i < len; i++) { + c = read(); + if (c == -1) { + break; + } + if (b != null) { + b[off + i] = (byte) c; + } + } + return i; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/KeepAliveInputStream.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/KeepAliveInputStream.java similarity index 73% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/KeepAliveInputStream.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/KeepAliveInputStream.java index 429df74..1da5a52 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/KeepAliveInputStream.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/KeepAliveInputStream.java @@ -1,119 +1,115 @@ -/* - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ -package org.sentrysoftware.wbem.sblim.cimclient.internal.http.io; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.HttpClient; - -/** - * Class KeepAliveInputStream implements an input stream for connections that - * keep iAlive after a request is completed - * - */ -public class KeepAliveInputStream extends FilterInputStream { - - private HttpClient iClient; - - /** - * Ctor. - * - * @param pStream - * The underlying stream - * @param pClient - * The associated client. - */ - public KeepAliveInputStream(InputStream pStream, HttpClient pClient) { - super(pStream); - this.iClient = pClient; - } - - @Override - public int read() throws IOException { - int i = super.read(); - if (i == -1 && this.iClient != null) { - this.iClient.streamFinished(); - this.iClient = null; - } - return i; - } - - @Override - public int read(byte buf[]) throws IOException { - return read(buf, 0, buf.length); - } - - @Override - public int read(byte buf[], int off, int len) throws IOException { - int i = super.read(buf, off, len); - if (i == -1 && this.iClient != null) { - this.iClient.streamFinished(); - this.iClient = null; - } - return i; - } - - @Override - public long skip(long len) throws IOException { - long i = super.skip(len); - - if (i == -1 && this.iClient != null) { - this.iClient.streamFinished(); - this.iClient = null; - } - return i; - } - - @Override - public void close() throws IOException { - super.close(); - if (this.iClient != null) { - this.iClient.streamFinished(); - this.iClient = null; - } - } -} +/* + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ +package org.metricshub.wbem.sblim.cimclient.internal.http.io; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.FilterInputStream; +import java.io.IOException; +import java.io.InputStream; +import org.metricshub.wbem.sblim.cimclient.internal.http.HttpClient; + +/** + * Class KeepAliveInputStream implements an input stream for connections that + * keep iAlive after a request is completed + * + */ +public class KeepAliveInputStream extends FilterInputStream { + private HttpClient iClient; + + /** + * Ctor. + * + * @param pStream + * The underlying stream + * @param pClient + * The associated client. + */ + public KeepAliveInputStream(InputStream pStream, HttpClient pClient) { + super(pStream); + this.iClient = pClient; + } + + @Override + public int read() throws IOException { + int i = super.read(); + if (i == -1 && this.iClient != null) { + this.iClient.streamFinished(); + this.iClient = null; + } + return i; + } + + @Override + public int read(byte buf[]) throws IOException { + return read(buf, 0, buf.length); + } + + @Override + public int read(byte buf[], int off, int len) throws IOException { + int i = super.read(buf, off, len); + if (i == -1 && this.iClient != null) { + this.iClient.streamFinished(); + this.iClient = null; + } + return i; + } + + @Override + public long skip(long len) throws IOException { + long i = super.skip(len); + + if (i == -1 && this.iClient != null) { + this.iClient.streamFinished(); + this.iClient = null; + } + return i; + } + + @Override + public void close() throws IOException { + super.close(); + if (this.iClient != null) { + this.iClient.streamFinished(); + this.iClient = null; + } + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/PersistentInputStream.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/PersistentInputStream.java similarity index 72% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/PersistentInputStream.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/PersistentInputStream.java index cc269ae..01dbdca 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/PersistentInputStream.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/PersistentInputStream.java @@ -1,93 +1,90 @@ -/* - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ -package org.sentrysoftware.wbem.sblim.cimclient.internal.http.io; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; - -/** - * Class PersistentInputStream implements an input stream for which close() can - * be disabled. - * - */ -public class PersistentInputStream extends FilterInputStream { - - boolean iClosable = false; - - boolean iClosed = false; - - /** - * Ctor. - * - * @param pStream - * The underlying stream - */ - public PersistentInputStream(InputStream pStream) { - this(pStream, false); - } - - /** - * Ctor. - * - * @param pStream - * The underlying stream - * @param pClosable - * If false this stream will ignore calls to the - * close() method. - */ - public PersistentInputStream(InputStream pStream, boolean pClosable) { - super(pStream); - this.iClosable = pClosable; - } - - @Override - public synchronized void close() throws IOException { - if (!this.iClosed) { - this.iClosed = true; - if (this.iClosable) this.in.close(); - } else throw new IOException("Error while closing the input stream. It was already closed"); - } -} +/* + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ +package org.metricshub.wbem.sblim.cimclient.internal.http.io; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.FilterInputStream; +import java.io.IOException; +import java.io.InputStream; + +/** + * Class PersistentInputStream implements an input stream for which close() can + * be disabled. + * + */ +public class PersistentInputStream extends FilterInputStream { + boolean iClosable = false; + + boolean iClosed = false; + + /** + * Ctor. + * + * @param pStream + * The underlying stream + */ + public PersistentInputStream(InputStream pStream) { + this(pStream, false); + } + + /** + * Ctor. + * + * @param pStream + * The underlying stream + * @param pClosable + * If false this stream will ignore calls to the + * close() method. + */ + public PersistentInputStream(InputStream pStream, boolean pClosable) { + super(pStream); + this.iClosable = pClosable; + } + + @Override + public synchronized void close() throws IOException { + if (!this.iClosed) { + this.iClosed = true; + if (this.iClosable) this.in.close(); + } else throw new IOException("Error while closing the input stream. It was already closed"); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/PersistentOutputStream.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/PersistentOutputStream.java similarity index 72% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/PersistentOutputStream.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/PersistentOutputStream.java index 6a9209c..1c9450f 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/PersistentOutputStream.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/PersistentOutputStream.java @@ -1,92 +1,89 @@ -/* - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ -package org.sentrysoftware.wbem.sblim.cimclient.internal.http.io; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.FilterOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -/** - * Class PersistentOutputStream implements an output stream for which close() - * can be disabled. - */ -public class PersistentOutputStream extends FilterOutputStream { - - boolean iClosable = false; - - boolean iClosed = false; - - /** - * Ctor. - * - * @param pStream - * The underlying stream - */ - public PersistentOutputStream(OutputStream pStream) { - this(pStream, false); - } - - /** - * Ctor. - * - * @param pStream - * The underlying stream - * @param pClosable - * If false this stream will ignore calls to the - * close() method. - */ - public PersistentOutputStream(OutputStream pStream, boolean pClosable) { - super(pStream); - this.iClosable = pClosable; - } - - @Override - public synchronized void close() throws IOException { - if (!this.iClosed) { - this.iClosed = true; - if (this.iClosable) this.out.close(); - } else throw new IOException("Error while closing the Output stream. It was already closed"); - } -} +/* + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 1565892 2006-11-28 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ +package org.metricshub.wbem.sblim.cimclient.internal.http.io; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.FilterOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +/** + * Class PersistentOutputStream implements an output stream for which close() + * can be disabled. + */ +public class PersistentOutputStream extends FilterOutputStream { + boolean iClosable = false; + + boolean iClosed = false; + + /** + * Ctor. + * + * @param pStream + * The underlying stream + */ + public PersistentOutputStream(OutputStream pStream) { + this(pStream, false); + } + + /** + * Ctor. + * + * @param pStream + * The underlying stream + * @param pClosable + * If false this stream will ignore calls to the + * close() method. + */ + public PersistentOutputStream(OutputStream pStream, boolean pClosable) { + super(pStream); + this.iClosable = pClosable; + } + + @Override + public synchronized void close() throws IOException { + if (!this.iClosed) { + this.iClosed = true; + if (this.iClosable) this.out.close(); + } else throw new IOException("Error while closing the Output stream. It was already closed"); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/TrailerException.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/TrailerException.java similarity index 60% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/TrailerException.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/TrailerException.java index 02ef4cf..b01ce75 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/TrailerException.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/TrailerException.java @@ -1,81 +1,83 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1688273 2007-04-16 ebak Full support of HTTP trailers - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.http.io; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.wbem.WBEMException; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConstants; - -/** - * TrailerException is thrown by ChunkedInputStream when it receives a http - * trailer which contains the following entries: CIMStatusCode, - * CIMStatusCodeDescription. These http trailer entries are known to be used by - * Pegasus CIMOM. - */ -public class TrailerException extends RuntimeException { - - private static final long serialVersionUID = 4355341648542585509L; - - private WBEMException iWBEMException; - - /** - * Ctor. - * - * @param pException - * The contained WBEMException - */ - public TrailerException(WBEMException pException) { - super(WBEMConstants.HTTP_TRAILER_STATUS_CODE + ":" + pException.getID() + " " - + WBEMConstants.HTTP_TRAILER_STATUS_DESCRIPTION + ":" + pException.getMessage()); - this.iWBEMException = pException; - } - - /** - * getWBEMException - * - * @return WBEMException - */ - public WBEMException getWBEMException() { - return this.iWBEMException; - } - -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, ebak@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1688273 2007-04-16 ebak Full support of HTTP trailers + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.http.io; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.wbem.WBEMException; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConstants; + +/** + * TrailerException is thrown by ChunkedInputStream when it receives a http + * trailer which contains the following entries: CIMStatusCode, + * CIMStatusCodeDescription. These http trailer entries are known to be used by + * Pegasus CIMOM. + */ +public class TrailerException extends RuntimeException { + private static final long serialVersionUID = 4355341648542585509L; + + private WBEMException iWBEMException; + + /** + * Ctor. + * + * @param pException + * The contained WBEMException + */ + public TrailerException(WBEMException pException) { + super( + WBEMConstants.HTTP_TRAILER_STATUS_CODE + + ":" + + pException.getID() + + " " + + WBEMConstants.HTTP_TRAILER_STATUS_DESCRIPTION + + ":" + + pException.getMessage() + ); + this.iWBEMException = pException; + } + + /** + * getWBEMException + * + * @return WBEMException + */ + public WBEMException getWBEMException() { + return this.iWBEMException; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/package.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/package.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/io/package.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/io/package.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/package.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/package.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/http/package.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/http/package.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/logging/LogAndTraceBroker.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/logging/LogAndTraceBroker.java similarity index 73% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/logging/LogAndTraceBroker.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/logging/LogAndTraceBroker.java index ee5664f..96d8f03 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/logging/LogAndTraceBroker.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/logging/LogAndTraceBroker.java @@ -1,957 +1,1011 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1565892 2006-11-14 lupusalex Make SBLIM client JSR48 compliant - * 1711092 2006-05-02 lupusalex Some fixes/additions of log&trace messages - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 3001345 2010-05-18 blaschke-oss File handle leaks in HttpSocketFactory and LogAndTraceBroker - * 3027618 2010-07-14 blaschke-oss Close files/readers in finally blocks - * 3154232 2011-01-13 blaschke-oss EmbeddedObject misspelled in javadoc - * 3252669 2011-03-28 blaschke-oss setXmlTraceStream blindly closes previous stream - * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues - * 3469018 2012-01-03 blaschke-oss Properties not passed to CIMIndicationHandler - * 3484014 2012-02-03 blaschke-oss Add LogAndTraceBroker.isLoggable for message/trace - * 3489638 2012-02-28 blaschke-oss PERF: Bottleneck in LogAndTraceBroker.java - getCaller() - * 3554738 2012-08-16 blaschke-oss dump CIM xml by LogAndTraceBroker.trace() - * 3576396 2012-10-11 blaschke-oss Improve logging of config file name - * 3596303 2013-01-04 blaschke-oss windows http response WWW-Authenticate: Negotiate fails - * 2652 2013-07-26 blaschke-oss LogAndTraceBroker.setXmlTraceStream should not close previous stream - * 2651 2013-07-31 blaschke-oss IOException when tracing the cimxml - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.logging; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; -import java.util.logging.ConsoleHandler; -import java.util.logging.FileHandler; -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.LogRecord; -import java.util.logging.Logger; - -import org.sentrysoftware.wbem.sblim.cimclient.CIMXMLTraceListener; -import org.sentrysoftware.wbem.sblim.cimclient.LogAndTraceManager; -import org.sentrysoftware.wbem.sblim.cimclient.LogListener; -import org.sentrysoftware.wbem.sblim.cimclient.TraceListener; -import org.sentrysoftware.wbem.sblim.cimclient.WBEMConfigurationProperties; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConfiguration; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConstants; - -/** - * Class LogAndTraceBroker is the central class that implements the logging and - * tracing of the CIM Client. It manages the collections of the internal log and - * trace listeners. It sets up the application independent logging. It provides - * the API to send log and trace messages and forwards them to the appropriate - * listeners. - * - */ -public class LogAndTraceBroker { - - private static final String TRACE_LOGGER = "org.sentrysoftware.wbem.sblim.cimclient.trace"; - - private static final String FILE_LOGGER = "org.sentrysoftware.wbem.sblim.cimclient.file"; - - private static final String CONSOLE_LOGGER = "org.sentrysoftware.wbem.sblim.cimclient.console"; - - private static LogAndTraceBroker cBroker = new LogAndTraceBroker(); - - /** - * Returns the singleton instance of the broker - * - * @return The broker instance - */ - public static LogAndTraceBroker getBroker() { - return cBroker; - } - - /** - * Returns if the logging framework has been initialized. This method is - * used by the WBEMConfiguration class to determine if the - * logging is already up. The WBEMConfiguration is initialized - * before the logging, so methods in this class cannot assume the logging to - * be up and running. - * - * @return true if the logging is up, false - * otherwise - */ - public static boolean isLoggingStarted() { - return cBroker != null; - } - - private volatile ArrayList iLogListeners; - - private volatile ArrayList iTraceListeners; - - private volatile ArrayList iCIMXMLTraceListeners; - - private String iProductName = "SBLIM CIM Client for Java"; - - private String iCopyright = "COPYRIGHT (C) 2006, 2013 IBM Corp."; - - private String iVersion = "?"; - - private String iBuildDate = "?"; - - private String iBuildTime = "?"; - - private OutputStream iXmlTraceStream = null; - - private OutputStream iXmlTraceFile = null; - - private final String iTHIS_CLASS = this.getClass().getName(); - - private final String iTHROWABLE = Throwable.class.getName(); - - private int iInternalLevelConsole = Level.OFF.intValue(); - - private int iInternalLevelLogFile = Level.OFF.intValue(); - - private int iInternalLevelTraceFile = Level.OFF.intValue(); - - private LogListener iInternalListenerLogConsole = null; - - private LogListener iInternalListenerLogFile = null; - - private TraceListener iInternalListenerTraceConsole = null; - - private TraceListener iInternalListenerTraceFile = null; - - private int iNumInternalLogListeners = 0; - - private int iNumExternalLogListeners = 0; - - private int iNumInternalTraceListeners = 0; - - private int iNumExternalTraceListeners = 0; - - private LogAndTraceBroker() { - this.iLogListeners = new ArrayList(); - this.iTraceListeners = new ArrayList(); - this.iCIMXMLTraceListeners = new ArrayList(); - loadVersionTxt(); - registerInternalListeners(); - initXmlTraceFile(); - } - - @Override - protected void finalize() throws Throwable { - try { - if (this.iXmlTraceFile != null && (!this.iXmlTraceFile.equals(System.out)) - && (!this.iXmlTraceFile.equals(System.err))) this.iXmlTraceFile.close(); - } catch (IOException e) { - // bad luck - } finally { - this.iXmlTraceFile = null; - super.finalize(); - } - } - - /** - * Registers the listeners for our internal loggers - */ - public void registerInternalListeners() { - try { - Level level = WBEMConfiguration.getGlobalConfiguration().getLogConsoleLevel(); - String type = WBEMConfiguration.getGlobalConfiguration().getLogConsoleType(); - if (level.intValue() < Level.OFF.intValue() && WBEMConstants.MESSAGE.equals(type)) { - final Logger logger = Logger.getLogger(CONSOLE_LOGGER); - final Handler handler = new ConsoleHandler(); - handler.setFormatter(new LogFormatter()); - handler.setLevel(level); - logger.addHandler(handler); - logger.setLevel(level); - logger.setUseParentHandlers(false); - this.iInternalLevelConsole = level.intValue(); - if (this.iInternalListenerLogConsole != null) removeLogListener(this.iInternalListenerLogConsole); - this.iInternalListenerLogConsole = new LogListener() { - - public void log(Level pLevel, String pMessageKey, String pMessage, - Object[] pParameters) { - LogRecord record = new LogRecord(pLevel, pMessageKey + " " + pMessage); - record.setParameters(pParameters); - logger.log(record); - } - }; - addLogListener(this.iInternalListenerLogConsole); - } - } catch (Exception e) { - // Don't crash for logging - } - try { - Level level = WBEMConfiguration.getGlobalConfiguration().getLogFileLevel(); - String location = WBEMConfiguration.getGlobalConfiguration().getLogFileLocation(); - int size = WBEMConfiguration.getGlobalConfiguration().getLogFileSizeLimit(); - int count = WBEMConfiguration.getGlobalConfiguration().getLogFileCount(); - if (level.intValue() < Level.OFF.intValue()) { - final Logger logger = Logger.getLogger(FILE_LOGGER); - final Handler handler = new FileHandler(location, size, count); - handler.setFormatter(new LogFormatter()); - handler.setLevel(level); - logger.addHandler(handler); - logger.setLevel(level); - logger.setUseParentHandlers(false); - this.iInternalLevelLogFile = level.intValue(); - if (this.iInternalListenerLogFile != null) removeLogListener(this.iInternalListenerLogFile); - this.iInternalListenerLogFile = new LogListener() { - - public void log(Level pLevel, String pMessageKey, String pMessage, - Object[] pParameters) { - LogRecord record = new LogRecord(pLevel, pMessageKey + " " + pMessage); - record.setParameters(pParameters); - logger.log(record); - } - }; - addLogListener(this.iInternalListenerLogFile); - } - } catch (Exception e) { - // Don't crash for logging - } - try { - Level level = WBEMConfiguration.getGlobalConfiguration().getLogConsoleLevel(); - String type = WBEMConfiguration.getGlobalConfiguration().getLogConsoleType(); - if (level.intValue() < Level.OFF.intValue() && WBEMConstants.TRACE.equals(type)) { - final Logger logger = Logger.getLogger(CONSOLE_LOGGER); - final Handler handler = new ConsoleHandler(); - handler.setFormatter(new TraceFormatter()); - handler.setLevel(level); - logger.addHandler(handler); - logger.setLevel(level); - logger.setUseParentHandlers(false); - this.iInternalLevelConsole = level.intValue(); - if (this.iInternalListenerTraceConsole != null) removeTraceListener(this.iInternalListenerTraceConsole); - this.iInternalListenerTraceConsole = new TraceListener() { - - public void trace(Level pLevel, StackTraceElement pOrigin, String pMessage) { - LogRecord record = new LogRecord(pLevel, pMessage); - record.setSourceMethodName(String.valueOf(pOrigin)); - logger.log(record); - } - - public void trace(Level pLevel, StackTraceElement pOrigin, String pMessage, - Throwable pThrown) { - LogRecord record = new LogRecord(pLevel, pMessage); - record.setSourceMethodName(String.valueOf(pOrigin)); - record.setThrown(pThrown); - logger.log(record); - } - }; - addTraceListener(this.iInternalListenerTraceConsole); - } - } catch (Exception e) { - // Don't crash for logging - } - try { - Level level = WBEMConfiguration.getGlobalConfiguration().getTraceFileLevel(); - String location = WBEMConfiguration.getGlobalConfiguration().getTraceFileLocation(); - int size = WBEMConfiguration.getGlobalConfiguration().getTraceFileSizeLimit(); - int count = WBEMConfiguration.getGlobalConfiguration().getTraceFileCount(); - if (level.intValue() < Level.OFF.intValue()) { - final Logger logger = Logger.getLogger(TRACE_LOGGER); - final Handler handler = new FileHandler(location, size, count); - handler.setFormatter(new TraceFormatter()); - handler.setLevel(level); - logger.addHandler(handler); - logger.setLevel(level); - logger.setUseParentHandlers(false); - this.iInternalLevelTraceFile = level.intValue(); - if (this.iInternalListenerTraceFile != null) removeTraceListener(this.iInternalListenerTraceFile); - this.iInternalListenerTraceFile = new TraceListener() { - - public void trace(Level pLevel, StackTraceElement pOrigin, String pMessage) { - LogRecord record = new LogRecord(pLevel, pMessage); - record.setSourceMethodName(String.valueOf(pOrigin)); - logger.log(record); - } - - public void trace(Level pLevel, StackTraceElement pOrigin, String pMessage, - Throwable pThrown) { - LogRecord record = new LogRecord(pLevel, pMessage); - record.setSourceMethodName(String.valueOf(pOrigin)); - record.setThrown(pThrown); - logger.log(record); - } - }; - addTraceListener(this.iInternalListenerTraceFile); - } - } catch (Exception e) { - // Don't crash for logging - } - } - - /** - * Adds a listener for log messages. The listener will be notified of any - * log event. Uses copy on write to ensure concurrent read access. - * - * @param pListener - * The listener - */ - public synchronized void addLogListener(LogListener pListener) { - if (pListener == null) return; - sendGreetings(pListener); - ArrayList newListeners = new ArrayList(this.iLogListeners); - newListeners.add(pListener); - this.iLogListeners = newListeners; - - if ((this.iInternalListenerLogFile != null && this.iInternalListenerLogFile - .equals(pListener)) - || (this.iInternalListenerLogConsole != null && this.iInternalListenerLogConsole - .equals(pListener))) { - this.iNumInternalLogListeners++; - } else { - this.iNumExternalLogListeners++; - } - } - - private void loadVersionTxt() { - InputStream is = null; - try { - Properties version = new Properties(); - is = LogAndTraceManager.class.getResourceAsStream("version.txt"); - version.load(is); - this.iProductName = version.getProperty("PRODUCTNAME"); - this.iCopyright = version.getProperty("COPYRIGHT"); - this.iVersion = version.getProperty("VERSION"); - this.iBuildDate = version.getProperty("BUILDDATE"); - this.iBuildTime = version.getProperty("BUILDTIME"); - } catch (Exception e) { - // nothing to do - } finally { - if (is != null) { - try { - is.close(); - } catch (IOException e) { - // nothing ro do - } - } - } - } - - private void sendGreetings(LogListener pListener) { - - pListener.log(MessageLoader.getLevel(Messages.GREETING), Messages.GREETING, MessageLoader - .getLocalizedMessage(Messages.GREETING), new Object[] { this.iProductName, - this.iCopyright }); - pListener.log(MessageLoader.getLevel(Messages.RELEASE), Messages.RELEASE, MessageLoader - .getLocalizedMessage(Messages.RELEASE), new Object[] { this.iVersion, - this.iBuildDate, this.iBuildTime }); - pListener.log(MessageLoader.getLevel(Messages.OS), Messages.OS, MessageLoader - .getLocalizedMessage(Messages.OS), new Object[] { System.getProperty("os.name"), - System.getProperty("os.version"), System.getProperty("os.arch") }); - pListener.log(MessageLoader.getLevel(Messages.JRE), Messages.JRE, MessageLoader - .getLocalizedMessage(Messages.JRE), new Object[] { - System.getProperty("java.version"), System.getProperty("java.vendor") }); - pListener.log(MessageLoader.getLevel(Messages.JVM), Messages.JVM, MessageLoader - .getLocalizedMessage(Messages.JVM), new Object[] { - System.getProperty("java.vm.name"), System.getProperty("java.vm.version"), - System.getProperty("java.vm.vendor") }); - pListener.log(MessageLoader.getLevel(Messages.CONFIGURATION_URL), - Messages.CONFIGURATION_URL, MessageLoader - .getLocalizedMessage(Messages.CONFIGURATION_URL), - new Object[] { WBEMConfiguration.getActiveConfigFullURL() }); - if (!WBEMConfiguration.isConfigurationLoadSuccessful()) { - pListener.log(MessageLoader.getLevel(Messages.CONFIGURATION_LOAD_FAILED), - Messages.CONFIGURATION_LOAD_FAILED, MessageLoader - .getLocalizedMessage(Messages.CONFIGURATION_LOAD_FAILED), - (Object[]) null); - if (WBEMConfiguration.getConfigurationLoadException() != null) { - pListener.log(MessageLoader.getLevel(Messages.EXCEPTION_DURING_CONFIGURATION_LOAD), - Messages.EXCEPTION_DURING_CONFIGURATION_LOAD, MessageLoader - .getLocalizedMessage(Messages.EXCEPTION_DURING_CONFIGURATION_LOAD), - new Object[] { WBEMConfiguration.getConfigurationLoadException() - .getMessage() }); - } - } - } - - private void sendGreetings(TraceListener pListener) { - StackTraceElement origin = new Throwable().getStackTrace()[0]; - pListener.trace(MessageLoader.getLevel(Messages.GREETING), origin, MessageFormat.format( - MessageLoader.getMessage(Messages.GREETING), new Object[] { this.iProductName, - this.iCopyright })); - pListener.trace(MessageLoader.getLevel(Messages.RELEASE), origin, MessageFormat.format( - MessageLoader.getMessage(Messages.RELEASE), new Object[] { this.iVersion, - this.iBuildDate, this.iBuildTime })); - pListener.trace(MessageLoader.getLevel(Messages.OS), origin, MessageFormat.format( - MessageLoader.getMessage(Messages.OS), new Object[] { - System.getProperty("os.name"), System.getProperty("os.version"), - System.getProperty("os.arch") })); - pListener.trace(MessageLoader.getLevel(Messages.JRE), origin, MessageFormat.format( - MessageLoader.getMessage(Messages.JRE), new Object[] { - System.getProperty("java.version"), System.getProperty("java.vendor") })); - pListener.trace(MessageLoader.getLevel(Messages.JVM), origin, MessageFormat.format( - MessageLoader.getMessage(Messages.JVM), new Object[] { - System.getProperty("java.vm.name"), System.getProperty("java.vm.version"), - System.getProperty("java.vm.vendor") })); - pListener.trace(MessageLoader.getLevel(Messages.CONFIGURATION_URL), origin, MessageFormat - .format(MessageLoader.getMessage(Messages.CONFIGURATION_URL), - new Object[] { WBEMConfiguration.getActiveConfigURL() })); - if (!WBEMConfiguration.isConfigurationLoadSuccessful()) { - pListener.trace(MessageLoader.getLevel(Messages.CONFIGURATION_LOAD_FAILED), origin, - MessageLoader.getMessage(Messages.CONFIGURATION_LOAD_FAILED)); - if (WBEMConfiguration.getConfigurationLoadException() != null) { - pListener.trace(MessageLoader - .getLevel(Messages.EXCEPTION_DURING_CONFIGURATION_LOAD), origin, - MessageLoader.getMessage(Messages.EXCEPTION_DURING_CONFIGURATION_LOAD), - WBEMConfiguration.getConfigurationLoadException()); - } - } - } - - /** - * Remove a listener. This listener will not be notified of log events - * anymore. - * - * @param pListener - * The listener - */ - public synchronized void removeLogListener(LogListener pListener) { - ArrayList newListeners = new ArrayList(this.iLogListeners); - if (!newListeners.remove(pListener)) return; - this.iLogListeners = newListeners; - - if (this.iInternalListenerLogFile != null - && this.iInternalListenerLogFile.equals(pListener)) { - // Removing internal log listener for file - this.iInternalListenerLogFile = null; - this.iNumInternalLogListeners--; - } else if (this.iInternalListenerLogConsole != null - && this.iInternalListenerLogConsole.equals(pListener)) { - // Removing internal log listener for console - this.iInternalListenerLogConsole = null; - this.iNumInternalLogListeners--; - } else { - // Removing user log listener - this.iNumExternalLogListeners--; - } - } - - /** - * Removes all listeners. Caution this will also remove the internal console - * and file loggers. - */ - public synchronized void clearLogListeners() { - this.iLogListeners = new ArrayList(); - removeHandlers(Logger.getLogger(CONSOLE_LOGGER)); - removeHandlers(Logger.getLogger(FILE_LOGGER)); - - this.iInternalListenerLogFile = null; - this.iInternalListenerLogConsole = null; - this.iNumInternalLogListeners = 0; - this.iNumExternalLogListeners = 0; - } - - /** - * Gets the registered log listeners including the internal console and file - * loggers. - * - * @return The list of listeners - */ - public List getLogListeners() { - return this.iLogListeners; - } - - /** - * Adds a listener for log messages. The listener will be notified of any - * trace event. - * - * @param pListener - * The listener - */ - public synchronized void addTraceListener(TraceListener pListener) { - if (pListener == null) return; - sendGreetings(pListener); - ArrayList newListeners = new ArrayList(this.iTraceListeners); - newListeners.add(pListener); - this.iTraceListeners = newListeners; - - if ((this.iInternalListenerTraceFile != null && this.iInternalListenerTraceFile - .equals(pListener)) - || (this.iInternalListenerTraceConsole != null && this.iInternalListenerTraceConsole - .equals(pListener))) { - this.iNumInternalTraceListeners++; - } else { - this.iNumExternalTraceListeners++; - } - } - - /** - * Removes a listener. This listener will not be notified of trace events - * anymore. - * - * @param pListener - * The listener - */ - public synchronized void removeTraceListener(TraceListener pListener) { - ArrayList newListeners = new ArrayList(this.iTraceListeners); - if (!newListeners.remove(pListener)) return; - this.iTraceListeners = newListeners; - - if (this.iInternalListenerTraceFile != null - && this.iInternalListenerTraceFile.equals(pListener)) { - // Removing internal tracelistener for file - this.iInternalListenerTraceFile = null; - this.iNumInternalTraceListeners--; - } else if (this.iInternalListenerTraceConsole != null - && this.iInternalListenerTraceConsole.equals(pListener)) { - // Removing internal trace listener for console - this.iInternalListenerTraceConsole = null; - this.iNumInternalTraceListeners--; - } else { - // Removing user trace listener - this.iNumExternalTraceListeners--; - } - } - - /** - * Removes all listeners. Caution this will also remove the internal trace - * file listener. - */ - public synchronized void clearTraceListeners() { - this.iTraceListeners = new ArrayList(); - removeHandlers(Logger.getLogger(TRACE_LOGGER)); - - this.iInternalListenerTraceFile = null; - this.iInternalListenerTraceConsole = null; - this.iNumInternalTraceListeners = 0; - this.iNumExternalTraceListeners = 0; - } - - /** - * Gets the registered trace listeners including the internal console and - * file loggers. - * - * @return A list of listeners - */ - public List getTraceListeners() { - return this.iTraceListeners; - } - - /** - * Adds a listener for CIM-XML trace messages. The listener will be notified - * of any CIM-XML trace event. - * - * @param pListener - * The listener - */ - public synchronized void addCIMXMLTraceListener(CIMXMLTraceListener pListener) { - if (pListener == null) return; - ArrayList newListeners = new ArrayList( - this.iCIMXMLTraceListeners); - newListeners.add(pListener); - this.iCIMXMLTraceListeners = newListeners; - } - - /** - * Removes a CIM-XML trace listener. This listener will not be notified of - * CIM-XML trace events anymore. - * - * @param pListener - * The listener - */ - public synchronized void removeCIMXMLTraceListener(CIMXMLTraceListener pListener) { - ArrayList newListeners = new ArrayList( - this.iCIMXMLTraceListeners); - if (!newListeners.remove(pListener)) return; - this.iCIMXMLTraceListeners = newListeners; - } - - /** - * Removes all CIM-XML trace listeners. - */ - public synchronized void clearCIMXMLTraceListeners() { - if (this.iCIMXMLTraceListeners.size() > 0) this.iCIMXMLTraceListeners = new ArrayList(); - } - - /** - * Gets the registered CIM-XML trace listeners. - * - * @return A list of listeners - */ - public List getCIMXMLTraceListeners() { - return this.iCIMXMLTraceListeners; - } - - /** - * Forwards a log/trace message to the registered log&trace listeners. - * - * @param pKey - * The message identifier. - */ - public void message(String pKey) { - message(pKey, (Object[]) null); - } - - /** - * Forwards a log/trace message to the registered log&trace listeners. - * - * @param pKey - * The message identifier. - * @param pParameter - * The parameter for the message - */ - public void message(String pKey, Object pParameter) { - message(pKey, new Object[] { pParameter }); - } - - /** - * Forwards a log/trace message to the registered log&trace listeners. - * - * @param pKey - * The message identifier. - * @param pParameters - * The parameters for the message - */ - public void message(String pKey, Object[] pParameters) { - try { - final String message = MessageLoader.getMessage(pKey); - final String localMessage = MessageLoader.getLocalizedMessage(pKey); - final Level level = MessageLoader.getLevel(pKey); - if (isLoggableTrace(level)) { - final List traceListeners = getTraceListeners(); - StackTraceElement caller = getCaller(); - for (int i = 0; i < traceListeners.size(); ++i) { - traceListeners.get(i).trace(level, caller, - pKey + " " + MessageFormat.format(message, pParameters)); - } - } - final List logListeners = getLogListeners(); - for (int i = 0; i < logListeners.size(); ++i) { - logListeners.get(i).log(level, pKey, localMessage, pParameters); - } - } catch (Exception e) { - // don't crash for logging - } - } - - /** - * Forwards a trace message to the registered trace listeners. - * - * @param pLevel - * One of the three message level identifiers FINE, FINER and - * FINEST - * @param pMessage - * The message text - */ - public void trace(Level pLevel, String pMessage) { - try { - if (isLoggableTrace(pLevel)) { - final List traceListeners = getTraceListeners(); - StackTraceElement caller = getCaller(); - for (int i = 0; i < traceListeners.size(); ++i) { - traceListeners.get(i).trace(pLevel, caller, pMessage); - } - } - } catch (Exception e) { - // don't crash for logging - } - } - - /** - * Forwards a trace message to the registered trace listeners. - * - * @param pLevel - * One of the three message level identifiers FINE, FINER and - * FINEST - * @param pMessage - * The message text - * @param pThrown - * The throwable associated with the message - */ - public void trace(Level pLevel, String pMessage, Throwable pThrown) { - try { - if (isLoggableTrace(pLevel)) { - final List traceListeners = getTraceListeners(); - StackTraceElement caller = getCaller(); - for (int i = 0; i < traceListeners.size(); ++i) { - traceListeners.get(i).trace(pLevel, caller, pMessage, pThrown); - } - } - } catch (Exception e) { - // don't crash for logging - } - } - - /** - * Forwards a CIM-XML trace message to the registered CIM-XML trace - * listeners. - * - * @param pLevel - * One of the message level identifiers, e.g. FINE - * @param pMessage - * The CIM-XML message text - * @param pOutgoing - * true if CIM-XML is outgoing (being sent from - * client to server), false if CIM-XML is incoming - * (being sent from server to client) - */ - public void traceCIMXML(Level pLevel, String pMessage, boolean pOutgoing) { - try { - if (this.iCIMXMLTraceListeners.size() > 0) { - final List traceListeners = getCIMXMLTraceListeners(); - for (int i = 0; i < traceListeners.size(); ++i) { - traceListeners.get(i).traceCIMXML(pLevel, pMessage, pOutgoing); - } - } - } catch (Exception e) { - // don't crash for logging - } - } - - /** - * Forwards a method entry message to the registered trace listeners. - */ - public void entry() { - trace(Level.FINEST, "Entering method"); - } - - /** - * Forwards a method exit message to the registered trace listeners. - */ - public void exit() { - trace(Level.FINEST, "Exiting method"); - } - - /** - * Returns the output stream to which all CIM-XML traffic (outgoing & - * incoming) will be copied for debugging purposes. - * - * @return The output stream. A null value means that CIM-XML - * debugging is disabled - */ - public OutputStream getXmlTraceStream() { - return this.iXmlTraceStream; - } - - /** - * Sets an output stream to which all CIM-XML traffic (outgoing & - * incoming) will be copied for debugging purposes. - * - * @param pStream - * The output stream. A null value means that - * CIM-XML debugging is disabled. - */ - public void setXmlTraceStream(OutputStream pStream) { - this.iXmlTraceStream = pStream; - } - - /* - * Initializes the CIM-XML trace file (sblim.wbem.cimxmlTraceStream) during - * initialization of LogAndTraceBroker - the trace file is used if CIM-XML - * tracing is enabled (sblim.wbem.cimxmlTracing=true) but there is no - * CIM-XML trace stream set via setXmlTraceStream() - */ - private void initXmlTraceFile() { - try { - if (WBEMConfiguration.getGlobalConfiguration().isCimXmlTracingEnabled()) { - String filename = WBEMConfiguration.getGlobalConfiguration().getCimXmlTraceStream(); - if (filename != null && filename.length() > 0 && this.iXmlTraceFile == null - && getXmlTraceStream() == null) { - if (filename.equalsIgnoreCase("System.out")) { - this.iXmlTraceFile = System.out; - } else if (filename.equalsIgnoreCase("System.err")) { - this.iXmlTraceFile = System.err; - } else { - try { - this.iXmlTraceFile = new FileOutputStream(filename); - } catch (IOException e) { - trace(Level.FINE, "Unable to open " - + WBEMConfigurationProperties.CIMXML_TRACE_STREAM + "=" - + filename, e); - } - } - setXmlTraceStream(this.iXmlTraceFile); - } - } - } catch (Exception e) { - // Don't crash for logging - } - } - - /** - * Analyzes the stack trace and determines from where the - * LogAndTraceBroker was called. - * - * @return First StackTraceElement outside the - * LogAndTraceBroker - */ - private StackTraceElement getCaller() { - StackTraceElement[] stack = (new Throwable()).getStackTrace(); - for (int i = 0; i < stack.length; ++i) { - StackTraceElement frame = stack[i]; - String cname = frame.getClassName(); - if (!this.iTHIS_CLASS.equals(cname) && !this.iTHROWABLE.equals(cname)) { return frame; } - } - return null; - } - - /** - * Removes all handlers from a logger - * - * @param pLogger - * The logger - */ - private void removeHandlers(Logger pLogger) { - Handler[] handlers = pLogger.getHandlers(); - for (int i = 0; i < handlers.length; ++i) { - pLogger.removeHandler(handlers[i]); - handlers[i].close(); - } - } - - /** - * Checks whether there are trace listeners installed that will log a trace - * message with the specified level. Use this method to determine if a - * trace() method call could result in logging before preparing the - * information to be logged. For example: - * - *
      -	 *     if (logger.isLoggableTrace(Level.WARNING) {
      -	 *         // Prepare info for logging
      -	 *         logger.trace(Level.WARNING, ...
      -	 * 
      - * - * @param pLevel - * The Level of the trace message. - * @return true if trace message could be logged, - * false otherwise. - */ - public boolean isLoggableTrace(Level pLevel) { - // If there are no trace listeners or specified level is OFF, message - // will not be logged - if (this.iTraceListeners.size() == 0 || pLevel.intValue() == Level.OFF.intValue()) return false; - - // If there are external trace listeners, message could be logged (user - // can alter level at will, so we do not know what it is) - if (this.iNumExternalTraceListeners > 0) return true; - - // If there are internal trace listeners, determine if message will be - // logged - if (this.iNumInternalTraceListeners > 0) { - int level = Level.OFF.intValue(); - if (this.iInternalListenerTraceFile != null) { - level = this.iInternalLevelTraceFile; - } - if (this.iInternalListenerTraceConsole != null && level > this.iInternalLevelConsole) { - level = this.iInternalLevelConsole; - } - return level <= pLevel.intValue(); - } - - return true; - } - - /** - * Checks whether there are log listeners installed that will log a message - * with the specified level. Use this method to determine if a message() - * method call could result in logging before preparing the information to - * be logged. For example: - * - *
      -	 *     if (logger.isLoggableMessage(Level.WARNING) {
      -	 *         // Prepare info for logging
      -	 *         logger.message(Level.WARNING, ...
      -	 * 
      - * - * @param pLevel - * The Level of the message. - * @return true if message could be logged, false - * otherwise. - */ - public boolean isLoggableMessage(Level pLevel) { - // If message is traceable, message could be logged - if (isLoggableTrace(pLevel)) return true; - - // If there are no log listeners or specified level is OFF, message - // will not be logged - if (this.iLogListeners.size() == 0 || pLevel.intValue() == Level.OFF.intValue()) return false; - - // If there are external log listeners, message could be logged (user - // can alter level at will, so we do not know what it is) - if (this.iNumExternalLogListeners > 0) return true; - - // If there are internal log listeners, determine if message will be - // logged - if (this.iNumInternalLogListeners > 0) { - int level = Level.OFF.intValue(); - if (this.iInternalListenerLogFile != null) { - level = this.iInternalLevelLogFile; - } - if (this.iInternalListenerLogConsole != null && level > this.iInternalLevelConsole) { - level = this.iInternalLevelConsole; - } - return level <= pLevel.intValue(); - } - - return true; - } - - /** - * Checks whether there are CIM-XML trace listeners installed that will log - * a CIM-XML trace message. Use this method to determine if a trace() method - * call could result in logging before preparing the information to be - * logged. For example: - * - *
      -	 *     if (logger.isLoggableCIMXMLTrace(Level.FINEST) {
      -	 *         // Prepare info for logging
      -	 *         logger.traceCIMXML(Level.FINEST, ...
      -	 * 
      - * - * @param pLevel - * The Level of the trace message. - * @return true if CIM-XML trace message could be logged, - * false otherwise. - */ - public boolean isLoggableCIMXMLTrace(Level pLevel) { - // If there are no CIM-XML trace listeners or specified level is OFF, - // message will not be logged - if (this.iCIMXMLTraceListeners.size() == 0 || pLevel.intValue() == Level.OFF.intValue()) return false; - - return true; - } -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1565892 2006-11-14 lupusalex Make SBLIM client JSR48 compliant + * 1711092 2006-05-02 lupusalex Some fixes/additions of log&trace messages + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 3001345 2010-05-18 blaschke-oss File handle leaks in HttpSocketFactory and LogAndTraceBroker + * 3027618 2010-07-14 blaschke-oss Close files/readers in finally blocks + * 3154232 2011-01-13 blaschke-oss EmbeddedObject misspelled in javadoc + * 3252669 2011-03-28 blaschke-oss setXmlTraceStream blindly closes previous stream + * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues + * 3469018 2012-01-03 blaschke-oss Properties not passed to CIMIndicationHandler + * 3484014 2012-02-03 blaschke-oss Add LogAndTraceBroker.isLoggable for message/trace + * 3489638 2012-02-28 blaschke-oss PERF: Bottleneck in LogAndTraceBroker.java - getCaller() + * 3554738 2012-08-16 blaschke-oss dump CIM xml by LogAndTraceBroker.trace() + * 3576396 2012-10-11 blaschke-oss Improve logging of config file name + * 3596303 2013-01-04 blaschke-oss windows http response WWW-Authenticate: Negotiate fails + * 2652 2013-07-26 blaschke-oss LogAndTraceBroker.setXmlTraceStream should not close previous stream + * 2651 2013-07-31 blaschke-oss IOException when tracing the cimxml + */ + +package org.metricshub.wbem.sblim.cimclient.internal.logging; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import java.util.logging.ConsoleHandler; +import java.util.logging.FileHandler; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.LogRecord; +import java.util.logging.Logger; +import org.metricshub.wbem.sblim.cimclient.CIMXMLTraceListener; +import org.metricshub.wbem.sblim.cimclient.LogAndTraceManager; +import org.metricshub.wbem.sblim.cimclient.LogListener; +import org.metricshub.wbem.sblim.cimclient.TraceListener; +import org.metricshub.wbem.sblim.cimclient.WBEMConfigurationProperties; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfiguration; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConstants; + +/** + * Class LogAndTraceBroker is the central class that implements the logging and + * tracing of the CIM Client. It manages the collections of the internal log and + * trace listeners. It sets up the application independent logging. It provides + * the API to send log and trace messages and forwards them to the appropriate + * listeners. + * + */ +public class LogAndTraceBroker { + private static final String TRACE_LOGGER = "org.metricshub.wbem.sblim.cimclient.trace"; + + private static final String FILE_LOGGER = "org.metricshub.wbem.sblim.cimclient.file"; + + private static final String CONSOLE_LOGGER = "org.metricshub.wbem.sblim.cimclient.console"; + + private static LogAndTraceBroker cBroker = new LogAndTraceBroker(); + + /** + * Returns the singleton instance of the broker + * + * @return The broker instance + */ + public static LogAndTraceBroker getBroker() { + return cBroker; + } + + /** + * Returns if the logging framework has been initialized. This method is + * used by the WBEMConfiguration class to determine if the + * logging is already up. The WBEMConfiguration is initialized + * before the logging, so methods in this class cannot assume the logging to + * be up and running. + * + * @return true if the logging is up, false + * otherwise + */ + public static boolean isLoggingStarted() { + return cBroker != null; + } + + private volatile ArrayList iLogListeners; + + private volatile ArrayList iTraceListeners; + + private volatile ArrayList iCIMXMLTraceListeners; + + private String iProductName = "SBLIM CIM Client for Java"; + + private String iCopyright = "COPYRIGHT (C) 2006, 2013 IBM Corp."; + + private String iVersion = "?"; + + private String iBuildDate = "?"; + + private String iBuildTime = "?"; + + private OutputStream iXmlTraceStream = null; + + private OutputStream iXmlTraceFile = null; + + private final String iTHIS_CLASS = this.getClass().getName(); + + private final String iTHROWABLE = Throwable.class.getName(); + + private int iInternalLevelConsole = Level.OFF.intValue(); + + private int iInternalLevelLogFile = Level.OFF.intValue(); + + private int iInternalLevelTraceFile = Level.OFF.intValue(); + + private LogListener iInternalListenerLogConsole = null; + + private LogListener iInternalListenerLogFile = null; + + private TraceListener iInternalListenerTraceConsole = null; + + private TraceListener iInternalListenerTraceFile = null; + + private int iNumInternalLogListeners = 0; + + private int iNumExternalLogListeners = 0; + + private int iNumInternalTraceListeners = 0; + + private int iNumExternalTraceListeners = 0; + + private LogAndTraceBroker() { + this.iLogListeners = new ArrayList(); + this.iTraceListeners = new ArrayList(); + this.iCIMXMLTraceListeners = new ArrayList(); + loadVersionTxt(); + registerInternalListeners(); + initXmlTraceFile(); + } + + @Override + protected void finalize() throws Throwable { + try { + if ( + this.iXmlTraceFile != null && + (!this.iXmlTraceFile.equals(System.out)) && + (!this.iXmlTraceFile.equals(System.err)) + ) this.iXmlTraceFile.close(); + } catch (IOException e) { + // bad luck + } finally { + this.iXmlTraceFile = null; + super.finalize(); + } + } + + /** + * Registers the listeners for our internal loggers + */ + public void registerInternalListeners() { + try { + Level level = WBEMConfiguration.getGlobalConfiguration().getLogConsoleLevel(); + String type = WBEMConfiguration.getGlobalConfiguration().getLogConsoleType(); + if (level.intValue() < Level.OFF.intValue() && WBEMConstants.MESSAGE.equals(type)) { + final Logger logger = Logger.getLogger(CONSOLE_LOGGER); + final Handler handler = new ConsoleHandler(); + handler.setFormatter(new LogFormatter()); + handler.setLevel(level); + logger.addHandler(handler); + logger.setLevel(level); + logger.setUseParentHandlers(false); + this.iInternalLevelConsole = level.intValue(); + if (this.iInternalListenerLogConsole != null) removeLogListener(this.iInternalListenerLogConsole); + this.iInternalListenerLogConsole = + new LogListener() { + + public void log(Level pLevel, String pMessageKey, String pMessage, Object[] pParameters) { + LogRecord record = new LogRecord(pLevel, pMessageKey + " " + pMessage); + record.setParameters(pParameters); + logger.log(record); + } + }; + addLogListener(this.iInternalListenerLogConsole); + } + } catch (Exception e) { + // Don't crash for logging + } + try { + Level level = WBEMConfiguration.getGlobalConfiguration().getLogFileLevel(); + String location = WBEMConfiguration.getGlobalConfiguration().getLogFileLocation(); + int size = WBEMConfiguration.getGlobalConfiguration().getLogFileSizeLimit(); + int count = WBEMConfiguration.getGlobalConfiguration().getLogFileCount(); + if (level.intValue() < Level.OFF.intValue()) { + final Logger logger = Logger.getLogger(FILE_LOGGER); + final Handler handler = new FileHandler(location, size, count); + handler.setFormatter(new LogFormatter()); + handler.setLevel(level); + logger.addHandler(handler); + logger.setLevel(level); + logger.setUseParentHandlers(false); + this.iInternalLevelLogFile = level.intValue(); + if (this.iInternalListenerLogFile != null) removeLogListener(this.iInternalListenerLogFile); + this.iInternalListenerLogFile = + new LogListener() { + + public void log(Level pLevel, String pMessageKey, String pMessage, Object[] pParameters) { + LogRecord record = new LogRecord(pLevel, pMessageKey + " " + pMessage); + record.setParameters(pParameters); + logger.log(record); + } + }; + addLogListener(this.iInternalListenerLogFile); + } + } catch (Exception e) { + // Don't crash for logging + } + try { + Level level = WBEMConfiguration.getGlobalConfiguration().getLogConsoleLevel(); + String type = WBEMConfiguration.getGlobalConfiguration().getLogConsoleType(); + if (level.intValue() < Level.OFF.intValue() && WBEMConstants.TRACE.equals(type)) { + final Logger logger = Logger.getLogger(CONSOLE_LOGGER); + final Handler handler = new ConsoleHandler(); + handler.setFormatter(new TraceFormatter()); + handler.setLevel(level); + logger.addHandler(handler); + logger.setLevel(level); + logger.setUseParentHandlers(false); + this.iInternalLevelConsole = level.intValue(); + if (this.iInternalListenerTraceConsole != null) removeTraceListener(this.iInternalListenerTraceConsole); + this.iInternalListenerTraceConsole = + new TraceListener() { + + public void trace(Level pLevel, StackTraceElement pOrigin, String pMessage) { + LogRecord record = new LogRecord(pLevel, pMessage); + record.setSourceMethodName(String.valueOf(pOrigin)); + logger.log(record); + } + + public void trace(Level pLevel, StackTraceElement pOrigin, String pMessage, Throwable pThrown) { + LogRecord record = new LogRecord(pLevel, pMessage); + record.setSourceMethodName(String.valueOf(pOrigin)); + record.setThrown(pThrown); + logger.log(record); + } + }; + addTraceListener(this.iInternalListenerTraceConsole); + } + } catch (Exception e) { + // Don't crash for logging + } + try { + Level level = WBEMConfiguration.getGlobalConfiguration().getTraceFileLevel(); + String location = WBEMConfiguration.getGlobalConfiguration().getTraceFileLocation(); + int size = WBEMConfiguration.getGlobalConfiguration().getTraceFileSizeLimit(); + int count = WBEMConfiguration.getGlobalConfiguration().getTraceFileCount(); + if (level.intValue() < Level.OFF.intValue()) { + final Logger logger = Logger.getLogger(TRACE_LOGGER); + final Handler handler = new FileHandler(location, size, count); + handler.setFormatter(new TraceFormatter()); + handler.setLevel(level); + logger.addHandler(handler); + logger.setLevel(level); + logger.setUseParentHandlers(false); + this.iInternalLevelTraceFile = level.intValue(); + if (this.iInternalListenerTraceFile != null) removeTraceListener(this.iInternalListenerTraceFile); + this.iInternalListenerTraceFile = + new TraceListener() { + + public void trace(Level pLevel, StackTraceElement pOrigin, String pMessage) { + LogRecord record = new LogRecord(pLevel, pMessage); + record.setSourceMethodName(String.valueOf(pOrigin)); + logger.log(record); + } + + public void trace(Level pLevel, StackTraceElement pOrigin, String pMessage, Throwable pThrown) { + LogRecord record = new LogRecord(pLevel, pMessage); + record.setSourceMethodName(String.valueOf(pOrigin)); + record.setThrown(pThrown); + logger.log(record); + } + }; + addTraceListener(this.iInternalListenerTraceFile); + } + } catch (Exception e) { + // Don't crash for logging + } + } + + /** + * Adds a listener for log messages. The listener will be notified of any + * log event. Uses copy on write to ensure concurrent read access. + * + * @param pListener + * The listener + */ + public synchronized void addLogListener(LogListener pListener) { + if (pListener == null) return; + sendGreetings(pListener); + ArrayList newListeners = new ArrayList(this.iLogListeners); + newListeners.add(pListener); + this.iLogListeners = newListeners; + + if ( + (this.iInternalListenerLogFile != null && this.iInternalListenerLogFile.equals(pListener)) || + (this.iInternalListenerLogConsole != null && this.iInternalListenerLogConsole.equals(pListener)) + ) { + this.iNumInternalLogListeners++; + } else { + this.iNumExternalLogListeners++; + } + } + + private void loadVersionTxt() { + InputStream is = null; + try { + Properties version = new Properties(); + is = LogAndTraceManager.class.getResourceAsStream("version.txt"); + version.load(is); + this.iProductName = version.getProperty("PRODUCTNAME"); + this.iCopyright = version.getProperty("COPYRIGHT"); + this.iVersion = version.getProperty("VERSION"); + this.iBuildDate = version.getProperty("BUILDDATE"); + this.iBuildTime = version.getProperty("BUILDTIME"); + } catch (Exception e) { + // nothing to do + } finally { + if (is != null) { + try { + is.close(); + } catch (IOException e) { + // nothing ro do + } + } + } + } + + private void sendGreetings(LogListener pListener) { + pListener.log( + MessageLoader.getLevel(Messages.GREETING), + Messages.GREETING, + MessageLoader.getLocalizedMessage(Messages.GREETING), + new Object[] { this.iProductName, this.iCopyright } + ); + pListener.log( + MessageLoader.getLevel(Messages.RELEASE), + Messages.RELEASE, + MessageLoader.getLocalizedMessage(Messages.RELEASE), + new Object[] { this.iVersion, this.iBuildDate, this.iBuildTime } + ); + pListener.log( + MessageLoader.getLevel(Messages.OS), + Messages.OS, + MessageLoader.getLocalizedMessage(Messages.OS), + new Object[] { System.getProperty("os.name"), System.getProperty("os.version"), System.getProperty("os.arch") } + ); + pListener.log( + MessageLoader.getLevel(Messages.JRE), + Messages.JRE, + MessageLoader.getLocalizedMessage(Messages.JRE), + new Object[] { System.getProperty("java.version"), System.getProperty("java.vendor") } + ); + pListener.log( + MessageLoader.getLevel(Messages.JVM), + Messages.JVM, + MessageLoader.getLocalizedMessage(Messages.JVM), + new Object[] { + System.getProperty("java.vm.name"), + System.getProperty("java.vm.version"), + System.getProperty("java.vm.vendor") + } + ); + pListener.log( + MessageLoader.getLevel(Messages.CONFIGURATION_URL), + Messages.CONFIGURATION_URL, + MessageLoader.getLocalizedMessage(Messages.CONFIGURATION_URL), + new Object[] { WBEMConfiguration.getActiveConfigFullURL() } + ); + if (!WBEMConfiguration.isConfigurationLoadSuccessful()) { + pListener.log( + MessageLoader.getLevel(Messages.CONFIGURATION_LOAD_FAILED), + Messages.CONFIGURATION_LOAD_FAILED, + MessageLoader.getLocalizedMessage(Messages.CONFIGURATION_LOAD_FAILED), + (Object[]) null + ); + if (WBEMConfiguration.getConfigurationLoadException() != null) { + pListener.log( + MessageLoader.getLevel(Messages.EXCEPTION_DURING_CONFIGURATION_LOAD), + Messages.EXCEPTION_DURING_CONFIGURATION_LOAD, + MessageLoader.getLocalizedMessage(Messages.EXCEPTION_DURING_CONFIGURATION_LOAD), + new Object[] { WBEMConfiguration.getConfigurationLoadException().getMessage() } + ); + } + } + } + + private void sendGreetings(TraceListener pListener) { + StackTraceElement origin = new Throwable().getStackTrace()[0]; + pListener.trace( + MessageLoader.getLevel(Messages.GREETING), + origin, + MessageFormat.format( + MessageLoader.getMessage(Messages.GREETING), + new Object[] { this.iProductName, this.iCopyright } + ) + ); + pListener.trace( + MessageLoader.getLevel(Messages.RELEASE), + origin, + MessageFormat.format( + MessageLoader.getMessage(Messages.RELEASE), + new Object[] { this.iVersion, this.iBuildDate, this.iBuildTime } + ) + ); + pListener.trace( + MessageLoader.getLevel(Messages.OS), + origin, + MessageFormat.format( + MessageLoader.getMessage(Messages.OS), + new Object[] { System.getProperty("os.name"), System.getProperty("os.version"), System.getProperty("os.arch") } + ) + ); + pListener.trace( + MessageLoader.getLevel(Messages.JRE), + origin, + MessageFormat.format( + MessageLoader.getMessage(Messages.JRE), + new Object[] { System.getProperty("java.version"), System.getProperty("java.vendor") } + ) + ); + pListener.trace( + MessageLoader.getLevel(Messages.JVM), + origin, + MessageFormat.format( + MessageLoader.getMessage(Messages.JVM), + new Object[] { + System.getProperty("java.vm.name"), + System.getProperty("java.vm.version"), + System.getProperty("java.vm.vendor") + } + ) + ); + pListener.trace( + MessageLoader.getLevel(Messages.CONFIGURATION_URL), + origin, + MessageFormat.format( + MessageLoader.getMessage(Messages.CONFIGURATION_URL), + new Object[] { WBEMConfiguration.getActiveConfigURL() } + ) + ); + if (!WBEMConfiguration.isConfigurationLoadSuccessful()) { + pListener.trace( + MessageLoader.getLevel(Messages.CONFIGURATION_LOAD_FAILED), + origin, + MessageLoader.getMessage(Messages.CONFIGURATION_LOAD_FAILED) + ); + if (WBEMConfiguration.getConfigurationLoadException() != null) { + pListener.trace( + MessageLoader.getLevel(Messages.EXCEPTION_DURING_CONFIGURATION_LOAD), + origin, + MessageLoader.getMessage(Messages.EXCEPTION_DURING_CONFIGURATION_LOAD), + WBEMConfiguration.getConfigurationLoadException() + ); + } + } + } + + /** + * Remove a listener. This listener will not be notified of log events + * anymore. + * + * @param pListener + * The listener + */ + public synchronized void removeLogListener(LogListener pListener) { + ArrayList newListeners = new ArrayList(this.iLogListeners); + if (!newListeners.remove(pListener)) return; + this.iLogListeners = newListeners; + + if (this.iInternalListenerLogFile != null && this.iInternalListenerLogFile.equals(pListener)) { + // Removing internal log listener for file + this.iInternalListenerLogFile = null; + this.iNumInternalLogListeners--; + } else if (this.iInternalListenerLogConsole != null && this.iInternalListenerLogConsole.equals(pListener)) { + // Removing internal log listener for console + this.iInternalListenerLogConsole = null; + this.iNumInternalLogListeners--; + } else { + // Removing user log listener + this.iNumExternalLogListeners--; + } + } + + /** + * Removes all listeners. Caution this will also remove the internal console + * and file loggers. + */ + public synchronized void clearLogListeners() { + this.iLogListeners = new ArrayList(); + removeHandlers(Logger.getLogger(CONSOLE_LOGGER)); + removeHandlers(Logger.getLogger(FILE_LOGGER)); + + this.iInternalListenerLogFile = null; + this.iInternalListenerLogConsole = null; + this.iNumInternalLogListeners = 0; + this.iNumExternalLogListeners = 0; + } + + /** + * Gets the registered log listeners including the internal console and file + * loggers. + * + * @return The list of listeners + */ + public List getLogListeners() { + return this.iLogListeners; + } + + /** + * Adds a listener for log messages. The listener will be notified of any + * trace event. + * + * @param pListener + * The listener + */ + public synchronized void addTraceListener(TraceListener pListener) { + if (pListener == null) return; + sendGreetings(pListener); + ArrayList newListeners = new ArrayList(this.iTraceListeners); + newListeners.add(pListener); + this.iTraceListeners = newListeners; + + if ( + (this.iInternalListenerTraceFile != null && this.iInternalListenerTraceFile.equals(pListener)) || + (this.iInternalListenerTraceConsole != null && this.iInternalListenerTraceConsole.equals(pListener)) + ) { + this.iNumInternalTraceListeners++; + } else { + this.iNumExternalTraceListeners++; + } + } + + /** + * Removes a listener. This listener will not be notified of trace events + * anymore. + * + * @param pListener + * The listener + */ + public synchronized void removeTraceListener(TraceListener pListener) { + ArrayList newListeners = new ArrayList(this.iTraceListeners); + if (!newListeners.remove(pListener)) return; + this.iTraceListeners = newListeners; + + if (this.iInternalListenerTraceFile != null && this.iInternalListenerTraceFile.equals(pListener)) { + // Removing internal tracelistener for file + this.iInternalListenerTraceFile = null; + this.iNumInternalTraceListeners--; + } else if (this.iInternalListenerTraceConsole != null && this.iInternalListenerTraceConsole.equals(pListener)) { + // Removing internal trace listener for console + this.iInternalListenerTraceConsole = null; + this.iNumInternalTraceListeners--; + } else { + // Removing user trace listener + this.iNumExternalTraceListeners--; + } + } + + /** + * Removes all listeners. Caution this will also remove the internal trace + * file listener. + */ + public synchronized void clearTraceListeners() { + this.iTraceListeners = new ArrayList(); + removeHandlers(Logger.getLogger(TRACE_LOGGER)); + + this.iInternalListenerTraceFile = null; + this.iInternalListenerTraceConsole = null; + this.iNumInternalTraceListeners = 0; + this.iNumExternalTraceListeners = 0; + } + + /** + * Gets the registered trace listeners including the internal console and + * file loggers. + * + * @return A list of listeners + */ + public List getTraceListeners() { + return this.iTraceListeners; + } + + /** + * Adds a listener for CIM-XML trace messages. The listener will be notified + * of any CIM-XML trace event. + * + * @param pListener + * The listener + */ + public synchronized void addCIMXMLTraceListener(CIMXMLTraceListener pListener) { + if (pListener == null) return; + ArrayList newListeners = new ArrayList(this.iCIMXMLTraceListeners); + newListeners.add(pListener); + this.iCIMXMLTraceListeners = newListeners; + } + + /** + * Removes a CIM-XML trace listener. This listener will not be notified of + * CIM-XML trace events anymore. + * + * @param pListener + * The listener + */ + public synchronized void removeCIMXMLTraceListener(CIMXMLTraceListener pListener) { + ArrayList newListeners = new ArrayList(this.iCIMXMLTraceListeners); + if (!newListeners.remove(pListener)) return; + this.iCIMXMLTraceListeners = newListeners; + } + + /** + * Removes all CIM-XML trace listeners. + */ + public synchronized void clearCIMXMLTraceListeners() { + if (this.iCIMXMLTraceListeners.size() > 0) this.iCIMXMLTraceListeners = new ArrayList(); + } + + /** + * Gets the registered CIM-XML trace listeners. + * + * @return A list of listeners + */ + public List getCIMXMLTraceListeners() { + return this.iCIMXMLTraceListeners; + } + + /** + * Forwards a log/trace message to the registered log&trace listeners. + * + * @param pKey + * The message identifier. + */ + public void message(String pKey) { + message(pKey, (Object[]) null); + } + + /** + * Forwards a log/trace message to the registered log&trace listeners. + * + * @param pKey + * The message identifier. + * @param pParameter + * The parameter for the message + */ + public void message(String pKey, Object pParameter) { + message(pKey, new Object[] { pParameter }); + } + + /** + * Forwards a log/trace message to the registered log&trace listeners. + * + * @param pKey + * The message identifier. + * @param pParameters + * The parameters for the message + */ + public void message(String pKey, Object[] pParameters) { + try { + final String message = MessageLoader.getMessage(pKey); + final String localMessage = MessageLoader.getLocalizedMessage(pKey); + final Level level = MessageLoader.getLevel(pKey); + if (isLoggableTrace(level)) { + final List traceListeners = getTraceListeners(); + StackTraceElement caller = getCaller(); + for (int i = 0; i < traceListeners.size(); ++i) { + traceListeners.get(i).trace(level, caller, pKey + " " + MessageFormat.format(message, pParameters)); + } + } + final List logListeners = getLogListeners(); + for (int i = 0; i < logListeners.size(); ++i) { + logListeners.get(i).log(level, pKey, localMessage, pParameters); + } + } catch (Exception e) { + // don't crash for logging + } + } + + /** + * Forwards a trace message to the registered trace listeners. + * + * @param pLevel + * One of the three message level identifiers FINE, FINER and + * FINEST + * @param pMessage + * The message text + */ + public void trace(Level pLevel, String pMessage) { + try { + if (isLoggableTrace(pLevel)) { + final List traceListeners = getTraceListeners(); + StackTraceElement caller = getCaller(); + for (int i = 0; i < traceListeners.size(); ++i) { + traceListeners.get(i).trace(pLevel, caller, pMessage); + } + } + } catch (Exception e) { + // don't crash for logging + } + } + + /** + * Forwards a trace message to the registered trace listeners. + * + * @param pLevel + * One of the three message level identifiers FINE, FINER and + * FINEST + * @param pMessage + * The message text + * @param pThrown + * The throwable associated with the message + */ + public void trace(Level pLevel, String pMessage, Throwable pThrown) { + try { + if (isLoggableTrace(pLevel)) { + final List traceListeners = getTraceListeners(); + StackTraceElement caller = getCaller(); + for (int i = 0; i < traceListeners.size(); ++i) { + traceListeners.get(i).trace(pLevel, caller, pMessage, pThrown); + } + } + } catch (Exception e) { + // don't crash for logging + } + } + + /** + * Forwards a CIM-XML trace message to the registered CIM-XML trace + * listeners. + * + * @param pLevel + * One of the message level identifiers, e.g. FINE + * @param pMessage + * The CIM-XML message text + * @param pOutgoing + * true if CIM-XML is outgoing (being sent from + * client to server), false if CIM-XML is incoming + * (being sent from server to client) + */ + public void traceCIMXML(Level pLevel, String pMessage, boolean pOutgoing) { + try { + if (this.iCIMXMLTraceListeners.size() > 0) { + final List traceListeners = getCIMXMLTraceListeners(); + for (int i = 0; i < traceListeners.size(); ++i) { + traceListeners.get(i).traceCIMXML(pLevel, pMessage, pOutgoing); + } + } + } catch (Exception e) { + // don't crash for logging + } + } + + /** + * Forwards a method entry message to the registered trace listeners. + */ + public void entry() { + trace(Level.FINEST, "Entering method"); + } + + /** + * Forwards a method exit message to the registered trace listeners. + */ + public void exit() { + trace(Level.FINEST, "Exiting method"); + } + + /** + * Returns the output stream to which all CIM-XML traffic (outgoing & + * incoming) will be copied for debugging purposes. + * + * @return The output stream. A null value means that CIM-XML + * debugging is disabled + */ + public OutputStream getXmlTraceStream() { + return this.iXmlTraceStream; + } + + /** + * Sets an output stream to which all CIM-XML traffic (outgoing & + * incoming) will be copied for debugging purposes. + * + * @param pStream + * The output stream. A null value means that + * CIM-XML debugging is disabled. + */ + public void setXmlTraceStream(OutputStream pStream) { + this.iXmlTraceStream = pStream; + } + + /* + * Initializes the CIM-XML trace file (sblim.wbem.cimxmlTraceStream) during + * initialization of LogAndTraceBroker - the trace file is used if CIM-XML + * tracing is enabled (sblim.wbem.cimxmlTracing=true) but there is no + * CIM-XML trace stream set via setXmlTraceStream() + */ + private void initXmlTraceFile() { + try { + if (WBEMConfiguration.getGlobalConfiguration().isCimXmlTracingEnabled()) { + String filename = WBEMConfiguration.getGlobalConfiguration().getCimXmlTraceStream(); + if (filename != null && filename.length() > 0 && this.iXmlTraceFile == null && getXmlTraceStream() == null) { + if (filename.equalsIgnoreCase("System.out")) { + this.iXmlTraceFile = System.out; + } else if (filename.equalsIgnoreCase("System.err")) { + this.iXmlTraceFile = System.err; + } else { + try { + this.iXmlTraceFile = new FileOutputStream(filename); + } catch (IOException e) { + trace( + Level.FINE, + "Unable to open " + WBEMConfigurationProperties.CIMXML_TRACE_STREAM + "=" + filename, + e + ); + } + } + setXmlTraceStream(this.iXmlTraceFile); + } + } + } catch (Exception e) { + // Don't crash for logging + } + } + + /** + * Analyzes the stack trace and determines from where the + * LogAndTraceBroker was called. + * + * @return First StackTraceElement outside the + * LogAndTraceBroker + */ + private StackTraceElement getCaller() { + StackTraceElement[] stack = (new Throwable()).getStackTrace(); + for (int i = 0; i < stack.length; ++i) { + StackTraceElement frame = stack[i]; + String cname = frame.getClassName(); + if (!this.iTHIS_CLASS.equals(cname) && !this.iTHROWABLE.equals(cname)) { + return frame; + } + } + return null; + } + + /** + * Removes all handlers from a logger + * + * @param pLogger + * The logger + */ + private void removeHandlers(Logger pLogger) { + Handler[] handlers = pLogger.getHandlers(); + for (int i = 0; i < handlers.length; ++i) { + pLogger.removeHandler(handlers[i]); + handlers[i].close(); + } + } + + /** + * Checks whether there are trace listeners installed that will log a trace + * message with the specified level. Use this method to determine if a + * trace() method call could result in logging before preparing the + * information to be logged. For example: + * + *
      +	 *     if (logger.isLoggableTrace(Level.WARNING) {
      +	 *         // Prepare info for logging
      +	 *         logger.trace(Level.WARNING, ...
      +	 * 
      + * + * @param pLevel + * The Level of the trace message. + * @return true if trace message could be logged, + * false otherwise. + */ + public boolean isLoggableTrace(Level pLevel) { + // If there are no trace listeners or specified level is OFF, message + // will not be logged + if (this.iTraceListeners.size() == 0 || pLevel.intValue() == Level.OFF.intValue()) return false; + + // If there are external trace listeners, message could be logged (user + // can alter level at will, so we do not know what it is) + if (this.iNumExternalTraceListeners > 0) return true; + + // If there are internal trace listeners, determine if message will be + // logged + if (this.iNumInternalTraceListeners > 0) { + int level = Level.OFF.intValue(); + if (this.iInternalListenerTraceFile != null) { + level = this.iInternalLevelTraceFile; + } + if (this.iInternalListenerTraceConsole != null && level > this.iInternalLevelConsole) { + level = this.iInternalLevelConsole; + } + return level <= pLevel.intValue(); + } + + return true; + } + + /** + * Checks whether there are log listeners installed that will log a message + * with the specified level. Use this method to determine if a message() + * method call could result in logging before preparing the information to + * be logged. For example: + * + *
      +	 *     if (logger.isLoggableMessage(Level.WARNING) {
      +	 *         // Prepare info for logging
      +	 *         logger.message(Level.WARNING, ...
      +	 * 
      + * + * @param pLevel + * The Level of the message. + * @return true if message could be logged, false + * otherwise. + */ + public boolean isLoggableMessage(Level pLevel) { + // If message is traceable, message could be logged + if (isLoggableTrace(pLevel)) return true; + + // If there are no log listeners or specified level is OFF, message + // will not be logged + if (this.iLogListeners.size() == 0 || pLevel.intValue() == Level.OFF.intValue()) return false; + + // If there are external log listeners, message could be logged (user + // can alter level at will, so we do not know what it is) + if (this.iNumExternalLogListeners > 0) return true; + + // If there are internal log listeners, determine if message will be + // logged + if (this.iNumInternalLogListeners > 0) { + int level = Level.OFF.intValue(); + if (this.iInternalListenerLogFile != null) { + level = this.iInternalLevelLogFile; + } + if (this.iInternalListenerLogConsole != null && level > this.iInternalLevelConsole) { + level = this.iInternalLevelConsole; + } + return level <= pLevel.intValue(); + } + + return true; + } + + /** + * Checks whether there are CIM-XML trace listeners installed that will log + * a CIM-XML trace message. Use this method to determine if a trace() method + * call could result in logging before preparing the information to be + * logged. For example: + * + *
      +	 *     if (logger.isLoggableCIMXMLTrace(Level.FINEST) {
      +	 *         // Prepare info for logging
      +	 *         logger.traceCIMXML(Level.FINEST, ...
      +	 * 
      + * + * @param pLevel + * The Level of the trace message. + * @return true if CIM-XML trace message could be logged, + * false otherwise. + */ + public boolean isLoggableCIMXMLTrace(Level pLevel) { + // If there are no CIM-XML trace listeners or specified level is OFF, + // message will not be logged + if (this.iCIMXMLTraceListeners.size() == 0 || pLevel.intValue() == Level.OFF.intValue()) return false; + + return true; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/logging/LogFormatter.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/logging/LogFormatter.java similarity index 71% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/logging/LogFormatter.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/logging/LogFormatter.java index 5933868..2ff6d23 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/logging/LogFormatter.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/logging/LogFormatter.java @@ -1,84 +1,81 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1565892 2006-11-15 lupusalex Make SBLIM client JSR48 compliant - * 1745282 2007-06-29 ebak Uniform time stamps for log files - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.logging; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.text.MessageFormat; -import java.util.logging.Formatter; -import java.util.logging.LogRecord; - -/** - * Class LogFormatter implements the formatting algorithm for our console log. - * - */ -public class LogFormatter extends Formatter { - - private final String iLineSeparator = System.getProperty("line.separator"); - - /** - * Ctor. - */ - public LogFormatter() { - super(); - } - - /* - * (non-Javadoc) - * - * @see java.util.logging.Formatter#format(java.util.logging.LogRecord) - */ - @Override - public String format(LogRecord pRecord) { - StringBuffer buffer = new StringBuffer(); - buffer.append(TimeStamp.format(pRecord.getMillis())); - buffer.append(" >"); - buffer.append(String.valueOf(pRecord.getThreadID())); - buffer.append("< "); - // buffer.append(iLineSeparator); - buffer.append(pRecord.getLevel().getName()); - buffer.append(": "); - buffer.append(MessageFormat.format(pRecord.getMessage(), pRecord.getParameters())); - buffer.append(this.iLineSeparator); - return buffer.toString(); - } -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1565892 2006-11-15 lupusalex Make SBLIM client JSR48 compliant + * 1745282 2007-06-29 ebak Uniform time stamps for log files + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.logging; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.text.MessageFormat; +import java.util.logging.Formatter; +import java.util.logging.LogRecord; + +/** + * Class LogFormatter implements the formatting algorithm for our console log. + * + */ +public class LogFormatter extends Formatter { + private final String iLineSeparator = System.getProperty("line.separator"); + + /** + * Ctor. + */ + public LogFormatter() { + super(); + } + + /* + * (non-Javadoc) + * + * @see java.util.logging.Formatter#format(java.util.logging.LogRecord) + */ + @Override + public String format(LogRecord pRecord) { + StringBuffer buffer = new StringBuffer(); + buffer.append(TimeStamp.format(pRecord.getMillis())); + buffer.append(" >"); + buffer.append(String.valueOf(pRecord.getThreadID())); + buffer.append("< "); + // buffer.append(iLineSeparator); + buffer.append(pRecord.getLevel().getName()); + buffer.append(": "); + buffer.append(MessageFormat.format(pRecord.getMessage(), pRecord.getParameters())); + buffer.append(this.iLineSeparator); + return buffer.toString(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/logging/MessageLoader.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/logging/MessageLoader.java similarity index 74% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/logging/MessageLoader.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/logging/MessageLoader.java index 0af851c..8f80a92 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/logging/MessageLoader.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/logging/MessageLoader.java @@ -1,140 +1,135 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1565892 2006-11-14 lupusalex Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2787464 2009-05-05 blaschke-oss lang exception in Chinese env with Java client 2.0.7 - */ -package org.sentrysoftware.wbem.sblim.cimclient.internal.logging; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; -import java.util.logging.Level; - -/** - * Class MessageLoader encapsulates the access to the resource file containing - * log messages. - * - */ -public final class MessageLoader { - - private static final String BUNDLE_NAME = "org.sblim.cimclient.internal.logging.messages"; //$NON-NLS-1$ - - private static final ResourceBundle RESOURCE_BUNDLE_LOCAL - /* = ResourceBundle.getBundle(BUNDLE_NAME, Locale.getDefault()) */; - - private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME, - Locale.ENGLISH); - - /* - * Use English if default locale not supported (doing it here handles - * exception, assigning above does not) - */ - static { - ResourceBundle bundleLocal; - try { - bundleLocal = ResourceBundle.getBundle(BUNDLE_NAME, Locale.getDefault()); - } catch (MissingResourceException e) { - bundleLocal = RESOURCE_BUNDLE; - } - RESOURCE_BUNDLE_LOCAL = bundleLocal; - } - - private MessageLoader() { - // prevent instantiation - } - - /** - * Returns the English message for a given key. - * - * @param pKey - * The key - * @return The message - */ - public static String getMessage(String pKey) { - try { - return RESOURCE_BUNDLE.getString(pKey); - } catch (MissingResourceException e) { - return '!' + pKey + '!'; - } - } - - /** - * Returns the localized message for a given key. - * - * @param pKey - * The key - * @return The message - */ - public static String getLocalizedMessage(String pKey) { - try { - return RESOURCE_BUNDLE_LOCAL.getString(pKey); - } catch (MissingResourceException e) { - return '!' + pKey + '!'; - } - } - - /** - * Returns the level of a given message id based on the naming convention. - * The convention is: - * CIM<unique 4 digit id><level token>, e.g. - * CIM1234S. Valid level tokens are S, W, I and - * C for SEVERE, WARNING, INFO and - * CONFIG respectively. - * - * @param pKey - * The message id - * @return The level - */ - public static Level getLevel(String pKey) { - char level = pKey.charAt(pKey.length() - 1); - switch (level) { - case 'S': - return Level.SEVERE; - case 'W': - return Level.WARNING; - case 'I': - return Level.INFO; - case 'C': - return Level.CONFIG; - default: - return null; - } - } -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1565892 2006-11-14 lupusalex Make SBLIM client JSR48 compliant + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2787464 2009-05-05 blaschke-oss lang exception in Chinese env with Java client 2.0.7 + */ +package org.metricshub.wbem.sblim.cimclient.internal.logging; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Locale; +import java.util.MissingResourceException; +import java.util.ResourceBundle; +import java.util.logging.Level; + +/** + * Class MessageLoader encapsulates the access to the resource file containing + * log messages. + * + */ +public final class MessageLoader { + private static final String BUNDLE_NAME = "org.sblim.cimclient.internal.logging.messages"; //$NON-NLS-1$ + + private static final ResourceBundle RESOURCE_BUNDLE_LOCAL/* = ResourceBundle.getBundle(BUNDLE_NAME, Locale.getDefault()) */; + + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME, Locale.ENGLISH); + + /* + * Use English if default locale not supported (doing it here handles + * exception, assigning above does not) + */ + static { + ResourceBundle bundleLocal; + try { + bundleLocal = ResourceBundle.getBundle(BUNDLE_NAME, Locale.getDefault()); + } catch (MissingResourceException e) { + bundleLocal = RESOURCE_BUNDLE; + } + RESOURCE_BUNDLE_LOCAL = bundleLocal; + } + + private MessageLoader() { + // prevent instantiation + } + + /** + * Returns the English message for a given key. + * + * @param pKey + * The key + * @return The message + */ + public static String getMessage(String pKey) { + try { + return RESOURCE_BUNDLE.getString(pKey); + } catch (MissingResourceException e) { + return '!' + pKey + '!'; + } + } + + /** + * Returns the localized message for a given key. + * + * @param pKey + * The key + * @return The message + */ + public static String getLocalizedMessage(String pKey) { + try { + return RESOURCE_BUNDLE_LOCAL.getString(pKey); + } catch (MissingResourceException e) { + return '!' + pKey + '!'; + } + } + + /** + * Returns the level of a given message id based on the naming convention. + * The convention is: + * CIM<unique 4 digit id><level token>, e.g. + * CIM1234S. Valid level tokens are S, W, I and + * C for SEVERE, WARNING, INFO and + * CONFIG respectively. + * + * @param pKey + * The message id + * @return The level + */ + public static Level getLevel(String pKey) { + char level = pKey.charAt(pKey.length() - 1); + switch (level) { + case 'S': + return Level.SEVERE; + case 'W': + return Level.WARNING; + case 'I': + return Level.INFO; + case 'C': + return Level.CONFIG; + default: + return null; + } + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/logging/Messages.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/logging/Messages.java similarity index 82% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/logging/Messages.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/logging/Messages.java index 3efa689..2a2d746 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/logging/Messages.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/logging/Messages.java @@ -1,252 +1,249 @@ -/* - (C) Copyright IBM Corp. 2006, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1565892 2006-11-16 lupusalex Make SBLIM client JSR48 compliant - * 1711092 2006-05-02 lupusalex Some fixes/additions of log&trace messages - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 3536399 2012-08-25 hellerda Add client/listener peer authentication properties - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.logging; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * Interface Messages holds the constants for the message keys. - * - */ -public interface Messages { - - /** - * GREETING - */ - public String GREETING = "CIM0001I"; - - /** - * RELEASE - */ - public String RELEASE = "CIM0002I"; - - /** - * OS - */ - public String OS = "CIM0003I"; - - /** - * JRE - */ - public String JRE = "CIM0004I"; - - /** - * JVM - */ - public String JVM = "CIM0005I"; - - /** - * CONFIGURATION_URL - */ - public String CONFIGURATION_URL = "CIM1001C"; - - /** - * CONFIGURATION_LOAD_FAILED - */ - public String CONFIGURATION_LOAD_FAILED = "CIM1002C"; - - /** - * EXCEPTION_DURING_CONFIGURATION_LOAD - */ - public String EXCEPTION_DURING_CONFIGURATION_LOAD = "CIM1003S"; - - /** - * INVALID_KEY_IN_CONFIG_FILE - */ - public String INVALID_KEY_IN_CONFIG_FILE = "CIM1004W"; - - /** - * HTTP_PROXY_AUTH_UNSUPPORTED - */ - public String HTTP_PROXY_AUTH_UNSUPPORTED = "CIM2001S"; - - /** - * HTTP_CONNECTION_FAILED - */ - public String HTTP_CONNECTION_FAILED = "CIM2002W"; - - /** - * HTTP_NO_SOCKET_FACTORY - */ - public String HTTP_NO_SOCKET_FACTORY = "CIM2003S"; - - /** - * HTTP_AUTH_MODULE_INVALID - */ - public String HTTP_AUTH_MODULE_INVALID = "CIM2004S"; - - /** - * HTTP_INVALID_HEADER - */ - public String HTTP_INVALID_HEADER = "CIM2005W"; - - /** - * HTTP_HANDLE_CONNECTION_FAILED - */ - public String HTTP_HANDLE_CONNECTION_FAILED = "CIM2006S"; - - /** - * HTTP_PEGASUS_LOCAL_AUTH_READ - */ - public String HTTP_PEGASUS_LOCAL_AUTH_READ = "CIM2007S"; - - /** - * SSL_JSSE_PROVIDER_LOAD_FAILED - */ - public String SSL_JSSE_PROVIDER_LOAD_FAILED = "CIM2100S"; - - /** - * SSL_KEYSTORE_NOT_FOUND - */ - public String SSL_KEYSTORE_NOT_FOUND = "CIM2101C"; - - /** - * SSL_KEYSTORE_NOT_READABLE - */ - public String SSL_KEYSTORE_NOT_READABLE = "CIM2102W"; - - /** - * SSL_KEYSTORE_INVALID_CERT - */ - public String SSL_KEYSTORE_INVALID_CERT = "CIM2103W"; - - /** - * SSL_KEYSTORE_UNRECOVERABLE_KEY - */ - public String SSL_KEYSTORE_UNRECOVERABLE_KEY = "CIM2104W"; - - /** - * SSL_KEYSTORE_INVALID - */ - public String SSL_KEYSTORE_INVALID = "CIM2105W"; - - /** - * SSL_KEYSTORE_OTHER - */ - public String SSL_KEYSTORE_OTHER = "CIM2106W"; - - /** - * SSL_KEYSTORE_FALLBACK - */ - public String SSL_KEYSTORE_FALLBACK = "CIM2107C"; - - /** - * SSL_CONTEXT_INIT_FAILED - */ - public String SSL_CONTEXT_INIT_FAILED = "CIM2301S"; - - /** - * SSL_KEYSTORE_INVALID_ALGORITHM - */ - public String SSL_KEYSTORE_INVALID_ALGORITHM = "CIM2108W"; - - /** - * SSL_KEYSTORE_NULL - */ - public String SSL_KEYSTORE_NULL = "CIM2110C"; - - /** - * SSL_TRUSTSTORE_NOT_FOUND - */ - public String SSL_TRUSTSTORE_NOT_FOUND = "CIM2201C"; - - /** - * SSL_TRUSTSTORE_NOT_READABLE - */ - public String SSL_TRUSTSTORE_NOT_READABLE = "CIM2202W"; - - /** - * SSL_TRUSTSTORE_INVALID_CERT - */ - public String SSL_TRUSTSTORE_INVALID_CERT = "CIM2203W"; - - /** - * SSL_TRUSTSTORE_INVALID - */ - public String SSL_TRUSTSTORE_INVALID = "CIM2205W"; - - /** - * SSL_TRUSTSTORE_OTHER - */ - public String SSL_TRUSTSTORE_OTHER = "CIM2206W"; - - /** - * SSL_TRUSTSTORE_FALLBACK - */ - public String SSL_TRUSTSTORE_FALLBACK = "CIM2207C"; - - /** - * SSL_TRUSTSTORE_INVALID_ALGORITHM - */ - public String SSL_TRUSTSTORE_INVALID_ALGORITHM = "CIM2208W"; - - /** - * SSL_TRUSTSTORE_ACTIVE - */ - public String SSL_TRUSTSTORE_ACTIVE = "CIM2209C"; - - /** - * SSL_TRUSTSTORE_NULL - */ - public String SSL_TRUSTSTORE_NULL = "CIM2210C"; - - /** - * SSL_TRUSTSTORE_INACTIVE - */ - public String SSL_TRUSTSTORE_INACTIVE = "CIM2211W"; - - /** - * SSL_TRUSTSTORE_FALLBACK_NOTRUST - */ - public String SSL_TRUSTSTORE_FALLBACK_NOTRUST = "CIM2212W"; - - /** - * CIM_XMLHELPER_FAILED - */ - public String CIM_XMLHELPER_FAILED = "CIM3000S"; - - /** - * TEST_MESSAGE - */ - public String TEST_MESSAGE = "CIM9999S"; -} +/* + (C) Copyright IBM Corp. 2006, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1565892 2006-11-16 lupusalex Make SBLIM client JSR48 compliant + * 1711092 2006-05-02 lupusalex Some fixes/additions of log&trace messages + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 3536399 2012-08-25 hellerda Add client/listener peer authentication properties + */ + +package org.metricshub.wbem.sblim.cimclient.internal.logging; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * Interface Messages holds the constants for the message keys. + * + */ +public interface Messages { + /** + * GREETING + */ + public String GREETING = "CIM0001I"; + + /** + * RELEASE + */ + public String RELEASE = "CIM0002I"; + + /** + * OS + */ + public String OS = "CIM0003I"; + + /** + * JRE + */ + public String JRE = "CIM0004I"; + + /** + * JVM + */ + public String JVM = "CIM0005I"; + + /** + * CONFIGURATION_URL + */ + public String CONFIGURATION_URL = "CIM1001C"; + + /** + * CONFIGURATION_LOAD_FAILED + */ + public String CONFIGURATION_LOAD_FAILED = "CIM1002C"; + + /** + * EXCEPTION_DURING_CONFIGURATION_LOAD + */ + public String EXCEPTION_DURING_CONFIGURATION_LOAD = "CIM1003S"; + + /** + * INVALID_KEY_IN_CONFIG_FILE + */ + public String INVALID_KEY_IN_CONFIG_FILE = "CIM1004W"; + + /** + * HTTP_PROXY_AUTH_UNSUPPORTED + */ + public String HTTP_PROXY_AUTH_UNSUPPORTED = "CIM2001S"; + + /** + * HTTP_CONNECTION_FAILED + */ + public String HTTP_CONNECTION_FAILED = "CIM2002W"; + + /** + * HTTP_NO_SOCKET_FACTORY + */ + public String HTTP_NO_SOCKET_FACTORY = "CIM2003S"; + + /** + * HTTP_AUTH_MODULE_INVALID + */ + public String HTTP_AUTH_MODULE_INVALID = "CIM2004S"; + + /** + * HTTP_INVALID_HEADER + */ + public String HTTP_INVALID_HEADER = "CIM2005W"; + + /** + * HTTP_HANDLE_CONNECTION_FAILED + */ + public String HTTP_HANDLE_CONNECTION_FAILED = "CIM2006S"; + + /** + * HTTP_PEGASUS_LOCAL_AUTH_READ + */ + public String HTTP_PEGASUS_LOCAL_AUTH_READ = "CIM2007S"; + + /** + * SSL_JSSE_PROVIDER_LOAD_FAILED + */ + public String SSL_JSSE_PROVIDER_LOAD_FAILED = "CIM2100S"; + + /** + * SSL_KEYSTORE_NOT_FOUND + */ + public String SSL_KEYSTORE_NOT_FOUND = "CIM2101C"; + + /** + * SSL_KEYSTORE_NOT_READABLE + */ + public String SSL_KEYSTORE_NOT_READABLE = "CIM2102W"; + + /** + * SSL_KEYSTORE_INVALID_CERT + */ + public String SSL_KEYSTORE_INVALID_CERT = "CIM2103W"; + + /** + * SSL_KEYSTORE_UNRECOVERABLE_KEY + */ + public String SSL_KEYSTORE_UNRECOVERABLE_KEY = "CIM2104W"; + + /** + * SSL_KEYSTORE_INVALID + */ + public String SSL_KEYSTORE_INVALID = "CIM2105W"; + + /** + * SSL_KEYSTORE_OTHER + */ + public String SSL_KEYSTORE_OTHER = "CIM2106W"; + + /** + * SSL_KEYSTORE_FALLBACK + */ + public String SSL_KEYSTORE_FALLBACK = "CIM2107C"; + + /** + * SSL_CONTEXT_INIT_FAILED + */ + public String SSL_CONTEXT_INIT_FAILED = "CIM2301S"; + + /** + * SSL_KEYSTORE_INVALID_ALGORITHM + */ + public String SSL_KEYSTORE_INVALID_ALGORITHM = "CIM2108W"; + + /** + * SSL_KEYSTORE_NULL + */ + public String SSL_KEYSTORE_NULL = "CIM2110C"; + + /** + * SSL_TRUSTSTORE_NOT_FOUND + */ + public String SSL_TRUSTSTORE_NOT_FOUND = "CIM2201C"; + + /** + * SSL_TRUSTSTORE_NOT_READABLE + */ + public String SSL_TRUSTSTORE_NOT_READABLE = "CIM2202W"; + + /** + * SSL_TRUSTSTORE_INVALID_CERT + */ + public String SSL_TRUSTSTORE_INVALID_CERT = "CIM2203W"; + + /** + * SSL_TRUSTSTORE_INVALID + */ + public String SSL_TRUSTSTORE_INVALID = "CIM2205W"; + + /** + * SSL_TRUSTSTORE_OTHER + */ + public String SSL_TRUSTSTORE_OTHER = "CIM2206W"; + + /** + * SSL_TRUSTSTORE_FALLBACK + */ + public String SSL_TRUSTSTORE_FALLBACK = "CIM2207C"; + + /** + * SSL_TRUSTSTORE_INVALID_ALGORITHM + */ + public String SSL_TRUSTSTORE_INVALID_ALGORITHM = "CIM2208W"; + + /** + * SSL_TRUSTSTORE_ACTIVE + */ + public String SSL_TRUSTSTORE_ACTIVE = "CIM2209C"; + + /** + * SSL_TRUSTSTORE_NULL + */ + public String SSL_TRUSTSTORE_NULL = "CIM2210C"; + + /** + * SSL_TRUSTSTORE_INACTIVE + */ + public String SSL_TRUSTSTORE_INACTIVE = "CIM2211W"; + + /** + * SSL_TRUSTSTORE_FALLBACK_NOTRUST + */ + public String SSL_TRUSTSTORE_FALLBACK_NOTRUST = "CIM2212W"; + + /** + * CIM_XMLHELPER_FAILED + */ + public String CIM_XMLHELPER_FAILED = "CIM3000S"; + + /** + * TEST_MESSAGE + */ + public String TEST_MESSAGE = "CIM9999S"; +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/logging/TimeStamp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/logging/TimeStamp.java similarity index 74% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/logging/TimeStamp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/logging/TimeStamp.java index 9f1303b..86a4ef8 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/logging/TimeStamp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/logging/TimeStamp.java @@ -1,120 +1,116 @@ -/* - (C) Copyright IBM Corp. 2006, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1745282 2007-06-29 ebak Uniform time stamps for log files - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 3062747 2010-09-21 blaschke-oss SblimCIMClient does not log all CIM-XML responces. - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.logging; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Calendar; - -/** - * Class TimeStamp is responsible for building uniform date/time strings for - * logging and tracing. - * - */ -public class TimeStamp { - - private static String pad(int pDigits, int pNum) { - String str = Integer.toString(pNum); - int len = Math.max(pDigits, str.length()); - char[] cA = new char[len]; - int paddingDigits = pDigits - str.length(); - int dIdx = 0; - while (dIdx < paddingDigits) - cA[dIdx++] = '0'; - int sIdx = 0; - while (dIdx < len) - cA[dIdx++] = str.charAt(sIdx++); - return new String(cA); - } - - /** - * formatWorker - * - * @param pMillis - * - total milliseconds - * @param pIncludeMillis - * - include milliseconds in String - * @return formatted date/time String. ( YYYY.MM.DD HH:mm:SS[.sss] ) - */ - private static String formatWorker(long pMillis, boolean pIncludeMillis) { - Calendar cal = Calendar.getInstance(); - cal.setTimeInMillis(pMillis); - StringBuilder sb = new StringBuilder(Integer.toString(cal.get(Calendar.YEAR))); - sb.append('.'); - sb.append(pad(2, cal.get(Calendar.MONTH) + 1)); - sb.append('.'); - sb.append(pad(2, cal.get(Calendar.DAY_OF_MONTH))); - sb.append(' '); - sb.append(pad(2, cal.get(Calendar.HOUR_OF_DAY))); - sb.append(':'); - sb.append(pad(2, cal.get(Calendar.MINUTE))); - sb.append(':'); - sb.append(pad(2, cal.get(Calendar.SECOND))); - if (pIncludeMillis) { - sb.append('.'); - sb.append(pad(3, cal.get(Calendar.MILLISECOND))); - } - return sb.toString(); - } - - /** - * format - * - * @param pMillis - * - total milliseconds - * @return formatted date/time String. ( YYYY.MM.DD HH:mm:SS ) - */ - public static String format(long pMillis) { - return formatWorker(pMillis, false); - } - - /** - * formatWithMillis - * - * @param pMillis - * - total milliseconds - * @return formatted date/time String. ( YYYY.MM.DD HH:mm:SS.sss ) - */ - public static String formatWithMillis(long pMillis) { - return formatWorker(pMillis, true); - } -} +/* + (C) Copyright IBM Corp. 2006, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1745282 2007-06-29 ebak Uniform time stamps for log files + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 3062747 2010-09-21 blaschke-oss SblimCIMClient does not log all CIM-XML responces. + */ + +package org.metricshub.wbem.sblim.cimclient.internal.logging; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Calendar; + +/** + * Class TimeStamp is responsible for building uniform date/time strings for + * logging and tracing. + * + */ +public class TimeStamp { + + private static String pad(int pDigits, int pNum) { + String str = Integer.toString(pNum); + int len = Math.max(pDigits, str.length()); + char[] cA = new char[len]; + int paddingDigits = pDigits - str.length(); + int dIdx = 0; + while (dIdx < paddingDigits) cA[dIdx++] = '0'; + int sIdx = 0; + while (dIdx < len) cA[dIdx++] = str.charAt(sIdx++); + return new String(cA); + } + + /** + * formatWorker + * + * @param pMillis + * - total milliseconds + * @param pIncludeMillis + * - include milliseconds in String + * @return formatted date/time String. ( YYYY.MM.DD HH:mm:SS[.sss] ) + */ + private static String formatWorker(long pMillis, boolean pIncludeMillis) { + Calendar cal = Calendar.getInstance(); + cal.setTimeInMillis(pMillis); + StringBuilder sb = new StringBuilder(Integer.toString(cal.get(Calendar.YEAR))); + sb.append('.'); + sb.append(pad(2, cal.get(Calendar.MONTH) + 1)); + sb.append('.'); + sb.append(pad(2, cal.get(Calendar.DAY_OF_MONTH))); + sb.append(' '); + sb.append(pad(2, cal.get(Calendar.HOUR_OF_DAY))); + sb.append(':'); + sb.append(pad(2, cal.get(Calendar.MINUTE))); + sb.append(':'); + sb.append(pad(2, cal.get(Calendar.SECOND))); + if (pIncludeMillis) { + sb.append('.'); + sb.append(pad(3, cal.get(Calendar.MILLISECOND))); + } + return sb.toString(); + } + + /** + * format + * + * @param pMillis + * - total milliseconds + * @return formatted date/time String. ( YYYY.MM.DD HH:mm:SS ) + */ + public static String format(long pMillis) { + return formatWorker(pMillis, false); + } + + /** + * formatWithMillis + * + * @param pMillis + * - total milliseconds + * @return formatted date/time String. ( YYYY.MM.DD HH:mm:SS.sss ) + */ + public static String formatWithMillis(long pMillis) { + return formatWorker(pMillis, true); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/logging/TraceFormatter.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/logging/TraceFormatter.java similarity index 74% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/logging/TraceFormatter.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/logging/TraceFormatter.java index 5a7b49d..3fb3265 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/logging/TraceFormatter.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/logging/TraceFormatter.java @@ -1,95 +1,92 @@ -/* - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1565892 2006-11-15 lupusalex Make SBLIM client JSR48 compliant - * 1745282 2007-06-29 ebak Uniform time stamps for log files - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.logging; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.logging.Formatter; -import java.util.logging.LogRecord; - -/** - * Class TraceFormatter implements the formatting algorithm for our console log. - * - */ -public class TraceFormatter extends Formatter { - - private final String iLineSeparator = System.getProperty("line.separator"); - - /** - * Ctor. - */ - public TraceFormatter() { - super(); - } - - /* - * (non-Javadoc) - * - * @see java.util.logging.Formatter#format(java.util.logging.LogRecord) - */ - @Override - public String format(LogRecord pRecord) { - StringBuffer buffer = new StringBuffer(); - buffer.append(TimeStamp.format(pRecord.getMillis())); - buffer.append(" >"); - buffer.append(String.valueOf(pRecord.getThreadID())); - buffer.append("< "); - buffer.append(pRecord.getSourceMethodName()); - buffer.append(this.iLineSeparator); - buffer.append(pRecord.getLevel().getName()); - buffer.append(": "); - buffer.append(pRecord.getMessage()); - buffer.append(this.iLineSeparator); - if (pRecord.getThrown() != null) { - buffer.append("---> "); - StringWriter stringWriter = new StringWriter(); - PrintWriter printWriter = new PrintWriter(stringWriter); - pRecord.getThrown().printStackTrace(printWriter); - printWriter.close(); - buffer.append(stringWriter.toString()); - buffer.append(this.iLineSeparator); - } - return buffer.toString(); - } -} +/* + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1565892 2006-11-15 lupusalex Make SBLIM client JSR48 compliant + * 1745282 2007-06-29 ebak Uniform time stamps for log files + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.logging; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.logging.Formatter; +import java.util.logging.LogRecord; + +/** + * Class TraceFormatter implements the formatting algorithm for our console log. + * + */ +public class TraceFormatter extends Formatter { + private final String iLineSeparator = System.getProperty("line.separator"); + + /** + * Ctor. + */ + public TraceFormatter() { + super(); + } + + /* + * (non-Javadoc) + * + * @see java.util.logging.Formatter#format(java.util.logging.LogRecord) + */ + @Override + public String format(LogRecord pRecord) { + StringBuffer buffer = new StringBuffer(); + buffer.append(TimeStamp.format(pRecord.getMillis())); + buffer.append(" >"); + buffer.append(String.valueOf(pRecord.getThreadID())); + buffer.append("< "); + buffer.append(pRecord.getSourceMethodName()); + buffer.append(this.iLineSeparator); + buffer.append(pRecord.getLevel().getName()); + buffer.append(": "); + buffer.append(pRecord.getMessage()); + buffer.append(this.iLineSeparator); + if (pRecord.getThrown() != null) { + buffer.append("---> "); + StringWriter stringWriter = new StringWriter(); + PrintWriter printWriter = new PrintWriter(stringWriter); + pRecord.getThrown().printStackTrace(printWriter); + printWriter.close(); + buffer.append(stringWriter.toString()); + buffer.append(this.iLineSeparator); + } + return buffer.toString(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/logging/package.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/logging/package.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/logging/package.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/logging/package.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/package.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/package.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/package.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/package.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/pullparser/XMLPullParser.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/pullparser/XMLPullParser.java similarity index 76% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/pullparser/XMLPullParser.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/pullparser/XMLPullParser.java index 2bc3239..e9b0a16 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/pullparser/XMLPullParser.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/pullparser/XMLPullParser.java @@ -1,1272 +1,1329 @@ -/* - XMLPullParser.java - - (C) Copyright IBM Corp. 2005, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 18274 2005-09-12 fiuczy String values get corrupted by CIM client - * 1535756 2006-08-07 lupusalex Make code warning free - * 1663270 2007-02-19 ebak Minor performance problems - * 1708584 2007-04-27 ebak CloseableIterator might not clean up streams - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2714989 2009-03-26 blaschke-oss Code cleanup from redundant null check et al - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 3001359 2010-05-18 blaschke-oss XMLPullParser.CharString equals() method broken - * 3019252 2010-06-21 blaschke-oss Methods concatenate strings using + in a loop - * 3026316 2010-07-07 blaschke-oss XMLPullParser unused fields - * 3026417 2010-07-07 blaschke-oss XMLAttributeValue does not use iHash field - * 3028518 2010-07-14 blaschke-oss Additional StringBuilder use - * 3048749 2010-08-20 blaschke-oss Hex digit parsing logic error in XMLPullParser - * 3304058 2011-05-20 blaschke-oss Use same date format in change history - * 2639 2013-05-11 blaschke-oss CDATA parsing broken in PULL parser - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.pullparser; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.io.Reader; -import java.util.ArrayList; -import java.util.logging.Level; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.XMLDefaultHandlerImpl; -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; -import org.xml.sax.Attributes; - -/** - * Class XMLPullParser is responsible for XML parsing. - * - */ -public class XMLPullParser { - - /** - * Class XMLAttributes is an Attributes implementation. - */ - class XMLAttributes implements Attributes { - - public int getIndex(String qName) { - /* - * ebak: this is not good, since this Vector contains - * XMLAttributeValues return iAttributeNames.indexOf(qName); - */ - for (int i = 0; i < XMLPullParser.this.iAttributeNames.size(); i++) { - XMLAttributeValue xmlAttrValue = XMLPullParser.this.iAttributeNames.get(i); - if (qName.equals(xmlAttrValue.toString())) return i; - } - return -1; - } - - /** - * @param uri - * @param localName - * @return int getIndex - */ - public int getIndex(String uri, String localName) { - return 0; - } - - public int getLength() { - return XMLPullParser.this.iTotalAttributes; - } - - /** - * @param index - * @return String getLocalName - */ - public String getLocalName(int index) { - return EMPTY; - } - - public String getQName(int index) { - return XMLPullParser.this.iAttributeNames.get(index).getText(); - } - - /** - * @param index - * @return String getType - */ - public String getType(int index) { - return EMPTY; - } - - /** - * @param qName - * @return String getType - */ - public String getType(String qName) { - return EMPTY; - } - - /** - * @param uri - * @param localName - * @return String getType - */ - public String getType(String uri, String localName) { - return EMPTY; - } - - /** - * @param index - * @return String getURI - */ - public String getURI(int index) { - return EMPTY; - } - - public String getValue(int index) { - return XMLPullParser.this.iAttributeValues.get(index).getText(); - } - - public String getValue(String qName) { - /* - * ebak: the implementation have to return null if the attribute not - * found ebak: indexOf not good here, because iAttributeNames - * doesn't contain Strings - */ - int idx = getIndex(qName); - if (idx < 0) return null; - return getValue(idx); - } - - /** - * @param uri - * @param localName - * @return String getType - */ - public String getValue(String uri, String localName) { - return EMPTY; - } - } - - class XMLAttributeValue { - - int iCurrentPos; - - int iBegin, iLen; - - String iText; - - private boolean iTranslate; - - /** - * Ctor. - * - * @param begin - * @param len - * @param translate - */ - public XMLAttributeValue(int begin, int len, boolean translate) { - this.iBegin = begin; - this.iLen = len; - this.iTranslate = translate; - } - - /** - * Ctor. - * - * @param begin - * @param len - */ - public XMLAttributeValue(int begin, int len) { - this.iBegin = begin; - this.iLen = len; - this.iTranslate = true; - } - - /** - * getText - * - * @return String - */ - public String getText() { - if (this.iText == null) { - if (this.iTranslate) { - try { - // Integer hashKey = new Integer(hash); - // text = (String)stringTable.get(hashKey); - // text = null; - // if (text == null) { - this.iText = _getChars(); - // stringTable.put(hashKey, text); - // } else { - // // System.out.println("Found:"+text); - // cnt++; - // } - } catch (Exception e) { - LogAndTraceBroker.getBroker().trace(Level.WARNING, - "exception while decoding CHARACTERS XML", e); - this.iText = new String(XMLPullParser.this.iBufferChar, this.iBegin, - this.iLen); - } - } else { - // Integer hashKey = new Integer(hash); - // text = (String)stringTable.get(hashKey); - // text = null; - // if (text == null) { - this.iText = new String(XMLPullParser.this.iBufferChar, this.iBegin, this.iLen); - // stringTable.put(hashKey, text); - // } else { - // // System.out.println("Found:"+text); - // cnt++; - // } - } - } - return this.iText; - } - - // public void setTranslate(boolean translate) { - // this.translate = translate; - // } - - /** - * init - * - * @param begin - * @param len - */ - public void init(int begin, int len) { - this.iBegin = begin; - this.iLen = len; - this.iText = null; - } - - /** - * setTranslate - * - * @param translate - */ - public void setTranslate(boolean translate) { - this.iTranslate = translate; - } - - @Override - public String toString() { - return getText(); - } - - protected String _getChars() throws XMLPullParserException { - StringBuffer attributeValue = new StringBuffer(); - int last = this.iBegin + this.iLen; - char ch; - // char prevCh = '\0'; //18274 - for (this.iCurrentPos = this.iBegin; this.iCurrentPos < last; this.iCurrentPos++) { - ch = XMLPullParser.this.iBufferChar[this.iCurrentPos]; - if (ch == '&') { - // try { - // System.out.println(_currentPos); - int ref = parseReference(); - - if (ref > -1) attributeValue.append((char) ref); - // } - // catch (Exception e) { - // e.printStackTrace(); - // } - // } else if (ch == '\t' - // || ch == '\r' - // || ch == '\n') { - // - // if (ch != '\n' || prevCh != '\r'){ - // attributeValue.append(' '); - // } - } else { - attributeValue.append(ch); - } - // prevCh = ch; //18274 - } - return attributeValue.toString(); - } - - protected int parseReference() throws XMLPullParserException { - this.iCurrentPos++; - char ch1 = XMLPullParser.this.iBufferChar[this.iCurrentPos++]; - if (ch1 == '#') { - ch1 = XMLPullParser.this.iBufferChar[this.iCurrentPos++]; - if (ch1 == 'x') { - int value = 0; - do { - ch1 = XMLPullParser.this.iBufferChar[this.iCurrentPos++]; - if (ch1 >= '0' && ch1 <= '9') value = value * 16 + (ch1 - '0'); - else if (ch1 >= 'A' && ch1 <= 'F' || ch1 >= 'a' && ch1 <= 'f') value = value - * 16 + (Character.toUpperCase(ch1) - 'A' + 10); - else if (ch1 == ';') break; - else throw new XMLPullParserException( - "invalid character while parsing hex encoded number " + escape(ch1)); - } while (true); - this.iCurrentPos--; // 18274 - return (char) value; - } - int value = 0; - if (ch1 >= '0' && ch1 <= '9') { - do { - if (ch1 >= '0' && ch1 <= '9') { - value = value * 10 + (ch1 - '0'); - ch1 = XMLPullParser.this.iBufferChar[this.iCurrentPos++]; - } else if (ch1 == ';') break; - else throw new XMLPullParserException( - "invalid character while parsing decimal encoded number: " - + escape(ch1)); - } while (true); - this.iCurrentPos--; // 18274 - return (char) value; - } - throw new XMLPullParserException("invalid number format"); - } - int startPos = this.iCurrentPos - 1; - if (isValidStartElementNameChar(ch1)) { - do { - ch1 = XMLPullParser.this.iBufferChar[this.iCurrentPos++]; - if (ch1 == ';') break; - if (!isValidElementNameChar(ch1)) throw new XMLPullParserException( - "invalid reference character " + escape(ch1)); - } while (true); - } else { - throw new XMLPullParserException( - "expected valid name start character for value reference"); - } - this.iCurrentPos--; - ch1 = XMLPullParser.this.iBufferChar[startPos]; - char ch2 = XMLPullParser.this.iBufferChar[startPos + 1]; - char ch3 = XMLPullParser.this.iBufferChar[startPos + 2]; - - if (ch1 == 'l' && ch2 == 't' && ch3 == ';') { - return '<'; - } else if (ch1 == 'g' && ch2 == 't' && ch3 == ';') { - return '>'; - } else { - char ch4 = XMLPullParser.this.iBufferChar[startPos + 3]; - if (ch1 == 'a' && ch2 == 'm' && ch3 == 'p' && ch4 == ';') { return '&'; } - char ch5 = XMLPullParser.this.iBufferChar[startPos + 4]; - if (ch1 == 'a' && ch2 == 'p' && ch3 == 'o' && ch4 == 's' && ch5 == ';') { - return '\''; - } else if (ch1 == 'q' && ch2 == 'u' && ch3 == 'o' && ch4 == 't' && ch5 == ';') { - return '\"'; - } else { - // TODO return reference - } - } - return -1; - } - } - - /** - * ATTRIBUTE - */ - public static final int ATTRIBUTE = 10; - - /** - * CDATA - */ - public static final int CDATA = 12; - - /** - * CHARACTERS - */ - public static final int CHARACTERS = 4; - - /** - * COMMENT - */ - public static final int COMMENT = 5; - - /** - * DTD - */ - public static final int DTD = 11; - - /** - * EMPTY - */ - public static final String EMPTY = ""; - - /** - * END_DOCUMENT - */ - public static final int END_DOCUMENT = 8; - - /** - * END_ELEMENT - */ - public static final int END_ELEMENT = 2; - - /** - * ENTITY_DECLARATION - */ - public static final int ENTITY_DECLARATION = 15; - - /** - * ENTITY_REFERENCE - */ - public static final int ENTITY_REFERENCE = 9; - - /** - * NAMESPACE - */ - public static final int NAMESPACE = 13; - - /** - * NOTATION_DECLARATION - */ - public static final int NOTATION_DECLARATION = 14; - - /** - * PROCESSING_INSTRUCTION - */ - public static final int PROCESSING_INSTRUCTION = 3; - - /** - * SPACE - */ - public static final int SPACE = 6; - - /** - * START_DOCUMENT - */ - public static final int START_DOCUMENT = 7; - - /** - * START_ELEMENT - */ - public static final int START_ELEMENT = 1; - - /** - * main - * - * @param args - */ - public static void main(String[] args) { - // this did testing - } - - // TODO: ebak: this function seems to be wrong, because "synchronizes" to - // IRETURNVALUE - /** - * next - * - * @param reader - * @param parserHdlr - * @return boolean - * @throws Exception - */ - public static boolean next(XMLPullParser reader, XMLDefaultHandlerImpl parserHdlr) - throws Exception { - while (reader.hasNext()) { - int event = reader.next(); - switch (event) { - case START_ELEMENT: - parserHdlr.startElement(EMPTY, EMPTY, reader.getElementName(), reader - .getAttributes()); - break; - case END_ELEMENT: - parserHdlr.endElement(EMPTY, EMPTY, reader.getElementName()); - - String lastElementName = null; - if (reader.getElementNames().size() > 0) { - ArrayList elementNames = reader.getElementNames(); - lastElementName = elementNames.get(elementNames.size() - 1); - } - - if (lastElementName != null && lastElementName.equalsIgnoreCase("IRETURNVALUE")) { return true; } - break; - case CHARACTERS: - char[] buf = reader.getText().toCharArray(); - parserHdlr.characters(buf, 0, buf.length); - break; - case END_DOCUMENT: - return false; - } - } - return false; - } - - ArrayList iAttributeNames = new ArrayList(); - - Attributes iAttributes; - - ArrayList iAttributeValues = new ArrayList(); - - char[] iBufferChar = null; - - XMLAttributeValue iCharacters; - - boolean iClosingElementNamePending; - - int iColNumber = 1; - - int iCurrentPosition = 0; - - int iCurrentState = 0; - - String iElementName; - - ArrayList iElementNames = new ArrayList(); - - int iEndCharacters; - - int iFinishChar = 0; - - Reader iInstream; - - /* - * ebak: implement close - */ - boolean iClosed; - - int iLineNumber = 1; - - boolean iSeenEpilog; - - boolean iSeenProlog; - - int iStartCharacters; - - int iTotalAttributes; - - /** - * Ctor. - * - * @param in - */ - public XMLPullParser(Reader in) { - this.iInstream = in; - reset(); - } - - /** - * close - * - * @throws IOException - */ - public void close() throws IOException { - if (this.iClosed) return; - this.iClosed = true; - this.iInstream.close(); - } - - /** - * getAttributes - * - * @return Attributes - */ - public Attributes getAttributes() { - if (this.iCurrentState != START_ELEMENT) return null; - - if (this.iAttributes == null) { - this.iAttributes = new XMLAttributes(); - } - return this.iAttributes; - } - - /** - * getElementName - * - * @return String - */ - public String getElementName() { - return this.iElementName; - } - - /** - * getElementNames - * - * @return Vector - */ - public ArrayList getElementNames() { - return this.iElementNames; - } - - /** - * getLevel - * - * @return int - */ - public int getLevel() { - return this.iElementNames.size(); - } - - /** - * getText - * - * @return String - */ - public String getText() { - String result = null; - if (this.iCurrentState == CHARACTERS && this.iCharacters != null) { return this.iCharacters - .getText(); } - return result; - } - - /** - * hasNext - * - * @return boolean - */ - public boolean hasNext() { - return !this.iClosed && this.iCurrentState != END_DOCUMENT; - } - - /** - * next - * - * @return int - * @throws IOException - */ - public int next() throws IOException { - char ch; - resetAttributes(); - ensureCapacity(); - if (this.iClosingElementNamePending) { - this.iClosingElementNamePending = false; - this.iElementNames.remove(this.iElementNames.size() - 1); - this.iCurrentState = END_ELEMENT; - return this.iCurrentState; - } - do { - ch = (char) getNextCharCheckingEOF(); - if (ch == '<') { - ch = (char) getNextChar(); - if (ch == '?') { - if (this.iSeenProlog) { throw new XMLPullParserException( - "The processing instruction target matching \"[xX][mM][lL]\" is not allowed."); } - this.iSeenProlog = true; - parsePI(); - ch = (char) getNextChar(); - ch = skipOptionalSpaces(ch); - if (ch != '<') throw new XMLPullParserException(this, - "Content is not allowed in prolog."); - goBack(); - - this.iCurrentState = START_DOCUMENT; - return this.iCurrentState; - } else if (ch == '!') { - ch = (char) getNextChar(); - if (ch == '-') { - parseComment(); - - this.iCurrentState = COMMENT; - return this.iCurrentState; - } else if (ch == '[') { - parseCDATA(); - this.iCurrentState = CHARACTERS; - return this.iCurrentState; - } else throw new XMLPullParserException(this, "unexpected char " + escape(ch)); - } else if (ch == '/') { - parseEndElement(); - this.iCurrentState = END_ELEMENT; - return this.iCurrentState; - } else if (ch == '&') { - parseUnknown(); - } else if (isValidStartElementNameChar(ch)) { - if (!this.iSeenProlog) { - this.iSeenProlog = true; - this.iCurrentState = START_DOCUMENT; - goBack(); - goBack(); - return this.iCurrentState; - } - parseStartElement(ch); - this.iCurrentState = START_ELEMENT; - return this.iCurrentState; - } else { - throw new XMLPullParserException(this, "unexpected char " + escape(ch)); - } - } else { - this.iStartCharacters = this.iCurrentPosition - 1; - boolean amp = false; - // int hash = 0; - // int n = 0; - do { - // n = (n+1)&15; - // hash = hash*primes[n]+ch; - - ch = (char) getNextCharCheckingEOF(); - if (ch == (char) -1) { - if (this.iElementNames.size() != 0) throw new XMLPullParserException(this, - "unexpected EOF "); - - this.iCurrentState = END_DOCUMENT; - return this.iCurrentState; - } else if (ch == '\r' || ch == '\n') { /* :) */} else { - if (!isSpace(ch) && ch != '<' && this.iElementNames.size() == 0) { - if (!this.iSeenProlog) throw new XMLPullParserException(this, - "Content is not allowed in trailing section."); - throw new XMLPullParserException(this, - "Content is not allowed in trailing section."); - } - } - amp = false; - if (ch == '&') { - amp = true; - int i = parseReference(); - ch = (char) (i & 0xFFFF); - } - } while (ch != '<' || amp); - this.iEndCharacters = this.iCurrentPosition; - goBack(); - if (this.iElementNames.size() > 0) { - if (this.iCharacters == null) this.iCharacters = new XMLAttributeValue( - this.iStartCharacters, this.iEndCharacters - this.iStartCharacters - 1); - else { - this.iCharacters.init(this.iStartCharacters, this.iEndCharacters - - this.iStartCharacters - 1); - this.iCharacters.setTranslate(true); - } - - this.iCurrentState = CHARACTERS; - return this.iCurrentState; - } - } - } while (true); - } - - /** - * reset - */ - public void reset() { - this.iSeenProlog = true; - this.iCurrentState = 0; - this.iClosingElementNamePending = false; - this.iColNumber = 1; - this.iLineNumber = 1; - this.iElementName = null; - this.iElementNames.clear(); - this.iAttributeNames.clear(); - this.iAttributeValues.clear(); - this.iAttributes = null; - - this.iStartCharacters = 0; - this.iEndCharacters = 0; - - this.iTotalAttributes = 0; - this.iSeenProlog = false; - this.iSeenEpilog = false; - } - - @Override - public String toString() { - switch (this.iCurrentState) { - case START_ELEMENT: { - StringBuilder sb = new StringBuilder("START ELEM: <"); - sb.append(this.iElementName); - if (this.iAttributeNames.size() > 0) { - sb.append(" "); - for (int i = 0; i < this.iAttributeNames.size(); i++) { - sb.append(this.iAttributeNames.get(i)); - sb.append("=\""); - sb.append(this.iAttributeValues.get(i)); - sb.append("\" "); - } - } - sb.append(">"); - return sb.toString(); - } - case END_ELEMENT: { - String s = "END ELEM: "; - return s; - } - case CHARACTERS: { - return "CHARACTERS: \"" + getText(); // .replaceAll("\n", - // "\\\\n").replaceAll("\r", - // "\\\\r").replaceAll("\t", - // "\\\\t")+"\""; - } - } - return "UNKOWN"; - } - - protected char _getNextChar() { - return (char) -1; - } - - protected void addAttribute(int begName, int lenName, int begValue, int lenValue) { - if (this.iAttributeNames.size() > this.iTotalAttributes) { - XMLAttributeValue attribute = this.iAttributeValues.get(this.iTotalAttributes); - XMLAttributeValue name = this.iAttributeNames.get(this.iTotalAttributes); - this.iTotalAttributes++; - attribute.init(begValue, lenValue); - attribute.setTranslate(true); - name.init(begName, lenName); - name.setTranslate(false); - } else { - XMLAttributeValue attribute = new XMLAttributeValue(begValue, lenValue); - XMLAttributeValue name = new XMLAttributeValue(begName, lenName, false); - this.iTotalAttributes++; - this.iAttributeNames.add(name); - this.iAttributeValues.add(attribute); - } - } - - protected void ensureCapacity() { - if (this.iBufferChar == null) this.iBufferChar = new char[1024]; - - if (this.iCurrentPosition >= (8 * this.iBufferChar.length) / 10) { - System.arraycopy(this.iBufferChar, this.iCurrentPosition, this.iBufferChar, 0, - this.iFinishChar - this.iCurrentPosition); - this.iFinishChar -= this.iCurrentPosition; - this.iCurrentPosition = 0; - } - } - - protected String escape(char ch) { - String result; - if (ch == '\n') result = "\'\\n\'"; - if (ch == '\r') result = "\'\\r\'"; - if (ch == '\t') result = "\'\\t\'"; - if (ch == '\'') result = "\'\\'\'"; - if (ch > '\177' || ch < ' ') result = "\'\\u" + Integer.toHexString(ch) + "\'"; - else result = "\'" + ch + "\'"; - return result; - } - - protected int getChar() throws IOException { - if (this.iFinishChar <= this.iCurrentPosition) { - if (this.iBufferChar == null) { - this.iBufferChar = new char[1024]; - } else if (this.iFinishChar >= this.iBufferChar.length) { - char[] tmp = this.iBufferChar; - this.iBufferChar = new char[this.iBufferChar.length << 1]; - System.arraycopy(tmp, 0, this.iBufferChar, 0, tmp.length); - } - - int total = this.iInstream.read(this.iBufferChar, this.iFinishChar, - this.iBufferChar.length - this.iFinishChar); - - if (total <= 0) { return -1; } - this.iFinishChar += total; - } - return this.iBufferChar[this.iCurrentPosition++]; - } - - protected int getNextChar() throws IOException { - int ch; - - if (this.iFinishChar <= this.iCurrentPosition) { - ch = getChar(); - } else ch = this.iBufferChar[this.iCurrentPosition++]; - - if (ch == -1) throw new XMLPullParserException(this, "unexpected end of document"); - if (ch == '\n') { - this.iLineNumber++; - this.iColNumber = 1; - } else this.iColNumber++; - - return (char) ch; - } - - protected int getNextCharCheckingEOF() throws IOException { - int ch; - - if (this.iFinishChar <= this.iCurrentPosition) { - ch = getChar(); - } else ch = this.iBufferChar[this.iCurrentPosition++]; - - if (ch == '\n') { - this.iLineNumber++; - this.iColNumber = 1; - } else this.iColNumber++; - - return (char) ch; - } - - protected void goBack() { - this.iCurrentPosition--; - if (this.iColNumber > 1) { - this.iColNumber--; - } - } - - protected boolean isSpace(char ch) { - return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t'; - } - - protected boolean isValidElementNameChar(char ch) { - return (ch < 256 && (ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z' || ch == '_' - || ch == ':' || ch == '-' || ch == '.' || ch >= '0' && ch <= '9' || ch == '\267')) - || ch >= '\300' - && ch <= '\u02FF' - || ch >= '\u0370' - && ch <= '\u037D' - || ch >= '\u0300' - && ch <= '\u036F' - || ch >= '\u037F' - && ch <= '\u2027' - || ch >= '\u202A' && ch <= '\u218F' || ch >= '\u2800' && ch <= '\uFFEF'; - // return isValidStartElementNameChar(ch) - // || (ch < 256 && (ch == '-' - // || ch == '.' - // || ch >= '0' && ch <= '9' - // || ch == '\267')) - // || ch >= '\u0300' && ch <= '\u036F' - // || ch >= '\u0400' && ch <= '\u2027' - // || ch >= '\u202A' && ch <= '\u218F' - // || ch >= '\u2800' && ch <= '\uFFEF'; - } - - protected boolean isValidStartElementNameChar(char ch) { - return (ch < 256 && (ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z' || ch == '_' || ch == ':')) - || (ch >= '\300' && ch <= '\u02FF' || ch >= '\u0370' && ch <= '\u037D' - || ch >= '\u037F' && ch <= '\u0400' || ch >= '\u0400' && ch <= '\u2027' - || ch >= '\u202A' && ch <= '\u218F' || ch >= '\u2800' && ch <= '\uFFEF'); - } - - protected void parseAttribute(char ch) throws IOException { - int startAttributeName = this.iCurrentPosition - 1; - int endAttributeName; - // int hash = 0; - // int n = 0; - do { - // n = (n+1)&15; - // hash = hash*primes[n]+ch; - - ch = (char) getNextChar(); - } while (isValidElementNameChar(ch)); - endAttributeName = this.iCurrentPosition; - // String attributeName = new String(bufferChar, startAttributeName, - // endAttributeName - startAttributeName-1); - // attributeNames.add(attributeName); - - ch = skipOptionalSpaces(ch); - - if (ch != '=') throw new XMLPullParserException(this, "missing character \'=\'instead " - + escape(ch) + " was found "); - - ch = (char) getNextChar(); - ch = skipOptionalSpaces(ch); - - char delimiter; - if (ch != '\"' && ch != '\'') throw new XMLPullParserException(this, - "missing character \'\"\' or \'\'\' instead " + escape(ch) + " was found "); - delimiter = ch; - - // StringBuffer attributeValue = new StringBuffer(); - int startAttributeValue = this.iCurrentPosition; - char prevCh = '\0'; - // int hashvalue = 0; - // n = 0; - do { - // n = (n+1)&15; - // hashvalue = hashvalue *primes[n] +ch; - - ch = (char) getNextChar(); - if (ch == delimiter) break; - else if (ch == '<' || ch == '>') throw new XMLPullParserException(this, - "illegal character " + escape(ch)); - else if (ch == '&') { - int ref = parseReference(); - ch = (char) (ref & 0xffff); - // attributeValue.append((char)ref); - } else if (ch == '\t' || ch == '\r' || ch == '\n') { - - if (ch != '\n' || prevCh != '\r') { - // attributeValue.append(' '); - } - } else { - // attributeValue.append(ch); - } - prevCh = ch; - } while (true); - int endAttributeValue = this.iCurrentPosition; - // attributeValues.add(attributeValue.toString()); - addAttribute(startAttributeName, endAttributeName - startAttributeName - 1, - startAttributeValue, endAttributeValue - startAttributeValue - 1); - - return; - } - - protected int parseCDATA() throws IOException { - char ch; - - if ((char) getNextChar() != 'C' || (char) getNextChar() != 'D' - || (char) getNextChar() != 'A' || (char) getNextChar() != 'T' - || (char) getNextChar() != 'A' || (char) getNextChar() != '[') throw new XMLPullParserException( - "CDATA must start with \"' && doubleBraket) { - break; - } else { - braketFound = false; - doubleBraket = false; - } - if (ch == (char) -1) throw new XMLPullParserException( - "XML document structures must start and end within the same entity."); - } while (true); - - int endCharacter = this.iCurrentPosition - 3; - - this.iCharacters.setTranslate(false); - this.iCharacters.init(startCharacter, endCharacter - startCharacter); - - return -1; - } - - protected int parseComment() throws IOException { - char ch; - ch = (char) getNextChar(); - if (ch != '-') throw new XMLPullParserException("Comment must start with \"\n"); - if (this.iConfiguration.isCimXmlTracingEnabled() && debugStream != null) debugStream - .write(resultStr.toString().getBytes()); - if (LogAndTraceBroker.getBroker().isLoggableCIMXMLTrace(Level.FINEST)) logger - .traceCIMXML(Level.FINEST, resultStr.toString(), false); - } - } - } while (retries-- > 0); - - // Benchmark.stopTransportTimer(); - - // Look for CIM error and description, include in exception if exists - String errorCIM = connection.getHeaderField("CIMError"); - String errorDescriptionCIM = null; - if (errorCIM != null) { - logger.trace(Level.FINER, "Found CIMError field with value \"" + errorCIM + "\""); - - errorDescriptionCIM = connection.getHeaderField("CIMErrorDescription"); - if (errorDescriptionCIM != null) { - try { - errorDescriptionCIM = URLDecoder.decode(errorDescriptionCIM, "UTF-8"); - } catch (Exception e) { - errorDescriptionCIM = null; - } - logger.trace(Level.FINER, "Found CIMErrorDescription field with value \"" - + errorDescriptionCIM + "\""); - } - } - - // Look for OpenPegasus error details, decode and include in exception - // if it exists - String errorOP = connection.getHeaderField("PGErrorDetail"); - if (errorOP != null) { - try { - errorOP = URLDecoder.decode(errorOP, "UTF-8"); - } catch (Exception e) { - errorOP = null; - } - logger.trace(Level.FINER, "Found PGErrorDetail field with value \"" + errorOP + "\""); - } - - // Look for SFCB error details, decode and include in exception - // if it exists - String errorSFCB = connection.getHeaderField("SFCBErrorDetail"); - if (errorSFCB != null) { - try { - errorSFCB = URLDecoder.decode(errorSFCB, "UTF-8"); - } catch (Exception e) { - errorSFCB = null; - } - logger.trace(Level.FINER, "Found SFCBErrorDetail field with value \"" + errorSFCB - + "\""); - } - - // If CIMErrorDescription present, format of WBEMException is: - // - // HTTP StatusCode - ReasonPhrase (CIMError: "ErrorString", - // CIMErrorDescription: "ErrorString") - // - // Otherwise, format of WBEMException message is: - // - // HTTP StatusCode - ReasonPhrase (CIMError: "ErrorString", OpenPegasus - // Error: "ErrorString", SFCB Error: "ErrorString") - // - // For example: - // HTTP 503 - Service Unavailable (SFCB Error: - // "Max Session Limit Exceeded") - StringBuffer errorMsg = new StringBuffer("HTTP "); - errorMsg.append(connection.getResponseCode()); - errorMsg.append(" - "); - errorMsg.append(connection.getResponseMessage()); - if (errorCIM != null && errorDescriptionCIM != null) { - errorMsg.append(" (CIMError: \""); - errorMsg.append(errorCIM); - errorMsg.append("\", CIMErrorDescription: \""); - errorMsg.append(errorDescriptionCIM); - errorMsg.append("\")"); - } else if (errorCIM != null || errorOP != null || errorSFCB != null) { - errorMsg.append(" ("); - if (errorCIM != null) { - errorMsg.append("CIMError: \""); - errorMsg.append(errorCIM); - errorMsg.append('"'); - } - if (errorOP != null) { - if (errorCIM != null) errorMsg.append(", "); - errorMsg.append("OpenPegasus Error: \""); - errorMsg.append(errorOP); - errorMsg.append('"'); - } - if (errorSFCB != null) { - if (errorCIM != null || errorOP != null) errorMsg.append(", "); - errorMsg.append("SFCB Error: \""); - errorMsg.append(errorSFCB); - errorMsg.append('"'); - } - errorMsg.append(')'); - } - - connection.disconnect(); - - throw new WBEMException(exceptionNum, errorMsg.toString()); - } - - private HttpUrlConnection newConnection(boolean pIsIndication, URI pRecipient, - HttpClientPool pClientPool, String pCimMethod, HttpHeader pHeader, boolean pUseMPost) { - - final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - - HttpUrlConnection connection = new HttpUrlConnection(pRecipient, pClientPool, - this.iAuthorizationHandler); - if (pUseMPost) { - connection.setRequestMethod(WBEMConstants.HTTP_MPOST); - } else connection.setRequestMethod(WBEMConstants.HTTP_POST); - connection.useHttp11("1.1".equals(this.iConfiguration.getHttpVersion())); - - String firstLocaleStr = this.iLocales[0].getLanguage(); - if (this.iLocales[0].getCountry().length() > 0) firstLocaleStr = firstLocaleStr + '-' - + this.iLocales[0].getCountry(); - StringBuilder restLocaleStrBld = new StringBuilder(""); - for (int i = 1; i < this.iLocales.length; i++) { - if (this.iLocales[i] != null && this.iLocales[i].getLanguage().length() > 0) { - restLocaleStrBld.append(", "); - restLocaleStrBld.append(this.iLocales[i].getLanguage()); - if (this.iLocales[i].getCountry().length() > 0) { - restLocaleStrBld.append('-'); - restLocaleStrBld.append(this.iLocales[i].getCountry()); - } - } - } - - connection.setDoOutput(true); - connection.setDoInput(true); - connection.setRequestProperty("Content-type", "application/xml; charset=\"utf-8\""); - connection.setRequestProperty("Accept", "text/html, text/xml, application/xml"); - connection.setRequestProperty("Cache-Control", "no-cache"); - connection.setRequestProperty("Content-Language", firstLocaleStr); - connection.setRequestProperty("Accept-Language", firstLocaleStr - + restLocaleStrBld.toString() + ", *"); - if (this.iAuthorization != null) connection.setRequestProperty("Authorization", - this.iAuthorization); - - String prefix = ""; - if (connection.getRequestMethod().equalsIgnoreCase(WBEMConstants.HTTP_MPOST)) { - String ns = getNextNs(); - connection.setRequestProperty("Man", "http://www.dmtf.org/cim/mapping/http/v1.0;ns=" - + ns); - prefix = ns + "-"; - } - connection.setRequestProperty(prefix + "CIMProtocolVersion", "1.0"); - - if (pIsIndication) { - try { - connection.setRequestProperty("CIMExport", HttpHeader.encode("MethodRequest", - "UTF-8", "US-ASCII")); - connection.setRequestProperty("CIMExportMethod", HttpHeader.encode( - "ExportIndication", "UTF-8", "US-ASCII")); - } catch (UnsupportedEncodingException e) { - logger.trace(Level.FINE, "Exception while encoding http header", e); - connection.setRequestProperty("CIMExport", "MethodRequest"); - connection.setRequestProperty("CIMExportMethod", "ExportIndication"); - } - } else { - connection.setRequestProperty(prefix + "CIMOperation", "MethodCall"); - try { - connection.setRequestProperty(prefix + "CIMMethod", HttpHeader.encode(pCimMethod, - "UTF-8", "US-ASCII")); - } catch (UnsupportedEncodingException e) { - logger.trace(Level.FINE, "Exception while encoding http header", e); - connection.setRequestProperty(prefix + "CIMMethod", pCimMethod); - } - } - Iterator> iter = pHeader.iterator(); - while (iter.hasNext()) { - Entry entry = iter.next(); - connection.setRequestProperty(prefix + entry.getKey().toString(), entry.getValue() - .toString()); - } - - logger.exit(); - return connection; - } - - private String getNextNs() { - this.iNsCounter = (this.iNsCounter < 99) ? ++this.iNsCounter : 10; - return String.valueOf(this.iNsCounter); - } - - private HttpHeader parseHeaders(URLConnection pConnection) { - String man = pConnection.getHeaderField("Man"); - String opt = pConnection.getHeaderField("Opt"); - HttpHeader headers = new HttpHeader(); - int i; - String ns = null; - - HttpHeaderParser manOptHeader = null; - if (man != null && man.length() > 0) manOptHeader = new HttpHeaderParser(man); - else if (opt != null && opt.length() > 0) manOptHeader = new HttpHeaderParser(opt); - if (manOptHeader != null) ns = manOptHeader.getValue("ns"); - - if (ns != null) { - i = 0; - String key; - while ((key = pConnection.getHeaderFieldKey(++i)) != null) { - if (key.startsWith(ns + "-")) headers.addParsedField(key.substring(3), pConnection - .getHeaderField(i)); - else headers.addParsedField(key, pConnection.getHeaderField(i)); - } - } else { - i = 0; - String key; - while ((key = pConnection.getHeaderFieldKey(++i)) != null) { - headers.addParsedField(key, pConnection.getHeaderField(i)); - } - } - - return headers; - } - - private String getCharacterSet(HttpHeader pHeader) { - String contentType = pHeader.getField("Content-type"); - String charset = "UTF-8"; - if (contentType != null && contentType.length() > 0) { - HttpHeaderParser contentTypeHeader = new HttpHeaderParser(contentType); - charset = contentTypeHeader.getValue("charset", charset); - } - return charset; - } - - /** - * getIterator : get generic CloseableIterator - * - * @param - * : Type Parameter - * @param pStream - * : Input Stream Reader - * @param pPath - * : CIMObjectPath - * @return generic CloseableIterator - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws WBEMException - */ - - // :TODO : try to find solution of "unchecked" warning - @SuppressWarnings("unchecked") - private CloseableIterator getIterator(InputStreamReader pStream, CIMObjectPath pPath) - throws IOException, SAXException, ParserConfigurationException, WBEMException { - - String parser = this.iConfiguration.getCimXmlParser(); - - CloseableIterator iter = null; - - if (WBEMConstants.SAX.equals(parser)) { - iter = new CloseableIteratorSAX(pStream, pPath); - } else if (WBEMConstants.PULL.equals(parser)) { - iter = new CloseableIteratorPULL(pStream, pPath); - } else if (WBEMConstants.DOM.equals(parser)) { - iter = new CloseableIteratorDOM(pStream, pPath); - } else { - throw new IllegalArgumentException("Invalid CIM-XML parser configured (\"" + parser - + "\") "); - } - try { - // check for CIMExceptions - iter.hasNext(); - return (CloseableIterator) iter; - } catch (RuntimeException e) { - iter.close(); - if (e.getCause() != null && e.getCause() instanceof WBEMException) { throw (WBEMException) e - .getCause(); } - throw e; - } - } - - private EnumerateResponse getEnumerateResponse(InputStreamReader pStream, - CIMObjectPath pPath) throws IOException, SAXException, ParserConfigurationException, - WBEMException { - - String parser = this.iConfiguration.getCimXmlParser(); - - if (WBEMConstants.SAX.equals(parser)) return new EnumerateResponseSAX(pStream, pPath) - .getEnumResponse(); - else if (WBEMConstants.PULL.equals(parser)) return new EnumerateResponsePULL(pStream, - pPath).getEnumResponse(); - else if (WBEMConstants.DOM.equals(parser)) return new EnumerateResponseDOM(pStream, - pPath).getEnumResponse(); - - throw new IllegalArgumentException("Invalid CIM-XML parser configured (\"" + parser - + "\") "); - } - - private CIMResponse getSingleResponse(InputStreamReader pStream, CIMObjectPath pLocalPath) - throws WBEMException { - final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - Document dom; - try { - // Using factory get an instance of document builder - DocumentBuilder db = dbf.newDocumentBuilder(); - // parse using builder to get DOM representation of the XML file - dom = db.parse(new InputSource(pStream)); - } catch (TrailerException e) { - throw e.getWBEMException(); - } catch (Exception e) { - String msg = "Exception occurred during DOM parsing!"; - logger.trace(Level.SEVERE, msg, e); - throw new WBEMException(WBEMException.CIM_ERR_FAILED, msg, null, e); - } - CIMXMLParserImpl.setLocalObjectPath(pLocalPath); - CIMMessage cimMsg; - try { - cimMsg = CIMXMLParserImpl.parseCIM(dom.getDocumentElement()); - } catch (CIMXMLParseException e) { - String msg = "Exception occurred during parseCIM!"; - logger.trace(Level.SEVERE, msg, e); - throw new WBEMException(WBEMException.CIM_ERR_FAILED, msg, null, e); - } - if (!(cimMsg instanceof CIMResponse)) { - String msg = "CIM message must be response!"; - logger.trace(Level.SEVERE, msg); - throw new WBEMException(msg); - } - return (CIMResponse) cimMsg; - } - - public Properties getLocalProperties() { - return this.iConfiguration.getLocalProperties(); - } - - public void setLocalProperties(Properties pProperties) { - this.iConfiguration.setLocalProperties(pProperties); - } - - public void setLocalProperty(String pKey, String pValue) { - this.iConfiguration.setLocalProperty(pKey, pValue); - } - - private synchronized void checkState() throws IllegalStateException { - if (this.iInitialized && !this.iClosed) return; - String state = this.iClosed ? "closed." : "not initialized."; - LogAndTraceBroker.getBroker().trace(Level.FINE, "Illegal state for operation: " + state); - throw new IllegalStateException("WBEMClient is " + state); - } - - public EnumerateResponse associatorPaths(CIMObjectPath pObjectName, - String pAssociationClass, String pResultClass, String pRole, String pResultRole, - String pFilterQueryLanguage, String pFilterQuery, UnsignedInteger32 pTimeout, - boolean pContinueOnError, UnsignedInteger32 pMaxObjects) throws WBEMException { - - final String operation = "OpenAssociatorInstancePaths"; - final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - - checkState(); - - try { - if (pObjectName == null || pObjectName.getNamespace() == null - || pObjectName.getObjectName() == null) { throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); } - - HttpHeader hh = new HttpHeader(); - hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", - "US-ASCII")); - - Document doc = this.iXmlHelper.newDocument(); - - this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper - .OpenAssociatorInstancePaths_request(doc, pObjectName, pAssociationClass, - pResultClass, pRole, pResultRole, pFilterQueryLanguage, pFilterQuery, - pTimeout, pContinueOnError, pMaxObjects)); - - InputStreamReader is = transmitRequest(operation, hh, doc); - - EnumerateResponse enumResp = getEnumerateResponse(is, pObjectName); - return enumResp; - - } catch (WBEMException e) { - logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); - throw e; - } catch (Exception e) { - if (e.getCause() != null && e.getCause() instanceof WBEMException) { - logger - .trace(Level.FINE, operation + " request resulted in CIM Error", e - .getCause()); - throw (WBEMException) e.getCause(); - } - logger.trace(Level.FINE, operation + " request failed", e); - throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); - } finally { - logger.exit(); - } - } - - public EnumerateResponse associators(CIMObjectPath pObjectName, - String pAssocClass, String pResultClass, String pRole, String pResultRole, - boolean pIncludeClassOrigin, String[] pPropertyList, String pFilterQueryLanguage, - String pFilterQuery, UnsignedInteger32 pTimeout, boolean pContinueOnError, - UnsignedInteger32 pMaxObjects) throws WBEMException { - - final String operation = "OpenAssociatorInstances"; - final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - - checkState(); - - try { - if (pObjectName == null || pObjectName.getNamespace() == null - || pObjectName.getObjectName() == null) { throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); } - - HttpHeader hh = new HttpHeader(); - hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", - "US-ASCII")); - - Document doc = this.iXmlHelper.newDocument(); - - this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.OpenAssociatorInstances_request( - doc, pObjectName, pAssocClass, pResultClass, pRole, pResultRole, - pIncludeClassOrigin, pPropertyList, pFilterQueryLanguage, pFilterQuery, - pTimeout, pContinueOnError, pMaxObjects)); - - InputStreamReader is = transmitRequest(operation, hh, doc); - - EnumerateResponse enumResp = getEnumerateResponse(is, pObjectName); - return enumResp; - - } catch (WBEMException e) { - logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); - throw e; - } catch (Exception e) { - if (e.getCause() != null && e.getCause() instanceof WBEMException) { - logger - .trace(Level.FINE, operation + " request resulted in CIM Error", e - .getCause()); - throw (WBEMException) e.getCause(); - } - logger.trace(Level.FINE, operation + " request failed", e); - throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); - } finally { - logger.exit(); - } - } - - public void closeEnumeration(CIMObjectPath pObjectName, String pEnumerationContext) - throws WBEMException { - - final String operation = "CloseEnumeration"; - final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - - checkState(); - - try { - if (pObjectName == null || pObjectName.getNamespace() == null - || pObjectName.getObjectName() == null) { throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); } - - HttpHeader hh = new HttpHeader(); - hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", - "US-ASCII")); - - Document doc = this.iXmlHelper.newDocument(); - - this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.CloseEnumeration_request(doc, - pObjectName, pEnumerationContext)); - - InputStreamReader is = transmitRequest(operation, hh, doc); - - CloseableIterator iter = getIterator(is, pObjectName); - - // Check for exceptions - try { - iter.hasNext(); - } finally { - iter.close(); - } - } catch (WBEMException e) { - logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); - throw e; - } catch (Exception e) { - if (e.getCause() != null && e.getCause() instanceof WBEMException) { - logger - .trace(Level.FINE, operation + " request resulted in CIM Error", e - .getCause()); - throw (WBEMException) e.getCause(); - } - logger.trace(Level.FINE, operation + " request failed", e); - throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); - } finally { - logger.exit(); - } - - } - - public EnumerateResponse enumerateInstancePaths(CIMObjectPath pObjectName, - String pFilterQueryLanguage, String pFilterQuery, UnsignedInteger32 pTimeout, - boolean pContinueOnError, UnsignedInteger32 pMaxObjects) throws WBEMException { - - final String operation = "OpenEnumerateInstancePaths"; - final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - - checkState(); - - try { - if (pObjectName == null || pObjectName.getNamespace() == null - || pObjectName.getObjectName() == null) { throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); } - - HttpHeader hh = new HttpHeader(); - hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", - "US-ASCII")); - - Document doc = this.iXmlHelper.newDocument(); - - this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper - .OpenEnumerateInstancePaths_request(doc, pObjectName, pFilterQueryLanguage, - pFilterQuery, pTimeout, pContinueOnError, pMaxObjects)); - - InputStreamReader is = transmitRequest(operation, hh, doc); - - EnumerateResponse enumResp = getEnumerateResponse(is, pObjectName); - return enumResp; - - } catch (WBEMException e) { - logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); - throw e; - } catch (Exception e) { - if (e.getCause() != null && e.getCause() instanceof WBEMException) { - logger - .trace(Level.FINE, operation + " request resulted in CIM Error", e - .getCause()); - throw (WBEMException) e.getCause(); - } - logger.trace(Level.FINE, operation + " request failed", e); - throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); - } finally { - logger.exit(); - } - } - - public EnumerateResponse enumerateInstances(CIMObjectPath pObjectName, - boolean pDeepInheritance, boolean pIncludeClassOrigin, String[] pPropertyList, - String pFilterQueryLanguage, String pFilterQuery, UnsignedInteger32 pTimeout, - boolean pContinueOnError, UnsignedInteger32 pMaxObjects) throws WBEMException { - - final String operation = "OpenEnumerateInstances"; - final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - - checkState(); - - try { - if (pObjectName == null || pObjectName.getNamespace() == null - || pObjectName.getObjectName() == null) { throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); } - - HttpHeader hh = new HttpHeader(); - hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", - "US-ASCII")); - - Document doc = this.iXmlHelper.newDocument(); - - this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.OpenEnumerateInstances_request( - doc, pObjectName, pDeepInheritance, pIncludeClassOrigin, pPropertyList, - pFilterQueryLanguage, pFilterQuery, pTimeout, pContinueOnError, pMaxObjects)); - - InputStreamReader is = transmitRequest(operation, hh, doc); - EnumerateResponse enumResp = getEnumerateResponse(is, pObjectName); - return enumResp; - - } catch (WBEMException e) { - logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); - throw e; - } catch (Exception e) { - if (e.getCause() != null && e.getCause() instanceof WBEMException) { - logger - .trace(Level.FINE, operation + " request resulted in CIM Error", e - .getCause()); - throw (WBEMException) e.getCause(); - } - logger.trace(Level.FINE, operation + " request failed", e); - throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); - } finally { - logger.exit(); - } - } - - // not supported yet - public UnsignedInteger64 enumerationCount(CIMObjectPath pObjectName, String pEnumerationContext) - throws WBEMException { - final String operation = "EnumerationCount"; - final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - - checkState(); - - try { - if (pObjectName == null || pObjectName.getNamespace() == null - || pObjectName.getObjectName() == null) { throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); } - - HttpHeader hh = new HttpHeader(); - hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", - "US-ASCII")); - - Document doc = this.iXmlHelper.newDocument(); - - this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.EnumerationCount_request(doc, - pObjectName, pEnumerationContext)); - - InputStreamReader is = transmitRequest(operation, hh, doc); - // Currently this is not supported by server. Server returns - // error : "CIM_ERR_NOT_SUPPORTED" - // This error is caught by parser and exception is thrown - - getEnumerateResponse(is, pObjectName); - // Error mentioned above will go away if server starts to support - // EnumerationCount, we need to update code i.e. remove exception - // and return UnsignedInteger64 - - // this exception will be thrown only if server starts to support - // enumerationCount - throw new WBEMException(operation + " is currently not supported by client"); - - } catch (WBEMException e) { - logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); - throw e; - } catch (Exception e) { - if (e.getCause() != null && e.getCause() instanceof WBEMException) { - logger - .trace(Level.FINE, operation + " request resulted in CIM Error", e - .getCause()); - throw (WBEMException) e.getCause(); - } - logger.trace(Level.FINE, operation + " request failed", e); - throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); - } finally { - logger.exit(); - } - } - - public EnumerateResponse execQueryInstances(CIMObjectPath pObjectName, - String pFilterQuery, String pFilterQueryLanguage, boolean pReturnQueryResultClass, - UnsignedInteger32 pTimeout, boolean pContinueOnError, UnsignedInteger32 pMaxObjects, - CIMClass pQueryResultClass) throws WBEMException { - - final String operation = "OpenQueryInstances"; - final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - - checkState(); - - try { - if (pObjectName == null || pObjectName.getNamespace() == null - || pObjectName.getObjectName() == null) { throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); } - - HttpHeader hh = new HttpHeader(); - hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", - "US-ASCII")); - - Document doc = this.iXmlHelper.newDocument(); - - this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.OpenQueryInstances_request(doc, - pObjectName, pFilterQuery, pFilterQueryLanguage, pReturnQueryResultClass, - pTimeout, pContinueOnError, pMaxObjects, pQueryResultClass)); - - InputStreamReader is = transmitRequest(operation, hh, doc); - EnumerateResponse enumResp = getEnumerateResponse(is, pObjectName); - return enumResp; - - } catch (WBEMException e) { - logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); - throw e; - } catch (Exception e) { - if (e.getCause() != null && e.getCause() instanceof WBEMException) { - logger - .trace(Level.FINE, operation + " request resulted in CIM Error", e - .getCause()); - throw (WBEMException) e.getCause(); - } - logger.trace(Level.FINE, operation + " request failed", e); - throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); - } finally { - logger.exit(); - } - } - - public EnumerateResponse getInstancePaths(CIMObjectPath pObjectName, - String pContext, UnsignedInteger32 pMaxObjects) throws WBEMException { - - final String operation = "PullInstancePaths"; - final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - - checkState(); - - try { - if (pObjectName == null || pObjectName.getNamespace() == null - || pObjectName.getObjectName() == null) { throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); } - - HttpHeader hh = new HttpHeader(); - hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", - "US-ASCII")); - - Document doc = this.iXmlHelper.newDocument(); - - this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.PullInstancePaths_request(doc, - pObjectName, pContext, pMaxObjects)); - - InputStreamReader is = transmitRequest(operation, hh, doc); - EnumerateResponse enumResp = getEnumerateResponse(is, pObjectName); - return enumResp; - - } catch (WBEMException e) { - logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); - throw e; - } catch (Exception e) { - if (e.getCause() != null && e.getCause() instanceof WBEMException) { - logger - .trace(Level.FINE, operation + " request resulted in CIM Error", e - .getCause()); - throw (WBEMException) e.getCause(); - } - logger.trace(Level.FINE, operation + " request failed", e); - throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); - } finally { - logger.exit(); - } - } - - public EnumerateResponse getInstances(CIMObjectPath pObjectName, String pContext, - UnsignedInteger32 pMaxObjects) throws WBEMException { - - final String operation = "PullInstances"; - final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - - checkState(); - - try { - if (pObjectName == null || pObjectName.getNamespace() == null - || pObjectName.getObjectName() == null) { throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); } - - HttpHeader hh = new HttpHeader(); - hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", - "US-ASCII")); - - Document doc = this.iXmlHelper.newDocument(); - - this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.PullInstances_request(doc, - pObjectName, pContext, pMaxObjects)); - - InputStreamReader is = transmitRequest(operation, hh, doc); - EnumerateResponse enumResp = getEnumerateResponse(is, pObjectName); - return enumResp; - - } catch (WBEMException e) { - logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); - throw e; - } catch (Exception e) { - if (e.getCause() != null && e.getCause() instanceof WBEMException) { - logger - .trace(Level.FINE, operation + " request resulted in CIM Error", e - .getCause()); - throw (WBEMException) e.getCause(); - } - logger.trace(Level.FINE, operation + " request failed", e); - throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); - } finally { - logger.exit(); - } - } - - public EnumerateResponse getInstancesWithPath(CIMObjectPath pObjectName, - String pContext, UnsignedInteger32 pMaxObjects) throws WBEMException { - - final String operation = "PullInstancesWithPath"; - final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - - checkState(); - - try { - if (pObjectName == null || pObjectName.getNamespace() == null - || pObjectName.getObjectName() == null) { throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); } - - HttpHeader hh = new HttpHeader(); - hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", - "US-ASCII")); - - Document doc = this.iXmlHelper.newDocument(); - - this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.PullInstancesWithPath_request( - doc, pObjectName, pContext, pMaxObjects)); - - InputStreamReader is = transmitRequest(operation, hh, doc); - EnumerateResponse enumResp = getEnumerateResponse(is, pObjectName); - return enumResp; - - } catch (WBEMException e) { - logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); - throw e; - } catch (Exception e) { - if (e.getCause() != null && e.getCause() instanceof WBEMException) { - logger - .trace(Level.FINE, operation + " request resulted in CIM Error", e - .getCause()); - throw (WBEMException) e.getCause(); - } - logger.trace(Level.FINE, operation + " request failed", e); - throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); - } finally { - logger.exit(); - } - } - - public EnumerateResponse referencePaths(CIMObjectPath pObjectName, - String pResultClass, String pRole, String pFilterQueryLanguage, String pFilterQuery, - UnsignedInteger32 pTimeout, boolean pContinueOnError, UnsignedInteger32 pMaxObjects) - throws WBEMException { - - final String operation = "OpenReferenceInstancePaths"; - final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - - checkState(); - - try { - if (pObjectName == null || pObjectName.getNamespace() == null - || pObjectName.getObjectName() == null) { throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); } - - HttpHeader hh = new HttpHeader(); - hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", - "US-ASCII")); - - Document doc = this.iXmlHelper.newDocument(); - - this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper - .OpenReferenceInstancePaths_request(doc, pObjectName, pResultClass, pRole, - pFilterQueryLanguage, pFilterQuery, pTimeout, pContinueOnError, - pMaxObjects)); - - InputStreamReader is = transmitRequest(operation, hh, doc); - EnumerateResponse enumResp = getEnumerateResponse(is, pObjectName); - return enumResp; - - } catch (WBEMException e) { - logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); - throw e; - } catch (Exception e) { - if (e.getCause() != null && e.getCause() instanceof WBEMException) { - logger - .trace(Level.FINE, operation + " request resulted in CIM Error", e - .getCause()); - throw (WBEMException) e.getCause(); - } - logger.trace(Level.FINE, operation + " request failed", e); - throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); - } finally { - logger.exit(); - } - } - - public EnumerateResponse references(CIMObjectPath pObjectName, - String pResultClass, String pRole, boolean pIncludeClassOrigin, String[] pPropertyList, - String pFilterQueryLanguage, String pFilterQuery, UnsignedInteger32 pTimeout, - boolean pContinueOnError, UnsignedInteger32 pMaxObjects) throws WBEMException { - - final String operation = "OpenReferenceInstances"; - final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - - checkState(); - - try { - - if (pObjectName == null || pObjectName.getNamespace() == null - || pObjectName.getObjectName() == null) { throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); } - - HttpHeader hh = new HttpHeader(); - hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", - "US-ASCII")); - - Document doc = this.iXmlHelper.newDocument(); - - this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.OpenReferenceInstances_request( - doc, pObjectName, pResultClass, pRole, pIncludeClassOrigin, pPropertyList, - pFilterQueryLanguage, pFilterQuery, pTimeout, pContinueOnError, pMaxObjects)); - - InputStreamReader is = transmitRequest(operation, hh, doc); - EnumerateResponse enumResp = getEnumerateResponse(is, pObjectName); - return enumResp; - - } catch (WBEMException e) { - logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); - throw e; - } catch (Exception e) { - if (e.getCause() != null && e.getCause() instanceof WBEMException) { - logger - .trace(Level.FINE, operation + " request resulted in CIM Error", e - .getCause()); - throw (WBEMException) e.getCause(); - } - logger.trace(Level.FINE, operation + " request failed", e); - throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); - } finally { - logger.exit(); - } - } - - private InputStreamReader transmitIndicationRequest(URI pRecipient, HttpClientPool pClientPool, - HttpHeader pHeader, Document pDocument) throws IOException, ProtocolException, - WBEMException { - return transmitRequestWorker(true, pRecipient, pClientPool, null, pHeader, pDocument); - } - - public boolean sendIndication(URI pRecipient, CIMInstance pIndication) throws WBEMException { - final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); - logger.entry(); - - checkState(); - - try { - if (pRecipient == null || pRecipient.getScheme() == null - || pRecipient.getHost() == null || pRecipient.getPort() <= 0) { throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, - "Invalid recipient URI, must contain valid scheme://host:port"); } - - if (!pRecipient.getScheme().equalsIgnoreCase(WBEMConstants.HTTP) - && !pRecipient.getScheme().equalsIgnoreCase(WBEMConstants.HTTPS)) throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid scheme " - + pRecipient.getScheme() + ", must be http or https"); - - if (pIndication == null) { throw new WBEMException( - WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid indication, must not be null"); } - - logger.trace(Level.FINER, "Attempting to send following indication to " - + pRecipient.toString() + ":\n" + pIndication.toString()); - - HttpHeader hh = new HttpHeader(); - - Document doc = this.iXmlHelper.newDocument(); - - this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.sendIndication_request(doc, - pIndication)); - - HttpClientPool indPool = new HttpClientPool(this.iConfiguration); - - InputStreamReader is = transmitIndicationRequest(pRecipient, indPool, hh, doc); - - boolean success = false; - if (is != null) { - CIMResponse response = getSingleResponse(is, null); - success = response != null && response.isSuccessful(); - } - - indPool.closePool(); - - return success; - } catch (WBEMException e) { - logger.trace(Level.FINE, "Sending indication resulted in CIM Error", e); - throw e; - } catch (Exception e) { - if (e.getCause() != null && e.getCause() instanceof WBEMException) { - logger.trace(Level.FINE, "Sending indication resulted in CIM Error", e.getCause()); - throw (WBEMException) e.getCause(); - } - logger.trace(Level.FINE, "Sending indication failed", e); - throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); - } finally { - logger.exit(); - } - } -} +/* + (C) Copyright IBM Corp. 2006, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, a.wolf-reber@de.ibm.com + * + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1565892 2006-11-08 lupusalex Make SBLIM client JSR48 compliant + * 1688273 2007-04-16 ebak Full support of HTTP trailers + * 1702832 2007-04-18 lupusalex WBEMClientCIMXL.setCustomSocketFactory() not implemented + * 1686000 2007-04-19 ebak modifyInstance() missing from WBEMClient + * 1714184 2007-05-07 lupusalex FVT: NPE on WBEMClientCIMXML.init() + * 1715053 2007-05-08 lupusalex FVT: No forced retry on HTTP 501/510 + * 1714853 2007-05-08 lupusalex Inexplicit error when operation is invoked on closed client + * 1714902 2007-05-08 lupusalex Threading related weak spots + * 1715482 2007-05-10 lupusalex CIM_ERR_FAILED thrown when access denied + * 1736318 2007-06-13 lupusalex Wrong object path in HTTP header + * 1737141 2007-06-18 ebak Sync up with JSR48 evolution + * 1741654 2007-08-22 ebak Header mismatch error on ModifyInstance + * 1949000 2008-04-24 blaschke-oss setLocales() is empty + * 1963762 2008-05-14 blaschke-oss connection leak in WBEMClientCIMXML + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2002599 2008-07-05 raman_arora M-POST not supported in java-client + * 2034342 2008-07-31 blaschke-oss HttpClient not closed on cimclient close + * 2087975 2008-09-03 blaschke-oss can't set the pPropagated in WBEMClient.enumerateClasses() + * 2382763 2008-12-03 blaschke-oss HTTP header field Accept-Language does not include * + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + * 2845211 2009-08-27 raman_arora Pull Enumeration Feature (SAX Parser) + * 2860081 2009-09-17 raman_arora Pull Enumeration Feature (DOM Parser) + * 2846231 2009-09-23 rgummada connection failure on CIMOM w/o user/pw + * 2865222 2009-09-29 raman_arora enumerateQualifierTypes shouldn't require a class name + * 2858933 2009-10-12 raman_arora JSR48 new APIs: associatorClasses & associatorInstances + * 2884718 2009-10-23 blaschke-oss Merge JSR48 and SBLIM client properties + * 2878054 2009-10-25 raman_arora Pull Enumeration Feature (PULL Parser) + * 2888774 2009-10-29 raman_arora support POST retry on HTTP error 505 + * 2886829 2009-11-18 raman_arora JSR48 new APIs: referenceClasses & referenceInstances + * 2909941 2010-01-06 blaschke-oss RequestStateChange gives wrong exception/error id + * 2930341 2010-01-12 blaschke-oss Sync up WBEMClientConstants with JSR48 1.0.0 + * 2913938 2010-02-17 blaschke-oss Duplicate CIM requests with identical message ID + * 2961592 2010-03-01 blaschke-oss Remove WBEMClient.setLocales() UnsupportedOperationException + * 2964463 2010-03-08 blaschke-oss WBEMClient.initialize() throws wrong exception + * 2942520 2010-03-08 blaschke-oss IPv6 link local address with scope_id including a dot not supported + * 3019252 2010-06-21 blaschke-oss Methods concatenate strings using + in a loop + * 3028518 2010-07-14 blaschke-oss Additional StringBuilder use + * 3185833 2011-02-18 blaschke-oss missing newline when logging request/response + * 3197423 2011-03-02 blaschke-oss Server authentication with PegasusLocalAuthInfo failing + * 3277928 2011-04-06 blaschke-oss CIM-XML tracing cannot be enabled in the field + * 3423064 2011-10-13 blaschke-oss Add UpdateExpiredPassword Header for Reqs from Java Client + * 3496355 2012-03-02 blaschke-oss JSR48 1.0.0: add new WBEMClientConstants + * 3514537 2012-04-03 blaschke-oss TCK: execQueryInstances requires boolean, not Boolean + * 3514685 2012-04-03 blaschke-oss TCK: getProperty must return default values + * 3515180 2012-04-05 blaschke-oss JSR48 log dir/file should handle UNIX/Win separators + * 3516848 2012-04-11 blaschke-oss enumerateNamespaces() method to WBEMClient + * 3521119 2012-04-24 blaschke-oss JSR48 1.0.0: remove CIMObjectPath 2/3/4-parm ctors + * 3521328 2012-04-25 blaschke-oss JSR48 1.0.0: remove WBEMClient associators and references + * 3522904 2012-05-02 blaschke-oss Add new API WBEMClientSBLIM.isActive() + * 3521157 2012-05-10 blaschke-oss JSR48 1.0.0: PROP_ENABLE_*_LOGGING is Level, not 0/1 + * 3525914 2012-05-11 blaschke-oss TCK: SetPropertyTest.testSetProperty failing + * 3545797 2012-07-19 blaschke-oss Support new error code of SFCB + * 3553858 2012-08-06 blaschke-oss Append duplicate HTTP header fields instead of replace + * 3554738 2012-08-16 blaschke-oss dump CIM xml by LogAndTraceBroker.trace() + * 3601894 2013-01-23 blaschke-oss Enhance HTTP and CIM-XML tracing + * 2614 2013-02-21 blaschke-oss Remove redundant code in transmitRequest + * 2616 2013-02-23 blaschke-oss Add new API WBEMClientSBLIM.sendIndication() + * 2651 2013-07-31 blaschke-oss IOException when tracing the cimxml + * 2662 2013-09-10 blaschke-oss Need the specific SSLHandshakeException during the cim call + * 2594 2013-11-30 blaschke-oss CR28: Support CIMErrorDescription HTTP field + */ +package org.metricshub.wbem.sblim.cimclient.internal.wbem; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.net.HttpURLConnection; +import java.net.PasswordAuthentication; +import java.net.ProtocolException; +import java.net.SocketException; +import java.net.SocketTimeoutException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URLConnection; +import java.net.URLDecoder; +import java.net.UnknownHostException; +import java.security.Principal; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.logging.Level; +import javax.net.SocketFactory; +import javax.net.ssl.SSLHandshakeException; +import javax.security.auth.Subject; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import org.metricshub.wbem.javax.cim.CIMArgument; +import org.metricshub.wbem.javax.cim.CIMClass; +import org.metricshub.wbem.javax.cim.CIMInstance; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.cim.CIMQualifierType; +import org.metricshub.wbem.javax.cim.UnsignedInteger32; +import org.metricshub.wbem.javax.cim.UnsignedInteger64; +import org.metricshub.wbem.javax.wbem.CloseableIterator; +import org.metricshub.wbem.javax.wbem.WBEMException; +import org.metricshub.wbem.javax.wbem.client.EnumerateResponse; +import org.metricshub.wbem.javax.wbem.client.PasswordCredential; +import org.metricshub.wbem.javax.wbem.client.RoleCredential; +import org.metricshub.wbem.javax.wbem.client.WBEMClient; +import org.metricshub.wbem.javax.wbem.client.WBEMClientConstants; +import org.metricshub.wbem.sblim.cimclient.WBEMClientSBLIM; +import org.metricshub.wbem.sblim.cimclient.WBEMConfigurationProperties; +import org.metricshub.wbem.sblim.cimclient.internal.cim.CIMHelper; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.CIMClientXML_HelperImpl; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.CIMMessage; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.CIMResponse; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.CIMXMLParseException; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.CIMXMLParserImpl; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.SAXHelper; +import org.metricshub.wbem.sblim.cimclient.internal.http.AuthorizationHandler; +import org.metricshub.wbem.sblim.cimclient.internal.http.AuthorizationInfo; +import org.metricshub.wbem.sblim.cimclient.internal.http.HttpClientPool; +import org.metricshub.wbem.sblim.cimclient.internal.http.HttpHeader; +import org.metricshub.wbem.sblim.cimclient.internal.http.HttpHeader.HeaderEntry; +import org.metricshub.wbem.sblim.cimclient.internal.http.HttpHeaderParser; +import org.metricshub.wbem.sblim.cimclient.internal.http.HttpUrlConnection; +import org.metricshub.wbem.sblim.cimclient.internal.http.io.DebugInputStream; +import org.metricshub.wbem.sblim.cimclient.internal.http.io.TrailerException; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; +import org.metricshub.wbem.sblim.cimclient.internal.logging.Messages; +import org.metricshub.wbem.sblim.cimclient.internal.logging.TimeStamp; +import org.metricshub.wbem.sblim.cimclient.internal.util.MOF; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfiguration; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfigurationDefaults; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConstants; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +/** + * The WBEMClientCIMXML is a implementation of the + * javax.wbem.client.WBEMClient interface for the CIM-XML protocol + * including the extensions of the + * org.metricshub.wbem.sblim.cimclient.WBEMClientSBLIM interface. + * + * @see WBEMClient + * @see WBEMClientSBLIM + */ +public class WBEMClientCIMXML implements WBEMClientSBLIM { + private final WBEMConfiguration iConfiguration = new WBEMConfiguration(new Properties()); + + private Locale[] iLocales; // final + + private HttpClientPool iHttpClientPool; // final + + private URI iUri; // final + + private AuthorizationHandler iAuthorizationHandler; // final + + private CIMClientXML_HelperImpl iXmlHelper; // final + + private volatile String iAuthorization; + + private volatile int iNsCounter = 10; + + private volatile boolean iMPostFailed = false; + + private volatile long iMPostFailTime = 0; + + private volatile long iCurrentTime = 0; + + private volatile boolean iInitialized = false; + + private volatile boolean iClosed = false; + + private String iInteropNamespace = null; + + /** + * Ctor. + */ + public WBEMClientCIMXML() { + super(); + } + + private synchronized void initializeClient(URI pUri, Subject pSubject, Locale[] pLocales) + throws IllegalArgumentException { + if (this.iInitialized) throw new IllegalStateException("WBEMClient is already initialized"); + + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + try { + this.iHttpClientPool = new HttpClientPool(this.iConfiguration); + this.iLocales = (pLocales != null && pLocales.length > 0) ? pLocales : WBEMConstants.DEFAULT_LOCALES; + this.iUri = pUri; + + AuthorizationInfo authInfo = AuthorizationInfo.createAuthorizationInfo( + this.iConfiguration.getHttpAuthenticationModule(), + Boolean.FALSE, + this.iUri.getHost(), + this.iUri.getPort(), + null, + null, + null + ); + + Principal principal = ( + pSubject != null && pSubject.getPrincipals() != null && !pSubject.getPrincipals().isEmpty() + ) + ? (Principal) pSubject.getPrincipals().iterator().next() + : null; + Object credential = + ( + pSubject != null && pSubject.getPrivateCredentials() != null && !pSubject.getPrivateCredentials().isEmpty() + ? pSubject.getPrivateCredentials().iterator().next() + : null + ); + + boolean defaultAuthEnabled = WBEMConfiguration.getGlobalConfiguration().isDefaultAuthorizationEnabled(); + + String user = (principal != null) ? principal.getName() : ""; + String password = (credential != null && credential instanceof PasswordCredential) + ? new String(((PasswordCredential) credential).getUserPassword()) + : ( + (credential != null && credential instanceof RoleCredential) + ? new String(((RoleCredential) credential).getCredential()) + : "" + ); + + if (defaultAuthEnabled && (user == null || user.length() == 0) && password.length() == 0) { + logger.trace(Level.FINER, "Principal and Credential not set - using default authorization!"); + + user = WBEMConfiguration.getGlobalConfiguration().getDefaultPrincipal(); + password = WBEMConfiguration.getGlobalConfiguration().getDefaultCredentials(); + } + + authInfo.setCredentials(new PasswordAuthentication(user, password.toCharArray())); + this.iAuthorizationHandler = new AuthorizationHandler(); + this.iAuthorizationHandler.addAuthorizationInfo(authInfo); + + try { + this.iXmlHelper = new CIMClientXML_HelperImpl(); + } catch (ParserConfigurationException e) { + logger.trace(Level.FINE, "Exception while instantiating CIMClientXML_HelperImpl", e); + logger.message(Messages.CIM_XMLHELPER_FAILED); + throw new RuntimeException(e); + } + + this.iInitialized = true; + } finally { + logger.exit(); + } + } + + public void initialize(CIMObjectPath pName, Subject pSubject, Locale[] pLocales) + throws IllegalArgumentException, WBEMException { + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + try { + final URI uri; + + if (pName == null || pName.getHost() == null || pName.getHost().length() == 0) { + throw new IllegalArgumentException("Empty host path"); + } + if (pName.getScheme() == null || pName.getScheme().length() == 0) { + throw new IllegalArgumentException("Empty scheme"); + } + if ( + !pName.getScheme().equalsIgnoreCase(WBEMConstants.HTTP) && + !pName.getScheme().equalsIgnoreCase(WBEMConstants.HTTPS) + ) { + throw new IllegalArgumentException("Protocol not supported"); + } + + try { + uri = CIMHelper.createCimomUri(pName); + } catch (URISyntaxException e) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Malformed URI"); + } + + initializeClient(uri, pSubject, pLocales); + } finally { + logger.exit(); + } + } + + public void initialize(URI pUri, Subject pSubject, Locale[] pLocales) throws IllegalArgumentException, WBEMException { + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + try { + final URI uri; + + if (pUri == null || pUri.getHost() == null || pUri.getHost().length() == 0) { + throw new IllegalArgumentException("Empty host path"); + } + if (pUri.getScheme() == null || pUri.getScheme().length() == 0) { + throw new IllegalArgumentException("Empty scheme"); + } + if ( + !pUri.getScheme().equalsIgnoreCase(WBEMConstants.HTTP) && + !pUri.getScheme().equalsIgnoreCase(WBEMConstants.HTTPS) + ) { + throw new IllegalArgumentException("Protocol not supported"); + } + + try { + uri = CIMHelper.createCimomUri(pUri); + } catch (URISyntaxException e) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Malformed URI"); + } + + initializeClient(uri, pSubject, pLocales); + } finally { + logger.exit(); + } + } + + public Properties getProperties() { + return this.iConfiguration.getDomainProperties(); + } + + private int getLastSeparator(String path) { + if (path == null) return -1; + + int last = -1; + int sepUnix = path.lastIndexOf('/'); + int sepWin = path.lastIndexOf('\\'); + + if (sepUnix != -1 && sepWin != -1) { + last = sepUnix > sepWin ? sepUnix : sepWin; + } else if (sepUnix != -1) { + last = sepUnix; + } else if (sepWin != -1) { + last = sepWin; + } + return last; + } + + public String getProperty(String pKey) { + if (pKey.startsWith("javax.wbem.")) { + // Process JSR48 properties + if (pKey.equals(WBEMClientConstants.PROP_ENABLE_CONSOLE_LOGGING)) { + return this.iConfiguration.getLogConsoleLevel().getName(); + } else if (pKey.equals(WBEMClientConstants.PROP_ENABLE_FILE_LOGGING)) { + return this.iConfiguration.getLogFileLevel().getName(); + } else if (pKey.equals(WBEMClientConstants.PROP_LOG_BYTE_LIMIT)) { + return Integer.toString(this.iConfiguration.getLogFileSizeLimit()); + } else if (pKey.equals(WBEMClientConstants.PROP_LOG_DIR)) { + String SblimKey = this.iConfiguration.getLogFileLocation(); + if (SblimKey == null) return null; + int lastSep = getLastSeparator(SblimKey); + return lastSep == -1 ? null : SblimKey.substring(0, lastSep); + } else if (pKey.equals(WBEMClientConstants.PROP_LOG_FILENAME)) { + String SblimKey = this.iConfiguration.getLogFileLocation(); + if (SblimKey == null) return null; + int lastSep = getLastSeparator(SblimKey); + return lastSep == -1 ? SblimKey : SblimKey.substring(lastSep + 1); + } else if (pKey.equals(WBEMClientConstants.PROP_LOG_NUM_FILES)) { + return Integer.toString(this.iConfiguration.getLogFileCount()); + } else if (pKey.equals(WBEMClientConstants.PROP_TIMEOUT)) { + return Integer.toString(this.iConfiguration.getHttpTimeout()); + } else if (pKey.equals(WBEMClientConstants.PROPERTY_WBEM_CHUNKING)) { + return this.iConfiguration.isHttpChunked() ? "1" : "0"; + } else if (pKey.equals(WBEMClientConstants.PROP_CLIENT_KEYSTORE)) { + return this.iConfiguration.getSslKeyStorePath(); + } else if (pKey.equals(WBEMClientConstants.PROP_CLIENT_KEYSTORE_PASSWORD)) { + return this.iConfiguration.getSslKeyStorePassword(); + } else if (pKey.equals(WBEMClientConstants.PROP_CLIENT_TRUSTSTORE)) { + return this.iConfiguration.getSslTrustStorePath(); + } else { + return null; + } + } + return this.iConfiguration.getDomainProperty(pKey); + } + + public void setProperties(Properties pProperties) { + this.iConfiguration.setDomainProperties(pProperties); + } + + public void setProperty(String pKey, String pValue) { + if (pKey.startsWith("javax.wbem.")) { + // Process JSR48 properties + if (pKey.equals(WBEMClientConstants.PROP_ENABLE_CONSOLE_LOGGING)) { + this.iConfiguration.setDomainProperty(WBEMConfigurationProperties.LOG_CONSOLE_LEVEL, pValue); + } else if (pKey.equals(WBEMClientConstants.PROP_ENABLE_FILE_LOGGING)) { + this.iConfiguration.setDomainProperty(WBEMConfigurationProperties.LOG_FILE_LEVEL, pValue); + } else if (pKey.equals(WBEMClientConstants.PROP_LOG_BYTE_LIMIT)) { + this.iConfiguration.setDomainProperty(WBEMConfigurationProperties.LOG_FILE_SIZE_LIMIT, pValue); + } else if (pKey.equals(WBEMClientConstants.PROP_LOG_DIR)) { + StringBuffer NewSblimLog = new StringBuffer(pValue != null ? pValue : ""); + if (NewSblimLog.length() > 0 && NewSblimLog.charAt(NewSblimLog.length() - 1) != File.separatorChar) { + NewSblimLog.append(File.separator); + } + + String CurSblimLog = this.iConfiguration.getDomainProperty(WBEMConfigurationProperties.LOG_FILE_LOCATION); + if (CurSblimLog == null) { + CurSblimLog = WBEMConfigurationDefaults.LOG_FILE_LOCATION; + } + + int i = getLastSeparator(CurSblimLog); + if (i == -1) { + NewSblimLog.append(CurSblimLog); + } else { + NewSblimLog.append(CurSblimLog.substring(i + 1)); + } + + this.iConfiguration.setDomainProperty(WBEMConfigurationProperties.LOG_FILE_LOCATION, NewSblimLog.toString()); + } else if (pKey.equals(WBEMClientConstants.PROP_LOG_FILENAME)) { + StringBuffer NewSblimLog = new StringBuffer(pValue != null ? pValue : ""); + + String CurSblimLog = this.iConfiguration.getDomainProperty(WBEMConfigurationProperties.LOG_FILE_LOCATION); + if (CurSblimLog != null) { + int i = getLastSeparator(CurSblimLog); + if (i != -1) { + NewSblimLog.insert(0, CurSblimLog.substring(0, i + 1)); + } + } + + this.iConfiguration.setDomainProperty(WBEMConfigurationProperties.LOG_FILE_LOCATION, NewSblimLog.toString()); + } else if (pKey.equals(WBEMClientConstants.PROP_LOG_NUM_FILES)) { + this.iConfiguration.setDomainProperty(WBEMConfigurationProperties.LOG_FILE_COUNT, pValue); + } else if (pKey.equals(WBEMClientConstants.PROP_TIMEOUT)) { + this.iConfiguration.setDomainProperty(WBEMConfigurationProperties.HTTP_TIMEOUT, pValue); + } else if (pKey.equals(WBEMClientConstants.PROPERTY_WBEM_CHUNKING)) { + this.iConfiguration.setDomainProperty( + WBEMConfigurationProperties.HTTP_USE_CHUNKING, + pValue.equals("0") ? "false" : "true" + ); + } else if (pKey.equals(WBEMClientConstants.PROP_CLIENT_KEYSTORE)) { + this.iConfiguration.setDomainProperty(WBEMConfigurationProperties.KEYSTORE_PATH, pValue); + } else if (pKey.equals(WBEMClientConstants.PROP_CLIENT_KEYSTORE_PASSWORD)) { + this.iConfiguration.setDomainProperty(WBEMConfigurationProperties.KEYSTORE_PASSWORD, pValue); + } else if (pKey.equals(WBEMClientConstants.PROP_CLIENT_TRUSTSTORE)) { + this.iConfiguration.setDomainProperty(WBEMConfigurationProperties.TRUSTSTORE_PATH, pValue); + } else { + throw new IllegalArgumentException(pKey); + } + } else { + this.iConfiguration.setDomainProperty(pKey, pValue); + } + } + + public CloseableIterator associatorNames( + CIMObjectPath pObjectName, + String pAssociationClass, + String pResultClass, + String pRole, + String pResultRole + ) + throws WBEMException { + final String operation = "AssociatorNames"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pObjectName == null || pObjectName.getNamespace() == null || pObjectName.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.associatorNames_request(doc, pObjectName, pAssociationClass, pResultClass, pRole, pResultRole) + ); + + InputStreamReader is = transmitRequest("AssociatorNames", hh, doc); + + CloseableIterator iter = getIterator(is, pObjectName); + return iter; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public CloseableIterator associatorClasses( + CIMObjectPath pObjectName, + String pAssociationClass, + String pResultClass, + String pRole, + String pResultRole, + boolean pIncludeQualifiers, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException { + final String operation = "AssociatorClasses"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pObjectName == null || pObjectName.getNamespace() == null || pObjectName.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.associatorClasses_request( + doc, + pObjectName, + pAssociationClass, + pResultClass, + pRole, + pResultRole, + pIncludeQualifiers, + pIncludeClassOrigin, + pPropertyList + ) + ); + + InputStreamReader is = transmitRequest("Associators", hh, doc); + + CloseableIterator iter = getIterator(is, pObjectName); + + return iter; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public CloseableIterator associatorInstances( + CIMObjectPath pObjectName, + String pAssociationClass, + String pResultClass, + String pRole, + String pResultRole, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException { + final String operation = "AssociatorInstances"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pObjectName == null || pObjectName.getNamespace() == null || pObjectName.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.associatorInstances_request( + doc, + pObjectName, + pAssociationClass, + pResultClass, + pRole, + pResultRole, + pIncludeClassOrigin, + pPropertyList + ) + ); + + InputStreamReader is = transmitRequest("Associators", hh, doc); + + CloseableIterator iter = getIterator(is, pObjectName); + return iter; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public synchronized void close() { + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + try { + checkState(); + if (this.iHttpClientPool != null) { + this.iHttpClientPool.closePool(); + } + } finally { + this.iClosed = true; + logger.exit(); + } + } + + public void createClass(CIMClass pClass) throws WBEMException { + final String operation = "CreateClass"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pClass == null || pClass.getObjectPath() == null || pClass.getObjectPath().getNamespace() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pClass.getObjectPath().getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.createClass_request(doc, pClass.getObjectPath(), pClass)); + + InputStreamReader is = transmitRequest("CreateClass", hh, doc); + + CloseableIterator iter = getIterator(is, pClass.getObjectPath()); + try { + iter.hasNext(); + } finally { + iter.close(); + } + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public CIMObjectPath createInstance(CIMInstance pInstance) throws WBEMException { + final String operation = "CreateInstance"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pInstance == null || pInstance.getObjectPath() == null || pInstance.getObjectPath().getNamespace() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pInstance.getObjectPath().getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.createInstance_request(doc, pInstance.getObjectPath(), pInstance) + ); + + InputStreamReader is = transmitRequest("CreateInstance", hh, doc); + + CloseableIterator iter = getIterator(is, pInstance.getObjectPath()); + try { + if (iter.hasNext()) { + return (CIMObjectPath) iter.next(); + } + } finally { + iter.close(); + } + + return null; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public void deleteClass(CIMObjectPath pPath) throws WBEMException { + final String operation = "DeleteClass"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pPath == null || pPath.getNamespace() == null || pPath.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pPath.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.deleteClass_request(doc, pPath)); + + InputStreamReader is = transmitRequest("DeleteClass", hh, doc); + + CloseableIterator iter = getIterator(is, pPath); + try { + iter.hasNext(); + } finally { + iter.close(); + } + + return; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public void deleteInstance(CIMObjectPath pPath) throws WBEMException { + final String operation = "DeleteInstance"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pPath == null || pPath.getNamespace() == null || pPath.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pPath.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + + this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.deleteInstance_request(doc, pPath)); + + InputStreamReader is = transmitRequest("DeleteInstance", hh, doc); + + CloseableIterator iter = getIterator(is, pPath); + try { + iter.hasNext(); + } finally { + iter.close(); + } + + return; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public void deleteQualifierType(CIMObjectPath pPath) throws WBEMException { + final String operation = "DeleteQualifierType"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pPath == null || pPath.getNamespace() == null || pPath.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pPath.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.deleteQualifierType_request(doc, pPath)); + + InputStreamReader is = transmitRequest("DeleteQualifierType", hh, doc); + + CloseableIterator iter = getIterator(is, pPath); + try { + iter.hasNext(); + } finally { + iter.close(); + } + + return; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public CloseableIterator enumerateClassNames(CIMObjectPath pPath, boolean pDeep) throws WBEMException { + final String operation = "EnumerateClassNames"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pPath == null || pPath.getNamespace() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pPath.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.enumerateClassNames_request(doc, pPath, pDeep)); + + InputStreamReader is = transmitRequest("EnumerateClassNames", hh, doc); + + CloseableIterator iter = getIterator(is, pPath); + return iter; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public CloseableIterator enumerateClasses( + CIMObjectPath pPath, + boolean pDeep, + boolean pPropagated, + boolean pIncludeQualifiers, + boolean pIncludeClassOrigin + ) + throws WBEMException { + final String operation = "EnumerateClasses"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pPath == null || pPath.getNamespace() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pPath.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.enumerateClasses_request( + doc, + pPath, + pDeep, + pPropagated, + pIncludeQualifiers, + pIncludeClassOrigin + ) + ); + + InputStreamReader is = transmitRequest("EnumerateClasses", hh, doc); + + CloseableIterator iter = getIterator(is, pPath); + return iter; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public CloseableIterator enumerateInstanceNames(CIMObjectPath pPath) throws WBEMException { + final String operation = "EnumerateInstanceNames"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pPath == null || pPath.getNamespace() == null || pPath.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pPath.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.enumerateInstanceNames_request(doc, pPath)); + + InputStreamReader is = transmitRequest("EnumerateInstanceNames", hh, doc); + + CloseableIterator iter = getIterator(is, pPath); + return iter; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public CloseableIterator enumerateInstances( + CIMObjectPath pPath, + boolean pDeep, + boolean pPropagated, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException { + final String operation = "EnumerateInstances"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pPath == null || pPath.getNamespace() == null || pPath.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pPath.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.enumerateInstances_request( + doc, + pPath, + pDeep, + pPropagated, + false, + pIncludeClassOrigin, + pPropertyList + ) + ); + + InputStreamReader is = transmitRequest("EnumerateInstances", hh, doc); + + CloseableIterator iter = getIterator(is, pPath); + return iter; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + // DSP1033 states that CIMOMs shall include an Interop Namespace and that + // the name of this Interop Namespace shall be either "interop" (preferred) + // or "root/interop" while OpenPegasus 2.11 and earlier implemented + // "root/PG_InterOp" prior to adopting DSP1033. + private static final String[] InteropNamespaces = { "interop", "root/interop", "root/PG_InterOp" }; + + private CloseableIterator enumerateNamespace(String pNamespace) { + if (pNamespace != null && pNamespace.trim().length() > 0) { + try { + CloseableIterator result = enumerateInstanceNames( + new CIMObjectPath(null, null, null, pNamespace, "CIM_Namespace", null) + ); + if (result != null) return result; + } catch (Exception e) { + // namespace may not exist + } + } + return null; + } + + public CloseableIterator enumerateNamespaces(String pNamespace) throws WBEMException { + CloseableIterator result; + + // First, try the user's specified namespace (if any) + if (pNamespace != null && pNamespace.trim().length() > 0) { + result = enumerateNamespace(pNamespace); + if (result != null) return result; + } + + // Second, try the saved interop namespace (if any) + if (this.iInteropNamespace != null) { + result = enumerateNamespace(this.iInteropNamespace); + if (result != null) return result; + this.iInteropNamespace = null; + } + + // Finally, try the default interop namespace names + for (int i = 0; i < InteropNamespaces.length; i++) { + result = enumerateNamespace(InteropNamespaces[i]); + if (result != null) { + if (this.iInteropNamespace == null) this.iInteropNamespace = InteropNamespaces[i]; + return result; + } + } + + throw new WBEMException( + WBEMException.CIM_ERR_FAILED, + "Interop namespaces do not exist, CIMOM may not support DSP1033" + ); + } + + public CloseableIterator> enumerateQualifierTypes(CIMObjectPath pPath) throws WBEMException { + final String operation = "EnumerateQualifiers"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + // enumerateQualifierTypes does not need class name, as it lists all + // qualifiers in namespace + if (pPath == null || pPath.getNamespace() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pPath.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.enumQualifierTypes_request(doc, pPath)); + + InputStreamReader is = transmitRequest("EnumerateQualifiers", hh, doc); + + CloseableIterator> iter = getIterator(is, pPath); + return iter; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public CloseableIterator execQuery(CIMObjectPath pPath, String pQuery, String pQueryLanguage) + throws WBEMException { + final String operation = "ExecQuery"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pPath == null || pPath.getNamespace() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pPath.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.execQuery_request(doc, pPath, pQuery, pQueryLanguage)); + + InputStreamReader is = transmitRequest("ExecQuery", hh, doc); + + CloseableIterator iter = getIterator(is, pPath); + return iter; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public CIMClass getClass( + CIMObjectPath pName, + boolean pPropagated, + boolean pIncludeQualifiers, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException { + final String operation = "GetClass"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pName == null || pName.getNamespace() == null || pName.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pName.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.getClass_request( + doc, + pName, + pPropagated, + pIncludeQualifiers, + pIncludeClassOrigin, + pPropertyList + ) + ); + + InputStreamReader is = transmitRequest("GetClass", hh, doc); + + CloseableIterator iter = getIterator(is, pName); + try { + if (iter.hasNext()) { + return (CIMClass) iter.next(); + } + } finally { + iter.close(); + } + + return null; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public CIMInstance getInstance( + CIMObjectPath pName, + boolean pPropagated, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException { + final String operation = "GetInstance"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pName == null || pName.getNamespace() == null || pName.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pName.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.getInstance_request(doc, pName, pPropagated, false, pIncludeClassOrigin, pPropertyList) + ); + + InputStreamReader is = transmitRequest("GetInstance", hh, doc); + + CloseableIterator iter = getIterator(is, pName); + try { + if (iter.hasNext()) { + CIMInstance result = (CIMInstance) iter.next(); + return new CIMInstance(pName, result.getProperties()); + } + } finally { + iter.close(); + } + + return null; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public CIMQualifierType getQualifierType(CIMObjectPath pName) throws WBEMException { + final String operation = "GetQualifier"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pName == null || pName.getNamespace() == null || pName.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pName.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.getQualifier_request(doc, pName, pName.getObjectName())); + + InputStreamReader is = transmitRequest("GetQualifier", hh, doc); + + CloseableIterator iter = getIterator(is, pName); + try { + if (iter.hasNext()) { + return (CIMQualifierType) iter.next(); + } + } finally { + iter.close(); + } + + return null; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public Object invokeMethod( + CIMObjectPath pName, + String pMethodName, + CIMArgument[] pInputArguments, + CIMArgument[] pOutputArguments + ) + throws WBEMException { + final String operation = "InvokeMethod"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pName == null || pName.getNamespace() == null || pName.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(MOF.objectHandle(pName, false, true), "UTF-8", "US-ASCII")); + + // sfcb needs pragma set for UpdateExpiredPassword call + if (pMethodName != null && pMethodName.equalsIgnoreCase("UpdateExpiredPassword")) hh.addField( + "Pragma", + "UpdateExpiredPassword" + ); + + Document doc = this.iXmlHelper.newDocument(); + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.invokeMethod_request(doc, pName, pMethodName, pInputArguments) + ); + + InputStreamReader is = transmitRequest(pMethodName, hh, doc); + + CIMResponse response = null; + String parser = this.iConfiguration.getCimXmlParser(); + // TODO: set the local namespace for parsers + if (WBEMConstants.SAX.equals(parser) || WBEMConstants.PULL.equals(parser)) { + return SAXHelper.parseInvokeMethodResponse(is, pOutputArguments, null); + } + // DOM parser + response = getSingleResponse(is, null); + response.checkError(); + List resultSet = response.getFirstReturnValue(); + + Object rc = resultSet.size() > 0 ? resultSet.get(0) : null; + + List outParamValues = response.getParamValues(); + if (pOutputArguments != null && outParamValues != null) { + Iterator itr = outParamValues.iterator(); + for (int i = 0; i < pOutputArguments.length; i++) if (itr.hasNext()) { + pOutputArguments[i] = (CIMArgument) itr.next(); + } else { + break; + } + } + return rc; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public boolean isActive() { + return this.iInitialized && !this.iClosed; + } + + public void modifyClass(CIMClass pClass) throws WBEMException { + final String operation = "ModifyClass"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if ( + pClass == null || + pClass.getObjectPath() == null || + pClass.getObjectPath().getNamespace() == null || + pClass.getObjectPath().getObjectName() == null + ) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pClass.getObjectPath().getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.setClass_request(doc, pClass.getObjectPath(), pClass)); + + InputStreamReader is = transmitRequest("ModifyClass", hh, doc); + + CloseableIterator iter = getIterator(is, pClass.getObjectPath()); + try { + iter.hasNext(); + } finally { + iter.close(); + } + + return; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public void modifyInstance(CIMInstance pInst, String[] pPropertyList) throws WBEMException { + final String operation = "ModifyInstance"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + checkState(); + if ( + pInst == null || + pInst.getObjectPath() == null || + pInst.getObjectPath().getNamespace() == null || + pInst.getObjectPath().getObjectName() == null + ) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + final CIMObjectPath path = pInst.getObjectPath(); + try { + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(path.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.setInstance_request(doc, path, pInst, true, pPropertyList)); + InputStreamReader is = transmitRequest(operation, hh, doc); + + CloseableIterator iter = getIterator(is, path); + try { + iter.hasNext(); + } finally { + iter.close(); + } + return; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public CloseableIterator referenceClasses( + CIMObjectPath pObjectName, + String pResultClass, + String pRole, + boolean pIncludeQualifiers, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException { + final String operation = "ReferenceClasses"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pObjectName == null || pObjectName.getNamespace() == null || pObjectName.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.referenceClasses_request( + doc, + pObjectName, + pResultClass, + pRole, + pIncludeQualifiers, + pIncludeClassOrigin, + pPropertyList + ) + ); + + InputStreamReader is = transmitRequest("References", hh, doc); + + return getIterator(is, pObjectName); + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public CloseableIterator referenceInstances( + CIMObjectPath pObjectName, + String pResultClass, + String pRole, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) + throws WBEMException { + final String operation = "ReferenceInstances"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pObjectName == null || pObjectName.getNamespace() == null || pObjectName.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.referenceInstances_request( + doc, + pObjectName, + pResultClass, + pRole, + pIncludeClassOrigin, + pPropertyList + ) + ); + + InputStreamReader is = transmitRequest("References", hh, doc); + + return getIterator(is, pObjectName); + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public CloseableIterator referenceNames(CIMObjectPath pObjectName, String pResultClass, String pRole) + throws WBEMException { + final String operation = "ReferenceNames"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pObjectName == null || pObjectName.getNamespace() == null || pObjectName.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.referenceNames_request(doc, pObjectName, pResultClass, pRole) + ); + + InputStreamReader is = transmitRequest("ReferenceNames", hh, doc); + + CloseableIterator iter = getIterator(is, pObjectName); + return iter; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public void setLocales(Locale[] pLocales) { + this.iLocales = (pLocales != null && pLocales.length > 0) ? pLocales : WBEMConstants.DEFAULT_LOCALES; + } + + public void setQualifierType(CIMQualifierType pQualifierType) throws WBEMException { + final String operation = "SetQualifierType"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if ( + pQualifierType == null || + pQualifierType.getObjectPath() == null || + pQualifierType.getObjectPath().getNamespace() == null || + pQualifierType.getObjectPath().getObjectName() == null + ) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pQualifierType.getObjectPath().getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.setQualifierType_request(doc, pQualifierType.getObjectPath(), pQualifierType) + ); + + InputStreamReader is = transmitRequest("SetQualifierType", hh, doc); + + CloseableIterator iter = getIterator(is, pQualifierType.getObjectPath()); + try { + iter.hasNext(); + } finally { + iter.close(); + } + + return; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public SocketFactory getCustomSocketFactory() { + return this.iConfiguration.getCustomSocketFactory(); + } + + public void setCustomSocketFactory(SocketFactory pFactory) throws UnsupportedOperationException { + this.iConfiguration.setCustomSocketFactory(pFactory); + } + + private String getHttpErrorString(int pStatusCode) { + switch (pStatusCode) { + case 400: + return "400 - BAD REQUEST"; + case 401: + return "401 - UNAUTHORIZED"; + case 403: + return "403 - FORBIDDEN"; + case 405: + return "405 - METHOD NOT ALLOWED"; + case 407: + return "407 - PROXY AUTHENTICATION REQUIRED"; + } + return null; + } + + private InputStreamReader transmitRequest(String pCimMethod, HttpHeader pHeader, Document pDocument) + throws IOException, ProtocolException, WBEMException { + return transmitRequestWorker(false, this.iUri, this.iHttpClientPool, pCimMethod, pHeader, pDocument); + } + + /* + * Worker for both transmitRequest() (pIsIndication == false) and + * transmitIndicationRequest() (pIsIndication == true). + */ + private InputStreamReader transmitRequestWorker( + boolean pIsIndication, + URI pRecipient, + HttpClientPool pClientPool, + String pCimMethod, + HttpHeader pHeader, + Document pDocument + ) + throws IOException, ProtocolException, WBEMException { + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + HttpUrlConnection connection = null; + int exceptionNum = WBEMException.CIM_ERR_FAILED; + + // retry HTTP MPOST only if failure is more than 24 hours old + if (this.iMPostFailed && !pIsIndication) { + this.iCurrentTime = System.currentTimeMillis(); + if ((this.iCurrentTime - this.iMPostFailTime) > 24 * 60 * 60 * 1000) this.iMPostFailed = false; + } + boolean useMPost = this.iMPostFailed || pIsIndication ? false : this.iConfiguration.isHttpMPost(); + int retries = this.iConfiguration.getHttpConnectRetriesCount(); + do { + logger.trace(Level.FINE, "Attempting to connect.. number of attempts left:" + retries); + + // Disconnect existing connection to prevent object leak + if (connection != null) { + connection.disconnect(); + } + connection = newConnection(pIsIndication, pRecipient, pClientPool, pCimMethod, pHeader, useMPost); + try { + logger.trace(Level.FINE, "Connecting..."); + connection.connect(); + } catch (UnknownHostException e) { + throw new WBEMException(WBEMException.CIM_ERR_FAILED, "Unknown host", null, e); + } catch (SocketException e) { + throw new WBEMException(WBEMException.CIM_ERR_FAILED, "Unable to connect", null, e); + } catch (SSLHandshakeException e) { + throw new WBEMException(WBEMException.CIM_ERR_FAILED, "SSL handshake exception", null, e); + } + + OutputStream os = connection.getOutputStream(); + + if ( + this.iConfiguration.isCimXmlTracingEnabled() || + LogAndTraceBroker.getBroker().isLoggableCIMXMLTrace(Level.FINEST) + ) { + OutputStream pos = new ByteArrayOutputStream(); + CIMClientXML_HelperImpl.dumpDocument(pos, pDocument, pIsIndication ? "indication request" : "request"); + OutputStream debugStream = LogAndTraceBroker.getBroker().getXmlTraceStream(); + if (this.iConfiguration.isCimXmlTracingEnabled() && debugStream != null) debugStream.write( + pos.toString().getBytes() + ); + if (LogAndTraceBroker.getBroker().isLoggableCIMXMLTrace(Level.FINEST)) logger.traceCIMXML( + Level.FINEST, + pos.toString(), + true + ); + } + CIMClientXML_HelperImpl.serialize(os, pDocument); + os.flush(); + os.close(); + + int resultCode = 200; + try { + resultCode = connection.getResponseCode(); + } catch (SocketException e) { + connection.disconnect(); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, "Unable to connect", null, e); + } catch (SocketTimeoutException e) { + connection.disconnect(); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, "Connection timed out", null, e); + } catch (SSLHandshakeException e) { + connection.disconnect(); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, "SSL handshake exception", null, e); + } + + HttpHeader headers = parseHeaders(connection); + String auth = connection.getRequestProperty("Authorization"); + if (auth != null) { + this.iAuthorization = auth; + } + + exceptionNum = WBEMException.CIM_ERR_FAILED; + + switch (resultCode) { + case HttpURLConnection.HTTP_OK: // 200 + if (this.iConfiguration.isHttpContentLengthRetryEnabled()) { + String contentLengthField = headers.getField("Content-length"); + if (contentLengthField != null && contentLengthField.trim().length() > 0) { + int contentLength = Integer.parseInt(contentLengthField); + int lengthToCheck = this.iConfiguration.getHttpContentLengthThreshold(); + + if (contentLength < lengthToCheck) { + logger.trace(Level.FINE, "Content Length below " + lengthToCheck + ", retrying"); + break; + } + } + } + + String charset = getCharacterSet(headers); + + InputStream is = connection.getInputStream(); + OutputStream debugStream = LogAndTraceBroker.getBroker().getXmlTraceStream(); + if ( + (this.iConfiguration.isCimXmlTracingEnabled() && debugStream != null) || + LogAndTraceBroker.getBroker().isLoggableCIMXMLTrace(Level.FINEST) + ) { + is = new DebugInputStream(is, debugStream, pIsIndication ? "indication response" : "response"); + } + + return new InputStreamReader(is, charset); + case HttpURLConnection.HTTP_NOT_IMPLEMENTED: // 501 + // TODO if there is an error with the default xml + // encoder/decoder, load the correct version + // The problem is that the CIMOM does not return the DTD + // version, CIM version or Protocol Version + // that is expecting + String cimProtocolVersion = headers.getField("CIMProtocolVersion"); + if (cimProtocolVersion == null && headers.getField("CIMError") == null && useMPost) { + logger.trace(Level.FINER, "Received HTTP Error 501 - NOT IMPLEMENTED with M-POST, falling back to POST"); + this.iMPostFailTime = System.currentTimeMillis(); + useMPost = false; + this.iMPostFailed = true; + ++retries; + break; + } + + logger.trace(Level.FINER, "Received HTTP Error 501 - NOT IMPLEMENTED, skipping retries"); + retries = 0; + break; + case HttpURLConnection.HTTP_BAD_REQUEST: // 400 + case HttpURLConnection.HTTP_FORBIDDEN: // 403 + case HttpURLConnection.HTTP_BAD_METHOD: // 405 + logger.trace(Level.FINER, "Received HTTP Error " + getHttpErrorString(resultCode) + ", skipping retries"); + retries = 0; + break; + case HttpURLConnection.HTTP_UNAUTHORIZED: // 401 + case HttpURLConnection.HTTP_PROXY_AUTH: // 407 + logger.trace(Level.FINER, "Received HTTP Error " + getHttpErrorString(resultCode) + ", skipping retries"); + exceptionNum = WBEMException.CIM_ERR_ACCESS_DENIED; + retries = 0; + break; + default: + if (useMPost) { + logger.trace(Level.FINER, "Received HTTP Error " + resultCode + " with M-POST, falling back to POST"); + this.iMPostFailTime = System.currentTimeMillis(); + useMPost = false; + this.iMPostFailed = true; + ++retries; + } else { + logger.trace(Level.FINER, "Received HTTP Error " + resultCode + ", retrying"); + } + } + + // Log HTTP error in XML trace if we are going to retry request + // (this means there is no response and no exception to indicate + // result of current request, which makes it look like the client is + // sending multiple requests without any response) + if (retries > 0) { + OutputStream debugStream = LogAndTraceBroker.getBroker().getXmlTraceStream(); + if ( + (this.iConfiguration.isCimXmlTracingEnabled() && debugStream != null) || + LogAndTraceBroker.getBroker().isLoggableCIMXMLTrace(Level.FINEST) + ) { + StringBuilder resultStr = new StringBuilder("<--- error response begin "); + resultStr.append(TimeStamp.formatWithMillis(System.currentTimeMillis())); + resultStr.append(" ----\nHTTP "); + resultStr.append(resultCode); + resultStr.append(' '); + resultStr.append(connection.getResponseMessage()); + resultStr.append(" (retrying request)\n---- error response end ----->\n"); + if (this.iConfiguration.isCimXmlTracingEnabled() && debugStream != null) debugStream.write( + resultStr.toString().getBytes() + ); + if (LogAndTraceBroker.getBroker().isLoggableCIMXMLTrace(Level.FINEST)) logger.traceCIMXML( + Level.FINEST, + resultStr.toString(), + false + ); + } + } + } while (retries-- > 0); + + // Benchmark.stopTransportTimer(); + + // Look for CIM error and description, include in exception if exists + String errorCIM = connection.getHeaderField("CIMError"); + String errorDescriptionCIM = null; + if (errorCIM != null) { + logger.trace(Level.FINER, "Found CIMError field with value \"" + errorCIM + "\""); + + errorDescriptionCIM = connection.getHeaderField("CIMErrorDescription"); + if (errorDescriptionCIM != null) { + try { + errorDescriptionCIM = URLDecoder.decode(errorDescriptionCIM, "UTF-8"); + } catch (Exception e) { + errorDescriptionCIM = null; + } + logger.trace(Level.FINER, "Found CIMErrorDescription field with value \"" + errorDescriptionCIM + "\""); + } + } + + // Look for OpenPegasus error details, decode and include in exception + // if it exists + String errorOP = connection.getHeaderField("PGErrorDetail"); + if (errorOP != null) { + try { + errorOP = URLDecoder.decode(errorOP, "UTF-8"); + } catch (Exception e) { + errorOP = null; + } + logger.trace(Level.FINER, "Found PGErrorDetail field with value \"" + errorOP + "\""); + } + + // Look for SFCB error details, decode and include in exception + // if it exists + String errorSFCB = connection.getHeaderField("SFCBErrorDetail"); + if (errorSFCB != null) { + try { + errorSFCB = URLDecoder.decode(errorSFCB, "UTF-8"); + } catch (Exception e) { + errorSFCB = null; + } + logger.trace(Level.FINER, "Found SFCBErrorDetail field with value \"" + errorSFCB + "\""); + } + + // If CIMErrorDescription present, format of WBEMException is: + // + // HTTP StatusCode - ReasonPhrase (CIMError: "ErrorString", + // CIMErrorDescription: "ErrorString") + // + // Otherwise, format of WBEMException message is: + // + // HTTP StatusCode - ReasonPhrase (CIMError: "ErrorString", OpenPegasus + // Error: "ErrorString", SFCB Error: "ErrorString") + // + // For example: + // HTTP 503 - Service Unavailable (SFCB Error: + // "Max Session Limit Exceeded") + StringBuffer errorMsg = new StringBuffer("HTTP "); + errorMsg.append(connection.getResponseCode()); + errorMsg.append(" - "); + errorMsg.append(connection.getResponseMessage()); + if (errorCIM != null && errorDescriptionCIM != null) { + errorMsg.append(" (CIMError: \""); + errorMsg.append(errorCIM); + errorMsg.append("\", CIMErrorDescription: \""); + errorMsg.append(errorDescriptionCIM); + errorMsg.append("\")"); + } else if (errorCIM != null || errorOP != null || errorSFCB != null) { + errorMsg.append(" ("); + if (errorCIM != null) { + errorMsg.append("CIMError: \""); + errorMsg.append(errorCIM); + errorMsg.append('"'); + } + if (errorOP != null) { + if (errorCIM != null) errorMsg.append(", "); + errorMsg.append("OpenPegasus Error: \""); + errorMsg.append(errorOP); + errorMsg.append('"'); + } + if (errorSFCB != null) { + if (errorCIM != null || errorOP != null) errorMsg.append(", "); + errorMsg.append("SFCB Error: \""); + errorMsg.append(errorSFCB); + errorMsg.append('"'); + } + errorMsg.append(')'); + } + + connection.disconnect(); + + throw new WBEMException(exceptionNum, errorMsg.toString()); + } + + private HttpUrlConnection newConnection( + boolean pIsIndication, + URI pRecipient, + HttpClientPool pClientPool, + String pCimMethod, + HttpHeader pHeader, + boolean pUseMPost + ) { + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + HttpUrlConnection connection = new HttpUrlConnection(pRecipient, pClientPool, this.iAuthorizationHandler); + if (pUseMPost) { + connection.setRequestMethod(WBEMConstants.HTTP_MPOST); + } else connection.setRequestMethod(WBEMConstants.HTTP_POST); + connection.useHttp11("1.1".equals(this.iConfiguration.getHttpVersion())); + + String firstLocaleStr = this.iLocales[0].getLanguage(); + if (this.iLocales[0].getCountry().length() > 0) firstLocaleStr = + firstLocaleStr + '-' + this.iLocales[0].getCountry(); + StringBuilder restLocaleStrBld = new StringBuilder(""); + for (int i = 1; i < this.iLocales.length; i++) { + if (this.iLocales[i] != null && this.iLocales[i].getLanguage().length() > 0) { + restLocaleStrBld.append(", "); + restLocaleStrBld.append(this.iLocales[i].getLanguage()); + if (this.iLocales[i].getCountry().length() > 0) { + restLocaleStrBld.append('-'); + restLocaleStrBld.append(this.iLocales[i].getCountry()); + } + } + } + + connection.setDoOutput(true); + connection.setDoInput(true); + connection.setRequestProperty("Content-type", "application/xml; charset=\"utf-8\""); + connection.setRequestProperty("Accept", "text/html, text/xml, application/xml"); + connection.setRequestProperty("Cache-Control", "no-cache"); + connection.setRequestProperty("Content-Language", firstLocaleStr); + connection.setRequestProperty("Accept-Language", firstLocaleStr + restLocaleStrBld.toString() + ", *"); + if (this.iAuthorization != null) connection.setRequestProperty("Authorization", this.iAuthorization); + + String prefix = ""; + if (connection.getRequestMethod().equalsIgnoreCase(WBEMConstants.HTTP_MPOST)) { + String ns = getNextNs(); + connection.setRequestProperty("Man", "http://www.dmtf.org/cim/mapping/http/v1.0;ns=" + ns); + prefix = ns + "-"; + } + connection.setRequestProperty(prefix + "CIMProtocolVersion", "1.0"); + + if (pIsIndication) { + try { + connection.setRequestProperty("CIMExport", HttpHeader.encode("MethodRequest", "UTF-8", "US-ASCII")); + connection.setRequestProperty("CIMExportMethod", HttpHeader.encode("ExportIndication", "UTF-8", "US-ASCII")); + } catch (UnsupportedEncodingException e) { + logger.trace(Level.FINE, "Exception while encoding http header", e); + connection.setRequestProperty("CIMExport", "MethodRequest"); + connection.setRequestProperty("CIMExportMethod", "ExportIndication"); + } + } else { + connection.setRequestProperty(prefix + "CIMOperation", "MethodCall"); + try { + connection.setRequestProperty(prefix + "CIMMethod", HttpHeader.encode(pCimMethod, "UTF-8", "US-ASCII")); + } catch (UnsupportedEncodingException e) { + logger.trace(Level.FINE, "Exception while encoding http header", e); + connection.setRequestProperty(prefix + "CIMMethod", pCimMethod); + } + } + Iterator> iter = pHeader.iterator(); + while (iter.hasNext()) { + Entry entry = iter.next(); + connection.setRequestProperty(prefix + entry.getKey().toString(), entry.getValue().toString()); + } + + logger.exit(); + return connection; + } + + private String getNextNs() { + this.iNsCounter = (this.iNsCounter < 99) ? ++this.iNsCounter : 10; + return String.valueOf(this.iNsCounter); + } + + private HttpHeader parseHeaders(URLConnection pConnection) { + String man = pConnection.getHeaderField("Man"); + String opt = pConnection.getHeaderField("Opt"); + HttpHeader headers = new HttpHeader(); + int i; + String ns = null; + + HttpHeaderParser manOptHeader = null; + if (man != null && man.length() > 0) manOptHeader = new HttpHeaderParser(man); else if ( + opt != null && opt.length() > 0 + ) manOptHeader = new HttpHeaderParser(opt); + if (manOptHeader != null) ns = manOptHeader.getValue("ns"); + + if (ns != null) { + i = 0; + String key; + while ((key = pConnection.getHeaderFieldKey(++i)) != null) { + if (key.startsWith(ns + "-")) headers.addParsedField( + key.substring(3), + pConnection.getHeaderField(i) + ); else headers.addParsedField(key, pConnection.getHeaderField(i)); + } + } else { + i = 0; + String key; + while ((key = pConnection.getHeaderFieldKey(++i)) != null) { + headers.addParsedField(key, pConnection.getHeaderField(i)); + } + } + + return headers; + } + + private String getCharacterSet(HttpHeader pHeader) { + String contentType = pHeader.getField("Content-type"); + String charset = "UTF-8"; + if (contentType != null && contentType.length() > 0) { + HttpHeaderParser contentTypeHeader = new HttpHeaderParser(contentType); + charset = contentTypeHeader.getValue("charset", charset); + } + return charset; + } + + /** + * getIterator : get generic CloseableIterator + * + * @param + * : Type Parameter + * @param pStream + * : Input Stream Reader + * @param pPath + * : CIMObjectPath + * @return generic CloseableIterator + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws WBEMException + */ + + // :TODO : try to find solution of "unchecked" warning + @SuppressWarnings("unchecked") + private CloseableIterator getIterator(InputStreamReader pStream, CIMObjectPath pPath) + throws IOException, SAXException, ParserConfigurationException, WBEMException { + String parser = this.iConfiguration.getCimXmlParser(); + + CloseableIterator iter = null; + + if (WBEMConstants.SAX.equals(parser)) { + iter = new CloseableIteratorSAX(pStream, pPath); + } else if (WBEMConstants.PULL.equals(parser)) { + iter = new CloseableIteratorPULL(pStream, pPath); + } else if (WBEMConstants.DOM.equals(parser)) { + iter = new CloseableIteratorDOM(pStream, pPath); + } else { + throw new IllegalArgumentException("Invalid CIM-XML parser configured (\"" + parser + "\") "); + } + try { + // check for CIMExceptions + iter.hasNext(); + return (CloseableIterator) iter; + } catch (RuntimeException e) { + iter.close(); + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + throw (WBEMException) e.getCause(); + } + throw e; + } + } + + private EnumerateResponse getEnumerateResponse(InputStreamReader pStream, CIMObjectPath pPath) + throws IOException, SAXException, ParserConfigurationException, WBEMException { + String parser = this.iConfiguration.getCimXmlParser(); + + if (WBEMConstants.SAX.equals(parser)) return new EnumerateResponseSAX(pStream, pPath) + .getEnumResponse(); else if (WBEMConstants.PULL.equals(parser)) return new EnumerateResponsePULL(pStream, pPath) + .getEnumResponse(); else if (WBEMConstants.DOM.equals(parser)) return new EnumerateResponseDOM(pStream, pPath) + .getEnumResponse(); + + throw new IllegalArgumentException("Invalid CIM-XML parser configured (\"" + parser + "\") "); + } + + private CIMResponse getSingleResponse(InputStreamReader pStream, CIMObjectPath pLocalPath) throws WBEMException { + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + Document dom; + try { + // Using factory get an instance of document builder + DocumentBuilder db = dbf.newDocumentBuilder(); + // parse using builder to get DOM representation of the XML file + dom = db.parse(new InputSource(pStream)); + } catch (TrailerException e) { + throw e.getWBEMException(); + } catch (Exception e) { + String msg = "Exception occurred during DOM parsing!"; + logger.trace(Level.SEVERE, msg, e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, msg, null, e); + } + CIMXMLParserImpl.setLocalObjectPath(pLocalPath); + CIMMessage cimMsg; + try { + cimMsg = CIMXMLParserImpl.parseCIM(dom.getDocumentElement()); + } catch (CIMXMLParseException e) { + String msg = "Exception occurred during parseCIM!"; + logger.trace(Level.SEVERE, msg, e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, msg, null, e); + } + if (!(cimMsg instanceof CIMResponse)) { + String msg = "CIM message must be response!"; + logger.trace(Level.SEVERE, msg); + throw new WBEMException(msg); + } + return (CIMResponse) cimMsg; + } + + public Properties getLocalProperties() { + return this.iConfiguration.getLocalProperties(); + } + + public void setLocalProperties(Properties pProperties) { + this.iConfiguration.setLocalProperties(pProperties); + } + + public void setLocalProperty(String pKey, String pValue) { + this.iConfiguration.setLocalProperty(pKey, pValue); + } + + private synchronized void checkState() throws IllegalStateException { + if (this.iInitialized && !this.iClosed) return; + String state = this.iClosed ? "closed." : "not initialized."; + LogAndTraceBroker.getBroker().trace(Level.FINE, "Illegal state for operation: " + state); + throw new IllegalStateException("WBEMClient is " + state); + } + + public EnumerateResponse associatorPaths( + CIMObjectPath pObjectName, + String pAssociationClass, + String pResultClass, + String pRole, + String pResultRole, + String pFilterQueryLanguage, + String pFilterQuery, + UnsignedInteger32 pTimeout, + boolean pContinueOnError, + UnsignedInteger32 pMaxObjects + ) + throws WBEMException { + final String operation = "OpenAssociatorInstancePaths"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pObjectName == null || pObjectName.getNamespace() == null || pObjectName.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.OpenAssociatorInstancePaths_request( + doc, + pObjectName, + pAssociationClass, + pResultClass, + pRole, + pResultRole, + pFilterQueryLanguage, + pFilterQuery, + pTimeout, + pContinueOnError, + pMaxObjects + ) + ); + + InputStreamReader is = transmitRequest(operation, hh, doc); + + EnumerateResponse enumResp = getEnumerateResponse(is, pObjectName); + return enumResp; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public EnumerateResponse associators( + CIMObjectPath pObjectName, + String pAssocClass, + String pResultClass, + String pRole, + String pResultRole, + boolean pIncludeClassOrigin, + String[] pPropertyList, + String pFilterQueryLanguage, + String pFilterQuery, + UnsignedInteger32 pTimeout, + boolean pContinueOnError, + UnsignedInteger32 pMaxObjects + ) + throws WBEMException { + final String operation = "OpenAssociatorInstances"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pObjectName == null || pObjectName.getNamespace() == null || pObjectName.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.OpenAssociatorInstances_request( + doc, + pObjectName, + pAssocClass, + pResultClass, + pRole, + pResultRole, + pIncludeClassOrigin, + pPropertyList, + pFilterQueryLanguage, + pFilterQuery, + pTimeout, + pContinueOnError, + pMaxObjects + ) + ); + + InputStreamReader is = transmitRequest(operation, hh, doc); + + EnumerateResponse enumResp = getEnumerateResponse(is, pObjectName); + return enumResp; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public void closeEnumeration(CIMObjectPath pObjectName, String pEnumerationContext) throws WBEMException { + final String operation = "CloseEnumeration"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pObjectName == null || pObjectName.getNamespace() == null || pObjectName.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.CloseEnumeration_request(doc, pObjectName, pEnumerationContext) + ); + + InputStreamReader is = transmitRequest(operation, hh, doc); + + CloseableIterator iter = getIterator(is, pObjectName); + + // Check for exceptions + try { + iter.hasNext(); + } finally { + iter.close(); + } + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public EnumerateResponse enumerateInstancePaths( + CIMObjectPath pObjectName, + String pFilterQueryLanguage, + String pFilterQuery, + UnsignedInteger32 pTimeout, + boolean pContinueOnError, + UnsignedInteger32 pMaxObjects + ) + throws WBEMException { + final String operation = "OpenEnumerateInstancePaths"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pObjectName == null || pObjectName.getNamespace() == null || pObjectName.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.OpenEnumerateInstancePaths_request( + doc, + pObjectName, + pFilterQueryLanguage, + pFilterQuery, + pTimeout, + pContinueOnError, + pMaxObjects + ) + ); + + InputStreamReader is = transmitRequest(operation, hh, doc); + + EnumerateResponse enumResp = getEnumerateResponse(is, pObjectName); + return enumResp; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public EnumerateResponse enumerateInstances( + CIMObjectPath pObjectName, + boolean pDeepInheritance, + boolean pIncludeClassOrigin, + String[] pPropertyList, + String pFilterQueryLanguage, + String pFilterQuery, + UnsignedInteger32 pTimeout, + boolean pContinueOnError, + UnsignedInteger32 pMaxObjects + ) + throws WBEMException { + final String operation = "OpenEnumerateInstances"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pObjectName == null || pObjectName.getNamespace() == null || pObjectName.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.OpenEnumerateInstances_request( + doc, + pObjectName, + pDeepInheritance, + pIncludeClassOrigin, + pPropertyList, + pFilterQueryLanguage, + pFilterQuery, + pTimeout, + pContinueOnError, + pMaxObjects + ) + ); + + InputStreamReader is = transmitRequest(operation, hh, doc); + EnumerateResponse enumResp = getEnumerateResponse(is, pObjectName); + return enumResp; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + // not supported yet + public UnsignedInteger64 enumerationCount(CIMObjectPath pObjectName, String pEnumerationContext) + throws WBEMException { + final String operation = "EnumerationCount"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pObjectName == null || pObjectName.getNamespace() == null || pObjectName.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.EnumerationCount_request(doc, pObjectName, pEnumerationContext) + ); + + InputStreamReader is = transmitRequest(operation, hh, doc); + // Currently this is not supported by server. Server returns + // error : "CIM_ERR_NOT_SUPPORTED" + // This error is caught by parser and exception is thrown + + getEnumerateResponse(is, pObjectName); + // Error mentioned above will go away if server starts to support + // EnumerationCount, we need to update code i.e. remove exception + // and return UnsignedInteger64 + + // this exception will be thrown only if server starts to support + // enumerationCount + throw new WBEMException(operation + " is currently not supported by client"); + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public EnumerateResponse execQueryInstances( + CIMObjectPath pObjectName, + String pFilterQuery, + String pFilterQueryLanguage, + boolean pReturnQueryResultClass, + UnsignedInteger32 pTimeout, + boolean pContinueOnError, + UnsignedInteger32 pMaxObjects, + CIMClass pQueryResultClass + ) + throws WBEMException { + final String operation = "OpenQueryInstances"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pObjectName == null || pObjectName.getNamespace() == null || pObjectName.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.OpenQueryInstances_request( + doc, + pObjectName, + pFilterQuery, + pFilterQueryLanguage, + pReturnQueryResultClass, + pTimeout, + pContinueOnError, + pMaxObjects, + pQueryResultClass + ) + ); + + InputStreamReader is = transmitRequest(operation, hh, doc); + EnumerateResponse enumResp = getEnumerateResponse(is, pObjectName); + return enumResp; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public EnumerateResponse getInstancePaths( + CIMObjectPath pObjectName, + String pContext, + UnsignedInteger32 pMaxObjects + ) + throws WBEMException { + final String operation = "PullInstancePaths"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pObjectName == null || pObjectName.getNamespace() == null || pObjectName.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.PullInstancePaths_request(doc, pObjectName, pContext, pMaxObjects) + ); + + InputStreamReader is = transmitRequest(operation, hh, doc); + EnumerateResponse enumResp = getEnumerateResponse(is, pObjectName); + return enumResp; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public EnumerateResponse getInstances( + CIMObjectPath pObjectName, + String pContext, + UnsignedInteger32 pMaxObjects + ) + throws WBEMException { + final String operation = "PullInstances"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pObjectName == null || pObjectName.getNamespace() == null || pObjectName.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.PullInstances_request(doc, pObjectName, pContext, pMaxObjects) + ); + + InputStreamReader is = transmitRequest(operation, hh, doc); + EnumerateResponse enumResp = getEnumerateResponse(is, pObjectName); + return enumResp; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public EnumerateResponse getInstancesWithPath( + CIMObjectPath pObjectName, + String pContext, + UnsignedInteger32 pMaxObjects + ) + throws WBEMException { + final String operation = "PullInstancesWithPath"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pObjectName == null || pObjectName.getNamespace() == null || pObjectName.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.PullInstancesWithPath_request(doc, pObjectName, pContext, pMaxObjects) + ); + + InputStreamReader is = transmitRequest(operation, hh, doc); + EnumerateResponse enumResp = getEnumerateResponse(is, pObjectName); + return enumResp; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public EnumerateResponse referencePaths( + CIMObjectPath pObjectName, + String pResultClass, + String pRole, + String pFilterQueryLanguage, + String pFilterQuery, + UnsignedInteger32 pTimeout, + boolean pContinueOnError, + UnsignedInteger32 pMaxObjects + ) + throws WBEMException { + final String operation = "OpenReferenceInstancePaths"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pObjectName == null || pObjectName.getNamespace() == null || pObjectName.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.OpenReferenceInstancePaths_request( + doc, + pObjectName, + pResultClass, + pRole, + pFilterQueryLanguage, + pFilterQuery, + pTimeout, + pContinueOnError, + pMaxObjects + ) + ); + + InputStreamReader is = transmitRequest(operation, hh, doc); + EnumerateResponse enumResp = getEnumerateResponse(is, pObjectName); + return enumResp; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + public EnumerateResponse references( + CIMObjectPath pObjectName, + String pResultClass, + String pRole, + boolean pIncludeClassOrigin, + String[] pPropertyList, + String pFilterQueryLanguage, + String pFilterQuery, + UnsignedInteger32 pTimeout, + boolean pContinueOnError, + UnsignedInteger32 pMaxObjects + ) + throws WBEMException { + final String operation = "OpenReferenceInstances"; + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if (pObjectName == null || pObjectName.getNamespace() == null || pObjectName.getObjectName() == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); + } + + HttpHeader hh = new HttpHeader(); + hh.addField("CIMObject", HttpHeader.encode(pObjectName.getNamespace(), "UTF-8", "US-ASCII")); + + Document doc = this.iXmlHelper.newDocument(); + + this.iXmlHelper.createCIMMessage( + doc, + this.iXmlHelper.OpenReferenceInstances_request( + doc, + pObjectName, + pResultClass, + pRole, + pIncludeClassOrigin, + pPropertyList, + pFilterQueryLanguage, + pFilterQuery, + pTimeout, + pContinueOnError, + pMaxObjects + ) + ); + + InputStreamReader is = transmitRequest(operation, hh, doc); + EnumerateResponse enumResp = getEnumerateResponse(is, pObjectName); + return enumResp; + } catch (WBEMException e) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, operation + " request resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, operation + " request failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } + + private InputStreamReader transmitIndicationRequest( + URI pRecipient, + HttpClientPool pClientPool, + HttpHeader pHeader, + Document pDocument + ) + throws IOException, ProtocolException, WBEMException { + return transmitRequestWorker(true, pRecipient, pClientPool, null, pHeader, pDocument); + } + + public boolean sendIndication(URI pRecipient, CIMInstance pIndication) throws WBEMException { + final LogAndTraceBroker logger = LogAndTraceBroker.getBroker(); + logger.entry(); + + checkState(); + + try { + if ( + pRecipient == null || + pRecipient.getScheme() == null || + pRecipient.getHost() == null || + pRecipient.getPort() <= 0 + ) { + throw new WBEMException( + WBEMException.CIM_ERR_INVALID_PARAMETER, + "Invalid recipient URI, must contain valid scheme://host:port" + ); + } + + if ( + !pRecipient.getScheme().equalsIgnoreCase(WBEMConstants.HTTP) && + !pRecipient.getScheme().equalsIgnoreCase(WBEMConstants.HTTPS) + ) throw new WBEMException( + WBEMException.CIM_ERR_INVALID_PARAMETER, + "Invalid scheme " + pRecipient.getScheme() + ", must be http or https" + ); + + if (pIndication == null) { + throw new WBEMException(WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid indication, must not be null"); + } + + logger.trace( + Level.FINER, + "Attempting to send following indication to " + pRecipient.toString() + ":\n" + pIndication.toString() + ); + + HttpHeader hh = new HttpHeader(); + + Document doc = this.iXmlHelper.newDocument(); + + this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.sendIndication_request(doc, pIndication)); + + HttpClientPool indPool = new HttpClientPool(this.iConfiguration); + + InputStreamReader is = transmitIndicationRequest(pRecipient, indPool, hh, doc); + + boolean success = false; + if (is != null) { + CIMResponse response = getSingleResponse(is, null); + success = response != null && response.isSuccessful(); + } + + indPool.closePool(); + + return success; + } catch (WBEMException e) { + logger.trace(Level.FINE, "Sending indication resulted in CIM Error", e); + throw e; + } catch (Exception e) { + if (e.getCause() != null && e.getCause() instanceof WBEMException) { + logger.trace(Level.FINE, "Sending indication resulted in CIM Error", e.getCause()); + throw (WBEMException) e.getCause(); + } + logger.trace(Level.FINE, "Sending indication failed", e); + throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e); + } finally { + logger.exit(); + } + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/indications/CIMEvent.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/indications/CIMEvent.java similarity index 74% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/indications/CIMEvent.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/indications/CIMEvent.java index 5b5fce7..dd4f17a 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/indications/CIMEvent.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/indications/CIMEvent.java @@ -1,133 +1,129 @@ -/* - CIMEvent.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------ - * 17931 2005-07-28 thschaef Add InetAddress field - * + constructor and getter - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.indications; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.net.InetAddress; - -import org.sentrysoftware.wbem.javax.cim.CIMInstance; - -/** - * Class CIMEvent is required for indication handling. - * - */ -public class CIMEvent { - - protected CIMInstance iIndication; - - protected String iID; - - protected InetAddress iInetAddress = null; - - /** - * Ctor. - * - * @param pIndication - */ - public CIMEvent(CIMInstance pIndication) { - this(pIndication, null); - } - - /** - * Ctor. - * - * @param pIndication - * @param id - */ - public CIMEvent(CIMInstance pIndication, String id) { - this.iIndication = pIndication; - this.iID = id; - } - - /** - * Constructor that takes the CIMInstance of the indication, the id as well - * as the InetAddress of the remote machine. - * - * @param pIndication - * The indication instance - * @param pId - * The id - * @param pInetAddress - * The address - */ - public CIMEvent(CIMInstance pIndication, String pId, InetAddress pInetAddress) { - this.iIndication = pIndication; - this.iID = pId; - this.iInetAddress = pInetAddress; - } - - /** - * This method returns the InetAddress of the machine that hosts the CIM - * Agent that sent the indication. Be aware the remote machine could have - * multiple network adapters - thus the result can be ambiguous. - * - * @return The InetAddress of the remote machine - */ - public InetAddress getInetAddress() { - return this.iInetAddress; - } - - /** - * getIndication - * - * @return CIMInstance - */ - public CIMInstance getIndication() { - return this.iIndication; - } - - /** - * getID - * - * @return String - */ - public String getID() { - return this.iID; - } -} +/* + CIMEvent.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------ + * 17931 2005-07-28 thschaef Add InetAddress field + * + constructor and getter + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.indications; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.net.InetAddress; +import org.metricshub.wbem.javax.cim.CIMInstance; + +/** + * Class CIMEvent is required for indication handling. + * + */ +public class CIMEvent { + protected CIMInstance iIndication; + + protected String iID; + + protected InetAddress iInetAddress = null; + + /** + * Ctor. + * + * @param pIndication + */ + public CIMEvent(CIMInstance pIndication) { + this(pIndication, null); + } + + /** + * Ctor. + * + * @param pIndication + * @param id + */ + public CIMEvent(CIMInstance pIndication, String id) { + this.iIndication = pIndication; + this.iID = id; + } + + /** + * Constructor that takes the CIMInstance of the indication, the id as well + * as the InetAddress of the remote machine. + * + * @param pIndication + * The indication instance + * @param pId + * The id + * @param pInetAddress + * The address + */ + public CIMEvent(CIMInstance pIndication, String pId, InetAddress pInetAddress) { + this.iIndication = pIndication; + this.iID = pId; + this.iInetAddress = pInetAddress; + } + + /** + * This method returns the InetAddress of the machine that hosts the CIM + * Agent that sent the indication. Be aware the remote machine could have + * multiple network adapters - thus the result can be ambiguous. + * + * @return The InetAddress of the remote machine + */ + public InetAddress getInetAddress() { + return this.iInetAddress; + } + + /** + * getIndication + * + * @return CIMInstance + */ + public CIMInstance getIndication() { + return this.iIndication; + } + + /** + * getID + * + * @return String + */ + public String getID() { + return this.iID; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/indications/CIMEventDispatcher.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/indications/CIMEventDispatcher.java similarity index 66% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/indications/CIMEventDispatcher.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/indications/CIMEventDispatcher.java index 811e56d..0f14f63 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/indications/CIMEventDispatcher.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/indications/CIMEventDispatcher.java @@ -1,209 +1,218 @@ -/* - CIMEventDispatcher.java - - (C) Copyright IBM Corp. 2005, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1498927 2006-06-01 lupusalex Fill gaps in logging coverage - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 3477087 2012-01-23 blaschke-oss Need Access to an Indication Sender's IP Address - * 2628 2013-03-26 blaschke-oss Limit size of LinkedList of CIMEvents to be dispatched - */ -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.indications; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.EventListener; -import java.util.LinkedList; -import java.util.logging.Level; - -import org.sentrysoftware.wbem.javax.wbem.listener.IndicationListener; - -import org.sentrysoftware.wbem.sblim.cimclient.IndicationListenerSBLIM; -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; - -/** - * Class CIMEventDispatcher is required for indication handling. - * - */ -public class CIMEventDispatcher extends Thread { - - protected LinkedList iEventQueue = new LinkedList(); - - protected EventListener iListener = null; - - private boolean iAlive = true; - - private int iMaxEvents = 0; - - private LogAndTraceBroker iLogger = LogAndTraceBroker.getBroker(); - - /** - * Construct a CIMEventDispatcher object which distributes CIMEvents to the - * appropriate CIMListener. The EventListener must be an instance of - * IndicationListener or IndicationListenerSBLIM. - * - * @param pListener - * The CIMListener (IndicationListener or - * IndicationListenerSBLIM) which receives the CIMEvents to be - * dispatched. - */ - public CIMEventDispatcher(EventListener pListener) { - this(pListener, 0); - } - - /** - * Construct a CIMEventDispatcher object which distributes CIMEvents to the - * appropriate CIMListener. The EventListener must be an instance of - * IndicationListener or IndicationListenerSBLIM. - * - * @param pListener - * The CIMListener (IndicationListener or - * IndicationListenerSBLIM) which receives the CIMEvents to be - * dispatched. - * @param pMaxEvents - * The maximum number of CIMEvents waiting to be dispatched. - */ - public CIMEventDispatcher(EventListener pListener, int pMaxEvents) { - if (!(pListener instanceof IndicationListener) - && !(pListener instanceof IndicationListenerSBLIM)) throw new IllegalArgumentException( - "Listener must be instance of IndicationListener or IndicationListenerSBLIM"); - this.iListener = pListener; - this.iMaxEvents = pMaxEvents; - setDaemon(true); - setName("CIMEventDispatcher"); - start(); - } - - /** - * Propagates the CIMEvent to the event consumers. - * - * @param pEvent - * The CIMEvent to be dispatched. - */ - public synchronized void dispatchEvent(CIMEvent pEvent) { - - if (pEvent != null) { - if (this.iMaxEvents > 0) { - int size = this.iEventQueue.size(); - if (size >= this.iMaxEvents) { - for (int i = size - this.iMaxEvents + 1; i > 0; i--) { - CIMEvent event = this.iEventQueue.remove(0); - this.iLogger.trace(Level.FINE, "Deleted CIMEvent (id=" + event.getID() - + ") from the queue (maximum size of " + this.iMaxEvents - + " reached)"); - } - } - } - this.iEventQueue.add(pEvent); - this.iLogger.trace(Level.FINE, "Added CIMEvent (id=" + pEvent.getID() - + ") to the queue (" + this.iEventQueue.size() + " elements total)"); - notify(); - } else { - this.iLogger.trace(Level.WARNING, "CIMEvent to dispatch was null"); - } - } - - /** - * Starts the dispatching engine of the CIMEventDispatcher. - * - */ - public synchronized void startup() { - this.iAlive = true; - start(); - } - - /** - * Stops the dispatching of events. - */ - public synchronized void kill() { - this.iAlive = false; - notify(); - } - - /** - * close - */ - public synchronized void close() { - kill(); - } - - private synchronized CIMEvent getEvent() { - CIMEvent event = null; - while (event == null) { - try { - if (this.iEventQueue.size() == 0) wait(); - } catch (InterruptedException e) { /**/} - if (!this.iAlive) break; - if (this.iEventQueue.size() > 0) { - event = this.iEventQueue.remove(0); - this.iLogger.trace(Level.FINER, "Removed CIMEvent (id=" + event.getID() - + ") from the queue (" + this.iEventQueue.size() + " elements left)"); - } - } - return event; - } - - @Override - public void run() { - while (this.iAlive) { - try { - CIMEvent event = getEvent(); - if (event != null) { - this.iLogger.trace(Level.FINER, "Processing CIMEvent (id=" + event.getID() - + ")"); - try { - if (this.iListener instanceof IndicationListener) ((IndicationListener) this.iListener) - .indicationOccured(event.getID(), event.getIndication()); - else // if instanceof IndicationListenerSBLIM) - ((IndicationListenerSBLIM) this.iListener).indicationOccured(event.getID(), - event.getIndication(), event.getInetAddress()); - } catch (Throwable t) { - this.iLogger.trace(Level.FINE, "Exception caught in listener (" - + this.iListener.getClass().getName() - + ") while processing CIMEvent", t); - } - } - } catch (Throwable t) { - this.iLogger.trace(Level.FINE, "Exception in event dispatcher loop", t); - } - } - } -} +/* + CIMEventDispatcher.java + + (C) Copyright IBM Corp. 2005, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1498927 2006-06-01 lupusalex Fill gaps in logging coverage + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 3477087 2012-01-23 blaschke-oss Need Access to an Indication Sender's IP Address + * 2628 2013-03-26 blaschke-oss Limit size of LinkedList of CIMEvents to be dispatched + */ +package org.metricshub.wbem.sblim.cimclient.internal.wbem.indications; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.EventListener; +import java.util.LinkedList; +import java.util.logging.Level; +import org.metricshub.wbem.javax.wbem.listener.IndicationListener; +import org.metricshub.wbem.sblim.cimclient.IndicationListenerSBLIM; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; + +/** + * Class CIMEventDispatcher is required for indication handling. + * + */ +public class CIMEventDispatcher extends Thread { + protected LinkedList iEventQueue = new LinkedList(); + + protected EventListener iListener = null; + + private boolean iAlive = true; + + private int iMaxEvents = 0; + + private LogAndTraceBroker iLogger = LogAndTraceBroker.getBroker(); + + /** + * Construct a CIMEventDispatcher object which distributes CIMEvents to the + * appropriate CIMListener. The EventListener must be an instance of + * IndicationListener or IndicationListenerSBLIM. + * + * @param pListener + * The CIMListener (IndicationListener or + * IndicationListenerSBLIM) which receives the CIMEvents to be + * dispatched. + */ + public CIMEventDispatcher(EventListener pListener) { + this(pListener, 0); + } + + /** + * Construct a CIMEventDispatcher object which distributes CIMEvents to the + * appropriate CIMListener. The EventListener must be an instance of + * IndicationListener or IndicationListenerSBLIM. + * + * @param pListener + * The CIMListener (IndicationListener or + * IndicationListenerSBLIM) which receives the CIMEvents to be + * dispatched. + * @param pMaxEvents + * The maximum number of CIMEvents waiting to be dispatched. + */ + public CIMEventDispatcher(EventListener pListener, int pMaxEvents) { + if ( + !(pListener instanceof IndicationListener) && !(pListener instanceof IndicationListenerSBLIM) + ) throw new IllegalArgumentException("Listener must be instance of IndicationListener or IndicationListenerSBLIM"); + this.iListener = pListener; + this.iMaxEvents = pMaxEvents; + setDaemon(true); + setName("CIMEventDispatcher"); + start(); + } + + /** + * Propagates the CIMEvent to the event consumers. + * + * @param pEvent + * The CIMEvent to be dispatched. + */ + public synchronized void dispatchEvent(CIMEvent pEvent) { + if (pEvent != null) { + if (this.iMaxEvents > 0) { + int size = this.iEventQueue.size(); + if (size >= this.iMaxEvents) { + for (int i = size - this.iMaxEvents + 1; i > 0; i--) { + CIMEvent event = this.iEventQueue.remove(0); + this.iLogger.trace( + Level.FINE, + "Deleted CIMEvent (id=" + + event.getID() + + ") from the queue (maximum size of " + + this.iMaxEvents + + " reached)" + ); + } + } + } + this.iEventQueue.add(pEvent); + this.iLogger.trace( + Level.FINE, + "Added CIMEvent (id=" + pEvent.getID() + ") to the queue (" + this.iEventQueue.size() + " elements total)" + ); + notify(); + } else { + this.iLogger.trace(Level.WARNING, "CIMEvent to dispatch was null"); + } + } + + /** + * Starts the dispatching engine of the CIMEventDispatcher. + * + */ + public synchronized void startup() { + this.iAlive = true; + start(); + } + + /** + * Stops the dispatching of events. + */ + public synchronized void kill() { + this.iAlive = false; + notify(); + } + + /** + * close + */ + public synchronized void close() { + kill(); + } + + private synchronized CIMEvent getEvent() { + CIMEvent event = null; + while (event == null) { + try { + if (this.iEventQueue.size() == 0) wait(); + } catch (InterruptedException e) { + /**/ + } + if (!this.iAlive) break; + if (this.iEventQueue.size() > 0) { + event = this.iEventQueue.remove(0); + this.iLogger.trace( + Level.FINER, + "Removed CIMEvent (id=" + event.getID() + ") from the queue (" + this.iEventQueue.size() + " elements left)" + ); + } + } + return event; + } + + @Override + public void run() { + while (this.iAlive) { + try { + CIMEvent event = getEvent(); + if (event != null) { + this.iLogger.trace(Level.FINER, "Processing CIMEvent (id=" + event.getID() + ")"); + try { + if (this.iListener instanceof IndicationListener) ((IndicationListener) this.iListener).indicationOccured( + event.getID(), + event.getIndication() + ); else ((IndicationListenerSBLIM) this.iListener).indicationOccured( // if instanceof IndicationListenerSBLIM) + event.getID(), + event.getIndication(), + event.getInetAddress() + ); + } catch (Throwable t) { + this.iLogger.trace( + Level.FINE, + "Exception caught in listener (" + this.iListener.getClass().getName() + ") while processing CIMEvent", + t + ); + } + } + } catch (Throwable t) { + this.iLogger.trace(Level.FINE, "Exception in event dispatcher loop", t); + } + } + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/indications/CIMIndicationHandler.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/indications/CIMIndicationHandler.java similarity index 74% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/indications/CIMIndicationHandler.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/indications/CIMIndicationHandler.java index bb955c2..d22c534 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/indications/CIMIndicationHandler.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/indications/CIMIndicationHandler.java @@ -1,830 +1,845 @@ -/* - (C) Copyright IBM Corp. 2005, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 17931 2005-07-28 thschaef Add InetAddress to CIM Event - * 1438152 2006-05-15 lupusalex Wrong message ID in ExportResponseMessage - * 1498938 2006-06-01 lupusalex Multiple events in single cim-xml request are not handled - * 1498130 2006-05-31 lupusalex Selection of xml parser on a per connection basis - * 1535756 2006-08-07 lupusalex Make code warning free - * 1565892 2006-11-16 lupusalex Make SBLIM client JSR48 compliant - * 1656285 2007-02-12 ebak IndicationHandler does not accept non-Integer message ID - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2714989 2009-03-26 blaschke-oss Code cleanup from redundant null check et al - * 2901216 2009-12-01 blaschke-oss lost IndicationURL for IndcationListener.indicationOccured - * 3185818 2011-02-18 blaschke-oss indicationOccured URL incorrect - * 3186176 2011-02-18 blaschke-oss XML response for indication not traced - * 3185763 2011-02-25 blaschke-oss Reliable indication support - Phase 1 - * 3288721 2011-05-20 blaschke-oss Need the function of indication reordering - * 3304058 2011-05-20 blaschke-oss Use same date format in change history - * 3304953 2011-05-20 blaschke-oss Indication URL mapped to lower case - * 3374206 2011-07-22 blaschke-oss NullPointerException caused by Indication - * 3376657 2011-07-24 blaschke-oss Get reliable indication properties once - * 3390724 2011-08-12 blaschke-oss Problem with Reliable Indication support in the Listener - * 3459036 2011-12-13 blaschke-oss Linked list for RI queue not efficient for many LDs - * 3485074 2012-02-06 blaschke-oss An Indication trace request - * 3484022 2012-02-08 blaschke-oss Turn reliable indication mode on and off based on SC/SN - * 3492214 2012-02-23 blaschke-oss Add a SenderIPAddress property indications - * 3513228 2012-04-23 blaschke-oss Reliable Indications support can create lots of threads - * 3553858 2012-08-06 blaschke-oss Append duplicate HTTP header fields instead of replace - * 3554738 2012-08-16 blaschke-oss dump CIM xml by LogAndTraceBroker.trace() - * 3601894 2013-01-23 blaschke-oss Enhance HTTP and CIM-XML tracing - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.indications; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.net.InetAddress; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Map; -import java.util.Set; -import java.util.Vector; -import java.util.Map.Entry; -import java.util.logging.Level; - -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMInstance; -import org.sentrysoftware.wbem.javax.cim.CIMProperty; -import org.sentrysoftware.wbem.javax.wbem.WBEMException; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.ParserConfigurationException; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.CIMClientXML_HelperImpl; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.CIMRequest; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.CIMXMLBuilderImpl; -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.CIMXMLParserImpl; -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.HttpContentHandler; -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.HttpException; -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.HttpHeader; -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.HttpHeaderParser; -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.MessageReader; -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.MessageWriter; -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.HttpHeader.HeaderEntry; -import org.sentrysoftware.wbem.sblim.cimclient.internal.http.io.DebugInputStream; -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConfiguration; -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.WBEMConfigurationDefaults; -import org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.CIMError; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.InputSource; - -/** - * Handles the HTTP connections, providing the necessary interfaces for - * CIMListener server. - */ -public class CIMIndicationHandler extends HttpContentHandler { - - /** - * DataManager is responsible for background processing of the - * reliable indication queue and cache. - */ - private class DataManager extends Thread { - - private boolean iAlive = true; - - private LinkedList iLinkedList; - - private Hashtable iHashTable; - - public DataManager(LinkedList pServerList) { - this.iLinkedList = pServerList; - this.iHashTable = null; - setDaemon(true); - } - - public DataManager(Hashtable pServerTable) { - this.iLinkedList = null; - this.iHashTable = pServerTable; - setDaemon(true); - } - - @Override - public void run() { - while (this.iAlive) { - try { - if (this.iLinkedList != null) { - ServerListEntry entry; - Iterator iterator; - - iterator = this.iLinkedList.iterator(); - while (iterator.hasNext()) { - entry = iterator.next(); - IndicationServer server = entry.getIndicationServer(); - if (server != null) { - ReliableIndicationHandler handler = server.getRIHandler(); - if (handler != null) { - handler.processAll(); - } - } - } - } else if (this.iHashTable != null) { - Map.Entry entry; - Iterator> iterator; - - Set> set = this.iHashTable - .entrySet(); - if (set != null) { - iterator = set.iterator(); - while (iterator.hasNext()) { - entry = iterator.next(); - IndicationServer server = entry.getValue(); - if (server != null) { - ReliableIndicationHandler handler = server.getRIHandler(); - if (handler != null) { - handler.processAll(); - } - } - } - } - } - sleep(1000); - } catch (Throwable t) { - // Expected, ignore and try again - } - } - } - - public void stopRun() { - this.iAlive = false; - } - } - - /** - * IndicationServer represents an entry in the linked list or - * hash table of servers handled by this CIMIndicationHandler - * instance. Each entry in the list/table will have a unique - * serverIP/destinationURL pair along with its own - * ReliableIndicationHandler. This is done to handle multiple - * contexts from the same server. - * - * NOTE: Multiple contexts from the same server will not be handled - * correctly if the user creates multiple - * CIM_ListenerDestination instances with the same - * Destination property. While this is poor programming - * practice (two different instances with same pertinent information), the - * real issue is that there is no way for the Client to differentiate - * between a context switch and two different contexts if the - * serverIP/destinationURL are the same. This issue it is not covered by - * DSP1054 1.2. - */ - private class IndicationServer { - - private boolean iRIInitialized = false; - - private ReliableIndicationHandler iRIHandler; - - public IndicationServer() { - // initialize() does the work - } - - public void initialize(ReliableIndicationHandler pRIHandler) { - this.iRIInitialized = true; - this.iRIHandler = pRIHandler; - } - - public boolean isInitialized() { - return this.iRIInitialized; - } - - public ReliableIndicationHandler getRIHandler() { - return this.iRIHandler; - } - } - - /** - * ServerListEntry represents a physical entry within the - * linked list. An IndicationServer instance is extracted from - * the linked list by proceeding through each entry in the linked list - * looking for the corresponding server IP and destination URL. - */ - private class ServerListEntry { - - private InetAddress iInetAddress; - - private String iDestinationUrl; - - private IndicationServer iIndicationServer; - - public ServerListEntry(InetAddress pInetAddress, String pDestinationUrl) { - this.iInetAddress = pInetAddress; - this.iDestinationUrl = pDestinationUrl; - this.iIndicationServer = new IndicationServer(); - } - - public InetAddress getInetAddress() { - return this.iInetAddress; - } - - public String getDestinationUrl() { - return this.iDestinationUrl; - } - - public IndicationServer getIndicationServer() { - return this.iIndicationServer; - } - } - - /** - * ServerTableEntry represents a physical key within the hash - * table while the corresponding IndicationServer is the value - * associated with the key. The hash table key is comprised of a server IP - * and destination URL. - */ - private class ServerTableEntry { - - private InetAddress iInetAddress; - - private String iDestinationUrl; - - public ServerTableEntry(InetAddress pInetAddress, String pDestinationUrl) { - this.iInetAddress = pInetAddress; - this.iDestinationUrl = pDestinationUrl; - } - - public InetAddress getInetAddress() { - return this.iInetAddress; - } - - public String getDestinationUrl() { - return this.iDestinationUrl; - } - - @Override - public boolean equals(Object pObj) { - if (!(pObj instanceof ServerTableEntry)) return false; - ServerTableEntry that = (ServerTableEntry) pObj; - if (this.iInetAddress.equals(that.getInetAddress()) - && this.iDestinationUrl.equalsIgnoreCase(that.getDestinationUrl())) return true; - return false; - } - - @Override - public int hashCode() { - return (this.iInetAddress.hashCode()) ^ (this.iDestinationUrl.hashCode()); - } - } - - private CIMEventDispatcher iDispatcher = null; - - private int iMessageId = 0; - - private LogAndTraceBroker iLogger = LogAndTraceBroker.getBroker(); - - private WBEMConfiguration iSessionProperties; - - private boolean iReliableIndicationsDisabled = true; - - private int iHashtableCapacity = 0; // 0 -> linked list, >0 -> hash table - - private LinkedList iServerList; - - private Hashtable iServerTable; - - private String iIndicationTraceClass; - - private String iIndicationTraceProperties[]; - - private boolean iAddSenderIPAddress; - - private DataManager iDataManagerThread; - - /** - * Ctor. - * - * @param pDispatcher - */ - public CIMIndicationHandler(CIMEventDispatcher pDispatcher) { - this(pDispatcher, null); - } - - /** - * Ctor. - * - * @param pDispatcher - * @param pProperties - */ - public CIMIndicationHandler(CIMEventDispatcher pDispatcher, WBEMConfiguration pProperties) { - this.iDispatcher = pDispatcher; - this.iSessionProperties = (pProperties != null) ? pProperties : WBEMConfiguration - .getGlobalConfiguration(); - this.iReliableIndicationsDisabled = !this.iSessionProperties.isReliableIndicationEnabled(); - - // Initialize reliable indication support - if (!this.iReliableIndicationsDisabled) { - this.iHashtableCapacity = this.iSessionProperties - .getReliableIndicationHashtableCapacity(); - - // Validate ReliableIndicationHashtableCapacity property - if (this.iHashtableCapacity < 0 || this.iHashtableCapacity > 25000) { - this.iLogger.trace(Level.FINE, "ReliableIndicationHashtableCapacity of " - + this.iHashtableCapacity + " outside range, using default value"); - - this.iHashtableCapacity = Integer.valueOf( - WBEMConfigurationDefaults.LISTENER_RELIABLE_INDICATION_HASHTABLE_CAPACITY) - .intValue(); - } - - if (this.iHashtableCapacity == 0) { - this.iServerList = new LinkedList(); - this.iDataManagerThread = new DataManager(this.iServerList); - } else { - this.iServerTable = new Hashtable( - this.iHashtableCapacity); - this.iDataManagerThread = new DataManager(this.iServerTable); - } - - this.iDataManagerThread.start(); - } - - // Initialize indication trace, if any - String filter = this.iSessionProperties.getListenerIndicationTraceFilter(); - if (filter != null && filter.trim().length() > 0) { - // Format: [class:]property[,property]* - String properties; - - int colon = filter.indexOf(':'); - if (colon == -1) { - this.iIndicationTraceClass = null; - properties = filter; - } else { - this.iIndicationTraceClass = filter.substring(0, colon).trim().toLowerCase(); - properties = filter.substring(colon + 1).trim(); - } - - String[] props = properties.split(","); - if (props != null && props.length > 0) { - ArrayList a = new ArrayList(); - - for (int i = 0; i < props.length; i++) { - String prop = props[i].trim().toLowerCase(); - if (prop != null && prop.length() > 0) { - a.add(prop); - } - } - - if (a.size() > 0) { - this.iIndicationTraceProperties = a.toArray(new String[0]); - - if (this.iLogger.isLoggableTrace(Level.INFO)) { - StringBuilder msg = new StringBuilder( - "Indication trace enabled: class filter="); - - if (this.iIndicationTraceClass != null) { - msg.append("\""); - msg.append(this.iIndicationTraceClass); - msg.append("\""); - } else { - msg.append(""); - } - msg.append(", properties="); - for (int i = 0; i < this.iIndicationTraceProperties.length; i++) { - if (i > 0) msg.append(","); - msg.append("\""); - msg.append(this.iIndicationTraceProperties[i]); - msg.append("\""); - } - this.iLogger.trace(Level.INFO, msg.toString()); - } - } else { - this.iIndicationTraceProperties = null; - } - } - } - - this.iAddSenderIPAddress = this.iSessionProperties.getListenerAddSenderIPAddress(); - } - - @Override - protected void finalize() throws Throwable { - try { - close(); - } finally { - super.finalize(); - } - } - - @Override - public void close() { - if (this.iDataManagerThread != null) { - this.iDataManagerThread.stopRun(); - this.iDataManagerThread = null; - } - if (this.iDispatcher != null) { - this.iDispatcher.close(); - this.iDispatcher = null; - } - } - - /** - * getMsgID - * - * @return int - */ - public synchronized int getMsgID() { - this.iMessageId++; - if (this.iMessageId > 1000000) this.iMessageId = 0; - return this.iMessageId; - } - - private static HttpHeader processHeader(HttpHeader pHeader, MessageWriter pWriter) - throws HttpException { - - HttpHeader header = processHttpExtensions(pHeader); - String cimExport = header.getField("CIMExport"); - String cimOperation = header.getField("CIMOperation"); - - if (cimOperation != null && !"METHODCALL".equalsIgnoreCase(cimOperation)) { - pWriter.getHeader().addField("CIMError", "unsupported-operation"); - throw new HttpException(400, "Bad Request"); - } - if (cimExport != null && !"METHODREQUEST".equalsIgnoreCase(cimExport) - && !"EXPORTMETHODCALL".equalsIgnoreCase(cimExport)) { - pWriter.getHeader().addField("CIMError", "unsupported-operation"); - throw new HttpException(400, "Bad Request"); - } - if (cimOperation == null && cimExport == null) { - // TODO: verify the status returned by the server for this - // situation, is not defined on the spec - pWriter.getHeader().addField("CIMError", "unsupported-operation"); - throw new HttpException(400, "Bad Request"); - } - - return header; - } - - @Override - public void handleContent(MessageReader pReader, MessageWriter pWriter, - InetAddress pInetAddress, String pLocalAddress) throws HttpException, IOException { - - CIMError error = null; - - // TODO validate CIMHeaders! - HttpHeader inputHeader = pReader.getHeader(); - inputHeader = processHeader(inputHeader, pWriter); - LogAndTraceBroker.getBroker().trace(Level.FINER, - "Indication Request HTTP Headers= " + inputHeader.toString()); - String cimMethod = inputHeader.getField("CIMMethod"); - String cimExport = inputHeader.getField("CIMExport"); - - CIMRequest request = null; - CIMClientXML_HelperImpl xmlHelper = null; - - try { - xmlHelper = new CIMClientXML_HelperImpl(); - } catch (ParserConfigurationException e1) { - IOException e = new IOException("ParserConfigurationException"); - e.initCause(e1); - throw e; - } - - InputStream inputstream = null; - if ((this.iSessionProperties.isCimXmlTracingEnabled() && LogAndTraceBroker.getBroker() - .getXmlTraceStream() != null) - || LogAndTraceBroker.getBroker().isLoggableCIMXMLTrace(Level.FINEST)) { - inputstream = new DebugInputStream(pReader.getInputStream(), LogAndTraceBroker - .getBroker().getXmlTraceStream(), "indication request"); - } else { - inputstream = pReader.getInputStream(); - } - - request = parseDocument(xmlHelper, pReader, inputstream); - - if (request == null) throw new HttpException(400, "Bad Request"); - - if ((cimExport == null && !cimMethod.equalsIgnoreCase("Indication")) - || !request.isCIMExport()) { throw new HttpException(400, "Bad Request"); } - - error = dispatchIndications(pReader, pInetAddress, pLocalAddress, request); - - buildResponse(xmlHelper, pWriter, request, error); - } - - private CIMRequest parseDocument(CIMClientXML_HelperImpl xmlHelper, MessageReader pReader, - InputStream inputstream) throws HttpException { - - // TODO: integrate SAX parser and DOM parser - - Document doc = null; - try { - - doc = xmlHelper.parse(new InputSource(new InputStreamReader(inputstream, pReader - .getCharacterEncoding()))); - Element rootE = doc.getDocumentElement(); - return (CIMRequest) CIMXMLParserImpl.parseCIM(rootE); - } catch (Exception e) { - this.iLogger.trace(Level.WARNING, "exception while parsing the XML with DOM parser", e); - throw new HttpException(400, "Bad Request"); - } - } - - /** - * Returns the corresponding indication server if the server is already - * present in the linked list, otherwise appends the server to the linked - * list and returns the new entry. - * - * @param pInetAddress - * Address of indication server. - * @param pDestinationUrl - * Destination URL of indication. - * @return IndicationServer with given address. - */ - private IndicationServer getIndicationServerFromList(InetAddress pInetAddress, - String pDestinationUrl) { - ServerListEntry entry; - Iterator iterator = this.iServerList.iterator(); - while (iterator.hasNext()) { - entry = iterator.next(); - if (entry.getInetAddress().equals(pInetAddress) - && entry.getDestinationUrl().equalsIgnoreCase(pDestinationUrl)) return entry - .getIndicationServer(); - } - entry = new ServerListEntry(pInetAddress, pDestinationUrl); - this.iServerList.add(entry); - this.iLogger.trace(Level.FINE, "Creating reliable indication handler for server IP " - + entry.getInetAddress().toString() + ", destination URL " - + entry.getDestinationUrl() + " in linked list"); - - return entry.getIndicationServer(); - } - - /** - * Returns the corresponding indication server if the server is already - * present in the hash table, otherwise adds the server to the hash table - * and returns the new entry. - * - * @param pInetAddress - * Address of indication server. - * @param pDestinationUrl - * Destination URL of indication. - * @return IndicationServer with given address. - */ - private IndicationServer getIndicationServerFromTable(InetAddress pInetAddress, - String pDestinationUrl) { - ServerTableEntry key; - IndicationServer server; - - key = new ServerTableEntry(pInetAddress, pDestinationUrl); - server = this.iServerTable.get(key); - if (server == null) { - server = new IndicationServer(); - this.iServerTable.put(key, server); - this.iLogger.trace(Level.FINE, "Creating reliable indication handler for server IP " - + key.getInetAddress().toString() + ", destination URL " - + key.getDestinationUrl() + " in hash table"); - } - return server; - } - - /** - * deliverIndication handles reliable indications and returns a boolean - * indicating whether the indication should be delivered or not - * - * @param pIndication - * Indication. - * @param pId - * Indication destination URL. - * @param pInetAddress - * Indication server IP. - * @return true if indication should be delivered, - * false if ReliableIndicationHandler will - * deliver indication - */ - private synchronized boolean deliverIndication(CIMInstance pIndication, String pId, - InetAddress pInetAddress) { - IndicationServer server; - - // Each serverIP/destinationURL pair needs its own - // ReliableIndicationHandler in order to handle multiple contexts - if (this.iHashtableCapacity == 0) { - server = getIndicationServerFromList(pInetAddress, pId); - } else { - server = getIndicationServerFromTable(pInetAddress, pId); - } - - // Initialize if not yet done so - if (!server.isInitialized()) { - // Validate DeliveryRetryAttempts property - long attempts = this.iSessionProperties.getListenerDeliveryRetryAttempts(); - if (attempts <= 0 || attempts > 1000) { - this.iLogger.trace(Level.FINE, "DeliveryRetryAttempts of " + attempts - + " outside range, using default value"); - - attempts = Long.valueOf(WBEMConfigurationDefaults.LISTENER_DELIVERY_RETRY_ATTEMPTS) - .longValue(); - } - - // Validate DeliveryRetryInterval property - long interval = this.iSessionProperties.getListenerDeliveryRetryInterval(); - if (interval <= 0 || interval > 86400) { - this.iLogger.trace(Level.FINE, "DeliveryRetryInterval of " + interval - + " outside range, using default value"); - - interval = Long.valueOf(WBEMConfigurationDefaults.LISTENER_DELIVERY_RETRY_INTERVAL) - .longValue(); - } - - // Create new ReliableIndicationHandler for this - // CIMIndicationHandler - server.initialize(new ReliableIndicationHandler(this.iDispatcher, attempts * interval - * 10 * 1000)); - - this.iLogger - .trace(Level.FINE, "Reliable indication support enabled for IP " - + pInetAddress.getHostAddress() + " and URL " + pId - + ", DeliveryRetryAttempts=" + attempts + ", DeliveryRetryInterval=" - + interval); - } - - // Let ReliableIndicationHandler deliver it - server.getRIHandler().handleIndication(pIndication, pId, pInetAddress); - return false; - } - - private CIMError dispatchIndications(MessageReader pReader, InetAddress pInetAddress, - String pLocalAddress, CIMRequest request) { - try { - Vector paramValue = request.getParamValue(); - Iterator iter = paramValue.iterator(); - while (iter.hasNext()) { - Object cimEvent = iter.next(); - if (cimEvent instanceof CIMInstance) { - CIMInstance indicationInst = (CIMInstance) cimEvent; - - String path = pReader.getMethod().getFile(); - String id; - - if (path == null) { - id = pLocalAddress + "/"; - } else if (path.equalsIgnoreCase("/cimom")) { - id = path; - } else if (path.length() < 4 || !path.regionMatches(true, 0, "http", 0, 4)) { - if (path.startsWith("/")) { - id = pLocalAddress + path; - } else { - id = pLocalAddress + "/" + path; - } - } else /* path.startsWith("http") */{ - id = path; - } - - // Add SenderIPAddress property if enabled - if (this.iAddSenderIPAddress) { - int size = indicationInst.getPropertyCount(); - CIMProperty props[] = new CIMProperty[size + 1]; - for (int i = 0; i < size; i++) - props[i] = indicationInst.getProperty(i); - props[size] = new CIMProperty("SBLIMJCC_SenderIPAddress", - CIMDataType.STRING_T, pInetAddress.getHostAddress()); - indicationInst = new CIMInstance(indicationInst.getObjectPath(), props); - } - - // Do any user-requested indication tracing here - if (this.iIndicationTraceProperties != null - && this.iLogger.isLoggableTrace(Level.FINE) - && (this.iIndicationTraceClass == null || indicationInst.getClassName() - .toLowerCase().indexOf(this.iIndicationTraceClass) != -1)) { - StringBuilder msg = new StringBuilder("Received indication "); - msg.append(indicationInst.getClassName()); - msg.append(" from IP="); - String inet = pInetAddress.getHostAddress(); - msg.append(inet != null ? inet : ""); - msg.append(" to URL="); - msg.append(id); - msg.append(" with properties:"); - for (int i = 0; i < this.iIndicationTraceProperties.length; i++) { - msg.append(" "); - CIMProperty prop = indicationInst - .getProperty(this.iIndicationTraceProperties[i]); - if (prop == null) { - msg.append(this.iIndicationTraceProperties[i]); - msg.append(" not a property;"); - } else { - Object value = prop.getValue(); - if (value == null) { - msg.append(prop.getName()); - msg.append(" = ;"); - } else { - msg.append(prop.toString().trim()); - } - } - } - this.iLogger.trace(Level.FINE, msg.toString()); - } - - if (this.iReliableIndicationsDisabled - || deliverIndication(indicationInst, id, pInetAddress)) { - this.iDispatcher.dispatchEvent(new CIMEvent(indicationInst, id, - pInetAddress)); - } - } - } - return null; - } catch (Exception e) { - return new CIMError(new WBEMException(WBEMException.CIM_ERR_FAILED, "CIM_ERR_FAILED", - null, e)); - } - } - - private void buildResponse(CIMClientXML_HelperImpl xmlHelper, MessageWriter pWriter, - CIMRequest request, CIMError error) throws HttpException, IOException { - Document responseDoc = null; - try { - DocumentBuilder docBuilder = xmlHelper.getDocumentBuilder(); - responseDoc = docBuilder.newDocument(); - CIMXMLBuilderImpl.createIndication_response(responseDoc, request.getId(), error); - - } catch (Exception e) { - // TODO: check this error code, may not be appropriate - throw new HttpException(400, "Bad Request"); - } - if (this.iSessionProperties.isCimXmlTracingEnabled() - || this.iLogger.isLoggableCIMXMLTrace(Level.FINEST)) { - OutputStream pos = new ByteArrayOutputStream(); - CIMClientXML_HelperImpl.dumpDocument(pos, responseDoc, "indication response"); - OutputStream debugStream = this.iLogger.getXmlTraceStream(); - if (this.iSessionProperties.isCimXmlTracingEnabled() && debugStream != null) debugStream - .write(pos.toString().getBytes()); - if (this.iLogger.isLoggableCIMXMLTrace(Level.FINEST)) this.iLogger.traceCIMXML( - Level.FINEST, pos.toString(), true); - } - CIMClientXML_HelperImpl.serialize(pWriter.getOutputStream(), responseDoc); - pWriter.getHeader().addField("CIMExport", "MethodResponse"); - } - - private static HttpHeader processHttpExtensions(HttpHeader pOriginalHeader) { - String man = pOriginalHeader.getField("Man"); - String opt = pOriginalHeader.getField("Opt"); - HttpHeader headers = new HttpHeader(); - String ns = null; - - HttpHeaderParser manOptHeader = null; - if (man != null && man.length() > 0) manOptHeader = new HttpHeaderParser(man); - else if (opt != null && opt.length() > 0) manOptHeader = new HttpHeaderParser(opt); - if (manOptHeader != null) ns = manOptHeader.getValue("ns"); - - if (ns != null) { - - Iterator> iter = pOriginalHeader.iterator(); - String key; - while (iter.hasNext()) { - Entry entry = iter.next(); - if (entry != null) { - key = entry.getKey().toString(); - if (key.startsWith(ns + "-")) headers.addParsedField(key.substring(3), entry - .getValue().toString()); - else headers.addParsedField(key, entry.getValue().toString()); - } - } - } else { - headers = pOriginalHeader; - } - - return headers; - } - -} +/* + (C) Copyright IBM Corp. 2005, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 17931 2005-07-28 thschaef Add InetAddress to CIM Event + * 1438152 2006-05-15 lupusalex Wrong message ID in ExportResponseMessage + * 1498938 2006-06-01 lupusalex Multiple events in single cim-xml request are not handled + * 1498130 2006-05-31 lupusalex Selection of xml parser on a per connection basis + * 1535756 2006-08-07 lupusalex Make code warning free + * 1565892 2006-11-16 lupusalex Make SBLIM client JSR48 compliant + * 1656285 2007-02-12 ebak IndicationHandler does not accept non-Integer message ID + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2714989 2009-03-26 blaschke-oss Code cleanup from redundant null check et al + * 2901216 2009-12-01 blaschke-oss lost IndicationURL for IndcationListener.indicationOccured + * 3185818 2011-02-18 blaschke-oss indicationOccured URL incorrect + * 3186176 2011-02-18 blaschke-oss XML response for indication not traced + * 3185763 2011-02-25 blaschke-oss Reliable indication support - Phase 1 + * 3288721 2011-05-20 blaschke-oss Need the function of indication reordering + * 3304058 2011-05-20 blaschke-oss Use same date format in change history + * 3304953 2011-05-20 blaschke-oss Indication URL mapped to lower case + * 3374206 2011-07-22 blaschke-oss NullPointerException caused by Indication + * 3376657 2011-07-24 blaschke-oss Get reliable indication properties once + * 3390724 2011-08-12 blaschke-oss Problem with Reliable Indication support in the Listener + * 3459036 2011-12-13 blaschke-oss Linked list for RI queue not efficient for many LDs + * 3485074 2012-02-06 blaschke-oss An Indication trace request + * 3484022 2012-02-08 blaschke-oss Turn reliable indication mode on and off based on SC/SN + * 3492214 2012-02-23 blaschke-oss Add a SenderIPAddress property indications + * 3513228 2012-04-23 blaschke-oss Reliable Indications support can create lots of threads + * 3553858 2012-08-06 blaschke-oss Append duplicate HTTP header fields instead of replace + * 3554738 2012-08-16 blaschke-oss dump CIM xml by LogAndTraceBroker.trace() + * 3601894 2013-01-23 blaschke-oss Enhance HTTP and CIM-XML tracing + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.indications; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.InetAddress; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.Vector; +import java.util.logging.Level; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.ParserConfigurationException; +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMInstance; +import org.metricshub.wbem.javax.cim.CIMProperty; +import org.metricshub.wbem.javax.wbem.WBEMException; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.CIMClientXML_HelperImpl; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.CIMRequest; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.CIMXMLBuilderImpl; +import org.metricshub.wbem.sblim.cimclient.internal.cimxml.CIMXMLParserImpl; +import org.metricshub.wbem.sblim.cimclient.internal.http.HttpContentHandler; +import org.metricshub.wbem.sblim.cimclient.internal.http.HttpException; +import org.metricshub.wbem.sblim.cimclient.internal.http.HttpHeader; +import org.metricshub.wbem.sblim.cimclient.internal.http.HttpHeader.HeaderEntry; +import org.metricshub.wbem.sblim.cimclient.internal.http.HttpHeaderParser; +import org.metricshub.wbem.sblim.cimclient.internal.http.MessageReader; +import org.metricshub.wbem.sblim.cimclient.internal.http.MessageWriter; +import org.metricshub.wbem.sblim.cimclient.internal.http.io.DebugInputStream; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfiguration; +import org.metricshub.wbem.sblim.cimclient.internal.util.WBEMConfigurationDefaults; +import org.metricshub.wbem.sblim.cimclient.internal.wbem.CIMError; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.InputSource; + +/** + * Handles the HTTP connections, providing the necessary interfaces for + * CIMListener server. + */ +public class CIMIndicationHandler extends HttpContentHandler { + + /** + * DataManager is responsible for background processing of the + * reliable indication queue and cache. + */ + private class DataManager extends Thread { + private boolean iAlive = true; + + private LinkedList iLinkedList; + + private Hashtable iHashTable; + + public DataManager(LinkedList pServerList) { + this.iLinkedList = pServerList; + this.iHashTable = null; + setDaemon(true); + } + + public DataManager(Hashtable pServerTable) { + this.iLinkedList = null; + this.iHashTable = pServerTable; + setDaemon(true); + } + + @Override + public void run() { + while (this.iAlive) { + try { + if (this.iLinkedList != null) { + ServerListEntry entry; + Iterator iterator; + + iterator = this.iLinkedList.iterator(); + while (iterator.hasNext()) { + entry = iterator.next(); + IndicationServer server = entry.getIndicationServer(); + if (server != null) { + ReliableIndicationHandler handler = server.getRIHandler(); + if (handler != null) { + handler.processAll(); + } + } + } + } else if (this.iHashTable != null) { + Map.Entry entry; + Iterator> iterator; + + Set> set = this.iHashTable.entrySet(); + if (set != null) { + iterator = set.iterator(); + while (iterator.hasNext()) { + entry = iterator.next(); + IndicationServer server = entry.getValue(); + if (server != null) { + ReliableIndicationHandler handler = server.getRIHandler(); + if (handler != null) { + handler.processAll(); + } + } + } + } + } + sleep(1000); + } catch (Throwable t) { + // Expected, ignore and try again + } + } + } + + public void stopRun() { + this.iAlive = false; + } + } + + /** + * IndicationServer represents an entry in the linked list or + * hash table of servers handled by this CIMIndicationHandler + * instance. Each entry in the list/table will have a unique + * serverIP/destinationURL pair along with its own + * ReliableIndicationHandler. This is done to handle multiple + * contexts from the same server. + * + * NOTE: Multiple contexts from the same server will not be handled + * correctly if the user creates multiple + * CIM_ListenerDestination instances with the same + * Destination property. While this is poor programming + * practice (two different instances with same pertinent information), the + * real issue is that there is no way for the Client to differentiate + * between a context switch and two different contexts if the + * serverIP/destinationURL are the same. This issue it is not covered by + * DSP1054 1.2. + */ + private class IndicationServer { + private boolean iRIInitialized = false; + + private ReliableIndicationHandler iRIHandler; + + public IndicationServer() { + // initialize() does the work + } + + public void initialize(ReliableIndicationHandler pRIHandler) { + this.iRIInitialized = true; + this.iRIHandler = pRIHandler; + } + + public boolean isInitialized() { + return this.iRIInitialized; + } + + public ReliableIndicationHandler getRIHandler() { + return this.iRIHandler; + } + } + + /** + * ServerListEntry represents a physical entry within the + * linked list. An IndicationServer instance is extracted from + * the linked list by proceeding through each entry in the linked list + * looking for the corresponding server IP and destination URL. + */ + private class ServerListEntry { + private InetAddress iInetAddress; + + private String iDestinationUrl; + + private IndicationServer iIndicationServer; + + public ServerListEntry(InetAddress pInetAddress, String pDestinationUrl) { + this.iInetAddress = pInetAddress; + this.iDestinationUrl = pDestinationUrl; + this.iIndicationServer = new IndicationServer(); + } + + public InetAddress getInetAddress() { + return this.iInetAddress; + } + + public String getDestinationUrl() { + return this.iDestinationUrl; + } + + public IndicationServer getIndicationServer() { + return this.iIndicationServer; + } + } + + /** + * ServerTableEntry represents a physical key within the hash + * table while the corresponding IndicationServer is the value + * associated with the key. The hash table key is comprised of a server IP + * and destination URL. + */ + private class ServerTableEntry { + private InetAddress iInetAddress; + + private String iDestinationUrl; + + public ServerTableEntry(InetAddress pInetAddress, String pDestinationUrl) { + this.iInetAddress = pInetAddress; + this.iDestinationUrl = pDestinationUrl; + } + + public InetAddress getInetAddress() { + return this.iInetAddress; + } + + public String getDestinationUrl() { + return this.iDestinationUrl; + } + + @Override + public boolean equals(Object pObj) { + if (!(pObj instanceof ServerTableEntry)) return false; + ServerTableEntry that = (ServerTableEntry) pObj; + if ( + this.iInetAddress.equals(that.getInetAddress()) && + this.iDestinationUrl.equalsIgnoreCase(that.getDestinationUrl()) + ) return true; + return false; + } + + @Override + public int hashCode() { + return (this.iInetAddress.hashCode()) ^ (this.iDestinationUrl.hashCode()); + } + } + + private CIMEventDispatcher iDispatcher = null; + + private int iMessageId = 0; + + private LogAndTraceBroker iLogger = LogAndTraceBroker.getBroker(); + + private WBEMConfiguration iSessionProperties; + + private boolean iReliableIndicationsDisabled = true; + + private int iHashtableCapacity = 0; // 0 -> linked list, >0 -> hash table + + private LinkedList iServerList; + + private Hashtable iServerTable; + + private String iIndicationTraceClass; + + private String iIndicationTraceProperties[]; + + private boolean iAddSenderIPAddress; + + private DataManager iDataManagerThread; + + /** + * Ctor. + * + * @param pDispatcher + */ + public CIMIndicationHandler(CIMEventDispatcher pDispatcher) { + this(pDispatcher, null); + } + + /** + * Ctor. + * + * @param pDispatcher + * @param pProperties + */ + public CIMIndicationHandler(CIMEventDispatcher pDispatcher, WBEMConfiguration pProperties) { + this.iDispatcher = pDispatcher; + this.iSessionProperties = (pProperties != null) ? pProperties : WBEMConfiguration.getGlobalConfiguration(); + this.iReliableIndicationsDisabled = !this.iSessionProperties.isReliableIndicationEnabled(); + + // Initialize reliable indication support + if (!this.iReliableIndicationsDisabled) { + this.iHashtableCapacity = this.iSessionProperties.getReliableIndicationHashtableCapacity(); + + // Validate ReliableIndicationHashtableCapacity property + if (this.iHashtableCapacity < 0 || this.iHashtableCapacity > 25000) { + this.iLogger.trace( + Level.FINE, + "ReliableIndicationHashtableCapacity of " + this.iHashtableCapacity + " outside range, using default value" + ); + + this.iHashtableCapacity = + Integer.valueOf(WBEMConfigurationDefaults.LISTENER_RELIABLE_INDICATION_HASHTABLE_CAPACITY).intValue(); + } + + if (this.iHashtableCapacity == 0) { + this.iServerList = new LinkedList(); + this.iDataManagerThread = new DataManager(this.iServerList); + } else { + this.iServerTable = new Hashtable(this.iHashtableCapacity); + this.iDataManagerThread = new DataManager(this.iServerTable); + } + + this.iDataManagerThread.start(); + } + + // Initialize indication trace, if any + String filter = this.iSessionProperties.getListenerIndicationTraceFilter(); + if (filter != null && filter.trim().length() > 0) { + // Format: [class:]property[,property]* + String properties; + + int colon = filter.indexOf(':'); + if (colon == -1) { + this.iIndicationTraceClass = null; + properties = filter; + } else { + this.iIndicationTraceClass = filter.substring(0, colon).trim().toLowerCase(); + properties = filter.substring(colon + 1).trim(); + } + + String[] props = properties.split(","); + if (props != null && props.length > 0) { + ArrayList a = new ArrayList(); + + for (int i = 0; i < props.length; i++) { + String prop = props[i].trim().toLowerCase(); + if (prop != null && prop.length() > 0) { + a.add(prop); + } + } + + if (a.size() > 0) { + this.iIndicationTraceProperties = a.toArray(new String[0]); + + if (this.iLogger.isLoggableTrace(Level.INFO)) { + StringBuilder msg = new StringBuilder("Indication trace enabled: class filter="); + + if (this.iIndicationTraceClass != null) { + msg.append("\""); + msg.append(this.iIndicationTraceClass); + msg.append("\""); + } else { + msg.append(""); + } + msg.append(", properties="); + for (int i = 0; i < this.iIndicationTraceProperties.length; i++) { + if (i > 0) msg.append(","); + msg.append("\""); + msg.append(this.iIndicationTraceProperties[i]); + msg.append("\""); + } + this.iLogger.trace(Level.INFO, msg.toString()); + } + } else { + this.iIndicationTraceProperties = null; + } + } + } + + this.iAddSenderIPAddress = this.iSessionProperties.getListenerAddSenderIPAddress(); + } + + @Override + protected void finalize() throws Throwable { + try { + close(); + } finally { + super.finalize(); + } + } + + @Override + public void close() { + if (this.iDataManagerThread != null) { + this.iDataManagerThread.stopRun(); + this.iDataManagerThread = null; + } + if (this.iDispatcher != null) { + this.iDispatcher.close(); + this.iDispatcher = null; + } + } + + /** + * getMsgID + * + * @return int + */ + public synchronized int getMsgID() { + this.iMessageId++; + if (this.iMessageId > 1000000) this.iMessageId = 0; + return this.iMessageId; + } + + private static HttpHeader processHeader(HttpHeader pHeader, MessageWriter pWriter) throws HttpException { + HttpHeader header = processHttpExtensions(pHeader); + String cimExport = header.getField("CIMExport"); + String cimOperation = header.getField("CIMOperation"); + + if (cimOperation != null && !"METHODCALL".equalsIgnoreCase(cimOperation)) { + pWriter.getHeader().addField("CIMError", "unsupported-operation"); + throw new HttpException(400, "Bad Request"); + } + if ( + cimExport != null && + !"METHODREQUEST".equalsIgnoreCase(cimExport) && + !"EXPORTMETHODCALL".equalsIgnoreCase(cimExport) + ) { + pWriter.getHeader().addField("CIMError", "unsupported-operation"); + throw new HttpException(400, "Bad Request"); + } + if (cimOperation == null && cimExport == null) { + // TODO: verify the status returned by the server for this + // situation, is not defined on the spec + pWriter.getHeader().addField("CIMError", "unsupported-operation"); + throw new HttpException(400, "Bad Request"); + } + + return header; + } + + @Override + public void handleContent( + MessageReader pReader, + MessageWriter pWriter, + InetAddress pInetAddress, + String pLocalAddress + ) + throws HttpException, IOException { + CIMError error = null; + + // TODO validate CIMHeaders! + HttpHeader inputHeader = pReader.getHeader(); + inputHeader = processHeader(inputHeader, pWriter); + LogAndTraceBroker.getBroker().trace(Level.FINER, "Indication Request HTTP Headers= " + inputHeader.toString()); + String cimMethod = inputHeader.getField("CIMMethod"); + String cimExport = inputHeader.getField("CIMExport"); + + CIMRequest request = null; + CIMClientXML_HelperImpl xmlHelper = null; + + try { + xmlHelper = new CIMClientXML_HelperImpl(); + } catch (ParserConfigurationException e1) { + IOException e = new IOException("ParserConfigurationException"); + e.initCause(e1); + throw e; + } + + InputStream inputstream = null; + if ( + (this.iSessionProperties.isCimXmlTracingEnabled() && LogAndTraceBroker.getBroker().getXmlTraceStream() != null) || + LogAndTraceBroker.getBroker().isLoggableCIMXMLTrace(Level.FINEST) + ) { + inputstream = + new DebugInputStream( + pReader.getInputStream(), + LogAndTraceBroker.getBroker().getXmlTraceStream(), + "indication request" + ); + } else { + inputstream = pReader.getInputStream(); + } + + request = parseDocument(xmlHelper, pReader, inputstream); + + if (request == null) throw new HttpException(400, "Bad Request"); + + if ((cimExport == null && !cimMethod.equalsIgnoreCase("Indication")) || !request.isCIMExport()) { + throw new HttpException(400, "Bad Request"); + } + + error = dispatchIndications(pReader, pInetAddress, pLocalAddress, request); + + buildResponse(xmlHelper, pWriter, request, error); + } + + private CIMRequest parseDocument(CIMClientXML_HelperImpl xmlHelper, MessageReader pReader, InputStream inputstream) + throws HttpException { + // TODO: integrate SAX parser and DOM parser + + Document doc = null; + try { + doc = xmlHelper.parse(new InputSource(new InputStreamReader(inputstream, pReader.getCharacterEncoding()))); + Element rootE = doc.getDocumentElement(); + return (CIMRequest) CIMXMLParserImpl.parseCIM(rootE); + } catch (Exception e) { + this.iLogger.trace(Level.WARNING, "exception while parsing the XML with DOM parser", e); + throw new HttpException(400, "Bad Request"); + } + } + + /** + * Returns the corresponding indication server if the server is already + * present in the linked list, otherwise appends the server to the linked + * list and returns the new entry. + * + * @param pInetAddress + * Address of indication server. + * @param pDestinationUrl + * Destination URL of indication. + * @return IndicationServer with given address. + */ + private IndicationServer getIndicationServerFromList(InetAddress pInetAddress, String pDestinationUrl) { + ServerListEntry entry; + Iterator iterator = this.iServerList.iterator(); + while (iterator.hasNext()) { + entry = iterator.next(); + if ( + entry.getInetAddress().equals(pInetAddress) && entry.getDestinationUrl().equalsIgnoreCase(pDestinationUrl) + ) return entry.getIndicationServer(); + } + entry = new ServerListEntry(pInetAddress, pDestinationUrl); + this.iServerList.add(entry); + this.iLogger.trace( + Level.FINE, + "Creating reliable indication handler for server IP " + + entry.getInetAddress().toString() + + ", destination URL " + + entry.getDestinationUrl() + + " in linked list" + ); + + return entry.getIndicationServer(); + } + + /** + * Returns the corresponding indication server if the server is already + * present in the hash table, otherwise adds the server to the hash table + * and returns the new entry. + * + * @param pInetAddress + * Address of indication server. + * @param pDestinationUrl + * Destination URL of indication. + * @return IndicationServer with given address. + */ + private IndicationServer getIndicationServerFromTable(InetAddress pInetAddress, String pDestinationUrl) { + ServerTableEntry key; + IndicationServer server; + + key = new ServerTableEntry(pInetAddress, pDestinationUrl); + server = this.iServerTable.get(key); + if (server == null) { + server = new IndicationServer(); + this.iServerTable.put(key, server); + this.iLogger.trace( + Level.FINE, + "Creating reliable indication handler for server IP " + + key.getInetAddress().toString() + + ", destination URL " + + key.getDestinationUrl() + + " in hash table" + ); + } + return server; + } + + /** + * deliverIndication handles reliable indications and returns a boolean + * indicating whether the indication should be delivered or not + * + * @param pIndication + * Indication. + * @param pId + * Indication destination URL. + * @param pInetAddress + * Indication server IP. + * @return true if indication should be delivered, + * false if ReliableIndicationHandler will + * deliver indication + */ + private synchronized boolean deliverIndication(CIMInstance pIndication, String pId, InetAddress pInetAddress) { + IndicationServer server; + + // Each serverIP/destinationURL pair needs its own + // ReliableIndicationHandler in order to handle multiple contexts + if (this.iHashtableCapacity == 0) { + server = getIndicationServerFromList(pInetAddress, pId); + } else { + server = getIndicationServerFromTable(pInetAddress, pId); + } + + // Initialize if not yet done so + if (!server.isInitialized()) { + // Validate DeliveryRetryAttempts property + long attempts = this.iSessionProperties.getListenerDeliveryRetryAttempts(); + if (attempts <= 0 || attempts > 1000) { + this.iLogger.trace(Level.FINE, "DeliveryRetryAttempts of " + attempts + " outside range, using default value"); + + attempts = Long.valueOf(WBEMConfigurationDefaults.LISTENER_DELIVERY_RETRY_ATTEMPTS).longValue(); + } + + // Validate DeliveryRetryInterval property + long interval = this.iSessionProperties.getListenerDeliveryRetryInterval(); + if (interval <= 0 || interval > 86400) { + this.iLogger.trace(Level.FINE, "DeliveryRetryInterval of " + interval + " outside range, using default value"); + + interval = Long.valueOf(WBEMConfigurationDefaults.LISTENER_DELIVERY_RETRY_INTERVAL).longValue(); + } + + // Create new ReliableIndicationHandler for this + // CIMIndicationHandler + server.initialize(new ReliableIndicationHandler(this.iDispatcher, attempts * interval * 10 * 1000)); + + this.iLogger.trace( + Level.FINE, + "Reliable indication support enabled for IP " + + pInetAddress.getHostAddress() + + " and URL " + + pId + + ", DeliveryRetryAttempts=" + + attempts + + ", DeliveryRetryInterval=" + + interval + ); + } + + // Let ReliableIndicationHandler deliver it + server.getRIHandler().handleIndication(pIndication, pId, pInetAddress); + return false; + } + + private CIMError dispatchIndications( + MessageReader pReader, + InetAddress pInetAddress, + String pLocalAddress, + CIMRequest request + ) { + try { + Vector paramValue = request.getParamValue(); + Iterator iter = paramValue.iterator(); + while (iter.hasNext()) { + Object cimEvent = iter.next(); + if (cimEvent instanceof CIMInstance) { + CIMInstance indicationInst = (CIMInstance) cimEvent; + + String path = pReader.getMethod().getFile(); + String id; + + if (path == null) { + id = pLocalAddress + "/"; + } else if (path.equalsIgnoreCase("/cimom")) { + id = path; + } else if (path.length() < 4 || !path.regionMatches(true, 0, "http", 0, 4)) { + if (path.startsWith("/")) { + id = pLocalAddress + path; + } else { + id = pLocalAddress + "/" + path; + } + } else /* path.startsWith("http") */{ + id = path; + } + + // Add SenderIPAddress property if enabled + if (this.iAddSenderIPAddress) { + int size = indicationInst.getPropertyCount(); + CIMProperty props[] = new CIMProperty[size + 1]; + for (int i = 0; i < size; i++) props[i] = indicationInst.getProperty(i); + props[size] = + new CIMProperty("SBLIMJCC_SenderIPAddress", CIMDataType.STRING_T, pInetAddress.getHostAddress()); + indicationInst = new CIMInstance(indicationInst.getObjectPath(), props); + } + + // Do any user-requested indication tracing here + if ( + this.iIndicationTraceProperties != null && + this.iLogger.isLoggableTrace(Level.FINE) && + ( + this.iIndicationTraceClass == null || + indicationInst.getClassName().toLowerCase().indexOf(this.iIndicationTraceClass) != -1 + ) + ) { + StringBuilder msg = new StringBuilder("Received indication "); + msg.append(indicationInst.getClassName()); + msg.append(" from IP="); + String inet = pInetAddress.getHostAddress(); + msg.append(inet != null ? inet : ""); + msg.append(" to URL="); + msg.append(id); + msg.append(" with properties:"); + for (int i = 0; i < this.iIndicationTraceProperties.length; i++) { + msg.append(" "); + CIMProperty prop = indicationInst.getProperty(this.iIndicationTraceProperties[i]); + if (prop == null) { + msg.append(this.iIndicationTraceProperties[i]); + msg.append(" not a property;"); + } else { + Object value = prop.getValue(); + if (value == null) { + msg.append(prop.getName()); + msg.append(" = ;"); + } else { + msg.append(prop.toString().trim()); + } + } + } + this.iLogger.trace(Level.FINE, msg.toString()); + } + + if (this.iReliableIndicationsDisabled || deliverIndication(indicationInst, id, pInetAddress)) { + this.iDispatcher.dispatchEvent(new CIMEvent(indicationInst, id, pInetAddress)); + } + } + } + return null; + } catch (Exception e) { + return new CIMError(new WBEMException(WBEMException.CIM_ERR_FAILED, "CIM_ERR_FAILED", null, e)); + } + } + + private void buildResponse( + CIMClientXML_HelperImpl xmlHelper, + MessageWriter pWriter, + CIMRequest request, + CIMError error + ) + throws HttpException, IOException { + Document responseDoc = null; + try { + DocumentBuilder docBuilder = xmlHelper.getDocumentBuilder(); + responseDoc = docBuilder.newDocument(); + CIMXMLBuilderImpl.createIndication_response(responseDoc, request.getId(), error); + } catch (Exception e) { + // TODO: check this error code, may not be appropriate + throw new HttpException(400, "Bad Request"); + } + if (this.iSessionProperties.isCimXmlTracingEnabled() || this.iLogger.isLoggableCIMXMLTrace(Level.FINEST)) { + OutputStream pos = new ByteArrayOutputStream(); + CIMClientXML_HelperImpl.dumpDocument(pos, responseDoc, "indication response"); + OutputStream debugStream = this.iLogger.getXmlTraceStream(); + if (this.iSessionProperties.isCimXmlTracingEnabled() && debugStream != null) debugStream.write( + pos.toString().getBytes() + ); + if (this.iLogger.isLoggableCIMXMLTrace(Level.FINEST)) this.iLogger.traceCIMXML( + Level.FINEST, + pos.toString(), + true + ); + } + CIMClientXML_HelperImpl.serialize(pWriter.getOutputStream(), responseDoc); + pWriter.getHeader().addField("CIMExport", "MethodResponse"); + } + + private static HttpHeader processHttpExtensions(HttpHeader pOriginalHeader) { + String man = pOriginalHeader.getField("Man"); + String opt = pOriginalHeader.getField("Opt"); + HttpHeader headers = new HttpHeader(); + String ns = null; + + HttpHeaderParser manOptHeader = null; + if (man != null && man.length() > 0) manOptHeader = new HttpHeaderParser(man); else if ( + opt != null && opt.length() > 0 + ) manOptHeader = new HttpHeaderParser(opt); + if (manOptHeader != null) ns = manOptHeader.getValue("ns"); + + if (ns != null) { + Iterator> iter = pOriginalHeader.iterator(); + String key; + while (iter.hasNext()) { + Entry entry = iter.next(); + if (entry != null) { + key = entry.getKey().toString(); + if (key.startsWith(ns + "-")) headers.addParsedField( + key.substring(3), + entry.getValue().toString() + ); else headers.addParsedField(key, entry.getValue().toString()); + } + } + } else { + headers = pOriginalHeader; + } + + return headers; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/indications/RIHandlerTest.txt b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/indications/RIHandlerTest.txt similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/indications/RIHandlerTest.txt rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/indications/RIHandlerTest.txt diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/indications/ReliableIndicationHandler.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/indications/ReliableIndicationHandler.java similarity index 84% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/indications/ReliableIndicationHandler.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/indications/ReliableIndicationHandler.java index 2c8ec62..5b0f86f 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/indications/ReliableIndicationHandler.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/indications/ReliableIndicationHandler.java @@ -1,661 +1,673 @@ -/* - (C) Copyright IBM Corp. 2011, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Dave Blaschke, IBM, blaschke@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 3288721 2011-05-20 blaschke-oss Need the function of indication reordering - * 3376657 2011-07-24 blaschke-oss Get reliable indication properties once - * 3484022 2012-02-08 blaschke-oss Turn reliable indication mode on and off based on SC/SN - * 3513228 2012-04-23 blaschke-oss Reliable Indications support can create lots of threads - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.indications; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.net.InetAddress; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.logging.Level; - -import org.sentrysoftware.wbem.javax.cim.CIMInstance; -import org.sentrysoftware.wbem.javax.cim.CIMProperty; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; - -/** - * ReliableIndicationHandler is responsible for determining when to - * dispatch reliable indications, which includes queuing unexpected indications, - * caching all indications for the duration of their sequence identifier - * lifetime, and logging missing, duplicate and out-of-order indications. This - * functionality is based on the changes first introduced by DSP1054 v1.1. - * - * The handleIndication, areAllEmpty and - * processAll methods need to be synchronized because they are the - * entry points into ReliableIndicationHandler - the first is the - * public entry point that needs to be passed each and every reliable - * indication, the other two are only called by the DataManager thread and hence - * protected. All of the private methods are only called from one of the three - * synchronized methods. - * - * NOTE: ReliableIndicationHandler does NOT contain any logic for - * handling sequence number wrapping. It was deemed unnecessary because of the - * performance impact to each and every indication for a VERY rare occurrence: - * sequence numbers are longs (signed 64-bit integers) that are are supposed to - * start at 0, so even if the listener handled 1,000,00 indications per second, - * it would take over 292,471 years for the sequence number to wrap. - */ -public class ReliableIndicationHandler { - - /** - * ReliableIndication represents an entry in the indication - * delivery queue, and contains all the information required to manage and - * dispatch the indication. Entries in the queue are stored in order of - * increasing sequence number and are dispatched when the missing - * indication(s) arrive or their sequence identifier lifetime expires. Only - * one sequence context can be in the queue at any one time. - */ - private class ReliableIndication { - - private long iDiscardTime; - - private String iId; - - private CIMInstance iIndication; - - private InetAddress iInetAddress; - - private long iSequenceNumber; - - public ReliableIndication(CIMInstance pIndication, long pSequenceNumber, long pDiscardTime, - String pId, InetAddress pInetAddress) { - this.iIndication = pIndication; - this.iSequenceNumber = pSequenceNumber; - this.iDiscardTime = pDiscardTime; - this.iId = pId; - this.iInetAddress = pInetAddress; - } - - public long getDiscardTime() { - return this.iDiscardTime; - } - - public String getId() { - return this.iId; - } - - public CIMInstance getIndication() { - return this.iIndication; - } - - public InetAddress getInetAddress() { - return this.iInetAddress; - } - - public long getSequenceNumber() { - return this.iSequenceNumber; - } - } - - /** - * CacheEntry represents an entry in the sequence identifier - * cache. The sequence identifier is comprised of the sequence context and - * sequence number, and must be cached for the duration of the sequence - * identifier lifetime. Entries in the cache are stored in order of - * increasing discard time. - */ - private class CacheEntry { - - private String iSeqContext; - - private long iSeqNumber; - - private long iDiscardTime; - - public CacheEntry(String pSequenceContext, long pSequenceNumber, long pDiscardTime) { - this.iSeqContext = pSequenceContext; - this.iSeqNumber = pSequenceNumber; - this.iDiscardTime = pDiscardTime; - } - - public long getDiscardTime() { - return this.iDiscardTime; - } - - public String getSequenceContext() { - return this.iSeqContext; - } - - public long getSequenceNumber() { - return this.iSeqNumber; - } - } - - private LinkedList iQueue = new LinkedList(); - - private LinkedList iCache = new LinkedList(); - - private CIMEventDispatcher iDispatcher; - - private LogAndTraceBroker iLogger = LogAndTraceBroker.getBroker(); - - private long iIndentifierLifetime; - - // private long iLastArrivalTime; - - private String iLastSequenceContext; - - private Long iLastSequenceNumber; - - private long iExpectedSequenceNumber = 0; - - private boolean iIsFirstIndication = true; - - /** - * Constructs a ReliableIndicationHandler instance that uses - * the specified event dispatcher and sequence identifier lifetime to handle - * reliable indications. - * - * @param pDispatcher - * CIMEventDispatcher that does the actual - * indication dispatching. - * @param pIdentiferLifetime - * Sequence identifier lifetime. - */ - public ReliableIndicationHandler(CIMEventDispatcher pDispatcher, long pIdentiferLifetime) { - this.iDispatcher = pDispatcher; - this.iIndentifierLifetime = pIdentiferLifetime; - } - - /** - * Adds a reliable indication to the indication delivery queue. - * - * @param pIndication - * Reliable indication to be queued for delivery. - */ - private void addToQueue(ReliableIndication pIndication) { - int size = this.iQueue.size(); - - if ((size == 0) - || (this.iQueue.getLast().getSequenceNumber()) < pIndication.getSequenceNumber()) { - this.iQueue.addLast(pIndication); - } else { - int i; - for (i = size - 1; i >= 0; i--) { - ReliableIndication indication = this.iQueue.get(i); - if (indication.getSequenceNumber() < pIndication.getSequenceNumber()) { - this.iQueue.add(i + 1, pIndication); - // printQueue(); - processQueue(); - return; - } - } - this.iQueue.addFirst(pIndication); - } - - // printQueue(); - // Process queue if there are two or more entries - if (size > 0) processQueue(); - } - - /** - * Delivers all reliable indications in the indication delivery queue. - */ - private void flushQueue() { - if (this.iQueue.isEmpty()) return; - for (int i = this.iQueue.size() - 1; i >= 0; i--) { - ReliableIndication indication = this.iQueue.removeFirst(); - logMissingQueueEntries(indication.getSequenceNumber()); - - this.iDispatcher.dispatchEvent(new CIMEvent(indication.getIndication(), indication - .getId(), indication.getInetAddress())); - - this.iExpectedSequenceNumber = indication.getSequenceNumber() + 1; - } - } - - /** - * Determines if the indication delivery queue is empty. - * - * @return true if indication delivery queue is empty, - * false otherwise. - */ - private boolean isQueueEmpty() { - return this.iQueue.isEmpty(); - } - - /** - * Logs any missing reliable indications at the front of the indication - * delivery queue. - * - * @param pSequenceNumber - * Sequence number of first indication present in delivery queue. - */ - private void logMissingQueueEntries(long pSequenceNumber) { - if (pSequenceNumber > this.iExpectedSequenceNumber) { - for (long l = this.iExpectedSequenceNumber; l < pSequenceNumber; l++) { - this.iLogger.trace(Level.FINE, "Missing indication #" + l + " detected"); - } - } - } - - /** - * Prints all reliable indications in the indication delivery queue. - */ - // private void printQueue() { - // System.out.println("ReliableInidcation queue >"); - // for (int i = 0; i < this.iQueue.size(); i++) { - // ReliableIndication indication = this.iQueue.get(i); - // System.out.println(" Q[" + i + "]: " + indication.getSequenceNumber() + - // "@" - // + indication.getDiscardTime()); - // } - // } - /* */ - - /** - * Processes the indication delivery queue and dispatches all reliable - * indications whose sequence identifier lifetime has expired or whose - * sequence numbers are in the expected order. - */ - private void processQueue() { - if (this.iQueue.isEmpty()) return; - long currentTime = System.currentTimeMillis(); - - ReliableIndication indication = this.iQueue.getFirst(); - - // First dispatch all indications whose lifetimes have expired - while (indication.getDiscardTime() <= currentTime) { - indication = this.iQueue.removeFirst(); - logMissingQueueEntries(indication.getSequenceNumber()); - - this.iDispatcher.dispatchEvent(new CIMEvent(indication.getIndication(), indication - .getId(), indication.getInetAddress())); - - this.iExpectedSequenceNumber = indication.getSequenceNumber() + 1; - - if (this.iQueue.isEmpty()) return; - indication = this.iQueue.getFirst(); - } - - // Second dispatch all indications that are in the expected order - while (indication.getSequenceNumber() == this.iExpectedSequenceNumber) { - indication = this.iQueue.removeFirst(); - - this.iDispatcher.dispatchEvent(new CIMEvent(indication.getIndication(), indication - .getId(), indication.getInetAddress())); - - this.iExpectedSequenceNumber++; - - if (this.iQueue.isEmpty()) return; - indication = this.iQueue.getFirst(); - } - } - - /** - * Adds a reliable indication to the sequence identifier cache. - * - * @param pSequenceContext - * Sequence context of reliable indication to be cached. - * @param pSequenceNumber - * Sequence number of reliable indication to be cached. - * @param pDiscardTime - * Sequence identifier lifetime expiration time. - */ - private void addToCache(String pSequenceContext, long pSequenceNumber, long pDiscardTime) { - CacheEntry newEntry = new CacheEntry(pSequenceContext, pSequenceNumber, pDiscardTime); - int size = this.iCache.size(); - - if ((size == 0) || (this.iCache.getLast().getDiscardTime() <= pDiscardTime)) { - this.iCache.addLast(newEntry); - } else { - int i; - for (i = size - 1; i >= 0; i--) { - CacheEntry entry = this.iCache.get(i); - if (entry.getDiscardTime() <= pDiscardTime) { - this.iCache.add(i + 1, newEntry); - // printCache(); - return; - } - } - this.iCache.addFirst(newEntry); - } - - // printCache(); - } - - /** - * Removes all entries in the sequence identifier cache. - */ - // private void flushCache() { - // this.iCache.clear(); - // } - /* */ - - /** - * Determines if the sequence identifier cache is empty. - * - * @return true if sequence identifier cache is empty, - * false otherwise. - */ - private boolean isCacheEmpty() { - return this.iCache.isEmpty(); - } - - /** - * Determines if the sequence context is in the sequence identifier cache. - * - * @param pSequenceContext - * Sequence context to look for. - * @return true if sequence context is in sequence identifier - * cache, false otherwise. - */ - private boolean isInCache(String pSequenceContext) { - if (this.iCache.isEmpty()) return false; - Iterator iterator = this.iCache.iterator(); - while (iterator.hasNext()) { - if (iterator.next().getSequenceContext().compareTo(pSequenceContext) == 0) return true; - } - return false; - } - - /** - * Determines if the sequence identifier (context and number) is in the - * sequence identifier cache. - * - * @param pSequenceContext - * Sequence context to look for. - * @param pSequenceNumber - * Sequence number to look for. - * @return true if sequence identifier is in sequence - * identifier cache, false otherwise. - */ - private boolean isInCache(String pSequenceContext, long pSequenceNumber) { - if (this.iCache.isEmpty()) return false; - Iterator iterator = this.iCache.iterator(); - while (iterator.hasNext()) { - CacheEntry entry = iterator.next(); - if ((entry.getSequenceContext().compareTo(pSequenceContext) == 0) - && (entry.getSequenceNumber() == pSequenceNumber)) return true; - } - return false; - } - - /** - * Prints all entries in the sequence identifier cache. - */ - // private void printCache() { - // System.out.println("ReliableIndication cache >"); - // for (int i = 0; i < this.iCache.size(); i++) { - // CacheEntry entry = this.iCache.get(i); - // System.out.println(" C[" + i + "]: " + entry.getSequenceContext() + "," - // + entry.getSequenceNumber() + "@" + entry.getDiscardTime()); - // } - // } - /* */ - - /** - * Processes the sequence identifier cache and removes all entries whose - * sequence identifier lifetime has expired. - */ - private void processCache() { - if (this.iCache.isEmpty()) return; - long currentTime = System.currentTimeMillis(); - - for (int i = this.iCache.size() - 1; i >= 0; i--) { - if (this.iCache.getFirst().getDiscardTime() > currentTime) break; - this.iCache.removeFirst(); - } - } - - /** - * Determines if both the indication delivery queue and sequence identifier - * cache are empty. - * - * @return true if both the indication delivery queue and - * sequence identifier cache are empty, false - * otherwise. - */ - protected synchronized boolean areAllEmpty() { - return isCacheEmpty() && isQueueEmpty(); - } - - /** - * Flushes both the indication delivery queue and sequence identifier cache. - */ - // private void flushAll() { - // flushQueue(); - // flushCache(); - // } - /* */ - - /** - * Processes both the indication delivery queue and sequence identifier - * cache. - */ - protected synchronized void processAll() { - processQueue(); - processCache(); - } - - /** - * Main worker routine for ReliableIndicationHandler. The - * indication is either sent directly to the CIMEventDispatcher - * or placed in the indication delivery queue to be dispatched later. All - * reliable indications are placed in the sequence identifier cache. - * - * @param pIndication - * Indication. - * @param pId - * Indication destination URL. - * @param pInetAddress - * Indication server IP. - */ - public synchronized void handleIndication(CIMInstance pIndication, String pId, - InetAddress pInetAddress) { - // Get current time - long arrivalTime = System.currentTimeMillis(); - - // Get reliable indication properties from indication - CIMProperty seqCtxProp = pIndication.getProperty("SequenceContext"); - CIMProperty seqNumProp = pIndication.getProperty("SequenceNumber"); - - // At this point indication is reliable or not reliable - - // Indication is not reliable, handle appropriately and deliver - if (seqCtxProp == null || seqNumProp == null || seqCtxProp.getValue() == null - || seqNumProp.getValue() == null) { - // Handle switch from reliable to not reliable - if (this.iLastSequenceContext != null) { - // Deliver all enqueued indications from previous context - flushQueue(); - - this.iLastSequenceContext = null; - this.iLastSequenceNumber = null; - } - - // Deliver indication - this.iDispatcher.dispatchEvent(new CIMEvent(pIndication, pId, pInetAddress)); - this.iIsFirstIndication = false; - return; - } - - // At this point indication is reliable - - // Initial indication arrived, save knowledge about sequence identifier - // and deliver - if (this.iIsFirstIndication) { - // Remember sequence context/number and arrival time - this.iLastSequenceContext = (String) seqCtxProp.getValue(); - this.iLastSequenceNumber = (Long) seqNumProp.getValue(); - this.iExpectedSequenceNumber = this.iLastSequenceNumber.longValue() + 1; - // this.iLastArrivalTime = arrivalTime; - - // Cache sequence identifier - addToCache(this.iLastSequenceContext, this.iLastSequenceNumber.longValue(), arrivalTime - + this.iIndentifierLifetime); - - // Deliver indication - this.iDispatcher.dispatchEvent(new CIMEvent(pIndication, pId, pInetAddress)); - this.iIsFirstIndication = false; - return; - } - - // At this point indication is reliable and previous indication was - // reliable - - String seqCtx = (String) seqCtxProp.getValue(); - Long seqNum = (Long) seqNumProp.getValue(); - long seqNumVal = seqNum.longValue(); - - // Indication arrived after sequence identifier lifetime of previous - // indication expired, discard knowledge about previous sequence - // identifier and deliver - // if (arrivalTime > (this.iLastArrivalTime + - // this.iIndentifierLifetime)) { - // this.iLogger.trace(Level.FINE, - // "Discarding knowledge of previous sequence identifier because lifetime expired"); - - // Nothing should be cached or enqueued at this point - // flushAll(); - - // Remember sequence context/number and arrival time - // this.iLastSequenceContext = seqCtx; - // this.iLastSequenceNumber = seqNum; - // this.iExpectedSequenceNumber = seqNumVal + 1; - // this.iLastArrivalTime = arrivalTime; - - // Cache sequence identifier - // addToCache(seqCtx, seqNumVal, arrivalTime + - // this.iIndentifierLifetime); - - // Deliver indication - // this.iDispatcher.dispatchEvent(new CIMEvent(pIndication, pId, - // pInetAddress)); - // return; - // } - - // Indication arrived with different sequence context than expected - if (this.iLastSequenceContext == null || seqCtx.compareTo(this.iLastSequenceContext) != 0) { - // Cached sequence context indicates this indication arrived - // out-of-order from previous context, log and ignore - if (isInCache(seqCtx)) { - this.iLogger.trace(Level.FINE, "Out-of-order indication #" + seqNumVal - + " received from previous context; indication ignored, logged: " - + pIndication.toString()); - - return; - } - - this.iLogger.trace(Level.FINE, - "Discarding knowledge of previous sequence identifier because context changed"); - - // Deliver all enqueued indications from previous context - flushQueue(); - - // Remember sequence context and arrival time, sequence number - // should be zero - this.iLastSequenceContext = seqCtx; - this.iLastSequenceNumber = Long.valueOf(0); - this.iExpectedSequenceNumber = 1; - // this.iLastArrivalTime = arrivalTime; - - // Cache sequence identifier - addToCache(seqCtx, seqNumVal, arrivalTime + this.iIndentifierLifetime); - - // Expected sequence number, go ahead and deliver - if (seqNumVal == 0) { - this.iDispatcher.dispatchEvent(new CIMEvent(pIndication, pId, pInetAddress)); - return; - } - - // Unexpected (non-zero) sequence number, enqueue - this.iLastSequenceNumber = Long.valueOf(-1); - this.iExpectedSequenceNumber = 0; - addToQueue(new ReliableIndication(pIndication, seqNumVal, arrivalTime - + this.iIndentifierLifetime, pId, pInetAddress)); - - return; - } - - // Indication arrived with expected sequence number, go ahead and - // deliver - if (seqNumVal == this.iExpectedSequenceNumber) { - // Remember sequence context/number and arrival time - this.iLastSequenceNumber = seqNum; - this.iExpectedSequenceNumber = seqNumVal + 1; - // this.iLastArrivalTime = arrivalTime; - - // Cache sequence identifier - addToCache(seqCtx, seqNumVal, arrivalTime + this.iIndentifierLifetime); - - // Deliver indication - this.iDispatcher.dispatchEvent(new CIMEvent(pIndication, pId, pInetAddress)); - - return; - } - - // Duplicate indication arrived, log and ignore - if (isInCache(seqCtx, seqNumVal)) { - this.iLogger.trace(Level.FINE, "Duplicate indication #" + seqNumVal - + " received; indication ignored"); - - // Cache sequence identifier (duplicate entries okay and much easier - // than deleting/adding or moving) - addToCache(seqCtx, seqNumVal, arrivalTime + this.iIndentifierLifetime); - - return; - } - - // Out-of-order indication arrived, log and ignore - if (seqNumVal < this.iExpectedSequenceNumber) { - this.iLogger.trace(Level.FINE, "Out-of-order indication #" + seqNumVal + " received (#" - + this.iExpectedSequenceNumber + " expected); indication ignored, logged: " - + pIndication.toString()); - - // Cache sequence identifier - addToCache(seqCtx, seqNumVal, arrivalTime + this.iIndentifierLifetime); - - return; - } - - // Indication with higher sequence number than expected received, cache - // and enqueue it - addToCache(seqCtx, seqNumVal, arrivalTime + this.iIndentifierLifetime); - addToQueue(new ReliableIndication(pIndication, seqNumVal, arrivalTime - + this.iIndentifierLifetime, pId, pInetAddress)); - - return; - } -} +/* + (C) Copyright IBM Corp. 2011, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Dave Blaschke, IBM, blaschke@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 3288721 2011-05-20 blaschke-oss Need the function of indication reordering + * 3376657 2011-07-24 blaschke-oss Get reliable indication properties once + * 3484022 2012-02-08 blaschke-oss Turn reliable indication mode on and off based on SC/SN + * 3513228 2012-04-23 blaschke-oss Reliable Indications support can create lots of threads + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.indications; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.net.InetAddress; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.logging.Level; +import org.metricshub.wbem.javax.cim.CIMInstance; +import org.metricshub.wbem.javax.cim.CIMProperty; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; + +/** + * ReliableIndicationHandler is responsible for determining when to + * dispatch reliable indications, which includes queuing unexpected indications, + * caching all indications for the duration of their sequence identifier + * lifetime, and logging missing, duplicate and out-of-order indications. This + * functionality is based on the changes first introduced by DSP1054 v1.1. + * + * The handleIndication, areAllEmpty and + * processAll methods need to be synchronized because they are the + * entry points into ReliableIndicationHandler - the first is the + * public entry point that needs to be passed each and every reliable + * indication, the other two are only called by the DataManager thread and hence + * protected. All of the private methods are only called from one of the three + * synchronized methods. + * + * NOTE: ReliableIndicationHandler does NOT contain any logic for + * handling sequence number wrapping. It was deemed unnecessary because of the + * performance impact to each and every indication for a VERY rare occurrence: + * sequence numbers are longs (signed 64-bit integers) that are are supposed to + * start at 0, so even if the listener handled 1,000,00 indications per second, + * it would take over 292,471 years for the sequence number to wrap. + */ +public class ReliableIndicationHandler { + + /** + * ReliableIndication represents an entry in the indication + * delivery queue, and contains all the information required to manage and + * dispatch the indication. Entries in the queue are stored in order of + * increasing sequence number and are dispatched when the missing + * indication(s) arrive or their sequence identifier lifetime expires. Only + * one sequence context can be in the queue at any one time. + */ + private class ReliableIndication { + private long iDiscardTime; + + private String iId; + + private CIMInstance iIndication; + + private InetAddress iInetAddress; + + private long iSequenceNumber; + + public ReliableIndication( + CIMInstance pIndication, + long pSequenceNumber, + long pDiscardTime, + String pId, + InetAddress pInetAddress + ) { + this.iIndication = pIndication; + this.iSequenceNumber = pSequenceNumber; + this.iDiscardTime = pDiscardTime; + this.iId = pId; + this.iInetAddress = pInetAddress; + } + + public long getDiscardTime() { + return this.iDiscardTime; + } + + public String getId() { + return this.iId; + } + + public CIMInstance getIndication() { + return this.iIndication; + } + + public InetAddress getInetAddress() { + return this.iInetAddress; + } + + public long getSequenceNumber() { + return this.iSequenceNumber; + } + } + + /** + * CacheEntry represents an entry in the sequence identifier + * cache. The sequence identifier is comprised of the sequence context and + * sequence number, and must be cached for the duration of the sequence + * identifier lifetime. Entries in the cache are stored in order of + * increasing discard time. + */ + private class CacheEntry { + private String iSeqContext; + + private long iSeqNumber; + + private long iDiscardTime; + + public CacheEntry(String pSequenceContext, long pSequenceNumber, long pDiscardTime) { + this.iSeqContext = pSequenceContext; + this.iSeqNumber = pSequenceNumber; + this.iDiscardTime = pDiscardTime; + } + + public long getDiscardTime() { + return this.iDiscardTime; + } + + public String getSequenceContext() { + return this.iSeqContext; + } + + public long getSequenceNumber() { + return this.iSeqNumber; + } + } + + private LinkedList iQueue = new LinkedList(); + + private LinkedList iCache = new LinkedList(); + + private CIMEventDispatcher iDispatcher; + + private LogAndTraceBroker iLogger = LogAndTraceBroker.getBroker(); + + private long iIndentifierLifetime; + + // private long iLastArrivalTime; + + private String iLastSequenceContext; + + private Long iLastSequenceNumber; + + private long iExpectedSequenceNumber = 0; + + private boolean iIsFirstIndication = true; + + /** + * Constructs a ReliableIndicationHandler instance that uses + * the specified event dispatcher and sequence identifier lifetime to handle + * reliable indications. + * + * @param pDispatcher + * CIMEventDispatcher that does the actual + * indication dispatching. + * @param pIdentiferLifetime + * Sequence identifier lifetime. + */ + public ReliableIndicationHandler(CIMEventDispatcher pDispatcher, long pIdentiferLifetime) { + this.iDispatcher = pDispatcher; + this.iIndentifierLifetime = pIdentiferLifetime; + } + + /** + * Adds a reliable indication to the indication delivery queue. + * + * @param pIndication + * Reliable indication to be queued for delivery. + */ + private void addToQueue(ReliableIndication pIndication) { + int size = this.iQueue.size(); + + if ((size == 0) || (this.iQueue.getLast().getSequenceNumber()) < pIndication.getSequenceNumber()) { + this.iQueue.addLast(pIndication); + } else { + int i; + for (i = size - 1; i >= 0; i--) { + ReliableIndication indication = this.iQueue.get(i); + if (indication.getSequenceNumber() < pIndication.getSequenceNumber()) { + this.iQueue.add(i + 1, pIndication); + // printQueue(); + processQueue(); + return; + } + } + this.iQueue.addFirst(pIndication); + } + + // printQueue(); + // Process queue if there are two or more entries + if (size > 0) processQueue(); + } + + /** + * Delivers all reliable indications in the indication delivery queue. + */ + private void flushQueue() { + if (this.iQueue.isEmpty()) return; + for (int i = this.iQueue.size() - 1; i >= 0; i--) { + ReliableIndication indication = this.iQueue.removeFirst(); + logMissingQueueEntries(indication.getSequenceNumber()); + + this.iDispatcher.dispatchEvent( + new CIMEvent(indication.getIndication(), indication.getId(), indication.getInetAddress()) + ); + + this.iExpectedSequenceNumber = indication.getSequenceNumber() + 1; + } + } + + /** + * Determines if the indication delivery queue is empty. + * + * @return true if indication delivery queue is empty, + * false otherwise. + */ + private boolean isQueueEmpty() { + return this.iQueue.isEmpty(); + } + + /** + * Logs any missing reliable indications at the front of the indication + * delivery queue. + * + * @param pSequenceNumber + * Sequence number of first indication present in delivery queue. + */ + private void logMissingQueueEntries(long pSequenceNumber) { + if (pSequenceNumber > this.iExpectedSequenceNumber) { + for (long l = this.iExpectedSequenceNumber; l < pSequenceNumber; l++) { + this.iLogger.trace(Level.FINE, "Missing indication #" + l + " detected"); + } + } + } + + /** + * Prints all reliable indications in the indication delivery queue. + */ + // private void printQueue() { + // System.out.println("ReliableInidcation queue >"); + // for (int i = 0; i < this.iQueue.size(); i++) { + // ReliableIndication indication = this.iQueue.get(i); + // System.out.println(" Q[" + i + "]: " + indication.getSequenceNumber() + + // "@" + // + indication.getDiscardTime()); + // } + // } + /* */ + + /** + * Processes the indication delivery queue and dispatches all reliable + * indications whose sequence identifier lifetime has expired or whose + * sequence numbers are in the expected order. + */ + private void processQueue() { + if (this.iQueue.isEmpty()) return; + long currentTime = System.currentTimeMillis(); + + ReliableIndication indication = this.iQueue.getFirst(); + + // First dispatch all indications whose lifetimes have expired + while (indication.getDiscardTime() <= currentTime) { + indication = this.iQueue.removeFirst(); + logMissingQueueEntries(indication.getSequenceNumber()); + + this.iDispatcher.dispatchEvent( + new CIMEvent(indication.getIndication(), indication.getId(), indication.getInetAddress()) + ); + + this.iExpectedSequenceNumber = indication.getSequenceNumber() + 1; + + if (this.iQueue.isEmpty()) return; + indication = this.iQueue.getFirst(); + } + + // Second dispatch all indications that are in the expected order + while (indication.getSequenceNumber() == this.iExpectedSequenceNumber) { + indication = this.iQueue.removeFirst(); + + this.iDispatcher.dispatchEvent( + new CIMEvent(indication.getIndication(), indication.getId(), indication.getInetAddress()) + ); + + this.iExpectedSequenceNumber++; + + if (this.iQueue.isEmpty()) return; + indication = this.iQueue.getFirst(); + } + } + + /** + * Adds a reliable indication to the sequence identifier cache. + * + * @param pSequenceContext + * Sequence context of reliable indication to be cached. + * @param pSequenceNumber + * Sequence number of reliable indication to be cached. + * @param pDiscardTime + * Sequence identifier lifetime expiration time. + */ + private void addToCache(String pSequenceContext, long pSequenceNumber, long pDiscardTime) { + CacheEntry newEntry = new CacheEntry(pSequenceContext, pSequenceNumber, pDiscardTime); + int size = this.iCache.size(); + + if ((size == 0) || (this.iCache.getLast().getDiscardTime() <= pDiscardTime)) { + this.iCache.addLast(newEntry); + } else { + int i; + for (i = size - 1; i >= 0; i--) { + CacheEntry entry = this.iCache.get(i); + if (entry.getDiscardTime() <= pDiscardTime) { + this.iCache.add(i + 1, newEntry); + // printCache(); + return; + } + } + this.iCache.addFirst(newEntry); + } + // printCache(); + } + + /** + * Removes all entries in the sequence identifier cache. + */ + // private void flushCache() { + // this.iCache.clear(); + // } + /* */ + + /** + * Determines if the sequence identifier cache is empty. + * + * @return true if sequence identifier cache is empty, + * false otherwise. + */ + private boolean isCacheEmpty() { + return this.iCache.isEmpty(); + } + + /** + * Determines if the sequence context is in the sequence identifier cache. + * + * @param pSequenceContext + * Sequence context to look for. + * @return true if sequence context is in sequence identifier + * cache, false otherwise. + */ + private boolean isInCache(String pSequenceContext) { + if (this.iCache.isEmpty()) return false; + Iterator iterator = this.iCache.iterator(); + while (iterator.hasNext()) { + if (iterator.next().getSequenceContext().compareTo(pSequenceContext) == 0) return true; + } + return false; + } + + /** + * Determines if the sequence identifier (context and number) is in the + * sequence identifier cache. + * + * @param pSequenceContext + * Sequence context to look for. + * @param pSequenceNumber + * Sequence number to look for. + * @return true if sequence identifier is in sequence + * identifier cache, false otherwise. + */ + private boolean isInCache(String pSequenceContext, long pSequenceNumber) { + if (this.iCache.isEmpty()) return false; + Iterator iterator = this.iCache.iterator(); + while (iterator.hasNext()) { + CacheEntry entry = iterator.next(); + if ( + (entry.getSequenceContext().compareTo(pSequenceContext) == 0) && (entry.getSequenceNumber() == pSequenceNumber) + ) return true; + } + return false; + } + + /** + * Prints all entries in the sequence identifier cache. + */ + // private void printCache() { + // System.out.println("ReliableIndication cache >"); + // for (int i = 0; i < this.iCache.size(); i++) { + // CacheEntry entry = this.iCache.get(i); + // System.out.println(" C[" + i + "]: " + entry.getSequenceContext() + "," + // + entry.getSequenceNumber() + "@" + entry.getDiscardTime()); + // } + // } + /* */ + + /** + * Processes the sequence identifier cache and removes all entries whose + * sequence identifier lifetime has expired. + */ + private void processCache() { + if (this.iCache.isEmpty()) return; + long currentTime = System.currentTimeMillis(); + + for (int i = this.iCache.size() - 1; i >= 0; i--) { + if (this.iCache.getFirst().getDiscardTime() > currentTime) break; + this.iCache.removeFirst(); + } + } + + /** + * Determines if both the indication delivery queue and sequence identifier + * cache are empty. + * + * @return true if both the indication delivery queue and + * sequence identifier cache are empty, false + * otherwise. + */ + protected synchronized boolean areAllEmpty() { + return isCacheEmpty() && isQueueEmpty(); + } + + /** + * Flushes both the indication delivery queue and sequence identifier cache. + */ + // private void flushAll() { + // flushQueue(); + // flushCache(); + // } + /* */ + + /** + * Processes both the indication delivery queue and sequence identifier + * cache. + */ + protected synchronized void processAll() { + processQueue(); + processCache(); + } + + /** + * Main worker routine for ReliableIndicationHandler. The + * indication is either sent directly to the CIMEventDispatcher + * or placed in the indication delivery queue to be dispatched later. All + * reliable indications are placed in the sequence identifier cache. + * + * @param pIndication + * Indication. + * @param pId + * Indication destination URL. + * @param pInetAddress + * Indication server IP. + */ + public synchronized void handleIndication(CIMInstance pIndication, String pId, InetAddress pInetAddress) { + // Get current time + long arrivalTime = System.currentTimeMillis(); + + // Get reliable indication properties from indication + CIMProperty seqCtxProp = pIndication.getProperty("SequenceContext"); + CIMProperty seqNumProp = pIndication.getProperty("SequenceNumber"); + + // At this point indication is reliable or not reliable + + // Indication is not reliable, handle appropriately and deliver + if (seqCtxProp == null || seqNumProp == null || seqCtxProp.getValue() == null || seqNumProp.getValue() == null) { + // Handle switch from reliable to not reliable + if (this.iLastSequenceContext != null) { + // Deliver all enqueued indications from previous context + flushQueue(); + + this.iLastSequenceContext = null; + this.iLastSequenceNumber = null; + } + + // Deliver indication + this.iDispatcher.dispatchEvent(new CIMEvent(pIndication, pId, pInetAddress)); + this.iIsFirstIndication = false; + return; + } + + // At this point indication is reliable + + // Initial indication arrived, save knowledge about sequence identifier + // and deliver + if (this.iIsFirstIndication) { + // Remember sequence context/number and arrival time + this.iLastSequenceContext = (String) seqCtxProp.getValue(); + this.iLastSequenceNumber = (Long) seqNumProp.getValue(); + this.iExpectedSequenceNumber = this.iLastSequenceNumber.longValue() + 1; + // this.iLastArrivalTime = arrivalTime; + + // Cache sequence identifier + addToCache( + this.iLastSequenceContext, + this.iLastSequenceNumber.longValue(), + arrivalTime + this.iIndentifierLifetime + ); + + // Deliver indication + this.iDispatcher.dispatchEvent(new CIMEvent(pIndication, pId, pInetAddress)); + this.iIsFirstIndication = false; + return; + } + + // At this point indication is reliable and previous indication was + // reliable + + String seqCtx = (String) seqCtxProp.getValue(); + Long seqNum = (Long) seqNumProp.getValue(); + long seqNumVal = seqNum.longValue(); + + // Indication arrived after sequence identifier lifetime of previous + // indication expired, discard knowledge about previous sequence + // identifier and deliver + // if (arrivalTime > (this.iLastArrivalTime + + // this.iIndentifierLifetime)) { + // this.iLogger.trace(Level.FINE, + // "Discarding knowledge of previous sequence identifier because lifetime expired"); + + // Nothing should be cached or enqueued at this point + // flushAll(); + + // Remember sequence context/number and arrival time + // this.iLastSequenceContext = seqCtx; + // this.iLastSequenceNumber = seqNum; + // this.iExpectedSequenceNumber = seqNumVal + 1; + // this.iLastArrivalTime = arrivalTime; + + // Cache sequence identifier + // addToCache(seqCtx, seqNumVal, arrivalTime + + // this.iIndentifierLifetime); + + // Deliver indication + // this.iDispatcher.dispatchEvent(new CIMEvent(pIndication, pId, + // pInetAddress)); + // return; + // } + + // Indication arrived with different sequence context than expected + if (this.iLastSequenceContext == null || seqCtx.compareTo(this.iLastSequenceContext) != 0) { + // Cached sequence context indicates this indication arrived + // out-of-order from previous context, log and ignore + if (isInCache(seqCtx)) { + this.iLogger.trace( + Level.FINE, + "Out-of-order indication #" + + seqNumVal + + " received from previous context; indication ignored, logged: " + + pIndication.toString() + ); + + return; + } + + this.iLogger.trace(Level.FINE, "Discarding knowledge of previous sequence identifier because context changed"); + + // Deliver all enqueued indications from previous context + flushQueue(); + + // Remember sequence context and arrival time, sequence number + // should be zero + this.iLastSequenceContext = seqCtx; + this.iLastSequenceNumber = Long.valueOf(0); + this.iExpectedSequenceNumber = 1; + // this.iLastArrivalTime = arrivalTime; + + // Cache sequence identifier + addToCache(seqCtx, seqNumVal, arrivalTime + this.iIndentifierLifetime); + + // Expected sequence number, go ahead and deliver + if (seqNumVal == 0) { + this.iDispatcher.dispatchEvent(new CIMEvent(pIndication, pId, pInetAddress)); + return; + } + + // Unexpected (non-zero) sequence number, enqueue + this.iLastSequenceNumber = Long.valueOf(-1); + this.iExpectedSequenceNumber = 0; + addToQueue( + new ReliableIndication(pIndication, seqNumVal, arrivalTime + this.iIndentifierLifetime, pId, pInetAddress) + ); + + return; + } + + // Indication arrived with expected sequence number, go ahead and + // deliver + if (seqNumVal == this.iExpectedSequenceNumber) { + // Remember sequence context/number and arrival time + this.iLastSequenceNumber = seqNum; + this.iExpectedSequenceNumber = seqNumVal + 1; + // this.iLastArrivalTime = arrivalTime; + + // Cache sequence identifier + addToCache(seqCtx, seqNumVal, arrivalTime + this.iIndentifierLifetime); + + // Deliver indication + this.iDispatcher.dispatchEvent(new CIMEvent(pIndication, pId, pInetAddress)); + + return; + } + + // Duplicate indication arrived, log and ignore + if (isInCache(seqCtx, seqNumVal)) { + this.iLogger.trace(Level.FINE, "Duplicate indication #" + seqNumVal + " received; indication ignored"); + + // Cache sequence identifier (duplicate entries okay and much easier + // than deleting/adding or moving) + addToCache(seqCtx, seqNumVal, arrivalTime + this.iIndentifierLifetime); + + return; + } + + // Out-of-order indication arrived, log and ignore + if (seqNumVal < this.iExpectedSequenceNumber) { + this.iLogger.trace( + Level.FINE, + "Out-of-order indication #" + + seqNumVal + + " received (#" + + this.iExpectedSequenceNumber + + " expected); indication ignored, logged: " + + pIndication.toString() + ); + + // Cache sequence identifier + addToCache(seqCtx, seqNumVal, arrivalTime + this.iIndentifierLifetime); + + return; + } + + // Indication with higher sequence number than expected received, cache + // and enqueue it + addToCache(seqCtx, seqNumVal, arrivalTime + this.iIndentifierLifetime); + addToQueue( + new ReliableIndication(pIndication, seqNumVal, arrivalTime + this.iIndentifierLifetime, pId, pInetAddress) + ); + + return; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/indications/package.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/indications/package.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/indications/package.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/indications/package.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMAssociatorNamesOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMAssociatorNamesOp.java similarity index 67% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMAssociatorNamesOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMAssociatorNamesOp.java index e844142..059ce11 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMAssociatorNamesOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMAssociatorNamesOp.java @@ -1,122 +1,122 @@ -/* - CIMAssociatorNamesOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * @author Roberto - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public class CIMAssociatorNamesOp extends CIMOperation { - - protected String iAssociationClass; - - protected String iResultClass; - - protected String iRole; - - protected String iResultRole; - - /** - * Ctor. - * - * @param pObjectName - * @param pAssociationClass - * @param pResultClass - * @param pRole - * @param pResultRole - */ - public CIMAssociatorNamesOp(CIMObjectPath pObjectName, String pAssociationClass, - String pResultClass, String pRole, String pResultRole) { - - this.iMethodCall = "AssociatorNames"; - this.iObjectName = pObjectName; - this.iAssociationClass = pAssociationClass; - this.iResultClass = pResultClass; - this.iRole = pRole; - } - - /** - * Returns the association class name - * - * @return The association class name - */ - public String getAssocClass() { - return this.iAssociationClass; - } - - /** - * Returns the result class name - * - * @return The result class name - */ - public String getResultClass() { - return this.iResultClass; - } - - /** - * Returns the result role - * - * @return The result role - */ - public String getResultRole() { - return this.iResultRole; - } - - /** - * Returns the role - * - * @return The role - */ - public String getRole() { - return this.iRole; - } - -} +/* + CIMAssociatorNamesOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * @author Roberto + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class CIMAssociatorNamesOp extends CIMOperation { + protected String iAssociationClass; + + protected String iResultClass; + + protected String iRole; + + protected String iResultRole; + + /** + * Ctor. + * + * @param pObjectName + * @param pAssociationClass + * @param pResultClass + * @param pRole + * @param pResultRole + */ + public CIMAssociatorNamesOp( + CIMObjectPath pObjectName, + String pAssociationClass, + String pResultClass, + String pRole, + String pResultRole + ) { + this.iMethodCall = "AssociatorNames"; + this.iObjectName = pObjectName; + this.iAssociationClass = pAssociationClass; + this.iResultClass = pResultClass; + this.iRole = pRole; + } + + /** + * Returns the association class name + * + * @return The association class name + */ + public String getAssocClass() { + return this.iAssociationClass; + } + + /** + * Returns the result class name + * + * @return The result class name + */ + public String getResultClass() { + return this.iResultClass; + } + + /** + * Returns the result role + * + * @return The result role + */ + public String getResultRole() { + return this.iResultRole; + } + + /** + * Returns the role + * + * @return The role + */ + public String getRole() { + return this.iRole; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMAssociatorsOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMAssociatorsOp.java similarity index 70% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMAssociatorsOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMAssociatorsOp.java index 5fe4e4d..8448f68 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMAssociatorsOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMAssociatorsOp.java @@ -1,160 +1,162 @@ -/* - CIMAssociatorsOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * Class CIMAssociatorsOp - * - */ -public class CIMAssociatorsOp extends CIMOperation { - - protected String iAssociationClass; - - protected String iResultClass; - - protected String iRole; - - protected String iResultRole; - - protected boolean iIncludeQualifiers; - - protected boolean iIncludeClassOrigin; - - protected String[] iPropertyList; - - /** - * Ctor. - * - * @param pObjectName - * @param pAssociationClass - * @param pResultClass - * @param pRole - * @param pResultRole - * @param pIncludeQualifiers - * @param pIncludeClassOrigin - * @param pPropertyList - */ - public CIMAssociatorsOp(CIMObjectPath pObjectName, String pAssociationClass, - String pResultClass, String pRole, String pResultRole, boolean pIncludeQualifiers, - boolean pIncludeClassOrigin, String[] pPropertyList) { - - this.iMethodCall = "Associators"; - this.iObjectName = pObjectName; - this.iAssociationClass = pAssociationClass; - this.iResultClass = pResultClass; - this.iRole = pRole; - this.iIncludeClassOrigin = pIncludeClassOrigin; - this.iIncludeQualifiers = pIncludeQualifiers; - this.iPropertyList = pPropertyList; - } - - /** - * Returns the association class - * - * @return The association class - */ - public String getAssocClass() { - return this.iAssociationClass; - } - - /** - * Returns if includeQualifiers is set - * - * @return The value of includeClassOrigin - */ - public boolean isIncludeClassOrigin() { - return this.iIncludeClassOrigin; - } - - /** - * Returns if includeQualifiers is set - * - * @return The value of includeClassOrigin - */ - public boolean isIncludeQualifiers() { - return this.iIncludeQualifiers; - } - - /** - * Returns the property list - * - * @return The property list - */ - public String[] getPropertyList() { - return this.iPropertyList; - } - - /** - * Returns the result class - * - * @return The result class - */ - public String getResultClass() { - return this.iResultClass; - } - - /** - * Returns the result role - * - * @return The result role - */ - public String getResultRole() { - return this.iResultRole; - } - - /** - * Returns the role - * - * @return The role - */ - public String getRole() { - return this.iRole; - } - -} +/* + CIMAssociatorsOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * Class CIMAssociatorsOp + * + */ +public class CIMAssociatorsOp extends CIMOperation { + protected String iAssociationClass; + + protected String iResultClass; + + protected String iRole; + + protected String iResultRole; + + protected boolean iIncludeQualifiers; + + protected boolean iIncludeClassOrigin; + + protected String[] iPropertyList; + + /** + * Ctor. + * + * @param pObjectName + * @param pAssociationClass + * @param pResultClass + * @param pRole + * @param pResultRole + * @param pIncludeQualifiers + * @param pIncludeClassOrigin + * @param pPropertyList + */ + public CIMAssociatorsOp( + CIMObjectPath pObjectName, + String pAssociationClass, + String pResultClass, + String pRole, + String pResultRole, + boolean pIncludeQualifiers, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) { + this.iMethodCall = "Associators"; + this.iObjectName = pObjectName; + this.iAssociationClass = pAssociationClass; + this.iResultClass = pResultClass; + this.iRole = pRole; + this.iIncludeClassOrigin = pIncludeClassOrigin; + this.iIncludeQualifiers = pIncludeQualifiers; + this.iPropertyList = pPropertyList; + } + + /** + * Returns the association class + * + * @return The association class + */ + public String getAssocClass() { + return this.iAssociationClass; + } + + /** + * Returns if includeQualifiers is set + * + * @return The value of includeClassOrigin + */ + public boolean isIncludeClassOrigin() { + return this.iIncludeClassOrigin; + } + + /** + * Returns if includeQualifiers is set + * + * @return The value of includeClassOrigin + */ + public boolean isIncludeQualifiers() { + return this.iIncludeQualifiers; + } + + /** + * Returns the property list + * + * @return The property list + */ + public String[] getPropertyList() { + return this.iPropertyList; + } + + /** + * Returns the result class + * + * @return The result class + */ + public String getResultClass() { + return this.iResultClass; + } + + /** + * Returns the result role + * + * @return The result role + */ + public String getResultRole() { + return this.iResultRole; + } + + /** + * Returns the role + * + * @return The role + */ + public String getRole() { + return this.iRole; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateClassOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateClassOp.java similarity index 62% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateClassOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateClassOp.java index 0838f1b..dfa1766 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateClassOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateClassOp.java @@ -1,80 +1,77 @@ -/* - CIMCreateClassOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMClass; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * CIMCreateClassOp - * - */ -public class CIMCreateClassOp extends CIMOperation { - - protected CIMClass iCimClass; - - /** - * Ctor. - * - * @param pObjectName - * @param pCimClass - */ - public CIMCreateClassOp(CIMObjectPath pObjectName, CIMClass pCimClass) { - this.iMethodCall = "CreateClass"; - this.iObjectName = pObjectName; - this.iCimClass = pCimClass; - } - - /** - * Returns the CIM class - * - * @return The CIM class - */ - public CIMClass getCimClass() { - return this.iCimClass; - } -} +/* + CIMCreateClassOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMClass; +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * CIMCreateClassOp + * + */ +public class CIMCreateClassOp extends CIMOperation { + protected CIMClass iCimClass; + + /** + * Ctor. + * + * @param pObjectName + * @param pCimClass + */ + public CIMCreateClassOp(CIMObjectPath pObjectName, CIMClass pCimClass) { + this.iMethodCall = "CreateClass"; + this.iObjectName = pObjectName; + this.iCimClass = pCimClass; + } + + /** + * Returns the CIM class + * + * @return The CIM class + */ + public CIMClass getCimClass() { + return this.iCimClass; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateInstanceOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateInstanceOp.java similarity index 63% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateInstanceOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateInstanceOp.java index 664a50b..a8ad3a6 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateInstanceOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateInstanceOp.java @@ -1,81 +1,77 @@ -/* - CIMCreateInstanceOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMInstance; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * CIMCreateInstanceOp - * - */ -public class CIMCreateInstanceOp extends CIMOperation { - - protected CIMInstance iInstance; - - /** - * Ctor. - * - * @param pObjectName - * @param pInstance - */ - public CIMCreateInstanceOp(CIMObjectPath pObjectName, CIMInstance pInstance) { - this.iMethodCall = "CreateInstance"; - this.iObjectName = pObjectName; - this.iInstance = pInstance; - } - - /** - * Returns the instance - * - * @return The instance - */ - public CIMInstance getInstance() { - return this.iInstance; - } - -} +/* + CIMCreateInstanceOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMInstance; +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * CIMCreateInstanceOp + * + */ +public class CIMCreateInstanceOp extends CIMOperation { + protected CIMInstance iInstance; + + /** + * Ctor. + * + * @param pObjectName + * @param pInstance + */ + public CIMCreateInstanceOp(CIMObjectPath pObjectName, CIMInstance pInstance) { + this.iMethodCall = "CreateInstance"; + this.iObjectName = pObjectName; + this.iInstance = pInstance; + } + + /** + * Returns the instance + * + * @return The instance + */ + public CIMInstance getInstance() { + return this.iInstance; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateNameSpaceOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateNameSpaceOp.java similarity index 63% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateNameSpaceOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateNameSpaceOp.java index 86e6e25..f9a2184 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateNameSpaceOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateNameSpaceOp.java @@ -1,64 +1,62 @@ -/* - CIMCreateNameSpaceOp.java - - (C) Copyright IBM Corp. 2005, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 3001357 2010-05-18 blaschke-oss CIMDeleteNameSpaceOp name clash - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * CIMCreateNameSpaceOp - * - */ -public class CIMCreateNameSpaceOp extends CIMOperation { - - /** - * Ctor. - * - * @param pNamespace - */ - public CIMCreateNameSpaceOp(String pNamespace) { - this.iNameSpace = pNamespace; - } -} +/* + CIMCreateNameSpaceOp.java + + (C) Copyright IBM Corp. 2005, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 3001357 2010-05-18 blaschke-oss CIMDeleteNameSpaceOp name clash + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * CIMCreateNameSpaceOp + * + */ +public class CIMCreateNameSpaceOp extends CIMOperation { + + /** + * Ctor. + * + * @param pNamespace + */ + public CIMCreateNameSpaceOp(String pNamespace) { + this.iNameSpace = pNamespace; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateQualifierTypeOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateQualifierTypeOp.java similarity index 65% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateQualifierTypeOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateQualifierTypeOp.java index 8283c2c..f07d55f 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateQualifierTypeOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMCreateQualifierTypeOp.java @@ -1,82 +1,78 @@ -/* - CIMCreateQualifierTypeOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import org.sentrysoftware.wbem.javax.cim.CIMQualifierType; - -/** - * CIMCreateQualifierTypeOp - * - */ -public class CIMCreateQualifierTypeOp extends CIMOperation { - - protected CIMQualifierType iQualifierType; - - /** - * Ctor. - * - * @param pObjectName - * @param pQualifierType - */ - public CIMCreateQualifierTypeOp(CIMObjectPath pObjectName, CIMQualifierType pQualifierType) { - this.iMethodCall = "CreateQualifier"; - this.iObjectName = pObjectName; - this.iQualifierType = pQualifierType; - } - - /** - * Returns the qualifier type - * - * @return The qualifier type - */ - public CIMQualifierType getQualifierType() { - return this.iQualifierType; - } - -} +/* + CIMCreateQualifierTypeOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.cim.CIMQualifierType; + +/** + * CIMCreateQualifierTypeOp + * + */ +public class CIMCreateQualifierTypeOp extends CIMOperation { + protected CIMQualifierType iQualifierType; + + /** + * Ctor. + * + * @param pObjectName + * @param pQualifierType + */ + public CIMCreateQualifierTypeOp(CIMObjectPath pObjectName, CIMQualifierType pQualifierType) { + this.iMethodCall = "CreateQualifier"; + this.iObjectName = pObjectName; + this.iQualifierType = pQualifierType; + } + + /** + * Returns the qualifier type + * + * @return The qualifier type + */ + public CIMQualifierType getQualifierType() { + return this.iQualifierType; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteClassOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteClassOp.java similarity index 61% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteClassOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteClassOp.java index 583e7ee..f6f039a 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteClassOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteClassOp.java @@ -1,66 +1,64 @@ -/* - CIMDeleteClassOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * CIMDeleteClassOp - * - */ -public class CIMDeleteClassOp extends CIMOperation { - - /** - * Ctor. - * - * @param pObjectName - */ - public CIMDeleteClassOp(CIMObjectPath pObjectName) { - this.iMethodCall = "DeleteClass"; - this.iObjectName = pObjectName; - } -} +/* + CIMDeleteClassOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * CIMDeleteClassOp + * + */ +public class CIMDeleteClassOp extends CIMOperation { + + /** + * Ctor. + * + * @param pObjectName + */ + public CIMDeleteClassOp(CIMObjectPath pObjectName) { + this.iMethodCall = "DeleteClass"; + this.iObjectName = pObjectName; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteInstanceOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteInstanceOp.java similarity index 61% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteInstanceOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteInstanceOp.java index 94d5e86..6ed4219 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteInstanceOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteInstanceOp.java @@ -1,66 +1,64 @@ -/* - CIMDeleteInstanceOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * CIMDeleteInstanceOp - * - */ -public class CIMDeleteInstanceOp extends CIMOperation { - - /** - * Ctor. - * - * @param pObjectName - */ - public CIMDeleteInstanceOp(CIMObjectPath pObjectName) { - this.iMethodCall = "DeleteInstance"; - this.iObjectName = pObjectName; - } -} +/* + CIMDeleteInstanceOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * CIMDeleteInstanceOp + * + */ +public class CIMDeleteInstanceOp extends CIMOperation { + + /** + * Ctor. + * + * @param pObjectName + */ + public CIMDeleteInstanceOp(CIMObjectPath pObjectName) { + this.iMethodCall = "DeleteInstance"; + this.iObjectName = pObjectName; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteNameSpaceOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteNameSpaceOp.java similarity index 64% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteNameSpaceOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteNameSpaceOp.java index 48f8daa..4cab903 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteNameSpaceOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteNameSpaceOp.java @@ -1,66 +1,63 @@ -/* - CIMDeleteNameSpaceOp.java - - (C) Copyright IBM Corp. 2005, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 3001357 2010-05-18 blaschke-oss CIMDeleteNameSpaceOp name clash - * 3525145 2012-05-09 blaschke-oss Remove CIMDeleteNameSpaceOp.getNamespace - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * CIMDeleteNameSpaceOp - * - */ -public class CIMDeleteNameSpaceOp extends CIMOperation { - - /** - * Ctor. - * - * @param pNamespace - */ - public CIMDeleteNameSpaceOp(String pNamespace) { - this.iNameSpace = pNamespace; - } - -} +/* + CIMDeleteNameSpaceOp.java + + (C) Copyright IBM Corp. 2005, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 3001357 2010-05-18 blaschke-oss CIMDeleteNameSpaceOp name clash + * 3525145 2012-05-09 blaschke-oss Remove CIMDeleteNameSpaceOp.getNamespace + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * CIMDeleteNameSpaceOp + * + */ +public class CIMDeleteNameSpaceOp extends CIMOperation { + + /** + * Ctor. + * + * @param pNamespace + */ + public CIMDeleteNameSpaceOp(String pNamespace) { + this.iNameSpace = pNamespace; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteQualifierTypeOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteQualifierTypeOp.java similarity index 61% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteQualifierTypeOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteQualifierTypeOp.java index 80261fe..87851d0 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteQualifierTypeOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMDeleteQualifierTypeOp.java @@ -1,66 +1,64 @@ -/* - CIMDeleteQualifierTypeOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * CIMDeleteQualifierTypeOp - * - */ -public class CIMDeleteQualifierTypeOp extends CIMOperation { - - /** - * Ctor. - * - * @param pObjectName - */ - public CIMDeleteQualifierTypeOp(CIMObjectPath pObjectName) { - this.iMethodCall = "DeleteQualifier"; - this.iObjectName = pObjectName; - } -} +/* + CIMDeleteQualifierTypeOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * CIMDeleteQualifierTypeOp + * + */ +public class CIMDeleteQualifierTypeOp extends CIMOperation { + + /** + * Ctor. + * + * @param pObjectName + */ + public CIMDeleteQualifierTypeOp(CIMObjectPath pObjectName) { + this.iMethodCall = "DeleteQualifier"; + this.iObjectName = pObjectName; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumClassNamesOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumClassNamesOp.java similarity index 63% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumClassNamesOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumClassNamesOp.java index 1da8049..59ee6d9 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumClassNamesOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumClassNamesOp.java @@ -1,80 +1,76 @@ -/* - CIMEnumClassNamesOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * CIMEnumClassNamesOp - * - */ -public class CIMEnumClassNamesOp extends CIMOperation { - - protected boolean iDeep; - - /** - * Ctor. - * - * @param objectName - * @param deep - */ - public CIMEnumClassNamesOp(CIMObjectPath objectName, boolean deep) { - this.iMethodCall = "EnumerateClassNames"; - this.iObjectName = objectName; - this.iDeep = deep; - } - - /** - * Returns deep - * - * @return The value of deep - */ - public boolean isDeep() { - return this.iDeep; - } - -} +/* + CIMEnumClassNamesOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * CIMEnumClassNamesOp + * + */ +public class CIMEnumClassNamesOp extends CIMOperation { + protected boolean iDeep; + + /** + * Ctor. + * + * @param objectName + * @param deep + */ + public CIMEnumClassNamesOp(CIMObjectPath objectName, boolean deep) { + this.iMethodCall = "EnumerateClassNames"; + this.iObjectName = objectName; + this.iDeep = deep; + } + + /** + * Returns deep + * + * @return The value of deep + */ + public boolean isDeep() { + return this.iDeep; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumClassesOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumClassesOp.java similarity index 67% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumClassesOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumClassesOp.java index 92c2210..e5ff842 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumClassesOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumClassesOp.java @@ -1,120 +1,121 @@ -/* - CIMEnumClassesOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * CIMEnumClassesOp - * - */ -public class CIMEnumClassesOp extends CIMOperation { - - protected boolean iDeep; - - protected boolean iLocalOnly; - - protected boolean iIncludeQualifiers; - - protected boolean iIncludeClassOrigin; - - /** - * Ctor. - * - * @param pObjectName - * @param pDeep - * @param pLocalOnly - * @param pIncludeQualifiers - * @param pIncludeClassOrigin - */ - public CIMEnumClassesOp(CIMObjectPath pObjectName, boolean pDeep, boolean pLocalOnly, - boolean pIncludeQualifiers, boolean pIncludeClassOrigin) { - this.iMethodCall = "EnumerateClasses"; - this.iObjectName = pObjectName; - this.iDeep = pDeep; - this.iLocalOnly = pLocalOnly; - this.iIncludeClassOrigin = pIncludeClassOrigin; - this.iIncludeQualifiers = pIncludeQualifiers; - } - - /** - * Returns if deep is set - * - * @return The value of deep - */ - public boolean isDeep() { - return this.iDeep; - } - - /** - * Returns if includeClassOrigin is set - * - * @return The value of includeClassOrigin - */ - public boolean isIncludeClassOrigin() { - return this.iIncludeClassOrigin; - } - - /** - * Returns if includeQualifiers is set - * - * @return The value of includeQualifiers - */ - public boolean isIncludeQualifiers() { - return this.iIncludeQualifiers; - } - - /** - * Returns if localOnly is set - * - * @return The value of localOnly - */ - public boolean isLocalOnly() { - return this.iLocalOnly; - } - -} +/* + CIMEnumClassesOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * CIMEnumClassesOp + * + */ +public class CIMEnumClassesOp extends CIMOperation { + protected boolean iDeep; + + protected boolean iLocalOnly; + + protected boolean iIncludeQualifiers; + + protected boolean iIncludeClassOrigin; + + /** + * Ctor. + * + * @param pObjectName + * @param pDeep + * @param pLocalOnly + * @param pIncludeQualifiers + * @param pIncludeClassOrigin + */ + public CIMEnumClassesOp( + CIMObjectPath pObjectName, + boolean pDeep, + boolean pLocalOnly, + boolean pIncludeQualifiers, + boolean pIncludeClassOrigin + ) { + this.iMethodCall = "EnumerateClasses"; + this.iObjectName = pObjectName; + this.iDeep = pDeep; + this.iLocalOnly = pLocalOnly; + this.iIncludeClassOrigin = pIncludeClassOrigin; + this.iIncludeQualifiers = pIncludeQualifiers; + } + + /** + * Returns if deep is set + * + * @return The value of deep + */ + public boolean isDeep() { + return this.iDeep; + } + + /** + * Returns if includeClassOrigin is set + * + * @return The value of includeClassOrigin + */ + public boolean isIncludeClassOrigin() { + return this.iIncludeClassOrigin; + } + + /** + * Returns if includeQualifiers is set + * + * @return The value of includeQualifiers + */ + public boolean isIncludeQualifiers() { + return this.iIncludeQualifiers; + } + + /** + * Returns if localOnly is set + * + * @return The value of localOnly + */ + public boolean isLocalOnly() { + return this.iLocalOnly; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumInstanceNamesOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumInstanceNamesOp.java similarity index 61% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumInstanceNamesOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumInstanceNamesOp.java index 3df329f..6cb4c32 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumInstanceNamesOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumInstanceNamesOp.java @@ -1,66 +1,64 @@ -/* - CIMEnumInstanceNamesOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * CIMEnumInstanceNamesOp - * - */ -public class CIMEnumInstanceNamesOp extends CIMOperation { - - /** - * Ctor. - * - * @param objectName - */ - public CIMEnumInstanceNamesOp(CIMObjectPath objectName) { - this.iMethodCall = "EnumerateInstanceNames"; - this.iObjectName = objectName; - } -} +/* + CIMEnumInstanceNamesOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * CIMEnumInstanceNamesOp + * + */ +public class CIMEnumInstanceNamesOp extends CIMOperation { + + /** + * Ctor. + * + * @param objectName + */ + public CIMEnumInstanceNamesOp(CIMObjectPath objectName) { + this.iMethodCall = "EnumerateInstanceNames"; + this.iObjectName = objectName; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumInstancesOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumInstancesOp.java similarity index 68% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumInstancesOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumInstancesOp.java index 14c5bd6..69a8e51 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumInstancesOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumInstancesOp.java @@ -1,133 +1,135 @@ -/* - CIMEnumInstancesOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * CIMEnumInstancesOp - * - */ -public class CIMEnumInstancesOp extends CIMOperation { - - protected boolean iDeep; - - protected boolean iLocalOnly; - - protected boolean iIncludeQualifiers; - - protected boolean iIncludeClassOrigin; - - protected String[] iPropertyList; - - /** - * Ctor. - * - * @param objectName - * @param deep - * @param localOnly - * @param includeQualifiers - * @param includeClassOrigin - * @param propertyList - */ - public CIMEnumInstancesOp(CIMObjectPath objectName, boolean deep, boolean localOnly, - boolean includeQualifiers, boolean includeClassOrigin, String[] propertyList) { - this.iMethodCall = "EnumerateInstances"; - this.iObjectName = objectName; - this.iDeep = deep; - this.iLocalOnly = localOnly; - this.iIncludeClassOrigin = includeClassOrigin; - this.iIncludeQualifiers = includeQualifiers; - this.iPropertyList = propertyList; - } - - /** - * Returns deep - * - * @return The value of deep. - */ - public boolean isDeep() { - return this.iDeep; - } - - /** - * Returns includeClassOrigin - * - * @return The value of includeClassOrigin. - */ - public boolean isIncludeClassOrigin() { - return this.iIncludeClassOrigin; - } - - /** - * Returns includeQualifiers - * - * @return The value of includeQualifiers. - */ - public boolean isIncludeQualifiers() { - return this.iIncludeQualifiers; - } - - /** - * Returns localOnly - * - * @return The value of localOnly. - */ - public boolean isLocalOnly() { - return this.iLocalOnly; - } - - /** - * Returns propertyList - * - * @return The value of propertyList. - */ - public String[] getPropertyList() { - return this.iPropertyList; - } - -} +/* + CIMEnumInstancesOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * CIMEnumInstancesOp + * + */ +public class CIMEnumInstancesOp extends CIMOperation { + protected boolean iDeep; + + protected boolean iLocalOnly; + + protected boolean iIncludeQualifiers; + + protected boolean iIncludeClassOrigin; + + protected String[] iPropertyList; + + /** + * Ctor. + * + * @param objectName + * @param deep + * @param localOnly + * @param includeQualifiers + * @param includeClassOrigin + * @param propertyList + */ + public CIMEnumInstancesOp( + CIMObjectPath objectName, + boolean deep, + boolean localOnly, + boolean includeQualifiers, + boolean includeClassOrigin, + String[] propertyList + ) { + this.iMethodCall = "EnumerateInstances"; + this.iObjectName = objectName; + this.iDeep = deep; + this.iLocalOnly = localOnly; + this.iIncludeClassOrigin = includeClassOrigin; + this.iIncludeQualifiers = includeQualifiers; + this.iPropertyList = propertyList; + } + + /** + * Returns deep + * + * @return The value of deep. + */ + public boolean isDeep() { + return this.iDeep; + } + + /** + * Returns includeClassOrigin + * + * @return The value of includeClassOrigin. + */ + public boolean isIncludeClassOrigin() { + return this.iIncludeClassOrigin; + } + + /** + * Returns includeQualifiers + * + * @return The value of includeQualifiers. + */ + public boolean isIncludeQualifiers() { + return this.iIncludeQualifiers; + } + + /** + * Returns localOnly + * + * @return The value of localOnly. + */ + public boolean isLocalOnly() { + return this.iLocalOnly; + } + + /** + * Returns propertyList + * + * @return The value of propertyList. + */ + public String[] getPropertyList() { + return this.iPropertyList; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumNameSpaceOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumNameSpaceOp.java similarity index 63% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumNameSpaceOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumNameSpaceOp.java index a940053..8796148 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumNameSpaceOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumNameSpaceOp.java @@ -1,65 +1,63 @@ -/* - CIMEnumNameSpaceOp.java - - (C) Copyright IBM Corp. 2005, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 3001357 2010-05-18 blaschke-oss CIMDeleteNameSpaceOp name clash - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * CIMEnumNameSpaceOp - * - */ -public class CIMEnumNameSpaceOp extends CIMOperation { - - /** - * Ctor. - * - * @param pNamespace - */ - public CIMEnumNameSpaceOp(String pNamespace) { - this.iMethodCall = "EnumNameSpace"; - this.iNameSpace = pNamespace; - } -} +/* + CIMEnumNameSpaceOp.java + + (C) Copyright IBM Corp. 2005, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 3001357 2010-05-18 blaschke-oss CIMDeleteNameSpaceOp name clash + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * CIMEnumNameSpaceOp + * + */ +public class CIMEnumNameSpaceOp extends CIMOperation { + + /** + * Ctor. + * + * @param pNamespace + */ + public CIMEnumNameSpaceOp(String pNamespace) { + this.iMethodCall = "EnumNameSpace"; + this.iNameSpace = pNamespace; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumQualifierTypesOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumQualifierTypesOp.java similarity index 61% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumQualifierTypesOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumQualifierTypesOp.java index 9b1554b..5f16d6b 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumQualifierTypesOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMEnumQualifierTypesOp.java @@ -1,66 +1,64 @@ -/* - CIMEnumQualifierTypesOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * CIMEnumQualifierTypesOp - * - */ -public class CIMEnumQualifierTypesOp extends CIMOperation { - - /** - * Ctor. - * - * @param pObjectName - */ - public CIMEnumQualifierTypesOp(CIMObjectPath pObjectName) { - this.iMethodCall = "EnumerateQualifiers"; - this.iObjectName = pObjectName; - } -} +/* + CIMEnumQualifierTypesOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * CIMEnumQualifierTypesOp + * + */ +public class CIMEnumQualifierTypesOp extends CIMOperation { + + /** + * Ctor. + * + * @param pObjectName + */ + public CIMEnumQualifierTypesOp(CIMObjectPath pObjectName) { + this.iMethodCall = "EnumerateQualifiers"; + this.iObjectName = pObjectName; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMExecQueryOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMExecQueryOp.java similarity index 66% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMExecQueryOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMExecQueryOp.java index bf05624..470de49 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMExecQueryOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMExecQueryOp.java @@ -1,93 +1,89 @@ -/* - CIMExecQueryOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * CIMExecQueryOp - * - */ -public class CIMExecQueryOp extends CIMOperation { - - protected String iQuery; - - protected String iQueryLanguage; - - /** - * Ctor. - * - * @param objectName - * @param query - * @param queryLanguage - */ - public CIMExecQueryOp(CIMObjectPath objectName, String query, String queryLanguage) { - this.iMethodCall = "ExecQuery"; - this.iObjectName = objectName; - this.iQuery = query; - this.iQueryLanguage = queryLanguage; - } - - /** - * Returns query - * - * @return The value of query. - */ - public String getQuery() { - return this.iQuery; - } - - /** - * Returns queryLanguage - * - * @return The value of queryLanguage. - */ - public String getQueryLanguage() { - return this.iQueryLanguage; - } - -} +/* + CIMExecQueryOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * CIMExecQueryOp + * + */ +public class CIMExecQueryOp extends CIMOperation { + protected String iQuery; + + protected String iQueryLanguage; + + /** + * Ctor. + * + * @param objectName + * @param query + * @param queryLanguage + */ + public CIMExecQueryOp(CIMObjectPath objectName, String query, String queryLanguage) { + this.iMethodCall = "ExecQuery"; + this.iObjectName = objectName; + this.iQuery = query; + this.iQueryLanguage = queryLanguage; + } + + /** + * Returns query + * + * @return The value of query. + */ + public String getQuery() { + return this.iQuery; + } + + /** + * Returns queryLanguage + * + * @return The value of queryLanguage. + */ + public String getQueryLanguage() { + return this.iQueryLanguage; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMGetClassOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMGetClassOp.java similarity index 68% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMGetClassOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMGetClassOp.java index 3cf683b..b742f80 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMGetClassOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMGetClassOp.java @@ -1,121 +1,121 @@ -/* - CIMGetClassOp.java - - (C) Copyright IBM Corp. 2005, 2012 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 3525150 2012-05-09 blaschke-oss Remove CIMGetClassOp.getPropertyLis - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * CIMGetClassOp - * - */ -public class CIMGetClassOp extends CIMSingleResultOperation { - - protected boolean iLocalOnly; - - protected boolean iIncludeQualifiers; - - protected boolean iIncludeClassOrigin; - - protected String[] iPropertyList; - - /** - * Ctor. - * - * @param pObjectName - * @param pLocalOnly - * @param pIncludeQualifiers - * @param pIncludeClassOrigin - * @param pPropertyList - */ - public CIMGetClassOp(CIMObjectPath pObjectName, boolean pLocalOnly, boolean pIncludeQualifiers, - boolean pIncludeClassOrigin, String[] pPropertyList) { - - this.iMethodCall = "GetClass"; - this.iObjectName = pObjectName; - this.iLocalOnly = pLocalOnly; - this.iIncludeClassOrigin = pIncludeClassOrigin; - this.iIncludeQualifiers = pIncludeQualifiers; - } - - /** - * Returns includeClassOrigin - * - * @return The value of includeClassOrigin. - */ - public boolean isIncludeClassOrigin() { - return this.iIncludeClassOrigin; - } - - /** - * Returns includeQualifiers - * - * @return The value of includeQualifiers. - */ - public boolean isIncludeQualifiers() { - return this.iIncludeQualifiers; - } - - /** - * Returns localOnly - * - * @return The value of localOnly. - */ - public boolean isLocalOnly() { - return this.iLocalOnly; - } - - /** - * Returns propertyList - * - * @return The value of propertyList. - */ - public String[] getPropertyList() { - return this.iPropertyList; - } - -} +/* + CIMGetClassOp.java + + (C) Copyright IBM Corp. 2005, 2012 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 3525150 2012-05-09 blaschke-oss Remove CIMGetClassOp.getPropertyLis + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * CIMGetClassOp + * + */ +public class CIMGetClassOp extends CIMSingleResultOperation { + protected boolean iLocalOnly; + + protected boolean iIncludeQualifiers; + + protected boolean iIncludeClassOrigin; + + protected String[] iPropertyList; + + /** + * Ctor. + * + * @param pObjectName + * @param pLocalOnly + * @param pIncludeQualifiers + * @param pIncludeClassOrigin + * @param pPropertyList + */ + public CIMGetClassOp( + CIMObjectPath pObjectName, + boolean pLocalOnly, + boolean pIncludeQualifiers, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) { + this.iMethodCall = "GetClass"; + this.iObjectName = pObjectName; + this.iLocalOnly = pLocalOnly; + this.iIncludeClassOrigin = pIncludeClassOrigin; + this.iIncludeQualifiers = pIncludeQualifiers; + } + + /** + * Returns includeClassOrigin + * + * @return The value of includeClassOrigin. + */ + public boolean isIncludeClassOrigin() { + return this.iIncludeClassOrigin; + } + + /** + * Returns includeQualifiers + * + * @return The value of includeQualifiers. + */ + public boolean isIncludeQualifiers() { + return this.iIncludeQualifiers; + } + + /** + * Returns localOnly + * + * @return The value of localOnly. + */ + public boolean isLocalOnly() { + return this.iLocalOnly; + } + + /** + * Returns propertyList + * + * @return The value of propertyList. + */ + public String[] getPropertyList() { + return this.iPropertyList; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMGetInstanceOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMGetInstanceOp.java similarity index 67% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMGetInstanceOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMGetInstanceOp.java index c35ba7e..6477215 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMGetInstanceOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMGetInstanceOp.java @@ -1,120 +1,121 @@ -/* - CIMGetInstanceOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * CIMGetInstanceOp - * - */ -public class CIMGetInstanceOp extends CIMSingleResultOperation { - - protected boolean iLocalOnly; - - protected boolean iIncludeQualifiers; - - protected boolean iIncludeClassOrigin; - - protected String[] iPropertyList; - - /** - * Ctor. - * - * @param pObjectName - * @param pLocalOnly - * @param pIncludeQualifiers - * @param pIncludeClassOrigin - * @param pPropertyList - */ - public CIMGetInstanceOp(CIMObjectPath pObjectName, boolean pLocalOnly, - boolean pIncludeQualifiers, boolean pIncludeClassOrigin, String[] pPropertyList) { - - this.iMethodCall = "GetInstance"; - this.iObjectName = pObjectName; - this.iLocalOnly = pLocalOnly; - this.iIncludeClassOrigin = pIncludeClassOrigin; - this.iIncludeQualifiers = pIncludeQualifiers; - this.iPropertyList = pPropertyList; - } - - /** - * Returns includeClassOrigin - * - * @return The value of includeClassOrigin. - */ - public boolean isIncludeClassOrigin() { - return this.iIncludeClassOrigin; - } - - /** - * Returns includeQualifiers - * - * @return The value of includeQualifiers. - */ - public boolean isIncludeQualifiers() { - return this.iIncludeQualifiers; - } - - /** - * Returns localOnly - * - * @return The value of localOnly. - */ - public boolean isLocalOnly() { - return this.iLocalOnly; - } - - /** - * Returns propertyList - * - * @return The value of propertyList. - */ - public String[] getPropertyList() { - return this.iPropertyList; - } -} +/* + CIMGetInstanceOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * CIMGetInstanceOp + * + */ +public class CIMGetInstanceOp extends CIMSingleResultOperation { + protected boolean iLocalOnly; + + protected boolean iIncludeQualifiers; + + protected boolean iIncludeClassOrigin; + + protected String[] iPropertyList; + + /** + * Ctor. + * + * @param pObjectName + * @param pLocalOnly + * @param pIncludeQualifiers + * @param pIncludeClassOrigin + * @param pPropertyList + */ + public CIMGetInstanceOp( + CIMObjectPath pObjectName, + boolean pLocalOnly, + boolean pIncludeQualifiers, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) { + this.iMethodCall = "GetInstance"; + this.iObjectName = pObjectName; + this.iLocalOnly = pLocalOnly; + this.iIncludeClassOrigin = pIncludeClassOrigin; + this.iIncludeQualifiers = pIncludeQualifiers; + this.iPropertyList = pPropertyList; + } + + /** + * Returns includeClassOrigin + * + * @return The value of includeClassOrigin. + */ + public boolean isIncludeClassOrigin() { + return this.iIncludeClassOrigin; + } + + /** + * Returns includeQualifiers + * + * @return The value of includeQualifiers. + */ + public boolean isIncludeQualifiers() { + return this.iIncludeQualifiers; + } + + /** + * Returns localOnly + * + * @return The value of localOnly. + */ + public boolean isLocalOnly() { + return this.iLocalOnly; + } + + /** + * Returns propertyList + * + * @return The value of propertyList. + */ + public String[] getPropertyList() { + return this.iPropertyList; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMGetPropertyOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMGetPropertyOp.java similarity index 64% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMGetPropertyOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMGetPropertyOp.java index 94a7696..5c61f4a 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMGetPropertyOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMGetPropertyOp.java @@ -1,80 +1,76 @@ -/* - CIMGetPropertyOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * CIMGetPropertyOp - * - */ -public class CIMGetPropertyOp extends CIMSingleResultOperation { - - protected String iPropertyName; - - /** - * Ctor. - * - * @param pObjectName - * @param pPropertyName - */ - public CIMGetPropertyOp(CIMObjectPath pObjectName, String pPropertyName) { - this.iMethodCall = "GetProperty"; - this.iObjectName = pObjectName; - this.iPropertyName = pPropertyName; - } - - /** - * Returns propertyName - * - * @return The value of propertyName. - */ - public String getPropertyName() { - return this.iPropertyName; - } - -} +/* + CIMGetPropertyOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * CIMGetPropertyOp + * + */ +public class CIMGetPropertyOp extends CIMSingleResultOperation { + protected String iPropertyName; + + /** + * Ctor. + * + * @param pObjectName + * @param pPropertyName + */ + public CIMGetPropertyOp(CIMObjectPath pObjectName, String pPropertyName) { + this.iMethodCall = "GetProperty"; + this.iObjectName = pObjectName; + this.iPropertyName = pPropertyName; + } + + /** + * Returns propertyName + * + * @return The value of propertyName. + */ + public String getPropertyName() { + return this.iPropertyName; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMGetQualifierTypeOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMGetQualifierTypeOp.java similarity index 65% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMGetQualifierTypeOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMGetQualifierTypeOp.java index 1730fe5..e4709e1 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMGetQualifierTypeOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMGetQualifierTypeOp.java @@ -1,80 +1,76 @@ -/* - CIMGetQualifierTypeOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * CIMGetQualifierTypeOp - * - */ -public class CIMGetQualifierTypeOp extends CIMSingleResultOperation { - - protected String iQualifierType; - - /** - * Ctor. - * - * @param pObjectName - * @param pQualifierType - */ - public CIMGetQualifierTypeOp(CIMObjectPath pObjectName, String pQualifierType) { - this.iMethodCall = "GetQualifierType"; - this.iObjectName = pObjectName; - this.iQualifierType = pQualifierType; - } - - /** - * Returns qualifierType - * - * @return The value of qualifierType. - */ - public String getQualifierType() { - return this.iQualifierType; - } - -} +/* + CIMGetQualifierTypeOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * CIMGetQualifierTypeOp + * + */ +public class CIMGetQualifierTypeOp extends CIMSingleResultOperation { + protected String iQualifierType; + + /** + * Ctor. + * + * @param pObjectName + * @param pQualifierType + */ + public CIMGetQualifierTypeOp(CIMObjectPath pObjectName, String pQualifierType) { + this.iMethodCall = "GetQualifierType"; + this.iObjectName = pObjectName; + this.iQualifierType = pQualifierType; + } + + /** + * Returns qualifierType + * + * @return The value of qualifierType. + */ + public String getQualifierType() { + return this.iQualifierType; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMInvokeMethodOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMInvokeMethodOp.java similarity index 65% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMInvokeMethodOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMInvokeMethodOp.java index 897c171..305d754 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMInvokeMethodOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMInvokeMethodOp.java @@ -1,109 +1,109 @@ -/* - CIMInvokeMethodOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMArgument; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * CIMInvokeMethodOp - * - */ -public class CIMInvokeMethodOp extends CIMOperation { - - protected String iMethodName; - - protected CIMArgument[] iInParams; - - protected CIMArgument[] iOutParams; - - /** - * Ctor. - * - * @param pObjectName - * @param pMethodName - * @param pInParams - * @param pOutParams - */ - public CIMInvokeMethodOp(CIMObjectPath pObjectName, String pMethodName, - CIMArgument[] pInParams, CIMArgument[] pOutParams) { - this.iMethodCall = "InvokeMethod"; - this.iObjectName = pObjectName; - this.iMethodName = pMethodName; - this.iInParams = pInParams; - this.iOutParams = pOutParams; - } - - /** - * Returns inParameters - * - * @return The value of inParameters. - */ - public CIMArgument[] getInParams() { - return this.iInParams; - } - - /** - * Returns methodName - * - * @return The value of methodName. - */ - public String getMethodName() { - return this.iMethodName; - } - - /** - * Returns outParameters - * - * @return The value of outParameters. - */ - public CIMArgument[] getOutParams() { - return this.iOutParams; - } - -} +/* + CIMInvokeMethodOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMArgument; +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * CIMInvokeMethodOp + * + */ +public class CIMInvokeMethodOp extends CIMOperation { + protected String iMethodName; + + protected CIMArgument[] iInParams; + + protected CIMArgument[] iOutParams; + + /** + * Ctor. + * + * @param pObjectName + * @param pMethodName + * @param pInParams + * @param pOutParams + */ + public CIMInvokeMethodOp( + CIMObjectPath pObjectName, + String pMethodName, + CIMArgument[] pInParams, + CIMArgument[] pOutParams + ) { + this.iMethodCall = "InvokeMethod"; + this.iObjectName = pObjectName; + this.iMethodName = pMethodName; + this.iInParams = pInParams; + this.iOutParams = pOutParams; + } + + /** + * Returns inParameters + * + * @return The value of inParameters. + */ + public CIMArgument[] getInParams() { + return this.iInParams; + } + + /** + * Returns methodName + * + * @return The value of methodName. + */ + public String getMethodName() { + return this.iMethodName; + } + + /** + * Returns outParameters + * + * @return The value of outParameters. + */ + public CIMArgument[] getOutParams() { + return this.iOutParams; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMOperation.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMOperation.java similarity index 70% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMOperation.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMOperation.java index b1cfae4..f868515 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMOperation.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMOperation.java @@ -1,133 +1,130 @@ -/* - CIMOperation.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import org.sentrysoftware.wbem.javax.wbem.WBEMException; - -/** - * CIMOperation - * - */ -public abstract class CIMOperation { - - protected CIMObjectPath iObjectName; - - protected String iNameSpace; - - protected String iMethodCall; - - protected Object iResult; - - /** - * Returns the object name - * - * @return The object name - */ - public CIMObjectPath getObjectName() { - return this.iObjectName; - } - - /** - * Returns the namespace - * - * @return The namespace - */ - public String getNameSpace() { - return this.iNameSpace; - } - - /** - * Sets the namespace - * - * @param pNamespace - * The namespace - */ - public void setNameSpace(String pNamespace) { - this.iNameSpace = pNamespace; - } - - /** - * Returns the method call - * - * @return The method call - */ - public String getMethodCall() { - return this.iMethodCall; - } - - /** - * Returns if an (uncaught) exception occurred - * - * @return true if an (uncaught) exception occurred, - * false otherwise - */ - public boolean isException() { - return (this.iResult instanceof Exception); - } - - /** - * Returns the result of the operation - * - * @return The result - * @throws WBEMException - */ - public Object getResult() throws WBEMException { - if (this.iResult instanceof WBEMException) throw (WBEMException) this.iResult; - return this.iResult; - } - - /** - * Sets the operation result - * - * @param pResult - * The result - */ - public void setResult(Object pResult) { - this.iResult = pResult; - } -} +/* + CIMOperation.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.wbem.WBEMException; + +/** + * CIMOperation + * + */ +public abstract class CIMOperation { + protected CIMObjectPath iObjectName; + + protected String iNameSpace; + + protected String iMethodCall; + + protected Object iResult; + + /** + * Returns the object name + * + * @return The object name + */ + public CIMObjectPath getObjectName() { + return this.iObjectName; + } + + /** + * Returns the namespace + * + * @return The namespace + */ + public String getNameSpace() { + return this.iNameSpace; + } + + /** + * Sets the namespace + * + * @param pNamespace + * The namespace + */ + public void setNameSpace(String pNamespace) { + this.iNameSpace = pNamespace; + } + + /** + * Returns the method call + * + * @return The method call + */ + public String getMethodCall() { + return this.iMethodCall; + } + + /** + * Returns if an (uncaught) exception occurred + * + * @return true if an (uncaught) exception occurred, + * false otherwise + */ + public boolean isException() { + return (this.iResult instanceof Exception); + } + + /** + * Returns the result of the operation + * + * @return The result + * @throws WBEMException + */ + public Object getResult() throws WBEMException { + if (this.iResult instanceof WBEMException) throw (WBEMException) this.iResult; + return this.iResult; + } + + /** + * Sets the operation result + * + * @param pResult + * The result + */ + public void setResult(Object pResult) { + this.iResult = pResult; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMReferenceNamesOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMReferenceNamesOp.java similarity index 66% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMReferenceNamesOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMReferenceNamesOp.java index d7cbbac..7db3498 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMReferenceNamesOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMReferenceNamesOp.java @@ -1,93 +1,89 @@ -/* - CIMReferenceNamesOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * CIMReferenceNamesOp - * - */ -public class CIMReferenceNamesOp extends CIMOperation { - - protected String iResultClass; - - protected String iResultRole; - - /** - * Ctor. - * - * @param pObjectName - * @param pResultClass - * @param pRole - */ - public CIMReferenceNamesOp(CIMObjectPath pObjectName, String pResultClass, String pRole) { - this.iMethodCall = "ReferenceNames"; - this.iObjectName = pObjectName; - this.iResultClass = pResultClass; - this.iResultRole = pRole; - } - - /** - * Returns resultClass - * - * @return The value of resultClass. - */ - public String getResultClass() { - return this.iResultClass; - } - - /** - * Returns resultRole - * - * @return The value of resultRole. - */ - public String getResultRole() { - return this.iResultRole; - } - -} +/* + CIMReferenceNamesOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * CIMReferenceNamesOp + * + */ +public class CIMReferenceNamesOp extends CIMOperation { + protected String iResultClass; + + protected String iResultRole; + + /** + * Ctor. + * + * @param pObjectName + * @param pResultClass + * @param pRole + */ + public CIMReferenceNamesOp(CIMObjectPath pObjectName, String pResultClass, String pRole) { + this.iMethodCall = "ReferenceNames"; + this.iObjectName = pObjectName; + this.iResultClass = pResultClass; + this.iResultRole = pRole; + } + + /** + * Returns resultClass + * + * @return The value of resultClass. + */ + public String getResultClass() { + return this.iResultClass; + } + + /** + * Returns resultRole + * + * @return The value of resultRole. + */ + public String getResultRole() { + return this.iResultRole; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMReferencesOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMReferencesOp.java similarity index 68% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMReferencesOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMReferencesOp.java index 8350e91..90af1f9 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMReferencesOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMReferencesOp.java @@ -1,132 +1,134 @@ -/* - CIMReferencesOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * CIMReferencesOp - * - */ -public class CIMReferencesOp extends CIMOperation { - - protected String iResultClass; - - protected String iRole; - - protected boolean iIncludeQualifiers; - - protected boolean iIncludeClassOrigin; - - protected String[] iPropertyList; - - /** - * Ctor. - * - * @param pObjectName - * @param pResultClass - * @param pRole - * @param pIncludeQualifiers - * @param pIncludeClassOrigin - * @param pPropertyList - */ - public CIMReferencesOp(CIMObjectPath pObjectName, String pResultClass, String pRole, - boolean pIncludeQualifiers, boolean pIncludeClassOrigin, String[] pPropertyList) { - this.iMethodCall = "References"; - this.iObjectName = pObjectName; - this.iResultClass = pResultClass; - this.iRole = pRole; - this.iIncludeQualifiers = pIncludeQualifiers; - this.iIncludeClassOrigin = pIncludeClassOrigin; - } - - /** - * Returns includeClassOrigin - * - * @return The value of includeClassOrigin. - */ - public boolean isIncludeClassOrigin() { - return this.iIncludeClassOrigin; - } - - /** - * Returns includeQualifiers - * - * @return The value of includeQualifiers. - */ - public boolean isIncludeQualifiers() { - return this.iIncludeQualifiers; - } - - /** - * Returns propertyList - * - * @return The value of propertyList. - */ - public String[] getPropertyList() { - return this.iPropertyList; - } - - /** - * Returns resultClass - * - * @return The value of resultClass. - */ - public String getResultClass() { - return this.iResultClass; - } - - /** - * Returns role - * - * @return The value of role. - */ - public String getRole() { - return this.iRole; - } - -} +/* + CIMReferencesOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * CIMReferencesOp + * + */ +public class CIMReferencesOp extends CIMOperation { + protected String iResultClass; + + protected String iRole; + + protected boolean iIncludeQualifiers; + + protected boolean iIncludeClassOrigin; + + protected String[] iPropertyList; + + /** + * Ctor. + * + * @param pObjectName + * @param pResultClass + * @param pRole + * @param pIncludeQualifiers + * @param pIncludeClassOrigin + * @param pPropertyList + */ + public CIMReferencesOp( + CIMObjectPath pObjectName, + String pResultClass, + String pRole, + boolean pIncludeQualifiers, + boolean pIncludeClassOrigin, + String[] pPropertyList + ) { + this.iMethodCall = "References"; + this.iObjectName = pObjectName; + this.iResultClass = pResultClass; + this.iRole = pRole; + this.iIncludeQualifiers = pIncludeQualifiers; + this.iIncludeClassOrigin = pIncludeClassOrigin; + } + + /** + * Returns includeClassOrigin + * + * @return The value of includeClassOrigin. + */ + public boolean isIncludeClassOrigin() { + return this.iIncludeClassOrigin; + } + + /** + * Returns includeQualifiers + * + * @return The value of includeQualifiers. + */ + public boolean isIncludeQualifiers() { + return this.iIncludeQualifiers; + } + + /** + * Returns propertyList + * + * @return The value of propertyList. + */ + public String[] getPropertyList() { + return this.iPropertyList; + } + + /** + * Returns resultClass + * + * @return The value of resultClass. + */ + public String getResultClass() { + return this.iResultClass; + } + + /** + * Returns role + * + * @return The value of role. + */ + public String getRole() { + return this.iRole; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMSetClassOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMSetClassOp.java similarity index 62% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMSetClassOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMSetClassOp.java index ec1c93a..ecc16a1 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMSetClassOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMSetClassOp.java @@ -1,81 +1,77 @@ -/* - CIMSetClassOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMClass; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * CIMSetClassOp - * - */ -public class CIMSetClassOp extends CIMOperation { - - protected CIMClass iCimClass; - - /** - * Ctor. - * - * @param objectName - * @param cimClass - */ - public CIMSetClassOp(CIMObjectPath objectName, CIMClass cimClass) { - this.iMethodCall = "SetClass"; - this.iObjectName = objectName; - this.iCimClass = cimClass; - } - - /** - * Returns cimClass - * - * @return The value of cimClass. - */ - public CIMClass getCimClass() { - return this.iCimClass; - } - -} +/* + CIMSetClassOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMClass; +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * CIMSetClassOp + * + */ +public class CIMSetClassOp extends CIMOperation { + protected CIMClass iCimClass; + + /** + * Ctor. + * + * @param objectName + * @param cimClass + */ + public CIMSetClassOp(CIMObjectPath objectName, CIMClass cimClass) { + this.iMethodCall = "SetClass"; + this.iObjectName = objectName; + this.iCimClass = cimClass; + } + + /** + * Returns cimClass + * + * @return The value of cimClass. + */ + public CIMClass getCimClass() { + return this.iCimClass; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMSetInstanceOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMSetInstanceOp.java similarity index 64% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMSetInstanceOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMSetInstanceOp.java index 25925b2..160f299 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMSetInstanceOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMSetInstanceOp.java @@ -1,108 +1,108 @@ -/* - CIMSetInstanceOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMInstance; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * CIMSetInstanceOp - * - */ -public class CIMSetInstanceOp extends CIMOperation { - - protected CIMInstance iInstance; - - protected boolean iIncludeQualifiers; - - protected String[] iPropertyList; - - /** - * Ctor. - * - * @param objectName - * @param instance - * @param includeQualifiers - * @param propertyList - */ - public CIMSetInstanceOp(CIMObjectPath objectName, CIMInstance instance, - boolean includeQualifiers, String[] propertyList) { - this.iMethodCall = "SetInstance"; - this.iObjectName = objectName; - this.iInstance = instance; - this.iIncludeQualifiers = includeQualifiers; - this.iPropertyList = propertyList; - } - - /** - * Returns includeQualifiers - * - * @return The value of includeQualifiers. - */ - public boolean isIncludeQualifiers() { - return this.iIncludeQualifiers; - } - - /** - * Returns instance - * - * @return The value of instance. - */ - public CIMInstance getInstance() { - return this.iInstance; - } - - /** - * Returns propertyList - * - * @return The value of propertyList. - */ - public String[] getPropertyList() { - return this.iPropertyList; - } - -} +/* + CIMSetInstanceOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMInstance; +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * CIMSetInstanceOp + * + */ +public class CIMSetInstanceOp extends CIMOperation { + protected CIMInstance iInstance; + + protected boolean iIncludeQualifiers; + + protected String[] iPropertyList; + + /** + * Ctor. + * + * @param objectName + * @param instance + * @param includeQualifiers + * @param propertyList + */ + public CIMSetInstanceOp( + CIMObjectPath objectName, + CIMInstance instance, + boolean includeQualifiers, + String[] propertyList + ) { + this.iMethodCall = "SetInstance"; + this.iObjectName = objectName; + this.iInstance = instance; + this.iIncludeQualifiers = includeQualifiers; + this.iPropertyList = propertyList; + } + + /** + * Returns includeQualifiers + * + * @return The value of includeQualifiers. + */ + public boolean isIncludeQualifiers() { + return this.iIncludeQualifiers; + } + + /** + * Returns instance + * + * @return The value of instance. + */ + public CIMInstance getInstance() { + return this.iInstance; + } + + /** + * Returns propertyList + * + * @return The value of propertyList. + */ + public String[] getPropertyList() { + return this.iPropertyList; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMSetPropertyOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMSetPropertyOp.java similarity index 66% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMSetPropertyOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMSetPropertyOp.java index 34318a6..eebfeb4 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMSetPropertyOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMSetPropertyOp.java @@ -1,93 +1,89 @@ -/* - CIMSetPropertyOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; - -/** - * CIMSetPropertyOp - * - */ -public class CIMSetPropertyOp extends CIMOperation { - - protected String iPropertyName; - - protected Object iCimValue; - - /** - * Ctor. - * - * @param objectName - * @param propertyName - * @param cimValue - */ - public CIMSetPropertyOp(CIMObjectPath objectName, String propertyName, Object cimValue) { - this.iMethodCall = "SetProperty"; - this.iObjectName = objectName; - this.iCimValue = cimValue; - this.iPropertyName = propertyName; - } - - /** - * Returns cimValue - * - * @return The value of cimValue. - */ - public Object getCimValue() { - return this.iCimValue; - } - - /** - * Returns propertyName - * - * @return The value of propertyName. - */ - public String getPropertyName() { - return this.iPropertyName; - } - -} +/* + CIMSetPropertyOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; + +/** + * CIMSetPropertyOp + * + */ +public class CIMSetPropertyOp extends CIMOperation { + protected String iPropertyName; + + protected Object iCimValue; + + /** + * Ctor. + * + * @param objectName + * @param propertyName + * @param cimValue + */ + public CIMSetPropertyOp(CIMObjectPath objectName, String propertyName, Object cimValue) { + this.iMethodCall = "SetProperty"; + this.iObjectName = objectName; + this.iCimValue = cimValue; + this.iPropertyName = propertyName; + } + + /** + * Returns cimValue + * + * @return The value of cimValue. + */ + public Object getCimValue() { + return this.iCimValue; + } + + /** + * Returns propertyName + * + * @return The value of propertyName. + */ + public String getPropertyName() { + return this.iPropertyName; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMSetQualifierTypeOp.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMSetQualifierTypeOp.java similarity index 64% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMSetQualifierTypeOp.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMSetQualifierTypeOp.java index 7b7ca7f..2e8a77f 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMSetQualifierTypeOp.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMSetQualifierTypeOp.java @@ -1,82 +1,78 @@ -/* - CIMSetQualifierTypeOp.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import org.sentrysoftware.wbem.javax.cim.CIMQualifierType; - -/** - * CIMSetQualifierTypeOp - * - */ -public class CIMSetQualifierTypeOp extends CIMOperation { - - protected CIMQualifierType iQualifierType; - - /** - * Ctor. - * - * @param objectName - * @param qualifierType - */ - public CIMSetQualifierTypeOp(CIMObjectPath objectName, CIMQualifierType qualifierType) { - this.iMethodCall = "SetQualifierTypeOp"; - this.iObjectName = objectName; - this.iQualifierType = qualifierType; - } - - /** - * Returns qualifierType - * - * @return The value of qualifierType. - */ - public CIMQualifierType getQualifierType() { - return this.iQualifierType; - } - -} +/* + CIMSetQualifierTypeOp.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2797550 2009-06-01 raman_arora JSR48 compliance - add Java Generics + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.cim.CIMQualifierType; + +/** + * CIMSetQualifierTypeOp + * + */ +public class CIMSetQualifierTypeOp extends CIMOperation { + protected CIMQualifierType iQualifierType; + + /** + * Ctor. + * + * @param objectName + * @param qualifierType + */ + public CIMSetQualifierTypeOp(CIMObjectPath objectName, CIMQualifierType qualifierType) { + this.iMethodCall = "SetQualifierTypeOp"; + this.iObjectName = objectName; + this.iQualifierType = qualifierType; + } + + /** + * Returns qualifierType + * + * @return The value of qualifierType. + */ + public CIMQualifierType getQualifierType() { + return this.iQualifierType; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMSingleResultOperation.java b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMSingleResultOperation.java similarity index 61% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMSingleResultOperation.java rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMSingleResultOperation.java index fdc3bf3..7721d52 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/CIMSingleResultOperation.java +++ b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/CIMSingleResultOperation.java @@ -1,72 +1,70 @@ -/* - CIMSingleResultOperation.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535756 2006-08-07 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.wbem.operations; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Vector; - -import org.sentrysoftware.wbem.javax.wbem.WBEMException; - -/** - * CIMSingleResultOperation - * - */ -abstract public class CIMSingleResultOperation extends CIMOperation { - - /* - * (non-Javadoc) - * - * @see org.sblim.wbem.client.operations.CIMOperation#getResult() - */ - @Override - public Object getResult() throws WBEMException { - if (this.iResult instanceof Exception) throw (WBEMException) this.iResult; - if (this.iResult instanceof Vector && ((Vector) this.iResult).size() > 0) return ((Vector) this.iResult) - .elementAt(0); - return null; - } -} +/* + CIMSingleResultOperation.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535756 2006-08-07 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.cimclient.internal.wbem.operations; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Vector; +import org.metricshub.wbem.javax.wbem.WBEMException; + +/** + * CIMSingleResultOperation + * + */ +public abstract class CIMSingleResultOperation extends CIMOperation { + + /* + * (non-Javadoc) + * + * @see org.sblim.wbem.client.operations.CIMOperation#getResult() + */ + @Override + public Object getResult() throws WBEMException { + if (this.iResult instanceof Exception) throw (WBEMException) this.iResult; + if (this.iResult instanceof Vector && ((Vector) this.iResult).size() > 0) return ( + (Vector) this.iResult + ).elementAt(0); + return null; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/package.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/package.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/operations/package.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/operations/package.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/package.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/package.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/wbem/package.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/internal/wbem/package.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/package.html b/src/main/java/org/metricshub/wbem/sblim/cimclient/package.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/cimclient/package.html rename to src/main/java/org/metricshub/wbem/sblim/cimclient/package.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/Advertiser.java b/src/main/java/org/metricshub/wbem/sblim/slp/Advertiser.java similarity index 80% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/Advertiser.java rename to src/main/java/org/metricshub/wbem/sblim/slp/Advertiser.java index 9ee106f..1c2cd11 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/Advertiser.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/Advertiser.java @@ -1,130 +1,126 @@ -/* - ServiceType.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1516246 2006-07-22 lupusalex Integrate SLP client code - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Locale; -import java.util.Vector; - -/** - * The Advertiser is the SA interface, allowing clients to register new service - * instances with SLP, to change the attributes of existing services, and to - * deregister service instances. New registrations and modifications of - * attributes are made in the language locale with which the Advertiser was - * created, deregistrations of service instances are made for all locales. - */ -public interface Advertiser { - - /** - * Return the language locale with which this object was created. - * - * @return The locale - */ - public abstract Locale getLocale(); - - /** - * Register a new service with SLP having the given attributes. The API - * library is required to perform the operation in all scopes obtained - * through configuration. - * - * @param pURL - * The URL for the service. - * @param pAttributes - * A vector of ServiceLocationAttribute objects describing the - * service. - * @throws ServiceLocationException - */ - public abstract void register(ServiceURL pURL, Vector pAttributes) - throws ServiceLocationException; - - /** - * Deregister a service from the SLP framework. This has the effect of - * deregistering the service from every language locale. The API library is - * required to perform the operation in all scopes obtained through - * configuration. - * - * @param pURL - * The URL for the service. - * @throws ServiceLocationException - */ - public abstract void deregister(ServiceURL pURL) throws ServiceLocationException; - - /** - * Update the registration by adding the given attributes. The API library - * is required to perform the operation in all scopes obtained through - * configuration. - * - * @param pURL - * The URL for the service. - * @param pAttributes - * A Vector of ServiceLocationAttribute objects to add to the - * existing registration. Use an empty vector to update the URL - * alone. May not be null. - * @throws ServiceLocationException - */ - public abstract void addAttributes(ServiceURL pURL, Vector pAttributes) - throws ServiceLocationException; - - /** - * Delete the attributes from a URL for the locale with which the Advertiser - * was created. The API library is required to perform the operation in all - * scopes obtained through configuration. - * - * @param pURL - * The URL for the service. - * @param pAttributeIds - * A vector of Strings indicating the ids of the attributes to - * remove. The strings may be attribute ids or they may be - * wildcard patterns to match ids. See [7] for the syntax of - * wildcard patterns. The strings may include SLP reserved - * characters, they will be escaped by the API before - * transmission. May not be the empty vector or null. - * @throws ServiceLocationException - */ - public abstract void deleteAttributes(ServiceURL pURL, Vector pAttributeIds) - throws ServiceLocationException; -} +/* + ServiceType.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1516246 2006-07-22 lupusalex Integrate SLP client code + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Locale; +import java.util.Vector; + +/** + * The Advertiser is the SA interface, allowing clients to register new service + * instances with SLP, to change the attributes of existing services, and to + * deregister service instances. New registrations and modifications of + * attributes are made in the language locale with which the Advertiser was + * created, deregistrations of service instances are made for all locales. + */ +public interface Advertiser { + /** + * Return the language locale with which this object was created. + * + * @return The locale + */ + public abstract Locale getLocale(); + + /** + * Register a new service with SLP having the given attributes. The API + * library is required to perform the operation in all scopes obtained + * through configuration. + * + * @param pURL + * The URL for the service. + * @param pAttributes + * A vector of ServiceLocationAttribute objects describing the + * service. + * @throws ServiceLocationException + */ + public abstract void register(ServiceURL pURL, Vector pAttributes) + throws ServiceLocationException; + + /** + * Deregister a service from the SLP framework. This has the effect of + * deregistering the service from every language locale. The API library is + * required to perform the operation in all scopes obtained through + * configuration. + * + * @param pURL + * The URL for the service. + * @throws ServiceLocationException + */ + public abstract void deregister(ServiceURL pURL) throws ServiceLocationException; + + /** + * Update the registration by adding the given attributes. The API library + * is required to perform the operation in all scopes obtained through + * configuration. + * + * @param pURL + * The URL for the service. + * @param pAttributes + * A Vector of ServiceLocationAttribute objects to add to the + * existing registration. Use an empty vector to update the URL + * alone. May not be null. + * @throws ServiceLocationException + */ + public abstract void addAttributes(ServiceURL pURL, Vector pAttributes) + throws ServiceLocationException; + + /** + * Delete the attributes from a URL for the locale with which the Advertiser + * was created. The API library is required to perform the operation in all + * scopes obtained through configuration. + * + * @param pURL + * The URL for the service. + * @param pAttributeIds + * A vector of Strings indicating the ids of the attributes to + * remove. The strings may be attribute ids or they may be + * wildcard patterns to match ids. See [7] for the syntax of + * wildcard patterns. The strings may include SLP reserved + * characters, they will be escaped by the API before + * transmission. May not be the empty vector or null. + * @throws ServiceLocationException + */ + public abstract void deleteAttributes(ServiceURL pURL, Vector pAttributeIds) throws ServiceLocationException; +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/Locator.java b/src/main/java/org/metricshub/wbem/sblim/slp/Locator.java similarity index 80% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/Locator.java rename to src/main/java/org/metricshub/wbem/sblim/slp/Locator.java index 9b4b861..8d8652d 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/Locator.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/Locator.java @@ -1,278 +1,301 @@ -/* - ServiceType.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1516246 2006-07-22 lupusalex Integrate SLP client code - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.net.InetAddress; -import java.util.Locale; -import java.util.Vector; - -/** - * The Locator is the UA interface, allowing clients to query the SLP framework - * about existing service types, services instances, and about the attributes of - * an existing service instance or service type. Queries for services and - * attributes are made in the locale with which the Locator was created, queries - * for service types are independent of locale. - */ -public interface Locator { - - /** - * Return the language locale with which this object was created. - * - * @return The locale - */ - public abstract Locale getLocale(); - - /** - * Returns an enumeration of ServiceType objects giving known service types - * for the given scopes and given naming authority. If no service types are - * found, an empty enumeration is returned. - * - * @param pNamingAuthority - * The naming authority. Use "" for the default naming authority - * and "*" for all naming authorities. - * @param pScopes - * A Vector of scope names. The vector should be selected from - * the results of a findScopes() API invocation. Use "DEFAULT" - * for the default scope. - * @return The enumeration - * @throws ServiceLocationException - */ - public abstract ServiceLocationEnumeration findServiceTypes(String pNamingAuthority, - Vector pScopes) throws ServiceLocationException; - - /** - * Returns an enumeration of ServiceType objects giving known service types - * for the given scopes and given naming authority. If no service types are - * found, an empty enumeration is returned.
      - *
      - * This method is not part of the RFC 2614 interface definition. - * - * @param pNamingAuthority - * The naming authority. Use "" for the default naming authority - * and "*" for all naming authorities. - * @param pScopes - * A Vector of scope names. The vector should be selected from - * the results of a findScopes() API invocation. Use "DEFAULT" - * for the default scope. - * @param pDirectoryAgent - * A vector of InetAddress that specify the directory agents to - * look for. - * - * @return The enumeration - * @throws ServiceLocationException - */ - public abstract ServiceLocationEnumeration findServiceTypes(String pNamingAuthority, - Vector pScopes, Vector pDirectoryAgent) - throws ServiceLocationException; - - /** - * Returns a vector of ServiceURL objects for services matching the query, - * and having a matching type in the given scopes. If no services are found, - * an empty enumeration is returned. - * - * @param pType - * The SLP service type of the service. - * @param pScopes - * A Vector of scope names. The vector should be selected from - * the results of a findScopes() API invocation. Use "DEFAULT" - * for the default scope. - * @param pSearchFilter - * An LDAPv3 [4] string encoded query. If the filter is empty, - * i.e. "", all services of the requested type in the specified - * scopes are returned. SLP reserved characters must be escaped - * in the query. Use ServiceLocationAttribute.escapeId() and - * ServiceLocationAttribute.escapeValue() to construct the query. - * - * @return The enumeration - * @throws ServiceLocationException - */ - public abstract ServiceLocationEnumeration findServices(ServiceType pType, - Vector pScopes, String pSearchFilter) throws ServiceLocationException; - - /** - * Returns a vector of ServiceURL objects for services matching the query, - * and having a matching type in the given scopes. If no services are found, - * an empty enumeration is returned.
      - *
      - * This method is not part of the RFC 2614 interface definition. - * - * @param pType - * The SLP service type of the service. - * @param pScopes - * A Vector of scope names. The vector should be selected from - * the results of a findScopes() API invocation. Use "DEFAULT" - * for the default scope. - * @param pSearchFilter - * An LDAPv3 [4] string encoded query. If the filter is empty, - * i.e. "", all services of the requested type in the specified - * scopes are returned. SLP reserved characters must be escaped - * in the query. Use ServiceLocationAttribute.escapeId() and - * ServiceLocationAttribute.escapeValue() to construct the query. - * @param pDirectoryAgents - * A vector of InetAddress that specify the directory agents to - * look for. - * - * @return The enumeration - * @throws ServiceLocationException - */ - public abstract ServiceLocationEnumeration findServices(ServiceType pType, - Vector pScopes, String pSearchFilter, Vector pDirectoryAgents) - throws ServiceLocationException; - - /** - * For the URL and scope, return a Vector of ServiceLocationAttribute - * objects whose ids match the String patterns in the attributeIds Vector. - * The request is made in the language locale of the Locator. If no - * attributes match, an empty enumeration is returned. - * - * @param URL - * The URL for which the attributes are desired. - * @param scopes - * A Vector of scope names. The vector should be selected from - * the results of a findScopes() API invocation. Use "DEFAULT" - * for the default scope. - * @param attributeIds - * A Vector of String patterns identifying the desired - * attributes. An empty vector means return all attributes. As - * described in [7], the patterns may include wildcard to match - * substrings. The strings may include SLP reserved characters, - * they will be escaped by the API before transmission. - * @return The enumeration - * @throws ServiceLocationException - */ - public abstract ServiceLocationEnumeration findAttributes(ServiceURL URL, - Vector scopes, Vector attributeIds) throws ServiceLocationException; - - /** - * For the URL and scope, return a Vector of ServiceLocationAttribute - * objects whose ids match the String patterns in the attributeIds Vector. - * The request is made in the language locale of the Locator. If no - * attributes match, an empty enumeration is returned.
      - *
      - * This method is not part of the RFC 2614 interface definition. - * - * @param pURL - * The URL for which the attributes are desired. - * @param pScopes - * A Vector of scope names. The vector should be selected from - * the results of a findScopes() API invocation. Use "DEFAULT" - * for the default scope. - * @param pAttributeIds - * A Vector of String patterns identifying the desired - * attributes. An empty vector means return all attributes. As - * described in [7], the patterns may include wildcard to match - * substrings. The strings may include SLP reserved characters, - * they will be escaped by the API before transmission. - * @param pDirectoryAgents - * A vector of InetAddress that specify the directory agents to - * look for. - * @return The enumeration - * @throws ServiceLocationException - * - */ - public abstract ServiceLocationEnumeration findAttributes(ServiceURL pURL, - Vector pScopes, Vector pAttributeIds, - Vector pDirectoryAgents) throws ServiceLocationException; - - /** - * For the type and scope, return a Vector of all ServiceLocationAttribute - * objects whose ids match the String patterns in the attributeIds Vector - * regardless of the Locator's locale. The request is made independent of - * language locale. If no attributes are found, an empty vector is returned. - * - * @param pType - * The service type. - * @param pScopes - * A Vector of scope names. The vector should be selected from - * the results of a findScopes() API invocation. Use "DEFAULT" - * for the default scope. - * @param pAttributeIds - * A Vector of String patterns identifying the desired - * attributes. An empty vector means return all attributes. As - * described in [7], the patterns may include wildcard to match - * all prefixes or suffixes. The patterns may include SLP - * reserved characters, they will be escaped by the API before - * transmission. - * @return The enumeration - * @throws ServiceLocationException - */ - public abstract ServiceLocationEnumeration findAttributes(ServiceType pType, - Vector pScopes, Vector pAttributeIds) throws ServiceLocationException; - - /** - * For the type and scope, return a Vector of all ServiceLocationAttribute - * objects whose ids match the String patterns in the attributeIds Vector - * regardless of the Locator's locale. The request is made independent of - * language locale. If no attributes are found, an empty vector is returned.
      - *
      - * This method is not part of the RFC 2614 interface definition. - * - * @param pType - * The service type. - * @param pScopes - * A Vector of scope names. The vector should be selected from - * the results of a findScopes() API invocation. Use "DEFAULT" - * for the default scope. - * @param pAttributeIds - * A Vector of String patterns identifying the desired - * attributes. An empty vector means return all attributes. As - * described in [7], the patterns may include wildcard to match - * all prefixes or suffixes. The patterns may include SLP - * reserved characters, they will be escaped by the API before - * transmission. - * @param pDirectoryAgents - * A vector of InetAddress that specify the directory agents to - * look for. - * @return The enumeration - * @throws ServiceLocationException - */ - public abstract ServiceLocationEnumeration findAttributes(ServiceType pType, - Vector pScopes, Vector pAttributeIds, - Vector pDirectoryAgents) throws ServiceLocationException; - -} +/* + ServiceType.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1516246 2006-07-22 lupusalex Integrate SLP client code + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.net.InetAddress; +import java.util.Locale; +import java.util.Vector; + +/** + * The Locator is the UA interface, allowing clients to query the SLP framework + * about existing service types, services instances, and about the attributes of + * an existing service instance or service type. Queries for services and + * attributes are made in the locale with which the Locator was created, queries + * for service types are independent of locale. + */ +public interface Locator { + /** + * Return the language locale with which this object was created. + * + * @return The locale + */ + public abstract Locale getLocale(); + + /** + * Returns an enumeration of ServiceType objects giving known service types + * for the given scopes and given naming authority. If no service types are + * found, an empty enumeration is returned. + * + * @param pNamingAuthority + * The naming authority. Use "" for the default naming authority + * and "*" for all naming authorities. + * @param pScopes + * A Vector of scope names. The vector should be selected from + * the results of a findScopes() API invocation. Use "DEFAULT" + * for the default scope. + * @return The enumeration + * @throws ServiceLocationException + */ + public abstract ServiceLocationEnumeration findServiceTypes(String pNamingAuthority, Vector pScopes) + throws ServiceLocationException; + + /** + * Returns an enumeration of ServiceType objects giving known service types + * for the given scopes and given naming authority. If no service types are + * found, an empty enumeration is returned.
      + *
      + * This method is not part of the RFC 2614 interface definition. + * + * @param pNamingAuthority + * The naming authority. Use "" for the default naming authority + * and "*" for all naming authorities. + * @param pScopes + * A Vector of scope names. The vector should be selected from + * the results of a findScopes() API invocation. Use "DEFAULT" + * for the default scope. + * @param pDirectoryAgent + * A vector of InetAddress that specify the directory agents to + * look for. + * + * @return The enumeration + * @throws ServiceLocationException + */ + public abstract ServiceLocationEnumeration findServiceTypes( + String pNamingAuthority, + Vector pScopes, + Vector pDirectoryAgent + ) + throws ServiceLocationException; + + /** + * Returns a vector of ServiceURL objects for services matching the query, + * and having a matching type in the given scopes. If no services are found, + * an empty enumeration is returned. + * + * @param pType + * The SLP service type of the service. + * @param pScopes + * A Vector of scope names. The vector should be selected from + * the results of a findScopes() API invocation. Use "DEFAULT" + * for the default scope. + * @param pSearchFilter + * An LDAPv3 [4] string encoded query. If the filter is empty, + * i.e. "", all services of the requested type in the specified + * scopes are returned. SLP reserved characters must be escaped + * in the query. Use ServiceLocationAttribute.escapeId() and + * ServiceLocationAttribute.escapeValue() to construct the query. + * + * @return The enumeration + * @throws ServiceLocationException + */ + public abstract ServiceLocationEnumeration findServices( + ServiceType pType, + Vector pScopes, + String pSearchFilter + ) + throws ServiceLocationException; + + /** + * Returns a vector of ServiceURL objects for services matching the query, + * and having a matching type in the given scopes. If no services are found, + * an empty enumeration is returned.
      + *
      + * This method is not part of the RFC 2614 interface definition. + * + * @param pType + * The SLP service type of the service. + * @param pScopes + * A Vector of scope names. The vector should be selected from + * the results of a findScopes() API invocation. Use "DEFAULT" + * for the default scope. + * @param pSearchFilter + * An LDAPv3 [4] string encoded query. If the filter is empty, + * i.e. "", all services of the requested type in the specified + * scopes are returned. SLP reserved characters must be escaped + * in the query. Use ServiceLocationAttribute.escapeId() and + * ServiceLocationAttribute.escapeValue() to construct the query. + * @param pDirectoryAgents + * A vector of InetAddress that specify the directory agents to + * look for. + * + * @return The enumeration + * @throws ServiceLocationException + */ + public abstract ServiceLocationEnumeration findServices( + ServiceType pType, + Vector pScopes, + String pSearchFilter, + Vector pDirectoryAgents + ) + throws ServiceLocationException; + + /** + * For the URL and scope, return a Vector of ServiceLocationAttribute + * objects whose ids match the String patterns in the attributeIds Vector. + * The request is made in the language locale of the Locator. If no + * attributes match, an empty enumeration is returned. + * + * @param URL + * The URL for which the attributes are desired. + * @param scopes + * A Vector of scope names. The vector should be selected from + * the results of a findScopes() API invocation. Use "DEFAULT" + * for the default scope. + * @param attributeIds + * A Vector of String patterns identifying the desired + * attributes. An empty vector means return all attributes. As + * described in [7], the patterns may include wildcard to match + * substrings. The strings may include SLP reserved characters, + * they will be escaped by the API before transmission. + * @return The enumeration + * @throws ServiceLocationException + */ + public abstract ServiceLocationEnumeration findAttributes( + ServiceURL URL, + Vector scopes, + Vector attributeIds + ) + throws ServiceLocationException; + + /** + * For the URL and scope, return a Vector of ServiceLocationAttribute + * objects whose ids match the String patterns in the attributeIds Vector. + * The request is made in the language locale of the Locator. If no + * attributes match, an empty enumeration is returned.
      + *
      + * This method is not part of the RFC 2614 interface definition. + * + * @param pURL + * The URL for which the attributes are desired. + * @param pScopes + * A Vector of scope names. The vector should be selected from + * the results of a findScopes() API invocation. Use "DEFAULT" + * for the default scope. + * @param pAttributeIds + * A Vector of String patterns identifying the desired + * attributes. An empty vector means return all attributes. As + * described in [7], the patterns may include wildcard to match + * substrings. The strings may include SLP reserved characters, + * they will be escaped by the API before transmission. + * @param pDirectoryAgents + * A vector of InetAddress that specify the directory agents to + * look for. + * @return The enumeration + * @throws ServiceLocationException + * + */ + public abstract ServiceLocationEnumeration findAttributes( + ServiceURL pURL, + Vector pScopes, + Vector pAttributeIds, + Vector pDirectoryAgents + ) + throws ServiceLocationException; + + /** + * For the type and scope, return a Vector of all ServiceLocationAttribute + * objects whose ids match the String patterns in the attributeIds Vector + * regardless of the Locator's locale. The request is made independent of + * language locale. If no attributes are found, an empty vector is returned. + * + * @param pType + * The service type. + * @param pScopes + * A Vector of scope names. The vector should be selected from + * the results of a findScopes() API invocation. Use "DEFAULT" + * for the default scope. + * @param pAttributeIds + * A Vector of String patterns identifying the desired + * attributes. An empty vector means return all attributes. As + * described in [7], the patterns may include wildcard to match + * all prefixes or suffixes. The patterns may include SLP + * reserved characters, they will be escaped by the API before + * transmission. + * @return The enumeration + * @throws ServiceLocationException + */ + public abstract ServiceLocationEnumeration findAttributes( + ServiceType pType, + Vector pScopes, + Vector pAttributeIds + ) + throws ServiceLocationException; + + /** + * For the type and scope, return a Vector of all ServiceLocationAttribute + * objects whose ids match the String patterns in the attributeIds Vector + * regardless of the Locator's locale. The request is made independent of + * language locale. If no attributes are found, an empty vector is returned.
      + *
      + * This method is not part of the RFC 2614 interface definition. + * + * @param pType + * The service type. + * @param pScopes + * A Vector of scope names. The vector should be selected from + * the results of a findScopes() API invocation. Use "DEFAULT" + * for the default scope. + * @param pAttributeIds + * A Vector of String patterns identifying the desired + * attributes. An empty vector means return all attributes. As + * described in [7], the patterns may include wildcard to match + * all prefixes or suffixes. The patterns may include SLP + * reserved characters, they will be escaped by the API before + * transmission. + * @param pDirectoryAgents + * A vector of InetAddress that specify the directory agents to + * look for. + * @return The enumeration + * @throws ServiceLocationException + */ + public abstract ServiceLocationEnumeration findAttributes( + ServiceType pType, + Vector pScopes, + Vector pAttributeIds, + Vector pDirectoryAgents + ) + throws ServiceLocationException; +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/SLPConfigProperties.java b/src/main/java/org/metricshub/wbem/sblim/slp/SLPConfigProperties.java similarity index 92% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/SLPConfigProperties.java rename to src/main/java/org/metricshub/wbem/sblim/slp/SLPConfigProperties.java index 5e60dab..7f2f57f 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/SLPConfigProperties.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/SLPConfigProperties.java @@ -1,461 +1,457 @@ -/* - SLPConfigProperties.java - - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535793 2006-09-19 lupusalex Fix&Integrate CIM&SLP configuration classes - * 1911400 2008-03-10 blaschks-oss Source RPM file on SourceForge is broken - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - * 2907527 2009-12-02 blaschke-oss Fix SLP properties issues - */ - -package org.sentrysoftware.wbem.sblim.slp; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * The interface SLPConfigProperties holds string constants for the - * configuration properties of the SLP package. To set a property call - * System.setProperty(name, value). Note that these properties have - * global VM scope. - * - */ -public interface SLPConfigProperties { - - /** - * A URL string giving the location of the SLP config file.
      - *
      - * By default the SLP client looks for - *
        - *
      • file:sblim-slp-client2.properties
      • - *
      • file:%USER_HOME%/sblim-slp-client2.properties
      • - *
      • file:/etc/java/sblim-slp-client2.properties
      • - *
      • file:/etc/sblim-slp-client2.properties
      • - *
      - * The first file found will be used. The default search list is not applied - * if this property is set, even if the given URL does not exist.
      - *
      - * SBLIM specific extension to RFC 2614 - */ - public static final String NET_SLP_CONFIG_URL = "net.slp.configURL"; - - /** - * A 16 bit positive integer giving the number of seconds the DA url - * lifetime should exceed the discovery interval.
      - *
      - * Default is 900 seconds (15 minutes).
      - *
      - * SBLIM specific extension to RFC 2614 - */ - public static final String NET_SLP_DA_ACTIVE_DISCOVERY_GRANULARITY = "net.slp.DAActiveDiscoveryGranularity"; - - /** - * A 16 bit positive integer giving the number of seconds between DA active - * discovery queries.
      - *
      - * Default is 900 seconds (15 minutes).
      - *
      - * If the property is set to zero, active discovery is turned off. This is - * useful when the DAs available are explicitly restricted to those obtained - * from DHCP or the net.slp.DAAddresses property. - */ - public static final String NET_SLP_DA_ACTIVE_DISCOVERY_INTERVAL = "net.slp.DAActiveDiscoveryInterval"; - - /** - * A value-list of IP addresses or DNS resolvable host names giving the - * SLPv2 DAs to use for statically configured UAs and SAs. Ignored by DAs - * (unless the DA is also an SA server).
      - *
      - * Default is none.
      - *
      - * The following grammar describes the property: - *

      - * - * addr-list = addr / addr "," addr-list
      - * addr = fqdn / hostnumber
      - * fqdn = ALPHA / ALPHA *[ anum / "-" ] anum
      - * anum = ALPHA / DIGIT
      - * hostnumber = 1*3DIGIT 3("." 1*3DIGIT)
      - *
      - *

      - * An example is:
      - *

      - * - * sawah,mandi,sambal - * - *

      - * IP addresses can be used instead of host names in networks where DNS is - * not deployed, but network administrators are reminded that using IP - * addresses will complicate machine renumbering, since the SLP - * configuration property files in statically configured networks will have - * to be changed. Similarly, if host names are used, implementors must be - * careful that a name service is available before SLP starts, in other - * words, SLP cannot be used to find the name service.
      - */ - public static final String NET_SLP_DA_ADDRESSES = "net.slp.DAAddresses"; - - /** - * A comma-separated list of parenthesized attribute/value list pairs that - * the DA must advertise in DAAdverts. The property must be in the SLP - * attribute list wire format, including escapes for reserved characters.
      - *
      - * Not evaluated by SBLIM SLP client - */ - public static final String NET_SLP_DA_ATTRIBUTES = "net.slp.DAAttributes"; - - /** - * A value-list of 32 bit integers used as timeouts, in milliseconds, to - * implement the multicast convergence algorithm during active DA discovery. - * Each value specifies the time to wait before sending the next request, or - * until nothing new has been learned from two successive requests.
      - *
      - * Default is: 200,200,200,200,300,400. - */ - public static final String NET_SLP_DA_DISCOVERY_TIMEOUTS = "net.slp.DADiscoveryTimeouts"; - - /** - * A 32 bit integer giving the number of seconds for the DA heartbeat. - * Ignored if isDA is false.
      - *
      - * Default is 10800 seconds (3 hours).
      - *
      - * Not evaluated by SBLIM SLP client - */ - public static final String NET_SLP_DA_HEARTBEAT = "net.slp.DAHeartbeat"; - - /** - * A value-list of 32 bit integers used as timeouts, in milliseconds, to - * implement unicast datagram transmission to DAs. The nth value gives the - * time to block waiting for a reply on the nth try to contact the DA.
      - *
      - * Default is: 100,200,300 - */ - public static final String NET_SLP_DATAGRAM_TIMEOUTS = "net.slp.datagramTimeouts"; - - /** - * Value-list of strings giving the IP addresses of network interfaces on - * which the DA or SA should listen on port 427 for multicast, unicast UDP, - * and TCP messages.
      - *
      - * Default is empty, i.e. use the default network interface.
      - *
      - * The grammar for this property is: - *

      - * - * addr-list = hostnumber / hostnumber "," addr-list
      - * hostnumber = 1*3DIGIT 3("." 1*3DIGIT) - *
      - *

      - * An example is: - *

      - * 195.42.42.42,195.42.142.1,195.42.120.1 - *

      - * The example machine has three interfaces on which the DA should listen. - * Note that since this property only takes IP addresses, it will need to be - * changed if the network is renumbered. - */ - public static final String NET_SLP_INTERFACES = "net.slp.interfaces"; - - /** - * A boolean indicating if broadcast should be used instead of multicast.
      - *
      - * Default is false. - */ - public static final String NET_SLP_IS_BROADCAST_ONLY = "net.slp.isBroadcastOnly"; - - /** - * A boolean indicating if the SLP server is to act as a DA. If - * false, run as a SA.
      - *
      - * Default is false. - */ - public static final String NET_SLP_IS_DA = "net.slp.isDA"; - - /** - * A RFC 1766 Language Tag for the language locale. Setting this property - * causes the property value to become the default locale for SLP messages. - * This property is also used for SA and DA configuration.
      - *
      - * Default is en.
      - *
      - * Not evaluated by SBLIM SLP client - */ - public static final String NET_SLP_LOCALE = "net.slp.locale"; - - /** - * A 32 bit integer giving the maximum number of results to accumulate and - * return for a synchronous request before the timeout, or the maximum - * number of results to return through a callback if the request results are - * reported asynchronously.
      - * Positive integers and -1 are legal values. If -1, indicates that all - * results should be returned.
      - *
      - * Default value is 2147483647 (2^31 - 1)
      - * SBLIM specific: RFC 2614 recommendation is -1.
      - *
      - * DAs and SAs always return all results that match the request. This - * configuration value applies only to UAs, that filter incoming results and - * only return as many values as net.slp.maxResults indicates. - */ - public static final String NET_SLP_MAX_RESULTS = "net.slp.maxResults"; - - /** - * A 16 bit integer giving the network packet MTU, in bytes. This is the - * maximum size of any datagram to send, but the implementation might - * receive a larger datagram. The maximum size includes IP, and UDP or TCP - * headers.
      - *
      - * Default is 1400. - */ - public static final String NET_SLP_MTU = "net.slp.MTU"; - - /** - * A 32 bit integer giving the maximum amount of time to perform multicast, - * in milliseconds.
      - *
      - * Default is 2000 ms. - */ - public static final String NET_SLP_MULTICAST_MAXIMUM_WAIT = "net.slp.multicastMaximumWait"; - - /** - * A value-list of 32 bit integers used as timeouts, in milliseconds, to - * implement the multicast convergence algorithm. Each value specifies the - * time to wait before sending the next request, or until nothing new has - * been learned from two successive requests.
      - *
      - * Default is: 200, 200, 200, 200, 300, 400
      - * SBLIM specific: RFC 2614 recommendation is - * 3000,3000,3000,3000,3000.
      - *
      - * In a fast network the aggressive values of 1000,1250,1500,2000,4000 allow - * better performance.
      - *
      - * Note that the net.slp.DADiscoveryTimeouts property must be used for - * active DA discovery. - */ - public static final String NET_SLP_MULTICAST_TIMEOUTS = "net.slp.multicastTimeouts"; - - /** - * A positive integer less than or equal to 255, giving the multicast TTL.
      - *
      - * Default is 255. - */ - public static final String NET_SLP_MULTICAST_TTL = "net.slp.multicastTTL"; - - /** - * A boolean indicating whether passive DA detection should be used.
      - *
      - * Default is true.
      - *
      - * Not evaluated by SBLIM SLP client - */ - public static final String NET_SLP_PASSIVE_DA_DETECTION = "net.slp.passiveDADetection"; - - /** - * A 16 bit integer giving the port used for listening.
      - *
      - * Default is 427. - */ - public static final String NET_SLP_PORT = "net.slp.port"; - - /** - * A boolean indicating whether IPv6 addresses should be used.
      - *
      - * Default is true. - */ - public static final String NET_SLP_USEIPV6 = "net.slp.useipv6"; - - /** - * A boolean indicating whether IPv4 addresses should be used.
      - *
      - * Default is true. - */ - public static final String NET_SLP_USEIPV4 = "net.slp.useipv4"; - - /** - * A 32 bit integer giving the maximum value for all random wait parameters, - * in milliseconds.
      - *
      - * Default is 1000 ms.
      - *
      - * Not evaluated by SBLIM SLP client - */ - public static final String NET_SLP_RANDOM_WAIT_BOUND = "net.slp.randomWaitBound"; - - /** - * A comma-separated list of parenthesized attribute/value list pairs that - * the SA must advertise in SAAdverts. The property must be in the SLP - * attribute list wire format, including escapes for reserved characters.
      - *
      - * Not evaluated by SBLIM SLP client - */ - public static final String NET_SLP_SA_ATTRIBUTES = "net.slp.SAAttributes"; - - /** - * A value-list of strings indicating the scopes that are only applied to - * SAs. In contradiction the "net.slp.useScopes" specifies the scope for UAs - * and SAs.
      - *
      - * SBLIM specific extension to RFC 2614 - */ - public static final String NET_SLP_SAONLY_SCOPES = "net.slp.SAOnlyScopes"; - - /** - * A comma-separated list of parenthesized attribute/value list pairs that - * the SA must advertise in SAAdverts. The property must be in the SLP - * attribute list wire format, including escapes for reserved characters.
      - *
      - * Not evaluated by SBLIM SLP client - */ - public static final String NET_SLP_SECURITY_ENABLED = "net.slp.securityEnabled"; - - /** - * A string containing a URL pointing to a document containing serialized - * registrations that should be processed when the DA or SA server starts - * up.
      - *
      - * Default is none.
      - *
      - * Not evaluated by SBLIM SLP client - */ - public static final String NET_SLP_SERIALIZED_REG_URL = "net.slp.serializedRegUrl"; - - /** - * A 32 bit integer giving the server socket queue length for SAs/DAs.
      - *
      - * Default is 10.
      - *
      - * SBLIM specific extension to RFC 2614 - * - */ - public static final String NET_SLP_SERVER_SOCKET_QUEUE_LENGTH = "net.slp.serverSocketQueueLength"; - - /** - * A 32 bit integer giving the TCP timeout in milliseconds.
      - *
      - * The default is 20000 ms.
      - *
      - * SBLIM specific extension to RFC 2614 - * - */ - public static final String NET_SLP_TCPTIMEOUT = "net.slp.TCPTimeout"; - - /** - * A boolean controlling printing of messages about traffic with DAs.
      - *
      - * Default is false.
      - *
      - * Not evaluated by SBLIM SLP client - */ - public static final String NET_SLP_TRACE_DA_TRAFFIC = "net.slp.traceDATraffic"; - - /** - * A boolean controlling printing details when a SLP message is dropped for - * any reason.
      - *
      - * Default is false.
      - *
      - * Not evaluated by SBLIM SLP client - */ - public static final String NET_SLP_TRACE_DROP = "net.slp.traceDrop"; - - /** - * A boolean controlling printing of details on SLP messages. The fields in - * all incoming messages and outgoing replies are printed.
      - *
      - * Default is false. - */ - public static final String NET_SLP_TRACE_MSG = "net.slp.traceMsg"; - - /** - * A boolean controlling dumps of all registered services upon registration - * and deregistration. If true, the contents of the DA or SA server are - * dumped after a registration or deregistration occurs.
      - *
      - * Default is false.
      - *
      - * Not evaluated by SBLIM SLP client - */ - public static final String NET_SLP_TRACE_REG = "net.slp.traceReg"; - - /** - * A value-list of service type names. In the absence of any DAs, UAs - * perform SA discovery for finding scopes. These SA discovery requests may - * contain a request for service types as an attribute.
      - *
      - * The API implementation will use the service type names supplied by this - * property to discover only those SAs (and their scopes) which support the - * desired service type or types. For example, if net.slp.typeHint is set to - * "service:imap,service:pop3" then SA discovery requests will include the - * search filter:
      - *
      - * (|(service-type=service:imap)(service-type=service:pop3))
      - *
      - * - * The API library can also use unicast to contact the discovered SAs for - * subsequent requests for these service types, to optimize network access.
      - *
      - * Not evaluated by SBLIM SLP client - */ - public static final String NET_SLP_TYPE_HINT = "net.slp.typeHint"; - - /** - * A value-list of strings indicating the only scopes a UA or SA is allowed - * to use when making requests or registering, or the scopes a DA must - * support.
      - * If not present for the DA and SA, then in the absence of scope - * information from DHCP, the default scope "DEFAULT" is used. If not - * present for the UA, and there is no scope information available from - * DHCP, then the user scoping model is in force.
      - * Active and passive DA discovery or SA discovery are used for scope - * discovery, and the scope "DEFAULT" is used if no other information is - * available.
      - * If a DA or SA gets another scope in a request, a SCOPE_NOT_SUPPORTED - * error should be returned, unless the request was multicast, in which case - * it should be dropped. If a DA gets another scope in a registration, a - * SCOPE_NOT_SUPPORTED error must be returned. - */ - public static final String NET_SLP_USE_SCOPES = "net.slp.useScopes"; - - /** - * Trace level. Can be ALL, INFO, WARNING, ERROR, OFF
      - *
      - * Not evaluated by SBLIM SLP client - */ - public static final String NET_SLP_TRC_LEVEL = "net.slp.trc.level"; - -} +/* + SLPConfigProperties.java + + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535793 2006-09-19 lupusalex Fix&Integrate CIM&SLP configuration classes + * 1911400 2008-03-10 blaschks-oss Source RPM file on SourceForge is broken + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + * 2907527 2009-12-02 blaschke-oss Fix SLP properties issues + */ + +package org.metricshub.wbem.sblim.slp; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * The interface SLPConfigProperties holds string constants for the + * configuration properties of the SLP package. To set a property call + * System.setProperty(name, value). Note that these properties have + * global VM scope. + * + */ +public interface SLPConfigProperties { + /** + * A URL string giving the location of the SLP config file.
      + *
      + * By default the SLP client looks for + *
        + *
      • file:sblim-slp-client2.properties
      • + *
      • file:%USER_HOME%/sblim-slp-client2.properties
      • + *
      • file:/etc/java/sblim-slp-client2.properties
      • + *
      • file:/etc/sblim-slp-client2.properties
      • + *
      + * The first file found will be used. The default search list is not applied + * if this property is set, even if the given URL does not exist.
      + *
      + * SBLIM specific extension to RFC 2614 + */ + public static final String NET_SLP_CONFIG_URL = "net.slp.configURL"; + + /** + * A 16 bit positive integer giving the number of seconds the DA url + * lifetime should exceed the discovery interval.
      + *
      + * Default is 900 seconds (15 minutes).
      + *
      + * SBLIM specific extension to RFC 2614 + */ + public static final String NET_SLP_DA_ACTIVE_DISCOVERY_GRANULARITY = "net.slp.DAActiveDiscoveryGranularity"; + + /** + * A 16 bit positive integer giving the number of seconds between DA active + * discovery queries.
      + *
      + * Default is 900 seconds (15 minutes).
      + *
      + * If the property is set to zero, active discovery is turned off. This is + * useful when the DAs available are explicitly restricted to those obtained + * from DHCP or the net.slp.DAAddresses property. + */ + public static final String NET_SLP_DA_ACTIVE_DISCOVERY_INTERVAL = "net.slp.DAActiveDiscoveryInterval"; + + /** + * A value-list of IP addresses or DNS resolvable host names giving the + * SLPv2 DAs to use for statically configured UAs and SAs. Ignored by DAs + * (unless the DA is also an SA server).
      + *
      + * Default is none.
      + *
      + * The following grammar describes the property: + *

      + * + * addr-list = addr / addr "," addr-list
      + * addr = fqdn / hostnumber
      + * fqdn = ALPHA / ALPHA *[ anum / "-" ] anum
      + * anum = ALPHA / DIGIT
      + * hostnumber = 1*3DIGIT 3("." 1*3DIGIT)
      + *
      + *

      + * An example is:
      + *

      + * + * sawah,mandi,sambal + * + *

      + * IP addresses can be used instead of host names in networks where DNS is + * not deployed, but network administrators are reminded that using IP + * addresses will complicate machine renumbering, since the SLP + * configuration property files in statically configured networks will have + * to be changed. Similarly, if host names are used, implementors must be + * careful that a name service is available before SLP starts, in other + * words, SLP cannot be used to find the name service.
      + */ + public static final String NET_SLP_DA_ADDRESSES = "net.slp.DAAddresses"; + + /** + * A comma-separated list of parenthesized attribute/value list pairs that + * the DA must advertise in DAAdverts. The property must be in the SLP + * attribute list wire format, including escapes for reserved characters.
      + *
      + * Not evaluated by SBLIM SLP client + */ + public static final String NET_SLP_DA_ATTRIBUTES = "net.slp.DAAttributes"; + + /** + * A value-list of 32 bit integers used as timeouts, in milliseconds, to + * implement the multicast convergence algorithm during active DA discovery. + * Each value specifies the time to wait before sending the next request, or + * until nothing new has been learned from two successive requests.
      + *
      + * Default is: 200,200,200,200,300,400. + */ + public static final String NET_SLP_DA_DISCOVERY_TIMEOUTS = "net.slp.DADiscoveryTimeouts"; + + /** + * A 32 bit integer giving the number of seconds for the DA heartbeat. + * Ignored if isDA is false.
      + *
      + * Default is 10800 seconds (3 hours).
      + *
      + * Not evaluated by SBLIM SLP client + */ + public static final String NET_SLP_DA_HEARTBEAT = "net.slp.DAHeartbeat"; + + /** + * A value-list of 32 bit integers used as timeouts, in milliseconds, to + * implement unicast datagram transmission to DAs. The nth value gives the + * time to block waiting for a reply on the nth try to contact the DA.
      + *
      + * Default is: 100,200,300 + */ + public static final String NET_SLP_DATAGRAM_TIMEOUTS = "net.slp.datagramTimeouts"; + + /** + * Value-list of strings giving the IP addresses of network interfaces on + * which the DA or SA should listen on port 427 for multicast, unicast UDP, + * and TCP messages.
      + *
      + * Default is empty, i.e. use the default network interface.
      + *
      + * The grammar for this property is: + *

      + * + * addr-list = hostnumber / hostnumber "," addr-list
      + * hostnumber = 1*3DIGIT 3("." 1*3DIGIT) + *
      + *

      + * An example is: + *

      + * 195.42.42.42,195.42.142.1,195.42.120.1 + *

      + * The example machine has three interfaces on which the DA should listen. + * Note that since this property only takes IP addresses, it will need to be + * changed if the network is renumbered. + */ + public static final String NET_SLP_INTERFACES = "net.slp.interfaces"; + + /** + * A boolean indicating if broadcast should be used instead of multicast.
      + *
      + * Default is false. + */ + public static final String NET_SLP_IS_BROADCAST_ONLY = "net.slp.isBroadcastOnly"; + + /** + * A boolean indicating if the SLP server is to act as a DA. If + * false, run as a SA.
      + *
      + * Default is false. + */ + public static final String NET_SLP_IS_DA = "net.slp.isDA"; + + /** + * A RFC 1766 Language Tag for the language locale. Setting this property + * causes the property value to become the default locale for SLP messages. + * This property is also used for SA and DA configuration.
      + *
      + * Default is en.
      + *
      + * Not evaluated by SBLIM SLP client + */ + public static final String NET_SLP_LOCALE = "net.slp.locale"; + + /** + * A 32 bit integer giving the maximum number of results to accumulate and + * return for a synchronous request before the timeout, or the maximum + * number of results to return through a callback if the request results are + * reported asynchronously.
      + * Positive integers and -1 are legal values. If -1, indicates that all + * results should be returned.
      + *
      + * Default value is 2147483647 (2^31 - 1)
      + * SBLIM specific: RFC 2614 recommendation is -1.
      + *
      + * DAs and SAs always return all results that match the request. This + * configuration value applies only to UAs, that filter incoming results and + * only return as many values as net.slp.maxResults indicates. + */ + public static final String NET_SLP_MAX_RESULTS = "net.slp.maxResults"; + + /** + * A 16 bit integer giving the network packet MTU, in bytes. This is the + * maximum size of any datagram to send, but the implementation might + * receive a larger datagram. The maximum size includes IP, and UDP or TCP + * headers.
      + *
      + * Default is 1400. + */ + public static final String NET_SLP_MTU = "net.slp.MTU"; + + /** + * A 32 bit integer giving the maximum amount of time to perform multicast, + * in milliseconds.
      + *
      + * Default is 2000 ms. + */ + public static final String NET_SLP_MULTICAST_MAXIMUM_WAIT = "net.slp.multicastMaximumWait"; + + /** + * A value-list of 32 bit integers used as timeouts, in milliseconds, to + * implement the multicast convergence algorithm. Each value specifies the + * time to wait before sending the next request, or until nothing new has + * been learned from two successive requests.
      + *
      + * Default is: 200, 200, 200, 200, 300, 400
      + * SBLIM specific: RFC 2614 recommendation is + * 3000,3000,3000,3000,3000.
      + *
      + * In a fast network the aggressive values of 1000,1250,1500,2000,4000 allow + * better performance.
      + *
      + * Note that the net.slp.DADiscoveryTimeouts property must be used for + * active DA discovery. + */ + public static final String NET_SLP_MULTICAST_TIMEOUTS = "net.slp.multicastTimeouts"; + + /** + * A positive integer less than or equal to 255, giving the multicast TTL.
      + *
      + * Default is 255. + */ + public static final String NET_SLP_MULTICAST_TTL = "net.slp.multicastTTL"; + + /** + * A boolean indicating whether passive DA detection should be used.
      + *
      + * Default is true.
      + *
      + * Not evaluated by SBLIM SLP client + */ + public static final String NET_SLP_PASSIVE_DA_DETECTION = "net.slp.passiveDADetection"; + + /** + * A 16 bit integer giving the port used for listening.
      + *
      + * Default is 427. + */ + public static final String NET_SLP_PORT = "net.slp.port"; + + /** + * A boolean indicating whether IPv6 addresses should be used.
      + *
      + * Default is true. + */ + public static final String NET_SLP_USEIPV6 = "net.slp.useipv6"; + + /** + * A boolean indicating whether IPv4 addresses should be used.
      + *
      + * Default is true. + */ + public static final String NET_SLP_USEIPV4 = "net.slp.useipv4"; + + /** + * A 32 bit integer giving the maximum value for all random wait parameters, + * in milliseconds.
      + *
      + * Default is 1000 ms.
      + *
      + * Not evaluated by SBLIM SLP client + */ + public static final String NET_SLP_RANDOM_WAIT_BOUND = "net.slp.randomWaitBound"; + + /** + * A comma-separated list of parenthesized attribute/value list pairs that + * the SA must advertise in SAAdverts. The property must be in the SLP + * attribute list wire format, including escapes for reserved characters.
      + *
      + * Not evaluated by SBLIM SLP client + */ + public static final String NET_SLP_SA_ATTRIBUTES = "net.slp.SAAttributes"; + + /** + * A value-list of strings indicating the scopes that are only applied to + * SAs. In contradiction the "net.slp.useScopes" specifies the scope for UAs + * and SAs.
      + *
      + * SBLIM specific extension to RFC 2614 + */ + public static final String NET_SLP_SAONLY_SCOPES = "net.slp.SAOnlyScopes"; + + /** + * A comma-separated list of parenthesized attribute/value list pairs that + * the SA must advertise in SAAdverts. The property must be in the SLP + * attribute list wire format, including escapes for reserved characters.
      + *
      + * Not evaluated by SBLIM SLP client + */ + public static final String NET_SLP_SECURITY_ENABLED = "net.slp.securityEnabled"; + + /** + * A string containing a URL pointing to a document containing serialized + * registrations that should be processed when the DA or SA server starts + * up.
      + *
      + * Default is none.
      + *
      + * Not evaluated by SBLIM SLP client + */ + public static final String NET_SLP_SERIALIZED_REG_URL = "net.slp.serializedRegUrl"; + + /** + * A 32 bit integer giving the server socket queue length for SAs/DAs.
      + *
      + * Default is 10.
      + *
      + * SBLIM specific extension to RFC 2614 + * + */ + public static final String NET_SLP_SERVER_SOCKET_QUEUE_LENGTH = "net.slp.serverSocketQueueLength"; + + /** + * A 32 bit integer giving the TCP timeout in milliseconds.
      + *
      + * The default is 20000 ms.
      + *
      + * SBLIM specific extension to RFC 2614 + * + */ + public static final String NET_SLP_TCPTIMEOUT = "net.slp.TCPTimeout"; + + /** + * A boolean controlling printing of messages about traffic with DAs.
      + *
      + * Default is false.
      + *
      + * Not evaluated by SBLIM SLP client + */ + public static final String NET_SLP_TRACE_DA_TRAFFIC = "net.slp.traceDATraffic"; + + /** + * A boolean controlling printing details when a SLP message is dropped for + * any reason.
      + *
      + * Default is false.
      + *
      + * Not evaluated by SBLIM SLP client + */ + public static final String NET_SLP_TRACE_DROP = "net.slp.traceDrop"; + + /** + * A boolean controlling printing of details on SLP messages. The fields in + * all incoming messages and outgoing replies are printed.
      + *
      + * Default is false. + */ + public static final String NET_SLP_TRACE_MSG = "net.slp.traceMsg"; + + /** + * A boolean controlling dumps of all registered services upon registration + * and deregistration. If true, the contents of the DA or SA server are + * dumped after a registration or deregistration occurs.
      + *
      + * Default is false.
      + *
      + * Not evaluated by SBLIM SLP client + */ + public static final String NET_SLP_TRACE_REG = "net.slp.traceReg"; + + /** + * A value-list of service type names. In the absence of any DAs, UAs + * perform SA discovery for finding scopes. These SA discovery requests may + * contain a request for service types as an attribute.
      + *
      + * The API implementation will use the service type names supplied by this + * property to discover only those SAs (and their scopes) which support the + * desired service type or types. For example, if net.slp.typeHint is set to + * "service:imap,service:pop3" then SA discovery requests will include the + * search filter:
      + *
      + * (|(service-type=service:imap)(service-type=service:pop3))
      + *
      + * + * The API library can also use unicast to contact the discovered SAs for + * subsequent requests for these service types, to optimize network access.
      + *
      + * Not evaluated by SBLIM SLP client + */ + public static final String NET_SLP_TYPE_HINT = "net.slp.typeHint"; + + /** + * A value-list of strings indicating the only scopes a UA or SA is allowed + * to use when making requests or registering, or the scopes a DA must + * support.
      + * If not present for the DA and SA, then in the absence of scope + * information from DHCP, the default scope "DEFAULT" is used. If not + * present for the UA, and there is no scope information available from + * DHCP, then the user scoping model is in force.
      + * Active and passive DA discovery or SA discovery are used for scope + * discovery, and the scope "DEFAULT" is used if no other information is + * available.
      + * If a DA or SA gets another scope in a request, a SCOPE_NOT_SUPPORTED + * error should be returned, unless the request was multicast, in which case + * it should be dropped. If a DA gets another scope in a registration, a + * SCOPE_NOT_SUPPORTED error must be returned. + */ + public static final String NET_SLP_USE_SCOPES = "net.slp.useScopes"; + + /** + * Trace level. Can be ALL, INFO, WARNING, ERROR, OFF
      + *
      + * Not evaluated by SBLIM SLP client + */ + public static final String NET_SLP_TRC_LEVEL = "net.slp.trc.level"; +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceLocationAttribute.java b/src/main/java/org/metricshub/wbem/sblim/slp/ServiceLocationAttribute.java similarity index 82% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceLocationAttribute.java rename to src/main/java/org/metricshub/wbem/sblim/slp/ServiceLocationAttribute.java index 9bfe79a..1b531d2 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceLocationAttribute.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/ServiceLocationAttribute.java @@ -1,406 +1,401 @@ -/* - ServiceLocationAttribute.java - - (C) Copyright IBM Corp. 2005, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1516246 2006-07-22 lupusalex Integrate SLP client code - * 1678915 2007-03-27 lupusalex Integrated WBEM service discovery via SLP - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2795671 2009-05-22 raman_arora Add Type to Comparable - * 2797696 2009-05-27 raman_arora Input files use unsafe operations - * 2823494 2009-08-03 rgummada Change Boolean constructor to static - * 3022519 2010-06-30 blaschke-oss ServiceLocationAttribute.equals() compares same array - * 3022524 2010-06-30 blaschke-oss iSortedValueEntries not serializable in Serializable class - * 3023349 2010-07-02 blaschke-oss SLP uses # constructor instead of valueOf - * 2650 2013-07-18 blaschke-oss SLP opaque value handling incorrect - */ - -package org.sentrysoftware.wbem.sblim.slp; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.sblim.cimclient.GenericExts; -import org.sentrysoftware.wbem.sblim.slp.internal.AttributeHandler; -import org.sentrysoftware.wbem.sblim.slp.internal.Convert; -import org.sentrysoftware.wbem.sblim.slp.internal.SLPString; - -import java.io.ByteArrayOutputStream; -import java.io.Serializable; -import java.util.Arrays; -import java.util.StringTokenizer; -import java.util.Vector; - - -/** - * Service location attribute - */ -public class ServiceLocationAttribute implements Serializable { - - private static final long serialVersionUID = -6753246108754657715L; - - private Vector iValues; - - private String iId; - - /** - * Construct a service location attribute. Errors in the id or values vector - * result in an IllegalArgumentException. - * - * @param pId - * The attribute name. The String can consist of any Unicode - * character. - * @param pValues - * A Vector of one or more attribute values. Vector contents must - * be uniform in type and one of Integer, String, Boolean, or - * byte[]. If the attribute is a keyword attribute, then the - * parameter should be null. String values can consist of any - * Unicode character. - */ - public ServiceLocationAttribute(String pId, Vector pValues) { - this.iId = pId; - if (pValues != null && pValues.size() > 0) { - this.iValues = GenericExts.cloneVector(pValues); - } - } - - /** - * Construct a service location attribute from a String. - * - * @param pString - * The string to parse - * @throws ServiceLocationException - * When the string parsing failed - */ - public ServiceLocationAttribute(String pString) throws ServiceLocationException { - if (pString == null || pString.length() == 0) throw new ServiceLocationException( - ServiceLocationException.PARSE_ERROR, - "Empty or null String is not good for this constructor!"); - - if (pString.startsWith("(") && pString.endsWith(")")) { - int equalPos = pString.indexOf('='); - if (equalPos < 0) throw new ServiceLocationException( - ServiceLocationException.PARSE_ERROR, "Missing '=' from attribute string: " - + pString); - this.iId = Convert.unescape(pString.substring(1, equalPos)); - if (this.iId.length() == 0) throw new ServiceLocationException( - ServiceLocationException.PARSE_ERROR, - "Empty attribute ID in attribute string: " + pString); - String valueString = pString.substring(equalPos + 1, pString.length() - 1); - - parseValueString(valueString); - - } else { - if (pString.indexOf('(') >= 0 || pString.indexOf(')') >= 0) throw new ServiceLocationException( - ServiceLocationException.PARSE_ERROR); - this.iId = Convert.unescape(pString); - this.iValues = null; - } - } - - /** - * Returns an escaped version of the id parameter, suitable for inclusion in - * a query. Any reserved characters as specified in [7] are escaped using - * UTF-8 encoding. If any characters in the tag are illegal, throws - * IllegalArgumentException. - * - * @param pId - * The attribute id to escape. ServiceLocationException is thrown - * if any characters are illegal for an attribute tag. - * @return The escaped version - */ - public static String escapeId(String pId) { - return Convert.escape(pId, Convert.ATTR_RESERVED); - } - - /** - * Returns a String containing the escaped value parameter as a string, - * suitable for inclusion in a query. If the parameter is a string, any - * reserved characters as specified in [7] are escaped using UTF-8 encoding. - * If the parameter is a byte array, then the escaped string begins with the - * nonUTF-8 sequence `\ff` and the rest of the string consists of the - * escaped bytes, which is the encoding for opaque. If the value parameter - * is a Boolean or Integer, then the returned string contains the object - * converted into a string. If the value is any type other than String, - * Integer, Boolean or byte[], an IllegalArgumentException is thrown. - * - * @param pValue - * The attribute value to be converted into a string and escaped. - * @return The escaped value - */ - public static String escapeValue(Object pValue) { - return AttributeHandler.escapeValue(pValue); - } - - /** - * Returns a cloned vector of attribute values, or null if the attribute is - * a keyword attribute. If the attribute is single-valued, then the vector - * contains only one object. - * - * @return The value vector - * - */ - public Vector getValues() { - if (this.iValues != null) return GenericExts.cloneVector(this.iValues); - return this.iValues; - } - - /** - * Returns the attribute's name. - * - * @return The name (id) - */ - public String getId() { - return this.iId; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - * - * Overrides Object.equals(). Two attributes are equal if their identifiers - * are equal and their value vectors contain the same number of equal values - * as determined by the Object equals() method. Values having byte[] type - * are equal if the contents of all byte arrays in both attribute vectors - * match. Note that the SLP string matching algorithm [7] MUST NOT be used - * for comparing attribute identifiers or string values. - */ - @Override - public boolean equals(Object obj) { - if (obj == this) return true; - if (!(obj instanceof ServiceLocationAttribute)) return false; - - ServiceLocationAttribute that = (ServiceLocationAttribute) obj; - if (!that.getId().equalsIgnoreCase(this.iId)) return false; - - Vector thatValues = that.iValues; - if (this.iValues == null) return thatValues == null; - if (thatValues == null) return false; - if (this.iValues.size() != thatValues.size()) return false; - - ValueEntry[] thisEntries = getSortedValueEntries(); - ValueEntry[] thatEntries = that.getSortedValueEntries(); - - return Arrays.equals(thisEntries, thatEntries); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - * - * Overrides Object.toString(). The string returned contains a formatted - * representation of the attribute, giving the attribute's id, values, and - * the Java type of the values. The returned string is suitable for - * debugging purposes, but is not in SLP wire format. - */ - @Override - public String toString() { - StringBuffer stringbuffer = new StringBuffer("("); - stringbuffer.append(this.iId); - if (this.iValues != null) { - stringbuffer.append("="); - int size = this.iValues.size(); - for (int i = 0; i < size; i++) { - Object obj = this.iValues.elementAt(i); - if (i > 0) { - stringbuffer.append(","); - } - if (obj instanceof byte[]) obj = AttributeHandler.mkOpaqueStr((byte[]) obj); - stringbuffer.append(obj.toString()); - } - - } - stringbuffer.append(")"); - return stringbuffer.toString(); - } - - private int iHashCode = 0; - - private void incHashCode(int pHashCode) { - this.iHashCode *= 31; - this.iHashCode += pHashCode; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - * - * Overrides Object.hashCode(). Hashes on the attribute's identifier. - */ - @Override - public int hashCode() { - if (this.iHashCode == 0) { - this.iHashCode = this.iId.hashCode(); - if (this.iValues != null) { - ValueEntry[] valueEntries = getSortedValueEntries(); - for (int i = 0; i < valueEntries.length; i++) - incHashCode(valueEntries[i].hashCode()); - } - } - return this.iHashCode; - } - - private void parseValueString(String pStr) throws ServiceLocationException { - StringTokenizer tokenizer = new StringTokenizer(pStr, ","); - this.iValues = new Vector(); - while (tokenizer.hasMoreElements()) { - String valueStr = tokenizer.nextToken(); - Object value; - try { - int intVal = Integer.parseInt(valueStr); - value = Integer.valueOf(intVal); - } catch (NumberFormatException e) { - if ("TRUE".equalsIgnoreCase(valueStr)) { - value = Boolean.TRUE; - } else if ("FALSE".equalsIgnoreCase(valueStr)) { - value = Boolean.FALSE; - } else if (valueStr.startsWith("\\FF")) { - value = parseOpaqueStr(valueStr); - } else { - value = Convert.unescape(valueStr); - } - } - this.iValues.add(value); - } - } - - private static byte[] parseOpaqueStr(String pStr) throws ServiceLocationException { - if (pStr.length() == 3) throw new ServiceLocationException( - ServiceLocationException.PARSE_ERROR, - "There must be at least three characters after \\FF in opaque string!" + " pStr=" - + pStr); - - ByteArrayOutputStream oStr = new ByteArrayOutputStream(); - int pos = 3; // skip "\\FF" - int left; - while ((left = pStr.length() - pos) > 0) { - if (left < 3) throw new ServiceLocationException(ServiceLocationException.PARSE_ERROR, - "Number of characters must be multiple of three after \\FF in opaque string!" - + " pStr=" + pStr); - if (pStr.charAt(pos) != '\\') throw new ServiceLocationException( - ServiceLocationException.PARSE_ERROR, - "Hex value must be preceded by \\ in opaque string!" + " pStr=" + pStr); - String hexStr = pStr.substring(pos + 1, pos + 3); - pos += 3; - try { - oStr.write(Integer.parseInt(hexStr, 16)); - } catch (NumberFormatException e) { - throw new ServiceLocationException(ServiceLocationException.PARSE_ERROR, - "Failed to parse hex value: " + hexStr + " in opaque string: " + pStr - + " !"); - } - } - return oStr.toByteArray(); - } - - static class ValueEntry implements Comparable { - - /** - * iStr - */ - public String iStr; - - /** - * iValue - */ - public Object iValue; - - public int compareTo(ValueEntry o) { - ValueEntry that = o; - return this.iStr.compareTo(that.iStr); - } - - @Override - public boolean equals(Object pObj) { - if (this == pObj) return true; - if (!(pObj instanceof ValueEntry)) return false; - ValueEntry that = (ValueEntry) pObj; - if (this.iValue == null) return that.iValue == null; - if (that.iValue == null) return false; - if (!this.iValue.getClass().equals(that.iValue.getClass())) return false; - if (this.iValue instanceof byte[]) return Arrays.equals((byte[]) this.iValue, - (byte[]) that.iValue); - if (this.iValue instanceof String) return this.iStr.equals(that.iStr); - return this.iValue.equals(that.iValue); - } - - @Override - public int hashCode() { - return this.iStr == null ? 1 : this.iStr.hashCode(); - } - - } - - private transient ValueEntry[] iSortedValueEntries; - - /** - * Used for equals check and hashCode calculation. - * - * @param pAttrib - * @return attribute values in unified order, which is : values are sorted - * by theirs toString(). - */ - private ValueEntry[] getSortedValueEntries() { - if (this.iValues == null) return null; - if (this.iSortedValueEntries != null) return this.iSortedValueEntries; - this.iSortedValueEntries = new ValueEntry[this.iValues.size()]; - for (int i = 0; i < this.iValues.size(); i++) { - ValueEntry entry = new ValueEntry(); - this.iSortedValueEntries[i] = entry; - Object value = this.iValues.get(i); - entry.iValue = value; - if (value == null) { - entry.iStr = ""; - } else { - if (value instanceof String) { - entry.iStr = SLPString.unify((String) value); - } else if (value instanceof byte[]) { - entry.iStr = AttributeHandler.mkOpaqueStr((byte[]) value); - } else { - entry.iStr = value.toString(); - } - } - } - Arrays.sort(this.iSortedValueEntries); - return this.iSortedValueEntries; - } - -} +/* + ServiceLocationAttribute.java + + (C) Copyright IBM Corp. 2005, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1516246 2006-07-22 lupusalex Integrate SLP client code + * 1678915 2007-03-27 lupusalex Integrated WBEM service discovery via SLP + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2795671 2009-05-22 raman_arora Add Type to Comparable + * 2797696 2009-05-27 raman_arora Input files use unsafe operations + * 2823494 2009-08-03 rgummada Change Boolean constructor to static + * 3022519 2010-06-30 blaschke-oss ServiceLocationAttribute.equals() compares same array + * 3022524 2010-06-30 blaschke-oss iSortedValueEntries not serializable in Serializable class + * 3023349 2010-07-02 blaschke-oss SLP uses # constructor instead of valueOf + * 2650 2013-07-18 blaschke-oss SLP opaque value handling incorrect + */ + +package org.metricshub.wbem.sblim.slp; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.ByteArrayOutputStream; +import java.io.Serializable; +import java.util.Arrays; +import java.util.StringTokenizer; +import java.util.Vector; +import org.metricshub.wbem.sblim.cimclient.GenericExts; +import org.metricshub.wbem.sblim.slp.internal.AttributeHandler; +import org.metricshub.wbem.sblim.slp.internal.Convert; +import org.metricshub.wbem.sblim.slp.internal.SLPString; + +/** + * Service location attribute + */ +public class ServiceLocationAttribute implements Serializable { + private static final long serialVersionUID = -6753246108754657715L; + + private Vector iValues; + + private String iId; + + /** + * Construct a service location attribute. Errors in the id or values vector + * result in an IllegalArgumentException. + * + * @param pId + * The attribute name. The String can consist of any Unicode + * character. + * @param pValues + * A Vector of one or more attribute values. Vector contents must + * be uniform in type and one of Integer, String, Boolean, or + * byte[]. If the attribute is a keyword attribute, then the + * parameter should be null. String values can consist of any + * Unicode character. + */ + public ServiceLocationAttribute(String pId, Vector pValues) { + this.iId = pId; + if (pValues != null && pValues.size() > 0) { + this.iValues = GenericExts.cloneVector(pValues); + } + } + + /** + * Construct a service location attribute from a String. + * + * @param pString + * The string to parse + * @throws ServiceLocationException + * When the string parsing failed + */ + public ServiceLocationAttribute(String pString) throws ServiceLocationException { + if (pString == null || pString.length() == 0) throw new ServiceLocationException( + ServiceLocationException.PARSE_ERROR, + "Empty or null String is not good for this constructor!" + ); + + if (pString.startsWith("(") && pString.endsWith(")")) { + int equalPos = pString.indexOf('='); + if (equalPos < 0) throw new ServiceLocationException( + ServiceLocationException.PARSE_ERROR, + "Missing '=' from attribute string: " + pString + ); + this.iId = Convert.unescape(pString.substring(1, equalPos)); + if (this.iId.length() == 0) throw new ServiceLocationException( + ServiceLocationException.PARSE_ERROR, + "Empty attribute ID in attribute string: " + pString + ); + String valueString = pString.substring(equalPos + 1, pString.length() - 1); + + parseValueString(valueString); + } else { + if (pString.indexOf('(') >= 0 || pString.indexOf(')') >= 0) throw new ServiceLocationException( + ServiceLocationException.PARSE_ERROR + ); + this.iId = Convert.unescape(pString); + this.iValues = null; + } + } + + /** + * Returns an escaped version of the id parameter, suitable for inclusion in + * a query. Any reserved characters as specified in [7] are escaped using + * UTF-8 encoding. If any characters in the tag are illegal, throws + * IllegalArgumentException. + * + * @param pId + * The attribute id to escape. ServiceLocationException is thrown + * if any characters are illegal for an attribute tag. + * @return The escaped version + */ + public static String escapeId(String pId) { + return Convert.escape(pId, Convert.ATTR_RESERVED); + } + + /** + * Returns a String containing the escaped value parameter as a string, + * suitable for inclusion in a query. If the parameter is a string, any + * reserved characters as specified in [7] are escaped using UTF-8 encoding. + * If the parameter is a byte array, then the escaped string begins with the + * nonUTF-8 sequence `\ff` and the rest of the string consists of the + * escaped bytes, which is the encoding for opaque. If the value parameter + * is a Boolean or Integer, then the returned string contains the object + * converted into a string. If the value is any type other than String, + * Integer, Boolean or byte[], an IllegalArgumentException is thrown. + * + * @param pValue + * The attribute value to be converted into a string and escaped. + * @return The escaped value + */ + public static String escapeValue(Object pValue) { + return AttributeHandler.escapeValue(pValue); + } + + /** + * Returns a cloned vector of attribute values, or null if the attribute is + * a keyword attribute. If the attribute is single-valued, then the vector + * contains only one object. + * + * @return The value vector + * + */ + public Vector getValues() { + if (this.iValues != null) return GenericExts.cloneVector(this.iValues); + return this.iValues; + } + + /** + * Returns the attribute's name. + * + * @return The name (id) + */ + public String getId() { + return this.iId; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + * + * Overrides Object.equals(). Two attributes are equal if their identifiers + * are equal and their value vectors contain the same number of equal values + * as determined by the Object equals() method. Values having byte[] type + * are equal if the contents of all byte arrays in both attribute vectors + * match. Note that the SLP string matching algorithm [7] MUST NOT be used + * for comparing attribute identifiers or string values. + */ + @Override + public boolean equals(Object obj) { + if (obj == this) return true; + if (!(obj instanceof ServiceLocationAttribute)) return false; + + ServiceLocationAttribute that = (ServiceLocationAttribute) obj; + if (!that.getId().equalsIgnoreCase(this.iId)) return false; + + Vector thatValues = that.iValues; + if (this.iValues == null) return thatValues == null; + if (thatValues == null) return false; + if (this.iValues.size() != thatValues.size()) return false; + + ValueEntry[] thisEntries = getSortedValueEntries(); + ValueEntry[] thatEntries = that.getSortedValueEntries(); + + return Arrays.equals(thisEntries, thatEntries); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + * + * Overrides Object.toString(). The string returned contains a formatted + * representation of the attribute, giving the attribute's id, values, and + * the Java type of the values. The returned string is suitable for + * debugging purposes, but is not in SLP wire format. + */ + @Override + public String toString() { + StringBuffer stringbuffer = new StringBuffer("("); + stringbuffer.append(this.iId); + if (this.iValues != null) { + stringbuffer.append("="); + int size = this.iValues.size(); + for (int i = 0; i < size; i++) { + Object obj = this.iValues.elementAt(i); + if (i > 0) { + stringbuffer.append(","); + } + if (obj instanceof byte[]) obj = AttributeHandler.mkOpaqueStr((byte[]) obj); + stringbuffer.append(obj.toString()); + } + } + stringbuffer.append(")"); + return stringbuffer.toString(); + } + + private int iHashCode = 0; + + private void incHashCode(int pHashCode) { + this.iHashCode *= 31; + this.iHashCode += pHashCode; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + * + * Overrides Object.hashCode(). Hashes on the attribute's identifier. + */ + @Override + public int hashCode() { + if (this.iHashCode == 0) { + this.iHashCode = this.iId.hashCode(); + if (this.iValues != null) { + ValueEntry[] valueEntries = getSortedValueEntries(); + for (int i = 0; i < valueEntries.length; i++) incHashCode(valueEntries[i].hashCode()); + } + } + return this.iHashCode; + } + + private void parseValueString(String pStr) throws ServiceLocationException { + StringTokenizer tokenizer = new StringTokenizer(pStr, ","); + this.iValues = new Vector(); + while (tokenizer.hasMoreElements()) { + String valueStr = tokenizer.nextToken(); + Object value; + try { + int intVal = Integer.parseInt(valueStr); + value = Integer.valueOf(intVal); + } catch (NumberFormatException e) { + if ("TRUE".equalsIgnoreCase(valueStr)) { + value = Boolean.TRUE; + } else if ("FALSE".equalsIgnoreCase(valueStr)) { + value = Boolean.FALSE; + } else if (valueStr.startsWith("\\FF")) { + value = parseOpaqueStr(valueStr); + } else { + value = Convert.unescape(valueStr); + } + } + this.iValues.add(value); + } + } + + private static byte[] parseOpaqueStr(String pStr) throws ServiceLocationException { + if (pStr.length() == 3) throw new ServiceLocationException( + ServiceLocationException.PARSE_ERROR, + "There must be at least three characters after \\FF in opaque string!" + " pStr=" + pStr + ); + + ByteArrayOutputStream oStr = new ByteArrayOutputStream(); + int pos = 3; // skip "\\FF" + int left; + while ((left = pStr.length() - pos) > 0) { + if (left < 3) throw new ServiceLocationException( + ServiceLocationException.PARSE_ERROR, + "Number of characters must be multiple of three after \\FF in opaque string!" + " pStr=" + pStr + ); + if (pStr.charAt(pos) != '\\') throw new ServiceLocationException( + ServiceLocationException.PARSE_ERROR, + "Hex value must be preceded by \\ in opaque string!" + " pStr=" + pStr + ); + String hexStr = pStr.substring(pos + 1, pos + 3); + pos += 3; + try { + oStr.write(Integer.parseInt(hexStr, 16)); + } catch (NumberFormatException e) { + throw new ServiceLocationException( + ServiceLocationException.PARSE_ERROR, + "Failed to parse hex value: " + hexStr + " in opaque string: " + pStr + " !" + ); + } + } + return oStr.toByteArray(); + } + + static class ValueEntry implements Comparable { + /** + * iStr + */ + public String iStr; + + /** + * iValue + */ + public Object iValue; + + public int compareTo(ValueEntry o) { + ValueEntry that = o; + return this.iStr.compareTo(that.iStr); + } + + @Override + public boolean equals(Object pObj) { + if (this == pObj) return true; + if (!(pObj instanceof ValueEntry)) return false; + ValueEntry that = (ValueEntry) pObj; + if (this.iValue == null) return that.iValue == null; + if (that.iValue == null) return false; + if (!this.iValue.getClass().equals(that.iValue.getClass())) return false; + if (this.iValue instanceof byte[]) return Arrays.equals((byte[]) this.iValue, (byte[]) that.iValue); + if (this.iValue instanceof String) return this.iStr.equals(that.iStr); + return this.iValue.equals(that.iValue); + } + + @Override + public int hashCode() { + return this.iStr == null ? 1 : this.iStr.hashCode(); + } + } + + private transient ValueEntry[] iSortedValueEntries; + + /** + * Used for equals check and hashCode calculation. + * + * @param pAttrib + * @return attribute values in unified order, which is : values are sorted + * by theirs toString(). + */ + private ValueEntry[] getSortedValueEntries() { + if (this.iValues == null) return null; + if (this.iSortedValueEntries != null) return this.iSortedValueEntries; + this.iSortedValueEntries = new ValueEntry[this.iValues.size()]; + for (int i = 0; i < this.iValues.size(); i++) { + ValueEntry entry = new ValueEntry(); + this.iSortedValueEntries[i] = entry; + Object value = this.iValues.get(i); + entry.iValue = value; + if (value == null) { + entry.iStr = ""; + } else { + if (value instanceof String) { + entry.iStr = SLPString.unify((String) value); + } else if (value instanceof byte[]) { + entry.iStr = AttributeHandler.mkOpaqueStr((byte[]) value); + } else { + entry.iStr = value.toString(); + } + } + } + Arrays.sort(this.iSortedValueEntries); + return this.iSortedValueEntries; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceLocationAttributeDescriptor.java b/src/main/java/org/metricshub/wbem/sblim/slp/ServiceLocationAttributeDescriptor.java similarity index 81% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceLocationAttributeDescriptor.java rename to src/main/java/org/metricshub/wbem/sblim/slp/ServiceLocationAttributeDescriptor.java index 4d2e5a9..9749da0 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceLocationAttributeDescriptor.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/ServiceLocationAttributeDescriptor.java @@ -1,166 +1,162 @@ -/* - ServiceLocationAttributeDescriptor.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1516246 2006-07-22 lupusalex Integrate SLP client code - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Enumeration; - -/** - * The ServiceLocationAttributeDescriptor interface provides introspection on a - * template attribute definition (see RFC 2609). Classes implementing the - * ServiceLocationAttributeDescriptor interface return information on a - * particular service location attribute definition from the service template. - * This information is primarily for GUI tools. Programmatic attribute - * verification should be done through the ServiceLocationAttributeVerifier. - * - */ -public interface ServiceLocationAttributeDescriptor { - - /** - * Return a String containing the attribute's id. - * - * @return The id - */ - public abstract String getId(); - - /** - * Returns a String containing the fully package-qualified Java type of the - * attribute. SLP types are translated into Java types as follows:
      - *
      - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
      SLPJava
      STRING"java.lang.String"
      INTEGER"java.lang.Integer"
      BOOLEAN"java.lang.Boolean"
      OPAQUE"[B" (byte[])
      KEYWORD"" (empty string)
      - * - * @return The Java type - */ - public abstract String getValueType(); - - /** - * Return a String containing the attribute's help text. - * - * @return The description - */ - public abstract String getDescription(); - - /** - * Return an Enumeration of allowed values for the attribute type. For - * keyword attributes returns null. For no allowed values (i.e. - * unrestricted) returns an empty Enumeration. - * - * @return The allowed values - */ - public abstract Enumeration getAllowedValues(); - - /** - * Return an Enumeration of default values for the attribute type. For - * keyword attributes returns null. For no allowed values (i.e. - * unrestricted) returns an empty Enumeration. - * - * @return The default values - */ - public abstract Enumeration getDefaultValues(); - - /** - * Returns true if the "X" flag is set, indicating that the attribute should - * be included in an any Locator.findServices() request search filter. - * - * @return true if "X" is set, false otherwise - */ - public abstract boolean getRequiresExplicitMatch(); - - /** - * Returns true if the "M" flag is set. - * - * @return true if "M" is set, false otherwise - */ - public abstract boolean getIsMultivalued(); - - /** - * Returns true if the "O"" flag is set. - * - * @return true if "O" is set, false otherwise - */ - public abstract boolean getIsOptional(); - - /** - * Returns true if the "L" flag is set. - * - * @return true if "L" is set, false otherwise - */ - public abstract boolean getIsLiteral(); - - /** - * Returns true if the attribute is a keyword attribute. - * - * @return true if the attribute is a keyword, - * false otherwise - */ - public abstract boolean getIsKeyword(); - -} +/* + ServiceLocationAttributeDescriptor.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1516246 2006-07-22 lupusalex Integrate SLP client code + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Enumeration; + +/** + * The ServiceLocationAttributeDescriptor interface provides introspection on a + * template attribute definition (see RFC 2609). Classes implementing the + * ServiceLocationAttributeDescriptor interface return information on a + * particular service location attribute definition from the service template. + * This information is primarily for GUI tools. Programmatic attribute + * verification should be done through the ServiceLocationAttributeVerifier. + * + */ +public interface ServiceLocationAttributeDescriptor { + /** + * Return a String containing the attribute's id. + * + * @return The id + */ + public abstract String getId(); + + /** + * Returns a String containing the fully package-qualified Java type of the + * attribute. SLP types are translated into Java types as follows:
      + *
      + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
      SLPJava
      STRING"java.lang.String"
      INTEGER"java.lang.Integer"
      BOOLEAN"java.lang.Boolean"
      OPAQUE"[B" (byte[])
      KEYWORD"" (empty string)
      + * + * @return The Java type + */ + public abstract String getValueType(); + + /** + * Return a String containing the attribute's help text. + * + * @return The description + */ + public abstract String getDescription(); + + /** + * Return an Enumeration of allowed values for the attribute type. For + * keyword attributes returns null. For no allowed values (i.e. + * unrestricted) returns an empty Enumeration. + * + * @return The allowed values + */ + public abstract Enumeration getAllowedValues(); + + /** + * Return an Enumeration of default values for the attribute type. For + * keyword attributes returns null. For no allowed values (i.e. + * unrestricted) returns an empty Enumeration. + * + * @return The default values + */ + public abstract Enumeration getDefaultValues(); + + /** + * Returns true if the "X" flag is set, indicating that the attribute should + * be included in an any Locator.findServices() request search filter. + * + * @return true if "X" is set, false otherwise + */ + public abstract boolean getRequiresExplicitMatch(); + + /** + * Returns true if the "M" flag is set. + * + * @return true if "M" is set, false otherwise + */ + public abstract boolean getIsMultivalued(); + + /** + * Returns true if the "O"" flag is set. + * + * @return true if "O" is set, false otherwise + */ + public abstract boolean getIsOptional(); + + /** + * Returns true if the "L" flag is set. + * + * @return true if "L" is set, false otherwise + */ + public abstract boolean getIsLiteral(); + + /** + * Returns true if the attribute is a keyword attribute. + * + * @return true if the attribute is a keyword, + * false otherwise + */ + public abstract boolean getIsKeyword(); +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceLocationAttributeVerifier.java b/src/main/java/org/metricshub/wbem/sblim/slp/ServiceLocationAttributeVerifier.java similarity index 81% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceLocationAttributeVerifier.java rename to src/main/java/org/metricshub/wbem/sblim/slp/ServiceLocationAttributeVerifier.java index 34e63cf..0223420 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceLocationAttributeVerifier.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/ServiceLocationAttributeVerifier.java @@ -1,155 +1,149 @@ -/* - ServiceLocationAttributeVerifier.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1516246 2006-07-22 lupusalex Integrate SLP client code - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Enumeration; -import java.util.Locale; -import java.util.Vector; - -/** - * The ServiceLocationAttributeVerifier provides access to service templates. - * Classes implementing this interface parse SLP template definitions, provide - * information on attribute definitions for service types, and verify whether a - * ServiceLocationAttribute object matches a template for a particular service - * type. Clients obtain ServiceLocationAttributeVerifier objects for specific - * SLP service types through the TemplateRegistry. - * - * - */ -public interface ServiceLocationAttributeVerifier { - - /** - * Returns the SLP service type for which this is the verifier. - * - * @return The service type - */ - public abstract ServiceType getServiceType(); - - /** - * Return the language locale of the template. - * - * @return The locale - */ - public abstract Locale getLocale(); - - /** - * Return the template version number identifier. - * - * @return The version - */ - public abstract String getVersion(); - - /** - * Return the URL syntax expression for the service: URL. - * - * @return The url syntax - */ - public abstract String getURLSyntax(); - - /** - * Return the descriptive help text for the template. - * - * @return The description - */ - public abstract String getDescription(); - - /** - * Return the ServiceLocationAttributeDescriptor for the attribute having - * the named id. If no such attribute exists in this template, return null. - * This method is primarily for GUI tools to display attribute information. - * Programmatic verification of attributes should use the verifyAttribute() - * method. - * - * @param pAttributeId - * The attribute id - * @return The descriptor - */ - public abstract ServiceLocationAttributeDescriptor getAttributeDescriptor(String pAttributeId); - - /** - * Returns an Enumeration allowing introspection on the attribute definition - * in the service template. The Enumeration returns - * ServiceLocationAttributeDescriptor objects for the attributes. This - * method is primarily for GUI tools to display attribute information. - * Programmatic verification of attributes should use the verifyAttribute() - * method. - * - * @return Enumeration of attribute descriptors - */ - public abstract Enumeration getAttributeDescriptors(); - - /** - * Verify that the attribute matches the template definition. If the - * attribute doesn't match, ServiceLocationException is thrown with the - * error code as ServiceLocationException.PARSE_ERROR. - * - * @param pAttribute - * The ServiceLocationAttribute object to be verified. - * @throws ServiceLocationException - * if validation failed - * - */ - public abstract void verifyAttribute(ServiceLocationAttribute pAttribute) - throws ServiceLocationException; - - /** - * Verify that the Vector of ServiceLocationAttribute objects matches the - * template for this service type. The vector must contain all the required - * attributes, and all attributes must match their template definitions. If - * the attributes don't match, ServiceLocationException is thrown with the - * error code as ServiceLocationException.PARSE_ERROR - * - * @param pAttributeVector - * A Vector of ServiceLocationAttribute objects for the - * registration. - * @throws ServiceLocationException - * if attributes don't match - */ - public abstract void verifyRegistration(Vector pAttributeVector) - throws ServiceLocationException; - -} +/* + ServiceLocationAttributeVerifier.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1516246 2006-07-22 lupusalex Integrate SLP client code + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Enumeration; +import java.util.Locale; +import java.util.Vector; + +/** + * The ServiceLocationAttributeVerifier provides access to service templates. + * Classes implementing this interface parse SLP template definitions, provide + * information on attribute definitions for service types, and verify whether a + * ServiceLocationAttribute object matches a template for a particular service + * type. Clients obtain ServiceLocationAttributeVerifier objects for specific + * SLP service types through the TemplateRegistry. + * + * + */ +public interface ServiceLocationAttributeVerifier { + /** + * Returns the SLP service type for which this is the verifier. + * + * @return The service type + */ + public abstract ServiceType getServiceType(); + + /** + * Return the language locale of the template. + * + * @return The locale + */ + public abstract Locale getLocale(); + + /** + * Return the template version number identifier. + * + * @return The version + */ + public abstract String getVersion(); + + /** + * Return the URL syntax expression for the service: URL. + * + * @return The url syntax + */ + public abstract String getURLSyntax(); + + /** + * Return the descriptive help text for the template. + * + * @return The description + */ + public abstract String getDescription(); + + /** + * Return the ServiceLocationAttributeDescriptor for the attribute having + * the named id. If no such attribute exists in this template, return null. + * This method is primarily for GUI tools to display attribute information. + * Programmatic verification of attributes should use the verifyAttribute() + * method. + * + * @param pAttributeId + * The attribute id + * @return The descriptor + */ + public abstract ServiceLocationAttributeDescriptor getAttributeDescriptor(String pAttributeId); + + /** + * Returns an Enumeration allowing introspection on the attribute definition + * in the service template. The Enumeration returns + * ServiceLocationAttributeDescriptor objects for the attributes. This + * method is primarily for GUI tools to display attribute information. + * Programmatic verification of attributes should use the verifyAttribute() + * method. + * + * @return Enumeration of attribute descriptors + */ + public abstract Enumeration getAttributeDescriptors(); + + /** + * Verify that the attribute matches the template definition. If the + * attribute doesn't match, ServiceLocationException is thrown with the + * error code as ServiceLocationException.PARSE_ERROR. + * + * @param pAttribute + * The ServiceLocationAttribute object to be verified. + * @throws ServiceLocationException + * if validation failed + * + */ + public abstract void verifyAttribute(ServiceLocationAttribute pAttribute) throws ServiceLocationException; + + /** + * Verify that the Vector of ServiceLocationAttribute objects matches the + * template for this service type. The vector must contain all the required + * attributes, and all attributes must match their template definitions. If + * the attributes don't match, ServiceLocationException is thrown with the + * error code as ServiceLocationException.PARSE_ERROR + * + * @param pAttributeVector + * A Vector of ServiceLocationAttribute objects for the + * registration. + * @throws ServiceLocationException + * if attributes don't match + */ + public abstract void verifyRegistration(Vector pAttributeVector) throws ServiceLocationException; +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceLocationEnumeration.java b/src/main/java/org/metricshub/wbem/sblim/slp/ServiceLocationEnumeration.java similarity index 77% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceLocationEnumeration.java rename to src/main/java/org/metricshub/wbem/sblim/slp/ServiceLocationEnumeration.java index a42bfb6..590b761 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceLocationEnumeration.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/ServiceLocationEnumeration.java @@ -1,92 +1,89 @@ -/* - ServiceLocationEnumeration.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1516246 2006-07-22 lupusalex Integrate SLP client code - * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Enumeration; -import java.util.NoSuchElementException; - -/** - * The ServiceLocationEnumeration class is the return type for all Locator SLP - * operations. The Java API library may implement this class to block until - * results are available from the SLP operation, so that the client can achieve - * asynchronous operation by retrieving results from the enumeration in a - * separate thread. Clients use the superclass nextElement() method if they are - * unconcerned with SLP exceptions (this method will never ever throw one). - */ -public interface ServiceLocationEnumeration extends Enumeration { - - /** - * Return the next value or block until it becomes available. - * - * @return The next value - * @throws ServiceLocationException - * Thrown if the SLP operation encounters an error. - * @throws NoSuchElementException - * If there are no more elements to return. - */ - public abstract Object next() throws ServiceLocationException, NoSuchElementException; - - /** - * @return next Object in Exception table - * @throws NoSuchElementException - * - * This in internal implementation to get list of all exceptions - * thrown/caught by parser This can throw RuntimeExceptions. - * They can be ignored or used for analysis. - * - * use hasNextException to check whether there exists another - * element in Exception table - */ - public abstract Object nextException() throws NoSuchElementException; - - /** - * @return true if there exists another element in Exception table - * - */ - public abstract boolean hasMoreExceptions(); -} +/* + ServiceLocationEnumeration.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1516246 2006-07-22 lupusalex Integrate SLP client code + * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Enumeration; +import java.util.NoSuchElementException; + +/** + * The ServiceLocationEnumeration class is the return type for all Locator SLP + * operations. The Java API library may implement this class to block until + * results are available from the SLP operation, so that the client can achieve + * asynchronous operation by retrieving results from the enumeration in a + * separate thread. Clients use the superclass nextElement() method if they are + * unconcerned with SLP exceptions (this method will never ever throw one). + */ +public interface ServiceLocationEnumeration extends Enumeration { + /** + * Return the next value or block until it becomes available. + * + * @return The next value + * @throws ServiceLocationException + * Thrown if the SLP operation encounters an error. + * @throws NoSuchElementException + * If there are no more elements to return. + */ + public abstract Object next() throws ServiceLocationException, NoSuchElementException; + + /** + * @return next Object in Exception table + * @throws NoSuchElementException + * + * This in internal implementation to get list of all exceptions + * thrown/caught by parser This can throw RuntimeExceptions. + * They can be ignored or used for analysis. + * + * use hasNextException to check whether there exists another + * element in Exception table + */ + public abstract Object nextException() throws NoSuchElementException; + + /** + * @return true if there exists another element in Exception table + * + */ + public abstract boolean hasMoreExceptions(); +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceLocationException.java b/src/main/java/org/metricshub/wbem/sblim/slp/ServiceLocationException.java similarity index 78% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceLocationException.java rename to src/main/java/org/metricshub/wbem/sblim/slp/ServiceLocationException.java index 71ae593..5f97d96 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceLocationException.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/ServiceLocationException.java @@ -1,262 +1,278 @@ -/* - ServiceLocationException.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1516246 2006-07-22 lupusalex Integrate SLP client code - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.slp; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * The ServiceLocationException class is thrown by all methods when exceptional - * conditions occur in the SLP framework. The error code property determines the - * exact nature of the condition, and an optional message may provide more - * information. - */ -public class ServiceLocationException extends Exception { - - private static final long serialVersionUID = 6414188770647750627L; - - /** - * OK - */ - public static final short OK = 0; - - /** - * There is data for the service type in the scope in the AttrRqst or - * SrvRqst, but not in the requested language. - */ - public static final short LANGUAGE_NOT_SUPPORTED = 1; - - /** - * The message fails to obey SLP syntax. - */ - public static final short PARSE_ERROR = 2; - - /** - * The SrvReg has problems -- e.g., a zero lifetime or an omitted Language - * Tag. - */ - public static final short INVALID_REGISTRATION = 3; - - /** - * The SLP message did not include a scope in its supported by - * the SA or DA. - */ - public static final short SCOPE_NOT_SUPPORTED = 4; - - /** - * The DA or SA receives a request for an unsupported SLP SPI. - */ - public static final short AUTHENTICATION_UNKNOWN = 5; - - /** - * The DA expected URL and ATTR authentication in the SrvReg and did not - * receive it. - */ - public static final short AUTHENTICATION_ABSENT = 6; - - /** - * The DA detected an authentication error in an Authentication block. - */ - public static final short AUTHENTICATION_FAILED = 7; - - /** - * Unsupported version number in message header. - */ - public static final short VERSION_NOT_SUPPORTED = 9; - - /** - * The DA (or SA) is too sick to respond. - */ - public static final short INTERNAL_ERROR = 10; - - /** - * UA or SA SHOULD retry, using exponential back off. - */ - public static final short DA_BUSY = 11; - - /** - * The DA (or SA) received an unknown option from the mandatory range (see - * section 9.1). - */ - public static final short OPTION_NOT_SUPPORTED = 12; - - /** - * The DA received a SrvReg without FRESH set, for an unregistered service - * or with inconsistent Service Types. - */ - public static final short INVALID_UPDATE = 13; - - /** - * The SA received an AttrRqst or SrvTypeRqst and does not support it. - */ - public static final short REQUEST_NOT_SUPPORTED = 14; - - /** - * The SA sent a SrvReg or partial SrvDereg to a DA more frequently than the - * DA's min-refresh-interval. - */ - public static final short REFRESH_REJECTED = 15; - - /** - * NOT_IMPLEMENTED - */ - public static final short NOT_IMPLEMENTED = 16; - - /** - * NETWORK_INIT_FAILED - */ - public static final short NETWORK_INIT_FAILED = 17; - - /** - * NETWORK_TIMED_OUT - */ - public static final short NETWORK_TIMED_OUT = 18; - - /** - * NETWORK_ERROR - */ - public static final short NETWORK_ERROR = 19; - - /** - * INTERNAL_SYSTEM_ERROR - */ - public static final short INTERNAL_SYSTEM_ERROR = 20; - - /** - * TYPE_ERROR - */ - public static final short TYPE_ERROR = 21; - - /** - * BUFFER_OVERFLOW - */ - public static final short BUFFER_OVERFLOW = 22; - - /** - * PREVIOUS_RESPONDER_OVERFLOW - */ - public static final short PREVIOUS_RESPONDER_OVERFLOW = 100; - - private static final String[] ERROR_MESSAGES = { "OK", "LANGUAGE_NOT_SUPPORTED", "PARSE_ERROR", - "INVALID_REGISTRATION", "SCOPE_NOT_SUPPORTED", "AUTHENTICATION_UNKNOWN", - "AUTHENTICATION_ABSENT", "AUTHENTICATION_FAILED", "", "VERSION_NOT_SUPPORTED", - "INTERNAL_ERROR", "DA_BUSY", "OPTION_NOT_SUPPORTED", "INVALID_UPDATE", - "REQUEST_NOT_SUPPORTED", "REFRESH_REJECTED", "NOT_IMPLEMENTED", "NETWORK_INIT_FAILED", - "NETWORK_TIMED_OUT", "NETWORK_ERROR", "INTERNAL_SYSTEM_ERROR", "TYPE_ERROR", - "BUFFER_OVERFLOW" }; - - private short iErrorCode; - - /** - * Ctor. - * - * @param pErrorCode - * One of the ec constants in this class - */ - public ServiceLocationException(short pErrorCode) { - super(ERROR_MESSAGES[pErrorCode]); - this.iErrorCode = pErrorCode; - } - - /** - * Ctor. - * - * @param pErrorCode - * One of the ec constants in this class - * @param pCause - * The cause - */ - public ServiceLocationException(short pErrorCode, Throwable pCause) { - super(ERROR_MESSAGES[pErrorCode], pCause); - this.iErrorCode = pErrorCode; - } - - /** - * Ctor. - * - * @param pErrorCode - * One of the ec constants in this class - * @param pMessage - * A more specific message - * @param pCause - * - */ - public ServiceLocationException(short pErrorCode, String pMessage, Throwable pCause) { - super(ERROR_MESSAGES[pErrorCode] + "(" + pMessage + ")", pCause); - this.iErrorCode = pErrorCode; - } - - /** - * Ctor. - * - * @param pErrorCode - * One of the error code constants in this class - * @param pMessage - * A more specific message - */ - public ServiceLocationException(short pErrorCode, String pMessage) { - this(pErrorCode, pMessage, null); - } - - /** - * Return the error code. The error code takes on one of the static field - * values. - * - * @return The error code - */ - public short getErrorCode() { - return this.iErrorCode; - } - - /** - * Gets the message associated to this exception. - * - * @return The message - */ - @Override - public String getMessage() { - if (getCause() == null) { return super.getMessage(); } - return super.getMessage() + "; nested exception is: \n\t" + getCause().toString(); - } - -} +/* + ServiceLocationException.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1516246 2006-07-22 lupusalex Integrate SLP client code + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.slp; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * The ServiceLocationException class is thrown by all methods when exceptional + * conditions occur in the SLP framework. The error code property determines the + * exact nature of the condition, and an optional message may provide more + * information. + */ +public class ServiceLocationException extends Exception { + private static final long serialVersionUID = 6414188770647750627L; + + /** + * OK + */ + public static final short OK = 0; + + /** + * There is data for the service type in the scope in the AttrRqst or + * SrvRqst, but not in the requested language. + */ + public static final short LANGUAGE_NOT_SUPPORTED = 1; + + /** + * The message fails to obey SLP syntax. + */ + public static final short PARSE_ERROR = 2; + + /** + * The SrvReg has problems -- e.g., a zero lifetime or an omitted Language + * Tag. + */ + public static final short INVALID_REGISTRATION = 3; + + /** + * The SLP message did not include a scope in its supported by + * the SA or DA. + */ + public static final short SCOPE_NOT_SUPPORTED = 4; + + /** + * The DA or SA receives a request for an unsupported SLP SPI. + */ + public static final short AUTHENTICATION_UNKNOWN = 5; + + /** + * The DA expected URL and ATTR authentication in the SrvReg and did not + * receive it. + */ + public static final short AUTHENTICATION_ABSENT = 6; + + /** + * The DA detected an authentication error in an Authentication block. + */ + public static final short AUTHENTICATION_FAILED = 7; + + /** + * Unsupported version number in message header. + */ + public static final short VERSION_NOT_SUPPORTED = 9; + + /** + * The DA (or SA) is too sick to respond. + */ + public static final short INTERNAL_ERROR = 10; + + /** + * UA or SA SHOULD retry, using exponential back off. + */ + public static final short DA_BUSY = 11; + + /** + * The DA (or SA) received an unknown option from the mandatory range (see + * section 9.1). + */ + public static final short OPTION_NOT_SUPPORTED = 12; + + /** + * The DA received a SrvReg without FRESH set, for an unregistered service + * or with inconsistent Service Types. + */ + public static final short INVALID_UPDATE = 13; + + /** + * The SA received an AttrRqst or SrvTypeRqst and does not support it. + */ + public static final short REQUEST_NOT_SUPPORTED = 14; + + /** + * The SA sent a SrvReg or partial SrvDereg to a DA more frequently than the + * DA's min-refresh-interval. + */ + public static final short REFRESH_REJECTED = 15; + + /** + * NOT_IMPLEMENTED + */ + public static final short NOT_IMPLEMENTED = 16; + + /** + * NETWORK_INIT_FAILED + */ + public static final short NETWORK_INIT_FAILED = 17; + + /** + * NETWORK_TIMED_OUT + */ + public static final short NETWORK_TIMED_OUT = 18; + + /** + * NETWORK_ERROR + */ + public static final short NETWORK_ERROR = 19; + + /** + * INTERNAL_SYSTEM_ERROR + */ + public static final short INTERNAL_SYSTEM_ERROR = 20; + + /** + * TYPE_ERROR + */ + public static final short TYPE_ERROR = 21; + + /** + * BUFFER_OVERFLOW + */ + public static final short BUFFER_OVERFLOW = 22; + + /** + * PREVIOUS_RESPONDER_OVERFLOW + */ + public static final short PREVIOUS_RESPONDER_OVERFLOW = 100; + + private static final String[] ERROR_MESSAGES = { + "OK", + "LANGUAGE_NOT_SUPPORTED", + "PARSE_ERROR", + "INVALID_REGISTRATION", + "SCOPE_NOT_SUPPORTED", + "AUTHENTICATION_UNKNOWN", + "AUTHENTICATION_ABSENT", + "AUTHENTICATION_FAILED", + "", + "VERSION_NOT_SUPPORTED", + "INTERNAL_ERROR", + "DA_BUSY", + "OPTION_NOT_SUPPORTED", + "INVALID_UPDATE", + "REQUEST_NOT_SUPPORTED", + "REFRESH_REJECTED", + "NOT_IMPLEMENTED", + "NETWORK_INIT_FAILED", + "NETWORK_TIMED_OUT", + "NETWORK_ERROR", + "INTERNAL_SYSTEM_ERROR", + "TYPE_ERROR", + "BUFFER_OVERFLOW" + }; + + private short iErrorCode; + + /** + * Ctor. + * + * @param pErrorCode + * One of the ec constants in this class + */ + public ServiceLocationException(short pErrorCode) { + super(ERROR_MESSAGES[pErrorCode]); + this.iErrorCode = pErrorCode; + } + + /** + * Ctor. + * + * @param pErrorCode + * One of the ec constants in this class + * @param pCause + * The cause + */ + public ServiceLocationException(short pErrorCode, Throwable pCause) { + super(ERROR_MESSAGES[pErrorCode], pCause); + this.iErrorCode = pErrorCode; + } + + /** + * Ctor. + * + * @param pErrorCode + * One of the ec constants in this class + * @param pMessage + * A more specific message + * @param pCause + * + */ + public ServiceLocationException(short pErrorCode, String pMessage, Throwable pCause) { + super(ERROR_MESSAGES[pErrorCode] + "(" + pMessage + ")", pCause); + this.iErrorCode = pErrorCode; + } + + /** + * Ctor. + * + * @param pErrorCode + * One of the error code constants in this class + * @param pMessage + * A more specific message + */ + public ServiceLocationException(short pErrorCode, String pMessage) { + this(pErrorCode, pMessage, null); + } + + /** + * Return the error code. The error code takes on one of the static field + * values. + * + * @return The error code + */ + public short getErrorCode() { + return this.iErrorCode; + } + + /** + * Gets the message associated to this exception. + * + * @return The message + */ + @Override + public String getMessage() { + if (getCause() == null) { + return super.getMessage(); + } + return super.getMessage() + "; nested exception is: \n\t" + getCause().toString(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceLocationManager.java b/src/main/java/org/metricshub/wbem/sblim/slp/ServiceLocationManager.java similarity index 77% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceLocationManager.java rename to src/main/java/org/metricshub/wbem/sblim/slp/ServiceLocationManager.java index 5ab9b3d..bfbfa85 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceLocationManager.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/ServiceLocationManager.java @@ -1,122 +1,118 @@ -/* - ServiceLocationManager.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1516246 2006-07-22 lupusalex Integrate SLP client code - * 1535756 2006-08-08 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Locale; -import java.util.Vector; - -import org.sentrysoftware.wbem.sblim.slp.internal.AdvertiserImpl; -import org.sentrysoftware.wbem.sblim.slp.internal.ua.LocatorImpl; - -/** - * The ServiceLocationManager manages access to the service location framework. - * Clients obtain the Locator and Advertiser objects for UA and SA, and a Vector - * of known scope names from the ServiceLocationManager. - * - */ -public class ServiceLocationManager { - - /** - * Returns the maximum across all DAs of the min-refresh-interval attribute. - * This value satisfies the advertised refresh interval bounds for all DAs, - * and, if used by the SA, assures that no refresh registration will be - * rejected. If no DA advertises a min-refresh-interval attribute, a value - * of 0 is returned. - * - * Not yet implemented - * - * @return The minimum refresh interval - * @throws ServiceLocationException - */ - public static int getRefreshInterval() throws ServiceLocationException { - throw new ServiceLocationException(ServiceLocationException.NOT_IMPLEMENTED); - } - - /** - * Returns an List of strings with all available scope names. The list of - * scopes comes from a variety of sources, see Section 2.1 for the scope - * discovery algorithm. There is always at least one string in the Vector, - * the default scope, "DEFAULT". - * - * Not yet implemented - * - * @return A Vector containing the scopes - * @throws ServiceLocationException - */ - public static Vector findScopes() throws ServiceLocationException { - throw new ServiceLocationException(ServiceLocationException.NOT_IMPLEMENTED); - } - - /** - * Return a Locator object for the given language locale. If the - * implementation does not support UA functionality, returns null. - * - * @param pLocale - * The language locale of the Locator. The default SLP locale is - * used if null. - * @return The Locator - */ - public static Locator getLocator(Locale pLocale) { - return new LocatorImpl(pLocale); - } - - /** - * Return an Advertiser object for the given language locale. If the - * implementation does not support SA functionality, returns null. - * - * @param pLocale - * The language locale of the Advertiser. The default SLP locale - * is used if null. - * @return The advertiser - */ - public static Advertiser getAdvertiser(Locale pLocale) { - return new AdvertiserImpl(pLocale); - } - -} +/* + ServiceLocationManager.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1516246 2006-07-22 lupusalex Integrate SLP client code + * 1535756 2006-08-08 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Locale; +import java.util.Vector; +import org.metricshub.wbem.sblim.slp.internal.AdvertiserImpl; +import org.metricshub.wbem.sblim.slp.internal.ua.LocatorImpl; + +/** + * The ServiceLocationManager manages access to the service location framework. + * Clients obtain the Locator and Advertiser objects for UA and SA, and a Vector + * of known scope names from the ServiceLocationManager. + * + */ +public class ServiceLocationManager { + + /** + * Returns the maximum across all DAs of the min-refresh-interval attribute. + * This value satisfies the advertised refresh interval bounds for all DAs, + * and, if used by the SA, assures that no refresh registration will be + * rejected. If no DA advertises a min-refresh-interval attribute, a value + * of 0 is returned. + * + * Not yet implemented + * + * @return The minimum refresh interval + * @throws ServiceLocationException + */ + public static int getRefreshInterval() throws ServiceLocationException { + throw new ServiceLocationException(ServiceLocationException.NOT_IMPLEMENTED); + } + + /** + * Returns an List of strings with all available scope names. The list of + * scopes comes from a variety of sources, see Section 2.1 for the scope + * discovery algorithm. There is always at least one string in the Vector, + * the default scope, "DEFAULT". + * + * Not yet implemented + * + * @return A Vector containing the scopes + * @throws ServiceLocationException + */ + public static Vector findScopes() throws ServiceLocationException { + throw new ServiceLocationException(ServiceLocationException.NOT_IMPLEMENTED); + } + + /** + * Return a Locator object for the given language locale. If the + * implementation does not support UA functionality, returns null. + * + * @param pLocale + * The language locale of the Locator. The default SLP locale is + * used if null. + * @return The Locator + */ + public static Locator getLocator(Locale pLocale) { + return new LocatorImpl(pLocale); + } + + /** + * Return an Advertiser object for the given language locale. If the + * implementation does not support SA functionality, returns null. + * + * @param pLocale + * The language locale of the Advertiser. The default SLP locale + * is used if null. + * @return The advertiser + */ + public static Advertiser getAdvertiser(Locale pLocale) { + return new AdvertiserImpl(pLocale); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceType.java b/src/main/java/org/metricshub/wbem/sblim/slp/ServiceType.java similarity index 80% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceType.java rename to src/main/java/org/metricshub/wbem/sblim/slp/ServiceType.java index ed67ccc..30b7436 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceType.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/ServiceType.java @@ -1,271 +1,275 @@ -/* - ServiceType.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1516246 2006-07-22 lupusalex Integrate SLP client code - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.slp; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.Serializable; -import java.util.NoSuchElementException; -import java.util.StringTokenizer; - -/** - * The ServiceType object models the SLP service type. It parses a string based - * service type specifier into its various components, and contains property - * accessors to return the components. URL schemes, protocol service types, and - * abstract service types are all handled. - */ -public class ServiceType implements Serializable { - - private static final long serialVersionUID = -4850546870881037017L; - - private boolean iIsServiceURL = true; - - private String iPrincipleType = ""; - - private String iAbstractType = ""; - - private String iNamingAuthority = ""; - - /** - * - * Constructs a service type object from the service type specifier. Throws - * IllegalArgumentException if the type name is syntactically incorrect. - * - * @param pType - * The service type name as a String. If the service type is from - * a service: URL, the "service:" prefix must be intact. - */ - public ServiceType(String pType) { - parse(pType); - } - - /** - * Returns true if the type name contains the "service:" prefix. - * - * @return true if the type name contains the "service:" prefix - */ - public boolean isServiceURL() { - return this.iIsServiceURL; - } - - /** - * Returns true if the type name is for an abstract type. - * - * @return true if the type name is for an abstract type - */ - public boolean isAbstractType() { - return this.iAbstractType.length() > 0; - } - - /** - * Returns true if the naming authority is the default, i.e. is the empty - * string. - * - * @return true if the naming authority is the default, i.e. is - * the empty string - */ - public boolean isNADefault() { - return this.iNamingAuthority.length() <= 0; - } - - /** - * Returns the concrete type name in an abstract type, or the empty string - * if the service type is not abstract. For example, if the type name is - * "service:printing:ipp", the method returns "ipp". If the type name is - * "service:ftp", the method returns "". - * - * @return true if the service type is not abstract - */ - public String getConcreteTypeName() { - return this.iAbstractType; - } - - /** - * Returns the abstract type name for an abstract type, the protocol name in - * a protocol type, or the URL scheme for a generic URL. For example, in the - * abstract type name "service:printing:ipp", the method returns "printing". - * In the protocol type name "service:ftp", the method returns "ftp". - * - * @return The principle type name - */ - public String getPrincipleTypeName() { - return this.iPrincipleType; - } - - /** - * If the type is an abstract type, returns the fully formatted abstract - * type name including the "service:" and naming authority but without the - * concrete type name or intervening colon. If not an abstract type, returns - * the empty string. For example, in the abstract type name - * "service:printing:ipp", the method returns "service:printing". - * - * @return The abstract type name - */ - public String getAbstractTypeName() { - if (isAbstractType()) return "service:" + this.iPrincipleType - + (this.iNamingAuthority.length() <= 0 ? "" : "." + this.iNamingAuthority); - return ""; - } - - /** - * Return the naming authority name, or the empty string if the naming - * authority is the default. - * - * @return The naming authority - */ - public String getNamingAuthority() { - return this.iNamingAuthority; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - * - * Overrides Object.equals(). The two objects are equal if they are both - * ServiceType objects and the components of both are equal. - */ - @Override - public boolean equals(Object obj) { - if (obj == this) return true; - if (!(obj instanceof ServiceType)) return false; - - ServiceType servicetype = (ServiceType) obj; - return this.iIsServiceURL == servicetype.iIsServiceURL - && this.iPrincipleType.equals(servicetype.iPrincipleType) - && this.iAbstractType.equals(servicetype.iAbstractType) - && this.iNamingAuthority.equals(servicetype.iNamingAuthority); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - * - * Returns the fully formatted type name, including the "service:" if the - * type was originally from a service: URL. - */ - @Override - public String toString() { - // TODO: clean up this - return (this.iIsServiceURL ? "service:" : "") + this.iPrincipleType - + (this.iNamingAuthority.length() <= 0 ? "" : "." + this.iNamingAuthority) - + (this.iAbstractType.length() <= 0 ? "" : ":" + this.iAbstractType); - } - - private int iHashCode = 0; - - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - * - * Overrides Object.hashCode(). Hashes on the string value of the "service" - * prefix, naming authority, if any, abstract and concrete type names for - * abstract types, protocol type name for protocol types, and URL scheme for - * generic URLs. - */ - @Override - public int hashCode() { - if (this.iHashCode == 0) this.iHashCode = toString().hashCode(); - return this.iHashCode; - } - - private void parse(String pString) { - StringTokenizer st = new StringTokenizer(pString, ":.", true); - while (true) { - try { - - String token = st.nextToken(); - if (token.equals(":") || token.equals(".")) continue; - - if (!token.equalsIgnoreCase("service")) { - this.iIsServiceURL = false; - do { - this.iPrincipleType = this.iPrincipleType + token.toLowerCase(); - if (!st.hasMoreTokens()) break; - token = st.nextToken(); - } while (true); - - validateTypeComponent(this.iPrincipleType); - if (!st.hasMoreTokens()) return; - continue; - } - token = st.nextToken(); - if (!token.equals(":")) continue; - this.iPrincipleType = st.nextToken().toLowerCase(); - validateTypeComponent(this.iPrincipleType); - - if (!st.hasMoreTokens()) return; - token = st.nextToken(); - if (token.equals(".")) { - token = st.nextToken(); - validateTypeComponent(token); - if (token.equalsIgnoreCase("iana")) continue; - this.iNamingAuthority = token.toLowerCase(); - if (!st.hasMoreTokens()) return; - token = st.nextToken(); - } - if (token.equals(":")) { - String abstractTypeToken = st.nextToken(); - validateTypeComponent(abstractTypeToken); - this.iAbstractType = abstractTypeToken.toLowerCase(); - if (!st.hasMoreTokens()) return; - } - } catch (NoSuchElementException e) { - throw new IllegalArgumentException(e.getMessage()); - } - } - } - - private static void validateTypeComponent(String str) { - int length = str.length(); - - for (int pos = 0; pos < length; pos++) { - char ch = str.charAt(pos); - if (!Character.isLetterOrDigit(ch) && ch != '+' && ch != '-') { throw new IllegalArgumentException(); } - } - } -} +/* + ServiceType.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1516246 2006-07-22 lupusalex Integrate SLP client code + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.slp; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.Serializable; +import java.util.NoSuchElementException; +import java.util.StringTokenizer; + +/** + * The ServiceType object models the SLP service type. It parses a string based + * service type specifier into its various components, and contains property + * accessors to return the components. URL schemes, protocol service types, and + * abstract service types are all handled. + */ +public class ServiceType implements Serializable { + private static final long serialVersionUID = -4850546870881037017L; + + private boolean iIsServiceURL = true; + + private String iPrincipleType = ""; + + private String iAbstractType = ""; + + private String iNamingAuthority = ""; + + /** + * + * Constructs a service type object from the service type specifier. Throws + * IllegalArgumentException if the type name is syntactically incorrect. + * + * @param pType + * The service type name as a String. If the service type is from + * a service: URL, the "service:" prefix must be intact. + */ + public ServiceType(String pType) { + parse(pType); + } + + /** + * Returns true if the type name contains the "service:" prefix. + * + * @return true if the type name contains the "service:" prefix + */ + public boolean isServiceURL() { + return this.iIsServiceURL; + } + + /** + * Returns true if the type name is for an abstract type. + * + * @return true if the type name is for an abstract type + */ + public boolean isAbstractType() { + return this.iAbstractType.length() > 0; + } + + /** + * Returns true if the naming authority is the default, i.e. is the empty + * string. + * + * @return true if the naming authority is the default, i.e. is + * the empty string + */ + public boolean isNADefault() { + return this.iNamingAuthority.length() <= 0; + } + + /** + * Returns the concrete type name in an abstract type, or the empty string + * if the service type is not abstract. For example, if the type name is + * "service:printing:ipp", the method returns "ipp". If the type name is + * "service:ftp", the method returns "". + * + * @return true if the service type is not abstract + */ + public String getConcreteTypeName() { + return this.iAbstractType; + } + + /** + * Returns the abstract type name for an abstract type, the protocol name in + * a protocol type, or the URL scheme for a generic URL. For example, in the + * abstract type name "service:printing:ipp", the method returns "printing". + * In the protocol type name "service:ftp", the method returns "ftp". + * + * @return The principle type name + */ + public String getPrincipleTypeName() { + return this.iPrincipleType; + } + + /** + * If the type is an abstract type, returns the fully formatted abstract + * type name including the "service:" and naming authority but without the + * concrete type name or intervening colon. If not an abstract type, returns + * the empty string. For example, in the abstract type name + * "service:printing:ipp", the method returns "service:printing". + * + * @return The abstract type name + */ + public String getAbstractTypeName() { + if (isAbstractType()) return ( + "service:" + this.iPrincipleType + (this.iNamingAuthority.length() <= 0 ? "" : "." + this.iNamingAuthority) + ); + return ""; + } + + /** + * Return the naming authority name, or the empty string if the naming + * authority is the default. + * + * @return The naming authority + */ + public String getNamingAuthority() { + return this.iNamingAuthority; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + * + * Overrides Object.equals(). The two objects are equal if they are both + * ServiceType objects and the components of both are equal. + */ + @Override + public boolean equals(Object obj) { + if (obj == this) return true; + if (!(obj instanceof ServiceType)) return false; + + ServiceType servicetype = (ServiceType) obj; + return ( + this.iIsServiceURL == servicetype.iIsServiceURL && + this.iPrincipleType.equals(servicetype.iPrincipleType) && + this.iAbstractType.equals(servicetype.iAbstractType) && + this.iNamingAuthority.equals(servicetype.iNamingAuthority) + ); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + * + * Returns the fully formatted type name, including the "service:" if the + * type was originally from a service: URL. + */ + @Override + public String toString() { + // TODO: clean up this + return ( + (this.iIsServiceURL ? "service:" : "") + + this.iPrincipleType + + (this.iNamingAuthority.length() <= 0 ? "" : "." + this.iNamingAuthority) + + (this.iAbstractType.length() <= 0 ? "" : ":" + this.iAbstractType) + ); + } + + private int iHashCode = 0; + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + * + * Overrides Object.hashCode(). Hashes on the string value of the "service" + * prefix, naming authority, if any, abstract and concrete type names for + * abstract types, protocol type name for protocol types, and URL scheme for + * generic URLs. + */ + @Override + public int hashCode() { + if (this.iHashCode == 0) this.iHashCode = toString().hashCode(); + return this.iHashCode; + } + + private void parse(String pString) { + StringTokenizer st = new StringTokenizer(pString, ":.", true); + while (true) { + try { + String token = st.nextToken(); + if (token.equals(":") || token.equals(".")) continue; + + if (!token.equalsIgnoreCase("service")) { + this.iIsServiceURL = false; + do { + this.iPrincipleType = this.iPrincipleType + token.toLowerCase(); + if (!st.hasMoreTokens()) break; + token = st.nextToken(); + } while (true); + + validateTypeComponent(this.iPrincipleType); + if (!st.hasMoreTokens()) return; + continue; + } + token = st.nextToken(); + if (!token.equals(":")) continue; + this.iPrincipleType = st.nextToken().toLowerCase(); + validateTypeComponent(this.iPrincipleType); + + if (!st.hasMoreTokens()) return; + token = st.nextToken(); + if (token.equals(".")) { + token = st.nextToken(); + validateTypeComponent(token); + if (token.equalsIgnoreCase("iana")) continue; + this.iNamingAuthority = token.toLowerCase(); + if (!st.hasMoreTokens()) return; + token = st.nextToken(); + } + if (token.equals(":")) { + String abstractTypeToken = st.nextToken(); + validateTypeComponent(abstractTypeToken); + this.iAbstractType = abstractTypeToken.toLowerCase(); + if (!st.hasMoreTokens()) return; + } + } catch (NoSuchElementException e) { + throw new IllegalArgumentException(e.getMessage()); + } + } + } + + private static void validateTypeComponent(String str) { + int length = str.length(); + + for (int pos = 0; pos < length; pos++) { + char ch = str.charAt(pos); + if (!Character.isLetterOrDigit(ch) && ch != '+' && ch != '-') { + throw new IllegalArgumentException(); + } + } + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceURL.java b/src/main/java/org/metricshub/wbem/sblim/slp/ServiceURL.java similarity index 83% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceURL.java rename to src/main/java/org/metricshub/wbem/sblim/slp/ServiceURL.java index d9d1370..e6cfeec 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/ServiceURL.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/ServiceURL.java @@ -1,341 +1,340 @@ -/* - ServiceURL.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1516246 2006-07-22 lupusalex Integrate SLP client code - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.slp; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.Serializable; - -/** - * The ServiceURL object models the advertised SLP service URL. It can be either - * a service: URL or a regular URL. These objects are returned from service - * lookup requests, and describe the registered services. This class should be a - * subclass of java.net.URL but can't since that class is final. - */ -public class ServiceURL implements Serializable { - - private static final long serialVersionUID = 8998115518853094365L; - - /** - * Indicates that no port information is required or was returned for this - * URL. - */ - public static final int NO_PORT = 0; - - /** - * Indicates that the URL has a zero lifetime. This value is never returned - * from the API, but can be used to create a ServiceURL object to - * deregister, delete attributes, or find attributes. - */ - public static final int LIFETIME_NONE = 0; - - /** - * The default URL lifetime (3 hours) in seconds. - */ - public static final int LIFETIME_DEFAULT = 10800; - - /** - * The maximum URL lifetime (about 18 hours) in seconds. - */ - public static final int LIFETIME_MAXIMUM = 65535; - - /** - * Indicates that the API implementation should continuously re-register the - * URL until the application exits. - */ - public static final int LIFETIME_PERMANENT = -1; - - static final int PORT_MAXIMUM = 65535; - - private ServiceType iServiceType = null; - - private String iTransport = null; - - private String iHost = null; - - private int iPort = 0; - - private String iURLPath = null; - - private int iLifetime = LIFETIME_DEFAULT; - - /** - * Construct a service URL object having the specified lifetime. - * - * @param pServiceURL - * The URL as a string. Must be either a service: URL or a valid - * generic URL according to RFC 2396 [2]. - * @param pLifetime - * The service advertisement lifetime in seconds. This value may - * be either between LIFETIME_NONE and LIFETIME_MAXIMUM or - * LIFETIME_PERMANENT. - */ - public ServiceURL(String pServiceURL, int pLifetime) { - - if (pLifetime > LIFETIME_MAXIMUM || pLifetime < LIFETIME_PERMANENT) throw new IllegalArgumentException( - "lifetime:" + pLifetime); - - for (int i = 0; i < pServiceURL.length(); i++) { - char c = pServiceURL.charAt(i); - if ("/:-.%_\'*()$!,+\\;@?&=[]".indexOf(c) == -1 && !Character.isLetterOrDigit(c)) { throw new IllegalArgumentException( - "invalid character: '" + c + "' on string \"" + pServiceURL + "\""); } - } - - parseURL(pServiceURL); - - this.iLifetime = (pLifetime == LIFETIME_PERMANENT) ? LIFETIME_MAXIMUM : pLifetime; - } - - /** - * Returns the service type object representing the service type name of the - * URL. - * - * @return The service type - */ - public ServiceType getServiceType() { - return this.iServiceType; - } - - /** - * Set the service type name to the object. Ignored if the URL is a service: - * URL. - * - * @param pServicetype - * The service type object. - */ - public void setServiceType(ServiceType pServicetype) { - if (!this.iServiceType.isServiceURL()) this.iServiceType = pServicetype; - } - - /** - * Get the network layer transport identifier. If the transport is IP, an - * empty string, "", is returned. - * - * @return The NLT identifier - */ - public String getTransport() { - // FIXME What the hell is it? - return ""; - } - - /** - * Returns the host identifier. For IP, this will be the machine name or IP - * address. - * - * @return The host - */ - public String getHost() { - return this.iHost; - } - - /** - * Returns the port number, if any. For non-IP transports, always returns - * NO_PORT. - * - * @return The port - */ - public int getPort() { - return this.iPort; - } - - /** - * Returns the URL path description, if any. - * - * @return The URL path - */ - public String getURLPath() { - return this.iURLPath; - } - - /** - * Returns the service advertisement lifetime. This will be a positive int - * between LIFETIME_NONE and LIFETIME_MAXIMUM. - * - * @return The lifetime - */ - public int getLifetime() { - return this.iLifetime; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - * - * Compares the object to the ServiceURL and returns true if the two are the - * same. Two ServiceURL objects are equal if their current service types - * match and they have the same host, port, transport, and URL path. - */ - @Override - public boolean equals(Object obj) { - if (obj == this) return true; - if (!(obj instanceof ServiceURL)) return false; - - ServiceURL that = (ServiceURL) obj; - - return equalObjs(this.iServiceType, that.iServiceType) - && equalStrs(this.iTransport, that.iTransport) && equalStrs(this.iHost, that.iHost) - && this.iPort == that.iPort; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - * - * Returns a formatted string with the URL. Overrides Object.toString(). The - * returned URL has the original service type or URL scheme, not the current - * service type. - */ - @Override - public String toString() { - StringBuffer buf = new StringBuffer(); - if (this.iServiceType != null) buf.append(this.iServiceType); - if (this.iURLPath != null) { - if (buf.length() > 0) buf.append("://"); - buf.append(this.iURLPath); - } - return buf.toString(); - } - - private int iHashCode = 0; - - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - * - * Overrides Object.hashCode(). Hashes on the current service type, - * transport, host, port, and URL part. !! in this case toString() must not - * contain the lifeTime - */ - @Override - public int hashCode() { - if (this.iHashCode == 0) { - this.iHashCode = toString().hashCode(); - } - return this.iHashCode; - } - - private static final String DELIM = "://"; - - /** - *
      -	 * service: URL or URL
      -	 * 
      -	 * "service:" srvtype "://" addrspec
      -	 * "service:" abstract-type ":" concrete-type> "://" addrspecc
      -	 * 
      -	 * addrspesc  = ( hostName / IPv4Address / IPv6Address ) [ ":" port ]
      -	 * 
      - * - * @param pUrlString - * @throws IllegalArgumentException - */ - private void parseURL(String pUrlStr) throws IllegalArgumentException { - int srvTypeEndIdx = pUrlStr.indexOf(DELIM); - String addrStr; - if (srvTypeEndIdx >= 0) { - this.iServiceType = new ServiceType(pUrlStr.substring(0, srvTypeEndIdx)); - addrStr = pUrlStr.substring(srvTypeEndIdx + DELIM.length()); - } else { - if (pUrlStr.startsWith("service:")) { - this.iServiceType = new ServiceType(pUrlStr); - addrStr = null; - } else { - addrStr = pUrlStr; - } - } - if (addrStr == null) return; - this.iURLPath = addrStr; - if (addrStr.charAt(0) == '[') { - parseIPv6Address(addrStr); - } else { - parseIPv4Address(addrStr); - } - } - - private void parseIPv6Address(String pAddrStr) throws IllegalArgumentException { - int hostEndIdx = pAddrStr.indexOf(']'); - if (hostEndIdx < 0) throw new IllegalArgumentException("']' is not found for IPv6 address"); - int colonIdx = hostEndIdx + 1; - this.iHost = pAddrStr.substring(0, colonIdx); - if (colonIdx < pAddrStr.length()) { - if (pAddrStr.charAt(colonIdx) != ':') throw new IllegalArgumentException( - "':' expected in \"" + pAddrStr + "\" at position " + colonIdx + " !"); - parsePort(pAddrStr.substring(colonIdx + 1), pAddrStr); - } - } - - private void parseIPv4Address(String pAddrStr) { - int colonIdx = pAddrStr.indexOf(':'); - if (colonIdx > 0) { - this.iHost = pAddrStr.substring(0, colonIdx); - parsePort(pAddrStr.substring(colonIdx + 1), pAddrStr); - } else { - this.iHost = pAddrStr; - } - } - - private void parsePort(String pPortStr, String pAddrStr) throws IllegalArgumentException { - try { - this.iPort = Integer.parseInt(pPortStr); - } catch (NumberFormatException e) { - throw new IllegalArgumentException("Port field : " + pPortStr + " in " + pAddrStr - + " is invalid!"); - } - } - - private static boolean equalObjs(Object pThis, Object pThat) { - return pThis == null ? pThat == null : pThis.equals(pThat); - } - - private static boolean equalStrs(String pThis, String pThat) { - return (pThis == null || pThis.length() == 0) ? (pThat == null || pThat.length() == 0) - : pThis.equals(pThat); - } - -} +/* + ServiceURL.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1516246 2006-07-22 lupusalex Integrate SLP client code + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.slp; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.Serializable; + +/** + * The ServiceURL object models the advertised SLP service URL. It can be either + * a service: URL or a regular URL. These objects are returned from service + * lookup requests, and describe the registered services. This class should be a + * subclass of java.net.URL but can't since that class is final. + */ +public class ServiceURL implements Serializable { + private static final long serialVersionUID = 8998115518853094365L; + + /** + * Indicates that no port information is required or was returned for this + * URL. + */ + public static final int NO_PORT = 0; + + /** + * Indicates that the URL has a zero lifetime. This value is never returned + * from the API, but can be used to create a ServiceURL object to + * deregister, delete attributes, or find attributes. + */ + public static final int LIFETIME_NONE = 0; + + /** + * The default URL lifetime (3 hours) in seconds. + */ + public static final int LIFETIME_DEFAULT = 10800; + + /** + * The maximum URL lifetime (about 18 hours) in seconds. + */ + public static final int LIFETIME_MAXIMUM = 65535; + + /** + * Indicates that the API implementation should continuously re-register the + * URL until the application exits. + */ + public static final int LIFETIME_PERMANENT = -1; + + static final int PORT_MAXIMUM = 65535; + + private ServiceType iServiceType = null; + + private String iTransport = null; + + private String iHost = null; + + private int iPort = 0; + + private String iURLPath = null; + + private int iLifetime = LIFETIME_DEFAULT; + + /** + * Construct a service URL object having the specified lifetime. + * + * @param pServiceURL + * The URL as a string. Must be either a service: URL or a valid + * generic URL according to RFC 2396 [2]. + * @param pLifetime + * The service advertisement lifetime in seconds. This value may + * be either between LIFETIME_NONE and LIFETIME_MAXIMUM or + * LIFETIME_PERMANENT. + */ + public ServiceURL(String pServiceURL, int pLifetime) { + if (pLifetime > LIFETIME_MAXIMUM || pLifetime < LIFETIME_PERMANENT) throw new IllegalArgumentException( + "lifetime:" + pLifetime + ); + + for (int i = 0; i < pServiceURL.length(); i++) { + char c = pServiceURL.charAt(i); + if ("/:-.%_\'*()$!,+\\;@?&=[]".indexOf(c) == -1 && !Character.isLetterOrDigit(c)) { + throw new IllegalArgumentException("invalid character: '" + c + "' on string \"" + pServiceURL + "\""); + } + } + + parseURL(pServiceURL); + + this.iLifetime = (pLifetime == LIFETIME_PERMANENT) ? LIFETIME_MAXIMUM : pLifetime; + } + + /** + * Returns the service type object representing the service type name of the + * URL. + * + * @return The service type + */ + public ServiceType getServiceType() { + return this.iServiceType; + } + + /** + * Set the service type name to the object. Ignored if the URL is a service: + * URL. + * + * @param pServicetype + * The service type object. + */ + public void setServiceType(ServiceType pServicetype) { + if (!this.iServiceType.isServiceURL()) this.iServiceType = pServicetype; + } + + /** + * Get the network layer transport identifier. If the transport is IP, an + * empty string, "", is returned. + * + * @return The NLT identifier + */ + public String getTransport() { + // FIXME What the hell is it? + return ""; + } + + /** + * Returns the host identifier. For IP, this will be the machine name or IP + * address. + * + * @return The host + */ + public String getHost() { + return this.iHost; + } + + /** + * Returns the port number, if any. For non-IP transports, always returns + * NO_PORT. + * + * @return The port + */ + public int getPort() { + return this.iPort; + } + + /** + * Returns the URL path description, if any. + * + * @return The URL path + */ + public String getURLPath() { + return this.iURLPath; + } + + /** + * Returns the service advertisement lifetime. This will be a positive int + * between LIFETIME_NONE and LIFETIME_MAXIMUM. + * + * @return The lifetime + */ + public int getLifetime() { + return this.iLifetime; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + * + * Compares the object to the ServiceURL and returns true if the two are the + * same. Two ServiceURL objects are equal if their current service types + * match and they have the same host, port, transport, and URL path. + */ + @Override + public boolean equals(Object obj) { + if (obj == this) return true; + if (!(obj instanceof ServiceURL)) return false; + + ServiceURL that = (ServiceURL) obj; + + return ( + equalObjs(this.iServiceType, that.iServiceType) && + equalStrs(this.iTransport, that.iTransport) && + equalStrs(this.iHost, that.iHost) && + this.iPort == that.iPort + ); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + * + * Returns a formatted string with the URL. Overrides Object.toString(). The + * returned URL has the original service type or URL scheme, not the current + * service type. + */ + @Override + public String toString() { + StringBuffer buf = new StringBuffer(); + if (this.iServiceType != null) buf.append(this.iServiceType); + if (this.iURLPath != null) { + if (buf.length() > 0) buf.append("://"); + buf.append(this.iURLPath); + } + return buf.toString(); + } + + private int iHashCode = 0; + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + * + * Overrides Object.hashCode(). Hashes on the current service type, + * transport, host, port, and URL part. !! in this case toString() must not + * contain the lifeTime + */ + @Override + public int hashCode() { + if (this.iHashCode == 0) { + this.iHashCode = toString().hashCode(); + } + return this.iHashCode; + } + + private static final String DELIM = "://"; + + /** + *
      +	 * service: URL or URL
      +	 *
      +	 * "service:" srvtype "://" addrspec
      +	 * "service:" abstract-type ":" concrete-type> "://" addrspecc
      +	 *
      +	 * addrspesc  = ( hostName / IPv4Address / IPv6Address ) [ ":" port ]
      +	 * 
      + * + * @param pUrlString + * @throws IllegalArgumentException + */ + private void parseURL(String pUrlStr) throws IllegalArgumentException { + int srvTypeEndIdx = pUrlStr.indexOf(DELIM); + String addrStr; + if (srvTypeEndIdx >= 0) { + this.iServiceType = new ServiceType(pUrlStr.substring(0, srvTypeEndIdx)); + addrStr = pUrlStr.substring(srvTypeEndIdx + DELIM.length()); + } else { + if (pUrlStr.startsWith("service:")) { + this.iServiceType = new ServiceType(pUrlStr); + addrStr = null; + } else { + addrStr = pUrlStr; + } + } + if (addrStr == null) return; + this.iURLPath = addrStr; + if (addrStr.charAt(0) == '[') { + parseIPv6Address(addrStr); + } else { + parseIPv4Address(addrStr); + } + } + + private void parseIPv6Address(String pAddrStr) throws IllegalArgumentException { + int hostEndIdx = pAddrStr.indexOf(']'); + if (hostEndIdx < 0) throw new IllegalArgumentException("']' is not found for IPv6 address"); + int colonIdx = hostEndIdx + 1; + this.iHost = pAddrStr.substring(0, colonIdx); + if (colonIdx < pAddrStr.length()) { + if (pAddrStr.charAt(colonIdx) != ':') throw new IllegalArgumentException( + "':' expected in \"" + pAddrStr + "\" at position " + colonIdx + " !" + ); + parsePort(pAddrStr.substring(colonIdx + 1), pAddrStr); + } + } + + private void parseIPv4Address(String pAddrStr) { + int colonIdx = pAddrStr.indexOf(':'); + if (colonIdx > 0) { + this.iHost = pAddrStr.substring(0, colonIdx); + parsePort(pAddrStr.substring(colonIdx + 1), pAddrStr); + } else { + this.iHost = pAddrStr; + } + } + + private void parsePort(String pPortStr, String pAddrStr) throws IllegalArgumentException { + try { + this.iPort = Integer.parseInt(pPortStr); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Port field : " + pPortStr + " in " + pAddrStr + " is invalid!"); + } + } + + private static boolean equalObjs(Object pThis, Object pThat) { + return pThis == null ? pThat == null : pThis.equals(pThat); + } + + private static boolean equalStrs(String pThis, String pThat) { + return (pThis == null || pThis.length() == 0) ? (pThat == null || pThat.length() == 0) : pThis.equals(pThat); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/TemplateRegistry.java b/src/main/java/org/metricshub/wbem/sblim/slp/TemplateRegistry.java similarity index 78% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/TemplateRegistry.java rename to src/main/java/org/metricshub/wbem/sblim/slp/TemplateRegistry.java index 07338e5..c2c9f70 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/TemplateRegistry.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/TemplateRegistry.java @@ -1,143 +1,140 @@ -/* - TemplateRegistry.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1516246 2006-07-22 lupusalex Integrate SLP client code - * 1535756 2006-08-08 lupusalex Make code warning free - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.slp; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Locale; - -/** - * Subclasses of the TemplateRegistry abstract class provide access to service - * location templates [8]. Classes implementing TemplateRegistry perform a - * variety of functions. They manage the registration and access of service type - * template documents. They create attribute verifiers from service templates, - * for verification of attributes and introspection on template documents. Note - * that clients of the Advertiser are not required to verify attributes before - * registering (though they may get a TYPE_ERROR if the implementation supports - * type checking and there is a mismatch with the template). - * - */ -public abstract class TemplateRegistry { - - /** - * Returns the distinguished TemplateRegistry object for performing - * operations on and with service templates. Returns null if the - * implementation doesn't support TemplateRegistry functionality. - * - * Not yet implemented - * - * @return The template registry - */ - public static TemplateRegistry getTemplateRegistry() { - throw new RuntimeException("not implemented"); - } - - /** - * Register the service template with the template registry. - * - * @param pType - * The service type. - * @param pDocumentURL - * A string containing the URL of the template document. May not - * be the empty string. - * @param pLocale - * A Locale object containing the language locale of the - * template. - * @param pVersion - * The version number identifier of template document. - * @throws ServiceLocationException - */ - public abstract void registerServiceTemplate(ServiceType pType, String pDocumentURL, - Locale pLocale, String pVersion) throws ServiceLocationException; - - /** - * Deregister the template for the service type. - * - * @param pType - * The service type. - * @param pLocale - * A Locale object containing the language locale of the - * template. - * @param pVersion - * A String containing the version number. Use null to indicate - * the latest version. - * @throws ServiceLocationException - */ - public abstract void deregisterServiceTemplate(ServiceType pType, Locale pLocale, - String pVersion) throws ServiceLocationException; - - /** - * Returns the URL for the template document. - * - * @param pType - * The service type. - * @param pLocale - * A Locale object containing the language locale of the - * template. - * @param pVersion - * A String containing the version number. Use null to indicate - * the latest version. - * @return The URL - * @throws ServiceLocationException - */ - public abstract String findTemplateURL(ServiceType pType, Locale pLocale, String pVersion) - throws ServiceLocationException; - - /** - * Reads the template document URL and returns an attribute verifier for the - * service type. The attribute verifier can be used for verifying that - * registration attributes match the template, and for introspection on the - * template definition. - * - * @param pDocumentURL - * A String containing the template document's URL. May not be - * the empty string. - * @return The verifier - * @throws ServiceLocationException - */ - public abstract ServiceLocationAttributeVerifier attributeVerifier(String pDocumentURL) - throws ServiceLocationException; - -} +/* + TemplateRegistry.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1516246 2006-07-22 lupusalex Integrate SLP client code + * 1535756 2006-08-08 lupusalex Make code warning free + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.slp; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Locale; + +/** + * Subclasses of the TemplateRegistry abstract class provide access to service + * location templates [8]. Classes implementing TemplateRegistry perform a + * variety of functions. They manage the registration and access of service type + * template documents. They create attribute verifiers from service templates, + * for verification of attributes and introspection on template documents. Note + * that clients of the Advertiser are not required to verify attributes before + * registering (though they may get a TYPE_ERROR if the implementation supports + * type checking and there is a mismatch with the template). + * + */ +public abstract class TemplateRegistry { + + /** + * Returns the distinguished TemplateRegistry object for performing + * operations on and with service templates. Returns null if the + * implementation doesn't support TemplateRegistry functionality. + * + * Not yet implemented + * + * @return The template registry + */ + public static TemplateRegistry getTemplateRegistry() { + throw new RuntimeException("not implemented"); + } + + /** + * Register the service template with the template registry. + * + * @param pType + * The service type. + * @param pDocumentURL + * A string containing the URL of the template document. May not + * be the empty string. + * @param pLocale + * A Locale object containing the language locale of the + * template. + * @param pVersion + * The version number identifier of template document. + * @throws ServiceLocationException + */ + public abstract void registerServiceTemplate(ServiceType pType, String pDocumentURL, Locale pLocale, String pVersion) + throws ServiceLocationException; + + /** + * Deregister the template for the service type. + * + * @param pType + * The service type. + * @param pLocale + * A Locale object containing the language locale of the + * template. + * @param pVersion + * A String containing the version number. Use null to indicate + * the latest version. + * @throws ServiceLocationException + */ + public abstract void deregisterServiceTemplate(ServiceType pType, Locale pLocale, String pVersion) + throws ServiceLocationException; + + /** + * Returns the URL for the template document. + * + * @param pType + * The service type. + * @param pLocale + * A Locale object containing the language locale of the + * template. + * @param pVersion + * A String containing the version number. Use null to indicate + * the latest version. + * @return The URL + * @throws ServiceLocationException + */ + public abstract String findTemplateURL(ServiceType pType, Locale pLocale, String pVersion) + throws ServiceLocationException; + + /** + * Reads the template document URL and returns an attribute verifier for the + * service type. The attribute verifier can be used for verifying that + * registration attributes match the template, and for introspection on the + * template definition. + * + * @param pDocumentURL + * A String containing the template document's URL. May not be + * the empty string. + * @return The verifier + * @throws ServiceLocationException + */ + public abstract ServiceLocationAttributeVerifier attributeVerifier(String pDocumentURL) + throws ServiceLocationException; +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/AdvertiserImpl.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/AdvertiserImpl.java similarity index 69% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/AdvertiserImpl.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/AdvertiserImpl.java index 8ec0d2f..e9ed890 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/AdvertiserImpl.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/AdvertiserImpl.java @@ -1,186 +1,178 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1804402 2007-11-10 ebak IPv6 ready SLP - revision 4 - * 1892103 2008-02-15 ebak SLP improvements - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.sblim.slp.Advertiser; -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationAttribute; -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; -import org.sentrysoftware.wbem.sblim.slp.ServiceURL; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.MsgFactory; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.SLPMessage; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.ServiceAcknowledgment; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.ServiceDeregistration; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.ServiceRegistration; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.Util; - -import java.io.IOException; -import java.net.DatagramPacket; -import java.net.DatagramSocket; -import java.net.InetAddress; -import java.net.SocketTimeoutException; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.Vector; - - - -/** - * AdvertiserImpl - * - */ -public class AdvertiserImpl implements Advertiser { - - private Locale iLocale; - - private String iLangTag; - - private List iDefScopeList; - - private final int iMaxDatagramSize = SLPConfig.getGlobalCfg().getMTU(); - - private final byte[] iInBuf = new byte[this.iMaxDatagramSize]; - - private final int[] iTimeOuts = SLPConfig.getGlobalCfg().getDatagramTimeouts(); - - private boolean iUseV6 = Net.hasIPv6() && SLPConfig.getGlobalCfg().useIPv6(); - - /** - * Ctor. - * - * @param pLocale - */ - public AdvertiserImpl(Locale pLocale) { - this.iLocale = pLocale; - this.iLangTag = Util.getLangTag(this.iLocale); - this.iDefScopeList = new ArrayList(); - this.iDefScopeList.add(SLPDefaults.DEFAULT_SCOPE); - } - - /** - * @param pURL - * @param pAttributes - * @throws ServiceLocationException - */ - public void addAttributes(ServiceURL pURL, Vector pAttributes) - throws ServiceLocationException { - throw new ServiceLocationException(ServiceLocationException.NOT_IMPLEMENTED); - } - - /** - * @param pURL - * @param pAttributeIds - * @throws ServiceLocationException - */ - public void deleteAttributes(ServiceURL pURL, Vector pAttributeIds) - throws ServiceLocationException { - throw new ServiceLocationException(ServiceLocationException.NOT_IMPLEMENTED); - } - - public void deregister(ServiceURL pURL) throws ServiceLocationException { - sendMessage(new ServiceDeregistration(this.iLangTag, this.iDefScopeList, pURL, null)); - } - - public Locale getLocale() { - return this.iLocale; - } - - public void register(ServiceURL pURL, Vector pAttributes) - throws ServiceLocationException { - sendMessage(new ServiceRegistration(this.iLangTag, pURL, this.iDefScopeList, pAttributes, - null)); - - } - - private void sendMessage(SLPMessage pMsg) throws ServiceLocationException { - try { - int res = unicast(pMsg); - if (res != ServiceLocationException.OK) throw new ServiceLocationException((short) res); - TRC.debug("service registered"); - } catch (IOException e) { - throw new ServiceLocationException(ServiceLocationException.NETWORK_ERROR, e); - } - } - - private int unicast(SLPMessage pMsg) throws ServiceLocationException, IOException { - DatagramSocket dgSocket = new DatagramSocket(); - try { - byte[] reqBytes = pMsg.serialize(false, true, false); - InetAddress loopback = this.iUseV6 ? SLPConfig.getLoopbackV6() : SLPConfig - .getLoopbackV4(); - TRC.debug("loopback:" + loopback); - - DatagramPacket outPacket = new DatagramPacket(reqBytes, reqBytes.length, loopback, - SLPConfig.getGlobalCfg().getPort()); - DatagramPacket inPacket = new DatagramPacket(this.iInBuf, this.iInBuf.length); - - int timeOutIdx = 0; - while (timeOutIdx < this.iTimeOuts.length) { - TRC.debug("sending : " + pMsg); - dgSocket.send(outPacket); - dgSocket.setSoTimeout(this.iTimeOuts[timeOutIdx++]); - try { - dgSocket.receive(inPacket); - } catch (SocketTimeoutException e) { - TRC.debug("receive time out"); - continue; - } - SLPMessage msg = MsgFactory.parse(inPacket); - TRC.debug("expected: " + pMsg.getXID() + ", received : " + msg); - if (msg instanceof ServiceAcknowledgment) { - ServiceAcknowledgment ack = (ServiceAcknowledgment) msg; - if (ack.getXID() == pMsg.getXID()) return ack.getErrorCode(); - } - TRC.debug("ignoring :" + msg); - } - } finally { - dgSocket.close(); - } - TRC.warning("registration failed"); - return ServiceLocationException.INVALID_REGISTRATION; - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1804402 2007-11-10 ebak IPv6 ready SLP - revision 4 + * 1892103 2008-02-15 ebak SLP improvements + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp.internal; + +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; +import java.net.SocketTimeoutException; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Vector; +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.sblim.slp.Advertiser; +import org.metricshub.wbem.sblim.slp.ServiceLocationAttribute; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; +import org.metricshub.wbem.sblim.slp.ServiceURL; +import org.metricshub.wbem.sblim.slp.internal.msg.MsgFactory; +import org.metricshub.wbem.sblim.slp.internal.msg.SLPMessage; +import org.metricshub.wbem.sblim.slp.internal.msg.ServiceAcknowledgment; +import org.metricshub.wbem.sblim.slp.internal.msg.ServiceDeregistration; +import org.metricshub.wbem.sblim.slp.internal.msg.ServiceRegistration; +import org.metricshub.wbem.sblim.slp.internal.msg.Util; + +/** + * AdvertiserImpl + * + */ +public class AdvertiserImpl implements Advertiser { + private Locale iLocale; + + private String iLangTag; + + private List iDefScopeList; + + private final int iMaxDatagramSize = SLPConfig.getGlobalCfg().getMTU(); + + private final byte[] iInBuf = new byte[this.iMaxDatagramSize]; + + private final int[] iTimeOuts = SLPConfig.getGlobalCfg().getDatagramTimeouts(); + + private boolean iUseV6 = Net.hasIPv6() && SLPConfig.getGlobalCfg().useIPv6(); + + /** + * Ctor. + * + * @param pLocale + */ + public AdvertiserImpl(Locale pLocale) { + this.iLocale = pLocale; + this.iLangTag = Util.getLangTag(this.iLocale); + this.iDefScopeList = new ArrayList(); + this.iDefScopeList.add(SLPDefaults.DEFAULT_SCOPE); + } + + /** + * @param pURL + * @param pAttributes + * @throws ServiceLocationException + */ + public void addAttributes(ServiceURL pURL, Vector pAttributes) + throws ServiceLocationException { + throw new ServiceLocationException(ServiceLocationException.NOT_IMPLEMENTED); + } + + /** + * @param pURL + * @param pAttributeIds + * @throws ServiceLocationException + */ + public void deleteAttributes(ServiceURL pURL, Vector pAttributeIds) throws ServiceLocationException { + throw new ServiceLocationException(ServiceLocationException.NOT_IMPLEMENTED); + } + + public void deregister(ServiceURL pURL) throws ServiceLocationException { + sendMessage(new ServiceDeregistration(this.iLangTag, this.iDefScopeList, pURL, null)); + } + + public Locale getLocale() { + return this.iLocale; + } + + public void register(ServiceURL pURL, Vector pAttributes) throws ServiceLocationException { + sendMessage(new ServiceRegistration(this.iLangTag, pURL, this.iDefScopeList, pAttributes, null)); + } + + private void sendMessage(SLPMessage pMsg) throws ServiceLocationException { + try { + int res = unicast(pMsg); + if (res != ServiceLocationException.OK) throw new ServiceLocationException((short) res); + TRC.debug("service registered"); + } catch (IOException e) { + throw new ServiceLocationException(ServiceLocationException.NETWORK_ERROR, e); + } + } + + private int unicast(SLPMessage pMsg) throws ServiceLocationException, IOException { + DatagramSocket dgSocket = new DatagramSocket(); + try { + byte[] reqBytes = pMsg.serialize(false, true, false); + InetAddress loopback = this.iUseV6 ? SLPConfig.getLoopbackV6() : SLPConfig.getLoopbackV4(); + TRC.debug("loopback:" + loopback); + + DatagramPacket outPacket = new DatagramPacket( + reqBytes, + reqBytes.length, + loopback, + SLPConfig.getGlobalCfg().getPort() + ); + DatagramPacket inPacket = new DatagramPacket(this.iInBuf, this.iInBuf.length); + + int timeOutIdx = 0; + while (timeOutIdx < this.iTimeOuts.length) { + TRC.debug("sending : " + pMsg); + dgSocket.send(outPacket); + dgSocket.setSoTimeout(this.iTimeOuts[timeOutIdx++]); + try { + dgSocket.receive(inPacket); + } catch (SocketTimeoutException e) { + TRC.debug("receive time out"); + continue; + } + SLPMessage msg = MsgFactory.parse(inPacket); + TRC.debug("expected: " + pMsg.getXID() + ", received : " + msg); + if (msg instanceof ServiceAcknowledgment) { + ServiceAcknowledgment ack = (ServiceAcknowledgment) msg; + if (ack.getXID() == pMsg.getXID()) return ack.getErrorCode(); + } + TRC.debug("ignoring :" + msg); + } + } finally { + dgSocket.close(); + } + TRC.warning("registration failed"); + return ServiceLocationException.INVALID_REGISTRATION; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/AttributeHandler.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/AttributeHandler.java similarity index 75% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/AttributeHandler.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/AttributeHandler.java index e8e5aba..71f7f28 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/AttributeHandler.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/AttributeHandler.java @@ -1,129 +1,125 @@ -/* - (C) Copyright IBM Corp. 2007, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2650 2013-07-18 blaschke-oss SLP opaque value handling incorrect - */ - -package org.sentrysoftware.wbem.sblim.slp.internal; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Iterator; -import java.util.Vector; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationAttribute; - -/** - * AttributeHandler - * - */ -public class AttributeHandler { - - /* - * attr-list = attribute / attribute `,' attr-list attribute = `(' attr-tag - * `=' attr-val-list `)' / attr-tag attr-val-list = attr-val / attr-val `,' - * attr-val-list attr-tag = 1*safe-tag attr-val = intval / strval / boolval - * / opaque intval = [-]1*DIGIT strval = 1*safe-val boolval = "true" / - * "false" opaque = "\FF" 1*escape-val safe-val = ; Any character except - * reserved. safe-tag = ; Any character except reserved, star and bad-tag. - * reserved = `(' / `)' / `,' / `\' / `!' / `<' / `=' / `>' / `~' / CTL - * escape-val = `\' HEXDIG HEXDIG bad-tag = CR / LF / HTAB / `_' star = `*' - */ - /** - * @param pAttr - * @return String - */ - public static String buildString(ServiceLocationAttribute pAttr) { - StringBuffer buf = new StringBuffer(); - Vector valVec = pAttr.getValues(); - if (valVec != null && valVec.size() > 0) buf.append('('); - buf.append(Convert.escape(pAttr.getId(), Convert.ATTR_RESERVED)); - if (valVec != null && valVec.size() > 0) { - buf.append('='); - Iterator itr = valVec.iterator(); - boolean first = true; - while (itr.hasNext()) { - if (first) first = false; - else buf.append(','); - buf.append(AttributeHandler.escapeValue(itr.next())); - } - buf.append(')'); - } - return buf.toString(); - } - - /** - * escapeValue - * - * @param pValue - * @return String - */ - public static String escapeValue(Object pValue) { - if (pValue instanceof String) { - return Convert.escape((String) pValue, Convert.ATTR_RESERVED); - } else if (pValue instanceof Integer) { - return ((Integer) pValue).toString(); - } else if (pValue instanceof Boolean) { - return ((Boolean) pValue).toString(); - } else if (pValue instanceof byte[]) { - return AttributeHandler.mkOpaqueStr((byte[]) pValue); - } else if (pValue == null) { return ""; } - throw new IllegalArgumentException("Type: " + pValue.getClass().getName() - + " cannot be an attribute value!"); - } - - /** - * mkOpaqueStr - * - * @param pBytes - * @return String - */ - public static String mkOpaqueStr(byte[] pBytes) { - StringBuilder buf = new StringBuilder("\\FF"); - for (int i = 0; i < pBytes.length; i++) { - int value = pBytes[i] & 0xff; - String hexStr = Integer.toString(value, 16).toUpperCase(); - buf.append('\\'); - if (hexStr.length() == 1) buf.append('0'); - buf.append(hexStr); - } - return buf.toString(); - } - -} +/* + (C) Copyright IBM Corp. 2007, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2650 2013-07-18 blaschke-oss SLP opaque value handling incorrect + */ + +package org.metricshub.wbem.sblim.slp.internal; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Iterator; +import java.util.Vector; +import org.metricshub.wbem.sblim.slp.ServiceLocationAttribute; + +/** + * AttributeHandler + * + */ +public class AttributeHandler { + + /* + * attr-list = attribute / attribute `,' attr-list attribute = `(' attr-tag + * `=' attr-val-list `)' / attr-tag attr-val-list = attr-val / attr-val `,' + * attr-val-list attr-tag = 1*safe-tag attr-val = intval / strval / boolval + * / opaque intval = [-]1*DIGIT strval = 1*safe-val boolval = "true" / + * "false" opaque = "\FF" 1*escape-val safe-val = ; Any character except + * reserved. safe-tag = ; Any character except reserved, star and bad-tag. + * reserved = `(' / `)' / `,' / `\' / `!' / `<' / `=' / `>' / `~' / CTL + * escape-val = `\' HEXDIG HEXDIG bad-tag = CR / LF / HTAB / `_' star = `*' + */ + /** + * @param pAttr + * @return String + */ + public static String buildString(ServiceLocationAttribute pAttr) { + StringBuffer buf = new StringBuffer(); + Vector valVec = pAttr.getValues(); + if (valVec != null && valVec.size() > 0) buf.append('('); + buf.append(Convert.escape(pAttr.getId(), Convert.ATTR_RESERVED)); + if (valVec != null && valVec.size() > 0) { + buf.append('='); + Iterator itr = valVec.iterator(); + boolean first = true; + while (itr.hasNext()) { + if (first) first = false; else buf.append(','); + buf.append(AttributeHandler.escapeValue(itr.next())); + } + buf.append(')'); + } + return buf.toString(); + } + + /** + * escapeValue + * + * @param pValue + * @return String + */ + public static String escapeValue(Object pValue) { + if (pValue instanceof String) { + return Convert.escape((String) pValue, Convert.ATTR_RESERVED); + } else if (pValue instanceof Integer) { + return ((Integer) pValue).toString(); + } else if (pValue instanceof Boolean) { + return ((Boolean) pValue).toString(); + } else if (pValue instanceof byte[]) { + return AttributeHandler.mkOpaqueStr((byte[]) pValue); + } else if (pValue == null) { + return ""; + } + throw new IllegalArgumentException("Type: " + pValue.getClass().getName() + " cannot be an attribute value!"); + } + + /** + * mkOpaqueStr + * + * @param pBytes + * @return String + */ + public static String mkOpaqueStr(byte[] pBytes) { + StringBuilder buf = new StringBuilder("\\FF"); + for (int i = 0; i < pBytes.length; i++) { + int value = pBytes[i] & 0xff; + String hexStr = Integer.toString(value, 16).toUpperCase(); + buf.append('\\'); + if (hexStr.length() == 1) buf.append('0'); + buf.append(hexStr); + } + return buf.toString(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/Convert.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/Convert.java similarity index 75% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/Convert.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/Convert.java index 4ba64cf..82638ee 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/Convert.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/Convert.java @@ -1,173 +1,171 @@ -/* - (C) Copyright IBM Corp. 2007, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2650 2013-07-18 blaschke-oss SLP opaque value handling incorrect - */ - -package org.sentrysoftware.wbem.sblim.slp.internal; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.UnsupportedEncodingException; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; - -/** - * Convert - * - */ -public class Convert { - - /** - * ATTR_RESERVED - */ - public static final String ATTR_RESERVED = "(),\\!<=>~"; - - /** - * SCOPE_RESERVED - */ - public static final String SCOPE_RESERVED = "(),\\!<=>~;*+"; - - /** - * DEFAULT_RESERVED - */ - public static final String DEFAULT_RESERVED = ATTR_RESERVED; - - private static final byte[] EMPTY_BYTES = new byte[0]; - - /** - * getBytes - * - * @param pStr - * @return byte[] - */ - public static byte[] getBytes(String pStr) { - if (pStr == null) return EMPTY_BYTES; - try { - return pStr.getBytes(SLPDefaults.ENCODING); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException("Unsupported encoding : " + SLPDefaults.ENCODING, e); - } - } - - /** - * escape - * - * @param pStr - * @return String - */ - public static String escape(String pStr) { - return escape(pStr, DEFAULT_RESERVED); - } - - /** - * escape - * - * @param pStr - * @param pReservedChars - * @return String - */ - public static String escape(String pStr, String pReservedChars) { - if (pStr == null) return ""; - if (pReservedChars == null) return pStr; - StringBuffer strBuf = null; - for (int i = 0; i < pStr.length(); i++) { - char ch = pStr.charAt(i); - if (ch < 32 || pReservedChars.indexOf(ch) >= 0) { - if (strBuf == null) { - strBuf = new StringBuffer(); - if (i > 0) strBuf.append(pStr.substring(0, i)); - } - strBuf.append(escapeChar(ch)); - } else if (strBuf != null) { - strBuf.append(ch); - } - } - return strBuf == null ? pStr : strBuf.toString(); - } - - /** - * unescape - * - * @param pStr - * @return String - * @throws ServiceLocationException - */ - public static String unescape(String pStr) throws ServiceLocationException { - if (pStr == null) return null; - StringBuffer resBuf = null; - int pos, lastPos = 0; - while ((pos = pStr.indexOf('\\', lastPos)) >= 0) { - char ch = unescapeChar(pStr.substring(pos)); - if (resBuf == null) resBuf = new StringBuffer(); - resBuf.append(pStr.subSequence(lastPos, pos)).append(ch); - lastPos = pos + 3; - } - if (resBuf != null && lastPos < pStr.length()) resBuf.append(pStr.substring(lastPos, pStr - .length())); - return resBuf == null ? pStr : resBuf.toString(); - } - - /** - * The escape character is a backslash (UTF-8 0x5c) followed by the two - * hexadecimal digits of the escaped character. -> Character code is ASCII. - * - * @param ch - * @return String - */ - private static String escapeChar(char ch) { - int code = ch; - String hexStr = Integer.toHexString(code).toUpperCase(); - return (hexStr.length() == 1 ? "\\0" : "\\") + hexStr; - } - - private static char unescapeChar(String pEscSeq) throws ServiceLocationException { - if (pEscSeq.length() < 3) throw new ServiceLocationException( - ServiceLocationException.PARSE_ERROR, - "Escaped character must contain 2 hex digits!\n" + "pEscSeq:" + pEscSeq); - String hexStr = pEscSeq.substring(1, 3); - try { - int code = Integer.parseInt(hexStr, 16); - return (char) code; - } catch (NumberFormatException e) { - throw new ServiceLocationException(ServiceLocationException.PARSE_ERROR, - "Failed to parse hex string: " + hexStr + ", pEscSeq=" + pEscSeq + " !", e); - } - } - -} +/* + (C) Copyright IBM Corp. 2007, 2013 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2650 2013-07-18 blaschke-oss SLP opaque value handling incorrect + */ + +package org.metricshub.wbem.sblim.slp.internal; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.UnsupportedEncodingException; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; + +/** + * Convert + * + */ +public class Convert { + /** + * ATTR_RESERVED + */ + public static final String ATTR_RESERVED = "(),\\!<=>~"; + + /** + * SCOPE_RESERVED + */ + public static final String SCOPE_RESERVED = "(),\\!<=>~;*+"; + + /** + * DEFAULT_RESERVED + */ + public static final String DEFAULT_RESERVED = ATTR_RESERVED; + + private static final byte[] EMPTY_BYTES = new byte[0]; + + /** + * getBytes + * + * @param pStr + * @return byte[] + */ + public static byte[] getBytes(String pStr) { + if (pStr == null) return EMPTY_BYTES; + try { + return pStr.getBytes(SLPDefaults.ENCODING); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException("Unsupported encoding : " + SLPDefaults.ENCODING, e); + } + } + + /** + * escape + * + * @param pStr + * @return String + */ + public static String escape(String pStr) { + return escape(pStr, DEFAULT_RESERVED); + } + + /** + * escape + * + * @param pStr + * @param pReservedChars + * @return String + */ + public static String escape(String pStr, String pReservedChars) { + if (pStr == null) return ""; + if (pReservedChars == null) return pStr; + StringBuffer strBuf = null; + for (int i = 0; i < pStr.length(); i++) { + char ch = pStr.charAt(i); + if (ch < 32 || pReservedChars.indexOf(ch) >= 0) { + if (strBuf == null) { + strBuf = new StringBuffer(); + if (i > 0) strBuf.append(pStr.substring(0, i)); + } + strBuf.append(escapeChar(ch)); + } else if (strBuf != null) { + strBuf.append(ch); + } + } + return strBuf == null ? pStr : strBuf.toString(); + } + + /** + * unescape + * + * @param pStr + * @return String + * @throws ServiceLocationException + */ + public static String unescape(String pStr) throws ServiceLocationException { + if (pStr == null) return null; + StringBuffer resBuf = null; + int pos, lastPos = 0; + while ((pos = pStr.indexOf('\\', lastPos)) >= 0) { + char ch = unescapeChar(pStr.substring(pos)); + if (resBuf == null) resBuf = new StringBuffer(); + resBuf.append(pStr.subSequence(lastPos, pos)).append(ch); + lastPos = pos + 3; + } + if (resBuf != null && lastPos < pStr.length()) resBuf.append(pStr.substring(lastPos, pStr.length())); + return resBuf == null ? pStr : resBuf.toString(); + } + + /** + * The escape character is a backslash (UTF-8 0x5c) followed by the two + * hexadecimal digits of the escaped character. -> Character code is ASCII. + * + * @param ch + * @return String + */ + private static String escapeChar(char ch) { + int code = ch; + String hexStr = Integer.toHexString(code).toUpperCase(); + return (hexStr.length() == 1 ? "\\0" : "\\") + hexStr; + } + + private static char unescapeChar(String pEscSeq) throws ServiceLocationException { + if (pEscSeq.length() < 3) throw new ServiceLocationException( + ServiceLocationException.PARSE_ERROR, + "Escaped character must contain 2 hex digits!\n" + "pEscSeq:" + pEscSeq + ); + String hexStr = pEscSeq.substring(1, 3); + try { + int code = Integer.parseInt(hexStr, 16); + return (char) code; + } catch (NumberFormatException e) { + throw new ServiceLocationException( + ServiceLocationException.PARSE_ERROR, + "Failed to parse hex string: " + hexStr + ", pEscSeq=" + pEscSeq + " !", + e + ); + } + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/IPv6MulticastAddressFactory.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/IPv6MulticastAddressFactory.java similarity index 70% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/IPv6MulticastAddressFactory.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/IPv6MulticastAddressFactory.java index 677b3c9..f39b9fa 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/IPv6MulticastAddressFactory.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/IPv6MulticastAddressFactory.java @@ -1,169 +1,164 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.net.InetAddress; -import java.net.UnknownHostException; - -import org.sentrysoftware.wbem.sblim.slp.ServiceType; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.AttributeRequest; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.SLPMessage; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.ServiceRequest; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.ServiceTypeRequest; - -/** - *
      - * SVRLOC group-id : FF0X:0:0:0:0:0:0:116
      - *  - SRVTYPERQST Service Type Request
      - *  - ATTRRQST Attribute Request
      - *  - UA sends too
      - *  
      - * SVRLOC-DA group-id : FF0X:0:0:0:0:0:0:123
      - *  - SRVRQST for the "service:directory-agent" service type
      - *  - UA sends too
      - * 
      - * 1000 - 13FF: SRVRQST : FF0X:0:0:0:0:0:1:....
      - *  - the ID is the hashcode of the Service Type string used in the SrvRqst.
      - *  - UA sends too
      - * 
      - */ -public class IPv6MulticastAddressFactory { - - private static final byte[] SRVLOC = { (byte) 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - (byte) 0x16 }; - - private static final byte[] SRVLOC_DA = { (byte) 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, (byte) 0x23 }; - - private static final byte[] SRV_RQST = { (byte) 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0 }; - - /** - * getSrvLocAddress - * - * @param pScope - * @return InetAddress - * @throws UnknownHostException - */ - public static InetAddress getSrvLocAddress(int pScope) throws UnknownHostException { - SRVLOC[1] = (byte) (pScope & 0xff); - return InetAddress.getByAddress(SRVLOC); - } - - /** - * get - * - * @param pScope - * @param pMsg - * @return InetAddress - * @throws UnknownHostException - */ - public static InetAddress get(int pScope, SLPMessage pMsg) throws UnknownHostException { - if (pMsg instanceof ServiceTypeRequest || pMsg instanceof AttributeRequest) { return getSrvLocAddress(pScope); } - if (pMsg instanceof ServiceRequest) { - ServiceRequest srvRqst = (ServiceRequest) pMsg; - return get(pScope, srvRqst.getServiceType()); - } - throw new IllegalArgumentException("Cannot determine IPv6 multicast address for " - + pMsg.getClass().getName() + " !"); - } - - /** - * get - * - * @param pScope - * @param pSrvType - * @return InetAddress - * @throws UnknownHostException - */ - public static InetAddress get(int pScope, ServiceType pSrvType) throws UnknownHostException { - if (pSrvType.equals(SLPDefaults.DA_SERVICE_TYPE)) { - SRVLOC_DA[1] = (byte) (pScope & 0xff); - return InetAddress.getByAddress(SRVLOC_DA); - } - return get(pScope, getSrvTypeHash(pSrvType)); - } - - /** - * get - * - * @param pScope - * @param pSrvHash - * @return InetAddress - * @throws UnknownHostException - */ - public static InetAddress get(int pScope, int pSrvHash) throws UnknownHostException { - byte scope = (byte) (pScope & 0xff); - SRV_RQST[1] = scope; - SRV_RQST[14] = (byte) ((pSrvHash >> 8) & 0xff); - SRV_RQST[15] = (byte) (pSrvHash & 0xff); - return InetAddress.getByAddress(SRV_RQST); - } - - /** - *
      -	 *  unsigned long slp_hash(const char *pc, unsigned int len) {
      -	 *    unsigned long h = 0;
      -	 *    while (len-- != 0) {
      -	 *        h *= 33;
      -	 *        h += *pc++;
      -	 *    }
      -	 *    return (0x3FF & h); // round to a range of 0-1023
      -	 *   }
      -	 * 
      - * - * @param pServiceType - * @return int - */ - public static int getSrvTypeHash(ServiceType pServiceType) { - if (pServiceType == null) return 0x1000; - String typeStr = pServiceType.toString(); - int hash = 0; - for (int i = 0; i < typeStr.length(); i++) { - hash *= 33; - hash += typeStr.charAt(i); - } - return (0x3ff & hash) + 0x1000; - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.slp.internal; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.net.InetAddress; +import java.net.UnknownHostException; +import org.metricshub.wbem.sblim.slp.ServiceType; +import org.metricshub.wbem.sblim.slp.internal.msg.AttributeRequest; +import org.metricshub.wbem.sblim.slp.internal.msg.SLPMessage; +import org.metricshub.wbem.sblim.slp.internal.msg.ServiceRequest; +import org.metricshub.wbem.sblim.slp.internal.msg.ServiceTypeRequest; + +/** + *
      + * SVRLOC group-id : FF0X:0:0:0:0:0:0:116
      + *  - SRVTYPERQST Service Type Request
      + *  - ATTRRQST Attribute Request
      + *  - UA sends too
      + *
      + * SVRLOC-DA group-id : FF0X:0:0:0:0:0:0:123
      + *  - SRVRQST for the "service:directory-agent" service type
      + *  - UA sends too
      + *
      + * 1000 - 13FF: SRVRQST : FF0X:0:0:0:0:0:1:....
      + *  - the ID is the hashcode of the Service Type string used in the SrvRqst.
      + *  - UA sends too
      + * 
      + */ +public class IPv6MulticastAddressFactory { + private static final byte[] SRVLOC = { (byte) 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, (byte) 0x16 }; + + private static final byte[] SRVLOC_DA = { (byte) 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, (byte) 0x23 }; + + private static final byte[] SRV_RQST = { (byte) 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }; + + /** + * getSrvLocAddress + * + * @param pScope + * @return InetAddress + * @throws UnknownHostException + */ + public static InetAddress getSrvLocAddress(int pScope) throws UnknownHostException { + SRVLOC[1] = (byte) (pScope & 0xff); + return InetAddress.getByAddress(SRVLOC); + } + + /** + * get + * + * @param pScope + * @param pMsg + * @return InetAddress + * @throws UnknownHostException + */ + public static InetAddress get(int pScope, SLPMessage pMsg) throws UnknownHostException { + if (pMsg instanceof ServiceTypeRequest || pMsg instanceof AttributeRequest) { + return getSrvLocAddress(pScope); + } + if (pMsg instanceof ServiceRequest) { + ServiceRequest srvRqst = (ServiceRequest) pMsg; + return get(pScope, srvRqst.getServiceType()); + } + throw new IllegalArgumentException( + "Cannot determine IPv6 multicast address for " + pMsg.getClass().getName() + " !" + ); + } + + /** + * get + * + * @param pScope + * @param pSrvType + * @return InetAddress + * @throws UnknownHostException + */ + public static InetAddress get(int pScope, ServiceType pSrvType) throws UnknownHostException { + if (pSrvType.equals(SLPDefaults.DA_SERVICE_TYPE)) { + SRVLOC_DA[1] = (byte) (pScope & 0xff); + return InetAddress.getByAddress(SRVLOC_DA); + } + return get(pScope, getSrvTypeHash(pSrvType)); + } + + /** + * get + * + * @param pScope + * @param pSrvHash + * @return InetAddress + * @throws UnknownHostException + */ + public static InetAddress get(int pScope, int pSrvHash) throws UnknownHostException { + byte scope = (byte) (pScope & 0xff); + SRV_RQST[1] = scope; + SRV_RQST[14] = (byte) ((pSrvHash >> 8) & 0xff); + SRV_RQST[15] = (byte) (pSrvHash & 0xff); + return InetAddress.getByAddress(SRV_RQST); + } + + /** + *
      +	 *  unsigned long slp_hash(const char *pc, unsigned int len) {
      +	 *    unsigned long h = 0;
      +	 *    while (len-- != 0) {
      +	 *        h *= 33;
      +	 *        h += *pc++;
      +	 *    }
      +	 *    return (0x3FF & h); // round to a range of 0-1023
      +	 *   }
      +	 * 
      + * + * @param pServiceType + * @return int + */ + public static int getSrvTypeHash(ServiceType pServiceType) { + if (pServiceType == null) return 0x1000; + String typeStr = pServiceType.toString(); + int hash = 0; + for (int i = 0; i < typeStr.length(); i++) { + hash *= 33; + hash += typeStr.charAt(i); + } + return (0x3ff & hash) + 0x1000; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/Net.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/Net.java similarity index 71% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/Net.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/Net.java index fe99ac9..76c3edf 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/Net.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/Net.java @@ -1,108 +1,104 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.net.Inet4Address; -import java.net.Inet6Address; -import java.net.InetAddress; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.util.Enumeration; - -/** - * Net - * - */ -public class Net { - - private static boolean cHasV6, cHasV4; - - /** - * hasIPv6 - * - * @return boolean - */ - public static boolean hasIPv6() { - scan(); - return cHasV6; - } - - /** - * hasIPv4 - * - * @return boolean - */ - public static boolean hasIPv4() { - scan(); - return cHasV4; - } - - private static boolean cScanned; - - private static void scan() { - if (cScanned) return; - try { - cScanned = true; - Enumeration ifaceEnum = NetworkInterface.getNetworkInterfaces(); - ifLoop: while (ifaceEnum.hasMoreElements()) { - NetworkInterface iface = ifaceEnum.nextElement(); - Enumeration addrEnum = iface.getInetAddresses(); - while (addrEnum.hasMoreElements()) { - InetAddress addr = addrEnum.nextElement(); - if (addr instanceof Inet4Address) { - cHasV4 = true; - if (cHasV6) break ifLoop; - } else if (addr instanceof Inet6Address) { - cHasV6 = true; - if (cHasV4) break ifLoop; - } - } - } - TRC.info("available IP versions : IPv4:" + cHasV4 + ", IPv6:" + cHasV6); - } catch (SocketException e) { - TRC.error(e); - } - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp.internal; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.net.Inet4Address; +import java.net.Inet6Address; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.util.Enumeration; + +/** + * Net + * + */ +public class Net { + private static boolean cHasV6, cHasV4; + + /** + * hasIPv6 + * + * @return boolean + */ + public static boolean hasIPv6() { + scan(); + return cHasV6; + } + + /** + * hasIPv4 + * + * @return boolean + */ + public static boolean hasIPv4() { + scan(); + return cHasV4; + } + + private static boolean cScanned; + + private static void scan() { + if (cScanned) return; + try { + cScanned = true; + Enumeration ifaceEnum = NetworkInterface.getNetworkInterfaces(); + ifLoop:while (ifaceEnum.hasMoreElements()) { + NetworkInterface iface = ifaceEnum.nextElement(); + Enumeration addrEnum = iface.getInetAddresses(); + while (addrEnum.hasMoreElements()) { + InetAddress addr = addrEnum.nextElement(); + if (addr instanceof Inet4Address) { + cHasV4 = true; + if (cHasV6) break ifLoop; + } else if (addr instanceof Inet6Address) { + cHasV6 = true; + if (cHasV4) break ifLoop; + } + } + } + TRC.info("available IP versions : IPv4:" + cHasV4 + ", IPv6:" + cHasV6); + } catch (SocketException e) { + TRC.error(e); + } + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/SLPConfig.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/SLPConfig.java similarity index 79% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/SLPConfig.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/SLPConfig.java index 37dbc2b..bb1cc16 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/SLPConfig.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/SLPConfig.java @@ -1,616 +1,619 @@ -/* - SLPConfig.java - - (C) Copyright IBM Corp. 2005, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * Change History - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1516246 2006-07-22 lupusalex Integrate SLP client code - * 1535793 2006-09-14 lupusalex Fix&Integrate CIM&SLP configuration classes - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2414503 2008-12-10 raman_arora parseList not returning populated list - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2823494 2009-08-03 rgummada Change Boolean constructor to static - * 3026311 2010-07-07 blaschke-oss Vacuous comparison of integer value - * 3026360 2010-07-07 blaschke-oss Handle unwritten fields - */ - -package org.sentrysoftware.wbem.sblim.slp.internal; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.io.InputStream; -import java.net.InetAddress; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Properties; -import java.util.StringTokenizer; -import java.util.Map.Entry; -import java.util.logging.Level; - -import org.sentrysoftware.wbem.sblim.slp.SLPConfigProperties; - -/** - * SLPConfig - * - */ -public final class SLPConfig { - - private static InetAddress cBroadcastAddress; - - private static SLPConfig cInstance = null; - - private static InetAddress cLocalHostAddress; - - private static InetAddress cLoopBackV4; - - private static InetAddress cLoopBackV6; - - private static InetAddress cMulticastAddress; - - // SRVLOC_MulticastAddress requires scope (FF0s:0:0:0:0:0:0:116) - private static InetAddress cSRVLOC_MulticastAddress = null; - - // SRVLOC_DA_MulticastAddress requires scope (FF0s:0:0:0:0:0:0:123) - private static InetAddress cSRVLOC_DA_MulticastAddress = null; - - private static InetAddress getByName(String pName) { - try { - return InetAddress.getByName(pName); - } catch (UnknownHostException e) { - e.printStackTrace(); - return null; - } - } - - static { - cLoopBackV4 = getByName(SLPDefaults.LOOPBACK_ADDRESS_V4); - cLoopBackV6 = getByName(SLPDefaults.LOOPBACK_ADDRESS_V6); - cMulticastAddress = getByName(SLPDefaults.MULTICAST_ADDRESS); - cBroadcastAddress = getByName(SLPDefaults.BROADCAST_ADDRESS); - try { - cLocalHostAddress = InetAddress.getLocalHost(); - } catch (UnknownHostException e) { - e.printStackTrace(); - } - } - - /** - * getBroadcastAddress - * - * @return InetAddress - */ - public static InetAddress getBroadcastAddress() { - return cBroadcastAddress; - } - - /** - * getGlobalCfg - * - * @return SLPConfig - */ - public static synchronized SLPConfig getGlobalCfg() { - if (cInstance == null) { - cInstance = new SLPConfig(); - } - return cInstance; - } - - /** - * getLoopbackV4 - * - * @return InetAddress - */ - public static InetAddress getLoopbackV4() { - return cLoopBackV4; - } - - /** - * getLoopbackV6 - * - * @return InetAddress - */ - public static InetAddress getLoopbackV6() { - return cLoopBackV6; - } - - /** - * getMulticastAddress - * - * @return InetAddress - */ - public static InetAddress getMulticastAddress() { - return cMulticastAddress; - } - - /** - * getSRVLOC_MulticastAddress - * - * @return InetAddress - */ - public static InetAddress getSRVLOC_MulticastAddress() { - return cSRVLOC_MulticastAddress; - } - - /** - * getSRVLOC_DA_MulticastAddress - * - * @return InetAddress - */ - public static InetAddress getSRVLOC_DA_MulticastAddress() { - return cSRVLOC_DA_MulticastAddress; - } - - private static int getIntProperty(String pName, int pDefaultValue, int pMinValue, int pMaxValue) { - int value = Integer.getInteger(pName, pDefaultValue).intValue(); - return Math.min(pMaxValue, Math.max(pMinValue, value)); - } - - private SLPConfig() { - - try { - // try to load config class from CIM client. This will cause load of - // the CIM client's config file. - Class.forName("org.sblim.cimclient.internal.util.WBEMConfiguration"); - } catch (ClassNotFoundException e) { - // nothing to do - } - - Properties slpProperties = new Properties(new Properties()); - try { - InputStream inputstream = getConfigURLStream(); - if (inputstream != null) { - slpProperties.load(inputstream); - } - for (Iterator> iterator = slpProperties.entrySet().iterator(); iterator - .hasNext();) { - Entry entry = iterator.next(); - System - .setProperty(String.valueOf(entry.getKey()), String.valueOf(entry - .getValue())); - } - } catch (IOException e) { - System.out.println("Error while parsing property file"); - e.printStackTrace(); - } - } - - /** - * getActiveDiscoveryGranularity - * - * @return int - */ - public int getActiveDiscoveryGranularity() { - return getIntProperty(SLPConfigProperties.NET_SLP_DA_ACTIVE_DISCOVERY_GRANULARITY, - SLPDefaults.ACTIVE_DISCOVERY_GRANULARITY, SLPLimits.MIN_DISCOVERY_GRANULARITY, - SLPLimits.MAX_DISCOVERY_GRANULARITY); - } - - /** - * getActiveDiscoveryInterval - * - * @return int - */ - public int getActiveDiscoveryInterval() { - int interval = getIntProperty(SLPConfigProperties.NET_SLP_DA_ACTIVE_DISCOVERY_INTERVAL, - SLPDefaults.ACTIVE_DISCOVERY_INTERVAL, SLPLimits.MIN_DISCOVERY_INTERVAL, - SLPLimits.MAX_DISCOVERY_INTERVAL); // 3mins - if (interval > 0 && interval < 300) { return 300; - // prevent network flooding - } - return interval; - } - - /** - * getDADiscoveryTimeouts - * - * @return int[] - */ - public int[] getDADiscoveryTimeouts() { - return parseTimeouts(SLPConfigProperties.NET_SLP_DA_DISCOVERY_TIMEOUTS, - SLPDefaults.DA_DISCOVERY_TIMEOUTS); - } - - /** - * getDatagramTimeouts - * - * @return int[] - */ - public int[] getDatagramTimeouts() { - return parseTimeouts(SLPConfigProperties.NET_SLP_DATAGRAM_TIMEOUTS, - SLPDefaults.DATAGRAM_TIMEOUTS); - } - - /** - * getInterfaces - * - * @return List - */ - @SuppressWarnings("null") - public List getInterfaces() { - - String property = System.getProperty(SLPConfigProperties.NET_SLP_INTERFACES); - - List addresses = parseList(property); - - final int count = addresses == null ? 0 : addresses.size(); - List interfaces = new ArrayList(count); - - if (count == 0) { - interfaces.add(cLocalHostAddress); - interfaces.add(cLoopBackV4); - interfaces.add(cLoopBackV6); - } else { - for (int i = 0; i < count; ++i) { - String address = addresses.get(i); - try { - InetAddress inetAddress = InetAddress.getByName(address); - if (!interfaces.contains(inetAddress)) { - if (inetAddress.equals(cLocalHostAddress)) { - interfaces.add(0, inetAddress); - } else { - interfaces.add(inetAddress); - } - } - } catch (UnknownHostException e) { - // TODO log this - continue; - } - } - } - return interfaces; - } - - /** - * getPort - * - * @return int - */ - public int getPort() { - return Integer.getInteger(SLPConfigProperties.NET_SLP_PORT, SLPDefaults.SLP_PORT) - .intValue(); - } - - /** - * setPort - * - * @param pPort - */ - public void setPort(int pPort) { - System.setProperty(SLPConfigProperties.NET_SLP_PORT, Integer.toString(pPort)); - } - - /** - * getTraceLevel - * - * @return String - */ - public Level getTraceLevel() { - String str = System.getProperty(SLPConfigProperties.NET_SLP_TRC_LEVEL); - if ("OFF".equalsIgnoreCase(str)) return Level.OFF; - if ("ERROR".equalsIgnoreCase(str)) return Level.SEVERE; - if ("WARNING".equalsIgnoreCase(str)) return Level.WARNING; - if ("INFO".equalsIgnoreCase(str)) return Level.INFO; - if ("ALL".equalsIgnoreCase(str)) return Level.FINEST; - return Level.SEVERE; - } - - /** - * setTraceLevel - * - * @param pLevel - */ - public void setTraceLevel(String pLevel) { - System.setProperty(SLPConfigProperties.NET_SLP_TRC_LEVEL, pLevel); - } - - /** - * setUseIPv6 - * - * @param pValue - */ - public void setUseIPv6(boolean pValue) { - System.setProperty(SLPConfigProperties.NET_SLP_USEIPV6, Boolean.toString(pValue)); - } - - /** - * useIPv6 - * - * @return boolean - */ - public boolean useIPv6() { - return getBoolean(SLPConfigProperties.NET_SLP_USEIPV6, SLPDefaults.USE_IPV6); - } - - /** - * setUseIPv4 - * - * @param pValue - */ - public void setUseIPv4(boolean pValue) { - System.setProperty(SLPConfigProperties.NET_SLP_USEIPV4, Boolean.valueOf(pValue).toString()); - } - - /** - * useIPv4 - * - * @return boolean - */ - public boolean useIPv4() { - return getBoolean(SLPConfigProperties.NET_SLP_USEIPV4, SLPDefaults.USE_IPV4); - } - - /** - * getLocalHost - * - * @return InetAddress - */ - public InetAddress getLocalHost() { - List interfaces = getInterfaces(); - return interfaces.get(0); - } - - /** - * getMaximumResults - * - * @return int - */ - public int getMaximumResults() { - int value = Integer.getInteger(SLPConfigProperties.NET_SLP_MAX_RESULTS, - SLPDefaults.MAXIMUM_RESULTS).intValue(); - return (value >= 1 && value < SLPDefaults.MAXIMUM_RESULTS) ? value - : SLPDefaults.MAXIMUM_RESULTS; - } - - /** - * getMTU - * - * @return int - */ - public int getMTU() { - return getIntProperty(SLPConfigProperties.NET_SLP_MTU, SLPDefaults.MTU, SLPLimits.MIN_MTU, - SLPLimits.MAX_MTU); - } - - /** - * getMulticastMaximumWait - * - * @return int - */ - public int getMulticastMaximumWait() { - return getIntProperty(SLPConfigProperties.NET_SLP_MULTICAST_MAXIMUM_WAIT, - SLPDefaults.MULTICAST_MAXIMUM_WAIT, SLPLimits.MIN_MULTICAST_MAXIMUM_WAIT, - SLPLimits.MAX_MULTICAST_MAXIMUM_WAIT); - } - - /** - * getMulticastRadius - * - * @return int - */ - public int getMulticastRadius() { - return getIntProperty(SLPConfigProperties.NET_SLP_MULTICAST_TTL, - SLPDefaults.MULTICAST_RADIUS, SLPLimits.MIN_MULTICAST_RADIUS, - SLPLimits.MAX_MULTICAST_RADIUS); - } - - /** - * getMulticastTimeouts - * - * @return int[] - */ - public int[] getMulticastTimeouts() { - return parseTimeouts(SLPConfigProperties.NET_SLP_MULTICAST_TIMEOUTS, - SLPDefaults.MULTICAST_TIMEOUTS); - } - - /** - * getPreconfiguredDAs - * - * @return List <InetAddress> - */ - public List getPreconfiguredDAs() { - String addressString = System.getProperty(SLPConfigProperties.NET_SLP_DA_ADDRESSES, ""); - List addresses = parseList(addressString); - if (addresses == null) return null; - List result = new ArrayList(); - for (Iterator iter = addresses.iterator(); iter.hasNext();) { - try { - result.add(InetAddress.getByName(iter.next())); - } catch (UnknownHostException e) { - // TODO: log this - } - } - return result; - } - - /** - * getConfiguredScopes - * - * @return List<String> - */ - public List getConfiguredScopes() { - List scopes = parseList(SLPConfigProperties.NET_SLP_USE_SCOPES); - if (scopes == null) scopes = new ArrayList(); - if (scopes.size() == 0) scopes.add(SLPDefaults.DEFAULT_SCOPE); - return scopes; - } - - /** - * getSAOnlyScopes - * - * @return List<String> - */ - public List getSAOnlyScopes() { - return parseList(SLPConfigProperties.NET_SLP_SAONLY_SCOPES); - } - - /** - * getServerSocketQueueLength - * - * @return int - */ - public int getServerSocketQueueLength() { - return getIntProperty(SLPConfigProperties.NET_SLP_SERVER_SOCKET_QUEUE_LENGTH, - SLPDefaults.SERVER_SOCKET_QUEUE_LENGTH, SLPLimits.MIN_SERVER_SOCKET_QUEUE_LENGTH, - SLPLimits.MAX_SERVER_SOCKET_QUEUE_LENGTH); - } - - /** - * getTCPTimeout - * - * @return int - */ - public int getTCPTimeout() { - return getIntProperty(SLPConfigProperties.NET_SLP_TCPTIMEOUT, SLPDefaults.TCP_TIMEOUT, - SLPLimits.MIN_TCP_TIMEOUT, SLPLimits.MAX_TCP_TIMEOUT); - } - - /** - * getTraceMsg - * - * @return boolean - */ - public boolean getTraceMsg() { - return Boolean.getBoolean(SLPConfigProperties.NET_SLP_TRACE_MSG); - } - - /** - * isBroadcastOnly - * - * @return boolean - */ - public boolean isBroadcastOnly() { - return Boolean.getBoolean(SLPConfigProperties.NET_SLP_IS_BROADCAST_ONLY); - } - - /** - * isDA - * - * @return boolean - */ - public boolean isDA() { - return Boolean.getBoolean(SLPConfigProperties.NET_SLP_IS_DA); - } - - /** - * isSA - * - * @return boolean - */ - public boolean isSA() { - return !isDA(); - } - - private static boolean getBoolean(String pPropName, boolean pDefaultValue) { - if (System.getProperty(pPropName) == null) return pDefaultValue; - return Boolean.getBoolean(pPropName); - } - - private InputStream getConfigURLStream() { - - String configURL = System.getProperty(SLPConfigProperties.NET_SLP_CONFIG_URL); - - if (configURL != null) { - if (configURL.trim().length() > 0) { - try { - URL url = new URL(configURL); - InputStream inputstream = url.openStream(); - return inputstream; - } catch (MalformedURLException e) { - // TODO log this - } catch (IOException e) { - // TODO LOG this... config file not found - } - } - return null; - } - for (int i = 0; i < SLPDefaults.CONF_URLS.length; ++i) { - configURL = SLPDefaults.CONF_URLS[i]; - try { - URL url = new URL(configURL); - InputStream inputstream = url.openStream(); - return inputstream; - } catch (Exception e) { - // Nothing to do - } - } - return null; - } - - /** - * Parses comma separated list. - * - * @param pList - * @return List of Strings - */ - private static List parseList(String pListStr) { - if (pListStr == null || pListStr.length() == 0) return null; - // TODO - StringTokenizer tokenizer = new StringTokenizer(pListStr, ","); - if (tokenizer.countTokens() == 0) return null; - List list = new ArrayList(tokenizer.countTokens()); - while (tokenizer.hasMoreTokens()) { - String str = tokenizer.nextToken().trim(); - if (str.length() == 0) continue; - list.add(str); - } - return list.size() == 0 ? null : list; - } - - private int[] parseTimeouts(String pPropertyName, int[] pDefaultTimeouts) { - String value = System.getProperty(pPropertyName); - - List list = parseList(value); - if (list == null) return pDefaultTimeouts; - - int timeouts[] = new int[list.size()]; - for (int pos = 0; pos < list.size(); pos++) { - String timeoutElem = list.get(pos); - try { - timeouts[pos] = Integer.parseInt(timeoutElem); - } catch (NumberFormatException e) { - return pDefaultTimeouts; - } - } - return timeouts; - } -} +/* + SLPConfig.java + + (C) Copyright IBM Corp. 2005, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * Change History + * Flag Date Prog Description + * ------------------------------------------------------------------------------- + * 1516246 2006-07-22 lupusalex Integrate SLP client code + * 1535793 2006-09-14 lupusalex Fix&Integrate CIM&SLP configuration classes + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2414503 2008-12-10 raman_arora parseList not returning populated list + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2823494 2009-08-03 rgummada Change Boolean constructor to static + * 3026311 2010-07-07 blaschke-oss Vacuous comparison of integer value + * 3026360 2010-07-07 blaschke-oss Handle unwritten fields + */ + +package org.metricshub.wbem.sblim.slp.internal; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.io.InputStream; +import java.net.InetAddress; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.StringTokenizer; +import java.util.logging.Level; +import org.metricshub.wbem.sblim.slp.SLPConfigProperties; + +/** + * SLPConfig + * + */ +public final class SLPConfig { + private static InetAddress cBroadcastAddress; + + private static SLPConfig cInstance = null; + + private static InetAddress cLocalHostAddress; + + private static InetAddress cLoopBackV4; + + private static InetAddress cLoopBackV6; + + private static InetAddress cMulticastAddress; + + // SRVLOC_MulticastAddress requires scope (FF0s:0:0:0:0:0:0:116) + private static InetAddress cSRVLOC_MulticastAddress = null; + + // SRVLOC_DA_MulticastAddress requires scope (FF0s:0:0:0:0:0:0:123) + private static InetAddress cSRVLOC_DA_MulticastAddress = null; + + private static InetAddress getByName(String pName) { + try { + return InetAddress.getByName(pName); + } catch (UnknownHostException e) { + e.printStackTrace(); + return null; + } + } + + static { + cLoopBackV4 = getByName(SLPDefaults.LOOPBACK_ADDRESS_V4); + cLoopBackV6 = getByName(SLPDefaults.LOOPBACK_ADDRESS_V6); + cMulticastAddress = getByName(SLPDefaults.MULTICAST_ADDRESS); + cBroadcastAddress = getByName(SLPDefaults.BROADCAST_ADDRESS); + try { + cLocalHostAddress = InetAddress.getLocalHost(); + } catch (UnknownHostException e) { + e.printStackTrace(); + } + } + + /** + * getBroadcastAddress + * + * @return InetAddress + */ + public static InetAddress getBroadcastAddress() { + return cBroadcastAddress; + } + + /** + * getGlobalCfg + * + * @return SLPConfig + */ + public static synchronized SLPConfig getGlobalCfg() { + if (cInstance == null) { + cInstance = new SLPConfig(); + } + return cInstance; + } + + /** + * getLoopbackV4 + * + * @return InetAddress + */ + public static InetAddress getLoopbackV4() { + return cLoopBackV4; + } + + /** + * getLoopbackV6 + * + * @return InetAddress + */ + public static InetAddress getLoopbackV6() { + return cLoopBackV6; + } + + /** + * getMulticastAddress + * + * @return InetAddress + */ + public static InetAddress getMulticastAddress() { + return cMulticastAddress; + } + + /** + * getSRVLOC_MulticastAddress + * + * @return InetAddress + */ + public static InetAddress getSRVLOC_MulticastAddress() { + return cSRVLOC_MulticastAddress; + } + + /** + * getSRVLOC_DA_MulticastAddress + * + * @return InetAddress + */ + public static InetAddress getSRVLOC_DA_MulticastAddress() { + return cSRVLOC_DA_MulticastAddress; + } + + private static int getIntProperty(String pName, int pDefaultValue, int pMinValue, int pMaxValue) { + int value = Integer.getInteger(pName, pDefaultValue).intValue(); + return Math.min(pMaxValue, Math.max(pMinValue, value)); + } + + private SLPConfig() { + try { + // try to load config class from CIM client. This will cause load of + // the CIM client's config file. + Class.forName("org.sblim.cimclient.internal.util.WBEMConfiguration"); + } catch (ClassNotFoundException e) { + // nothing to do + } + + Properties slpProperties = new Properties(new Properties()); + try { + InputStream inputstream = getConfigURLStream(); + if (inputstream != null) { + slpProperties.load(inputstream); + } + for (Iterator> iterator = slpProperties.entrySet().iterator(); iterator.hasNext();) { + Entry entry = iterator.next(); + System.setProperty(String.valueOf(entry.getKey()), String.valueOf(entry.getValue())); + } + } catch (IOException e) { + System.out.println("Error while parsing property file"); + e.printStackTrace(); + } + } + + /** + * getActiveDiscoveryGranularity + * + * @return int + */ + public int getActiveDiscoveryGranularity() { + return getIntProperty( + SLPConfigProperties.NET_SLP_DA_ACTIVE_DISCOVERY_GRANULARITY, + SLPDefaults.ACTIVE_DISCOVERY_GRANULARITY, + SLPLimits.MIN_DISCOVERY_GRANULARITY, + SLPLimits.MAX_DISCOVERY_GRANULARITY + ); + } + + /** + * getActiveDiscoveryInterval + * + * @return int + */ + public int getActiveDiscoveryInterval() { + int interval = getIntProperty( + SLPConfigProperties.NET_SLP_DA_ACTIVE_DISCOVERY_INTERVAL, + SLPDefaults.ACTIVE_DISCOVERY_INTERVAL, + SLPLimits.MIN_DISCOVERY_INTERVAL, + SLPLimits.MAX_DISCOVERY_INTERVAL + ); // 3mins + if (interval > 0 && interval < 300) { + return 300; + // prevent network flooding + } + return interval; + } + + /** + * getDADiscoveryTimeouts + * + * @return int[] + */ + public int[] getDADiscoveryTimeouts() { + return parseTimeouts(SLPConfigProperties.NET_SLP_DA_DISCOVERY_TIMEOUTS, SLPDefaults.DA_DISCOVERY_TIMEOUTS); + } + + /** + * getDatagramTimeouts + * + * @return int[] + */ + public int[] getDatagramTimeouts() { + return parseTimeouts(SLPConfigProperties.NET_SLP_DATAGRAM_TIMEOUTS, SLPDefaults.DATAGRAM_TIMEOUTS); + } + + /** + * getInterfaces + * + * @return List + */ + @SuppressWarnings("null") + public List getInterfaces() { + String property = System.getProperty(SLPConfigProperties.NET_SLP_INTERFACES); + + List addresses = parseList(property); + + final int count = addresses == null ? 0 : addresses.size(); + List interfaces = new ArrayList(count); + + if (count == 0) { + interfaces.add(cLocalHostAddress); + interfaces.add(cLoopBackV4); + interfaces.add(cLoopBackV6); + } else { + for (int i = 0; i < count; ++i) { + String address = addresses.get(i); + try { + InetAddress inetAddress = InetAddress.getByName(address); + if (!interfaces.contains(inetAddress)) { + if (inetAddress.equals(cLocalHostAddress)) { + interfaces.add(0, inetAddress); + } else { + interfaces.add(inetAddress); + } + } + } catch (UnknownHostException e) { + // TODO log this + continue; + } + } + } + return interfaces; + } + + /** + * getPort + * + * @return int + */ + public int getPort() { + return Integer.getInteger(SLPConfigProperties.NET_SLP_PORT, SLPDefaults.SLP_PORT).intValue(); + } + + /** + * setPort + * + * @param pPort + */ + public void setPort(int pPort) { + System.setProperty(SLPConfigProperties.NET_SLP_PORT, Integer.toString(pPort)); + } + + /** + * getTraceLevel + * + * @return String + */ + public Level getTraceLevel() { + String str = System.getProperty(SLPConfigProperties.NET_SLP_TRC_LEVEL); + if ("OFF".equalsIgnoreCase(str)) return Level.OFF; + if ("ERROR".equalsIgnoreCase(str)) return Level.SEVERE; + if ("WARNING".equalsIgnoreCase(str)) return Level.WARNING; + if ("INFO".equalsIgnoreCase(str)) return Level.INFO; + if ("ALL".equalsIgnoreCase(str)) return Level.FINEST; + return Level.SEVERE; + } + + /** + * setTraceLevel + * + * @param pLevel + */ + public void setTraceLevel(String pLevel) { + System.setProperty(SLPConfigProperties.NET_SLP_TRC_LEVEL, pLevel); + } + + /** + * setUseIPv6 + * + * @param pValue + */ + public void setUseIPv6(boolean pValue) { + System.setProperty(SLPConfigProperties.NET_SLP_USEIPV6, Boolean.toString(pValue)); + } + + /** + * useIPv6 + * + * @return boolean + */ + public boolean useIPv6() { + return getBoolean(SLPConfigProperties.NET_SLP_USEIPV6, SLPDefaults.USE_IPV6); + } + + /** + * setUseIPv4 + * + * @param pValue + */ + public void setUseIPv4(boolean pValue) { + System.setProperty(SLPConfigProperties.NET_SLP_USEIPV4, Boolean.valueOf(pValue).toString()); + } + + /** + * useIPv4 + * + * @return boolean + */ + public boolean useIPv4() { + return getBoolean(SLPConfigProperties.NET_SLP_USEIPV4, SLPDefaults.USE_IPV4); + } + + /** + * getLocalHost + * + * @return InetAddress + */ + public InetAddress getLocalHost() { + List interfaces = getInterfaces(); + return interfaces.get(0); + } + + /** + * getMaximumResults + * + * @return int + */ + public int getMaximumResults() { + int value = Integer.getInteger(SLPConfigProperties.NET_SLP_MAX_RESULTS, SLPDefaults.MAXIMUM_RESULTS).intValue(); + return (value >= 1 && value < SLPDefaults.MAXIMUM_RESULTS) ? value : SLPDefaults.MAXIMUM_RESULTS; + } + + /** + * getMTU + * + * @return int + */ + public int getMTU() { + return getIntProperty(SLPConfigProperties.NET_SLP_MTU, SLPDefaults.MTU, SLPLimits.MIN_MTU, SLPLimits.MAX_MTU); + } + + /** + * getMulticastMaximumWait + * + * @return int + */ + public int getMulticastMaximumWait() { + return getIntProperty( + SLPConfigProperties.NET_SLP_MULTICAST_MAXIMUM_WAIT, + SLPDefaults.MULTICAST_MAXIMUM_WAIT, + SLPLimits.MIN_MULTICAST_MAXIMUM_WAIT, + SLPLimits.MAX_MULTICAST_MAXIMUM_WAIT + ); + } + + /** + * getMulticastRadius + * + * @return int + */ + public int getMulticastRadius() { + return getIntProperty( + SLPConfigProperties.NET_SLP_MULTICAST_TTL, + SLPDefaults.MULTICAST_RADIUS, + SLPLimits.MIN_MULTICAST_RADIUS, + SLPLimits.MAX_MULTICAST_RADIUS + ); + } + + /** + * getMulticastTimeouts + * + * @return int[] + */ + public int[] getMulticastTimeouts() { + return parseTimeouts(SLPConfigProperties.NET_SLP_MULTICAST_TIMEOUTS, SLPDefaults.MULTICAST_TIMEOUTS); + } + + /** + * getPreconfiguredDAs + * + * @return List <InetAddress> + */ + public List getPreconfiguredDAs() { + String addressString = System.getProperty(SLPConfigProperties.NET_SLP_DA_ADDRESSES, ""); + List addresses = parseList(addressString); + if (addresses == null) return null; + List result = new ArrayList(); + for (Iterator iter = addresses.iterator(); iter.hasNext();) { + try { + result.add(InetAddress.getByName(iter.next())); + } catch (UnknownHostException e) { + // TODO: log this + } + } + return result; + } + + /** + * getConfiguredScopes + * + * @return List<String> + */ + public List getConfiguredScopes() { + List scopes = parseList(SLPConfigProperties.NET_SLP_USE_SCOPES); + if (scopes == null) scopes = new ArrayList(); + if (scopes.size() == 0) scopes.add(SLPDefaults.DEFAULT_SCOPE); + return scopes; + } + + /** + * getSAOnlyScopes + * + * @return List<String> + */ + public List getSAOnlyScopes() { + return parseList(SLPConfigProperties.NET_SLP_SAONLY_SCOPES); + } + + /** + * getServerSocketQueueLength + * + * @return int + */ + public int getServerSocketQueueLength() { + return getIntProperty( + SLPConfigProperties.NET_SLP_SERVER_SOCKET_QUEUE_LENGTH, + SLPDefaults.SERVER_SOCKET_QUEUE_LENGTH, + SLPLimits.MIN_SERVER_SOCKET_QUEUE_LENGTH, + SLPLimits.MAX_SERVER_SOCKET_QUEUE_LENGTH + ); + } + + /** + * getTCPTimeout + * + * @return int + */ + public int getTCPTimeout() { + return getIntProperty( + SLPConfigProperties.NET_SLP_TCPTIMEOUT, + SLPDefaults.TCP_TIMEOUT, + SLPLimits.MIN_TCP_TIMEOUT, + SLPLimits.MAX_TCP_TIMEOUT + ); + } + + /** + * getTraceMsg + * + * @return boolean + */ + public boolean getTraceMsg() { + return Boolean.getBoolean(SLPConfigProperties.NET_SLP_TRACE_MSG); + } + + /** + * isBroadcastOnly + * + * @return boolean + */ + public boolean isBroadcastOnly() { + return Boolean.getBoolean(SLPConfigProperties.NET_SLP_IS_BROADCAST_ONLY); + } + + /** + * isDA + * + * @return boolean + */ + public boolean isDA() { + return Boolean.getBoolean(SLPConfigProperties.NET_SLP_IS_DA); + } + + /** + * isSA + * + * @return boolean + */ + public boolean isSA() { + return !isDA(); + } + + private static boolean getBoolean(String pPropName, boolean pDefaultValue) { + if (System.getProperty(pPropName) == null) return pDefaultValue; + return Boolean.getBoolean(pPropName); + } + + private InputStream getConfigURLStream() { + String configURL = System.getProperty(SLPConfigProperties.NET_SLP_CONFIG_URL); + + if (configURL != null) { + if (configURL.trim().length() > 0) { + try { + URL url = new URL(configURL); + InputStream inputstream = url.openStream(); + return inputstream; + } catch (MalformedURLException e) { + // TODO log this + } catch (IOException e) { + // TODO LOG this... config file not found + } + } + return null; + } + for (int i = 0; i < SLPDefaults.CONF_URLS.length; ++i) { + configURL = SLPDefaults.CONF_URLS[i]; + try { + URL url = new URL(configURL); + InputStream inputstream = url.openStream(); + return inputstream; + } catch (Exception e) { + // Nothing to do + } + } + return null; + } + + /** + * Parses comma separated list. + * + * @param pList + * @return List of Strings + */ + private static List parseList(String pListStr) { + if (pListStr == null || pListStr.length() == 0) return null; + // TODO + StringTokenizer tokenizer = new StringTokenizer(pListStr, ","); + if (tokenizer.countTokens() == 0) return null; + List list = new ArrayList(tokenizer.countTokens()); + while (tokenizer.hasMoreTokens()) { + String str = tokenizer.nextToken().trim(); + if (str.length() == 0) continue; + list.add(str); + } + return list.size() == 0 ? null : list; + } + + private int[] parseTimeouts(String pPropertyName, int[] pDefaultTimeouts) { + String value = System.getProperty(pPropertyName); + + List list = parseList(value); + if (list == null) return pDefaultTimeouts; + + int timeouts[] = new int[list.size()]; + for (int pos = 0; pos < list.size(); pos++) { + String timeoutElem = list.get(pos); + try { + timeouts[pos] = Integer.parseInt(timeoutElem); + } catch (NumberFormatException e) { + return pDefaultTimeouts; + } + } + return timeouts; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/SLPDefaults.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/SLPDefaults.java similarity index 76% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/SLPDefaults.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/SLPDefaults.java index ee1a589..eb270f1 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/SLPDefaults.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/SLPDefaults.java @@ -1,219 +1,215 @@ -/* - SLPDefaults.java - - (C) Copyright IBM Corp. 2005, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com - * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1516246 2006-07-22 lupusalex Integrate SLP client code - * 1535793 2006-09-14 lupusalex Fix&Integrate CIM&SLP configuration classes - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1911400 2008-03-10 blaschks-oss Source RPM file on SourceForge is broken - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Locale; - -import org.sentrysoftware.wbem.sblim.slp.ServiceType; - -/** - * SLPDefaults - * - */ -/** - * Class SLPDefaults is responsible for - * - */ -public interface SLPDefaults { - - /** - * ALL_AUTHORITIES - */ - public static final String ALL_AUTHORITIES = "*"; - - /** - * BROADCAST_ADDRESS - */ - public static final String BROADCAST_ADDRESS = "255.255.255.255"; - - /** - * CONF_URLS - */ - public static final String[] CONF_URLS = { - "file:sblim-slp-client2.properties", - "file:" + System.getProperty("user.home") + System.getProperty("file.separator") - + "sblim-slp-client2.properties", - "file:/etc/java/sblim-slp-client2.properties", "file:/etc/sblim-slp-client2.properties" }; - - /** - * DA_DISCOVERY_TIMEOUTS - */ - public static final int DA_DISCOVERY_TIMEOUTS[] = { 200, 200, 200, 200, 300, 400 }; - - /** - * DA_SERVICE_TYPE - */ - public static final ServiceType DA_SERVICE_TYPE = new ServiceType("service:directory-agent"); - - /** - * DATAGRAM_TIMEOUTS - */ - public static final int DATAGRAM_TIMEOUTS[] = { 100, 200, 300 }; - - /** - * DEFAULT_SCOPE - */ - public static final String DEFAULT_SCOPE = "default"; - - /** - * ACTIVE_DISCOVERY_GRANULARITY - */ - public static final int ACTIVE_DISCOVERY_GRANULARITY = 900; - - /** - * ACTIVE_DISCOVERY_INTERVAL - */ - public static final int ACTIVE_DISCOVERY_INTERVAL = 900; - - /** - * LOCALE - */ - public static final Locale LOCALE = new Locale("en", ""); - - /** - * LOG_FILE - */ - public static final String LOG_FILE = "slp.log"; - - /** - * LOOPBACK_ADDRESS_V4 - */ - public static final String LOOPBACK_ADDRESS_V4 = "127.0.0.1"; - - /** - * LOOPBACK_ADDRESS_V6 - */ - public static final String LOOPBACK_ADDRESS_V6 = "::1"; - - /** - * LOOPBACK_NAME - */ - public static final String LOOPBACK_NAME = "localhost"; - - /** - * MAXIMUM_RESULTS - */ - public static final int MAXIMUM_RESULTS = 0x7fffffff; - - /** - * MTU - */ - public static final int MTU = 1400; - - /** - * MULTICAST_ADDRESS - */ - public static final String MULTICAST_ADDRESS = "239.255.255.253"; - - /** - * MULTICAST_MAXIMUM_WAIT - */ - public static final int MULTICAST_MAXIMUM_WAIT = 2000; - - /** - * MULTICAST_RADIUS - */ - public static final int MULTICAST_RADIUS = 255; - - /** - * MULTICAST_TIMEOUTS - */ - public static final int MULTICAST_TIMEOUTS[] = { 200, 200, 200, 200, 300, 400 }; - - /** - * SA_SERVICE_TYPE - */ - public static final ServiceType SA_SERVICE_TYPE = new ServiceType("service:service-agent"); - - /** - * SERVER_SOCKET_QUEUE_LENGTH - */ - public static final int SERVER_SOCKET_QUEUE_LENGTH = 10; - - /** - * SLP_PORT - */ - public static final int SLP_PORT = 427; - - /** - * USE_IPV6 - */ - public static final boolean USE_IPV6 = true; - - /** - * USE_IPV4 - */ - public static final boolean USE_IPV4 = true; - - /** - * SLP_VERSION - */ - public static final int SLP_VERSION = 2; - - /** - * TCP_TIMEOUT - */ - public static final int TCP_TIMEOUT = 20000; - - /** - * ENCODING - */ - public static final String ENCODING = "UTF-8"; - - /** - * DA list is rediscovered if DACACHE_TIMEOUT (seconds) is elapsed. - */ - public static final int DACACHE_TIMEOUT = 90; - - /** - * IPV6_MULTICAST_SCOPE - */ - public static final int IPV6_MULTICAST_SCOPE = 5; - -} +/* + SLPDefaults.java + + (C) Copyright IBM Corp. 2005, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com + * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1516246 2006-07-22 lupusalex Integrate SLP client code + * 1535793 2006-09-14 lupusalex Fix&Integrate CIM&SLP configuration classes + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1911400 2008-03-10 blaschks-oss Source RPM file on SourceForge is broken + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.slp.internal; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Locale; +import org.metricshub.wbem.sblim.slp.ServiceType; + +/** + * SLPDefaults + * + */ +/** + * Class SLPDefaults is responsible for + * + */ +public interface SLPDefaults { + /** + * ALL_AUTHORITIES + */ + public static final String ALL_AUTHORITIES = "*"; + + /** + * BROADCAST_ADDRESS + */ + public static final String BROADCAST_ADDRESS = "255.255.255.255"; + + /** + * CONF_URLS + */ + public static final String[] CONF_URLS = { + "file:sblim-slp-client2.properties", + "file:" + System.getProperty("user.home") + System.getProperty("file.separator") + "sblim-slp-client2.properties", + "file:/etc/java/sblim-slp-client2.properties", + "file:/etc/sblim-slp-client2.properties" + }; + + /** + * DA_DISCOVERY_TIMEOUTS + */ + public static final int DA_DISCOVERY_TIMEOUTS[] = { 200, 200, 200, 200, 300, 400 }; + + /** + * DA_SERVICE_TYPE + */ + public static final ServiceType DA_SERVICE_TYPE = new ServiceType("service:directory-agent"); + + /** + * DATAGRAM_TIMEOUTS + */ + public static final int DATAGRAM_TIMEOUTS[] = { 100, 200, 300 }; + + /** + * DEFAULT_SCOPE + */ + public static final String DEFAULT_SCOPE = "default"; + + /** + * ACTIVE_DISCOVERY_GRANULARITY + */ + public static final int ACTIVE_DISCOVERY_GRANULARITY = 900; + + /** + * ACTIVE_DISCOVERY_INTERVAL + */ + public static final int ACTIVE_DISCOVERY_INTERVAL = 900; + + /** + * LOCALE + */ + public static final Locale LOCALE = new Locale("en", ""); + + /** + * LOG_FILE + */ + public static final String LOG_FILE = "slp.log"; + + /** + * LOOPBACK_ADDRESS_V4 + */ + public static final String LOOPBACK_ADDRESS_V4 = "127.0.0.1"; + + /** + * LOOPBACK_ADDRESS_V6 + */ + public static final String LOOPBACK_ADDRESS_V6 = "::1"; + + /** + * LOOPBACK_NAME + */ + public static final String LOOPBACK_NAME = "localhost"; + + /** + * MAXIMUM_RESULTS + */ + public static final int MAXIMUM_RESULTS = 0x7fffffff; + + /** + * MTU + */ + public static final int MTU = 1400; + + /** + * MULTICAST_ADDRESS + */ + public static final String MULTICAST_ADDRESS = "239.255.255.253"; + + /** + * MULTICAST_MAXIMUM_WAIT + */ + public static final int MULTICAST_MAXIMUM_WAIT = 2000; + + /** + * MULTICAST_RADIUS + */ + public static final int MULTICAST_RADIUS = 255; + + /** + * MULTICAST_TIMEOUTS + */ + public static final int MULTICAST_TIMEOUTS[] = { 200, 200, 200, 200, 300, 400 }; + + /** + * SA_SERVICE_TYPE + */ + public static final ServiceType SA_SERVICE_TYPE = new ServiceType("service:service-agent"); + + /** + * SERVER_SOCKET_QUEUE_LENGTH + */ + public static final int SERVER_SOCKET_QUEUE_LENGTH = 10; + + /** + * SLP_PORT + */ + public static final int SLP_PORT = 427; + + /** + * USE_IPV6 + */ + public static final boolean USE_IPV6 = true; + + /** + * USE_IPV4 + */ + public static final boolean USE_IPV4 = true; + + /** + * SLP_VERSION + */ + public static final int SLP_VERSION = 2; + + /** + * TCP_TIMEOUT + */ + public static final int TCP_TIMEOUT = 20000; + + /** + * ENCODING + */ + public static final String ENCODING = "UTF-8"; + + /** + * DA list is rediscovered if DACACHE_TIMEOUT (seconds) is elapsed. + */ + public static final int DACACHE_TIMEOUT = 90; + + /** + * IPV6_MULTICAST_SCOPE + */ + public static final int IPV6_MULTICAST_SCOPE = 5; +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/SLPLimits.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/SLPLimits.java similarity index 74% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/SLPLimits.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/SLPLimits.java index d915756..25f803a 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/SLPLimits.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/SLPLimits.java @@ -1,123 +1,119 @@ -/* - SLPLimits.java - - (C) Copyright IBM Corp. 2006, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Alexander Wolf-Reber, IBM a.wolf-reber@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1535793 2006-09-14 lupusalex Fix&Integrate CIM&SLP configuration classes - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2907527 2009-12-02 blaschke-oss Fix SLP properties issues - */ -package org.sentrysoftware.wbem.sblim.slp.internal; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * SLPLimits - * - */ -public interface SLPLimits { - - /** - * MAX_DISCOVERY_GRANULARITY - */ - public static final int MAX_DISCOVERY_GRANULARITY = 10800; - - /** - * MAX_DISCOVERY_INTERVAL - */ - public static final int MAX_DISCOVERY_INTERVAL = 3 * 60 * 60; // 3h - - /** - * MAX_MTU - */ - public static final int MAX_MTU = 8192; - - /** - * MAX_MULTICAST_MAXIMUM_WAIT - */ - public static final int MAX_MULTICAST_MAXIMUM_WAIT = 60000; - - /** - * MAX_MULTICAST_RADIUS - */ - public static final int MAX_MULTICAST_RADIUS = 255; - - /** - * MAX_SERVER_SOCKET_QUEUE_LENGTH - */ - public static final int MAX_SERVER_SOCKET_QUEUE_LENGTH = 0x7fffffff; - - /** - * MAX_TCP_TIMEOUT - */ - public static final int MAX_TCP_TIMEOUT = 360000; - - /** - * MIN_DISCOVERY_GRANULARITY - */ - public static final int MIN_DISCOVERY_GRANULARITY = 0; - - /** - * MIN_DISCOVERY_INTERVAL - */ - public static final int MIN_DISCOVERY_INTERVAL = 0; - - /** - * MIN_MTU - */ - public static final int MIN_MTU = 128; - - /** - * MIN_MULTICAST_MAXIMUM_WAIT - */ - public static final int MIN_MULTICAST_MAXIMUM_WAIT = 1000; - - /** - * MIN_MULTICAST_RADIUS - */ - public static final int MIN_MULTICAST_RADIUS = 1; - - /** - * MIN_SERVER_SOCKET_QUEUE_LENGTH - */ - public static final int MIN_SERVER_SOCKET_QUEUE_LENGTH = 0; - - /** - * MIN_TCP_TIMEOUT - */ - public static final int MIN_TCP_TIMEOUT = 100; - -} +/* + SLPLimits.java + + (C) Copyright IBM Corp. 2006, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Alexander Wolf-Reber, IBM a.wolf-reber@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1535793 2006-09-14 lupusalex Fix&Integrate CIM&SLP configuration classes + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2907527 2009-12-02 blaschke-oss Fix SLP properties issues + */ +package org.metricshub.wbem.sblim.slp.internal; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * SLPLimits + * + */ +public interface SLPLimits { + /** + * MAX_DISCOVERY_GRANULARITY + */ + public static final int MAX_DISCOVERY_GRANULARITY = 10800; + + /** + * MAX_DISCOVERY_INTERVAL + */ + public static final int MAX_DISCOVERY_INTERVAL = 3 * 60 * 60; // 3h + + /** + * MAX_MTU + */ + public static final int MAX_MTU = 8192; + + /** + * MAX_MULTICAST_MAXIMUM_WAIT + */ + public static final int MAX_MULTICAST_MAXIMUM_WAIT = 60000; + + /** + * MAX_MULTICAST_RADIUS + */ + public static final int MAX_MULTICAST_RADIUS = 255; + + /** + * MAX_SERVER_SOCKET_QUEUE_LENGTH + */ + public static final int MAX_SERVER_SOCKET_QUEUE_LENGTH = 0x7fffffff; + + /** + * MAX_TCP_TIMEOUT + */ + public static final int MAX_TCP_TIMEOUT = 360000; + + /** + * MIN_DISCOVERY_GRANULARITY + */ + public static final int MIN_DISCOVERY_GRANULARITY = 0; + + /** + * MIN_DISCOVERY_INTERVAL + */ + public static final int MIN_DISCOVERY_INTERVAL = 0; + + /** + * MIN_MTU + */ + public static final int MIN_MTU = 128; + + /** + * MIN_MULTICAST_MAXIMUM_WAIT + */ + public static final int MIN_MULTICAST_MAXIMUM_WAIT = 1000; + + /** + * MIN_MULTICAST_RADIUS + */ + public static final int MIN_MULTICAST_RADIUS = 1; + + /** + * MIN_SERVER_SOCKET_QUEUE_LENGTH + */ + public static final int MIN_SERVER_SOCKET_QUEUE_LENGTH = 0; + + /** + * MIN_TCP_TIMEOUT + */ + public static final int MIN_TCP_TIMEOUT = 100; +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/SLPString.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/SLPString.java similarity index 77% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/SLPString.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/SLPString.java index a8608c7..e592e5e 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/SLPString.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/SLPString.java @@ -1,121 +1,118 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - *
      - * This class provides functions for comparison of SLP message strings.
      - * 
      - * From RFC 2608:
      - * 
      - * String comparison for order and equality in SLP MUST be case
      - * insensitive inside the 0x00-0x7F subrange of UTF-8 (which corresponds
      - * to ASCII character encoding).  Case insensitivity SHOULD be supported
      - * throughout the entire UTF-8 encoded Unicode [6] character set.
      - * 
      - * The case insensitivity rule applies to all string matching in SLPv2,
      - * including Scope strings, SLP SPI strings, service types, attribute
      - * tags and values in query handling, language tags, previous responder
      - * lists.  Comparisons of URL strings, however, is case sensitive.
      - * 
      - * White space (SPACE, CR, LF, TAB) internal to a string value is folded
      - * to a single SPACE character for the sake of string comparisons.
      - * White space preceding or following a string value is ignored for the
      - * purposes of string comparison.  For example, "  Some String  "
      - * matches "SOME    STRING".
      - * 
      - */ - -public class SLPString { - - /** - * equals - * - * @param pStr0 - * @param pStr1 - * @return boolean - */ - public static boolean equals(String pStr0, String pStr1) { - if (pStr0 == null) return pStr1 == null; - if (pStr1 == null) return false; - return unify(pStr0).equals(unify(pStr1)); - } - - /** - * compare - * - * @param pStr0 - * @param pStr1 - * @return int - */ - public static int compare(String pStr0, String pStr1) { - return unify(pStr0).compareTo(unify(pStr1)); - } - - /** - * public for testing only. - * - * @param pStr - * @return String - */ - public static String unify(String pStr) { - if (pStr == null) return null; - StringBuffer resBuf = new StringBuffer(); - boolean inSpace = false; - for (int i = 0; i < pStr.length(); i++) { - char ch = pStr.charAt(i); - if (ch == ' ' || ch == '\t' || ch == 0xa || ch == 0xd) { - if (resBuf.length() == 0) continue; // skip front white spaces - inSpace = true; - } else { - if (inSpace) { - resBuf.append(' '); - inSpace = false; - } - resBuf.append(Character.toLowerCase(ch)); - } - } - return resBuf.toString(); - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.slp.internal; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + *
      + * This class provides functions for comparison of SLP message strings.
      + *
      + * From RFC 2608:
      + *
      + * String comparison for order and equality in SLP MUST be case
      + * insensitive inside the 0x00-0x7F subrange of UTF-8 (which corresponds
      + * to ASCII character encoding).  Case insensitivity SHOULD be supported
      + * throughout the entire UTF-8 encoded Unicode [6] character set.
      + *
      + * The case insensitivity rule applies to all string matching in SLPv2,
      + * including Scope strings, SLP SPI strings, service types, attribute
      + * tags and values in query handling, language tags, previous responder
      + * lists.  Comparisons of URL strings, however, is case sensitive.
      + *
      + * White space (SPACE, CR, LF, TAB) internal to a string value is folded
      + * to a single SPACE character for the sake of string comparisons.
      + * White space preceding or following a string value is ignored for the
      + * purposes of string comparison.  For example, "  Some String  "
      + * matches "SOME    STRING".
      + * 
      + */ + +public class SLPString { + + /** + * equals + * + * @param pStr0 + * @param pStr1 + * @return boolean + */ + public static boolean equals(String pStr0, String pStr1) { + if (pStr0 == null) return pStr1 == null; + if (pStr1 == null) return false; + return unify(pStr0).equals(unify(pStr1)); + } + + /** + * compare + * + * @param pStr0 + * @param pStr1 + * @return int + */ + public static int compare(String pStr0, String pStr1) { + return unify(pStr0).compareTo(unify(pStr1)); + } + + /** + * public for testing only. + * + * @param pStr + * @return String + */ + public static String unify(String pStr) { + if (pStr == null) return null; + StringBuffer resBuf = new StringBuffer(); + boolean inSpace = false; + for (int i = 0; i < pStr.length(); i++) { + char ch = pStr.charAt(i); + if (ch == ' ' || ch == '\t' || ch == 0xa || ch == 0xd) { + if (resBuf.length() == 0) continue; // skip front white spaces + inSpace = true; + } else { + if (inSpace) { + resBuf.append(' '); + inSpace = false; + } + resBuf.append(Character.toLowerCase(ch)); + } + } + return resBuf.toString(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/TRC.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/TRC.java similarity index 77% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/TRC.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/TRC.java index 85cafcc..f8364a6 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/TRC.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/TRC.java @@ -1,303 +1,314 @@ -/* - (C) Copyright IBM Corp. 2007, 2011 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1892103 2008-02-12 ebak SLP improvements - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues - */ - -package org.sentrysoftware.wbem.sblim.slp.internal; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.OutputStream; -import java.io.PrintStream; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.Calendar; -import java.util.Date; -import java.util.logging.Level; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; - -/** - * debug -> FINEST info -> INFO warning -> WARNING error -> SEVERE - * - */ -public class TRC { - - private static PrintStream cOut; - - private static Level cLevel = SLPConfig.getGlobalCfg().getTraceLevel(); - - private static LogAndTraceBroker cLogger = LogAndTraceBroker.getBroker(); - - private static Pattern[] cDenyPatterns; - - private static Pattern[] cAllowPatterns; - - private static final String NAME = new TRC().getClass().getName(); - - /** - * setLevel - * - * @param pLevel - */ - public static void setLevel(Level pLevel) { - cLevel = pLevel; - } - - /** - * setConsolLog - * - * @param pOutStr - */ - public static void setOutput(OutputStream pOutStr) { - setOutput(new PrintStream(pOutStr)); - } - - /** - * setOutputStream - * - * @param pOutStr - */ - public static void setOutput(PrintStream pOutStr) { - cOut = pOutStr; - } - - /** - * setPatterns - * - * @param pDenyPatterns - * @param pAllowPatterns - */ - public static void setPatterns(String[] pDenyPatterns, String[] pAllowPatterns) { - cDenyPatterns = compile(pDenyPatterns); - cAllowPatterns = compile(pAllowPatterns); - } - - private static Pattern[] compile(String[] pStrs) { - if (pStrs == null) return null; - Pattern[] patterns = new Pattern[pStrs.length]; - for (int i = 0; i < patterns.length; i++) { - patterns[i] = Pattern.compile(pStrs[i]); - } - return patterns; - } - - /** - * debug - * - * @param pMsg - */ - public static void debug(String pMsg) { - debug(pMsg, null); - } - - /** - * debug - * - * @param pMsg - * @param pEx - */ - public static void debug(String pMsg, Exception pEx) { - if (cLevel.intValue() > Level.FINEST.intValue()) return; - trace(Level.FINEST, pMsg, pEx); - } - - /** - * info - * - * @param pMsg - */ - public static void info(String pMsg) { - info(pMsg, null); - } - - /** - * info - * - * @param pMsg - * @param pEx - */ - public static void info(String pMsg, Exception pEx) { - if (cLevel.intValue() > Level.INFO.intValue()) return; - trace(Level.INFO, pMsg, pEx); - } - - /** - * warning - * - * @param pMsg - */ - public static void warning(String pMsg) { - warning(pMsg, null); - } - - /** - * warning - * - * @param pMsg - * @param pEx - */ - public static void warning(String pMsg, Exception pEx) { - if (cLevel.intValue() > Level.WARNING.intValue()) return; - trace(Level.WARNING, pMsg, pEx); - } - - /** - * error - * - * @param pMsg - */ - public static void error(String pMsg) { - error(pMsg, null); - } - - /** - * error - * - * @param pEx - */ - public static void error(Exception pEx) { - error(null, pEx); - } - - /** - * error - * - * @param pMsg - * @param pEx - */ - public static void error(String pMsg, Exception pEx) { - if (cLevel.intValue() > Level.SEVERE.intValue()) return; - trace(Level.SEVERE, pMsg, pEx); - } - - private static boolean hasMatch(Pattern[] pPatterns, String pStr) { - if (pPatterns == null) return false; - for (int i = 0; i < pPatterns.length; i++) { - Pattern pattern = pPatterns[i]; - Matcher m = pattern.matcher(pStr); - if (m.matches()) return true; - } - return false; - } - - private static boolean deny(String pFnStr) { - return hasMatch(cDenyPatterns, pFnStr); - } - - private static boolean allow(String pFnStr) { - return hasMatch(cAllowPatterns, pFnStr); - } - - private static void trace(Level pLevel, String pMsg, Exception pEx) { - StackTraceElement location = getLocation(); - String fnStr = getFunctionStr(location); - if (deny(fnStr) && !allow(fnStr)) return; - StringBuffer buf = new StringBuffer('[' + pLevel.toString() + ' ' - + Thread.currentThread().getName() + ' ' + getDate() + ' ' - + getLocationStr(location) + "]\n"); - if (pMsg != null) buf.append(pMsg + '\n'); - if (pEx != null) { - StringWriter writer = new StringWriter(); - pEx.printStackTrace(new PrintWriter(writer)); - buf.append(writer.toString() + '\n'); - } - synchronized (TRC.class) { - if (cOut != null) { - cOut.println(buf.toString()); - System.out.flush(); - } else { - cLogger.trace(pLevel, buf.toString()); - } - } - } - - private static StackTraceElement getLocation() { - Throwable thr = new Throwable(); - StackTraceElement[] elements = thr.getStackTrace(); - StackTraceElement e = null; - for (int i = 0; i < elements.length; i++) { - e = elements[i]; - if (!e.getClassName().equals(NAME)) return e; - } - return null; - } - - private static String getFunctionStr(StackTraceElement pSTE) { - return pSTE.getClassName() + '.' + pSTE.getMethodName(); - } - - private static String getLocationStr(StackTraceElement pSTE) { - return getFunctionStr(pSTE) + '(' + pSTE.getFileName() + ':' + pSTE.getLineNumber() + ')'; - } - - private static String pad(int pDigits, int pNum) { - String str = Integer.toString(pNum); - int len = Math.max(pDigits, str.length()); - char[] cA = new char[len]; - int paddingDigits = pDigits - str.length(); - int dIdx = 0; - while (dIdx < paddingDigits) - cA[dIdx++] = '0'; - int sIdx = 0; - while (dIdx < len) - cA[dIdx++] = str.charAt(sIdx++); - return new String(cA); - } - - /** - * getDate - * - * @return String - */ - private static String getDate() { - long millis = new Date().getTime(); - Calendar cal = Calendar.getInstance(); - cal.setTimeInMillis(millis); - return Integer.toString(cal.get(Calendar.YEAR)) + '.' + pad(2, cal.get(Calendar.MONTH) + 1) - + '.' + pad(2, cal.get(Calendar.DAY_OF_MONTH)) + ' ' - + pad(2, cal.get(Calendar.HOUR_OF_DAY)) + ':' + pad(2, cal.get(Calendar.MINUTE)) - + ':' + pad(2, cal.get(Calendar.SECOND)) + ' ' - + pad(3, cal.get(Calendar.MILLISECOND)); - } - -} +/* + (C) Copyright IBM Corp. 2007, 2011 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1892103 2008-02-12 ebak SLP improvements + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues + */ + +package org.metricshub.wbem.sblim.slp.internal; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.OutputStream; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Calendar; +import java.util.Date; +import java.util.logging.Level; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.metricshub.wbem.sblim.cimclient.internal.logging.LogAndTraceBroker; + +/** + * debug -> FINEST info -> INFO warning -> WARNING error -> SEVERE + * + */ +public class TRC { + private static PrintStream cOut; + + private static Level cLevel = SLPConfig.getGlobalCfg().getTraceLevel(); + + private static LogAndTraceBroker cLogger = LogAndTraceBroker.getBroker(); + + private static Pattern[] cDenyPatterns; + + private static Pattern[] cAllowPatterns; + + private static final String NAME = new TRC().getClass().getName(); + + /** + * setLevel + * + * @param pLevel + */ + public static void setLevel(Level pLevel) { + cLevel = pLevel; + } + + /** + * setConsolLog + * + * @param pOutStr + */ + public static void setOutput(OutputStream pOutStr) { + setOutput(new PrintStream(pOutStr)); + } + + /** + * setOutputStream + * + * @param pOutStr + */ + public static void setOutput(PrintStream pOutStr) { + cOut = pOutStr; + } + + /** + * setPatterns + * + * @param pDenyPatterns + * @param pAllowPatterns + */ + public static void setPatterns(String[] pDenyPatterns, String[] pAllowPatterns) { + cDenyPatterns = compile(pDenyPatterns); + cAllowPatterns = compile(pAllowPatterns); + } + + private static Pattern[] compile(String[] pStrs) { + if (pStrs == null) return null; + Pattern[] patterns = new Pattern[pStrs.length]; + for (int i = 0; i < patterns.length; i++) { + patterns[i] = Pattern.compile(pStrs[i]); + } + return patterns; + } + + /** + * debug + * + * @param pMsg + */ + public static void debug(String pMsg) { + debug(pMsg, null); + } + + /** + * debug + * + * @param pMsg + * @param pEx + */ + public static void debug(String pMsg, Exception pEx) { + if (cLevel.intValue() > Level.FINEST.intValue()) return; + trace(Level.FINEST, pMsg, pEx); + } + + /** + * info + * + * @param pMsg + */ + public static void info(String pMsg) { + info(pMsg, null); + } + + /** + * info + * + * @param pMsg + * @param pEx + */ + public static void info(String pMsg, Exception pEx) { + if (cLevel.intValue() > Level.INFO.intValue()) return; + trace(Level.INFO, pMsg, pEx); + } + + /** + * warning + * + * @param pMsg + */ + public static void warning(String pMsg) { + warning(pMsg, null); + } + + /** + * warning + * + * @param pMsg + * @param pEx + */ + public static void warning(String pMsg, Exception pEx) { + if (cLevel.intValue() > Level.WARNING.intValue()) return; + trace(Level.WARNING, pMsg, pEx); + } + + /** + * error + * + * @param pMsg + */ + public static void error(String pMsg) { + error(pMsg, null); + } + + /** + * error + * + * @param pEx + */ + public static void error(Exception pEx) { + error(null, pEx); + } + + /** + * error + * + * @param pMsg + * @param pEx + */ + public static void error(String pMsg, Exception pEx) { + if (cLevel.intValue() > Level.SEVERE.intValue()) return; + trace(Level.SEVERE, pMsg, pEx); + } + + private static boolean hasMatch(Pattern[] pPatterns, String pStr) { + if (pPatterns == null) return false; + for (int i = 0; i < pPatterns.length; i++) { + Pattern pattern = pPatterns[i]; + Matcher m = pattern.matcher(pStr); + if (m.matches()) return true; + } + return false; + } + + private static boolean deny(String pFnStr) { + return hasMatch(cDenyPatterns, pFnStr); + } + + private static boolean allow(String pFnStr) { + return hasMatch(cAllowPatterns, pFnStr); + } + + private static void trace(Level pLevel, String pMsg, Exception pEx) { + StackTraceElement location = getLocation(); + String fnStr = getFunctionStr(location); + if (deny(fnStr) && !allow(fnStr)) return; + StringBuffer buf = new StringBuffer( + '[' + + pLevel.toString() + + ' ' + + Thread.currentThread().getName() + + ' ' + + getDate() + + ' ' + + getLocationStr(location) + + "]\n" + ); + if (pMsg != null) buf.append(pMsg + '\n'); + if (pEx != null) { + StringWriter writer = new StringWriter(); + pEx.printStackTrace(new PrintWriter(writer)); + buf.append(writer.toString() + '\n'); + } + synchronized (TRC.class) { + if (cOut != null) { + cOut.println(buf.toString()); + System.out.flush(); + } else { + cLogger.trace(pLevel, buf.toString()); + } + } + } + + private static StackTraceElement getLocation() { + Throwable thr = new Throwable(); + StackTraceElement[] elements = thr.getStackTrace(); + StackTraceElement e = null; + for (int i = 0; i < elements.length; i++) { + e = elements[i]; + if (!e.getClassName().equals(NAME)) return e; + } + return null; + } + + private static String getFunctionStr(StackTraceElement pSTE) { + return pSTE.getClassName() + '.' + pSTE.getMethodName(); + } + + private static String getLocationStr(StackTraceElement pSTE) { + return getFunctionStr(pSTE) + '(' + pSTE.getFileName() + ':' + pSTE.getLineNumber() + ')'; + } + + private static String pad(int pDigits, int pNum) { + String str = Integer.toString(pNum); + int len = Math.max(pDigits, str.length()); + char[] cA = new char[len]; + int paddingDigits = pDigits - str.length(); + int dIdx = 0; + while (dIdx < paddingDigits) cA[dIdx++] = '0'; + int sIdx = 0; + while (dIdx < len) cA[dIdx++] = str.charAt(sIdx++); + return new String(cA); + } + + /** + * getDate + * + * @return String + */ + private static String getDate() { + long millis = new Date().getTime(); + Calendar cal = Calendar.getInstance(); + cal.setTimeInMillis(millis); + return ( + Integer.toString(cal.get(Calendar.YEAR)) + + '.' + + pad(2, cal.get(Calendar.MONTH) + 1) + + '.' + + pad(2, cal.get(Calendar.DAY_OF_MONTH)) + + ' ' + + pad(2, cal.get(Calendar.HOUR_OF_DAY)) + + ':' + + pad(2, cal.get(Calendar.MINUTE)) + + ':' + + pad(2, cal.get(Calendar.SECOND)) + + ' ' + + pad(3, cal.get(Calendar.MILLISECOND)) + ); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/AttributeReply.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/AttributeReply.java similarity index 72% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/AttributeReply.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/AttributeReply.java index a0604f0..45832f4 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/AttributeReply.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/AttributeReply.java @@ -1,153 +1,147 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1892103 2008-02-12 ebak SLP improvements - * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.msg; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.util.Iterator; -import java.util.List; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationAttribute; -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; -import org.sentrysoftware.wbem.sblim.slp.internal.TRC; - -/* - * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service - * Location header (function = AttrRply = 7) | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Error - * Code | length of | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | - * \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |# of - * AttrAuths | Attribute Authentication Block (if present) \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * - */ - -/** - * AttributeReply message - * - */ -public class AttributeReply extends ReplyMessage { - - private List iAttrList; - - /** - * parse - * - * @param pHdr - * @param pInStr - * @return SLPMessage - * @throws ServiceLocationException - * @throws IOException - */ - public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException { - AttributeReply reply = new AttributeReply(pHdr, pInStr.read16(), pInStr.readAttributeList()); - if (pInStr.readAuthBlockList() != null) TRC.warning("Non empty auth block!"); - return reply; - } - - /** - * Ctor. - * - * @param pErrorCode - * @param pAttrList - * - list of ServiceLocationAttributes - */ - public AttributeReply(int pErrorCode, List pAttrList) { - super(ATTR_RPLY, pErrorCode); - this.iAttrList = pAttrList; - } - - /** - * Ctor. - * - * @param pLangTag - * @param pErrorCode - * @param pAttrList - * - list of ServiceLocationAttributes - */ - public AttributeReply(String pLangTag, int pErrorCode, List pAttrList) { - super(ATTR_RPLY, pLangTag, pErrorCode); - this.iAttrList = pAttrList; - } - - /** - * Ctor. - * - * @param pHeader - * @param pErrorCode - * @param pAttrList - * - list of ServiceLocationAttributes - */ - public AttributeReply(MsgHeader pHeader, int pErrorCode, - List pAttrList) { - super(pHeader, pErrorCode); - this.iAttrList = pAttrList; - } - - @Override - public Iterator getResultIterator() { - return this.iAttrList == null ? null : this.iAttrList.iterator(); - } - - /** - * @param pOption - */ - @Override - protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) { - return pOutStr.write16(getErrorCode()) && pOutStr.writeAttributeList(this.iAttrList) - && pOutStr.writeAuthBlockList(null); - } - - @Override - public Iterator getExceptionIterator() { - // this message doesn't have exception table - return null; - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1892103 2008-02-12 ebak SLP improvements + * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp.internal.msg; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.util.Iterator; +import java.util.List; +import org.metricshub.wbem.sblim.slp.ServiceLocationAttribute; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; +import org.metricshub.wbem.sblim.slp.internal.TRC; + +/* + * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service + * Location header (function = AttrRply = 7) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Error + * Code | length of | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | + * \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |# of + * AttrAuths | Attribute Authentication Block (if present) \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * + */ + +/** + * AttributeReply message + * + */ +public class AttributeReply extends ReplyMessage { + private List iAttrList; + + /** + * parse + * + * @param pHdr + * @param pInStr + * @return SLPMessage + * @throws ServiceLocationException + * @throws IOException + */ + public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { + AttributeReply reply = new AttributeReply(pHdr, pInStr.read16(), pInStr.readAttributeList()); + if (pInStr.readAuthBlockList() != null) TRC.warning("Non empty auth block!"); + return reply; + } + + /** + * Ctor. + * + * @param pErrorCode + * @param pAttrList + * - list of ServiceLocationAttributes + */ + public AttributeReply(int pErrorCode, List pAttrList) { + super(ATTR_RPLY, pErrorCode); + this.iAttrList = pAttrList; + } + + /** + * Ctor. + * + * @param pLangTag + * @param pErrorCode + * @param pAttrList + * - list of ServiceLocationAttributes + */ + public AttributeReply(String pLangTag, int pErrorCode, List pAttrList) { + super(ATTR_RPLY, pLangTag, pErrorCode); + this.iAttrList = pAttrList; + } + + /** + * Ctor. + * + * @param pHeader + * @param pErrorCode + * @param pAttrList + * - list of ServiceLocationAttributes + */ + public AttributeReply(MsgHeader pHeader, int pErrorCode, List pAttrList) { + super(pHeader, pErrorCode); + this.iAttrList = pAttrList; + } + + @Override + public Iterator getResultIterator() { + return this.iAttrList == null ? null : this.iAttrList.iterator(); + } + + /** + * @param pOption + */ + @Override + protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) { + return ( + pOutStr.write16(getErrorCode()) && pOutStr.writeAttributeList(this.iAttrList) && pOutStr.writeAuthBlockList(null) + ); + } + + @Override + public Iterator getExceptionIterator() { + // this message doesn't have exception table + return null; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/AttributeRequest.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/AttributeRequest.java similarity index 66% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/AttributeRequest.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/AttributeRequest.java index 448bdb0..35ee7bf 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/AttributeRequest.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/AttributeRequest.java @@ -1,178 +1,199 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1892103 2008-02-15 ebak SLP improvements - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.msg; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.util.List; -import java.util.SortedSet; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; -import org.sentrysoftware.wbem.sblim.slp.ServiceURL; - -/* - * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service - * Location header (function = AttrRqst = 6) | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of - * PRList | String \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of - * URL | URL \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | - * length of | string \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of - * string | string \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of - * string | string \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - -/** - * AttributeRequest message - * - */ -public class AttributeRequest extends RequestMessage { - - private String iURLStr; - - private List iTagList; - - private List iSPIList; - - private static final int[] ALLOWED_RSPS = { ATTR_RPLY }; - - /** - * parse - * - * @param pHdr - * @param pInStr - * @return SLPMessage - * @throws ServiceLocationException - * @throws IOException - */ - public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException { - return new AttributeRequest(pHdr, pInStr.readStringSet(), pInStr.readString(), pInStr - .readStringList(), pInStr.readStringList(), pInStr.readStringList()); - } - - /** - * Ctor. - * - * @param pPrevResponderSet - * - set of address strings - * @param pURLStr - * @param pScopeList - * - list of scope strings - * @param pTagList - * @param pSPIList - */ - public AttributeRequest(SortedSet pPrevResponderSet, String pURLStr, - List pScopeList, List pTagList, List pSPIList) { - super(ATTR_RQST, pPrevResponderSet, pScopeList); - init(pURLStr, pTagList, pSPIList); - } - - /** - * Ctor. - * - * @param pLangTag - * @param pPrevResponderSet - * - set of address strings - * @param pURLStr - * @param pScopeList - * - list of scope strings - * @param pTagList - * @param pSPIList - */ - public AttributeRequest(String pLangTag, SortedSet pPrevResponderSet, String pURLStr, - List pScopeList, List pTagList, List pSPIList) { - super(ATTR_RQST, pLangTag, pPrevResponderSet, pScopeList); - init(pURLStr, pTagList, pSPIList); - } - - /** - * Ctor. - * - * @param pHeader - * @param pPrevResponderSet - * - set of address strings - * @param pURLStr - * @param pScopeList - * - list of scope strings - * @param pTagList - * @param pSPIList - */ - public AttributeRequest(MsgHeader pHeader, SortedSet pPrevResponderSet, String pURLStr, - List pScopeList, List pTagList, List pSPIList) { - super(pHeader, pPrevResponderSet, pScopeList); - init(pURLStr, pTagList, pSPIList); - } - - /** - * getServiceURL - * - * @return ServiceURL - */ - public ServiceURL getServiceURL() { - return new ServiceURL(this.iURLStr, 65535); - } - - @Override - protected boolean serializeRequestBody(SLPOutputStream pOutStr) { - return pOutStr.write(this.iURLStr) && pOutStr.writeStringList(getScopeList()) - && pOutStr.writeStringList(this.iTagList) && pOutStr.writeStringList(this.iSPIList); - } - - @Override - protected int[] getAllowedResponseIDs() { - return ALLOWED_RSPS; - } - - private void init(String pURLStr, List pTagList, List pSPIList) { - this.iURLStr = pURLStr; - this.iTagList = pTagList; - this.iSPIList = pSPIList; - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1892103 2008-02-15 ebak SLP improvements + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp.internal.msg; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.util.List; +import java.util.SortedSet; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; +import org.metricshub.wbem.sblim.slp.ServiceURL; + +/* + * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service + * Location header (function = AttrRqst = 6) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of + * PRList | String \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of + * URL | URL \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | + * length of | string \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of + * string | string \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of + * string | string \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + +/** + * AttributeRequest message + * + */ +public class AttributeRequest extends RequestMessage { + private String iURLStr; + + private List iTagList; + + private List iSPIList; + + private static final int[] ALLOWED_RSPS = { ATTR_RPLY }; + + /** + * parse + * + * @param pHdr + * @param pInStr + * @return SLPMessage + * @throws ServiceLocationException + * @throws IOException + */ + public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { + return new AttributeRequest( + pHdr, + pInStr.readStringSet(), + pInStr.readString(), + pInStr.readStringList(), + pInStr.readStringList(), + pInStr.readStringList() + ); + } + + /** + * Ctor. + * + * @param pPrevResponderSet + * - set of address strings + * @param pURLStr + * @param pScopeList + * - list of scope strings + * @param pTagList + * @param pSPIList + */ + public AttributeRequest( + SortedSet pPrevResponderSet, + String pURLStr, + List pScopeList, + List pTagList, + List pSPIList + ) { + super(ATTR_RQST, pPrevResponderSet, pScopeList); + init(pURLStr, pTagList, pSPIList); + } + + /** + * Ctor. + * + * @param pLangTag + * @param pPrevResponderSet + * - set of address strings + * @param pURLStr + * @param pScopeList + * - list of scope strings + * @param pTagList + * @param pSPIList + */ + public AttributeRequest( + String pLangTag, + SortedSet pPrevResponderSet, + String pURLStr, + List pScopeList, + List pTagList, + List pSPIList + ) { + super(ATTR_RQST, pLangTag, pPrevResponderSet, pScopeList); + init(pURLStr, pTagList, pSPIList); + } + + /** + * Ctor. + * + * @param pHeader + * @param pPrevResponderSet + * - set of address strings + * @param pURLStr + * @param pScopeList + * - list of scope strings + * @param pTagList + * @param pSPIList + */ + public AttributeRequest( + MsgHeader pHeader, + SortedSet pPrevResponderSet, + String pURLStr, + List pScopeList, + List pTagList, + List pSPIList + ) { + super(pHeader, pPrevResponderSet, pScopeList); + init(pURLStr, pTagList, pSPIList); + } + + /** + * getServiceURL + * + * @return ServiceURL + */ + public ServiceURL getServiceURL() { + return new ServiceURL(this.iURLStr, 65535); + } + + @Override + protected boolean serializeRequestBody(SLPOutputStream pOutStr) { + return ( + pOutStr.write(this.iURLStr) && + pOutStr.writeStringList(getScopeList()) && + pOutStr.writeStringList(this.iTagList) && + pOutStr.writeStringList(this.iSPIList) + ); + } + + @Override + protected int[] getAllowedResponseIDs() { + return ALLOWED_RSPS; + } + + private void init(String pURLStr, List pTagList, List pSPIList) { + this.iURLStr = pURLStr; + this.iTagList = pTagList; + this.iSPIList = pSPIList; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/DAAdvert.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/DAAdvert.java similarity index 67% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/DAAdvert.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/DAAdvert.java index 34e5cd4..a55c4f7 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/DAAdvert.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/DAAdvert.java @@ -1,203 +1,232 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1892103 2008-02-12 ebak SLP improvements - * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.msg; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.TreeSet; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationAttribute; -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; - -/* - * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service - * Location header (function = DAAdvert = 8) | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Error - * Code | DA Stateless Boot Timestamp | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |DA - * Stateless Boot Time,, contd.| Length of URL | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ \ URL \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of - * | \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of - * | \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of - * | String \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | # Auth - * Blocks | Authentication block (if any) \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ FIXME: is - * this URL an URL-entry or an URL String. Assuming URL String. - */ - -/** - * DAAdvert message - * - */ -public class DAAdvert extends ReplyMessage { - - private long iStatelessBootTime; - - private String iURLStr; - - private List iScopeList; - - private List iAttrList; - - private List iSPIList; - - /** - * parse - * - * @param pHdr - * @param pInStr - * @return SLPMessage - * @throws ServiceLocationException - * @throws IOException - */ - public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException { - return new DAAdvert(pHdr, pInStr.read16(), pInStr.read32(), pInStr.readString(), pInStr - .readStringList(), pInStr.readAttributeList(), pInStr.readStringList()); - } - - /** - * Ctor. - * - * @param pErrorCode - * @param pStatelessBootTime - * @param pURLStr - * @param pScopeList - * - list of scope strings - * @param pAttrList - * - list of ServiceLocationAttributes - * @param pSPIList - */ - public DAAdvert(int pErrorCode, long pStatelessBootTime, String pURLStr, - List pScopeList, List pAttrList, List pSPIList) { - super(DA_ADVERT, pErrorCode); - init(pStatelessBootTime, pURLStr, pScopeList, pAttrList, pSPIList); - } - - /** - * Ctor. - * - * @param pLangTag - * @param pErrorCode - * @param pStatelessBootTime - * @param pURLStr - * @param pScopeList - * - list of scope strings - * @param pAttrList - * - list of ServiceLocationAttributes - * @param pSPIList - */ - public DAAdvert(String pLangTag, int pErrorCode, long pStatelessBootTime, String pURLStr, - List pScopeList, List pAttrList, List pSPIList) { - super(DA_ADVERT, pLangTag, pErrorCode); - init(pStatelessBootTime, pURLStr, pScopeList, pAttrList, pSPIList); - } - - /** - * Ctor. - * - * @param pHeader - * @param pErrorCode - * @param pStatelessBootTime - * @param pURLStr - * @param pScopeList - * - list of scope strings - * @param pAttrList - * - list of ServiceLocationAttributes - * @param pSPIList - */ - public DAAdvert(MsgHeader pHeader, int pErrorCode, long pStatelessBootTime, String pURLStr, - List pScopeList, List pAttrList, List pSPIList) { - super(pHeader, pErrorCode); - init(pStatelessBootTime, pURLStr, pScopeList, pAttrList, pSPIList); - } - - /** - * @return Iterator of DADescriptors - * @see ReplyMessage#getResultIterator() - */ - @Override - public Iterator getResultIterator() { - ArrayList list = new ArrayList(1); - list.add(new DADescriptor(this.iURLStr, new TreeSet(this.iScopeList), - this.iAttrList)); - return list.iterator(); - } - - /** - * @param pOption - */ - @Override - protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) { - return pOutStr.write16(getErrorCode()) && pOutStr.write32(this.iStatelessBootTime) - && pOutStr.write(this.iURLStr) && pOutStr.writeStringList(this.iScopeList) - && pOutStr.writeAttributeList(this.iAttrList) - && pOutStr.writeStringList(this.iSPIList); - } - - private void init(long pStatelessBootTime, String pURLStr, List pScopeList, - List pAttrList, List pSPIList) { - this.iStatelessBootTime = pStatelessBootTime; - this.iURLStr = pURLStr; - this.iScopeList = pScopeList; - this.iAttrList = pAttrList; - this.iSPIList = pSPIList; - } - - @Override - public Iterator getExceptionIterator() { - // this message doesn't have exception table - return null; - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1892103 2008-02-12 ebak SLP improvements + * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp.internal.msg; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.TreeSet; +import org.metricshub.wbem.sblim.slp.ServiceLocationAttribute; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; + +/* + * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service + * Location header (function = DAAdvert = 8) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Error + * Code | DA Stateless Boot Timestamp | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |DA + * Stateless Boot Time,, contd.| Length of URL | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ \ URL \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of + * | \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of + * | \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of + * | String \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | # Auth + * Blocks | Authentication block (if any) \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ FIXME: is + * this URL an URL-entry or an URL String. Assuming URL String. + */ + +/** + * DAAdvert message + * + */ +public class DAAdvert extends ReplyMessage { + private long iStatelessBootTime; + + private String iURLStr; + + private List iScopeList; + + private List iAttrList; + + private List iSPIList; + + /** + * parse + * + * @param pHdr + * @param pInStr + * @return SLPMessage + * @throws ServiceLocationException + * @throws IOException + */ + public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { + return new DAAdvert( + pHdr, + pInStr.read16(), + pInStr.read32(), + pInStr.readString(), + pInStr.readStringList(), + pInStr.readAttributeList(), + pInStr.readStringList() + ); + } + + /** + * Ctor. + * + * @param pErrorCode + * @param pStatelessBootTime + * @param pURLStr + * @param pScopeList + * - list of scope strings + * @param pAttrList + * - list of ServiceLocationAttributes + * @param pSPIList + */ + public DAAdvert( + int pErrorCode, + long pStatelessBootTime, + String pURLStr, + List pScopeList, + List pAttrList, + List pSPIList + ) { + super(DA_ADVERT, pErrorCode); + init(pStatelessBootTime, pURLStr, pScopeList, pAttrList, pSPIList); + } + + /** + * Ctor. + * + * @param pLangTag + * @param pErrorCode + * @param pStatelessBootTime + * @param pURLStr + * @param pScopeList + * - list of scope strings + * @param pAttrList + * - list of ServiceLocationAttributes + * @param pSPIList + */ + public DAAdvert( + String pLangTag, + int pErrorCode, + long pStatelessBootTime, + String pURLStr, + List pScopeList, + List pAttrList, + List pSPIList + ) { + super(DA_ADVERT, pLangTag, pErrorCode); + init(pStatelessBootTime, pURLStr, pScopeList, pAttrList, pSPIList); + } + + /** + * Ctor. + * + * @param pHeader + * @param pErrorCode + * @param pStatelessBootTime + * @param pURLStr + * @param pScopeList + * - list of scope strings + * @param pAttrList + * - list of ServiceLocationAttributes + * @param pSPIList + */ + public DAAdvert( + MsgHeader pHeader, + int pErrorCode, + long pStatelessBootTime, + String pURLStr, + List pScopeList, + List pAttrList, + List pSPIList + ) { + super(pHeader, pErrorCode); + init(pStatelessBootTime, pURLStr, pScopeList, pAttrList, pSPIList); + } + + /** + * @return Iterator of DADescriptors + * @see ReplyMessage#getResultIterator() + */ + @Override + public Iterator getResultIterator() { + ArrayList list = new ArrayList(1); + list.add(new DADescriptor(this.iURLStr, new TreeSet(this.iScopeList), this.iAttrList)); + return list.iterator(); + } + + /** + * @param pOption + */ + @Override + protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) { + return ( + pOutStr.write16(getErrorCode()) && + pOutStr.write32(this.iStatelessBootTime) && + pOutStr.write(this.iURLStr) && + pOutStr.writeStringList(this.iScopeList) && + pOutStr.writeAttributeList(this.iAttrList) && + pOutStr.writeStringList(this.iSPIList) + ); + } + + private void init( + long pStatelessBootTime, + String pURLStr, + List pScopeList, + List pAttrList, + List pSPIList + ) { + this.iStatelessBootTime = pStatelessBootTime; + this.iURLStr = pURLStr; + this.iScopeList = pScopeList; + this.iAttrList = pAttrList; + this.iSPIList = pSPIList; + } + + @Override + public Iterator getExceptionIterator() { + // this message doesn't have exception table + return null; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/DADescriptor.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/DADescriptor.java similarity index 72% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/DADescriptor.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/DADescriptor.java index 3b44256..3e1e834 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/DADescriptor.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/DADescriptor.java @@ -1,170 +1,161 @@ -/* - (C) Copyright IBM Corp. 2007, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2795671 2009-05-22 raman_arora Add Type to Comparable - * 3023135 2010-07-01 blaschke-oss DADescriptor equals/compareTo issue - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.msg; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Iterator; -import java.util.List; -import java.util.TreeSet; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationAttribute; - -/** - *
      - * This class contains the DA related information from a DAAdvert message.
      - * URL
      - * Scope list
      - * Attribute list
      - * 
      - */ -public class DADescriptor implements Comparable { - - private String iURL; - - private TreeSet iScopeSet; - - private List iAttributes; - - /** - * Ctor. - * - * @param pURL - * @param pScopeSet - * - set of scope Strings - * @param pAttributes - * - set of ServiceLocationAttributes - */ - public DADescriptor(String pURL, TreeSet pScopeSet, - List pAttributes) { - this.iURL = pURL; - this.iScopeSet = pScopeSet; - this.iAttributes = pAttributes; - } - - /** - * getURL - * - * @return String - */ - public String getURL() { - return this.iURL; - } - - /** - * hasScope - * - * @param pScope - * @return boolean - */ - public boolean hasScope(String pScope) { - if (this.iScopeSet == null) return false; - return this.iScopeSet.contains(pScope); - } - - public int compareTo(DADescriptor o) { - DADescriptor that = o; - return this.iURL.compareTo(that.iURL); - } - - @Override - public boolean equals(Object pObj) { - if (!(pObj instanceof DADescriptor)) return false; - DADescriptor that = (DADescriptor) pObj; - return this.iURL.equals(that.iURL); - } - - private int iHashCode = 0; - - private void incHashCode(int pHashCode) { - this.iHashCode *= 31; - this.iHashCode += pHashCode; - } - - /* - * hashCode has to be independent of the order of scopes and attributes - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - if (this.iHashCode == 0) { - this.iHashCode = this.iURL.hashCode(); - Iterator itr; - if (this.iScopeSet != null) { - itr = this.iScopeSet.iterator(); - while (itr.hasNext()) - incHashCode(itr.next().hashCode()); - } - if (this.iAttributes != null) { - itr = this.iAttributes.iterator(); - /* - * iHasCode is simply incremented, because attribute order - * mustn't be considered. - */ - while (itr.hasNext()) - this.iHashCode += itr.next().hashCode(); - } - } - return this.iHashCode; - } - - @Override - public String toString() { - StringBuffer strBuf = new StringBuffer("URL : " + this.iURL + "\nScopes : "); - if (this.iScopeSet != null) { - Iterator itr = this.iScopeSet.iterator(); - boolean more = false; - while (itr.hasNext()) { - if (more) strBuf.append(", "); - else more = true; - strBuf.append(itr.next()); - } - } - - return strBuf.toString(); - } - -} +/* + (C) Copyright IBM Corp. 2007, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2795671 2009-05-22 raman_arora Add Type to Comparable + * 3023135 2010-07-01 blaschke-oss DADescriptor equals/compareTo issue + */ + +package org.metricshub.wbem.sblim.slp.internal.msg; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Iterator; +import java.util.List; +import java.util.TreeSet; +import org.metricshub.wbem.sblim.slp.ServiceLocationAttribute; + +/** + *
      + * This class contains the DA related information from a DAAdvert message.
      + * URL
      + * Scope list
      + * Attribute list
      + * 
      + */ +public class DADescriptor implements Comparable { + private String iURL; + + private TreeSet iScopeSet; + + private List iAttributes; + + /** + * Ctor. + * + * @param pURL + * @param pScopeSet + * - set of scope Strings + * @param pAttributes + * - set of ServiceLocationAttributes + */ + public DADescriptor(String pURL, TreeSet pScopeSet, List pAttributes) { + this.iURL = pURL; + this.iScopeSet = pScopeSet; + this.iAttributes = pAttributes; + } + + /** + * getURL + * + * @return String + */ + public String getURL() { + return this.iURL; + } + + /** + * hasScope + * + * @param pScope + * @return boolean + */ + public boolean hasScope(String pScope) { + if (this.iScopeSet == null) return false; + return this.iScopeSet.contains(pScope); + } + + public int compareTo(DADescriptor o) { + DADescriptor that = o; + return this.iURL.compareTo(that.iURL); + } + + @Override + public boolean equals(Object pObj) { + if (!(pObj instanceof DADescriptor)) return false; + DADescriptor that = (DADescriptor) pObj; + return this.iURL.equals(that.iURL); + } + + private int iHashCode = 0; + + private void incHashCode(int pHashCode) { + this.iHashCode *= 31; + this.iHashCode += pHashCode; + } + + /* + * hashCode has to be independent of the order of scopes and attributes + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + if (this.iHashCode == 0) { + this.iHashCode = this.iURL.hashCode(); + Iterator itr; + if (this.iScopeSet != null) { + itr = this.iScopeSet.iterator(); + while (itr.hasNext()) incHashCode(itr.next().hashCode()); + } + if (this.iAttributes != null) { + itr = this.iAttributes.iterator(); + /* + * iHasCode is simply incremented, because attribute order + * mustn't be considered. + */ + while (itr.hasNext()) this.iHashCode += itr.next().hashCode(); + } + } + return this.iHashCode; + } + + @Override + public String toString() { + StringBuffer strBuf = new StringBuffer("URL : " + this.iURL + "\nScopes : "); + if (this.iScopeSet != null) { + Iterator itr = this.iScopeSet.iterator(); + boolean more = false; + while (itr.hasNext()) { + if (more) strBuf.append(", "); else more = true; + strBuf.append(itr.next()); + } + } + + return strBuf.toString(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/FunctionIDs.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/FunctionIDs.java similarity index 69% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/FunctionIDs.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/FunctionIDs.java index 355a2a4..c118a2c 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/FunctionIDs.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/FunctionIDs.java @@ -1,115 +1,111 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.msg; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * FunctionIDs - */ -public interface FunctionIDs { - - /** - * SRV_RQST - */ - public static final int SRV_RQST = 1; - - /** - * SRV_RPLY - */ - public static final int SRV_RPLY = 2; - - /** - * SRV_REG - */ - public static final int SRV_REG = 3; - - /** - * SRV_DEREG - */ - public static final int SRV_DEREG = 4; - - /** - * SRV_ACK - */ - public static final int SRV_ACK = 5; - - /** - * ATTR_RQST - */ - public static final int ATTR_RQST = 6; - - /** - * ATTR_RPLY - */ - public static final int ATTR_RPLY = 7; - - /** - * DA_ADVERT - */ - public static final int DA_ADVERT = 8; - - /** - * SRV_TYPE_RQST - */ - public static final int SRV_TYPE_RQST = 9; - - /** - * SRV_TYPE_RPLY - */ - public static final int SRV_TYPE_RPLY = 10; - - /** - * SA_ADVERT - */ - public static final int SA_ADVERT = 11; - - /** - * FIRST_ID - */ - public static final int FIRST_ID = SRV_RQST; - - /** - * LAST_ID - */ - public static final int LAST_ID = SA_ADVERT; - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.slp.internal.msg; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * FunctionIDs + */ +public interface FunctionIDs { + /** + * SRV_RQST + */ + public static final int SRV_RQST = 1; + + /** + * SRV_RPLY + */ + public static final int SRV_RPLY = 2; + + /** + * SRV_REG + */ + public static final int SRV_REG = 3; + + /** + * SRV_DEREG + */ + public static final int SRV_DEREG = 4; + + /** + * SRV_ACK + */ + public static final int SRV_ACK = 5; + + /** + * ATTR_RQST + */ + public static final int ATTR_RQST = 6; + + /** + * ATTR_RPLY + */ + public static final int ATTR_RPLY = 7; + + /** + * DA_ADVERT + */ + public static final int DA_ADVERT = 8; + + /** + * SRV_TYPE_RQST + */ + public static final int SRV_TYPE_RQST = 9; + + /** + * SRV_TYPE_RPLY + */ + public static final int SRV_TYPE_RPLY = 10; + + /** + * SA_ADVERT + */ + public static final int SA_ADVERT = 11; + + /** + * FIRST_ID + */ + public static final int FIRST_ID = SRV_RQST; + + /** + * LAST_ID + */ + public static final int LAST_ID = SA_ADVERT; +} diff --git a/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/MsgFactory.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/MsgFactory.java new file mode 100644 index 0000000..ff1c65a --- /dev/null +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/MsgFactory.java @@ -0,0 +1,243 @@ +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.slp.internal.msg; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.io.InputStream; +import java.net.DatagramPacket; +import java.net.Socket; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; +import org.metricshub.wbem.sblim.slp.internal.msg.FunctionIDs; + +/** + * MsgFactory + * + */ +public class MsgFactory implements FunctionIDs { + + /** + * FactoryEntry + * + */ + private interface FactoryEntry { + /** + * parse + * + * @param pHdr + * @param pInStr + * @return SLPMessage + * @throws ServiceLocationException + * @throws IOException + */ + public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException; + } + + private static FactoryEntry[] cFactoryArray; + + private static void placeFactory(int pFnID, FactoryEntry pEntry) { + cFactoryArray[pFnID - FIRST_ID] = pEntry; + } + + private static synchronized void createFactoryArray() { + if (cFactoryArray != null) return; + cFactoryArray = new FactoryEntry[LAST_ID - FIRST_ID + 1]; + for (int i = 0; i < cFactoryArray.length; i++) cFactoryArray[i] = null; + placeFactory( + ATTR_RPLY, + new FactoryEntry() { + + public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { + return AttributeReply.parse(pHdr, pInStr); + } + } + ); + placeFactory( + ATTR_RQST, + new FactoryEntry() { + + public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { + return AttributeRequest.parse(pHdr, pInStr); + } + } + ); + placeFactory( + DA_ADVERT, + new FactoryEntry() { + + public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { + return DAAdvert.parse(pHdr, pInStr); + } + } + ); + placeFactory( + SA_ADVERT, + new FactoryEntry() { + + public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { + return SAAdvert.parse(pHdr, pInStr); + } + } + ); + placeFactory( + SRV_ACK, + new FactoryEntry() { + + public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { + return ServiceAcknowledgment.parse(pHdr, pInStr); + } + } + ); + placeFactory( + SRV_DEREG, + new FactoryEntry() { + + public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { + return ServiceDeregistration.parse(pHdr, pInStr); + } + } + ); + placeFactory( + SRV_REG, + new FactoryEntry() { + + public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { + return ServiceRegistration.parse(pHdr, pInStr); + } + } + ); + placeFactory( + SRV_RPLY, + new FactoryEntry() { + + public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { + return ServiceReply.parse(pHdr, pInStr); + } + } + ); + placeFactory( + SRV_RQST, + new FactoryEntry() { + + public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { + return ServiceRequest.parse(pHdr, pInStr); + } + } + ); + // + placeFactory( + SRV_TYPE_RPLY, + new FactoryEntry() { + + public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { + return ServiceTypeReply.parse(pHdr, pInStr); + } + } + ); + placeFactory( + SRV_TYPE_RQST, + new FactoryEntry() { + + public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { + return ServiceTypeRequest.parse(pHdr, pInStr); + } + } + ); + } + + private static FactoryEntry getFactory(int pFnID) { + createFactoryArray(); + return cFactoryArray[pFnID - FIRST_ID]; + } + + /** + * parse + * + * @param pSock + * @return SLPMessage + * @throws ServiceLocationException + * @throws IOException + */ + public static SLPMessage parse(Socket pSock) throws ServiceLocationException, IOException { + return parse(pSock.getInputStream()); + } + + /** + * parse + * + * @param pInStr + * @return SLPMessage + * @throws ServiceLocationException + * @throws IOException + */ + public static SLPMessage parse(InputStream pInStr) throws ServiceLocationException, IOException { + return parse(new SLPInputStream(pInStr)); + } + + /** + * parse + * + * @param pPacket + * @return SLPMessage + * @throws ServiceLocationException + * @throws IOException + */ + public static SLPMessage parse(DatagramPacket pPacket) throws ServiceLocationException, IOException { + return parse(new SLPInputStream(pPacket)); + } + + /** + * parse + * + * @param pInStr + * @return SLPMessage + * @throws ServiceLocationException + * @throws IOException + */ + public static SLPMessage parse(SLPInputStream pInStr) throws ServiceLocationException, IOException { + MsgHeader hdr = MsgHeader.parse(pInStr); + FactoryEntry factory = getFactory(hdr.getFunctionID()); + if (factory == null) throw new ServiceLocationException( + ServiceLocationException.NOT_IMPLEMENTED, + "FunctionID=" + hdr.getFunctionID() + " is not implemented!" + ); + return factory.parse(hdr, pInStr); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/MsgHeader.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/MsgHeader.java similarity index 81% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/MsgHeader.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/MsgHeader.java index a1a858c..1260edc 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/MsgHeader.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/MsgHeader.java @@ -1,341 +1,341 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1892103 2008-02-15 ebak SLP improvements - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.msg; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.util.Random; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; -import org.sentrysoftware.wbem.sblim.slp.internal.Convert; - -/* - * SLP Header: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 - * 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | - * Version | Function-ID | Length | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length, - * contd.|O|F|R| reserved |Next Ext Offset| - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Next - * Extension Offset, contd.| XID | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Language - * Tag Length | Language Tag \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * - * Message Type Abbreviation Function-ID - * - * Service Request SrvRqst 1 Service Reply SrvRply 2 Service Registration SrvReg - * 3 Service Deregister SrvDeReg 4 Service Acknowledge SrvAck 5 Attribute - * Request AttrRqst 6 Attribute Reply AttrRply 7 DA Advertisement DAAdvert 8 - * Service Type Request SrvTypeRqst 9 Service Type Reply SrvTypeRply 10 SA - * Advertisement SAAdvert 11 - * - * Length: @2 3 bytes length of the entire SLP message, header included. - * - * Flags: @5 1 byte OVERFLOW (0x80): is set when a message's length exceeds what - * can fit into a datagram. FRESH (0x40): is set on every new SrvReg. REQUEST - * MCAST (0x20): is set when multicasting or broadcasting requests. - * - * Reserved: @6 1 byte bits MUST be 0. - * - * Next Extension Offset: @7 3 bytes is set to 0 unless extensions are used. The - * first extension begins at 'offset' bytes, from the message's beginning. It is - * placed after the SLP message data. - * - * XID: @10 2 bytes is set to a unique value for each unique request. If the - * request is retransmitted, the same XID is used. Replies set the XID to the - * same value as the xid in the request. Only unsolicited DAAdverts are sent - * with an XID of 0. - * - * Language Tag Length: @12 2 bytes is the length in bytes of the Language Tag - * field. - * - * Language Tag: @14 The Language Tag in a reply MUST be the same as the - * Language Tag in the request. This field must be encoded 1*8ALPHA *("-" - * 1*8ALPHA). - */ - -/** - * MsgHeader - * - */ -public class MsgHeader implements FunctionIDs { - - /** - * VERSION - */ - public static final byte VERSION = 2; - - /** - * RAW_HDR_LEN - */ - public static final int RAW_HDR_LEN = 14; - - /** - * OVERFLOW - */ - public static final int OVERFLOW = 0x8000; - - /** - * FRESH - */ - public static final int FRESH = 0x4000; - - /** - * MCAST - */ - public static final int MCAST = 0x2000; - - /** - * Initialized with a random value, then it is increased by every - * getNewXID(). - */ - private static int cXID = -1; - - private int iVersion, iFunctionID; - - private String iLangTag; - - private boolean iOverflow, iFresh, iMCast; - - /** - * XIDs SHOULD be randomly chosen to avoid duplicate XIDs in requests if UAs - * restart frequently. This variable is used only for to keep the XID of a - * parsed message. serialize() overwrites it. - */ - private int iXID; - - /** - * parse - * - * @param pInStr - * @return MsgHeader - * @throws ServiceLocationException - * @throws IOException - */ - public static MsgHeader parse(SLPInputStream pInStr) throws ServiceLocationException, - IOException { - int version = pInStr.read8(); - int fnID = pInStr.read8(); - if (fnID < FIRST_ID || fnID > LAST_ID) throw new ServiceLocationException( - ServiceLocationException.PARSE_ERROR, "functionID:" + fnID + " is not supported!"); - // int len = - pInStr.read24(); // TODO: could be used for sanity checking - int flags = pInStr.read16(); - pInStr.read24(); // skip extension - int XID = pInStr.read16(); - String langTag = pInStr.readString(); - return new MsgHeader(version, fnID, langTag, (flags & OVERFLOW) > 0, (flags & FRESH) > 0, - (flags & MCAST) > 0, XID); - } - - /** - * Ctor. - * - * @param pHdr - */ - public MsgHeader(MsgHeader pHdr) { - this(pHdr.iVersion, pHdr.iFunctionID, pHdr.iLangTag, pHdr.iOverflow, pHdr.iFresh, - pHdr.iMCast, pHdr.iXID); - } - - /** - * Ctor. - * - * @param pVersion - * @param pFunctionID - * @param pLangTag - * @param pOverflow - * @param pFresh - * @param pMCast - * @param pXID - */ - public MsgHeader(int pVersion, int pFunctionID, String pLangTag, boolean pOverflow, - boolean pFresh, boolean pMCast, int pXID) { - this.iVersion = pVersion; - this.iFunctionID = pFunctionID; - this.iLangTag = pLangTag; - this.iOverflow = pOverflow; - this.iFresh = pFresh; - this.iMCast = pMCast; - this.iXID = pXID; - } - - /** - * getVersion - * - * @return int - */ - public int getVersion() { - return this.iVersion; - } - - /** - * getFunctionID - * - * @return int - */ - public int getFunctionID() { - return this.iFunctionID; - } - - /** - * getLangTag - * - * @return int - */ - public String getLangTag() { - return this.iLangTag; - } - - /** - * overflows - * - * @return boolean - */ - public boolean overflows() { - return this.iOverflow; - } - - /** - * fresh - * - * @return boolean - */ - public boolean fresh() { - return this.iFresh; - } - - /** - * multicast - * - * @return boolean - */ - public boolean multicast() { - return this.iMCast; - } - - /** - * @return the XID which is parsed from the message. serialize() doesn't use - * this value, that serializes a new XID into the stream at every - * call (unless pKeepXID is set). - */ - public int getXID() { - return this.iXID; - } - - /** - * The response have to contain the same XID of the request. So this setter - * can be useful. - * - * @param pXID - */ - public void setXID(int pXID) { - this.iXID = pXID; - } - - /** - * getSize - * - * @return int - */ - public int getSize() { - byte[] langBytes = getLangTagBytes(); - return RAW_HDR_LEN + langBytes.length; - } - - /* - * message body have to be serialized first in order to know length and - * MCAST - */ - /** - * serialize - * - * @param pBodyLength - * @param pOverflow - * @param pSetMultiCastFlag - * @param pKeepXID - * @return byte[] - */ - public byte[] serialize(int pBodyLength, boolean pOverflow, boolean pSetMultiCastFlag, - boolean pKeepXID) { - SLPOutputStream outStr = new SLPOutputStream(); - outStr.writeNoChk8(VERSION); - outStr.writeNoChk8(this.iFunctionID); - outStr.writeNoChk24(getSize() + pBodyLength); - int flags = 0; - if (pOverflow) flags |= OVERFLOW; - if (this.iFresh) flags |= FRESH; - if (pSetMultiCastFlag) flags |= MCAST; - outStr.writeNoChk16(flags); - outStr.writeNoChk24(0); // skip extension - if (!pKeepXID) this.iXID = getNewXID(); - outStr.writeNoChk16(this.iXID); - byte[] langTagBytes = getLangTagBytes(); - outStr.writeNoChk16(langTagBytes.length); - outStr.writeNoChk(langTagBytes); - return outStr.toByteArray(); - } - - private byte[] iLangTagBytes; - - private byte[] getLangTagBytes() { - if (this.iLangTagBytes != null) return this.iLangTagBytes; - this.iLangTagBytes = Convert.getBytes(this.iLangTag); - return this.iLangTagBytes; - } - - /* - * XID = 0 is not allowed except for some special case - */ - private static int getNewXID() { - if (cXID < 0) { - cXID = new Random().nextInt(65536); - return cXID == 0 ? ++cXID : cXID; - } - ++cXID; - cXID &= 0xffff; - if (cXID == 0) ++cXID; - return ++cXID; - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1892103 2008-02-15 ebak SLP improvements + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.slp.internal.msg; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.util.Random; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; +import org.metricshub.wbem.sblim.slp.internal.Convert; + +/* + * SLP Header: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 + * 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | + * Version | Function-ID | Length | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length, + * contd.|O|F|R| reserved |Next Ext Offset| + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Next + * Extension Offset, contd.| XID | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Language + * Tag Length | Language Tag \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * + * Message Type Abbreviation Function-ID + * + * Service Request SrvRqst 1 Service Reply SrvRply 2 Service Registration SrvReg + * 3 Service Deregister SrvDeReg 4 Service Acknowledge SrvAck 5 Attribute + * Request AttrRqst 6 Attribute Reply AttrRply 7 DA Advertisement DAAdvert 8 + * Service Type Request SrvTypeRqst 9 Service Type Reply SrvTypeRply 10 SA + * Advertisement SAAdvert 11 + * + * Length: @2 3 bytes length of the entire SLP message, header included. + * + * Flags: @5 1 byte OVERFLOW (0x80): is set when a message's length exceeds what + * can fit into a datagram. FRESH (0x40): is set on every new SrvReg. REQUEST + * MCAST (0x20): is set when multicasting or broadcasting requests. + * + * Reserved: @6 1 byte bits MUST be 0. + * + * Next Extension Offset: @7 3 bytes is set to 0 unless extensions are used. The + * first extension begins at 'offset' bytes, from the message's beginning. It is + * placed after the SLP message data. + * + * XID: @10 2 bytes is set to a unique value for each unique request. If the + * request is retransmitted, the same XID is used. Replies set the XID to the + * same value as the xid in the request. Only unsolicited DAAdverts are sent + * with an XID of 0. + * + * Language Tag Length: @12 2 bytes is the length in bytes of the Language Tag + * field. + * + * Language Tag: @14 The Language Tag in a reply MUST be the same as the + * Language Tag in the request. This field must be encoded 1*8ALPHA *("-" + * 1*8ALPHA). + */ + +/** + * MsgHeader + * + */ +public class MsgHeader implements FunctionIDs { + /** + * VERSION + */ + public static final byte VERSION = 2; + + /** + * RAW_HDR_LEN + */ + public static final int RAW_HDR_LEN = 14; + + /** + * OVERFLOW + */ + public static final int OVERFLOW = 0x8000; + + /** + * FRESH + */ + public static final int FRESH = 0x4000; + + /** + * MCAST + */ + public static final int MCAST = 0x2000; + + /** + * Initialized with a random value, then it is increased by every + * getNewXID(). + */ + private static int cXID = -1; + + private int iVersion, iFunctionID; + + private String iLangTag; + + private boolean iOverflow, iFresh, iMCast; + + /** + * XIDs SHOULD be randomly chosen to avoid duplicate XIDs in requests if UAs + * restart frequently. This variable is used only for to keep the XID of a + * parsed message. serialize() overwrites it. + */ + private int iXID; + + /** + * parse + * + * @param pInStr + * @return MsgHeader + * @throws ServiceLocationException + * @throws IOException + */ + public static MsgHeader parse(SLPInputStream pInStr) throws ServiceLocationException, IOException { + int version = pInStr.read8(); + int fnID = pInStr.read8(); + if (fnID < FIRST_ID || fnID > LAST_ID) throw new ServiceLocationException( + ServiceLocationException.PARSE_ERROR, + "functionID:" + fnID + " is not supported!" + ); + // int len = + pInStr.read24(); // TODO: could be used for sanity checking + int flags = pInStr.read16(); + pInStr.read24(); // skip extension + int XID = pInStr.read16(); + String langTag = pInStr.readString(); + return new MsgHeader(version, fnID, langTag, (flags & OVERFLOW) > 0, (flags & FRESH) > 0, (flags & MCAST) > 0, XID); + } + + /** + * Ctor. + * + * @param pHdr + */ + public MsgHeader(MsgHeader pHdr) { + this(pHdr.iVersion, pHdr.iFunctionID, pHdr.iLangTag, pHdr.iOverflow, pHdr.iFresh, pHdr.iMCast, pHdr.iXID); + } + + /** + * Ctor. + * + * @param pVersion + * @param pFunctionID + * @param pLangTag + * @param pOverflow + * @param pFresh + * @param pMCast + * @param pXID + */ + public MsgHeader( + int pVersion, + int pFunctionID, + String pLangTag, + boolean pOverflow, + boolean pFresh, + boolean pMCast, + int pXID + ) { + this.iVersion = pVersion; + this.iFunctionID = pFunctionID; + this.iLangTag = pLangTag; + this.iOverflow = pOverflow; + this.iFresh = pFresh; + this.iMCast = pMCast; + this.iXID = pXID; + } + + /** + * getVersion + * + * @return int + */ + public int getVersion() { + return this.iVersion; + } + + /** + * getFunctionID + * + * @return int + */ + public int getFunctionID() { + return this.iFunctionID; + } + + /** + * getLangTag + * + * @return int + */ + public String getLangTag() { + return this.iLangTag; + } + + /** + * overflows + * + * @return boolean + */ + public boolean overflows() { + return this.iOverflow; + } + + /** + * fresh + * + * @return boolean + */ + public boolean fresh() { + return this.iFresh; + } + + /** + * multicast + * + * @return boolean + */ + public boolean multicast() { + return this.iMCast; + } + + /** + * @return the XID which is parsed from the message. serialize() doesn't use + * this value, that serializes a new XID into the stream at every + * call (unless pKeepXID is set). + */ + public int getXID() { + return this.iXID; + } + + /** + * The response have to contain the same XID of the request. So this setter + * can be useful. + * + * @param pXID + */ + public void setXID(int pXID) { + this.iXID = pXID; + } + + /** + * getSize + * + * @return int + */ + public int getSize() { + byte[] langBytes = getLangTagBytes(); + return RAW_HDR_LEN + langBytes.length; + } + + /* + * message body have to be serialized first in order to know length and + * MCAST + */ + /** + * serialize + * + * @param pBodyLength + * @param pOverflow + * @param pSetMultiCastFlag + * @param pKeepXID + * @return byte[] + */ + public byte[] serialize(int pBodyLength, boolean pOverflow, boolean pSetMultiCastFlag, boolean pKeepXID) { + SLPOutputStream outStr = new SLPOutputStream(); + outStr.writeNoChk8(VERSION); + outStr.writeNoChk8(this.iFunctionID); + outStr.writeNoChk24(getSize() + pBodyLength); + int flags = 0; + if (pOverflow) flags |= OVERFLOW; + if (this.iFresh) flags |= FRESH; + if (pSetMultiCastFlag) flags |= MCAST; + outStr.writeNoChk16(flags); + outStr.writeNoChk24(0); // skip extension + if (!pKeepXID) this.iXID = getNewXID(); + outStr.writeNoChk16(this.iXID); + byte[] langTagBytes = getLangTagBytes(); + outStr.writeNoChk16(langTagBytes.length); + outStr.writeNoChk(langTagBytes); + return outStr.toByteArray(); + } + + private byte[] iLangTagBytes; + + private byte[] getLangTagBytes() { + if (this.iLangTagBytes != null) return this.iLangTagBytes; + this.iLangTagBytes = Convert.getBytes(this.iLangTag); + return this.iLangTagBytes; + } + + /* + * XID = 0 is not allowed except for some special case + */ + private static int getNewXID() { + if (cXID < 0) { + cXID = new Random().nextInt(65536); + return cXID == 0 ? ++cXID : cXID; + } + ++cXID; + cXID &= 0xffff; + if (cXID == 0) ++cXID; + return ++cXID; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ReplyMessage.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ReplyMessage.java similarity index 71% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ReplyMessage.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ReplyMessage.java index 6e44cd7..b544282 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ReplyMessage.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ReplyMessage.java @@ -1,114 +1,110 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.msg; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Iterator; - -/** - * ReplyMessage - * - */ -public abstract class ReplyMessage extends SLPMessage { - - private int iErrorCode; - - /** - * Ctor. - * - * @param pFunctionID - * @param pErrorCode - */ - public ReplyMessage(int pFunctionID, int pErrorCode) { - super(pFunctionID); - this.iErrorCode = pErrorCode; - } - - /** - * Ctor. - * - * @param pFunctionID - * @param pLangTag - * @param pErrorCode - */ - public ReplyMessage(int pFunctionID, String pLangTag, int pErrorCode) { - super(pFunctionID, pLangTag); - this.iErrorCode = pErrorCode; - } - - /** - * Ctor. - * - * @param pHeader - * @param pErrorCode - */ - public ReplyMessage(MsgHeader pHeader, int pErrorCode) { - super(pHeader); - this.iErrorCode = pErrorCode; - } - - /** - * getErrorCode - * - * @return int - */ - public int getErrorCode() { - return this.iErrorCode; - } - - /** - * getResultIterator - * - * @return Iterator - */ - public abstract Iterator getResultIterator(); - - /** - * getExceptionIterator - * - * @return Iterator - */ - public abstract Iterator getExceptionIterator(); - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp.internal.msg; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Iterator; + +/** + * ReplyMessage + * + */ +public abstract class ReplyMessage extends SLPMessage { + private int iErrorCode; + + /** + * Ctor. + * + * @param pFunctionID + * @param pErrorCode + */ + public ReplyMessage(int pFunctionID, int pErrorCode) { + super(pFunctionID); + this.iErrorCode = pErrorCode; + } + + /** + * Ctor. + * + * @param pFunctionID + * @param pLangTag + * @param pErrorCode + */ + public ReplyMessage(int pFunctionID, String pLangTag, int pErrorCode) { + super(pFunctionID, pLangTag); + this.iErrorCode = pErrorCode; + } + + /** + * Ctor. + * + * @param pHeader + * @param pErrorCode + */ + public ReplyMessage(MsgHeader pHeader, int pErrorCode) { + super(pHeader); + this.iErrorCode = pErrorCode; + } + + /** + * getErrorCode + * + * @return int + */ + public int getErrorCode() { + return this.iErrorCode; + } + + /** + * getResultIterator + * + * @return Iterator + */ + public abstract Iterator getResultIterator(); + + /** + * getExceptionIterator + * + * @return Iterator + */ + public abstract Iterator getExceptionIterator(); +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/RequestMessage.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/RequestMessage.java similarity index 70% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/RequestMessage.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/RequestMessage.java index 39e8cef..4fd3209 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/RequestMessage.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/RequestMessage.java @@ -1,207 +1,204 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1892103 2008-02-12 ebak SLP improvements - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.msg; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Iterator; -import java.util.List; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.sentrysoftware.wbem.sblim.slp.internal.msg.SLPMessage; -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; - -/** - * RequestMessage - * - */ -public abstract class RequestMessage extends SLPMessage { - - private SortedSet iPrevResponderSet; - - private List iScopeList; - - /** - * Ctor. - * - * @param pFunctionID - * @param pPrevResponderSet - * - set of address strings - * @param pScopeList - * - list of scope strings - */ - public RequestMessage(int pFunctionID, SortedSet pPrevResponderSet, - List pScopeList) { - super(pFunctionID); - init(pPrevResponderSet, pScopeList); - } - - /** - * Ctor. - * - * @param pFunctionID - * @param pLangTag - * @param pPrevResponderSet - * - set of address strings - * @param pScopeList - * - list of scope strings - */ - public RequestMessage(int pFunctionID, String pLangTag, SortedSet pPrevResponderSet, - List pScopeList) { - super(pFunctionID, pLangTag); - init(pPrevResponderSet, pScopeList); - } - - /** - * Ctor. - * - * @param pHeader - * @param pPrevResponderSet - * - set of address strings - * @param pScopeList - * - list of scope strings - */ - public RequestMessage(MsgHeader pHeader, SortedSet pPrevResponderSet, - List pScopeList) { - super(pHeader); - init(pPrevResponderSet, pScopeList); - } - - /** - * getPrevResponderSet - * - * @return SortedSet - */ - public SortedSet getPrevResponderSet() { - return this.iPrevResponderSet; - } - - /** - * getPrevRespondersItr - * - * @return Iterator - */ - public Iterator getPrevRespondersItr() { - return this.iPrevResponderSet == null ? null : this.iPrevResponderSet.iterator(); - } - - /** - * updatePrevResponders - * - * @param pResponder - * @return boolean - */ - public boolean updatePrevResponders(String pResponder) { - if (this.iPrevResponderSet == null) this.iPrevResponderSet = new TreeSet(); - return this.iPrevResponderSet.add(pResponder); - } - - /** - * getScopeList - * - * @return List of scope strings - */ - public List getScopeList() { - return this.iScopeList; - } - - /** - * isAllowedResponseType - * - * @param pRspMsg - * @return boolean - */ - public boolean isAllowedResponseType(SLPMessage pRspMsg) { - if (pRspMsg == null) return false; - int id = pRspMsg.getFunctionID(); - int[] rspIDs = getAllowedResponseIDs(); - if (rspIDs == null) return true; - for (int i = 0; i < rspIDs.length; i++) - if (id == rspIDs[i]) return true; - return false; - } - - /** - * serializeWithoutResponders - * - * @param pSetMulticastFlag - * @param pDatagramLimited - * @param pKeepXID - * @return byte[] - * @throws ServiceLocationException - */ - public byte[] serializeWithoutResponders(boolean pSetMulticastFlag, boolean pDatagramLimited, - boolean pKeepXID) throws ServiceLocationException { - - return serialize(pSetMulticastFlag, pDatagramLimited, pKeepXID, new SkipResponders()); - } - - @Override - protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pSkipResponders) - throws ServiceLocationException { - if (!pOutStr.writeStringList(pSkipResponders == null ? getPrevRespondersItr() : null)) throw new ServiceLocationException( - ServiceLocationException.PREVIOUS_RESPONDER_OVERFLOW, - "Previous responder list has overflowed!"); - return serializeRequestBody(pOutStr); - } - - protected abstract boolean serializeRequestBody(SLPOutputStream pOutStr) - throws ServiceLocationException; - - protected abstract int[] getAllowedResponseIDs(); - - private void init(SortedSet pPrevResponderSet, List pScopeList) { - this.iPrevResponderSet = pPrevResponderSet; - this.iScopeList = pScopeList; - } - - class SkipResponders extends SerializeOption { - /* - * non-null instance indicates that the PreviousResponderList - * serialization have to be skipped - */ - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1892103 2008-02-12 ebak SLP improvements + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + */ + +package org.metricshub.wbem.sblim.slp.internal.msg; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Iterator; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; +import org.metricshub.wbem.sblim.slp.internal.msg.SLPMessage; + +/** + * RequestMessage + * + */ +public abstract class RequestMessage extends SLPMessage { + private SortedSet iPrevResponderSet; + + private List iScopeList; + + /** + * Ctor. + * + * @param pFunctionID + * @param pPrevResponderSet + * - set of address strings + * @param pScopeList + * - list of scope strings + */ + public RequestMessage(int pFunctionID, SortedSet pPrevResponderSet, List pScopeList) { + super(pFunctionID); + init(pPrevResponderSet, pScopeList); + } + + /** + * Ctor. + * + * @param pFunctionID + * @param pLangTag + * @param pPrevResponderSet + * - set of address strings + * @param pScopeList + * - list of scope strings + */ + public RequestMessage( + int pFunctionID, + String pLangTag, + SortedSet pPrevResponderSet, + List pScopeList + ) { + super(pFunctionID, pLangTag); + init(pPrevResponderSet, pScopeList); + } + + /** + * Ctor. + * + * @param pHeader + * @param pPrevResponderSet + * - set of address strings + * @param pScopeList + * - list of scope strings + */ + public RequestMessage(MsgHeader pHeader, SortedSet pPrevResponderSet, List pScopeList) { + super(pHeader); + init(pPrevResponderSet, pScopeList); + } + + /** + * getPrevResponderSet + * + * @return SortedSet + */ + public SortedSet getPrevResponderSet() { + return this.iPrevResponderSet; + } + + /** + * getPrevRespondersItr + * + * @return Iterator + */ + public Iterator getPrevRespondersItr() { + return this.iPrevResponderSet == null ? null : this.iPrevResponderSet.iterator(); + } + + /** + * updatePrevResponders + * + * @param pResponder + * @return boolean + */ + public boolean updatePrevResponders(String pResponder) { + if (this.iPrevResponderSet == null) this.iPrevResponderSet = new TreeSet(); + return this.iPrevResponderSet.add(pResponder); + } + + /** + * getScopeList + * + * @return List of scope strings + */ + public List getScopeList() { + return this.iScopeList; + } + + /** + * isAllowedResponseType + * + * @param pRspMsg + * @return boolean + */ + public boolean isAllowedResponseType(SLPMessage pRspMsg) { + if (pRspMsg == null) return false; + int id = pRspMsg.getFunctionID(); + int[] rspIDs = getAllowedResponseIDs(); + if (rspIDs == null) return true; + for (int i = 0; i < rspIDs.length; i++) if (id == rspIDs[i]) return true; + return false; + } + + /** + * serializeWithoutResponders + * + * @param pSetMulticastFlag + * @param pDatagramLimited + * @param pKeepXID + * @return byte[] + * @throws ServiceLocationException + */ + public byte[] serializeWithoutResponders(boolean pSetMulticastFlag, boolean pDatagramLimited, boolean pKeepXID) + throws ServiceLocationException { + return serialize(pSetMulticastFlag, pDatagramLimited, pKeepXID, new SkipResponders()); + } + + @Override + protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pSkipResponders) + throws ServiceLocationException { + if ( + !pOutStr.writeStringList(pSkipResponders == null ? getPrevRespondersItr() : null) + ) throw new ServiceLocationException( + ServiceLocationException.PREVIOUS_RESPONDER_OVERFLOW, + "Previous responder list has overflowed!" + ); + return serializeRequestBody(pOutStr); + } + + protected abstract boolean serializeRequestBody(SLPOutputStream pOutStr) throws ServiceLocationException; + + protected abstract int[] getAllowedResponseIDs(); + + private void init(SortedSet pPrevResponderSet, List pScopeList) { + this.iPrevResponderSet = pPrevResponderSet; + this.iScopeList = pScopeList; + } + + class SkipResponders extends SerializeOption { + /* + * non-null instance indicates that the PreviousResponderList + * serialization have to be skipped + */ + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/SAAdvert.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/SAAdvert.java similarity index 69% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/SAAdvert.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/SAAdvert.java index 43eefc6..82b48be 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/SAAdvert.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/SAAdvert.java @@ -1,174 +1,171 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1892103 2008-02-12 ebak SLP improvements - * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.msg; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationAttribute; -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; - -/* - * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service - * Location header (function = SAAdvert = 11) | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of - * URL | URL \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | - * Length of | \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of - * | \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | # auth - * blocks | authentication block (if any) \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * - */ - -/** - * SAAdvert message - * - */ -public class SAAdvert extends ReplyMessage { - - private String iURLStr; - - private List iScopeList; - - private List iAttrList; - - /** - * parse - * - * @param pHdr - * @param pInStr - * @return SLPMessage - * @throws ServiceLocationException - * @throws IOException - */ - public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException { - return new SAAdvert(pHdr, pInStr.readString(), pInStr.readStringList(), pInStr - .readAttributeList()); - } - - /** - * Ctor. - * - * @param pURLStr - * @param pScopeList - * - list of scope strings - * @param pAttrList - * - list of ServiceLocationAttributes - */ - public SAAdvert(String pURLStr, List pScopeList, - List pAttrList) { - super(SA_ADVERT, 0); - init(pURLStr, pScopeList, pAttrList); - } - - /** - * Ctor. - * - * @param pLangTag - * @param pURLStr - * @param pScopeList - * - list of scope strings - * @param pAttrList - * - list of ServiceLocationAttributes - */ - public SAAdvert(String pLangTag, String pURLStr, List pScopeList, - List pAttrList) { - super(SA_ADVERT, pLangTag, 0); - init(pURLStr, pScopeList, pAttrList); - } - - /** - * Ctor. - * - * @param pHeader - * @param pURLStr - * @param pScopeList - * - list of scope strings - * @param pAttrList - * - list of ServiceLocationAttributes - */ - public SAAdvert(MsgHeader pHeader, String pURLStr, List pScopeList, - List pAttrList) { - super(pHeader, 0); - init(pURLStr, pScopeList, pAttrList); - } - - @Override - public Iterator getResultIterator() { - ArrayList list = new ArrayList(); - list.add(this.iURLStr); - return list.iterator(); - } - - /** - * @param pOption - */ - @Override - protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) { - return pOutStr.write(this.iURLStr) && pOutStr.writeStringList(this.iScopeList) - && pOutStr.writeAttributeList(this.iAttrList); - } - - private void init(String pURLStr, List pScopeList, - List pAttrList) { - this.iURLStr = pURLStr; - this.iScopeList = pScopeList; - this.iAttrList = pAttrList; - } - - @Override - public Iterator getExceptionIterator() { - // this message doesn't have exception table - return null; - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1892103 2008-02-12 ebak SLP improvements + * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp.internal.msg; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import org.metricshub.wbem.sblim.slp.ServiceLocationAttribute; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; + +/* + * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service + * Location header (function = SAAdvert = 11) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of + * URL | URL \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | + * Length of | \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of + * | \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | # auth + * blocks | authentication block (if any) \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * + */ + +/** + * SAAdvert message + * + */ +public class SAAdvert extends ReplyMessage { + private String iURLStr; + + private List iScopeList; + + private List iAttrList; + + /** + * parse + * + * @param pHdr + * @param pInStr + * @return SLPMessage + * @throws ServiceLocationException + * @throws IOException + */ + public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { + return new SAAdvert(pHdr, pInStr.readString(), pInStr.readStringList(), pInStr.readAttributeList()); + } + + /** + * Ctor. + * + * @param pURLStr + * @param pScopeList + * - list of scope strings + * @param pAttrList + * - list of ServiceLocationAttributes + */ + public SAAdvert(String pURLStr, List pScopeList, List pAttrList) { + super(SA_ADVERT, 0); + init(pURLStr, pScopeList, pAttrList); + } + + /** + * Ctor. + * + * @param pLangTag + * @param pURLStr + * @param pScopeList + * - list of scope strings + * @param pAttrList + * - list of ServiceLocationAttributes + */ + public SAAdvert(String pLangTag, String pURLStr, List pScopeList, List pAttrList) { + super(SA_ADVERT, pLangTag, 0); + init(pURLStr, pScopeList, pAttrList); + } + + /** + * Ctor. + * + * @param pHeader + * @param pURLStr + * @param pScopeList + * - list of scope strings + * @param pAttrList + * - list of ServiceLocationAttributes + */ + public SAAdvert( + MsgHeader pHeader, + String pURLStr, + List pScopeList, + List pAttrList + ) { + super(pHeader, 0); + init(pURLStr, pScopeList, pAttrList); + } + + @Override + public Iterator getResultIterator() { + ArrayList list = new ArrayList(); + list.add(this.iURLStr); + return list.iterator(); + } + + /** + * @param pOption + */ + @Override + protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) { + return ( + pOutStr.write(this.iURLStr) && + pOutStr.writeStringList(this.iScopeList) && + pOutStr.writeAttributeList(this.iAttrList) + ); + } + + private void init(String pURLStr, List pScopeList, List pAttrList) { + this.iURLStr = pURLStr; + this.iScopeList = pScopeList; + this.iAttrList = pAttrList; + } + + @Override + public Iterator getExceptionIterator() { + // this message doesn't have exception table + return null; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/SLPInputStream.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/SLPInputStream.java similarity index 78% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/SLPInputStream.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/SLPInputStream.java index 8854335..b81fa4f 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/SLPInputStream.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/SLPInputStream.java @@ -1,504 +1,503 @@ -/* - (C) Copyright IBM Corp. 2007, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1892103 2008-02-12 ebak SLP improvements - * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 3023349 2010-07-02 blaschke-oss SLP uses # constructor instead of valueOf - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.msg; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.net.DatagramPacket; -import java.net.Socket; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.SortedSet; -import java.util.StringTokenizer; -import java.util.TreeSet; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationAttribute; -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; -import org.sentrysoftware.wbem.sblim.slp.ServiceType; -import org.sentrysoftware.wbem.sblim.slp.ServiceURL; -import org.sentrysoftware.wbem.sblim.slp.internal.Convert; -import org.sentrysoftware.wbem.sblim.slp.internal.SLPDefaults; -import org.sentrysoftware.wbem.sblim.slp.internal.TRC; - -/** - * Helps the parsing of the bytes of SLP messages. - * - */ -public class SLPInputStream { - - private InputStream iInStr; - - private final byte[] iBBuf = new byte[4]; - - /** - * Ctor. - * - * @param pBytes - */ - public SLPInputStream(byte[] pBytes) { - this(pBytes, 0, pBytes.length); - } - - /** - * Ctor. - * - * @param pSock - * @throws IOException - */ - public SLPInputStream(Socket pSock) throws IOException { - this(pSock.getInputStream()); - } - - /** - * Ctor. - * - * @param pInStr - */ - public SLPInputStream(InputStream pInStr) { - this.iInStr = pInStr; - } - - /** - * Ctor. - * - * @param pPacket - */ - public SLPInputStream(DatagramPacket pPacket) { - this(pPacket.getData(), pPacket.getOffset(), pPacket.getLength()); - } - - /** - * Ctor. - * - * @param pBytes - * @param pOffset - * @param pLength - */ - public SLPInputStream(byte[] pBytes, int pOffset, int pLength) { - this.iInStr = new ByteArrayInputStream(pBytes, pOffset, pLength); - } - - /** - * readString - * - * @return String - * @throws ServiceLocationException - * @throws IOException - */ - public String readString() throws ServiceLocationException, IOException { - return Convert.unescape(readRawString()); - } - - /** - * readStringSet - * - * @return SortedSet of Strings - * @throws ServiceLocationException - * @throws IOException - */ - public SortedSet readStringSet() throws ServiceLocationException, IOException { - SortedSet set = new TreeSet(); - readStringCollection(set); - return set; - } - - /** - * readStringList - * - * @return List of Strings - * @throws ServiceLocationException - * @throws IOException - */ - public List readStringList() throws ServiceLocationException, IOException { - ArrayList strList = new ArrayList(); - readStringCollection(strList); - return strList; - } - - /** - * readAttribute - * - * @return ServiceLocationAttribute - * @throws ServiceLocationException - * @throws IOException - */ - public ServiceLocationAttribute readAttribute() throws ServiceLocationException, IOException { - String str = readRawString(); - return str == null ? null : new ServiceLocationAttribute(str); - } - - /** - * readAttributeList - * - * @return List of ServiceLocationAttributes - * @throws ServiceLocationException - * @throws IOException - */ - public List readAttributeList() throws ServiceLocationException, - IOException { - String str = readRawString(); - return str == null ? null : new AttrListParser(str).getList(); - } - - /** - * # of AttrAuths |(if present) Attribute Authentication Blocks... - * - * @return null - * @throws ServiceLocationException - * @throws IOException - */ - public List readAuthBlockList() throws ServiceLocationException, IOException { - Integer blockCntInt = doRead8(); - if (blockCntInt == null) return null; - int blockCnt = blockCntInt.intValue(); - if (blockCnt != 0) throw new ServiceLocationException( - ServiceLocationException.NOT_IMPLEMENTED, - "Handling of authentication blocks is not implemented! blockCount = " + blockCnt); - return null; - } - - /* - * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | - * Reserved | Lifetime | URL Length | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |URL - * len, contd.| URL (variable length) \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |# of - * URL auths | Auth. blocks (if any) \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - /** - * @return ServiceURL - * @throws ServiceLocationException - * @throws IOException - */ - public ServiceURL readURL() throws ServiceLocationException, IOException { - if (doRead8() == null) return null; // skip reserved - Integer lifeTimeInt = doRead16(); - if (lifeTimeInt == null) return null; - int lifeTime = lifeTimeInt.intValue(); - String urlStr = readString(); - if (urlStr == null) return null; - Integer numOfAuthsInt = doRead8(); - if (numOfAuthsInt == null) return null; - int numOfAuths = numOfAuthsInt.intValue(); - while (numOfAuths-- > 0) { - TRC.warning("readAuth"); - readString(); - } - return new ServiceURL(urlStr, lifeTime); - } - - /** - * readUrlList - * - * @param pURLExceptions - * @return List of valid ServiceURLs - * @throws ServiceLocationException - * @throws IOException - * - * Add URL to list only if it is valid URL i.e. no exception is - * thrown by parser - * - */ - public List readUrlList(List pURLExceptions) - throws ServiceLocationException, IOException { - Integer cntInt = doRead16(); - if (cntInt == null) return null; - int cnt = cntInt.intValue(); - ArrayList urlList = new ArrayList(cnt); - ServiceURL url; - while (cnt-- > 0) { - try { - url = readURL(); - if (url == null) break; - urlList.add(url); - } catch (IllegalArgumentException e) { - pURLExceptions.add(e); - TRC.warning("Ignoring Invalid URL : " + e.getMessage()); - } - } - return urlList; - } - - /** - * readServiceType - * - * @return ServiceType - * @throws ServiceLocationException - * @throws IOException - */ - public ServiceType readServiceType() throws ServiceLocationException, IOException { - String str = readString(); - return str == null ? null : new ServiceType(str); - } - - /** - * readServTypeList - * - * @return List of ServiceTypes - * @throws ServiceLocationException - * @throws IOException - */ - public List readServTypeList() throws ServiceLocationException, IOException { - Iterator strItr = readStringList().iterator(); - ArrayList srvTypeList = new ArrayList(); - while (strItr.hasNext()) { - srvTypeList.add(new ServiceType(strItr.next())); - } - return srvTypeList; - } - - /** - * read8 - * - * @return int - * @throws ServiceLocationException - * @throws IOException - */ - public int read8() throws ServiceLocationException, IOException { - Integer res = doRead8(); - if (res == null) throw new ServiceLocationException(ServiceLocationException.PARSE_ERROR, - "Failed to read byte field!"); - return res.intValue(); - } - - /** - * read16 - * - * @return int - * @throws ServiceLocationException - * @throws IOException - */ - public int read16() throws ServiceLocationException, IOException { - Integer res = doRead16(); - if (res == null) throw new ServiceLocationException(ServiceLocationException.PARSE_ERROR, - "Failed to read 2-byte-long field!"); - return res.intValue(); - } - - /** - * read24 - * - * @return int - * @throws ServiceLocationException - * @throws IOException - */ - public int read24() throws ServiceLocationException, IOException { - Integer res = doRead24(); - if (res == null) throw new ServiceLocationException(ServiceLocationException.PARSE_ERROR, - "Failed to read 3-byte-long field!"); - return res.intValue(); - } - - /** - * read32 - * - * @return long - * @throws ServiceLocationException - * @throws IOException - */ - public long read32() throws ServiceLocationException, IOException { - Long res = doRead32(); - if (res == null) throw new ServiceLocationException(ServiceLocationException.PARSE_ERROR, - "Failed to read 4-byte-long field!"); - return res.longValue(); - } - - private Integer doRead8() throws IOException { - int res = this.iInStr.read(); - return res < 0 ? null : Integer.valueOf(res); - } - - private Integer doRead16() throws IOException { - int cnt = this.iInStr.read(this.iBBuf, 0, 2); - if (cnt != 2) return null; - return Integer.valueOf((this.iBBuf[0] & 0xff) << 8 | this.iBBuf[1] & 0xff); - } - - private Integer doRead24() throws IOException { - int cnt = this.iInStr.read(this.iBBuf, 0, 3); - if (cnt != 3) return null; - return Integer.valueOf((this.iBBuf[0] & 0xff) << 16 | (this.iBBuf[1] & 0xff) << 8 - | this.iBBuf[2] & 0xff); - } - - private Long doRead32() throws IOException { - int cnt = this.iInStr.read(this.iBBuf, 0, 4); - if (cnt != 4) return null; - long res = (this.iBBuf[0] & 0xff) << 8; - res |= (this.iBBuf[1] & 0xff) << 8; - res |= (this.iBBuf[2] & 0xff) << 8; - res |= this.iBBuf[3] & 0xff; - return Long.valueOf(res); - } - - private String readRawString() throws ServiceLocationException, IOException { - Integer lenInt = doRead16(); - if (lenInt == null) return null; - int len = lenInt.intValue(); - if (len <= 0) return null; - byte[] bytes = new byte[len]; - int read = this.iInStr.read(bytes, 0, len); - if (read != len) return null; - try { - return new String(bytes, SLPDefaults.ENCODING); - } catch (UnsupportedEncodingException e) { - throw new ServiceLocationException(ServiceLocationException.INTERNAL_SYSTEM_ERROR, e); - } - } - - private void readStringCollection(Collection pCol) throws ServiceLocationException, - IOException { - String rawListStr = readRawString(); - if (rawListStr == null) return; - StringTokenizer tokenizer = new StringTokenizer(rawListStr, ","); - while (tokenizer.hasMoreElements()) - pCol.add(Convert.unescape(tokenizer.nextToken())); - } - - private static class AttrListParser { - - private int iPos = 0; - - private String iAttrListStr; - - private ArrayList iList = new ArrayList(); - - /** - * Ctor. - * - * @param pAttrListStr - * @throws ServiceLocationException - */ - public AttrListParser(String pAttrListStr) throws ServiceLocationException { - debug("attrListStr=" + pAttrListStr); - this.iAttrListStr = pAttrListStr; - String attrStr; - while ((attrStr = readEntry()) != null) { - debug("attrStr=" + attrStr); - this.iList.add(new ServiceLocationAttribute(attrStr)); - } - } - - /** - * getList - * - * @return List of ServiceLocationAttributes - */ - public List getList() { - return this.iList; - } - - /* - * ( "(" attrID "=" ( value "," )* value ")" ("," / EndOfString ) ) / - * attrID ("," / EndOfString ) - */ - private String readEntry() throws ServiceLocationException { - if (this.iAttrListStr == null) return null; - int lastIdx = this.iAttrListStr.length() - 1; - if (this.iPos == lastIdx) return null; - boolean inBlock = false; - int startPos = this.iPos; - while (true) { - char ch = this.iAttrListStr.charAt(this.iPos); - if (ch == '(') { - if (inBlock || this.iPos != startPos) throw new ServiceLocationException( - ServiceLocationException.PARSE_ERROR, invalidChar('(')); - inBlock = true; - } else if (ch == ')') { - if (!inBlock) throw new ServiceLocationException( - ServiceLocationException.PARSE_ERROR, invalidChar(')')); - if (this.iPos == lastIdx) return this.iAttrListStr.substring(startPos); - inBlock = false; - } else { - if (inBlock) { - if (this.iPos == lastIdx) - /* - * throw new ServiceLocationException( - * ServiceLocationException.PARSE_ERROR, "There is no - * ')' for '(' !" ); - */ - return this.iAttrListStr.substring(startPos); - } else { - if (ch == ',') { - ++this.iPos; - return this.iAttrListStr.substring(startPos, this.iPos - 1); - } - if (this.iPos == lastIdx) { return this.iAttrListStr.substring(startPos); } - } - } - if (this.iPos == lastIdx) throw new ServiceLocationException( - ServiceLocationException.PARSE_ERROR, "Unexpected end of Attribute list:\n" - + this.iAttrListStr); - ++this.iPos; - } - } - - /** - * @param ch - */ - private String invalidChar(char ch) { - return "Invalid '(' character in Attribute list:\n" + this.iAttrListStr - + "\nat position: " + this.iPos; - } - - } - - /** - * @param pMsg - */ - static void debug(String pMsg) { - // System.out.println(pMsg); - } - -} +/* + (C) Copyright IBM Corp. 2007, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1892103 2008-02-12 ebak SLP improvements + * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 3023349 2010-07-02 blaschke-oss SLP uses # constructor instead of valueOf + */ + +package org.metricshub.wbem.sblim.slp.internal.msg; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.net.DatagramPacket; +import java.net.Socket; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.SortedSet; +import java.util.StringTokenizer; +import java.util.TreeSet; +import org.metricshub.wbem.sblim.slp.ServiceLocationAttribute; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; +import org.metricshub.wbem.sblim.slp.ServiceType; +import org.metricshub.wbem.sblim.slp.ServiceURL; +import org.metricshub.wbem.sblim.slp.internal.Convert; +import org.metricshub.wbem.sblim.slp.internal.SLPDefaults; +import org.metricshub.wbem.sblim.slp.internal.TRC; + +/** + * Helps the parsing of the bytes of SLP messages. + * + */ +public class SLPInputStream { + private InputStream iInStr; + + private final byte[] iBBuf = new byte[4]; + + /** + * Ctor. + * + * @param pBytes + */ + public SLPInputStream(byte[] pBytes) { + this(pBytes, 0, pBytes.length); + } + + /** + * Ctor. + * + * @param pSock + * @throws IOException + */ + public SLPInputStream(Socket pSock) throws IOException { + this(pSock.getInputStream()); + } + + /** + * Ctor. + * + * @param pInStr + */ + public SLPInputStream(InputStream pInStr) { + this.iInStr = pInStr; + } + + /** + * Ctor. + * + * @param pPacket + */ + public SLPInputStream(DatagramPacket pPacket) { + this(pPacket.getData(), pPacket.getOffset(), pPacket.getLength()); + } + + /** + * Ctor. + * + * @param pBytes + * @param pOffset + * @param pLength + */ + public SLPInputStream(byte[] pBytes, int pOffset, int pLength) { + this.iInStr = new ByteArrayInputStream(pBytes, pOffset, pLength); + } + + /** + * readString + * + * @return String + * @throws ServiceLocationException + * @throws IOException + */ + public String readString() throws ServiceLocationException, IOException { + return Convert.unescape(readRawString()); + } + + /** + * readStringSet + * + * @return SortedSet of Strings + * @throws ServiceLocationException + * @throws IOException + */ + public SortedSet readStringSet() throws ServiceLocationException, IOException { + SortedSet set = new TreeSet(); + readStringCollection(set); + return set; + } + + /** + * readStringList + * + * @return List of Strings + * @throws ServiceLocationException + * @throws IOException + */ + public List readStringList() throws ServiceLocationException, IOException { + ArrayList strList = new ArrayList(); + readStringCollection(strList); + return strList; + } + + /** + * readAttribute + * + * @return ServiceLocationAttribute + * @throws ServiceLocationException + * @throws IOException + */ + public ServiceLocationAttribute readAttribute() throws ServiceLocationException, IOException { + String str = readRawString(); + return str == null ? null : new ServiceLocationAttribute(str); + } + + /** + * readAttributeList + * + * @return List of ServiceLocationAttributes + * @throws ServiceLocationException + * @throws IOException + */ + public List readAttributeList() throws ServiceLocationException, IOException { + String str = readRawString(); + return str == null ? null : new AttrListParser(str).getList(); + } + + /** + * # of AttrAuths |(if present) Attribute Authentication Blocks... + * + * @return null + * @throws ServiceLocationException + * @throws IOException + */ + public List readAuthBlockList() throws ServiceLocationException, IOException { + Integer blockCntInt = doRead8(); + if (blockCntInt == null) return null; + int blockCnt = blockCntInt.intValue(); + if (blockCnt != 0) throw new ServiceLocationException( + ServiceLocationException.NOT_IMPLEMENTED, + "Handling of authentication blocks is not implemented! blockCount = " + blockCnt + ); + return null; + } + + /* + * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | + * Reserved | Lifetime | URL Length | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |URL + * len, contd.| URL (variable length) \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |# of + * URL auths | Auth. blocks (if any) \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + /** + * @return ServiceURL + * @throws ServiceLocationException + * @throws IOException + */ + public ServiceURL readURL() throws ServiceLocationException, IOException { + if (doRead8() == null) return null; // skip reserved + Integer lifeTimeInt = doRead16(); + if (lifeTimeInt == null) return null; + int lifeTime = lifeTimeInt.intValue(); + String urlStr = readString(); + if (urlStr == null) return null; + Integer numOfAuthsInt = doRead8(); + if (numOfAuthsInt == null) return null; + int numOfAuths = numOfAuthsInt.intValue(); + while (numOfAuths-- > 0) { + TRC.warning("readAuth"); + readString(); + } + return new ServiceURL(urlStr, lifeTime); + } + + /** + * readUrlList + * + * @param pURLExceptions + * @return List of valid ServiceURLs + * @throws ServiceLocationException + * @throws IOException + * + * Add URL to list only if it is valid URL i.e. no exception is + * thrown by parser + * + */ + public List readUrlList(List pURLExceptions) throws ServiceLocationException, IOException { + Integer cntInt = doRead16(); + if (cntInt == null) return null; + int cnt = cntInt.intValue(); + ArrayList urlList = new ArrayList(cnt); + ServiceURL url; + while (cnt-- > 0) { + try { + url = readURL(); + if (url == null) break; + urlList.add(url); + } catch (IllegalArgumentException e) { + pURLExceptions.add(e); + TRC.warning("Ignoring Invalid URL : " + e.getMessage()); + } + } + return urlList; + } + + /** + * readServiceType + * + * @return ServiceType + * @throws ServiceLocationException + * @throws IOException + */ + public ServiceType readServiceType() throws ServiceLocationException, IOException { + String str = readString(); + return str == null ? null : new ServiceType(str); + } + + /** + * readServTypeList + * + * @return List of ServiceTypes + * @throws ServiceLocationException + * @throws IOException + */ + public List readServTypeList() throws ServiceLocationException, IOException { + Iterator strItr = readStringList().iterator(); + ArrayList srvTypeList = new ArrayList(); + while (strItr.hasNext()) { + srvTypeList.add(new ServiceType(strItr.next())); + } + return srvTypeList; + } + + /** + * read8 + * + * @return int + * @throws ServiceLocationException + * @throws IOException + */ + public int read8() throws ServiceLocationException, IOException { + Integer res = doRead8(); + if (res == null) throw new ServiceLocationException( + ServiceLocationException.PARSE_ERROR, + "Failed to read byte field!" + ); + return res.intValue(); + } + + /** + * read16 + * + * @return int + * @throws ServiceLocationException + * @throws IOException + */ + public int read16() throws ServiceLocationException, IOException { + Integer res = doRead16(); + if (res == null) throw new ServiceLocationException( + ServiceLocationException.PARSE_ERROR, + "Failed to read 2-byte-long field!" + ); + return res.intValue(); + } + + /** + * read24 + * + * @return int + * @throws ServiceLocationException + * @throws IOException + */ + public int read24() throws ServiceLocationException, IOException { + Integer res = doRead24(); + if (res == null) throw new ServiceLocationException( + ServiceLocationException.PARSE_ERROR, + "Failed to read 3-byte-long field!" + ); + return res.intValue(); + } + + /** + * read32 + * + * @return long + * @throws ServiceLocationException + * @throws IOException + */ + public long read32() throws ServiceLocationException, IOException { + Long res = doRead32(); + if (res == null) throw new ServiceLocationException( + ServiceLocationException.PARSE_ERROR, + "Failed to read 4-byte-long field!" + ); + return res.longValue(); + } + + private Integer doRead8() throws IOException { + int res = this.iInStr.read(); + return res < 0 ? null : Integer.valueOf(res); + } + + private Integer doRead16() throws IOException { + int cnt = this.iInStr.read(this.iBBuf, 0, 2); + if (cnt != 2) return null; + return Integer.valueOf((this.iBBuf[0] & 0xff) << 8 | this.iBBuf[1] & 0xff); + } + + private Integer doRead24() throws IOException { + int cnt = this.iInStr.read(this.iBBuf, 0, 3); + if (cnt != 3) return null; + return Integer.valueOf((this.iBBuf[0] & 0xff) << 16 | (this.iBBuf[1] & 0xff) << 8 | this.iBBuf[2] & 0xff); + } + + private Long doRead32() throws IOException { + int cnt = this.iInStr.read(this.iBBuf, 0, 4); + if (cnt != 4) return null; + long res = (this.iBBuf[0] & 0xff) << 8; + res |= (this.iBBuf[1] & 0xff) << 8; + res |= (this.iBBuf[2] & 0xff) << 8; + res |= this.iBBuf[3] & 0xff; + return Long.valueOf(res); + } + + private String readRawString() throws ServiceLocationException, IOException { + Integer lenInt = doRead16(); + if (lenInt == null) return null; + int len = lenInt.intValue(); + if (len <= 0) return null; + byte[] bytes = new byte[len]; + int read = this.iInStr.read(bytes, 0, len); + if (read != len) return null; + try { + return new String(bytes, SLPDefaults.ENCODING); + } catch (UnsupportedEncodingException e) { + throw new ServiceLocationException(ServiceLocationException.INTERNAL_SYSTEM_ERROR, e); + } + } + + private void readStringCollection(Collection pCol) throws ServiceLocationException, IOException { + String rawListStr = readRawString(); + if (rawListStr == null) return; + StringTokenizer tokenizer = new StringTokenizer(rawListStr, ","); + while (tokenizer.hasMoreElements()) pCol.add(Convert.unescape(tokenizer.nextToken())); + } + + private static class AttrListParser { + private int iPos = 0; + + private String iAttrListStr; + + private ArrayList iList = new ArrayList(); + + /** + * Ctor. + * + * @param pAttrListStr + * @throws ServiceLocationException + */ + public AttrListParser(String pAttrListStr) throws ServiceLocationException { + debug("attrListStr=" + pAttrListStr); + this.iAttrListStr = pAttrListStr; + String attrStr; + while ((attrStr = readEntry()) != null) { + debug("attrStr=" + attrStr); + this.iList.add(new ServiceLocationAttribute(attrStr)); + } + } + + /** + * getList + * + * @return List of ServiceLocationAttributes + */ + public List getList() { + return this.iList; + } + + /* + * ( "(" attrID "=" ( value "," )* value ")" ("," / EndOfString ) ) / + * attrID ("," / EndOfString ) + */ + private String readEntry() throws ServiceLocationException { + if (this.iAttrListStr == null) return null; + int lastIdx = this.iAttrListStr.length() - 1; + if (this.iPos == lastIdx) return null; + boolean inBlock = false; + int startPos = this.iPos; + while (true) { + char ch = this.iAttrListStr.charAt(this.iPos); + if (ch == '(') { + if (inBlock || this.iPos != startPos) throw new ServiceLocationException( + ServiceLocationException.PARSE_ERROR, + invalidChar('(') + ); + inBlock = true; + } else if (ch == ')') { + if (!inBlock) throw new ServiceLocationException(ServiceLocationException.PARSE_ERROR, invalidChar(')')); + if (this.iPos == lastIdx) return this.iAttrListStr.substring(startPos); + inBlock = false; + } else { + if (inBlock) { + if (this.iPos == lastIdx) /* + * throw new ServiceLocationException( + * ServiceLocationException.PARSE_ERROR, "There is no + * ')' for '(' !" ); + */ + return this.iAttrListStr.substring(startPos); + } else { + if (ch == ',') { + ++this.iPos; + return this.iAttrListStr.substring(startPos, this.iPos - 1); + } + if (this.iPos == lastIdx) { + return this.iAttrListStr.substring(startPos); + } + } + } + if (this.iPos == lastIdx) throw new ServiceLocationException( + ServiceLocationException.PARSE_ERROR, + "Unexpected end of Attribute list:\n" + this.iAttrListStr + ); + ++this.iPos; + } + } + + /** + * @param ch + */ + private String invalidChar(char ch) { + return "Invalid '(' character in Attribute list:\n" + this.iAttrListStr + "\nat position: " + this.iPos; + } + } + + /** + * @param pMsg + */ + static void debug(String pMsg) { + // System.out.println(pMsg); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/SLPMessage.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/SLPMessage.java similarity index 71% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/SLPMessage.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/SLPMessage.java index 766b0fd..6a4f51c 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/SLPMessage.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/SLPMessage.java @@ -1,223 +1,223 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1892103 2008-02-12 ebak SLP improvements - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.msg; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; -import org.sentrysoftware.wbem.sblim.slp.internal.SLPConfig; -import org.sentrysoftware.wbem.sblim.slp.internal.SLPDefaults; - -/** - * SLPMessage - * - */ -public abstract class SLPMessage implements FunctionIDs { - - // cache it for instance lifetime, do not parse always - private final int iMaxDatagramSize = SLPConfig.getGlobalCfg().getMTU(); - - private MsgHeader iHeader; - - /** - * Ctor. - * - * @param pFunctionID - */ - public SLPMessage(int pFunctionID) { - this(pFunctionID, Util.getLangTag(SLPDefaults.LOCALE)); - } - - /** - * Ctor. - * - * @param pFunctionID - * @param pLangTag - */ - public SLPMessage(int pFunctionID, String pLangTag) { - this(new MsgHeader(MsgHeader.VERSION, pFunctionID, pLangTag, false, pFunctionID == SRV_REG, - false, 0)); - } - - /** - * Ctor. - * - * @param pHeader - */ - public SLPMessage(MsgHeader pHeader) { - this.iHeader = pHeader; - } - - /** - * getHeader - * - * @return MsgHeader - */ - public MsgHeader getHeader() { - return this.iHeader; - } - - /** - * getVersion - * - * @return int - */ - public int getVersion() { - return this.iHeader.getVersion(); - } - - /** - * getFunctionID - * - * @return int - */ - public int getFunctionID() { - return this.iHeader.getFunctionID(); - } - - /** - * getLangTag - * - * @return String - */ - public String getLangTag() { - return this.iHeader.getLangTag(); - } - - /** - * overflows - * - * @return boolean - */ - public boolean overflows() { - return this.iHeader.overflows(); - } - - /** - * fresh - * - * @return boolean - */ - public boolean fresh() { - return this.iHeader.fresh(); - } - - /** - * multicast - * - * @return boolean - */ - public boolean multicast() { - return this.iHeader.multicast(); - } - - /** - * getXID - * - * @return int - */ - public int getXID() { - return this.iHeader.getXID(); - } - - /** - * @see MsgHeader#setXID(int) - * @param pXID - */ - public void setXID(int pXID) { - this.iHeader.setXID(pXID); - } - - /** - * serialize - * - * @param pSetMulticastFlag - * @param pDatagramLimited - * @param pKeepXID - * @return byte[] - * @throws ServiceLocationException - */ - public byte[] serialize(boolean pSetMulticastFlag, boolean pDatagramLimited, boolean pKeepXID) - throws ServiceLocationException { - return serialize(pSetMulticastFlag, pDatagramLimited, pKeepXID, null); - } - - /** - * serialize - * - * @param pSetMulticastFlag - * @param pDatagramLimited - * @param pKeepXID - * @param pOption - * - passed to the serializeBody() method of the inherited - * classes - * @return byte[] - * @throws ServiceLocationException - */ - public byte[] serialize(boolean pSetMulticastFlag, boolean pDatagramLimited, boolean pKeepXID, - SerializeOption pOption) throws ServiceLocationException { - SLPOutputStream bodyOutStr = new SLPOutputStream(pDatagramLimited ? this.iMaxDatagramSize - - this.iHeader.getSize() : -1); - boolean fit = serializeBody(bodyOutStr, pOption); - byte[] bodyBytes = bodyOutStr.toByteArray(); - byte[] headerBytes = this.iHeader.serialize(bodyBytes.length, !fit, pSetMulticastFlag, - pKeepXID); - byte[] bytes = new byte[headerBytes.length + bodyBytes.length]; - System.arraycopy(headerBytes, 0, bytes, 0, headerBytes.length); - System.arraycopy(bodyBytes, 0, bytes, headerBytes.length, bodyBytes.length); - return bytes; - } - - /** - * @return true if all data is written into pOStr (all data fits into size - * limit) - */ - protected abstract boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) - throws ServiceLocationException; - - @Override - public String toString() { - return super.toString() + " " + getXID(); - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1892103 2008-02-12 ebak SLP improvements + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.slp.internal.msg; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import org.metricshub.wbem.sblim.slp.ServiceLocationException; +import org.metricshub.wbem.sblim.slp.internal.SLPConfig; +import org.metricshub.wbem.sblim.slp.internal.SLPDefaults; + +/** + * SLPMessage + * + */ +public abstract class SLPMessage implements FunctionIDs { + // cache it for instance lifetime, do not parse always + private final int iMaxDatagramSize = SLPConfig.getGlobalCfg().getMTU(); + + private MsgHeader iHeader; + + /** + * Ctor. + * + * @param pFunctionID + */ + public SLPMessage(int pFunctionID) { + this(pFunctionID, Util.getLangTag(SLPDefaults.LOCALE)); + } + + /** + * Ctor. + * + * @param pFunctionID + * @param pLangTag + */ + public SLPMessage(int pFunctionID, String pLangTag) { + this(new MsgHeader(MsgHeader.VERSION, pFunctionID, pLangTag, false, pFunctionID == SRV_REG, false, 0)); + } + + /** + * Ctor. + * + * @param pHeader + */ + public SLPMessage(MsgHeader pHeader) { + this.iHeader = pHeader; + } + + /** + * getHeader + * + * @return MsgHeader + */ + public MsgHeader getHeader() { + return this.iHeader; + } + + /** + * getVersion + * + * @return int + */ + public int getVersion() { + return this.iHeader.getVersion(); + } + + /** + * getFunctionID + * + * @return int + */ + public int getFunctionID() { + return this.iHeader.getFunctionID(); + } + + /** + * getLangTag + * + * @return String + */ + public String getLangTag() { + return this.iHeader.getLangTag(); + } + + /** + * overflows + * + * @return boolean + */ + public boolean overflows() { + return this.iHeader.overflows(); + } + + /** + * fresh + * + * @return boolean + */ + public boolean fresh() { + return this.iHeader.fresh(); + } + + /** + * multicast + * + * @return boolean + */ + public boolean multicast() { + return this.iHeader.multicast(); + } + + /** + * getXID + * + * @return int + */ + public int getXID() { + return this.iHeader.getXID(); + } + + /** + * @see MsgHeader#setXID(int) + * @param pXID + */ + public void setXID(int pXID) { + this.iHeader.setXID(pXID); + } + + /** + * serialize + * + * @param pSetMulticastFlag + * @param pDatagramLimited + * @param pKeepXID + * @return byte[] + * @throws ServiceLocationException + */ + public byte[] serialize(boolean pSetMulticastFlag, boolean pDatagramLimited, boolean pKeepXID) + throws ServiceLocationException { + return serialize(pSetMulticastFlag, pDatagramLimited, pKeepXID, null); + } + + /** + * serialize + * + * @param pSetMulticastFlag + * @param pDatagramLimited + * @param pKeepXID + * @param pOption + * - passed to the serializeBody() method of the inherited + * classes + * @return byte[] + * @throws ServiceLocationException + */ + public byte[] serialize( + boolean pSetMulticastFlag, + boolean pDatagramLimited, + boolean pKeepXID, + SerializeOption pOption + ) + throws ServiceLocationException { + SLPOutputStream bodyOutStr = new SLPOutputStream( + pDatagramLimited ? this.iMaxDatagramSize - this.iHeader.getSize() : -1 + ); + boolean fit = serializeBody(bodyOutStr, pOption); + byte[] bodyBytes = bodyOutStr.toByteArray(); + byte[] headerBytes = this.iHeader.serialize(bodyBytes.length, !fit, pSetMulticastFlag, pKeepXID); + byte[] bytes = new byte[headerBytes.length + bodyBytes.length]; + System.arraycopy(headerBytes, 0, bytes, 0, headerBytes.length); + System.arraycopy(bodyBytes, 0, bytes, headerBytes.length, bodyBytes.length); + return bytes; + } + + /** + * @return true if all data is written into pOStr (all data fits into size + * limit) + */ + protected abstract boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) + throws ServiceLocationException; + + @Override + public String toString() { + return super.toString() + " " + getXID(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/SLPOutputStream.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/SLPOutputStream.java similarity index 81% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/SLPOutputStream.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/SLPOutputStream.java index 56ef272..ef3ec73 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/SLPOutputStream.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/SLPOutputStream.java @@ -1,442 +1,435 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2210455 2008-10-30 blaschke-oss Enhance javadoc, fix potential null pointers - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2797696 2009-05-27 raman_arora Input files use unsafe operations - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.msg; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.ByteArrayOutputStream; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationAttribute; -import org.sentrysoftware.wbem.sblim.slp.ServiceType; -import org.sentrysoftware.wbem.sblim.slp.ServiceURL; -import org.sentrysoftware.wbem.sblim.slp.internal.AttributeHandler; -import org.sentrysoftware.wbem.sblim.slp.internal.Convert; -import org.sentrysoftware.wbem.sblim.slp.internal.TRC; - -/** - * SLPOutputStream helps the building of SLP message bytes - * - */ -public class SLPOutputStream { - - private static final int MAX_FIELD_SIZE = 65535; - - private static final byte[] EMPTY_BYTES = new byte[0]; - - private ByteArrayOutputStream iOutStr = new ByteArrayOutputStream(); - - private int iStreamLimit; - - /** - * Ctor. - */ - public SLPOutputStream() { - this(Integer.MAX_VALUE); - } - - /** - * Ctor. - * - * @param pStreamLimit - */ - public SLPOutputStream(int pStreamLimit) { - this.iStreamLimit = pStreamLimit <= 0 ? Integer.MAX_VALUE : pStreamLimit; - } - - /** - * size - * - * @return int - */ - public int size() { - return this.iOutStr.size(); - } - - /** - * freeSpace - * - * @return int - */ - public int freeSpace() { - return this.iStreamLimit - this.iOutStr.size(); - } - - /** - * toByteArray - * - * @return byte[] - */ - public byte[] toByteArray() { - return this.iOutStr.toByteArray(); - } - - /** - * write - * - * @param pBytes - * @return boolean - */ - public boolean write(byte[] pBytes) { - if (freeSpace() < pBytes.length) return false; - writeNoChk(pBytes); - return true; - } - - /** - * write - * - * @param pServType - * @return boolean - */ - public boolean write(ServiceType pServType) { - if (pServType == null) return write((String) null); - return write(pServType.toString()); - } - - /** - * URL_HDR_LENGTH - */ - public static final int URL_HDR_LENGTH = 6; - - /* - * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | - * Reserved | Lifetime | URL Length | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |URL - * len, contd.| URL (variable length) \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |# of - * URL auths | Auth. blocks (if any) \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - /** - * @param pURL - * @return boolean - */ - public boolean write(ServiceURL pURL) { - // URL strings in URL entries are not encoded - String urlStr = pURL.toString(); - byte[] urlStrBytes = Convert.getBytes(urlStr); - if (freeSpace() < URL_HDR_LENGTH + urlStrBytes.length) return false; - writeNoChk8(0); - writeNoChk16(pURL.getLifetime()); - writeNoChk16(urlStrBytes.length); - writeNoChk(urlStrBytes); - writeNoChk8(0); - return true; - } - - /** - * writeURLList - * - * @param pURLList - * @return boolean - */ - @SuppressWarnings("null") - public boolean writeURLList(List pURLList) { - int cnt = pURLList == null ? 0 : pURLList.size(); - if (cnt == 0) return write16(cnt); - SLPOutputStream tmpStr = new SLPOutputStream(); - int i; - for (i = 0; i < cnt; i++) { - tmpStr.write((ServiceURL) pURLList.get(i)); - if (freeSpace() < tmpStr.size() + 2) break; - } - writeNoChk16(i); - writeNoChk(tmpStr.toByteArray()); - return i == cnt; - } - - /** - * writeServTypeList - * - * @param pServTypeList - * @return boolean - */ - public boolean writeServTypeList(List pServTypeList) { - return writeServTypeList(pServTypeList == null ? null : pServTypeList.iterator()); - } - - /** - * writeServTypeList - * - * @param pServTypeItr - * @return boolean - */ - public boolean writeServTypeList(Iterator pServTypeItr) { - if (pServTypeItr == null) return writeStringList((Iterator) null); - ArrayList servTypeList = new ArrayList(); - while (pServTypeItr.hasNext()) - servTypeList.add(((ServiceType) pServTypeItr.next()).toString()); - return writeStringList(servTypeList); - } - - /** - * writeAttributeList - * - * @param pAttrList - * @return boolean - */ - public boolean writeAttributeList(List pAttrList) { - return writeAttributeList(pAttrList == null ? null : pAttrList.iterator()); - } - - /** - * writeAttributeList - * - * @param pAttrItr - * @return boolean - */ - public boolean writeAttributeList(Iterator pAttrItr) { - if (pAttrItr == null) return writeStringList((Iterator) null); - ArrayList attrStrList = new ArrayList(); - while (pAttrItr.hasNext()) - attrStrList.add(AttributeHandler - .buildString((ServiceLocationAttribute) pAttrItr.next())); - return writeStringList(attrStrList, null); - } - - /** - * # of AttrAuths |(if present) Attribute Authentication Blocks... - * - * @param pAuthBlockList - * @return boolean - */ - public boolean writeAuthBlockList(List pAuthBlockList) { - int cnt = pAuthBlockList == null ? 0 : pAuthBlockList.size(); - if (cnt != 0) TRC - .error("Handling of non empty authentication block list is not implemented!"); - return write8(0); - } - - /** - * write - * - * @param pStr - * @return boolean - */ - public boolean write(String pStr) { - return write(pStr, Convert.DEFAULT_RESERVED); - } - - /** - * write - * - * @param pStr - * @param pReservedChars - * @return boolean - */ - public boolean write(String pStr, String pReservedChars) { - byte[] bytes = pStr == null ? EMPTY_BYTES : Convert.getBytes(Convert.escape(pStr, - pReservedChars)); - if (bytes.length > MAX_FIELD_SIZE) return false; - if (freeSpace() < bytes.length + 2) return false; - writeNoChk16(bytes.length); - writeNoChk(bytes); - return true; - } - - /** - * writeStringList - * - * @param pStrList - * @return boolean - */ - public boolean writeStringList(List pStrList) { - return writeStringList(pStrList == null ? null : pStrList.iterator()); - } - - /** - * writeStringList - * - * @param pStrListItr - * @return boolean - */ - public boolean writeStringList(Iterator pStrListItr) { - return writeStringList(pStrListItr, Convert.DEFAULT_RESERVED); - } - - /** - * writeStringList - * - * @param pStrList - * @param pReservedChars - * @return boolean - */ - public boolean writeStringList(List pStrList, String pReservedChars) { - return writeStringList(pStrList == null ? null : pStrList.iterator(), pReservedChars); - } - - /** - * writeStringList - * - * @param pStrListItr - * @param pReservedChars - * @return true if all list items are written to the stream, otherwise false - */ - public boolean writeStringList(Iterator pStrListItr, String pReservedChars) { - ByteArrayOutputStream listByteStr = new ByteArrayOutputStream(); - boolean first = true; - boolean allWritten = true; - if (pStrListItr != null) while (pStrListItr.hasNext()) { - StringBuffer strBuf = new StringBuffer(); - String listItemStr = Convert.escape(pStrListItr.next(), pReservedChars); - if (first) { - first = false; - } else { - strBuf.append(','); - } - strBuf.append(listItemStr); - byte[] listItemBytes = Convert.getBytes(strBuf.toString()); - int currentSize = listByteStr.size() + listItemBytes.length; - if (currentSize > MAX_FIELD_SIZE || currentSize + 2 > freeSpace()) { - allWritten = false; - break; - } - listByteStr.write(listItemBytes, 0, listItemBytes.length); - } - byte[] listBytes = listByteStr.toByteArray(); - writeNoChk16(listBytes.length); - writeNoChk(listBytes); - return allWritten; - } - - /** - * write8 - * - * @param pValue - * @return boolean - */ - public boolean write8(int pValue) { - if (freeSpace() < 1) return false; - writeNoChk8(pValue); - return true; - } - - /** - * write16 - * - * @param pValue - * @return boolean - */ - public boolean write16(int pValue) { - if (freeSpace() < 2) return false; - writeNoChk16(pValue); - return true; - } - - /** - * write24 - * - * @param pValue - * @return boolean - */ - public boolean write24(int pValue) { - if (freeSpace() < 3) return false; - writeNoChk24(pValue); - return true; - } - - /** - * write32 - * - * @param pValue - * @return boolean - */ - public boolean write32(long pValue) { - if (freeSpace() < 4) return false; - writeNoChk32(pValue); - return true; - } - - /** - * writeNoChk - * - * @param pBytes - */ - public void writeNoChk(byte[] pBytes) { - this.iOutStr.write(pBytes, 0, pBytes.length); - } - - /** - * writeNoChk8 - * - * @param pValue - */ - public void writeNoChk8(int pValue) { - this.iOutStr.write(pValue); - } - - /** - * writeNoChk16 - * - * @param pValue - */ - public void writeNoChk16(int pValue) { - this.iOutStr.write((pValue >> 8) & 0xff); - this.iOutStr.write((pValue & 0xff)); - } - - /** - * writeNoChk24 - * - * @param pValue - */ - public void writeNoChk24(int pValue) { - this.iOutStr.write((pValue >> 16) & 0xff); - writeNoChk16(pValue); - } - - /** - * writeNoChk32 - * - * @param pValue - */ - public void writeNoChk32(long pValue) { - this.iOutStr.write((int) ((pValue >> 24) & 0xff)); - writeNoChk24((int) pValue); - } -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2210455 2008-10-30 blaschke-oss Enhance javadoc, fix potential null pointers + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2797696 2009-05-27 raman_arora Input files use unsafe operations + */ + +package org.metricshub.wbem.sblim.slp.internal.msg; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.ByteArrayOutputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import org.metricshub.wbem.sblim.slp.ServiceLocationAttribute; +import org.metricshub.wbem.sblim.slp.ServiceType; +import org.metricshub.wbem.sblim.slp.ServiceURL; +import org.metricshub.wbem.sblim.slp.internal.AttributeHandler; +import org.metricshub.wbem.sblim.slp.internal.Convert; +import org.metricshub.wbem.sblim.slp.internal.TRC; + +/** + * SLPOutputStream helps the building of SLP message bytes + * + */ +public class SLPOutputStream { + private static final int MAX_FIELD_SIZE = 65535; + + private static final byte[] EMPTY_BYTES = new byte[0]; + + private ByteArrayOutputStream iOutStr = new ByteArrayOutputStream(); + + private int iStreamLimit; + + /** + * Ctor. + */ + public SLPOutputStream() { + this(Integer.MAX_VALUE); + } + + /** + * Ctor. + * + * @param pStreamLimit + */ + public SLPOutputStream(int pStreamLimit) { + this.iStreamLimit = pStreamLimit <= 0 ? Integer.MAX_VALUE : pStreamLimit; + } + + /** + * size + * + * @return int + */ + public int size() { + return this.iOutStr.size(); + } + + /** + * freeSpace + * + * @return int + */ + public int freeSpace() { + return this.iStreamLimit - this.iOutStr.size(); + } + + /** + * toByteArray + * + * @return byte[] + */ + public byte[] toByteArray() { + return this.iOutStr.toByteArray(); + } + + /** + * write + * + * @param pBytes + * @return boolean + */ + public boolean write(byte[] pBytes) { + if (freeSpace() < pBytes.length) return false; + writeNoChk(pBytes); + return true; + } + + /** + * write + * + * @param pServType + * @return boolean + */ + public boolean write(ServiceType pServType) { + if (pServType == null) return write((String) null); + return write(pServType.toString()); + } + + /** + * URL_HDR_LENGTH + */ + public static final int URL_HDR_LENGTH = 6; + + /* + * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | + * Reserved | Lifetime | URL Length | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |URL + * len, contd.| URL (variable length) \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |# of + * URL auths | Auth. blocks (if any) \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + /** + * @param pURL + * @return boolean + */ + public boolean write(ServiceURL pURL) { + // URL strings in URL entries are not encoded + String urlStr = pURL.toString(); + byte[] urlStrBytes = Convert.getBytes(urlStr); + if (freeSpace() < URL_HDR_LENGTH + urlStrBytes.length) return false; + writeNoChk8(0); + writeNoChk16(pURL.getLifetime()); + writeNoChk16(urlStrBytes.length); + writeNoChk(urlStrBytes); + writeNoChk8(0); + return true; + } + + /** + * writeURLList + * + * @param pURLList + * @return boolean + */ + @SuppressWarnings("null") + public boolean writeURLList(List pURLList) { + int cnt = pURLList == null ? 0 : pURLList.size(); + if (cnt == 0) return write16(cnt); + SLPOutputStream tmpStr = new SLPOutputStream(); + int i; + for (i = 0; i < cnt; i++) { + tmpStr.write((ServiceURL) pURLList.get(i)); + if (freeSpace() < tmpStr.size() + 2) break; + } + writeNoChk16(i); + writeNoChk(tmpStr.toByteArray()); + return i == cnt; + } + + /** + * writeServTypeList + * + * @param pServTypeList + * @return boolean + */ + public boolean writeServTypeList(List pServTypeList) { + return writeServTypeList(pServTypeList == null ? null : pServTypeList.iterator()); + } + + /** + * writeServTypeList + * + * @param pServTypeItr + * @return boolean + */ + public boolean writeServTypeList(Iterator pServTypeItr) { + if (pServTypeItr == null) return writeStringList((Iterator) null); + ArrayList servTypeList = new ArrayList(); + while (pServTypeItr.hasNext()) servTypeList.add(((ServiceType) pServTypeItr.next()).toString()); + return writeStringList(servTypeList); + } + + /** + * writeAttributeList + * + * @param pAttrList + * @return boolean + */ + public boolean writeAttributeList(List pAttrList) { + return writeAttributeList(pAttrList == null ? null : pAttrList.iterator()); + } + + /** + * writeAttributeList + * + * @param pAttrItr + * @return boolean + */ + public boolean writeAttributeList(Iterator pAttrItr) { + if (pAttrItr == null) return writeStringList((Iterator) null); + ArrayList attrStrList = new ArrayList(); + while (pAttrItr.hasNext()) attrStrList.add( + AttributeHandler.buildString((ServiceLocationAttribute) pAttrItr.next()) + ); + return writeStringList(attrStrList, null); + } + + /** + * # of AttrAuths |(if present) Attribute Authentication Blocks... + * + * @param pAuthBlockList + * @return boolean + */ + public boolean writeAuthBlockList(List pAuthBlockList) { + int cnt = pAuthBlockList == null ? 0 : pAuthBlockList.size(); + if (cnt != 0) TRC.error("Handling of non empty authentication block list is not implemented!"); + return write8(0); + } + + /** + * write + * + * @param pStr + * @return boolean + */ + public boolean write(String pStr) { + return write(pStr, Convert.DEFAULT_RESERVED); + } + + /** + * write + * + * @param pStr + * @param pReservedChars + * @return boolean + */ + public boolean write(String pStr, String pReservedChars) { + byte[] bytes = pStr == null ? EMPTY_BYTES : Convert.getBytes(Convert.escape(pStr, pReservedChars)); + if (bytes.length > MAX_FIELD_SIZE) return false; + if (freeSpace() < bytes.length + 2) return false; + writeNoChk16(bytes.length); + writeNoChk(bytes); + return true; + } + + /** + * writeStringList + * + * @param pStrList + * @return boolean + */ + public boolean writeStringList(List pStrList) { + return writeStringList(pStrList == null ? null : pStrList.iterator()); + } + + /** + * writeStringList + * + * @param pStrListItr + * @return boolean + */ + public boolean writeStringList(Iterator pStrListItr) { + return writeStringList(pStrListItr, Convert.DEFAULT_RESERVED); + } + + /** + * writeStringList + * + * @param pStrList + * @param pReservedChars + * @return boolean + */ + public boolean writeStringList(List pStrList, String pReservedChars) { + return writeStringList(pStrList == null ? null : pStrList.iterator(), pReservedChars); + } + + /** + * writeStringList + * + * @param pStrListItr + * @param pReservedChars + * @return true if all list items are written to the stream, otherwise false + */ + public boolean writeStringList(Iterator pStrListItr, String pReservedChars) { + ByteArrayOutputStream listByteStr = new ByteArrayOutputStream(); + boolean first = true; + boolean allWritten = true; + if (pStrListItr != null) while (pStrListItr.hasNext()) { + StringBuffer strBuf = new StringBuffer(); + String listItemStr = Convert.escape(pStrListItr.next(), pReservedChars); + if (first) { + first = false; + } else { + strBuf.append(','); + } + strBuf.append(listItemStr); + byte[] listItemBytes = Convert.getBytes(strBuf.toString()); + int currentSize = listByteStr.size() + listItemBytes.length; + if (currentSize > MAX_FIELD_SIZE || currentSize + 2 > freeSpace()) { + allWritten = false; + break; + } + listByteStr.write(listItemBytes, 0, listItemBytes.length); + } + byte[] listBytes = listByteStr.toByteArray(); + writeNoChk16(listBytes.length); + writeNoChk(listBytes); + return allWritten; + } + + /** + * write8 + * + * @param pValue + * @return boolean + */ + public boolean write8(int pValue) { + if (freeSpace() < 1) return false; + writeNoChk8(pValue); + return true; + } + + /** + * write16 + * + * @param pValue + * @return boolean + */ + public boolean write16(int pValue) { + if (freeSpace() < 2) return false; + writeNoChk16(pValue); + return true; + } + + /** + * write24 + * + * @param pValue + * @return boolean + */ + public boolean write24(int pValue) { + if (freeSpace() < 3) return false; + writeNoChk24(pValue); + return true; + } + + /** + * write32 + * + * @param pValue + * @return boolean + */ + public boolean write32(long pValue) { + if (freeSpace() < 4) return false; + writeNoChk32(pValue); + return true; + } + + /** + * writeNoChk + * + * @param pBytes + */ + public void writeNoChk(byte[] pBytes) { + this.iOutStr.write(pBytes, 0, pBytes.length); + } + + /** + * writeNoChk8 + * + * @param pValue + */ + public void writeNoChk8(int pValue) { + this.iOutStr.write(pValue); + } + + /** + * writeNoChk16 + * + * @param pValue + */ + public void writeNoChk16(int pValue) { + this.iOutStr.write((pValue >> 8) & 0xff); + this.iOutStr.write((pValue & 0xff)); + } + + /** + * writeNoChk24 + * + * @param pValue + */ + public void writeNoChk24(int pValue) { + this.iOutStr.write((pValue >> 16) & 0xff); + writeNoChk16(pValue); + } + + /** + * writeNoChk32 + * + * @param pValue + */ + public void writeNoChk32(long pValue) { + this.iOutStr.write((int) ((pValue >> 24) & 0xff)); + writeNoChk24((int) pValue); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/SerializeOption.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/SerializeOption.java similarity index 61% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/SerializeOption.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/SerializeOption.java index 1b63262..ed7e464 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/SerializeOption.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/SerializeOption.java @@ -1,56 +1,53 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1892103 2008-02-12 ebak SLP improvements - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.msg; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * Inherited classes of SerializeOption provide additional serialization - * parameters for the inherited SLPMessage classes. - * - */ -public abstract class SerializeOption { - - /* - * Inherited classes add the methods. - */ - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1892103 2008-02-12 ebak SLP improvements + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.slp.internal.msg; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/** + * Inherited classes of SerializeOption provide additional serialization + * parameters for the inherited SLPMessage classes. + * + */ +public abstract class SerializeOption { + /* + * Inherited classes add the methods. + */ + +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ServiceAcknowledgment.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ServiceAcknowledgment.java similarity index 71% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ServiceAcknowledgment.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ServiceAcknowledgment.java index 2c8f445..279842f 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ServiceAcknowledgment.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ServiceAcknowledgment.java @@ -1,122 +1,117 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1892103 2008-02-12 ebak SLP improvements - * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.msg; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.util.Iterator; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; - -/** - * ServiceAcknowledgment message - * - */ -public class ServiceAcknowledgment extends ReplyMessage { - - /** - * parse - * - * @param pHdr - * @param pInStr - * @return SLPMessage - * @throws ServiceLocationException - * @throws IOException - */ - public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException { - return new ServiceAcknowledgment(pHdr, pInStr.read16()); - } - - /** - * Ctor. - * - * @param pErrorCode - */ - public ServiceAcknowledgment(int pErrorCode) { - super(SRV_ACK, pErrorCode); - } - - /** - * Ctor. - * - * @param pLangTag - * @param pErrorCode - */ - public ServiceAcknowledgment(String pLangTag, int pErrorCode) { - super(SRV_ACK, pLangTag, pErrorCode); - } - - /** - * Ctor. - * - * @param pHeader - * @param pErrorCode - */ - public ServiceAcknowledgment(MsgHeader pHeader, int pErrorCode) { - super(pHeader, pErrorCode); - } - - @Override - public Iterator getResultIterator() { - // this message doesn't have iterable results - return null; - } - - /** - * @param pOption - */ - @Override - protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) { - return pOutStr.write16(getErrorCode()); - } - - @Override - public Iterator getExceptionIterator() { - // this message doesn't have exception table - return null; - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1892103 2008-02-12 ebak SLP improvements + * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp.internal.msg; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.util.Iterator; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; + +/** + * ServiceAcknowledgment message + * + */ +public class ServiceAcknowledgment extends ReplyMessage { + + /** + * parse + * + * @param pHdr + * @param pInStr + * @return SLPMessage + * @throws ServiceLocationException + * @throws IOException + */ + public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { + return new ServiceAcknowledgment(pHdr, pInStr.read16()); + } + + /** + * Ctor. + * + * @param pErrorCode + */ + public ServiceAcknowledgment(int pErrorCode) { + super(SRV_ACK, pErrorCode); + } + + /** + * Ctor. + * + * @param pLangTag + * @param pErrorCode + */ + public ServiceAcknowledgment(String pLangTag, int pErrorCode) { + super(SRV_ACK, pLangTag, pErrorCode); + } + + /** + * Ctor. + * + * @param pHeader + * @param pErrorCode + */ + public ServiceAcknowledgment(MsgHeader pHeader, int pErrorCode) { + super(pHeader, pErrorCode); + } + + @Override + public Iterator getResultIterator() { + // this message doesn't have iterable results + return null; + } + + /** + * @param pOption + */ + @Override + protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) { + return pOutStr.write16(getErrorCode()); + } + + @Override + public Iterator getExceptionIterator() { + // this message doesn't have exception table + return null; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ServiceDeregistration.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ServiceDeregistration.java similarity index 74% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ServiceDeregistration.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ServiceDeregistration.java index 7054afa..e88a4c3 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ServiceDeregistration.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ServiceDeregistration.java @@ -1,167 +1,159 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1892103 2008-02-12 ebak SLP improvements - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.msg; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.util.List; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; -import org.sentrysoftware.wbem.sblim.slp.ServiceURL; - -/* - * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service - * Location header (function = SrvDeReg = 4) | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of - * | \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | URL Entry \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of - * | \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ The - * is a of attribute tags to deregister as defined in - * Section 9.4. If no is present, the SrvDeReg deregisters the - * service in all languages it has been registered in. If the is - * present, the SrvDeReg deregisters the attributes whose tags are listed in the - * tag spec. Services registered with Authentication Blocks MUST NOT include a - * in a SrvDeReg message: A DA will respond with an - * AUTHENTICATION_FAILED error in this case. - */ - -/** - * ServiceDeregistration message - * - */ -public class ServiceDeregistration extends SLPMessage { - - private List iScopeList; - - private ServiceURL iURL; - - private List iTagList; - - /** - * parse - * - * @param pHdr - * @param pInStr - * @return SLPMessage - * @throws ServiceLocationException - * @throws IOException - */ - public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException { - return new ServiceDeregistration(pHdr, pInStr.readStringList(), pInStr.readURL(), pInStr - .readStringList()); - } - - /** - * Ctor. - * - * @param pScopeList - * - list of scope strings - * @param pURL - * @param pTagList - */ - public ServiceDeregistration(List pScopeList, ServiceURL pURL, List pTagList) { - super(SRV_DEREG); - init(pScopeList, pURL, pTagList); - } - - /** - * Ctor. - * - * @param pLangTag - * @param pScopeList - * - list of scope strings - * @param pURL - * @param pTagList - */ - public ServiceDeregistration(String pLangTag, List pScopeList, ServiceURL pURL, - List pTagList) { - super(SRV_DEREG, pLangTag); - init(pScopeList, pURL, pTagList); - } - - /** - * Ctor. - * - * @param pHeader - * @param pScopeList - * - list of scope strings - * @param pURL - * @param pTagList - */ - public ServiceDeregistration(MsgHeader pHeader, List pScopeList, ServiceURL pURL, - List pTagList) { - super(pHeader); - init(pScopeList, pURL, pTagList); - } - - /** - * getServiceURL - * - * @return ServiceURL - */ - public ServiceURL getServiceURL() { - return this.iURL; - } - - /** - * @param pOption - */ - @Override - protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) { - return pOutStr.writeStringList(this.iScopeList) && pOutStr.write(this.iURL) - && pOutStr.writeStringList(this.iTagList); - } - - private void init(List pScopeList, ServiceURL pURL, List pTagList) { - this.iScopeList = pScopeList; - this.iURL = pURL; - this.iTagList = pTagList; - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1892103 2008-02-12 ebak SLP improvements + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp.internal.msg; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.util.List; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; +import org.metricshub.wbem.sblim.slp.ServiceURL; + +/* + * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service + * Location header (function = SrvDeReg = 4) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of + * | \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | URL Entry \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of + * | \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ The + * is a of attribute tags to deregister as defined in + * Section 9.4. If no is present, the SrvDeReg deregisters the + * service in all languages it has been registered in. If the is + * present, the SrvDeReg deregisters the attributes whose tags are listed in the + * tag spec. Services registered with Authentication Blocks MUST NOT include a + * in a SrvDeReg message: A DA will respond with an + * AUTHENTICATION_FAILED error in this case. + */ + +/** + * ServiceDeregistration message + * + */ +public class ServiceDeregistration extends SLPMessage { + private List iScopeList; + + private ServiceURL iURL; + + private List iTagList; + + /** + * parse + * + * @param pHdr + * @param pInStr + * @return SLPMessage + * @throws ServiceLocationException + * @throws IOException + */ + public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { + return new ServiceDeregistration(pHdr, pInStr.readStringList(), pInStr.readURL(), pInStr.readStringList()); + } + + /** + * Ctor. + * + * @param pScopeList + * - list of scope strings + * @param pURL + * @param pTagList + */ + public ServiceDeregistration(List pScopeList, ServiceURL pURL, List pTagList) { + super(SRV_DEREG); + init(pScopeList, pURL, pTagList); + } + + /** + * Ctor. + * + * @param pLangTag + * @param pScopeList + * - list of scope strings + * @param pURL + * @param pTagList + */ + public ServiceDeregistration(String pLangTag, List pScopeList, ServiceURL pURL, List pTagList) { + super(SRV_DEREG, pLangTag); + init(pScopeList, pURL, pTagList); + } + + /** + * Ctor. + * + * @param pHeader + * @param pScopeList + * - list of scope strings + * @param pURL + * @param pTagList + */ + public ServiceDeregistration(MsgHeader pHeader, List pScopeList, ServiceURL pURL, List pTagList) { + super(pHeader); + init(pScopeList, pURL, pTagList); + } + + /** + * getServiceURL + * + * @return ServiceURL + */ + public ServiceURL getServiceURL() { + return this.iURL; + } + + /** + * @param pOption + */ + @Override + protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) { + return ( + pOutStr.writeStringList(this.iScopeList) && pOutStr.write(this.iURL) && pOutStr.writeStringList(this.iTagList) + ); + } + + private void init(List pScopeList, ServiceURL pURL, List pTagList) { + this.iScopeList = pScopeList; + this.iURL = pURL; + this.iTagList = pTagList; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ServiceRegistration.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ServiceRegistration.java similarity index 65% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ServiceRegistration.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ServiceRegistration.java index 0a15908..a396138 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ServiceRegistration.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ServiceRegistration.java @@ -1,197 +1,217 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1892103 2008-02-12 ebak SLP improvements - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.msg; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.util.List; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationAttribute; -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; -import org.sentrysoftware.wbem.sblim.slp.ServiceURL; - -/* - * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service - * Location header (function = SrvReg = 3) | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | - * \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of - * service type string | \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of - * | \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of - * attr-list string | \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |# of - * AttrAuths |(if present) Attribute Authentication Blocks...\ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ -/** - * ServiceRegistration message - * - */ -public class ServiceRegistration extends SLPMessage { - - private ServiceURL iServURL; - - private List iScopeList; - - private List iAttrList; - - private List iAuthBlockList; - - /** - * parse - * - * @param pHdr - * @param pInStr - * @return SLPMessage - * @throws ServiceLocationException - * @throws IOException - */ - public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException { - ServiceURL url = pInStr.readURL(); - pInStr.readServiceType(); // FIXME reading dummy SrvType. Correct? - return new ServiceRegistration(pHdr, url, pInStr.readStringList(), pInStr - .readAttributeList(), pInStr.readAuthBlockList()); - } - - /** - * Ctor. - * - * @param pServURL - * @param pScopeList - * - list of scope strings - * @param pAttrList - * - list of ServiceLocationAttributes - * @param pAuthBlockList - */ - public ServiceRegistration(ServiceURL pServURL, List pScopeList, - List pAttrList, List pAuthBlockList) { - super(SRV_REG); - init(pServURL, pScopeList, pAttrList, pAuthBlockList); - } - - /** - * Ctor. - * - * @param pLangTag - * @param pServURL - * @param pScopeList - * - list of scope strings - * @param pAttrList - * - list of ServiceLocationAttributes - * @param pAuthBlockList - */ - public ServiceRegistration(String pLangTag, ServiceURL pServURL, List pScopeList, - List pAttrList, List pAuthBlockList) { - super(SRV_REG, pLangTag); - init(pServURL, pScopeList, pAttrList, pAuthBlockList); - } - - /** - * Ctor. - * - * @param pHeader - * @param pServURL - * @param pScopeList - * - list of scope strings - * @param pAttrList - * - list of ServiceLocationAttributes - * @param pAuthBlockList - */ - public ServiceRegistration(MsgHeader pHeader, ServiceURL pServURL, List pScopeList, - List pAttrList, List pAuthBlockList) { - super(pHeader); - init(pServURL, pScopeList, pAttrList, pAuthBlockList); - } - - /** - * getServiceURL - * - * @return ServiceURL - */ - public ServiceURL getServiceURL() { - return this.iServURL; - } - - /** - * getScopeList - * - * @return List - */ - public List getScopeList() { - return this.iScopeList; - } - - /** - * getAttributeList - * - * @return List - */ - public List getAttributeList() { - return this.iAttrList; - } - - /** - * @param pOption - */ - @Override - protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) { - return pOutStr.write(this.iServURL) && pOutStr.write(this.iServURL.getServiceType()) - && pOutStr.writeStringList(this.iScopeList) - && pOutStr.writeAttributeList(this.iAttrList) - && pOutStr.writeAuthBlockList(this.iAuthBlockList); - } - - private void init(ServiceURL pServURL, List pScopeList, - List pAttrList, List pAuthBlockList) { - this.iServURL = pServURL; - this.iScopeList = pScopeList; - this.iAttrList = pAttrList; - this.iAuthBlockList = pAuthBlockList; - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1892103 2008-02-12 ebak SLP improvements + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp.internal.msg; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.util.List; +import org.metricshub.wbem.sblim.slp.ServiceLocationAttribute; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; +import org.metricshub.wbem.sblim.slp.ServiceURL; + +/* + * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service + * Location header (function = SrvReg = 3) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | + * \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of + * service type string | \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of + * | \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of + * attr-list string | \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |# of + * AttrAuths |(if present) Attribute Authentication Blocks...\ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ +/** + * ServiceRegistration message + * + */ +public class ServiceRegistration extends SLPMessage { + private ServiceURL iServURL; + + private List iScopeList; + + private List iAttrList; + + private List iAuthBlockList; + + /** + * parse + * + * @param pHdr + * @param pInStr + * @return SLPMessage + * @throws ServiceLocationException + * @throws IOException + */ + public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { + ServiceURL url = pInStr.readURL(); + pInStr.readServiceType(); // FIXME reading dummy SrvType. Correct? + return new ServiceRegistration( + pHdr, + url, + pInStr.readStringList(), + pInStr.readAttributeList(), + pInStr.readAuthBlockList() + ); + } + + /** + * Ctor. + * + * @param pServURL + * @param pScopeList + * - list of scope strings + * @param pAttrList + * - list of ServiceLocationAttributes + * @param pAuthBlockList + */ + public ServiceRegistration( + ServiceURL pServURL, + List pScopeList, + List pAttrList, + List pAuthBlockList + ) { + super(SRV_REG); + init(pServURL, pScopeList, pAttrList, pAuthBlockList); + } + + /** + * Ctor. + * + * @param pLangTag + * @param pServURL + * @param pScopeList + * - list of scope strings + * @param pAttrList + * - list of ServiceLocationAttributes + * @param pAuthBlockList + */ + public ServiceRegistration( + String pLangTag, + ServiceURL pServURL, + List pScopeList, + List pAttrList, + List pAuthBlockList + ) { + super(SRV_REG, pLangTag); + init(pServURL, pScopeList, pAttrList, pAuthBlockList); + } + + /** + * Ctor. + * + * @param pHeader + * @param pServURL + * @param pScopeList + * - list of scope strings + * @param pAttrList + * - list of ServiceLocationAttributes + * @param pAuthBlockList + */ + public ServiceRegistration( + MsgHeader pHeader, + ServiceURL pServURL, + List pScopeList, + List pAttrList, + List pAuthBlockList + ) { + super(pHeader); + init(pServURL, pScopeList, pAttrList, pAuthBlockList); + } + + /** + * getServiceURL + * + * @return ServiceURL + */ + public ServiceURL getServiceURL() { + return this.iServURL; + } + + /** + * getScopeList + * + * @return List + */ + public List getScopeList() { + return this.iScopeList; + } + + /** + * getAttributeList + * + * @return List + */ + public List getAttributeList() { + return this.iAttrList; + } + + /** + * @param pOption + */ + @Override + protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) { + return ( + pOutStr.write(this.iServURL) && + pOutStr.write(this.iServURL.getServiceType()) && + pOutStr.writeStringList(this.iScopeList) && + pOutStr.writeAttributeList(this.iAttrList) && + pOutStr.writeAuthBlockList(this.iAuthBlockList) + ); + } + + private void init( + ServiceURL pServURL, + List pScopeList, + List pAttrList, + List pAuthBlockList + ) { + this.iServURL = pServURL; + this.iScopeList = pScopeList; + this.iAttrList = pAttrList; + this.iAuthBlockList = pAuthBlockList; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ServiceReply.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ServiceReply.java similarity index 77% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ServiceReply.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ServiceReply.java index 27a9903..4e886ff 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ServiceReply.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ServiceReply.java @@ -1,185 +1,177 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1892103 2008-02-12 ebak SLP improvements - * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.msg; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; -import org.sentrysoftware.wbem.sblim.slp.ServiceURL; - -/* - * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service - * Location header (function = SrvRply = 2) | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Error - * Code | URL Entry count | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ... \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ -/** - * ServiceReply message - * - */ -public class ServiceReply extends ReplyMessage { - - private List iURLEntries; - - private List iURLExceptions; - - /** - * parse - * - * @param pHdr - * @param pInStr - * @return SLPMessage - * @throws ServiceLocationException - * @throws IOException - */ - public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException { - int errorCode = pInStr.read16(); - ArrayList urlExceptions = new ArrayList(); - List urlEntries = pInStr.readUrlList(urlExceptions); - return new ServiceReply(pHdr, errorCode, urlEntries, urlExceptions); - } - - /** - * Ctor. - * - * @param pErrorCode - * @param pURLEntries - * - list of ServiceURLs - */ - public ServiceReply(int pErrorCode, List pURLEntries) { - super(SRV_RPLY, pErrorCode); - this.iURLEntries = pURLEntries; - } - - /** - * Ctor. - * - * @param pLangTag - * @param pErrorCode - * @param pURLEntries - * - list of ServiceURLs - * @param pURLExceptions - * - list of URL Exceptions - */ - public ServiceReply(String pLangTag, int pErrorCode, List pURLEntries, - List pURLExceptions) { - super(SRV_RPLY, pLangTag, pErrorCode); - this.iURLEntries = pURLEntries; - this.iURLExceptions = pURLExceptions; - } - - /** - * Ctor. - * - * @param pHeader - * @param pErrorCode - * @param pURLEntries - * - list of ServiceURLs - * @param pURLExceptions - * - list of URL Exceptions - */ - public ServiceReply(MsgHeader pHeader, int pErrorCode, List pURLEntries, - List pURLExceptions) { - super(pHeader, pErrorCode); - this.iURLEntries = pURLEntries; - this.iURLExceptions = pURLExceptions; - } - - /** - * getResultIterator - * - * @return iterator of URL Exception list - */ - @Override - public Iterator getResultIterator() { - return this.iURLEntries == null ? null : this.iURLEntries.iterator(); - } - - /** - * getExceptionIterator - * - * @return iterator of URL Exception list - */ - @Override - public Iterator getExceptionIterator() { - return this.iURLExceptions == null ? null : this.iURLExceptions.iterator(); - } - - /** - * getURLEntries - * - * @return list of ServiceURLs - */ - public List getURLEntries() { - return this.iURLEntries; - } - - /** - * getURLExceptions - * - * @return list of URL Exceptions - */ - public List getURLExceptions() { - return this.iURLExceptions; - } - - /** - * @param pOption - */ - @Override - protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) { - return pOutStr.write16(getErrorCode()) && pOutStr.writeURLList(this.iURLEntries); - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1892103 2008-02-12 ebak SLP improvements + * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp.internal.msg; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; +import org.metricshub.wbem.sblim.slp.ServiceURL; + +/* + * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service + * Location header (function = SrvRply = 2) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Error + * Code | URL Entry count | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ... \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ +/** + * ServiceReply message + * + */ +public class ServiceReply extends ReplyMessage { + private List iURLEntries; + + private List iURLExceptions; + + /** + * parse + * + * @param pHdr + * @param pInStr + * @return SLPMessage + * @throws ServiceLocationException + * @throws IOException + */ + public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { + int errorCode = pInStr.read16(); + ArrayList urlExceptions = new ArrayList(); + List urlEntries = pInStr.readUrlList(urlExceptions); + return new ServiceReply(pHdr, errorCode, urlEntries, urlExceptions); + } + + /** + * Ctor. + * + * @param pErrorCode + * @param pURLEntries + * - list of ServiceURLs + */ + public ServiceReply(int pErrorCode, List pURLEntries) { + super(SRV_RPLY, pErrorCode); + this.iURLEntries = pURLEntries; + } + + /** + * Ctor. + * + * @param pLangTag + * @param pErrorCode + * @param pURLEntries + * - list of ServiceURLs + * @param pURLExceptions + * - list of URL Exceptions + */ + public ServiceReply(String pLangTag, int pErrorCode, List pURLEntries, List pURLExceptions) { + super(SRV_RPLY, pLangTag, pErrorCode); + this.iURLEntries = pURLEntries; + this.iURLExceptions = pURLExceptions; + } + + /** + * Ctor. + * + * @param pHeader + * @param pErrorCode + * @param pURLEntries + * - list of ServiceURLs + * @param pURLExceptions + * - list of URL Exceptions + */ + public ServiceReply(MsgHeader pHeader, int pErrorCode, List pURLEntries, List pURLExceptions) { + super(pHeader, pErrorCode); + this.iURLEntries = pURLEntries; + this.iURLExceptions = pURLExceptions; + } + + /** + * getResultIterator + * + * @return iterator of URL Exception list + */ + @Override + public Iterator getResultIterator() { + return this.iURLEntries == null ? null : this.iURLEntries.iterator(); + } + + /** + * getExceptionIterator + * + * @return iterator of URL Exception list + */ + @Override + public Iterator getExceptionIterator() { + return this.iURLExceptions == null ? null : this.iURLExceptions.iterator(); + } + + /** + * getURLEntries + * + * @return list of ServiceURLs + */ + public List getURLEntries() { + return this.iURLEntries; + } + + /** + * getURLExceptions + * + * @return list of URL Exceptions + */ + public List getURLExceptions() { + return this.iURLExceptions; + } + + /** + * @param pOption + */ + @Override + protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) { + return pOutStr.write16(getErrorCode()) && pOutStr.writeURLList(this.iURLEntries); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ServiceRequest.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ServiceRequest.java similarity index 69% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ServiceRequest.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ServiceRequest.java index 72649d1..e3ac6ad 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ServiceRequest.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ServiceRequest.java @@ -1,189 +1,206 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1892103 2008-02-15 ebak SLP improvements - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.msg; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.util.List; -import java.util.SortedSet; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; -import org.sentrysoftware.wbem.sblim.slp.ServiceType; - -/* - * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service - * Location header (function = SrvRqst = 1) | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of - * | String \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of - * | String \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of - * | String \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of - * predicate string | Service Request \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of - * string | String \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - -/* - * The string indicates a SLP SPI that the requester has been - * configured with. If this string is omitted, the responder does not include - * any Authentication Blocks in its reply. If it is included, the responder MUST - * return a reply which has an associated authentication block with the SLP SPI - * in the SrvRqst. If no replies may be returned because the SLP SPI is not - * supported, the responder returns an AUTHENTICATION_UNKNOWN error. - */ - -/** - * ServiceRequest message - * - */ -public class ServiceRequest extends RequestMessage { - - private ServiceType iServiceType; - - private String iPredicate, iSlpSpi; - - private static final int[] ALLOWED_RSPS = { SRV_RPLY, DA_ADVERT, SA_ADVERT }; - - /** - * parse - * - * @param pHdr - * @param pInStr - * @return SLPMessage - * @throws ServiceLocationException - * @throws IOException - */ - public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException { - return new ServiceRequest(pHdr, pInStr.readStringSet(), // prevResponders - pInStr.readServiceType(), // serviceType - pInStr.readStringList(), // scopeList - pInStr.readString(), // predicate - pInStr.readString() // SlpSpi - ); - } - - /** - * Ctor. - * - * @param pLangTag - * @param pPrevResponderSet - * - set of address strings - * @param pServiceType - * @param pScopeList - * - list of scope strings - * @param pPredicate - * @param pSlpSpi - */ - public ServiceRequest(String pLangTag, SortedSet pPrevResponderSet, - ServiceType pServiceType, List pScopeList, String pPredicate, String pSlpSpi) { - super(SRV_RQST, pLangTag, pPrevResponderSet, pScopeList); - init(pServiceType, pPredicate, pSlpSpi); - } - - /** - * Ctor. - * - * @param pPrevResponderSet - * - set of address strings - * @param pServiceType - * @param pScopeList - * - list of scope strings - * @param pPredicate - * @param pSlpSpi - */ - public ServiceRequest(SortedSet pPrevResponderSet, ServiceType pServiceType, - List pScopeList, String pPredicate, String pSlpSpi) { - super(SRV_RQST, pPrevResponderSet, pScopeList); - init(pServiceType, pPredicate, pSlpSpi); - } - - /** - * @param pHeader - * @param pPrevResponderSet - * - set of address strings - * @param pServiceType - * @param pScopeList - * - list of scope strings - * @param pPredicate - * - LDAPv3 search filter - * @param pSlpSpi - */ - public ServiceRequest(MsgHeader pHeader, SortedSet pPrevResponderSet, - ServiceType pServiceType, List pScopeList, String pPredicate, String pSlpSpi) { - super(pHeader, pPrevResponderSet, pScopeList); - init(pServiceType, pPredicate, pSlpSpi); - } - - /** - * getServiceType - * - * @return ServiceType - */ - public ServiceType getServiceType() { - return this.iServiceType; - } - - @Override - protected boolean serializeRequestBody(SLPOutputStream pOutStr) { - return pOutStr.write(this.iServiceType) && pOutStr.writeStringList(getScopeList()) - && pOutStr.write(this.iPredicate) && pOutStr.write(this.iSlpSpi); - } - - @Override - protected int[] getAllowedResponseIDs() { - return ALLOWED_RSPS; - } - - private void init(ServiceType pServiceType, String pPredicate, String pSlpSpi) { - this.iServiceType = pServiceType; - this.iPredicate = pPredicate; - this.iSlpSpi = pSlpSpi; - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1892103 2008-02-15 ebak SLP improvements + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp.internal.msg; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.util.List; +import java.util.SortedSet; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; +import org.metricshub.wbem.sblim.slp.ServiceType; + +/* + * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service + * Location header (function = SrvRqst = 1) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of + * | String \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of + * | String \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of + * | String \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of + * predicate string | Service Request \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of + * string | String \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + +/* + * The string indicates a SLP SPI that the requester has been + * configured with. If this string is omitted, the responder does not include + * any Authentication Blocks in its reply. If it is included, the responder MUST + * return a reply which has an associated authentication block with the SLP SPI + * in the SrvRqst. If no replies may be returned because the SLP SPI is not + * supported, the responder returns an AUTHENTICATION_UNKNOWN error. + */ + +/** + * ServiceRequest message + * + */ +public class ServiceRequest extends RequestMessage { + private ServiceType iServiceType; + + private String iPredicate, iSlpSpi; + + private static final int[] ALLOWED_RSPS = { SRV_RPLY, DA_ADVERT, SA_ADVERT }; + + /** + * parse + * + * @param pHdr + * @param pInStr + * @return SLPMessage + * @throws ServiceLocationException + * @throws IOException + */ + public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { + return new ServiceRequest( + pHdr, + pInStr.readStringSet(), // prevResponders + pInStr.readServiceType(), // serviceType + pInStr.readStringList(), // scopeList + pInStr.readString(), // predicate + pInStr.readString() // SlpSpi + ); + } + + /** + * Ctor. + * + * @param pLangTag + * @param pPrevResponderSet + * - set of address strings + * @param pServiceType + * @param pScopeList + * - list of scope strings + * @param pPredicate + * @param pSlpSpi + */ + public ServiceRequest( + String pLangTag, + SortedSet pPrevResponderSet, + ServiceType pServiceType, + List pScopeList, + String pPredicate, + String pSlpSpi + ) { + super(SRV_RQST, pLangTag, pPrevResponderSet, pScopeList); + init(pServiceType, pPredicate, pSlpSpi); + } + + /** + * Ctor. + * + * @param pPrevResponderSet + * - set of address strings + * @param pServiceType + * @param pScopeList + * - list of scope strings + * @param pPredicate + * @param pSlpSpi + */ + public ServiceRequest( + SortedSet pPrevResponderSet, + ServiceType pServiceType, + List pScopeList, + String pPredicate, + String pSlpSpi + ) { + super(SRV_RQST, pPrevResponderSet, pScopeList); + init(pServiceType, pPredicate, pSlpSpi); + } + + /** + * @param pHeader + * @param pPrevResponderSet + * - set of address strings + * @param pServiceType + * @param pScopeList + * - list of scope strings + * @param pPredicate + * - LDAPv3 search filter + * @param pSlpSpi + */ + public ServiceRequest( + MsgHeader pHeader, + SortedSet pPrevResponderSet, + ServiceType pServiceType, + List pScopeList, + String pPredicate, + String pSlpSpi + ) { + super(pHeader, pPrevResponderSet, pScopeList); + init(pServiceType, pPredicate, pSlpSpi); + } + + /** + * getServiceType + * + * @return ServiceType + */ + public ServiceType getServiceType() { + return this.iServiceType; + } + + @Override + protected boolean serializeRequestBody(SLPOutputStream pOutStr) { + return ( + pOutStr.write(this.iServiceType) && + pOutStr.writeStringList(getScopeList()) && + pOutStr.write(this.iPredicate) && + pOutStr.write(this.iSlpSpi) + ); + } + + @Override + protected int[] getAllowedResponseIDs() { + return ALLOWED_RSPS; + } + + private void init(ServiceType pServiceType, String pPredicate, String pSlpSpi) { + this.iServiceType = pServiceType; + this.iPredicate = pPredicate; + this.iSlpSpi = pSlpSpi; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ServiceTypeReply.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ServiceTypeReply.java similarity index 76% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ServiceTypeReply.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ServiceTypeReply.java index b46735e..1a5b2a5 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ServiceTypeReply.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ServiceTypeReply.java @@ -1,144 +1,138 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1892103 2008-02-12 ebak SLP improvements - * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.msg; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.util.Iterator; -import java.util.List; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; -import org.sentrysoftware.wbem.sblim.slp.ServiceType; - -/* - * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service - * Location header (function = SrvTypeRply = 10) | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Error - * Code | length of | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | - * \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ -/** - * ServiceTypeReply message - * - */ -public class ServiceTypeReply extends ReplyMessage { - - private List iServTypeList; - - /** - * parse - * - * @param pHdr - * @param pInStr - * @return SLPMessage - * @throws ServiceLocationException - * @throws IOException - */ - public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException { - return new ServiceTypeReply(pHdr, pInStr.read16(), pInStr.readServTypeList()); - } - - /** - * Ctor. - * - * @param pErrorCode - * @param pServTypeList - * - list of ServiceTypes - */ - public ServiceTypeReply(int pErrorCode, List pServTypeList) { - super(SRV_TYPE_RPLY, pErrorCode); - this.iServTypeList = pServTypeList; - } - - /** - * Ctor. - * - * @param pLangTag - * @param pErrorCode - * @param pServTypeList - * - list of ServiceTypes - */ - public ServiceTypeReply(String pLangTag, int pErrorCode, List pServTypeList) { - super(SRV_TYPE_RPLY, pLangTag, pErrorCode); - this.iServTypeList = pServTypeList; - } - - /** - * Ctor. - * - * @param pHeader - * @param pErrorCode - * @param pServTypeList - * - list of ServiceTypes - */ - public ServiceTypeReply(MsgHeader pHeader, int pErrorCode, List pServTypeList) { - super(pHeader, pErrorCode); - this.iServTypeList = pServTypeList; - } - - @Override - public Iterator getResultIterator() { - return this.iServTypeList == null ? null : this.iServTypeList.iterator(); - } - - /** - * @param pOption - */ - @Override - protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) { - return pOutStr.write16(getErrorCode()) && pOutStr.writeServTypeList(getResultIterator()); - } - - @Override - public Iterator getExceptionIterator() { - // this message doesn't have exception table - return null; - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1892103 2008-02-12 ebak SLP improvements + * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp.internal.msg; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.util.Iterator; +import java.util.List; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; +import org.metricshub.wbem.sblim.slp.ServiceType; + +/* + * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service + * Location header (function = SrvTypeRply = 10) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Error + * Code | length of | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | + * \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ +/** + * ServiceTypeReply message + * + */ +public class ServiceTypeReply extends ReplyMessage { + private List iServTypeList; + + /** + * parse + * + * @param pHdr + * @param pInStr + * @return SLPMessage + * @throws ServiceLocationException + * @throws IOException + */ + public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { + return new ServiceTypeReply(pHdr, pInStr.read16(), pInStr.readServTypeList()); + } + + /** + * Ctor. + * + * @param pErrorCode + * @param pServTypeList + * - list of ServiceTypes + */ + public ServiceTypeReply(int pErrorCode, List pServTypeList) { + super(SRV_TYPE_RPLY, pErrorCode); + this.iServTypeList = pServTypeList; + } + + /** + * Ctor. + * + * @param pLangTag + * @param pErrorCode + * @param pServTypeList + * - list of ServiceTypes + */ + public ServiceTypeReply(String pLangTag, int pErrorCode, List pServTypeList) { + super(SRV_TYPE_RPLY, pLangTag, pErrorCode); + this.iServTypeList = pServTypeList; + } + + /** + * Ctor. + * + * @param pHeader + * @param pErrorCode + * @param pServTypeList + * - list of ServiceTypes + */ + public ServiceTypeReply(MsgHeader pHeader, int pErrorCode, List pServTypeList) { + super(pHeader, pErrorCode); + this.iServTypeList = pServTypeList; + } + + @Override + public Iterator getResultIterator() { + return this.iServTypeList == null ? null : this.iServTypeList.iterator(); + } + + /** + * @param pOption + */ + @Override + protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) { + return pOutStr.write16(getErrorCode()) && pOutStr.writeServTypeList(getResultIterator()); + } + + @Override + public Iterator getExceptionIterator() { + // this message doesn't have exception table + return null; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ServiceTypeRequest.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ServiceTypeRequest.java similarity index 69% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ServiceTypeRequest.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ServiceTypeRequest.java index e23b01e..bfe8e49 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/ServiceTypeRequest.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/ServiceTypeRequest.java @@ -1,153 +1,156 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1892103 2008-02-15 ebak SLP improvements - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.msg; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.util.List; -import java.util.SortedSet; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; - -/* - * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service - * Location header (function = SrvTypeRqst = 9) | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of - * PRList | String \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of - * Naming Authority | \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of - * | String \ - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ -/** - * ServiceTypeRequest message - * - */ -public class ServiceTypeRequest extends RequestMessage { - - private String iNamingAuth; - - private static final int[] ALLOWED_RSPS = { SRV_TYPE_RPLY }; - - /** - * parse - * - * @param pHdr - * @param pInStr - * @return SLPMessage - * @throws ServiceLocationException - * @throws IOException - */ - public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException { - return new ServiceTypeRequest(pHdr, pInStr.readStringSet(), // prevResponderSet - pInStr.readString(), // naming authority - pInStr.readStringList() // scope list - ); - } - - /** - * Ctor. - * - * @param pPrevResponderSet - * - set of address strings - * @param pNamingAuth - * @param pScopeList - * - set of scope strings - */ - public ServiceTypeRequest(SortedSet pPrevResponderSet, String pNamingAuth, - List pScopeList) { - super(SRV_TYPE_RQST, pPrevResponderSet, pScopeList); - init(pNamingAuth); - } - - /** - * Ctor. - * - * @param pLangTag - * @param pPrevResponderSet - * - set of address strings - * @param pNamingAuth - * @param pScopeList - * - set of scope strings - */ - public ServiceTypeRequest(String pLangTag, SortedSet pPrevResponderSet, - String pNamingAuth, List pScopeList) { - super(SRV_TYPE_RQST, pLangTag, pPrevResponderSet, pScopeList); - init(pNamingAuth); - } - - /** - * Ctor. - * - * @param pHeader - * @param pPrevResponderSet - * - set of address strings - * @param pNamingAuth - * @param pScopeList - * - set of scope strings - */ - public ServiceTypeRequest(MsgHeader pHeader, SortedSet pPrevResponderSet, - String pNamingAuth, List pScopeList) { - super(pHeader, pPrevResponderSet, pScopeList); - init(pNamingAuth); - } - - @Override - protected boolean serializeRequestBody(SLPOutputStream pOutStr) { - return pOutStr.write(this.iNamingAuth) && pOutStr.writeStringList(getScopeList()); - } - - @Override - protected int[] getAllowedResponseIDs() { - return ALLOWED_RSPS; - } - - private void init(String pNamingAuth) { - this.iNamingAuth = pNamingAuth; - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1892103 2008-02-15 ebak SLP improvements + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp.internal.msg; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.util.List; +import java.util.SortedSet; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; + +/* + * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service + * Location header (function = SrvTypeRqst = 9) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of + * PRList | String \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of + * Naming Authority | \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of + * | String \ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ +/** + * ServiceTypeRequest message + * + */ +public class ServiceTypeRequest extends RequestMessage { + private String iNamingAuth; + + private static final int[] ALLOWED_RSPS = { SRV_TYPE_RPLY }; + + /** + * parse + * + * @param pHdr + * @param pInStr + * @return SLPMessage + * @throws ServiceLocationException + * @throws IOException + */ + public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { + return new ServiceTypeRequest( + pHdr, + pInStr.readStringSet(), // prevResponderSet + pInStr.readString(), // naming authority + pInStr.readStringList() // scope list + ); + } + + /** + * Ctor. + * + * @param pPrevResponderSet + * - set of address strings + * @param pNamingAuth + * @param pScopeList + * - set of scope strings + */ + public ServiceTypeRequest(SortedSet pPrevResponderSet, String pNamingAuth, List pScopeList) { + super(SRV_TYPE_RQST, pPrevResponderSet, pScopeList); + init(pNamingAuth); + } + + /** + * Ctor. + * + * @param pLangTag + * @param pPrevResponderSet + * - set of address strings + * @param pNamingAuth + * @param pScopeList + * - set of scope strings + */ + public ServiceTypeRequest( + String pLangTag, + SortedSet pPrevResponderSet, + String pNamingAuth, + List pScopeList + ) { + super(SRV_TYPE_RQST, pLangTag, pPrevResponderSet, pScopeList); + init(pNamingAuth); + } + + /** + * Ctor. + * + * @param pHeader + * @param pPrevResponderSet + * - set of address strings + * @param pNamingAuth + * @param pScopeList + * - set of scope strings + */ + public ServiceTypeRequest( + MsgHeader pHeader, + SortedSet pPrevResponderSet, + String pNamingAuth, + List pScopeList + ) { + super(pHeader, pPrevResponderSet, pScopeList); + init(pNamingAuth); + } + + @Override + protected boolean serializeRequestBody(SLPOutputStream pOutStr) { + return pOutStr.write(this.iNamingAuth) && pOutStr.writeStringList(getScopeList()); + } + + @Override + protected int[] getAllowedResponseIDs() { + return ALLOWED_RSPS; + } + + private void init(String pNamingAuth) { + this.iNamingAuth = pNamingAuth; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/Util.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/Util.java similarity index 63% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/Util.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/Util.java index 97b24cd..dcc2280 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/Util.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/msg/Util.java @@ -1,66 +1,63 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.msg; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.Locale; - -/** - * Common handful functions can be here. - * - */ -public class Util { - - /** - * getLangTag - * - * @param pLocale - * @return String - */ - public static String getLangTag(Locale pLocale) { - if (pLocale == null) return null; - String country = pLocale.getCountry(); - String lang = pLocale.getLanguage(); - return (country != null && country.length() > 0) ? lang + "-" + country : lang; - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.slp.internal.msg; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.Locale; + +/** + * Common handful functions can be here. + * + */ +public class Util { + + /** + * getLangTag + * + * @param pLocale + * @return String + */ + public static String getLangTag(Locale pLocale) { + if (pLocale == null) return null; + String country = pLocale.getCountry(); + String lang = pLocale.getLanguage(); + return (country != null && country.length() > 0) ? lang + "-" + country : lang; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/package.html b/src/main/java/org/metricshub/wbem/sblim/slp/internal/package.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/package.html rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/package.html diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/sa/DatagramThread.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/sa/DatagramThread.java similarity index 71% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/sa/DatagramThread.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/sa/DatagramThread.java index b311dc7..64ebf2b 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/sa/DatagramThread.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/sa/DatagramThread.java @@ -1,124 +1,119 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1892103 2008-02-13 ebak SLP improvements - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.sa; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.net.DatagramPacket; -import java.net.InetAddress; -import java.net.MulticastSocket; -import java.net.SocketTimeoutException; - -import org.sentrysoftware.wbem.sblim.slp.internal.SLPConfig; -import org.sentrysoftware.wbem.sblim.slp.internal.SLPDefaults; -import org.sentrysoftware.wbem.sblim.slp.internal.TRC; - -/** - * DatagramThread - * - */ -public class DatagramThread extends RecieverThread { - - private static MulticastSocket cMCastSocket; - - private DatagramPacket iPacket = new DatagramPacket(new byte[SLPDefaults.MTU], SLPDefaults.MTU); - - /** - * Ctor. - * - * @param pSrvAgent - */ - public DatagramThread(ServiceAgent pSrvAgent) { - super("DatagramThread", pSrvAgent); - } - - /** - * joinGroup - * - * @param pGroup - * @throws IOException - */ - public synchronized void joinGroup(InetAddress pGroup) throws IOException { - TRC.debug("join:" + pGroup); - cMCastSocket.joinGroup(pGroup); - } - - /** - * leaveGroup - * - * @param pGroup - * @throws IOException - */ - public synchronized void leaveGroup(InetAddress pGroup) throws IOException { - TRC.debug("leave:" + pGroup); - cMCastSocket.leaveGroup(pGroup); - } - - @Override - protected void init() throws IOException { - if (cMCastSocket == null) { - cMCastSocket = new MulticastSocket(SLPConfig.getGlobalCfg().getPort()); - cMCastSocket.setReuseAddress(true); - cMCastSocket.setSoTimeout(100); - } - } - - @Override - protected void mainLoop() throws IOException { - try { - cMCastSocket.receive(this.iPacket); - TRC.debug("Packet received"); - this.iSrvAgent.processMessage(cMCastSocket, this.iPacket); - } catch (SocketTimeoutException e) { - // superclass will restart this function - } - } - - @Override - protected void close() { - if (cMCastSocket == null) return; - cMCastSocket.close(); - cMCastSocket = null; - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1892103 2008-02-13 ebak SLP improvements + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.slp.internal.sa; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.InetAddress; +import java.net.MulticastSocket; +import java.net.SocketTimeoutException; +import org.metricshub.wbem.sblim.slp.internal.SLPConfig; +import org.metricshub.wbem.sblim.slp.internal.SLPDefaults; +import org.metricshub.wbem.sblim.slp.internal.TRC; + +/** + * DatagramThread + * + */ +public class DatagramThread extends RecieverThread { + private static MulticastSocket cMCastSocket; + + private DatagramPacket iPacket = new DatagramPacket(new byte[SLPDefaults.MTU], SLPDefaults.MTU); + + /** + * Ctor. + * + * @param pSrvAgent + */ + public DatagramThread(ServiceAgent pSrvAgent) { + super("DatagramThread", pSrvAgent); + } + + /** + * joinGroup + * + * @param pGroup + * @throws IOException + */ + public synchronized void joinGroup(InetAddress pGroup) throws IOException { + TRC.debug("join:" + pGroup); + cMCastSocket.joinGroup(pGroup); + } + + /** + * leaveGroup + * + * @param pGroup + * @throws IOException + */ + public synchronized void leaveGroup(InetAddress pGroup) throws IOException { + TRC.debug("leave:" + pGroup); + cMCastSocket.leaveGroup(pGroup); + } + + @Override + protected void init() throws IOException { + if (cMCastSocket == null) { + cMCastSocket = new MulticastSocket(SLPConfig.getGlobalCfg().getPort()); + cMCastSocket.setReuseAddress(true); + cMCastSocket.setSoTimeout(100); + } + } + + @Override + protected void mainLoop() throws IOException { + try { + cMCastSocket.receive(this.iPacket); + TRC.debug("Packet received"); + this.iSrvAgent.processMessage(cMCastSocket, this.iPacket); + } catch (SocketTimeoutException e) { + // superclass will restart this function + } + } + + @Override + protected void close() { + if (cMCastSocket == null) return; + cMCastSocket.close(); + cMCastSocket = null; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/sa/MessageTable.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/sa/MessageTable.java similarity index 76% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/sa/MessageTable.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/sa/MessageTable.java index 8e76db6..12c06f1 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/sa/MessageTable.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/sa/MessageTable.java @@ -1,256 +1,247 @@ -/* - (C) Copyright IBM Corp. 2007, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1892103 2008-02-12 ebak SLP improvements - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2795671 2009-05-22 raman_arora Add Type to Comparable - * 3023120 2010-07-01 blaschke-oss RequestDescriptor equals/compareTo issue - * 3023349 2010-07-02 blaschke-oss SLP uses # constructor instead of valueOf - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.sa; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.net.InetAddress; -import java.util.Arrays; -import java.util.Date; -import java.util.SortedMap; -import java.util.TreeMap; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.RequestMessage; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.SLPMessage; - -/** - * Keeps track of datagram messages. For requests with the same XID the same - * responses should be returned. - * - */ -public class MessageTable { - - private static class RequestDescriptor implements Comparable { - - private byte[] iSrcAddress; - - private byte[] iRequest; - - /** - * Ctor. - * - * @param pSource - * @param pRequest - * @throws ServiceLocationException - */ - public RequestDescriptor(InetAddress pSource, SLPMessage pRequest) - throws ServiceLocationException { - this.iSrcAddress = pSource.getAddress(); - this.iRequest = (pRequest instanceof RequestMessage) ? ((RequestMessage) pRequest) - .serializeWithoutResponders(false, true, true) : pRequest.serialize(false, - true, true); - } - - public int compareTo(RequestDescriptor pObj) { - RequestDescriptor that = pObj; - int cmp = compare(this.iSrcAddress, that.iSrcAddress); - if (cmp != 0) return cmp; - return compare(this.iRequest, that.iRequest); - } - - private static int compare(byte[] pBytes0, byte[] pBytes1) { - int len = Math.min(pBytes0.length, pBytes1.length); - for (int i = 0; i < len; i++) { - int cmp = pBytes0[i] & 0xff - pBytes1[i] & 0xff; - if (cmp != 0) return cmp; - } - return pBytes0.length - pBytes1.length; - } - - @Override - public boolean equals(Object pObj) { - if (!(pObj instanceof RequestDescriptor)) return false; - RequestDescriptor that = (RequestDescriptor) pObj; - return compare(this.iSrcAddress, that.iSrcAddress) == 0 - && compare(this.iRequest, that.iRequest) == 0; - } - - @Override - public int hashCode() { - return Arrays.hashCode(this.iSrcAddress) + Arrays.hashCode(this.iRequest); - } - } - - private static class TableEntry { - - private long iTime; - - private RequestDescriptor iReqDesc; - - private byte[] iResponse; - - /** - * Ctor. - * - * @param pTime - * @param pReqKey - * @param pResponse - */ - public TableEntry(long pTime, RequestDescriptor pReqKey, byte[] pResponse) { - this.iTime = pTime; - this.iReqDesc = pReqKey; - this.iResponse = pResponse; - } - - /** - * getTime - * - * @return long - */ - public long getTime() { - return this.iTime; - } - - /** - * setTime - * - * @param pTime - */ - public void setTime(long pTime) { - this.iTime = pTime; - } - - /** - * getRequestDescriptor - * - * @return RequestDescriptor - */ - public RequestDescriptor getRequestDescriptor() { - return this.iReqDesc; - } - - /** - * getResponse - * - * @return byte[] - */ - public byte[] getResponse() { - return this.iResponse; - } - - } - - /** - * Remember messages for 30 seconds. - */ - private static final long KEEPIN = 30; - - /** - * Time -> TableEntry - */ - private SortedMap iTimeMap = new TreeMap(); - - /** - * RequestKey -> TableEntry - */ - private SortedMap iReqMap = new TreeMap(); - - /** - * getResponse - * - * @param pSource - * @param pRequest - * @return byte[] - * @throws ServiceLocationException - */ - public synchronized byte[] getResponse(InetAddress pSource, SLPMessage pRequest) - throws ServiceLocationException { - long now = getSecs(); - RequestDescriptor reqDesc = new RequestDescriptor(pSource, pRequest); - TableEntry entry = this.iReqMap.get(reqDesc); - if (entry == null) return null; - clean(); - updateTime(entry, now); - return entry.getResponse(); - } - - /** - * addResponse - * - * @param pSource - * @param pRequest - * @param pRespond - * @throws ServiceLocationException - */ - public synchronized void addResponse(InetAddress pSource, SLPMessage pRequest, byte[] pRespond) - throws ServiceLocationException { - insert(new TableEntry(getSecs(), new RequestDescriptor(pSource, pRequest), pRespond)); - clean(); - } - - private void clean() { - long now = getSecs(); - Long timeStamp; - while ((timeStamp = this.iTimeMap.firstKey()) != null) { - if (now - timeStamp.longValue() < KEEPIN) break; - TableEntry entry = this.iTimeMap.get(timeStamp); - remove(entry); - } - } - - private void insert(TableEntry pEntry) { - this.iTimeMap.put(Long.valueOf(pEntry.getTime()), pEntry); - this.iReqMap.put(pEntry.getRequestDescriptor(), pEntry); - } - - private void remove(TableEntry pEntry) { - this.iTimeMap.remove(Long.valueOf(pEntry.getTime())); - this.iReqMap.remove(pEntry.getRequestDescriptor()); - } - - private void updateTime(TableEntry pEntry, long pTime) { - remove(pEntry); - pEntry.setTime(pTime); - insert(pEntry); - } - - private static long getSecs() { - return new Date().getTime() / 1000; - } - -} +/* + (C) Copyright IBM Corp. 2007, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1892103 2008-02-12 ebak SLP improvements + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2795671 2009-05-22 raman_arora Add Type to Comparable + * 3023120 2010-07-01 blaschke-oss RequestDescriptor equals/compareTo issue + * 3023349 2010-07-02 blaschke-oss SLP uses # constructor instead of valueOf + */ + +package org.metricshub.wbem.sblim.slp.internal.sa; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.net.InetAddress; +import java.util.Arrays; +import java.util.Date; +import java.util.SortedMap; +import java.util.TreeMap; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; +import org.metricshub.wbem.sblim.slp.internal.msg.RequestMessage; +import org.metricshub.wbem.sblim.slp.internal.msg.SLPMessage; + +/** + * Keeps track of datagram messages. For requests with the same XID the same + * responses should be returned. + * + */ +public class MessageTable { + + private static class RequestDescriptor implements Comparable { + private byte[] iSrcAddress; + + private byte[] iRequest; + + /** + * Ctor. + * + * @param pSource + * @param pRequest + * @throws ServiceLocationException + */ + public RequestDescriptor(InetAddress pSource, SLPMessage pRequest) throws ServiceLocationException { + this.iSrcAddress = pSource.getAddress(); + this.iRequest = + (pRequest instanceof RequestMessage) + ? ((RequestMessage) pRequest).serializeWithoutResponders(false, true, true) + : pRequest.serialize(false, true, true); + } + + public int compareTo(RequestDescriptor pObj) { + RequestDescriptor that = pObj; + int cmp = compare(this.iSrcAddress, that.iSrcAddress); + if (cmp != 0) return cmp; + return compare(this.iRequest, that.iRequest); + } + + private static int compare(byte[] pBytes0, byte[] pBytes1) { + int len = Math.min(pBytes0.length, pBytes1.length); + for (int i = 0; i < len; i++) { + int cmp = pBytes0[i] & 0xff - pBytes1[i] & 0xff; + if (cmp != 0) return cmp; + } + return pBytes0.length - pBytes1.length; + } + + @Override + public boolean equals(Object pObj) { + if (!(pObj instanceof RequestDescriptor)) return false; + RequestDescriptor that = (RequestDescriptor) pObj; + return compare(this.iSrcAddress, that.iSrcAddress) == 0 && compare(this.iRequest, that.iRequest) == 0; + } + + @Override + public int hashCode() { + return Arrays.hashCode(this.iSrcAddress) + Arrays.hashCode(this.iRequest); + } + } + + private static class TableEntry { + private long iTime; + + private RequestDescriptor iReqDesc; + + private byte[] iResponse; + + /** + * Ctor. + * + * @param pTime + * @param pReqKey + * @param pResponse + */ + public TableEntry(long pTime, RequestDescriptor pReqKey, byte[] pResponse) { + this.iTime = pTime; + this.iReqDesc = pReqKey; + this.iResponse = pResponse; + } + + /** + * getTime + * + * @return long + */ + public long getTime() { + return this.iTime; + } + + /** + * setTime + * + * @param pTime + */ + public void setTime(long pTime) { + this.iTime = pTime; + } + + /** + * getRequestDescriptor + * + * @return RequestDescriptor + */ + public RequestDescriptor getRequestDescriptor() { + return this.iReqDesc; + } + + /** + * getResponse + * + * @return byte[] + */ + public byte[] getResponse() { + return this.iResponse; + } + } + + /** + * Remember messages for 30 seconds. + */ + private static final long KEEPIN = 30; + + /** + * Time -> TableEntry + */ + private SortedMap iTimeMap = new TreeMap(); + + /** + * RequestKey -> TableEntry + */ + private SortedMap iReqMap = new TreeMap(); + + /** + * getResponse + * + * @param pSource + * @param pRequest + * @return byte[] + * @throws ServiceLocationException + */ + public synchronized byte[] getResponse(InetAddress pSource, SLPMessage pRequest) throws ServiceLocationException { + long now = getSecs(); + RequestDescriptor reqDesc = new RequestDescriptor(pSource, pRequest); + TableEntry entry = this.iReqMap.get(reqDesc); + if (entry == null) return null; + clean(); + updateTime(entry, now); + return entry.getResponse(); + } + + /** + * addResponse + * + * @param pSource + * @param pRequest + * @param pRespond + * @throws ServiceLocationException + */ + public synchronized void addResponse(InetAddress pSource, SLPMessage pRequest, byte[] pRespond) + throws ServiceLocationException { + insert(new TableEntry(getSecs(), new RequestDescriptor(pSource, pRequest), pRespond)); + clean(); + } + + private void clean() { + long now = getSecs(); + Long timeStamp; + while ((timeStamp = this.iTimeMap.firstKey()) != null) { + if (now - timeStamp.longValue() < KEEPIN) break; + TableEntry entry = this.iTimeMap.get(timeStamp); + remove(entry); + } + } + + private void insert(TableEntry pEntry) { + this.iTimeMap.put(Long.valueOf(pEntry.getTime()), pEntry); + this.iReqMap.put(pEntry.getRequestDescriptor(), pEntry); + } + + private void remove(TableEntry pEntry) { + this.iTimeMap.remove(Long.valueOf(pEntry.getTime())); + this.iReqMap.remove(pEntry.getRequestDescriptor()); + } + + private void updateTime(TableEntry pEntry, long pTime) { + remove(pEntry); + pEntry.setTime(pTime); + insert(pEntry); + } + + private static long getSecs() { + return new Date().getTime() / 1000; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/sa/RecieverThread.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/sa/RecieverThread.java similarity index 74% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/sa/RecieverThread.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/sa/RecieverThread.java index 561444d..1e786bf 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/sa/RecieverThread.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/sa/RecieverThread.java @@ -1,177 +1,172 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.sa; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; -import org.sentrysoftware.wbem.sblim.slp.internal.TRC; - -/** - * RecieverThread - * - */ -public abstract class RecieverThread implements Runnable { - - private Thread iThread; - - private volatile boolean iStop; - - private boolean iInited; - - private Object iInitLock = new Object(); - - protected ServiceAgent iSrvAgent; - - /** - * Ctor. - * - * @param pName - * @param pSrvAgent - */ - public RecieverThread(String pName, ServiceAgent pSrvAgent) { - this.iThread = new Thread(this, pName); - this.iSrvAgent = pSrvAgent; - } - - /** - * start - */ - public void start() { - this.iThread.start(); - } - - /** - * wait4init - */ - public void wait4init() { - synchronized (this.iInitLock) { - try { - if (this.iInited) return; - this.iInitLock.wait(); - return; - } catch (InterruptedException e) { - TRC.error(e); - } - } - } - - /** - * stop - */ - public void stop() { - stop(true); - } - - /** - * stop - * - * @param pWait - */ - public void stop(boolean pWait) { - this.iStop = true; - if (pWait) join(); - } - - public void run() { - // 1st init - synchronized (this.iInitLock) { - TRC.debug("initing"); - initialize(); - this.iInited = true; - TRC.debug("inited"); - try { - this.iInitLock.notifyAll(); - } catch (IllegalMonitorStateException e) { - TRC.error(e); - } - } - while (!this.iStop) { - try { - mainLoop(); - } catch (Exception e) { - TRC.error(e); - sleep(100); - initialize(); - } - } - close(); - this.iStop = false; - TRC.debug("STOPPED"); - } - - // exception of init shoud be reachable for ServiceTable - - protected abstract void init() throws ServiceLocationException, IOException; - - protected abstract void mainLoop() throws IOException; - - protected abstract void close(); - - private void join() { - try { - this.iThread.join(); - } catch (InterruptedException e) { - TRC.error(e); - } - } - - private void initialize() { - try { - init(); - } catch (ServiceLocationException e) { - TRC.error(e); - } catch (IOException e) { - TRC.error(e); - } - } - - private static void sleep(int pMillis) { - try { - Thread.sleep(pMillis); - } catch (InterruptedException e) { - TRC.error(e); - } - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.slp.internal.sa; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; +import org.metricshub.wbem.sblim.slp.internal.TRC; + +/** + * RecieverThread + * + */ +public abstract class RecieverThread implements Runnable { + private Thread iThread; + + private volatile boolean iStop; + + private boolean iInited; + + private Object iInitLock = new Object(); + + protected ServiceAgent iSrvAgent; + + /** + * Ctor. + * + * @param pName + * @param pSrvAgent + */ + public RecieverThread(String pName, ServiceAgent pSrvAgent) { + this.iThread = new Thread(this, pName); + this.iSrvAgent = pSrvAgent; + } + + /** + * start + */ + public void start() { + this.iThread.start(); + } + + /** + * wait4init + */ + public void wait4init() { + synchronized (this.iInitLock) { + try { + if (this.iInited) return; + this.iInitLock.wait(); + return; + } catch (InterruptedException e) { + TRC.error(e); + } + } + } + + /** + * stop + */ + public void stop() { + stop(true); + } + + /** + * stop + * + * @param pWait + */ + public void stop(boolean pWait) { + this.iStop = true; + if (pWait) join(); + } + + public void run() { + // 1st init + synchronized (this.iInitLock) { + TRC.debug("initing"); + initialize(); + this.iInited = true; + TRC.debug("inited"); + try { + this.iInitLock.notifyAll(); + } catch (IllegalMonitorStateException e) { + TRC.error(e); + } + } + while (!this.iStop) { + try { + mainLoop(); + } catch (Exception e) { + TRC.error(e); + sleep(100); + initialize(); + } + } + close(); + this.iStop = false; + TRC.debug("STOPPED"); + } + + // exception of init shoud be reachable for ServiceTable + + protected abstract void init() throws ServiceLocationException, IOException; + + protected abstract void mainLoop() throws IOException; + + protected abstract void close(); + + private void join() { + try { + this.iThread.join(); + } catch (InterruptedException e) { + TRC.error(e); + } + } + + private void initialize() { + try { + init(); + } catch (ServiceLocationException e) { + TRC.error(e); + } catch (IOException e) { + TRC.error(e); + } + } + + private static void sleep(int pMillis) { + try { + Thread.sleep(pMillis); + } catch (InterruptedException e) { + TRC.error(e); + } + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/sa/ServiceAgent.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/sa/ServiceAgent.java similarity index 74% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/sa/ServiceAgent.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/sa/ServiceAgent.java index bae0455..4b61e1b 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/sa/ServiceAgent.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/sa/ServiceAgent.java @@ -1,363 +1,351 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1804402 2007-11-10 ebak IPv6 ready SLP - revision 4 - * 1892103 2008-02-15 ebak SLP improvements - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.sa; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.io.OutputStream; -import java.net.DatagramPacket; -import java.net.DatagramSocket; -import java.net.Socket; -import java.net.UnknownHostException; -import java.util.List; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; -import org.sentrysoftware.wbem.sblim.slp.ServiceURL; -import org.sentrysoftware.wbem.sblim.slp.internal.IPv6MulticastAddressFactory; -import org.sentrysoftware.wbem.sblim.slp.internal.Net; -import org.sentrysoftware.wbem.sblim.slp.internal.SLPConfig; -import org.sentrysoftware.wbem.sblim.slp.internal.SLPDefaults; -import org.sentrysoftware.wbem.sblim.slp.internal.TRC; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.AttributeReply; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.AttributeRequest; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.FunctionIDs; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.MsgFactory; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.ReplyMessage; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.RequestMessage; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.SLPMessage; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.ServiceAcknowledgment; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.ServiceDeregistration; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.ServiceRegistration; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.ServiceReply; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.ServiceRequest; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.ServiceTypeReply; - -/** - * ServiceAgent - * - */ -public class ServiceAgent implements FunctionIDs { - - private boolean iUseV4 = Net.hasIPv4() && SLPConfig.getGlobalCfg().useIPv4(), iUseV6 = Net - .hasIPv6() - && SLPConfig.getGlobalCfg().useIPv6(); - - boolean iStarted; - - private volatile boolean iSkipFirstRequest; - - private DatagramThread iDGThread = new DatagramThread(this); - - private TCPThread iTCPThread = new TCPThread(this); - - private ServiceTable iSrvTable = new ServiceTable(this.iDGThread); - - private MessageTable iMsgTable = new MessageTable(); - - /** - * main - * - * @param pArgs - * @throws IOException - */ - public static void main(String[] pArgs) throws IOException { - if (pArgs != null && pArgs.length >= 1) { - int port = Integer.parseInt(pArgs[0]); - SLPConfig.getGlobalCfg().setPort(port); - } - ServiceAgent srvAgent = new ServiceAgent(); - srvAgent.start(); - TRC.debug("starting idle loop"); - while (true) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - // lofasz - } - } - } - - /** - * setSkipFirstRequest - * - * @param pValue - */ - public void setSkipFirstRequest(boolean pValue) { - this.iSkipFirstRequest = pValue; - } - - /** - * start - * - * @throws IOException - */ - public void start() throws IOException { - if (this.iStarted) return; - // launch receivers - TRC.debug("start receivers"); - if (this.iUseV4 || this.iUseV6) { - this.iTCPThread.start(); - this.iDGThread.start(); - TRC.debug("wait4 TCP init"); - this.iTCPThread.wait4init(); - TRC.debug("wait4 Datagram init"); - this.iDGThread.wait4init(); - } - this.iStarted = true; - TRC.debug("receivers started"); - // join multicast groups - if (this.iUseV4) this.iDGThread.joinGroup(SLPConfig.getMulticastAddress()); - if (this.iUseV6) { - this.iDGThread.joinGroup(IPv6MulticastAddressFactory - .getSrvLocAddress(SLPDefaults.IPV6_MULTICAST_SCOPE)); - } - } - - /** - * stop - */ - public void stop() { - // stop the receivers - if (this.iUseV4 || this.iUseV6) { - this.iTCPThread.stop(); - this.iDGThread.stop(); - } - this.iStarted = false; - - } - - /** - * processMessage - * - * @param pDGSock - * @param pPacket - */ - public void processMessage(DatagramSocket pDGSock, DatagramPacket pPacket) { - byte[] reply; - SLPMessage msg; - try { - msg = MsgFactory.parse(pPacket); - } catch (Exception e) { - // no response for unparseable messages - TRC.debug("Message parsing error!", e); - return; - } - - try { - TRC.debug("processing: " + msg); - reply = this.iMsgTable.getResponse(pPacket.getAddress(), msg); - if (reply == null) { - SLPMessage replyMsg = makeReply(msg); - if (replyMsg != null) { - TRC.debug("response : " + replyMsg); - reply = replyMsg.serialize(false, true, true); - this.iMsgTable.addResponse(pPacket.getAddress(), msg, reply); - // debugging: do not reply to the first request - if (this.iSkipFirstRequest) { - TRC.debug("refusing response"); - return; - } - } - } else { - TRC.debug("cached response"); - } - } catch (ServiceLocationException e) { - TRC.debug(e.toString(), e); - reply = makeErrorReply(msg, e); // known XID - } - if (reply != null) { - try { - TRC.debug("sending response"); - pDGSock.send(new DatagramPacket(reply, reply.length, pPacket.getAddress(), pPacket - .getPort())); - } catch (IOException e) { - TRC.error(e); - } - } - } - - /** - * processMessage - * - * @param pStreamSock - */ - public void processMessage(Socket pStreamSock) { - byte[] reply; - SLPMessage msg; - try { - msg = MsgFactory.parse(pStreamSock.getInputStream()); - } catch (Exception e) { - // no response for unparseable messages - TRC.debug("Message parsing error!", e); - return; - } - try { - SLPMessage replyMsg = makeReply(msg); - reply = replyMsg == null ? null : replyMsg.serialize(false, false, true); - } catch (ServiceLocationException e) { - reply = makeErrorReply(msg, e); - } - if (reply != null) { - try { - OutputStream os = pStreamSock.getOutputStream(); - os.write(reply); - os.flush(); - } catch (IOException e) { - TRC.error(e); - } - } - try { - pStreamSock.close(); - } catch (IOException e) { - TRC.error(e); - } - } - - /* - * XID is set to a unique value for each unique request. If the request is - * retransmitted, the same XID is used. Replies set the XID to the same - * value as the xid in the request. Only unsolicited DAAdverts are sent with - * an XID of 0. - */ - private SLPMessage makeReply(SLPMessage pRequest) throws ServiceLocationException { - try { - SLPMessage msg = pRequest instanceof RequestMessage ? makeReply4Request((RequestMessage) pRequest) - : makeReply4Others(pRequest); - if (msg != null) msg.setXID(pRequest.getXID()); - return msg; - } catch (UnknownHostException e) { - TRC.error(e); - throw new ServiceLocationException(ServiceLocationException.NETWORK_ERROR); - } catch (IOException e) { - TRC.error(e); - throw new ServiceLocationException(ServiceLocationException.NETWORK_ERROR); - } - - } - - private ReplyMessage makeReply4Request(RequestMessage pRequest) { - ReplyMessage replyMsg; - List scopes = pRequest.getScopeList(); - switch (pRequest.getFunctionID()) { - case SRV_RQST: - ServiceRequest srvRqst = (ServiceRequest) pRequest; - if (SLPDefaults.DA_SERVICE_TYPE.equals(srvRqst.getServiceType())) return null; - List urlList = this.iSrvTable.getServiceURLs(srvRqst.getServiceType(), - scopes); - TRC.debug("srvReply : " + urlList); - replyMsg = new ServiceReply(0, urlList); - break; - case ATTR_RQST: - AttributeRequest attrRqst = (AttributeRequest) pRequest; - replyMsg = new AttributeReply(0, this.iSrvTable.getAttributes(attrRqst - .getServiceURL(), scopes)); - break; - case SRV_TYPE_RQST: - // ServiceTypeRequest srvTypeRqst = - // (ServiceTypeRequest)pRequest; - replyMsg = new ServiceTypeReply(0, this.iSrvTable.getServiceTypes(scopes)); - break; - default: - return null; - } - return replyMsg; - } - - private SLPMessage makeReply4Others(SLPMessage pRequest) throws IOException { - switch (pRequest.getFunctionID()) { - case SRV_REG: - ServiceRegistration srvReg = (ServiceRegistration) pRequest; - this.iSrvTable.add(srvReg.getServiceURL(), srvReg.getAttributeList(), srvReg - .getScopeList()); - return new ServiceAcknowledgment(0); - case SRV_DEREG: - ServiceDeregistration srvDereg = (ServiceDeregistration) pRequest; - this.iSrvTable.remove(srvDereg.getServiceURL()); - return new ServiceAcknowledgment(0); - default: - // FIXME maybe returning an error message is better - return null; - } - } - - private static byte[] makeErrorReply(SLPMessage pRequest, ServiceLocationException pE) { - return makeErrorReply(pRequest, pE.getErrorCode()); - } - - /* - * Error reply: SRV_REG, SRV_DEREG -> SRV_ACK SRV_RQST -> SRV_RSP ATTR_RQST - * -> ATTR_RPLY SRV_TYPE_RQST -> SRV_TYPE_RPLY - */ - - private static byte[] makeErrorReply(SLPMessage pRequest, int pErrorCode) { - ReplyMessage replyMsg; - switch (pRequest.getFunctionID()) { - case SRV_RQST: - replyMsg = new ServiceReply(pErrorCode, null); - break; - case ATTR_RQST: - replyMsg = new AttributeReply(pErrorCode, null); - break; - case SRV_TYPE_RQST: - replyMsg = new ServiceTypeReply(pErrorCode, null); - break; - case SRV_REG: - case SRV_DEREG: - replyMsg = new ServiceAcknowledgment(pErrorCode); - break; - default: - return null; - } - replyMsg.setXID(pRequest.getXID()); - try { - return replyMsg.serialize(false, true, true); - } catch (ServiceLocationException se) { - TRC.error(se); - return null; - } - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1804402 2007-11-10 ebak IPv6 ready SLP - revision 4 + * 1892103 2008-02-15 ebak SLP improvements + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + */ + +package org.metricshub.wbem.sblim.slp.internal.sa; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.io.OutputStream; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.Socket; +import java.net.UnknownHostException; +import java.util.List; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; +import org.metricshub.wbem.sblim.slp.ServiceURL; +import org.metricshub.wbem.sblim.slp.internal.IPv6MulticastAddressFactory; +import org.metricshub.wbem.sblim.slp.internal.Net; +import org.metricshub.wbem.sblim.slp.internal.SLPConfig; +import org.metricshub.wbem.sblim.slp.internal.SLPDefaults; +import org.metricshub.wbem.sblim.slp.internal.TRC; +import org.metricshub.wbem.sblim.slp.internal.msg.AttributeReply; +import org.metricshub.wbem.sblim.slp.internal.msg.AttributeRequest; +import org.metricshub.wbem.sblim.slp.internal.msg.FunctionIDs; +import org.metricshub.wbem.sblim.slp.internal.msg.MsgFactory; +import org.metricshub.wbem.sblim.slp.internal.msg.ReplyMessage; +import org.metricshub.wbem.sblim.slp.internal.msg.RequestMessage; +import org.metricshub.wbem.sblim.slp.internal.msg.SLPMessage; +import org.metricshub.wbem.sblim.slp.internal.msg.ServiceAcknowledgment; +import org.metricshub.wbem.sblim.slp.internal.msg.ServiceDeregistration; +import org.metricshub.wbem.sblim.slp.internal.msg.ServiceRegistration; +import org.metricshub.wbem.sblim.slp.internal.msg.ServiceReply; +import org.metricshub.wbem.sblim.slp.internal.msg.ServiceRequest; +import org.metricshub.wbem.sblim.slp.internal.msg.ServiceTypeReply; + +/** + * ServiceAgent + * + */ +public class ServiceAgent implements FunctionIDs { + private boolean iUseV4 = Net.hasIPv4() && SLPConfig.getGlobalCfg().useIPv4(), iUseV6 = + Net.hasIPv6() && SLPConfig.getGlobalCfg().useIPv6(); + + boolean iStarted; + + private volatile boolean iSkipFirstRequest; + + private DatagramThread iDGThread = new DatagramThread(this); + + private TCPThread iTCPThread = new TCPThread(this); + + private ServiceTable iSrvTable = new ServiceTable(this.iDGThread); + + private MessageTable iMsgTable = new MessageTable(); + + /** + * main + * + * @param pArgs + * @throws IOException + */ + public static void main(String[] pArgs) throws IOException { + if (pArgs != null && pArgs.length >= 1) { + int port = Integer.parseInt(pArgs[0]); + SLPConfig.getGlobalCfg().setPort(port); + } + ServiceAgent srvAgent = new ServiceAgent(); + srvAgent.start(); + TRC.debug("starting idle loop"); + while (true) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + // lofasz + } + } + } + + /** + * setSkipFirstRequest + * + * @param pValue + */ + public void setSkipFirstRequest(boolean pValue) { + this.iSkipFirstRequest = pValue; + } + + /** + * start + * + * @throws IOException + */ + public void start() throws IOException { + if (this.iStarted) return; + // launch receivers + TRC.debug("start receivers"); + if (this.iUseV4 || this.iUseV6) { + this.iTCPThread.start(); + this.iDGThread.start(); + TRC.debug("wait4 TCP init"); + this.iTCPThread.wait4init(); + TRC.debug("wait4 Datagram init"); + this.iDGThread.wait4init(); + } + this.iStarted = true; + TRC.debug("receivers started"); + // join multicast groups + if (this.iUseV4) this.iDGThread.joinGroup(SLPConfig.getMulticastAddress()); + if (this.iUseV6) { + this.iDGThread.joinGroup(IPv6MulticastAddressFactory.getSrvLocAddress(SLPDefaults.IPV6_MULTICAST_SCOPE)); + } + } + + /** + * stop + */ + public void stop() { + // stop the receivers + if (this.iUseV4 || this.iUseV6) { + this.iTCPThread.stop(); + this.iDGThread.stop(); + } + this.iStarted = false; + } + + /** + * processMessage + * + * @param pDGSock + * @param pPacket + */ + public void processMessage(DatagramSocket pDGSock, DatagramPacket pPacket) { + byte[] reply; + SLPMessage msg; + try { + msg = MsgFactory.parse(pPacket); + } catch (Exception e) { + // no response for unparseable messages + TRC.debug("Message parsing error!", e); + return; + } + + try { + TRC.debug("processing: " + msg); + reply = this.iMsgTable.getResponse(pPacket.getAddress(), msg); + if (reply == null) { + SLPMessage replyMsg = makeReply(msg); + if (replyMsg != null) { + TRC.debug("response : " + replyMsg); + reply = replyMsg.serialize(false, true, true); + this.iMsgTable.addResponse(pPacket.getAddress(), msg, reply); + // debugging: do not reply to the first request + if (this.iSkipFirstRequest) { + TRC.debug("refusing response"); + return; + } + } + } else { + TRC.debug("cached response"); + } + } catch (ServiceLocationException e) { + TRC.debug(e.toString(), e); + reply = makeErrorReply(msg, e); // known XID + } + if (reply != null) { + try { + TRC.debug("sending response"); + pDGSock.send(new DatagramPacket(reply, reply.length, pPacket.getAddress(), pPacket.getPort())); + } catch (IOException e) { + TRC.error(e); + } + } + } + + /** + * processMessage + * + * @param pStreamSock + */ + public void processMessage(Socket pStreamSock) { + byte[] reply; + SLPMessage msg; + try { + msg = MsgFactory.parse(pStreamSock.getInputStream()); + } catch (Exception e) { + // no response for unparseable messages + TRC.debug("Message parsing error!", e); + return; + } + try { + SLPMessage replyMsg = makeReply(msg); + reply = replyMsg == null ? null : replyMsg.serialize(false, false, true); + } catch (ServiceLocationException e) { + reply = makeErrorReply(msg, e); + } + if (reply != null) { + try { + OutputStream os = pStreamSock.getOutputStream(); + os.write(reply); + os.flush(); + } catch (IOException e) { + TRC.error(e); + } + } + try { + pStreamSock.close(); + } catch (IOException e) { + TRC.error(e); + } + } + + /* + * XID is set to a unique value for each unique request. If the request is + * retransmitted, the same XID is used. Replies set the XID to the same + * value as the xid in the request. Only unsolicited DAAdverts are sent with + * an XID of 0. + */ + private SLPMessage makeReply(SLPMessage pRequest) throws ServiceLocationException { + try { + SLPMessage msg = pRequest instanceof RequestMessage + ? makeReply4Request((RequestMessage) pRequest) + : makeReply4Others(pRequest); + if (msg != null) msg.setXID(pRequest.getXID()); + return msg; + } catch (UnknownHostException e) { + TRC.error(e); + throw new ServiceLocationException(ServiceLocationException.NETWORK_ERROR); + } catch (IOException e) { + TRC.error(e); + throw new ServiceLocationException(ServiceLocationException.NETWORK_ERROR); + } + } + + private ReplyMessage makeReply4Request(RequestMessage pRequest) { + ReplyMessage replyMsg; + List scopes = pRequest.getScopeList(); + switch (pRequest.getFunctionID()) { + case SRV_RQST: + ServiceRequest srvRqst = (ServiceRequest) pRequest; + if (SLPDefaults.DA_SERVICE_TYPE.equals(srvRqst.getServiceType())) return null; + List urlList = this.iSrvTable.getServiceURLs(srvRqst.getServiceType(), scopes); + TRC.debug("srvReply : " + urlList); + replyMsg = new ServiceReply(0, urlList); + break; + case ATTR_RQST: + AttributeRequest attrRqst = (AttributeRequest) pRequest; + replyMsg = new AttributeReply(0, this.iSrvTable.getAttributes(attrRqst.getServiceURL(), scopes)); + break; + case SRV_TYPE_RQST: + // ServiceTypeRequest srvTypeRqst = + // (ServiceTypeRequest)pRequest; + replyMsg = new ServiceTypeReply(0, this.iSrvTable.getServiceTypes(scopes)); + break; + default: + return null; + } + return replyMsg; + } + + private SLPMessage makeReply4Others(SLPMessage pRequest) throws IOException { + switch (pRequest.getFunctionID()) { + case SRV_REG: + ServiceRegistration srvReg = (ServiceRegistration) pRequest; + this.iSrvTable.add(srvReg.getServiceURL(), srvReg.getAttributeList(), srvReg.getScopeList()); + return new ServiceAcknowledgment(0); + case SRV_DEREG: + ServiceDeregistration srvDereg = (ServiceDeregistration) pRequest; + this.iSrvTable.remove(srvDereg.getServiceURL()); + return new ServiceAcknowledgment(0); + default: + // FIXME maybe returning an error message is better + return null; + } + } + + private static byte[] makeErrorReply(SLPMessage pRequest, ServiceLocationException pE) { + return makeErrorReply(pRequest, pE.getErrorCode()); + } + + /* + * Error reply: SRV_REG, SRV_DEREG -> SRV_ACK SRV_RQST -> SRV_RSP ATTR_RQST + * -> ATTR_RPLY SRV_TYPE_RQST -> SRV_TYPE_RPLY + */ + + private static byte[] makeErrorReply(SLPMessage pRequest, int pErrorCode) { + ReplyMessage replyMsg; + switch (pRequest.getFunctionID()) { + case SRV_RQST: + replyMsg = new ServiceReply(pErrorCode, null); + break; + case ATTR_RQST: + replyMsg = new AttributeReply(pErrorCode, null); + break; + case SRV_TYPE_RQST: + replyMsg = new ServiceTypeReply(pErrorCode, null); + break; + case SRV_REG: + case SRV_DEREG: + replyMsg = new ServiceAcknowledgment(pErrorCode); + break; + default: + return null; + } + replyMsg.setXID(pRequest.getXID()); + try { + return replyMsg.serialize(false, true, true); + } catch (ServiceLocationException se) { + TRC.error(se); + return null; + } + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/sa/ServiceTable.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/sa/ServiceTable.java similarity index 77% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/sa/ServiceTable.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/sa/ServiceTable.java index 4c2e9f2..60f04ff 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/sa/ServiceTable.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/sa/ServiceTable.java @@ -1,421 +1,404 @@ -/* - (C) Copyright IBM Corp. 2007, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 3023349 2010-07-02 blaschke-oss SLP uses # constructor instead of valueOf - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.sa; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationAttribute; -import org.sentrysoftware.wbem.sblim.slp.ServiceType; -import org.sentrysoftware.wbem.sblim.slp.ServiceURL; -import org.sentrysoftware.wbem.sblim.slp.internal.IPv6MulticastAddressFactory; -import org.sentrysoftware.wbem.sblim.slp.internal.Net; -import org.sentrysoftware.wbem.sblim.slp.internal.SLPConfig; -import org.sentrysoftware.wbem.sblim.slp.internal.SLPDefaults; -import org.sentrysoftware.wbem.sblim.slp.internal.TRC; - -/** - * ServiceTable - * - */ -public class ServiceTable { - - DatagramThread iDgramThread; - - private boolean iUseV6 = Net.hasIPv6() && SLPConfig.getGlobalCfg().useIPv6(); - - class AddressHashTable { - - class Counter { - - /** - * iValue - */ - public int iValue = 1; - } - - /** - * AddressHash -> Counter - */ - private HashMap iMap = new HashMap(); - - /** - * register - * - * @param pType - * @throws UnknownHostException - * @throws IOException - */ - public void register(ServiceType pType) throws UnknownHostException, IOException { - Integer hash = Integer.valueOf(IPv6MulticastAddressFactory.getSrvTypeHash(pType)); - TRC.debug("srvType:" + pType + ", hash:" + hash); - Counter cntr = this.iMap.get(hash); - if (cntr == null) { - cntr = new Counter(); - this.iMap.put(hash, cntr); - ServiceTable.this.iDgramThread.joinGroup(IPv6MulticastAddressFactory.get( - SLPDefaults.IPV6_MULTICAST_SCOPE, hash.intValue())); - } else { - ++cntr.iValue; - } - - } - - /** - * unregister - * - * @param pType - * @throws UnknownHostException - * @throws IOException - */ - public void unregister(ServiceType pType) throws UnknownHostException, IOException { - Integer hash = Integer.valueOf(IPv6MulticastAddressFactory.getSrvTypeHash(pType)); - Counter cntr = this.iMap.get(hash); - if (cntr == null) return; - if (cntr.iValue <= 1) { - this.iMap.remove(hash); - ServiceTable.this.iDgramThread.leaveGroup(IPv6MulticastAddressFactory.get( - SLPDefaults.IPV6_MULTICAST_SCOPE, hash.intValue())); - } else { - --cntr.iValue; - } - } - - } - - private static class ServiceEntry { - - private ServiceURL iSrvURL; - - private List iAttribs; - - private List iScopes; - - /** - * Ctor. - * - * @param pSrvURL - * @param pAttribs - * @param pScopes - */ - public ServiceEntry(ServiceURL pSrvURL, List pAttribs, - List pScopes) { - set(pSrvURL, pAttribs, pScopes); - } - - /** - * set - * - * @param pSrvURL - * @param pAttribs - * @param pScopes - */ - public void set(ServiceURL pSrvURL, List pAttribs, - List pScopes) { - this.iSrvURL = pSrvURL; - this.iAttribs = pAttribs; - this.iScopes = pScopes; - } - - /** - * getServiceURL - * - * @return ServiceURL - */ - public ServiceURL getServiceURL() { - return this.iSrvURL; - } - - /** - * getServiceType - * - * @return ServiceType - */ - public ServiceType getServiceType() { - return this.iSrvURL.getServiceType(); - } - - /** - * getAttributes - * - * @return List - */ - public List getAttributes() { - return this.iAttribs; - } - - /** - * getScopes - * - * @return List - */ - public List getScopes() { - return this.iScopes; - } - - /** - * hasMatchingScope - * - * @param pScopes - * @return boolean - */ - public boolean hasMatchingScope(List pScopes) { - if (pScopes == null) return false; - Iterator itr = pScopes.iterator(); - while (itr.hasNext()) - if (hasScope(itr.next())) return true; - return false; - } - - @Override - public String toString() { - return "url:" + this.iSrvURL + ", attribs:" + dumpList(this.iAttribs) + ", scopes:" - + dumpList(this.iScopes); - } - - private boolean hasScope(String pScope) { - return this.iScopes == null ? false : this.iScopes.contains(pScope); - } - - } - - static class ServiceEntryList extends ArrayList { - - private static final long serialVersionUID = 1L; - - /** - * get - * - * @param pSrvURL - * @return ServiceEntry - */ - public ServiceEntry get(ServiceURL pSrvURL) { - for (int i = 0; i < size(); i++) { - ServiceEntry entry = (ServiceEntry) get(i); - if (pSrvURL.equals(entry.getServiceURL())) return entry; - } - return null; - } - - /** - * remove - * - * @param pSrvURL - */ - public void remove(ServiceURL pSrvURL) { - for (int i = 0; i < size(); i++) { - ServiceEntry entry = (ServiceEntry) get(i); - if (pSrvURL.equals(entry.getServiceURL())) { - remove(i); - break; - } - } - } - - /** - * getServiceURLs - * - * @param pSrvType - * @param pScopes - * @return List - */ - public List getServiceURLs(ServiceType pSrvType, List pScopes) { - if (pSrvType == null) return null; - List srvURLs = null; - for (int i = 0; i < size(); i++) { - ServiceEntry entry = (ServiceEntry) get(i); - if (!entry.hasMatchingScope(pScopes)) continue; - if (pSrvType.getPrincipleTypeName().equals( - entry.getServiceType().getPrincipleTypeName())) { - if (srvURLs == null) srvURLs = new ArrayList(); - srvURLs.add(entry.getServiceURL()); - } - } - return srvURLs; - } - - } - - private ServiceEntryList iSrvEntryTable = new ServiceEntryList(); - - private AddressHashTable iAddressHashTable = new AddressHashTable(); - - /** - * Ctor. - * - * @param pDgramThread - */ - public ServiceTable(DatagramThread pDgramThread) { - this.iDgramThread = pDgramThread; - } - - /** - * add - * - * @param pSrvURL - * @param pAttrList - * @param pScopes - * @throws UnknownHostException - * @throws IOException - */ - public synchronized void add(ServiceURL pSrvURL, List pAttrList, - List pScopes) throws UnknownHostException, IOException { - if (pSrvURL == null) return; - TRC.debug("add URL:" + pSrvURL + ", scopes:" + dumpList(pScopes)); - ServiceEntry srvEntry = this.iSrvEntryTable.get(pSrvURL); - if (srvEntry == null) { - this.iSrvEntryTable.add(new ServiceEntry(pSrvURL, pAttrList, pScopes)); - } else { - srvEntry.set(pSrvURL, pAttrList, pScopes); - } - - if (!this.iUseV6) return; - this.iAddressHashTable.register(pSrvURL.getServiceType()); - } - - /** - * remove - * - * @param pSrvURL - * @throws UnknownHostException - * @throws IOException - */ - public synchronized void remove(ServiceURL pSrvURL) throws UnknownHostException, IOException { - this.iSrvEntryTable.remove(pSrvURL); - - if (!this.iUseV6) return; - this.iAddressHashTable.unregister(pSrvURL.getServiceType()); - } - - /** - * getServiceURLs - * - * @param pSrvType - * @param pScopes - * @return List ServiceURL - */ - public synchronized List getServiceURLs(ServiceType pSrvType, List pScopes) { - TRC.debug("getServiceURLs srvType:" + pSrvType + ", scopes:" + dumpList(pScopes)); - List list = this.iSrvEntryTable.getServiceURLs(pSrvType, pScopes); - return list; - } - - /** - * getAttributes - * - * @param pSrvURL - * @param pScopes - * @return List ServiceLocationAttribute - */ - public synchronized List getAttributes(ServiceURL pSrvURL, - List pScopes) { - if (pSrvURL == null) return null; - if (pSrvURL.getURLPath() == null) return getAttributes(pSrvURL.getServiceType(), pScopes); - ServiceEntry entry = this.iSrvEntryTable.get(pSrvURL); - return entry == null ? null : entry.getAttributes(); - } - - /** - * getAttributes - * - * @param pSrvType - * @param pScopes - * @return List ServiceLocationAttribute - */ - public synchronized List getAttributes(ServiceType pSrvType, - List pScopes) { - if (pSrvType == null) return null; - HashSet attribs = new HashSet(); - for (int i = 0; i < this.iSrvEntryTable.size(); i++) { - ServiceEntry entry = (ServiceEntry) this.iSrvEntryTable.get(i); - ServiceType srvType = entry.getServiceType(); - if (pSrvType.equals(srvType)) attribs.addAll(entry.getAttributes()); - } - return new ArrayList(attribs); - } - - /** - * getServiceTypes - * - * @param pScopes - * @return List ServiceType - */ - public synchronized List getServiceTypes(List pScopes) { - List srvTypes = null; - for (int i = 0; i < this.iSrvEntryTable.size(); i++) { - ServiceEntry entry = (ServiceEntry) this.iSrvEntryTable.get(i); - if (entry.hasMatchingScope(pScopes)) { - ServiceType srvType = entry.getServiceType(); - if (srvType == null) continue; - if (srvTypes == null) srvTypes = new ArrayList(); - srvTypes.add(srvType); - } - } - return srvTypes; - } - - static String dumpList(List pList) { - return dumpList(pList, ","); - } - - private static String dumpList(List pList, String pSep) { - if (pList == null) return "null"; - StringBuffer buf = new StringBuffer(); - Iterator itr = pList.iterator(); - boolean first = true; - while (itr.hasNext()) { - if (!first) buf.append(pSep); - buf.append(itr.next().toString()); - first = false; - } - return buf.toString(); - } - -} +/* + (C) Copyright IBM Corp. 2007, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 3023349 2010-07-02 blaschke-oss SLP uses # constructor instead of valueOf + */ + +package org.metricshub.wbem.sblim.slp.internal.sa; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import org.metricshub.wbem.sblim.slp.ServiceLocationAttribute; +import org.metricshub.wbem.sblim.slp.ServiceType; +import org.metricshub.wbem.sblim.slp.ServiceURL; +import org.metricshub.wbem.sblim.slp.internal.IPv6MulticastAddressFactory; +import org.metricshub.wbem.sblim.slp.internal.Net; +import org.metricshub.wbem.sblim.slp.internal.SLPConfig; +import org.metricshub.wbem.sblim.slp.internal.SLPDefaults; +import org.metricshub.wbem.sblim.slp.internal.TRC; + +/** + * ServiceTable + * + */ +public class ServiceTable { + DatagramThread iDgramThread; + + private boolean iUseV6 = Net.hasIPv6() && SLPConfig.getGlobalCfg().useIPv6(); + + class AddressHashTable { + + class Counter { + /** + * iValue + */ + public int iValue = 1; + } + + /** + * AddressHash -> Counter + */ + private HashMap iMap = new HashMap(); + + /** + * register + * + * @param pType + * @throws UnknownHostException + * @throws IOException + */ + public void register(ServiceType pType) throws UnknownHostException, IOException { + Integer hash = Integer.valueOf(IPv6MulticastAddressFactory.getSrvTypeHash(pType)); + TRC.debug("srvType:" + pType + ", hash:" + hash); + Counter cntr = this.iMap.get(hash); + if (cntr == null) { + cntr = new Counter(); + this.iMap.put(hash, cntr); + ServiceTable.this.iDgramThread.joinGroup( + IPv6MulticastAddressFactory.get(SLPDefaults.IPV6_MULTICAST_SCOPE, hash.intValue()) + ); + } else { + ++cntr.iValue; + } + } + + /** + * unregister + * + * @param pType + * @throws UnknownHostException + * @throws IOException + */ + public void unregister(ServiceType pType) throws UnknownHostException, IOException { + Integer hash = Integer.valueOf(IPv6MulticastAddressFactory.getSrvTypeHash(pType)); + Counter cntr = this.iMap.get(hash); + if (cntr == null) return; + if (cntr.iValue <= 1) { + this.iMap.remove(hash); + ServiceTable.this.iDgramThread.leaveGroup( + IPv6MulticastAddressFactory.get(SLPDefaults.IPV6_MULTICAST_SCOPE, hash.intValue()) + ); + } else { + --cntr.iValue; + } + } + } + + private static class ServiceEntry { + private ServiceURL iSrvURL; + + private List iAttribs; + + private List iScopes; + + /** + * Ctor. + * + * @param pSrvURL + * @param pAttribs + * @param pScopes + */ + public ServiceEntry(ServiceURL pSrvURL, List pAttribs, List pScopes) { + set(pSrvURL, pAttribs, pScopes); + } + + /** + * set + * + * @param pSrvURL + * @param pAttribs + * @param pScopes + */ + public void set(ServiceURL pSrvURL, List pAttribs, List pScopes) { + this.iSrvURL = pSrvURL; + this.iAttribs = pAttribs; + this.iScopes = pScopes; + } + + /** + * getServiceURL + * + * @return ServiceURL + */ + public ServiceURL getServiceURL() { + return this.iSrvURL; + } + + /** + * getServiceType + * + * @return ServiceType + */ + public ServiceType getServiceType() { + return this.iSrvURL.getServiceType(); + } + + /** + * getAttributes + * + * @return List + */ + public List getAttributes() { + return this.iAttribs; + } + + /** + * getScopes + * + * @return List + */ + public List getScopes() { + return this.iScopes; + } + + /** + * hasMatchingScope + * + * @param pScopes + * @return boolean + */ + public boolean hasMatchingScope(List pScopes) { + if (pScopes == null) return false; + Iterator itr = pScopes.iterator(); + while (itr.hasNext()) if (hasScope(itr.next())) return true; + return false; + } + + @Override + public String toString() { + return "url:" + this.iSrvURL + ", attribs:" + dumpList(this.iAttribs) + ", scopes:" + dumpList(this.iScopes); + } + + private boolean hasScope(String pScope) { + return this.iScopes == null ? false : this.iScopes.contains(pScope); + } + } + + static class ServiceEntryList extends ArrayList { + private static final long serialVersionUID = 1L; + + /** + * get + * + * @param pSrvURL + * @return ServiceEntry + */ + public ServiceEntry get(ServiceURL pSrvURL) { + for (int i = 0; i < size(); i++) { + ServiceEntry entry = (ServiceEntry) get(i); + if (pSrvURL.equals(entry.getServiceURL())) return entry; + } + return null; + } + + /** + * remove + * + * @param pSrvURL + */ + public void remove(ServiceURL pSrvURL) { + for (int i = 0; i < size(); i++) { + ServiceEntry entry = (ServiceEntry) get(i); + if (pSrvURL.equals(entry.getServiceURL())) { + remove(i); + break; + } + } + } + + /** + * getServiceURLs + * + * @param pSrvType + * @param pScopes + * @return List + */ + public List getServiceURLs(ServiceType pSrvType, List pScopes) { + if (pSrvType == null) return null; + List srvURLs = null; + for (int i = 0; i < size(); i++) { + ServiceEntry entry = (ServiceEntry) get(i); + if (!entry.hasMatchingScope(pScopes)) continue; + if (pSrvType.getPrincipleTypeName().equals(entry.getServiceType().getPrincipleTypeName())) { + if (srvURLs == null) srvURLs = new ArrayList(); + srvURLs.add(entry.getServiceURL()); + } + } + return srvURLs; + } + } + + private ServiceEntryList iSrvEntryTable = new ServiceEntryList(); + + private AddressHashTable iAddressHashTable = new AddressHashTable(); + + /** + * Ctor. + * + * @param pDgramThread + */ + public ServiceTable(DatagramThread pDgramThread) { + this.iDgramThread = pDgramThread; + } + + /** + * add + * + * @param pSrvURL + * @param pAttrList + * @param pScopes + * @throws UnknownHostException + * @throws IOException + */ + public synchronized void add(ServiceURL pSrvURL, List pAttrList, List pScopes) + throws UnknownHostException, IOException { + if (pSrvURL == null) return; + TRC.debug("add URL:" + pSrvURL + ", scopes:" + dumpList(pScopes)); + ServiceEntry srvEntry = this.iSrvEntryTable.get(pSrvURL); + if (srvEntry == null) { + this.iSrvEntryTable.add(new ServiceEntry(pSrvURL, pAttrList, pScopes)); + } else { + srvEntry.set(pSrvURL, pAttrList, pScopes); + } + + if (!this.iUseV6) return; + this.iAddressHashTable.register(pSrvURL.getServiceType()); + } + + /** + * remove + * + * @param pSrvURL + * @throws UnknownHostException + * @throws IOException + */ + public synchronized void remove(ServiceURL pSrvURL) throws UnknownHostException, IOException { + this.iSrvEntryTable.remove(pSrvURL); + + if (!this.iUseV6) return; + this.iAddressHashTable.unregister(pSrvURL.getServiceType()); + } + + /** + * getServiceURLs + * + * @param pSrvType + * @param pScopes + * @return List ServiceURL + */ + public synchronized List getServiceURLs(ServiceType pSrvType, List pScopes) { + TRC.debug("getServiceURLs srvType:" + pSrvType + ", scopes:" + dumpList(pScopes)); + List list = this.iSrvEntryTable.getServiceURLs(pSrvType, pScopes); + return list; + } + + /** + * getAttributes + * + * @param pSrvURL + * @param pScopes + * @return List ServiceLocationAttribute + */ + public synchronized List getAttributes(ServiceURL pSrvURL, List pScopes) { + if (pSrvURL == null) return null; + if (pSrvURL.getURLPath() == null) return getAttributes(pSrvURL.getServiceType(), pScopes); + ServiceEntry entry = this.iSrvEntryTable.get(pSrvURL); + return entry == null ? null : entry.getAttributes(); + } + + /** + * getAttributes + * + * @param pSrvType + * @param pScopes + * @return List ServiceLocationAttribute + */ + public synchronized List getAttributes(ServiceType pSrvType, List pScopes) { + if (pSrvType == null) return null; + HashSet attribs = new HashSet(); + for (int i = 0; i < this.iSrvEntryTable.size(); i++) { + ServiceEntry entry = (ServiceEntry) this.iSrvEntryTable.get(i); + ServiceType srvType = entry.getServiceType(); + if (pSrvType.equals(srvType)) attribs.addAll(entry.getAttributes()); + } + return new ArrayList(attribs); + } + + /** + * getServiceTypes + * + * @param pScopes + * @return List ServiceType + */ + public synchronized List getServiceTypes(List pScopes) { + List srvTypes = null; + for (int i = 0; i < this.iSrvEntryTable.size(); i++) { + ServiceEntry entry = (ServiceEntry) this.iSrvEntryTable.get(i); + if (entry.hasMatchingScope(pScopes)) { + ServiceType srvType = entry.getServiceType(); + if (srvType == null) continue; + if (srvTypes == null) srvTypes = new ArrayList(); + srvTypes.add(srvType); + } + } + return srvTypes; + } + + static String dumpList(List pList) { + return dumpList(pList, ","); + } + + private static String dumpList(List pList, String pSep) { + if (pList == null) return "null"; + StringBuffer buf = new StringBuffer(); + Iterator itr = pList.iterator(); + boolean first = true; + while (itr.hasNext()) { + if (!first) buf.append(pSep); + buf.append(itr.next().toString()); + first = false; + } + return buf.toString(); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/sa/TCPThread.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/sa/TCPThread.java similarity index 70% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/sa/TCPThread.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/sa/TCPThread.java index 2c07417..7ef60f6 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/sa/TCPThread.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/sa/TCPThread.java @@ -1,117 +1,110 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.sa; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.SocketTimeoutException; - -import org.sentrysoftware.wbem.sblim.slp.internal.SLPConfig; -import org.sentrysoftware.wbem.sblim.slp.internal.TRC; - -/** - * TCPThread - * - */ -public class TCPThread extends RecieverThread { - - private ServerSocket iListenerSocket; - - /** - * Ctor. - * - * @param pSrvAgent - */ - public TCPThread(ServiceAgent pSrvAgent) { - super("TCP receiver", pSrvAgent); - } - - @Override - protected void init() throws IOException { - this.iListenerSocket = new ServerSocket(SLPConfig.getGlobalCfg().getPort()); - this.iListenerSocket.setReuseAddress(true); - this.iListenerSocket.setSoTimeout(100); - } - - @Override - protected void mainLoop() throws IOException { - try { - new ConnectionThread(this.iListenerSocket.accept()); - } catch (SocketTimeoutException e) { - // superclass will execute the mainLoop again - } - } - - private class ConnectionThread implements Runnable { - - private Socket iSock; - - /** - * Ctor. - * - * @param pSock - */ - public ConnectionThread(Socket pSock) { - this.iSock = pSock; - new Thread(this).start(); - } - - public void run() { - TCPThread.this.iSrvAgent.processMessage(this.iSock); - } - - } - - @Override - protected void close() { - if (this.iListenerSocket == null) return; - try { - this.iListenerSocket.close(); - } catch (IOException e) { - TRC.error(e); - } - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + */ + +package org.metricshub.wbem.sblim.slp.internal.sa; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketTimeoutException; +import org.metricshub.wbem.sblim.slp.internal.SLPConfig; +import org.metricshub.wbem.sblim.slp.internal.TRC; + +/** + * TCPThread + * + */ +public class TCPThread extends RecieverThread { + private ServerSocket iListenerSocket; + + /** + * Ctor. + * + * @param pSrvAgent + */ + public TCPThread(ServiceAgent pSrvAgent) { + super("TCP receiver", pSrvAgent); + } + + @Override + protected void init() throws IOException { + this.iListenerSocket = new ServerSocket(SLPConfig.getGlobalCfg().getPort()); + this.iListenerSocket.setReuseAddress(true); + this.iListenerSocket.setSoTimeout(100); + } + + @Override + protected void mainLoop() throws IOException { + try { + new ConnectionThread(this.iListenerSocket.accept()); + } catch (SocketTimeoutException e) { + // superclass will execute the mainLoop again + } + } + + private class ConnectionThread implements Runnable { + private Socket iSock; + + /** + * Ctor. + * + * @param pSock + */ + public ConnectionThread(Socket pSock) { + this.iSock = pSock; + new Thread(this).start(); + } + + public void run() { + TCPThread.this.iSrvAgent.processMessage(this.iSock); + } + } + + @Override + protected void close() { + if (this.iListenerSocket == null) return; + try { + this.iListenerSocket.close(); + } catch (IOException e) { + TRC.error(e); + } + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/ua/DACache.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/ua/DACache.java similarity index 79% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/ua/DACache.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/ua/DACache.java index d4bbea2..543a827 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/ua/DACache.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/ua/DACache.java @@ -1,175 +1,168 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.ua; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.TreeMap; -import java.util.TreeSet; - -import org.sentrysoftware.wbem.sblim.slp.internal.SLPDefaults; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.DADescriptor; - -/** - * DACache caches the discovered DA list in order to eliminate frequent DA - * discovery network traffic. - * - */ -public class DACache { - - private static class ScopeEntry { - - private long iTimeOfDiscovery; - - private TreeSet iDADescriptors; - - /** - * Ctor. - * - * @param pDADescriptors - */ - public ScopeEntry(TreeSet pDADescriptors) { - this.iDADescriptors = pDADescriptors; - this.iTimeOfDiscovery = getSecs(); - } - - /** - * valid - * - * @return boolean - */ - public boolean valid() { - return getSecs() - this.iTimeOfDiscovery <= SLPDefaults.DACACHE_TIMEOUT; - } - - /** - * getDADescriptorItr - * - * @return Iterator - */ - public Iterator getDADescriptorItr() { - return this.iDADescriptors == null ? null : this.iDADescriptors.iterator(); - } - - } - - /** - * key: scope value: ScopeEntry - */ - private static TreeMap cScopeMap = new TreeMap(); - - // TODO: handle scopes - - /** - * @param pScopes - * @return List of discoverable scope strings - */ - public static synchronized List getDiscoverableScopeList(List pScopes) { - if (pScopes == null || pScopes.size() == 0) return null; - List scopeList = null; - Iterator itr = pScopes.iterator(); - while (itr.hasNext()) { - String scope = itr.next(); - ScopeEntry scopeEntry = cScopeMap.get(scope); - if (scopeEntry == null || !scopeEntry.valid()) { - if (scopeList == null) scopeList = new ArrayList(); - scopeList.add(scope); - } - } - return scopeList; - } - - /** - * @param pScopes - * @return List of DA URLs - */ - public static synchronized List getDAList(List pScopes) { - if (cScopeMap == null) return null; - TreeSet daSet = new TreeSet(); - Iterator scopeItr = pScopes.iterator(); - while (scopeItr.hasNext()) { - String scope = scopeItr.next(); - ScopeEntry scopeEntry = cScopeMap.get(scope); - if (scopeEntry == null) continue; - Iterator descItr = scopeEntry.getDADescriptorItr(); - if (descItr == null) continue; - while (descItr.hasNext()) { - daSet.add(descItr.next().getURL()); - } - } - return new ArrayList(daSet); - } - - /** - * @param pScopes - * - list of discovered hosts - * @param pDADescriptors - * - DADescriptors of the discovered DAs - */ - public static synchronized void setDAList(List pScopes, - List pDADescriptors) { - if (pScopes == null || pDADescriptors == null) return; - Iterator scopeItr = pScopes.iterator(); - while (scopeItr.hasNext()) { - String scope = scopeItr.next(); - TreeSet daDescsForScope = null; - Iterator descItr = pDADescriptors.iterator(); - while (descItr.hasNext()) { - DADescriptor daDesc = descItr.next(); - if (daDesc.hasScope(scope)) { - if (daDescsForScope == null) daDescsForScope = new TreeSet(); - daDescsForScope.add(daDesc); - } - } - cScopeMap.put(scope, new ScopeEntry(daDescsForScope)); - } - } - - static long getSecs() { - return new Date().getTime() / 1000; - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp.internal.ua; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.TreeMap; +import java.util.TreeSet; +import org.metricshub.wbem.sblim.slp.internal.SLPDefaults; +import org.metricshub.wbem.sblim.slp.internal.msg.DADescriptor; + +/** + * DACache caches the discovered DA list in order to eliminate frequent DA + * discovery network traffic. + * + */ +public class DACache { + + private static class ScopeEntry { + private long iTimeOfDiscovery; + + private TreeSet iDADescriptors; + + /** + * Ctor. + * + * @param pDADescriptors + */ + public ScopeEntry(TreeSet pDADescriptors) { + this.iDADescriptors = pDADescriptors; + this.iTimeOfDiscovery = getSecs(); + } + + /** + * valid + * + * @return boolean + */ + public boolean valid() { + return getSecs() - this.iTimeOfDiscovery <= SLPDefaults.DACACHE_TIMEOUT; + } + + /** + * getDADescriptorItr + * + * @return Iterator + */ + public Iterator getDADescriptorItr() { + return this.iDADescriptors == null ? null : this.iDADescriptors.iterator(); + } + } + + /** + * key: scope value: ScopeEntry + */ + private static TreeMap cScopeMap = new TreeMap(); + + // TODO: handle scopes + + /** + * @param pScopes + * @return List of discoverable scope strings + */ + public static synchronized List getDiscoverableScopeList(List pScopes) { + if (pScopes == null || pScopes.size() == 0) return null; + List scopeList = null; + Iterator itr = pScopes.iterator(); + while (itr.hasNext()) { + String scope = itr.next(); + ScopeEntry scopeEntry = cScopeMap.get(scope); + if (scopeEntry == null || !scopeEntry.valid()) { + if (scopeList == null) scopeList = new ArrayList(); + scopeList.add(scope); + } + } + return scopeList; + } + + /** + * @param pScopes + * @return List of DA URLs + */ + public static synchronized List getDAList(List pScopes) { + if (cScopeMap == null) return null; + TreeSet daSet = new TreeSet(); + Iterator scopeItr = pScopes.iterator(); + while (scopeItr.hasNext()) { + String scope = scopeItr.next(); + ScopeEntry scopeEntry = cScopeMap.get(scope); + if (scopeEntry == null) continue; + Iterator descItr = scopeEntry.getDADescriptorItr(); + if (descItr == null) continue; + while (descItr.hasNext()) { + daSet.add(descItr.next().getURL()); + } + } + return new ArrayList(daSet); + } + + /** + * @param pScopes + * - list of discovered hosts + * @param pDADescriptors + * - DADescriptors of the discovered DAs + */ + public static synchronized void setDAList(List pScopes, List pDADescriptors) { + if (pScopes == null || pDADescriptors == null) return; + Iterator scopeItr = pScopes.iterator(); + while (scopeItr.hasNext()) { + String scope = scopeItr.next(); + TreeSet daDescsForScope = null; + Iterator descItr = pDADescriptors.iterator(); + while (descItr.hasNext()) { + DADescriptor daDesc = descItr.next(); + if (daDesc.hasScope(scope)) { + if (daDescsForScope == null) daDescsForScope = new TreeSet(); + daDescsForScope.add(daDesc); + } + } + cScopeMap.put(scope, new ScopeEntry(daDescsForScope)); + } + } + + static long getSecs() { + return new Date().getTime() / 1000; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/ua/DatagramRequester.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/ua/DatagramRequester.java similarity index 78% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/ua/DatagramRequester.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/ua/DatagramRequester.java index 47b8795..9eefc37 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/ua/DatagramRequester.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/ua/DatagramRequester.java @@ -1,419 +1,407 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1804402 2007-11-10 ebak IPv6 ready SLP - revision 4 - * 1892103 2008-02-12 ebak SLP improvements - * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery - * 1950819 2008-04-24 rgummada SLP error: "java.io.IOException" on Linux and IPv6 - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2839595 2009-09-30 rgummada SLP discovery fails on Unix IPv6 systems - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.ua; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.net.DatagramPacket; -import java.net.DatagramSocket; -import java.net.Inet6Address; -import java.net.InetAddress; -import java.net.MulticastSocket; -import java.net.SocketTimeoutException; -import java.util.ArrayList; -import java.util.Date; -import java.util.Iterator; -import java.util.List; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; -import org.sentrysoftware.wbem.sblim.slp.internal.IPv6MulticastAddressFactory; -import org.sentrysoftware.wbem.sblim.slp.internal.Net; -import org.sentrysoftware.wbem.sblim.slp.internal.SLPConfig; -import org.sentrysoftware.wbem.sblim.slp.internal.SLPDefaults; -import org.sentrysoftware.wbem.sblim.slp.internal.TRC; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.MsgFactory; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.ReplyMessage; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.RequestMessage; - -/** - * DatagramRequester - * - */ -public class DatagramRequester implements Runnable { - - RequestMessage iReqMsg; - - private Thread iThread; - - ResultTable iResTable; - - private InetAddress iDst0, iDst1; - - private DatagramSocket iDGramSocket; - - private int iPort = SLPConfig.getGlobalCfg().getPort(); - - private boolean iUseV4 = Net.hasIPv4() && SLPConfig.getGlobalCfg().useIPv4(), iUseV6 = Net - .hasIPv6() - && SLPConfig.getGlobalCfg().useIPv6(); - - private List iTCPRequesters; - - int iTotalTimeOut; - - int[] iTimeOuts; - - int iMaxResults = SLPConfig.getGlobalCfg().getMaximumResults(); - - /* - * this size is used for the receiver instead of the configurable MTU size - */ - private static final int MAX_DATAGRAM_SIZE = 65536; - - private final byte[] iInBuf = new byte[MAX_DATAGRAM_SIZE]; - - /** - * Constructor used for unicast requests - * - * @param pRqstMsg - * @param pResTable - * @param pDst - * @throws IOException - */ - public DatagramRequester(RequestMessage pRqstMsg, ResultTable pResTable, InetAddress pDst) - throws IOException { - this.iReqMsg = pRqstMsg; - this.iResTable = pResTable; - this.iDst0 = pDst; - this.iTimeOuts = SLPConfig.getGlobalCfg().getDatagramTimeouts(); - this.iDGramSocket = new DatagramSocket(); - } - - /** - * Constructor used for multicast requests - * - * @param pRqstMsg - * @param pResTable - * @throws IOException - */ - public DatagramRequester(RequestMessage pRqstMsg, ResultTable pResTable) throws IOException { - this.iReqMsg = pRqstMsg; - this.iResTable = pResTable; - this.iTimeOuts = SLPConfig.getGlobalCfg().getMulticastTimeouts(); - this.iTotalTimeOut = SLPConfig.getGlobalCfg().getMulticastMaximumWait(); - MulticastSocket mcastSocket = new MulticastSocket(); - this.iDGramSocket = mcastSocket; - if (this.iUseV6) { - this.iDst0 = IPv6MulticastAddressFactory - .get(SLPDefaults.IPV6_MULTICAST_SCOPE, pRqstMsg); - try { - mcastSocket.joinGroup(this.iDst0); - } catch (IOException ioe) { - // some kernels can't handle IPv6 mcast - TRC.warning("IOException caught during join, disabling IPv6: " + ioe.getMessage(), - ioe); - this.iDst0 = null; - } - } - if (this.iUseV4) { - this.iDst1 = SLPConfig.getMulticastAddress(); - mcastSocket.joinGroup(this.iDst1); - } - } - - /** - * start - * - * @param pAsThread - */ - public void start(boolean pAsThread) { - this.iResTable.registerRequester(this); - if (pAsThread) { - this.iThread = new Thread(this); - this.iThread.start(); - } else { - this.iThread = null; - run(); - } - } - - /** - * For diagnostic only. - * - * @return int - */ - public int getPort() { - return this.iDGramSocket == null ? -1 : this.iDGramSocket.getLocalPort(); - } - - /** - * waitFor - */ - public void waitFor() { - if (this.iThread == null) return; - try { - this.iThread.join(); - } catch (InterruptedException e) { - TRC.error(e); - } - } - - public void run() { - try { - if (this.iDGramSocket instanceof MulticastSocket) { - mcastNegotiate(); - } else { - ucastNegotiate(); - } - } catch (Exception e) { - this.iResTable.addException(e); - TRC.error(e.getMessage(), e); - } finally { - this.iDGramSocket.close(); - this.iResTable.unregisterRequester(this); - } - } - - class MCastLoopController { - - private long iStartTime = getMillis(); - - private int iTimeOutIdx = 0; - - /** - * getTimeOut - * - * @return int - */ - public int getTimeOut() { - return DatagramRequester.this.iTimeOuts[this.iTimeOutIdx]; - } - - private boolean hasNextTimeOut() { - return this.iTimeOutIdx < DatagramRequester.this.iTimeOuts.length; - } - - /** - * nextTimeOut - */ - public void nextTimeOut() { - if (hasNextTimeOut()) ++this.iTimeOutIdx; - } - - /** - * hasNext - * - * @return boolean - */ - public boolean hasNext() { - return DatagramRequester.this.iResTable.getTotalResponses() < DatagramRequester.this.iMaxResults - && getMillis() - this.iStartTime < DatagramRequester.this.iTotalTimeOut - && hasNextTimeOut(); - } - - } - - private void mcastNegotiate() throws Exception { - byte[] reqBytes = this.iReqMsg.serialize(true, true, false); - DatagramPacket outPacket0 = this.iDst0 == null ? null : new DatagramPacket(reqBytes, - reqBytes.length, this.iDst0, this.iPort); - DatagramPacket outPacket1 = this.iDst1 == null ? null : new DatagramPacket(reqBytes, - reqBytes.length, this.iDst1, this.iPort); - DatagramPacket inPacket = new DatagramPacket(this.iInBuf, this.iInBuf.length); - MCastLoopController ctrl = new MCastLoopController(); - boolean respondersUpdated = false; - ResponseCache rspCache = new ResponseCache(); - sendLoop: while (ctrl.hasNext()) { - if (respondersUpdated) { - byte[] msg = this.iReqMsg.serialize(true, true, true); - if (outPacket0 != null) outPacket0.setData(msg); - if (outPacket1 != null) outPacket1.setData(msg); - respondersUpdated = false; - } - // send it relative frequently in order to avoid lost packets - TRC.debug("sending: " + this.iReqMsg); - - try { - if (outPacket0 != null) this.iDGramSocket.send(outPacket0); - } catch (IOException ioe) { - // some back level kernels can't handle sending IPv6 mcast - TRC.warning("IOException caught during send, disabling IPv6: " + ioe.getMessage(), - ioe); - outPacket0 = null; - this.iDst0 = null; - } - - if (outPacket1 != null) this.iDGramSocket.send(outPacket1); - while (ctrl.hasNext()) { - this.iDGramSocket.setSoTimeout(ctrl.getTimeOut()); - try { - this.iDGramSocket.receive(inPacket); - } catch (SocketTimeoutException e) { - // set new timeout value - TRC.debug("receive timed out"); - ctrl.nextTimeOut(); - continue sendLoop; - } - InetAddress responderAddress = inPacket.getAddress(); - - respondersUpdated = this.iReqMsg.updatePrevResponders(responderAddress.toString()); - - if (rspCache.contains(inPacket)) { - TRC.debug("received packet is found in rspCache"); - continue; // packet data is already processed - } - ReplyMessage replyMsg = handleResponse(inPacket); - - if (replyMsg != null) { - if (replyMsg.overflows()) { - if (!isLinkLocal(responderAddress)) { - // TCP doesn't seem to be working on linkLocal IPv6 - // connection - addTCPRequester(responderAddress); - rspCache.add(inPacket); - } - } else { - rspCache.add(inPacket); - } - } - } - break; - } - waitForTCPRequesters(); - } - - private void ucastNegotiate() throws Exception { - byte[] reqBytes = this.iReqMsg.serialize(false, true, false); - DatagramPacket outPacket = new DatagramPacket(reqBytes, reqBytes.length, this.iDst0, - this.iPort); - DatagramPacket inPacket = new DatagramPacket(this.iInBuf, this.iInBuf.length); - int timeOutIdx = 0; - int timeOut = this.iTimeOuts[timeOutIdx]; - /* - * ad-hoc solution to avoid endless loop in case of broken answers - */ - int tries = 10; - while (timeOutIdx < this.iTimeOuts.length && tries > 0) { - // send it relative frequently in order to avoid lost packets - TRC.debug("sending: " + this.iReqMsg); - this.iDGramSocket.send(outPacket); - this.iDGramSocket.setSoTimeout(timeOut); - try { - this.iDGramSocket.receive(inPacket); - } catch (SocketTimeoutException e) { - // set new timeout value - TRC.debug("receive timed out"); - timeOut = this.iTimeOuts[timeOutIdx++]; - continue; - } - InetAddress responderAddress = inPacket.getAddress(); - ReplyMessage replyMsg = handleResponse(inPacket); - if (replyMsg == null) { - --tries; - continue; - } - if (replyMsg.overflows()) { - TCPRequester tcpRequester = new TCPRequester(this.iResTable, responderAddress, - this.iReqMsg, true); - tcpRequester.waitFor(); - } - /* - * one answer is wanted from one host - */ - break; - } - } - - /** - * Tries to parse the content of the packet as a ReplyMessage. If parsing is - * successful ReplyMessage is placed into the ResultTable, otherwise the - * Exception is placed there. - * - * @param pPacket - * @return the ReplyMessage or null in case of - * - * Add all invalid URL exceptions thrown by parser into exception - * table - */ - private ReplyMessage handleResponse(DatagramPacket pPacket) { - ReplyMessage replyMsg; - try { - replyMsg = (ReplyMessage) MsgFactory.parse(pPacket); - TRC.debug("expected: " + this.iReqMsg.getXID() + ", received: " + replyMsg); - if (this.iReqMsg.getXID() != replyMsg.getXID() - || !this.iReqMsg.isAllowedResponseType(replyMsg)) { - TRC.debug("expected: " + this.iReqMsg.getXID() + ", ignoring: " + replyMsg); - return null; - } - } catch (Exception e) { - this.iResTable.addException(e); - return null; - } - TRC.debug("resTable <- " + replyMsg); - this.iResTable.addResults(replyMsg); - this.iResTable.addExceptions(replyMsg); - return replyMsg; - } - - private static boolean isLinkLocal(InetAddress pAddr) { - if (pAddr instanceof Inet6Address) { - Inet6Address dest6 = (Inet6Address) pAddr; - // TCP on linkLocal is evil - return dest6.isLinkLocalAddress(); - } - return false; - } - - static long getMillis() { - return new Date().getTime(); - } - - private void addTCPRequester(InetAddress pDest) throws ServiceLocationException { - if (this.iTCPRequesters == null) this.iTCPRequesters = new ArrayList(); - this.iTCPRequesters.add(new TCPRequester(this.iResTable, pDest, this.iReqMsg, true)); - } - - private void waitForTCPRequesters() { - if (this.iTCPRequesters == null) return; - Iterator itr = this.iTCPRequesters.iterator(); - while (itr.hasNext()) - itr.next().waitFor(); - this.iTCPRequesters.clear(); - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1804402 2007-11-10 ebak IPv6 ready SLP - revision 4 + * 1892103 2008-02-12 ebak SLP improvements + * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery + * 1950819 2008-04-24 rgummada SLP error: "java.io.IOException" on Linux and IPv6 + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2839595 2009-09-30 rgummada SLP discovery fails on Unix IPv6 systems + */ + +package org.metricshub.wbem.sblim.slp.internal.ua; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.Inet6Address; +import java.net.InetAddress; +import java.net.MulticastSocket; +import java.net.SocketTimeoutException; +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; +import org.metricshub.wbem.sblim.slp.internal.IPv6MulticastAddressFactory; +import org.metricshub.wbem.sblim.slp.internal.Net; +import org.metricshub.wbem.sblim.slp.internal.SLPConfig; +import org.metricshub.wbem.sblim.slp.internal.SLPDefaults; +import org.metricshub.wbem.sblim.slp.internal.TRC; +import org.metricshub.wbem.sblim.slp.internal.msg.MsgFactory; +import org.metricshub.wbem.sblim.slp.internal.msg.ReplyMessage; +import org.metricshub.wbem.sblim.slp.internal.msg.RequestMessage; + +/** + * DatagramRequester + * + */ +public class DatagramRequester implements Runnable { + RequestMessage iReqMsg; + + private Thread iThread; + + ResultTable iResTable; + + private InetAddress iDst0, iDst1; + + private DatagramSocket iDGramSocket; + + private int iPort = SLPConfig.getGlobalCfg().getPort(); + + private boolean iUseV4 = Net.hasIPv4() && SLPConfig.getGlobalCfg().useIPv4(), iUseV6 = + Net.hasIPv6() && SLPConfig.getGlobalCfg().useIPv6(); + + private List iTCPRequesters; + + int iTotalTimeOut; + + int[] iTimeOuts; + + int iMaxResults = SLPConfig.getGlobalCfg().getMaximumResults(); + + /* + * this size is used for the receiver instead of the configurable MTU size + */ + private static final int MAX_DATAGRAM_SIZE = 65536; + + private final byte[] iInBuf = new byte[MAX_DATAGRAM_SIZE]; + + /** + * Constructor used for unicast requests + * + * @param pRqstMsg + * @param pResTable + * @param pDst + * @throws IOException + */ + public DatagramRequester(RequestMessage pRqstMsg, ResultTable pResTable, InetAddress pDst) throws IOException { + this.iReqMsg = pRqstMsg; + this.iResTable = pResTable; + this.iDst0 = pDst; + this.iTimeOuts = SLPConfig.getGlobalCfg().getDatagramTimeouts(); + this.iDGramSocket = new DatagramSocket(); + } + + /** + * Constructor used for multicast requests + * + * @param pRqstMsg + * @param pResTable + * @throws IOException + */ + public DatagramRequester(RequestMessage pRqstMsg, ResultTable pResTable) throws IOException { + this.iReqMsg = pRqstMsg; + this.iResTable = pResTable; + this.iTimeOuts = SLPConfig.getGlobalCfg().getMulticastTimeouts(); + this.iTotalTimeOut = SLPConfig.getGlobalCfg().getMulticastMaximumWait(); + MulticastSocket mcastSocket = new MulticastSocket(); + this.iDGramSocket = mcastSocket; + if (this.iUseV6) { + this.iDst0 = IPv6MulticastAddressFactory.get(SLPDefaults.IPV6_MULTICAST_SCOPE, pRqstMsg); + try { + mcastSocket.joinGroup(this.iDst0); + } catch (IOException ioe) { + // some kernels can't handle IPv6 mcast + TRC.warning("IOException caught during join, disabling IPv6: " + ioe.getMessage(), ioe); + this.iDst0 = null; + } + } + if (this.iUseV4) { + this.iDst1 = SLPConfig.getMulticastAddress(); + mcastSocket.joinGroup(this.iDst1); + } + } + + /** + * start + * + * @param pAsThread + */ + public void start(boolean pAsThread) { + this.iResTable.registerRequester(this); + if (pAsThread) { + this.iThread = new Thread(this); + this.iThread.start(); + } else { + this.iThread = null; + run(); + } + } + + /** + * For diagnostic only. + * + * @return int + */ + public int getPort() { + return this.iDGramSocket == null ? -1 : this.iDGramSocket.getLocalPort(); + } + + /** + * waitFor + */ + public void waitFor() { + if (this.iThread == null) return; + try { + this.iThread.join(); + } catch (InterruptedException e) { + TRC.error(e); + } + } + + public void run() { + try { + if (this.iDGramSocket instanceof MulticastSocket) { + mcastNegotiate(); + } else { + ucastNegotiate(); + } + } catch (Exception e) { + this.iResTable.addException(e); + TRC.error(e.getMessage(), e); + } finally { + this.iDGramSocket.close(); + this.iResTable.unregisterRequester(this); + } + } + + class MCastLoopController { + private long iStartTime = getMillis(); + + private int iTimeOutIdx = 0; + + /** + * getTimeOut + * + * @return int + */ + public int getTimeOut() { + return DatagramRequester.this.iTimeOuts[this.iTimeOutIdx]; + } + + private boolean hasNextTimeOut() { + return this.iTimeOutIdx < DatagramRequester.this.iTimeOuts.length; + } + + /** + * nextTimeOut + */ + public void nextTimeOut() { + if (hasNextTimeOut()) ++this.iTimeOutIdx; + } + + /** + * hasNext + * + * @return boolean + */ + public boolean hasNext() { + return ( + DatagramRequester.this.iResTable.getTotalResponses() < DatagramRequester.this.iMaxResults && + getMillis() - this.iStartTime < DatagramRequester.this.iTotalTimeOut && + hasNextTimeOut() + ); + } + } + + private void mcastNegotiate() throws Exception { + byte[] reqBytes = this.iReqMsg.serialize(true, true, false); + DatagramPacket outPacket0 = this.iDst0 == null + ? null + : new DatagramPacket(reqBytes, reqBytes.length, this.iDst0, this.iPort); + DatagramPacket outPacket1 = this.iDst1 == null + ? null + : new DatagramPacket(reqBytes, reqBytes.length, this.iDst1, this.iPort); + DatagramPacket inPacket = new DatagramPacket(this.iInBuf, this.iInBuf.length); + MCastLoopController ctrl = new MCastLoopController(); + boolean respondersUpdated = false; + ResponseCache rspCache = new ResponseCache(); + sendLoop:while (ctrl.hasNext()) { + if (respondersUpdated) { + byte[] msg = this.iReqMsg.serialize(true, true, true); + if (outPacket0 != null) outPacket0.setData(msg); + if (outPacket1 != null) outPacket1.setData(msg); + respondersUpdated = false; + } + // send it relative frequently in order to avoid lost packets + TRC.debug("sending: " + this.iReqMsg); + + try { + if (outPacket0 != null) this.iDGramSocket.send(outPacket0); + } catch (IOException ioe) { + // some back level kernels can't handle sending IPv6 mcast + TRC.warning("IOException caught during send, disabling IPv6: " + ioe.getMessage(), ioe); + outPacket0 = null; + this.iDst0 = null; + } + + if (outPacket1 != null) this.iDGramSocket.send(outPacket1); + while (ctrl.hasNext()) { + this.iDGramSocket.setSoTimeout(ctrl.getTimeOut()); + try { + this.iDGramSocket.receive(inPacket); + } catch (SocketTimeoutException e) { + // set new timeout value + TRC.debug("receive timed out"); + ctrl.nextTimeOut(); + continue sendLoop; + } + InetAddress responderAddress = inPacket.getAddress(); + + respondersUpdated = this.iReqMsg.updatePrevResponders(responderAddress.toString()); + + if (rspCache.contains(inPacket)) { + TRC.debug("received packet is found in rspCache"); + continue; // packet data is already processed + } + ReplyMessage replyMsg = handleResponse(inPacket); + + if (replyMsg != null) { + if (replyMsg.overflows()) { + if (!isLinkLocal(responderAddress)) { + // TCP doesn't seem to be working on linkLocal IPv6 + // connection + addTCPRequester(responderAddress); + rspCache.add(inPacket); + } + } else { + rspCache.add(inPacket); + } + } + } + break; + } + waitForTCPRequesters(); + } + + private void ucastNegotiate() throws Exception { + byte[] reqBytes = this.iReqMsg.serialize(false, true, false); + DatagramPacket outPacket = new DatagramPacket(reqBytes, reqBytes.length, this.iDst0, this.iPort); + DatagramPacket inPacket = new DatagramPacket(this.iInBuf, this.iInBuf.length); + int timeOutIdx = 0; + int timeOut = this.iTimeOuts[timeOutIdx]; + /* + * ad-hoc solution to avoid endless loop in case of broken answers + */ + int tries = 10; + while (timeOutIdx < this.iTimeOuts.length && tries > 0) { + // send it relative frequently in order to avoid lost packets + TRC.debug("sending: " + this.iReqMsg); + this.iDGramSocket.send(outPacket); + this.iDGramSocket.setSoTimeout(timeOut); + try { + this.iDGramSocket.receive(inPacket); + } catch (SocketTimeoutException e) { + // set new timeout value + TRC.debug("receive timed out"); + timeOut = this.iTimeOuts[timeOutIdx++]; + continue; + } + InetAddress responderAddress = inPacket.getAddress(); + ReplyMessage replyMsg = handleResponse(inPacket); + if (replyMsg == null) { + --tries; + continue; + } + if (replyMsg.overflows()) { + TCPRequester tcpRequester = new TCPRequester(this.iResTable, responderAddress, this.iReqMsg, true); + tcpRequester.waitFor(); + } + /* + * one answer is wanted from one host + */ + break; + } + } + + /** + * Tries to parse the content of the packet as a ReplyMessage. If parsing is + * successful ReplyMessage is placed into the ResultTable, otherwise the + * Exception is placed there. + * + * @param pPacket + * @return the ReplyMessage or null in case of + * + * Add all invalid URL exceptions thrown by parser into exception + * table + */ + private ReplyMessage handleResponse(DatagramPacket pPacket) { + ReplyMessage replyMsg; + try { + replyMsg = (ReplyMessage) MsgFactory.parse(pPacket); + TRC.debug("expected: " + this.iReqMsg.getXID() + ", received: " + replyMsg); + if (this.iReqMsg.getXID() != replyMsg.getXID() || !this.iReqMsg.isAllowedResponseType(replyMsg)) { + TRC.debug("expected: " + this.iReqMsg.getXID() + ", ignoring: " + replyMsg); + return null; + } + } catch (Exception e) { + this.iResTable.addException(e); + return null; + } + TRC.debug("resTable <- " + replyMsg); + this.iResTable.addResults(replyMsg); + this.iResTable.addExceptions(replyMsg); + return replyMsg; + } + + private static boolean isLinkLocal(InetAddress pAddr) { + if (pAddr instanceof Inet6Address) { + Inet6Address dest6 = (Inet6Address) pAddr; + // TCP on linkLocal is evil + return dest6.isLinkLocalAddress(); + } + return false; + } + + static long getMillis() { + return new Date().getTime(); + } + + private void addTCPRequester(InetAddress pDest) throws ServiceLocationException { + if (this.iTCPRequesters == null) this.iTCPRequesters = new ArrayList(); + this.iTCPRequesters.add(new TCPRequester(this.iResTable, pDest, this.iReqMsg, true)); + } + + private void waitForTCPRequesters() { + if (this.iTCPRequesters == null) return; + Iterator itr = this.iTCPRequesters.iterator(); + while (itr.hasNext()) itr.next().waitFor(); + this.iTCPRequesters.clear(); + } +} diff --git a/src/main/java/org/metricshub/wbem/sblim/slp/internal/ua/LocatorImpl.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/ua/LocatorImpl.java new file mode 100644 index 0000000..2209d68 --- /dev/null +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/ua/LocatorImpl.java @@ -0,0 +1,178 @@ +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp.internal.ua; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.net.InetAddress; +import java.util.Locale; +import java.util.SortedSet; +import java.util.Vector; +import org.metricshub.wbem.sblim.slp.Locator; +import org.metricshub.wbem.sblim.slp.ServiceLocationEnumeration; +import org.metricshub.wbem.sblim.slp.ServiceType; +import org.metricshub.wbem.sblim.slp.ServiceURL; +import org.metricshub.wbem.sblim.slp.internal.SLPDefaults; +import org.metricshub.wbem.sblim.slp.internal.TRC; +import org.metricshub.wbem.sblim.slp.internal.msg.AttributeRequest; +import org.metricshub.wbem.sblim.slp.internal.msg.ServiceRequest; +import org.metricshub.wbem.sblim.slp.internal.msg.ServiceTypeRequest; +import org.metricshub.wbem.sblim.slp.internal.msg.Util; + +/** + * LocatorImpl + * + */ +public class LocatorImpl implements Locator { + private Locale iLocale; + + private String iLangTag; + + /** + * Ctor. + * + * @param pLocale + */ + public LocatorImpl(Locale pLocale) { + this.iLocale = pLocale; + this.iLangTag = Util.getLangTag(this.iLocale); + TRC.debug("created, langTag=" + this.iLangTag); + } + + public ServiceLocationEnumeration findAttributes( + ServiceURL pURL, + Vector pScopes, + Vector pAttributeIds + ) { + return findAttributes(pURL, pScopes, pAttributeIds, null); + } + + public ServiceLocationEnumeration findAttributes( + ServiceURL pURL, + Vector pScopes, + Vector pAttributeIds, + Vector pDirectoryAgents + ) { + return new SLEnumerationImpl( + new AttributeRequest( + this.iLangTag, + (SortedSet) null, + pURL.toString(), + getScopes(pScopes), + pAttributeIds, + null + ), + pDirectoryAgents + ); + } + + public ServiceLocationEnumeration findAttributes( + ServiceType pType, + Vector pScopes, + Vector pAttributeIds + ) { + return findAttributes(pType, pScopes, pAttributeIds, null); + } + + public ServiceLocationEnumeration findAttributes( + ServiceType pType, + Vector pScopes, + Vector pAttributeIds, + Vector pDirectoryAgents + ) { + return new SLEnumerationImpl( + new AttributeRequest( + this.iLangTag, + (SortedSet) null, + pType.toString(), + getScopes(pScopes), + pAttributeIds, + null + ), + pDirectoryAgents + ); + } + + public ServiceLocationEnumeration findServiceTypes(String pNamingAuthority, Vector pScopes) { + return findServiceTypes(pNamingAuthority, pScopes, null); + } + + public ServiceLocationEnumeration findServiceTypes( + String pNamingAuthority, + Vector pScopes, + Vector pDirectoryAgent + ) { + return new SLEnumerationImpl( + new ServiceTypeRequest(this.iLangTag, null, pNamingAuthority, getScopes(pScopes)), + pDirectoryAgent + ); + } + + public ServiceLocationEnumeration findServices(ServiceType pType, Vector pScopes, String pSearchFilter) { + return findServices(pType, pScopes, pSearchFilter, null); + } + + public ServiceLocationEnumeration findServices( + ServiceType pType, + Vector pScopes, + String pSearchFilter, + Vector pDirectoryAgents + ) { + return new SLEnumerationImpl( + new ServiceRequest(this.iLangTag, null, pType, getScopes(pScopes), pSearchFilter, null), + pDirectoryAgents + ); + } + + public Locale getLocale() { + return this.iLocale; + } + + /** + * @param pScopes + * @return pScopes if that is not empty or a Vector with "default" entry if + * the pScopes is null or empty + */ + private static Vector getScopes(Vector pScopes) { + if (pScopes == null) pScopes = new Vector(); + if (pScopes.isEmpty()) pScopes.add(SLPDefaults.DEFAULT_SCOPE); + return pScopes; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/ua/ResponseCache.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/ua/ResponseCache.java similarity index 75% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/ua/ResponseCache.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/ua/ResponseCache.java index d471e8a..4d753ac 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/ua/ResponseCache.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/ua/ResponseCache.java @@ -1,126 +1,121 @@ -/* - (C) Copyright IBM Corp. 2007, 2010 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1892103 2008-02-12 ebak SLP improvements - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 3019214 2010-06-21 blaschke-oss SLP equals methods assume too much - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.ua; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.net.DatagramPacket; -import java.util.Arrays; -import java.util.HashSet; - -/** - * ResponseCache intends to eliminate the processing of SLP responses with the - * same content. - * - */ -public class ResponseCache { - - private static class Entry { - - private byte[] iData; - - private int iHashCode; - - /** - * Ctor. - * - * @param pData - * @param pOffset - * @param pLength - */ - public Entry(byte[] pData, int pOffset, int pLength) { - this.iData = new byte[pLength]; - System.arraycopy(pData, pOffset, this.iData, 0, pLength); - for (int pos = 0; pos < this.iData.length; ++pos) { - this.iHashCode <<= 4; - this.iHashCode += (this.iData[pos] & 0xff); - } - } - - /** - * Ctor. - * - * @param pPacket - */ - public Entry(DatagramPacket pPacket) { - this(pPacket.getData(), pPacket.getOffset(), pPacket.getLength()); - } - - @Override - public int hashCode() { - return this.iHashCode; - } - - @Override - public boolean equals(Object pObj) { - if (pObj == null || !(pObj instanceof Entry)) return false; - if (this == pObj) return true; - Entry that = (Entry) pObj; - return this.iHashCode == that.iHashCode && Arrays.equals(this.iData, that.iData); - } - - } - - private HashSet iResponseSet = new HashSet(); - - /** - * add - * - * @param pPacket - */ - public void add(DatagramPacket pPacket) { - this.iResponseSet.add(new Entry(pPacket)); - } - - /** - * contains - * - * @param pPacket - * @return boolean - */ - public boolean contains(DatagramPacket pPacket) { - return this.iResponseSet.contains(new Entry(pPacket)); - } - -} +/* + (C) Copyright IBM Corp. 2007, 2010 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1892103 2008-02-12 ebak SLP improvements + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 3019214 2010-06-21 blaschke-oss SLP equals methods assume too much + */ + +package org.metricshub.wbem.sblim.slp.internal.ua; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.net.DatagramPacket; +import java.util.Arrays; +import java.util.HashSet; + +/** + * ResponseCache intends to eliminate the processing of SLP responses with the + * same content. + * + */ +public class ResponseCache { + + private static class Entry { + private byte[] iData; + + private int iHashCode; + + /** + * Ctor. + * + * @param pData + * @param pOffset + * @param pLength + */ + public Entry(byte[] pData, int pOffset, int pLength) { + this.iData = new byte[pLength]; + System.arraycopy(pData, pOffset, this.iData, 0, pLength); + for (int pos = 0; pos < this.iData.length; ++pos) { + this.iHashCode <<= 4; + this.iHashCode += (this.iData[pos] & 0xff); + } + } + + /** + * Ctor. + * + * @param pPacket + */ + public Entry(DatagramPacket pPacket) { + this(pPacket.getData(), pPacket.getOffset(), pPacket.getLength()); + } + + @Override + public int hashCode() { + return this.iHashCode; + } + + @Override + public boolean equals(Object pObj) { + if (pObj == null || !(pObj instanceof Entry)) return false; + if (this == pObj) return true; + Entry that = (Entry) pObj; + return this.iHashCode == that.iHashCode && Arrays.equals(this.iData, that.iData); + } + } + + private HashSet iResponseSet = new HashSet(); + + /** + * add + * + * @param pPacket + */ + public void add(DatagramPacket pPacket) { + this.iResponseSet.add(new Entry(pPacket)); + } + + /** + * contains + * + * @param pPacket + * @return boolean + */ + public boolean contains(DatagramPacket pPacket) { + return this.iResponseSet.contains(new Entry(pPacket)); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/ua/ResultTable.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/ua/ResultTable.java similarity index 78% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/ua/ResultTable.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/ua/ResultTable.java index cd01bad..6d4e7da 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/ua/ResultTable.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/ua/ResultTable.java @@ -1,235 +1,227 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1892103 2008-02-12 ebak SLP improvements - * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.ua; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.NoSuchElementException; - -import org.sentrysoftware.wbem.sblim.slp.internal.TRC; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.ReplyMessage; - -/** - * ResultTable - * - */ -public class ResultTable implements Iterator { - - private ArrayList iRequesters = new ArrayList(); - - private ArrayList iExceptions = new ArrayList(); - - /* - * iInSet contains the results which are not read out. iOutSet contains the - * results which are read out. - */ - private LinkedHashSet iInSet = new LinkedHashSet(); - - private LinkedHashSet iOutSet = new LinkedHashSet(); - - /** - * ResultTable has to know which Requesters provide results. Requester have - * to be registered before hasNext() is called. - * - * @see #unregisterRequester(DatagramRequester) - * @param pReq - */ - public synchronized void registerRequester(DatagramRequester pReq) { - for (int i = 0; i < this.iRequesters.size(); i++) - if (pReq == this.iRequesters.get(i)) return; - this.iRequesters.add(pReq); - } - - /** - * If the Requester's sequence is completed, Requester has to be - * unregistered otherwise hasNext() will block. - * - * @param pReq - */ - public synchronized void unregisterRequester(DatagramRequester pReq) { - for (int i = 0; i < this.iRequesters.size(); i++) { - if (pReq == this.iRequesters.get(i)) { - this.iRequesters.remove(i); - if (this.iRequesters.size() == 0) wakeUp(); - return; - } - } - } - - /** - * addResults - * - * @param pReplyMsg - */ - public void addResults(ReplyMessage pReplyMsg) { - addResults(pReplyMsg.getResultIterator()); - } - - /** - * addResults - * - * @param pResItr - */ - public synchronized void addResults(Iterator pResItr) { - if (pResItr == null) return; - while (pResItr.hasNext()) - addResult(pResItr.next()); - // waking up hasNext() - if (this.iInSet.size() > 0) wakeUp(); - } - - /** - * addExceptions - * - * @param pReplyMsg - */ - public synchronized void addExceptions(ReplyMessage pReplyMsg) { - addExceptions(pReplyMsg.getExceptionIterator()); - } - - /** - * addExceptions - * - * @param pExceptionItr - */ - public synchronized void addExceptions(Iterator pExceptionItr) { - if (pExceptionItr == null) return; - while (pExceptionItr.hasNext()) - addException((Exception) pExceptionItr.next()); - } - - /** - * addException - * - * @param pE - */ - public synchronized void addException(Exception pE) { - this.iExceptions.add(pE); - if (this.iExceptions.size() > 0) wakeUp(); - } - - /** - * getTotalResponses - * - * @return int - */ - public synchronized int getTotalResponses() { - return this.iOutSet.size() + this.iInSet.size(); - } - - /** - * @see java.util.Iterator#hasNext() - * @return true if there are results or exceptions to read - */ - public synchronized boolean hasNext() { - if (hasData()) return true; - // no more requester, no chance for result - if (this.iRequesters.size() == 0) return false; - /* - * wait wake up if iInSet is extended or all Requesters are unregistered - */ - try { - wait(); - } catch (InterruptedException e) { - TRC.error(e); - } - return hasData(); - } - - /** - * @see java.util.Iterator#next() - * @return a result or an Exception - */ - public synchronized Object next() throws NoSuchElementException { - Iterator itr = this.iInSet.iterator(); - Object res = itr.next(); - this.iInSet.remove(res); - this.iOutSet.add(res); - return res; - } - - /** - * @return next element in Exception table - * @throws NoSuchElementException - */ - public Object nextException() throws NoSuchElementException { - Iterator itr = this.iExceptions.iterator(); - Object res = itr.next(); - this.iExceptions.remove(res); - return res; - } - - /** - * @return next element in Exception table - */ - public boolean hasMoreExceptions() { - return this.iExceptions.size() > 0; - } - - public void remove() { - throw new UnsupportedOperationException(); - } - - private void addResult(Object pResult) { - if (this.iOutSet.contains(pResult) || this.iInSet.contains(pResult)) return; - this.iInSet.add(pResult); - } - - private void wakeUp() { - try { - notifyAll(); - } catch (IllegalMonitorStateException e) { - TRC.error(e); - } - } - - private boolean hasData() { - return this.iInSet.size() > 0; - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1892103 2008-02-12 ebak SLP improvements + * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2204488 2008-10-28 raman_arora Fix code to remove compiler warnings + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + */ + +package org.metricshub.wbem.sblim.slp.internal.ua; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.NoSuchElementException; +import org.metricshub.wbem.sblim.slp.internal.TRC; +import org.metricshub.wbem.sblim.slp.internal.msg.ReplyMessage; + +/** + * ResultTable + * + */ +public class ResultTable implements Iterator { + private ArrayList iRequesters = new ArrayList(); + + private ArrayList iExceptions = new ArrayList(); + + /* + * iInSet contains the results which are not read out. iOutSet contains the + * results which are read out. + */ + private LinkedHashSet iInSet = new LinkedHashSet(); + + private LinkedHashSet iOutSet = new LinkedHashSet(); + + /** + * ResultTable has to know which Requesters provide results. Requester have + * to be registered before hasNext() is called. + * + * @see #unregisterRequester(DatagramRequester) + * @param pReq + */ + public synchronized void registerRequester(DatagramRequester pReq) { + for (int i = 0; i < this.iRequesters.size(); i++) if (pReq == this.iRequesters.get(i)) return; + this.iRequesters.add(pReq); + } + + /** + * If the Requester's sequence is completed, Requester has to be + * unregistered otherwise hasNext() will block. + * + * @param pReq + */ + public synchronized void unregisterRequester(DatagramRequester pReq) { + for (int i = 0; i < this.iRequesters.size(); i++) { + if (pReq == this.iRequesters.get(i)) { + this.iRequesters.remove(i); + if (this.iRequesters.size() == 0) wakeUp(); + return; + } + } + } + + /** + * addResults + * + * @param pReplyMsg + */ + public void addResults(ReplyMessage pReplyMsg) { + addResults(pReplyMsg.getResultIterator()); + } + + /** + * addResults + * + * @param pResItr + */ + public synchronized void addResults(Iterator pResItr) { + if (pResItr == null) return; + while (pResItr.hasNext()) addResult(pResItr.next()); + // waking up hasNext() + if (this.iInSet.size() > 0) wakeUp(); + } + + /** + * addExceptions + * + * @param pReplyMsg + */ + public synchronized void addExceptions(ReplyMessage pReplyMsg) { + addExceptions(pReplyMsg.getExceptionIterator()); + } + + /** + * addExceptions + * + * @param pExceptionItr + */ + public synchronized void addExceptions(Iterator pExceptionItr) { + if (pExceptionItr == null) return; + while (pExceptionItr.hasNext()) addException((Exception) pExceptionItr.next()); + } + + /** + * addException + * + * @param pE + */ + public synchronized void addException(Exception pE) { + this.iExceptions.add(pE); + if (this.iExceptions.size() > 0) wakeUp(); + } + + /** + * getTotalResponses + * + * @return int + */ + public synchronized int getTotalResponses() { + return this.iOutSet.size() + this.iInSet.size(); + } + + /** + * @see java.util.Iterator#hasNext() + * @return true if there are results or exceptions to read + */ + public synchronized boolean hasNext() { + if (hasData()) return true; + // no more requester, no chance for result + if (this.iRequesters.size() == 0) return false; + /* + * wait wake up if iInSet is extended or all Requesters are unregistered + */ + try { + wait(); + } catch (InterruptedException e) { + TRC.error(e); + } + return hasData(); + } + + /** + * @see java.util.Iterator#next() + * @return a result or an Exception + */ + public synchronized Object next() throws NoSuchElementException { + Iterator itr = this.iInSet.iterator(); + Object res = itr.next(); + this.iInSet.remove(res); + this.iOutSet.add(res); + return res; + } + + /** + * @return next element in Exception table + * @throws NoSuchElementException + */ + public Object nextException() throws NoSuchElementException { + Iterator itr = this.iExceptions.iterator(); + Object res = itr.next(); + this.iExceptions.remove(res); + return res; + } + + /** + * @return next element in Exception table + */ + public boolean hasMoreExceptions() { + return this.iExceptions.size() > 0; + } + + public void remove() { + throw new UnsupportedOperationException(); + } + + private void addResult(Object pResult) { + if (this.iOutSet.contains(pResult) || this.iInSet.contains(pResult)) return; + this.iInSet.add(pResult); + } + + private void wakeUp() { + try { + notifyAll(); + } catch (IllegalMonitorStateException e) { + TRC.error(e); + } + } + + private boolean hasData() { + return this.iInSet.size() > 0; + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/ua/SLEnumerationImpl.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/ua/SLEnumerationImpl.java similarity index 79% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/ua/SLEnumerationImpl.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/ua/SLEnumerationImpl.java index 3d3b875..99d0e22 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/ua/SLEnumerationImpl.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/ua/SLEnumerationImpl.java @@ -1,257 +1,249 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1804402 2007-11-10 ebak IPv6 ready SLP - revision 4 - * 1892103 2008-02-12 ebak SLP improvements - * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.ua; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.NoSuchElementException; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationEnumeration; -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; -import org.sentrysoftware.wbem.sblim.slp.ServiceURL; -import org.sentrysoftware.wbem.sblim.slp.internal.SLPDefaults; -import org.sentrysoftware.wbem.sblim.slp.internal.TRC; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.DADescriptor; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.RequestMessage; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.ServiceRequest; - -/** - * SLEnumerationImpl - * - */ -public class SLEnumerationImpl implements ServiceLocationEnumeration { - - private RequestMessage iReqMsg; - - private ResultTable iResultTable; - - private List iDAList; - - private boolean iInited = false; - - private boolean iIsDASrvRequest; - - private DatagramRequester iMCastRequester; - - /** - * Ctor. - * - * @param pReqMsg - * @param pDAList - */ - public SLEnumerationImpl(RequestMessage pReqMsg, List pDAList) { - this.iReqMsg = pReqMsg; - this.iResultTable = new ResultTable(); - this.iDAList = pDAList; - this.iIsDASrvRequest = isDASrvRequest(); - } - - /** - * This implementation can throw RuntimeExceptions. They can be ignored or - * used for analysis. - * - * @see ServiceLocationEnumeration#next() - */ - public Object next() throws NoSuchElementException { - Object obj = this.iResultTable.next(); - if (obj instanceof Exception) throw new RuntimeException((Exception) obj); - if (this.iIsDASrvRequest) { - // DADescriptor is internal -> converting to ServiceURL - DADescriptor daDesc = (DADescriptor) obj; - return new ServiceURL(daDesc.getURL(), ServiceURL.LIFETIME_MAXIMUM); - } - return obj; - } - - /** - * @return next Object in Exception table - * @throws NoSuchElementException - * - * This in internal implementation to get list of all exceptions - * thrown/caught by parser This can throw RuntimeExceptions. - * They can be ignored or used for analysis. - * - * use hasNextException to check whether there exists another - * element in Exception table - */ - public Object nextException() throws NoSuchElementException { - return this.iResultTable.nextException(); - } - - /** - * @return true if there exists another element in Exception table - * - */ - public boolean hasMoreExceptions() { - return this.iResultTable.hasMoreExceptions(); - } - - /* - * states: - init - initiated - finished - */ - public boolean hasMoreElements() { - if (!this.iInited) { - List daList = null; - /* - * OpenSLP DA doesn't reply to unicasted DA discovery, therefore if - * the discoverable service type is service:directory-agent a - * multicasting is done. - */ - if (!this.iIsDASrvRequest) { - try { - daList = getDAList(this.iReqMsg.getScopeList()); - } catch (Exception e) { - throw new RuntimeException(new ServiceLocationException( - ServiceLocationException.INTERNAL_ERROR, e)); - } - } - try { - if (daList == null || daList.size() == 0) { - setupMulticasting(); - } else { - setupUnicasting(daList); - } - } catch (Exception e) { - throw new RuntimeException(e); - } - this.iInited = true; - } - return this.iResultTable.hasNext(); - } - - public Object nextElement() throws NoSuchElementException { - return next(); - } - - /** - * For diagnostic only! - * - * @return int - */ - public int getPort() { - return this.iMCastRequester == null ? -1 : this.iMCastRequester.getPort(); - } - - private boolean isDASrvRequest() { - if (!(this.iReqMsg instanceof ServiceRequest)) return false; - ServiceRequest srvReq = (ServiceRequest) this.iReqMsg; - return SLPDefaults.DA_SERVICE_TYPE.equals(srvReq.getServiceType()); - } - - /** - * @param pScopes - * @return List of DA address InetAddresses - * @throws UnknownHostException - */ - private List getDAList(List pScopes) throws UnknownHostException, - IOException { - if (this.iDAList != null && this.iDAList.size() > 0) return this.iDAList; - - // return cached DA list from previous discovery - List scopes = DACache.getDiscoverableScopeList(pScopes); - if (scopes != null) { - ResultTable resultTable = new ResultTable(); - ServiceRequest srvReq = new ServiceRequest(null, SLPDefaults.DA_SERVICE_TYPE, scopes, - null, null); - // multicast DA discovery - DatagramRequester requester = new DatagramRequester(srvReq, resultTable); - requester.start(false); - if (resultTable.hasNext()) { - List daList = new ArrayList(); - while (resultTable.hasNext()) { - try { - daList.add((DADescriptor) resultTable.next()); - } catch (RuntimeException e) { - TRC.warning(e.getMessage(), e); - } - } - DACache.setDAList(scopes, daList); - } - } - return getInetAddresses(DACache.getDAList(pScopes)); - } - - private List getInetAddresses(List pAddrStrList) { - if (pAddrStrList == null) return null; - List list = new ArrayList(pAddrStrList.size()); - Iterator strItr = pAddrStrList.iterator(); - while (strItr.hasNext()) { - String srvURLStr = strItr.next(); - try { - ServiceURL srvURL = new ServiceURL(srvURLStr, ServiceURL.LIFETIME_DEFAULT); - list.add(InetAddress.getByName(srvURL.getURLPath())); - } catch (Exception e) { - TRC.error("Failed to get InetAddress for srvURLStr=" + srvURLStr, e); - } - } - TRC.info("number of discovered DAs:" + list.size()); - return list; - } - - private void setupUnicasting(List pDAList) throws IOException { - Iterator itr = pDAList.iterator(); - while (itr.hasNext()) { - InetAddress address = itr.next(); - new DatagramRequester(this.iReqMsg, this.iResultTable, address).start(true); - } - } - - private void setupMulticasting() throws ServiceLocationException, IOException { - try { - this.iMCastRequester = new DatagramRequester(this.iReqMsg, this.iResultTable); - this.iMCastRequester.start(true); - } catch (UnknownHostException e) { - throw new ServiceLocationException(ServiceLocationException.NETWORK_ERROR, e); - } - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1804402 2007-11-10 ebak IPv6 ready SLP - revision 4 + * 1892103 2008-02-12 ebak SLP improvements + * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) + * 2763216 2009-04-14 blaschke-oss Code cleanup: visible spelling/grammar errors + */ + +package org.metricshub.wbem.sblim.slp.internal.ua; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; +import org.metricshub.wbem.sblim.slp.ServiceLocationEnumeration; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; +import org.metricshub.wbem.sblim.slp.ServiceURL; +import org.metricshub.wbem.sblim.slp.internal.SLPDefaults; +import org.metricshub.wbem.sblim.slp.internal.TRC; +import org.metricshub.wbem.sblim.slp.internal.msg.DADescriptor; +import org.metricshub.wbem.sblim.slp.internal.msg.RequestMessage; +import org.metricshub.wbem.sblim.slp.internal.msg.ServiceRequest; + +/** + * SLEnumerationImpl + * + */ +public class SLEnumerationImpl implements ServiceLocationEnumeration { + private RequestMessage iReqMsg; + + private ResultTable iResultTable; + + private List iDAList; + + private boolean iInited = false; + + private boolean iIsDASrvRequest; + + private DatagramRequester iMCastRequester; + + /** + * Ctor. + * + * @param pReqMsg + * @param pDAList + */ + public SLEnumerationImpl(RequestMessage pReqMsg, List pDAList) { + this.iReqMsg = pReqMsg; + this.iResultTable = new ResultTable(); + this.iDAList = pDAList; + this.iIsDASrvRequest = isDASrvRequest(); + } + + /** + * This implementation can throw RuntimeExceptions. They can be ignored or + * used for analysis. + * + * @see ServiceLocationEnumeration#next() + */ + public Object next() throws NoSuchElementException { + Object obj = this.iResultTable.next(); + if (obj instanceof Exception) throw new RuntimeException((Exception) obj); + if (this.iIsDASrvRequest) { + // DADescriptor is internal -> converting to ServiceURL + DADescriptor daDesc = (DADescriptor) obj; + return new ServiceURL(daDesc.getURL(), ServiceURL.LIFETIME_MAXIMUM); + } + return obj; + } + + /** + * @return next Object in Exception table + * @throws NoSuchElementException + * + * This in internal implementation to get list of all exceptions + * thrown/caught by parser This can throw RuntimeExceptions. + * They can be ignored or used for analysis. + * + * use hasNextException to check whether there exists another + * element in Exception table + */ + public Object nextException() throws NoSuchElementException { + return this.iResultTable.nextException(); + } + + /** + * @return true if there exists another element in Exception table + * + */ + public boolean hasMoreExceptions() { + return this.iResultTable.hasMoreExceptions(); + } + + /* + * states: - init - initiated - finished + */ + public boolean hasMoreElements() { + if (!this.iInited) { + List daList = null; + /* + * OpenSLP DA doesn't reply to unicasted DA discovery, therefore if + * the discoverable service type is service:directory-agent a + * multicasting is done. + */ + if (!this.iIsDASrvRequest) { + try { + daList = getDAList(this.iReqMsg.getScopeList()); + } catch (Exception e) { + throw new RuntimeException(new ServiceLocationException(ServiceLocationException.INTERNAL_ERROR, e)); + } + } + try { + if (daList == null || daList.size() == 0) { + setupMulticasting(); + } else { + setupUnicasting(daList); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + this.iInited = true; + } + return this.iResultTable.hasNext(); + } + + public Object nextElement() throws NoSuchElementException { + return next(); + } + + /** + * For diagnostic only! + * + * @return int + */ + public int getPort() { + return this.iMCastRequester == null ? -1 : this.iMCastRequester.getPort(); + } + + private boolean isDASrvRequest() { + if (!(this.iReqMsg instanceof ServiceRequest)) return false; + ServiceRequest srvReq = (ServiceRequest) this.iReqMsg; + return SLPDefaults.DA_SERVICE_TYPE.equals(srvReq.getServiceType()); + } + + /** + * @param pScopes + * @return List of DA address InetAddresses + * @throws UnknownHostException + */ + private List getDAList(List pScopes) throws UnknownHostException, IOException { + if (this.iDAList != null && this.iDAList.size() > 0) return this.iDAList; + + // return cached DA list from previous discovery + List scopes = DACache.getDiscoverableScopeList(pScopes); + if (scopes != null) { + ResultTable resultTable = new ResultTable(); + ServiceRequest srvReq = new ServiceRequest(null, SLPDefaults.DA_SERVICE_TYPE, scopes, null, null); + // multicast DA discovery + DatagramRequester requester = new DatagramRequester(srvReq, resultTable); + requester.start(false); + if (resultTable.hasNext()) { + List daList = new ArrayList(); + while (resultTable.hasNext()) { + try { + daList.add((DADescriptor) resultTable.next()); + } catch (RuntimeException e) { + TRC.warning(e.getMessage(), e); + } + } + DACache.setDAList(scopes, daList); + } + } + return getInetAddresses(DACache.getDAList(pScopes)); + } + + private List getInetAddresses(List pAddrStrList) { + if (pAddrStrList == null) return null; + List list = new ArrayList(pAddrStrList.size()); + Iterator strItr = pAddrStrList.iterator(); + while (strItr.hasNext()) { + String srvURLStr = strItr.next(); + try { + ServiceURL srvURL = new ServiceURL(srvURLStr, ServiceURL.LIFETIME_DEFAULT); + list.add(InetAddress.getByName(srvURL.getURLPath())); + } catch (Exception e) { + TRC.error("Failed to get InetAddress for srvURLStr=" + srvURLStr, e); + } + } + TRC.info("number of discovered DAs:" + list.size()); + return list; + } + + private void setupUnicasting(List pDAList) throws IOException { + Iterator itr = pDAList.iterator(); + while (itr.hasNext()) { + InetAddress address = itr.next(); + new DatagramRequester(this.iReqMsg, this.iResultTable, address).start(true); + } + } + + private void setupMulticasting() throws ServiceLocationException, IOException { + try { + this.iMCastRequester = new DatagramRequester(this.iReqMsg, this.iResultTable); + this.iMCastRequester.start(true); + } catch (UnknownHostException e) { + throw new ServiceLocationException(ServiceLocationException.NETWORK_ERROR, e); + } + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/ua/TCPRequester.java b/src/main/java/org/metricshub/wbem/sblim/slp/internal/ua/TCPRequester.java similarity index 66% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/ua/TCPRequester.java rename to src/main/java/org/metricshub/wbem/sblim/slp/internal/ua/TCPRequester.java index a37b149..b785097 100644 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/ua/TCPRequester.java +++ b/src/main/java/org/metricshub/wbem/sblim/slp/internal/ua/TCPRequester.java @@ -1,153 +1,147 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 1892103 2008-02-12 ebak SLP improvements - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.ua; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.io.OutputStream; -import java.net.InetAddress; -import java.net.Socket; - -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; -import org.sentrysoftware.wbem.sblim.slp.internal.SLPConfig; -import org.sentrysoftware.wbem.sblim.slp.internal.TRC; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.MsgFactory; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.ReplyMessage; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.RequestMessage; - -/** - * TCPRequester - * - */ -public class TCPRequester implements Runnable { - - private InetAddress iDestination; - - private Thread iThread; - - private ResultTable iResTable; - - private RequestMessage iReqMsg; - - private byte[] iRequestBytes; - - private int iPort = SLPConfig.getGlobalCfg().getPort(); - - private final int iTCPTimeOut = SLPConfig.getGlobalCfg().getTCPTimeout(); - - /** - * Ctor. - * - * @param pResTable - * @param pDestination - * @param pReqMsg - * @param pAsThread - * @throws ServiceLocationException - */ - public TCPRequester(ResultTable pResTable, InetAddress pDestination, RequestMessage pReqMsg, - boolean pAsThread) throws ServiceLocationException { - this.iResTable = pResTable; - this.iDestination = pDestination; - this.iReqMsg = pReqMsg; - this.iRequestBytes = pReqMsg.serializeWithoutResponders(false, false, true); - // FIXME: Is it safe to omit PreviousResopnder list for TCP request? - if (pAsThread) { - this.iThread = new Thread(this); - this.iThread.start(); - } else { - this.iThread = null; - run(); - } - } - - /** - * waitFor - */ - public void waitFor() { - if (this.iThread == null) return; - try { - this.iThread.join(); - } catch (InterruptedException e) { - TRC.error(e); - } - } - - public void run() { - Socket socket = null; - try { - socket = new Socket(this.iDestination, this.iPort); - socket.setSoTimeout(this.iTCPTimeOut); - OutputStream os = socket.getOutputStream(); - TRC.debug("sendTCP"); - os.write(this.iRequestBytes); - os.flush(); - handleResponse(socket); - TRC.debug("recievedOnTCP"); - } catch (Exception e) { - TRC.error(e.getMessage()); - } finally { - if (socket != null) { - try { - socket.close(); - } catch (IOException e) { - TRC.error(e); - } - } - } - - } - - private void handleResponse(Socket pSocket) { - ReplyMessage replyMsg; - try { - replyMsg = (ReplyMessage) MsgFactory.parse(pSocket); - } catch (Exception e) { - this.iResTable.addException(e); - return; - } - if (this.iReqMsg.getXID() == replyMsg.getXID() - && this.iReqMsg.isAllowedResponseType(replyMsg)) this.iResTable - .addResults(replyMsg); - } - -} +/* + (C) Copyright IBM Corp. 2007, 2009 + + THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE + ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE + CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. + + You can obtain a current copy of the Eclipse Public License from + http://www.opensource.org/licenses/eclipse-1.0.php + + @author : Endre Bak, IBM, ebak@de.ibm.com + * + * Change History + * Flag Date Prog Description + *------------------------------------------------------------------------------- + * 1804402 2007-09-28 ebak IPv6 ready SLP + * 1892103 2008-02-12 ebak SLP improvements + * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL + * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) + */ + +package org.metricshub.wbem.sblim.slp.internal.ua; + +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * WBEM Java Client + * ჻჻჻჻჻჻ + * Copyright 2023 - 2025 MetricsHub + * ჻჻჻჻჻჻ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetAddress; +import java.net.Socket; +import org.metricshub.wbem.sblim.slp.ServiceLocationException; +import org.metricshub.wbem.sblim.slp.internal.SLPConfig; +import org.metricshub.wbem.sblim.slp.internal.TRC; +import org.metricshub.wbem.sblim.slp.internal.msg.MsgFactory; +import org.metricshub.wbem.sblim.slp.internal.msg.ReplyMessage; +import org.metricshub.wbem.sblim.slp.internal.msg.RequestMessage; + +/** + * TCPRequester + * + */ +public class TCPRequester implements Runnable { + private InetAddress iDestination; + + private Thread iThread; + + private ResultTable iResTable; + + private RequestMessage iReqMsg; + + private byte[] iRequestBytes; + + private int iPort = SLPConfig.getGlobalCfg().getPort(); + + private final int iTCPTimeOut = SLPConfig.getGlobalCfg().getTCPTimeout(); + + /** + * Ctor. + * + * @param pResTable + * @param pDestination + * @param pReqMsg + * @param pAsThread + * @throws ServiceLocationException + */ + public TCPRequester(ResultTable pResTable, InetAddress pDestination, RequestMessage pReqMsg, boolean pAsThread) + throws ServiceLocationException { + this.iResTable = pResTable; + this.iDestination = pDestination; + this.iReqMsg = pReqMsg; + this.iRequestBytes = pReqMsg.serializeWithoutResponders(false, false, true); + // FIXME: Is it safe to omit PreviousResopnder list for TCP request? + if (pAsThread) { + this.iThread = new Thread(this); + this.iThread.start(); + } else { + this.iThread = null; + run(); + } + } + + /** + * waitFor + */ + public void waitFor() { + if (this.iThread == null) return; + try { + this.iThread.join(); + } catch (InterruptedException e) { + TRC.error(e); + } + } + + public void run() { + Socket socket = null; + try { + socket = new Socket(this.iDestination, this.iPort); + socket.setSoTimeout(this.iTCPTimeOut); + OutputStream os = socket.getOutputStream(); + TRC.debug("sendTCP"); + os.write(this.iRequestBytes); + os.flush(); + handleResponse(socket); + TRC.debug("recievedOnTCP"); + } catch (Exception e) { + TRC.error(e.getMessage()); + } finally { + if (socket != null) { + try { + socket.close(); + } catch (IOException e) { + TRC.error(e); + } + } + } + } + + private void handleResponse(Socket pSocket) { + ReplyMessage replyMsg; + try { + replyMsg = (ReplyMessage) MsgFactory.parse(pSocket); + } catch (Exception e) { + this.iResTable.addException(e); + return; + } + if ( + this.iReqMsg.getXID() == replyMsg.getXID() && this.iReqMsg.isAllowedResponseType(replyMsg) + ) this.iResTable.addResults(replyMsg); + } +} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/package.html b/src/main/java/org/metricshub/wbem/sblim/slp/package.html similarity index 100% rename from src/main/java/org/sentrysoftware/wbem/sblim/slp/package.html rename to src/main/java/org/metricshub/wbem/sblim/slp/package.html diff --git a/src/main/java/org/sentrysoftware/wbem/client/WbemQueryResult.java b/src/main/java/org/sentrysoftware/wbem/client/WbemQueryResult.java deleted file mode 100644 index 91b01c8..0000000 --- a/src/main/java/org/sentrysoftware/wbem/client/WbemQueryResult.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.sentrysoftware.wbem.client; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.List; - -/** - * Wrapper class for WBEM query result. - * - */ -public class WbemQueryResult { - - /** List of the properties of the query. */ - private final List properties; - - /** Query results. */ - private final List> values; - - public WbemQueryResult( - final List properties, - final List> values) { - this.properties = properties; - this.values = values; - } - - public List getProperties() { - return properties; - } - - public List> getValues() { - return values; - } -} diff --git a/src/main/java/org/sentrysoftware/wbem/client/WqlQuery.java b/src/main/java/org/sentrysoftware/wbem/client/WqlQuery.java deleted file mode 100644 index ec2405a..0000000 --- a/src/main/java/org/sentrysoftware/wbem/client/WqlQuery.java +++ /dev/null @@ -1,138 +0,0 @@ -package org.sentrysoftware.wbem.client; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.sentrysoftware.wbem.client.exceptions.WqlQuerySyntaxException; - -/** - * Handler for WQL query. - * - */ -public class WqlQuery { - - private WqlQuery() { } - - private static final String ID = "[^\\s]+"; - private static final String LIST_SEPARATOR = "\\s*,\\s*"; - - private static final Pattern CHECK_SELECT_PATTERN = Pattern.compile( - "^\\s*SELECT\\s+(\\*|(?!SELECT|FROM|WHERE)\\w+|((?!SELECT|FROM|WHERE)\\w+\\s*,\\s*)+((?!SELECT|FROM|WHERE)\\w+))\\s+FROM\\s+((?!SELECT|WHERE|FROM)\\w+)\\s*?$", - Pattern.CASE_INSENSITIVE); - - private static final Pattern EXTRACT_SELECT_PATTERN= Pattern.compile( - "^\\s*SELECT\\s+(.+)\\s+FROM\\s+("+ID+")\\s*$", - Pattern.CASE_INSENSITIVE); - private static final int SELECT_GROUP_CLASSNAME = 2; - private static final int SELECT_GROUP_FIELDS = 1; - private static final int SELECT_GROUP_COUNT = 2; - - private String className; - private Set properties; - private List originalProperties; - - /** - * Constructor for WQL query. - * - * @param query the WQL query. - * @throws WqlQuerySyntaxException On WQL Syntax exception. - */ - public static WqlQuery parseQuery(final String query) throws WqlQuerySyntaxException { - - Utils.checkNonNull(query, "query"); - - if (CHECK_SELECT_PATTERN.matcher(query).find()) { - final WqlQuery wqlQuery = new WqlQuery(); - wqlQuery.parseSelect(query); - return wqlQuery; - } - throw new WqlQuerySyntaxException(query); - } - - public String getClassName() { - return className; - } - - public String[] getPropertiesArray() { - return properties.isEmpty() ? - null : - properties.stream() - .filter(property -> !WbemCimDataHandler.PATH_PROPERTY.equalsIgnoreCase(property)) - .toArray(String[]::new); - } - - public Set getProperties() { - return properties; - } - - public List getOriginalProperties() { - return originalProperties; - } - - public boolean hasDuplicateProperties() { - return properties != null && originalProperties != null && properties.size() != originalProperties.size(); - } - - private void parseSelect( - final String query) throws WqlQuerySyntaxException { - - final Matcher matcher = EXTRACT_SELECT_PATTERN.matcher(query); - if (!matcher.find()) { - throw new WqlQuerySyntaxException(query); - } - if (matcher.groupCount() < SELECT_GROUP_COUNT) { - throw new WqlQuerySyntaxException(query); - } - - className = matcher.group(SELECT_GROUP_CLASSNAME); - - final String fieldsList = matcher.group(SELECT_GROUP_FIELDS); - final String[] fieldArray = Optional.ofNullable(fieldsList) - .filter(s -> !"*".equals(s)) - .map(s -> s.split(LIST_SEPARATOR)) - .orElse(new String[0]); - - originalProperties = Stream.of(fieldArray) - .map(String::trim) - .collect(Collectors.toList()); - - // using a map, so the properties will keep the case and the order of the query. - final Map originalMap = new HashMap<>(); - originalProperties.stream().forEach( - property -> originalMap.computeIfAbsent(property.toLowerCase(), prop -> property)); - - properties = originalProperties.stream() - .map(property -> originalMap.get(property.toLowerCase())) - .collect(Collectors.toCollection(LinkedHashSet::new)); - } -} diff --git a/src/main/java/org/sentrysoftware/wbem/client/exceptions/WqlQuerySyntaxException.java b/src/main/java/org/sentrysoftware/wbem/client/exceptions/WqlQuerySyntaxException.java deleted file mode 100644 index 98eca75..0000000 --- a/src/main/java/org/sentrysoftware/wbem/client/exceptions/WqlQuerySyntaxException.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.sentrysoftware.wbem.client.exceptions; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -/** - * Exception for a syntax error in the WQL Query parameter. - * - */ -public class WqlQuerySyntaxException extends Exception { - - private static final long serialVersionUID = 1L; - - public WqlQuerySyntaxException(final String wqlQuery) { - super("Syntax error in WQL Query: " + wqlQuery); - } - - public WqlQuerySyntaxException(final Throwable cause) { - super(cause); - } -} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/NodeFactory.java b/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/NodeFactory.java deleted file mode 100644 index 3e5aaaf..0000000 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/cimxml/sax/NodeFactory.java +++ /dev/null @@ -1,492 +0,0 @@ -/* - (C) Copyright IBM Corp. 2006, 2013 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1720707 2007-05-17 ebak Conventional Node factory for CIM-XML SAX parser - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - * 2845211 2009-08-27 raman_arora Pull Enumeration Feature (SAX Parser) - * 3498482 2012-03-09 blaschke-oss Red Hat: Possible XML Hash DoS in sblim - * 3535383 2012-08-01 blaschke-oss HashDoS fix 3498482 - * 2672 2013-09-26 blaschke-oss Remove SIMPLEREQACK support - * 2690 2013-10-11 blaschke-oss Remove RESPONSEDESTINATION support - * 2538 2013-11-28 blaschke-oss CR14: Support new CORRELATOR element - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.util.HashMap; - -import org.sentrysoftware.wbem.sblim.cimclient.internal.cimxml.sax.node.*; - -/** - * Class NodeFactory is responsible for Node instance construction. - * - */ -public class NodeFactory implements NodeConstIf { - - /** - * getNodeInstance - * - * @param pNodeName - * Should be an XML element name constant which is defined in - * NodeConstIf - * @return the Node subclass which implements the parsing of pNodeName named - * XML Element. - */ - public static Node getNodeInstance(String pNodeName) { - createParserMap(); - return cParserMap.get(pNodeName).create(); - } - - /** - * getEnum - * - * @param pNodeName - * @return The corresponding String constant for an XML element name. It - * must be used, because the Node subclasses use reference based - * equals comparisons (==). - */ - public static String getEnum(String pNodeName) { - return NODENAME_HASH.get(pNodeName); - } - - private static HashMap cParserMap; - - private interface FactoryEntry { - - /** - * create - * - * @return Node - */ - public Node create(); - } - - private synchronized static void createParserMap() { - if (cParserMap != null) return; - cParserMap = new HashMap(); - cParserMap.put(CIM, new FactoryEntry() { - - public Node create() { - return new CIMNode(); - } - }); - // DECLARATION - not implemented - // DECLGROUP - not implemented - // DECLGROUP.WITHNAME - not implemented - // DECLGROUP.WITHPATH - not implemented - cParserMap.put(QUALIFIER_DECLARATION, new FactoryEntry() { - - public Node create() { - return new QualiDeclNode(); - } - }); - cParserMap.put(SCOPE, new FactoryEntry() { - - public Node create() { - return new ScopeNode(); - } - }); - cParserMap.put(VALUE, new FactoryEntry() { - - public Node create() { - return new ValueNode(); - } - }); - cParserMap.put(VALUE_ARRAY, new FactoryEntry() { - - public Node create() { - return new ValueArrayNode(); - } - }); - cParserMap.put(VALUE_REFERENCE, new FactoryEntry() { - - public Node create() { - return new ValueReferenceNode(); - } - }); - cParserMap.put(VALUE_REFARRAY, new FactoryEntry() { - - public Node create() { - return new ValueRefArrayNode(); - } - }); - cParserMap.put(VALUE_OBJECT, new FactoryEntry() { - - public Node create() { - return new ValueObjectNode(); - } - }); - cParserMap.put(VALUE_NAMEDINSTANCE, new FactoryEntry() { - - public Node create() { - return new ValueNamedInstanceNode(); - } - }); - cParserMap.put(VALUE_OBJECTWITHLOCALPATH, new FactoryEntry() { - - public Node create() { - return new ValueObjectWithLocalPathNode(); - } - }); - cParserMap.put(VALUE_OBJECTWITHPATH, new FactoryEntry() { - - public Node create() { - return new ValueObjectWithPathNode(); - } - }); - cParserMap.put(VALUE_NULL, new FactoryEntry() { - - public Node create() { - return new ValueNullNode(); - } - }); - cParserMap.put(VALUE_INSTANCEWITHPATH, new FactoryEntry() { - - public Node create() { - return new ValueInstanceWithPathNode(); - } - }); - cParserMap.put(NAMESPACEPATH, new FactoryEntry() { - - public Node create() { - return new NameSpacePathNode(); - } - }); - cParserMap.put(LOCALNAMESPACEPATH, new FactoryEntry() { - - public Node create() { - return new LocalNameSpacePathNode(); - } - }); - cParserMap.put(HOST, new FactoryEntry() { - - public Node create() { - return new HostNode(); - } - }); - cParserMap.put(NAMESPACE, new FactoryEntry() { - - public Node create() { - return new NameSpaceNode(); - } - }); - cParserMap.put(CLASSPATH, new FactoryEntry() { - - public Node create() { - return new ClassPathNode(); - } - }); - cParserMap.put(LOCALCLASSPATH, new FactoryEntry() { - - public Node create() { - return new LocalClassPathNode(); - } - }); - cParserMap.put(CLASSNAME, new FactoryEntry() { - - public Node create() { - return new ClassNameNode(); - } - }); - cParserMap.put(INSTANCEPATH, new FactoryEntry() { - - public Node create() { - return new InstancePathNode(); - } - }); - cParserMap.put(LOCALINSTANCEPATH, new FactoryEntry() { - - public Node create() { - return new LocalInstancePathNode(); - } - }); - cParserMap.put(INSTANCENAME, new FactoryEntry() { - - public Node create() { - return new InstanceNameNode(); - } - }); - cParserMap.put(OBJECTPATH, new FactoryEntry() { - - public Node create() { - return new ObjectPathNode(); - } - }); - cParserMap.put(KEYBINDING, new FactoryEntry() { - - public Node create() { - return new KeyBindingNode(); - } - }); - cParserMap.put(KEYVALUE, new FactoryEntry() { - - public Node create() { - return new KeyValueNode(); - } - }); - cParserMap.put(CLASS, new FactoryEntry() { - - public Node create() { - return new ClassNode(); - } - }); - cParserMap.put(INSTANCE, new FactoryEntry() { - - public Node create() { - return new InstanceNode(); - } - }); - cParserMap.put(QUALIFIER, new FactoryEntry() { - - public Node create() { - return new QualifierNode(); - } - }); - cParserMap.put(PROPERTY, new FactoryEntry() { - - public Node create() { - return new PropertyNode(); - } - }); - cParserMap.put(PROPERTY_ARRAY, new FactoryEntry() { - - public Node create() { - return new PropertyArrayNode(); - } - }); - cParserMap.put(PROPERTY_REFERENCE, new FactoryEntry() { - - public Node create() { - return new PropertyReferenceNode(); - } - }); - cParserMap.put(METHOD, new FactoryEntry() { - - public Node create() { - return new MethodNode(); - } - }); - cParserMap.put(PARAMETER, new FactoryEntry() { - - public Node create() { - return new ParameterNode(); - } - }); - cParserMap.put(PARAMETER_REFERENCE, new FactoryEntry() { - - public Node create() { - return new ParameterReferenceNode(); - } - }); - cParserMap.put(PARAMETER_ARRAY, new FactoryEntry() { - - public Node create() { - return new ParameterArrayNode(); - } - }); - cParserMap.put(PARAMETER_REFARRAY, new FactoryEntry() { - - public Node create() { - return new ParameterRefArrayNode(); - } - }); - cParserMap.put(MESSAGE, new FactoryEntry() { - - public Node create() { - return new MessageNode(); - } - }); - cParserMap.put(MULTIREQ, new FactoryEntry() { - - public Node create() { - return new MultiReqNode(); - } - }); - cParserMap.put(MULTIEXPREQ, new FactoryEntry() { - - public Node create() { - return new MultiExpReqNode(); - } - }); - cParserMap.put(SIMPLEREQ, new FactoryEntry() { - - public Node create() { - return new SimpleReqNode(); - } - }); - cParserMap.put(SIMPLEEXPREQ, new FactoryEntry() { - - public Node create() { - return new SimpleExpReqNode(); - } - }); - cParserMap.put(IMETHODCALL, new FactoryEntry() { - - public Node create() { - return new IMethodCallNode(); - } - }); - cParserMap.put(METHODCALL, new FactoryEntry() { - - public Node create() { - return new MethodCallNode(); - } - }); - cParserMap.put(EXPMETHODCALL, new FactoryEntry() { - - public Node create() { - return new ExpMethodCallNode(); - } - }); - cParserMap.put(PARAMVALUE, new FactoryEntry() { - - public Node create() { - return new ParamValueNode(); - } - }); - cParserMap.put(IPARAMVALUE, new FactoryEntry() { - - public Node create() { - return new IParamValueNode(); - } - }); - cParserMap.put(EXPPARAMVALUE, new FactoryEntry() { - - public Node create() { - return new ExpParamValueNode(); - } - }); - cParserMap.put(MULTIRSP, new FactoryEntry() { - - public Node create() { - return new MultiRspNode(); - } - }); - cParserMap.put(MULTIEXPRSP, new FactoryEntry() { - - public Node create() { - return new MultiExpRspNode(); - } - }); - cParserMap.put(SIMPLERSP, new FactoryEntry() { - - public Node create() { - return new SimpleRspNode(); - } - }); - cParserMap.put(SIMPLEEXPRSP, new FactoryEntry() { - - public Node create() { - return new SimpleExpRspNode(); - } - }); - cParserMap.put(METHODRESPONSE, new FactoryEntry() { - - public Node create() { - return new MethodResponseNode(); - } - }); - cParserMap.put(EXPMETHODRESPONSE, new FactoryEntry() { - - public Node create() { - return new ExpMethodResponseNode(); - } - }); - cParserMap.put(IMETHODRESPONSE, new FactoryEntry() { - - public Node create() { - return new IMethodResponseNode(); - } - }); - cParserMap.put(ERROR, new FactoryEntry() { - - public Node create() { - return new ErrorNode(); - } - }); - cParserMap.put(RETURNVALUE, new FactoryEntry() { - - public Node create() { - return new ReturnValueNode(); - } - }); - cParserMap.put(IRETURNVALUE, new FactoryEntry() { - - public Node create() { - return new IReturnValueNode(); - } - }); - cParserMap.put(CORRELATOR, new FactoryEntry() { - - public Node create() { - return new CorrelatorNode(); - } - }); - } - - private static final HashMap NODENAME_HASH = new HashMap(); - - private static void initNodeNameHash(String[] pEnumA) { - for (int i = 0; i < pEnumA.length; i++) - NODENAME_HASH.put(pEnumA[i], pEnumA[i]); - } - - static { - initNodeNameHash(new String[] { CIM, DECLARATION, DECLGROUP, DECLGROUP_WITHNAME, - DECLGROUP_WITHPATH, QUALIFIER_DECLARATION, SCOPE, VALUE, VALUE_ARRAY, - VALUE_REFERENCE, VALUE_REFARRAY, VALUE_OBJECT, VALUE_NAMEDINSTANCE, - VALUE_NAMEDOBJECT, VALUE_OBJECTWITHLOCALPATH, VALUE_OBJECTWITHPATH, VALUE_NULL, - VALUE_INSTANCEWITHPATH, - - NAMESPACEPATH, LOCALNAMESPACEPATH, HOST, NAMESPACE, CLASSPATH, LOCALCLASSPATH, - CLASSNAME, INSTANCEPATH, LOCALINSTANCEPATH, INSTANCENAME, OBJECTPATH, KEYBINDING, - KEYVALUE, - - CLASS, INSTANCE, QUALIFIER, PROPERTY, PROPERTY_ARRAY, PROPERTY_REFERENCE, METHOD, - PARAMETER, PARAMETER_REFERENCE, PARAMETER_ARRAY, PARAMETER_REFARRAY, - - /* - * TABLE stuff is missing yet - */ - MESSAGE, MULTIREQ, MULTIEXPREQ, SIMPLEREQ, SIMPLEEXPREQ, IMETHODCALL, METHODCALL, - EXPMETHODCALL, PARAMVALUE, IPARAMVALUE, EXPPARAMVALUE, MULTIRSP, MULTIEXPRSP, - SIMPLERSP, SIMPLEEXPRSP, METHODRESPONSE, EXPMETHODRESPONSE, IMETHODRESPONSE, ERROR, - RETURNVALUE, IRETURNVALUE, CORRELATOR }); - } - -} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/uri/Test.java b/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/uri/Test.java deleted file mode 100644 index b6ff8dc..0000000 --- a/src/main/java/org/sentrysoftware/wbem/sblim/cimclient/internal/uri/Test.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - (C) Copyright IBM Corp. 2006, 2011 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, ebak@de.ibm.com - * - * Flag Date Prog Description - * ------------------------------------------------------------------------------- - * 1565892 2006-11-05 ebak Make SBLIM client JSR48 compliant - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 3194680 2011-02-28 blaschke-oss Error in numeric keys - */ - -package org.sentrysoftware.wbem.sblim.cimclient.internal.uri; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import org.sentrysoftware.wbem.sblim.cimclient.internal.util.Util; - -/** - * Class Test is responsible for testing the WBEM-URI String parsing. - */ -public class Test { - - private static String cUriArray[] = { - - "//www.acme.com/root/cimv2", - - "//www.acme.com/root/cimv2:CIM_RegisteredProfile", - - "https://jdd:test@acme.com:5959/cimv2:CIM_RegisteredProfile", - - "https://jdd:test@acme.com:5959/cimv2:CIM_RegisteredProfile." - + "Cool=\"Hey! It's a string\"", - - "https://jdd:test@acme.com:5959/cimv2:CIM_RegisteredProfile.ThisShouldBeAnInt=0", - - "https://jdd:test@acme.com:5959/cimv2:CIM_RegisteredProfile." - + "Cool=\"Hey! It's a string\"," - + "Yeah=\"Gee! \\\"It's an embedded string\\\"\"", - - "https://jdd:test@acme.com:5959/cimv2:CIM_RegisteredProfile." - // + - // "SelfRef=\"https://jdd:test@acme.com:5959/cimv2:CIM_RegisteredProfile\"", - + "InstRef=\"CIM_RegisteredProfile.IntKey=10\"", - "https://jdd:test@acme.com:5959/cimv2:CIM_RegisteredProfile." - + "Yeah=" - + Util.quote("Gee! " + Util.quote("It's an embedded string")) - + ",Ref=" - + Util.quote(// "https://jdd:test@acme.com:5959/cimv2:CIM_RegisteredProfile." - "root/cimv2:CIM_RegisteredProfile." + "Yeah=" - + Util.quote("Gee! " + Util.quote("It's an embedded string"))), - - "https://jdd:test@64.202.189.170:5959/cimv2:CIM_RegisteredProfile." - + "Yeah=" - + Util.quote("Gee! " + Util.quote("It's an embedded string")) - + ",Ref=" - + Util.quote(// "https://jdd:test@acme.com:5959/cimv2:CIM_RegisteredProfile." - "CIM_RegisteredProfile." + "Yeah=" - + Util.quote("Gee! " + Util.quote("It's an embedded string"))), - - "https://64.202.189.170:5959/cimv2:CIM_RegisteredProfile." - + "Yeah=" - + Util.quote("Gee! " + Util.quote("It's an embedded string")) - + ",Ref=" - + Util.quote(// "https://jdd:test@acme.com:5959/cimv2:CIM_RegisteredProfile." - "CIM_RegisteredProfile." + "Yeah=" - + Util.quote("Gee! " + Util.quote("It's an embedded string"))), - - "https://64.202.189.170:5959/cimv2:CIM_RegisteredProfile." - + "Yeah=" - + Util.quote("Gee! " + Util.quote("It's an embedded string")) - + ",Ref=" - + Util.quote("CIM_RegisteredProfile." + "Yeah=" - + Util.quote("Gee! " + Util.quote("It's an embedded string"))) - + ",CharKey0='a'" + ",CharKey1='\\x32'" + ",boolKeyT=True" + ",boolKeyF=False" - + ",binValP=01011010b" + ",binValN=-01011010b" + ",octValP=0644" - + ",octValN=-0644" + ",decValP=1848" + ",decValN=-1848" + ",hexValP=0x55aa" - + ",hexValN=-0x55aa" + ",realValP=+23.566e-23" + ",realValN=-23.566e+23" - + ",dtAbs=" + Util.quote("20061027112135.600123+001") + ",dtInv=" - + Util.quote("00000042123625.600123:000"), - - /* - * Typed URI strings - */ - "https://64.202.189.170:5959/cimv2/(instance)CIM_RegisteredProfile." - + "Yeah=(string)" - + Util.quote("Gee! " + Util.quote("It's an embedded string")) - + ",uInt32=(uint32)100000" - + ",Real32=(real32)3.14" - + ",dtAbs=(datetime)" - + Util.quote("20061027112135.600123+001") - + ",dtInv=(datetime)" - + Util.quote("00000042123625.600123:000") - + ",Bool=(boolean)true" - + ",Char=(char16)'x'" - + ",Ref=(reference)" - + Util.quote("/(instance)CIM_RegisteredProfile." + "Yeah=(string)" - + Util.quote("Gee! " + Util.quote("It's an embedded string")) - + ",ClassRef=(reference)" - + Util.quote("/(instance)CIM_Gyurcsany.Key=(uint8)10")) - + ",RefWithNS=(reference)" - + Util.quote("root/cimv2/(instance)CIM_Orban.Key=(uint8)42") - - }; - - /** - * main - * - * @param args - */ - public static void main(String args[]) { - for (int i = 0; i < cUriArray.length; i++) { - System.out.println("\nparsing:\n" + cUriArray[i]); - URI uri = URI.parse(cUriArray[i]); - if (uri == null) { - System.out.println("parsing failed!"); - continue; - } - System.out.println("class:\n" + uri.getClass().getName()); - System.out.println("refactored string:\n" + uri.toString()); - - System.out.println("namespace name : " + uri.getNamespaceName()); - System.out.println("namespace type : " + uri.getNamespaceType()); - System.out.println("user info : " + uri.getUserInfo()); - System.out.println("host name : " + uri.getHost()); - System.out.println("port : " + uri.getPort()); - System.out.println("class name : " + uri.getClassName()); - KeyValuePairs pairs = uri.getKeyValuePairs(); - if (pairs == null) continue; - for (int j = 0; j < pairs.size(); j++) { - KeyValuePair pair = (KeyValuePair) pairs.elementAt(j); - Value value = pair.getValue(); - System.out.println("key : " + pair.getKey() + "\n " + getTypeStr(value) + " : " - + pair.getValue().toString() + " " + getIntProps(value)); - } - } - } - - private static String getTypeStr(Value pVal) { - if (pVal instanceof ReferenceValue) return "refValue"; - else if (pVal instanceof StringValue) return "strValue"; - else if (pVal instanceof CharValue) return "chrValue"; - else if (pVal instanceof BooleanValue) return "boolValue"; - else if (pVal instanceof DateTimeValue) return "dateTimeVal"; - else if (pVal instanceof IntegerValue) return "intValue"; - else if (pVal instanceof RealValue) return "realValue"; - return pVal.getClass().getName(); - } - - private static String getIntProps(Value pVal) { - if (!(pVal instanceof IntegerValue)) return ""; - IntegerValue intVal = (IntegerValue) pVal; - return "sigend=" + intVal.isSigned() + ", bitWidth=" + intVal.getBitWidth(); - } - -} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/MsgFactory.java b/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/MsgFactory.java deleted file mode 100644 index 43483a8..0000000 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/msg/MsgFactory.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.msg; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.io.IOException; -import java.io.InputStream; -import java.net.DatagramPacket; -import java.net.Socket; - -import org.sentrysoftware.wbem.sblim.slp.internal.msg.FunctionIDs; -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException; - -/** - * MsgFactory - * - */ -public class MsgFactory implements FunctionIDs { - - /** - * FactoryEntry - * - */ - private interface FactoryEntry { - - /** - * parse - * - * @param pHdr - * @param pInStr - * @return SLPMessage - * @throws ServiceLocationException - * @throws IOException - */ - public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException; - } - - private static FactoryEntry[] cFactoryArray; - - private static void placeFactory(int pFnID, FactoryEntry pEntry) { - cFactoryArray[pFnID - FIRST_ID] = pEntry; - } - - private static synchronized void createFactoryArray() { - if (cFactoryArray != null) return; - cFactoryArray = new FactoryEntry[LAST_ID - FIRST_ID + 1]; - for (int i = 0; i < cFactoryArray.length; i++) - cFactoryArray[i] = null; - placeFactory(ATTR_RPLY, new FactoryEntry() { - - public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException { - return AttributeReply.parse(pHdr, pInStr); - } - }); - placeFactory(ATTR_RQST, new FactoryEntry() { - - public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException { - return AttributeRequest.parse(pHdr, pInStr); - } - }); - placeFactory(DA_ADVERT, new FactoryEntry() { - - public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException { - return DAAdvert.parse(pHdr, pInStr); - } - }); - placeFactory(SA_ADVERT, new FactoryEntry() { - - public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException { - return SAAdvert.parse(pHdr, pInStr); - } - }); - placeFactory(SRV_ACK, new FactoryEntry() { - - public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException { - return ServiceAcknowledgment.parse(pHdr, pInStr); - } - }); - placeFactory(SRV_DEREG, new FactoryEntry() { - - public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException { - return ServiceDeregistration.parse(pHdr, pInStr); - } - }); - placeFactory(SRV_REG, new FactoryEntry() { - - public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException { - return ServiceRegistration.parse(pHdr, pInStr); - } - }); - placeFactory(SRV_RPLY, new FactoryEntry() { - - public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException { - return ServiceReply.parse(pHdr, pInStr); - } - }); - placeFactory(SRV_RQST, new FactoryEntry() { - - public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException { - return ServiceRequest.parse(pHdr, pInStr); - } - }); - // - placeFactory(SRV_TYPE_RPLY, new FactoryEntry() { - - public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException { - return ServiceTypeReply.parse(pHdr, pInStr); - } - }); - placeFactory(SRV_TYPE_RQST, new FactoryEntry() { - - public SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) - throws ServiceLocationException, IOException { - return ServiceTypeRequest.parse(pHdr, pInStr); - } - }); - } - - private static FactoryEntry getFactory(int pFnID) { - createFactoryArray(); - return cFactoryArray[pFnID - FIRST_ID]; - } - - /** - * parse - * - * @param pSock - * @return SLPMessage - * @throws ServiceLocationException - * @throws IOException - */ - public static SLPMessage parse(Socket pSock) throws ServiceLocationException, IOException { - return parse(pSock.getInputStream()); - } - - /** - * parse - * - * @param pInStr - * @return SLPMessage - * @throws ServiceLocationException - * @throws IOException - */ - public static SLPMessage parse(InputStream pInStr) throws ServiceLocationException, IOException { - return parse(new SLPInputStream(pInStr)); - } - - /** - * parse - * - * @param pPacket - * @return SLPMessage - * @throws ServiceLocationException - * @throws IOException - */ - public static SLPMessage parse(DatagramPacket pPacket) throws ServiceLocationException, - IOException { - return parse(new SLPInputStream(pPacket)); - } - - /** - * parse - * - * @param pInStr - * @return SLPMessage - * @throws ServiceLocationException - * @throws IOException - */ - public static SLPMessage parse(SLPInputStream pInStr) throws ServiceLocationException, - IOException { - MsgHeader hdr = MsgHeader.parse(pInStr); - FactoryEntry factory = getFactory(hdr.getFunctionID()); - if (factory == null) throw new ServiceLocationException( - ServiceLocationException.NOT_IMPLEMENTED, "FunctionID=" + hdr.getFunctionID() - + " is not implemented!"); - return factory.parse(hdr, pInStr); - } - -} diff --git a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/ua/LocatorImpl.java b/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/ua/LocatorImpl.java deleted file mode 100644 index e099497..0000000 --- a/src/main/java/org/sentrysoftware/wbem/sblim/slp/internal/ua/LocatorImpl.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - (C) Copyright IBM Corp. 2007, 2009 - - THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE - ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE - CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. - - You can obtain a current copy of the Eclipse Public License from - http://www.opensource.org/licenses/eclipse-1.0.php - - @author : Endre Bak, IBM, ebak@de.ibm.com - * - * Change History - * Flag Date Prog Description - *------------------------------------------------------------------------------- - * 1804402 2007-09-28 ebak IPv6 ready SLP - * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL - * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) - * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) - */ - -package org.sentrysoftware.wbem.sblim.slp.internal.ua; - -/*- - * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ - * WBEM Java Client - * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software - * ჻჻჻჻჻჻ - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ - */ - -import java.net.InetAddress; -import java.util.Locale; -import java.util.SortedSet; -import java.util.Vector; - -import org.sentrysoftware.wbem.sblim.slp.Locator; -import org.sentrysoftware.wbem.sblim.slp.ServiceLocationEnumeration; -import org.sentrysoftware.wbem.sblim.slp.ServiceType; -import org.sentrysoftware.wbem.sblim.slp.ServiceURL; -import org.sentrysoftware.wbem.sblim.slp.internal.SLPDefaults; -import org.sentrysoftware.wbem.sblim.slp.internal.TRC; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.AttributeRequest; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.ServiceRequest; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.ServiceTypeRequest; -import org.sentrysoftware.wbem.sblim.slp.internal.msg.Util; - -/** - * LocatorImpl - * - */ -public class LocatorImpl implements Locator { - - private Locale iLocale; - - private String iLangTag; - - /** - * Ctor. - * - * @param pLocale - */ - public LocatorImpl(Locale pLocale) { - this.iLocale = pLocale; - this.iLangTag = Util.getLangTag(this.iLocale); - TRC.debug("created, langTag=" + this.iLangTag); - } - - public ServiceLocationEnumeration findAttributes(ServiceURL pURL, Vector pScopes, - Vector pAttributeIds) { - return findAttributes(pURL, pScopes, pAttributeIds, null); - } - - public ServiceLocationEnumeration findAttributes(ServiceURL pURL, Vector pScopes, - Vector pAttributeIds, Vector pDirectoryAgents) { - return new SLEnumerationImpl(new AttributeRequest(this.iLangTag, (SortedSet) null, - pURL.toString(), getScopes(pScopes), pAttributeIds, null), pDirectoryAgents); - } - - public ServiceLocationEnumeration findAttributes(ServiceType pType, Vector pScopes, - Vector pAttributeIds) { - return findAttributes(pType, pScopes, pAttributeIds, null); - } - - public ServiceLocationEnumeration findAttributes(ServiceType pType, Vector pScopes, - Vector pAttributeIds, Vector pDirectoryAgents) { - return new SLEnumerationImpl(new AttributeRequest(this.iLangTag, (SortedSet) null, - pType.toString(), getScopes(pScopes), pAttributeIds, null), pDirectoryAgents); - } - - public ServiceLocationEnumeration findServiceTypes(String pNamingAuthority, - Vector pScopes) { - return findServiceTypes(pNamingAuthority, pScopes, null); - } - - public ServiceLocationEnumeration findServiceTypes(String pNamingAuthority, - Vector pScopes, Vector pDirectoryAgent) { - return new SLEnumerationImpl(new ServiceTypeRequest(this.iLangTag, null, pNamingAuthority, - getScopes(pScopes)), pDirectoryAgent); - } - - public ServiceLocationEnumeration findServices(ServiceType pType, Vector pScopes, - String pSearchFilter) { - return findServices(pType, pScopes, pSearchFilter, null); - } - - public ServiceLocationEnumeration findServices(ServiceType pType, Vector pScopes, - String pSearchFilter, Vector pDirectoryAgents) { - return new SLEnumerationImpl(new ServiceRequest(this.iLangTag, null, pType, - getScopes(pScopes), pSearchFilter, null), pDirectoryAgents); - } - - public Locale getLocale() { - return this.iLocale; - } - - /** - * @param pScopes - * @return pScopes if that is not empty or a Vector with "default" entry if - * the pScopes is null or empty - */ - private static Vector getScopes(Vector pScopes) { - if (pScopes == null) pScopes = new Vector(); - if (pScopes.isEmpty()) pScopes.add(SLPDefaults.DEFAULT_SCOPE); - return pScopes; - } - -} diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index 1f6fbb6..94cac33 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -1,9 +1,10 @@ # WBEM Java Client The Web-Based Entreprise Management (WBEM) Java Client is a library that enables to: -* Connect to a WBEM Server -* Execute WQL (WBEM Query Language) queries such as EnumerateInstances -It uses HTTP/HTTPS protocol for that purpose. + +- Connect to a WBEM Server +- Execute WQL (WBEM Query Language) queries such as EnumerateInstances + It uses HTTP/HTTPS protocol for that purpose. # How to run the WBEM Client inside Java @@ -24,11 +25,10 @@ When you embed the WBEM Java Client into your Java application, it's important t ### Exporting Packages with `--add-exports` -Use the `--add-exports` flag to allow modules to access the internal parsers provided by the `com.sun.org.apache.xerces` package in the `java.xml` module: +Use the `--add-exports` flag to allow modules to access the internal parsers provided by the `com.sun.org.apache.xerces` package in the `java.xml` module: - `java.xml/com.sun.org.apache.xerces.internal.parsers` - ### Opening Packages with `--add-opens` Use the `--add-opens` flag to open the required packages in the `java.base` module: @@ -38,7 +38,6 @@ Use the `--add-opens` flag to open the required packages in the `java.base` modu - `java.base/sun.net.www.protocol.http` - `java.base/sun.security.ssl` - ### Example Usage When invoking the `jar` command, include the specified `--add-exports` and `--add-opens` options in the JVM arguments. For example: @@ -48,15 +47,16 @@ java -jar --add-exports java.xml/com.sun.org.apache.xerces.internal.parsers --ad ``` Use it as follows: + ```Java -package org.sentrysoftware.wbem; +package org.metricshub.wbem; import java.net.MalformedURLException; import java.net.URL; -import org.sentrysoftware.wbem.client.WbemClient; -import org.sentrysoftware.wbem.client.WqlQuery; -import org.sentrysoftware.wbem.javax.wbem.WBEMException; -import org.sentrysoftware.wbem.utils.exceptions.WqlQuerySyntaxException; +import org.metricshub.wbem.client.WbemClient; +import org.metricshub.wbem.client.WqlQuery; +import org.metricshub.wbem.client.exceptions.WqlQuerySyntaxException; +import org.metricshub.wbem.javax.wbem.WBEMException; public class Main { @@ -88,4 +88,4 @@ public class Main { } } -``` \ No newline at end of file +``` diff --git a/src/site/resources/css/site.css b/src/site/resources/css/site.css new file mode 100644 index 0000000..e85911b --- /dev/null +++ b/src/site/resources/css/site.css @@ -0,0 +1,86 @@ +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * Open MetricsHub Web Site + * ჻჻჻჻჻჻ + * Copyright (C) 2025 MetricsHub + * ჻჻჻჻჻჻ + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/* Poppins font */ +@font-face { + font-family: 'Poppins'; + src: url('../fonts/Poppins-ExtraBold.woff2') format('woff2'), + url('../fonts/Poppins-ExtraBold.woff') format('woff'), + url('../fonts/Poppins-ExtraBold.ttf') format('truetype'), + local('Helvetica'); + font-weight: 800; + font-style: normal; + font-display: swap; +} + +@font-face { + font-family: 'Poppins'; + src: url('../fonts/Poppins-Bold.woff2') format('woff2'), + url('../fonts/Poppins-Bold.woff') format('woff'), + url('../fonts/Poppins-Bold.ttf') format('truetype'), + local('Helvetica'); + font-weight: 700; + font-style: normal; + font-display: swap; +} + +@font-face { + font-family: 'Poppins'; + src: url('../fonts/Poppins-Regular.woff2') format('woff2'), + url('../fonts/Poppins-Regular.woff') format('woff'), + url('../fonts/Poppins-Regular.ttf') format('truetype'), + local('Helvetica'); + font-weight: 400; + font-style: normal; + font-display: swap; +} + +/* MetricsHub fonts */ +:root { + --title-font: "Poppins", sans-serif; + --heading-font: "Poppins", sans-serif; + --content-font: "Poppins", sans-serif; + + --content-font-size: medium; + --banner-font-size: 40px; + --banner-font-weight: 800; + +} + + /* MetricsHub colors */ +body { + --main-fgcolor: #212529; + --banner-bgcolor: #266fd0; + --link-color: #266fd0; + --alternate-bgcolor: #266fd0; + --alternate-fgcolor: #fff; +} + +body.dark { + --link-color: #7cb6ff; + --main-bgcolor: #262626; + --main-fgcolor: #e9ecef; +} \ No newline at end of file diff --git a/src/site/resources/favicon.ico b/src/site/resources/favicon.ico new file mode 100644 index 0000000..61a2a88 Binary files /dev/null and b/src/site/resources/favicon.ico differ diff --git a/src/site/resources/fonts/Poppins-Bold.ttf b/src/site/resources/fonts/Poppins-Bold.ttf new file mode 100644 index 0000000..00559ee Binary files /dev/null and b/src/site/resources/fonts/Poppins-Bold.ttf differ diff --git a/src/site/resources/fonts/Poppins-Bold.woff b/src/site/resources/fonts/Poppins-Bold.woff new file mode 100644 index 0000000..c979105 Binary files /dev/null and b/src/site/resources/fonts/Poppins-Bold.woff differ diff --git a/src/site/resources/fonts/Poppins-Bold.woff2 b/src/site/resources/fonts/Poppins-Bold.woff2 new file mode 100644 index 0000000..13e0e28 Binary files /dev/null and b/src/site/resources/fonts/Poppins-Bold.woff2 differ diff --git a/src/site/resources/fonts/Poppins-ExtraBold.ttf b/src/site/resources/fonts/Poppins-ExtraBold.ttf new file mode 100644 index 0000000..df70936 Binary files /dev/null and b/src/site/resources/fonts/Poppins-ExtraBold.ttf differ diff --git a/src/site/resources/fonts/Poppins-ExtraBold.woff b/src/site/resources/fonts/Poppins-ExtraBold.woff new file mode 100644 index 0000000..0d7982a Binary files /dev/null and b/src/site/resources/fonts/Poppins-ExtraBold.woff differ diff --git a/src/site/resources/fonts/Poppins-ExtraBold.woff2 b/src/site/resources/fonts/Poppins-ExtraBold.woff2 new file mode 100644 index 0000000..ad86d02 Binary files /dev/null and b/src/site/resources/fonts/Poppins-ExtraBold.woff2 differ diff --git a/src/site/resources/fonts/Poppins-Regular.ttf b/src/site/resources/fonts/Poppins-Regular.ttf new file mode 100644 index 0000000..9f0c71b Binary files /dev/null and b/src/site/resources/fonts/Poppins-Regular.ttf differ diff --git a/src/site/resources/fonts/Poppins-Regular.woff2 b/src/site/resources/fonts/Poppins-Regular.woff2 new file mode 100644 index 0000000..964d6d2 Binary files /dev/null and b/src/site/resources/fonts/Poppins-Regular.woff2 differ diff --git a/src/site/resources/images/metricshub-logo.png b/src/site/resources/images/metricshub-logo.png new file mode 100644 index 0000000..89d6fb8 Binary files /dev/null and b/src/site/resources/images/metricshub-logo.png differ diff --git a/src/site/resources/images/sentry-logo-179x75px.png b/src/site/resources/images/sentry-logo-179x75px.png deleted file mode 100644 index 42e53f7..0000000 Binary files a/src/site/resources/images/sentry-logo-179x75px.png and /dev/null differ diff --git a/src/site/site.xml b/src/site/site.xml index b533fec..2a35e65 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -4,7 +4,7 @@ org.sentrysoftware.maven sentry-maven-skin - 6.2.00 + 6.4.01 @@ -13,15 +13,14 @@ - images/sentry-logo-179x75px.png - https://sentrysoftware.com + images/metricshub-logo.png + https://metricshub.org - diff --git a/src/test/java/org/metricshub/wbem/WbemCimDataHandlerTest.java b/src/test/java/org/metricshub/wbem/WbemCimDataHandlerTest.java new file mode 100644 index 0000000..0067dac --- /dev/null +++ b/src/test/java/org/metricshub/wbem/WbemCimDataHandlerTest.java @@ -0,0 +1,345 @@ +package org.metricshub.wbem; + +import java.math.BigInteger; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.metricshub.wbem.client.WbemCimDataHandler; +import org.metricshub.wbem.javax.cim.CIMClass; +import org.metricshub.wbem.javax.cim.CIMClassProperty; +import org.metricshub.wbem.javax.cim.CIMDataType; +import org.metricshub.wbem.javax.cim.CIMDateTime; +import org.metricshub.wbem.javax.cim.CIMDateTimeAbsolute; +import org.metricshub.wbem.javax.cim.CIMDateTimeInterval; +import org.metricshub.wbem.javax.cim.CIMInstance; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.cim.CIMProperty; + +class WbemCimDataHandlerTest { + + @Test + void testGetCimPropertyAsString() { + final CIMObjectPath objectPath = new CIMObjectPath( + "root/emc:Symm_StorageSystem.CreationClassName=\"Symm_StorageSystem\",Name=\"SYMMETRIX-+-000297800620\"" + ); + + Assertions.assertThrows( + IllegalArgumentException.class, + () -> + WbemCimDataHandler.getCimPropertyAsString( + null, + new CIMInstance( + objectPath, + new CIMProperty[] { new CIMProperty("Name", CIMDataType.STRING_T, "SYMMETRIX-+-000297800620") } + ), + null + ) + ); + Assertions.assertThrows( + IllegalArgumentException.class, + () -> WbemCimDataHandler.getCimPropertyAsString("Name", null, null) + ); + + Assertions.assertThrows( + IllegalArgumentException.class, + () -> + WbemCimDataHandler.getCimPropertyAsString( + "__Path", + new CIMInstance( + null, + new CIMProperty[] { new CIMProperty("Name", CIMDataType.STRING_T, "SYMMETRIX-+-000297800620") } + ), + null + ) + ); + Assertions.assertThrows( + IllegalArgumentException.class, + () -> + WbemCimDataHandler.getCimPropertyAsString( + "Ref", + new CIMInstance( + objectPath, + new CIMProperty[] { new CIMProperty("Ref", new CIMDataType("Ref", 1), "x") } + ), + null + ) + ); + + Assertions.assertEquals( + "Symm_StorageSystem.CreationClassName=\"Symm_StorageSystem\",Name=\"SYMMETRIX-+-000297800620\"", + WbemCimDataHandler.getCimPropertyAsString("__PATH", new CIMInstance(objectPath, null), null) + ); + + Assertions.assertEquals( + "", + WbemCimDataHandler.getCimPropertyAsString( + "UnknownProperty", + new CIMInstance( + objectPath, + new CIMProperty[] { + new CIMProperty("Name", CIMDataType.STRING_T, "\"SYMMETRIX-+-000297800620;\"") + } + ), + null + ) + ); + + Assertions.assertEquals( + "blablaVal", + WbemCimDataHandler.getCimPropertyAsString( + "blabla", + new CIMInstance( + objectPath, + new CIMProperty[] { + new CIMProperty("Name", CIMDataType.STRING_T, "\"SYMMETRIX-+-000297800620;\""), + new CIMProperty("blabla", CIMDataType.STRING_T, "blablaVal", true, false, null) + } + ), + null + ) + ); + + Assertions.assertEquals( + "", + WbemCimDataHandler.getCimPropertyAsString( + "Name", + new CIMInstance( + objectPath, + new CIMProperty[] { new CIMProperty("Name", CIMDataType.STRING_T, null) } + ), + null + ) + ); + + Assertions.assertEquals( + "\"SYMMETRIX-+-000297800620;\"", + WbemCimDataHandler.getCimPropertyAsString( + "Name", + new CIMInstance( + objectPath, + new CIMProperty[] { + new CIMProperty("Name", CIMDataType.STRING_T, "\"SYMMETRIX-+-000297800620;\"") + } + ), + null + ) + ); + + Assertions.assertEquals( + "true", + WbemCimDataHandler.getCimPropertyAsString( + "EMCAutoMetaEnabled", + new CIMInstance( + objectPath, + new CIMProperty[] { new CIMProperty("EMCAutoMetaEnabled", CIMDataType.BOOLEAN_T, Boolean.TRUE) } + ), + null + ) + ); + + Assertions.assertEquals( + "true|false|", + WbemCimDataHandler.getCimPropertyAsString( + "EMCAutoMetaEnabledArray", + new CIMInstance( + objectPath, + new CIMProperty[] { + new CIMProperty( + "EMCAutoMetaEnabledArray", + CIMDataType.BOOLEAN_ARRAY_T, + new Boolean[] { Boolean.TRUE, Boolean.FALSE } + ) + } + ), + null + ) + ); + + Assertions.assertEquals( + "10", + WbemCimDataHandler.getCimPropertyAsString( + "PortType", + new CIMInstance( + objectPath, + new CIMProperty[] { new CIMProperty("PortType", CIMDataType.SINT32_T, Integer.valueOf(10)) } + ), + null + ) + ); + + Assertions.assertEquals( + "2125000000", + WbemCimDataHandler.getCimPropertyAsString( + "MaxSpeed", + new CIMInstance( + objectPath, + new CIMProperty[] { + new CIMProperty("MaxSpeed", CIMDataType.UINT64_T, new BigInteger("2125000000")) + } + ), + null + ) + ); + + Assertions.assertEquals( + "1|2|", + WbemCimDataHandler.getCimPropertyAsString( + "OperationalStatus", + new CIMInstance( + objectPath, + new CIMProperty[] { + new CIMProperty("OperationalStatus", CIMDataType.SINT16_ARRAY_T, new Short[] { 1, 2 }) + } + ), + null + ) + ); + + Assertions.assertEquals( + "Symm_StorageSystem.CreationClassName=\"Symm_StorageSystem\",Name=\"SYMMETRIX-+-000297800620\"", + WbemCimDataHandler.getCimPropertyAsString( + "Ref", + new CIMInstance( + objectPath, + new CIMProperty[] { new CIMProperty("Ref", new CIMDataType("Ref"), objectPath) } + ), + null + ) + ); + + Assertions.assertEquals( + "Symm_StorageSystem.CreationClassName=\"Symm_StorageSystem\",Name=\"SYMMETRIX-+-000297800620\"" + "|", + WbemCimDataHandler.getCimPropertyAsString( + "Ref", + new CIMInstance( + objectPath, + new CIMProperty[] { + new CIMProperty("Ref", new CIMDataType("Ref", 1), new CIMObjectPath[] { objectPath }) + } + ), + null + ) + ); + + Assertions.assertEquals( + "Symm_StorageSystem.CreationClassName=\"Symm_StorageSystem\",Name=\"SYMMETRIX-+-000297800620\"" + + "||" + + "Symm_StorageSystem.CreationClassName=\"Symm_StorageSystem\",Name=\"SYMMETRIX-+-000297800620\"" + + "|", + WbemCimDataHandler.getCimPropertyAsString( + "Ref", + new CIMInstance( + objectPath, + new CIMProperty[] { + new CIMProperty( + "Ref", + new CIMDataType("Ref", 3), + new CIMObjectPath[] { objectPath, null, objectPath } + ) + } + ), + null + ) + ); + + Assertions.assertEquals( + "1173882243000", + WbemCimDataHandler.getCimPropertyAsString( + "timeAbsolute", + new CIMInstance( + objectPath, + new CIMProperty[] { + new CIMProperty( + "timeAbsolute", + CIMDataType.DATETIME_T, + new CIMDateTimeAbsolute("20070314160503.566012+101") + ) + } + ), + null + ) + ); + + Assertions.assertEquals( + "1173882243566", + WbemCimDataHandler.getCimPropertyAsString( + "timeInterval", + new CIMInstance( + objectPath, + new CIMProperty[] { + new CIMProperty( + "timeInterval", + CIMDataType.DATETIME_T, + new CIMDateTimeInterval(1173882243566L) + ) + } + ), + null + ) + ); + + Assertions.assertEquals( + "1173882243000|1173882243566|", + WbemCimDataHandler.getCimPropertyAsString( + "timeArray", + new CIMInstance( + objectPath, + new CIMProperty[] { + new CIMProperty( + "timeArray", + CIMDataType.DATETIME_ARRAY_T, + new CIMDateTime[] { + new CIMDateTimeAbsolute("20070314160503.566012+101"), + new CIMDateTimeInterval(1173882243566L) + } + ) + } + ), + null + ) + ); + + final CIMClass cimClass = new CIMClass( + "testClass", + null, + null, + new CIMClassProperty[] { + new CIMClassProperty("KeyProp", CIMDataType.STRING_T, null, null, false, false, null) + }, + null + ); + + Assertions.assertEquals( + "class testClass {" + " string KeyProp;" + "};", + WbemCimDataHandler + .getCimPropertyAsString( + "propClass", + new CIMInstance( + objectPath, + new CIMProperty[] { new CIMProperty("propClass", CIMDataType.CLASS_T, cimClass) } + ), + null + ) + .replaceAll("[\r\n]", "") + ); + + Assertions.assertEquals( + "class testClass {" + " string KeyProp;" + "};" + "$$" + "class testClass {" + " string KeyProp;" + "};" + "$", + WbemCimDataHandler + .getCimPropertyAsString( + "propClass", + new CIMInstance( + objectPath, + new CIMProperty[] { + new CIMProperty( + "propClass", + CIMDataType.CLASS_ARRAY_T, + new CIMClass[] { cimClass, null, cimClass } + ) + } + ), + "$" + ) + .replaceAll("[\r\n]", "") + ); + } +} diff --git a/src/test/java/org/metricshub/wbem/WbemClientTest.java b/src/test/java/org/metricshub/wbem/WbemClientTest.java new file mode 100644 index 0000000..e59d1c2 --- /dev/null +++ b/src/test/java/org/metricshub/wbem/WbemClientTest.java @@ -0,0 +1,218 @@ +package org.metricshub.wbem; + +import java.net.URL; +import java.util.Locale; +import javax.security.auth.Subject; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.metricshub.wbem.client.WbemClient; +import org.metricshub.wbem.client.WbemQueryResult; +import org.metricshub.wbem.client.WqlQuery; +import org.metricshub.wbem.javax.cim.CIMInstance; +import org.metricshub.wbem.javax.cim.CIMObjectPath; +import org.metricshub.wbem.javax.wbem.CloseableIterator; +import org.metricshub.wbem.javax.wbem.client.EnumerateResponse; +import org.metricshub.wbem.javax.wbem.client.WBEMClient; +import org.metricshub.wbem.javax.wbem.client.WBEMClientConstants; +import org.metricshub.wbem.javax.wbem.client.WBEMClientFactory; +import org.mockito.ArgumentMatchers; +import org.mockito.MockedStatic; +import org.mockito.Mockito; + +class WbemClientTest { + + @Test + void testConnect() throws Exception { + final URL url = new URL("https://host:8080"); + final String username = "user"; + final char[] password = { 'p', 'a', 's', 's' }; + int timeout = 60 * 1000; + + Assertions.assertThrows( + IllegalArgumentException.class, + () -> new WbemClient().connect(null, username, password, timeout) + ); + Assertions.assertThrows( + IllegalArgumentException.class, + () -> new WbemClient().connect(url, null, password, timeout) + ); + Assertions.assertThrows( + IllegalArgumentException.class, + () -> new WbemClient().connect(url, username, null, timeout) + ); + + try ( + final MockedStatic mockedWBEMClientFactory = Mockito.mockStatic(WBEMClientFactory.class); + final WbemClient wbemClient = new WbemClient() + ) { + final WBEMClient client = Mockito.mock(WBEMClient.class); + + mockedWBEMClientFactory.when(() -> WBEMClientFactory.getClient("CIM-XML")).thenReturn(client); + Mockito.doNothing().when(client).setProperty(WBEMClientConstants.PROP_TIMEOUT, String.valueOf(timeout)); + Mockito + .doNothing() + .when(client) + .initialize( + ArgumentMatchers.any(CIMObjectPath.class), + ArgumentMatchers.any(Subject.class), + ArgumentMatchers.eq(new Locale[] { Locale.ENGLISH }) + ); + + wbemClient.connect(url, username, password, timeout); + } + } + + @SuppressWarnings("unchecked") + @Test + void testExecuteWql() throws Exception { + final String namespace = "root/emc"; + final WqlQuery queryHandler = WqlQuery.parseQuery("Select * from EMC_StorageSystem"); + + Assertions.assertThrows(IllegalArgumentException.class, () -> new WbemClient().executeWql(null, namespace, null)); + Assertions.assertThrows( + IllegalArgumentException.class, + () -> new WbemClient().executeWql(queryHandler, null, null) + ); + + Assertions.assertThrows( + IllegalStateException.class, + () -> new WbemClient().executeWql(queryHandler, namespace, null) + ); + + final URL url = new URL("https://host:8080"); + final String username = "user"; + final char[] password = { 'p', 'a', 's', 's' }; + int timeout = 60 * 1000; + final WBEMClient client = Mockito.mock(WBEMClient.class); + final CloseableIterator iterator = Mockito.mock(CloseableIterator.class); + final WbemQueryResult result = Mockito.mock(WbemQueryResult.class); + + try ( + final MockedStatic mockedWBEMClientFactory = Mockito.mockStatic(WBEMClientFactory.class); + final MockedStatic mockedMatsyaWbemClient = Mockito.mockStatic(WbemClient.class); + final WbemClient matsyaWbemClient = new WbemClient() + ) { + mockedWBEMClientFactory.when(() -> WBEMClientFactory.getClient("CIM-XML")).thenReturn(client); + + Mockito.doNothing().when(client).setProperty(WBEMClientConstants.PROP_TIMEOUT, String.valueOf(timeout)); + + Mockito + .doNothing() + .when(client) + .initialize( + ArgumentMatchers.any(CIMObjectPath.class), + ArgumentMatchers.any(Subject.class), + ArgumentMatchers.eq(new Locale[] { Locale.ENGLISH }) + ); + + Mockito + .doReturn(iterator) + .when(client) + .enumerateInstances( + ArgumentMatchers.any(CIMObjectPath.class), + ArgumentMatchers.eq(true), + ArgumentMatchers.eq(false), + ArgumentMatchers.eq(true), + ArgumentMatchers.eq(queryHandler.getPropertiesArray()) + ); + + mockedMatsyaWbemClient + .when( + () -> + WbemClient.enumerateInstances( + ArgumentMatchers.any(WqlQuery.class), + ArgumentMatchers.any(CloseableIterator.class), + ArgumentMatchers.isNull() + ) + ) + .thenReturn(result); + + matsyaWbemClient.connect(url, username, password, timeout); + + Assertions.assertEquals(result, matsyaWbemClient.executeWql(queryHandler, namespace, null)); + } + } + + @SuppressWarnings("unchecked") + @Test + void testGetAssociators() throws Exception { + final URL url = new URL("https://host:8080"); + final String username = "user"; + final char[] password = { 'p', 'a', 's', 's' }; + int timeout = 60 * 1000; + final WBEMClient client = Mockito.mock(WBEMClient.class); + final WqlQuery queryHandler = WqlQuery.parseQuery("Select * from EMC_StorageSystem"); + final EnumerateResponse response = Mockito.mock(EnumerateResponse.class); + final CloseableIterator iterator = Mockito.mock(CloseableIterator.class); + final WbemQueryResult result = Mockito.mock(WbemQueryResult.class); + + final String objectPathAssociators = "objectPathAssociators"; + Assertions.assertThrows( + IllegalArgumentException.class, + () -> new WbemClient().getAssociators(null, objectPathAssociators, null) + ); + Assertions.assertThrows( + IllegalArgumentException.class, + () -> new WbemClient().getAssociators(queryHandler, null, null) + ); + + Assertions.assertThrows( + IllegalStateException.class, + () -> new WbemClient().getAssociators(queryHandler, objectPathAssociators, null) + ); + + try ( + final MockedStatic mockedWBEMClientFactory = Mockito.mockStatic(WBEMClientFactory.class); + final MockedStatic mockedMatsyaWbemClient = Mockito.mockStatic(WbemClient.class); + final WbemClient matsyaWbemClient = new WbemClient() + ) { + mockedWBEMClientFactory.when(() -> WBEMClientFactory.getClient("CIM-XML")).thenReturn(client); + + Mockito.doNothing().when(client).setProperty(WBEMClientConstants.PROP_TIMEOUT, String.valueOf(timeout)); + + Mockito + .doNothing() + .when(client) + .initialize( + ArgumentMatchers.any(CIMObjectPath.class), + ArgumentMatchers.any(Subject.class), + ArgumentMatchers.eq(new Locale[] { Locale.ENGLISH }) + ); + + Mockito + .doReturn(response) + .when(client) + .associators( + ArgumentMatchers.any(CIMObjectPath.class), + ArgumentMatchers.eq(queryHandler.getClassName()), + ArgumentMatchers.isNull(), + ArgumentMatchers.isNull(), + ArgumentMatchers.isNull(), + ArgumentMatchers.eq(false), + ArgumentMatchers.eq(queryHandler.getPropertiesArray()), + ArgumentMatchers.isNull(), + ArgumentMatchers.isNull(), + ArgumentMatchers.isNull(), + ArgumentMatchers.eq(false), + ArgumentMatchers.isNull() + ); + + Mockito.doReturn(iterator).when(response).getResponses(); + + mockedMatsyaWbemClient + .when( + () -> + WbemClient.enumerateInstances( + ArgumentMatchers.any(WqlQuery.class), + ArgumentMatchers.any(CloseableIterator.class), + ArgumentMatchers.isNull() + ) + ) + .thenReturn(result); + + matsyaWbemClient.connect(url, username, password, timeout); + + Assertions.assertEquals(result, matsyaWbemClient.getAssociators(queryHandler, objectPathAssociators, null)); + } + } +} diff --git a/src/test/java/org/sentrysoftware/wbem/WbemExecutorTest.java b/src/test/java/org/metricshub/wbem/WbemExecutorTest.java similarity index 64% rename from src/test/java/org/sentrysoftware/wbem/WbemExecutorTest.java rename to src/test/java/org/metricshub/wbem/WbemExecutorTest.java index a7beb0b..0536132 100644 --- a/src/test/java/org/sentrysoftware/wbem/WbemExecutorTest.java +++ b/src/test/java/org/metricshub/wbem/WbemExecutorTest.java @@ -1,82 +1,99 @@ -package org.sentrysoftware.wbem; - -import java.net.URL; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.mockito.ArgumentMatchers; -import org.mockito.MockedStatic; -import org.mockito.Mockito; -import org.sentrysoftware.wbem.client.WbemExecutor; -import org.sentrysoftware.wbem.client.WbemQueryResult; -import org.sentrysoftware.wbem.javax.wbem.WBEMException; - -class WbemExecutorTest { - - @SuppressWarnings("unchecked") - @Test - void testExecuteWql() throws Exception { - final URL url = new URL("https://host:8080"); - final String username = "user"; - final char[] password = {'p', 'a', 's', 's'}; - int timeout = 60*1000; - final String namespace = "root/emc"; - final String query = "Select * from EMC_StorageSystem"; - - Assertions.assertThrows(IllegalArgumentException.class, () -> WbemExecutor.executeWql(null, namespace, username, password, query, timeout, null)); - Assertions.assertThrows(IllegalArgumentException.class, () -> WbemExecutor.executeWql(url, namespace, null, password, query, timeout, null)); - Assertions.assertThrows(IllegalArgumentException.class, () -> WbemExecutor.executeWql(url, namespace, username, null, query, timeout, null)); - Assertions.assertThrows(IllegalArgumentException.class, () -> WbemExecutor.executeWql(url, namespace, username, password, null, timeout, null)); - Assertions.assertThrows(TimeoutException.class, () -> WbemExecutor.executeWql(url, namespace, username, password, query, 0, null)); - - final WbemQueryResult result = Mockito.mock(WbemQueryResult.class); - final Future handler = Mockito.mock(Future.class); - final ExecutorService executor = Mockito.mock(ExecutorService.class); - - try (final MockedStatic mockedExecutorService = Mockito.mockStatic(Executors.class)) { - final WBEMException wbemException = new WBEMException("msg"); - final ExecutionException executionException = new ExecutionException(wbemException); - - mockedExecutorService.when(Executors::newSingleThreadExecutor).thenReturn(executor); - - Mockito.doReturn(handler).when(executor).submit(ArgumentMatchers.any(Callable.class)); - Mockito.doThrow(executionException).when(handler).get(timeout, TimeUnit.MILLISECONDS); - - Assertions.assertThrows( - WBEMException.class, - () -> WbemExecutor.executeWql(url, namespace, username, password, query, timeout, null)); - } - - try (final MockedStatic mockedExecutorService = Mockito.mockStatic(Executors.class)) { - final IllegalArgumentException illegalArgumentException = new IllegalArgumentException("msg"); - final ExecutionException executionException = new ExecutionException(illegalArgumentException); - - mockedExecutorService.when(Executors::newSingleThreadExecutor).thenReturn(executor); - - Mockito.doReturn(handler).when(executor).submit(ArgumentMatchers.any(Callable.class)); - Mockito.doThrow(executionException).when(handler).get(timeout, TimeUnit.MILLISECONDS); - - Assertions.assertThrows( - RuntimeException.class, - () -> WbemExecutor.executeWql(url, namespace, username, password, query, timeout, null)); - } - - try (final MockedStatic mockedExecutorService = Mockito.mockStatic(Executors.class)) { - mockedExecutorService.when(Executors::newSingleThreadExecutor).thenReturn(executor); - - Mockito.doReturn(handler).when(executor).submit(ArgumentMatchers.any(Callable.class)); - Mockito.doReturn(result).when(handler).get(timeout, TimeUnit.MILLISECONDS); - - Assertions.assertEquals( - result, - WbemExecutor.executeWql(url, namespace, username, password, query, timeout, null)); - } - } -} +package org.metricshub.wbem; + +import java.net.URL; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.metricshub.wbem.client.WbemExecutor; +import org.metricshub.wbem.client.WbemQueryResult; +import org.metricshub.wbem.javax.wbem.WBEMException; +import org.mockito.ArgumentMatchers; +import org.mockito.MockedStatic; +import org.mockito.Mockito; + +class WbemExecutorTest { + + @SuppressWarnings("unchecked") + @Test + void testExecuteWql() throws Exception { + final URL url = new URL("https://host:8080"); + final String username = "user"; + final char[] password = { 'p', 'a', 's', 's' }; + int timeout = 60 * 1000; + final String namespace = "root/emc"; + final String query = "Select * from EMC_StorageSystem"; + + Assertions.assertThrows( + IllegalArgumentException.class, + () -> WbemExecutor.executeWql(null, namespace, username, password, query, timeout, null) + ); + Assertions.assertThrows( + IllegalArgumentException.class, + () -> WbemExecutor.executeWql(url, namespace, null, password, query, timeout, null) + ); + Assertions.assertThrows( + IllegalArgumentException.class, + () -> WbemExecutor.executeWql(url, namespace, username, null, query, timeout, null) + ); + Assertions.assertThrows( + IllegalArgumentException.class, + () -> WbemExecutor.executeWql(url, namespace, username, password, null, timeout, null) + ); + Assertions.assertThrows( + TimeoutException.class, + () -> WbemExecutor.executeWql(url, namespace, username, password, query, 0, null) + ); + + final WbemQueryResult result = Mockito.mock(WbemQueryResult.class); + final Future handler = Mockito.mock(Future.class); + final ExecutorService executor = Mockito.mock(ExecutorService.class); + + try (final MockedStatic mockedExecutorService = Mockito.mockStatic(Executors.class)) { + final WBEMException wbemException = new WBEMException("msg"); + final ExecutionException executionException = new ExecutionException(wbemException); + + mockedExecutorService.when(Executors::newSingleThreadExecutor).thenReturn(executor); + + Mockito.doReturn(handler).when(executor).submit(ArgumentMatchers.any(Callable.class)); + Mockito.doThrow(executionException).when(handler).get(timeout, TimeUnit.MILLISECONDS); + + Assertions.assertThrows( + WBEMException.class, + () -> WbemExecutor.executeWql(url, namespace, username, password, query, timeout, null) + ); + } + + try (final MockedStatic mockedExecutorService = Mockito.mockStatic(Executors.class)) { + final IllegalArgumentException illegalArgumentException = new IllegalArgumentException("msg"); + final ExecutionException executionException = new ExecutionException(illegalArgumentException); + + mockedExecutorService.when(Executors::newSingleThreadExecutor).thenReturn(executor); + + Mockito.doReturn(handler).when(executor).submit(ArgumentMatchers.any(Callable.class)); + Mockito.doThrow(executionException).when(handler).get(timeout, TimeUnit.MILLISECONDS); + + Assertions.assertThrows( + RuntimeException.class, + () -> WbemExecutor.executeWql(url, namespace, username, password, query, timeout, null) + ); + } + + try (final MockedStatic mockedExecutorService = Mockito.mockStatic(Executors.class)) { + mockedExecutorService.when(Executors::newSingleThreadExecutor).thenReturn(executor); + + Mockito.doReturn(handler).when(executor).submit(ArgumentMatchers.any(Callable.class)); + Mockito.doReturn(result).when(handler).get(timeout, TimeUnit.MILLISECONDS); + + Assertions.assertEquals( + result, + WbemExecutor.executeWql(url, namespace, username, password, query, timeout, null) + ); + } + } +} diff --git a/src/test/java/org/sentrysoftware/wbem/WqlQueryTest.java b/src/test/java/org/metricshub/wbem/WqlQueryTest.java similarity index 85% rename from src/test/java/org/sentrysoftware/wbem/WqlQueryTest.java rename to src/test/java/org/metricshub/wbem/WqlQueryTest.java index acac015..566e2c6 100644 --- a/src/test/java/org/sentrysoftware/wbem/WqlQueryTest.java +++ b/src/test/java/org/metricshub/wbem/WqlQueryTest.java @@ -1,76 +1,81 @@ -package org.sentrysoftware.wbem; - -import java.util.Arrays; -import java.util.LinkedHashSet; -import java.util.stream.Collectors; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.sentrysoftware.wbem.client.WqlQuery; -import org.sentrysoftware.wbem.client.exceptions.WqlQuerySyntaxException; - -class WqlQueryTest { - - @Test - void testQueryCommon() { - Assertions.assertThrows(IllegalArgumentException.class, () -> WqlQuery.parseQuery(null)); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Sel")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Up")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Upate T set a=x, b=y")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Upate T set a=x, b=y where c=z")); - } - - @Test - void testSelect() throws Exception { - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Sel a,b From T")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Update a,b From T")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select *,a,b From T")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select *,* From T")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select * * From T")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select a,b ")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select From ")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select From T")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery(" a,b From T")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select a,b From ")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select Select a,b From T")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select a,b From From T")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select ,a,b From T")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select a, ,b From T")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select a,b, From T")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select a b From T")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select a;b From T")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select a,b From T U")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select a,b T ")); - Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("From a,b Select T")); - - { - final WqlQuery wqlQuery = WqlQuery.parseQuery("SELECT * FROM HITACHI_FCPort"); - - Assertions.assertEquals("HITACHI_FCPort", wqlQuery.getClassName()); - Assertions.assertNull(wqlQuery.getPropertiesArray()); - Assertions.assertTrue(wqlQuery.getProperties().isEmpty()); - Assertions.assertTrue(wqlQuery.getOriginalProperties().isEmpty()); - Assertions.assertFalse(wqlQuery.hasDuplicateProperties()); - } - { - final WqlQuery wqlQuery = WqlQuery.parseQuery(" select Antecedent, Dependent from IBMTSDS_SHWIDToSPC"); - - Assertions.assertEquals("IBMTSDS_SHWIDToSPC", wqlQuery.getClassName()); - Assertions.assertArrayEquals(new String[] {"Antecedent", "Dependent"}, wqlQuery.getPropertiesArray()); - Assertions.assertEquals(Arrays.asList("Antecedent", "Dependent").stream().collect(Collectors.toCollection(LinkedHashSet::new)), wqlQuery.getProperties()); - Assertions.assertEquals(Arrays.asList("Antecedent", "Dependent"), wqlQuery.getOriginalProperties()); - Assertions.assertFalse(wqlQuery.hasDuplicateProperties()); - } - { - final WqlQuery wqlQuery = WqlQuery.parseQuery(" SELECT __Path, Name, __PATH from EMC_StorageSystem "); - - Assertions.assertEquals("EMC_StorageSystem", wqlQuery.getClassName()); - Assertions.assertArrayEquals(new String[] {"Name"}, wqlQuery.getPropertiesArray()); - Assertions.assertEquals(Arrays.asList("__Path", "Name").stream().collect(Collectors.toCollection(LinkedHashSet::new)), wqlQuery.getProperties()); - Assertions.assertEquals(Arrays.asList("__Path", "Name", "__PATH"), wqlQuery.getOriginalProperties()); - Assertions.assertTrue(wqlQuery.hasDuplicateProperties()); - } - } -} +package org.metricshub.wbem; + +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.stream.Collectors; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.metricshub.wbem.client.WqlQuery; +import org.metricshub.wbem.client.exceptions.WqlQuerySyntaxException; + +class WqlQueryTest { + + @Test + void testQueryCommon() { + Assertions.assertThrows(IllegalArgumentException.class, () -> WqlQuery.parseQuery(null)); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Sel")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Up")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Upate T set a=x, b=y")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Upate T set a=x, b=y where c=z")); + } + + @Test + void testSelect() throws Exception { + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Sel a,b From T")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Update a,b From T")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select *,a,b From T")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select *,* From T")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select * * From T")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select a,b ")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select From ")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select From T")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery(" a,b From T")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select a,b From ")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select Select a,b From T")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select a,b From From T")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select ,a,b From T")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select a, ,b From T")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select a,b, From T")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select a b From T")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select a;b From T")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select a,b From T U")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("Select a,b T ")); + Assertions.assertThrows(WqlQuerySyntaxException.class, () -> WqlQuery.parseQuery("From a,b Select T")); + + { + final WqlQuery wqlQuery = WqlQuery.parseQuery("SELECT * FROM HITACHI_FCPort"); + + Assertions.assertEquals("HITACHI_FCPort", wqlQuery.getClassName()); + Assertions.assertNull(wqlQuery.getPropertiesArray()); + Assertions.assertTrue(wqlQuery.getProperties().isEmpty()); + Assertions.assertTrue(wqlQuery.getOriginalProperties().isEmpty()); + Assertions.assertFalse(wqlQuery.hasDuplicateProperties()); + } + { + final WqlQuery wqlQuery = WqlQuery.parseQuery(" select Antecedent, Dependent from IBMTSDS_SHWIDToSPC"); + + Assertions.assertEquals("IBMTSDS_SHWIDToSPC", wqlQuery.getClassName()); + Assertions.assertArrayEquals(new String[] { "Antecedent", "Dependent" }, wqlQuery.getPropertiesArray()); + Assertions.assertEquals( + Arrays.asList("Antecedent", "Dependent").stream().collect(Collectors.toCollection(LinkedHashSet::new)), + wqlQuery.getProperties() + ); + Assertions.assertEquals(Arrays.asList("Antecedent", "Dependent"), wqlQuery.getOriginalProperties()); + Assertions.assertFalse(wqlQuery.hasDuplicateProperties()); + } + { + final WqlQuery wqlQuery = WqlQuery.parseQuery(" SELECT __Path, Name, __PATH from EMC_StorageSystem "); + + Assertions.assertEquals("EMC_StorageSystem", wqlQuery.getClassName()); + Assertions.assertArrayEquals(new String[] { "Name" }, wqlQuery.getPropertiesArray()); + Assertions.assertEquals( + Arrays.asList("__Path", "Name").stream().collect(Collectors.toCollection(LinkedHashSet::new)), + wqlQuery.getProperties() + ); + Assertions.assertEquals(Arrays.asList("__Path", "Name", "__PATH"), wqlQuery.getOriginalProperties()); + Assertions.assertTrue(wqlQuery.hasDuplicateProperties()); + } + } +} diff --git a/src/test/java/org/sentrysoftware/wbem/WbemCimDataHandlerTest.java b/src/test/java/org/sentrysoftware/wbem/WbemCimDataHandlerTest.java deleted file mode 100644 index 8a9be5f..0000000 --- a/src/test/java/org/sentrysoftware/wbem/WbemCimDataHandlerTest.java +++ /dev/null @@ -1,158 +0,0 @@ -package org.sentrysoftware.wbem; - -import java.math.BigInteger; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import org.sentrysoftware.wbem.javax.cim.CIMClass; -import org.sentrysoftware.wbem.javax.cim.CIMClassProperty; -import org.sentrysoftware.wbem.javax.cim.CIMDataType; -import org.sentrysoftware.wbem.javax.cim.CIMDateTime; -import org.sentrysoftware.wbem.javax.cim.CIMDateTimeAbsolute; -import org.sentrysoftware.wbem.javax.cim.CIMDateTimeInterval; -import org.sentrysoftware.wbem.javax.cim.CIMInstance; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import org.sentrysoftware.wbem.javax.cim.CIMProperty; -import org.sentrysoftware.wbem.client.WbemCimDataHandler; - -class WbemCimDataHandlerTest { - - @Test - void testGetCimPropertyAsString() { - - final CIMObjectPath objectPath = new CIMObjectPath("root/emc:Symm_StorageSystem.CreationClassName=\"Symm_StorageSystem\",Name=\"SYMMETRIX-+-000297800620\""); - - Assertions.assertThrows(IllegalArgumentException.class, () -> WbemCimDataHandler.getCimPropertyAsString(null, new CIMInstance(objectPath, new CIMProperty[] {new CIMProperty("Name", CIMDataType.STRING_T, "SYMMETRIX-+-000297800620")}), null)); - Assertions.assertThrows(IllegalArgumentException.class, () -> WbemCimDataHandler.getCimPropertyAsString("Name", null, null)); - - Assertions.assertThrows(IllegalArgumentException.class, () -> WbemCimDataHandler.getCimPropertyAsString("__Path", new CIMInstance(null, new CIMProperty[] {new CIMProperty("Name", CIMDataType.STRING_T, "SYMMETRIX-+-000297800620")}), null)); - Assertions.assertThrows(IllegalArgumentException.class, () -> WbemCimDataHandler.getCimPropertyAsString("Ref", new CIMInstance(objectPath, new CIMProperty[] {new CIMProperty("Ref", new CIMDataType("Ref", 1), "x")}), null)); - - Assertions.assertEquals( - "Symm_StorageSystem.CreationClassName=\"Symm_StorageSystem\",Name=\"SYMMETRIX-+-000297800620\"", - WbemCimDataHandler.getCimPropertyAsString("__PATH", new CIMInstance(objectPath, null), null)); - - Assertions.assertEquals( - "", - WbemCimDataHandler.getCimPropertyAsString( - "UnknownProperty", - new CIMInstance(objectPath, new CIMProperty[] {new CIMProperty("Name", CIMDataType.STRING_T, "\"SYMMETRIX-+-000297800620;\"")}), null)); - - Assertions.assertEquals( - "blablaVal", - WbemCimDataHandler.getCimPropertyAsString( - "blabla", - new CIMInstance(objectPath, new CIMProperty[] {new CIMProperty("Name", CIMDataType.STRING_T, "\"SYMMETRIX-+-000297800620;\""), new CIMProperty("blabla", CIMDataType.STRING_T, "blablaVal", true, false, null)}), null)); - - Assertions.assertEquals( - "", - WbemCimDataHandler.getCimPropertyAsString( - "Name", - new CIMInstance(objectPath, new CIMProperty[] {new CIMProperty("Name", CIMDataType.STRING_T, null)}), null)); - - Assertions.assertEquals( - "\"SYMMETRIX-+-000297800620;\"", - WbemCimDataHandler.getCimPropertyAsString( - "Name", - new CIMInstance(objectPath, new CIMProperty[] {new CIMProperty("Name", CIMDataType.STRING_T, "\"SYMMETRIX-+-000297800620;\"")}), null)); - - Assertions.assertEquals( - "true", - WbemCimDataHandler.getCimPropertyAsString( - "EMCAutoMetaEnabled", - new CIMInstance(objectPath, new CIMProperty[] {new CIMProperty("EMCAutoMetaEnabled", CIMDataType.BOOLEAN_T, Boolean.TRUE)}), null)); - - Assertions.assertEquals( - "true|false|", - WbemCimDataHandler.getCimPropertyAsString( - "EMCAutoMetaEnabledArray", - new CIMInstance(objectPath, new CIMProperty[] {new CIMProperty("EMCAutoMetaEnabledArray", CIMDataType.BOOLEAN_ARRAY_T, new Boolean[] {Boolean.TRUE, Boolean.FALSE})}), null)); - - Assertions.assertEquals( - "10", - WbemCimDataHandler.getCimPropertyAsString( - "PortType", - new CIMInstance(objectPath, new CIMProperty[] {new CIMProperty("PortType", CIMDataType.SINT32_T, Integer.valueOf(10))}), null)); - - Assertions.assertEquals( - "2125000000", - WbemCimDataHandler.getCimPropertyAsString( - "MaxSpeed", - new CIMInstance(objectPath, new CIMProperty[] {new CIMProperty("MaxSpeed", CIMDataType.UINT64_T, new BigInteger("2125000000"))}), null)); - - Assertions.assertEquals( - "1|2|", - WbemCimDataHandler.getCimPropertyAsString( - "OperationalStatus", - new CIMInstance(objectPath, new CIMProperty[] {new CIMProperty("OperationalStatus", CIMDataType.SINT16_ARRAY_T, new Short[] {1,2})}), null)); - - Assertions.assertEquals( - "Symm_StorageSystem.CreationClassName=\"Symm_StorageSystem\",Name=\"SYMMETRIX-+-000297800620\"", - WbemCimDataHandler.getCimPropertyAsString( - "Ref", - new CIMInstance(objectPath, new CIMProperty[] {new CIMProperty("Ref", new CIMDataType("Ref"), objectPath)}), null)); - - Assertions.assertEquals( - "Symm_StorageSystem.CreationClassName=\"Symm_StorageSystem\",Name=\"SYMMETRIX-+-000297800620\"" + - "|", - WbemCimDataHandler.getCimPropertyAsString( - "Ref", - new CIMInstance(objectPath, new CIMProperty[] {new CIMProperty("Ref", new CIMDataType("Ref", 1), new CIMObjectPath[] {objectPath})}), null)); - - Assertions.assertEquals( - "Symm_StorageSystem.CreationClassName=\"Symm_StorageSystem\",Name=\"SYMMETRIX-+-000297800620\"" + - "||"+ - "Symm_StorageSystem.CreationClassName=\"Symm_StorageSystem\",Name=\"SYMMETRIX-+-000297800620\"" + - "|", - WbemCimDataHandler.getCimPropertyAsString( - "Ref", - new CIMInstance(objectPath, new CIMProperty[] {new CIMProperty("Ref", new CIMDataType("Ref", 3), new CIMObjectPath[] {objectPath, null, objectPath})}), null)); - - Assertions.assertEquals( - "1173882243000", - WbemCimDataHandler.getCimPropertyAsString( - "timeAbsolute", - new CIMInstance(objectPath, new CIMProperty[] {new CIMProperty("timeAbsolute", CIMDataType.DATETIME_T, new CIMDateTimeAbsolute("20070314160503.566012+101"))}), null)); - - Assertions.assertEquals( - "1173882243566", - WbemCimDataHandler.getCimPropertyAsString( - "timeInterval", - new CIMInstance(objectPath, new CIMProperty[] {new CIMProperty("timeInterval", CIMDataType.DATETIME_T, new CIMDateTimeInterval(1173882243566L))}), null)); - - Assertions.assertEquals( - "1173882243000|1173882243566|", - WbemCimDataHandler.getCimPropertyAsString( - "timeArray", - new CIMInstance(objectPath, new CIMProperty[] {new CIMProperty("timeArray", CIMDataType.DATETIME_ARRAY_T, new CIMDateTime[] {new CIMDateTimeAbsolute("20070314160503.566012+101"), new CIMDateTimeInterval(1173882243566L)})}), null)); - - final CIMClass cimClass = new CIMClass( - "testClass", - null, - null, - new CIMClassProperty[] {new CIMClassProperty("KeyProp", CIMDataType.STRING_T, null, null, false, false, null)}, - null); - - Assertions.assertEquals( - "class testClass {" + - " string KeyProp;" + - "};", - WbemCimDataHandler.getCimPropertyAsString( - "propClass", - new CIMInstance(objectPath, new CIMProperty[] {new CIMProperty("propClass", CIMDataType.CLASS_T, cimClass)}), null).replaceAll("[\r\n]", "")); - - Assertions.assertEquals( - "class testClass {" + - " string KeyProp;" + - "};" + - "$$" + - "class testClass {" + - " string KeyProp;" + - "};" + - "$", - WbemCimDataHandler.getCimPropertyAsString( - "propClass", - new CIMInstance(objectPath, new CIMProperty[] {new CIMProperty("propClass", CIMDataType.CLASS_ARRAY_T, new CIMClass[] {cimClass, null, cimClass})}), "$").replaceAll("[\r\n]", "")); - } -} diff --git a/src/test/java/org/sentrysoftware/wbem/WbemClientTest.java b/src/test/java/org/sentrysoftware/wbem/WbemClientTest.java deleted file mode 100644 index 7e24bb7..0000000 --- a/src/test/java/org/sentrysoftware/wbem/WbemClientTest.java +++ /dev/null @@ -1,163 +0,0 @@ -package org.sentrysoftware.wbem; - -import java.net.URL; -import java.util.Locale; - -import javax.security.auth.Subject; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.mockito.ArgumentMatchers; -import org.mockito.MockedStatic; -import org.mockito.Mockito; -import org.sentrysoftware.wbem.client.WbemClient; -import org.sentrysoftware.wbem.client.WbemQueryResult; -import org.sentrysoftware.wbem.client.WqlQuery; -import org.sentrysoftware.wbem.javax.cim.CIMInstance; -import org.sentrysoftware.wbem.javax.cim.CIMObjectPath; -import org.sentrysoftware.wbem.javax.wbem.CloseableIterator; -import org.sentrysoftware.wbem.javax.wbem.client.EnumerateResponse; -import org.sentrysoftware.wbem.javax.wbem.client.WBEMClient; -import org.sentrysoftware.wbem.javax.wbem.client.WBEMClientConstants; -import org.sentrysoftware.wbem.javax.wbem.client.WBEMClientFactory; - -class WbemClientTest { - - @Test - void testConnect() throws Exception { - final URL url = new URL("https://host:8080"); - final String username = "user"; - final char[] password = {'p', 'a', 's', 's'}; - int timeout = 60*1000; - - Assertions.assertThrows(IllegalArgumentException.class, () -> new WbemClient().connect(null, username, password, timeout)); - Assertions.assertThrows(IllegalArgumentException.class, () -> new WbemClient().connect(url, null, password, timeout)); - Assertions.assertThrows(IllegalArgumentException.class, () -> new WbemClient().connect(url, username, null, timeout)); - - try (final MockedStatic mockedWBEMClientFactory = Mockito.mockStatic(WBEMClientFactory.class); - final WbemClient wbemClient = new WbemClient()) { - final WBEMClient client = Mockito.mock(WBEMClient.class); - - mockedWBEMClientFactory.when(() -> WBEMClientFactory.getClient("CIM-XML")).thenReturn(client); - Mockito.doNothing().when(client).setProperty(WBEMClientConstants.PROP_TIMEOUT, String.valueOf(timeout)); - Mockito.doNothing().when(client).initialize( - ArgumentMatchers.any(CIMObjectPath.class), - ArgumentMatchers.any(Subject.class), - ArgumentMatchers.eq(new Locale[] {Locale.ENGLISH})); - - wbemClient.connect(url, username, password, timeout); - } - } - - @SuppressWarnings("unchecked") - @Test - void testExecuteWql() throws Exception { - final String namespace = "root/emc"; - final WqlQuery queryHandler = WqlQuery.parseQuery("Select * from EMC_StorageSystem"); - - Assertions.assertThrows(IllegalArgumentException.class, () -> new WbemClient().executeWql(null, namespace, null)); - Assertions.assertThrows(IllegalArgumentException.class, () -> new WbemClient().executeWql(queryHandler, null, null)); - - Assertions.assertThrows(IllegalStateException.class, () -> new WbemClient().executeWql(queryHandler, namespace, null)); - - final URL url = new URL("https://host:8080"); - final String username = "user"; - final char[] password = {'p', 'a', 's', 's'}; - int timeout = 60*1000; - final WBEMClient client = Mockito.mock(WBEMClient.class); - final CloseableIterator iterator = Mockito.mock(CloseableIterator.class); - final WbemQueryResult result = Mockito.mock(WbemQueryResult.class); - - try (final MockedStatic mockedWBEMClientFactory = Mockito.mockStatic(WBEMClientFactory.class); - final MockedStatic mockedMatsyaWbemClient = Mockito.mockStatic(WbemClient.class); - final WbemClient matsyaWbemClient =new WbemClient()) { - - mockedWBEMClientFactory.when(() -> WBEMClientFactory.getClient("CIM-XML")).thenReturn(client); - - Mockito.doNothing().when(client).setProperty(WBEMClientConstants.PROP_TIMEOUT, String.valueOf(timeout)); - - Mockito.doNothing().when(client).initialize( - ArgumentMatchers.any(CIMObjectPath.class), - ArgumentMatchers.any(Subject.class), - ArgumentMatchers.eq(new Locale[] {Locale.ENGLISH})); - - Mockito.doReturn(iterator).when(client).enumerateInstances( - ArgumentMatchers.any(CIMObjectPath.class), - ArgumentMatchers.eq(true), - ArgumentMatchers.eq(false), - ArgumentMatchers.eq(true), - ArgumentMatchers.eq(queryHandler.getPropertiesArray())); - - mockedMatsyaWbemClient.when(() -> WbemClient.enumerateInstances( - ArgumentMatchers.any(WqlQuery.class), - ArgumentMatchers.any(CloseableIterator.class), - ArgumentMatchers.isNull())) - .thenReturn(result); - - matsyaWbemClient.connect(url, username, password, timeout); - - Assertions.assertEquals(result, matsyaWbemClient.executeWql(queryHandler, namespace, null)); - } - } - - @SuppressWarnings("unchecked") - @Test - void testGetAssociators() throws Exception { - final URL url = new URL("https://host:8080"); - final String username = "user"; - final char[] password = {'p', 'a', 's', 's'}; - int timeout = 60*1000; - final WBEMClient client = Mockito.mock(WBEMClient.class); - final WqlQuery queryHandler = WqlQuery.parseQuery("Select * from EMC_StorageSystem"); - final EnumerateResponse response = Mockito.mock(EnumerateResponse.class); - final CloseableIterator iterator = Mockito.mock(CloseableIterator.class); - final WbemQueryResult result = Mockito.mock(WbemQueryResult.class); - - final String objectPathAssociators = "objectPathAssociators"; - Assertions.assertThrows(IllegalArgumentException.class, () -> new WbemClient().getAssociators(null, objectPathAssociators, null)); - Assertions.assertThrows(IllegalArgumentException.class, () -> new WbemClient().getAssociators(queryHandler, null, null)); - - Assertions.assertThrows(IllegalStateException.class, () -> new WbemClient().getAssociators(queryHandler, objectPathAssociators, null)); - - try (final MockedStatic mockedWBEMClientFactory = Mockito.mockStatic(WBEMClientFactory.class); - final MockedStatic mockedMatsyaWbemClient = Mockito.mockStatic(WbemClient.class); - final WbemClient matsyaWbemClient = new WbemClient()) { - - mockedWBEMClientFactory.when(() -> WBEMClientFactory.getClient("CIM-XML")).thenReturn(client); - - Mockito.doNothing().when(client).setProperty(WBEMClientConstants.PROP_TIMEOUT, String.valueOf(timeout)); - - Mockito.doNothing().when(client).initialize( - ArgumentMatchers.any(CIMObjectPath.class), - ArgumentMatchers.any(Subject.class), - ArgumentMatchers.eq(new Locale[] {Locale.ENGLISH})); - - Mockito.doReturn(response).when(client).associators( - ArgumentMatchers.any(CIMObjectPath.class), - ArgumentMatchers.eq(queryHandler.getClassName()), - ArgumentMatchers.isNull(), - ArgumentMatchers.isNull(), - ArgumentMatchers.isNull(), - ArgumentMatchers.eq(false), - ArgumentMatchers.eq(queryHandler.getPropertiesArray()), - ArgumentMatchers.isNull(), - ArgumentMatchers.isNull(), - ArgumentMatchers.isNull(), - ArgumentMatchers.eq(false), - ArgumentMatchers.isNull()); - - Mockito.doReturn(iterator).when(response).getResponses(); - - mockedMatsyaWbemClient.when(() -> WbemClient.enumerateInstances( - ArgumentMatchers.any(WqlQuery.class), - ArgumentMatchers.any(CloseableIterator.class), - ArgumentMatchers.isNull())) - .thenReturn(result); - - matsyaWbemClient.connect(url, username, password, timeout); - - Assertions.assertEquals(result, matsyaWbemClient.getAssociators(queryHandler, objectPathAssociators, null)); - } - } - -}