blob: 36450899fee69b7678b676509579c883e129ddb5 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT 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.apache.felix.ipojo.handlers.providedservice;
import java.util.Iterator;
import org.apache.felix.ipojo.architecture.HandlerDescription;
import org.apache.felix.ipojo.metadata.Attribute;
import org.apache.felix.ipojo.metadata.Element;
/**
* Provided Service Handler Description.
*
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ProvidedServiceHandlerDescription extends HandlerDescription {
/**
* Provided Service Description list.
*/
private ProvidedServiceDescription[] m_providedServices = new ProvidedServiceDescription[0];
/**
* Constructor.
*
* @param isValid : the validity of the provided service handler.
*/
public ProvidedServiceHandlerDescription(boolean isValid) {
super(ProvidedServiceHandler.class.getName(), isValid);
}
/**
* Get the provided service descriptions.
* @return the provided service description list.
*/
public ProvidedServiceDescription[] getProvidedServices() {
return m_providedServices;
}
/**
* Add a provided service.
*
* @param pds : the provided service to add
*/
public void addProvidedService(ProvidedServiceDescription pds) {
// Verify that the provided service description is not already in the
// array.
for (int i = 0; i < m_providedServices.length; i++) {
if (m_providedServices[i] == pds) {
return; // NOTHING DO DO, the description is already in the
// array
}
}
// The component Description is not in the array, add it
ProvidedServiceDescription[] newPSD = new ProvidedServiceDescription[m_providedServices.length + 1];
System.arraycopy(m_providedServices, 0, newPSD, 0, m_providedServices.length);
newPSD[m_providedServices.length] = pds;
m_providedServices = newPSD;
}
/**
* Build the provided service handler description.
* @return the handler description.
* @see org.apache.felix.ipojo.architecture.HandlerDescription#getHandlerInfo()
*/
public Element getHandlerInfo() {
Element services = super.getHandlerInfo();
for (int i = 0; i < m_providedServices.length; i++) {
Element service = new Element("service", "");
String state = "unregistered";
if (m_providedServices[i].getState() == ProvidedService.REGISTERED) {
state = "registered";
}
String spec = "[";
for (int j = 0; j < m_providedServices[i].getServiceSpecification().length; j++) {
if (j == 0) {
spec += m_providedServices[i].getServiceSpecification()[j];
} else {
spec += ", " + m_providedServices[i].getServiceSpecification()[j];
}
}
spec += "]";
service.addAttribute(new Attribute("specifications", spec));
service.addAttribute(new Attribute("state", state));
Iterator it = m_providedServices[i].getProperties().keySet().iterator();
while (it.hasNext()) {
Element prop = new Element("property", "");
String k = (String) it.next();
prop.addAttribute(new Attribute("name", k));
prop.addAttribute(new Attribute("value", m_providedServices[i].getProperties().getProperty(k).toString()));
service.addElement(prop);
}
services.addElement(service);
}
return services;
}
}