
org.brutusin.jsonsrv.JsonService Maven / Gradle / Ivy
/*
* Copyright 2015 brutusin.org
*
* Licensed 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.brutusin.jsonsrv;
import net.jodah.typetools.TypeResolver;
import org.brutusin.commons.json.JsonHelper;
import org.brutusin.commons.json.JsonSchema;
/**
*
* @author Ignacio del Valle Alles [email protected]
*/
public final class JsonService {
private final String id;
private final JsonAction action;
private final String inputSchema;
private final String outputSchema;
private final JsonSchema validationInputSchema;
private final Class inputClass;
private final Class outputClass;
public JsonService(String id, JsonAction action, JsonHelper jsonHelper) {
this.id = id;
this.action = action;
Class>[] types = TypeResolver.resolveRawArguments(JsonAction.class, action.getClass());
this.inputClass = (Class) types[0];
this.outputClass = (Class) types[1];
this.inputSchema = jsonHelper.getSchemaHelper().getSchemaString(this.inputClass);
this.outputSchema = jsonHelper.getSchemaHelper().getSchemaString(this.outputClass);
try {
this.validationInputSchema = jsonHelper.getSchemaHelper().getSchema(jsonHelper.getSchemaHelper().getSchemaString(this.inputClass));
} catch (Exception ex) {
throw new Error(ex);
}
}
public String getId() {
return id;
}
public JsonAction getAction() {
return action;
}
public String getInputSchema() {
return inputSchema;
}
public String getOutputSchema() {
return outputSchema;
}
public JsonSchema getValidationInputSchema() {
return validationInputSchema;
}
public Class getInputClass() {
return inputClass;
}
public Class getOutputClass() {
return outputClass;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy