http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/injection/scope/package.html ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/injection/scope/package.html b/core/api/src/main/java/org/apache/polygene/api/injection/scope/package.html new file mode 100644 index 0000000..10f4f1c --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/injection/scope/package.html @@ -0,0 +1,24 @@ +<!-- + ~ 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/1c722f44/core/api/src/main/java/org/apache/polygene/api/metrics/Metric.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/metrics/Metric.java b/core/api/src/main/java/org/apache/polygene/api/metrics/Metric.java new file mode 100644 index 0000000..46cd3f5 --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/metrics/Metric.java @@ -0,0 +1,28 @@ +/* + * 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.polygene.api.metrics; + +/** + * Marker interface for all Metric types. + */ +public interface Metric +{ +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/metrics/MetricNames.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/metrics/MetricNames.java b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricNames.java new file mode 100644 index 0000000..d24bd8e --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricNames.java @@ -0,0 +1,95 @@ +/* + * 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.polygene.api.metrics; + +import org.apache.polygene.api.structure.Module; + +import java.lang.reflect.Method; +import java.util.StringJoiner; + +/** + * Metric names utilities. + */ +public class MetricNames +{ + /** + * Build a Metric name for the given fragments. + * + * @param fragments Name fragments + * @return Metric name + */ + public static String nameFor( String... fragments ) + { + StringJoiner joiner = new StringJoiner( "." ); + for( String fragment : fragments ) + { + joiner.add( fragment ); + } + return joiner.toString(); + } + + /** + * Build a Metric name for the given Module, Type and optional fragments. + * + * @param module Module + * @param type Type + * @param fragments Name fragments + * @return Metric name + */ + public static String nameFor( Module module, Class<?> type, String... fragments ) + { + StringJoiner joiner = new StringJoiner( "." ) + .add( module.layer().name() ) + .add( module.name() ) + .add( className( type ) ); + for( String fragment : fragments ) + { + joiner.add( fragment ); + } + return joiner.toString(); + } + + /** + * Build a Metric name for the given Module, Method and optional fragments. + * + * @param module Module + * @param method Method + * @param fragments Name fragments + * @return Metric name + */ + public static String nameFor( Module module, Method method, String... fragments ) + { + StringJoiner joiner = new StringJoiner( "." ) + .add( module.layer().name() ) + .add( module.name() ) + .add( className( method.getDeclaringClass() ) ) + .add( method.getName() ); + for( String fragment : fragments ) + { + joiner.add( fragment ); + } + return joiner.toString(); + } + + private static String className( Class<?> clazz ) + { + return clazz.getName().substring( clazz.getName().lastIndexOf( '.' ) + 1 ).replace( '$', '.' ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsCounter.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsCounter.java b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsCounter.java new file mode 100644 index 0000000..9b9b9df --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsCounter.java @@ -0,0 +1,35 @@ +/* + * 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.polygene.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/1c722f44/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsCounterFactory.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsCounterFactory.java b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsCounterFactory.java new file mode 100644 index 0000000..45959a3 --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsCounterFactory.java @@ -0,0 +1,37 @@ +/* + * 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.polygene.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 name A human readable, short name of the metric. + * + * @return A Metric instance to be used, OR org.apache.polygene.spi.metrics.DefaultMetric.NULL if not supported. + */ + MetricsCounter createCounter( String name ); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsFactory.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsFactory.java b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsFactory.java new file mode 100644 index 0000000..af85ea9 --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsFactory.java @@ -0,0 +1,31 @@ +/* + * 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.polygene.api.metrics; + +import java.util.stream.Stream; + +/** + * Metrics Factory. + */ +public interface MetricsFactory +{ + Stream<Metric> registered(); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsGauge.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsGauge.java b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsGauge.java new file mode 100644 index 0000000..cf34fe6 --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsGauge.java @@ -0,0 +1,38 @@ +/* + * 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.polygene.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/1c722f44/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsGaugeFactory.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsGaugeFactory.java b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsGaugeFactory.java new file mode 100644 index 0000000..9af3d19 --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsGaugeFactory.java @@ -0,0 +1,38 @@ +/* + * 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.polygene.api.metrics; + +/** + * Register MetricsGauge with the underlying Metrics system. + */ +public interface MetricsGaugeFactory extends MetricsFactory +{ + /** + * Register a MetricsGauge with the underlying Metrics system. + * + * @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( String name, MetricsGauge<T> gauge ); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsHealthCheck.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsHealthCheck.java b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsHealthCheck.java new file mode 100644 index 0000000..e65703c --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsHealthCheck.java @@ -0,0 +1,59 @@ +/* + * 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.polygene.api.metrics; + +/** + * Metrics Health Check. + */ +public interface MetricsHealthCheck extends Metric +{ + Result check() + throws Exception; + + 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/1c722f44/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsHealthCheckFactory.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsHealthCheckFactory.java b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsHealthCheckFactory.java new file mode 100644 index 0000000..ff31d02 --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsHealthCheckFactory.java @@ -0,0 +1,39 @@ +/* + * 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.polygene.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 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.apache.polygene.spi.metrics.DefaultMetric.NULL if not supported. + * + */ + MetricsHealthCheck registerHealthCheck( String name, MetricsHealthCheck check ); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsHistogram.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsHistogram.java b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsHistogram.java new file mode 100644 index 0000000..a61ee1f --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsHistogram.java @@ -0,0 +1,31 @@ +/* + * 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.polygene.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/1c722f44/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsHistogramFactory.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsHistogramFactory.java b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsHistogramFactory.java new file mode 100644 index 0000000..3ca7bbd --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsHistogramFactory.java @@ -0,0 +1,38 @@ +/* + * 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.polygene.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 name A human readable, short name of the metric. + * + * @return A Metric instance to be used, OR org.apache.polygene.spi.metrics.DefaultMetric.NULL if not supported. + * + */ + MetricsHistogram createHistogram( String name ); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsMeter.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsMeter.java b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsMeter.java new file mode 100644 index 0000000..e6f4df8 --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsMeter.java @@ -0,0 +1,39 @@ +/* + * 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.polygene.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/1c722f44/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsMeterFactory.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsMeterFactory.java b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsMeterFactory.java new file mode 100644 index 0000000..209ba3b --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsMeterFactory.java @@ -0,0 +1,37 @@ +/* + * 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.polygene.api.metrics; + +/** + * 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 name A human readable, short name of the metric. + * + * @return A Metric instance to be used, OR org.apache.polygene.spi.metrics.DefaultMetric.NULL if not supported. + */ + MetricsMeter createMeter( String name ); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsNotSupportedException.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsNotSupportedException.java b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsNotSupportedException.java new file mode 100644 index 0000000..4a47f45 --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsNotSupportedException.java @@ -0,0 +1,33 @@ +/* + * 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.polygene.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() + "]." ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsProvider.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsProvider.java b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsProvider.java new file mode 100644 index 0000000..f3fd5c7 --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsProvider.java @@ -0,0 +1,62 @@ +/* + * 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.polygene.api.metrics; + +/** + * Metrics Provider SPI. + * <p> + * The Polygene Runtime will automatically look for a service that implements the MetricsProvider interface + * and use it for internal Runtime metrics, such as the UnitOfWork measuring the time from creation to close. + * </p> + * <p> + * The Metrics Library is available to add metric functionality to applications in the same way, and + * will use the same MetricsProvider. + * </p> + * <p> + * Note that the usual visibility rules applies, so you might have more than one MetricsProvider server, + * perhaps per layer. + * </p> + */ +public interface MetricsProvider +{ + /** + * Creates a new factory instance. + * + * The instantiation is done by providing a Metric type, which is one of + * <ul> + * <li>{@link MetricsCounter}</li> + * <li>{@link MetricsGauge}</li> + * <li>{@link MetricsHealthCheck}</li> + * <li>{@link MetricsHistogram}</li> + * <li>{@link MetricsMeter}</li> + * <li>{@link MetricsTimer}</li> + * </ul> + * + * @param factoryType The class of the metric type needed. + * @param <T> The metric type requested. + * + * @return A factory instance + * + * @throws MetricsNotSupportedException when the MetricsProvider is not supporting the factory type requested. + */ + <T extends MetricsFactory> T createFactory( Class<T> factoryType ) + throws MetricsNotSupportedException; +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsTimer.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsTimer.java b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsTimer.java new file mode 100644 index 0000000..c1eb9e1 --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsTimer.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.polygene.api.metrics; + +/** + * Timer Metrics. + */ +public interface MetricsTimer extends Metric +{ + /** + * Start the Timer Metrics. + */ + Context start(); + + /** + * Timer Metrics Context. + */ + interface Context + { + /** + * Stop the Timer Metrics. + */ + void stop(); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsTimerFactory.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsTimerFactory.java b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsTimerFactory.java new file mode 100644 index 0000000..e672d5b --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/metrics/MetricsTimerFactory.java @@ -0,0 +1,38 @@ +/* + * 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.polygene.api.metrics; + +/** + * 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 name A human readable, short name of the metric. + * + * @return A Metric instance to be used, OR org.apache.polygene.spi.metrics.DefaultMetric.NULL if not supported. + * + */ + MetricsTimer createTimer( String name ); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/metrics/package.html ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/metrics/package.html b/core/api/src/main/java/org/apache/polygene/api/metrics/package.html new file mode 100644 index 0000000..3657fe5 --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/metrics/package.html @@ -0,0 +1,24 @@ +<!-- + ~ 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>Metrics API.</h2> + </body> +</html> http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/mixin/Initializable.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/mixin/Initializable.java b/core/api/src/main/java/org/apache/polygene/api/mixin/Initializable.java new file mode 100644 index 0000000..60136f7 --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/mixin/Initializable.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.polygene.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 Exception if something went wrong + */ + void initialize() throws Exception; +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/mixin/InitializationException.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/mixin/InitializationException.java b/core/api/src/main/java/org/apache/polygene/api/mixin/InitializationException.java new file mode 100644 index 0000000..11159b1 --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/mixin/InitializationException.java @@ -0,0 +1,38 @@ +/* + * 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.polygene.api.mixin; + +/** + * Thrown when a Fragment or object could not be initialized. + */ +public class InitializationException + extends RuntimeException +{ + private static final long serialVersionUID = 1L; + + public InitializationException() + { + } + + public InitializationException( String message, Throwable cause ) + { + super( message, cause ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/mixin/InvalidMixinException.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/mixin/InvalidMixinException.java b/core/api/src/main/java/org/apache/polygene/api/mixin/InvalidMixinException.java new file mode 100644 index 0000000..0df6730 --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/mixin/InvalidMixinException.java @@ -0,0 +1,35 @@ +/* + * 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.polygene.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/1c722f44/core/api/src/main/java/org/apache/polygene/api/mixin/MixinDescriptor.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/mixin/MixinDescriptor.java b/core/api/src/main/java/org/apache/polygene/api/mixin/MixinDescriptor.java new file mode 100644 index 0000000..261e7bc --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/mixin/MixinDescriptor.java @@ -0,0 +1,29 @@ +/* + * 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.polygene.api.mixin; + +/** + * Mixin Descriptor. + */ +public interface MixinDescriptor +{ + Class<?> mixinClass(); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/mixin/MixinMappingException.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/mixin/MixinMappingException.java b/core/api/src/main/java/org/apache/polygene/api/mixin/MixinMappingException.java new file mode 100644 index 0000000..84f3746 --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/mixin/MixinMappingException.java @@ -0,0 +1,35 @@ +/* + * 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.polygene.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/1c722f44/core/api/src/main/java/org/apache/polygene/api/mixin/Mixins.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/mixin/Mixins.java b/core/api/src/main/java/org/apache/polygene/api/mixin/Mixins.java new file mode 100644 index 0000000..e81989c --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/mixin/Mixins.java @@ -0,0 +1,84 @@ +/* + * 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.polygene.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. + * <p> + * 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. + * </p> + * <p> + * Example; + * </p> + * <pre><code> + * + * @Mixins( MyBeerOrder.class ) + * public interface BeerOrderComposite extends BeerOrder, Composite + * { + * } + * + * public class MyBeerOrder + * implements BeerOrder + * { + * : + * } + * </code></pre> + * <p> + * Many implementations can be listed, + * </p> + * <pre><code> + * @Mixins( { MyBeerOrder.class, DescriptionImpl.class } ) + * public interface BeerOrderComposite extends BeerOrder, Description, Composite + * { + * } + * </code></pre> + * <p> + * 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. + * </p> + * + * <p> + * 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. + * </p> + * + * @see org.apache.polygene.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/1c722f44/core/api/src/main/java/org/apache/polygene/api/mixin/NoopMixin.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/mixin/NoopMixin.java b/core/api/src/main/java/org/apache/polygene/api/mixin/NoopMixin.java new file mode 100644 index 0000000..7cfc81a --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/mixin/NoopMixin.java @@ -0,0 +1,84 @@ +/* + * 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.polygene.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/1c722f44/core/api/src/main/java/org/apache/polygene/api/mixin/package.html ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/mixin/package.html b/core/api/src/main/java/org/apache/polygene/api/mixin/package.html new file mode 100644 index 0000000..7c916a3 --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/mixin/package.html @@ -0,0 +1,24 @@ +<!-- + ~ 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>Mixin API.</h2> + </body> +</html> http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/object/NoSuchObjectException.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/object/NoSuchObjectException.java b/core/api/src/main/java/org/apache/polygene/api/object/NoSuchObjectException.java new file mode 100644 index 0000000..82b63bd --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/object/NoSuchObjectException.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.polygene.api.object; + +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.polygene.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, Stream<Class<?>> visible ) + { + super( "Could not find any visible Object of type [" + type + "] in module [" + + moduleName + + "]. The visible types are: \n" + + visible.map( Class::getName ).collect( Collectors.joining("\n") ) + ); + 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/1c722f44/core/api/src/main/java/org/apache/polygene/api/object/ObjectDescriptor.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/object/ObjectDescriptor.java b/core/api/src/main/java/org/apache/polygene/api/object/ObjectDescriptor.java new file mode 100644 index 0000000..81ee90b --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/object/ObjectDescriptor.java @@ -0,0 +1,31 @@ +/* + * 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.polygene.api.object; + +import org.apache.polygene.api.composite.ModelDescriptor; + +/** + * Object Descriptor. + */ +public interface ObjectDescriptor + extends ModelDescriptor +{ +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/object/ObjectFactory.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/object/ObjectFactory.java b/core/api/src/main/java/org/apache/polygene/api/object/ObjectFactory.java new file mode 100644 index 0000000..bd9a723 --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/object/ObjectFactory.java @@ -0,0 +1,52 @@ +/* + * 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.polygene.api.object; + +import org.apache.polygene.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> T newObject( Class<T> type, Object... uses ) + throws NoSuchObjectException, ConstructionException; + + /** + * Inject an existing instance. Only fields and methods will be called. + * + * @param instance instance + * @param uses dependencies + * + * @throws ConstructionException if it was not possible to construct the Object dependencies + */ + 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/1c722f44/core/api/src/main/java/org/apache/polygene/api/object/package.html ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/object/package.html b/core/api/src/main/java/org/apache/polygene/api/object/package.html new file mode 100644 index 0000000..6956f39 --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/object/package.html @@ -0,0 +1,24 @@ +<!-- + ~ 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>Object API.</h2> + </body> +</html> http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/package.html ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/package.html b/core/api/src/main/java/org/apache/polygene/api/package.html new file mode 100644 index 0000000..1964935 --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/package.html @@ -0,0 +1,24 @@ +<!-- + ~ 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>Apache Polygene⢠API.</h2> + </body> +</html> http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/property/DefaultValues.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/property/DefaultValues.java b/core/api/src/main/java/org/apache/polygene/api/property/DefaultValues.java new file mode 100644 index 0000000..00a128e --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/property/DefaultValues.java @@ -0,0 +1,88 @@ +/* + * 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.polygene.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<Type, Object> DEFAULT_VALUES = new HashMap<Type, Object>(); + + 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<Foo> -> 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/1c722f44/core/api/src/main/java/org/apache/polygene/api/property/GenericPropertyInfo.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/property/GenericPropertyInfo.java b/core/api/src/main/java/org/apache/polygene/api/property/GenericPropertyInfo.java new file mode 100644 index 0000000..0b3dd9b --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/property/GenericPropertyInfo.java @@ -0,0 +1,63 @@ +/* + * 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.polygene.api.property; + +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +import static org.apache.polygene.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/1c722f44/core/api/src/main/java/org/apache/polygene/api/property/Immutable.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/property/Immutable.java b/core/api/src/main/java/org/apache/polygene/api/property/Immutable.java new file mode 100644 index 0000000..dee1d2f --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/property/Immutable.java @@ -0,0 +1,37 @@ +/* + * 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.polygene.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 +{ +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/property/InvalidPropertyTypeException.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/property/InvalidPropertyTypeException.java b/core/api/src/main/java/org/apache/polygene/api/property/InvalidPropertyTypeException.java new file mode 100644 index 0000000..56e78d0 --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/property/InvalidPropertyTypeException.java @@ -0,0 +1,41 @@ +/* + * 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.polygene.api.property; + +import java.lang.reflect.AccessibleObject; +import org.apache.polygene.api.common.ConstructionException; + +/** + * Thrown when attempting to subclass Property. + */ +public class InvalidPropertyTypeException extends ConstructionException +{ + public InvalidPropertyTypeException( AccessibleObject accessor ) + { + super( createMessage(accessor) ); + } + + private static String createMessage( AccessibleObject accessor ) + { + StringBuilder builder = new StringBuilder(); + builder.append( "Not allowed to subclass " + Property.class.getName() + ". Property accessor " + accessor + " is returning a Property subclass." ); + return builder.toString(); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/property/Numbers.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/property/Numbers.java b/core/api/src/main/java/org/apache/polygene/api/property/Numbers.java new file mode 100644 index 0000000..779485c --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/property/Numbers.java @@ -0,0 +1,162 @@ +/* + * 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.polygene.api.property; + +import java.math.BigDecimal; + +/** + * Convenience class for mathematical operations on numerical properties. + * <pre>import static org.apache.polygene.api.property.Numbers.*; + * ... + * add( object.numberProperty(), 5 );</pre> + */ +public final class Numbers +{ + // Integer operations + + public static Property<Integer> add( Property<Integer> property, int amount ) + { + property.set( property.get() + amount ); + return property; + } + + public static Property<Integer> mult( Property<Integer> property, int amount ) + { + property.set( property.get() * amount ); + return property; + } + + public static Property<Integer> sub( Property<Integer> property, int amount ) + { + property.set( property.get() - amount ); + return property; + } + + public static Property<Integer> div( Property<Integer> property, int amount ) + { + property.set( property.get() / amount ); + return property; + } + + // Long operations + + public static Property<Long> add( Property<Long> property, long amount ) + { + property.set( property.get() + amount ); + return property; + } + + public static Property<Long> mult( Property<Long> property, long amount ) + { + property.set( property.get() * amount ); + return property; + } + + public static Property<Long> sub( Property<Long> property, long amount ) + { + property.set( property.get() - amount ); + return property; + } + + public static Property<Long> div( Property<Long> property, long amount ) + { + property.set( property.get() / amount ); + return property; + } + + // Double operations + + public static Property<Double> add( Property<Double> property, double amount ) + { + property.set( property.get() + amount ); + return property; + } + + public static Property<Double> mult( Property<Double> property, double amount ) + { + property.set( property.get() * amount ); + return property; + } + + public static Property<Double> sub( Property<Double> property, double amount ) + { + property.set( property.get() - amount ); + return property; + } + + public static Property<Double> div( Property<Double> property, double amount ) + { + property.set( property.get() / amount ); + return property; + } + + // Float operations + + public static Property<Float> add( Property<Float> property, float amount ) + { + property.set( property.get() + amount ); + return property; + } + + public static Property<Float> mult( Property<Float> property, float amount ) + { + property.set( property.get() * amount ); + return property; + } + + public static Property<Float> sub( Property<Float> property, float amount ) + { + property.set( property.get() - amount ); + return property; + } + + public static Property<Float> div( Property<Float> property, float amount ) + { + property.set( property.get() / amount ); + return property; + } + + // BigDecimal operations + + public static Property<BigDecimal> add( Property<BigDecimal> property, BigDecimal amount ) + { + property.set( property.get().add( amount ) ); + return property; + } + + public static Property<BigDecimal> mult( Property<BigDecimal> property, BigDecimal amount ) + { + property.set( property.get().multiply( amount ) ); + return property; + } + + public static Property<BigDecimal> sub( Property<BigDecimal> property, BigDecimal amount ) + { + property.set( property.get().subtract( amount ) ); + return property; + } + + public static Property<BigDecimal> div( Property<BigDecimal> property, BigDecimal amount ) + { + property.set( property.get().divide( amount ) ); + return property; + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/property/Property.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/property/Property.java b/core/api/src/main/java/org/apache/polygene/api/property/Property.java new file mode 100644 index 0000000..f3384b1 --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/property/Property.java @@ -0,0 +1,63 @@ +/* + * 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.polygene.api.property; + +/** + * Properties are declared in Composite interfaces by using this interface. + * <p> + * It creates a first-class object for the property from which you can get and set the value, and access any + * metadata about it. + * </p> + * <p>The type of the Property can be one of the following:</p> + * <ul> + * <li> A boxed primitive (Long,Integer,Boolean, etc.)</li> + * <li> String</li> + * <li> BigInteger</li> + * <li> BigDecimal</li> + * <li> Date</li> + * <li> DateTime (Joda Time)</li> + * <li> LocalDateTime (Joda Time)</li> + * <li> A serializable</li> + * <li> A ValueComposite</li> + * <li> A List, Set or Collection of any of the above</li> + * </ul> + * + * @param <T> Parameterized type of the Property + */ +public interface Property<T> +{ + /** + * Get the value of the property. + * + * @return the value + */ + T get(); + + /** + * Set the value of the property + * + * @param newValue the new value + * + * @throws IllegalArgumentException if the value has an invalid value + * @throws IllegalStateException if the property is immutable + */ + void set( T newValue ) + throws IllegalArgumentException, IllegalStateException; +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/property/PropertyDescriptor.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/property/PropertyDescriptor.java b/core/api/src/main/java/org/apache/polygene/api/property/PropertyDescriptor.java new file mode 100644 index 0000000..52b217c --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/property/PropertyDescriptor.java @@ -0,0 +1,62 @@ +/* + * 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.polygene.api.property; + +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.Type; +import org.apache.polygene.api.common.QualifiedName; +import org.apache.polygene.api.structure.MetaInfoHolder; +import org.apache.polygene.api.structure.ModuleDescriptor; +import org.apache.polygene.api.type.ValueType; + +/** + * Property Descriptor. + */ +public interface PropertyDescriptor extends MetaInfoHolder +{ + boolean isImmutable(); + + /** + * Get the qualified name of the property which is equal to: + * <pre><code> + * <interface name>:<method name> + * </code></pre> + * + * @return the qualified name of the property + */ + QualifiedName qualifiedName(); + + /** + * Get the type of the property. If the property is declared + * as Property<X> then X is returned. + * + * @return the property type + */ + Type type(); + + AccessibleObject accessor(); + + Object initialValue( ModuleDescriptor module ); + + ValueType valueType(); + + boolean queryable(); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/property/PropertyMixin.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/property/PropertyMixin.java b/core/api/src/main/java/org/apache/polygene/api/property/PropertyMixin.java new file mode 100644 index 0000000..1be3155 --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/property/PropertyMixin.java @@ -0,0 +1,60 @@ +/* + * 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.polygene.api.property; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import org.apache.polygene.api.common.AppliesTo; +import org.apache.polygene.api.common.AppliesToFilter; +import org.apache.polygene.api.injection.scope.State; + +/** + * Generic mixin for properties. + */ +// START SNIPPET: actual +@AppliesTo( { PropertyMixin.PropertyFilter.class } ) +public final class PropertyMixin + implements InvocationHandler +{ + @State + private StateHolder state; + + @Override + public Object invoke( Object proxy, Method method, Object[] args ) + throws Throwable + { + return state.propertyFor( method ); + } + + /** + * Filter Property methods to apply generic Property Mixin. + */ + public static class PropertyFilter + implements AppliesToFilter + { + @Override + public boolean appliesTo( Method method, Class<?> mixin, Class<?> compositeType, Class<?> modifierClass ) + { + return Property.class.isAssignableFrom( method.getReturnType() ); + } + } +} +// END SNIPPET: actual http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/main/java/org/apache/polygene/api/property/PropertyWrapper.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/polygene/api/property/PropertyWrapper.java b/core/api/src/main/java/org/apache/polygene/api/property/PropertyWrapper.java new file mode 100644 index 0000000..85e703c --- /dev/null +++ b/core/api/src/main/java/org/apache/polygene/api/property/PropertyWrapper.java @@ -0,0 +1,72 @@ +/* + * 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.polygene.api.property; + +/** + * If you want to catch getting and setting properties, then create a GenericConcern + * that wraps the Polygene-supplied Property instance with PropertyWrappers. Override + * get() and/or set() to perform your custom code. + */ +public class PropertyWrapper + implements Property<Object> +{ + protected Property<Object> next; + + public PropertyWrapper( Property<Object> next ) + { + this.next = next; + } + + public Property<Object> next() + { + return next; + } + + @Override + public Object get() + { + return next.get(); + } + + @Override + public void set( Object newValue ) + throws IllegalArgumentException, IllegalStateException + { + next.set( newValue ); + } + + @Override + public int hashCode() + { + return next.hashCode(); + } + + @Override + public boolean equals( Object obj ) + { + return next.equals( obj ); + } + + @Override + public String toString() + { + return next.toString(); + } +}
