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 2014/07/11 12:56:39 UTC
[27/61] [partial] ISIS-831: digression: moving progmodel/facets into
metamodel/facets
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/mandatory/MandatoryFacetAbstract.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/mandatory/MandatoryFacetAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/mandatory/MandatoryFacetAbstract.java
new file mode 100644
index 0000000..ee2ccea
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/mandatory/MandatoryFacetAbstract.java
@@ -0,0 +1,97 @@
+/*
+ * 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.metamodel.facets.propparam.mandatory;
+
+import org.apache.isis.applib.events.ValidityEvent;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.MarkerFacetAbstract;
+import org.apache.isis.core.metamodel.facets.all.named.NamedFacet;
+import org.apache.isis.core.metamodel.interactions.ActionArgumentContext;
+import org.apache.isis.core.metamodel.interactions.PropertyModifyContext;
+import org.apache.isis.core.metamodel.interactions.ProposedHolder;
+import org.apache.isis.core.metamodel.interactions.ValidityContext;
+
+public abstract class MandatoryFacetAbstract extends MarkerFacetAbstract implements MandatoryFacet {
+
+ public static Class<? extends Facet> type() {
+ return MandatoryFacet.class;
+ }
+
+ public enum Semantics {
+ REQUIRED,
+ OPTIONAL;
+
+ public static Semantics of(boolean required) {
+ return required ? REQUIRED: OPTIONAL;
+ }
+ }
+
+ private Semantics semantics;
+
+ public MandatoryFacetAbstract(final FacetHolder holder, final Semantics semantics) {
+ super(type(), holder);
+ this.semantics = semantics;
+ }
+
+ /**
+ * If not specified or, if a string, then zero length.
+ */
+ @Override
+ public final boolean isRequiredButNull(final ObjectAdapter adapter) {
+ if(!isInvertedSemantics()) {
+ final Object object = ObjectAdapter.Util.unwrap(adapter);
+ if (object == null) {
+ return true;
+ }
+ // special case string handling.
+ final String str = ObjectAdapter.Util.unwrapAsString(adapter);
+ return str != null && str.length() == 0;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean isInvertedSemantics() {
+ return this.semantics == Semantics.OPTIONAL;
+ }
+
+ @Override
+ public String invalidates(final ValidityContext<? extends ValidityEvent> context) {
+ if (!(context instanceof PropertyModifyContext) && !(context instanceof ActionArgumentContext)) {
+ return null;
+ }
+ if (!(context instanceof ProposedHolder)) {
+ // shouldn't happen, since both the above should hold a proposed
+ // value/argument
+ return null;
+ }
+ final ProposedHolder proposedHolder = (ProposedHolder) context;
+ final boolean required = isRequiredButNull(proposedHolder.getProposed());
+ if (!required) {
+ return null;
+ }
+ final NamedFacet namedFacet = getFacetHolder().getFacet(NamedFacet.class);
+ final String name = namedFacet != null? namedFacet.value(): null;
+ return name != null? "'" + name + "' is mandatory":"Mandatory";
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/mandatory/MandatoryFacetDefault.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/mandatory/MandatoryFacetDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/mandatory/MandatoryFacetDefault.java
new file mode 100644
index 0000000..5b041f3
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/mandatory/MandatoryFacetDefault.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.isis.core.metamodel.facets.propparam.mandatory;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+
+/**
+ * Whether a property or a parameter is mandatory (not optional).
+ *
+ * <p>
+ * For a mandatory property, the object cannot be saved/updated without the
+ * value being provided. For a mandatory parameter, the action cannot be invoked
+ * without the value being provided.
+ *
+ * <p>
+ * In the standard Apache Isis Programming Model, specify mandatory by
+ * <i>omitting</i> the <tt>@Optional</tt> annotation.
+ */
+public class MandatoryFacetDefault extends MandatoryFacetAbstract {
+
+ public MandatoryFacetDefault(final FacetHolder holder) {
+ super(holder, Semantics.REQUIRED);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/maxlen/MaxLengthFacet.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/maxlen/MaxLengthFacet.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/maxlen/MaxLengthFacet.java
new file mode 100644
index 0000000..4bbff60
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/maxlen/MaxLengthFacet.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.isis.core.metamodel.facets.propparam.maxlen;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facets.SingleIntValueFacet;
+import org.apache.isis.core.metamodel.interactions.ValidatingInteractionAdvisor;
+
+/**
+ * Whether the (string) property or a parameter's length must not exceed a
+ * certain length.
+ *
+ * <p>
+ * In the standard Apache Isis Programming Model, corresponds to the
+ * <tt>@MaxLength</tt> annotation.
+ */
+public interface MaxLengthFacet extends SingleIntValueFacet, ValidatingInteractionAdvisor {
+
+ /**
+ * Whether the provided string exceeds the maximum length.
+ */
+ public boolean exceeds(ObjectAdapter adapter);
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/maxlen/MaxLengthFacetAbstract.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/maxlen/MaxLengthFacetAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/maxlen/MaxLengthFacetAbstract.java
new file mode 100644
index 0000000..5b81201
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/maxlen/MaxLengthFacetAbstract.java
@@ -0,0 +1,74 @@
+/*
+ * 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.metamodel.facets.propparam.maxlen;
+
+import org.apache.isis.applib.events.ValidityEvent;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.SingleIntValueFacetAbstract;
+import org.apache.isis.core.metamodel.interactions.ProposedHolder;
+import org.apache.isis.core.metamodel.interactions.ValidityContext;
+import org.apache.isis.core.metamodel.spec.ObjectAdapterUtils;
+
+public abstract class MaxLengthFacetAbstract extends SingleIntValueFacetAbstract implements MaxLengthFacet {
+
+ public static Class<? extends Facet> type() {
+ return MaxLengthFacet.class;
+ }
+
+ public MaxLengthFacetAbstract(final int value, final FacetHolder holder) {
+ super(type(), holder, value);
+ }
+
+ /**
+ * Whether the provided argument exceeds the {@link #value() maximum length}
+ * .
+ */
+ @Override
+ public boolean exceeds(final ObjectAdapter adapter) {
+ final String str = ObjectAdapterUtils.unwrapObjectAsString(adapter);
+ if (str == null) {
+ return false;
+ }
+ final int maxLength = value();
+ return maxLength != 0 && str.length() > maxLength;
+ }
+
+ @Override
+ public String invalidates(final ValidityContext<? extends ValidityEvent> context) {
+ if (!(context instanceof ProposedHolder)) {
+ return null;
+ }
+ final ProposedHolder proposedHolder = (ProposedHolder) context;
+ final ObjectAdapter proposedArgument = proposedHolder.getProposed();
+ if (!exceeds(proposedArgument)) {
+ return null;
+ }
+ return "The value proposed exceeds the maximum length of " + value();
+ }
+
+ @Override
+ protected String toStringValues() {
+ final int val = value();
+ return val == 0 ? "unlimited" : String.valueOf(val);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/multiline/MultiLineFacet.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/multiline/MultiLineFacet.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/multiline/MultiLineFacet.java
new file mode 100644
index 0000000..b0fb745
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/multiline/MultiLineFacet.java
@@ -0,0 +1,50 @@
+/*
+ * 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.metamodel.facets.propparam.multiline;
+
+import org.apache.isis.core.metamodel.facets.MultipleValueFacet;
+
+/**
+ * Whether the (string) property or parameter should be rendered over multiple
+ * lines.
+ *
+ * <p>
+ * In the standard Apache Isis Programming Model, corresponds to the
+ * <tt>@MultiLine</tt> annotation.
+ */
+public interface MultiLineFacet extends MultipleValueFacet {
+
+ /**
+ * How many lines to use.
+ */
+ public int numberOfLines();
+
+ /**
+ * Whether carriage returns should be used to split over multiple lines or
+ * not.
+ *
+ * <p>
+ * If set to <tt>true</tt>, then user must use carriage returns to split. If
+ * set to <tt>false</tt>, then the viewer should automatically wrap when
+ * spills over the length of one line.
+ */
+ public boolean preventWrapping();
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/multiline/MultiLineFacetAbstract.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/multiline/MultiLineFacetAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/multiline/MultiLineFacetAbstract.java
new file mode 100644
index 0000000..e3371a6
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/multiline/MultiLineFacetAbstract.java
@@ -0,0 +1,56 @@
+/*
+ * 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.metamodel.facets.propparam.multiline;
+
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.MultipleValueFacetAbstract;
+
+public abstract class MultiLineFacetAbstract extends MultipleValueFacetAbstract implements MultiLineFacet {
+
+ public static Class<? extends Facet> type() {
+ return MultiLineFacet.class;
+ }
+
+ private final int numberOfLines;
+ private final boolean preventWrapping;
+
+ public MultiLineFacetAbstract(final int numberOfLines, final boolean preventWrapping, final FacetHolder holder) {
+ super(type(), holder);
+ this.numberOfLines = numberOfLines;
+ this.preventWrapping = preventWrapping;
+ }
+
+ @Override
+ public int numberOfLines() {
+ return numberOfLines;
+ }
+
+ @Override
+ public boolean preventWrapping() {
+ return preventWrapping;
+ }
+
+ @Override
+ protected String toStringValues() {
+ return "lines=" + numberOfLines + "," + (preventWrapping ? "prevent-wrapping" : "allow-wrapping");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/renderedadjusted/RenderedAdjustedFacet.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/renderedadjusted/RenderedAdjustedFacet.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/renderedadjusted/RenderedAdjustedFacet.java
new file mode 100644
index 0000000..ce4e24a
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/renderedadjusted/RenderedAdjustedFacet.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.metamodel.facets.propparam.renderedadjusted;
+
+import org.apache.isis.core.metamodel.facets.SingleIntValueFacet;
+
+/**
+ * The amount to adjust a date by when rendered.
+ *
+ * <p>
+ * Intended to be used by the viewer as a rendering hint.
+ *
+ * <p>
+ * In the standard Apache Isis Programming Model, corresponds to the
+ * <tt>@RenderedAdjusted</tt> annotation.
+ */
+public interface RenderedAdjustedFacet extends SingleIntValueFacet {
+
+ @Override
+ public int value();
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/renderedadjusted/RenderedAdjustedFacetAbstract.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/renderedadjusted/RenderedAdjustedFacetAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/renderedadjusted/RenderedAdjustedFacetAbstract.java
new file mode 100644
index 0000000..a5d6b18
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/propparam/renderedadjusted/RenderedAdjustedFacetAbstract.java
@@ -0,0 +1,45 @@
+/*
+ * 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.metamodel.facets.propparam.renderedadjusted;
+
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetAbstract;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+
+public abstract class RenderedAdjustedFacetAbstract extends FacetAbstract implements RenderedAdjustedFacet {
+
+ public static Class<? extends Facet> type() {
+ return RenderedAdjustedFacet.class;
+ }
+
+ public RenderedAdjustedFacetAbstract(final FacetHolder holder, final boolean derived) {
+ super(type(), holder, Derivation.NOT_DERIVED);
+ }
+
+ @Override
+ public abstract int value();
+
+ @Override
+ protected String toStringValues() {
+ final int val = value();
+ return val == -1 ? "default" : String.valueOf(val);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/renderedadjusted/RenderedAdjustedFacet.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/renderedadjusted/RenderedAdjustedFacet.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/renderedadjusted/RenderedAdjustedFacet.java
deleted file mode 100644
index 6722482..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/renderedadjusted/RenderedAdjustedFacet.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.metamodel.facets.renderedadjusted;
-
-import org.apache.isis.core.metamodel.facets.SingleIntValueFacet;
-
-/**
- * The amount to adjust a date by when rendered.
- *
- * <p>
- * Intended to be used by the viewer as a rendering hint.
- *
- * <p>
- * In the standard Apache Isis Programming Model, corresponds to the
- * <tt>@RenderedAdjusted</tt> annotation.
- */
-public interface RenderedAdjustedFacet extends SingleIntValueFacet {
-
- @Override
- public int value();
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/renderedadjusted/RenderedAdjustedFacetAbstract.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/renderedadjusted/RenderedAdjustedFacetAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/renderedadjusted/RenderedAdjustedFacetAbstract.java
deleted file mode 100644
index 6079456..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/renderedadjusted/RenderedAdjustedFacetAbstract.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.metamodel.facets.renderedadjusted;
-
-import org.apache.isis.core.metamodel.facetapi.Facet;
-import org.apache.isis.core.metamodel.facetapi.FacetAbstract;
-import org.apache.isis.core.metamodel.facetapi.FacetHolder;
-
-public abstract class RenderedAdjustedFacetAbstract extends FacetAbstract implements RenderedAdjustedFacet {
-
- public static Class<? extends Facet> type() {
- return RenderedAdjustedFacet.class;
- }
-
- public RenderedAdjustedFacetAbstract(final FacetHolder holder, final boolean derived) {
- super(type(), holder, Derivation.NOT_DERIVED);
- }
-
- @Override
- public abstract int value();
-
- @Override
- protected String toStringValues() {
- final int val = value();
- return val == -1 ? "default" : String.valueOf(val);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/ElementSpecificationProviderFromTypeOfFacet.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/ElementSpecificationProviderFromTypeOfFacet.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/ElementSpecificationProviderFromTypeOfFacet.java
deleted file mode 100644
index 68376d9..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/ElementSpecificationProviderFromTypeOfFacet.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * 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.metamodel.facets.typeof;
-
-import org.apache.isis.core.metamodel.spec.ElementSpecificationProvider;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-
-public class ElementSpecificationProviderFromTypeOfFacet implements ElementSpecificationProvider {
-
- public static ElementSpecificationProvider createFrom(final TypeOfFacet typeOfFacet) {
- if (typeOfFacet == null) {
- return null;
- }
- final ObjectSpecification spec = typeOfFacet.valueSpec();
- return new ElementSpecificationProviderFromTypeOfFacet(spec);
- }
-
- private final ObjectSpecification spec;
-
- public ElementSpecificationProviderFromTypeOfFacet(final ObjectSpecification spec) {
- this.spec = spec;
- }
-
- @Override
- public ObjectSpecification getElementType() {
- return spec;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/TypeOfFacet.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/TypeOfFacet.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/TypeOfFacet.java
deleted file mode 100644
index 1707be0..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/TypeOfFacet.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.metamodel.facets.typeof;
-
-import org.apache.isis.core.metamodel.facets.SingleClassValueFacet;
-
-/**
- * The type of the collection or the action.
- *
- * <p>
- * In the standard Apache Isis Programming Model, corresponds to annotating the
- * collection's accessor or the action's invoker method with the
- * <tt>@TypeOf</tt> annotation.
- */
-public interface TypeOfFacet extends SingleClassValueFacet {
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/TypeOfFacetAbstract.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/TypeOfFacetAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/TypeOfFacetAbstract.java
deleted file mode 100644
index 3c26ca4..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/TypeOfFacetAbstract.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.metamodel.facets.typeof;
-
-import org.apache.isis.core.metamodel.facetapi.Facet;
-import org.apache.isis.core.metamodel.facetapi.FacetHolder;
-import org.apache.isis.core.metamodel.facets.SingleClassValueFacetAbstract;
-import org.apache.isis.core.metamodel.spec.SpecificationLoader;
-
-public abstract class TypeOfFacetAbstract extends SingleClassValueFacetAbstract implements TypeOfFacet {
-
- public static Class<? extends Facet> type() {
- return TypeOfFacet.class;
- }
-
- public TypeOfFacetAbstract(final Class<?> type, final FacetHolder holder, final SpecificationLoader specificationLookup) {
- super(type(), holder, type, specificationLookup);
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + " [type=" + value() + "]";
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/TypeOfFacetDefaultToObject.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/TypeOfFacetDefaultToObject.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/TypeOfFacetDefaultToObject.java
deleted file mode 100644
index 6d7813a..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/TypeOfFacetDefaultToObject.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.metamodel.facets.typeof;
-
-import org.apache.isis.core.metamodel.facetapi.FacetHolder;
-import org.apache.isis.core.metamodel.spec.SpecificationLoader;
-
-public class TypeOfFacetDefaultToObject extends TypeOfFacetAbstract {
-
- public TypeOfFacetDefaultToObject(final FacetHolder holder, final SpecificationLoader specificationLookup) {
- super(Object.class, holder, specificationLookup);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/TypeOfFacetInferredFromArray.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/TypeOfFacetInferredFromArray.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/TypeOfFacetInferredFromArray.java
deleted file mode 100644
index 5d396f6..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/TypeOfFacetInferredFromArray.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.metamodel.facets.typeof;
-
-import org.apache.isis.core.metamodel.facetapi.FacetHolder;
-import org.apache.isis.core.metamodel.spec.SpecificationLoader;
-
-public class TypeOfFacetInferredFromArray extends TypeOfFacetAbstract {
-
- public TypeOfFacetInferredFromArray(final Class<?> type, final FacetHolder holder, final SpecificationLoader specificationLookup) {
- super(type, holder, specificationLookup);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/TypeOfFacetInferredFromGenerics.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/TypeOfFacetInferredFromGenerics.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/TypeOfFacetInferredFromGenerics.java
deleted file mode 100644
index b6fb2b0..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typeof/TypeOfFacetInferredFromGenerics.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.metamodel.facets.typeof;
-
-import org.apache.isis.core.metamodel.facetapi.FacetHolder;
-import org.apache.isis.core.metamodel.spec.SpecificationLoader;
-
-public class TypeOfFacetInferredFromGenerics extends TypeOfFacetAbstract {
-
- public TypeOfFacetInferredFromGenerics(final Class<?> type, final FacetHolder holder, final SpecificationLoader specificationLookup) {
- super(type, holder, specificationLookup);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typicallen/TypicalLengthFacet.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typicallen/TypicalLengthFacet.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typicallen/TypicalLengthFacet.java
deleted file mode 100644
index 428834d..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typicallen/TypicalLengthFacet.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.metamodel.facets.typicallen;
-
-import org.apache.isis.core.metamodel.facets.SingleIntValueFacet;
-
-/**
- * The typical length of a property or a parameter.
- *
- * <p>
- * Intended to be used by the viewer as a rendering hint to size the UI field to
- * an appropriate size.
- *
- * <p>
- * In the standard Apache Isis Programming Model, corresponds to the
- * <tt>@TypicalLength</tt> annotation.
- */
-public interface TypicalLengthFacet extends SingleIntValueFacet {
-
- @Override
- public int value();
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typicallen/TypicalLengthFacetAbstract.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typicallen/TypicalLengthFacetAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typicallen/TypicalLengthFacetAbstract.java
deleted file mode 100644
index 9312c97..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/typicallen/TypicalLengthFacetAbstract.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.metamodel.facets.typicallen;
-
-import org.apache.isis.core.metamodel.facetapi.Facet;
-import org.apache.isis.core.metamodel.facetapi.FacetAbstract;
-import org.apache.isis.core.metamodel.facetapi.FacetHolder;
-
-public abstract class TypicalLengthFacetAbstract extends FacetAbstract implements TypicalLengthFacet {
-
- public static Class<? extends Facet> type() {
- return TypicalLengthFacet.class;
- }
-
- public TypicalLengthFacetAbstract(final FacetHolder holder, final boolean derived) {
- super(type(), holder, Derivation.NOT_DERIVED);
- }
-
- @Override
- public abstract int value();
-
- @Override
- protected String toStringValues() {
- final int val = value();
- return val == 0 ? "default" : String.valueOf(val);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/DateAndTimeValueSemanticsProviderAbstract.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/DateAndTimeValueSemanticsProviderAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/DateAndTimeValueSemanticsProviderAbstract.java
new file mode 100644
index 0000000..2d5025d
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/DateAndTimeValueSemanticsProviderAbstract.java
@@ -0,0 +1,111 @@
+/*
+ * 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.metamodel.facets.value;
+
+import java.text.DateFormat;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.TimeZone;
+
+import com.google.common.collect.Maps;
+
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.core.commons.config.ConfigurationConstants;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.object.value.vsp.ValueSemanticsProviderContext;
+
+public abstract class DateAndTimeValueSemanticsProviderAbstract<T> extends ValueSemanticsProviderAbstractTemporal<T> {
+
+ private static Map<String, DateFormat> formats = Maps.newHashMap();
+
+ static {
+ formats.put(ISO_ENCODING_FORMAT, createDateEncodingFormat("yyyyMMdd'T'HHmmssSSS"));
+ formats.put("iso", createDateFormat("yyyy-MM-dd HH:mm"));
+ formats.put("medium", DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT));
+ }
+
+ private static final Object DEFAULT_VALUE = null; // no default
+ private static final int TYPICAL_LENGTH = 18;
+
+ @SuppressWarnings("unchecked")
+ public DateAndTimeValueSemanticsProviderAbstract(final FacetHolder holder, final Class<T> adaptedClass, final Immutability immutability, final EqualByContent equalByContent, final IsisConfiguration configuration, final ValueSemanticsProviderContext context) {
+ super("datetime", holder, adaptedClass, TYPICAL_LENGTH, immutability, equalByContent, (T) DEFAULT_VALUE, configuration, context);
+
+ final String formatRequired = configuration.getString(ConfigurationConstants.ROOT + "value.format.datetime");
+ if (formatRequired == null) {
+ format = formats().get(defaultFormat());
+ } else {
+ setMask(formatRequired);
+ }
+ }
+
+
+ // //////////////////////////////////////////////////////////////////
+ // temporal-specific stuff
+ // //////////////////////////////////////////////////////////////////
+
+ @Override
+ protected String defaultFormat() {
+ return "medium";
+ }
+
+ @Override
+ protected Map<String, DateFormat> formats() {
+ return formats;
+ }
+
+ @Override
+ protected DateFormat format(final Localization localization) {
+ final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, localization.getLocale());
+ dateFormat.setTimeZone(localization.getTimeZone());
+ return dateFormat;
+ }
+
+ @Override
+ public String toString() {
+ return "JavaDateTimeValueSemanticsProvider: " + format;
+ }
+
+ protected List<DateFormat> formatsToTry(Localization localization) {
+ List<DateFormat> formats = new ArrayList<DateFormat>();
+
+ Locale locale = localization == null ? Locale.getDefault() : localization.getLocale();
+ formats.add(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale));
+ formats.add(createDateFormat("yyyy-MM-dd HH:mm:ss.SSS"));
+ formats.add(createDateFormat("yyyyMMdd'T'HHmmssSSS"));
+ formats.add(DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, locale));
+ formats.add(createDateFormat("yyyy-MM-dd HH:mm:ss"));
+ formats.add(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale));
+ formats.add(createDateFormat("yyyyMMdd'T'HHmmss"));
+ formats.add(createDateFormat("yyyy-MM-dd HH:mm"));
+ formats.add(createDateFormat("yyyyMMdd'T'HHmm"));
+ formats.add(createDateFormat("dd-MMM-yyyy HH:mm"));
+
+ for (DateFormat format : formats) {
+ format.setTimeZone(localization == null ? TimeZone.getDefault() : localization.getTimeZone());
+ }
+
+ return formats;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/JodaFunctions.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/JodaFunctions.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/JodaFunctions.java
new file mode 100644
index 0000000..da99431
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/JodaFunctions.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.metamodel.facets.value;
+
+import java.util.List;
+import java.util.Locale;
+import java.util.StringTokenizer;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
+
+import org.joda.time.LocalDate;
+import org.joda.time.format.DateTimeFormatter;
+
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.core.metamodel.facets.object.parseable.TextEntryParseException;
+
+public final class JodaFunctions {
+
+ private JodaFunctions(){}
+
+ public static Function<DateTimeFormatter, DateTimeFormatter> withLocale(final Localization localization) {
+ return new Function<DateTimeFormatter, DateTimeFormatter>() {
+ @Override
+ public DateTimeFormatter apply(DateTimeFormatter input) {
+ if (localization == null) {
+ return input;
+ }
+ final Locale locale = localization.getLocale();
+ if (locale == null) {
+ return input;
+ }
+ return input.withLocale(locale);
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/ValueSemanticsProviderAbstractTemporal.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/ValueSemanticsProviderAbstractTemporal.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/ValueSemanticsProviderAbstractTemporal.java
new file mode 100644
index 0000000..715040f
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/ValueSemanticsProviderAbstractTemporal.java
@@ -0,0 +1,370 @@
+/*
+ * 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.metamodel.facets.value;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.TimeZone;
+
+import com.google.common.collect.Maps;
+
+import org.apache.isis.applib.adapters.EncodingException;
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.core.commons.config.ConfigurationConstants;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.object.parseable.TextEntryParseException;
+import org.apache.isis.core.metamodel.facets.object.value.vsp.ValueSemanticsProviderAndFacetAbstract;
+import org.apache.isis.core.metamodel.facets.object.value.vsp.ValueSemanticsProviderContext;
+import org.apache.isis.core.metamodel.facets.value.date.DateValueFacet;
+
+public abstract class ValueSemanticsProviderAbstractTemporal<T> extends ValueSemanticsProviderAndFacetAbstract<T> implements DateValueFacet {
+
+ /**
+ * Introduced to allow BDD tests to provide a different format string
+ * "mid-flight".
+ */
+ public static void setFormat(final String propertyType, final String formatStr) {
+ FORMATS.get().put(propertyType, formatStr);
+ }
+
+ private final static ThreadLocal<Map<String, String>> FORMATS = new ThreadLocal<Map<String, String>>() {
+ @Override
+ protected java.util.Map<String, String> initialValue() {
+ return Maps.newHashMap();
+ }
+ };
+
+ protected static final String ISO_ENCODING_FORMAT = "iso_encoding";
+ protected static final TimeZone UTC_TIME_ZONE;
+
+ public final static String FORMAT_KEY_PREFIX = ConfigurationConstants.ROOT + "value.format.";
+
+ static {
+ TimeZone timeZone = TimeZone.getTimeZone("Etc/UTC");
+ if (timeZone == null) {
+ timeZone = TimeZone.getTimeZone("UTC");
+ }
+ UTC_TIME_ZONE = timeZone;
+ }
+
+ /**
+ * The facet type, used if not specified explicitly in the constructor.
+ */
+ public static Class<? extends Facet> type() {
+ return DateValueFacet.class;
+ }
+
+ protected static DateFormat createDateFormat(final String mask) {
+ return new SimpleDateFormat(mask);
+ }
+
+ /**
+ * for encoding always use UTC.
+ */
+ protected static DateFormat createDateEncodingFormat(final String mask) {
+ DateFormat encodingFormat = createDateFormat(mask);
+ encodingFormat.setTimeZone(UTC_TIME_ZONE);
+ return encodingFormat;
+ }
+
+ private final DateFormat encodingFormat;
+ protected DateFormat format;
+ private String configuredFormat;
+ private String propertyType;
+
+ /**
+ * Uses {@link #type()} as the facet type.
+ */
+ public ValueSemanticsProviderAbstractTemporal(final String propertyName, final FacetHolder holder, final Class<T> adaptedClass, final int typicalLength, final Immutability immutability, final EqualByContent equalByContent, final T defaultValue, final IsisConfiguration configuration,
+ final ValueSemanticsProviderContext context) {
+ this(propertyName, type(), holder, adaptedClass, typicalLength, immutability, equalByContent, defaultValue, configuration, context);
+ }
+
+ /**
+ * Allows the specific facet subclass to be specified (rather than use
+ * {@link #type()}.
+ */
+ public ValueSemanticsProviderAbstractTemporal(final String propertyType, final Class<? extends Facet> facetType, final FacetHolder holder, final Class<T> adaptedClass, final int typicalLength, final Immutability immutability, final EqualByContent equalByContent, final T defaultValue,
+ final IsisConfiguration configuration, final ValueSemanticsProviderContext context) {
+ super(facetType, holder, adaptedClass, typicalLength, immutability, equalByContent, defaultValue, configuration, context);
+ configureFormats();
+
+ this.propertyType = propertyType;
+ configuredFormat = getConfiguration().getString(FORMAT_KEY_PREFIX + propertyType, defaultFormat()).toLowerCase().trim();
+ buildFormat(configuredFormat);
+
+ encodingFormat = formats().get(ISO_ENCODING_FORMAT);
+ }
+
+ protected void configureFormats() {
+ final Map<String, DateFormat> formats = formats();
+ for (final Map.Entry<String, DateFormat> mapEntry : formats.entrySet()) {
+ final DateFormat format = mapEntry.getValue();
+ format.setLenient(false);
+ if (ignoreTimeZone()) {
+ format.setTimeZone(UTC_TIME_ZONE);
+ }
+ }
+ }
+
+ protected void buildDefaultFormatIfRequired() {
+ final Map<String, String> map = FORMATS.get();
+ final String currentlyConfiguredFormat = map.get(propertyType);
+ if (currentlyConfiguredFormat == null || configuredFormat.equals(currentlyConfiguredFormat)) {
+ return;
+ }
+
+ // (re)create format
+ configuredFormat = currentlyConfiguredFormat;
+ buildFormat(configuredFormat);
+ }
+
+ protected void buildFormat(final String configuredFormat) {
+ final Map<String, DateFormat> formats = formats();
+ format = formats.get(configuredFormat);
+ if (format == null) {
+ setMask(configuredFormat);
+ }
+ }
+
+ // //////////////////////////////////////////////////////////////////
+ // Parsing
+ // //////////////////////////////////////////////////////////////////
+
+ @Override
+ protected T doParse(final Object context, final String entry, final Localization localization) {
+ buildDefaultFormatIfRequired();
+ final String dateString = entry.trim();
+ final String str = dateString.toLowerCase();
+ if (str.equals("today") || str.equals("now")) {
+ return now();
+ } else if (dateString.startsWith("+")) {
+ return relativeDate(context == null ? now() : context, dateString, true);
+ } else if (dateString.startsWith("-")) {
+ return relativeDate(context == null ? now() : context, dateString, false);
+ } else {
+ return parseDate(dateString, context == null ? now() : context, localization);
+ }
+ }
+
+ private T parseDate(final String dateString, final Object original, final Localization localization) {
+ List<DateFormat> elements = formatsToTry(localization);
+ return setDate(parseDate(dateString, elements.iterator()));
+ }
+
+ protected abstract List<DateFormat> formatsToTry(Localization localization);
+
+ private Date parseDate(final String dateString, final Iterator<DateFormat> elements) {
+ final DateFormat format = elements.next();
+ try {
+ return format.parse(dateString);
+ } catch (final ParseException e) {
+ if (elements.hasNext()) {
+ return parseDate(dateString, elements);
+ } else {
+ throw new TextEntryParseException("Not recognised as a date: " + dateString);
+ }
+ }
+ }
+
+ private T relativeDate(final Object object, final String str, final boolean add) {
+ if (str.equals("")) {
+ return now();
+ }
+
+ try {
+ T date = (T) object;
+ final StringTokenizer st = new StringTokenizer(str.substring(1), " ");
+ while (st.hasMoreTokens()) {
+ final String token = st.nextToken();
+ date = relativeDate2(date, token, add);
+ }
+ return date;
+ } catch (final Exception e) {
+ return now();
+ }
+ }
+
+ private T relativeDate2(final T original, String str, final boolean add) {
+ int hours = 0;
+ int minutes = 0;
+ int days = 0;
+ int months = 0;
+ int years = 0;
+
+ if (str.endsWith("H")) {
+ str = str.substring(0, str.length() - 1);
+ hours = Integer.valueOf(str).intValue();
+ } else if (str.endsWith("M")) {
+ str = str.substring(0, str.length() - 1);
+ minutes = Integer.valueOf(str).intValue();
+ } else if (str.endsWith("w")) {
+ str = str.substring(0, str.length() - 1);
+ days = 7 * Integer.valueOf(str).intValue();
+ } else if (str.endsWith("y")) {
+ str = str.substring(0, str.length() - 1);
+ years = Integer.valueOf(str).intValue();
+ } else if (str.endsWith("m")) {
+ str = str.substring(0, str.length() - 1);
+ months = Integer.valueOf(str).intValue();
+ } else if (str.endsWith("d")) {
+ str = str.substring(0, str.length() - 1);
+ days = Integer.valueOf(str).intValue();
+ } else {
+ days = Integer.valueOf(str).intValue();
+ }
+
+ if (add) {
+ return add(original, years, months, days, hours, minutes);
+ } else {
+ return add(original, -years, -months, -days, -hours, -minutes);
+ }
+ }
+
+ // ///////////////////////////////////////////////////////////////////////////
+ // TitleProvider
+ // ///////////////////////////////////////////////////////////////////////////
+
+ @Override
+ public String titleString(final Object value, final Localization localization) {
+ if (value == null) {
+ return null;
+ }
+ final Date date = dateValue(value);
+ DateFormat f = format;
+ if (localization != null) {
+ f = format(localization);
+ }
+ return titleString(f, date);
+ }
+
+ protected DateFormat format(final Localization localization) {
+ return format;
+ }
+
+ @Override
+ public String titleStringWithMask(final Object value, final String usingMask) {
+ final Date date = dateValue(value);
+ return titleString(new SimpleDateFormat(usingMask), date);
+ }
+
+ private String titleString(final DateFormat formatter, final Date date) {
+ return date == null ? "" : formatter.format(date);
+ }
+
+ // //////////////////////////////////////////////////////////////////
+ // EncoderDecoder
+ // //////////////////////////////////////////////////////////////////
+
+ @Override
+ protected String doEncode(final Object object) {
+ final Date date = dateValue(object);
+ return encode(date);
+ }
+
+ private synchronized String encode(final Date date) {
+ return encodingFormat.format(date);
+ }
+
+ @Override
+ protected T doRestore(final String data) {
+ final Calendar cal = Calendar.getInstance();
+ cal.setTimeZone(UTC_TIME_ZONE);
+
+ // TODO allow restoring of dates where datetime expected, and datetimes where date expected - to allow for changing of field types.
+ try {
+ cal.setTime(parse(data));
+ clearFields(cal);
+ return setDate(cal.getTime());
+ } catch (final ParseException e) {
+ if (data.charAt(0) == 'T') {
+ final long millis = Long.parseLong(data.substring(1));
+ cal.setTimeInMillis(millis);
+ clearFields(cal);
+ return setDate(cal.getTime());
+ } else {
+ throw new EncodingException(e);
+ }
+ }
+ }
+
+ private synchronized Date parse(final String data) throws ParseException {
+ return encodingFormat.parse(data);
+ }
+
+ // //////////////////////////////////////////////////////////////////
+ // DateValueFacet
+ // //////////////////////////////////////////////////////////////////
+
+ @Override
+ public final Date dateValue(final ObjectAdapter object) {
+ return object == null ? null : dateValue(object.getObject());
+ }
+
+ @Override
+ public final ObjectAdapter createValue(final Date date) {
+ return getAdapterManager().adapterFor(setDate(date));
+ }
+
+
+ // //////////////////////////////////////////////////////////////////
+ // temporal-specific stuff
+ // //////////////////////////////////////////////////////////////////
+
+ protected abstract T add(T original, int years, int months, int days, int hours, int minutes);
+
+ protected void clearFields(final Calendar cal) {
+ }
+
+ protected abstract Date dateValue(Object value);
+
+ protected abstract String defaultFormat();
+
+ protected abstract Map<String, DateFormat> formats();
+
+ protected boolean ignoreTimeZone() {
+ return false;
+ }
+
+ protected abstract T now();
+
+ protected abstract T setDate(Date date);
+
+ public void setMask(final String mask) {
+ format = new SimpleDateFormat(mask);
+ format.setTimeZone(UTC_TIME_ZONE);
+ format.setLenient(false);
+ }
+
+ protected boolean isEmpty() {
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/bigdecimal/BigDecimalValueFacet.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/bigdecimal/BigDecimalValueFacet.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/bigdecimal/BigDecimalValueFacet.java
new file mode 100644
index 0000000..055bd9d
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/bigdecimal/BigDecimalValueFacet.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.metamodel.facets.value.bigdecimal;
+
+import org.apache.isis.core.metamodel.facetapi.Facet;
+
+public interface BigDecimalValueFacet extends Facet {
+
+ /**
+ * Maximum length of digits for this decimal (in other words, its precision).
+ *
+ * <p>
+ * For example:
+ * <ul>
+ * <li><tt>12345.789</tt> has a length of 8 (and a {@link #getScale() scale} of 3)</li>
+ * <li><tt>12345</tt> has a length of 5 (and {@link #getScale() scale} of 0)</li>
+ * <li><tt>12345.0</tt> has a length of 6 (and {@link #getScale() scale} of 1)</li>
+ * </ul>
+ */
+ Integer getPrecision();
+
+ /**
+ * Same as {@link #getPrecision()}.
+ *
+ * @deprecated
+ */
+ @Deprecated
+ Integer getLength();
+
+ /**
+ * The number of digits to the right of the decimal place (fractional part) for this decimal.
+ *
+ * <p>
+ * For example:
+ * <ul>
+ * <li><tt>12345.789</tt> has scale of 3 (and a {@link #getLength() length} of 8)</li>
+ * <li><tt>12345</tt> has a scale of 0 (and a {@link #getLength() length} of 5)</li>
+ * <li><tt>12345.0</tt> has a scale of 1 (and a {@link #getLength() length} of 6)</li>
+ * </ul>
+ */
+ Integer getScale();
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/bigdecimal/BigDecimalValueFacetAbstract.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/bigdecimal/BigDecimalValueFacetAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/bigdecimal/BigDecimalValueFacetAbstract.java
new file mode 100644
index 0000000..2744099
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/bigdecimal/BigDecimalValueFacetAbstract.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.metamodel.facets.value.bigdecimal;
+
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetAbstract;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+
+public abstract class BigDecimalValueFacetAbstract extends FacetAbstract implements BigDecimalValueFacet {
+
+ public BigDecimalValueFacetAbstract(Class<? extends Facet> facetType, FacetHolder holder, Derivation derivation) {
+ super(facetType, holder, derivation);
+ }
+
+ @Override
+ public abstract Integer getPrecision();
+
+ @Override
+ public final Integer getLength() {
+ return getPrecision();
+ }
+
+ @Override
+ public abstract Integer getScale();
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/bigdecimal/BigDecimalValueFacetUsingSemanticsProviderFactory.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/bigdecimal/BigDecimalValueFacetUsingSemanticsProviderFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/bigdecimal/BigDecimalValueFacetUsingSemanticsProviderFactory.java
new file mode 100644
index 0000000..acb965e
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/bigdecimal/BigDecimalValueFacetUsingSemanticsProviderFactory.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.metamodel.facets.value.bigdecimal;
+
+import java.math.BigDecimal;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.object.value.vsp.ValueFacetUsingSemanticsProviderFactory;
+
+public class BigDecimalValueFacetUsingSemanticsProviderFactory extends ValueFacetUsingSemanticsProviderFactory<BigDecimal> {
+
+ public BigDecimalValueFacetUsingSemanticsProviderFactory() {
+ super();
+ }
+
+ @Override
+ public void process(final ProcessClassContext processClassContext) {
+ final Class<?> type = processClassContext.getCls();
+ final FacetHolder holder = processClassContext.getFacetHolder();
+ if (type != BigDecimal.class) {
+ return;
+ }
+ addFacets(new BigDecimalValueSemanticsProvider(holder, getConfiguration(), getContext()));
+ return;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/bigdecimal/BigDecimalValueSemanticsProvider.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/bigdecimal/BigDecimalValueSemanticsProvider.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/bigdecimal/BigDecimalValueSemanticsProvider.java
new file mode 100644
index 0000000..ce1ae1c
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/bigdecimal/BigDecimalValueSemanticsProvider.java
@@ -0,0 +1,146 @@
+/*
+ * 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.metamodel.facets.value.bigdecimal;
+
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.Locale;
+
+import org.apache.isis.applib.adapters.EncoderDecoder;
+import org.apache.isis.applib.adapters.Parser;
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.commons.exceptions.IsisException;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.object.parseable.TextEntryParseException;
+import org.apache.isis.core.metamodel.facets.object.value.vsp.ValueSemanticsProviderAndFacetAbstract;
+import org.apache.isis.core.metamodel.facets.object.value.vsp.ValueSemanticsProviderContext;
+
+public class BigDecimalValueSemanticsProvider extends ValueSemanticsProviderAndFacetAbstract<BigDecimal> implements BigDecimalValueFacet {
+
+ private static Class<? extends Facet> type() {
+ return BigDecimalValueFacet.class;
+ }
+
+ private static final int TYPICAL_LENGTH = 10;
+ private static final BigDecimal DEFAULT_VALUE = new BigDecimal(0);
+
+ public static final int DEFAULT_LENGTH = 18;
+ public static final int DEFAULT_SCALE = 2;
+
+ private final NumberFormat format;
+
+ /**
+ * Required because implementation of {@link Parser} and
+ * {@link EncoderDecoder}.
+ */
+ public BigDecimalValueSemanticsProvider() {
+ this(null, null, null);
+ }
+
+ public BigDecimalValueSemanticsProvider(final FacetHolder holder, final IsisConfiguration configuration, final ValueSemanticsProviderContext context) {
+ super(type(), holder, BigDecimal.class, TYPICAL_LENGTH, Immutability.IMMUTABLE, EqualByContent.HONOURED, DEFAULT_VALUE, configuration, context);
+ format = determineNumberFormat("value.format.decimal");
+ }
+
+ public void setLocale(final Locale l) {
+
+ }
+
+ // //////////////////////////////////////////////////////////////////
+ // Parser
+ // //////////////////////////////////////////////////////////////////
+
+ @Deprecated
+ @Override
+ public Integer getLength() {
+ return getPrecision();
+ }
+
+ @Override
+ public Integer getPrecision() {
+ return DEFAULT_LENGTH;
+ }
+
+ @Override
+ public Integer getScale() {
+ return DEFAULT_SCALE;
+ }
+
+ // //////////////////////////////////////////////////////////////////
+ // Parser
+ // //////////////////////////////////////////////////////////////////
+
+ @Override
+ protected BigDecimal doParse(final Object context, final String entry) {
+ try {
+ return new BigDecimal(entry);
+ } catch (final NumberFormatException e) {
+ throw new TextEntryParseException("Not an decimal " + entry, e);
+ }
+ }
+
+ @Override
+ public String titleString(final Object object, final Localization localization) {
+ return titleString(format, object);
+ }
+
+ @Override
+ public String titleStringWithMask(final Object value, final String usingMask) {
+ return titleString(new DecimalFormat(usingMask), value);
+ }
+
+ // //////////////////////////////////////////////////////////////////
+ // EncoderDecoder
+ // //////////////////////////////////////////////////////////////////
+
+ @Override
+ protected String doEncode(final Object object) {
+ // for dotnet compatibility - toString pre 1.3 was equivalent to
+ // toPlainString later.
+ try {
+ final Class<?> type = object.getClass();
+ try {
+ return (String) type.getMethod("toPlainString", (Class[]) null).invoke(object, (Object[]) null);
+ } catch (final NoSuchMethodException nsm) {
+ return (String) type.getMethod("toString", (Class[]) null).invoke(object, (Object[]) null);
+ }
+ } catch (final Exception e) {
+ throw new IsisException(e);
+ }
+
+ }
+
+ @Override
+ protected BigDecimal doRestore(final String data) {
+ return new BigDecimal(data);
+ }
+
+ // /////// toString ///////
+
+ @Override
+ public String toString() {
+ return "BigDecimalValueSemanticsProvider: " + format;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/biginteger/BigIntegerValueFacet.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/biginteger/BigIntegerValueFacet.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/biginteger/BigIntegerValueFacet.java
new file mode 100644
index 0000000..a276ba8
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/biginteger/BigIntegerValueFacet.java
@@ -0,0 +1,26 @@
+/*
+ * 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.metamodel.facets.value.biginteger;
+
+import org.apache.isis.core.metamodel.facetapi.Facet;
+
+public interface BigIntegerValueFacet extends Facet {
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/biginteger/BigIntegerValueFacetUsingSemanticsProviderFactory.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/biginteger/BigIntegerValueFacetUsingSemanticsProviderFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/biginteger/BigIntegerValueFacetUsingSemanticsProviderFactory.java
new file mode 100644
index 0000000..dbfeef2
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/biginteger/BigIntegerValueFacetUsingSemanticsProviderFactory.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.isis.core.metamodel.facets.value.biginteger;
+
+import java.math.BigInteger;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.object.value.vsp.ValueFacetUsingSemanticsProviderFactory;
+
+public class BigIntegerValueFacetUsingSemanticsProviderFactory extends ValueFacetUsingSemanticsProviderFactory<BigInteger> {
+
+ public BigIntegerValueFacetUsingSemanticsProviderFactory() {
+ super();
+ }
+
+ @Override
+ public void process(final ProcessClassContext processClassContext) {
+ final Class<?> type = processClassContext.getCls();
+ final FacetHolder holder = processClassContext.getFacetHolder();
+ if (type != BigInteger.class) {
+ return;
+ }
+ addFacets(new BigIntegerValueSemanticsProvider(holder, getConfiguration(), getContext()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/7227418b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/biginteger/BigIntegerValueSemanticsProvider.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/biginteger/BigIntegerValueSemanticsProvider.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/biginteger/BigIntegerValueSemanticsProvider.java
new file mode 100644
index 0000000..c5024b7
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/biginteger/BigIntegerValueSemanticsProvider.java
@@ -0,0 +1,106 @@
+/*
+ * 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.metamodel.facets.value.biginteger;
+
+import java.math.BigInteger;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+
+import org.apache.isis.applib.adapters.EncoderDecoder;
+import org.apache.isis.applib.adapters.Parser;
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.object.parseable.TextEntryParseException;
+import org.apache.isis.core.metamodel.facets.object.value.vsp.ValueSemanticsProviderAndFacetAbstract;
+import org.apache.isis.core.metamodel.facets.object.value.vsp.ValueSemanticsProviderContext;
+
+public class BigIntegerValueSemanticsProvider extends ValueSemanticsProviderAndFacetAbstract<BigInteger> implements BigIntegerValueFacet {
+
+ private static final int TYPICAL_LENGTH = 10;
+
+ private static Class<? extends Facet> type() {
+ return BigIntegerValueFacet.class;
+ }
+
+ private static final BigInteger DEFAULT_VALUE = BigInteger.valueOf(0);
+
+ private final NumberFormat format;
+
+ /**
+ * Required because implementation of {@link Parser} and
+ * {@link EncoderDecoder}.
+ */
+ public BigIntegerValueSemanticsProvider() {
+ this(null, null, null);
+ }
+
+ public BigIntegerValueSemanticsProvider(final FacetHolder holder, final IsisConfiguration configuration, final ValueSemanticsProviderContext context) {
+
+ super(type(), holder, BigInteger.class, TYPICAL_LENGTH, Immutability.IMMUTABLE, EqualByContent.HONOURED, DEFAULT_VALUE, configuration, context);
+ format = determineNumberFormat("value.format.int");
+ }
+
+ // //////////////////////////////////////////////////////////////////
+ // Parser
+ // //////////////////////////////////////////////////////////////////
+
+ @Override
+ protected BigInteger doParse(final Object context, final String entry) {
+ try {
+ return new BigInteger(entry);
+ } catch (final NumberFormatException e) {
+ throw new TextEntryParseException("Not an integer " + entry, e);
+ }
+ }
+
+ @Override
+ public String titleString(final Object object, final Localization localization) {
+ return titleString(format, object);
+ }
+
+ @Override
+ public String titleStringWithMask(final Object value, final String usingMask) {
+ return titleString(new DecimalFormat(usingMask), value);
+ }
+
+ // //////////////////////////////////////////////////////////////////
+ // EncoderDecoder
+ // //////////////////////////////////////////////////////////////////
+
+ @Override
+ protected String doEncode(final Object object) {
+ return object.toString();
+ }
+
+ @Override
+ protected BigInteger doRestore(final String data) {
+ return new BigInteger(data);
+ }
+
+ // /////// toString ///////
+
+ @Override
+ public String toString() {
+ return "BigIntegerValueSemanticsProvider: " + format;
+ }
+
+}