You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2012/12/05 00:41:10 UTC
[29/52] [partial] ISIS-188: consolidating isis-core
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/typicallen/fromtype/TypicalLengthFacetForParameterDerivedFromType.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/typicallen/fromtype/TypicalLengthFacetForParameterDerivedFromType.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/typicallen/fromtype/TypicalLengthFacetForParameterDerivedFromType.java
new file mode 100644
index 0000000..cff34b3
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/typicallen/fromtype/TypicalLengthFacetForParameterDerivedFromType.java
@@ -0,0 +1,42 @@
+/*
+ * 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.isis.core.progmodel.facets.param.typicallen.fromtype;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.multiline.MultiLineFacet;
+import org.apache.isis.core.metamodel.facets.typicallen.TypicalLengthFacet;
+import org.apache.isis.core.metamodel.facets.typicallen.TypicalLengthFacetAbstract;
+
+public class TypicalLengthFacetForParameterDerivedFromType extends TypicalLengthFacetAbstract {
+
+ private final TypicalLengthFacet typicalLengthFacet;
+
+ public TypicalLengthFacetForParameterDerivedFromType(final TypicalLengthFacet typicalLengthFacet, final FacetHolder holder) {
+ super(holder, true);
+ this.typicalLengthFacet = typicalLengthFacet;
+ }
+
+ @Override
+ public int value() {
+ final MultiLineFacet facet = getFacetHolder().getFacet(MultiLineFacet.class);
+ return facet.numberOfLines() * typicalLengthFacet.value();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/typicallen/fromtype/TypicalLengthFacetForParameterDerivedFromTypeFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/typicallen/fromtype/TypicalLengthFacetForParameterDerivedFromTypeFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/typicallen/fromtype/TypicalLengthFacetForParameterDerivedFromTypeFacetFactory.java
new file mode 100644
index 0000000..2e8c2c1
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/typicallen/fromtype/TypicalLengthFacetForParameterDerivedFromTypeFacetFactory.java
@@ -0,0 +1,55 @@
+/*
+ * 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.isis.core.progmodel.facets.param.typicallen.fromtype;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
+import org.apache.isis.core.metamodel.facets.FacetedMethodParameter;
+import org.apache.isis.core.metamodel.facets.typicallen.TypicalLengthFacet;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+
+public class TypicalLengthFacetForParameterDerivedFromTypeFacetFactory extends FacetFactoryAbstract {
+
+ public TypicalLengthFacetForParameterDerivedFromTypeFacetFactory() {
+ super(FeatureType.PARAMETERS_ONLY);
+ }
+
+ @Override
+ public void processParams(final ProcessParameterContext processParameterContext) {
+ final Class<?> type = processParameterContext.getMethod().getParameterTypes()[processParameterContext.getParamNum()];
+ final FacetedMethodParameter facetHolder = processParameterContext.getFacetHolder();
+ addFacetDerivedFromTypeIfPresent(facetHolder, type);
+ }
+
+ private void addFacetDerivedFromTypeIfPresent(final FacetHolder holder, final Class<?> type) {
+ final TypicalLengthFacet facet = getTypicalLengthFacet(type);
+ if (facet != null) {
+ FacetUtil.addFacet(new TypicalLengthFacetForParameterDerivedFromType(facet, holder));
+ }
+ }
+
+ private TypicalLengthFacet getTypicalLengthFacet(final Class<?> type) {
+ final ObjectSpecification paramTypeSpec = getSpecificationLoader().loadSpecification(type);
+ return paramTypeSpec.getFacet(TypicalLengthFacet.class);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/maskannot/MaskAnnotationForParameterFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/maskannot/MaskAnnotationForParameterFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/maskannot/MaskAnnotationForParameterFacetFactory.java
new file mode 100644
index 0000000..2431a80
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/maskannot/MaskAnnotationForParameterFacetFactory.java
@@ -0,0 +1,77 @@
+/*
+ * 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.isis.core.progmodel.facets.param.validate.maskannot;
+
+import org.apache.isis.applib.annotation.Mask;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facets.Annotations;
+import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
+import org.apache.isis.core.metamodel.facets.object.title.TitleFacet;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.progmodel.facets.object.mask.MaskFacet;
+import org.apache.isis.core.progmodel.facets.object.mask.TitleFacetBasedOnMask;
+
+public class MaskAnnotationForParameterFacetFactory extends FacetFactoryAbstract {
+
+ public MaskAnnotationForParameterFacetFactory() {
+ super(FeatureType.PARAMETERS_ONLY);
+ }
+
+ @Override
+ public void processParams(final ProcessParameterContext processParameterContext) {
+ final Class<?>[] parameterTypes = processParameterContext.getMethod().getParameterTypes();
+ if (processParameterContext.getParamNum() >= parameterTypes.length) {
+ // ignore
+ return;
+ }
+
+ final java.lang.annotation.Annotation[] parameterAnnotations = Annotations.getParameterAnnotations(processParameterContext.getMethod())[processParameterContext.getParamNum()];
+ for (int i = 0; i < parameterAnnotations.length; i++) {
+ if (parameterAnnotations[i] instanceof Mask) {
+ final Mask annotation = (Mask) parameterAnnotations[i];
+ addMaskFacetAndCorrespondingTitleFacet(processParameterContext.getFacetHolder(), annotation, parameterTypes[i]);
+ return;
+ }
+ }
+ }
+
+ private boolean addMaskFacetAndCorrespondingTitleFacet(final FacetHolder holder, final Mask annotation, final Class<?> cls) {
+ final MaskFacet maskFacet = createMaskFacet(annotation, holder);
+ if (maskFacet == null) {
+ return false;
+ }
+ FacetUtil.addFacet(maskFacet);
+
+ final ObjectSpecification type = getSpecificationLoader().loadSpecification(cls);
+ final TitleFacet underlyingTitleFacet = type.getFacet(TitleFacet.class);
+ if (underlyingTitleFacet != null) {
+ final TitleFacet titleFacet = new TitleFacetBasedOnMask(maskFacet, underlyingTitleFacet);
+ FacetUtil.addFacet(titleFacet);
+ }
+ return true;
+ }
+
+ private MaskFacet createMaskFacet(final Mask annotation, final FacetHolder holder) {
+ return annotation != null ? new MaskFacetAnnotationForParameter(annotation.value(), null, holder) : null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/maskannot/MaskFacetAnnotationForParameter.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/maskannot/MaskFacetAnnotationForParameter.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/maskannot/MaskFacetAnnotationForParameter.java
new file mode 100644
index 0000000..a4fe2cb
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/maskannot/MaskFacetAnnotationForParameter.java
@@ -0,0 +1,51 @@
+/*
+ * 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.isis.core.progmodel.facets.param.validate.maskannot;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.progmodel.facets.object.mask.MaskEvaluator;
+import org.apache.isis.core.progmodel.facets.object.mask.MaskFacetAbstract;
+
+public class MaskFacetAnnotationForParameter extends MaskFacetAbstract {
+ private final MaskEvaluator evaluator;
+
+ public MaskFacetAnnotationForParameter(final String outputMask, final String inputMask, final FacetHolder holder) {
+ super(outputMask, holder);
+ evaluator = inputMask == null ? null : new MaskEvaluator(inputMask);
+ }
+
+ @Override
+ public boolean doesNotMatch(final ObjectAdapter adapter) {
+ if (evaluator == null) {
+ return false;
+ } else {
+ if (adapter == null) {
+ return false;
+ }
+ final Object object = adapter.getObject();
+ if (object == null) {
+ return false;
+ }
+ return !evaluator.evaluate(object.toString());
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/maxlenannot/MaxLengthAnnotationForParameterFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/maxlenannot/MaxLengthAnnotationForParameterFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/maxlenannot/MaxLengthAnnotationForParameterFacetFactory.java
new file mode 100644
index 0000000..93ff7bc
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/maxlenannot/MaxLengthAnnotationForParameterFacetFactory.java
@@ -0,0 +1,54 @@
+/*
+ * 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.isis.core.progmodel.facets.param.validate.maxlenannot;
+
+import java.lang.annotation.Annotation;
+
+import org.apache.isis.applib.annotation.MaxLength;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facets.Annotations;
+import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
+import org.apache.isis.core.metamodel.facets.maxlen.MaxLengthFacet;
+
+public class MaxLengthAnnotationForParameterFacetFactory extends FacetFactoryAbstract {
+
+ public MaxLengthAnnotationForParameterFacetFactory() {
+ super(FeatureType.PARAMETERS_ONLY);
+ }
+
+ @Override
+ public void processParams(final ProcessParameterContext processParameterContext) {
+ final java.lang.annotation.Annotation[] parameterAnnotations = Annotations.getParameterAnnotations(processParameterContext.getMethod())[processParameterContext.getParamNum()];
+
+ for (final Annotation parameterAnnotation : parameterAnnotations) {
+ if (parameterAnnotation instanceof MaxLength) {
+ final MaxLength annotation = (MaxLength) parameterAnnotation;
+ FacetUtil.addFacet(create(annotation, processParameterContext.getFacetHolder()));
+ return;
+ }
+ }
+ }
+
+ private MaxLengthFacet create(final MaxLength annotation, final FacetHolder holder) {
+ return annotation == null ? null : new MaxLengthFacetAnnotationForParameter(annotation.value(), holder);
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/maxlenannot/MaxLengthFacetAnnotationForParameter.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/maxlenannot/MaxLengthFacetAnnotationForParameter.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/maxlenannot/MaxLengthFacetAnnotationForParameter.java
new file mode 100644
index 0000000..07c18fb
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/maxlenannot/MaxLengthFacetAnnotationForParameter.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.isis.core.progmodel.facets.param.validate.maxlenannot;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.maxlen.MaxLengthFacetAbstract;
+
+public class MaxLengthFacetAnnotationForParameter extends MaxLengthFacetAbstract {
+
+ public MaxLengthFacetAnnotationForParameter(final int value, final FacetHolder holder) {
+ super(value, holder);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/perspec/MustSatisfySpecificationOnParameterFacet.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/perspec/MustSatisfySpecificationOnParameterFacet.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/perspec/MustSatisfySpecificationOnParameterFacet.java
new file mode 100644
index 0000000..6b7e667
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/perspec/MustSatisfySpecificationOnParameterFacet.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.isis.core.progmodel.facets.param.validate.perspec;
+
+import java.util.List;
+
+import org.apache.isis.applib.events.ValidityEvent;
+import org.apache.isis.applib.spec.Specification;
+import org.apache.isis.applib.util.ReasonBuffer;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetAbstract;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.interactions.ProposedHolder;
+import org.apache.isis.core.metamodel.interactions.ValidatingInteractionAdvisor;
+import org.apache.isis.core.metamodel.interactions.ValidityContext;
+
+public class MustSatisfySpecificationOnParameterFacet extends FacetAbstract implements ValidatingInteractionAdvisor {
+
+ public static Class<? extends Facet> type() {
+ return MustSatisfySpecificationOnParameterFacet.class;
+ }
+
+ private final List<Specification> specifications;
+
+ public MustSatisfySpecificationOnParameterFacet(final List<Specification> specifications, final FacetHolder holder) {
+ super(type(), holder, Derivation.NOT_DERIVED);
+ this.specifications = specifications;
+ }
+
+ @Override
+ public String invalidates(final ValidityContext<? extends ValidityEvent> validityContext) {
+ if (!(validityContext instanceof ProposedHolder)) {
+ return null;
+ }
+ final ProposedHolder proposedHolder = (ProposedHolder) validityContext;
+ final ObjectAdapter targetNO = proposedHolder.getProposed();
+ final Object targetObject = targetNO.getObject();
+ final ReasonBuffer buf = new ReasonBuffer();
+ for (final Specification specification : specifications) {
+ buf.append(specification.satisfies(targetObject));
+ }
+ return buf.getReason();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/perspec/MustSatisfySpecificationOnParameterFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/perspec/MustSatisfySpecificationOnParameterFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/perspec/MustSatisfySpecificationOnParameterFacetFactory.java
new file mode 100644
index 0000000..dc3b100
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/perspec/MustSatisfySpecificationOnParameterFacetFactory.java
@@ -0,0 +1,82 @@
+/*
+ * 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.isis.core.progmodel.facets.param.validate.perspec;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.isis.applib.annotation.MustSatisfy;
+import org.apache.isis.applib.spec.Specification;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facets.Annotations;
+import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
+
+public class MustSatisfySpecificationOnParameterFacetFactory extends FacetFactoryAbstract {
+
+ public MustSatisfySpecificationOnParameterFacetFactory() {
+ super(FeatureType.PARAMETERS_ONLY);
+ }
+
+ @Override
+ public void processParams(final ProcessParameterContext processParameterContext) {
+ final java.lang.annotation.Annotation[] parameterAnnotations = Annotations.getParameterAnnotations(processParameterContext.getMethod())[processParameterContext.getParamNum()];
+
+ for (final Annotation parameterAnnotation : parameterAnnotations) {
+ if (parameterAnnotation instanceof MustSatisfy) {
+ final MustSatisfy annotation = (MustSatisfy) parameterAnnotation;
+ FacetUtil.addFacet(create(annotation, processParameterContext.getFacetHolder()));
+ return;
+ }
+ }
+ }
+
+ private Facet create(final MustSatisfy annotation, final FacetHolder holder) {
+ if (annotation == null) {
+ return null;
+ }
+ final Class<?>[] values = annotation.value();
+ final List<Specification> specifications = new ArrayList<Specification>();
+ for (final Class<?> value : values) {
+ final Specification specification = newSpecificationElseNull(value);
+ if (specification != null) {
+ specifications.add(specification);
+ }
+ }
+ return specifications.size() > 0 ? new MustSatisfySpecificationOnParameterFacet(specifications, holder) : null;
+ }
+
+ private static Specification newSpecificationElseNull(final Class<?> value) {
+ if (!(Specification.class.isAssignableFrom(value))) {
+ return null;
+ }
+ try {
+ return (Specification) value.newInstance();
+ } catch (final InstantiationException e) {
+ return null;
+ } catch (final IllegalAccessException e) {
+ return null;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/regexannot/RegExFacetAnnotationForParameter.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/regexannot/RegExFacetAnnotationForParameter.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/regexannot/RegExFacetAnnotationForParameter.java
new file mode 100644
index 0000000..5ddc290
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/regexannot/RegExFacetAnnotationForParameter.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.isis.core.progmodel.facets.param.validate.regexannot;
+
+import java.util.regex.Pattern;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.progmodel.facets.object.regex.RegExFacetAbstract;
+
+public class RegExFacetAnnotationForParameter extends RegExFacetAbstract {
+
+ private final Pattern pattern;
+
+ public RegExFacetAnnotationForParameter(final String validation, final String format, final boolean caseSensitive, final FacetHolder holder) {
+ super(validation, format, caseSensitive, holder);
+ pattern = Pattern.compile(validation(), patternFlags());
+ }
+
+ @Override
+ public String format(final String text) {
+ if (text == null) {
+ return "<not a string>";
+ }
+ if (format() == null || format().length() == 0) {
+ return text;
+ }
+ return pattern.matcher(text).replaceAll(format());
+ }
+
+ @Override
+ public boolean doesNotMatch(final String text) {
+ if (text == null) {
+ return true;
+ }
+ return !pattern.matcher(text).matches();
+ }
+
+ private int patternFlags() {
+ return !caseSensitive() ? Pattern.CASE_INSENSITIVE : 0;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/regexannot/RegExFacetAnnotationForParameterFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/regexannot/RegExFacetAnnotationForParameterFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/regexannot/RegExFacetAnnotationForParameterFacetFactory.java
new file mode 100644
index 0000000..76a5221
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/param/validate/regexannot/RegExFacetAnnotationForParameterFacetFactory.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.isis.core.progmodel.facets.param.validate.regexannot;
+
+import java.lang.annotation.Annotation;
+
+import org.apache.isis.applib.annotation.RegEx;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facets.Annotations;
+import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
+import org.apache.isis.core.metamodel.facets.object.title.TitleFacet;
+import org.apache.isis.core.progmodel.facets.object.regex.RegExFacet;
+import org.apache.isis.core.progmodel.facets.object.regex.TitleFacetFormattedByRegex;
+
+public class RegExFacetAnnotationForParameterFacetFactory extends FacetFactoryAbstract {
+
+ public RegExFacetAnnotationForParameterFacetFactory() {
+ super(FeatureType.PARAMETERS_ONLY);
+ }
+
+ @Override
+ public void processParams(final ProcessParameterContext processParameterContext) {
+ final Class<?>[] parameterTypes = processParameterContext.getMethod().getParameterTypes();
+ if (processParameterContext.getParamNum() >= parameterTypes.length) {
+ // ignore
+ return;
+ }
+ if (!Annotations.isString(parameterTypes[processParameterContext.getParamNum()])) {
+ return;
+ }
+
+ final Annotation[] parameterAnnotations = Annotations.getParameterAnnotations(processParameterContext.getMethod())[processParameterContext.getParamNum()];
+ for (final Annotation parameterAnnotation : parameterAnnotations) {
+ if (parameterAnnotation instanceof RegEx) {
+ final RegEx annotation = (RegEx) parameterAnnotation;
+ addRegexFacetAndCorrespondingTitleFacet(processParameterContext.getFacetHolder(), annotation);
+ return;
+ }
+ }
+ }
+
+ private void addRegexFacetAndCorrespondingTitleFacet(final FacetHolder holder, final RegEx annotation) {
+ final RegExFacet regexFacet = createRegexFacet(annotation, holder);
+ if (regexFacet == null) {
+ return;
+ }
+ FacetUtil.addFacet(regexFacet);
+
+ final TitleFacet titleFacet = createTitleFacet(regexFacet);
+ FacetUtil.addFacet(titleFacet);
+ }
+
+ private RegExFacet createRegexFacet(final RegEx annotation, final FacetHolder holder) {
+ if (annotation == null) {
+ return null;
+ }
+
+ final String validationExpression = annotation.validation();
+ final boolean caseSensitive = annotation.caseSensitive();
+ final String formatExpression = annotation.format();
+
+ return new RegExFacetAnnotationForParameter(validationExpression, formatExpression, caseSensitive, holder);
+ }
+
+ private TitleFacet createTitleFacet(final RegExFacet regexFacet) {
+ return new TitleFacetFormattedByRegex(regexFacet);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/accessor/PropertyAccessorFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/accessor/PropertyAccessorFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/accessor/PropertyAccessorFacetFactory.java
new file mode 100644
index 0000000..6fd00dd
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/accessor/PropertyAccessorFacetFactory.java
@@ -0,0 +1,105 @@
+/*
+ * 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.isis.core.progmodel.facets.properties.accessor;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facetapi.MethodRemover;
+import org.apache.isis.core.metamodel.methodutils.MethodScope;
+import org.apache.isis.core.progmodel.facets.MethodPrefixConstants;
+import org.apache.isis.core.progmodel.facets.PropertyOrCollectionIdentifyingFacetFactoryAbstract;
+
+public class PropertyAccessorFacetFactory extends PropertyOrCollectionIdentifyingFacetFactoryAbstract {
+
+ private static final String[] PREFIXES = { MethodPrefixConstants.GET_PREFIX, MethodPrefixConstants.IS_PREFIX };
+
+ public PropertyAccessorFacetFactory() {
+ super(FeatureType.PROPERTIES_ONLY, PREFIXES);
+ }
+
+ @Override
+ public void process(final ProcessMethodContext processMethodContext) {
+ attachPropertyAccessFacetForAccessorMethod(processMethodContext);
+ }
+
+ private static void attachPropertyAccessFacetForAccessorMethod(final ProcessMethodContext processMethodContext) {
+
+ final Method accessorMethod = processMethodContext.getMethod();
+
+ processMethodContext.removeMethod(accessorMethod);
+
+ final FacetHolder property = processMethodContext.getFacetHolder();
+ FacetUtil.addFacet(new PropertyAccessorFacetViaAccessor(accessorMethod, property));
+ }
+
+ // ///////////////////////////////////////////////////////
+ // PropertyOrCollectionIdentifying
+ // ///////////////////////////////////////////////////////
+
+ @Override
+ public boolean isPropertyOrCollectionAccessorCandidate(final Method method) {
+ final String methodName = method.getName();
+ if (methodName.startsWith(MethodPrefixConstants.GET_PREFIX)) {
+ return true;
+ }
+ if (methodName.startsWith(MethodPrefixConstants.IS_PREFIX) && method.getReturnType() == boolean.class) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * The method way well represent a collection, but this facet factory does
+ * not have any opinion on the matter.
+ */
+ @Override
+ public boolean isCollectionAccessor(final Method method) {
+ return false;
+ }
+
+ @Override
+ public boolean isPropertyAccessor(final Method method) {
+ if (!isPropertyOrCollectionAccessorCandidate(method)) {
+ return false;
+ }
+ final Class<?> methodReturnType = method.getReturnType();
+ return isCollectionOrArray(methodReturnType);
+ }
+
+ @Override
+ public void findAndRemovePropertyAccessors(final MethodRemover methodRemover, final List<Method> methodListToAppendTo) {
+ appendMatchingMethods(methodRemover, MethodPrefixConstants.IS_PREFIX, boolean.class, methodListToAppendTo);
+ appendMatchingMethods(methodRemover, MethodPrefixConstants.GET_PREFIX, Object.class, methodListToAppendTo);
+ }
+
+ private static void appendMatchingMethods(final MethodRemover methodRemover, final String prefix, final Class<?> returnType, final List<Method> methodListToAppendTo) {
+ methodListToAppendTo.addAll(methodRemover.removeMethods(MethodScope.OBJECT, prefix, returnType, false, 0));
+ }
+
+ @Override
+ public void findAndRemoveCollectionAccessors(final MethodRemover methodRemover, final List<Method> methodListToAppendTo) {
+ // does nothing
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/accessor/PropertyAccessorFacetViaAccessor.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/accessor/PropertyAccessorFacetViaAccessor.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/accessor/PropertyAccessorFacetViaAccessor.java
new file mode 100644
index 0000000..6b7002f
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/accessor/PropertyAccessorFacetViaAccessor.java
@@ -0,0 +1,77 @@
+/*
+ * 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.isis.core.progmodel.facets.properties.accessor;
+
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.isis.applib.DomainObjectContainer;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.util.AdapterInvokeUtils;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.ImperativeFacet;
+import org.apache.isis.core.metamodel.facets.accessor.PropertyOrCollectionAccessorFacetAbstract;
+
+public class PropertyAccessorFacetViaAccessor extends PropertyOrCollectionAccessorFacetAbstract implements ImperativeFacet {
+
+ private final Method method;
+
+ public PropertyAccessorFacetViaAccessor(final Method method, final FacetHolder holder) {
+ super(holder);
+ this.method = method;
+ }
+
+ /**
+ * Returns a singleton list of the {@link Method} provided in the
+ * constructor.
+ */
+ @Override
+ public List<Method> getMethods() {
+ return Collections.singletonList(method);
+ }
+
+ @Override
+ public boolean impliesResolve() {
+ return true;
+ }
+
+ /**
+ * Bytecode cannot automatically call
+ * {@link DomainObjectContainer#objectChanged(Object)} because cannot
+ * distinguish whether interacting with accessor to read it or to modify its
+ * contents.
+ */
+ @Override
+ public boolean impliesObjectChanged() {
+ return false;
+ }
+
+ @Override
+ public Object getProperty(final ObjectAdapter owningAdapter) {
+ return AdapterInvokeUtils.invoke(method, owningAdapter);
+ }
+
+ @Override
+ protected String toStringValues() {
+ return "method=" + method;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/choices/PropertyChoicesFacetAbstract.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/choices/PropertyChoicesFacetAbstract.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/choices/PropertyChoicesFacetAbstract.java
new file mode 100644
index 0000000..e7e280c
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/choices/PropertyChoicesFacetAbstract.java
@@ -0,0 +1,49 @@
+/*
+ * 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.isis.core.progmodel.facets.properties.choices;
+
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetAbstract;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.properties.choices.PropertyChoicesFacet;
+import org.apache.isis.core.metamodel.spec.SpecificationLoader;
+
+public abstract class PropertyChoicesFacetAbstract extends FacetAbstract implements PropertyChoicesFacet {
+
+ public static Class<? extends Facet> type() {
+ return PropertyChoicesFacet.class;
+ }
+
+ private final SpecificationLoader specificationLookup;
+
+ public PropertyChoicesFacetAbstract(final FacetHolder holder, final SpecificationLoader specificationLookup) {
+ super(type(), holder, Derivation.NOT_DERIVED);
+ this.specificationLookup = specificationLookup;
+ }
+
+ // ////////////////////////////////////////////////////////
+ // Dependencies (from constructor)
+ // ////////////////////////////////////////////////////////
+
+ protected SpecificationLoader getSpecificationLoader() {
+ return specificationLookup;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/choices/enums/PropertyChoicesFacetDerivedFromChoicesFacet.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/choices/enums/PropertyChoicesFacetDerivedFromChoicesFacet.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/choices/enums/PropertyChoicesFacetDerivedFromChoicesFacet.java
new file mode 100644
index 0000000..1c6673f
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/choices/enums/PropertyChoicesFacetDerivedFromChoicesFacet.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.isis.core.progmodel.facets.properties.choices.enums;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.FacetedMethod;
+import org.apache.isis.core.metamodel.facets.choices.ChoicesFacet;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.SpecificationLoader;
+import org.apache.isis.core.progmodel.facets.properties.choices.PropertyChoicesFacetAbstract;
+
+public class PropertyChoicesFacetDerivedFromChoicesFacet extends PropertyChoicesFacetAbstract {
+
+ public PropertyChoicesFacetDerivedFromChoicesFacet(final FacetHolder holder, final SpecificationLoader specificationLookup) {
+ super(holder, specificationLookup);
+ }
+
+ @Override
+ public Object[] getChoices(final ObjectAdapter adapter, final SpecificationLoader specificationLookup) {
+ final FacetHolder facetHolder = getFacetHolder();
+ final FacetedMethod noap = (FacetedMethod) facetHolder;
+ final ObjectSpecification noSpec = getSpecification(noap.getType());
+ final ChoicesFacet choicesFacet = noSpec.getFacet(ChoicesFacet.class);
+ if (choicesFacet == null) {
+ return new Object[0];
+ }
+ return choicesFacet.getChoices(adapter);
+ }
+
+ public ObjectSpecification getSpecification(final Class<?> type) {
+ return type == null ? null : getSpecificationLoader().loadSpecification(type);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/choices/enums/PropertyChoicesFacetDerivedFromChoicesFacetFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/choices/enums/PropertyChoicesFacetDerivedFromChoicesFacetFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/choices/enums/PropertyChoicesFacetDerivedFromChoicesFacetFacetFactory.java
new file mode 100644
index 0000000..63820ec
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/choices/enums/PropertyChoicesFacetDerivedFromChoicesFacetFacetFactory.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.isis.core.progmodel.facets.properties.choices.enums;
+
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManagerAware;
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
+
+public class PropertyChoicesFacetDerivedFromChoicesFacetFacetFactory extends FacetFactoryAbstract implements AdapterManagerAware {
+
+ private AdapterManager adapterManager;
+
+ public PropertyChoicesFacetDerivedFromChoicesFacetFacetFactory() {
+ super(FeatureType.PROPERTIES_ONLY);
+ }
+
+ @Override
+ public void process(final ProcessMethodContext processMethodContext) {
+
+ final Class<?> returnType = processMethodContext.getMethod().getReturnType();
+
+ if (!returnType.isEnum()) {
+ return;
+ }
+
+ FacetUtil.addFacet(new PropertyChoicesFacetDerivedFromChoicesFacet(processMethodContext.getFacetHolder(), getSpecificationLoader()));
+ }
+
+ // /////////////////////////////////////////////
+ // Injected
+ // /////////////////////////////////////////////
+
+ protected AdapterManager getAdapterManager() {
+ return adapterManager;
+ }
+
+ @Override
+ public void setAdapterManager(final AdapterManager adapterManager) {
+ this.adapterManager = adapterManager;
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/choices/method/PropertyChoicesFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/choices/method/PropertyChoicesFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/choices/method/PropertyChoicesFacetFactory.java
new file mode 100644
index 0000000..aff4fff
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/choices/method/PropertyChoicesFacetFactory.java
@@ -0,0 +1,81 @@
+/*
+ * 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.isis.core.progmodel.facets.properties.choices.method;
+
+import java.lang.reflect.Method;
+
+import org.apache.isis.core.commons.lang.NameUtils;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManagerAware;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.methodutils.MethodScope;
+import org.apache.isis.core.progmodel.facets.MethodFinderUtils;
+import org.apache.isis.core.progmodel.facets.MethodPrefixBasedFacetFactoryAbstract;
+import org.apache.isis.core.progmodel.facets.MethodPrefixConstants;
+
+public class PropertyChoicesFacetFactory extends MethodPrefixBasedFacetFactoryAbstract implements AdapterManagerAware {
+
+ private static final String[] PREFIXES = { MethodPrefixConstants.CHOICES_PREFIX };
+
+ private AdapterManager adapterManager;
+
+ public PropertyChoicesFacetFactory() {
+ super(FeatureType.PROPERTIES_ONLY, OrphanValidation.VALIDATE, PREFIXES);
+ }
+
+ @Override
+ public void process(final ProcessMethodContext processMethodContext) {
+
+ attachPropertyChoicesFacetIfChoicesMethodIsFound(processMethodContext);
+ }
+
+ private void attachPropertyChoicesFacetIfChoicesMethodIsFound(final ProcessMethodContext processMethodContext) {
+
+ final Method getMethod = processMethodContext.getMethod();
+ final String capitalizedName = NameUtils.javaBaseName(getMethod.getName());
+
+ final Class<?> cls = processMethodContext.getCls();
+ final Class<?> returnType = getMethod.getReturnType();
+ final Method choicesMethod = MethodFinderUtils.findMethod(cls, MethodScope.OBJECT, MethodPrefixConstants.CHOICES_PREFIX + capitalizedName, null, NO_PARAMETERS_TYPES);
+ if (choicesMethod == null) {
+ return;
+ }
+ processMethodContext.removeMethod(choicesMethod);
+
+ final FacetHolder property = processMethodContext.getFacetHolder();
+ FacetUtil.addFacet(new PropertyChoicesFacetViaMethod(choicesMethod, returnType, property, getSpecificationLoader(), getAdapterManager()));
+ }
+
+ // ///////////////////////////////////////////////////////
+ // Dependencies (injected)
+ // ///////////////////////////////////////////////////////
+
+ @Override
+ public void setAdapterManager(final AdapterManager adapterManager) {
+ this.adapterManager = adapterManager;
+ }
+
+ protected AdapterManager getAdapterManager() {
+ return adapterManager;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/choices/method/PropertyChoicesFacetViaMethod.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/choices/method/PropertyChoicesFacetViaMethod.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/choices/method/PropertyChoicesFacetViaMethod.java
new file mode 100644
index 0000000..60c7122
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/choices/method/PropertyChoicesFacetViaMethod.java
@@ -0,0 +1,96 @@
+/*
+ * 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.isis.core.progmodel.facets.properties.choices.method;
+
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.isis.core.commons.lang.ArrayUtil;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.util.AdapterInvokeUtils;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.ImperativeFacet;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.SpecificationLoader;
+import org.apache.isis.core.progmodel.facets.CollectionUtils;
+import org.apache.isis.core.progmodel.facets.properties.choices.PropertyChoicesFacetAbstract;
+
+public class PropertyChoicesFacetViaMethod extends PropertyChoicesFacetAbstract implements ImperativeFacet {
+
+ private final Method method;
+ private final Class<?> choicesClass;
+
+ private final AdapterManager adapterManager;
+
+ public PropertyChoicesFacetViaMethod(final Method method, final Class<?> choicesClass, final FacetHolder holder, final SpecificationLoader specificationLookup, final AdapterManager adapterManager) {
+ super(holder, specificationLookup);
+ this.method = method;
+ this.choicesClass = choicesClass;
+ this.adapterManager = adapterManager;
+ }
+
+ /**
+ * Returns a singleton list of the {@link Method} provided in the
+ * constructor.
+ */
+ @Override
+ public List<Method> getMethods() {
+ return Collections.singletonList(method);
+ }
+
+ @Override
+ public boolean impliesResolve() {
+ return true;
+ }
+
+ @Override
+ public boolean impliesObjectChanged() {
+ return false;
+ }
+
+ @Override
+ public Object[] getChoices(final ObjectAdapter owningAdapter, final SpecificationLoader specificationLookup) {
+ final Object options = AdapterInvokeUtils.invoke(method, owningAdapter);
+ if (options == null) {
+ return null;
+ }
+ if (options.getClass().isArray()) {
+ return ArrayUtil.getObjectAsObjectArray(options);
+ }
+ final ObjectSpecification specification = specificationLookup.loadSpecification(choicesClass);
+ return CollectionUtils.getCollectionAsObjectArray(options, specification, getAdapterManager());
+ }
+
+ @Override
+ protected String toStringValues() {
+ return "method=" + method + ",class=" + choicesClass;
+ }
+
+ // ////////////////////////////////////////////
+ // Dependencies
+ // ////////////////////////////////////////////
+
+ protected AdapterManager getAdapterManager() {
+ return adapterManager;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/PropertyDefaultFacetAbstract.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/PropertyDefaultFacetAbstract.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/PropertyDefaultFacetAbstract.java
new file mode 100644
index 0000000..876b1fd
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/PropertyDefaultFacetAbstract.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.isis.core.progmodel.facets.properties.defaults;
+
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetAbstract;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.properties.defaults.PropertyDefaultFacet;
+
+public abstract class PropertyDefaultFacetAbstract extends FacetAbstract implements PropertyDefaultFacet {
+
+ public static Class<? extends Facet> type() {
+ return PropertyDefaultFacet.class;
+ }
+
+ public PropertyDefaultFacetAbstract(final FacetHolder holder) {
+ super(type(), holder, Derivation.NOT_DERIVED);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/PropertyDefaultFacetNone.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/PropertyDefaultFacetNone.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/PropertyDefaultFacetNone.java
new file mode 100644
index 0000000..a4e638a
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/PropertyDefaultFacetNone.java
@@ -0,0 +1,44 @@
+/*
+ * 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.isis.core.progmodel.facets.properties.defaults;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+
+public class PropertyDefaultFacetNone extends PropertyDefaultFacetAbstract {
+
+ public PropertyDefaultFacetNone(final FacetHolder holder) {
+ super(holder);
+ }
+
+ /**
+ * Provides a default of <tt>null</tt>.
+ */
+ @Override
+ public ObjectAdapter getDefault(final ObjectAdapter inObject) {
+ return null;
+ }
+
+ @Override
+ public boolean isNoop() {
+ return true;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/fromtype/PropertyDefaultDerivedFromTypeFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/fromtype/PropertyDefaultDerivedFromTypeFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/fromtype/PropertyDefaultDerivedFromTypeFacetFactory.java
new file mode 100644
index 0000000..cb37776
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/fromtype/PropertyDefaultDerivedFromTypeFacetFactory.java
@@ -0,0 +1,79 @@
+/*
+ * 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.isis.core.progmodel.facets.properties.defaults.fromtype;
+
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManagerAware;
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
+import org.apache.isis.core.metamodel.facets.properties.defaults.PropertyDefaultFacet;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.progmodel.facets.object.defaults.DefaultedFacet;
+
+public class PropertyDefaultDerivedFromTypeFacetFactory extends FacetFactoryAbstract implements AdapterManagerAware {
+
+ private AdapterManager adapterManager;
+
+ public PropertyDefaultDerivedFromTypeFacetFactory() {
+ super(FeatureType.PROPERTIES_ONLY);
+ }
+
+ /**
+ * If there is a {@link DefaultedFacet} on the properties return type, then
+ * installs a {@link PropertyDefaultFacet} for the property with the same
+ * default.
+ */
+ @Override
+ public void process(final ProcessMethodContext processMethodContext) {
+ // don't overwrite any defaults that might already picked up
+ final PropertyDefaultFacet existingDefaultFacet = processMethodContext.getFacetHolder().getFacet(PropertyDefaultFacet.class);
+ if (existingDefaultFacet != null && !existingDefaultFacet.isNoop()) {
+ return;
+ }
+
+ // try to infer defaults from the underlying return type
+ final Class<?> returnType = processMethodContext.getMethod().getReturnType();
+ final DefaultedFacet returnTypeDefaultedFacet = getDefaultedFacet(returnType);
+ if (returnTypeDefaultedFacet != null) {
+ final PropertyDefaultFacetDerivedFromDefaultedFacet propertyFacet = new PropertyDefaultFacetDerivedFromDefaultedFacet(returnTypeDefaultedFacet, processMethodContext.getFacetHolder(), getAdapterManager());
+ FacetUtil.addFacet(propertyFacet);
+ }
+ }
+
+ private DefaultedFacet getDefaultedFacet(final Class<?> paramType) {
+ final ObjectSpecification paramTypeSpec = getSpecificationLoader().loadSpecification(paramType);
+ return paramTypeSpec.getFacet(DefaultedFacet.class);
+ }
+
+ // ////////////////////////////////////////////////////////////////////
+ // Injected
+ // ////////////////////////////////////////////////////////////////////
+
+ public AdapterManager getAdapterManager() {
+ return adapterManager;
+ }
+
+ @Override
+ public void setAdapterManager(final AdapterManager adapterMap) {
+ this.adapterManager = adapterMap;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/fromtype/PropertyDefaultFacetDerivedFromDefaultedFacet.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/fromtype/PropertyDefaultFacetDerivedFromDefaultedFacet.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/fromtype/PropertyDefaultFacetDerivedFromDefaultedFacet.java
new file mode 100644
index 0000000..976a58a
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/fromtype/PropertyDefaultFacetDerivedFromDefaultedFacet.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.isis.core.progmodel.facets.properties.defaults.fromtype;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.facetapi.FacetAbstract;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.properties.defaults.PropertyDefaultFacet;
+import org.apache.isis.core.progmodel.facets.object.defaults.DefaultedFacet;
+
+public class PropertyDefaultFacetDerivedFromDefaultedFacet extends FacetAbstract implements PropertyDefaultFacet {
+
+ private final DefaultedFacet typeFacet;
+ private final AdapterManager adapterManager;
+
+ public PropertyDefaultFacetDerivedFromDefaultedFacet(final DefaultedFacet typeFacet, final FacetHolder holder, final AdapterManager adapterManager) {
+ super(PropertyDefaultFacet.class, holder, Derivation.NOT_DERIVED);
+ this.typeFacet = typeFacet;
+ this.adapterManager = adapterManager;
+ }
+
+ @Override
+ public ObjectAdapter getDefault(final ObjectAdapter inObject) {
+ if (getIdentified() == null) {
+ return null;
+ }
+ final Object typeFacetDefault = typeFacet.getDefault();
+ if (typeFacetDefault == null) {
+ return null;
+ }
+ return getAdapterManager().adapterFor(typeFacetDefault);
+ }
+
+ // /////////////////////////////////////////////////////
+ // Dependencies (from constructor)
+ // /////////////////////////////////////////////////////
+
+ public AdapterManager getAdapterManager() {
+ return adapterManager;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/method/PropertyDefaultFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/method/PropertyDefaultFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/method/PropertyDefaultFacetFactory.java
new file mode 100644
index 0000000..146a21e
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/method/PropertyDefaultFacetFactory.java
@@ -0,0 +1,81 @@
+/*
+ * 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.isis.core.progmodel.facets.properties.defaults.method;
+
+import java.lang.reflect.Method;
+
+import org.apache.isis.core.commons.lang.NameUtils;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManagerAware;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.methodutils.MethodScope;
+import org.apache.isis.core.progmodel.facets.MethodFinderUtils;
+import org.apache.isis.core.progmodel.facets.MethodPrefixBasedFacetFactoryAbstract;
+import org.apache.isis.core.progmodel.facets.MethodPrefixConstants;
+
+public class PropertyDefaultFacetFactory extends MethodPrefixBasedFacetFactoryAbstract implements AdapterManagerAware {
+
+ private static final String[] PREFIXES = { MethodPrefixConstants.DEFAULT_PREFIX };
+
+ private AdapterManager adapterManager;
+
+ public PropertyDefaultFacetFactory() {
+ super(FeatureType.PROPERTIES_ONLY, OrphanValidation.VALIDATE, PREFIXES);
+ }
+
+ @Override
+ public void process(final ProcessMethodContext processMethodContext) {
+
+ attachPropertyDefaultFacetIfDefaultMethodIsFound(processMethodContext);
+ }
+
+ private void attachPropertyDefaultFacetIfDefaultMethodIsFound(final ProcessMethodContext processMethodContext) {
+
+ final Method getMethod = processMethodContext.getMethod();
+ final String capitalizedName = NameUtils.javaBaseName(getMethod.getName());
+
+ final Class<?> cls = processMethodContext.getCls();
+ final Class<?> returnType = getMethod.getReturnType();
+ final Method method = MethodFinderUtils.findMethod(cls, MethodScope.OBJECT, MethodPrefixConstants.DEFAULT_PREFIX + capitalizedName, returnType, NO_PARAMETERS_TYPES);
+ if (method == null) {
+ return;
+ }
+ processMethodContext.removeMethod(method);
+
+ final FacetHolder property = processMethodContext.getFacetHolder();
+ FacetUtil.addFacet(new PropertyDefaultFacetViaMethod(method, property, getSpecificationLoader(), getAdapterManager()));
+ }
+
+ // ///////////////////////////////////////////////////////
+ // Dependencies (injected)
+ // ///////////////////////////////////////////////////////
+
+ @Override
+ public void setAdapterManager(final AdapterManager adapterManager) {
+ this.adapterManager = adapterManager;
+ }
+
+ protected AdapterManager getAdapterManager() {
+ return adapterManager;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/method/PropertyDefaultFacetViaMethod.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/method/PropertyDefaultFacetViaMethod.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/method/PropertyDefaultFacetViaMethod.java
new file mode 100644
index 0000000..b5a1610
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/defaults/method/PropertyDefaultFacetViaMethod.java
@@ -0,0 +1,103 @@
+/*
+ * 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.isis.core.progmodel.facets.properties.defaults.method;
+
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.isis.core.commons.exceptions.UnknownTypeException;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.util.AdapterInvokeUtils;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.ImperativeFacet;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.SpecificationLoader;
+import org.apache.isis.core.progmodel.facets.properties.defaults.PropertyDefaultFacetAbstract;
+
+public class PropertyDefaultFacetViaMethod extends PropertyDefaultFacetAbstract implements ImperativeFacet {
+
+ private final Method method;
+ private final SpecificationLoader specificationLookup;
+ private final AdapterManager adapterManager;
+
+ public PropertyDefaultFacetViaMethod(final Method method, final FacetHolder holder, final SpecificationLoader specificationLookup, final AdapterManager adapterManager) {
+ super(holder);
+ this.method = method;
+ this.specificationLookup = specificationLookup;
+ this.adapterManager = adapterManager;
+ }
+
+ /**
+ * Returns a singleton list of the {@link Method} provided in the
+ * constructor.
+ */
+ @Override
+ public List<Method> getMethods() {
+ return Collections.singletonList(method);
+ }
+
+ @Override
+ public boolean impliesResolve() {
+ return true;
+ }
+
+ @Override
+ public boolean impliesObjectChanged() {
+ return false;
+ }
+
+ @Override
+ public ObjectAdapter getDefault(final ObjectAdapter owningAdapter) {
+ final Object result = AdapterInvokeUtils.invoke(method, owningAdapter);
+ if (result == null) {
+ return null;
+ }
+ return createAdapter(method.getReturnType(), result);
+ }
+
+ private ObjectAdapter createAdapter(final Class<?> type, final Object object) {
+ final ObjectSpecification specification = getSpecificationLookup().loadSpecification(type);
+ if (specification.isNotCollection()) {
+ return getAdapterManager().adapterFor(object);
+ } else {
+ throw new UnknownTypeException("not an object, is this a collection?");
+ }
+ }
+
+ @Override
+ protected String toStringValues() {
+ return "method=" + method;
+ }
+
+ // //////////////////////////////////////////////////////////////////
+ // Dependencies (from constructor)
+ // //////////////////////////////////////////////////////////////////
+
+ private SpecificationLoader getSpecificationLookup() {
+ return specificationLookup;
+ }
+
+ protected AdapterManager getAdapterManager() {
+ return adapterManager;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/derived/inferred/NotPersistableFacetInferred.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/derived/inferred/NotPersistableFacetInferred.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/derived/inferred/NotPersistableFacetInferred.java
new file mode 100644
index 0000000..8e8c0aa
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/derived/inferred/NotPersistableFacetInferred.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.isis.core.progmodel.facets.properties.derived.inferred;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.notpersisted.NotPersistedFacetAbstract;
+
+public class NotPersistableFacetInferred extends NotPersistedFacetAbstract {
+
+ public NotPersistableFacetInferred(final FacetHolder holder) {
+ super(holder);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/disabled/fromimmutable/DisabledFacetForPropertyDerivedFromImmutable.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/disabled/fromimmutable/DisabledFacetForPropertyDerivedFromImmutable.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/disabled/fromimmutable/DisabledFacetForPropertyDerivedFromImmutable.java
new file mode 100644
index 0000000..0f136fb
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/disabled/fromimmutable/DisabledFacetForPropertyDerivedFromImmutable.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.isis.core.progmodel.facets.properties.disabled.fromimmutable;
+
+import org.apache.isis.applib.annotation.Where;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.object.immutable.ImmutableFacet;
+import org.apache.isis.core.progmodel.facets.members.disabled.DisabledFacetAbstract;
+
+public class DisabledFacetForPropertyDerivedFromImmutable extends DisabledFacetAbstract {
+
+ public DisabledFacetForPropertyDerivedFromImmutable(final ImmutableFacet immutableFacet, final FacetHolder holder) {
+ super(immutableFacet.when(), Where.ANYWHERE, holder);
+ }
+
+ @Override
+ public String disabledReason(final ObjectAdapter target) {
+ return when().appliesTo(target) ? "Immutable" : null;
+ }
+
+}