http://git-wip-us.apache.org/repos/asf/polygene-website/blob/ba3a0fac/content/java/develop/howto-create-constraint.html ---------------------------------------------------------------------- diff --git a/content/java/develop/howto-create-constraint.html b/content/java/develop/howto-create-constraint.html new file mode 100644 index 0000000..8b6e5aa --- /dev/null +++ b/content/java/develop/howto-create-constraint.html @@ -0,0 +1,166 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Create a Constraint</title><link rel="stylesheet" type="text/css" href="css/style.css" /><meta name="generator" content="DocBook XSL Stylesheets V1.76.1" /><link rel="home" href="index.html" title="" /><link rel="up" href="tutorials.html" title="Tutorials" /><link rel="prev" href="howto-leverage-properties.html" title="Leverage Properties" /><link rel="next" href="howto-create-concern.html" title="Create a Concern" /> + + +<!-- favicon --> + +<link rel="shortcut icon" href="http://polygene.apache.org/favicon.ico" type="image/vnd.microsoft.icon" /> +<link rel="icon" href="http://polygene.apache.org/favicon.ico" type="image/x-icon" /> + +<!-- style --> + +<link href="css/shCore.css" rel="stylesheet" type="text/css" /> +<link href="css/shCoreEclipse.css" rel="stylesheet" type="text/css" /> +<link href="css/shThemeEclipse.css" rel="stylesheet" type="text/css" /> +<link href="css/polygene.css" rel="stylesheet" type="text/css" /> + +<!-- Syntax Highlighter --> + +<script type="text/javascript" src="js/shCore.js"></script> +<script type="text/javascript" src="js/shBrushJava.js"></script> +<script type="text/javascript" src="js/shBrushScala.js"></script> +<script type="text/javascript" src="js/shBrushJScript.js"></script> +<script type="text/javascript" src="js/shBrushBash.js"></script> +<script type="text/javascript" src="js/shBrushPlain.js"></script> +<script type="text/javascript" src="js/shBrushXml.js"></script> +<script type="text/javascript" src="js/shBrushGroovy.js"></script> +<script type="text/javascript" src="js/shBrushPython.js"></script> +<script type="text/javascript" src="js/shBrushRuby.js"></script> +<script type="text/javascript" src="js/shBrushCSharp.js"></script> + +<script type="text/javascript"> + SyntaxHighlighter.defaults['tab-size'] = 4; + SyntaxHighlighter.defaults['gutter'] = false; + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all() +</script> + +<!-- JQuery --> + +<script type="text/javascript" src="js/jquery-1.6.4.min.js"></script> + +<!-- Image Scaler --> + +<script type="text/javascript" src="js/imagescaler.js"></script> + +<!-- Table Styler --> + +<script type="text/javascript" src="js/tablestyler.js"></script> + +<!-- Apache Polygene WebSite Progressive Enhancement --> + +<link href="css/progressive-enhancement.css" rel="stylesheet" type="text/css" /> +<script type="text/javascript" src="js/jquery.scrollTo-1.4.2.js"></script> +<script type="text/javascript" src="js/progressive-enhancement.js"></script> + +<!-- Analytics --> + <script type="text/javascript"> + var _gaq = _gaq || []; + _gaq.push(['_setAccount', 'UA-62007352-1']); + _gaq.push(['_trackPageview']); + + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); + </script> + + </head><body><div xmlns="" xmlns:exsl="http://exslt.org/common" class="logo"><a href="index.html"><img src="images/logo-standard.png" /></a></div><div xmlns="" xmlns:exsl="http://exslt.org/common" class="top-nav"><div xmlns="http://www.w3.org/1999/xhtml" class="toc"><dl><dt><span class="section"><a href="index.html#home">Polygeneâ¢</a></span></dt><dt><span class="section"><a href="intro.html">Introduction</a></span></dt><dt><span class="section"><span xmlns="" href="tutorials.html">Tutorials</span></span></dt><dt><span class="section"><a href="javadocs.html">Javadoc</a></span></dt><dt><span class="section"><a href="samples.html">Samples</a></span></dt><dt><span class="section"><a href="core.html">Core</a></span></dt><dt><span class="section"><a href="libraries.html">Libraries</a></span></dt><dt><span class="section"><a href="extensions.html">Extensions</a></span></dt><dt><span class="section"><a href="tools.html">Tools</a></span></dt><dt><span class="section"><a href="glossary.ht ml">Glossary </a></span></dt></dl></div></div><div xmlns="" xmlns:exsl="http://exslt.org/common" class="sub-nav"><div xmlns="http://www.w3.org/1999/xhtml" class="toc"><dl><dt><span class="section"><a href="tutorials.html#_overview">Overview</a></span></dt><dt><span class="section"><a href="two-minutes-intro.html">Polygene⢠in 2 minutes</a></span></dt><dt><span class="section"><a href="ten-minutes-intro.html">Polygene⢠in 10 minutes</a></span></dt><dt><span class="section"><a href="thirty-minutes-intro.html">Polygene⢠in 30 minutes</a></span></dt><dt><span class="section"><a href="howto-depend-on-polygene.html">Depend on Polygeneâ¢</a></span></dt><dt><span class="section"><a href="howto-assemble-application.html">Assemble an Application</a></span></dt><dt><span class="section"><a href="tut-composites.html">Transient Composites Tutorial</a></span></dt><dt><span class="section"><a href="tut-services.html">Services Composites Tutorial</a></span></dt><dt><span class="section"><a href="howto-contextual-fragments.html">Use contextual fragments</a></span></dt><dt><span class="section"><a href="howto-leverage-properties.html">Leverage Properties</a></span></dt><dt><span class="section"><span xmlns="" href="howto-create-constraint.html">Create a Constraint</span></span></dt><dt><span class="section"><a href="howto-create-concern.html">Create a Concern</a></span></dt><dt><span class="section"><a href="howto-create-sideeffect.html">Create a SideEffect</a></span></dt><dt><span class="section"><a href="howto-create-entity.html">Create an Entity</a></span></dt><dt><span class="section"><a href="howto-configure-service.html">Configure a Service</a></span></dt><dt><span class="section"><a href="howto-invocation-annotation.html">Use @Invocation</a></span></dt><dt><span class="section"><a href="build-system.html">Polygene⢠Build System</a></span></dt><dt><span class="section"><a href="community-docs.html">Polygene⢠Documentation</a></span></dt><dt><span class="sectio n"><a href="releasing-apache.html">Releasing Polygeneâ¢</a></span></dt></dl></div></div><div class="section" title="Create a Constraint"><div class="titlepage"><div><div><h3 class="title"><a id="howto-create-constraint"></a>Create a Constraint</h3></div></div></div><p>Constraints are defined in <a class="xref" href="glossary.html#def-constraint">Constraint</a>.</p><p>If you want to reproduce whatâs explained in this tutorial, remember to depend on the Core Bootstrap artifact:</p><p>At runtime you will need the Core Runtime artifact too. See the <a class="xref" href="howto-depend-on-polygene.html" title="Depend on Polygeneâ¢">Depend on Polygeneâ¢</a> tutorial for details.</p><div class="section" title="Method Constraint"><div class="titlepage"><div><div><h4 class="title"><a id="_method_constraint"></a>Method Constraint</h4></div></div></div><p>Method Constraints are declared with annotations on the method argument. The annotation itself is custom, and it is possible to make your own.</p><pre class="programlisting brush: java">public interface Dialer +{ + void callPhoneNumber(@PhoneNumber String phoneNo); + +} +</pre><p>In the code above we say that we want the argument to the callPhoneNumber() method to be a valid phone number. This annotation is not built-in, so we need to declare it.</p><pre class="programlisting brush: java">@ConstraintDeclaration +@Retention( RetentionPolicy.RUNTIME ) +@Target( { ElementType.PARAMETER, ElementType.ANNOTATION_TYPE, ElementType.METHOD } ) +public @interface PhoneNumber +{ +} +</pre><p>We then need to provide the Constraint implementation.</p><pre class="programlisting brush: java">public class PhoneNumberConstraint + implements Constraint<PhoneNumber, String> +{ + public boolean isValid( PhoneNumber annotation, String number ) + { + boolean validPhoneNumber = true; // check phone number format... + return validPhoneNumber; // return true if valid phone number. + } +} +</pre><p>We also need to include the Constraint on the Composites we want to have them present.</p><pre class="programlisting brush: java">@Constraints( PhoneNumberConstraint.class ) +public interface DialerComposite extends ServiceComposite, Dialer +{ +} +</pre><p>If a Constraint is violated, then a ConstraintViolationException is thrown. The Exception contains ALL violations found +in the method invocation. Concerns can be used to catch and report these violations.</p><pre class="programlisting brush: java">public class ParameterViolationConcern extends ConcernOf<InvocationHandler> + implements InvocationHandler +{ + public Object invoke( Object proxy, Method method, Object[] args ) + throws Throwable + { + try + { + return next.invoke( proxy, method, args ); + } + catch( ConstraintViolationException e ) + { + for( ConstraintViolation violation : e.constraintViolations() ) + { + String name = violation.name(); + Object value = violation.value(); + Annotation constraint = violation.constraint(); + report( name, value, constraint ); + } + throw new IllegalArgumentException("Invalid argument(s)", e); + } + } + + [...snip...] + + private void report( String name, Object value, Annotation constraint ) + { + } +} +</pre></div><div class="section" title="Property Constraint"><div class="titlepage"><div><div><h4 class="title"><a id="_property_constraint"></a>Property Constraint</h4></div></div></div><p>Property Constraints are declared on the Property method.</p><pre class="programlisting brush: java">public interface HasPhoneNumber +{ + @PhoneNumber + Property<String> phoneNumber(); +} +</pre><p>In this case, the Constraint associated with the phoneNumber() method, will be called before the set() method on that +Property is called. If there is a constraint violation, the Exception thrown will be part of the caller, and not the +composite containing the Property, so a reporting constraint on the containing Composite will not see it. If you want +the containing Composite to handle the Constraint Violation, then you need to add a Concern on the Property itself, +which can be done like this;</p><pre class="programlisting brush: java">public abstract class PhoneNumberParameterViolationConcern extends ConcernOf<HasPhoneNumber> + implements HasPhoneNumber +{ + @Concerns( CheckViolation.class ) + public abstract Property<String> phoneNumber(); + + private abstract class CheckViolation extends ConcernOf<Property<String>> + implements Property<String> + { + public void set( String number ) + { + try + { + next.set( number ); + } + catch( ConstraintViolationException e ) + { + Collection<ConstraintViolation> violations = e.constraintViolations(); + report( violations ); + } + } + + [...snip...] + + private void report( Collection<ConstraintViolation> violations ) + { + } + } +} +</pre></div></div><div xmlns="" xmlns:exsl="http://exslt.org/common" class="footer"><p> + Copyright © 2015 The Apache Software Foundation, Licensed under the <a href="http://www.apache.org/licenses/" target="_blank">Apache License, Version 2.0</a>. + <br /><small> + Apache Polygene, Polygene, Apache, the Apache feather logo, and the Apache Polygene project logo are trademarks of The Apache Software Foundation.<br /> + All other marks mentioned may be trademarks or registered trademarks of their respective owners. + </small></p></div></body></html> \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/polygene-website/blob/ba3a0fac/content/java/develop/howto-create-entity.html ---------------------------------------------------------------------- diff --git a/content/java/develop/howto-create-entity.html b/content/java/develop/howto-create-entity.html new file mode 100644 index 0000000..673430c --- /dev/null +++ b/content/java/develop/howto-create-entity.html @@ -0,0 +1,243 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Create an Entity</title><link rel="stylesheet" type="text/css" href="css/style.css" /><meta name="generator" content="DocBook XSL Stylesheets V1.76.1" /><link rel="home" href="index.html" title="" /><link rel="up" href="tutorials.html" title="Tutorials" /><link rel="prev" href="howto-create-sideeffect.html" title="Create a SideEffect" /><link rel="next" href="howto-configure-service.html" title="Configure a Service" /> + + +<!-- favicon --> + +<link rel="shortcut icon" href="http://polygene.apache.org/favicon.ico" type="image/vnd.microsoft.icon" /> +<link rel="icon" href="http://polygene.apache.org/favicon.ico" type="image/x-icon" /> + +<!-- style --> + +<link href="css/shCore.css" rel="stylesheet" type="text/css" /> +<link href="css/shCoreEclipse.css" rel="stylesheet" type="text/css" /> +<link href="css/shThemeEclipse.css" rel="stylesheet" type="text/css" /> +<link href="css/polygene.css" rel="stylesheet" type="text/css" /> + +<!-- Syntax Highlighter --> + +<script type="text/javascript" src="js/shCore.js"></script> +<script type="text/javascript" src="js/shBrushJava.js"></script> +<script type="text/javascript" src="js/shBrushScala.js"></script> +<script type="text/javascript" src="js/shBrushJScript.js"></script> +<script type="text/javascript" src="js/shBrushBash.js"></script> +<script type="text/javascript" src="js/shBrushPlain.js"></script> +<script type="text/javascript" src="js/shBrushXml.js"></script> +<script type="text/javascript" src="js/shBrushGroovy.js"></script> +<script type="text/javascript" src="js/shBrushPython.js"></script> +<script type="text/javascript" src="js/shBrushRuby.js"></script> +<script type="text/javascript" src="js/shBrushCSharp.js"></script> + +<script type="text/javascript"> + SyntaxHighlighter.defaults['tab-size'] = 4; + SyntaxHighlighter.defaults['gutter'] = false; + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all() +</script> + +<!-- JQuery --> + +<script type="text/javascript" src="js/jquery-1.6.4.min.js"></script> + +<!-- Image Scaler --> + +<script type="text/javascript" src="js/imagescaler.js"></script> + +<!-- Table Styler --> + +<script type="text/javascript" src="js/tablestyler.js"></script> + +<!-- Apache Polygene WebSite Progressive Enhancement --> + +<link href="css/progressive-enhancement.css" rel="stylesheet" type="text/css" /> +<script type="text/javascript" src="js/jquery.scrollTo-1.4.2.js"></script> +<script type="text/javascript" src="js/progressive-enhancement.js"></script> + +<!-- Analytics --> + <script type="text/javascript"> + var _gaq = _gaq || []; + _gaq.push(['_setAccount', 'UA-62007352-1']); + _gaq.push(['_trackPageview']); + + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); + </script> + + </head><body><div xmlns="" xmlns:exsl="http://exslt.org/common" class="logo"><a href="index.html"><img src="images/logo-standard.png" /></a></div><div xmlns="" xmlns:exsl="http://exslt.org/common" class="top-nav"><div xmlns="http://www.w3.org/1999/xhtml" class="toc"><dl><dt><span class="section"><a href="index.html#home">Polygeneâ¢</a></span></dt><dt><span class="section"><a href="intro.html">Introduction</a></span></dt><dt><span class="section"><span xmlns="" href="tutorials.html">Tutorials</span></span></dt><dt><span class="section"><a href="javadocs.html">Javadoc</a></span></dt><dt><span class="section"><a href="samples.html">Samples</a></span></dt><dt><span class="section"><a href="core.html">Core</a></span></dt><dt><span class="section"><a href="libraries.html">Libraries</a></span></dt><dt><span class="section"><a href="extensions.html">Extensions</a></span></dt><dt><span class="section"><a href="tools.html">Tools</a></span></dt><dt><span class="section"><a href="glossary.ht ml">Glossary </a></span></dt></dl></div></div><div xmlns="" xmlns:exsl="http://exslt.org/common" class="sub-nav"><div xmlns="http://www.w3.org/1999/xhtml" class="toc"><dl><dt><span class="section"><a href="tutorials.html#_overview">Overview</a></span></dt><dt><span class="section"><a href="two-minutes-intro.html">Polygene⢠in 2 minutes</a></span></dt><dt><span class="section"><a href="ten-minutes-intro.html">Polygene⢠in 10 minutes</a></span></dt><dt><span class="section"><a href="thirty-minutes-intro.html">Polygene⢠in 30 minutes</a></span></dt><dt><span class="section"><a href="howto-depend-on-polygene.html">Depend on Polygeneâ¢</a></span></dt><dt><span class="section"><a href="howto-assemble-application.html">Assemble an Application</a></span></dt><dt><span class="section"><a href="tut-composites.html">Transient Composites Tutorial</a></span></dt><dt><span class="section"><a href="tut-services.html">Services Composites Tutorial</a></span></dt><dt><span class="section"><a href="howto-contextual-fragments.html">Use contextual fragments</a></span></dt><dt><span class="section"><a href="howto-leverage-properties.html">Leverage Properties</a></span></dt><dt><span class="section"><a href="howto-create-constraint.html">Create a Constraint</a></span></dt><dt><span class="section"><a href="howto-create-concern.html">Create a Concern</a></span></dt><dt><span class="section"><a href="howto-create-sideeffect.html">Create a SideEffect</a></span></dt><dt><span class="section"><span xmlns="" href="howto-create-entity.html">Create an Entity</span></span></dt><dt><span class="section"><a href="howto-configure-service.html">Configure a Service</a></span></dt><dt><span class="section"><a href="howto-invocation-annotation.html">Use @Invocation</a></span></dt><dt><span class="section"><a href="build-system.html">Polygene⢠Build System</a></span></dt><dt><span class="section"><a href="community-docs.html">Polygene⢠Documentation</a></span></dt><dt><span class="sectio n"><a href="releasing-apache.html">Releasing Polygeneâ¢</a></span></dt></dl></div></div><div class="section" title="Create an Entity"><div class="titlepage"><div><div><h3 class="title"><a id="howto-create-entity"></a>Create an Entity</h3></div></div></div><p>One of the most common tasks in Polygene⢠is the management of the life cycle of Entities. Since Polygene⢠is capable of +delivering much higher performance than traditional Object-Relational Mapping technologies, we also expect that people +use Entities more frequently in Polygene⢠applications, so it is a very important topic to cover.</p><p>If you want to reproduce whatâs explained in this tutorial, remember to depend on the Core Bootstrap artifact:</p><p>Moreover, youâll need an EntityStore for persistence and an Indexing engine for querying. Choose among the available +implementations listed in the <a class="xref" href="extensions.html" title="Extensions">Extensions</a> section.</p><p>At runtime you will need the Core Runtime artifact too. See the <a class="xref" href="howto-depend-on-polygene.html" title="Depend on Polygeneâ¢">Depend on Polygeneâ¢</a> tutorial for details.</p><div class="section" title="Basics First"><div class="titlepage"><div><div><h4 class="title"><a id="_basics_first"></a>Basics First</h4></div></div></div><p>All Entity operations MUST be done within a UnitOfWork. UnitOfWorks can be nested and if underlying UnitOfWorks are not +completed (method complete()), then none of the operations will be persisted permanently.</p><p>Entity composites are subtypes of the EntityComposite interface.</p><p>Domain code typically donât need to know of the EntityComposite types directly, and is instead using the domain specific +interface. The Visibility rules will be applied to associate the right EntityComposite when a domain type is requested. +Ambiguities are not accepted and will result in runtime exceptions.</p><p>Polygene⢠supports that each entity instance can have more than one entity type, and it is managed per instance. This feature +is beyond the scope of this HowTO and will be covered subsequently.</p></div><div class="section" title="Good Practice"><div class="titlepage"><div><div><h4 class="title"><a id="_good_practice"></a>Good Practice</h4></div></div></div><p>We have made the observation that it is good practice to separate the internal state from the observable behavior. By +this we mean that it is not a good practice to allow client code to manipulate or even view the internal states of +objects, which is such a common (bad) practice in the so called POJO world.</p><p>Instead, we recommend that the programmer defines the client requirement of what each participant within the client +context needs to conform to, and then create composites accordingly and hide all the state internal to the composite in +private mixins. By doing so, the same entity can participate in multiple contexts with different behavioral requirements +but using the same internal state.</p><p>We recommend limited use of primitive types for Properties and instead subtype the Property.</p><p>And try to use ValueComposites instead of Entities.</p></div><div class="section" title="The Entity"><div class="titlepage"><div><div><h4 class="title"><a id="_the_entity"></a>The Entity</h4></div></div></div><p>We need an entity to illustrate how we recommend to separate internal state from public behavior and observable state. +We will for the sake of simplicity use a trivial example. Please refer to other (possibly future) HowTos on patterns on +Entity management.</p><pre class="programlisting brush: java">public interface Car +{ + @Immutable + Association<Manufacturer> manufacturer(); + + @Immutable + Property<String> model(); + + ManyAssociation<Accident> accidents(); +} + +</pre><pre class="programlisting brush: java">public interface Manufacturer +{ + Property<String> name(); + Property<String> country(); + + @UseDefaults + Property<Long> carsProduced(); +} + +</pre><pre class="programlisting brush: java">public interface Accident +{ + Property<String> description(); + Property<LocalDate> occured(); + Property<LocalDate> repaired(); +} + +</pre><p>Above we define a Car domain object, which is of a particular Manufacturer (also an Entity), a model and a record of +Accidents.</p><p>We will also need to define the composites for the above domain structure;</p><pre class="programlisting brush: java">public interface CarEntity extends Car, EntityComposite +{} + +</pre><pre class="programlisting brush: java">public interface ManufacturerEntity extends Manufacturer, EntityComposite +{} + +</pre><pre class="programlisting brush: java">public interface AccidentValue extends Accident, ValueComposite +{} + +</pre><p>For this case, we define both the Car and the Manufacturer as Entities, whereas the Accident is a Value, since it is an +immutable event that can not be modified.</p></div><div class="section" title="Assembly"><div class="titlepage"><div><div><h4 class="title"><a id="_assembly"></a>Assembly</h4></div></div></div><p>All of the above must also be declared in the assembly. We MUST associate the EntityComposites with a relevant Module. +We must also assemble an EntityStore for the entire application, but that is outside the scope of this HowTo.</p><pre class="programlisting brush: java">public class MyAssembler + implements Assembler +{ + public void assemble( ModuleAssembly module ) + { + module.entities( CarEntity.class, + ManufacturerEntity.class ); + + module.values( AccidentValue.class ); + [...snip...] + + } +} +</pre><p>We have no other Composites involved yet, so we can proceed to look at the usage code.</p><p>We recommend that the life cycle management of entities is placed inside domain factories, one for each type and made +available as services.</p></div><div class="section" title="The Entity Factory"><div class="titlepage"><div><div><h4 class="title"><a id="_the_entity_factory"></a>The Entity Factory</h4></div></div></div><p>The entity factory is something you need to write yourself, but as with most things in Polygene⢠it will end up being a +fairly small implementation. So how is that done?</p><pre class="programlisting brush: java">public interface CarEntityFactory +{ + Car create(Manufacturer manufacturer, String model); +} + +</pre><p>That is just the domain interface. We now need to make the service interface, which Polygene⢠needs to identify services and +make it possible for the service injection later.</p><pre class="programlisting brush: java">@Mixins( { CarEntityFactoryMixin.class } ) +public interface CarEntityFactoryService + extends CarEntityFactory, ServiceComposite +{} +</pre><p>Then we need an implementation of the mixin.</p><pre class="programlisting brush: java">public class CarEntityFactoryMixin + implements CarEntityFactory +{ + +</pre><p>And doing that, first of all we need to request Polygene⢠runtime to give us the Module +that our code belongs to, and the UnitOfWork current context the execution is happening in.</p><p>Injections that are related to the Visibility rules are handled by the @Structure annotation. And the easiest way for us +to obtain a Module is simply to;</p><pre class="programlisting brush: java">public class CarEntityFactoryMixin + implements CarEntityFactory +{ + + @Structure + UnitOfWorkFactory unitOfWorkFactory; + +</pre><p>Here Polygene⢠will inject the member module with the correct Module. In case we only need the Module +during the construction, we can also request it in the same manner as constructor argument.</p><pre class="programlisting brush: java">public CarEntityFactoryMixin( @Structure UnitOfWorkFactory unitOfWorkFactory ) +{ +} + +</pre><p>This is important to know, since the injected member will not be available until AFTER the constructor has been +completed.</p><p>We then need to provide the implementation for the create() method.</p><pre class="programlisting brush: java">public Car create( Manufacturer manufacturer, String model ) +{ + UnitOfWork uow = unitOfWorkFactory.currentUnitOfWork(); + EntityBuilder<Car> builder = uow.newEntityBuilder( Car.class ); + + Car prototype = builder.instance(); + prototype.manufacturer().set( manufacturer ); + prototype.model().set( model ); + + return builder.newInstance(); +} +</pre><p>So far so good. But how about the Manufacturer input into the create() method?</p><p>DDD promotes the use of Repositories. They are the type-safe domain interfaces into locating entities without getting +bogged down with querying infrastructure details. And one Repository per Entity type, so we keep it nice, tidy and +re-usable. So letâs create one for the Manufacturer type.</p><pre class="programlisting brush: java">public interface ManufacturerRepository +{ + Manufacturer findByIdentity(Identity identity); + + Manufacturer findByName(String name); +} +</pre><p>And then we repeat the process for creating a Serviceâ¦</p><pre class="programlisting brush: java">@Mixins( ManufacturerRepositoryMixin.class ) +public interface ManufacturerRepositoryService + extends ManufacturerRepository, ServiceComposite +{} +</pre><p>and a Mixin that implements itâ¦</p><pre class="programlisting brush: java">public class ManufacturerRepositoryMixin + implements ManufacturerRepository +{ + @Structure + private UnitOfWorkFactory uowf; + + @Structure + private Module module; + + public Manufacturer findByIdentity( Identity identity ) + { + UnitOfWork uow = uowf.currentUnitOfWork(); + return uow.get(Manufacturer.class, identity ); + } + + public Manufacturer findByName( String name ) + { + UnitOfWork uow = uowf.currentUnitOfWork(); + QueryBuilder<Manufacturer> builder = + module.newQueryBuilder( Manufacturer.class ); + + Manufacturer template = templateFor( Manufacturer.class ); + builder.where( eq( template.name(), name ) ); + + Query<Manufacturer> query = uow.newQuery( builder); + return query.find(); + } +} + +</pre><p>But now we have introduced 2 services that also are required to be declared in the assembly. In this case, we want the +Services to be available to the application layer above, and not restricted to within this domain model.</p><pre class="programlisting brush: java">public class MyAssembler + implements Assembler +{ + public void assemble( ModuleAssembly module ) + { + module.entities( CarEntity.class, + ManufacturerEntity.class ); + + module.values( AccidentValue.class ); + module.addServices( + ManufacturerRepositoryService.class, + CarEntityFactoryService.class + ).visibleIn( Visibility.application ); + } +} +</pre></div><div class="section" title="The UnitOfWork"><div class="titlepage"><div><div><h4 class="title"><a id="_the_unitofwork"></a>The UnitOfWork</h4></div></div></div><p>If you notice, there is a couple of calls to Module.currentUnitOfWork(), but what is current UnitOfWork, and +who is setting that up?</p><p>Well, the domain layer should not worry about UoW, it is probably the responsibility of the application/service layer +sitting on top. That could be a web application creating and completing a UoW per request, or some other co-ordinator +doing long-running UnitOfWorks.</p><p>There are of course a lot more details to get all this completed, but that is beyond the scope of this HowTo. +See <a class="xref" href="core-api.html#core-api-unitofwork" title="Unit Of Work">UnitOfWork</a> in Core API.</p></div></div><div xmlns="" xmlns:exsl="http://exslt.org/common" class="footer"><p> + Copyright © 2015 The Apache Software Foundation, Licensed under the <a href="http://www.apache.org/licenses/" target="_blank">Apache License, Version 2.0</a>. + <br /><small> + Apache Polygene, Polygene, Apache, the Apache feather logo, and the Apache Polygene project logo are trademarks of The Apache Software Foundation.<br /> + All other marks mentioned may be trademarks or registered trademarks of their respective owners. + </small></p></div></body></html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-website/blob/ba3a0fac/content/java/develop/howto-create-sideeffect.html ---------------------------------------------------------------------- diff --git a/content/java/develop/howto-create-sideeffect.html b/content/java/develop/howto-create-sideeffect.html new file mode 100644 index 0000000..7b565b9 --- /dev/null +++ b/content/java/develop/howto-create-sideeffect.html @@ -0,0 +1,177 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Create a SideEffect</title><link rel="stylesheet" type="text/css" href="css/style.css" /><meta name="generator" content="DocBook XSL Stylesheets V1.76.1" /><link rel="home" href="index.html" title="" /><link rel="up" href="tutorials.html" title="Tutorials" /><link rel="prev" href="howto-create-concern.html" title="Create a Concern" /><link rel="next" href="howto-create-entity.html" title="Create an Entity" /> + + +<!-- favicon --> + +<link rel="shortcut icon" href="http://polygene.apache.org/favicon.ico" type="image/vnd.microsoft.icon" /> +<link rel="icon" href="http://polygene.apache.org/favicon.ico" type="image/x-icon" /> + +<!-- style --> + +<link href="css/shCore.css" rel="stylesheet" type="text/css" /> +<link href="css/shCoreEclipse.css" rel="stylesheet" type="text/css" /> +<link href="css/shThemeEclipse.css" rel="stylesheet" type="text/css" /> +<link href="css/polygene.css" rel="stylesheet" type="text/css" /> + +<!-- Syntax Highlighter --> + +<script type="text/javascript" src="js/shCore.js"></script> +<script type="text/javascript" src="js/shBrushJava.js"></script> +<script type="text/javascript" src="js/shBrushScala.js"></script> +<script type="text/javascript" src="js/shBrushJScript.js"></script> +<script type="text/javascript" src="js/shBrushBash.js"></script> +<script type="text/javascript" src="js/shBrushPlain.js"></script> +<script type="text/javascript" src="js/shBrushXml.js"></script> +<script type="text/javascript" src="js/shBrushGroovy.js"></script> +<script type="text/javascript" src="js/shBrushPython.js"></script> +<script type="text/javascript" src="js/shBrushRuby.js"></script> +<script type="text/javascript" src="js/shBrushCSharp.js"></script> + +<script type="text/javascript"> + SyntaxHighlighter.defaults['tab-size'] = 4; + SyntaxHighlighter.defaults['gutter'] = false; + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all() +</script> + +<!-- JQuery --> + +<script type="text/javascript" src="js/jquery-1.6.4.min.js"></script> + +<!-- Image Scaler --> + +<script type="text/javascript" src="js/imagescaler.js"></script> + +<!-- Table Styler --> + +<script type="text/javascript" src="js/tablestyler.js"></script> + +<!-- Apache Polygene WebSite Progressive Enhancement --> + +<link href="css/progressive-enhancement.css" rel="stylesheet" type="text/css" /> +<script type="text/javascript" src="js/jquery.scrollTo-1.4.2.js"></script> +<script type="text/javascript" src="js/progressive-enhancement.js"></script> + +<!-- Analytics --> + <script type="text/javascript"> + var _gaq = _gaq || []; + _gaq.push(['_setAccount', 'UA-62007352-1']); + _gaq.push(['_trackPageview']); + + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); + </script> + + </head><body><div xmlns="" xmlns:exsl="http://exslt.org/common" class="logo"><a href="index.html"><img src="images/logo-standard.png" /></a></div><div xmlns="" xmlns:exsl="http://exslt.org/common" class="top-nav"><div xmlns="http://www.w3.org/1999/xhtml" class="toc"><dl><dt><span class="section"><a href="index.html#home">Polygeneâ¢</a></span></dt><dt><span class="section"><a href="intro.html">Introduction</a></span></dt><dt><span class="section"><span xmlns="" href="tutorials.html">Tutorials</span></span></dt><dt><span class="section"><a href="javadocs.html">Javadoc</a></span></dt><dt><span class="section"><a href="samples.html">Samples</a></span></dt><dt><span class="section"><a href="core.html">Core</a></span></dt><dt><span class="section"><a href="libraries.html">Libraries</a></span></dt><dt><span class="section"><a href="extensions.html">Extensions</a></span></dt><dt><span class="section"><a href="tools.html">Tools</a></span></dt><dt><span class="section"><a href="glossary.ht ml">Glossary </a></span></dt></dl></div></div><div xmlns="" xmlns:exsl="http://exslt.org/common" class="sub-nav"><div xmlns="http://www.w3.org/1999/xhtml" class="toc"><dl><dt><span class="section"><a href="tutorials.html#_overview">Overview</a></span></dt><dt><span class="section"><a href="two-minutes-intro.html">Polygene⢠in 2 minutes</a></span></dt><dt><span class="section"><a href="ten-minutes-intro.html">Polygene⢠in 10 minutes</a></span></dt><dt><span class="section"><a href="thirty-minutes-intro.html">Polygene⢠in 30 minutes</a></span></dt><dt><span class="section"><a href="howto-depend-on-polygene.html">Depend on Polygeneâ¢</a></span></dt><dt><span class="section"><a href="howto-assemble-application.html">Assemble an Application</a></span></dt><dt><span class="section"><a href="tut-composites.html">Transient Composites Tutorial</a></span></dt><dt><span class="section"><a href="tut-services.html">Services Composites Tutorial</a></span></dt><dt><span class="section"><a href="howto-contextual-fragments.html">Use contextual fragments</a></span></dt><dt><span class="section"><a href="howto-leverage-properties.html">Leverage Properties</a></span></dt><dt><span class="section"><a href="howto-create-constraint.html">Create a Constraint</a></span></dt><dt><span class="section"><a href="howto-create-concern.html">Create a Concern</a></span></dt><dt><span class="section"><span xmlns="" href="howto-create-sideeffect.html">Create a SideEffect</span></span></dt><dt><span class="section"><a href="howto-create-entity.html">Create an Entity</a></span></dt><dt><span class="section"><a href="howto-configure-service.html">Configure a Service</a></span></dt><dt><span class="section"><a href="howto-invocation-annotation.html">Use @Invocation</a></span></dt><dt><span class="section"><a href="build-system.html">Polygene⢠Build System</a></span></dt><dt><span class="section"><a href="community-docs.html">Polygene⢠Documentation</a></span></dt><dt><span class="sectio n"><a href="releasing-apache.html">Releasing Polygeneâ¢</a></span></dt></dl></div></div><div class="section" title="Create a SideEffect"><div class="titlepage"><div><div><h3 class="title"><a id="howto-create-sideeffect"></a>Create a SideEffect</h3></div></div></div><p>SideEffects are defined in <a class="xref" href="glossary.html#def-sideeffect">SideEffect</a>.</p><p>If you want to reproduce whatâs explained in this tutorial, remember to depend on the Core Bootstrap artifact:</p><p>At runtime you will need the Core Runtime artifact too. See the <a class="xref" href="howto-depend-on-polygene.html" title="Depend on Polygeneâ¢">Depend on Polygeneâ¢</a> tutorial for details.</p><div class="section" title="Typed SideEffect"><div class="titlepage"><div><div><h4 class="title"><a id="_typed_sideeffect"></a>Typed SideEffect</h4></div></div></div><p>A typed SideEffect is a Java class that implements the MixinType it can be used on:</p><pre class="programlisting brush: java">public abstra ct class MailNotifySideEffect extends SideEffectOf<Confirmable> + implements Confirmable +{ + @Service + private MailService mailer; + + @This + private HasLineItems hasItems; + + @This + private HasCustomer hasCustomer; + + @Override + public void confirm() + { + StringBuilder builder = new StringBuilder(); + builder.append( "An Order has been made.\n\n\n" ); + builder.append( "Customer:" ); + builder.append( hasCustomer.name().get() ); + builder.append( "\n\nItems ordered:\n" ); + for( LineItem item : hasItems.lineItems().get() ) + { + builder.append( item.name().get() ); + builder.append( " : " ); + builder.append( item.quantity().get() ); + builder.append( "\n" ); + } + mailer.send( "[email protected]", builder.toString() ); + } +} +</pre><p>The MailNotifySideEffect is implemented as an abstract class, since we are not interested in the many other methods in +the Confirmable interface. Extending the SideEffectOf is a convenience mechanism, instead of an explicit @SideEffectFor +annotation on a private field, which can be used in rare occasions when you are not able to extend. This base class +defines the next field, which is set up by the Polygene⢠runtime and points to the next fragment in the call stack. We can +also see that the MailService, HasLineItems and HasCustomer are provided to the side-effect, which is done with +dependency injection. Polygene⢠also supports dependency injection via constructors and methods.</p><p>It can be used as follows;</p><pre class="programlisting brush: java">@SideEffects( MailNotifySideEffect.class ) +public interface OrderEntity + extends Order, HasSequenceNumber, HasCustomer, + HasLineItems, Confirmable, EntityComposite +{ +} +</pre><p>Methods of the SideEffect Fragment will be called after the Mixin invocation.</p></div><div class="section" title="Generic SideEffect"><div class="titlepage"><div><div><h4 class="title"><a id="_generic_sideeffect"></a>Generic SideEffect</h4></div></div></div><p>A generic SideEffect is a Java class that implements java.lang.reflect.InvocationHandler which allows it to be used on any +arbitrary MixinType.</p><pre class="programlisting brush: java">public class MyGenericSideEffect extends GenericSideEffect +{ + @Override + public Object invoke( Object proxy, Method method, Object[] args ) + throws Throwable + { + // Do whatever you need... + + try + { + // It is possible to obtain the returned values by using 'result' member; + Object returnedValue = result.invoke( proxy, method, args ); + } catch( NumberFormatException e ) + { + // And Exception will be thrown accordingly, in case you need to know. + throw new IllegalArgumentException(); // But any thrown exceptions are ignored. + } + return 23; // Return values will also be ignored. + } +} +</pre><p>It can be used as follows;</p><pre class="programlisting brush: java">@Concerns( MyGenericSideEffect.class ) +public interface AnyMixinType +{ + [...snip...] + +} +</pre><p>Methods of the SideEffect Fragment will be called before the Mixin invocation.</p><div class="section" title="AppliesTo"><div class="titlepage"><div><div><h5 class="title"><a id="_appliesto_2"></a>AppliesTo</h5></div></div></div><p>For generic SideEffects that should only trigger on methods with specific annotations or fulfilling some expression, add +@AppliesTo annotation to the SideEffect class which points to either triggering annotation(s), or to AppliesToFilter +implementation(s).</p><p>The SideEffect is invoked if one of the triggering annotations is found or one of the AppliesToFilter accepts the +invocation. In other words the AppliesTo arguments are ORâed.</p><p>Here is how the declaration goes ;</p><pre class="programlisting brush: java">@AppliesTo( { MyAnnotation.class, MyAppliesToFilter.class } ) +public class MyGenericSideEffect extends GenericSideEffect +{ + [...snip...] + +} +</pre><p>And how to use the annotation ;</p><pre class="programlisting brush: java">@Concerns( MyGenericSideEffect.class ) +public interface AnyMixinType +{ + + @MyAnnotation + void doSomething(); + + void doSomethingElse(); + +} + [...snip...] + +</pre><p>Here only the doSomething() method will see the SideEffect applied whereas the doSomethingElse() method wonât.</p><p>Finally here is how to implement an AppliesToFilter:</p><pre class="programlisting brush: java">public class MyAppliesToFilter implements AppliesToFilter +{ + public boolean appliesTo( Method method, Class<?> mixin, Class<?> compositeType, Class<?> modifierClass ) + { + boolean appliesTo = evaluate(method); // Do whatever you want + return appliesTo; + } + + [...snip...] + + private boolean evaluate( Method method ) + { + return true; + } +</pre></div></div></div><div xmlns="" xmlns:exsl="http://exslt.org/common" class="footer"><p> + Copyright © 2015 The Apache Software Foundation, Licensed under the <a href="http://www.apache.org/licenses/" target="_blank">Apache License, Version 2.0</a>. + <br /><small> + Apache Polygene, Polygene, Apache, the Apache feather logo, and the Apache Polygene project logo are trademarks of The Apache Software Foundation.<br /> + All other marks mentioned may be trademarks or registered trademarks of their respective owners. + </small></p></div></body></html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-website/blob/ba3a0fac/content/java/develop/howto-depend-on-polygene.html ---------------------------------------------------------------------- diff --git a/content/java/develop/howto-depend-on-polygene.html b/content/java/develop/howto-depend-on-polygene.html new file mode 100644 index 0000000..d8df773 --- /dev/null +++ b/content/java/develop/howto-depend-on-polygene.html @@ -0,0 +1,134 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Depend on Polygeneâ¢</title><link rel="stylesheet" type="text/css" href="css/style.css" /><meta name="generator" content="DocBook XSL Stylesheets V1.76.1" /><link rel="home" href="index.html" title="" /><link rel="up" href="tutorials.html" title="Tutorials" /><link rel="prev" href="thirty-minutes-intro.html" title="Polygene⢠in 30 minutes" /><link rel="next" href="howto-assemble-application.html" title="Assemble an Application" /> + + +<!-- favicon --> + +<link rel="shortcut icon" href="http://polygene.apache.org/favicon.ico" type="image/vnd.microsoft.icon" /> +<link rel="icon" href="http://polygene.apache.org/favicon.ico" type="image/x-icon" /> + +<!-- style --> + +<link href="css/shCore.css" rel="stylesheet" type="text/css" /> +<link href="css/shCoreEclipse.css" rel="stylesheet" type="text/css" /> +<link href="css/shThemeEclipse.css" rel="stylesheet" type="text/css" /> +<link href="css/polygene.css" rel="stylesheet" type="text/css" /> + +<!-- Syntax Highlighter --> + +<script type="text/javascript" src="js/shCore.js"></script> +<script type="text/javascript" src="js/shBrushJava.js"></script> +<script type="text/javascript" src="js/shBrushScala.js"></script> +<script type="text/javascript" src="js/shBrushJScript.js"></script> +<script type="text/javascript" src="js/shBrushBash.js"></script> +<script type="text/javascript" src="js/shBrushPlain.js"></script> +<script type="text/javascript" src="js/shBrushXml.js"></script> +<script type="text/javascript" src="js/shBrushGroovy.js"></script> +<script type="text/javascript" src="js/shBrushPython.js"></script> +<script type="text/javascript" src="js/shBrushRuby.js"></script> +<script type="text/javascript" src="js/shBrushCSharp.js"></script> + +<script type="text/javascript"> + SyntaxHighlighter.defaults['tab-size'] = 4; + SyntaxHighlighter.defaults['gutter'] = false; + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all() +</script> + +<!-- JQuery --> + +<script type="text/javascript" src="js/jquery-1.6.4.min.js"></script> + +<!-- Image Scaler --> + +<script type="text/javascript" src="js/imagescaler.js"></script> + +<!-- Table Styler --> + +<script type="text/javascript" src="js/tablestyler.js"></script> + +<!-- Apache Polygene WebSite Progressive Enhancement --> + +<link href="css/progressive-enhancement.css" rel="stylesheet" type="text/css" /> +<script type="text/javascript" src="js/jquery.scrollTo-1.4.2.js"></script> +<script type="text/javascript" src="js/progressive-enhancement.js"></script> + +<!-- Analytics --> + <script type="text/javascript"> + var _gaq = _gaq || []; + _gaq.push(['_setAccount', 'UA-62007352-1']); + _gaq.push(['_trackPageview']); + + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); + </script> + + </head><body><div xmlns="" xmlns:exsl="http://exslt.org/common" class="logo"><a href="index.html"><img src="images/logo-standard.png" /></a></div><div xmlns="" xmlns:exsl="http://exslt.org/common" class="top-nav"><div xmlns="http://www.w3.org/1999/xhtml" class="toc"><dl><dt><span class="section"><a href="index.html#home">Polygeneâ¢</a></span></dt><dt><span class="section"><a href="intro.html">Introduction</a></span></dt><dt><span class="section"><span xmlns="" href="tutorials.html">Tutorials</span></span></dt><dt><span class="section"><a href="javadocs.html">Javadoc</a></span></dt><dt><span class="section"><a href="samples.html">Samples</a></span></dt><dt><span class="section"><a href="core.html">Core</a></span></dt><dt><span class="section"><a href="libraries.html">Libraries</a></span></dt><dt><span class="section"><a href="extensions.html">Extensions</a></span></dt><dt><span class="section"><a href="tools.html">Tools</a></span></dt><dt><span class="section"><a href="glossary.ht ml">Glossary </a></span></dt></dl></div></div><div xmlns="" xmlns:exsl="http://exslt.org/common" class="sub-nav"><div xmlns="http://www.w3.org/1999/xhtml" class="toc"><dl><dt><span class="section"><a href="tutorials.html#_overview">Overview</a></span></dt><dt><span class="section"><a href="two-minutes-intro.html">Polygene⢠in 2 minutes</a></span></dt><dt><span class="section"><a href="ten-minutes-intro.html">Polygene⢠in 10 minutes</a></span></dt><dt><span class="section"><a href="thirty-minutes-intro.html">Polygene⢠in 30 minutes</a></span></dt><dt><span class="section"><span xmlns="" href="howto-depend-on-polygene.html">Depend on Polygeneâ¢</span></span></dt><dt><span class="section"><a href="howto-assemble-application.html">Assemble an Application</a></span></dt><dt><span class="section"><a href="tut-composites.html">Transient Composites Tutorial</a></span></dt><dt><span class="section"><a href="tut-services.html">Services Composites Tutorial</a></span></dt><dt><span clas s="section"><a href="howto-contextual-fragments.html">Use contextual fragments</a></span></dt><dt><span class="section"><a href="howto-leverage-properties.html">Leverage Properties</a></span></dt><dt><span class="section"><a href="howto-create-constraint.html">Create a Constraint</a></span></dt><dt><span class="section"><a href="howto-create-concern.html">Create a Concern</a></span></dt><dt><span class="section"><a href="howto-create-sideeffect.html">Create a SideEffect</a></span></dt><dt><span class="section"><a href="howto-create-entity.html">Create an Entity</a></span></dt><dt><span class="section"><a href="howto-configure-service.html">Configure a Service</a></span></dt><dt><span class="section"><a href="howto-invocation-annotation.html">Use @Invocation</a></span></dt><dt><span class="section"><a href="build-system.html">Polygene⢠Build System</a></span></dt><dt><span class="section"><a href="community-docs.html">Polygene⢠Documentation</a></span></dt><dt><span class="sectio n"><a href="releasing-apache.html">Releasing Polygeneâ¢</a></span></dt></dl></div></div><div class="section" title="Depend on Polygeneâ¢"><div class="titlepage"><div><div><h3 class="title"><a id="howto-depend-on-polygene"></a>Depend on Polygeneâ¢</h3></div></div></div><div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Some of the <a class="xref" href="libraries.html" title="Libraries">Libraries</a> and <a class="xref" href="extensions.html" title="Extensions">Extensions</a> depend on artifacts that are not deployed in central, youâll need to +add other repositories to your build scripts accordingly.</p></div><p>Release artifacts, including sources and javadoc, are deployed to Maven Central:</p><p><a class="ulink" href="http://repo1.maven.org/maven2/" target="_top">http://repo1.maven.org/maven2/</a> (US)</p><p><a class="ulink" href="http://uk.maven.org/maven2/" target="_top">http://uk.maven.org/maven2/</a> (Europe)</p><p>Snapshot artifacts, including sources and javadoc, are built against the <code class="literal">develop</code> branch and deployed weekly to the Apache SNAPSHOTS repository:</p><p><a class="ulink" href="http://repository.apache.org/snapshots/" target="_top">http://repository.apache.org/snapshots/</a></p><div class="section" title="Manually"><div class="titlepage"><div><div><h4 class="title"><a id="_manually"></a>Manually</h4></div></div></div><p>If you donât rely on your build scripts dependency resolution mechanism you should +<a class="ulink" href="https://polygene.apache.org/download.html" target="_top">download</a> the SDK distribution.</p></div><div class="section" title="Using Maven"><div class="titlepage"><div><div><h4 class="title"><a id="_using_maven"></a>Using Maven</h4></div></div></div><p>You simply declare dependencies on Polygene⢠artifacts:</p><pre class="programlisting brush: xml"><dependencies> + <dependency> + <groupId>org.apache.polygene.core</groupId> + <artifactId>org.apache.polygene.core.bootstrap</artifactId> + <version>POLYGENE_VERSION</version> + </dependency> + <dependency> + <groupId>org.apache.polygene.core</groupId> + <artifactId>org.apache.polygene.core.runtime</artifactId> + <version>POLYGENE_VERSION</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>org.apache.polygene.core</groupId> + <artifactId>org.apache.polygene.core.testsupport</artifactId> + <version>POLYGENE_VERSION</version> + <scope>test</scope> + </dependency> +</dependencies></pre><p>Where <code class="literal">POLYGENE_VERSION</code> is the Polygene⢠version you want to use.</p><p>If you want to use <code class="literal">-SNAPSHOT</code> versions, you need to register the Apache Snapshots repository:</p><pre class="programlisting brush: xml"><repositories> + <repository> + <id>apache-snapshots</id> + <url>https://repository.apache.org/snapshots/</url> + <releases><enabled>false</enabled></releases> + <snapshots><enabled>true</enabled></snapshots> + </repository> +</repositories></pre></div><div class="section" title="Using Gradle"><div class="titlepage"><div><div><h4 class="title"><a id="_using_gradle"></a>Using Gradle</h4></div></div></div><p>You simply declare dependencies on Polygene⢠artifacts:</p><pre class="programlisting brush: groovy">dependencies { + compile "org.apache.polygene.core:org.apache.polygene.core.bootstrap:POLYGENE_VERSION" + runtime "org.apache.polygene.core:org.apache.polygene.core.runtime:POLYGENE_VERSION" + testCompile "org.apache.polygene.core:org.apache.polygene.core.testsupport:POLYGENE_VERSION" +}</pre><p>Where <code class="literal">POLYGENE_VERSION</code> is the Polygene⢠version you want to use.</p><p>If you want to use <code class="literal">-SNAPSHOT</code> versions, you need to register the Apache Snapshots repository:</p><pre class="programlisting brush: groovy">repositories { + maven { name 'apache-snapshots'; url "https://repository.apache.org/snapshots/" } +}</pre></div><div class="section" title="Using Buildr"><div class="titlepage"><div><div><h4 class="title"><a id="_using_buildr"></a>Using Buildr</h4></div></div></div><p>You simply declare dependencies on Polygene⢠artifacts:</p><pre class="programlisting brush: ruby">compile.with 'org.apache.polygene.core:org.apache.polygene.core.bootstrap:POLYGENE_VERSION' +package(:war).with :libs => 'org.apache.polygene.core:org.apache.polygene.core.runtime:POLYGENE_VERSION' +test.with 'org.apache.polygene.core:org.apache.polygene.core.testsupport:POLYGENE_VERSION'</pre><p>Where <code class="literal">POLYGENE_VERSION</code> is the Polygene⢠version you want to use.</p><p>If you want to use <code class="literal">-SNAPSHOT</code> versions, you need to register the Apache Snapshots repository:</p><pre class="programlisting brush: ruby">repositories.remote << 'https://repository.apache.org/snapshots/'</pre></div><div class="section" title="Using SBT"><div class="titlepage"><div><div><h4 class="title"><a id="_using_sbt"></a>Using SBT</h4></div></div></div><p>You simply declare dependencies on Polygene⢠artifacts:</p><pre class="programlisting brush: scala">libraryDependencies += \ + "org.apache.polygene.core" % "org.apache.polygene.core.bootstrap" % "POLYGENE_VERSION" \ + withSources() withJavadoc() +libraryDependencies += \ + "org.apache.polygene.core" % "org.apache.polygene.core.runtime" % "POLYGENE_VERSION" % "runtime" \ + withSources() withJavadoc() +libraryDependencies += \ + "org.apache.polygene.core" % "org.apache.polygene.core.testsupport" % "POLYGENE_VERSION" % "test" \ + withSources() withJavadoc()</pre><p>Where <code class="literal">POLYGENE_VERSION</code> is the Polygene⢠version you want to use.</p><p>If you want to use <code class="literal">-SNAPSHOT</code> versions, you need to register the Apache Snapshots repository:</p><pre class="programlisting brush: scala">resolvers += "apache-snapshots" at "https://repository.apache.org/snapshots/"</pre></div><div class="section" title="Using Ivy"><div class="titlepage"><div><div><h4 class="title"><a id="_using_ivy"></a>Using Ivy</h4></div></div></div><p>You simply declare dependencies on Polygene⢠artifacts:</p><pre class="programlisting brush: xml"><ivy-module> + <dependencies> + <dependency org="org.apache.polygene.core" name="org.apache.polygene.core.bootstrap" + rev="POLYGENE_VERSION" conf="default" /> + <dependency org="org.apache.polygene.core" name="org.apache.polygene.core.runtime" + rev="POLYGENE_VERSION" conf="runtime" /> + <dependency org="org.apache.polygene.core" name="org.apache.polygene.core.testsupport" + rev="POLYGENE_VERSION" conf="test" /> + </dependencies> +</ivy-module></pre><p>Where <code class="literal">POLYGENE_VERSION</code> is the Polygene⢠version you want to use.</p><p>If you want to use <code class="literal">-SNAPSHOT</code> versions, you need to register the Apache Snapshots repository in a <code class="literal">ivysettings.xml</code> file:</p><pre class="programlisting brush: xml"><ivysettings> + <settings defaultResolver="chain"/> + <resolvers> + <chain name="chain"> + <ibiblio name="apache-snapshots" m2compatible="true" + root="https://repository.apache.org/snapshots/"/> + </chain> + </resolvers> +</ivysettings></pre></div></div><div xmlns="" xmlns:exsl="http://exslt.org/common" class="footer"><p> + Copyright © 2015 The Apache Software Foundation, Licensed under the <a href="http://www.apache.org/licenses/" target="_blank">Apache License, Version 2.0</a>. + <br /><small> + Apache Polygene, Polygene, Apache, the Apache feather logo, and the Apache Polygene project logo are trademarks of The Apache Software Foundation.<br /> + All other marks mentioned may be trademarks or registered trademarks of their respective owners. + </small></p></div></body></html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-website/blob/ba3a0fac/content/java/develop/howto-invocation-annotation.html ---------------------------------------------------------------------- diff --git a/content/java/develop/howto-invocation-annotation.html b/content/java/develop/howto-invocation-annotation.html new file mode 100644 index 0000000..1765b4a --- /dev/null +++ b/content/java/develop/howto-invocation-annotation.html @@ -0,0 +1,109 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Use @Invocation</title><link rel="stylesheet" type="text/css" href="css/style.css" /><meta name="generator" content="DocBook XSL Stylesheets V1.76.1" /><link rel="home" href="index.html" title="" /><link rel="up" href="tutorials.html" title="Tutorials" /><link rel="prev" href="howto-configure-service.html" title="Configure a Service" /><link rel="next" href="build-system.html" title="Polygene⢠Build System" /> + + +<!-- favicon --> + +<link rel="shortcut icon" href="http://polygene.apache.org/favicon.ico" type="image/vnd.microsoft.icon" /> +<link rel="icon" href="http://polygene.apache.org/favicon.ico" type="image/x-icon" /> + +<!-- style --> + +<link href="css/shCore.css" rel="stylesheet" type="text/css" /> +<link href="css/shCoreEclipse.css" rel="stylesheet" type="text/css" /> +<link href="css/shThemeEclipse.css" rel="stylesheet" type="text/css" /> +<link href="css/polygene.css" rel="stylesheet" type="text/css" /> + +<!-- Syntax Highlighter --> + +<script type="text/javascript" src="js/shCore.js"></script> +<script type="text/javascript" src="js/shBrushJava.js"></script> +<script type="text/javascript" src="js/shBrushScala.js"></script> +<script type="text/javascript" src="js/shBrushJScript.js"></script> +<script type="text/javascript" src="js/shBrushBash.js"></script> +<script type="text/javascript" src="js/shBrushPlain.js"></script> +<script type="text/javascript" src="js/shBrushXml.js"></script> +<script type="text/javascript" src="js/shBrushGroovy.js"></script> +<script type="text/javascript" src="js/shBrushPython.js"></script> +<script type="text/javascript" src="js/shBrushRuby.js"></script> +<script type="text/javascript" src="js/shBrushCSharp.js"></script> + +<script type="text/javascript"> + SyntaxHighlighter.defaults['tab-size'] = 4; + SyntaxHighlighter.defaults['gutter'] = false; + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all() +</script> + +<!-- JQuery --> + +<script type="text/javascript" src="js/jquery-1.6.4.min.js"></script> + +<!-- Image Scaler --> + +<script type="text/javascript" src="js/imagescaler.js"></script> + +<!-- Table Styler --> + +<script type="text/javascript" src="js/tablestyler.js"></script> + +<!-- Apache Polygene WebSite Progressive Enhancement --> + +<link href="css/progressive-enhancement.css" rel="stylesheet" type="text/css" /> +<script type="text/javascript" src="js/jquery.scrollTo-1.4.2.js"></script> +<script type="text/javascript" src="js/progressive-enhancement.js"></script> + +<!-- Analytics --> + <script type="text/javascript"> + var _gaq = _gaq || []; + _gaq.push(['_setAccount', 'UA-62007352-1']); + _gaq.push(['_trackPageview']); + + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); + </script> + + </head><body><div xmlns="" xmlns:exsl="http://exslt.org/common" class="logo"><a href="index.html"><img src="images/logo-standard.png" /></a></div><div xmlns="" xmlns:exsl="http://exslt.org/common" class="top-nav"><div xmlns="http://www.w3.org/1999/xhtml" class="toc"><dl><dt><span class="section"><a href="index.html#home">Polygeneâ¢</a></span></dt><dt><span class="section"><a href="intro.html">Introduction</a></span></dt><dt><span class="section"><span xmlns="" href="tutorials.html">Tutorials</span></span></dt><dt><span class="section"><a href="javadocs.html">Javadoc</a></span></dt><dt><span class="section"><a href="samples.html">Samples</a></span></dt><dt><span class="section"><a href="core.html">Core</a></span></dt><dt><span class="section"><a href="libraries.html">Libraries</a></span></dt><dt><span class="section"><a href="extensions.html">Extensions</a></span></dt><dt><span class="section"><a href="tools.html">Tools</a></span></dt><dt><span class="section"><a href="glossary.ht ml">Glossary </a></span></dt></dl></div></div><div xmlns="" xmlns:exsl="http://exslt.org/common" class="sub-nav"><div xmlns="http://www.w3.org/1999/xhtml" class="toc"><dl><dt><span class="section"><a href="tutorials.html#_overview">Overview</a></span></dt><dt><span class="section"><a href="two-minutes-intro.html">Polygene⢠in 2 minutes</a></span></dt><dt><span class="section"><a href="ten-minutes-intro.html">Polygene⢠in 10 minutes</a></span></dt><dt><span class="section"><a href="thirty-minutes-intro.html">Polygene⢠in 30 minutes</a></span></dt><dt><span class="section"><a href="howto-depend-on-polygene.html">Depend on Polygeneâ¢</a></span></dt><dt><span class="section"><a href="howto-assemble-application.html">Assemble an Application</a></span></dt><dt><span class="section"><a href="tut-composites.html">Transient Composites Tutorial</a></span></dt><dt><span class="section"><a href="tut-services.html">Services Composites Tutorial</a></span></dt><dt><span class="section"><a href="howto-contextual-fragments.html">Use contextual fragments</a></span></dt><dt><span class="section"><a href="howto-leverage-properties.html">Leverage Properties</a></span></dt><dt><span class="section"><a href="howto-create-constraint.html">Create a Constraint</a></span></dt><dt><span class="section"><a href="howto-create-concern.html">Create a Concern</a></span></dt><dt><span class="section"><a href="howto-create-sideeffect.html">Create a SideEffect</a></span></dt><dt><span class="section"><a href="howto-create-entity.html">Create an Entity</a></span></dt><dt><span class="section"><a href="howto-configure-service.html">Configure a Service</a></span></dt><dt><span class="section"><span xmlns="" href="howto-invocation-annotation.html">Use @Invocation</span></span></dt><dt><span class="section"><a href="build-system.html">Polygene⢠Build System</a></span></dt><dt><span class="section"><a href="community-docs.html">Polygene⢠Documentation</a></span></dt><dt><span class="sectio n"><a href="releasing-apache.html">Releasing Polygeneâ¢</a></span></dt></dl></div></div><div class="section" title="Use @Invocation"><div class="titlepage"><div><div><h3 class="title"><a id="howto-invocation-annotation"></a>Use @Invocation</h3></div></div></div><p>The @Invocation annotation is relatively unknown but can be rather powerful to use, especially when creating +libraries that needs to be flexible of what the user needs to do.</p><p>@Invocation is a different <code class="literal">InjectionScope</code>, which is a concept to tell Polygene runtime where to look for the +instances to be injected. Other, more well-known, <code class="literal">InjectionScope</code> annotations are <code class="literal">@This</code>, <code class="literal">@Structure</code> and +<code class="literal">@Service</code>.</p><p>The <code class="literal">@Invocation</code> injection scope can provide the following types, all related to the on-going method invocation, +which is especially useful in Generic Concerns or Generic Mixins;</p><div class="itemizedlist"><ul class="itemizedlist"><li class="listitem"> +<code class="literal">java.lang.reflect.Method</code> - The current method being invoked. +</li><li class="listitem"> +<code class="literal">java.lang.reflect.AnnotatedElement</code> - An descriptor for all annotations of the Method. +</li><li class="listitem"> +<span class="emphasis"><em>Custom Annotations</em></span> - Your own annotation type. +</li><li class="listitem"> +<code class="literal">java.util.Iterable<Method></code> - An iterable of all declared methods of the composite type. +</li></ul></div><div class="section" title="java.lang.reflect.Method"><div class="titlepage"><div><div><h4 class="title"><a id="_java_lang_reflect_method"></a>java.lang.reflect.Method</h4></div></div></div><p>This injection will simply provide the <code class="literal">java.lang.reflect.Method</code> of the on-going call. For generic fragments that +will be the same as the second argument in the <code class="literal">java.lang.reflect.InvocationHandler.invoke()</code> method. Sometimes +it is useful to obtain this for typed fragment as well, to reduce names in Strings.</p></div><div class="section" title="java.lang.reflect.AnnotatedElement"><div class="titlepage"><div><div><h4 class="title"><a id="_java_lang_reflect_annotatedelement"></a>java.lang.reflect.AnnotatedElement</h4></div></div></div><p>This Reflection API class encapsulates the annotation aspect of any element that can be annotated. Polygene implements +this interface for the Composite. That means that annotations for both the method as well as the composite is provided +through this injection.</p></div><div class="section" title="Custom Annotations"><div class="titlepage"><div><div><h4 class="title"><a id="_custom_annotations"></a>Custom Annotations</h4></div></div></div><p>It is often useful to introduce oneâs own annotations, especially for libraries, and use these annotations to direct +the runtime to do different things. Many of the "built-in" features in Polygene is actually done by this mechanism and +not directly implemented in the Core Runtime.</p><p>First create an annotation of your own liking, it must have <code class="literal">java.lang.annotation.Retention</code> set to <code class="literal">RUNTIME</code></p><pre class="programlisting brush: java">@Retention( RUNTIME ) +@interface Foo +{ + String value(); +} +</pre><p>After that it is possible to have this annotation placed on composite type methods,</p><pre class="programlisting brush: java">public interface MyComposite + extends TransientComposite +{ + @Foo( "1" ) + void doStuff(); +</pre><p>and then the annotation can simply be injected into your Concerns or Mixins, like this;</p><pre class="programlisting brush: java">public abstract static class MyConcern + extends ConcernOf<MyComposite> + implements MyComposite +{ + @Invocation + Foo foo; +</pre></div><div class="section" title="java.util.Iterable<Method>"><div class="titlepage"><div><div><h4 class="title"><a id="_java_util_iterable_lt_method_gt"></a>java.util.Iterable<Method></h4></div></div></div><p>This injection will provide all the declared methods of the current composite. This is particularly useful for mixins +or concerns that builds information about the composite they belong to.</p></div></div><div xmlns="" xmlns:exsl="http://exslt.org/common" class="footer"><p> + Copyright © 2015 The Apache Software Foundation, Licensed under the <a href="http://www.apache.org/licenses/" target="_blank">Apache License, Version 2.0</a>. + <br /><small> + Apache Polygene, Polygene, Apache, the Apache feather logo, and the Apache Polygene project logo are trademarks of The Apache Software Foundation.<br /> + All other marks mentioned may be trademarks or registered trademarks of their respective owners. + </small></p></div></body></html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-website/blob/ba3a0fac/content/java/develop/howto-leverage-properties.html ---------------------------------------------------------------------- diff --git a/content/java/develop/howto-leverage-properties.html b/content/java/develop/howto-leverage-properties.html new file mode 100644 index 0000000..6c85b9a --- /dev/null +++ b/content/java/develop/howto-leverage-properties.html @@ -0,0 +1,140 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Leverage Properties</title><link rel="stylesheet" type="text/css" href="css/style.css" /><meta name="generator" content="DocBook XSL Stylesheets V1.76.1" /><link rel="home" href="index.html" title="" /><link rel="up" href="tutorials.html" title="Tutorials" /><link rel="prev" href="howto-contextual-fragments.html" title="Use contextual fragments" /><link rel="next" href="howto-create-constraint.html" title="Create a Constraint" /> + + +<!-- favicon --> + +<link rel="shortcut icon" href="http://polygene.apache.org/favicon.ico" type="image/vnd.microsoft.icon" /> +<link rel="icon" href="http://polygene.apache.org/favicon.ico" type="image/x-icon" /> + +<!-- style --> + +<link href="css/shCore.css" rel="stylesheet" type="text/css" /> +<link href="css/shCoreEclipse.css" rel="stylesheet" type="text/css" /> +<link href="css/shThemeEclipse.css" rel="stylesheet" type="text/css" /> +<link href="css/polygene.css" rel="stylesheet" type="text/css" /> + +<!-- Syntax Highlighter --> + +<script type="text/javascript" src="js/shCore.js"></script> +<script type="text/javascript" src="js/shBrushJava.js"></script> +<script type="text/javascript" src="js/shBrushScala.js"></script> +<script type="text/javascript" src="js/shBrushJScript.js"></script> +<script type="text/javascript" src="js/shBrushBash.js"></script> +<script type="text/javascript" src="js/shBrushPlain.js"></script> +<script type="text/javascript" src="js/shBrushXml.js"></script> +<script type="text/javascript" src="js/shBrushGroovy.js"></script> +<script type="text/javascript" src="js/shBrushPython.js"></script> +<script type="text/javascript" src="js/shBrushRuby.js"></script> +<script type="text/javascript" src="js/shBrushCSharp.js"></script> + +<script type="text/javascript"> + SyntaxHighlighter.defaults['tab-size'] = 4; + SyntaxHighlighter.defaults['gutter'] = false; + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all() +</script> + +<!-- JQuery --> + +<script type="text/javascript" src="js/jquery-1.6.4.min.js"></script> + +<!-- Image Scaler --> + +<script type="text/javascript" src="js/imagescaler.js"></script> + +<!-- Table Styler --> + +<script type="text/javascript" src="js/tablestyler.js"></script> + +<!-- Apache Polygene WebSite Progressive Enhancement --> + +<link href="css/progressive-enhancement.css" rel="stylesheet" type="text/css" /> +<script type="text/javascript" src="js/jquery.scrollTo-1.4.2.js"></script> +<script type="text/javascript" src="js/progressive-enhancement.js"></script> + +<!-- Analytics --> + <script type="text/javascript"> + var _gaq = _gaq || []; + _gaq.push(['_setAccount', 'UA-62007352-1']); + _gaq.push(['_trackPageview']); + + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); + </script> + + </head><body><div xmlns="" xmlns:exsl="http://exslt.org/common" class="logo"><a href="index.html"><img src="images/logo-standard.png" /></a></div><div xmlns="" xmlns:exsl="http://exslt.org/common" class="top-nav"><div xmlns="http://www.w3.org/1999/xhtml" class="toc"><dl><dt><span class="section"><a href="index.html#home">Polygeneâ¢</a></span></dt><dt><span class="section"><a href="intro.html">Introduction</a></span></dt><dt><span class="section"><span xmlns="" href="tutorials.html">Tutorials</span></span></dt><dt><span class="section"><a href="javadocs.html">Javadoc</a></span></dt><dt><span class="section"><a href="samples.html">Samples</a></span></dt><dt><span class="section"><a href="core.html">Core</a></span></dt><dt><span class="section"><a href="libraries.html">Libraries</a></span></dt><dt><span class="section"><a href="extensions.html">Extensions</a></span></dt><dt><span class="section"><a href="tools.html">Tools</a></span></dt><dt><span class="section"><a href="glossary.ht ml">Glossary </a></span></dt></dl></div></div><div xmlns="" xmlns:exsl="http://exslt.org/common" class="sub-nav"><div xmlns="http://www.w3.org/1999/xhtml" class="toc"><dl><dt><span class="section"><a href="tutorials.html#_overview">Overview</a></span></dt><dt><span class="section"><a href="two-minutes-intro.html">Polygene⢠in 2 minutes</a></span></dt><dt><span class="section"><a href="ten-minutes-intro.html">Polygene⢠in 10 minutes</a></span></dt><dt><span class="section"><a href="thirty-minutes-intro.html">Polygene⢠in 30 minutes</a></span></dt><dt><span class="section"><a href="howto-depend-on-polygene.html">Depend on Polygeneâ¢</a></span></dt><dt><span class="section"><a href="howto-assemble-application.html">Assemble an Application</a></span></dt><dt><span class="section"><a href="tut-composites.html">Transient Composites Tutorial</a></span></dt><dt><span class="section"><a href="tut-services.html">Services Composites Tutorial</a></span></dt><dt><span class="section"><a href="howto-contextual-fragments.html">Use contextual fragments</a></span></dt><dt><span class="section"><span xmlns="" href="howto-leverage-properties.html">Leverage Properties</span></span></dt><dt><span class="section"><a href="howto-create-constraint.html">Create a Constraint</a></span></dt><dt><span class="section"><a href="howto-create-concern.html">Create a Concern</a></span></dt><dt><span class="section"><a href="howto-create-sideeffect.html">Create a SideEffect</a></span></dt><dt><span class="section"><a href="howto-create-entity.html">Create an Entity</a></span></dt><dt><span class="section"><a href="howto-configure-service.html">Configure a Service</a></span></dt><dt><span class="section"><a href="howto-invocation-annotation.html">Use @Invocation</a></span></dt><dt><span class="section"><a href="build-system.html">Polygene⢠Build System</a></span></dt><dt><span class="section"><a href="community-docs.html">Polygene⢠Documentation</a></span></dt><dt><span class="sectio n"><a href="releasing-apache.html">Releasing Polygeneâ¢</a></span></dt></dl></div></div><div class="section" title="Leverage Properties"><div class="titlepage"><div><div><h3 class="title"><a id="howto-leverage-properties"></a>Leverage Properties</h3></div></div></div><p>Polygene⢠does not follow the JavaBeans standard for property support. Instead, a much more explicit concept is in place. The +advantages are enormous, and the only real downside is that people are already destroyed, thinking in so called POJO +terms.</p><p>If you want to reproduce whatâs explained in this tutorial, remember to depend on the Core API artifact:</p><p>At runtime you will need the Core Runtime artifact too. See the <a class="xref" href="howto-depend-on-polygene.html" title="Depend on Polygeneâ¢">Depend on Polygeneâ¢</a> tutorial for details.</p><p>So in Polygene, instead of writing;</p><pre class="programlisting brush: java">public interface Book +{ + String getTitle(); + String getAuthor(); +} +</pre><pre class="programlisting brush: java">public interface MutableBook extends Book +{ + void setTitle( String title ); + void setAuthor( String author ); +} +</pre><p>where we need the MutableBook to be able to initialize it (known as Type 2 Dependency Injection) on creation. From our +point of view, this has many flaws. If we refactor the "Title" property, our IDE need to understand the getters and +setters concept. The good news now is that they all do, but how about meta information about the property itself. For +instance, how to define a system where a UI can get an Icon for "Author" in a generic way? All kinds of system has been +added, such as one can create a BookBean for some metadata, and then MBeans for management. Where will it end?</p><p>We think we have a much better solution, and are bold enough to abandon the getters/setters and POJOs. The above looks +like this;</p><pre class="programlisting brush: java">public interface Book +{ + @Immutable + Property<String> title(); + + @Immutable + Property<String> author(); +} +</pre><p>There is more to this than meets the eye.</p><div class="itemizedlist"><ul class="itemizedlist"><li class="listitem"> +@Immutable annotation signals that this canât change. +</li><li class="listitem"> +Property still have a set() method, which can be used during the initialization only. +</li><li class="listitem"> +Metadata about each Property can be declared as <a class="xref" href="glossary.html#def-metainfo">MetaInfo</a>. +</li></ul></div><pre class="programlisting brush: java">@Structure +Module module; + [...snip...] + + TransientBuilder<Book> builder = module.newTransientBuilder( Book.class ); + Book prototype = builder.prototype(); + prototype.title().set( "The Death of POJOs" ); + prototype.author().set( "Niclas Hedhman" ); + Book book = builder.newInstance(); + String title = book.title().get(); // Retrieves the title. + book.title().set( "Long Live POJOs" ); // throws an IllegalStateException +</pre><div class="section" title="Persistence"><div class="titlepage"><div><div><h4 class="title"><a id="_persistence"></a>Persistence</h4></div></div></div><p>The Property concept also allows a much better defined persistence model. In Polygene, only Property and Association +instances are persisted, and that makes the semantics around the persistence system very clear.</p><p>Properties reference values only, and these values must be Serializable, which means that Properties can not contain +Entities, since Entities are not Serializable. Associations are the opposite, as they must only reference Entities and +nothing else.</p></div><div class="section" title="MetaInfo"><div class="titlepage"><div><div><h4 class="title"><a id="_metainfo"></a>MetaInfo</h4></div></div></div><p>Properties can also have typed, custom meta information associated with them. Meta information is declared once per +Property per Module. A Property is identified by its method name and the interface it is declared in.</p><p>Letâs say we want to create a generic Swing client that can show and navigate the domain model, without knowing the +actual domain model. Such Swing client will utilize a SwingInfo property info if it is available.</p><pre class="programlisting brush: java">public interface SwingInfo +{ + Icon icon( Rectangle size ); + + String displayName( Locale locale ); +} +</pre><p>Our generic Swing UI will be mainly reflective in nature, but when it gets hold of a Property, it can simply do;</p><pre class="programlisting brush: java"> @Structure + private PolygeneAPI api; + [...snip...] + + private void addProperty( JPanel panel, Property<?> property ) + { + SwingInfo info = api.propertyDescriptorFor( property ).metaInfo( SwingInfo.class ); + Icon icon = info.icon( SIZE_32_32 ); + panel.add( new JLabel(info.displayName( this.locale ), icon, JLabel.CENTER) ); + } + [...snip...] + +} +</pre></div></div><div xmlns="" xmlns:exsl="http://exslt.org/common" class="footer"><p> + Copyright © 2015 The Apache Software Foundation, Licensed under the <a href="http://www.apache.org/licenses/" target="_blank">Apache License, Version 2.0</a>. + <br /><small> + Apache Polygene, Polygene, Apache, the Apache feather logo, and the Apache Polygene project logo are trademarks of The Apache Software Foundation.<br /> + All other marks mentioned may be trademarks or registered trademarks of their respective owners. + </small></p></div></body></html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-website/blob/ba3a0fac/content/java/develop/images/classes-are-dead.gif ---------------------------------------------------------------------- diff --git a/content/java/develop/images/classes-are-dead.gif b/content/java/develop/images/classes-are-dead.gif new file mode 100644 index 0000000..0280817 Binary files /dev/null and b/content/java/develop/images/classes-are-dead.gif differ http://git-wip-us.apache.org/repos/asf/polygene-website/blob/ba3a0fac/content/java/develop/images/cloudbees.png ---------------------------------------------------------------------- diff --git a/content/java/develop/images/cloudbees.png b/content/java/develop/images/cloudbees.png new file mode 100644 index 0000000..b9d0c94 Binary files /dev/null and b/content/java/develop/images/cloudbees.png differ http://git-wip-us.apache.org/repos/asf/polygene-website/blob/ba3a0fac/content/java/develop/images/core-overview.png ---------------------------------------------------------------------- diff --git a/content/java/develop/images/core-overview.png b/content/java/develop/images/core-overview.png new file mode 100644 index 0000000..8d1a4d9 Binary files /dev/null and b/content/java/develop/images/core-overview.png differ http://git-wip-us.apache.org/repos/asf/polygene-website/blob/ba3a0fac/content/java/develop/images/forkme_left_red.png ---------------------------------------------------------------------- diff --git a/content/java/develop/images/forkme_left_red.png b/content/java/develop/images/forkme_left_red.png new file mode 100644 index 0000000..3aacaef Binary files /dev/null and b/content/java/develop/images/forkme_left_red.png differ http://git-wip-us.apache.org/repos/asf/polygene-website/blob/ba3a0fac/content/java/develop/images/icons/README ---------------------------------------------------------------------- diff --git a/content/java/develop/images/icons/README b/content/java/develop/images/icons/README new file mode 100644 index 0000000..f12b2a7 --- /dev/null +++ b/content/java/develop/images/icons/README @@ -0,0 +1,5 @@ +Replaced the plain DocBook XSL admonition icons with Jimmac's DocBook +icons (http://jimmac.musichall.cz/ikony.php3). I dropped transparency +from the Jimmac icons to get round MS IE and FOP PNG incompatibilies. + +Stuart Rackham http://git-wip-us.apache.org/repos/asf/polygene-website/blob/ba3a0fac/content/java/develop/images/icons/admon/caution.png ---------------------------------------------------------------------- diff --git a/content/java/develop/images/icons/admon/caution.png b/content/java/develop/images/icons/admon/caution.png new file mode 100644 index 0000000..c6b6fd4 Binary files /dev/null and b/content/java/develop/images/icons/admon/caution.png differ
