index
int64
0
0
repo_id
stringlengths
9
205
file_path
stringlengths
31
246
content
stringlengths
1
12.2M
__index_level_0__
int64
0
10k
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/referencelistener/ReferenceListenerToProduce.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.test.referencelistener; import org.apache.aries.blueprint.annotation.referencelistener.Bind; import org.apache.aries.blueprint.annotation.referencelistener.Unbind; import org.apache.aries.blueprint.plugin.test.interfaces.ServiceB; public class ReferenceListenerToProduce { @Bind public void register(ServiceB serviceB) { } @Unbind public void unregister(ServiceB serviceB) { } public void addMe(ServiceB serviceB) { } public void removeMe(ServiceB serviceB) { } }
9,300
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/transactionenable/TxBean.java
/** * 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.aries.blueprint.plugin.test.transactionenable; import javax.inject.Singleton; import javax.transaction.Transactional; @Singleton @Transactional public class TxBean { public void txTest() { } }
9,301
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/service/Service2.java
/** * 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.aries.blueprint.plugin.test.service; public interface Service2 { }
9,302
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/service/ServiceProducer.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.test.service; import org.apache.aries.blueprint.annotation.bean.Bean; import org.apache.aries.blueprint.annotation.service.AutoExport; import org.apache.aries.blueprint.annotation.service.Service; import org.apache.aries.blueprint.annotation.service.ServiceProperty; import javax.inject.Singleton; @Singleton public class ServiceProducer implements Service1, Service2 { @Service @Bean(id = "producedSimplestService") public Service1 simplestServiceProduced() { return null; } @Service(ranking = 200) @Bean(id = "producedServiceWithRanking") public Service1 serviceWithRanking() { return null; } @Service(autoExport = AutoExport.ALL_CLASSES) @Bean(id = "producedServiceWithAllClasses") public Service1 serviceWithAllClasses() { return null; } @Service(autoExport = AutoExport.CLASS_HIERARCHY) @Bean(id = "producedServiceWithClassHierarchy") public Service1 serviceWithClassHierarchy() { return null; } @Service(classes = {Service1.class, Service2.class}) @Bean(id = "producedServiceWithManyInterfaces") public Service1 serviceWithManyInterfaces() { return null; } @Service(classes = Service2.class) @Bean(id = "producedServiceWithOneInterface") public Service2 serviceWithOneInterface() { return null; } @Service(ranking = -9, properties = { @ServiceProperty(name = "service.ranking", values = "-2"), @ServiceProperty(name = "a", values = "1") }) @Bean(id = "producedServiceWithRankingAndProperies") public Service2 serviceWithRankingAndProperties() { return null; } @Service(properties = { @ServiceProperty(name = "oneValue", values = "test"), @ServiceProperty(name = "intValue", values = "1", type = Integer.class), @ServiceProperty(name = "longArray", values = {"1", "2", "3"}, type = Long.class), @ServiceProperty(name = "emptyArray", values = {}), @ServiceProperty(name = "stringArray", values = {"a", "b"}), @ServiceProperty(name = "service.ranking", values = "5", type = Integer.class), }) @Bean(id = "producedServiceWithProperies") public Service2 serviceWithProperties() { return null; } }
9,303
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/service/ServiceWithRankingAndProperty.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.test.service; import org.apache.aries.blueprint.annotation.service.Service; import org.apache.aries.blueprint.annotation.service.ServiceProperty; import javax.inject.Singleton; @Service(ranking = 2, properties = @ServiceProperty(name = "service.ranking", values = "3")) @Singleton public class ServiceWithRankingAndProperty implements Service1, Service2 { }
9,304
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/service/ServiceWithManyInterfaces.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.test.service; import org.apache.aries.blueprint.annotation.service.Service; import javax.inject.Singleton; @Service(classes = {Service1.class, Service2.class}) @Singleton public class ServiceWithManyInterfaces implements Service1, Service2 { }
9,305
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/service/ServiceWithClassHierarchy.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.test.service; import org.apache.aries.blueprint.annotation.service.AutoExport; import org.apache.aries.blueprint.annotation.service.Service; import javax.inject.Singleton; @Service(autoExport = AutoExport.CLASS_HIERARCHY) @Singleton public class ServiceWithClassHierarchy implements Service1, Service2 { }
9,306
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/service/ServiceWithRankingParameter.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.test.service; import org.apache.aries.blueprint.annotation.service.Service; import javax.inject.Singleton; @Service(ranking = 1000) @Singleton public class ServiceWithRankingParameter implements Service1, Service2 { }
9,307
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/service/SimplestService.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.test.service; import org.apache.aries.blueprint.annotation.service.Service; import javax.inject.Singleton; @Service @Singleton public class SimplestService implements Service1, Service2 { }
9,308
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/service/ServiceWithOneInterface.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.test.service; import org.apache.aries.blueprint.annotation.service.Service; import javax.inject.Singleton; @Service(classes = Service1.class) @Singleton public class ServiceWithOneInterface implements Service1, Service2 { }
9,309
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/service/Service1.java
/** * 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.aries.blueprint.plugin.test.service; public interface Service1 { }
9,310
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/service/ServiceWithProperties.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.test.service; import org.apache.aries.blueprint.annotation.service.Service; import org.apache.aries.blueprint.annotation.service.ServiceProperty; import javax.inject.Singleton; @Service(properties = { @ServiceProperty(name = "oneValue", values = "test"), @ServiceProperty(name = "intValue", values = "1", type = Integer.class), @ServiceProperty(name = "longArray", values = {"1", "2", "3"}, type = Long.class), @ServiceProperty(name = "emptyArray", values = {}), @ServiceProperty(name = "stringArray", values = {"a", "b"}), }) @Singleton public class ServiceWithProperties implements Service1, Service2 { }
9,311
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/service/ServiceWithAllClasses.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.test.service; import org.apache.aries.blueprint.annotation.service.AutoExport; import org.apache.aries.blueprint.annotation.service.Service; import javax.inject.Singleton; @Service(autoExport = AutoExport.ALL_CLASSES) @Singleton public class ServiceWithAllClasses implements Service1, Service2 { }
9,312
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/reference/Ref4.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.test.reference; public interface Ref4 { }
9,313
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/reference/BeanWithReferenceLists.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.test.reference; import org.apache.aries.blueprint.annotation.service.Availability; import org.apache.aries.blueprint.annotation.service.MemberType; import org.apache.aries.blueprint.annotation.service.ReferenceList; import org.osgi.framework.ServiceReference; import javax.enterprise.inject.Produces; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; import java.util.List; @Singleton public class BeanWithReferenceLists { @Inject @ReferenceList(referenceInterface = Ref1.class) List<Ref1> ref1Field; @Inject @ReferenceList(referenceInterface = Ref1.class) @Named("myRef1List") List<Ref1> myRef1Field; @Inject @ReferenceList(referenceInterface = Ref1.class, filter = "(a=453)", componentName = "r1", availability = Availability.OPTIONAL) List<Ref1> myRef1FieldAllProps; @Inject @ReferenceList(referenceInterface = Ref1.class, filter = "(x=1)", memberType = MemberType.SERVICE_REFERENCE) List<ServiceReference<Ref1>> myRef1FieldFilter; @Inject @ReferenceList(referenceInterface = Ref2.class) public void setRef2Setter(List<Ref2> ref) { } @Inject @ReferenceList(referenceInterface = Ref2.class) @Named("myRef2List") public void setRef2SetterNamed(List<Ref2> ref) { } @Inject @ReferenceList(referenceInterface = Ref2.class, filter = "(b=453)", componentName = "r2", availability = Availability.OPTIONAL) public void setRef2SetterFull(List<Ref2> ref) { } @Inject @ReferenceList(referenceInterface = Ref2.class, componentName = "blablabla", memberType = MemberType.SERVICE_REFERENCE) public void setRef2SetterComponent(List<ServiceReference<Ref2>> ref) { } public BeanWithReferenceLists( @ReferenceList(referenceInterface = Ref1.class) List<Ref1> ref1, @ReferenceList(referenceInterface = Ref2.class, availability = Availability.OPTIONAL, memberType = MemberType.SERVICE_REFERENCE) List<ServiceReference<Ref2>> ref2, @ReferenceList(referenceInterface = Ref1.class, filter = "(y=3)") List<Ref1> ref1x, @ReferenceList(referenceInterface = Ref1.class, componentName = "compForConstr") List<Ref1> ref1c, @ReferenceList(referenceInterface = Ref1.class, filter = "(y=3)", componentName = "compForConstr") List<Ref1> ref1fc, @ReferenceList(referenceInterface = Ref1.class, availability = Availability.OPTIONAL) @Named("ref1ListForCons") List<Ref1> ref1Named ) { } @Produces @Named("producedWithReferenceLists") public String create( @ReferenceList(referenceInterface = Ref3.class) List<Ref3> ref3, @ReferenceList(referenceInterface = Ref4.class, availability = Availability.OPTIONAL) List<Ref4> ref4a, @ReferenceList(referenceInterface = Ref3.class, filter = "(y=3)") List<Ref3> ref3f, @ReferenceList(referenceInterface = Ref3.class, componentName = "compForProduces") List<Ref3> ref3c, @ReferenceList(referenceInterface = Ref3.class, filter = "(y=3)", componentName = "compForProduces", memberType = MemberType.SERVICE_REFERENCE) List<Ref3> ref3fc, @ReferenceList(referenceInterface = Ref3.class) @Named("ref3ListForProduces") List<Ref3> ref3Named ) { return null; } }
9,314
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/reference/Ref2.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.test.reference; public interface Ref2 { }
9,315
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/reference/Ref3.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.test.reference; public interface Ref3 { }
9,316
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/reference/Ref1.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.test.reference; public interface Ref1 { }
9,317
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/reference/BeanWithReferences.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.test.reference; import org.apache.aries.blueprint.annotation.service.Availability; import org.apache.aries.blueprint.annotation.service.Reference; import javax.enterprise.inject.Produces; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; @Singleton public class BeanWithReferences { @Inject @Reference Ref1 ref1Field; @Inject @Reference @Named("myRef1") Ref1 myRef1Field; @Inject @Reference(filter = "(a=453)", componentName = "r1", timeout = 2000, availability = Availability.OPTIONAL) Ref1 myRef1FieldAllProps; @Inject @Reference(filter = "(x=1)") Ref1 myRef1FieldFilter; @Inject @Reference public void setRef2Setter(Ref2 ref) { } @Inject @Reference @Named("myRef2") public void setRef2SetterNamed(Ref2 ref) { } @Inject @Reference(filter = "(b=453)", componentName = "r2", timeout = 1000, availability = Availability.OPTIONAL) public void setRef2SetterFull(Ref2 ref) { } @Inject @Reference(componentName = "blablabla") public void setRef2SetterComponent(Ref2 ref) { } public BeanWithReferences( @Reference Ref1 ref1, @Reference(availability = Availability.OPTIONAL, timeout = 20000) Ref2 ref2, @Reference(filter = "(y=3)") Ref1 ref1x, @Reference(componentName = "compForConstr") Ref1 ref1c, @Reference(filter = "(y=3)", componentName = "compForConstr") Ref1 ref1fc, @Reference(availability = Availability.OPTIONAL) @Named("ref1ForCons") Ref1 ref1Named ) { } @Produces @Named("producedWithReferences") public String create( @Reference Ref3 ref3, @Reference(timeout = 20000) Ref4 ref4, @Reference(availability = Availability.OPTIONAL) Ref4 ref4a, @Reference(filter = "(y=3)") Ref3 ref3f, @Reference(componentName = "compForProduces") Ref3 ref3c, @Reference(filter = "(y=3)", componentName = "compForProduces") Ref3 ref3fc, @Reference(timeout = 1000) @Named("ref3ForProduces") Ref3 ref3Named ) { return null; } }
9,318
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/interfaces/ServiceD.java
/** * 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.aries.blueprint.plugin.test.interfaces; public interface ServiceD { }
9,319
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/interfaces/ServiceB.java
/** * 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.aries.blueprint.plugin.test.interfaces; public interface ServiceB { }
9,320
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/interfaces/ServiceC.java
/** * 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.aries.blueprint.plugin.test.interfaces; public interface ServiceC { }
9,321
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/interfaces/ServiceA.java
/** * 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.aries.blueprint.plugin.test.interfaces; public interface ServiceA { }
9,322
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/osgiserviceprovider/MyFactoryBeanAsService.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.test.osgiserviceprovider; import org.apache.aries.blueprint.plugin.test.MyProduced; import org.apache.aries.blueprint.plugin.test.interfaces.ServiceA; import org.ops4j.pax.cdi.api.OsgiServiceProvider; import org.ops4j.pax.cdi.api.Properties; import org.ops4j.pax.cdi.api.Property; import javax.enterprise.inject.Produces; import javax.inject.Named; import javax.inject.Singleton; @Singleton public class MyFactoryBeanAsService { @Produces @Named("producedForService") @OsgiServiceProvider public MyProduced createBeanWithServiceExpose1() { return null; } @Produces @Named("producedForServiceWithOneInterface") @OsgiServiceProvider(classes = MyProduced.class) public MyProduced createBeanWithServiceExpose2() { return null; } @Produces @Named("producedForServiceWithTwoInterfaces") @OsgiServiceProvider(classes = {MyProduced.class, ServiceA.class}) public MyProduced createBeanWithServiceExpose3() { return null; } @Produces @Named("producedForServiceWithProperties") @OsgiServiceProvider @Properties({ @Property(name = "n1", value = "v1"), @Property(name = "n2", value = "v2"), @Property(name = "service.ranking", value = "100") }) public MyProduced createBeanWithServiceExpose4() { return null; } }
9,323
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/osgiserviceprovider/ServiceWithTypedParameters.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.test.osgiserviceprovider; import org.ops4j.pax.cdi.api.OsgiServiceProvider; import org.ops4j.pax.cdi.api.Properties; import org.ops4j.pax.cdi.api.Property; import javax.inject.Singleton; @OsgiServiceProvider @Properties({ @Property(name = "test1", value = "test"), @Property(name = "test2:Integer", value = "15"), @Property(name = "test3:java.lang.Boolean", value = "true"), @Property(name = "test4:[]", value = "val1|val2"), @Property(name = "test5:Short[]", value = "1|2|3"), @Property(name = "test6:java.lang.Double[]", value = "1.5|0.8|-7.1") }) @Singleton public class ServiceWithTypedParameters { }
9,324
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/osgiserviceprovider/ServiceWithRanking.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.test.osgiserviceprovider; import org.apache.aries.blueprint.plugin.test.interfaces.ServiceA; import org.ops4j.pax.cdi.api.OsgiServiceProvider; import org.ops4j.pax.cdi.api.Properties; import org.ops4j.pax.cdi.api.Property; import javax.inject.Singleton; @Singleton @OsgiServiceProvider @Properties({ @Property(name = "service.ranking", value = "100") }) public class ServiceWithRanking implements ServiceA { }
9,325
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadBean1.java
/** * 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.aries.blueprint.plugin.bad; import javax.annotation.PostConstruct; import javax.inject.Singleton; import org.apache.aries.blueprint.plugin.test.ParentBean; @Singleton public class BadBean1 extends ParentBean { @PostConstruct public void secondInit() { } }
9,326
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/ParentWithInjectedField.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.bad; import javax.inject.Inject; import org.apache.aries.blueprint.plugin.test.MyBean1; public class ParentWithInjectedField { @SuppressWarnings("unused") @Inject private MyBean1 field; }
9,327
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean2.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.bad; import javax.inject.Inject; import javax.inject.Singleton; import org.apache.aries.blueprint.plugin.test.MyBean1; @Singleton public class BadFieldBean2 extends ParentWithInjectedField { @SuppressWarnings("unused") @Inject private MyBean1 field; }
9,328
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/FieldBean4.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.bad; import javax.inject.Singleton; import org.apache.aries.blueprint.plugin.test.MyBean1; @Singleton public class FieldBean4 extends ParentWithField { @SuppressWarnings("unused") private MyBean1 field; }
9,329
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean3.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.bad; import javax.inject.Singleton; import org.apache.aries.blueprint.plugin.test.MyBean1; @Singleton public class BadFieldBean3 extends ParentWithInjectedField { @SuppressWarnings("unused") private MyBean1 field; }
9,330
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/ParentWithField.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.bad; import org.apache.aries.blueprint.plugin.test.MyBean1; public class ParentWithField { @SuppressWarnings("unused") private MyBean1 field; }
9,331
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean1.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.bad; import javax.inject.Inject; import javax.inject.Singleton; import org.apache.aries.blueprint.plugin.test.MyBean1; @Singleton public class BadFieldBean1 extends ParentWithField { @SuppressWarnings("unused") @Inject private MyBean1 field; }
9,332
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadBean3.java
/** * 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.aries.blueprint.plugin.bad; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; public class BadBean3 { @Transactional(propagation = Propagation.NESTED) public void txNestedIsNotSupported() { } }
9,333
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadBean2.java
/** * 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.aries.blueprint.plugin.bad; import javax.annotation.PreDestroy; import javax.inject.Singleton; import org.apache.aries.blueprint.plugin.test.ParentBean; @Singleton public class BadBean2 extends ParentBean { @PreDestroy public void secondDestroy() { } }
9,334
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BlueprintTest.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.model; import org.apache.aries.blueprint.plugin.BlueprintConfigurationImpl; import org.apache.aries.blueprint.plugin.test.MyBean3; import org.apache.aries.blueprint.plugin.test.ServiceReferences; import org.junit.Assert; import org.junit.Test; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.service.blueprint.container.BlueprintContainer; import org.osgi.service.blueprint.container.Converter; import java.lang.annotation.Annotation; import java.util.Arrays; import java.util.HashSet; import java.util.Set; import static org.junit.Assert.assertEquals; public class BlueprintTest { private static final String NS_JPA1 = "http://aries.apache.org/xmlns/jpa/v1.0.0"; private static final String NS_TX1 = "http://aries.apache.org/xmlns/transactions/v1.0.0"; private final Set<String> namespaces = new HashSet<String>(Arrays.asList(NS_JPA1, NS_TX1)); private final BlueprintConfigurationImpl blueprintConfiguration = new BlueprintConfigurationImpl(namespaces, null, null, null, null); @Test public void testLists() { Blueprint blueprint = new Blueprint(blueprintConfiguration, MyBean3.class); Assert.assertEquals(1, blueprint.getBeans().size()); Assert.assertEquals(0, getOsgiServices(blueprint).size()); } @Test public void testLists2() { Blueprint blueprint = new Blueprint(blueprintConfiguration, ServiceReferences.class); Assert.assertEquals(1, blueprint.getBeans().size()); Assert.assertEquals(3, getOsgiServices(blueprint).size()); } private Set<String> getOsgiServices(Blueprint blueprint) { Set<String> blueprintWritersKeys = blueprint.getCustomWriters().keySet(); Set<String> osgiServices = new HashSet<>(); for (String blueprintWritersKey : blueprintWritersKeys) { if (blueprintWritersKey.startsWith("osgiService/")) { osgiServices.add(blueprintWritersKey); } } return osgiServices; } private void assertSpecialRef(String expectedId, Class<?> clazz) { Blueprint blueprint = new Blueprint(blueprintConfiguration); BeanRef ref = blueprint.getMatching(new BeanTemplate(clazz, new Annotation[]{})); assertEquals(expectedId, ref.id); } @Test public void testSpecialRefs() { assertSpecialRef("blueprintBundleContext", BundleContext.class); assertSpecialRef("blueprintBundle", Bundle.class); assertSpecialRef("blueprintContainer", BlueprintContainer.class); assertSpecialRef("blueprintConverter", Converter.class); } }
9,335
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/TransactionalDef.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.model; public class TransactionalDef { private final String method; private final String type; public TransactionalDef(String method, String type) { this.method = method; this.type = type; } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof TransactionalDef)) return false; TransactionalDef that = (TransactionalDef) o; if (method != null ? !method.equals(that.method) : that.method != null) return false; return type != null ? type.equals(that.type) : that.type == null; } @Override public int hashCode() { int result = method != null ? method.hashCode() : 0; result = 31 * result + (type != null ? type.hashCode() : 0); return result; } }
9,336
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/TestBeanForRef.java
/** * 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.aries.blueprint.plugin.model; import javax.inject.Inject; import javax.inject.Singleton; import javax.persistence.EntityManager; import javax.persistence.PersistenceUnit; import org.apache.aries.blueprint.plugin.test.interfaces.ServiceA; import org.apache.aries.blueprint.plugin.test.interfaces.ServiceB; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @Singleton public class TestBeanForRef { @Inject ServiceA serviceA; @Autowired ServiceB serviceB; @Value("${name:default}") String name; @PersistenceUnit(unitName="myunit") EntityManager em; }
9,337
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.model; import com.google.common.collect.Sets; import org.apache.aries.blueprint.plugin.BlueprintConfigurationImpl; import org.apache.aries.blueprint.plugin.bad.BadBean1; import org.apache.aries.blueprint.plugin.bad.BadBean2; import org.apache.aries.blueprint.plugin.bad.BadBean3; import org.apache.aries.blueprint.plugin.bad.BadFieldBean1; import org.apache.aries.blueprint.plugin.bad.BadFieldBean2; import org.apache.aries.blueprint.plugin.bad.BadFieldBean3; import org.apache.aries.blueprint.plugin.bad.FieldBean4; import org.apache.aries.blueprint.plugin.test.MyBean1; import org.apache.aries.blueprint.plugin.test.MyBean3; import org.apache.aries.blueprint.plugin.test.MyBean4; import org.apache.aries.blueprint.plugin.test.ServiceAImpl1; import org.junit.Test; import javax.inject.Named; import java.util.Arrays; import java.util.HashSet; import java.util.Set; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class BeanTest { private static final String NS_JPA1 = "http://aries.apache.org/xmlns/jpa/v1.1.0"; private static final String NS_TX1 = "http://aries.apache.org/xmlns/transactions/v1.1.0"; private final Set<String> namespaces = new HashSet<String>(Arrays.asList(NS_JPA1, NS_TX1)); private final BlueprintConfigurationImpl blueprintConfiguration = new BlueprintConfigurationImpl(namespaces, null, null, null, null); private final Blueprint blueprint = new Blueprint(blueprintConfiguration); @Test public void testParseMyBean1() { Bean bean = new Bean(MyBean1.class, blueprint); bean.resolveDependency(blueprint); assertEquals(MyBean1.class, bean.clazz); assertEquals("myBean1", bean.id); // Name derived from class name assertEquals(2, getPersistenceFields(bean).size()); assertEquals(Sets.newHashSet("em", "emf"), getPersistenceFields(bean)); assertEquals(1, bean.properties.size()); assertEquals("singleton", bean.attributes.get("scope")); Property prop = bean.properties.iterator().next(); assertEquals("bean2", prop.name); assertEquals("serviceA", prop.ref); Set<TransactionalDef> expectedTxs = Sets.newHashSet(new TransactionalDef("*", "RequiresNew"), new TransactionalDef("txNotSupported", "NotSupported"), new TransactionalDef("txMandatory", "Mandatory"), new TransactionalDef("txNever", "Never"), new TransactionalDef("txRequired", "Required"), new TransactionalDef("txOverridenWithRequiresNew", "RequiresNew"), new TransactionalDef("txSupports", "Supports")); assertEquals(expectedTxs, getTransactionalDefs(bean)); } @Test public void testParseMyBean3() { Bean bean = new Bean(MyBean3.class, blueprint); bean.resolveDependency(blueprint); assertEquals(MyBean3.class, bean.clazz); assertEquals("myBean3", bean.id); // Name derived from class name assertEquals("There should be no persistence fields", 0, getPersistenceFields(bean).size()); assertEquals(5, bean.properties.size()); assertEquals("prototype", bean.attributes.get("scope")); Set<TransactionalDef> expectedTxs = Sets.newHashSet(new TransactionalDef("*", "RequiresNew"), new TransactionalDef("txNotSupported", "NotSupported"), new TransactionalDef("txMandatory", "Mandatory"), new TransactionalDef("txNever", "Never"), new TransactionalDef("txRequired", "Required"), new TransactionalDef("txRequiresNew", "RequiresNew"), new TransactionalDef("txSupports", "Supports")); assertEquals(expectedTxs, getTransactionalDefs(bean)); } @Test public void testParseNamedBean() { Bean bean = new Bean(ServiceAImpl1.class, blueprint); bean.resolveDependency(blueprint); String definedName = ServiceAImpl1.class.getAnnotation(Named.class).value(); assertEquals("my1", definedName); assertEquals("Name should be defined using @Named", definedName, bean.id); assertEquals("There should be no persistence fields", 0, getPersistenceFields(bean).size()); assertTrue("There should be no transaction definition", getTransactionalDefs(bean).isEmpty()); assertEquals("There should be no properties", 0, bean.properties.size()); assertEquals("prototype", bean.attributes.get("scope")); } @Test public void testBlueprintBundleContext() { Bean bean = new Bean(MyBean4.class, blueprint); bean.resolveDependency(blueprint); Property bcProp = bean.properties.iterator().next(); assertEquals("bundleContext", bcProp.name); assertEquals("blueprintBundleContext", bcProp.ref); assertEquals("singleton", bean.attributes.get("scope")); Set<TransactionalDef> expectedTxs = Sets.newHashSet(new TransactionalDef("txWithoutClassAnnotation", "Supports")); assertEquals(expectedTxs, getTransactionalDefs(bean)); } private Set<TransactionalDef> getTransactionalDefs(Bean bean) { Set<String> beanWriters = bean.beanContentWriters.keySet(); Set<TransactionalDef> transactionalDefs = new HashSet<>(); for (String beanWriter : beanWriters) { if (beanWriter.startsWith("javax.transactional.method/")) { String[] splitId = beanWriter.split("/"); transactionalDefs.add(new TransactionalDef(splitId[2], splitId[3])); } } return transactionalDefs; } private Set<String> getPersistenceFields(Bean bean) { Set<String> beanWriters = bean.beanContentWriters.keySet(); Set<String> persistenceFields = new HashSet<>(); for (String beanWriter : beanWriters) { if (beanWriter.startsWith("javax.persistence.field.")) { persistenceFields.add(beanWriter.split("/")[1]); } } return persistenceFields; } @Test(expected = IllegalArgumentException.class) public void testMultipleInitMethods() { new Bean(BadBean1.class, blueprint); } @Test(expected = IllegalArgumentException.class) public void testMultipleDestroyMethods() { new Bean(BadBean2.class, blueprint); } @Test(expected = UnsupportedOperationException.class) public void testSpringNestedTransactionNotSupported() { new Bean(BadBean3.class, blueprint); } @Test(expected = UnsupportedOperationException.class) public void testBadFieldBean1() { new Blueprint(blueprintConfiguration, BadFieldBean1.class); } @Test(expected = UnsupportedOperationException.class) public void testBadFieldBean2() { new Blueprint(blueprintConfiguration, BadFieldBean2.class); } @Test(expected = UnsupportedOperationException.class) public void testBadFieldBean3() { new Blueprint(blueprintConfiguration, BadFieldBean3.class); } @Test public void testFieldBean4() { new Blueprint(blueprintConfiguration, FieldBean4.class); } }
9,338
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/PackageFinder.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin; import java.io.File; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.Stack; class PackageFinder { static Set<String> findPackagesInSources(List<String> compileSourceRoots) { Set<String> packages = new HashSet<>(); for (String src : compileSourceRoots) { File root = new File(src); if (root.exists()) { packages.addAll(findPackageRoots(root)); } } return packages; } private static Set<String> findPackageRoots(File file) { Set<String> packages = new HashSet<>(); Stack<SearchFile> stack = new Stack<>(); stack.add(new SearchFile(null, file)); while (!stack.isEmpty()) { SearchFile cur = stack.pop(); File[] files = cur.f.listFiles(); boolean foundFile = false; for (File child : files) { if (child.isFile()) { packages.add(cur.prefix); foundFile = true; } } if (foundFile) { continue; } for (File child : files) { if (child.isDirectory()) { stack.add(new SearchFile(cur.prefix != null ? cur.prefix + "." + child.getName() : child.getName(), child)); } } } return packages; } private static class SearchFile { String prefix; File f; SearchFile(String prefix, File f) { this.prefix = prefix; this.f = f; } } }
9,339
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/ResourceInitializer.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin; import org.apache.maven.model.Resource; import org.apache.maven.project.MavenProject; class ResourceInitializer { static void prepareBaseDir(MavenProject project, String baseDir){ Resource resource = new Resource(); resource.setDirectory(baseDir); project.addResource(resource); } }
9,340
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/BlueprintFileWriter.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin; import org.apache.aries.blueprint.plugin.model.Blueprint; import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.OutputStream; class BlueprintFileWriter { private final XMLStreamWriter writer; private final OutputStream os; private final ByteArrayOutputStream temp = new ByteArrayOutputStream(); BlueprintFileWriter(OutputStream os) throws XMLStreamException { this.writer = XMLOutputFactory.newFactory().createXMLStreamWriter(temp); this.os = os; } void write(Blueprint blueprint) { generateXml(blueprint); printFormatted(); } private void generateXml(Blueprint blueprint) { try { writer.writeStartDocument(); blueprint.write(writer); writer.writeEndDocument(); writer.close(); } catch (XMLStreamException e) { throw new RuntimeException(e.getMessage(), e); } } private void printFormatted() { try { TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transformer.transform( new StreamSource(new ByteArrayInputStream(temp.toByteArray())), new StreamResult(os)); } catch (TransformerException e) { throw new RuntimeException("Cannot print file", e); } } }
9,341
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/ArtifactFilter.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin; import org.apache.maven.artifact.Artifact; import java.util.HashSet; import java.util.Set; import java.util.regex.Pattern; class ArtifactFilter { private final Set<Pattern> includeArtifactPatterns; private final Set<Pattern> excludeArtifactPatterns; ArtifactFilter(Set<String> includeArtifacts, Set<String> excludeArtifacts) { includeArtifactPatterns = buildArtifactPatterns(includeArtifacts); excludeArtifactPatterns = buildPatterns(excludeArtifacts); } boolean shouldExclude(Artifact artifact) { return !canBeIncluded(artifact) || shouldBeExcluded(artifact); } private Set<Pattern> buildArtifactPatterns(Set<String> includeArtifacts) { if (includeArtifacts.isEmpty()) { Set<Pattern> patterns = new HashSet<>(); patterns.add(Pattern.compile(".*")); return patterns; } return buildPatterns(includeArtifacts); } private Set<Pattern> buildPatterns(Set<String> artifactFilters) { Set<Pattern> artifactPatterns = new HashSet<>(); for (String artifactFilter : artifactFilters) { artifactPatterns.add(Pattern.compile(artifactFilter)); } return artifactPatterns; } private boolean shouldBeExcluded(Artifact artifact) { for (Pattern excludeArtifactPattern : excludeArtifactPatterns) { if (excludeArtifactPattern.matcher(artifact.toString()).matches()) { return true; } } return false; } private boolean canBeIncluded(Artifact artifact) { for (Pattern includeArtifactPattern : includeArtifactPatterns) { if (includeArtifactPattern.matcher(artifact.toString()).matches()) { return true; } } return false; } }
9,342
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/FilteredClassFinder.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin; import org.apache.aries.blueprint.plugin.handlers.Handlers; import org.apache.xbean.finder.ClassFinder; import java.lang.annotation.Annotation; import java.util.Collection; import java.util.HashSet; import java.util.Set; class FilteredClassFinder { @SuppressWarnings("unchecked") static Set<Class<?>> findClasses(ClassFinder finder, Collection<String> packageNames) { return findClasses(finder, packageNames, Handlers.BEAN_MARKING_ANNOTATION_CLASSES.toArray(new Class[Handlers.BEAN_MARKING_ANNOTATION_CLASSES.size()])); } private static Set<Class<?>> findClasses(ClassFinder finder, Collection<String> packageNames, Class<? extends Annotation>[] annotations) { Set<Class<?>> rawClasses = new HashSet<Class<?>>(); for (Class<? extends Annotation> annotation : annotations) { rawClasses.addAll(finder.findAnnotatedClasses(annotation)); } return filterByBasePackages(rawClasses, packageNames); } private static Set<Class<?>> filterByBasePackages(Set<Class<?>> rawClasses, Collection<String> packageNames) { Set<Class<?>> filteredClasses = new HashSet<Class<?>>(); for (Class<?> clazz : rawClasses) { for (String packageName : packageNames) { if (clazz.getPackage().getName().startsWith(packageName)) { filteredClasses.add(clazz); } } } return filteredClasses; } }
9,343
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/NegativeTimeout.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin; class NegativeTimeout extends RuntimeException { NegativeTimeout(long defaultTimeout) { super("Default timeout cannot be negative " + defaultTimeout); } }
9,344
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/BlueprintConfigurationImpl.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin; import org.apache.aries.blueprint.plugin.spi.Activation; import org.apache.aries.blueprint.plugin.spi.Availability; import org.apache.aries.blueprint.plugin.spi.BlueprintConfiguration; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; public class BlueprintConfigurationImpl implements BlueprintConfiguration { private static final String NS_TX2 = "http://aries.apache.org/xmlns/transactions/v2.0.0"; private static final String NS_JPA2 = "http://aries.apache.org/xmlns/jpa/v2.0.0"; private final Set<String> namespaces; private final Activation defaultActivation; private final Map<String, String> customParameters; private final Availability defaultAvailability; private final Long defaultTimeout; public BlueprintConfigurationImpl(Set<String> namespaces, Activation defaultActivation, Map<String, String> customParameters, Availability defaultAvailability, Long defaultTimeout) { this.namespaces = namespaces != null ? namespaces : new HashSet<>(Arrays.asList(NS_TX2, NS_JPA2)); this.defaultActivation = defaultActivation; this.customParameters = customParameters == null ? new HashMap<String, String>() : customParameters; this.defaultAvailability = defaultAvailability; this.defaultTimeout = defaultTimeout; validateTimeout(); } private void validateTimeout() { if (defaultTimeout != null && defaultTimeout < 0L) { throw new NegativeTimeout(defaultTimeout); } } @Override public Set<String> getNamespaces() { return namespaces; } @Override public Activation getDefaultActivation() { return defaultActivation; } @Override public Availability getDefaultAvailability() { return defaultAvailability; } @Override public Long getDefaultTimeout() { return defaultTimeout; } @Override public Map<String, String> getCustomParameters() { return customParameters; } }
9,345
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/AddResourceDirMojo.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; /** * Creates resource base dir where blueprint file will be generated for IDE support */ @Mojo(name = "add-resource-dir", requiresDependencyResolution = ResolutionScope.COMPILE, defaultPhase = LifecyclePhase.GENERATE_RESOURCES, inheritByDefault = false, threadSafe = true) public class AddResourceDirMojo extends AbstractMojo { @Parameter(defaultValue = "${project}", required = true) protected MavenProject project; /** * Base directory to write generated hierarchy. */ @Parameter(defaultValue = "${project.build.directory}/generated-sources/blueprint/") private String baseDir; @Override public void execute() throws MojoExecutionException, MojoFailureException { ResourceInitializer.prepareBaseDir(project, baseDir); } }
9,346
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/GenerateMojo.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin; import org.apache.aries.blueprint.plugin.model.Blueprint; import org.apache.aries.blueprint.plugin.model.ConflictDetected; import org.apache.aries.blueprint.plugin.spi.Activation; import org.apache.aries.blueprint.plugin.spi.Availability; import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; import org.apache.xbean.finder.ClassFinder; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.sonatype.plexus.build.incremental.BuildContext; import java.io.File; import java.io.OutputStream; import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; /** * Generates blueprint from CDI annotations */ @Mojo(name = "blueprint-generate", requiresDependencyResolution = ResolutionScope.COMPILE, defaultPhase = LifecyclePhase.PROCESS_CLASSES, inheritByDefault = false, threadSafe = true) public class GenerateMojo extends AbstractMojo { @Parameter(defaultValue = "${project}", required = true) protected MavenProject project; @Parameter protected List<String> scanPaths; /** * Which extension namespaces should the plugin support */ @Parameter protected Set<String> namespaces; @Component private BuildContext buildContext; /** * Name of file to write */ @Parameter(defaultValue = "autowire.xml") protected String generatedFileName; /** * Base directory to write generated hierarchy. */ @Parameter(defaultValue = "${project.build.directory}/generated-sources/blueprint/") private String baseDir; /** * Base directory to write into * (relative to baseDir property). */ @Parameter(defaultValue = "OSGI-INF/blueprint/") private String generatedDir; /** * Specifies the default activation setting that will be defined for components. * Default is null, which indicates eager (blueprint default). * If LAZY then default-activation will be set to lazy. * If EAGER then default-activation will be explicitly set to eager. */ @Parameter protected Activation defaultActivation; /** * Specifies the default availability setting that will be defined for components. * Default is null, which indicates mandatory (blueprint default). * If MANDATORY then default-activation will be set to mandatory. * If OPTIONAL then default-activation will be explicitly set to optional. */ @Parameter protected Availability defaultAvailability; /** * Specifies the default timout setting that will be defined for components. * Default is null, which indicates 300000 seconds (blueprint default). */ @Parameter protected Long defaultTimeout; /** * Specifies additional parameters which could be used in extensions */ @Parameter protected Map<String, String> customParameters; /** * Which artifacts should be included in finding beans process */ @Parameter private Set<String> includeArtifacts = new HashSet<>(); /** * Which artifacts should be excluded from finding beans process */ @Parameter private Set<String> excludeArtifacts = new HashSet<>(); @Override public void execute() throws MojoExecutionException, MojoFailureException { List<String> toScan = getPackagesToScan(); if (!sourcesChanged()) { getLog().info("Skipping blueprint generation because source files were not changed"); return; } try { BlueprintConfigurationImpl blueprintConfiguration = new BlueprintConfigurationImpl(namespaces, defaultActivation, customParameters, defaultAvailability, defaultTimeout); generateBlueprint(toScan, blueprintConfiguration); } catch (ConflictDetected e) { throw new MojoExecutionException(e.getMessage(), e); } catch (Exception e) { throw new MojoExecutionException("Error during blueprint generation", e); } } private void generateBlueprint(List<String> toScan, BlueprintConfigurationImpl blueprintConfiguration) throws Exception { long startTime = System.currentTimeMillis(); ClassFinder classFinder = createProjectScopeFinder(); getLog().debug("Creating package scope class finder: " + (System.currentTimeMillis() - startTime) + "ms"); startTime = System.currentTimeMillis(); Set<Class<?>> classes = FilteredClassFinder.findClasses(classFinder, toScan); getLog().debug("Finding bean classes: " + (System.currentTimeMillis() - startTime) + "ms"); startTime = System.currentTimeMillis(); Blueprint blueprint = new Blueprint(blueprintConfiguration, classes); getLog().debug("Creating blueprint model: " + (System.currentTimeMillis() - startTime) + "ms"); startTime = System.currentTimeMillis(); writeBlueprintIfNeeded(blueprint); getLog().debug("Writing blueprint: " + (System.currentTimeMillis() - startTime) + "ms"); } private void writeBlueprintIfNeeded(Blueprint blueprint) throws Exception { if (blueprint.shouldBeGenerated()) { writeBlueprint(blueprint); } else { getLog().warn("Skipping blueprint generation because no beans were found"); } } private boolean sourcesChanged() { return buildContext.hasDelta(new File(project.getCompileSourceRoots().iterator().next())); } private void writeBlueprint(Blueprint blueprint) throws Exception { ResourceInitializer.prepareBaseDir(project, baseDir); File dir = new File(baseDir, generatedDir); File file = new File(dir, generatedFileName); file.getParentFile().mkdirs(); getLog().info("Generating blueprint to " + file); OutputStream fos = buildContext.newFileOutputStream(file); new BlueprintFileWriter(fos).write(blueprint); fos.close(); } private ClassFinder createProjectScopeFinder() throws Exception { List<URL> urls = new ArrayList<>(); long startTime = System.currentTimeMillis(); ClassRealm classRealm = new ClassRealm(new ClassWorld(), "maven-blueprint-plugin-classloader", getClass().getClassLoader()); classRealm.addURL(new File(project.getBuild().getOutputDirectory()).toURI().toURL()); urls.add(new File(project.getBuild().getOutputDirectory()).toURI().toURL()); ArtifactFilter artifactFilter = new ArtifactFilter(includeArtifacts, excludeArtifacts); for (Object artifactO : project.getArtifacts()) { Artifact artifact = (Artifact) artifactO; File file = artifact.getFile(); if (file == null) { continue; } URL artifactUrl = file.toURI().toURL(); classRealm.addURL(artifactUrl); if (artifactFilter.shouldExclude(artifact)) { getLog().debug("Excluded artifact: " + artifact); continue; } getLog().debug("Taken artifact: " + artifact); urls.add(artifactUrl); } getLog().debug(" Create class loader: " + (System.currentTimeMillis() - startTime) + "ms"); startTime = System.currentTimeMillis(); ClassFinder classFinder = new ClassFinder(classRealm, urls); getLog().debug(" Building class finder: " + (System.currentTimeMillis() - startTime) + "ms"); return classFinder; } private List<String> getPackagesToScan() throws MojoExecutionException { List<String> toScan = scanPaths; if (scanPaths == null || scanPaths.size() == 0 || scanPaths.iterator().next() == null) { getLog().info("Scan paths not specified - searching for packages"); Set<String> packages = PackageFinder.findPackagesInSources(project.getCompileSourceRoots()); if (packages.contains(null)) { throw new MojoExecutionException("Found file without package"); } toScan = new ArrayList<>(packages); Collections.sort(toScan); } for (String aPackage : toScan) { getLog().info("Package " + aPackage + " will be scanned"); } return toScan; } }
9,347
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.model; import java.lang.annotation.Annotation; import java.util.Set; final class BeanRef implements Comparable<BeanRef> { final String id; final Class<?> clazz; private final Set<Annotation> qualifiers; BeanRef(Class<?> clazz, String id, Annotation[] qualifiers) { this.clazz = clazz; this.id = id; this.qualifiers = QualifierHelper.getQualifiers(qualifiers); } boolean matches(BeanTemplate template) { boolean assignable = template.clazz.isAssignableFrom(this.clazz); return assignable && qualifiers.containsAll(template.qualifiers); } @Override public int compareTo(BeanRef other) { return this.id.compareTo(other.id); } boolean conflictsWith(BeanRef bean) { return id.equals(bean.id) && !clazz.equals(bean.clazz); } }
9,348
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Argument.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.model; import org.apache.aries.blueprint.plugin.handlers.Handlers; import org.apache.aries.blueprint.plugin.spi.CollectionDependencyAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.CustomDependencyAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.XmlWriter; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.List; import java.util.Set; import static org.apache.aries.blueprint.plugin.model.AnnotationHelper.findName; import static org.apache.aries.blueprint.plugin.model.AnnotationHelper.findValue; import static org.apache.aries.blueprint.plugin.model.NamingHelper.getBeanName; class Argument implements XmlWriter { private final String ref; private final String value; private final RefCollection refCollection; Argument(BlueprintRegistry blueprintRegistry, Class<?> argumentClass, Annotation[] annotations) { this.value = findValue(annotations); if (value != null) { ref = null; refCollection = null; return; } this.refCollection = RefCollection.getRefCollection(blueprintRegistry, argumentClass, annotations); if (refCollection != null) { ref = null; return; } this.ref = findRef(blueprintRegistry, argumentClass, annotations); } private String findRef(BlueprintRegistry blueprintRegistry, Class<?> argumentClass, Annotation[] annotations) { String ref = findName(annotations); for (CustomDependencyAnnotationHandler customDependencyAnnotationHandler : Handlers.CUSTOM_DEPENDENCY_ANNOTATION_HANDLERS) { Annotation annotation = (Annotation) AnnotationHelper.findAnnotation(annotations, customDependencyAnnotationHandler.getAnnotation()); if (annotation != null) { String generatedRef = customDependencyAnnotationHandler.handleDependencyAnnotation(argumentClass, annotation, ref, blueprintRegistry); if (generatedRef != null) { ref = generatedRef; break; } } } if (ref == null) { BeanTemplate template = new BeanTemplate(argumentClass, annotations); BeanRef bean = blueprintRegistry.getMatching(template); if (bean != null) { ref = bean.id; } else { ref = getBeanName(argumentClass); } } return ref; } String getRef() { return this.ref; } String getValue() { return this.value; } @Override public void write(XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement("argument"); if (ref != null) { writer.writeAttribute("ref", ref); } else if (value != null) { writer.writeAttribute("value", value); }else if (refCollection != null) { refCollection.write(writer); } writer.writeEndElement(); } }
9,349
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/QualifierHelper.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.model; import org.apache.aries.blueprint.plugin.handlers.Handlers; import java.lang.annotation.Annotation; import java.util.HashSet; import java.util.Set; class QualifierHelper { static Set<Annotation> getQualifiers(Annotation[] annotations) { final Set<Annotation> qualifiers = new HashSet<>(); for (Annotation ann : annotations) { if (isQualifier(ann) != null) { qualifiers.add(ann); } } return qualifiers; } private static Object isQualifier(Annotation ann) { for (Class<? extends Annotation> qualifingAnnotationClass : Handlers.QUALIFING_ANNOTATION_CLASSES) { Object annotation = ann.annotationType().getAnnotation(qualifingAnnotationClass); if (annotation != null) { return annotation; } } return null; } }
9,350
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.model; import org.apache.aries.blueprint.plugin.handlers.Handlers; import org.apache.aries.blueprint.plugin.spi.CollectionDependencyAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.CustomDependencyAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.NamedLikeHandler; import org.apache.aries.blueprint.plugin.spi.XmlWriter; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.Set; import static org.apache.aries.blueprint.plugin.model.AnnotationHelper.findName; import static org.apache.aries.blueprint.plugin.model.NamingHelper.getBeanName; class Property implements Comparable<Property>, XmlWriter { public final String name; public final String ref; public final String value; final boolean isField; private final RefCollection refCollection; private Property(String name, String ref, String value, boolean isField, RefCollection refCollection) { this.name = name; this.ref = ref; this.value = value; this.isField = isField; this.refCollection = refCollection; } static Property create(BlueprintRegistry blueprintRegistry, Field field) { if (needsInject(field)) { String value = AnnotationHelper.findValue(field.getAnnotations()); if (value != null) { return new Property(field.getName(), null, value, true, null); } RefCollection refCollection = RefCollection.getRefCollection(blueprintRegistry, field); if (refCollection != null) { return new Property(field.getName(), null, null, true, refCollection); } String ref = getForcedRefName(field); String refFromCustomeDependencyHandler = getRefFromCustomDependencyHandlers(blueprintRegistry, field, ref); if (refFromCustomeDependencyHandler != null) { ref = refFromCustomeDependencyHandler; } if (ref != null) { return new Property(field.getName(), ref, null, true, null); } BeanRef matching = blueprintRegistry.getMatching(new BeanTemplate(field)); ref = (matching == null) ? getDefaultRefName(field) : matching.id; return new Property(field.getName(), ref, null, true, null); } else { // Field is not a property return null; } } private static String getRefFromCustomDependencyHandlers(BlueprintRegistry blueprintRegistry, AnnotatedElement annotatedElement, String ref) { for (CustomDependencyAnnotationHandler customDependencyAnnotationHandler : Handlers.CUSTOM_DEPENDENCY_ANNOTATION_HANDLERS) { Annotation annotation = (Annotation) AnnotationHelper.findAnnotation(annotatedElement.getAnnotations(), customDependencyAnnotationHandler.getAnnotation()); if (annotation != null) { String generatedRef = customDependencyAnnotationHandler.handleDependencyAnnotation(annotatedElement, ref, blueprintRegistry); if (generatedRef != null) { return generatedRef; } } } return null; } static Property create(BlueprintRegistry blueprintRegistry, Method method) { String propertyName = resolveProperty(method); if (propertyName == null) { return null; } String value = AnnotationHelper.findValue(method.getAnnotations()); if (value != null) { return new Property(propertyName, null, value, false, null); } if (needsInject(method)) { RefCollection refCollection = RefCollection.getRefCollection(blueprintRegistry, method); if (refCollection != null) { return new Property(propertyName, null, null, true, refCollection); } String ref = getForcedRefName(method); if (ref == null) { ref = findName(method.getParameterAnnotations()[0]); } String refFromCustomeDependencyHandler = getRefFromCustomDependencyHandlers(blueprintRegistry, method, ref); if (refFromCustomeDependencyHandler != null) { ref = refFromCustomeDependencyHandler; } if (ref != null) { return new Property(propertyName, ref, null, false, null); } for (CustomDependencyAnnotationHandler customDependencyAnnotationHandler : Handlers.CUSTOM_DEPENDENCY_ANNOTATION_HANDLERS) { Annotation annotation = (Annotation) AnnotationHelper.findAnnotation(method.getParameterAnnotations()[0], customDependencyAnnotationHandler.getAnnotation()); if (annotation != null) { String generatedRef = customDependencyAnnotationHandler.handleDependencyAnnotation(method.getParameterTypes()[0], annotation, ref, blueprintRegistry); if (generatedRef != null) { ref = generatedRef; break; } } } if (ref != null) { return new Property(propertyName, ref, null, false, null); } BeanTemplate template = new BeanTemplate(method); BeanRef matching = blueprintRegistry.getMatching(template); ref = (matching == null) ? getBeanName(method.getParameterTypes()[0]) : matching.id; return new Property(propertyName, ref, null, false, null); } return null; } private static String resolveProperty(Method method) { if (method.getParameterTypes().length != 1) { return null; } String propertyName = method.getName().substring(3); return makeFirstLetterLower(propertyName); } /** * Assume it is defined in another manually created blueprint context with default name * * @param field * @return */ private static String getDefaultRefName(Field field) { return getBeanName(field.getType()); } private static String getForcedRefName(Field field) { return getForcedRefName(field.getType(), field); } private static String getForcedRefName(Method method) { return getForcedRefName(method.getParameterTypes()[0], method); } private static String getForcedRefName(Class<?> clazz, AnnotatedElement annotatedElement) { for (NamedLikeHandler namedLikeHandler : Handlers.NAMED_LIKE_HANDLERS) { if (annotatedElement.getAnnotation(namedLikeHandler.getAnnotation()) != null) { String name = namedLikeHandler.getName(clazz, annotatedElement); if (name != null) { return name; } } } return null; } private static boolean needsInject(AnnotatedElement annotatedElement) { for (Class injectDependencyAnnotation : AnnotationHelper.injectDependencyAnnotations) { if (annotatedElement.getAnnotation(injectDependencyAnnotation) != null) { return true; } } return false; } @Override public int compareTo(Property other) { return name.compareTo(other.name); } private static String makeFirstLetterLower(String name) { return name.substring(0, 1).toLowerCase() + name.substring(1, name.length()); } @Override public void write(XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement("property"); writer.writeAttribute("name", name); if (ref != null) { writer.writeAttribute("ref", ref); } else if (value != null) { writer.writeAttribute("value", value); } else if (refCollection != null) { refCollection.write(writer); } writer.writeEndElement(); } }
9,351
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/ConflictDetected.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.model; public class ConflictDetected extends RuntimeException { ConflictDetected(BeanRef bean1, BeanRef bean2) { super(String.format("Found two beans with id `%s`, but different classes: [%s, %s]", bean1.id, bean1.clazz.getName(), bean2.clazz.getName())); } }
9,352
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/AnnotationHelper.java
/** * 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.aries.blueprint.plugin.model; import org.apache.aries.blueprint.plugin.handlers.Handlers; import org.apache.aries.blueprint.plugin.spi.CollectionDependencyAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.InjectLikeHandler; import org.apache.aries.blueprint.plugin.spi.NamedLikeHandler; import org.apache.aries.blueprint.plugin.spi.ValueInjectionHandler; import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.List; class AnnotationHelper { static Class<? extends Annotation>[] injectDependencyAnnotations = findInjectDependencyAnnotations(); private static Class<? extends Annotation>[] findInjectDependencyAnnotations() { List<Class<? extends Annotation>> classes = new ArrayList<>(); for (InjectLikeHandler<? extends Annotation> injectLikeHandler : Handlers.BEAN_INJECT_LIKE_HANDLERS) { classes.add(injectLikeHandler.getAnnotation()); } for (ValueInjectionHandler<? extends Annotation> valueInjectionHandler : Handlers.VALUE_INJECTION_HANDLERS) { classes.add(valueInjectionHandler.getAnnotation()); } for (CollectionDependencyAnnotationHandler<? extends Annotation> collectionDependencyAnnotationHandler : Handlers.COLLECTION_DEPENDENCY_ANNOTATION_HANDLERS) { classes.add(collectionDependencyAnnotationHandler.getAnnotation()); } return classes.toArray(new Class[classes.size()]); } static String findValue(Annotation[] annotations) { for (ValueInjectionHandler valueInjectionHandler : Handlers.VALUE_INJECTION_HANDLERS) { Object annotation = findAnnotation(annotations, valueInjectionHandler.getAnnotation()); if (annotation != null) { String value = valueInjectionHandler.getValue(annotation); if (value != null) { return value; } } } return null; } static String findName(Annotation[] annotations) { for (NamedLikeHandler namedLikeHandler : Handlers.NAMED_LIKE_HANDLERS) { Object annotation = findAnnotation(annotations, namedLikeHandler.getAnnotation()); if (annotation != null) { String value = namedLikeHandler.getName(annotation); if (value != null) { return value; } } } return null; } static <T> T findAnnotation(Annotation[] annotations, Class<T> annotation) { for (Annotation a : annotations) { if (a.annotationType() == annotation) { return annotation.cast(a); } } return null; } static boolean findSingletons(Annotation[] annotations) { for (Class<? extends Annotation> singletonAnnotation : Handlers.SINGLETONS) { Object annotation = findAnnotation(annotations, singletonAnnotation); if (annotation != null) { return true; } } return false; } static boolean findSingleton(Class clazz) { for (Class<?> singletonAnnotation : Handlers.SINGLETONS) { if (clazz.getAnnotation(singletonAnnotation) != null) { return true; } } return false; } }
9,353
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/NamingHelper.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.model; import java.lang.reflect.AnnotatedElement; class NamingHelper { static String getBeanName(Class<?> clazz) { return getBeanName(clazz, clazz); } private static String getBeanName(Class<?> clazz, AnnotatedElement annotatedElement) { String name = AnnotationHelper.findName(annotatedElement.getAnnotations()); if (name != null) { return name; } return getBeanNameFromSimpleName(clazz.getSimpleName()); } private static String getBeanNameFromSimpleName(String name) { return name.substring(0, 1).toLowerCase() + name.substring(1, name.length()); } }
9,354
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanTemplate.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.model; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Set; class BeanTemplate { final Class<?> clazz; final Set<Annotation> qualifiers; BeanTemplate(Class<?> clazz, Annotation[] qualifiers) { this.clazz = clazz; this.qualifiers = QualifierHelper.getQualifiers(qualifiers); } BeanTemplate(Field field) { this(field.getType(), field.getAnnotations()); } BeanTemplate(Method method) { this(method.getParameterTypes()[0], method.getAnnotations()); } }
9,355
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRefStore.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.model; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.SortedSet; import java.util.TreeSet; class BeanRefStore { private SortedSet<BeanRef> reg = new TreeSet<BeanRef>(); void addBean(BeanRef beanRef) { rejectOnConflict(beanRef); reg.add(beanRef); } private void rejectOnConflict(BeanRef beanRef) { for (BeanRef bean : reg) { if(beanRef.conflictsWith(bean)){ throw new ConflictDetected(beanRef, bean); } } } BeanRef getMatching(BeanTemplate template) { for (BeanRef bean : reg) { if (bean.matches(template)) { return bean; } } return null; } List<BeanRef> getAllMatching(BeanTemplate template) { List<BeanRef> refs = new ArrayList<>(); for (BeanRef bean : reg) { if (bean.matches(template)) { refs.add(bean); } } return refs; } }
9,356
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/RefCollection.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.model; import org.apache.aries.blueprint.plugin.handlers.Handlers; import org.apache.aries.blueprint.plugin.spi.CollectionDependencyAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.XmlWriter; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.Set; class RefCollection implements XmlWriter { private final String type; private final List<String> refs; private RefCollection(String type, List<String> refs) { this.type = type; this.refs = refs; } static RefCollection getRefCollection(BlueprintRegistry blueprintRegistry, Class<?> injectedType, Annotation[] annotations) { List<String> refCollection = getMatchingRefs(blueprintRegistry, annotations); if (refCollection == null) { return null; } String collectionType = recognizeCollectionType(injectedType); return new RefCollection(collectionType, refCollection); } static RefCollection getRefCollection(BlueprintRegistry blueprintRegistry, Field field) { return getRefCollection(blueprintRegistry, field.getType(), field.getAnnotations()); } static RefCollection getRefCollection(BlueprintRegistry blueprintRegistry, Method method) { return getRefCollection(blueprintRegistry, method.getParameterTypes()[0], method.getAnnotations()); } private static String recognizeCollectionType(Class<?> type) { if (type.isAssignableFrom(List.class)) { return "list"; } if (type.isAssignableFrom(Set.class)) { return "set"; } if (type.isArray()) { return "array"; } throw new IllegalStateException("Expecting that class " + type.getName() + " will be Set, List or Array"); } private static List<String> getMatchingRefs(BlueprintRegistry blueprintRegistry, Annotation[] annotations) { for (CollectionDependencyAnnotationHandler<? extends Annotation> collectionDependencyAnnotationHandler : Handlers.COLLECTION_DEPENDENCY_ANNOTATION_HANDLERS) { Annotation annotation = (Annotation) AnnotationHelper.findAnnotation(annotations, collectionDependencyAnnotationHandler.getAnnotation()); if (annotation != null) { Class<?> classCollection = collectionDependencyAnnotationHandler.getBeanClass(annotation); List<BeanRef> refs = blueprintRegistry.getAllMatching(new BeanTemplate(classCollection, annotations)); List<String> refList = new ArrayList<>(); for (BeanRef ref : refs) { refList.add(ref.id); } return refList; } } return null; } @Override public void write(XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement(type); for (String componentId : refs) { writer.writeEmptyElement("ref"); writer.writeAttribute("component-id", componentId); } writer.writeEndElement(); } }
9,357
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanFromFactory.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.model; import org.apache.aries.blueprint.plugin.handlers.Handlers; import org.apache.aries.blueprint.plugin.spi.BeanAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.ContextEnricher; import java.lang.reflect.Method; class BeanFromFactory extends Bean { private static final String BLUEPRINT_BEAN_FROM_FACTORY_NAME_PROPERTY = "blueprint.beanFromFactory.nameFromFactoryMethodName"; private final Method producingMethod; BeanFromFactory(Bean factoryBean, Method factoryMethod, ContextEnricher contextEnricher) { super(factoryMethod.getReturnType(), contextEnricher); String forcedId = AnnotationHelper.findName(factoryMethod.getAnnotations()); if (forcedId != null) { this.id = forcedId; } if (forcedId == null && shouldGetBeanNameFromMethodName(contextEnricher)) { this.id = factoryMethod.getName(); } this.producingMethod = factoryMethod; setScope(factoryMethod); handleCustomBeanAnnotations(); attributes.put("factory-ref", factoryBean.id); attributes.put("factory-method", producingMethod.getName()); } private boolean shouldGetBeanNameFromMethodName(ContextEnricher contextEnricher) { String value = contextEnricher.getBlueprintConfiguration().getCustomParameters().get(BLUEPRINT_BEAN_FROM_FACTORY_NAME_PROPERTY); return Boolean.parseBoolean(value); } private void setScope(Method factoryMethod) { if (AnnotationHelper.findSingletons(factoryMethod.getAnnotations())) { attributes.put("scope", "singleton"); } } private void handleCustomBeanAnnotations() { for (BeanAnnotationHandler beanAnnotationHandler : Handlers.BEAN_ANNOTATION_HANDLERS) { Object annotation = AnnotationHelper.findAnnotation(producingMethod.getAnnotations(), beanAnnotationHandler.getAnnotation()); if (annotation != null) { beanAnnotationHandler.handleBeanAnnotation(producingMethod, id, contextEnricher, this); } } } @Override protected void resolveArguments(BlueprintRegistry matcher) { resolveArguments(matcher, producingMethod.getParameterTypes(), producingMethod.getParameterAnnotations()); } @Override BeanRef toBeanRef() { return new BeanRef(clazz, id, producingMethod.getAnnotations()); } }
9,358
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BlueprintRegistry.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.model; import org.apache.aries.blueprint.plugin.spi.ContextEnricher; import java.util.List; interface BlueprintRegistry extends ContextEnricher { BeanRef getMatching(BeanTemplate template); List<BeanRef> getAllMatching(BeanTemplate template); }
9,359
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.model; import org.apache.aries.blueprint.plugin.handlers.Handlers; import org.apache.aries.blueprint.plugin.spi.BeanAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.BeanEnricher; import org.apache.aries.blueprint.plugin.spi.ContextEnricher; import org.apache.aries.blueprint.plugin.spi.FieldAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.InjectLikeHandler; import org.apache.aries.blueprint.plugin.spi.MethodAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.XmlWriter; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.SortedSet; import java.util.TreeSet; import static org.apache.aries.blueprint.plugin.model.AnnotationHelper.findSingleton; import static org.apache.aries.blueprint.plugin.model.NamingHelper.getBeanName; class Bean implements BeanEnricher, XmlWriter, Comparable<Bean> { private static final String NS_EXT = "http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"; String id; final Class<?> clazz; SortedSet<Property> properties = new TreeSet<>(); List<Argument> constructorArguments = new ArrayList<>(); final Map<String, String> attributes = new HashMap<>(); final Map<String, XmlWriter> beanContentWriters = new HashMap<>(); protected final ContextEnricher contextEnricher; private final Introspector introspector; Bean(Class<?> clazz, ContextEnricher contextEnricher) { this.clazz = clazz; this.id = getBeanName(clazz); this.contextEnricher = contextEnricher; introspector = new Introspector(clazz); setScope(clazz); handleCustomBeanAnnotations(); handleFieldsAnnotation(introspector); handleMethodsAnnotation(introspector); } private void setScope(Class<?> clazz) { attributes.put("scope", findSingleton(clazz) ? "singleton" : "prototype"); } void resolveDependency(BlueprintRegistry blueprintRegistry) { resolveArguments(blueprintRegistry); resolveFields(blueprintRegistry); resolveMethods(blueprintRegistry); } private void handleMethodsAnnotation(Introspector introspector) { for (MethodAnnotationHandler methodAnnotationHandler : Handlers.METHOD_ANNOTATION_HANDLERS) { List<Method> methods = introspector.methodsWith(methodAnnotationHandler.getAnnotation()); if (methods.size() > 0) { methodAnnotationHandler.handleMethodAnnotation(clazz, methods, contextEnricher, this); } } } private void handleFieldsAnnotation(Introspector introspector) { for (FieldAnnotationHandler fieldAnnotationHandler : Handlers.FIELD_ANNOTATION_HANDLERS) { List<Field> fields = introspector.fieldsWith(fieldAnnotationHandler.getAnnotation()); if (fields.size() > 0) { fieldAnnotationHandler.handleFieldAnnotation(clazz, fields, contextEnricher, this); } } } private void handleCustomBeanAnnotations() { for (BeanAnnotationHandler beanAnnotationHandler : Handlers.BEAN_ANNOTATION_HANDLERS) { Object annotation = AnnotationHelper.findAnnotation(clazz.getAnnotations(), beanAnnotationHandler.getAnnotation()); if (annotation != null) { beanAnnotationHandler.handleBeanAnnotation(clazz, id, contextEnricher, this); } } } private void resolveMethods(BlueprintRegistry blueprintRegistry) { for (Method method : introspector.methodsWith(AnnotationHelper.injectDependencyAnnotations)) { Property prop = Property.create(blueprintRegistry, method); if (prop != null) { properties.add(prop); } } } private void resolveFields(BlueprintRegistry matcher) { for (Field field : introspector.fieldsWith(AnnotationHelper.injectDependencyAnnotations)) { Property prop = Property.create(matcher, field); if (prop != null) { properties.add(prop); } } } protected void resolveArguments(BlueprintRegistry matcher) { Constructor<?>[] declaredConstructors = clazz.getDeclaredConstructors(); for (Constructor constructor : declaredConstructors) { if (declaredConstructors.length == 1 || shouldInject(constructor)) { resolveArguments(matcher, constructor.getParameterTypes(), constructor.getParameterAnnotations()); break; } } } private boolean shouldInject(AnnotatedElement annotatedElement) { for (InjectLikeHandler injectLikeHandler : Handlers.BEAN_INJECT_LIKE_HANDLERS) { if (annotatedElement.getAnnotation(injectLikeHandler.getAnnotation()) != null) { return true; } } return false; } void resolveArguments(BlueprintRegistry blueprintRegistry, Class[] parameterTypes, Annotation[][] parameterAnnotations) { for (int i = 0; i < parameterTypes.length; ++i) { constructorArguments.add(new Argument(blueprintRegistry, parameterTypes[i], parameterAnnotations[i])); } } private void writeProperties(XMLStreamWriter writer) throws XMLStreamException { for (Property property : properties) { property.write(writer); } } private void writeArguments(XMLStreamWriter writer) throws XMLStreamException { for (Argument argument : constructorArguments) { argument.write(writer); } } private boolean needFieldInjection() { for (Property property : properties) { if (property.isField) { return true; } } return false; } @Override public void addAttribute(String key, String value) { attributes.put(key, value); } @Override public void addBeanContentWriter(String id, XmlWriter blueprintWriter) { beanContentWriters.put(id, blueprintWriter); } private void writeCustomContent(XMLStreamWriter writer) throws XMLStreamException { List<String> customWriterKeys = new ArrayList<>(beanContentWriters.keySet()); Collections.sort(customWriterKeys); for (String customWriterKey : customWriterKeys) { beanContentWriters.get(customWriterKey).write(writer); } } private void writeAttributes(XMLStreamWriter writer) throws XMLStreamException { for (Map.Entry<String, String> entry : attributes.entrySet()) { if ("scope".equals(entry.getKey()) && "singleton".equals(entry.getValue())) { continue; } writer.writeAttribute(entry.getKey(), entry.getValue()); } } @Override public void write(XMLStreamWriter writer) throws XMLStreamException { writeBeanStart(writer); writeCustomContent(writer); writeArguments(writer); writeProperties(writer); writer.writeEndElement(); } private void writeBeanStart(XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement("bean"); writer.writeAttribute("id", id); writer.writeAttribute("class", clazz.getName()); if (needFieldInjection()) { writer.writeNamespace("ext", NS_EXT); writer.writeAttribute("ext", NS_EXT, "field-injection", "true"); } writeAttributes(writer); } BeanRef toBeanRef() { return new BeanRef(clazz, id, clazz.getAnnotations()); } @Override public int compareTo(Bean o) { return id.compareTo(o.id); } }
9,360
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Introspector.java
/** * 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.aries.blueprint.plugin.model; import com.google.common.base.Preconditions; import com.google.common.collect.HashMultimap; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import com.google.common.collect.Sets; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Set; /** * Class to find uniquely-named fields declared in a class hierarchy with specified annotations. */ final class Introspector { private final Class<?> originalClazz; /** * @param clazz the class to introspect (including those defined in parent classes). */ Introspector(Class<?> clazz) { this.originalClazz = clazz; } /** * @param requiredAnnotations annotations the fields must have * @return fields in the given class (including parent classes) that match this finder's annotations requirements. * @throws UnsupportedOperationException if any field matching the annotations requirement shares its name with a * field declared elsewhere in the class hierarchy. */ @SafeVarargs final List<Field> fieldsWith(Class<? extends Annotation>... requiredAnnotations) { Multimap<String, Field> fieldsByName = HashMultimap.create(); Set<String> acceptedFieldNames = Sets.newHashSet(); Class<?> clazz = originalClazz; // For each parent class of clazz... while(clazz != null && clazz != Object.class) { for (Field field : clazz.getDeclaredFields()) { // ...add all declared fields fieldsByName.put(field.getName(), field); // ...and if it meets the annotation requirement, add the field name to the set of accepted field names if (hasAnyRequiredAnnotation(field, requiredAnnotations)) { acceptedFieldNames.add(field.getName()); } } clazz = clazz.getSuperclass(); } // Add all accepted fields to acceptedFields List<Field> acceptedFields = Lists.newArrayList(); for (String fieldName : acceptedFieldNames) { Collection<Field> fields = fieldsByName.get(fieldName); validateOnlyOneFieldWithName(fieldName, fields); acceptedFields.addAll(fields); } return acceptedFields; } /** * Check that each field name is defined no more than once * @param acceptedFieldName * @param acceptedFieldsWithSameName */ private void validateOnlyOneFieldWithName(String acceptedFieldName, Collection<Field> acceptedFieldsWithSameName) { if (acceptedFieldsWithSameName.size() > 1) { String header = String.format("Field '%s' in bean class '%s' has been defined multiple times in:", acceptedFieldName, originalClazz.getName()); StringBuilder msgBuilder = new StringBuilder(header); for (Field field : acceptedFieldsWithSameName) { msgBuilder.append("\n\t- ").append(field.getDeclaringClass().getName()); } throw new UnsupportedOperationException(msgBuilder.toString()); } } @SafeVarargs private final boolean hasAnyRequiredAnnotation(Field field, Class<? extends Annotation>... requiredAnnotations) { if (requiredAnnotations.length == 0) { throw new IllegalArgumentException("Must specify at least one annotation"); } for (Class<? extends Annotation> requiredAnnotation : requiredAnnotations) { if (field.getAnnotation(requiredAnnotation) != null) { return true; } } return false; } @SafeVarargs final List<Method> methodsWith(Class<? extends Annotation>... annotationClasses) { List<Method> methods = new ArrayList<>(); for (Method method : originalClazz.getMethods()) { for(Class<? extends Annotation> annotationClass : annotationClasses) { if (method.getAnnotation(annotationClass) != null) { methods.add(method); break; } } } return methods; } }
9,361
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Blueprint.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.model; import org.apache.aries.blueprint.plugin.handlers.Handlers; import org.apache.aries.blueprint.plugin.spi.BlueprintConfiguration; import org.apache.aries.blueprint.plugin.spi.ContextEnricher; import org.apache.aries.blueprint.plugin.spi.ContextInitializationHandler; import org.apache.aries.blueprint.plugin.spi.XmlWriter; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; public class Blueprint implements BlueprintRegistry, ContextEnricher, XmlWriter { private static final String NS_BLUEPRINT = "http://www.osgi.org/xmlns/blueprint/v1.0.0"; private final BeanRefStore beanRefStore = new BeanRefStore(); private final Map<String, XmlWriter> customWriters = new HashMap<>(); private final BlueprintConfiguration blueprintConfiguration; private final List<Bean> generatedBeans = new ArrayList<>(); Blueprint(BlueprintConfiguration blueprintConfiguration, Class<?>... beanClasses) { this(blueprintConfiguration, Arrays.asList(beanClasses)); } public Blueprint(BlueprintConfiguration blueprintConfiguration, Collection<Class<?>> beanClasses) { this.blueprintConfiguration = blueprintConfiguration; initContext(); parseBeans(beanClasses); resolveDependency(); } private void initContext() { for (ContextInitializationHandler contextInitializationHandler : Handlers.CONTEXT_INITIALIZATION_HANDLERS) { contextInitializationHandler.initContext(this); } } private void parseBeans(Collection<Class<?>> beanClasses) { for (Class<?> clazz : beanClasses) { parseBean(clazz); } } private void parseBean(Class<?> clazz) { Bean bean = new Bean(clazz, this); beanRefStore.addBean(bean.toBeanRef()); generatedBeans.add(bean); addBeansFromFactories(bean); } private void addBeansFromFactories(Bean factoryBean) { for (Method method : factoryBean.clazz.getMethods()) { if (!isFactoryMethod(method)) { continue; } BeanFromFactory beanFromFactory = new BeanFromFactory(factoryBean, method, this); beanRefStore.addBean(beanFromFactory.toBeanRef()); generatedBeans.add(beanFromFactory); } } private boolean isFactoryMethod(Method method) { boolean isFactoryMethod = false; for (Class<? extends Annotation> factoryMethodAnnotationClass : Handlers.FACTORY_METHOD_ANNOTATION_CLASSES) { Annotation annotation = AnnotationHelper.findAnnotation(method.getAnnotations(), factoryMethodAnnotationClass); if (annotation != null) { isFactoryMethod = true; break; } } return isFactoryMethod; } private void resolveDependency() { for (Bean bean : generatedBeans) { bean.resolveDependency(this); } } public BeanRef getMatching(BeanTemplate template) { return beanRefStore.getMatching(template); } public List<BeanRef> getAllMatching(BeanTemplate template) { return beanRefStore.getAllMatching(template); } Collection<Bean> getBeans() { return generatedBeans; } Map<String, XmlWriter> getCustomWriters() { return customWriters; } @Override public void addBean(String id, Class<?> clazz) { beanRefStore.addBean(new BeanRef(clazz, id, new Annotation[]{})); } @Override public void addBlueprintContentWriter(String id, XmlWriter blueprintWriter) { customWriters.put(id, blueprintWriter); } @Override public BlueprintConfiguration getBlueprintConfiguration() { return blueprintConfiguration; } public void write(XMLStreamWriter writer) throws XMLStreamException { writeBlueprint(writer); writeTypeConverters(writer); writeBeans(writer); writeCustomWriters(writer); writer.writeEndElement(); } private void writeTypeConverters(XMLStreamWriter writer) throws XMLStreamException { new CustomTypeConverterWriter(beanRefStore).write(writer); } private void writeCustomWriters(XMLStreamWriter writer) throws XMLStreamException { List<String> customWriterKeys = new ArrayList<>(customWriters.keySet()); Collections.sort(customWriterKeys); for (String customWriterKey : customWriterKeys) { customWriters.get(customWriterKey).write(writer); } } private void writeBeans(XMLStreamWriter writer) throws XMLStreamException { Collections.sort(generatedBeans); for (Bean beanWriter : generatedBeans) { beanWriter.write(writer); } } private void writeBlueprint(XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement("blueprint"); writer.writeDefaultNamespace(NS_BLUEPRINT); if (blueprintConfiguration.getDefaultActivation() != null) { writer.writeAttribute("default-activation", blueprintConfiguration.getDefaultActivation().toString()); } if (blueprintConfiguration.getDefaultAvailability() != null) { writer.writeAttribute("default-availability", blueprintConfiguration.getDefaultAvailability().toString()); } if (blueprintConfiguration.getDefaultTimeout() != null) { writer.writeAttribute("default-timeout", blueprintConfiguration.getDefaultTimeout().toString()); } } public boolean shouldBeGenerated() { return !getBeans().isEmpty(); } }
9,362
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/CustomTypeConverterWriter.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.model; import org.apache.aries.blueprint.plugin.spi.XmlWriter; import org.osgi.service.blueprint.container.Converter; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import java.lang.annotation.Annotation; import java.util.List; class CustomTypeConverterWriter implements XmlWriter { private static final String defaultBlueprintConverter = "blueprintConverter"; private final BeanRefStore beanRefStore; CustomTypeConverterWriter(BeanRefStore beanRefStore) { this.beanRefStore = beanRefStore; } public void write(XMLStreamWriter writer) throws XMLStreamException { List<BeanRef> typeConverters = beanRefStore.getAllMatching(new BeanTemplate(Converter.class, new Annotation[0])); if (hasCustomTypeConverters(typeConverters)) { return; } writer.writeStartElement("type-converters"); for (BeanRef typeConverter : typeConverters) { if (defaultBlueprintConverter.equals(typeConverter.id)) { continue; } writer.writeEmptyElement("ref"); writer.writeAttribute("component-id", typeConverter.id); } writer.writeEndElement(); } private boolean hasCustomTypeConverters(List<BeanRef> typeConverters) { return typeConverters.isEmpty() || typeConverters.size() == 1 && "blueprintConverter".equals(typeConverters.get(0).id); } }
9,363
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/Handlers.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.handlers; import org.apache.aries.blueprint.plugin.spi.BeanAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.BeanFinder; import org.apache.aries.blueprint.plugin.spi.CollectionDependencyAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.ContextInitializationHandler; import org.apache.aries.blueprint.plugin.spi.CustomDependencyAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.FactoryMethodFinder; import org.apache.aries.blueprint.plugin.spi.FieldAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.InjectLikeHandler; import org.apache.aries.blueprint.plugin.spi.MethodAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.NamedLikeHandler; import org.apache.aries.blueprint.plugin.spi.QualifingAnnotationFinder; import org.apache.aries.blueprint.plugin.spi.ValueInjectionHandler; import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.List; import java.util.ServiceLoader; public class Handlers { public static final List<Class<? extends Annotation>> BEAN_MARKING_ANNOTATION_CLASSES = new ArrayList<>(); public static final List<Class<? extends Annotation>> SINGLETONS = new ArrayList<>(); public static final List<InjectLikeHandler<? extends Annotation>> BEAN_INJECT_LIKE_HANDLERS = new ArrayList<>(); public static final List<NamedLikeHandler> NAMED_LIKE_HANDLERS = new ArrayList<>(); public static final List<ValueInjectionHandler<? extends Annotation>> VALUE_INJECTION_HANDLERS = new ArrayList<>(); public static final List<BeanAnnotationHandler<? extends Annotation>> BEAN_ANNOTATION_HANDLERS = new ArrayList<>(); public static final List<CustomDependencyAnnotationHandler<? extends Annotation>> CUSTOM_DEPENDENCY_ANNOTATION_HANDLERS = new ArrayList<>(); public static final List<MethodAnnotationHandler<? extends Annotation>> METHOD_ANNOTATION_HANDLERS = new ArrayList<>(); public static final List<FieldAnnotationHandler<? extends Annotation>> FIELD_ANNOTATION_HANDLERS = new ArrayList<>(); public static final List<Class<? extends Annotation>> FACTORY_METHOD_ANNOTATION_CLASSES = new ArrayList<>(); public static final List<Class<? extends Annotation>> QUALIFING_ANNOTATION_CLASSES = new ArrayList<>(); public static final List<ContextInitializationHandler> CONTEXT_INITIALIZATION_HANDLERS = new ArrayList<>(); public static final List<CollectionDependencyAnnotationHandler<? extends Annotation>> COLLECTION_DEPENDENCY_ANNOTATION_HANDLERS = new ArrayList<>(); static { for (BeanFinder beanFinder : ServiceLoader.load(BeanFinder.class)) { BEAN_MARKING_ANNOTATION_CLASSES.add(beanFinder.getAnnotation()); if (beanFinder.isSingleton()) { SINGLETONS.add(beanFinder.getAnnotation()); } } for (InjectLikeHandler<? extends Annotation> injectLikeHandler : ServiceLoader.load(InjectLikeHandler.class)) { BEAN_INJECT_LIKE_HANDLERS.add(injectLikeHandler); } for (NamedLikeHandler namedLikeHandler : ServiceLoader.load(NamedLikeHandler.class)) { NAMED_LIKE_HANDLERS.add(namedLikeHandler); } for (ValueInjectionHandler<? extends Annotation> valueInjectionHandler : ServiceLoader.load(ValueInjectionHandler.class)) { VALUE_INJECTION_HANDLERS.add(valueInjectionHandler); } for (BeanAnnotationHandler<? extends Annotation> beanAnnotationHandler : ServiceLoader.load(BeanAnnotationHandler.class)) { BEAN_ANNOTATION_HANDLERS.add(beanAnnotationHandler); } for (CustomDependencyAnnotationHandler<? extends Annotation> customDependencyAnnotationHandler : ServiceLoader.load(CustomDependencyAnnotationHandler.class)) { CUSTOM_DEPENDENCY_ANNOTATION_HANDLERS.add(customDependencyAnnotationHandler); } for (MethodAnnotationHandler<? extends Annotation> methodAnnotationHandler : ServiceLoader.load(MethodAnnotationHandler.class)) { METHOD_ANNOTATION_HANDLERS.add(methodAnnotationHandler); } for (FieldAnnotationHandler<? extends Annotation> fieldAnnotationHandler : ServiceLoader.load(FieldAnnotationHandler.class)) { FIELD_ANNOTATION_HANDLERS.add(fieldAnnotationHandler); } for (FactoryMethodFinder<? extends Annotation> factoryMethodFinder : ServiceLoader.load(FactoryMethodFinder.class)) { FACTORY_METHOD_ANNOTATION_CLASSES.add((Class<? extends Annotation>) factoryMethodFinder.getAnnotation()); } for (QualifingAnnotationFinder<? extends Annotation> qualifingAnnotationFinder : ServiceLoader.load(QualifingAnnotationFinder.class)) { QUALIFING_ANNOTATION_CLASSES.add((Class<? extends Annotation>) qualifingAnnotationFinder.getAnnotation()); } for (CollectionDependencyAnnotationHandler<? extends Annotation> collectionDependencyAnnotationHandler : ServiceLoader.load(CollectionDependencyAnnotationHandler.class)) { COLLECTION_DEPENDENCY_ANNOTATION_HANDLERS.add(collectionDependencyAnnotationHandler); } for (ContextInitializationHandler contextInitializationHandler : ServiceLoader.load(ContextInitializationHandler.class)) { CONTEXT_INITIALIZATION_HANDLERS.add(contextInitializationHandler); } } }
9,364
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/javax/InjectHandler.java
/** * 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.aries.blueprint.plugin.handlers.javax; import org.apache.aries.blueprint.plugin.spi.InjectLikeHandler; import javax.inject.Inject; public class InjectHandler implements InjectLikeHandler<Inject> { @Override public Class<Inject> getAnnotation() { return Inject.class; } }
9,365
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/javax/PersistenceContextHandler.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.handlers.javax; import org.apache.aries.blueprint.plugin.spi.BeanEnricher; import org.apache.aries.blueprint.plugin.spi.ContextEnricher; import org.apache.aries.blueprint.plugin.spi.FieldAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.XmlWriter; import javax.persistence.PersistenceContext; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import java.lang.reflect.Field; import java.util.List; public class PersistenceContextHandler implements FieldAnnotationHandler<PersistenceContext> { @Override public Class<PersistenceContext> getAnnotation() { return PersistenceContext.class; } @Override public void handleFieldAnnotation(Class<?> clazz, List<Field> fields, ContextEnricher contextEnricher, BeanEnricher beanEnricher) { final String nsJpa1 = Namespaces.getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), Namespaces.PATTERN_NS_JPA1); if (nsJpa1 != null) { for (final Field field : fields) { final String name = field.getName(); final PersistenceContext persistenceContext = field.getAnnotation(PersistenceContext.class); beanEnricher.addBeanContentWriter("javax.persistence.field.context/" + name, new XmlWriter() { @Override public void write(XMLStreamWriter writer) throws XMLStreamException { writer.writeEmptyElement("context"); writer.writeDefaultNamespace(nsJpa1); writer.writeAttribute("unitname", persistenceContext.unitName()); writer.writeAttribute("property", name); } }); } } final String nsJpa2 = Namespaces.getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), Namespaces.PATTERN_NS_JPA2); if (nsJpa2 != null) { contextEnricher.addBlueprintContentWriter("javax.persistence.enableJpa2", new XmlWriter() { @Override public void write(XMLStreamWriter writer) throws XMLStreamException { writer.writeEmptyElement("enable"); writer.writeDefaultNamespace(nsJpa2); } }); } } }
9,366
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/javax/PostConstructHandler.java
/** * 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.aries.blueprint.plugin.handlers.javax; import org.apache.aries.blueprint.plugin.spi.BeanEnricher; import org.apache.aries.blueprint.plugin.spi.ContextEnricher; import org.apache.aries.blueprint.plugin.spi.MethodAnnotationHandler; import javax.annotation.PostConstruct; import java.lang.reflect.Method; import java.util.List; public class PostConstructHandler implements MethodAnnotationHandler<PostConstruct> { @Override public Class<PostConstruct> getAnnotation() { return PostConstruct.class; } @Override public void handleMethodAnnotation(Class<?> clazz, List<Method> methods, ContextEnricher contextEnricher, BeanEnricher beanEnricher) { if(methods.size() > 1){ throw new IllegalArgumentException("There can be only one method annotated with @PostConstruct in bean"); } beanEnricher.addAttribute("init-method", methods.get(0).getName()); } }
9,367
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/javax/CdiTransactionFactory.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.handlers.javax; import com.google.common.base.CaseFormat; import org.apache.aries.blueprint.plugin.handlers.javax.AbstractTransactionFactory; import org.apache.aries.blueprint.plugin.spi.BeanAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.BeanEnricher; import org.apache.aries.blueprint.plugin.spi.BlueprintConfiguration; import org.apache.aries.blueprint.plugin.spi.ContextEnricher; import org.apache.aries.blueprint.plugin.spi.MethodAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.XmlWriter; import javax.transaction.cdi.Transactional; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Method; import java.util.List; import java.util.Set; public class CdiTransactionFactory extends AbstractTransactionFactory<Transactional> { String getTransactionTypeName(AnnotatedElement annotatedElement) { final Transactional transactional = annotatedElement.getAnnotation(Transactional.class); return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, transactional.value().name()); } @Override public Class<Transactional> getAnnotation() { return Transactional.class; } }
9,368
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/javax/NamedBeanFinder.java
/** * 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.aries.blueprint.plugin.handlers.javax; import javax.inject.Named; public class NamedBeanFinder implements org.apache.aries.blueprint.plugin.spi.BeanFinder<Named> { @Override public Class<Named> getAnnotation() { return Named.class; } @Override public boolean isSingleton() { return false; } }
9,369
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/javax/Namespaces.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.handlers.javax; import java.util.Set; class Namespaces { static final String PATTERN_NS_JPA1 = "http\\:\\/\\/aries\\.apache\\.org\\/xmlns\\/jpa\\/v1\\.(.)\\.(.)"; static final String PATTERN_NS_JPA2 = "http\\:\\/\\/aries\\.apache\\.org\\/xmlns\\/jpa\\/v2\\.(.)\\.(.)"; static final String PATTERN_NS_TX1 = "http\\:\\/\\/aries\\.apache\\.org\\/xmlns\\/transactions\\/v1\\.(.)\\.(.)"; static final String PATTERN_NS_TX2 = "http\\:\\/\\/aries\\.apache\\.org\\/xmlns\\/transactions\\/v2\\.(.)\\.(.)"; private static final String NS_TX_1_2_0 = "http://aries.apache.org/xmlns/transactions/v1.2.0"; static String getNamespaceByPattern(Set<String> namespaces, String pattern) { for (String namespace : namespaces) { if (namespace.matches(pattern)) { return namespace; } } return null; } static boolean isTX12(String namespace) { return NS_TX_1_2_0.equals(namespace); } }
9,370
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/javax/PersistenceUnitHandler.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.handlers.javax; import org.apache.aries.blueprint.plugin.spi.BeanEnricher; import org.apache.aries.blueprint.plugin.spi.ContextEnricher; import org.apache.aries.blueprint.plugin.spi.FieldAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.XmlWriter; import javax.persistence.PersistenceUnit; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import java.lang.reflect.Field; import java.util.List; import static org.apache.aries.blueprint.plugin.handlers.javax.Namespaces.PATTERN_NS_JPA1; import static org.apache.aries.blueprint.plugin.handlers.javax.Namespaces.PATTERN_NS_JPA2; import static org.apache.aries.blueprint.plugin.handlers.javax.Namespaces.getNamespaceByPattern; public class PersistenceUnitHandler implements FieldAnnotationHandler<PersistenceUnit> { @Override public Class<PersistenceUnit> getAnnotation() { return PersistenceUnit.class; } @Override public void handleFieldAnnotation(Class<?> clazz, List<Field> fields, ContextEnricher contextEnricher, BeanEnricher beanEnricher) { final String nsJpa1 = getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), PATTERN_NS_JPA1); if (nsJpa1 != null) { for (final Field field : fields) { final String name = field.getName(); final PersistenceUnit persistenceUnit = field.getAnnotation(PersistenceUnit.class); beanEnricher.addBeanContentWriter("javax.persistence.field.unit/" + name, new XmlWriter() { @Override public void write(XMLStreamWriter writer) throws XMLStreamException { writer.writeEmptyElement("unit"); writer.writeDefaultNamespace(nsJpa1); writer.writeAttribute("unitname", persistenceUnit.unitName()); writer.writeAttribute("property", name); } }); } } final String nsJpa2 = getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), PATTERN_NS_JPA2); if (nsJpa2 != null) { contextEnricher.addBlueprintContentWriter("javax.persistence.enableJpa2", new XmlWriter() { @Override public void write(XMLStreamWriter writer) throws XMLStreamException { writer.writeEmptyElement("enable"); writer.writeDefaultNamespace(nsJpa2); } }); } } }
9,371
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/javax/QualifierHandler.java
/** * 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.aries.blueprint.plugin.handlers.javax; import org.apache.aries.blueprint.plugin.spi.QualifingAnnotationFinder; import javax.inject.Qualifier; public class QualifierHandler implements QualifingAnnotationFinder<Qualifier> { @Override public Class<Qualifier> getAnnotation() { return Qualifier.class; } }
9,372
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/javax/PreDestroyHandler.java
/** * 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.aries.blueprint.plugin.handlers.javax; import org.apache.aries.blueprint.plugin.spi.BeanEnricher; import org.apache.aries.blueprint.plugin.spi.ContextEnricher; import org.apache.aries.blueprint.plugin.spi.MethodAnnotationHandler; import javax.annotation.PreDestroy; import java.lang.reflect.Method; import java.util.List; public class PreDestroyHandler implements MethodAnnotationHandler<PreDestroy> { @Override public Class<PreDestroy> getAnnotation() { return PreDestroy.class; } @Override public void handleMethodAnnotation(Class<?> clazz, List<Method> methods, ContextEnricher contextEnricher, BeanEnricher beanEnricher) { if(methods.size() > 1){ throw new IllegalArgumentException("There can be only one method annotated with @PreDestroy in bean"); } beanEnricher.addAttribute("destroy-method", methods.get(0).getName()); } }
9,373
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/javax/SingletonBeanFinder.java
/** * 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.aries.blueprint.plugin.handlers.javax; import javax.inject.Singleton; public class SingletonBeanFinder implements org.apache.aries.blueprint.plugin.spi.BeanFinder<Singleton> { @Override public Class<Singleton> getAnnotation() { return Singleton.class; } @Override public boolean isSingleton() { return true; } }
9,374
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/javax/AbstractTransactionFactory.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.handlers.javax; import org.apache.aries.blueprint.plugin.spi.*; import javax.transaction.Transactional; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Method; import java.util.List; abstract class AbstractTransactionFactory<T extends Annotation> implements BeanAnnotationHandler<T>, MethodAnnotationHandler<T> { abstract String getTransactionTypeName(AnnotatedElement annotatedElement); private static final String ENABLE_ANNOTATION = "transaction.enableAnnotation"; @Override public void handleMethodAnnotation(Class<?> clazz, List<Method> methods, ContextEnricher contextEnricher, BeanEnricher beanEnricher) { final String nsTx1 = Namespaces.getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), Namespaces.PATTERN_NS_TX1); if (nsTx1 != null) { enableAnnotationTx1(contextEnricher, nsTx1); for (final Method method : methods) { final String transactionTypeName = getTransactionTypeName(method); final String name = method.getName(); beanEnricher.addBeanContentWriter("javax.transactional.method/" + clazz.getName() + "/" + name + "/" + transactionTypeName, new XmlWriter() { @Override public void write(XMLStreamWriter writer) throws XMLStreamException { writer.writeEmptyElement("transaction"); writer.writeDefaultNamespace(nsTx1); writer.writeAttribute("method", name); writer.writeAttribute("value", transactionTypeName); } }); } } final String nsTx2 = Namespaces.getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), Namespaces.PATTERN_NS_TX2); if (nsTx2 != null) { insertEnableAnnotationTx2(contextEnricher, nsTx2); } } @Override public void handleBeanAnnotation(AnnotatedElement annotatedElement, String id, ContextEnricher contextEnricher, BeanEnricher beanEnricher) { final String nsTx1 = Namespaces.getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), Namespaces.PATTERN_NS_TX1); if (nsTx1 != null) { enableAnnotationTx1(contextEnricher, nsTx1); final String transactionTypeName = getTransactionTypeName(annotatedElement); beanEnricher.addBeanContentWriter("javax.transactional.method/" + annotatedElement + "/*/" + transactionTypeName, new XmlWriter() { @Override public void write(XMLStreamWriter writer) throws XMLStreamException { writer.writeEmptyElement("transaction"); writer.writeDefaultNamespace(nsTx1); writer.writeAttribute("method", "*"); writer.writeAttribute("value", transactionTypeName); } }); } final String nsTx2 = Namespaces.getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), Namespaces.PATTERN_NS_TX2); if (nsTx2 != null) { insertEnableAnnotationTx2(contextEnricher, nsTx2); } } private void enableAnnotationTx1(ContextEnricher contextEnricher, final String nsTx1) { // TX1 enable-annotation are valid only in 1.2.0 schema if (Namespaces.isTX12(nsTx1) && getEnableAnnotationConfig(contextEnricher.getBlueprintConfiguration())) { insertEnableAnnotationTx1(contextEnricher, nsTx1); } } private boolean getEnableAnnotationConfig(BlueprintConfiguration blueprintConfig) { String enableAnnotation = blueprintConfig.getCustomParameters().get(ENABLE_ANNOTATION); return enableAnnotation == null || Boolean.parseBoolean(enableAnnotation); } private void insertEnableAnnotationTx1(ContextEnricher contextEnricher, final String namespace) { contextEnricher.addBlueprintContentWriter("transaction/ennable-annotation", new XmlWriter() { @Override public void write(XMLStreamWriter writer) throws XMLStreamException { writer.writeEmptyElement("enable-annotations"); writer.writeDefaultNamespace(namespace); } }); } private void insertEnableAnnotationTx2(ContextEnricher contextEnricher, final String namespace) { contextEnricher.addBlueprintContentWriter("transaction/ennable-annotation", new XmlWriter() { @Override public void write(XMLStreamWriter writer) throws XMLStreamException { writer.writeEmptyElement("enable"); writer.writeDefaultNamespace(namespace); } }); } }
9,375
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/javax/NamedHandler.java
/** * 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.aries.blueprint.plugin.handlers.javax; import org.apache.aries.blueprint.plugin.spi.NamedLikeHandler; import javax.inject.Named; import java.lang.reflect.AnnotatedElement; public class NamedHandler implements NamedLikeHandler { @Override public Class getAnnotation() { return Named.class; } @Override public String getName(Class clazz, AnnotatedElement annotatedElement) { Named annotation = annotatedElement.getAnnotation(Named.class); if (annotation.value() == null || "".equals(annotation.value())) { return null; } return annotation.value(); } @Override public String getName(Object annotation) { Named named = Named.class.cast(annotation); if (named.value() == null || "".equals(named.value())) { return null; } return named.value(); } }
9,376
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/javax/JavaxTransactionFactory.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.handlers.javax; import com.google.common.base.CaseFormat; import org.apache.aries.blueprint.plugin.spi.BeanAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.BeanEnricher; import org.apache.aries.blueprint.plugin.spi.BlueprintConfiguration; import org.apache.aries.blueprint.plugin.spi.ContextEnricher; import org.apache.aries.blueprint.plugin.spi.MethodAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.XmlWriter; import javax.transaction.Transactional; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Method; import java.util.List; public class JavaxTransactionFactory extends AbstractTransactionFactory<Transactional> { String getTransactionTypeName(AnnotatedElement annotatedElement) { Transactional transactional = annotatedElement.getAnnotation(Transactional.class); return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, transactional.value().name()); } @Override public Class<Transactional> getAnnotation() { return Transactional.class; } }
9,377
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/javax/ProducesHandler.java
/** * 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.aries.blueprint.plugin.handlers.javax; import org.apache.aries.blueprint.plugin.spi.FactoryMethodFinder; import javax.enterprise.inject.Produces; public class ProducesHandler implements FactoryMethodFinder<Produces> { @Override public Class<Produces> getAnnotation() { return Produces.class; } }
9,378
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint/init/BlueprintInitialization.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.handlers.blueprint.init; import org.apache.aries.blueprint.plugin.spi.ContextEnricher; import org.apache.aries.blueprint.plugin.spi.ContextInitializationHandler; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.service.blueprint.container.BlueprintContainer; import org.osgi.service.blueprint.container.Converter; public class BlueprintInitialization implements ContextInitializationHandler { @Override public void initContext(ContextEnricher contextEnricher) { contextEnricher.addBean("blueprintBundleContext", BundleContext.class); contextEnricher.addBean("blueprintBundle", Bundle.class); contextEnricher.addBean("blueprintContainer", BlueprintContainer.class); contextEnricher.addBean("blueprintConverter", Converter.class); } }
9,379
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint/collection/CollectionInjectHandler.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.handlers.blueprint.collection; import org.apache.aries.blueprint.annotation.collection.CollectionInject; import org.apache.aries.blueprint.plugin.spi.CollectionDependencyAnnotationHandler; import java.lang.annotation.Annotation; public class CollectionInjectHandler implements CollectionDependencyAnnotationHandler<CollectionInject> { @Override public Class<CollectionInject> getAnnotation() { return CollectionInject.class; } @Override public Class<?> getBeanClass(Annotation annotation) { return ((CollectionInject) annotation).value(); } }
9,380
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint/config/ConfigAnnotationHandler.java
/** * 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.aries.blueprint.plugin.handlers.blueprint.config; import java.lang.reflect.AnnotatedElement; import org.apache.aries.blueprint.annotation.config.Config; import org.apache.aries.blueprint.plugin.spi.BeanAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.BeanEnricher; import org.apache.aries.blueprint.plugin.spi.ContextEnricher; public class ConfigAnnotationHandler implements BeanAnnotationHandler<Config>{ @Override public Class<Config> getAnnotation() { return Config.class; } @Override public void handleBeanAnnotation(AnnotatedElement annotatedElement, String id, ContextEnricher contextEnricher, BeanEnricher beanEnricher) { Config config = annotatedElement.getAnnotation(Config.class); contextEnricher.addBlueprintContentWriter("cm/property-placeholder", new ConfigWriter(config)); } }
9,381
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint/config/ConfigPropertiesHandler.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.handlers.blueprint.config; import org.apache.aries.blueprint.annotation.config.ConfigProperties; import org.apache.aries.blueprint.plugin.spi.ContextEnricher; import org.apache.aries.blueprint.plugin.spi.CustomDependencyAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.XmlWriter; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import java.lang.reflect.AnnotatedElement; import java.util.Properties; public class ConfigPropertiesHandler implements CustomDependencyAnnotationHandler<ConfigProperties> { @Override public String handleDependencyAnnotation(AnnotatedElement annotatedElement, String name, ContextEnricher contextEnricher) { ConfigProperties configProperties = annotatedElement.getAnnotation(ConfigProperties.class); final String pid = configProperties.pid(); final boolean update = configProperties.update(); final String id = getId(name, pid, update); enrichContext(contextEnricher, pid, update, id); return id; } private void enrichContext(ContextEnricher contextEnricher, final String pid, final boolean update, final String id) { contextEnricher.addBean(id, Properties.class); contextEnricher.addBlueprintContentWriter("properties/" + id, new XmlWriter() { @Override public void write(XMLStreamWriter writer) throws XMLStreamException { writer.writeEmptyElement("cm-properties"); writer.writeDefaultNamespace("http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.2.0"); writer.writeAttribute("id", id); writer.writeAttribute("persistent-id", pid); writer.writeAttribute("update", String.valueOf(update)); } }); } @Override public String handleDependencyAnnotation(Class<?> aClass, ConfigProperties configProperties, String name, ContextEnricher contextEnricher) { final String pid = configProperties.pid(); final boolean update = configProperties.update(); final String id = getId(name, pid, update); enrichContext(contextEnricher, pid, update, id); return id; } private String getId(String name, String pid, boolean update) { return name != null ? name : "properties-" + pid.replace('.', '-') + "-" + update; } @Override public Class<ConfigProperties> getAnnotation() { return ConfigProperties.class; } }
9,382
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint/config/ConfigWriter.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.handlers.blueprint.config; import org.apache.aries.blueprint.annotation.config.Config; import org.apache.aries.blueprint.annotation.config.DefaultProperty; import org.apache.aries.blueprint.plugin.spi.XmlWriter; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; class ConfigWriter implements XmlWriter { private static final String CONFIG_NS = "http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"; private Config config; ConfigWriter(Config config) { this.config = config; } @Override public void write(XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement("property-placeholder"); writer.writeDefaultNamespace(CONFIG_NS); writer.writeAttribute("persistent-id", config.pid()); if (!"${".equals(config.placeholderPrefix())) { writer.writeAttribute("placeholder-prefix", config.placeholderPrefix()); } if (!"}".equals(config.placeholderSuffix())) { writer.writeAttribute("placeholder-suffix", config.placeholderSuffix()); } writer.writeAttribute("update-strategy", config.updatePolicy()); DefaultProperty[] defaults = config.defaults(); if (defaults.length > 0) { writer.writeStartElement("default-properties"); for (DefaultProperty defaultProp : defaults) { writer.writeEmptyElement("property"); writer.writeAttribute("name", defaultProp.key()); writer.writeAttribute("value", defaultProp.value()); } writer.writeEndElement(); } writer.writeEndElement(); } }
9,383
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint/config/ConfigPropertyInjectionHandler.java
/** * 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.aries.blueprint.plugin.handlers.blueprint.config; import org.apache.aries.blueprint.annotation.config.ConfigProperty; public class ConfigPropertyInjectionHandler implements org.apache.aries.blueprint.plugin.spi.ValueInjectionHandler<ConfigProperty> { @Override public Class<ConfigProperty> getAnnotation() { return ConfigProperty.class; } @Override public String getValue(Object annotation) { return ((ConfigProperty)annotation).value(); } }
9,384
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint/bean/BeanHandler.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.handlers.blueprint.bean; import org.apache.aries.blueprint.annotation.bean.Activation; import org.apache.aries.blueprint.annotation.bean.Bean; import org.apache.aries.blueprint.annotation.bean.Scope; import org.apache.aries.blueprint.plugin.spi.BeanAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.BeanEnricher; import org.apache.aries.blueprint.plugin.spi.BeanFinder; import org.apache.aries.blueprint.plugin.spi.ContextEnricher; import org.apache.aries.blueprint.plugin.spi.FactoryMethodFinder; import org.apache.aries.blueprint.plugin.spi.NamedLikeHandler; import java.lang.reflect.AnnotatedElement; public class BeanHandler implements BeanFinder<Bean>, FactoryMethodFinder<Bean>, NamedLikeHandler<Bean>, BeanAnnotationHandler<Bean> { @Override public boolean isSingleton() { return false; } @Override public Class<Bean> getAnnotation() { return Bean.class; } @Override public String getName(Class clazz, AnnotatedElement annotatedElement) { Bean bean = annotatedElement.getAnnotation(Bean.class); if ("".equals(bean.id())) { return null; } return bean.id(); } @Override public String getName(Object annotation) { Bean bean = Bean.class.cast(annotation); if ("".equals(bean.id())) { return null; } return bean.id(); } @Override public void handleBeanAnnotation(AnnotatedElement annotatedElement, String id, ContextEnricher contextEnricher, BeanEnricher beanEnricher) { Bean annotation = annotatedElement.getAnnotation(Bean.class); if (annotation.activation() != Activation.DEFAULT) { beanEnricher.addAttribute("activation", annotation.activation().name().toLowerCase()); } beanEnricher.addAttribute("scope", annotation.scope() == Scope.SINGLETON ? "singleton" : "prototype"); if (annotation.dependsOn().length > 0) { StringBuilder dependsOn = new StringBuilder(); for (int i = 0; i < annotation.dependsOn().length; i++) { if (i > 0) { dependsOn.append(" "); } dependsOn.append(annotation.dependsOn()[i]); } beanEnricher.addAttribute("depends-on", dependsOn.toString()); } if (!annotation.initMethod().isEmpty()) { beanEnricher.addAttribute("init-method", annotation.initMethod()); } if (!annotation.destroyMethod().isEmpty()) { beanEnricher.addAttribute("destroy-method", annotation.destroyMethod()); } } }
9,385
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint/referencelistener/ReferenceListenerDefinition.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.handlers.blueprint.referencelistener; class ReferenceListenerDefinition { final String ref; final String bind; final String unbind; ReferenceListenerDefinition(String ref, String bind, String unbind) { this.ref = ref; this.bind = getOrNull(bind); this.unbind = getOrNull(unbind); } private static String getOrNull(String unbind) { return unbind == null || unbind.isEmpty() ? null : unbind; } }
9,386
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint/referencelistener/ReferenceListenerHandler.java
/** * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.aries.blueprint.plugin.handlers.blueprint.referencelistener; import org.apache.aries.blueprint.annotation.referencelistener.Bind; import org.apache.aries.blueprint.annotation.referencelistener.Cardinality; import org.apache.aries.blueprint.annotation.referencelistener.ReferenceListener; import org.apache.aries.blueprint.annotation.referencelistener.Unbind; import org.apache.aries.blueprint.plugin.spi.BeanAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.BeanEnricher; import org.apache.aries.blueprint.plugin.spi.ContextEnricher; import org.apache.aries.blueprint.plugin.spi.XmlWriter; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Method; import java.util.List; public class ReferenceListenerHandler implements BeanAnnotationHandler<ReferenceListener> { @Override public void handleBeanAnnotation(AnnotatedElement annotatedElement, String id, ContextEnricher contextEnricher, BeanEnricher beanEnricher) { ReferenceListener annotation = annotatedElement.getAnnotation(ReferenceListener.class); Class<?> referenceListenerClass = getClass(annotatedElement); String bindMethod = annotation.bindMethod().isEmpty() ? getAnnotatedMethodName(referenceListenerClass, Bind.class) : annotation.bindMethod(); String unbindMethod = annotation.unbindMethod().isEmpty() ? getAnnotatedMethodName(referenceListenerClass, Unbind.class) : annotation.unbindMethod(); ReferenceListenerDefinition referenceListenerDefinition = new ReferenceListenerDefinition( id, bindMethod, unbindMethod ); String referenceBeanName = annotation.referenceName().isEmpty() ? createReferenceBeanName(annotation) : annotation.referenceName(); if (annotation.cardinality() == Cardinality.SINGLE) { contextEnricher.addBean(referenceBeanName, annotation.referenceInterface()); createReference(referenceBeanName, referenceListenerDefinition, annotation, contextEnricher); } else { contextEnricher.addBean(referenceBeanName, List.class); createReferenceList(referenceBeanName, referenceListenerDefinition, annotation, contextEnricher); } } private void createReference(final String referenceBeanName, final ReferenceListenerDefinition referenceListenerDefinition, final ReferenceListener annotation, ContextEnricher contextEnricher) { contextEnricher.addBlueprintContentWriter("referenceWithReferenceListener/" + referenceBeanName + "/" + referenceListenerDefinition.ref, new XmlWriter() { @Override public void write(XMLStreamWriter xmlStreamWriter) throws XMLStreamException { xmlStreamWriter.writeStartElement("reference"); xmlStreamWriter.writeAttribute("interface", annotation.referenceInterface().getName()); xmlStreamWriter.writeAttribute("availability", annotation.availability().name().toLowerCase()); xmlStreamWriter.writeAttribute("id", referenceBeanName); if (!annotation.filter().isEmpty()) { xmlStreamWriter.writeAttribute("filter", annotation.filter()); } if (!annotation.componentName().isEmpty()) { xmlStreamWriter.writeAttribute("component-name", annotation.componentName()); } writeReferenceListner(xmlStreamWriter, referenceListenerDefinition); xmlStreamWriter.writeEndElement(); } }); } private void createReferenceList(final String referenceBeanName, final ReferenceListenerDefinition referenceListenerDefinition, final ReferenceListener annotation, ContextEnricher contextEnricher) { contextEnricher.addBlueprintContentWriter("referenceListWithReferenceListener/" + referenceBeanName + "/" + referenceListenerDefinition.ref, new XmlWriter() { @Override public void write(XMLStreamWriter xmlStreamWriter) throws XMLStreamException { xmlStreamWriter.writeStartElement("reference-list"); xmlStreamWriter.writeAttribute("interface", annotation.referenceInterface().getName()); xmlStreamWriter.writeAttribute("availability", annotation.availability().name().toLowerCase()); xmlStreamWriter.writeAttribute("id", referenceBeanName); if (!annotation.filter().isEmpty()) { xmlStreamWriter.writeAttribute("filter", annotation.filter()); } if (!annotation.componentName().isEmpty()) { xmlStreamWriter.writeAttribute("component-name", annotation.componentName()); } writeReferenceListner(xmlStreamWriter, referenceListenerDefinition); xmlStreamWriter.writeEndElement(); } }); } private void writeReferenceListner(XMLStreamWriter xmlStreamWriter, ReferenceListenerDefinition referenceListenerDefinition) throws XMLStreamException { xmlStreamWriter.writeStartElement("reference-listener"); xmlStreamWriter.writeAttribute("ref", referenceListenerDefinition.ref); if (referenceListenerDefinition.bind != null) { xmlStreamWriter.writeAttribute("bind-method", referenceListenerDefinition.bind); } if (referenceListenerDefinition.unbind != null) { xmlStreamWriter.writeAttribute("unbind-method", referenceListenerDefinition.unbind); } xmlStreamWriter.writeEndElement(); } private String createReferenceBeanName(ReferenceListener annotation) { String prefix = getBeanNameFromSimpleName(annotation.referenceInterface().getSimpleName()); String listPart = annotation.cardinality() == Cardinality.SINGLE ? "" : "List"; String suffix = createIdSuffix(annotation); return prefix + listPart + suffix; } private static String getBeanNameFromSimpleName(String name) { return name.substring(0, 1).toLowerCase() + name.substring(1, name.length()); } private String createIdSuffix(ReferenceListener listener) { return createComponentNamePart(listener) + createFilterPart(listener); } private String createComponentNamePart(ReferenceListener listener) { if (!listener.componentName().isEmpty()) { return "-" + listener.componentName(); } return ""; } private String createFilterPart(ReferenceListener listener) { if (!listener.filter().isEmpty()) { return "-" + getId(listener.filter()); } return ""; } private String getId(String raw) { StringBuilder builder = new StringBuilder(); for (int c = 0; c < raw.length(); c++) { char ch = raw.charAt(c); if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9') { builder.append(ch); } } return builder.toString(); } private String getAnnotatedMethodName(Class<?> referenceListenerClass, Class annotation) { for (Method method : referenceListenerClass.getMethods()) { if (method.getAnnotation(annotation) != null) { return method.getName(); } } return null; } @Override public Class<ReferenceListener> getAnnotation() { return ReferenceListener.class; } private Class<?> getClass(AnnotatedElement annotatedElement) { if (annotatedElement instanceof Class<?>) { return (Class<?>) annotatedElement; } if (annotatedElement instanceof Method) { return ((Method) annotatedElement).getReturnType(); } throw new RuntimeException("Unknown annotated element"); } }
9,387
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint/service/ReferenceParameters.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.handlers.blueprint.service; import org.apache.aries.blueprint.plugin.spi.Availability; import org.apache.aries.blueprint.plugin.spi.ContextEnricher; class ReferenceParameters { static boolean needTimeout(long timeout) { return timeout >= 0; } static boolean needAvailability(ContextEnricher contextEnricher, org.apache.aries.blueprint.annotation.service.Availability availability) { Availability defaultAvailability = contextEnricher.getBlueprintConfiguration().getDefaultAvailability(); return defaultAvailability == null && availability.equals(org.apache.aries.blueprint.annotation.service.Availability.OPTIONAL) || defaultAvailability != null && !defaultAvailability.name().equals(availability.name()); } }
9,388
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint/service/ServiceHandler.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.handlers.blueprint.service; import org.apache.aries.blueprint.annotation.service.AutoExport; import org.apache.aries.blueprint.annotation.service.Service; import org.apache.aries.blueprint.plugin.spi.BeanAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.BeanEnricher; import org.apache.aries.blueprint.plugin.spi.ContextEnricher; import org.apache.aries.blueprint.plugin.spi.XmlWriter; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import java.lang.reflect.AnnotatedElement; public class ServiceHandler implements BeanAnnotationHandler<Service> { @Override public Class<Service> getAnnotation() { return Service.class; } @Override public void handleBeanAnnotation(final AnnotatedElement annotatedElement, final String id, ContextEnricher contextEnricher, BeanEnricher beanEnricher) { final Service annotation = annotatedElement.getAnnotation(Service.class); contextEnricher.addBlueprintContentWriter("service/" + id, new XmlWriter() { @Override public void write(XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement("service"); writer.writeAttribute("ref", id); writeRanking(writer, annotation); writeExportSpecification(writer, annotation); new ServicePropertyWriter(annotation.properties(), annotation.ranking()).writeProperties(writer); writer.writeEndElement(); } }); } private void writeRanking(XMLStreamWriter writer, Service annotation) throws XMLStreamException { if (annotation.ranking() != 0) { writer.writeAttribute("ranking", String.valueOf(annotation.ranking())); } } private void writeExportSpecification(XMLStreamWriter writer, Service annotation) throws XMLStreamException { if (annotation.classes().length == 0) { if (annotation.autoExport() != AutoExport.DISABLED) { writer.writeAttribute("auto-export", autoExport(annotation.autoExport())); } } else if (annotation.classes().length == 1) { writer.writeAttribute("interface", annotation.classes()[0].getName()); } else { writeInterfaces(writer, annotation.classes()); } } private String autoExport(AutoExport autoExport) { switch (autoExport) { case INTERFACES: return "interfaces"; case ALL_CLASSES: return "all-classes"; case CLASS_HIERARCHY: return "class-hierarchy"; default: throw new IllegalStateException("unkown " + autoExport); } } private void writeInterfaces(XMLStreamWriter writer, Class<?>[] classes) throws XMLStreamException { writer.writeStartElement("interfaces"); for (Class<?> singleClass : classes) { writer.writeStartElement("value"); writer.writeCharacters(singleClass.getName()); writer.writeEndElement(); } writer.writeEndElement(); } }
9,389
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint/service/ReferenceHandler.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.handlers.blueprint.service; import org.apache.aries.blueprint.annotation.service.Reference; import org.apache.aries.blueprint.plugin.spi.ContextEnricher; import org.apache.aries.blueprint.plugin.spi.CustomDependencyAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.XmlWriter; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Field; import java.lang.reflect.Method; import static org.apache.aries.blueprint.plugin.handlers.blueprint.service.ReferenceParameters.needAvailability; import static org.apache.aries.blueprint.plugin.handlers.blueprint.service.ReferenceParameters.needTimeout; public class ReferenceHandler implements CustomDependencyAnnotationHandler<Reference> { @Override public Class<Reference> getAnnotation() { return Reference.class; } @Override public String handleDependencyAnnotation(AnnotatedElement annotatedElement, String name, ContextEnricher contextEnricher) { Reference reference = annotatedElement.getAnnotation(Reference.class); final Class<?> clazz = getClass(annotatedElement); return handleDependencyAnnotation(clazz, reference, name, contextEnricher); } @Override public String handleDependencyAnnotation(final Class<?> clazz, Reference reference, String name, ContextEnricher contextEnricher) { final String id = name != null ? name : ReferenceId.generateReferenceId(clazz, reference, contextEnricher); contextEnricher.addBean(id, clazz); contextEnricher.addBlueprintContentWriter(getWriterId(id, clazz), getXmlWriter(id, clazz, reference, contextEnricher)); return id; } private XmlWriter getXmlWriter(final String id, final Class<?> clazz, final Reference reference, final ContextEnricher contextEnricher) { return new XmlWriter() { @Override public void write(XMLStreamWriter writer) throws XMLStreamException { writer.writeEmptyElement("reference"); writer.writeAttribute("id", id); writer.writeAttribute("interface", clazz.getName()); if (!"".equals(reference.filter())) { writer.writeAttribute("filter", reference.filter()); } if (!"".equals(reference.componentName())) { writer.writeAttribute("component-name", reference.componentName()); } if (needTimeout(reference.timeout())) { writer.writeAttribute("timeout", String.valueOf(reference.timeout())); } if (needAvailability(contextEnricher, reference.availability())) { writer.writeAttribute("availability", reference.availability().name().toLowerCase()); } } }; } private String getWriterId(String id, Class<?> clazz) { return "reference/" + clazz.getName() + "/" + id; } private Class<?> getClass(AnnotatedElement annotatedElement) { if (annotatedElement instanceof Class<?>) { return (Class<?>) annotatedElement; } if (annotatedElement instanceof Method) { return ((Method) annotatedElement).getParameterTypes()[0]; } if (annotatedElement instanceof Field) { return ((Field) annotatedElement).getType(); } throw new RuntimeException("Unknown annotated element"); } }
9,390
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint/service/ReferenceListHandler.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.handlers.blueprint.service; import org.apache.aries.blueprint.annotation.service.MemberType; import org.apache.aries.blueprint.annotation.service.ReferenceList; import org.apache.aries.blueprint.plugin.spi.ContextEnricher; import org.apache.aries.blueprint.plugin.spi.CustomDependencyAnnotationHandler; import org.apache.aries.blueprint.plugin.spi.XmlWriter; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.List; import static org.apache.aries.blueprint.plugin.handlers.blueprint.service.ReferenceParameters.needAvailability; public class ReferenceListHandler implements CustomDependencyAnnotationHandler<ReferenceList> { @Override public Class<ReferenceList> getAnnotation() { return ReferenceList.class; } @Override public String handleDependencyAnnotation(AnnotatedElement annotatedElement, String name, ContextEnricher contextEnricher) { ReferenceList referenceList = annotatedElement.getAnnotation(ReferenceList.class); final Class<?> clazz = getClass(annotatedElement); return handleDependencyAnnotation(clazz, referenceList, name, contextEnricher); } @Override public String handleDependencyAnnotation(final Class<?> clazz, ReferenceList referenceList, String name, ContextEnricher contextEnricher) { if (clazz != List.class) { throw new ReferenceListInvalidInterface(clazz); } final String id = name != null ? name : ReferenceId.generateReferenceListId(referenceList, contextEnricher); contextEnricher.addBean(id, clazz); contextEnricher.addBlueprintContentWriter(getWriterId(id, referenceList.referenceInterface()), getXmlWriter(id, referenceList, contextEnricher)); return id; } private XmlWriter getXmlWriter(final String id, final ReferenceList referenceList, final ContextEnricher contextEnricher) { return new XmlWriter() { @Override public void write(XMLStreamWriter writer) throws XMLStreamException { writer.writeEmptyElement("reference-list"); writer.writeAttribute("id", id); writer.writeAttribute("interface", referenceList.referenceInterface().getName()); if (!"".equals(referenceList.filter())) { writer.writeAttribute("filter", referenceList.filter()); } if (!"".equals(referenceList.componentName())) { writer.writeAttribute("component-name", referenceList.componentName()); } if (needAvailability(contextEnricher, referenceList.availability())) { writer.writeAttribute("availability", referenceList.availability().name().toLowerCase()); } if (referenceList.memberType() == MemberType.SERVICE_REFERENCE) { writer.writeAttribute("member-type", "service-reference"); } } }; } private String getWriterId(String id, Class<?> clazz) { return "referenceList/" + clazz.getName() + "/" + id; } private Class<?> getClass(AnnotatedElement annotatedElement) { if (annotatedElement instanceof Class<?>) { return (Class<?>) annotatedElement; } if (annotatedElement instanceof Method) { return ((Method) annotatedElement).getParameterTypes()[0]; } if (annotatedElement instanceof Field) { return ((Field) annotatedElement).getType(); } throw new RuntimeException("Unknown annotated element"); } }
9,391
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint/service/ReferenceId.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.handlers.blueprint.service; import org.apache.aries.blueprint.annotation.service.Availability; import org.apache.aries.blueprint.annotation.service.MemberType; import org.apache.aries.blueprint.annotation.service.Reference; import org.apache.aries.blueprint.annotation.service.ReferenceList; import org.apache.aries.blueprint.plugin.spi.ContextEnricher; import static org.apache.aries.blueprint.plugin.handlers.blueprint.service.ReferenceParameters.needAvailability; import static org.apache.aries.blueprint.plugin.handlers.blueprint.service.ReferenceParameters.needTimeout; class ReferenceId { static String generateReferenceId(Class clazz, Reference reference, ContextEnricher contextEnricher) { StringBuilder sb = new StringBuilder(); writeBeanNameFromSimpleName(sb, clazz.getSimpleName()); appendFilter(sb, reference.filter()); appendComponentName(sb, reference.componentName()); appendAvailability(sb, reference.availability(), contextEnricher); appendTimeout(sb, reference.timeout()); return sb.toString().replaceAll("-+$", ""); } private static void appendTimeout(StringBuilder sb, long timeout) { sb.append("-"); if (needTimeout(timeout)) { sb.append(timeout); } } private static void appendAvailability(StringBuilder sb, Availability availability, ContextEnricher contextEnricher) { sb.append("-"); if (needAvailability(contextEnricher, availability)) { sb.append(availability.name().toLowerCase()); } } private static void appendComponentName(StringBuilder sb, String componentName) { sb.append("-"); if (!"".equals(componentName)) { sb.append(componentName); } } private static void appendFilter(StringBuilder sb, String filter) { sb.append("-"); if (!"".equals(filter)) { writeEscapedFilter(sb, filter); } } static String generateReferenceListId(ReferenceList referenceList, ContextEnricher contextEnricher) { StringBuilder sb = new StringBuilder("listOf-"); writeBeanNameFromSimpleName(sb, referenceList.referenceInterface().getSimpleName()); appendFilter(sb, referenceList.filter()); appendComponentName(sb, referenceList.componentName()); appendAvailability(sb, referenceList.availability(), contextEnricher); appendMemberType(sb, referenceList.memberType()); return sb.toString().replaceAll("-+$", ""); } private static void appendMemberType(StringBuilder sb, MemberType memberType) { sb.append("-"); if (memberType == MemberType.SERVICE_REFERENCE) { sb.append("reference"); } } private static void writeBeanNameFromSimpleName(StringBuilder sb, String name) { sb.append(name.substring(0, 1).toLowerCase()); sb.append(name.substring(1, name.length())); } private static void writeEscapedFilter(StringBuilder sb, String filter) { for (int c = 0; c < filter.length(); c++) { char ch = filter.charAt(c); if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9') { sb.append(ch); } } } }
9,392
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint/service/ReferenceListInvalidInterface.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.handlers.blueprint.service; import java.util.List; public class ReferenceListInvalidInterface extends RuntimeException { public ReferenceListInvalidInterface(Class<?> received) { super("Reference list must be " + List.class.getName() + " but received " + received.getName()); } }
9,393
0
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint
Create_ds/aries/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/blueprint/service/ServicePropertyWriter.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.aries.blueprint.plugin.handlers.blueprint.service; import org.apache.aries.blueprint.annotation.service.ServiceProperty; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import java.util.ArrayList; import java.util.List; class ServicePropertyWriter { private final List<ServiceProperty> serviceProperties; ServicePropertyWriter(ServiceProperty[] serviceProperties, int ranking) { this.serviceProperties = filterProperties(serviceProperties, ranking != 0); } private List<ServiceProperty> filterProperties(ServiceProperty[] properties, boolean rankingAlreadyProvided) { List<ServiceProperty> filtered = new ArrayList<>(); for (ServiceProperty sp : properties) { if (rankingAlreadyProvided && sp.name().equals("service.ranking")) { continue; } if (sp.values().length == 0) { continue; } filtered.add(sp); } return filtered; } void writeProperties(XMLStreamWriter writer) throws XMLStreamException { if (!serviceProperties.isEmpty()) { writer.writeStartElement("service-properties"); for (ServiceProperty serviceProperty : serviceProperties) { writeServiceProperty(writer, serviceProperty); } writer.writeEndElement(); } } private void writeServiceProperty(XMLStreamWriter writer, ServiceProperty serviceProperty) throws XMLStreamException { writer.writeStartElement("entry"); writer.writeAttribute("key", serviceProperty.name()); if (isSingleValue(serviceProperty)) { writeOneValueProperty(writer, serviceProperty); } else { writeMultiValueProperty(writer, serviceProperty); } writer.writeEndElement(); } private boolean isSingleValue(ServiceProperty serviceProperty) { return serviceProperty.values().length == 1; } private boolean isStringProperty(ServiceProperty serviceProperty) { return serviceProperty.type().equals(String.class); } private void writeOneValueProperty(XMLStreamWriter writer, ServiceProperty serviceProperty) throws XMLStreamException { if (isStringProperty(serviceProperty)) { writer.writeAttribute("value", serviceProperty.values()[0]); } else { writer.writeStartElement("value"); writer.writeAttribute("type", serviceProperty.type().getName()); writer.writeCharacters(serviceProperty.values()[0]); writer.writeEndElement(); } } private void writeMultiValueProperty(XMLStreamWriter writer, ServiceProperty serviceProperty) throws XMLStreamException { writer.writeStartElement("array"); if (!isStringProperty(serviceProperty)) { writer.writeAttribute("value-type", serviceProperty.type().getName()); } for (String value : serviceProperty.values()) { writer.writeStartElement("value"); writer.writeCharacters(value); writer.writeEndElement(); } writer.writeEndElement(); } }
9,394
0
Create_ds/aries/blueprint/blueprint-core/src/test/java/org/apache/aries
Create_ds/aries/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/OverloadTest.java
/* * 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.aries.blueprint; import org.apache.aries.blueprint.di.Repository; import org.apache.aries.blueprint.parser.ComponentDefinitionRegistryImpl; import org.junit.Test; public class OverloadTest extends AbstractBlueprintTest { @Test public void testOverload() throws Exception { ComponentDefinitionRegistryImpl registry = parse("/test-overload.xml"); Repository repository = new TestBlueprintContainer(registry).getRepository(); repository.create("b"); } }
9,395
0
Create_ds/aries/blueprint/blueprint-core/src/test/java/org/apache/aries
Create_ds/aries/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/ReferencesTest.java
/* * 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.aries.blueprint; import java.lang.reflect.InvocationHandler; import java.util.Collection; import java.util.concurrent.Callable; import org.apache.aries.blueprint.di.Repository; import org.apache.aries.blueprint.parser.ComponentDefinitionRegistryImpl; import org.apache.aries.proxy.InvocationListener; import org.apache.aries.proxy.ProxyManager; import org.apache.aries.proxy.UnableToProxyException; import org.apache.aries.proxy.impl.AbstractProxyManager; import org.osgi.framework.Bundle; import org.osgi.service.blueprint.container.ComponentDefinitionException; public class ReferencesTest extends AbstractBlueprintTest { public void testWiring() throws Exception { ComponentDefinitionRegistryImpl registry = parse("/test-references.xml"); ProxyManager proxyManager = new AbstractProxyManager() { @Override protected Object createNewProxy(Bundle bundle, Collection<Class<?>> classes, Callable<Object> objectCallable, InvocationListener invocationListener) throws UnableToProxyException { return new Object(); } @Override protected InvocationHandler getInvocationHandler(Object o) { return null; } @Override protected boolean isProxyClass(Class<?> aClass) { return false; } }; Repository repository = new TestBlueprintContainer(registry, proxyManager).getRepository(); repository.create("refItf"); try { repository.create("refClsErr"); fail("Should have failed"); } catch (ComponentDefinitionException e) { } repository.create("refClsOk"); } static class ProxyGenerationException extends RuntimeException { } }
9,396
0
Create_ds/aries/blueprint/blueprint-core/src/test/java/org/apache/aries
Create_ds/aries/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/WiringTest.java
/* * 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.aries.blueprint; import java.math.BigInteger; import java.net.URI; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.TimeZone; import junit.framework.Assert; import org.apache.aries.blueprint.CallbackTracker.Callback; import org.apache.aries.blueprint.container.BlueprintRepository; import org.apache.aries.blueprint.container.ServiceRecipe; import org.apache.aries.blueprint.di.CircularDependencyException; import org.apache.aries.blueprint.di.ExecutionContext; import org.apache.aries.blueprint.di.MapRecipe; import org.apache.aries.blueprint.di.Recipe; import org.apache.aries.blueprint.di.Repository; import org.apache.aries.blueprint.intercept.BeanA; import org.apache.aries.blueprint.intercept.BeanB; import org.apache.aries.blueprint.intercept.TheInterceptor; import org.apache.aries.blueprint.parser.ComponentDefinitionRegistryImpl; import org.apache.aries.blueprint.pojos.*; import org.apache.aries.blueprint.proxy.ProxyUtils; import org.osgi.framework.ServiceRegistration; import org.osgi.service.blueprint.container.ComponentDefinitionException; import static org.junit.Assert.assertArrayEquals; public class WiringTest extends AbstractBlueprintTest { public void testWiring() throws Exception { ComponentDefinitionRegistryImpl registry = parse("/test-wiring.xml"); Repository repository = new TestBlueprintContainer(registry).getRepository(); Object obj1 = repository.create("pojoA"); assertNotNull(obj1); assertTrue(obj1 instanceof PojoA); PojoA pojoa = (PojoA) obj1; // test singleton scope assertTrue(obj1 == repository.create("pojoA")); Object obj2 = repository.create("pojoB"); assertNotNull(obj2); assertTrue(obj2 instanceof PojoB); PojoB pojob = (PojoB) obj2; assertNotNull(pojoa.getPojob()); assertNotNull(pojoa.getPojob().getUri()); assertNotNull(pojoa.getList()); assertEquals("list value", pojoa.getList().get(0)); assertEquals(new Integer(55), pojoa.getList().get(2)); assertEquals(URI.create("http://geronimo.apache.org"), pojoa.getList().get(3)); Object c0 = pojoa.getList().get(1); Object c1 = pojoa.getList().get(4); assertNotNull(c0); assertNotNull(c1); assertEquals(PojoB.class, c0.getClass()); assertEquals(PojoB.class, c1.getClass()); assertNotSame(c0, c1); assertNotNull(pojoa.getArray()); assertEquals("list value", pojoa.getArray()[0]); assertEquals(pojob, pojoa.getArray()[1]); assertEquals(new Integer(55), pojoa.getArray()[2]); assertEquals(URI.create("http://geronimo.apache.org"), pojoa.getArray()[3]); assertNotNull(pojoa.getSet()); assertTrue(pojoa.getSet().contains("set value")); assertTrue(pojoa.getSet().contains(pojob.getUri())); assertTrue(pojoa.getSet().contains(URI.create("http://geronimo.apache.org"))); assertNotNull(pojoa.getMap()); assertEquals("val", pojoa.getMap().get("key")); assertEquals(pojob, pojoa.getMap().get(pojob)); assertEquals(URI.create("http://geronimo.apache.org"), pojoa.getMap().get(new Integer(5))); assertNotNull(pojoa.getProps()); assertEquals("value1", pojoa.getProps().get("key1")); assertEquals("value2", pojoa.getProps().get("2")); assertEquals("bar", pojoa.getProps().get("foo")); assertNotNull(pojoa.getNumber()); assertEquals(new BigInteger("10"), pojoa.getNumber()); assertNotNull(pojoa.getIntArray()); assertEquals(3, pojoa.getIntArray().length); assertEquals(1, pojoa.getIntArray()[0]); assertEquals(50, pojoa.getIntArray()[1]); assertEquals(100, pojoa.getIntArray()[2]); assertNotNull(pojoa.getNumberArray()); assertEquals(4, pojoa.getNumberArray().length); assertEquals(new Integer(1), pojoa.getNumberArray()[0]); assertEquals(new BigInteger("50"), pojoa.getNumberArray()[1]); assertEquals(new Long(100), pojoa.getNumberArray()[2]); assertEquals(new Integer(200), pojoa.getNumberArray()[3]); // test init-method assertEquals(true, pojob.getInitCalled()); // test service Object obj3 = repository.create("service1"); assertNotNull(obj3); assertTrue(obj3 instanceof ServiceRegistration); ExecutionContext.Holder.setContext((ExecutionContext) repository); for(Recipe r : ((ServiceRecipe)repository.getRecipe("service1")).getDependencies()) { if(r instanceof MapRecipe) { Map m = (Map) r.create(); assertEquals("value1", m.get("key1")); assertEquals("value2", m.get("key2")); assertTrue(m.get("key3") instanceof List); } } ExecutionContext.Holder.setContext(null); // tests 'prototype' scope Object obj4 = repository.create("pojoC"); assertNotNull(obj4); assertTrue(obj4 != repository.create("pojoC")); repository.destroy(); // test destroy-method assertEquals(true, pojob.getDestroyCalled()); } public void testSetterDisambiguation() throws Exception { ComponentDefinitionRegistryImpl registry = parse("/test-wiring.xml"); Repository repository = new TestBlueprintContainer(registry).getRepository(); AmbiguousPojo pojo = (AmbiguousPojo) repository.create("ambiguousViaInt"); assertEquals(5, pojo.getSum()); pojo = (AmbiguousPojo) repository.create("ambiguousViaList"); assertEquals(7, pojo.getSum()); } public void testFieldInjection() throws Exception { ComponentDefinitionRegistryImpl registry = parse("/test-wiring.xml"); Repository repository = new TestBlueprintContainer(registry).getRepository(); Object fiTestBean = repository.create("FITestBean"); assertNotNull(fiTestBean); assertTrue(fiTestBean instanceof FITestBean); FITestBean bean = (FITestBean) fiTestBean; // single field injection assertEquals("value", bean.getAttr()); // prefer setter injection to field injection assertEquals("IS_LOWER", bean.getUpperCaseAttr()); // support cascaded injection 'bean.name' via fields assertEquals("aName", bean.getBeanName()); // fail if field-injection is not specified try { repository.create("FIFailureTestBean"); Assert.fail("Expected exception"); } catch (ComponentDefinitionException cde) {} // fail if field-injection is false try { repository.create("FIFailureTest2Bean"); Assert.fail("Expected exception"); } catch (ComponentDefinitionException cde) {} } public void testCompoundProperties() throws Exception { ComponentDefinitionRegistryImpl registry = parse("/test-wiring.xml"); Repository repository = new TestBlueprintContainer(registry).getRepository(); Object obj5 = repository.create("compound"); assertNotNull(obj5); assertTrue(obj5 instanceof PojoB); PojoB pojob = (PojoB) obj5; assertEquals("hello bean property", pojob.getBean().getName()); Object obj = repository.create("goodIdRef"); assertNotNull(obj); assertTrue(obj instanceof BeanD); BeanD bean = (BeanD) obj; assertEquals("pojoA", bean.getName()); } public void testIdRefs() throws Exception { ComponentDefinitionRegistryImpl registry = parse("/test-bad-id-ref.xml"); try { new TestBlueprintContainer(registry).getRepository(); fail("Did not throw exception"); } catch (RuntimeException e) { // we expect exception // TODO: check error string? } } public void testDependencies() throws Exception { CallbackTracker.clear(); ComponentDefinitionRegistryImpl registry = parse("/test-depends-on.xml"); Repository repository = new TestBlueprintContainer(registry).getRepository(); Map instances = repository.createAll(Arrays.asList("c", "d", "e"), ProxyUtils.asList(Object.class)); List<Callback> callback = CallbackTracker.getCallbacks(); assertEquals(3, callback.size()); checkInitCallback(instances.get("d"), callback.get(0)); checkInitCallback(instances.get("c"), callback.get(1)); checkInitCallback(instances.get("e"), callback.get(2)); repository.destroy(); assertEquals(6, callback.size()); checkDestroyCallback(instances.get("e"), callback.get(3)); checkDestroyCallback(instances.get("c"), callback.get(4)); checkDestroyCallback(instances.get("d"), callback.get(5)); } private void checkInitCallback(Object obj, Callback callback) { assertEquals(Callback.INIT, callback.getType()); assertEquals(obj, callback.getObject()); } private void checkDestroyCallback(Object obj, Callback callback) { assertEquals(Callback.DESTROY, callback.getType()); assertEquals(obj, callback.getObject()); } public void testConstructor() throws Exception { ComponentDefinitionRegistryImpl registry = parse("/test-constructor.xml"); Repository repository = new TestBlueprintContainer(registry).getRepository(); Object obj1 = repository.create("pojoA"); assertNotNull(obj1); assertTrue(obj1 instanceof PojoA); PojoA pojoa = (PojoA) obj1; Object obj2 = repository.create("pojoB"); testPojoB(obj2, URI.create("urn:myuri"), 10); assertEquals(obj2, pojoa.getPojob()); assertEquals(new BigInteger("10"), pojoa.getNumber()); Object obj3 = repository.create("pojoC"); testPojoB(obj3, URI.create("urn:myuri-static"), 15); Object obj4 = repository.create("pojoD"); testPojoB(obj4, URI.create("urn:myuri-static"), 15); Object obj5 = repository.create("pojoE"); testPojoB(obj5, URI.create("urn:myuri-dynamic"), 20); Object obj6 = repository.create("multipleInt"); testMultiple(obj6, null, 123, null); Object obj7 = repository.create("multipleInteger"); testMultiple(obj7, null, -1, new Integer(123)); Object obj8 = repository.create("multipleString"); testMultiple(obj8, "123", -1, null); // TODO: check the below tests when the incoherence between TCK / spec is solved // try { // graph.create("multipleStringConvertable"); // fail("Did not throw exception"); // } catch (RuntimeException e) { // // we expect exception // } Object obj10 = repository.create("multipleFactory1"); testMultiple(obj10, null, 1234, null); Object obj11 = repository.create("multipleFactory2"); testMultiple(obj11, "helloCreate-boolean", -1, null); try { repository.create("multipleFactoryNull"); fail("Did not throw exception"); } catch (RuntimeException e) { // we expect exception // TODO: check the exception string? } Object obj12 = repository.create("multipleFactoryTypedNull"); testMultiple(obj12, "hello-boolean", -1, null); Object obj13 = repository.create("mapConstruction"); Map<String, String> constructionMap = new HashMap<String, String>(); constructionMap.put("a", "b"); testMultiple(obj13, constructionMap); Object obj14 = repository.create("propsConstruction"); Properties constructionProperties = new Properties(); constructionProperties.put("a", "b"); testMultiple(obj14, constructionProperties); Object obja = repository.create("mapConstructionWithDefaultType"); Map<String, Date> mapa = new HashMap<String, Date>(); // Months are 0-indexed Calendar calendar = new GregorianCalendar(2012, 0, 6); calendar.setTimeZone(TimeZone.getTimeZone("GMT")); mapa.put("date", new Date(calendar.getTimeInMillis())); testMultiple(obja, mapa); Object objc = repository.create("mapConstructionWithTypedEntries"); Map mapc = new HashMap(); mapc.put("boolean", Boolean.TRUE); mapc.put("double", 1.23); mapc.put("date", new Date(calendar.getTimeInMillis())); testMultiple(objc, mapc); Object objb = repository.create("mapConstructionWithNonDefaultTypedEntries"); Map mapb = new HashMap(); mapb.put("boolean", Boolean.TRUE); mapb.put("double", 3.45); mapb.put("otherdouble", 10.2); testMultiple(objb, mapb); Object objd = repository.create("mapConstructionWithNonDefaultTypedKeys"); Map mapd = new HashMap(); mapd.put(Boolean.TRUE, "boolean"); mapd.put(42.42, "double"); testMultiple(objd, mapd); BeanF obj15 = (BeanF) repository.create("booleanWrapped"); assertNotNull(obj15.getWrapped()); assertEquals(false, (boolean) obj15.getWrapped()); assertNull(obj15.getPrim()); // TODO: check the below tests when the incoherence between TCK / spec is solved // BeanF obj16 = (BeanF) graph.create("booleanPrim"); // assertNotNull(obj16.getPrim()); // assertEquals(false, (boolean) obj16.getPrim()); // assertNull(obj16.getWrapped()); } private void testPojoB(Object obj, URI uri, int intValue) { assertNotNull(obj); assertTrue(obj instanceof PojoB); PojoB pojob = (PojoB) obj; assertEquals(uri, pojob.getUri()); assertEquals(intValue, pojob.getNumber()); } private void testMultiple(Object obj, String stringValue, int intValue, Integer integerValue) { assertNotNull(obj); assertTrue(obj instanceof Multiple); assertEquals(intValue, ((Multiple)obj).getInt()); assertEquals(stringValue, ((Multiple)obj).getString()); assertEquals(integerValue, ((Multiple)obj).getInteger()); } private void testMultiple(Object obj, Map map) { assertNotNull(obj); assertTrue(obj instanceof Multiple); assertEquals(map, ((Multiple)obj).getMap()); } private void testMultiple(Object obj, Properties map) { assertNotNull(obj); assertTrue(obj instanceof Multiple); assertEquals(map, ((Multiple)obj).getProperties()); } public void testGenerics2() throws Exception { ComponentDefinitionRegistryImpl registry = parse("/test-generics.xml"); Repository repository = new TestBlueprintContainer(registry).getRepository(); repository.create("gen2"); } public void testGenerics() throws Exception { ComponentDefinitionRegistryImpl registry = parse("/test-generics.xml"); Repository repository = new TestBlueprintContainer(registry).getRepository(); List<Integer> expectedList = new ArrayList<Integer>(); expectedList.add(new Integer(10)); expectedList.add(new Integer(20)); expectedList.add(new Integer(50)); Set<Long> expectedSet = new HashSet<Long>(); expectedSet.add(new Long(1000)); expectedSet.add(new Long(2000)); expectedSet.add(new Long(5000)); Map<Short, Boolean> expectedMap = new HashMap<Short, Boolean>(); expectedMap.put(new Short((short)1), Boolean.TRUE); expectedMap.put(new Short((short)2), Boolean.FALSE); expectedMap.put(new Short((short)5), Boolean.TRUE); Object obj; PojoGenerics pojo; obj = repository.create("method"); assertTrue(obj instanceof PojoGenerics); pojo = (PojoGenerics) obj; assertEquals(expectedList, pojo.getList()); assertEquals(expectedSet, pojo.getSet()); assertEquals(expectedMap, pojo.getMap()); obj = repository.create("constructorList"); assertTrue(obj instanceof PojoGenerics); pojo = (PojoGenerics) obj; assertEquals(expectedList, pojo.getList()); obj = repository.create("constructorSet"); assertTrue(obj instanceof PojoGenerics); pojo = (PojoGenerics) obj; assertEquals(expectedSet, pojo.getSet()); obj = repository.create("constructorMap"); assertTrue(obj instanceof PojoGenerics); pojo = (PojoGenerics) obj; assertEquals(expectedMap, pojo.getMap()); obj = repository.create("genericPojo"); assertTrue(obj instanceof Primavera); assertEquals("string", ((Primavera) obj).prop); obj = repository.create("doubleGenericPojo"); assertTrue(obj instanceof Primavera); assertEquals("stringToo", ((Primavera) obj).prop); } public void testMixedGenericsTracker() throws Exception { ComponentDefinitionRegistryImpl registry = parse("/test-generics-mix.xml"); Repository repository = new TestBlueprintContainer(registry).getRepository(); repository.create("tracker"); } public void testMixedGenericsTypedTracker() throws Exception { ComponentDefinitionRegistryImpl registry = parse("/test-generics-mix.xml"); Repository repository = new TestBlueprintContainer(registry).getRepository(); try { repository.create("typedTracker"); fail("Should have thrown an exception"); } catch (ComponentDefinitionException e) { // expected } } public void testMixedGenericsTypedTrackerRaw() throws Exception { ComponentDefinitionRegistryImpl registry = parse("/test-generics-mix.xml"); Repository repository = new TestBlueprintContainer(registry).getRepository(); repository.create("typedTrackerRaw"); } public void testMixedGenericsTypedClassTracker() throws Exception { ComponentDefinitionRegistryImpl registry = parse("/test-generics-mix.xml"); Repository repository = new TestBlueprintContainer(registry).getRepository(); try { repository.create("typedClassTracker"); fail("Should have thrown an exception"); } catch (ComponentDefinitionException e) { // expected } } public void testMixedGenericsTypedClassTrackerRaw() throws Exception { ComponentDefinitionRegistryImpl registry = parse("/test-generics-mix.xml"); Repository repository = new TestBlueprintContainer(registry).getRepository(); repository.create("typedClassTrackerRaw"); } public void testMixedGenericsTypedGeneric() throws Exception { ComponentDefinitionRegistryImpl registry = parse("/test-generics-mix.xml"); Repository repository = new TestBlueprintContainer(registry).getRepository(); repository.create("typedGenericTracker"); } public void testMixedGenericsTypedGenericClass() throws Exception { ComponentDefinitionRegistryImpl registry = parse("/test-generics-mix.xml"); Repository repository = new TestBlueprintContainer(registry).getRepository(); repository.create("typedClassGenericTracker"); } public void testThreadPoolCreation() throws Exception { ComponentDefinitionRegistryImpl registry = parse("/test-threadpool.xml"); Repository repository = new TestBlueprintContainer(registry).getRepository(); repository.create("executorService"); } public void testCachePojo() throws Exception { ComponentDefinitionRegistryImpl registry = parse("/test-cache.xml"); Repository repository = new TestBlueprintContainer(registry).getRepository(); Thread.currentThread().setContextClassLoader(CachePojos.CacheContainer.class.getClassLoader()); repository.create("queueCountCache"); } public void testVarArgPojo() throws Exception { ComponentDefinitionRegistryImpl registry = parse("/test-vararg.xml"); Repository repository = new TestBlueprintContainer(registry).getRepository(); VarArg va = (VarArg) repository.create("vararg"); assertArrayEquals(new String[] { "-web" }, va.args); } public void testCircular() throws Exception { BlueprintRepository repository = createBlueprintContainer().getRepository(); // this should pass (we allow circular dependencies for components without init method) Object obj1 = repository.create("a"); // test service and listener circular dependencies Object obj2 = repository.create("service"); assertNotNull(obj2); assertTrue(obj2 instanceof ServiceRegistration); Object obj3 = repository.create("listener"); assertNotNull(obj3); assertTrue(obj3 instanceof PojoListener); assertEquals(obj2, ((PojoListener) obj3).getService() ); } public void testCircularPrototype() throws Exception { BlueprintRepository repository = createBlueprintContainer().getRepository(); try { repository.create("circularPrototypeDriver"); fail("Did not throw exception"); } catch (CircularDependencyException e) { // that's what we expect } try { repository.create("circularPrototype"); fail("Did not throw exception"); } catch (CircularDependencyException e) { // that's what we expect } } public void testRecursive() throws Exception { BlueprintRepository repository = createBlueprintContainer().getRepository(); try { repository.create("recursiveConstructor"); fail("Did not throw exception"); } catch (ComponentDefinitionException e) { if (e.getCause() instanceof CircularDependencyException) { // that's what we expect } else { fail("Did not throw expected exception"); throw e; } } PojoRecursive pojo; pojo = (PojoRecursive) repository.create("recursiveSetter"); assertNotNull(pojo); pojo = (PojoRecursive) repository.create("recursiveInitMethod"); assertNotNull(pojo); } public void testCircularBreaking() throws Exception { BlueprintRepository repository; repository = createBlueprintContainer().getRepository(); assertNotNull(repository.create("c1")); repository = createBlueprintContainer().getRepository(); assertNotNull(repository.create("c2")); repository = createBlueprintContainer().getRepository(); assertNotNull(repository.create("c3")); } public void testInterceptors() throws Exception { ComponentDefinitionRegistryImpl registry = parse("/test-interceptors.xml"); Repository repository = new TestBlueprintContainer(registry).getRepository(); BeanB b = (BeanB) repository.create("b"); assertNotNull(b.getA()); assertEquals("Hello Guillaume !", b.getA().hello("Guillaume")); assertEquals(1, TheInterceptor.calls.get()); } private TestBlueprintContainer createBlueprintContainer() throws Exception { ComponentDefinitionRegistryImpl registry = parse("/test-circular.xml"); return new TestBlueprintContainer(registry); } }
9,397
0
Create_ds/aries/blueprint/blueprint-core/src/test/java/org/apache/aries
Create_ds/aries/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/TestBundleContext.java
/* * 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.aries.blueprint; import java.io.File; import java.io.InputStream; import java.util.Collection; import java.util.Dictionary; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleException; import org.osgi.framework.BundleListener; import org.osgi.framework.Filter; import org.osgi.framework.FrameworkListener; import org.osgi.framework.InvalidSyntaxException; import org.osgi.framework.ServiceListener; import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceRegistration; public class TestBundleContext implements BundleContext { public void addBundleListener(BundleListener arg0) { } public void addFrameworkListener(FrameworkListener arg0) { } public void addServiceListener(ServiceListener arg0) { } public void addServiceListener(ServiceListener arg0, String arg1) throws InvalidSyntaxException { } public Filter createFilter(String arg0) throws InvalidSyntaxException { return null; } public ServiceReference[] getAllServiceReferences(String arg0, String arg1) throws InvalidSyntaxException { return null; } public Bundle getBundle() { return null; } public Bundle getBundle(long arg0) { return null; } public Bundle getBundle(String arg0) { return null; } public Bundle[] getBundles() { return null; } public File getDataFile(String arg0) { return null; } public String getProperty(String arg0) { return null; } public Object getService(ServiceReference arg0) { return null; } public ServiceReference getServiceReference(String arg0) { return null; } public ServiceReference getServiceReference(Class aClass) { return null; } public ServiceReference[] getServiceReferences(String arg0, String arg1) throws InvalidSyntaxException { return null; } public Collection getServiceReferences(Class arg0, String arg1) throws InvalidSyntaxException { return null; } public Bundle installBundle(String arg0) throws BundleException { return null; } public Bundle installBundle(String arg0, InputStream arg1) throws BundleException { return null; } public ServiceRegistration registerService(String[] arg0, Object arg1, Dictionary arg2) { return null; } public ServiceRegistration registerService(String arg0, Object arg1, Dictionary arg2) { return null; } public <S> ServiceRegistration<S> registerService(Class<S> aClass, S s, Dictionary<String,?> dictionary) { return null; } public void removeBundleListener(BundleListener arg0) { } public void removeFrameworkListener(FrameworkListener arg0) { } public void removeServiceListener(ServiceListener arg0) { } public boolean ungetService(ServiceReference arg0) { return false; } }
9,398
0
Create_ds/aries/blueprint/blueprint-core/src/test/java/org/apache/aries
Create_ds/aries/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/CallbackTracker.java
/* * 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.aries.blueprint; import java.util.ArrayList; import java.util.List; public class CallbackTracker { private static List<Callback> callbacks = new ArrayList<Callback>(); public static void add(Callback callback) { callbacks.add(callback); } public static List<Callback> getCallbacks() { return callbacks; } public static void clear() { callbacks.clear(); } public static class Callback { public static int INIT = 1; public static int DESTROY = 2; private Object object; private int type; public Callback(int type, Object object) { this.type = type; this.object = object; } public int getType() { return type; } public Object getObject() { return object; } public String toString() { return type + " " + object; } } }
9,399