use of jp.ossc.nimbus.beans.Property in project nimbus by nimbus-org.
the class PropertyFactoryTest method testSimple.
public void testSimple() throws Exception {
Property prop = PropertyFactory.createProperty("simple");
Test test = new Test();
prop.setProperty(test, "hoge");
assertEquals("hoge", prop.getProperty(test));
}
use of jp.ossc.nimbus.beans.Property in project nimbus by nimbus-org.
the class PropertyFactoryTest method testNestMap9.
public void testNestMap9() throws Exception {
Property prop = PropertyFactory.createProperty("test.map.hogeMap.hoge71");
Test test = new Test(new Test());
assertEquals("fuga71", prop.getProperty(test));
prop.setProperty(test, "hoge");
assertEquals("hoge", prop.getProperty(test));
}
use of jp.ossc.nimbus.beans.Property in project nimbus by nimbus-org.
the class BeanFlowRestServerService method processReadParameter.
protected boolean processReadParameter(RestRequest request, RestResponse response, List paths, ResourceMetaData resource) throws Exception {
if (journal != null) {
journal.addInfo(JOURNAL_KEY_REQUEST_PARAMETERS, request.getRequest().getParameterMap());
}
if (request.getRequestObject() == null) {
request.setRequestObject(request.getRequest().getParameterMap());
} else {
final Object requestObj = request.getRequestObject();
Iterator entries = request.getRequest().getParameterMap().entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
Property prop = null;
try {
prop = propertyAccess.getProperty((String) entry.getKey());
} catch (IllegalArgumentException e) {
getLogger().write("BFRS_00027", new Object[] { resource.resourcePath.path, entry.getKey() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_BAD_REQUEST);
return false;
}
if (!prop.isReadable(requestObj)) {
continue;
}
Class propType = null;
try {
propType = prop.getPropertyType(requestObj);
} catch (NoSuchPropertyException e) {
getLogger().write("BFRS_00012", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
} catch (InvocationTargetException e) {
getLogger().write("BFRS_00012", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
}
if (!prop.isWritable(requestObj, propType)) {
continue;
}
if (propType.isAssignableFrom(String.class)) {
try {
prop.setProperty(requestObj, propType, ((String[]) entry.getValue())[0]);
} catch (NoSuchPropertyException e) {
getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
} catch (InvocationTargetException e) {
getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
}
} else if (propType.isAssignableFrom(String[].class)) {
try {
prop.setProperty(requestObj, propType, entry.getValue());
} catch (NoSuchPropertyException e) {
getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
} catch (InvocationTargetException e) {
getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
}
} else if (propType.isAssignableFrom(List.class) || propType.isAssignableFrom(Set.class)) {
Collection collection = null;
try {
collection = (Collection) prop.getProperty(requestObj);
} catch (NoSuchPropertyException e) {
getLogger().write("BFRS_00014", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
} catch (InvocationTargetException e) {
getLogger().write("BFRS_00014", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
}
if (collection == null) {
if (propType.isInterface()) {
collection = propType.isAssignableFrom(List.class) ? (Collection) new ArrayList() : new HashSet();
} else {
try {
collection = (Collection) propType.newInstance();
} catch (InstantiationException e) {
getLogger().write("BFRS_00015", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName(), propType }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
} catch (IllegalAccessException e) {
getLogger().write("BFRS_00015", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName(), propType }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
}
}
}
Type propGenericType = null;
try {
propGenericType = prop.getPropertyGenericType(requestObj);
} catch (NoSuchPropertyException e) {
getLogger().write("BFRS_00012", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
} catch (InvocationTargetException e) {
getLogger().write("BFRS_00012", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
}
if (propGenericType instanceof ParameterizedType) {
Type[] elementTypes = ((ParameterizedType) propGenericType).getActualTypeArguments();
if (elementTypes.length == 0 || !(elementTypes[0] instanceof Class)) {
getLogger().write("BFRS_00016", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName(), propGenericType });
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
}
Class elementType = (Class) elementTypes[0];
try {
PropertyEditor editor = NimbusPropertyEditorManager.findEditor(elementType);
if (editor == null) {
getLogger().write("BFRS_00017", new Object[] { resource.resourcePath.path, entry.getKey(), elementType.getName() });
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
}
String[] params = (String[]) entry.getValue();
for (int i = 0; i < params.length; i++) {
editor.setAsText(params[i]);
collection.add(editor.getValue());
}
prop.setProperty(requestObj, propType, collection);
} catch (NoSuchPropertyException e) {
getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
} catch (InvocationTargetException e) {
getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
}
} else {
try {
String[] params = (String[]) entry.getValue();
for (int i = 0; i < params.length; i++) {
collection.add(params[i]);
}
prop.setProperty(requestObj, propType, collection);
} catch (NoSuchPropertyException e) {
getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
} catch (InvocationTargetException e) {
getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
}
}
} else if (propType.isArray()) {
Class componentType = propType.getComponentType();
PropertyEditor editor = NimbusPropertyEditorManager.findEditor(componentType);
if (editor == null) {
getLogger().write("BFRS_00017", new Object[] { resource.resourcePath.path, entry.getKey(), componentType.getName() });
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
}
String[] params = (String[]) entry.getValue();
Object array = Array.newInstance(componentType, params.length);
try {
for (int i = 0; i < params.length; i++) {
editor.setAsText(((String[]) entry.getValue())[0]);
Array.set(array, i, editor.getValue());
}
prop.setProperty(requestObj, propType, array);
} catch (IllegalArgumentException e) {
getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
} catch (NoSuchPropertyException e) {
getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
} catch (InvocationTargetException e) {
getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
}
} else {
PropertyEditor editor = NimbusPropertyEditorManager.findEditor(propType);
if (editor == null) {
getLogger().write("BFRS_00017", new Object[] { resource.resourcePath.path, entry.getKey(), propType.getName() });
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
}
editor.setAsText(((String[]) entry.getValue())[0]);
try {
prop.setProperty(requestObj, propType, editor.getValue());
} catch (NoSuchPropertyException e) {
getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
} catch (InvocationTargetException e) {
getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
}
}
}
}
return true;
}
use of jp.ossc.nimbus.beans.Property in project nimbus by nimbus-org.
the class BeanFlowRestServerService method processCreateRequestObject.
protected boolean processCreateRequestObject(RestRequest request, RestResponse response, List paths, ResourceMetaData resource, RequestMetaData requestData) throws Exception {
if (requestData == null) {
return true;
}
Map pathParameters = request.getPathParameterMap();
Object requestObj = null;
Class requestObjClass = null;
try {
requestObjClass = Utility.convertStringToClass(requestData.code, true);
} catch (ClassNotFoundException e) {
getLogger().write("BFRS_00004", new Object[] { resource.resourcePath.path, requestData.code }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
}
if (String.class.equals(requestObjClass)) {
if (pathParameters != null && pathParameters.size() != 0) {
requestObj = pathParameters.values().iterator().next();
}
} else if (String[].class.equals(requestObjClass)) {
if (pathParameters != null && pathParameters.size() != 0) {
requestObj = pathParameters.values().toArray();
}
} else if (Number.class.isAssignableFrom(requestObjClass)) {
if (pathParameters != null && pathParameters.size() != 0) {
String valStr = (String) pathParameters.values().iterator().next();
try {
if (Byte.class.isAssignableFrom(requestObjClass)) {
requestObj = Byte.valueOf(valStr);
} else if (Short.class.isAssignableFrom(requestObjClass)) {
requestObj = Short.valueOf(valStr);
} else if (Integer.class.isAssignableFrom(requestObjClass)) {
requestObj = Integer.valueOf(valStr);
} else if (Long.class.isAssignableFrom(requestObjClass)) {
requestObj = Long.valueOf(valStr);
} else if (Float.class.isAssignableFrom(requestObjClass)) {
requestObj = Float.valueOf(valStr);
} else if (Double.class.isAssignableFrom(requestObjClass)) {
requestObj = Double.valueOf(valStr);
} else if (BigInteger.class.isAssignableFrom(requestObjClass)) {
requestObj = new BigInteger(valStr);
} else if (BigDecimal.class.isAssignableFrom(requestObjClass)) {
requestObj = new BigDecimal(valStr);
} else {
getLogger().write("BFRS_00005", new Object[] { resource.resourcePath.path, requestObjClass.getName() });
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
}
} catch (NumberFormatException e) {
getLogger().write("BFRS_00026", new Object[] { resource.resourcePath.path, pathParameters.keySet().iterator().next(), valStr }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_BAD_REQUEST, "Illegal number format. val=" + valStr);
return false;
}
}
} else {
try {
requestObj = requestObjClass.newInstance();
} catch (InstantiationException e) {
getLogger().write("BFRS_00006", new Object[] { resource.resourcePath.path, requestObjClass.getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
} catch (IllegalAccessException e) {
getLogger().write("BFRS_00006", new Object[] { resource.resourcePath.path, requestObjClass.getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
}
if (pathParameters != null && pathParameters.size() != 0) {
Iterator entries = pathParameters.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
Property prop = null;
try {
prop = propertyAccess.getProperty((String) entry.getKey());
} catch (IllegalArgumentException e) {
getLogger().write("BFRS_00007", new Object[] { resource.resourcePath.path, entry.getKey() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
}
if (!prop.isReadable(requestObj)) {
continue;
}
Class propType = null;
try {
propType = prop.getPropertyType(requestObj);
} catch (NoSuchPropertyException e) {
getLogger().write("BFRS_00008", new Object[] { resource.resourcePath.path, entry.getKey(), requestObjClass.getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
} catch (InvocationTargetException e) {
getLogger().write("BFRS_00008", new Object[] { resource.resourcePath.path, entry.getKey(), requestObjClass.getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
}
if (!prop.isWritable(requestObj, propType)) {
continue;
}
if (propType.isAssignableFrom(String.class)) {
try {
prop.setProperty(requestObj, propType, entry.getValue());
} catch (NoSuchPropertyException e) {
getLogger().write("BFRS_00009", new Object[] { resource.resourcePath.path, entry.getKey(), requestObjClass.getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
} catch (InvocationTargetException e) {
getLogger().write("BFRS_00009", new Object[] { resource.resourcePath.path, entry.getKey(), requestObjClass.getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
}
} else {
PropertyEditor editor = NimbusPropertyEditorManager.findEditor(propType);
if (editor == null) {
getLogger().write("BFRS_00010", new Object[] { resource.resourcePath.path, entry.getKey(), propType.getName() });
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
}
editor.setAsText((String) entry.getValue());
try {
prop.setProperty(requestObj, propType, editor.getValue());
} catch (NoSuchPropertyException e) {
getLogger().write("BFRS_00009", new Object[] { resource.resourcePath.path, entry.getKey(), requestObjClass.getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
} catch (InvocationTargetException e) {
getLogger().write("BFRS_00009", new Object[] { resource.resourcePath.path, entry.getKey(), requestObjClass.getName() }, e);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
}
response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return false;
}
}
}
}
}
request.setRequestObject(requestObj);
return true;
}
use of jp.ossc.nimbus.beans.Property in project nimbus by nimbus-org.
the class PropertyWritableRecordFactoryService method startService.
/**
* サービスの開始処理を行う。<p>
*
* @exception Exception サービスの開始処理に失敗した場合
*/
public void startService() throws Exception {
super.startService();
if (formatKeyMapping != null) {
final Iterator keys = formatKeyMapping.keySet().iterator();
while (keys.hasNext()) {
final String key = (String) keys.next();
final String prop = formatKeyMapping.getProperty(key);
if (prop != null && prop.length() != 0) {
Property property = PropertyFactory.createProperty(prop);
property.setIgnoreNullProperty(true);
writableRecordPropertyMapping.put(key, property);
}
}
}
if (iterateFormats.size() != 0) {
final Iterator itrKeys = iterateFormats.keySet().iterator();
while (itrKeys.hasNext()) {
final String itrKey = (String) itrKeys.next();
final String format = (String) iterateFormats.get(itrKey);
iterateFormatMappings.put(itrKey, parseFormat(format));
if (!iterateFormatKeyMappings.containsKey(itrKey)) {
throw new IllegalArgumentException("IterateFormatKeyMapping that corresponds to \"" + itrKey + "\" is not specified.");
}
}
}
if (iterateFormatKeyMappings.size() != 0) {
final Iterator itrKeys = iterateFormatKeyMappings.keySet().iterator();
while (itrKeys.hasNext()) {
final String itrKey = (String) itrKeys.next();
final Properties props = (Properties) iterateFormatKeyMappings.get(itrKey);
final Map mapping = new HashMap();
final Iterator keys = props.keySet().iterator();
while (keys.hasNext()) {
final String key = (String) keys.next();
final String prop = props.getProperty(key);
if (prop != null && prop.length() != 0) {
Property property = PropertyFactory.createProperty(prop);
property.setIgnoreNullProperty(true);
mapping.put(key, property);
}
}
iterateWritableRecordPropertyMappings.put(itrKey, mapping);
}
}
}
Aggregations