Return-Path: X-Original-To: apmail-zest-commits-archive@minotaur.apache.org Delivered-To: apmail-zest-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 04D8B18404 for ; Fri, 31 Jul 2015 02:47:22 +0000 (UTC) Received: (qmail 76336 invoked by uid 500); 31 Jul 2015 02:47:22 -0000 Delivered-To: apmail-zest-commits-archive@zest.apache.org Received: (qmail 76283 invoked by uid 500); 31 Jul 2015 02:47:21 -0000 Mailing-List: contact commits-help@zest.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zest.apache.org Delivered-To: mailing list commits@zest.apache.org Received: (qmail 75620 invoked by uid 99); 31 Jul 2015 02:47:21 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 Jul 2015 02:47:21 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5A46FDFA70; Fri, 31 Jul 2015 02:47:21 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: niclas@apache.org To: commits@zest.apache.org Date: Fri, 31 Jul 2015 02:47:56 -0000 Message-Id: <7ea13dcddc544d8ba90c7b4fa91fb97a@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [37/51] [abbrv] [partial] zest-java git commit: Revert "First round of changes to move to org.apache.zest namespace." http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/entity/Identity.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/entity/Identity.java b/core/api/src/main/java/org/qi4j/api/entity/Identity.java new file mode 100644 index 0000000..b4adbc5 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.api.entity; + +import org.qi4j.api.injection.scope.State; +import org.qi4j.api.mixin.Mixins; +import org.qi4j.api.property.Immutable; +import org.qi4j.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. + *

+ * It is unique within the owning repository, but potentially not unique globally and between + * types. + *

