You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polygene.apache.org by ni...@apache.org on 2015/07/30 21:48:46 UTC

[47/80] [partial] zest-java git commit: First round of changes to move to org.apache.zest namespace.

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/constraint/Constraints.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/constraint/Constraints.java b/core/api/src/main/java/org/apache/zest/api/constraint/Constraints.java
new file mode 100644
index 0000000..f7828b5
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/constraint/Constraints.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.zest.api.constraint;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * This annotation is used by composites and mixins to declare what Constraints
+ * can be applied in the Composite.
+ * <p>
+ * Constraints implement the {@link Constraint} interface
+ * </p>
+ */
+@Retention( RetentionPolicy.RUNTIME )
+@Target( { ElementType.TYPE } )
+@Documented
+public @interface Constraints
+{
+    Class<? extends Constraint<?, ?>>[] value();
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/constraint/ConstraintsDescriptor.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/constraint/ConstraintsDescriptor.java b/core/api/src/main/java/org/apache/zest/api/constraint/ConstraintsDescriptor.java
new file mode 100644
index 0000000..1aa6824
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/constraint/ConstraintsDescriptor.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2008, Rickard Öberg. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.zest.api.constraint;
+
+/**
+ * Constraints Descriptor.
+ */
+public interface ConstraintsDescriptor
+{
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/constraint/Name.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/constraint/Name.java b/core/api/src/main/java/org/apache/zest/api/constraint/Name.java
new file mode 100644
index 0000000..281efcc
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/constraint/Name.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ * Copyright (c) 2007, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.zest.api.constraint;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation for parameter names. This is used to add extra information for constraint exception.
+ */
+@Retention( RetentionPolicy.RUNTIME )
+@Target( { ElementType.PARAMETER } )
+@Documented
+public @interface Name
+{
+    String value();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/constraint/package.html
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/constraint/package.html b/core/api/src/main/java/org/apache/zest/api/constraint/package.html
new file mode 100644
index 0000000..2e4d340
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/constraint/package.html
@@ -0,0 +1,21 @@
+<!--
+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.
+-->
+<html>
+    <body>
+        <h2>Constraint API.</h2>
+    </body>
+</html>

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/dataset/DataSet.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/dataset/DataSet.java b/core/api/src/main/java/org/apache/zest/api/dataset/DataSet.java
new file mode 100644
index 0000000..f52a563
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/dataset/DataSet.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.zest.api.dataset;
+
+import org.apache.zest.functional.Function;
+import org.apache.zest.functional.Specification;
+
+/**
+ * definition.constrain(entity(Person.class))
+ * builder.from(path(Person.class,Movie.))
+ * TODO
+ */
+public interface DataSet<T>
+{
+    DataSet<T> constrain( Specification<T> selection );
+
+    <U> DataSet<U> project( Function<T, U> conversion );
+
+    Query<T> newQuery();
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/dataset/DataSetSource.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/dataset/DataSetSource.java b/core/api/src/main/java/org/apache/zest/api/dataset/DataSetSource.java
new file mode 100644
index 0000000..ef99c08
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/dataset/DataSetSource.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.zest.api.dataset;
+
+/**
+ * TODO
+ */
+public interface DataSetSource
+{
+    <T> DataSet<T> newDataSet( Class<T> type );
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/dataset/Query.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/dataset/Query.java b/core/api/src/main/java/org/apache/zest/api/dataset/Query.java
new file mode 100644
index 0000000..53244ac
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/dataset/Query.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.zest.api.dataset;
+
+import org.apache.zest.api.property.Property;
+import org.apache.zest.api.query.QueryException;
+import org.apache.zest.api.query.QueryExecutionException;
+import org.apache.zest.functional.Specification;
+import org.apache.zest.functional.Visitor;
+
+/**
+ * TODO
+ */
+public interface Query<T>
+{
+    public enum Order
+    {
+        ASCENDING, DESCENDING
+    }
+
+    Query filter( Specification<T> filter );
+
+    Query orderBy( final Property<?> property, final Order order );
+
+    Query skip( int skipNrOfResults );
+
+    Query limit( int maxNrOfResults );
+
+    // Variables
+    Query<T> setVariable( String name, Object value );
+
+    Object getVariable( String name );
+
+    long count()
+        throws QueryExecutionException;
+
+    T first()
+        throws QueryExecutionException;
+
+    T single()
+        throws QueryException;
+
+    <ThrowableType extends Throwable> boolean execute( Visitor<T, ThrowableType> resultVisitor )
+        throws ThrowableType, QueryExecutionException;
+
+    Iterable<T> toIterable()
+        throws QueryExecutionException;
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/dataset/iterable/IterableDataSet.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/dataset/iterable/IterableDataSet.java b/core/api/src/main/java/org/apache/zest/api/dataset/iterable/IterableDataSet.java
new file mode 100644
index 0000000..e0d8614
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/dataset/iterable/IterableDataSet.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.zest.api.dataset.iterable;
+
+import org.apache.zest.api.dataset.DataSet;
+import org.apache.zest.api.dataset.Query;
+import org.apache.zest.functional.Function;
+import org.apache.zest.functional.Iterables;
+import org.apache.zest.functional.Specification;
+
+/**
+ * TODO
+ */
+public class IterableDataSet<T>
+    implements DataSet<T>
+{
+    private Iterable<T> iterable;
+
+    public IterableDataSet( Iterable<T> iterable )
+    {
+        this.iterable = iterable;
+    }
+
+    @Override
+    public DataSet<T> constrain( Specification<T> selection )
+    {
+        return new IterableDataSet<T>( Iterables.filter( selection, iterable ) );
+    }
+
+    @Override
+    public <U> DataSet<U> project( Function<T, U> conversion )
+    {
+        return new IterableDataSet<U>( Iterables.map( conversion, iterable ) );
+    }
+
+    @Override
+    public Query<T> newQuery()
+    {
+        return new IterableQuery<T>( iterable );
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/dataset/iterable/IterableQuery.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/dataset/iterable/IterableQuery.java b/core/api/src/main/java/org/apache/zest/api/dataset/iterable/IterableQuery.java
new file mode 100644
index 0000000..4c4952a
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/dataset/iterable/IterableQuery.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.zest.api.dataset.iterable;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.zest.api.dataset.Query;
+import org.apache.zest.api.property.Property;
+import org.apache.zest.api.query.QueryException;
+import org.apache.zest.functional.Iterables;
+import org.apache.zest.functional.Specification;
+import org.apache.zest.functional.Visitor;
+
+/**
+ * TODO
+ */
+public class IterableQuery<T> implements Query<T>
+{
+    private Iterable<T> iterable;
+    private int skip;
+    private int limit;
+    private Map<String, Object> variables = new HashMap<String, Object>();
+
+    public IterableQuery( Iterable<T> iterable )
+    {
+        this.iterable = iterable;
+    }
+
+    @Override
+    public Query filter( Specification<T> filter )
+    {
+        iterable = Iterables.filter( filter, iterable );
+
+        return this;
+    }
+
+    @Override
+    public Query orderBy( Property<?> property, Order order )
+    {
+        return this;
+    }
+
+    @Override
+    public Query skip( int skipNrOfResults )
+    {
+        this.skip = skipNrOfResults;
+
+        return this;
+    }
+
+    @Override
+    public Query limit( int maxNrOfResults )
+    {
+        this.limit = maxNrOfResults;
+        return this;
+    }
+
+    @Override
+    public Query<T> setVariable( String name, Object value )
+    {
+        variables.put( name, value );
+        return this;
+    }
+
+    @Override
+    public Object getVariable( String name )
+    {
+        return variables.get( name );
+    }
+
+    @Override
+    public long count()
+    {
+        return Iterables.count( Iterables.limit( limit, Iterables.skip( skip, iterable ) ) );
+    }
+
+    @Override
+    public T first()
+    {
+        return Iterables.first( Iterables.limit( limit, Iterables.skip( skip, iterable ) ) );
+    }
+
+    @Override
+    public T single()
+        throws QueryException
+    {
+        return Iterables.single( Iterables.limit( limit, Iterables.skip( skip, iterable ) ) );
+    }
+
+    @Override
+    public <ThrowableType extends Throwable> boolean execute( Visitor<T, ThrowableType> resultVisitor )
+        throws ThrowableType
+    {
+        for( T t : toIterable() )
+        {
+            if( !resultVisitor.visit( t ) )
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    @Override
+    public Iterable<T> toIterable()
+        throws QueryException
+    {
+        return Iterables.limit( limit, Iterables.skip( skip, iterable ) );
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/dataset/iterable/package.html
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/dataset/iterable/package.html b/core/api/src/main/java/org/apache/zest/api/dataset/iterable/package.html
new file mode 100644
index 0000000..9874cb5
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/dataset/iterable/package.html
@@ -0,0 +1,21 @@
+<!--
+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.
+-->
+<html>
+    <body>
+        <h2>Iterable DataSets.</h2>
+    </body>
+</html>

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/dataset/package.html
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/dataset/package.html b/core/api/src/main/java/org/apache/zest/api/dataset/package.html
new file mode 100644
index 0000000..f324682
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/dataset/package.html
@@ -0,0 +1,21 @@
+<!--
+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.
+-->
+<html>
+    <body>
+        <h2>DataSet API.</h2>
+    </body>
+</html>

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/entity/Aggregated.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/entity/Aggregated.java b/core/api/src/main/java/org/apache/zest/api/entity/Aggregated.java
new file mode 100644
index 0000000..96672b7
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/entity/Aggregated.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2009, Rickard Öberg. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.zest.api.entity;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Marks an association as aggregating the referenced Entities
+ */
+@Retention( RetentionPolicy.RUNTIME )
+@Target( { ElementType.METHOD } )
+@Documented
+public @interface Aggregated
+{
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/entity/EntityBuilder.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/entity/EntityBuilder.java b/core/api/src/main/java/org/apache/zest/api/entity/EntityBuilder.java
new file mode 100644
index 0000000..e403d47
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/entity/EntityBuilder.java
@@ -0,0 +1,60 @@
+/*  Copyright 2007 Niclas Hedhman.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *  
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zest.api.entity;
+
+import org.apache.zest.api.common.ConstructionException;
+
+/**
+ * EntityBuilders are used to instantiate EntityComposites. They can be acquired from
+ * {@link org.apache.zest.api.unitofwork.UnitOfWork#newEntityBuilder(Class)} and allows the client
+ * to provide additional settings before instantiating the Composite.
+ *
+ * After calling newInstance() the builder becomes invalid, and may not be called again.
+ */
+public interface EntityBuilder<T>
+{
+    /**
+     * Get a representation of the state for the new Composite.
+     * It is possible to access and update properties and associations,
+     * even immutable ones since the builder represents the initial state.
+     *
+     * @return a proxy implementing the Composite type
+     */
+    T instance();
+
+    /**
+     * Get a representation of the state of the given type for the new Composite.
+     * This is primarily used if you want to provide state for a private mixin type.
+     *
+     * @param mixinType the mixin which you want to provide state for
+     *
+     * @return a proxy implementing the given mixin type
+     */
+    <K> K instanceFor( Class<K> mixinType );
+
+    /**
+     * Create a new Entity instance.
+     *
+     * @return a new Entity instance
+     *
+     * @throws org.apache.zest.api.common.ConstructionException
+     *                            thrown if it was not possible to instantiate the Composite
+     * @throws LifecycleException if the entity could not be created
+     */
+    T newInstance()
+        throws ConstructionException, LifecycleException;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/entity/EntityBuilderTemplate.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/entity/EntityBuilderTemplate.java b/core/api/src/main/java/org/apache/zest/api/entity/EntityBuilderTemplate.java
new file mode 100644
index 0000000..56afa2c
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/entity/EntityBuilderTemplate.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.zest.api.entity;
+
+import org.apache.zest.api.structure.Module;
+
+/**
+ * EntityBuilderTemplate.
+ */
+public abstract class EntityBuilderTemplate<T>
+{
+    Class<T> type;
+
+    protected EntityBuilderTemplate( Class<T> type )
+    {
+        this.type = type;
+    }
+
+    protected abstract void build( T prototype );
+
+    public T newInstance( Module module )
+    {
+        EntityBuilder<T> builder = module.currentUnitOfWork().newEntityBuilder( type );
+        build( builder.instance() );
+        return builder.newInstance();
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/entity/EntityComposite.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/entity/EntityComposite.java b/core/api/src/main/java/org/apache/zest/api/entity/EntityComposite.java
new file mode 100644
index 0000000..43492c1
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/entity/EntityComposite.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ * Copyright (c) 2007, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.zest.api.entity;
+
+import org.apache.zest.api.association.AssociationMixin;
+import org.apache.zest.api.association.ManyAssociationMixin;
+import org.apache.zest.api.association.NamedAssociationMixin;
+import org.apache.zest.api.composite.Composite;
+import org.apache.zest.api.mixin.Mixins;
+
+/**
+ * EntityComposites are Composites that has mutable state persisted in EntityStores and equality defined from its
+ * identity.
+ */
+@Mixins( { AssociationMixin.class, ManyAssociationMixin.class, NamedAssociationMixin.class } )
+public interface EntityComposite
+    extends Identity, Composite
+{
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/entity/EntityDescriptor.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/entity/EntityDescriptor.java b/core/api/src/main/java/org/apache/zest/api/entity/EntityDescriptor.java
new file mode 100644
index 0000000..c0f0d9c
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/entity/EntityDescriptor.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2008, Rickard Öberg. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.zest.api.entity;
+
+import org.apache.zest.api.association.AssociationStateDescriptor;
+import org.apache.zest.api.composite.CompositeDescriptor;
+import org.apache.zest.api.composite.StatefulCompositeDescriptor;
+
+/**
+ * Entity Descriptor.
+ */
+public interface EntityDescriptor
+    extends CompositeDescriptor, StatefulCompositeDescriptor
+{
+    @Override
+    AssociationStateDescriptor state();
+
+    boolean queryable();
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/entity/EntityReference.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/entity/EntityReference.java b/core/api/src/main/java/org/apache/zest/api/entity/EntityReference.java
new file mode 100644
index 0000000..19d9f72
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/entity/EntityReference.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.zest.api.entity;
+
+import java.io.Serializable;
+import org.apache.zest.api.util.NullArgumentException;
+
+/**
+ * An EntityReference is identity of a specific Entity instance.
+ * <p>When stringified, the identity is used as-is. Example:</p>
+ * <pre>123456-abcde</pre>
+ */
+public final class EntityReference
+    implements Serializable
+{
+    /**
+     * Parse an URI to an EntityReference.
+     * @param uri the URI to parse
+     * @return the EntityReference represented by the given URI
+     */
+    public static EntityReference parseURI( String uri )
+    {
+        String identity = uri.substring( "urn:qi4j:entity:".length() );
+        return new EntityReference( identity );
+    }
+
+    /**
+     * Parse an Entity identity to an EntityReference.
+     * @param identity the EntityReference identity
+     * @return the EntityReference represented by the given identity
+     */
+    public static EntityReference parseEntityReference( String identity )
+    {
+        return new EntityReference( identity );
+    }
+
+    /**
+     * @param object an EntityComposite
+     * @return the EntityReference for the given EntityComposite
+     */
+    public static EntityReference entityReferenceFor( Object object )
+    {
+        return new EntityReference( (EntityComposite) object );
+    }
+
+    public static EntityReference create( Identity identity )
+    {
+        if( identity == null )
+            return null;
+        return new EntityReference( identity.identity().get() );
+    }
+
+    private static final long serialVersionUID = 1L;
+
+    private String identity;
+
+    /**
+     * @param entityComposite a non-null EntityComposite
+     * @throws NullPointerException if entityComposite is null
+     */
+    public EntityReference( EntityComposite entityComposite )
+    {
+        this( entityComposite.identity().get() );
+    }
+
+    /**
+     * @param identity reference identity
+     * @throws NullArgumentException if identity is null or empty
+     */
+    public EntityReference( String identity )
+    {
+        NullArgumentException.validateNotEmpty( "identity", identity );
+        this.identity = identity;
+    }
+
+    /**
+     * @return This EntityReference identity.
+     */
+    public final String identity()
+    {
+        return identity;
+    }
+
+    /**
+     * @return An URI representation of this EntityReference.
+     */
+    public String toURI()
+    {
+        return "urn:qi4j:entity:" + identity;
+    }
+
+    @Override
+    public boolean equals( Object o )
+    {
+        if( this == o )
+        {
+            return true;
+        }
+        if( o == null || getClass() != o.getClass() )
+        {
+            return false;
+        }
+        EntityReference that = (EntityReference) o;
+        return identity.equals( that.identity );
+    }
+
+    @Override
+    public int hashCode()
+    {
+        return identity.hashCode();
+    }
+
+    /**
+     * @return This EntityReference identity.
+     */
+    @Override
+    public String toString()
+    {
+        return identity;
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/entity/Identity.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/entity/Identity.java b/core/api/src/main/java/org/apache/zest/api/entity/Identity.java
new file mode 100644
index 0000000..06ab004
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/entity/Identity.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ * Copyright (c) 2007, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.zest.api.entity;
+
+import org.apache.zest.api.injection.scope.State;
+import org.apache.zest.api.mixin.Mixins;
+import org.apache.zest.api.property.Immutable;
+import org.apache.zest.api.property.Property;
+
+/**
+ * This interface provides the identity of the object which may be used
+ * to store the state in a database. It is not the responsibility of the
+ * framework to come up with a good identity string.
+ */
+@Mixins( Identity.IdentityMixin.class )
+public interface Identity
+{
+    /**
+     * Returns the client view of the identity.
+     * <p>
+     * It is unique within the owning repository, but potentially not unique globally and between
+     * types.
+     * </p>
+     * @return The Identity of 'this' composite.
+     */
+    @Immutable
+    Property<String> identity();
+
+    /**
+     * Default Identity implementation.
+     */
+    class IdentityMixin
+        implements Identity
+    {
+        @State
+        private Property<String> identity;
+
+        @Override
+        public Property<String> identity()
+        {
+            return identity;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/entity/IdentityGenerator.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/entity/IdentityGenerator.java b/core/api/src/main/java/org/apache/zest/api/entity/IdentityGenerator.java
new file mode 100644
index 0000000..199e54a
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/entity/IdentityGenerator.java
@@ -0,0 +1,32 @@
+/*  Copyright 2007 Niclas Hedhman.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *  
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zest.api.entity;
+
+/**
+ * Generator for identities of EntityComposite's.
+ */
+public interface IdentityGenerator
+{
+    /**
+     * Generate a new id for the given Composite type
+     *
+     * @param compositeType the type of composite
+     *
+     * @return a new identity
+     */
+    String generate( Class<?> compositeType );
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/entity/Lifecycle.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/entity/Lifecycle.java b/core/api/src/main/java/org/apache/zest/api/entity/Lifecycle.java
new file mode 100644
index 0000000..9d2fc27
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/entity/Lifecycle.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ * Copyright (c) 2007, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.zest.api.entity;
+
+/**
+ * Lifecycle interface for all Composites.
+ * <p>
+ * This Lifecycle interface is a built-in feature of the Zest runtime, similar to the Initializable interface.
+ * Any Mixin that implements this interface AND is part of an EntityComposite will have these two methods called
+ * upon creation/removal of the EntityComposite instance to/from the EntityStore. Meaning, the create method is called
+ * only when the identifiable EntityComposite is created the first time, and not when it is read from its persisted
+ * state and created into memory.
+ * </p>
+ * <p>
+ * Example;
+ * </p>
+ * <pre><code>
+ * public interface System
+ * {
+ *     Property&lt;User&gt; admin();
+ * }
+ *
+ * public class SystemAdminMixin&lt;LifeCycle&gt;
+ *     implements System, Lifecyle, ...
+ * {
+ *      &#64;Structure private UnitOfWork uow;
+ *      &#64;This private Identity meAsIdentity;
+ *
+ *      public void create()
+ *      {
+ *          String thisId = meAsIdentity.identity().get();
+ *          EntityBuilder builder = uow.newEntityBuilder( thisId + ":1", UserComposite.class );
+ *          User admin = builder.newInstance();
+ *          admin.set( admin );
+ *      }
+ *
+ *      public void remove()
+ *      {
+ *          uow.remove( admin.get() );
+ *      }
+ * }
+ *
+ * &#64;Mixins( SystemAdminMixin.class )
+ * public interface SystemEntity extends System, EntityComposite
+ * {}
+ *
+ * </code></pre>
+ */
+public interface Lifecycle
+{
+
+    /**
+     * Creation callback method.
+     * <p>
+     * Called by the Zest runtime before the newInstance of the entity completes, before the constraints are checked,
+     * allowing for additional initialization.
+     * </p>
+     * @throws LifecycleException if the entity could not be created
+     */
+    void create()
+        throws LifecycleException;
+
+    /**
+     * Removal callback method.
+     * <p>
+     * Called by the Zest runtime before the entity is removed from the system, allowing
+     * for clean-up operations.
+     * </p>
+     * @throws LifecycleException if the entity could not be removed
+     */
+    void remove()
+        throws LifecycleException;
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/entity/LifecycleException.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/entity/LifecycleException.java b/core/api/src/main/java/org/apache/zest/api/entity/LifecycleException.java
new file mode 100644
index 0000000..15189cd
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/entity/LifecycleException.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2008, Rickard Öberg. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.zest.api.entity;
+
+/**
+ * Thrown by methods of Lifecycle if invocation fails
+ */
+public class LifecycleException
+    extends RuntimeException
+{
+    public LifecycleException( String s )
+    {
+        super( s );
+    }
+
+    public LifecycleException( String s, Throwable throwable )
+    {
+        super( s, throwable );
+    }
+
+    public LifecycleException( Throwable throwable )
+    {
+        super( throwable );
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/entity/Queryable.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/entity/Queryable.java b/core/api/src/main/java/org/apache/zest/api/entity/Queryable.java
new file mode 100644
index 0000000..8bd7c6c
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/entity/Queryable.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2008, Alin Dreghiciu. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.zest.api.entity;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * This annotation is used to mark entity types or properties/associations that are indexable.
+ */
+@Retention( RetentionPolicy.RUNTIME )
+@Target( { ElementType.TYPE, ElementType.METHOD } )
+@Documented
+public @interface Queryable
+{
+    boolean value() default true;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/entity/package.html
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/entity/package.html b/core/api/src/main/java/org/apache/zest/api/entity/package.html
new file mode 100644
index 0000000..0386d8c
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/entity/package.html
@@ -0,0 +1,21 @@
+<!--
+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.
+-->
+<html>
+    <body>
+        <h2>Entity API.</h2>
+    </body>
+</html>

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/event/package.html
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/event/package.html b/core/api/src/main/java/org/apache/zest/api/event/package.html
new file mode 100644
index 0000000..a5ed0a7
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/event/package.html
@@ -0,0 +1,21 @@
+<!--
+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.
+-->
+<html>
+    <body>
+        <h2>Event API.</h2>
+    </body>
+</html>

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/injection/InjectionScope.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/injection/InjectionScope.java b/core/api/src/main/java/org/apache/zest/api/injection/InjectionScope.java
new file mode 100644
index 0000000..f2b3642
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/injection/InjectionScope.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ * Copyright (c) 2007, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.zest.api.injection;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * This is used to annotate annotation types which are used for injection.
+ * Each scope signifies a particular scope from which the injection value should be taken.
+ */
+@Retention( RetentionPolicy.RUNTIME )
+@Target( { ElementType.ANNOTATION_TYPE } )
+@Documented
+public @interface InjectionScope
+{
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/injection/package.html
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/injection/package.html b/core/api/src/main/java/org/apache/zest/api/injection/package.html
new file mode 100644
index 0000000..c41b495
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/injection/package.html
@@ -0,0 +1,21 @@
+<!--
+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.
+-->
+<html>
+    <body>
+        <h2>Dependency Injection API.</h2>
+    </body>
+</html>

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/injection/scope/Invocation.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/injection/scope/Invocation.java b/core/api/src/main/java/org/apache/zest/api/injection/scope/Invocation.java
new file mode 100644
index 0000000..df1742f
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/injection/scope/Invocation.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ * Copyright (c) 2007, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.zest.api.injection.scope;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import org.apache.zest.api.injection.InjectionScope;
+
+/**
+ * Annotation to denote the injection of a
+ * invocation specific resource.
+ * These include:
+ * <pre><code>
+ *  - The Method being invoked.
+ *
+ *  - An AnnotationElement with annotations
+ *    from both mixin type, mixin
+ *    implementation.
+ *
+ *  - An Annotation of a specific type
+ * </code></pre>
+ * Examples:
+ * <pre><code>
+ * &#64;Invocation Method theInvokedMethod
+ * &#64;Invocation AnnotationElement annotations
+ * &#64;Invocation Matches matchesAnnotation
+ * </code></pre>
+ */
+@Retention( RetentionPolicy.RUNTIME )
+@Target( { ElementType.FIELD, ElementType.PARAMETER } )
+@Documented
+@InjectionScope
+public @interface Invocation
+{
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/injection/scope/Service.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/injection/scope/Service.java b/core/api/src/main/java/org/apache/zest/api/injection/scope/Service.java
new file mode 100644
index 0000000..e636497
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/injection/scope/Service.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ * Copyright (c) 2007, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.zest.api.injection.scope;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import org.apache.zest.api.injection.InjectionScope;
+
+/**
+ * Annotation to denote the injection of a service dependency into a Fragment.
+ * <p>
+ * Examples:
+ * </p>
+ * <pre><code>
+ * &#64;Service MyService service
+ * &#64;Service Iterable&lt;MyService&gt; services
+ * &#64;Service ServiceReference&lt;MyService&gt; serviceRef
+ * &#64;Service Iterable&lt;ServiceReference&lt;MyService&gt;&gt; serviceRefs
+ * </code></pre>
+ */
+@Retention( RetentionPolicy.RUNTIME )
+@Target( { ElementType.FIELD, ElementType.PARAMETER } )
+@Documented
+@InjectionScope
+public @interface Service
+{
+}
+

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/injection/scope/State.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/injection/scope/State.java b/core/api/src/main/java/org/apache/zest/api/injection/scope/State.java
new file mode 100644
index 0000000..9645600
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/injection/scope/State.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.zest.api.injection.scope;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import org.apache.zest.api.injection.InjectionScope;
+
+/**
+ * Annotation to denote the injection of a property, association or
+ * StateHolder.
+ * <pre><code>
+ * &#64;State Property&lt;StringState propertyName;
+ * &#64;State Association&lt;MyEntityState associationName;
+ * &#64;State ManyAssociation&lt;MyEntityState manyAssociationName;
+ * &#64;State NamedAssociation&lt;MyEntityState namedAssociationName;
+ * &#64;State StateHolder state;
+ * &#64;State AssociationStateHolder associationState;
+ * </code></pre>
+ */
+@Retention( RetentionPolicy.RUNTIME )
+@Target( { ElementType.FIELD, ElementType.PARAMETER } )
+@Documented
+@InjectionScope
+public @interface State
+{
+    /**
+     * Name of the property or association.
+     * If not set then name will be name of field.
+     *
+     * @return the name
+     */
+    public abstract String value() default "";
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/injection/scope/Structure.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/injection/scope/Structure.java b/core/api/src/main/java/org/apache/zest/api/injection/scope/Structure.java
new file mode 100644
index 0000000..7f1322f
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/injection/scope/Structure.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ * Copyright (c) 2007, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.zest.api.injection.scope;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import org.apache.zest.api.injection.InjectionScope;
+
+/**
+ * Annotation to denote the injection of a
+ * resource specific for the module which the
+ * injected object/fragment is instantiated in.
+ * <p>
+ * Valid types are:
+ * </p>
+ * <pre><code>
+ * - TransientBuilderFactory
+ * - ObjectBuilderFactory
+ * - UnitOfWorkFactory
+ * - ServiceFinder
+ * - Module
+ * - Layer
+ * - Application
+ * - Qi4j
+ * - Qi4jSPI
+ * </code></pre>
+ */
+@Retention( RetentionPolicy.RUNTIME )
+@Target( { ElementType.FIELD, ElementType.PARAMETER } )
+@Documented
+@InjectionScope
+public @interface Structure
+{
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/injection/scope/This.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/injection/scope/This.java b/core/api/src/main/java/org/apache/zest/api/injection/scope/This.java
new file mode 100644
index 0000000..d91e319
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/injection/scope/This.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ * Copyright (c) 2007, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.zest.api.injection.scope;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import org.apache.zest.api.injection.InjectionScope;
+
+/**
+ * Annotation to denote the injection of a reference to the same Composite
+ * as the fragment is a part of.
+ * <p>
+ * If the Composite type does not implement the type of the field or parameter
+ * then it will be referencing a private mixin.
+ * </p>
+ * <p>
+ * Calls to the reference will have the same semantics as calls to the Composite itself.
+ * Specifically the same set of Modifiers will be used.
+ * </p>
+ */
+@Retention( RetentionPolicy.RUNTIME )
+@Target( { ElementType.FIELD, ElementType.PARAMETER } )
+@Documented
+@InjectionScope
+public @interface This
+{
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/injection/scope/Uses.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/injection/scope/Uses.java b/core/api/src/main/java/org/apache/zest/api/injection/scope/Uses.java
new file mode 100644
index 0000000..d6de357
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/injection/scope/Uses.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ * Copyright (c) 2007, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.zest.api.injection.scope;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import org.apache.zest.api.injection.InjectionScope;
+
+/**
+ * Annotation to denote the injection of a dependency to be used by a Mixin. The injected
+ * object is provided either by the TransientBuilder.uses() declarations, or if an instance of the appropriate types is not
+ * found, then a new Transient or Object is instantiated.
+ * Call {@link org.apache.zest.api.composite.TransientBuilder#use} to provide the instance
+ * to be injected.
+ *
+ * Example:
+ * <pre>@Uses SomeType someInstance</pre>
+ */
+@Retention( RetentionPolicy.RUNTIME )
+@Target( { ElementType.PARAMETER, ElementType.FIELD } )
+@Documented
+@InjectionScope
+public @interface Uses
+{
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/injection/scope/package.html
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/injection/scope/package.html b/core/api/src/main/java/org/apache/zest/api/injection/scope/package.html
new file mode 100644
index 0000000..b0ec496
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/injection/scope/package.html
@@ -0,0 +1,21 @@
+<!--
+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.
+-->
+<html>
+    <body>
+        <h2>Dependency Injection Scopes.</h2>
+    </body>
+</html>

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/metrics/Metric.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/Metric.java b/core/api/src/main/java/org/apache/zest/api/metrics/Metric.java
new file mode 100644
index 0000000..44c1c9b
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/Metric.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2012, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ *     You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zest.api.metrics;
+
+/**
+ * Marker interface for all Metric types.
+ */
+public interface Metric
+{
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/metrics/MetricsCounter.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsCounter.java b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsCounter.java
new file mode 100644
index 0000000..9bd1392
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsCounter.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2012, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ *     You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zest.api.metrics;
+
+/**
+ * Metrics Counter.
+ */
+public interface MetricsCounter extends Metric
+{
+    void increment();
+
+    void increment( int steps );
+
+    void decrement();
+
+    void decrement( int steps );
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/metrics/MetricsCounterFactory.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsCounterFactory.java b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsCounterFactory.java
new file mode 100644
index 0000000..ac1e7fe
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsCounterFactory.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2012, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ *     You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zest.api.metrics;
+
+/**
+ * Create MetricsCounter instances.
+ */
+public interface MetricsCounterFactory extends MetricsFactory
+{
+    /**
+     * Create a MetricsCounter instance.
+     * If the same arguments are given twice, the same instance must be returned.
+     *
+     * @param origin The class that instantiate the metric
+     * @param name   A human readable, short name of the metric.
+     *
+     * @return A Metric instance to be used, OR org.qi4j.spi.metrics.DefaultMetric.NULL if not supported.
+     */
+    MetricsCounter createCounter( Class<?> origin, String name );
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/metrics/MetricsFactory.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsFactory.java b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsFactory.java
new file mode 100644
index 0000000..7e36034
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsFactory.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2012, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ *     You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zest.api.metrics;
+
+/**
+ * Metrics Factory.
+ */
+public interface MetricsFactory
+{
+    Iterable<Metric> registered();
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/metrics/MetricsGauge.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsGauge.java b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsGauge.java
new file mode 100644
index 0000000..34aa4ca
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsGauge.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2012, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ *     You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zest.api.metrics;
+
+/**
+ * MetricsGauge is the most basic Metric type, and is completely flexible and therefor handled slightly differently in
+ * the MetricsFactory than all other Gauges. It needs to pass on custom code, so the implementation is typically
+ * an anonymous class, inlined at the implementation.
+ *
+ * @param <T> Any type holding the MetricsGauge's current value.
+ */
+public interface MetricsGauge<T> extends Metric
+{
+    /**
+     * Returns the metric's current value.
+     *
+     * @return the metric's current value
+     */
+    T value();
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/metrics/MetricsGaugeFactory.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsGaugeFactory.java b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsGaugeFactory.java
new file mode 100644
index 0000000..8e4ec95
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsGaugeFactory.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2012, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ *     You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zest.api.metrics;
+
+/**
+ * Register MetricsGauge with the underlying Metrics system.
+ */
+public interface MetricsGaugeFactory extends MetricsFactory
+{
+    /**
+     * Register a MetricsGauge with the underlying Metrics system.
+     *
+     * @param origin The class where the MetricsGauge is created.
+     * @param name   A human readable, short name of the metric.
+     * @param gauge  The implementation of the MetricsGauge.
+     * @param <T>    Any type holding the MetricsGauge's current value.
+     *
+     * @return The same MetricsGauge or the DefaultMetric.NULL MetricsGauge instance.
+     */
+    <T> MetricsGauge<T> registerGauge( Class<?> origin, String name, MetricsGauge<T> gauge );
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHealthCheck.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHealthCheck.java b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHealthCheck.java
new file mode 100644
index 0000000..c5d39d4
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHealthCheck.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2012, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ *     You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zest.api.metrics;
+
+/**
+ * Metrics Health Check.
+ */
+public interface MetricsHealthCheck extends Metric
+{
+    Result check()
+        throws Exception;
+
+    public final class Result
+    {
+        private final boolean healthy;
+        private final String message;
+        private final Throwable exception;
+
+        public Result( boolean isHealthy, String message, Throwable exception )
+        {
+            healthy = isHealthy;
+            this.message = message;
+            this.exception = exception;
+        }
+
+        public boolean isHealthy()
+        {
+            return healthy;
+        }
+
+        public String getMessage()
+        {
+            return message;
+        }
+
+        public Throwable getException()
+        {
+            return exception;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHealthCheckFactory.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHealthCheckFactory.java b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHealthCheckFactory.java
new file mode 100644
index 0000000..efb2d03
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHealthCheckFactory.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2012, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ *     You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zest.api.metrics;
+
+/**
+ * Create MetricsHealthCheck instances.
+ */
+public interface MetricsHealthCheckFactory extends MetricsFactory
+{
+    /**
+     * Create a MetricsHealthCheck instance.
+     * If the same arguments are given twice, the same instance must be returned.
+     *
+     * @param origin The class that instantiate the metric
+     * @param name   A human readable, short name of the metric.
+     * @param check  The health check to be performed regularly.
+     *
+     * @return A MetricsHealthCheck instance to be used, OR org.qi4j.spi.metrics.DefaultMetric.NULL if not supported.
+     *
+     */
+    MetricsHealthCheck registerHealthCheck( Class<?> origin, String name, MetricsHealthCheck check );
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHistogram.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHistogram.java b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHistogram.java
new file mode 100644
index 0000000..92fda33
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHistogram.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2012, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ *     You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zest.api.metrics;
+
+/**
+ * A metric which calculates the distribution of a value.
+ *
+ * @see <a href="http://www.johndcook.com/standard_deviation.html">Accurately computing running
+ *      variance</a>
+ */
+public interface MetricsHistogram extends Metric
+{
+    void update( long newValue );
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHistogramFactory.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHistogramFactory.java b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHistogramFactory.java
new file mode 100644
index 0000000..78cbbea
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHistogramFactory.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2012, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ *     You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zest.api.metrics;
+
+/**
+ * Create MetricsHistogram instances.
+ */
+public interface MetricsHistogramFactory extends MetricsFactory
+{
+    /**
+     * Create a MetricsHistogram instance.
+     * If the same arguments are given twice, the same instance must be returned.
+     *
+     * @param origin The class that instantiate the metric
+     * @param name   A human readable, short name of the metric.
+     *
+     * @return A Metric instance to be used, OR org.qi4j.spi.metrics.DefaultMetric.NULL if not supported.
+     *
+     */
+    MetricsHistogram createHistogram( Class<?> origin, String name );
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/metrics/MetricsMeter.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsMeter.java b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsMeter.java
new file mode 100644
index 0000000..d254d96
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsMeter.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2012, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ *     You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zest.api.metrics;
+
+/**
+ * A meter metric which measures mean throughput and one-, five-, and fifteen-minute
+ * exponentially-weighted moving average throughputs.
+ *
+ * @see <a href="http://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average">EMA</a>
+ */
+public interface MetricsMeter extends Metric
+{
+    void mark();
+
+    /**
+     * Mark the occurrence of a given number of events.
+     *
+     * @param numberOfEvents the number of events
+     */
+    void mark( int numberOfEvents );
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/metrics/MetricsMeterFactory.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsMeterFactory.java b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsMeterFactory.java
new file mode 100644
index 0000000..6deb83c
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsMeterFactory.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2012, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ *     You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zest.api.metrics;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Create MetricsMeter instances.
+ */
+public interface MetricsMeterFactory extends MetricsFactory
+{
+    /**
+     * Create a MetricsMeter instance.
+     * If the same arguments are given twice, the same instance must be returned.
+     *
+     * @param origin    The class that instantiate the metric
+     * @param name      A human readable, short name of the metric.
+     * @param eventType the plural name of the event the meter is measuring (e.g., {@code "requests"})
+     * @param rate      the scale unit for this timer's rate metrics
+     *
+     * @return A Metric instance to be used, OR org.qi4j.spi.metrics.DefaultMetric.NULL if not supported.
+     */
+    MetricsMeter createMeter( Class<?> origin, String name, String eventType, TimeUnit rate );
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/api/src/main/java/org/apache/zest/api/metrics/MetricsNotSupportedException.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsNotSupportedException.java b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsNotSupportedException.java
new file mode 100644
index 0000000..3f0dd0f
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsNotSupportedException.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.zest.api.metrics;
+
+/**
+ * Thrown when the underlying MetricsProvider do not support a Metric type.
+ */
+public class MetricsNotSupportedException extends RuntimeException
+{
+    public MetricsNotSupportedException( Class<? extends MetricsFactory> factoryType,
+                                         Class<? extends MetricsProvider> providerType
+    )
+    {
+        super( "Metrics [" + factoryType.getName() + "] is not supported by MetricsProvider [" + providerType.getName() + "]." );
+    }
+}