Skip to content

Commit

Permalink
[PAXCDI-186] fixed regression for alternatives
Browse files Browse the repository at this point in the history
  • Loading branch information
hwellmann committed Jun 19, 2015
1 parent 2a74c92 commit 87f38d1
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 4 deletions.
@@ -0,0 +1,6 @@
package org.ops4j.pax.cdi.sample6;


public interface MessageSource extends MessageProducer {

}
@@ -0,0 +1,31 @@
/*
* Copyright 2015 Harald Wellmann.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT 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.ops4j.pax.cdi.sample6.impl;

import javax.enterprise.inject.Alternative;

import org.ops4j.pax.cdi.sample6.MessageSource;

@Alternative
public class AlternativeMessageSourceImpl implements MessageSource {

@Override
public String getMessage() {
return "Quod erat demonstrandum.";
}
}
Expand Up @@ -17,14 +17,20 @@
*/
package org.ops4j.pax.cdi.sample6.impl;

import javax.inject.Inject;

import org.ops4j.pax.cdi.api.OsgiServiceProvider;
import org.ops4j.pax.cdi.sample6.MessageProducer;
import org.ops4j.pax.cdi.sample6.MessageSource;

@OsgiServiceProvider
public class MessageProducerImpl implements MessageProducer {

@Inject
private MessageSource source;

@Override
public String getMessage() {
return "Quod erat demonstrandum.";
return source.getMessage();
}
}
@@ -0,0 +1,29 @@
/*
* Copyright 2015 Harald Wellmann.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT 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.ops4j.pax.cdi.sample6.impl;

import org.ops4j.pax.cdi.sample6.MessageSource;


public class MessageSourceImpl implements MessageSource {

@Override
public String getMessage() {
return "Tertium non datur.";
}
}
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd">
<alternatives>
<class>org.ops4j.pax.cdi.sample6.impl.AlternativeMessageSourceImpl</class>
</alternatives>
</beans>
Expand Up @@ -18,8 +18,10 @@
package org.ops4j.pax.cdi.spi.scan;

import java.net.URL;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.ops4j.pax.cdi.spi.BeanBundles;
Expand All @@ -45,8 +47,9 @@ public boolean accept(Bundle providerBundle, String className) {
return true;
case NONE:
return false;
default:
throw new IllegalArgumentException(descriptor.getBeanDiscoveryMode().toString());
}
return false;
}

public BeanDescriptor findDescriptor(Bundle providerBundle) {
Expand Down Expand Up @@ -85,4 +88,12 @@ private boolean isWebBundle(Bundle bundle) {
String contextPath = headers.get("Web-ContextPath");
return (contextPath != null);
}

public List<URL> getBeanDescriptors() {
List<URL> urls = new ArrayList<>();
for (BeanDescriptor descriptor : descriptorMap.values()) {
urls.add(descriptor.getUrl());
}
return urls;
}
}
Expand Up @@ -94,8 +94,8 @@ public Set<String> getBeanClasses() {
* @return unmodifiable set
*/
public Set<URL> getBeanDescriptors() {
// FIXME
return Collections.emptySet();
Set<URL> urls = new HashSet<>(filter.getBeanDescriptors());
return Collections.unmodifiableSet(urls);
}

/**
Expand Down

0 comments on commit 87f38d1

Please sign in to comment.