+ * @return The Identity of 'this' composite. + */ + @Immutable + Property identity(); + + /** + * Default Identity implementation. + */ + class IdentityMixin + implements Identity + { + @State + private Property identity; + + @Override + public Property identity() + { + return identity; + } + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/entity/IdentityGenerator.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/entity/IdentityGenerator.java b/core/api/src/main/java/org/qi4j/api/entity/IdentityGenerator.java new file mode 100644 index 0000000..8d076e5 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.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/a789141d/core/api/src/main/java/org/qi4j/api/entity/Lifecycle.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/entity/Lifecycle.java b/core/api/src/main/java/org/qi4j/api/entity/Lifecycle.java new file mode 100644 index 0000000..3eabd78 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.api.entity; + +/** + * Lifecycle interface for all Composites. + *

+ * 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. + *

+ *

+ * Example; + *

+ *

+ * public interface System
+ * {
+ *     Property<User> admin();
+ * }
+ *
+ * public class SystemAdminMixin<LifeCycle>
+ *     implements System, Lifecyle, ...
+ * {
+ *      @Structure private UnitOfWork uow;
+ *      @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() );
+ *      }
+ * }
+ *
+ * @Mixins( SystemAdminMixin.class )
+ * public interface SystemEntity extends System, EntityComposite
+ * {}
+ *
+ * 
+ */ +public interface Lifecycle +{ + + /** + * Creation callback method. + *

+ * Called by the Zest runtime before the newInstance of the entity completes, before the constraints are checked, + * allowing for additional initialization. + *

+ * @throws LifecycleException if the entity could not be created + */ + void create() + throws LifecycleException; + + /** + * Removal callback method. + *

+ * Called by the Zest runtime before the entity is removed from the system, allowing + * for clean-up operations. + *

+ * @throws LifecycleException if the entity could not be removed + */ + void remove() + throws LifecycleException; +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/entity/LifecycleException.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/entity/LifecycleException.java b/core/api/src/main/java/org/qi4j/api/entity/LifecycleException.java new file mode 100644 index 0000000..b358fa1 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.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/a789141d/core/api/src/main/java/org/qi4j/api/entity/Queryable.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/entity/Queryable.java b/core/api/src/main/java/org/qi4j/api/entity/Queryable.java new file mode 100644 index 0000000..768e17d --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.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/a789141d/core/api/src/main/java/org/qi4j/api/entity/package.html ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/entity/package.html b/core/api/src/main/java/org/qi4j/api/entity/package.html new file mode 100644 index 0000000..0386d8c --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/entity/package.html @@ -0,0 +1,21 @@ + + + +

Entity API.

+ + http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/event/package.html ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/event/package.html b/core/api/src/main/java/org/qi4j/api/event/package.html new file mode 100644 index 0000000..a5ed0a7 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/event/package.html @@ -0,0 +1,21 @@ + + + +

Event API.

+ + http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/injection/InjectionScope.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/injection/InjectionScope.java b/core/api/src/main/java/org/qi4j/api/injection/InjectionScope.java new file mode 100644 index 0000000..7ada2e6 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.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/a789141d/core/api/src/main/java/org/qi4j/api/injection/package.html ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/injection/package.html b/core/api/src/main/java/org/qi4j/api/injection/package.html new file mode 100644 index 0000000..c41b495 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/injection/package.html @@ -0,0 +1,21 @@ + + + +

Dependency Injection API.

+ + http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/injection/scope/Invocation.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/injection/scope/Invocation.java b/core/api/src/main/java/org/qi4j/api/injection/scope/Invocation.java new file mode 100644 index 0000000..230e5c9 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.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.qi4j.api.injection.InjectionScope; + +/** + * Annotation to denote the injection of a + * invocation specific resource. + * These include: + *

+ *  - The Method being invoked.
+ *
+ *  - An AnnotationElement with annotations
+ *    from both mixin type, mixin
+ *    implementation.
+ *
+ *  - An Annotation of a specific type
+ * 
+ * Examples: + *

+ * @Invocation Method theInvokedMethod
+ * @Invocation AnnotationElement annotations
+ * @Invocation Matches matchesAnnotation
+ * 
+ */ +@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/a789141d/core/api/src/main/java/org/qi4j/api/injection/scope/Service.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/injection/scope/Service.java b/core/api/src/main/java/org/qi4j/api/injection/scope/Service.java new file mode 100644 index 0000000..6116cc1 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.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.qi4j.api.injection.InjectionScope; + +/** + * Annotation to denote the injection of a service dependency into a Fragment. + *

+ * Examples: + *

+ *

+ * @Service MyService service
+ * @Service Iterable<MyService> services
+ * @Service ServiceReference<MyService> serviceRef
+ * @Service Iterable<ServiceReference<MyService>> serviceRefs
+ * 
+ */ +@Retention( RetentionPolicy.RUNTIME ) +@Target( { ElementType.FIELD, ElementType.PARAMETER } ) +@Documented +@InjectionScope +public @interface Service +{ +} + http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/injection/scope/State.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/injection/scope/State.java b/core/api/src/main/java/org/qi4j/api/injection/scope/State.java new file mode 100644 index 0000000..ec3c52a --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.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.qi4j.api.injection.InjectionScope; + +/** + * Annotation to denote the injection of a property, association or + * StateHolder. + *

+ * @State Property<StringState propertyName;
+ * @State Association<MyEntityState associationName;
+ * @State ManyAssociation<MyEntityState manyAssociationName;
+ * @State NamedAssociation<MyEntityState namedAssociationName;
+ * @State StateHolder state;
+ * @State AssociationStateHolder associationState;
+ * 
+ */ +@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/a789141d/core/api/src/main/java/org/qi4j/api/injection/scope/Structure.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/injection/scope/Structure.java b/core/api/src/main/java/org/qi4j/api/injection/scope/Structure.java new file mode 100644 index 0000000..252af5e --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.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.qi4j.api.injection.InjectionScope; + +/** + * Annotation to denote the injection of a + * resource specific for the module which the + * injected object/fragment is instantiated in. + *

+ * Valid types are: + *

+ *

+ * - TransientBuilderFactory
+ * - ObjectBuilderFactory
+ * - UnitOfWorkFactory
+ * - ServiceFinder
+ * - Module
+ * - Layer
+ * - Application
+ * - Qi4j
+ * - Qi4jSPI
+ * 
+ */ +@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/a789141d/core/api/src/main/java/org/qi4j/api/injection/scope/This.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/injection/scope/This.java b/core/api/src/main/java/org/qi4j/api/injection/scope/This.java new file mode 100644 index 0000000..4d806d0 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.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.qi4j.api.injection.InjectionScope; + +/** + * Annotation to denote the injection of a reference to the same Composite + * as the fragment is a part of. + *

+ * If the Composite type does not implement the type of the field or parameter + * then it will be referencing a private mixin. + *

+ *

+ * Calls to the reference will have the same semantics as calls to the Composite itself. + * Specifically the same set of Modifiers will be used. + *

+ */ +@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/a789141d/core/api/src/main/java/org/qi4j/api/injection/scope/Uses.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/injection/scope/Uses.java b/core/api/src/main/java/org/qi4j/api/injection/scope/Uses.java new file mode 100644 index 0000000..d5b4080 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.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.qi4j.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.qi4j.api.composite.TransientBuilder#use} to provide the instance + * to be injected. + * + * Example: + *
@Uses SomeType someInstance
+ */ +@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/a789141d/core/api/src/main/java/org/qi4j/api/injection/scope/package.html ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/injection/scope/package.html b/core/api/src/main/java/org/qi4j/api/injection/scope/package.html new file mode 100644 index 0000000..b0ec496 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/injection/scope/package.html @@ -0,0 +1,21 @@ + + + +

Dependency Injection Scopes.

+ + http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/metrics/Metric.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/metrics/Metric.java b/core/api/src/main/java/org/qi4j/api/metrics/Metric.java new file mode 100644 index 0000000..775ab5d --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.api.metrics; + +/** + * Marker interface for all Metric types. + */ +public interface Metric +{ +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/metrics/MetricsCounter.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/metrics/MetricsCounter.java b/core/api/src/main/java/org/qi4j/api/metrics/MetricsCounter.java new file mode 100644 index 0000000..67404b3 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.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/a789141d/core/api/src/main/java/org/qi4j/api/metrics/MetricsCounterFactory.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/metrics/MetricsCounterFactory.java b/core/api/src/main/java/org/qi4j/api/metrics/MetricsCounterFactory.java new file mode 100644 index 0000000..caa2915 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.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/a789141d/core/api/src/main/java/org/qi4j/api/metrics/MetricsFactory.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/metrics/MetricsFactory.java b/core/api/src/main/java/org/qi4j/api/metrics/MetricsFactory.java new file mode 100644 index 0000000..0813dde --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.api.metrics; + +/** + * Metrics Factory. + */ +public interface MetricsFactory +{ + Iterable registered(); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/metrics/MetricsGauge.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/metrics/MetricsGauge.java b/core/api/src/main/java/org/qi4j/api/metrics/MetricsGauge.java new file mode 100644 index 0000000..1dd293b --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.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 Any type holding the MetricsGauge's current value. + */ +public interface MetricsGauge 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/a789141d/core/api/src/main/java/org/qi4j/api/metrics/MetricsGaugeFactory.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/metrics/MetricsGaugeFactory.java b/core/api/src/main/java/org/qi4j/api/metrics/MetricsGaugeFactory.java new file mode 100644 index 0000000..a469ac2 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.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 Any type holding the MetricsGauge's current value. + * + * @return The same MetricsGauge or the DefaultMetric.NULL MetricsGauge instance. + */ + MetricsGauge registerGauge( Class origin, String name, MetricsGauge gauge ); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/metrics/MetricsHealthCheck.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/metrics/MetricsHealthCheck.java b/core/api/src/main/java/org/qi4j/api/metrics/MetricsHealthCheck.java new file mode 100644 index 0000000..18bb151 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.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/a789141d/core/api/src/main/java/org/qi4j/api/metrics/MetricsHealthCheckFactory.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/metrics/MetricsHealthCheckFactory.java b/core/api/src/main/java/org/qi4j/api/metrics/MetricsHealthCheckFactory.java new file mode 100644 index 0000000..12decc5 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.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/a789141d/core/api/src/main/java/org/qi4j/api/metrics/MetricsHistogram.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/metrics/MetricsHistogram.java b/core/api/src/main/java/org/qi4j/api/metrics/MetricsHistogram.java new file mode 100644 index 0000000..fe38869 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.api.metrics; + +/** + * A metric which calculates the distribution of a value. + * + * @see Accurately computing running + * variance + */ +public interface MetricsHistogram extends Metric +{ + void update( long newValue ); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/metrics/MetricsHistogramFactory.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/metrics/MetricsHistogramFactory.java b/core/api/src/main/java/org/qi4j/api/metrics/MetricsHistogramFactory.java new file mode 100644 index 0000000..ab62508 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.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/a789141d/core/api/src/main/java/org/qi4j/api/metrics/MetricsMeter.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/metrics/MetricsMeter.java b/core/api/src/main/java/org/qi4j/api/metrics/MetricsMeter.java new file mode 100644 index 0000000..acbb73d --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.api.metrics; + +/** + * A meter metric which measures mean throughput and one-, five-, and fifteen-minute + * exponentially-weighted moving average throughputs. + * + * @see EMA + */ +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/a789141d/core/api/src/main/java/org/qi4j/api/metrics/MetricsMeterFactory.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/metrics/MetricsMeterFactory.java b/core/api/src/main/java/org/qi4j/api/metrics/MetricsMeterFactory.java new file mode 100644 index 0000000..53928bd --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.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/a789141d/core/api/src/main/java/org/qi4j/api/metrics/MetricsNotSupportedException.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/metrics/MetricsNotSupportedException.java b/core/api/src/main/java/org/qi4j/api/metrics/MetricsNotSupportedException.java new file mode 100644 index 0000000..aec7859 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/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.qi4j.api.metrics; + +/** + * Thrown when the underlying MetricsProvider do not support a Metric type. + */ +public class MetricsNotSupportedException extends RuntimeException +{ + public MetricsNotSupportedException( Class factoryType, + Class providerType + ) + { + super( "Metrics [" + factoryType.getName() + "] is not supported by MetricsProvider [" + providerType.getName() + "]." ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/metrics/MetricsProvider.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/metrics/MetricsProvider.java b/core/api/src/main/java/org/qi4j/api/metrics/MetricsProvider.java new file mode 100644 index 0000000..c11996b --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/metrics/MetricsProvider.java @@ -0,0 +1,58 @@ +/* + * 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.qi4j.api.metrics; + +/** + * Metrics Provider SPI. + *

+ * The Zest Runtime will automatically ook for a service that implements the MetricsProvider interdace + * and use it for internal Runtime metrics, such as the UnitOfWork measuring the time from creation to close. + *

+ *

+ * The Metrics Library is available to add metric functionality to applications in the same way, and + * will use the same MetricsProvider. + *

+ *

+ * Note that the usual visibitlity rules applies, so you might have more than one MetricsProvider server, + * perhaps per layer. + *

+ */ +public interface MetricsProvider +{ + /** + * Creates a new factory instance. + * + * The instanctiation is done by providing a Metric type, which is one of + *
    + *
  • {@link MetricsCounter}
  • + *
  • {@link MetricsGauge}
  • + *
  • {@link MetricsHealthCheck}
  • + *
  • {@link MetricsHistogram}
  • + *
  • {@link MetricsMeter}
  • + *
  • {@link MetricsTimer}
  • + *
+ * + * @param factoryType The class of the metric type needed. + * @param The metric type requested. + * + * @return A factory instance + * + * @throws MetricsNotSupportedException when the MetricsProvider is not supporting the factory type requested. + */ + T createFactory( Class factoryType ) + throws MetricsNotSupportedException; +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/metrics/MetricsTimer.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/metrics/MetricsTimer.java b/core/api/src/main/java/org/qi4j/api/metrics/MetricsTimer.java new file mode 100644 index 0000000..6de4714 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/metrics/MetricsTimer.java @@ -0,0 +1,39 @@ +/* + * 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.qi4j.api.metrics; + +/** + * Timer Metrics. + */ +public interface MetricsTimer extends Metric +{ + /** + * Start the Timer Metrics. + */ + Context start(); + + /** + * Timer Metrics Context. + */ + public interface Context + { + /** + * Stop the Timer Metrics. + */ + void stop(); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/metrics/MetricsTimerFactory.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/metrics/MetricsTimerFactory.java b/core/api/src/main/java/org/qi4j/api/metrics/MetricsTimerFactory.java new file mode 100644 index 0000000..18d3e38 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/metrics/MetricsTimerFactory.java @@ -0,0 +1,39 @@ +/* + * 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.qi4j.api.metrics; + +import java.util.concurrent.TimeUnit; + +/** + * Create MetricsTimer instances. + */ +public interface MetricsTimerFactory extends MetricsFactory +{ + /** + * Create a MetricsTimer 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 duration the scale unit for this timer's duration metrics + * @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. + * + */ + MetricsTimer createTimer( Class origin, String name, TimeUnit duration, TimeUnit rate ); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/metrics/package.html ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/metrics/package.html b/core/api/src/main/java/org/qi4j/api/metrics/package.html new file mode 100644 index 0000000..d0280bd --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/metrics/package.html @@ -0,0 +1,21 @@ + + + +

Metrics API.

+ + http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/mixin/Initializable.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/mixin/Initializable.java b/core/api/src/main/java/org/qi4j/api/mixin/Initializable.java new file mode 100644 index 0000000..53314e9 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/mixin/Initializable.java @@ -0,0 +1,32 @@ +/* + * 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.qi4j.api.mixin; + +/** + * Fragments which want to be initialized can implement + * this callback interface. It will be invoked after + * the fragment has bee instantiated and all injections have been done. + */ +public interface Initializable +{ + /** + * Initialize the fragment + * + * @throws org.qi4j.api.mixin.InitializationException + * if something went wrong + */ + void initialize() + throws InitializationException; +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/mixin/InitializationException.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/mixin/InitializationException.java b/core/api/src/main/java/org/qi4j/api/mixin/InitializationException.java new file mode 100644 index 0000000..4a42da6 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/mixin/InitializationException.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.qi4j.api.mixin; + +/** + * Thrown when a Fragment or object could not be instantiated. + */ +public class InitializationException + extends RuntimeException +{ + private static final long serialVersionUID = 1L; + + public InitializationException() + { + } + + public InitializationException( String message ) + { + super( message ); + } + + public InitializationException( String message, Throwable cause ) + { + super( message, cause ); + } + + public InitializationException( Throwable cause ) + { + super( cause ); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/mixin/InvalidMixinException.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/mixin/InvalidMixinException.java b/core/api/src/main/java/org/qi4j/api/mixin/InvalidMixinException.java new file mode 100644 index 0000000..967c6b6 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/mixin/InvalidMixinException.java @@ -0,0 +1,33 @@ +/* + * Copyright 2009 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.qi4j.api.mixin; + +import java.lang.reflect.Method; + +/** + * This exception is thrown if a Mixin is invalid (missing method implementation). + */ +public class InvalidMixinException + extends RuntimeException +{ + public InvalidMixinException( Class mixinClass, Method method ) + { + super( mixinClass.getName() + "does not have a method implementation for " + method ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/mixin/MixinDescriptor.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/mixin/MixinDescriptor.java b/core/api/src/main/java/org/qi4j/api/mixin/MixinDescriptor.java new file mode 100644 index 0000000..288aac3 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/mixin/MixinDescriptor.java @@ -0,0 +1,23 @@ +/* + * 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.qi4j.api.mixin; + +/** + * Mixin Descriptor. + */ +public interface MixinDescriptor +{ + Class mixinClass(); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/mixin/MixinMappingException.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/mixin/MixinMappingException.java b/core/api/src/main/java/org/qi4j/api/mixin/MixinMappingException.java new file mode 100644 index 0000000..4bd3a8a --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/mixin/MixinMappingException.java @@ -0,0 +1,33 @@ +/* + * Copyright 2008 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.qi4j.api.mixin; + +/** + * This Exception is thrown when it is not possible to map the MixinType to a valid + * CompositeType. + */ +public class MixinMappingException + extends RuntimeException +{ + private static final long serialVersionUID = 6843167709252705294L; + + public MixinMappingException( String message ) + { + super( message ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/mixin/Mixins.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/mixin/Mixins.java b/core/api/src/main/java/org/qi4j/api/mixin/Mixins.java new file mode 100644 index 0000000..e308381 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/mixin/Mixins.java @@ -0,0 +1,79 @@ +/* + * 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.qi4j.api.mixin; + +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 in composites to declare mixin implementation classes. + *

+ * Mixins tells the runtime which implementation class of a Mixin should be + * used. The @Mixins annotation can occur at any level in the composite hierarchy + * and the runtime will match each found Mixin implementation against a Mixins annotation. + * All mixin interfaces must have a Mixin implementation in the composite hierarchy or + * a runtime exception will occur. + *

+ *

+ * Example; + *

+ *

+ *
+ * @Mixins( MyBeerOrder.class )
+ * public interface BeerOrderComposite extends BeerOrder, Composite
+ * {
+ * }
+ *
+ * public class MyBeerOrder
+ * implements BeerOrder
+ * {
+ * :
+ * }
+ * 
+ *

+ * Many implementations can be listed, + *

+ *

+ * @Mixins( { MyBeerOrder.class, DescriptionImpl.class } )
+ * public interface BeerOrderComposite extends BeerOrder, Description, Composite
+ * {
+ * }
+ * 
+ *

+ * If the Mixins is a class that implements InvocationHandler, it will be + * used for all mixins. To avoid that an invocation handler based implementation + * not service all mixin, use the AppliesTo annotation. + *

+ * + *

+ * It is valid to have multiple Mixins for a mixin. The first one found + * will be used. The search order is in the order they are written in the Mixins + * annotation left-to-right, and depth-first recursive search of the super-interfaces again + * left-to-right. + *

+ * + * @see org.qi4j.api.common.AppliesTo + */ +@Retention( RetentionPolicy.RUNTIME ) +@Target( ElementType.TYPE ) +@Documented +public @interface Mixins +{ + Class[] value(); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/mixin/NoopMixin.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/mixin/NoopMixin.java b/core/api/src/main/java/org/qi4j/api/mixin/NoopMixin.java new file mode 100644 index 0000000..948018e --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/mixin/NoopMixin.java @@ -0,0 +1,78 @@ +/* + * 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.qi4j.api.mixin; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +/** + * Generic mixin that is a no-op. Can be useful if the functionality + * of a method is mainly provided by concerns and side-effects. + */ +public final class NoopMixin + implements InvocationHandler +{ + private static final Boolean BOOLEAN_DEFAULT = Boolean.FALSE; + private static final Short SHORT_DEFAULT = 0; + private static final Character CHARACTER_DEFAULT = 0; + private static final Integer INTEGER_DEFAULT = 0; + private static final Long LONG_DEFAULT = 0L; + private static final Float FLOAT_DEFAULT = 0f; + private static final Double DOUBLE_DEFAULT = 0.0; + + @Override + public Object invoke( Object object, Method method, Object[] args ) + throws Throwable + { + Class retType = method.getReturnType(); + if( !retType.isPrimitive() ) + { + return null; + } + if( Void.TYPE == retType ) + { + return null; + } + if( Boolean.TYPE == retType ) + { + return BOOLEAN_DEFAULT; + } + if( Short.TYPE == retType ) + { + return SHORT_DEFAULT; + } + if( Character.TYPE == retType ) + { + return CHARACTER_DEFAULT; + } + if( Integer.TYPE == retType ) + { + return INTEGER_DEFAULT; + } + if( Long.TYPE == retType ) + { + return LONG_DEFAULT; + } + if( Float.TYPE == retType ) + { + return FLOAT_DEFAULT; + } + if( Double.TYPE == retType ) + { + return DOUBLE_DEFAULT; + } + return null; + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/mixin/package.html ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/mixin/package.html b/core/api/src/main/java/org/qi4j/api/mixin/package.html new file mode 100644 index 0000000..a0ebe07 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/mixin/package.html @@ -0,0 +1,21 @@ + + + +

Mixin API.

+ + http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/object/NoSuchObjectException.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/object/NoSuchObjectException.java b/core/api/src/main/java/org/qi4j/api/object/NoSuchObjectException.java new file mode 100644 index 0000000..71a4cb7 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/object/NoSuchObjectException.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2008, 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.qi4j.api.object; + +import org.qi4j.api.common.InvalidApplicationException; + +/** + * This exception is thrown if no visible Object of the requested type can be found. + */ +public class NoSuchObjectException + extends InvalidApplicationException +{ + private static final long serialVersionUID = -1121690536365682511L; + + private final String objectType; + private final String moduleName; + + public NoSuchObjectException( String type, String moduleName ) + { + super( "Could not find any visible Object of type [" + type + "] in module [" + + moduleName + "]." ); + this.objectType = type; + this.moduleName = moduleName; + } + + public String objectType() + { + return objectType; + } + + public String moduleName() + { + return moduleName; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/object/ObjectDescriptor.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/object/ObjectDescriptor.java b/core/api/src/main/java/org/qi4j/api/object/ObjectDescriptor.java new file mode 100644 index 0000000..115c52e --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/object/ObjectDescriptor.java @@ -0,0 +1,25 @@ +/* + * 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.qi4j.api.object; + +import org.qi4j.api.composite.ModelDescriptor; + +/** + * Object Descriptor. + */ +public interface ObjectDescriptor + extends ModelDescriptor +{ +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/object/ObjectFactory.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/object/ObjectFactory.java b/core/api/src/main/java/org/qi4j/api/object/ObjectFactory.java new file mode 100644 index 0000000..9b8ec47 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/object/ObjectFactory.java @@ -0,0 +1,46 @@ +/* + * 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.qi4j.api.object; + +import org.qi4j.api.common.ConstructionException; + +/** + * This factory creates and injects POJO's. + */ +public interface ObjectFactory +{ + /** + * Create new objects of the given type. + * + * @param type an object class which will be instantiated. + * + * @return new objects. + * + * @throws ConstructionException Thrown if instantiation fails. + * @throws NoSuchObjectException Thrown if {@code type} class is not an object. + */ + T newObject( Class type, Object... uses ) + throws NoSuchObjectException, ConstructionException; + + /** + * Inject an existing instance. Only fields and methods will be called. + * + * @param instance + * + * @throws ConstructionException + */ + void injectTo( Object instance, Object... uses ) + throws ConstructionException; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/object/package.html ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/object/package.html b/core/api/src/main/java/org/qi4j/api/object/package.html new file mode 100644 index 0000000..1e06504 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/object/package.html @@ -0,0 +1,21 @@ + + + +

Object API.

+ + http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/package.html ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/package.html b/core/api/src/main/java/org/qi4j/api/package.html new file mode 100644 index 0000000..ff7d9af --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/package.html @@ -0,0 +1,21 @@ + + + +

Apache Zest™ API.

+ + http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/property/DefaultValues.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/property/DefaultValues.java b/core/api/src/main/java/org/qi4j/api/property/DefaultValues.java new file mode 100644 index 0000000..3d0dbff --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/property/DefaultValues.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2008, Michael Hunger. 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.qi4j.api.property; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; + +/** + * Default values for various property types + */ +public final class DefaultValues +{ + private static final Map DEFAULT_VALUES = new HashMap(); + + static + { + DEFAULT_VALUES.put( Byte.class, 0 ); + DEFAULT_VALUES.put( Short.class, 0 ); + DEFAULT_VALUES.put( Character.class, 0 ); + DEFAULT_VALUES.put( Integer.class, 0 ); + DEFAULT_VALUES.put( Long.class, 0L ); + DEFAULT_VALUES.put( Double.class, 0D ); + DEFAULT_VALUES.put( Float.class, 0F ); + DEFAULT_VALUES.put( Boolean.class, false ); + DEFAULT_VALUES.put( String.class, "" ); + } + + public static Object getDefaultValueOf( Type type ) + { + Object value = DEFAULT_VALUES.get( type ); + if( value != null ) + { + return value; + } + if( type instanceof ParameterizedType ) + { + // List -> List + type = ( (ParameterizedType) type ).getRawType(); + } + + if( type instanceof Class ) + { + Class typeAsClass = (Class) type; + if( Set.class.isAssignableFrom( typeAsClass ) ) + { + return new HashSet(); + } + else if( Map.class.isAssignableFrom( typeAsClass ) ) + { + return new LinkedHashMap(); + } + else if( Collection.class.isAssignableFrom( typeAsClass ) ) + { + return new ArrayList(); + } + else if( typeAsClass.isEnum() ) + { + return ( (Class) type ).getEnumConstants()[ 0 ]; + } + } + throw new IllegalArgumentException( "Cannot use @UseDefaults with type " + type.toString() ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/property/GenericPropertyInfo.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/property/GenericPropertyInfo.java b/core/api/src/main/java/org/qi4j/api/property/GenericPropertyInfo.java new file mode 100644 index 0000000..b8b9467 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/property/GenericPropertyInfo.java @@ -0,0 +1,61 @@ +/* + * Copyright 2007,2008 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.qi4j.api.property; + +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +import static org.qi4j.api.util.Classes.typeOf; + +/** + * Generic Property info utility class. + */ +public final class GenericPropertyInfo +{ + public static Type propertyTypeOf( AccessibleObject accessor ) + { + return toPropertyType( typeOf( accessor ) ); + } + + public static Type toPropertyType( Type methodReturnType ) + { + if( methodReturnType instanceof ParameterizedType ) + { + ParameterizedType parameterizedType = (ParameterizedType) methodReturnType; + if( Property.class.isAssignableFrom( (Class) parameterizedType.getRawType() ) ) + { + return parameterizedType.getActualTypeArguments()[ 0 ]; + } + } + + if( methodReturnType instanceof Class ) + { + Type[] interfaces = ( (Class) methodReturnType ).getGenericInterfaces(); + for( Type anInterface : interfaces ) + { + Type propertyType = toPropertyType( anInterface ); + if( propertyType != null ) + { + return propertyType; + } + } + } + return null; + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/main/java/org/qi4j/api/property/Immutable.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/property/Immutable.java b/core/api/src/main/java/org/qi4j/api/property/Immutable.java new file mode 100644 index 0000000..39e3cf9 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/property/Immutable.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.qi4j.api.property; + +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 adds Immutability to Types, Properties and Associations + */ +@Retention( RetentionPolicy.RUNTIME ) +@Target( { ElementType.TYPE, ElementType.METHOD } ) +@Documented +public @interface Immutable +{ +}