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 2015/03/30 14:56:50 UTC
[21/22] isis git commit: ISIS-720: mothballing scimpi
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/ScimpiNotFoundException.java
----------------------------------------------------------------------
diff --git a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/ScimpiNotFoundException.java b/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/ScimpiNotFoundException.java
deleted file mode 100644
index 6b1e77a..0000000
--- a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/ScimpiNotFoundException.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.viewer.scimpi.dispatcher;
-
-public class ScimpiNotFoundException extends ScimpiException {
- public ScimpiNotFoundException() {
- super();
- }
-
- public ScimpiNotFoundException(final String message, final Throwable cause) {
- super(message, cause);
- }
-
- public ScimpiNotFoundException(final String message) {
- super(message);
- }
-
- public ScimpiNotFoundException(final Throwable cause) {
- super(cause);
- }
-
- private static final long serialVersionUID = 1L;
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/TagOrderException.java
----------------------------------------------------------------------
diff --git a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/TagOrderException.java b/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/TagOrderException.java
deleted file mode 100644
index 97e00e4..0000000
--- a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/TagOrderException.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.viewer.scimpi.dispatcher;
-
-import org.apache.isis.viewer.scimpi.dispatcher.processor.Request;
-
-public class TagOrderException extends ScimpiException {
- private static final long serialVersionUID = 1L;
-
- public TagOrderException(final Request request) {
- super("Invalid tag in this context: " + request.getTag().getName());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/UserManager.java
----------------------------------------------------------------------
diff --git a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/UserManager.java b/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/UserManager.java
deleted file mode 100644
index cdb1b04..0000000
--- a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/UserManager.java
+++ /dev/null
@@ -1,91 +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.viewer.scimpi.dispatcher;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.commons.authentication.AnonymousSession;
-import org.apache.isis.core.commons.authentication.AuthenticationSession;
-import org.apache.isis.core.runtime.authentication.AuthenticationManager;
-import org.apache.isis.core.runtime.authentication.AuthenticationRequestPassword;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext;
-
-public class UserManager {
-
- private static final Logger LOG = LoggerFactory.getLogger(UserManager.class);
- private static UserManager instance;
-
- private static AuthenticationManager getAuthenticationManager() {
- if (instance == null) {
- throw new IllegalStateException("Server initialisation failed, or not defined as a context listener");
- }
- return instance.authenticationManager;
- }
-
- public static AuthenticationSession startRequest(final RequestContext context) {
- AuthenticationSession session = context.getSession();
- if (session == null) {
- session = new AnonymousSession();
- LOG.debug("start anonymous request: " + session);
- } else {
- LOG.debug("start request for: " + session.getUserName());
- }
- IsisContext.closeSession();
- IsisContext.openSession(session);
- return session;
- }
-
- public static AuthenticationSession authenticate(final AuthenticationRequestPassword passwordAuthenticationRequest) {
- final AuthenticationSession session = getAuthenticationManager().authenticate(passwordAuthenticationRequest);
- if (session != null) {
- LOG.info("log on user " + session.getUserName());
- IsisContext.closeSession();
- IsisContext.openSession(session);
- }
- return session;
- }
-
- public static void endRequest(final AuthenticationSession session) {
- if (session == null) {
- LOG.debug("end anonymous request");
- } else {
- LOG.debug("end request for: " + session.getUserName());
- }
- IsisContext.closeSession();
- }
-
- public static void logoffUser(final AuthenticationSession session) {
- LOG.info("log off user " + session.getUserName());
- IsisContext.closeSession();
- getAuthenticationManager().closeSession(session);
-
- final AnonymousSession replacementSession = new AnonymousSession();
- IsisContext.openSession(replacementSession);
- }
-
- private final AuthenticationManager authenticationManager;
-
- public UserManager(final AuthenticationManager authenticationManager) {
- this.authenticationManager = authenticationManager;
- UserManager.instance = this;
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/Util.java
----------------------------------------------------------------------
diff --git a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/Util.java b/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/Util.java
deleted file mode 100644
index b485dd0..0000000
--- a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/Util.java
+++ /dev/null
@@ -1,105 +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.viewer.scimpi.dispatcher;
-
-import java.text.DateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Locale;
-import java.util.TimeZone;
-
-class Util {
-
- public static final String DEFAULT_TIME_ZONE = "Europe/London";
- public static final String DEFAULT_LANGUAGE = "English, United Kingdom (en-gb)";
-
-
- private Util() {}
-
- public static boolean hasChanged(String version1, String version2) {
- return version2 == null && version1 != null || (version2 != null && !version2.equals(version1));
- }
-
- public static List<String> languages() {
- Locale[] locales = DateFormat.getAvailableLocales();
- List<String> list = new ArrayList<String>(locales.length);
- for (Locale locale : locales) {
- list.add(localeName(locale));
- }
- Collections.sort(list);
- return list;
- }
-
- public static List<String> timeZones() {
- List<String> timezones = Arrays.asList(TimeZone.getAvailableIDs());
- Collections.sort(timezones);
- return timezones;
- }
-
- public static TimeZone timeZone(String timeZoneEntry) {
- TimeZone timeZone = TimeZone.getTimeZone(timeZoneEntry);
- return timeZone;
- }
-
- public static Locale locale(String localeCode) {
- String substring[] = localeCode.trim().split("-");
- Locale locale;
- switch (substring.length) {
- case 1:
- locale = new Locale(substring[0]);
- break;
- case 2:
- locale = new Locale(substring[0], substring[1]);
- break;
- case 3:
- locale = new Locale(substring[0], substring[1], substring[3]);
- break;
- default:
- locale = Locale.getDefault();
- break;
- }
- return locale;
- }
-
- public static String languageName(String languageCode) {
- Locale locale = locale(languageCode);
- return localeName(locale);
- }
-
- public static String codeForLanguage(String language) {
- Locale[] locales = DateFormat.getAvailableLocales();
- for (Locale locale : locales) {
- String name = localeName(locale);
- if (name.equals(language)) {
- return locale.toString().toLowerCase().replace('_', '-');
- }
- }
- return null;
- }
-
- public static String localeName(Locale locale) {
- String language = locale.getDisplayLanguage();
- String country = locale.getDisplayCountry().length() == 0 ? "" : ", " + (locale.getDisplayCountry());
- return language + country + " (" + locale.toString().toLowerCase().replace('_', '-') + ")";
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/action/ActionAction.java
----------------------------------------------------------------------
diff --git a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/action/ActionAction.java b/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/action/ActionAction.java
deleted file mode 100644
index 44a9756..0000000
--- a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/action/ActionAction.java
+++ /dev/null
@@ -1,268 +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.viewer.scimpi.dispatcher.action;
-
-import java.io.IOException;
-import java.util.List;
-import org.apache.isis.applib.annotation.Where;
-import org.apache.isis.applib.profiles.Localization;
-import org.apache.isis.core.commons.authentication.AnonymousSession;
-import org.apache.isis.core.commons.authentication.AuthenticationSession;
-import org.apache.isis.core.commons.authentication.MessageBroker;
-import org.apache.isis.core.commons.debug.DebugBuilder;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
-import org.apache.isis.core.metamodel.adapter.version.ConcurrencyException;
-import org.apache.isis.core.metamodel.adapter.version.Version;
-import org.apache.isis.core.metamodel.consent.Consent;
-import org.apache.isis.core.metamodel.consent.Veto;
-import org.apache.isis.core.metamodel.facets.object.parseable.ParseableFacet;
-import org.apache.isis.core.metamodel.facets.object.parseable.TextEntryParseException;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
-import org.apache.isis.core.metamodel.spec.feature.ObjectActionParameter;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.viewer.scimpi.dispatcher.Action;
-import org.apache.isis.viewer.scimpi.dispatcher.Dispatcher;
-import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext;
-import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext.Scope;
-import org.apache.isis.viewer.scimpi.dispatcher.edit.FieldEditState;
-import org.apache.isis.viewer.scimpi.dispatcher.edit.FormState;
-import org.apache.isis.viewer.scimpi.dispatcher.util.MethodsUtils;
-
-public class ActionAction implements Action {
-
- public static final String ACTION = "action";
-
- // REVIEW: should provide this rendering context, rather than hardcoding.
- // the net effect currently is that class members annotated with
- // @Hidden(where=Where.ANYWHERE) or @Disabled(where=Where.ANYWHERE) will indeed
- // be hidden/disabled, but will be visible/enabled (perhaps incorrectly)
- // for any other value for Where
- private final Where where = Where.ANYWHERE;
-
- @Override
- public String getName() {
- return ACTION;
- }
-
- /**
- * REVIEW - this and EditAction are very similar - refactor out common code.
- */
- @Override
- public void process(final RequestContext context) throws IOException {
- final String objectId = context.getParameter("_" + OBJECT);
- final String version = context.getParameter("_" + VERSION);
- final String formId = context.getParameter("_" + FORM_ID);
- final String methodName = context.getParameter("_" + METHOD);
- final String override = context.getParameter("_" + RESULT_OVERRIDE);
- String resultName = context.getParameter("_" + RESULT_NAME);
- final String message = context.getParameter("_" + MESSAGE);
- resultName = resultName == null ? RequestContext.RESULT : resultName;
-
- FormState entryState = null;
- try {
- final ObjectAdapter object = MethodsUtils.findObject(context, objectId);
- // FIXME need to find method based on the set of parameters.
- // otherwise overloaded method may be incorrectly
- // selected.
- final ObjectAction action = MethodsUtils.findAction(object, methodName);
- entryState = validateParameters(context, action, object);
-
- AuthenticationSession session = context.getSession();
- if (session == null && action.isVisible(new AnonymousSession(), object, where).isVetoed()) {
- session = new AnonymousSession();
- }
-
- final Version originalVersion = context.getVersion(version);
- object.checkLock(originalVersion);
- if (entryState.isValid()) {
- final boolean hasResult = invokeMethod(context, resultName, object, action, entryState);
- String view = context.getParameter(hasResult ? "_" + VIEW : "_" + VOID);
-
- final int questionMark = view == null ? -1 : view.indexOf("?");
- if (questionMark > -1) {
- final String params[] = view.substring(questionMark + 1).split("&");
- for (final String param : params) {
- final int equals = param.indexOf("=");
- context.addVariable(param.substring(0, equals), param.substring(equals + 1), Scope.REQUEST);
- view = view.substring(0, questionMark);
- }
- }
- context.setRequestPath(view);
- if (message != null) {
- final MessageBroker messageBroker = getMessageBroker();
- messageBroker.addMessage(message);
- }
- if (override != null) {
- context.addVariable(resultName, override, Scope.REQUEST);
- }
- if (!action.hasReturn() && context.getVariable(resultName) == null) {
- context.addVariable(resultName, objectId, Scope.REQUEST);
- }
- } else {
- entryState.setForm(formId);
- context.addVariable(ENTRY_FIELDS, entryState, Scope.REQUEST);
- context.addVariable(resultName, objectId, Scope.REQUEST);
- if (override != null) {
- context.addVariable(resultName, override, Scope.REQUEST);
- }
- final String error = entryState.getError();
- final String view = context.getParameter("_" + ERROR);
- context.setRequestPath(view, Dispatcher.ACTION);
-
- final MessageBroker messageBroker = getMessageBroker();
- messageBroker.addWarning(error);
- }
- } catch (final ConcurrencyException e) {
- final ObjectAdapter adapter = getAdapterManager().getAdapterFor(e.getOid());
- String user = adapter.getOid().getVersion().getUser();
- String errorMessage = "The data for '" + adapter.titleString() + "' was changed by " + user
- + ". Please repeat the action based on those changes.";
- getMessageBroker().addMessage(errorMessage);
-
- entryState.setForm(formId);
- context.addVariable(ENTRY_FIELDS, entryState, Scope.REQUEST);
- context.addVariable(resultName, objectId, Scope.REQUEST);
- if (override != null) {
- context.addVariable(resultName, override, Scope.REQUEST);
- }
- final String error = entryState.getError();
- if (error != null) {
- context.addVariable(RequestContext.ERROR, error, Scope.REQUEST);
- }
-
- final String view = context.getParameter("_" + ERROR);
- context.setRequestPath(view, Dispatcher.ACTION);
-
- } catch (final RuntimeException e) {
- getMessageBroker().getMessages();
- getMessageBroker().getWarnings();
- throw e;
- }
- }
-
- private boolean invokeMethod(final RequestContext context, final String variable, final ObjectAdapter object, final ObjectAction action, final FormState entryState) {
-
- final ObjectAdapter[] parameters = getParameters(action, entryState);
- final String scopeName = context.getParameter("_" + SCOPE);
- final Scope scope = RequestContext.scope(scopeName, Scope.REQUEST);
- return MethodsUtils.runMethod(context, action, object, parameters, variable, scope);
- }
-
- private ObjectAdapter[] getParameters(final ObjectAction action, final FormState entryState) {
- final int parameterCount = action.getParameterCount();
- final ObjectAdapter[] parameters = new ObjectAdapter[parameterCount];
- for (int i = 0; i < parameterCount; i++) {
- parameters[i] = entryState.getField(parameterName(i)).getValue();
- }
- return parameters;
- }
-
- private FormState validateParameters(final RequestContext context, final ObjectAction action, final ObjectAdapter object) {
- final FormState formState = new FormState();
- final List<ObjectActionParameter> parameters2 = action.getParameters();
- final int parameterCount = action.getParameterCount();
- for (int i = 0; i < parameterCount; i++) {
- final String fieldName = parameterName(i);
- String newEntry = context.getParameter(fieldName);
-
- if (newEntry != null && newEntry.equals("-OTHER-")) {
- newEntry = context.getParameter(fieldName + "-other");
- }
-
- if (newEntry == null) {
- // TODO figure out a better way to determine if boolean or a
- // password
- final ObjectSpecification spec = parameters2.get(i).getSpecification();
- if (spec.isOfType(IsisContext.getSpecificationLoader().loadSpecification(boolean.class)) || spec.isOfType(IsisContext.getSpecificationLoader().loadSpecification(Boolean.class))) {
- newEntry = FALSE;
- } else {
- newEntry = "";
- }
- }
- final FieldEditState fieldState = formState.createField(fieldName, newEntry);
- Consent consent = null;
-
- if (!parameters2.get(i).isOptional() && newEntry.equals("")) {
- consent = new Veto(parameters2.get(i).getName() + " required");
- formState.setError("Not all fields have been set");
-
- } else if (parameters2.get(i).getSpecification().getFacet(ParseableFacet.class) != null) {
- try {
- final ParseableFacet facet = parameters2.get(i).getSpecification().getFacet(ParseableFacet.class);
- Localization localization = IsisContext.getLocalization();
- final String message = parameters2.get(i).isValid(object, newEntry, localization);
- if (message != null) {
- consent = new Veto(message);
- formState.setError("Not all fields are valid");
- }
- final ObjectAdapter entry = facet.parseTextEntry(null, newEntry, localization);
- fieldState.setValue(entry);
- } catch (final TextEntryParseException e) {
- consent = new Veto(e.getMessage());
- formState.setError("Not all fields are valid");
- }
- } else {
- fieldState.setValue(newEntry == null ? null : context.getMappedObject(newEntry));
- }
- if (consent != null && consent.isVetoed()) {
- fieldState.setError(consent.getReason());
- }
- }
-
- if (formState.isValid()) {
- final ObjectAdapter[] parameters = getParameters(action, formState);
- final Consent consent = action.isProposedArgumentSetValid(object, parameters);
- if (consent != null && consent.isVetoed()) {
- formState.setError(consent.getReason());
- }
- }
-
- return formState;
- }
-
- public static String parameterName(final int index) {
- return PARAMETER + (index + 1);
- }
-
- @Override
- public void init() {
- }
-
- @Override
- public void debug(final DebugBuilder debug) {
- }
-
-
- ///////////////////////////////////////////////////////////////////////////
- // from context
- ///////////////////////////////////////////////////////////////////////////
-
- protected MessageBroker getMessageBroker() {
- return IsisContext.getMessageBroker();
- }
-
- protected AdapterManager getAdapterManager() {
- return IsisContext.getPersistenceSession().getAdapterManager();
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/action/Attributes.java
----------------------------------------------------------------------
diff --git a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/action/Attributes.java b/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/action/Attributes.java
deleted file mode 100644
index 67d13e2..0000000
--- a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/action/Attributes.java
+++ /dev/null
@@ -1,131 +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.viewer.scimpi.dispatcher.action;
-
-import java.util.Enumeration;
-import java.util.Vector;
-
-import org.htmlparser.Attribute;
-import org.htmlparser.nodes.TagNode;
-
-import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext;
-
-public class Attributes {
- private static final String TRUE = " true yes on ";
- private static final String FALSE = " false no off ";
- private final TagNode tagNode;
- private final RequestContext context;
-
- public Attributes(final TagNode tagNode, final RequestContext context) {
- this.tagNode = tagNode;
- this.context = context;
- }
-
- public boolean isPropertySet(final String name) {
- final String attribute = tagNode.getAttribute(name);
- int end = attribute.length() - 1;
- final int pos = attribute.indexOf(':');
- end = pos == -1 ? end : pos;
- final String variabelName = attribute.substring(2, end);
- final Object value = context.getVariable(variabelName);
- return value != null;
- // return attribute != null &&
- // !context.replaceVariables(attribute).equals("");
- }
-
- public boolean isPropertySpecified(final String name) {
- final String attribute = tagNode.getAttribute(name);
- return attribute != null;
- }
-
- public String getOptionalProperty(final String name, final boolean ensureVariablesExists) {
- return getOptionalProperty(name, null, ensureVariablesExists);
- }
-
- public String getOptionalProperty(final String name, final String defaultValue, final boolean ensureVariablesExists) {
- final String attribute = tagNode.getAttribute(name);
- return attribute == null ? defaultValue : context.replaceVariables(attribute);
- }
-
- public String getRequiredProperty(final String name, final boolean ensureVariablesExists) {
- final String attribute = tagNode.getAttribute(name);
- if (attribute == null) {
- throw new RequiredPropertyException("Missing property: " + name);
- } else if (attribute.equals("")) {
- throw new RequiredPropertyException("Property not set: " + name);
- } else {
- return context.replaceVariables(attribute);
- }
- }
-
- public String[] getPropertyNames(final String excluding[]) {
- final Vector attributes = tagNode.getAttributesEx();
- final String[] names = new String[attributes.size()];
- int i = 0;
- names: for (final Enumeration e = attributes.elements(); e.hasMoreElements();) {
- final String name = ((Attribute) e.nextElement()).getName();
- if (name == null) {
- continue;
- }
- for (int j = 0; j < excluding.length; j++) {
- if (name.equals(excluding[j])) {
- continue names;
- }
- }
- if (tagNode.getAttribute(name) != null) {
- names[i++] = name;
- }
- }
-
- final String[] array = new String[i];
- System.arraycopy(names, 0, array, 0, i);
- return array;
- }
-
- @Override
- public String toString() {
- return tagNode.toHtml(); // getAttributesEx().toString();
- }
-
- public boolean isRequested(final String name) {
- return isRequested(name, false);
- }
-
- public boolean isRequested(final String name, final boolean defaultValue) {
- final String flag = getOptionalProperty(name, true);
- if (flag == null) {
- return defaultValue;
- } else {
- return isTrue(flag);
- }
- }
-
- public static boolean isTrue(final String flag) {
- final String value = " " + flag.toLowerCase().trim() + " ";
- if (TRUE.indexOf(value) >= 0) {
- return true;
- } else if (FALSE.indexOf(value) >= 0) {
- return false;
- } else {
- throw new PropertyException("Illegal flag value: " + flag);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/action/PropertyException.java
----------------------------------------------------------------------
diff --git a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/action/PropertyException.java b/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/action/PropertyException.java
deleted file mode 100644
index 2e42188..0000000
--- a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/action/PropertyException.java
+++ /dev/null
@@ -1,44 +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.viewer.scimpi.dispatcher.action;
-
-import org.apache.isis.viewer.scimpi.dispatcher.ScimpiException;
-
-public class PropertyException extends ScimpiException {
-
- private static final long serialVersionUID = 1L;
-
- public PropertyException() {
- super();
- }
-
- public PropertyException(final String message, final Throwable cause) {
- super(message, cause);
- }
-
- public PropertyException(final String message) {
- super(message);
- }
-
- public PropertyException(final Throwable cause) {
- super(cause);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/action/RequiredPropertyException.java
----------------------------------------------------------------------
diff --git a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/action/RequiredPropertyException.java b/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/action/RequiredPropertyException.java
deleted file mode 100644
index 20430d3..0000000
--- a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/action/RequiredPropertyException.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.viewer.scimpi.dispatcher.action;
-
-import org.apache.isis.viewer.scimpi.dispatcher.ScimpiException;
-
-public class RequiredPropertyException extends ScimpiException {
- private static final long serialVersionUID = 1L;
-
- public RequiredPropertyException() {
- super();
- }
-
- public RequiredPropertyException(final String message, final Throwable cause) {
- super(message, cause);
- }
-
- public RequiredPropertyException(final String message) {
- super(message);
- }
-
- public RequiredPropertyException(final Throwable cause) {
- super(cause);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/DefaultOidObjectMapping.java
----------------------------------------------------------------------
diff --git a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/DefaultOidObjectMapping.java b/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/DefaultOidObjectMapping.java
deleted file mode 100644
index 85d0f02..0000000
--- a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/DefaultOidObjectMapping.java
+++ /dev/null
@@ -1,511 +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.viewer.scimpi.dispatcher.context;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.commons.debug.DebugBuilder;
-import org.apache.isis.core.commons.exceptions.IsisException;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
-import org.apache.isis.core.metamodel.adapter.oid.AggregatedOid;
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller;
-import org.apache.isis.core.metamodel.adapter.oid.RootOid;
-import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
-import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
-import org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
-import org.apache.isis.core.metamodel.spec.feature.Contributed;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
-import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
-import org.apache.isis.viewer.scimpi.dispatcher.ScimpiException;
-import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext.Scope;
-
-public class DefaultOidObjectMapping implements ObjectMapping {
-
- private static final Logger LOG = LoggerFactory.getLogger(DefaultOidObjectMapping.class);
-
- private final Map<String, TransientRootAdapterMapping> requestTransients = Maps.newHashMap();
- private final Map<String, TransientRootAdapterMapping> sessionTransients = Maps.newHashMap();
-
- //private Class<? extends Oid> oidType;
-
-
- ///////////////////////////////////////
- // clear, endSession
- ///////////////////////////////////////
-
- @Override
- public void clear() {
- requestTransients.clear();
-
- final List<String> remove = Lists.newArrayList();
- for (final String id : sessionTransients.keySet()) {
- final Oid oid = sessionTransients.get(id).getOid();
- if (!oid.isTransient()) {
- remove.add(id);
- sessionTransients.put(id, null);
- }
- }
- for (final String id : remove) {
- sessionTransients.remove(id);
- }
- }
-
- @Override
- public void endSession() {
- sessionTransients.clear();
- }
-
-
- ///////////////////////////////////////
- // mapTransientObject
- ///////////////////////////////////////
-
- @Override
- public String mapTransientObject(final ObjectAdapter adapter) {
- try {
- final List<ObjectAdapter> savedObject = Lists.newArrayList();
- final JSONObject data = encodeTransientData(adapter, savedObject);
- return RequestContext.TRANSIENT_OBJECT_OID_MARKER + data.toString(4);
- } catch (final JSONException e) {
- throw new ScimpiException(e);
- }
- }
-
- private JSONObject encodeTransientData(final ObjectAdapter adapter, final List<ObjectAdapter> adaptersToSave) throws JSONException {
- if (adaptersToSave.contains(adapter)) {
- return null;
- }
- adaptersToSave.add(adapter);
-
- final JSONObject data = createJsonForAdapter(adapter);
-
- final ObjectSpecification specification = adapter.getSpecification();
- for (final ObjectAssociation association : specification.getAssociations(Contributed.EXCLUDED)) {
- final ObjectAdapter fieldValue = association.get(adapter);
- final String fieldName = association.getId();
-
- if (fieldValue == null) {
- data.put(fieldName, (Object) null);
- } else if (association.getSpecification().isEncodeable()) {
- final EncodableFacet encodeableFacet = fieldValue.getSpecification().getFacet(EncodableFacet.class);
- data.put(fieldName, encodeableFacet.toEncodedString(fieldValue));
-
- } else if (association instanceof OneToManyAssociation) {
- final List<JSONObject> collection = Lists.newArrayList();
- final CollectionFacet facet = fieldValue.getSpecification().getFacet(CollectionFacet.class);
- for (final ObjectAdapter element : facet.iterable(fieldValue)) {
- collection.add(encodeTransientData(element, adaptersToSave));
- }
- data.put(fieldName, collection);
- } else {
- if (fieldValue.isTransient() || fieldValue.isParented()) {
- final JSONObject saveData = encodeTransientData(fieldValue, adaptersToSave);
- if (saveData == null) {
- data.put(fieldName, mapObject(fieldValue, Scope.INTERACTION));
- } else {
- data.put(fieldName, saveData);
- }
- } else {
- data.put(fieldName, mapObject(fieldValue, Scope.INTERACTION));
- }
- }
- }
- return data;
- }
-
- private JSONObject createJsonForAdapter(final ObjectAdapter adapter) throws JSONException {
- final JSONObject data = new JSONObject();
-
- final Oid oid = adapter.getOid();
- data.put("_oid", oid.enString(getOidMarshaller()));
-
- if(oid instanceof RootOid) {
- return data;
- }
-
- if (!(oid instanceof AggregatedOid)) {
- throw new ScimpiException("Unsupported OID type " + oid);
- }
- return data;
- }
-
-
-
-
- ////////////////////////////////////////////////////
- // mapObject (either persistent or transient)
- ////////////////////////////////////////////////////
-
- @Override
- public String mapObject(final ObjectAdapter adapter, final Scope scope) {
-
- // TODO need to ensure that transient objects are remapped each time so
- // that any changes are added to
- // session data
- // continue work here.....here
-
- final Oid oid = adapter.getOid();
-// if (oidType == null) {
-// oidType = oid.getClass();
-// }
-
- String encodedOid = oid.enString(getOidMarshaller());
-
- //final boolean isTransient = adapter.isTransient();
- //final String transferableId = (isTransient ? "T" : "P") + adapter.getSpecification().getFullIdentifier() + "@" + encodedOid;
- final String transferableId = encodedOid;
- // LOG.debug("encoded " + oid + " as " + transferableId + " ~ " + encodedOid);
-
- if (adapter.isTransient()) {
- // old TODO cache these in requests so that Mementos are only created once.
- // old TODO if Transient/Interaction then return state; other store state in session an return OID string
- final TransientRootAdapterMapping mapping = new TransientRootAdapterMapping(adapter);
- mappingFor(scope).put(transferableId, mapping);
- }
-
- return transferableId;
- }
-
- private Map<String, TransientRootAdapterMapping> mappingFor(final Scope scope) {
- if (scope == Scope.REQUEST) {
- return requestTransients;
- }
- if (scope == Scope.INTERACTION || scope == Scope.SESSION) {
- return sessionTransients;
- }
- throw new ScimpiException("Can't hold globally transient object");
- }
-
-
-
- ////////////////////////////////////////////////////
- // mappedTransientObject (lookup)
- ////////////////////////////////////////////////////
-
- @Override
- public ObjectAdapter mappedTransientObject(final String jsonObjectData) {
- final String objectData = jsonObjectData; // StringEscapeUtils.unescapeHtml(data);
- if(LOG.isDebugEnabled()) {
- LOG.debug("data" + objectData);
- }
-
- try {
- final JSONObject jsonObject = new JSONObject(objectData);
- return restoreTransientObject(jsonObject);
- } catch (final JSONException e) {
- throw new ScimpiException("Problem reading data: " + jsonObjectData, e);
- }
- }
-
- private ObjectAdapter restoreTransientObject(final JSONObject jsonObject) throws JSONException {
-
- final ObjectAdapter adapter = getAdapter(jsonObject);
-
- //final String objectType = jsonObject.getString("_objectType");
- //final ObjectSpecification specification = getSpecificationLoader().lookupByObjectType(objectType);
- final ObjectSpecification specification = adapter.getSpecification();
-
- for (final ObjectAssociation association : specification.getAssociations(Contributed.EXCLUDED)) {
- final String fieldName = association.getId();
-
- final Object fieldValue = jsonObject.has(fieldName) ? jsonObject.get(fieldName) : null;
-
- if (association.getSpecification().isEncodeable()) {
- if (fieldValue == null) {
- ((OneToOneAssociation) association).initAssociation(adapter, null);
- } else {
- final EncodableFacet encodeableFacet = association.getSpecification().getFacet(EncodableFacet.class);
- final ObjectAdapter fromEncodedString = encodeableFacet.fromEncodedString((String) fieldValue);
- ((OneToOneAssociation) association).initAssociation(adapter, fromEncodedString);
- }
- } else if (association instanceof OneToManyAssociation) {
- final JSONArray collection = (JSONArray) fieldValue;
- for (int i = 0; i < collection.length(); i++) {
- final JSONObject jsonElement = (JSONObject) collection.get(i);
- final ObjectAdapter objectToAdd = restoreTransientObject(jsonElement);
- ((OneToManyAssociation) association).addElement(adapter, objectToAdd);
- }
-
- /*
- * CollectionFacet facet =
- * fieldValue.getSpecification().getFacet
- * (CollectionFacet.class); for (ObjectAdapter element :
- * facet.iterable(fieldValue)) {
- * collection.add(saveData(element, savedObject)); }
- * data.put(fieldName, collection);
- */
- } else {
- if (fieldValue == null) {
- ((OneToOneAssociation) association).initAssociation(adapter, null);
- } else {
- if (fieldValue instanceof JSONObject) {
- final ObjectAdapter fieldObject = restoreTransientObject((JSONObject) fieldValue);
- ((OneToOneAssociation) association).initAssociation(adapter, fieldObject);
- } else {
- final ObjectAdapter field = mappedObject((String) fieldValue);
- ((OneToOneAssociation) association).initAssociation(adapter, field);
- }
- }
- }
- }
- return adapter;
- }
-
- private ObjectAdapter getAdapter(final JSONObject jsonObject) throws JSONException {
-
- //final String objectType = jsonObject.getString("_objectType");
- //final String id = jsonObject.getString("_id");
- //final ObjectSpecification objectSpec = getSpecificationLoader().lookupByObjectType(objectType);
-
- final String oidStr = jsonObject.getString("_oid");
- final TypedOid typedOid = getOidMarshaller().unmarshal(oidStr, TypedOid.class);
-
- if(!typedOid.isTransient()) {
- return getAdapterManager().adapterFor(typedOid);
- } else {
- return mappedObject(oidStr);
- }
-
-// if (objectSpec.isParented() && !objectSpec.isParentedOrFreeCollection()) {
-// final String[] split = id.split("@");
-// final String parentOidStr = split[0];
-// final String aggregatedLocalId = split[1];
-//
-// RootOid parentOid;
-// if(RootOid.class.isAssignableFrom(oidType)) {
-// parentOid = getOidStringifier().deString(parentOidStr);
-// } else if (RootOidDefault.class.isAssignableFrom(oidType)) {
-// parentOid = RootOidDefault.createTransient(objectType, parentOidStr);
-// } else {
-// // REVIEW: for now, don't support holding references to aggregates whose parent is also an aggregate
-// throw new ScimpiException("Unsupported OID type " + oidType);
-// }
-//
-// final AggregatedOid oid = new AggregatedOid(objectType, parentOid, aggregatedLocalId);
-// return getPersistenceSession().recreateAdapter(oid, objectSpec);
-// } else {
-// return mappedObject("T" + objectType + "@" + id); // yuk!
-// }
- }
-
-
-
- ////////////////////////////////////////////////////
- // mappedObject (lookup - either persistent or transient)
- ////////////////////////////////////////////////////
-
- @Override
- public ObjectAdapter mappedObject(final String oidStr) {
-
- final TypedOid typedOid = getOidMarshaller().unmarshal(oidStr, TypedOid.class);
-
-
-// final char type = oidStr.charAt(0);
-//
-// // Pdom.todo.ToDoItem@OID:TODO:6
-// final String[] split = oidStr.split("@");
-// final String oidData = split[1];
-// final String[] oidDataArray = oidData.split(":");
-// final String objectType = oidDataArray[1];
-// final String aggregatedId = split.length > 2?split[2]:null;
-//
-// final ObjectSpecification spec = getSpecificationLoader().lookupByObjectType(objectType);
-
- //if ((type == 'T')) {
- if (typedOid.isTransient()) {
-
- TransientRootAdapterMapping mapping = sessionTransients.get(oidStr);
- if (mapping == null) {
- mapping = requestTransients.get(oidStr);
- }
- if (mapping == null) {
-
- // create as a (transient) root adapter
- // Oid oid = deString(objectType, oidData, State.TRANSIENT);
- //return getPersistenceSession().recreateAdapter(oid, pojo);
-
- return getAdapterManager().adapterFor(typedOid);
- }
-
- final ObjectAdapter mappedTransientObject = mapping.getObject();
- if(LOG.isDebugEnabled()) {
- LOG.debug("retrieved " + mappedTransientObject.getOid() + " for " + oidStr);
- }
-
- return mappedTransientObject;
- }
-
- try {
- //LOG.debug("decoding " + oidData);
-
- //if (aggregatedId != null) {
- if(typedOid instanceof AggregatedOid) {
-
-// final RootOid parentOid = deString(objectType, oidData, State.PERSISTENT);
-// Oid aggregatedOid = new AggregatedOid(objectType, parentOid, aggregatedId);
-
- AggregatedOid aggregatedOid = (AggregatedOid) typedOid;
- final TypedOid parentOid = aggregatedOid.getParentOid();
-
- getPersistenceSession().loadObject(parentOid);
- return getAdapterManager().getAdapterFor(aggregatedOid);
- }
-
-// RootOid oid = deString(objectType, oidData, State.PERSISTENT);
-// return getPersistenceSession().loadObject(oid);
-
- return getPersistenceSession().loadObject(typedOid);
-
- } catch (final SecurityException e) {
- throw new IsisException(e);
- }
- }
-
-
- ///////////////////////////////////////////////////////
- // reloadIdentityMap (reloads the session transients)
- ///////////////////////////////////////////////////////
-
- @Override
- public void reloadIdentityMap() {
- final Iterator<TransientRootAdapterMapping> mappings = sessionTransients.values().iterator();
- while (mappings.hasNext()) {
- final TransientRootAdapterMapping mapping = mappings.next();
- mapping.reload();
- }
- }
-
-
- ////////////////////////////////////////////////////
- // unmapObject (unmaps the transients)
- ////////////////////////////////////////////////////
-
- @Override
- public void unmapObject(final ObjectAdapter object, final Scope scope) {
- sessionTransients.remove(object.getOid());
- requestTransients.remove(object.getOid());
- }
-
-
- ///////////////////////////////////////
- // helpers
- ///////////////////////////////////////
-
-// enum State { TRANSIENT, PERSISTENT }
-
-// private RootOid deString(String objectType, final String oidData, State stateHint) {
-// if(RootOid.class.isAssignableFrom(oidType)) {
-// return getOidStringifier().deString(oidData);
-// } else {
-// throw new ScimpiException("Unsupported OID type " + oidType);
-// }
-// }
-
-
-// private String enString(RootOid ows) {
-// return getOidStringifier().enString(ows);
-// }
-
-// private String enString(final Oid parentOid, final String aggregatedId) {
-// return enString(parentOid) + "@" + aggregatedId;
-// }
-
-// private String enString(final Oid oid) {
-// final String parentOidStr;
-// if(oid instanceof RootOid) {
-// RootOid ows = (RootOid) oid;
-// parentOidStr = enString(ows);
-// } else if (oid instanceof RootOidDefault) {
-// final RootOidDefault parentSerialOid = (RootOidDefault) oid;
-// parentOidStr = parentSerialOid.getIdentifier();
-// } else {
-// throw new ScimpiException("Unsupported OID type " + oid);
-// }
-// return parentOidStr;
-// }
-
-
-
- /////////////////////////////////////////////////////////////////////////
- // debugging
- /////////////////////////////////////////////////////////////////////////
-
- @Override
- public void append(final DebugBuilder debug) {
- append(debug, requestTransients, "request");
- append(debug, sessionTransients, "session");
- }
-
- private void append(final DebugBuilder debug, final Map<String, TransientRootAdapterMapping> transients, final String type) {
- final Iterator<String> ids = new HashSet<String>(transients.keySet()).iterator();
- if (ids.hasNext()) {
- debug.appendTitle("Transient objects (" + type + ")");
- while (ids.hasNext()) {
- final String key = ids.next();
- debug.appendln(key, transients.get(key).debug());
- }
- }
- }
-
- @Override
- public void appendMappings(final DebugBuilder request) {
- }
-
-
- ///////////////////////////////////////
- // from context
- ///////////////////////////////////////
-
- protected SpecificationLoaderSpi getSpecificationLoader() {
- return IsisContext.getSpecificationLoader();
- }
-
- protected PersistenceSession getPersistenceSession() {
- return IsisContext.getPersistenceSession();
- }
-
- protected AdapterManager getAdapterManager() {
- return getPersistenceSession().getAdapterManager();
- }
-
- protected OidMarshaller getOidMarshaller() {
- return IsisContext.getOidMarshaller();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/DefaultVersionMapping.java
----------------------------------------------------------------------
diff --git a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/DefaultVersionMapping.java b/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/DefaultVersionMapping.java
deleted file mode 100644
index 2fb0006..0000000
--- a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/DefaultVersionMapping.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.viewer.scimpi.dispatcher.context;
-
-import org.apache.isis.core.metamodel.adapter.version.SerialNumberVersion;
-import org.apache.isis.core.metamodel.adapter.version.Version;
-
-public class DefaultVersionMapping implements VersionMapping {
-
- @Override
- public String mapVersion(final Version version) {
- // SerialNumberVersion v = (SerialNumberVersion) version;
- // return Long.toHexString(v.getSequence());
- return version.sequence();
- }
-
- @Override
- public Version getVersion(final String id) {
- final Long sequence = Long.valueOf(id, 16);
- return SerialNumberVersion.create(sequence, null, null);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/IndirectObjectMapping.java
----------------------------------------------------------------------
diff --git a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/IndirectObjectMapping.java b/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/IndirectObjectMapping.java
deleted file mode 100644
index 2a5dfff..0000000
--- a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/IndirectObjectMapping.java
+++ /dev/null
@@ -1,204 +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.viewer.scimpi.dispatcher.context;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.TreeSet;
-
-import com.google.common.collect.Maps;
-
-import org.apache.isis.core.commons.debug.DebugBuilder;
-import org.apache.isis.core.commons.exceptions.NotYetImplementedException;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext.Scope;
-
-public class IndirectObjectMapping implements ObjectMapping {
- private final Map<Scope, Map<String, Mapping>> scopedMappings = Maps.newLinkedHashMap();
- private int nextId = 0;
-
- public IndirectObjectMapping() {
- scopedMappings.put(Scope.GLOBAL, Maps.<String,Mapping>newHashMap());
- scopedMappings.put(Scope.SESSION, Maps.<String,Mapping>newHashMap());
- scopedMappings.put(Scope.INTERACTION, Maps.<String,Mapping>newHashMap());
- scopedMappings.put(Scope.REQUEST, Maps.<String,Mapping>newHashMap());
- }
-
- private String nextId() {
- nextId++;
- return String.valueOf(nextId);
- }
-
- @Override
- public void endSession() {
- scopedMappings.get(Scope.SESSION).clear();
- nextId = 0;
- }
-
- @Override
- public void reloadIdentityMap() {
- reloadIdentityMap(Scope.GLOBAL);
- reloadIdentityMap(Scope.SESSION);
- reloadIdentityMap(Scope.INTERACTION);
-
- final Map<String, Mapping> map = scopedMappings.get(Scope.INTERACTION);
- scopedMappings.put(Scope.REQUEST, map);
- scopedMappings.put(Scope.INTERACTION, new HashMap<String, Mapping>());
- }
-
- private void reloadIdentityMap(final Scope scope) {
- final Map<String, Mapping> map = scopedMappings.get(scope);
- final Iterator<String> ids = map.keySet().iterator();
- while (ids.hasNext()) {
- final String key = ids.next();
- final Mapping mapping = map.get(key);
- mapping.reload();
- }
- }
-
- @Override
- public void clear() {
- scopedMappings.get(Scope.REQUEST).clear();
- }
-
- @Override
- public void unmapObject(final ObjectAdapter object, final Scope scope) {
- final String id = mapObject(object, scope);
- scopedMappings.get(scope).remove(id);
- }
-
- @Override
- public void appendMappings(final DebugBuilder debug) {
- appendMappings(debug, scopedMappings.get(Scope.INTERACTION));
- }
-
- private void appendMappings(final DebugBuilder debug, final Map<String, Mapping> map) {
- final Iterator<String> names = map.keySet().iterator();
- while (names.hasNext()) {
- final String id = names.next();
- final ObjectAdapter object = mappedObject(id);
- debug.appendln(id, object);
- }
- }
-
- private void appendMappings(final DebugBuilder debug, final Scope scope) {
- debug.appendTitle("Objects for " + scope);
- final Map<String, Mapping> map = scopedMappings.get(scope);
- final Iterator<String> ids = new TreeSet<String>(map.keySet()).iterator();
- if (!ids.hasNext()) {
- debug.appendln("None", "");
- }
- while (ids.hasNext()) {
- final String key = ids.next();
- debug.appendln(key, map.get(key).debug());
- }
- }
-
- private Mapping createMapping(final ObjectAdapter adapter) {
- if (adapter.isTransient()) {
- return new TransientRootAdapterMapping(adapter);
- } else {
- return new PersistentRootAdapterMapping(adapter);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.isis.webapp.context.ObjectMapping#mappedObject(java.lang.String
- * )
- */
- @Override
- public ObjectAdapter mappedObject(final String id) {
- final Iterator<Map<String, Mapping>> iterator = scopedMappings.values().iterator();
- while (iterator.hasNext()) {
- final Map<String, Mapping> map = iterator.next();
- final Mapping mapping = map.get(id);
- if (mapping != null) {
- return mapping.getObject();
- }
- }
- return null;
- }
-
- @Override
- public String mapObject(final ObjectAdapter obj, final Scope scope) {
- ObjectAdapter object;
- object = obj;
- final Mapping mapping = createMapping(object);
-
- boolean changeScope = false;
- for (final Scope s : scopedMappings.keySet()) {
- final Map<String, Mapping> map = scopedMappings.get(s);
- if (map.containsValue(mapping)) {
- final String id = findMapping(map, mapping);
- if (changeScope) {
- map.remove(id);
- scopedMappings.get(scope).put(id, mapping);
- }
- return id;
- }
-
- if (s == scope) {
- changeScope = true;
- }
- }
-
- final Map<String, Mapping> map = scopedMappings.get(scope);
- final String id = obj.getSpecification().getShortIdentifier() + "@" + nextId();
- map.put(id, mapping);
- return id;
- }
-
- private String findMapping(final Map<String, Mapping> map, final Mapping mapping) {
- final Iterator<String> ids = map.keySet().iterator();
- while (ids.hasNext()) {
- final String key = ids.next();
- if (map.get(key).equals(mapping)) {
- return key;
- }
- }
-
- return null;
- }
-
- @Override
- public void append(final DebugBuilder debug) {
- debug.appendln("Next ID", nextId);
-
- appendMappings(debug, Scope.GLOBAL);
- appendMappings(debug, Scope.SESSION);
- appendMappings(debug, Scope.INTERACTION);
- appendMappings(debug, Scope.REQUEST);
- }
-
- @Override
- public ObjectAdapter mappedTransientObject(final String substring) {
- throw new NotYetImplementedException();
- }
-
- @Override
- public String mapTransientObject(final ObjectAdapter object) {
- throw new NotYetImplementedException();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/Mapping.java
----------------------------------------------------------------------
diff --git a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/Mapping.java b/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/Mapping.java
deleted file mode 100644
index a41481b..0000000
--- a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/Mapping.java
+++ /dev/null
@@ -1,205 +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.viewer.scimpi.dispatcher.context;
-
-import org.apache.isis.core.commons.debug.DebugString;
-import org.apache.isis.core.commons.ensure.Assert;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.adapter.oid.RootOid;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.runtime.memento.Memento;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
-
-interface Mapping {
- ObjectAdapter getObject();
-
- Oid getOid();
-
- String debug();
-
- void reload();
-
- void update();
-}
-
-class TransientRootAdapterMapping implements Mapping {
- private final RootOid oid;
- private Memento memento;
-
- public TransientRootAdapterMapping(final ObjectAdapter adapter) {
- oid = (RootOid) adapter.getOid();
- Assert.assertTrue("OID is for persistent", oid.isTransient());
- Assert.assertTrue("adapter is for persistent", adapter.isTransient());
- memento = new Memento(adapter);
- }
-
- @Override
- public ObjectAdapter getObject() {
- return getAdapterManager().getAdapterFor(oid);
- }
-
- @Override
- public Oid getOid() {
- return oid;
- }
-
- @Override
- public void reload() {
- memento.recreateObject();
- }
-
- @Override
- public void update() {
- memento = new Memento(getObject());
- }
-
-
- ////////////////////////////////////
- // debug
- ////////////////////////////////////
-
- @Override
- public String debug() {
- final DebugString debug = new DebugString();
- memento.debug(debug);
- return debug.toString();
- }
-
- ////////////////////////////////////
- // equals, hashCode
- ////////////////////////////////////
-
- @Override
- public boolean equals(final Object obj) {
- if (obj == this) {
- return true;
- }
-
- if (obj instanceof TransientRootAdapterMapping) {
- return ((TransientRootAdapterMapping) obj).oid.equals(oid);
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return oid.hashCode();
- }
-
-
- ////////////////////////////////////
- // from context
- ////////////////////////////////////
-
- private AdapterManager getAdapterManager() {
- return getPersistenceSession().getAdapterManager();
- }
-
- private PersistenceSession getPersistenceSession() {
- return IsisContext.getPersistenceSession();
- }
-}
-
-class PersistentRootAdapterMapping implements Mapping {
- private final RootOid oid;
- private final ObjectSpecification spec;
-
- public PersistentRootAdapterMapping(final ObjectAdapter object) {
- this.oid = (RootOid) object.getOid();
- this.spec = object.getSpecification();
- }
-
- @Override
- public Oid getOid() {
- return oid;
- }
-
- @Override
- public ObjectAdapter getObject() {
- if (!IsisContext.inTransaction()) {
- throw new IllegalStateException(getClass().getSimpleName() + " requires transaction in order to load");
- }
- return getPersistenceSession().loadObject(oid);
- }
-
- @Override
- public void reload() {
- // will only recreate if not already in the adapter mgr maps.
- getAdapterManager().adapterFor(oid);
- }
-
-
- @Override
- public void update() {
- }
-
- ////////////////////////////////////
- // debug
- ////////////////////////////////////
-
- @Override
- public String debug() {
- return oid + " " + spec.getShortIdentifier() + " " + getAdapterManager().getAdapterFor(oid);
- }
-
- ////////////////////////////////////
- // equals, hashCode
- ////////////////////////////////////
-
- @Override
- public boolean equals(final Object obj) {
- if (obj == this) {
- return true;
- }
-
- if (obj instanceof PersistentRootAdapterMapping) {
- final PersistentRootAdapterMapping other = (PersistentRootAdapterMapping) obj;
- return oid.equals(other.oid) && spec == other.spec;
- }
-
- return false;
- }
-
-
- @Override
- public int hashCode() {
- int hash = 37;
- hash = hash * 17 + oid.hashCode();
- hash = hash * 17 + spec.hashCode();
- return hash;
- }
-
-
- ////////////////////////////////////
- // from context
- ////////////////////////////////////
-
- protected PersistenceSession getPersistenceSession() {
- return IsisContext.getPersistenceSession();
- }
-
- protected AdapterManager getAdapterManager() {
- return getPersistenceSession().getAdapterManager();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/ObjectMapping.java
----------------------------------------------------------------------
diff --git a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/ObjectMapping.java b/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/ObjectMapping.java
deleted file mode 100644
index 9fe4013..0000000
--- a/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/ObjectMapping.java
+++ /dev/null
@@ -1,42 +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.viewer.scimpi.dispatcher.context;
-
-import org.apache.isis.core.commons.debug.DebugBuilder;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext.Scope;
-
-public interface ObjectMapping {
-
- void reloadIdentityMap();
- void endSession();
-
- void clear();
-
- String mapObject(ObjectAdapter obj, Scope scope);
- String mapTransientObject(ObjectAdapter object);
- void unmapObject(ObjectAdapter object, Scope scope);
-
- ObjectAdapter mappedObject(String oidStr);
- ObjectAdapter mappedTransientObject(String jsonData);
-
- void append(DebugBuilder debug);
- void appendMappings(DebugBuilder debug);
-}