Package org.apache.felix.bundlerepository

Examples of org.apache.felix.bundlerepository.Capability


            while ((event = reader.nextTag()) == XmlPullParser.START_TAG)
            {
                String element = reader.getName();
                if (CAPABILITY.equals(element))
                {
                    Capability capability = parseCapability(reader, resource);
                    if (capability != null)
                        resource.addCapability(capability);
                }
                else if (REQUIREMENT.equals(element))
                {
View Full Code Here


     */
  private Capability result() {
        this.component   = null;
        this.reporter  = null;
       
        Capability result   = this.result.build();
        this.result      = null;
       
        return result;
  }
View Full Code Here

    StringBuilder result = new StringBuilder("<obr>\n");

    /*
     *  Add capability to represent maven inforamtion
     */
    Capability mavenCapability = CapabilityEncoder.builder(CST.MAVEN).
                    property(CST.GROUP_ID, buildRepository.getArtifact().getGroupId()).
                    property(CST.ARTIFACT_ID, buildRepository.getArtifact().getArtifactId()).
                    property(CST.VERSION, buildRepository.getArtifact().getVersion()).
                      build();

    result.append(manager.getHelper().writeCapability(mavenCapability)).append("\n");

 
    /*
     *  Add capabilities to represent component metadata
     */
    CapabilityEncoder encoder         = new CapabilityEncoder();
    Set<ComponentReference<?>> processed  = new HashSet<ComponentReference<?>>();
    Set<VersionedReference<?>> referenced      = new HashSet<VersionedReference<?>>();

    for (ComponentDeclaration component : buildRepository.getComponents()) {
     
      if (processed.contains(component.getReference())) {
        reporter.report(Severity.WARNING,"Component " + component.getName() + " already defined in this build, declaration ignored "+component);
        continue;
      }

      /*
       * ACR repository is used at runtime by OBR Manager resolver. It uses direct searches over the
       * properties of the component that ignore the property inheritance mechanisms of APAM.
       *
       * We need to simulate inheritance by copying properties from the ancestor declarations.
       *
       * NOTE notice that we create and modify an effective cloned declaration, we must be careful
       * not to modify the original declaration in the project repository
       *
       */
      ComponentDeclaration group     = context.getComponent(component.getGroupVersioned());
      ComponentDeclaration effective  = component.getEffectiveDeclaration(group);
     
     
      /*
       * Name property is not inherited directly, but renamed at each level
       */
      ComponentDeclaration level = component;
      while (level != null) {


        if (level instanceof SpecificationDeclaration) {
          effective.getProperties().put(CST.SPECNAME, level.getName());
        }

        if (level instanceof ImplementationDeclaration) {
          effective.getProperties().put(CST.IMPLNAME, level.getName());
        }

        if (level instanceof InstanceDeclaration) {
          effective.getProperties().put(CST.INSTNAME, level.getName());
        }
       
        level = context.getComponent(level.getGroupVersioned());
      }
     
      /*
       * For unvalued properties we add default values, this allows filter to be evaluated even if no value
       * is explicitly specified
       */
      for (PropertyDefinition property : effective.getPropertyDefinitions()) {
       
        String defaultValue = property.getDefaultValue();
        String value    = effective.getProperty(property.getName());
       
        if (value == null && defaultValue != null) {
          effective.getProperties().put(property.getName(),defaultValue);
        }
      }
     
      /*
       * Encode the effective declaration
       */
      Capability encodedCapability  = encoder.encode(effective,reporter);
      if (encodedCapability != null) {
        result.append(manager.getHelper().writeCapability(encodedCapability)).append("\n");
        processed.add(component.getReference());
       
        /*
 
View Full Code Here

        if (!m_addedRequirementSet.isEmpty() || !m_globalCapabilities.isEmpty())
        {
            ResourceImpl fake = new ResourceImpl();
            for (Iterator iter = m_globalCapabilities.iterator(); iter.hasNext();)
            {
                Capability cap = (Capability) iter.next();
                fake.addCapability(cap);
            }
            for (Iterator iter = m_addedRequirementSet.iterator(); iter.hasNext();)
            {
                Requirement req = (Requirement) iter.next();
View Full Code Here

public class FelixCapabilityAdapterTest {
  @Test
  public void testObjectClassAttribute() {
    String objectClass = "com.foo.Bar";
    Capability cap = EasyMock.createNiceMock(Capability.class);
    EasyMock.expect(cap.getName()).andReturn(Capability.SERVICE);
    Map<String, Object> props = new HashMap<String, Object>();
    props.put(ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE.toLowerCase(), objectClass);
    EasyMock.expect(cap.getPropertiesAsMap()).andReturn(props);
    EasyMock.replay(cap);
    FelixCapabilityAdapter adapter = new FelixCapabilityAdapter(cap, EasyMock.createNiceMock(org.osgi.resource.Resource.class));
    assertEquals("Wrong value for attribute " + ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE, objectClass, adapter.getAttributes().get(ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE));
  }
View Full Code Here

    assertEquals("Wrong value for attribute " + ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE, objectClass, adapter.getAttributes().get(ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE));
  }
 
  @Test
  public void testOsgiServiceNamespace() {
    Capability cap = EasyMock.createNiceMock(Capability.class);
    EasyMock.expect(cap.getName()).andReturn(Capability.SERVICE);
    EasyMock.replay(cap);
    FelixCapabilityAdapter adapter = new FelixCapabilityAdapter(cap, EasyMock.createNiceMock(org.osgi.resource.Resource.class));
    assertEquals("Wrong namespace", ServiceNamespace.SERVICE_NAMESPACE, adapter.getNamespace());
  }
View Full Code Here

  }
 
  @Test
  public void testOsgiWiringPackageAttribute() {
    String pkg = "com.foo.Bar";
    Capability cap = EasyMock.createNiceMock(Capability.class);
    EasyMock.expect(cap.getName()).andReturn(Capability.PACKAGE).anyTimes();
    Map<String, Object> props = new HashMap<String, Object>();
    props.put(Capability.PACKAGE, pkg);
    EasyMock.expect(cap.getPropertiesAsMap()).andReturn(props);
    EasyMock.replay(cap);
    FelixCapabilityAdapter adapter = new FelixCapabilityAdapter(cap, EasyMock.createNiceMock(org.osgi.resource.Resource.class));
    assertEquals("Wrong value for attribute " + PackageNamespace.PACKAGE_NAMESPACE, pkg, adapter.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
  }
View Full Code Here

    assertEquals("Wrong value for attribute " + PackageNamespace.PACKAGE_NAMESPACE, pkg, adapter.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
  }
 
  @Test
  public void testOsgiWiringPackageNamespace() {
    Capability cap = EasyMock.createNiceMock(Capability.class);
    EasyMock.expect(cap.getName()).andReturn(Capability.PACKAGE);
    EasyMock.replay(cap);
    FelixCapabilityAdapter adapter = new FelixCapabilityAdapter(cap, EasyMock.createNiceMock(org.osgi.resource.Resource.class));
    assertEquals("Wrong namespace", PackageNamespace.PACKAGE_NAMESPACE, adapter.getNamespace());
  }
View Full Code Here

    assertEquals("Wrong namespace", PackageNamespace.PACKAGE_NAMESPACE, adapter.getNamespace());
  }
 
  @Test
  public void testOsgiWiringBundleNamespace() {
    Capability cap = EasyMock.createNiceMock(Capability.class);
    EasyMock.expect(cap.getName()).andReturn(Capability.BUNDLE);
    EasyMock.replay(cap);
    FelixCapabilityAdapter adapter = new FelixCapabilityAdapter(cap, EasyMock.createNiceMock(org.osgi.resource.Resource.class));
    assertEquals("Wrong namespace", BundleNamespace.BUNDLE_NAMESPACE, adapter.getNamespace());
  }
View Full Code Here

  }
 
  @Test
  public void testOsgiWiringBundleAttribute() {
    String symbolicName = "derbyclient";
    Capability cap = EasyMock.createNiceMock(Capability.class);
    EasyMock.expect(cap.getName()).andReturn(Capability.BUNDLE).anyTimes();
    Map<String, Object> props = new HashMap<String, Object>();
    props.put(Resource.SYMBOLIC_NAME, symbolicName);
    EasyMock.expect(cap.getPropertiesAsMap()).andReturn(props);
    EasyMock.replay(cap);
    FelixCapabilityAdapter adapter = new FelixCapabilityAdapter(cap, EasyMock.createNiceMock(org.osgi.resource.Resource.class));
    assertEquals("Wrong value for attribute " + BundleNamespace.BUNDLE_NAMESPACE, symbolicName, adapter.getAttributes().get(BundleNamespace.BUNDLE_NAMESPACE));
  }
View Full Code Here

TOP

Related Classes of org.apache.felix.bundlerepository.Capability

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.