Skip to content

Commit

Permalink
WELD-364 Modify the algorithm to find the business interface
Browse files Browse the repository at this point in the history
- still it will likely not work if there is a session bean with more
than one view extending/implementing the declaringClass
  • Loading branch information
mkouba authored and jharting committed Jan 28, 2014
1 parent 89d3441 commit c068d0d
Show file tree
Hide file tree
Showing 14 changed files with 238 additions and 10 deletions.
Expand Up @@ -28,6 +28,7 @@
import org.jboss.weld.logging.BeanLogger;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.serialization.spi.BeanIdentifier;
import org.jboss.weld.util.reflection.HierarchyDiscovery;
import org.jboss.weld.util.reflection.Reflections;

/**
Expand Down Expand Up @@ -135,12 +136,10 @@ private Class<?> findBusinessInterface(Class<?> declaringClass, Set<Class<?>> bu
if (businessInterfacesClasses.contains(declaringClass)) {
return declaringClass;
}
// TODO we can certainly optimize this search algorithm!
for (Class<?> view : businessInterfacesClasses) {
for (Class<?> currentClass = view; currentClass != Object.class && currentClass != null; currentClass = currentClass.getSuperclass()) {
if (currentClass.equals(view)) {
return view;
}
// This will likely not work if there is a session bean with more than one view extending/implementing the declaringClass
for (Class<?> businessInterface : businessInterfacesClasses) {
if (new HierarchyDiscovery(businessInterface).getTypeMap().containsKey(declaringClass)) {
return businessInterface;
}
}
return null;
Expand Down
Expand Up @@ -34,4 +34,10 @@ public void observeGiraffe(@Observes Giraffe giraffe) {
observations.incrementAndGet();
}

@Override
public void observeSuperGiraffe(@Observes Giraffe giraffe) {
assertNotNull(giraffe);
observations.incrementAndGet();
}

}
Expand Up @@ -19,7 +19,7 @@
import javax.ejb.Local;

@Local
public interface FooLocal {
public interface FooLocal extends FooSuperLocal {

public void observeGiraffe(Giraffe giraffe);

Expand Down
@@ -0,0 +1,26 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT 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.jboss.weld.tests.observers.ejb.local;

import javax.ejb.Local;

@Local
public interface FooSuperLocal {

public void observeSuperGiraffe(Giraffe giraffe);

}
Expand Up @@ -43,7 +43,7 @@ public static JavaArchive createTestArchive() {
public void testRemoteEjbObserverNotified(BeanManager beanManager) {
FooBean.observations.set(0);
beanManager.fireEvent(new Giraffe());
assertEquals(1, FooBean.observations.get());
assertEquals(2, FooBean.observations.get());
}

}
@@ -0,0 +1,43 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2014, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT 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.jboss.weld.tests.observers.ejb.localremote;

import static org.junit.Assert.assertNotNull;

import java.util.concurrent.atomic.AtomicInteger;

import javax.ejb.Stateless;
import javax.enterprise.event.Observes;

@Stateless
public class FooBean implements FooRemote, FooLocal {

public static AtomicInteger observations = new AtomicInteger(0);

@Override
public void observeGiraffe(@Observes Giraffe giraffe) {
assertNotNull(giraffe);
observations.incrementAndGet();
}

@Override
public void observeGiraffeLocal(@Observes Giraffe giraffe) {
assertNotNull(giraffe);
observations.incrementAndGet();
}

}
@@ -0,0 +1,26 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT 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.jboss.weld.tests.observers.ejb.localremote;

import javax.ejb.Local;

@Local
public interface FooLocal {

public void observeGiraffeLocal(Giraffe giraffe);

}
@@ -0,0 +1,26 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT 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.jboss.weld.tests.observers.ejb.localremote;

import javax.ejb.Remote;

@Remote
public interface FooRemote {

public void observeGiraffe(Giraffe giraffe);

}
@@ -0,0 +1,24 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT 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.jboss.weld.tests.observers.ejb.localremote;

import java.io.Serializable;

@SuppressWarnings("serial")
public class Giraffe implements Serializable {

}
@@ -0,0 +1,49 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2014, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT 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.jboss.weld.tests.observers.ejb.localremote;

import static org.junit.Assert.assertEquals;

import javax.enterprise.inject.spi.BeanManager;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.BeanArchive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.weld.tests.category.Integration;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

@Category(Integration.class)
@RunWith(Arquillian.class)
public class LocalRemoteEjbObserverTest {

@Deployment
public static JavaArchive createTestArchive() {
return ShrinkWrap.create(BeanArchive.class).addPackage(FooRemote.class.getPackage());
}

@Test
public void testLocalAndRemoteObserversNotified(BeanManager beanManager) {
FooBean.observations.set(0);
beanManager.fireEvent(new Giraffe());
assertEquals(2, FooBean.observations.get());
}

}
Expand Up @@ -34,4 +34,10 @@ public void observeGiraffe(@Observes Giraffe giraffe) {
observations.incrementAndGet();
}

@Override
public void observeSuperGiraffe(@Observes Giraffe giraffe) {
assertNotNull(giraffe);
observations.incrementAndGet();
}

}
Expand Up @@ -19,7 +19,7 @@
import javax.ejb.Remote;

@Remote
public interface FooRemote {
public interface FooRemote extends FooSuperRemote {

public void observeGiraffe(Giraffe giraffe);

Expand Down
@@ -0,0 +1,23 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT 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.jboss.weld.tests.observers.ejb.remote;

public interface FooSuperRemote {

public void observeSuperGiraffe(Giraffe giraffe);

}
Expand Up @@ -43,7 +43,7 @@ public static JavaArchive createTestArchive() {
public void testRemoteEjbObserverNotified(BeanManager beanManager) {
FooBean.observations.set(0);
beanManager.fireEvent(new Giraffe());
assertEquals(1, FooBean.observations.get());
assertEquals(2, FooBean.observations.get());
}

}

0 comments on commit c068d0d

Please sign in to comment.