
org.amdatu.remote.EndpointDescriptorReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.amdatu.remote.discovery.bonjour Show documentation
Show all versions of org.amdatu.remote.discovery.bonjour Show documentation
Amdatu Remote - Discovery (Bonjour)
The newest version!
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.amdatu.remote;
import java.io.Reader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.xml.parsers.SAXParserFactory;
import org.osgi.service.remoteserviceadmin.EndpointDescription;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
/**
* Parses an XML representation according to {@code http://www.osgi.org/xmlns/rsa/v1.0.0/rsa.xsd}
*
* @author Amdatu Project Team
*/
public final class EndpointDescriptorReader {
private final static SAXParserFactory SAX_PARSERFACTORY = SAXParserFactory.newInstance();
public List parseDocument(Reader reader) {
EndpointDescriptorParserHandler handler = new EndpointDescriptorParserHandler();
InputSource source = null;
try {
source = new InputSource(reader);
SAX_PARSERFACTORY.newSAXParser().parse(source, handler);
return handler.getEndpointDescriptions();
}
catch (Exception e) {
throw new IllegalArgumentException(e);
}
}
static class EndpointDescriptorParserHandler extends DefaultHandler {
private final List m_endpointDesciptions = new ArrayList();
private final Map m_endpointProperties = new HashMap();
private final StringBuilder m_valueBuffer = new StringBuilder();
private boolean m_inProperty = false;
private boolean m_inArray = false;
private boolean m_inList = false;
private boolean m_inSet = false;
private boolean m_inXml = false;
private boolean m_inValue = false;
private String m_propertyName;
private String m_propertyValue;
private ValueTypes m_propertyType;
private final List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy