Author: ivaynberg
Date: Wed Jan 31 13:01:14 2007
New Revision: 501991
URL: http://svn.apache.org/viewvc?view=rev&rev=501991
Log:
WICKET-28
Modified:
incubator/wicket/trunk/wicket-spring/src/main/java/wicket/spring/injection/AnnotProxyFieldValueFactory.java
incubator/wicket/trunk/wicket-spring/src/test/java/wicket/spring/injection/AnnotProxyFieldValueFactoryTest.java
Modified:
incubator/wicket/trunk/wicket-spring/src/main/java/wicket/spring/injection/AnnotProxyFieldValueFactory.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket-spring/src/main/java/wicket/spring/injection/AnnotProxyFieldValueFactory.java?view=diff&rev=501991&r1=501990&r2=501991
==============================================================================
---
incubator/wicket/trunk/wicket-spring/src/main/java/wicket/spring/injection/AnnotProxyFieldValueFactory.java
(original)
+++
incubator/wicket/trunk/wicket-spring/src/main/java/wicket/spring/injection/AnnotProxyFieldValueFactory.java
Wed Jan 31 13:01:14 2007
@@ -1,19 +1,19 @@
-/*
- * 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.
- */
+/*
+ * 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 wicket.spring.injection;
import java.lang.reflect.Field;
@@ -62,6 +62,8 @@
private final ConcurrentHashMap<SpringBeanLocator, Object> cache = new
ConcurrentHashMap<SpringBeanLocator, Object>();
+ private boolean failFast = true;
+
/**
* @param contextLocator
* spring context locator
@@ -96,8 +98,10 @@
}
// fail early - see if the locator can locate the
spring bean
- testLocator(locator, fieldOwner, field);
-
+ if (failFast) {
+ testLocator(locator, fieldOwner, field);
+ }
+
Object proxy =
LazyInitProxyFactory.createProxy(field.getType(), locator);
cache.put(locator, proxy);
return proxy;
@@ -144,4 +148,11 @@
return field.isAnnotationPresent(SpringBean.class);
}
+ /**
+ * @param failFast true if the locator fails if a bean can't be located
+ */
+ public void setFailFast(boolean failFast)
+ {
+ this.failFast = failFast;
+ }
}
Modified:
incubator/wicket/trunk/wicket-spring/src/test/java/wicket/spring/injection/AnnotProxyFieldValueFactoryTest.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket-spring/src/test/java/wicket/spring/injection/AnnotProxyFieldValueFactoryTest.java?view=diff&rev=501991&r1=501990&r2=501991
==============================================================================
---
incubator/wicket/trunk/wicket-spring/src/test/java/wicket/spring/injection/AnnotProxyFieldValueFactoryTest.java
(original)
+++
incubator/wicket/trunk/wicket-spring/src/test/java/wicket/spring/injection/AnnotProxyFieldValueFactoryTest.java
Wed Jan 31 13:01:14 2007
@@ -1,19 +1,19 @@
-/*
- * 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.
- */
+/*
+ * 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 wicket.spring.injection;
import java.lang.reflect.Field;
@@ -118,5 +118,31 @@
{
// noop
}
+ }
+
+ public void testFailsIfBeanWithIdIsNotFound() throws Exception
+ {
+ InjectableWithReferenceToNonexistingBean obj = new
InjectableWithReferenceToNonexistingBean();
+ Field field = obj.getClass().getDeclaredField("nonExisting");
+ try
+ {
+ factory.getFieldValue(field, obj);
+ fail();
+ }
+ catch (RuntimeException e) {
+ }
+ }
+
+ public void testSucceedsIfBeanWithIdIsNotFoundWhenFailFastIsDisabled()
throws Exception
+ {
+ InjectableWithReferenceToNonexistingBean obj = new
InjectableWithReferenceToNonexistingBean();
+ Field field = obj.getClass().getDeclaredField("nonExisting");
+ factory.setFailFast(false);
+ factory.getFieldValue(field, obj);
+ }
+
+ static class InjectableWithReferenceToNonexistingBean {
+ @SpringBean(id="nonExisting")
+ private Bean nonExisting;
}
}