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:11 UTC
[35/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/value/shortint/ShortPrimitiveValueSemanticsProvider.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortPrimitiveValueSemanticsProvider.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortPrimitiveValueSemanticsProvider.java
new file mode 100644
index 0000000..21eb32c
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortPrimitiveValueSemanticsProvider.java
@@ -0,0 +1,53 @@
+/*
+ * 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.value.shortint;
+
+import org.apache.isis.applib.adapters.EncoderDecoder;
+import org.apache.isis.applib.adapters.Parser;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+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.value.ValueSemanticsProviderContext;
+
+public class ShortPrimitiveValueSemanticsProvider extends ShortValueSemanticsProviderAbstract implements PropertyDefaultFacet {
+
+ /**
+ * Required because implementation of {@link Parser} and
+ * {@link EncoderDecoder}.
+ */
+ public ShortPrimitiveValueSemanticsProvider() {
+ this(null, null, null);
+ }
+
+ public ShortPrimitiveValueSemanticsProvider(final FacetHolder holder, final IsisConfiguration configuration, final ValueSemanticsProviderContext context) {
+ super(holder, short.class, configuration, context);
+ }
+
+ // //////////////////////////////////////////////////////////////////
+ // PropertyDefaultFacet
+ // //////////////////////////////////////////////////////////////////
+
+ @Override
+ public ObjectAdapter getDefault(final ObjectAdapter inObject) {
+ return createAdapter(short.class, Short.valueOf((short) 0));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortPrimitiveValueTypeFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortPrimitiveValueTypeFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortPrimitiveValueTypeFacetFactory.java
new file mode 100644
index 0000000..f678be3
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortPrimitiveValueTypeFacetFactory.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.value.shortint;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.progmodel.facets.object.value.ValueUsingValueSemanticsProviderFacetFactory;
+
+public class ShortPrimitiveValueTypeFacetFactory extends ValueUsingValueSemanticsProviderFacetFactory<Short> {
+
+ public ShortPrimitiveValueTypeFacetFactory() {
+ super();
+ }
+
+ @Override
+ public void process(final ProcessClassContext processClassContext) {
+ final Class<?> type = processClassContext.getCls();
+ final FacetHolder holder = processClassContext.getFacetHolder();
+
+ if (type != short.class) {
+ return;
+ }
+ addFacets(new ShortPrimitiveValueSemanticsProvider(holder, getConfiguration(), getContext()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortValueFacet.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortValueFacet.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortValueFacet.java
new file mode 100644
index 0000000..cdc47ae
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortValueFacet.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.core.progmodel.facets.value.shortint;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+
+public interface ShortValueFacet extends Facet {
+ Short shortValue(ObjectAdapter object);
+
+ ObjectAdapter createValue(Short value);
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortValueSemanticsProviderAbstract.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortValueSemanticsProviderAbstract.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortValueSemanticsProviderAbstract.java
new file mode 100644
index 0000000..e092e99
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortValueSemanticsProviderAbstract.java
@@ -0,0 +1,109 @@
+/*
+ * 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.value.shortint;
+
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.text.ParseException;
+
+import org.apache.isis.applib.profiles.Localization;
+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.progmodel.facets.object.value.ValueSemanticsProviderAndFacetAbstract;
+import org.apache.isis.core.progmodel.facets.object.value.ValueSemanticsProviderContext;
+
+public class ShortValueSemanticsProviderAbstract extends ValueSemanticsProviderAndFacetAbstract<Short> implements ShortValueFacet {
+
+ public static Class<? extends Facet> type() {
+ return ShortValueFacet.class;
+ }
+
+ private static final Short DEFAULT_VALUE = Short.valueOf((short) 0);
+ private static final int TYPICAL_LENGTH = 6;
+
+ private final NumberFormat format;
+
+ public ShortValueSemanticsProviderAbstract(final FacetHolder holder, final Class<Short> adaptedClass, final IsisConfiguration configuration, final ValueSemanticsProviderContext context) {
+ super(type(), holder, adaptedClass, TYPICAL_LENGTH, Immutability.IMMUTABLE, EqualByContent.HONOURED, DEFAULT_VALUE, configuration, context);
+ format = determineNumberFormat("value.format.short");
+ }
+
+ // //////////////////////////////////////////////////////////////////
+ // Parser
+ // //////////////////////////////////////////////////////////////////
+
+ @Override
+ protected Short doParse(final Object context, final String entry) {
+ try {
+ return Short.valueOf(format.parse(entry).shortValue());
+ } catch (final ParseException e) {
+ throw new TextEntryParseException("Not a whole number " + entry, e);
+ }
+ }
+
+ @Override
+ public String titleString(final Object value, final Localization localization) {
+ return titleString(format, value);
+ }
+
+ @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 Short doRestore(final String data) {
+ return new Short(data);
+ }
+
+ // //////////////////////////////////////////////////////////////////
+ // ShortValueFacet
+ // //////////////////////////////////////////////////////////////////
+
+ @Override
+ public ObjectAdapter createValue(final Short value) {
+ return getAdapterManager().adapterFor(value);
+ }
+
+ @Override
+ public Short shortValue(final ObjectAdapter object) {
+ return (Short) (object == null ? null : object.getObject());
+ }
+
+ // /////// toString ///////
+
+ @Override
+ public String toString() {
+ return "ShortValueSemanticsProvider: " + format;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortWrapperValueSemanticsProvider.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortWrapperValueSemanticsProvider.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortWrapperValueSemanticsProvider.java
new file mode 100644
index 0000000..903ef9f
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortWrapperValueSemanticsProvider.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.value.shortint;
+
+import org.apache.isis.applib.adapters.EncoderDecoder;
+import org.apache.isis.applib.adapters.Parser;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.progmodel.facets.object.value.ValueSemanticsProviderContext;
+
+public class ShortWrapperValueSemanticsProvider extends ShortValueSemanticsProviderAbstract {
+
+ /**
+ * Required because implementation of {@link Parser} and
+ * {@link EncoderDecoder}.
+ */
+ public ShortWrapperValueSemanticsProvider() {
+ this(null, null, null);
+ }
+
+ public ShortWrapperValueSemanticsProvider(final FacetHolder holder, final IsisConfiguration configuration, final ValueSemanticsProviderContext context) {
+ super(holder, Short.class, configuration, context);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortWrapperValueTypeFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortWrapperValueTypeFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortWrapperValueTypeFacetFactory.java
new file mode 100644
index 0000000..ac6fa1f
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/shortint/ShortWrapperValueTypeFacetFactory.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.value.shortint;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.progmodel.facets.object.value.ValueUsingValueSemanticsProviderFacetFactory;
+
+public class ShortWrapperValueTypeFacetFactory extends ValueUsingValueSemanticsProviderFacetFactory<Short> {
+
+ public ShortWrapperValueTypeFacetFactory() {
+ super();
+ }
+
+ @Override
+ public void process(final ProcessClassContext processClassContext) {
+ final Class<?> type = processClassContext.getCls();
+ final FacetHolder holder = processClassContext.getFacetHolder();
+
+ if (type != Short.class) {
+ return;
+ }
+ addFacets(new ShortWrapperValueSemanticsProvider(holder, getConfiguration(), getContext()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/string/StringValueFacet.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/string/StringValueFacet.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/string/StringValueFacet.java
new file mode 100644
index 0000000..465f39b
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/string/StringValueFacet.java
@@ -0,0 +1,30 @@
+/*
+ * 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.value.string;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+
+public interface StringValueFacet extends Facet {
+ String stringValue(ObjectAdapter object);
+
+ ObjectAdapter createValue(String value);
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/string/StringValueSemanticsProvider.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/string/StringValueSemanticsProvider.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/string/StringValueSemanticsProvider.java
new file mode 100644
index 0000000..361a024
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/string/StringValueSemanticsProvider.java
@@ -0,0 +1,129 @@
+/*
+ * 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.value.string;
+
+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.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.progmodel.facets.object.value.ValueSemanticsProviderAndFacetAbstract;
+import org.apache.isis.core.progmodel.facets.object.value.ValueSemanticsProviderContext;
+
+public class StringValueSemanticsProvider extends ValueSemanticsProviderAndFacetAbstract<String> implements StringValueFacet {
+
+ public static Class<? extends Facet> type() {
+ return StringValueFacet.class;
+ }
+
+ private static final int TYPICAL_LENGTH = 25;
+ private static final String DEFAULT_VALUE = null; // no default
+
+ /**
+ * Required because implementation of {@link Parser} and
+ * {@link EncoderDecoder}.
+ */
+ public StringValueSemanticsProvider() {
+ this(null, null, null);
+ }
+
+ public StringValueSemanticsProvider(final FacetHolder holder, final IsisConfiguration configuration, final ValueSemanticsProviderContext context) {
+ super(type(), holder, String.class, TYPICAL_LENGTH, Immutability.IMMUTABLE, EqualByContent.HONOURED, DEFAULT_VALUE, configuration, context);
+ }
+
+ // //////////////////////////////////////////////////////////////////
+ // Parser
+ // //////////////////////////////////////////////////////////////////
+
+ @Override
+ protected String doParse(final Object context, final String entry) {
+ if (entry.trim().equals("")) {
+ return null;
+ } else {
+ return entry;
+ }
+ }
+
+ @Override
+ public String titleString(final Object object, final Localization localization) {
+ final String string = (String) (object == null ? "" : object);
+ return string;
+ }
+
+ @Override
+ public String titleStringWithMask(final Object object, final String usingMask) {
+ return titleString(object, null);
+ }
+
+ // //////////////////////////////////////////////////////////////////
+ // EncoderDecoder
+ // //////////////////////////////////////////////////////////////////
+
+ @Override
+ protected String doEncode(final Object object) {
+ final String text = (String) object;
+ if (text.equals("NULL") || isEscaped(text)) {
+ return escapeText(text);
+ } else {
+ return text;
+ }
+ }
+
+ @Override
+ protected String doRestore(final String data) {
+ if (isEscaped(data)) {
+ return data.substring(1);
+ } else {
+ return data;
+ }
+ }
+
+ private boolean isEscaped(final String text) {
+ return text.startsWith("/");
+ }
+
+ private String escapeText(final String text) {
+ return "/" + text;
+ }
+
+ // //////////////////////////////////////////////////////////////////
+ // StringValueFacet
+ // //////////////////////////////////////////////////////////////////
+
+ @Override
+ public String stringValue(final ObjectAdapter object) {
+ return object == null ? "" : (String) object.getObject();
+ }
+
+ @Override
+ public ObjectAdapter createValue(final String value) {
+ return getAdapterManager().adapterFor(value);
+ }
+
+ // /////// toString ///////
+
+ @Override
+ public String toString() {
+ return "StringValueSemanticsProvider";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/string/StringValueTypeFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/string/StringValueTypeFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/string/StringValueTypeFacetFactory.java
new file mode 100644
index 0000000..a45880f
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/string/StringValueTypeFacetFactory.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.value.string;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.progmodel.facets.object.value.ValueUsingValueSemanticsProviderFacetFactory;
+
+public class StringValueTypeFacetFactory extends ValueUsingValueSemanticsProviderFacetFactory<String> {
+
+ public StringValueTypeFacetFactory() {
+ super();
+ }
+
+ @Override
+ public void process(final ProcessClassContext processClassContext) {
+ final Class<?> type = processClassContext.getCls();
+ final FacetHolder holder = processClassContext.getFacetHolder();
+
+ if (type != String.class) {
+ return;
+ }
+ addFacets(new StringValueSemanticsProvider(holder, getConfiguration(), getContext()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/time/TimeValueSemanticsProvider.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/time/TimeValueSemanticsProvider.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/time/TimeValueSemanticsProvider.java
new file mode 100644
index 0000000..2bc86b7
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/time/TimeValueSemanticsProvider.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.value.time;
+
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.Map;
+
+import com.google.common.collect.Maps;
+
+import org.apache.isis.applib.adapters.EncoderDecoder;
+import org.apache.isis.applib.adapters.Parser;
+import org.apache.isis.applib.value.Time;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.progmodel.facets.object.value.ValueSemanticsProviderContext;
+
+public class TimeValueSemanticsProvider extends TimeValueSemanticsProviderAbstract<org.apache.isis.applib.value.Time> {
+
+ private static final Map<String, DateFormat> formats = Maps.newHashMap();
+
+ static {
+ initFormats(formats);
+ }
+
+ /**
+ * Required because implementation of {@link Parser} and
+ * {@link EncoderDecoder}.
+ */
+ public TimeValueSemanticsProvider() {
+ this(null, null, null);
+ }
+
+ public TimeValueSemanticsProvider(final FacetHolder holder, final IsisConfiguration configuration, final ValueSemanticsProviderContext context) {
+ super(holder, org.apache.isis.applib.value.Time.class, configuration, context);
+ }
+
+ @Override
+ protected Map<String, DateFormat> formats() {
+ return formats;
+ }
+
+ @Override
+ protected boolean ignoreTimeZone() {
+ return true;
+ }
+
+ @Override
+ protected Time add(final Time original, final int years, final int months, final int days, final int hours, final int minutes) {
+ Time time = original;
+ time = time.add(hours, minutes);
+ return time;
+ }
+
+ @Override
+ protected Date dateValue(final Object object) {
+ final Time time = (Time) object;
+ return time == null ? null : time.asJavaDate();
+ }
+
+ @Override
+ protected Time now() {
+ return new Time();
+ }
+
+ @Override
+ protected Time setDate(final Date date) {
+ return new Time(date.getTime());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/time/TimeValueSemanticsProviderAbstract.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/time/TimeValueSemanticsProviderAbstract.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/time/TimeValueSemanticsProviderAbstract.java
new file mode 100644
index 0000000..067a681
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/time/TimeValueSemanticsProviderAbstract.java
@@ -0,0 +1,108 @@
+/*
+ * 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.value.time;
+
+import java.text.DateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+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.progmodel.facets.object.value.ValueSemanticsProviderContext;
+import org.apache.isis.core.progmodel.facets.value.ValueSemanticsProviderAbstractTemporal;
+
+public abstract class TimeValueSemanticsProviderAbstract<T> extends ValueSemanticsProviderAbstractTemporal<T> {
+
+ private static final Object DEFAULT_VALUE = null; // no default
+ private static final int TYPICAL_LENGTH = 8;
+
+ protected static void initFormats(final Map<String, DateFormat> formats) {
+ formats.put(ISO_ENCODING_FORMAT, createDateEncodingFormat("HHmmssSSS"));
+ formats.put("short", DateFormat.getTimeInstance(DateFormat.SHORT));
+ }
+
+ @SuppressWarnings("unchecked")
+ public TimeValueSemanticsProviderAbstract(final FacetHolder holder, final Class<T> adaptedClass, final IsisConfiguration configuration, final ValueSemanticsProviderContext context) {
+ super("time", holder, adaptedClass, TYPICAL_LENGTH, Immutability.NOT_IMMUTABLE, EqualByContent.NOT_HONOURED, (T) DEFAULT_VALUE, configuration, context);
+
+ final String formatRequired = configuration.getString(ConfigurationConstants.ROOT + "value.format.time");
+ if (formatRequired == null) {
+ format = formats().get(defaultFormat());
+ } else {
+ setMask(formatRequired);
+ }
+ }
+
+ // //////////////////////////////////////////////////////////////////
+ // DateValueFacet
+ // //////////////////////////////////////////////////////////////////
+
+ // //////////////////////////////////////////////////////////////////
+ // temporal-specific stuff
+ // //////////////////////////////////////////////////////////////////
+
+ @Override
+ protected void clearFields(final Calendar cal) {
+ cal.set(Calendar.YEAR, 1970);
+ cal.set(Calendar.MONTH, 0);
+ cal.set(Calendar.DAY_OF_MONTH, 1);
+ }
+
+ @Override
+ protected String defaultFormat() {
+ return "short";
+ }
+
+ @Override
+ public String toString() {
+ return "TimeValueSemanticsProvider: " + format;
+ }
+
+@Override
+ protected DateFormat format(final Localization localization) {
+ final DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT, localization.getLocale());
+ dateFormat.setTimeZone(UTC_TIME_ZONE);
+ return dateFormat;
+ }
+
+ protected List<DateFormat> formatsToTry(Localization localization) {
+ List<DateFormat> formats = new ArrayList<DateFormat>();
+
+ Locale locale = localization == null ? Locale.getDefault() : localization.getLocale();
+ formats.add(DateFormat.getTimeInstance(DateFormat.LONG, locale));
+ formats.add(DateFormat.getTimeInstance(DateFormat.MEDIUM, locale));
+ formats.add(DateFormat.getTimeInstance(DateFormat.SHORT, locale));
+ formats.add(createDateFormat("HH:mm:ss.SSS"));
+ formats.add(createDateFormat("HHmmssSSS"));
+ formats.add(createDateFormat("HH:mm:ss"));
+ formats.add(createDateFormat("HHmmss"));
+
+ for (DateFormat format : formats) {
+ format.setTimeZone(UTC_TIME_ZONE);
+ }
+
+ return formats;
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/time/TimeValueTypeFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/time/TimeValueTypeFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/time/TimeValueTypeFacetFactory.java
new file mode 100644
index 0000000..9317432
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/time/TimeValueTypeFacetFactory.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.value.time;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.progmodel.facets.object.value.ValueUsingValueSemanticsProviderFacetFactory;
+
+public class TimeValueTypeFacetFactory extends ValueUsingValueSemanticsProviderFacetFactory<org.apache.isis.applib.value.Time> {
+
+ public TimeValueTypeFacetFactory() {
+ super(); // as per inherited
+ // DateTimeValueSemanticsProvider#facetType
+ // (inherited)
+ }
+
+ @Override
+ public void process(final ProcessClassContext processClassContext) {
+ final Class<?> type = processClassContext.getCls();
+ final FacetHolder holder = processClassContext.getFacetHolder();
+
+ if (type != org.apache.isis.applib.value.Time.class) {
+ return;
+ }
+ addFacets(new TimeValueSemanticsProvider(holder, getConfiguration(), getContext()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timesql/JavaSqlTimeValueSemanticsProvider.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timesql/JavaSqlTimeValueSemanticsProvider.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timesql/JavaSqlTimeValueSemanticsProvider.java
new file mode 100644
index 0000000..8619828
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timesql/JavaSqlTimeValueSemanticsProvider.java
@@ -0,0 +1,98 @@
+/*
+ * 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.value.timesql;
+
+import java.sql.Time;
+import java.text.DateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Map;
+
+import com.google.common.collect.Maps;
+
+import org.apache.isis.applib.adapters.EncoderDecoder;
+import org.apache.isis.applib.adapters.Parser;
+import org.apache.isis.applib.clock.Clock;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.progmodel.facets.object.value.ValueSemanticsProviderContext;
+import org.apache.isis.core.progmodel.facets.value.time.TimeValueSemanticsProviderAbstract;
+
+/**
+ * Treats {@link java.sql.Time} as a time-only value type.
+ *
+ */
+public class JavaSqlTimeValueSemanticsProvider extends TimeValueSemanticsProviderAbstract<java.sql.Time> {
+ private static Map<String, DateFormat> formats = Maps.newHashMap();
+
+ static {
+ initFormats(formats);
+ }
+
+ /**
+ * Required because implementation of {@link Parser} and
+ * {@link EncoderDecoder}.
+ */
+ public JavaSqlTimeValueSemanticsProvider() {
+ this(null, null, null);
+ }
+
+ public JavaSqlTimeValueSemanticsProvider(final FacetHolder holder, final IsisConfiguration configuration, final ValueSemanticsProviderContext context) {
+ super(holder, java.sql.Time.class, configuration, context);
+ }
+
+ @Override
+ public Time add(final Time original, final int years, final int months, final int days, final int hours, final int minutes) {
+ final java.sql.Time time = original;
+ final Calendar cal = Calendar.getInstance();
+ cal.setTime(time);
+ cal.set(Calendar.YEAR, 0);
+ cal.set(Calendar.MONTH, 0);
+ cal.set(Calendar.DAY_OF_MONTH, 0);
+ cal.set(Calendar.MILLISECOND, 0);
+
+ cal.add(Calendar.HOUR, hours);
+ cal.add(Calendar.MINUTE, minutes);
+
+ return setDate(cal.getTime());
+ }
+
+ @Override
+ public java.util.Date dateValue(final Object object) {
+ final java.sql.Time time = (Time) object;
+ return time == null ? null : new java.util.Date(time.getTime());
+ }
+
+ @Override
+ protected Map<String, DateFormat> formats() {
+ return formats;
+ }
+
+ @Override
+ protected Time now() {
+ return new java.sql.Time(Clock.getTime());
+ }
+
+ @Override
+ protected Time setDate(final Date date) {
+ return new java.sql.Time(date.getTime());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timesql/JavaSqlTimeValueTypeFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timesql/JavaSqlTimeValueTypeFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timesql/JavaSqlTimeValueTypeFacetFactory.java
new file mode 100644
index 0000000..8d3bb11
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timesql/JavaSqlTimeValueTypeFacetFactory.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.value.timesql;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.progmodel.facets.object.value.ValueUsingValueSemanticsProviderFacetFactory;
+
+public class JavaSqlTimeValueTypeFacetFactory extends ValueUsingValueSemanticsProviderFacetFactory<java.sql.Time> {
+
+ public JavaSqlTimeValueTypeFacetFactory() {
+ super(); // as per inherited
+ // TimeValueSemanticsProvider#facetType
+ // (inherited)
+ }
+
+ @Override
+ public void process(final ProcessClassContext processClassContext) {
+ final Class<?> type = processClassContext.getCls();
+ final FacetHolder holder = processClassContext.getFacetHolder();
+
+ if (type != java.sql.Time.class) {
+ return;
+ }
+ addFacets(new JavaSqlTimeValueSemanticsProvider(holder, getConfiguration(), getContext()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timestamp/TimeStampValueSemanticsProvider.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timestamp/TimeStampValueSemanticsProvider.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timestamp/TimeStampValueSemanticsProvider.java
new file mode 100644
index 0000000..ed873e6
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timestamp/TimeStampValueSemanticsProvider.java
@@ -0,0 +1,85 @@
+/*
+ * 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.value.timestamp;
+
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.Map;
+
+import com.google.common.collect.Maps;
+
+import org.apache.isis.applib.adapters.EncoderDecoder;
+import org.apache.isis.applib.adapters.Parser;
+import org.apache.isis.applib.value.TimeStamp;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.object.parseable.InvalidEntryException;
+import org.apache.isis.core.metamodel.facets.properties.defaults.PropertyDefaultFacet;
+import org.apache.isis.core.progmodel.facets.object.value.ValueSemanticsProviderContext;
+
+public class TimeStampValueSemanticsProvider extends TimeStampValueSemanticsProviderAbstract<TimeStamp> {
+
+ public static final boolean isAPropertyDefaultFacet() {
+ return PropertyDefaultFacet.class.isAssignableFrom(TimeStampValueSemanticsProvider.class);
+ }
+
+ private static Map<String, DateFormat> formats = Maps.newHashMap();
+
+ static {
+ initFormats(formats);
+ }
+
+ /**
+ * Required because implementation of {@link Parser} and
+ * {@link EncoderDecoder}.
+ */
+ public TimeStampValueSemanticsProvider() {
+ this(null, null, null);
+ }
+
+ public TimeStampValueSemanticsProvider(final FacetHolder holder, final IsisConfiguration configuration, final ValueSemanticsProviderContext context) {
+ super(holder, TimeStamp.class, configuration, context);
+ }
+
+ // //////////////////////////////////////////////////////////////////
+ // temporal-specific stuff
+ // //////////////////////////////////////////////////////////////////
+
+ @Override
+ protected Date dateValue(final Object value) {
+ return new Date(((TimeStamp) value).longValue());
+ }
+
+ @Override
+ protected Map<String, DateFormat> formats() {
+ return formats;
+ }
+
+ @Override
+ protected TimeStamp now() {
+ throw new InvalidEntryException("Can't change a timestamp.");
+ }
+
+ @Override
+ protected TimeStamp setDate(final Date date) {
+ return new TimeStamp(date.getTime());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timestamp/TimeStampValueSemanticsProviderAbstract.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timestamp/TimeStampValueSemanticsProviderAbstract.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timestamp/TimeStampValueSemanticsProviderAbstract.java
new file mode 100644
index 0000000..2d530ea
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timestamp/TimeStampValueSemanticsProviderAbstract.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.progmodel.facets.value.timestamp;
+
+import java.text.DateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.applib.value.TimeStamp;
+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.progmodel.facets.object.value.ValueSemanticsProviderContext;
+import org.apache.isis.core.progmodel.facets.value.ValueSemanticsProviderAbstractTemporal;
+
+public abstract class TimeStampValueSemanticsProviderAbstract<T> extends ValueSemanticsProviderAbstractTemporal<T> {
+
+ private static final Object DEFAULT_VALUE = null; // no default
+ private static final int TYPICAL_LENGTH = 12;
+
+ protected static void initFormats(final Map<String, DateFormat> formats) {
+ formats.put(ISO_ENCODING_FORMAT, createDateEncodingFormat("yyyyMMdd'T'HHmmssSSS"));
+ formats.put("short", DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG));
+ }
+
+ @SuppressWarnings("unchecked")
+ public TimeStampValueSemanticsProviderAbstract(final FacetHolder holder, final Class<T> adaptedClass, final IsisConfiguration configuration, final ValueSemanticsProviderContext context) {
+ super("timestamp", holder, adaptedClass, TYPICAL_LENGTH, Immutability.NOT_IMMUTABLE, EqualByContent.NOT_HONOURED, (T) DEFAULT_VALUE, configuration, context);
+ final String formatRequired = configuration.getString(ConfigurationConstants.ROOT + "value.format.timestamp");
+ if (formatRequired == null) {
+ format = formats().get(defaultFormat());
+ } else {
+ setMask(formatRequired);
+ }
+ }
+
+ @Override
+ protected T add(final T original, final int years, final int months, final int days, final int hours, final int minutes) {
+ return original;
+ }
+
+ @Override
+ protected Date dateValue(final Object value) {
+ return new Date(((TimeStamp) value).longValue());
+ }
+
+ @Override
+ protected String defaultFormat() {
+ return "short";
+ }
+
+ @Override
+ public String toString() {
+ return "TimeStampValueSemanticsProvider: " + format;
+ }
+
+ @Override
+ protected DateFormat format(final Localization localization) {
+ final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG, localization.getLocale());
+ dateFormat.setTimeZone(localization.getTimeZone());
+ return dateFormat;
+ }
+
+ protected List<DateFormat> formatsToTry(Localization localization) {
+ List<DateFormat> formats = new ArrayList<DateFormat>();
+
+ formats.add(DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG, localization.getLocale()));
+ formats.add(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG, localization.getLocale()));
+ formats.add(createDateFormat("yyyy-MM-dd HH:mm:ss.SSS"));
+
+ for (DateFormat format : formats) {
+ format.setTimeZone(localization.getTimeZone());
+ }
+
+ return formats;
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timestamp/TimeStampValueTypeFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timestamp/TimeStampValueTypeFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timestamp/TimeStampValueTypeFacetFactory.java
new file mode 100644
index 0000000..eb58d2a
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timestamp/TimeStampValueTypeFacetFactory.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.progmodel.facets.value.timestamp;
+
+import org.apache.isis.applib.value.TimeStamp;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.progmodel.facets.object.value.ValueUsingValueSemanticsProviderFacetFactory;
+
+public class TimeStampValueTypeFacetFactory extends ValueUsingValueSemanticsProviderFacetFactory<TimeStamp> {
+
+ public TimeStampValueTypeFacetFactory() {
+ super(); // as per inherited
+ // DateTimeValueSemanticsProvider#facetType
+ // (inherited)
+ }
+
+ @Override
+ public void process(final ProcessClassContext processClassContext) {
+ final Class<?> type = processClassContext.getCls();
+ final FacetHolder holder = processClassContext.getFacetHolder();
+
+ if (type != org.apache.isis.applib.value.TimeStamp.class) {
+ return;
+ }
+ addFacets(new TimeStampValueSemanticsProvider(holder, getConfiguration(), getContext()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timestampsql/JavaSqlTimeStampValueSemanticsProvider.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timestampsql/JavaSqlTimeStampValueSemanticsProvider.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timestampsql/JavaSqlTimeStampValueSemanticsProvider.java
new file mode 100644
index 0000000..e4f3e98
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timestampsql/JavaSqlTimeStampValueSemanticsProvider.java
@@ -0,0 +1,86 @@
+/*
+ * 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.value.timestampsql;
+
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.Map;
+
+import com.google.common.collect.Maps;
+
+import org.apache.isis.applib.adapters.EncoderDecoder;
+import org.apache.isis.applib.adapters.Parser;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.object.parseable.InvalidEntryException;
+import org.apache.isis.core.metamodel.facets.properties.defaults.PropertyDefaultFacet;
+import org.apache.isis.core.progmodel.facets.object.value.ValueSemanticsProviderContext;
+import org.apache.isis.core.progmodel.facets.value.timestamp.TimeStampValueSemanticsProviderAbstract;
+
+public class JavaSqlTimeStampValueSemanticsProvider extends TimeStampValueSemanticsProviderAbstract<java.sql.Timestamp> {
+
+ public static final boolean isAPropertyDefaultFacet() {
+ return PropertyDefaultFacet.class.isAssignableFrom(JavaSqlTimeStampValueSemanticsProvider.class);
+ }
+
+ private static Map<String, DateFormat> formats = Maps.newHashMap();
+
+ static {
+ initFormats(formats);
+ }
+
+ /**
+ * Required because implementation of {@link Parser} and
+ * {@link EncoderDecoder}.
+ */
+ public JavaSqlTimeStampValueSemanticsProvider() {
+ this(null, null, null);
+ }
+
+ public JavaSqlTimeStampValueSemanticsProvider(final FacetHolder holder, final IsisConfiguration configuration, final ValueSemanticsProviderContext context) {
+ super(holder, java.sql.Timestamp.class, configuration, context);
+ }
+
+ // //////////////////////////////////////////////////////////////////
+ // temporal-specific stuff
+ // //////////////////////////////////////////////////////////////////
+
+ @Override
+ protected Date dateValue(final Object value) {
+ return new Date(((Timestamp) value).getTime());
+ }
+
+ @Override
+ protected Map<String, DateFormat> formats() {
+ return formats;
+ }
+
+ @Override
+ protected Timestamp now() {
+ throw new InvalidEntryException("Can't change a timestamp.");
+ }
+
+ @Override
+ protected Timestamp setDate(final Date date) {
+ return new Timestamp(date.getTime());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timestampsql/JavaSqlTimeStampValueTypeFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timestampsql/JavaSqlTimeStampValueTypeFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timestampsql/JavaSqlTimeStampValueTypeFacetFactory.java
new file mode 100644
index 0000000..2ba824c
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/value/timestampsql/JavaSqlTimeStampValueTypeFacetFactory.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.value.timestampsql;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.progmodel.facets.object.value.ValueUsingValueSemanticsProviderFacetFactory;
+
+public class JavaSqlTimeStampValueTypeFacetFactory extends ValueUsingValueSemanticsProviderFacetFactory<java.sql.Timestamp> {
+
+ public JavaSqlTimeStampValueTypeFacetFactory() {
+ super(); // as per inherited
+ // DateTimeValueSemanticsProvider#facetType
+ // (inherited)
+ }
+
+ @Override
+ public void process(final ProcessClassContext processClassContext) {
+ final Class<?> type = processClassContext.getCls();
+ final FacetHolder holder = processClassContext.getFacetHolder();
+
+ if (type != java.sql.Timestamp.class) {
+ return;
+ }
+ addFacets(new JavaSqlTimeStampValueSemanticsProvider(holder, getConfiguration(), getContext()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/layout/dflt/MemberLayoutArrangerDefault.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/layout/dflt/MemberLayoutArrangerDefault.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/layout/dflt/MemberLayoutArrangerDefault.java
new file mode 100644
index 0000000..365cc6a
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/layout/dflt/MemberLayoutArrangerDefault.java
@@ -0,0 +1,34 @@
+/**
+ * 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.layout.dflt;
+
+import org.apache.log4j.Logger;
+
+import org.apache.isis.core.metamodel.layout.MemberLayoutArrangerComposite;
+import org.apache.isis.core.metamodel.layout.memberorderfacet.MemberLayoutArrangerUsingMemberOrderFacet;
+import org.apache.isis.core.progmodel.layout.ordermethod.MemberLayoutArrangerUsingOrderMethod;
+
+public class MemberLayoutArrangerDefault extends MemberLayoutArrangerComposite {
+
+ @SuppressWarnings("unused")
+ private static final Logger LOG = Logger.getLogger(MemberLayoutArrangerDefault.class);
+
+ public MemberLayoutArrangerDefault() {
+ super(new MemberLayoutArrangerUsingOrderMethod(), new MemberLayoutArrangerUsingMemberOrderFacet());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/layout/ordermethod/MemberLayoutArrangerUsingOrderMethod.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/layout/ordermethod/MemberLayoutArrangerUsingOrderMethod.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/layout/ordermethod/MemberLayoutArrangerUsingOrderMethod.java
new file mode 100644
index 0000000..3ff52c9
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/layout/ordermethod/MemberLayoutArrangerUsingOrderMethod.java
@@ -0,0 +1,139 @@
+/**
+ * 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.layout.ordermethod;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.apache.isis.core.commons.lang.JavaClassUtils;
+import org.apache.isis.core.commons.lang.StringUtils;
+import org.apache.isis.core.metamodel.facets.FacetedMethod;
+import org.apache.isis.core.metamodel.facets.object.orderactions.ActionOrderFacet;
+import org.apache.isis.core.metamodel.facets.object.orderfields.FieldOrderFacet;
+import org.apache.isis.core.metamodel.layout.MemberLayoutArranger;
+import org.apache.isis.core.metamodel.layout.OrderSet;
+import org.apache.isis.core.metamodel.layout.ordermethod.SimpleOrderSet;
+import org.apache.isis.core.metamodel.methodutils.MethodFinderUtils;
+import org.apache.isis.core.metamodel.methodutils.MethodScope;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+
+public class MemberLayoutArrangerUsingOrderMethod implements MemberLayoutArranger {
+
+ private static final Logger LOG = Logger.getLogger(MemberLayoutArrangerUsingOrderMethod.class);
+
+ private static final Object[] NO_PARAMETERS = new Object[0];
+ private static final Class<?>[] NO_PARAMETERS_TYPES = new Class[0];
+
+ private static final String FIELD_PREFIX = null;
+
+ private static final String ACTION_PREFIX = null;
+
+ // ////////////////////////////////////////////////////////////////////////////
+ // constructor
+ // ////////////////////////////////////////////////////////////////////////////
+
+ public MemberLayoutArrangerUsingOrderMethod() {
+ }
+
+ // ////////////////////////////////////////////////////////////////////////////
+ // associations
+ // ////////////////////////////////////////////////////////////////////////////
+
+ @Override
+ public OrderSet createAssociationOrderSetFor(final ObjectSpecification spec, final List<FacetedMethod> associationMethods) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("MemberLayoutArrangerUsingOrderMethod: createAssociationOrderSetFor " + spec.getFullIdentifier());
+ }
+
+ // ... and the ordering of the properties and collections
+ final FieldOrderFacet fieldOrderFacet = spec.getFacet(FieldOrderFacet.class);
+ String fieldOrder = fieldOrderFacet == null ? null : fieldOrderFacet.value();
+
+ if (fieldOrder == null) {
+ fieldOrder = invokeSortOrderMethod(spec, FIELD_PREFIX);
+ }
+ return createOrderSet(fieldOrder, associationMethods);
+ }
+
+ // ////////////////////////////////////////////////////////////////////////////
+ // actions
+ // ////////////////////////////////////////////////////////////////////////////
+
+ @Override
+ public OrderSet createActionOrderSetFor(final ObjectSpecification spec, final List<FacetedMethod> actionFacetedMethodList) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("MemberLayoutArrangerUsingOrderMethod: createAssociationOrderSetFor " + spec.getFullIdentifier());
+ }
+
+ final ActionOrderFacet actionOrderFacet = spec.getFacet(ActionOrderFacet.class);
+ String actionOrder = actionOrderFacet == null ? null : actionOrderFacet.value();
+ if (actionOrder == null) {
+ actionOrder = invokeSortOrderMethod(spec, ACTION_PREFIX);
+ }
+ return createOrderSet(actionOrder, actionFacetedMethodList);
+ }
+
+ // ////////////////////////////////////////////////////////////////////////////
+ // helpers
+ // ////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Invokes a method called <tt>xxxOrder()</tt>, returning a {@link String}.
+ *
+ * @param spec
+ */
+ private String invokeSortOrderMethod(final ObjectSpecification spec, final String methodNamePrefix) {
+ final List<Method> methods = Arrays.asList(spec.getCorrespondingClass().getMethods());
+ final Method method = MethodFinderUtils.findMethod(methods, MethodScope.CLASS, (methodNamePrefix + "Order"), String.class, NO_PARAMETERS_TYPES);
+ if (method == null) {
+ return null;
+ }
+
+ if (!JavaClassUtils.isStatic(method)) {
+ LOG.warn("method " + spec.getFullIdentifier() + "." + methodNamePrefix + "Order() must be declared as static");
+ return null;
+ }
+
+ try {
+ final String s = (String) method.invoke(null, NO_PARAMETERS);
+ if (StringUtils.isNullOrEmpty(s)) {
+ return null;
+ }
+ return s;
+ } catch (final IllegalArgumentException e) {
+ LOG.warn("method " + spec.getFullIdentifier() + "#" + method.getName() + "() should accept no parameters");
+ return null;
+ } catch (final IllegalAccessException e) {
+ LOG.warn("method " + spec.getFullIdentifier() + "#" + method.getName() + "() must be declared as public");
+ return null;
+ } catch (final InvocationTargetException e) {
+ LOG.warn("method " + spec.getFullIdentifier() + "#" + method.getName() + "() has thrown an exception");
+ return null;
+ }
+ }
+
+ private OrderSet createOrderSet(final String order, final List<FacetedMethod> members) {
+ if (order == null) {
+ return null;
+ }
+ return SimpleOrderSet.createOrderSet(order, members);
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/metamodelvalidator/dflt/MetaModelValidatorDefault.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/metamodelvalidator/dflt/MetaModelValidatorDefault.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/metamodelvalidator/dflt/MetaModelValidatorDefault.java
new file mode 100644
index 0000000..76155f4
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/metamodelvalidator/dflt/MetaModelValidatorDefault.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.metamodelvalidator.dflt;
+
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidatorAbstract;
+import org.apache.isis.core.metamodel.specloader.validator.ValidationFailures;
+
+public class MetaModelValidatorDefault extends MetaModelValidatorAbstract {
+
+ /**
+ * Does nothing.
+ */
+ @Override
+ public void validate(ValidationFailures validationFailures) {
+ validateSpecifications(validationFailures);
+ }
+
+ private void validateSpecifications(ValidationFailures validationFailures) {
+ getSpecificationLoaderSpi().validateSpecifications(validationFailures);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/webapp/config/IsisConfigurationBuilderForWebapp.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/webapp/config/IsisConfigurationBuilderForWebapp.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/webapp/config/IsisConfigurationBuilderForWebapp.java
new file mode 100644
index 0000000..0127a64
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/webapp/config/IsisConfigurationBuilderForWebapp.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.webapp.config;
+
+import javax.servlet.ServletContext;
+
+import org.apache.log4j.Logger;
+
+import org.apache.isis.core.commons.config.IsisConfigurationBuilder;
+import org.apache.isis.core.commons.config.IsisConfigurationBuilderFileSystem;
+import org.apache.isis.core.commons.config.IsisConfigurationBuilderResourceStreams;
+
+/**
+ * Convenience implementation of {@link IsisConfigurationBuilder} that loads
+ * configuration resource using the {@link ResourceStreamSourceForWebInf}.
+ */
+public class IsisConfigurationBuilderForWebapp extends IsisConfigurationBuilderResourceStreams {
+
+ @SuppressWarnings("unused")
+ private static final Logger LOG = Logger.getLogger(IsisConfigurationBuilderFileSystem.class);
+
+ public IsisConfigurationBuilderForWebapp(final ServletContext servletContext) {
+ super(new ResourceStreamSourceForWebInf(servletContext));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/webapp/config/ResourceStreamSourceForWebInf.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/webapp/config/ResourceStreamSourceForWebInf.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/webapp/config/ResourceStreamSourceForWebInf.java
new file mode 100644
index 0000000..3859856
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/webapp/config/ResourceStreamSourceForWebInf.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.core.webapp.config;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.servlet.ServletContext;
+
+import org.apache.isis.core.commons.lang.PathUtils;
+import org.apache.isis.core.commons.resource.ResourceStreamSourceAbstract;
+
+public class ResourceStreamSourceForWebInf extends ResourceStreamSourceAbstract {
+
+ public static final String DEFAULT_WEBINF_DIRECTORY = "/WEB-INF";
+
+ private final ServletContext servletContext;
+ private final String configurationDirectory;
+
+ public ResourceStreamSourceForWebInf(final ServletContext servletContext) {
+ this(servletContext, DEFAULT_WEBINF_DIRECTORY);
+ }
+
+ public ResourceStreamSourceForWebInf(final ServletContext servletContext, final String configurationDirectory) {
+ this.servletContext = servletContext;
+ this.configurationDirectory = configurationDirectory;
+ }
+
+ @Override
+ public String getName() {
+ return "servlet context ('" + configurationDirectory + "')";
+ }
+
+ @Override
+ public InputStream doReadResource(final String resourcePath) throws IOException {
+ final String fullyQualifiedResourcePath = PathUtils.combine(configurationDirectory, resourcePath);
+ return servletContext.getResourceAsStream(fullyQualifiedResourcePath);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/webapp/content/ResourceCachingFilter.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/webapp/content/ResourceCachingFilter.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/webapp/content/ResourceCachingFilter.java
new file mode 100644
index 0000000..49011d5
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/webapp/content/ResourceCachingFilter.java
@@ -0,0 +1,225 @@
+/*
+ * 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.webapp.content;
+
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Adapted from {@link http
+ * ://www.digitalsanctuary.com/tech-blog/java/jboss/setting
+ * -cache-headers-from-jboss.html}
+ *
+ * <p>
+ * Usage:
+ *
+ * <pre>
+ * <filter>
+ * <filter-name>ResourceCachingFilter</filter-name>
+ * <filter-class>org.apache.isis.core.webapp.content.ResourceCachingFilter</filter-class>
+ * <init-param>
+ * <param-name>CacheTime</param-name>
+ * <param-value>86400</param-value>
+ * </init-param>
+ * </filter>
+ * ...
+ * <filter-mapping>
+ * <filter-name>ResourceCachingFilter</filter-name>
+ * <url-pattern>*.js</url-pattern>
+ * </filter-mapping>
+ * <filter-mapping>
+ * <filter-name>ResourceCachingFilter</filter-name>
+ * <url-pattern>*.css</url-pattern>
+ * </filter-mapping>
+ * <filter-mapping>
+ * <filter-name>ResourceCachingFilter</filter-name>
+ * <url-pattern>*.jpg</url-pattern>
+ * </filter-mapping>
+ * <filter-mapping>
+ * <filter-name>ResourceCachingFilter</filter-name>
+ * <url-pattern>*.png</url-pattern>
+ * </filter-mapping>
+ * <filter-mapping>
+ * <filter-name>ResourceCachingFilter</filter-name>
+ * <url-pattern>*.gif</url-pattern>
+ * </filter-mapping>
+ * </pre>
+ */
+public class ResourceCachingFilter implements Filter {
+
+ /**
+ * Attribute set on {@link HttpServletRequest} if the filter has been
+ * applied.
+ *
+ * <p>
+ * This is intended to inform other filters.
+ */
+ private static final String REQUEST_ATTRIBUTE = ResourceCachingFilter.class.getName() + ".resource";
+
+ /**
+ * To allow other filters to ask whether a request is mapped to the resource
+ * caching filter.
+ *
+ * <p>
+ * For example, the <tt>IsisSessionFilter</tt> uses this in order to skip
+ * any session handling.
+ */
+ public static boolean isCachedResource(final HttpServletRequest request) {
+ return request.getAttribute(REQUEST_ATTRIBUTE) != null;
+ }
+
+ /**
+ * The Constant MILLISECONDS_IN_SECOND.
+ */
+ private static final int MILLISECONDS_IN_SECOND = 1000;
+
+ /** The Constant POST_CHECK_VALUE. */
+ private static final String POST_CHECK_VALUE = "post-check=";
+
+ /** The Constant PRE_CHECK_VALUE. */
+ private static final String PRE_CHECK_VALUE = "pre-check=";
+
+ /** The Constant MAX_AGE_VALUE. */
+ private static final String MAX_AGE_VALUE = "max-age=";
+
+ /** The Constant ZERO_STRING_VALUE. */
+ private static final String ZERO_STRING_VALUE = "0";
+
+ /** The Constant NO_STORE_VALUE. */
+ private static final String NO_STORE_VALUE = "no-store";
+
+ /** The Constant NO_CACHE_VALUE. */
+ private static final String NO_CACHE_VALUE = "no-cache";
+
+ /** The Constant PRAGMA_HEADER. */
+ private static final String PRAGMA_HEADER = "Pragma";
+
+ /** The Constant CACHE_CONTROL_HEADER. */
+ private static final String CACHE_CONTROL_HEADER = "Cache-Control";
+
+ /** The Constant EXPIRES_HEADER. */
+ private static final String EXPIRES_HEADER = "Expires";
+
+ /** The Constant LAST_MODIFIED_HEADER. */
+ private static final String LAST_MODIFIED_HEADER = "Last-Modified";
+
+ /** The Constant CACHE_TIME_PARAM_NAME. */
+ private static final String CACHE_TIME_PARAM_NAME = "CacheTime";
+
+ /** The default for {@link #CACHE_TIME_PARAM_NAME}. */
+ private static final String CACHE_TIME_PARAM_NAME_DEFAULT = "" + 86400;
+
+ /** The reply headers. */
+ private String[][] mReplyHeaders = { {} };
+
+ /** The cache time in seconds. */
+ private Long cacheTime = 0L;
+
+ /**
+ * Initializes the Servlet filter with the cache time and sets up the
+ * unchanging headers.
+ *
+ * @param pConfig
+ * the config
+ *
+ * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
+ */
+ @Override
+ public void init(final FilterConfig pConfig) {
+ final ArrayList<String[]> newReplyHeaders = new ArrayList<String[]>();
+ final String cacheTime = pConfig.getInitParameter(CACHE_TIME_PARAM_NAME);
+ this.cacheTime = Long.parseLong(cacheTime != null ? cacheTime : CACHE_TIME_PARAM_NAME_DEFAULT);
+ if (this.cacheTime > 0L) {
+ newReplyHeaders.add(new String[] { CACHE_CONTROL_HEADER, MAX_AGE_VALUE + this.cacheTime.longValue() });
+ newReplyHeaders.add(new String[] { CACHE_CONTROL_HEADER, PRE_CHECK_VALUE + this.cacheTime.longValue() });
+ newReplyHeaders.add(new String[] { CACHE_CONTROL_HEADER, POST_CHECK_VALUE + this.cacheTime.longValue() });
+ } else {
+ newReplyHeaders.add(new String[] { PRAGMA_HEADER, NO_CACHE_VALUE });
+ newReplyHeaders.add(new String[] { EXPIRES_HEADER, ZERO_STRING_VALUE });
+ newReplyHeaders.add(new String[] { CACHE_CONTROL_HEADER, NO_CACHE_VALUE });
+ newReplyHeaders.add(new String[] { CACHE_CONTROL_HEADER, NO_STORE_VALUE });
+ }
+ this.mReplyHeaders = new String[newReplyHeaders.size()][2];
+ newReplyHeaders.toArray(this.mReplyHeaders);
+ }
+
+ /**
+ * Do filter.
+ *
+ * @param servletRequest
+ * the request
+ * @param servletResponse
+ * the response
+ * @param chain
+ * the chain
+ *
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
+ * @throws ServletException
+ * the servlet exception
+ *
+ * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
+ * javax.servlet.ServletResponse, javax.servlet.FilterChain)
+ */
+ @Override
+ public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain chain) throws IOException, ServletException {
+ // Apply the headers
+ final HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
+ final HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;
+ for (final String[] replyHeader : this.mReplyHeaders) {
+ final String name = replyHeader[0];
+ final String value = replyHeader[1];
+ httpResponse.addHeader(name, value);
+ }
+ if (this.cacheTime > 0L) {
+ final long now = System.currentTimeMillis();
+ final DateFormat httpDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
+ httpDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
+ httpResponse.addHeader(LAST_MODIFIED_HEADER, httpDateFormat.format(new Date(now)));
+ httpResponse.addHeader(EXPIRES_HEADER, httpDateFormat.format(new Date(now + (this.cacheTime.longValue() * MILLISECONDS_IN_SECOND))));
+ }
+ httpRequest.setAttribute(REQUEST_ATTRIBUTE, true);
+ chain.doFilter(servletRequest, servletResponse);
+ }
+
+ /**
+ * Destroy all humans!
+ *
+ * @see javax.servlet.Filter#destroy()
+ */
+ @Override
+ public void destroy() {
+ }
+
+}