@Test public void customTemplate() throws RegisterBlueprintException, CreateModelException { assertEquals( CustomTemplate.class, modelFactory.getErectors().get( Wheel.class ).getTemplate().getClass() ); } }
/** * Create new instance of {@link Erector#getTarget()}. Uses {@link #getNewInstance()} * if defined, otherwise fails back to {@link BlueprintTemplate#construct} * * @return Object new instance * @throws BlueprintTemplateException */ public Object createNewInstance() throws BlueprintTemplateException { if ( this.getNewInstance() != null ) { // XXX: warn if the return of the callback is not the same class as the target? return this.getNewInstance().createInstance(); } else { return this.getTemplate().construct( this.getTarget() ); } }
@Test public void testGet() throws BlueprintTemplateException { Car car = new Car(); car.setMileage(new Float(123.456)); Float val = (Float) erector.getTemplate().get(car, "mileage"); assertEquals(new Float(123.456), val); } }
public Command process(ModelFactory modelFactory, Erector erector, ModelField modelField, Object model) throws PolicyException { logger.debug( "processing {} for {}", modelField, model ); // If Model has not be set, create a new one from ModelFactory if ( modelField instanceof MappedField ) { if ( this.getSingleton() == null ) { logger.debug(" creating singleton for {}", this.getTarget() ); try { this.setSingleton( modelFactory.createModel( this.getTarget(), false ) ); } catch (CreateModelException e) { throw new PolicyException( e ); } } // Set Singleton into model try { erector.getTemplate().set( model, modelField.getName(), this.getSingleton() ); } catch (BlueprintTemplateException e) { throw new PolicyException(e); } } return Command.SKIP_INJECTION; }
value = erector.getTemplate().get(nonNullReferenceModel, defaultField.getName()); } catch (BlueprintTemplateException e) { throw new CreateModelException(e); createdModel = erector.getTemplate().set(createdModel, defaultField.getName(), value); } catch (BlueprintTemplateException e) { throw new CreateModelException(e); value = erector.getTemplate().get(nonNullReferenceModel, mappedField.getName()); } catch (BlueprintTemplateException e) { throw new CreateModelException(e); createdModel = erector.getTemplate().set(createdModel, mappedField.getName(), value); } catch (BlueprintTemplateException e) { throw new CreateModelException(e); value = (List) erector.getTemplate().construct(listField.getTargetList()); } catch (BlueprintTemplateException e) { throw new CreateModelException(e); modelList = (List) erector.getTemplate().get(nonNullReferenceModel, listField.getName()); } catch (BlueprintTemplateException e) { throw new CreateModelException(e); createdModel = erector.getTemplate().set(createdModel, listField.getName(), value); } catch (BlueprintTemplateException e) { throw new CreateModelException(e); value = erector.getTemplate().construct(setField.getTargetSet());
@Test public void testBlueprintWithPrimitive() throws CreateModelException, BlueprintTemplateException { Car car = modelFactory.createModel(Car.class); Erector erector = modelFactory.getErectors().get(Car.class); ModelField modelField = erector.getModelField("mileage"); assertEquals(new Float(100.1), modelField.getValue()); // Val is zero because primitive initializes as zero Object val = erector.getTemplate().get(new Car(), "mileage"); assertEquals(new Float(0.0), val); // Val is zero because primitive initializes as zero assertEquals(0.0, car.getMileage(), 0); } }