use of jp.ossc.nimbus.core.DeploymentException in project nimbus by nimbus-org.
the class BeanFlowRestServerService method reload.
public synchronized void reload() throws Exception {
if (serverDefinitionPath == null || serverDefinitionPath.length() == 0) {
throw new IllegalArgumentException("ServerDefinitionPath is null");
}
File serviceDefDir = null;
if (getServiceNameObject() != null) {
ServiceMetaData metaData = ServiceManagerFactory.getServiceMetaData(getServiceNameObject());
if (metaData != null) {
jp.ossc.nimbus.core.ServiceLoader loader = metaData.getServiceLoader();
if (loader != null) {
String filePath = loader.getServiceURL().getFile();
if (filePath != null) {
serviceDefDir = new File(filePath).getParentFile();
}
}
}
}
URL url = null;
File localFile = new File(serverDefinitionPath);
if (!localFile.exists() && serviceDefDir != null) {
localFile = new File(serviceDefDir, serverDefinitionPath);
}
if (localFile.exists()) {
if (!localFile.isFile()) {
throw new IllegalArgumentException("ServerDefinitionPath must be file : " + localFile);
}
try {
url = localFile.toURI().toURL();
} catch (MalformedURLException e) {
// この例外は発生しないはず
}
} else {
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final URL resource = classLoader.getResource(serverDefinitionPath);
if (resource != null) {
url = resource;
}
}
if (url == null) {
throw new IllegalArgumentException("ServerDefinitionPath not found : " + serverDefinitionPath);
}
final InputSource inputSource = new InputSource(url.openStream());
DocumentBuilderFactory domFactory = null;
if (documentBuilderFactoryClassName == null) {
domFactory = DocumentBuilderFactory.newInstance();
} else {
domFactory = (DocumentBuilderFactory) Class.forName(documentBuilderFactoryClassName, true, NimbusClassLoader.getInstance()).newInstance();
}
domFactory.setValidating(isValidate());
final DocumentBuilder builder = domFactory.newDocumentBuilder();
final NimbusEntityResolver resolver = new NimbusEntityResolver();
builder.setEntityResolver(resolver);
final MyErrorHandler handler = new MyErrorHandler();
builder.setErrorHandler(handler);
final Document doc = builder.parse(inputSource);
if (handler.isError()) {
throw new DeploymentException("Failed to parse ServerDefinition");
}
final RestServerMetaData serverData = new RestServerMetaData();
serverData.importXML(doc.getDocumentElement());
restServerMetaData = serverData;
}
use of jp.ossc.nimbus.core.DeploymentException in project nimbus by nimbus-org.
the class BeanFlowInvokerAccessImpl2 method fillInstance.
public void fillInstance(Element element, BeanFlowInvokerFactoryCallBack callBack, String encoding) {
this.encoding = encoding;
try {
factoryCallBack = callBack;
flowName = MetaData.getUniqueAttribute(element, NAME_ATTRIBUTE);
coverage = new BeanFlowCoverageImpl("<flow name=\"" + flowName + "\">");
String maxThreadsStr = MetaData.getOptionalAttribute(element, MAX_RUN_THREADS_ATTRIBUTE);
if (maxThreadsStr != null) {
maxThreadsStr = factoryCallBack.replaceProperty(maxThreadsStr);
try {
int maxThreads = Integer.parseInt(maxThreadsStr);
semaphore = new MemorySemaphore();
semaphore.setResourceCapacity(maxThreads);
semaphore.accept();
} catch (NumberFormatException e) {
throw new InvalidConfigurationException("maxThreads is number " + maxThreadsStr);
}
}
String timeoutStr = MetaData.getOptionalAttribute(element, TIMEOUT_ATTRIBUTE);
if (timeoutStr != null) {
timeoutStr = factoryCallBack.replaceProperty(timeoutStr);
try {
timeout = Long.parseLong(timeoutStr);
} catch (NumberFormatException e) {
throw new InvalidConfigurationException("timeout is number " + timeoutStr);
}
}
String maxWaitCountStr = MetaData.getOptionalAttribute(element, MAX_WAIT_THREADS_ATTRIBUTE);
if (maxWaitCountStr != null) {
maxWaitCountStr = factoryCallBack.replaceProperty(maxWaitCountStr);
try {
maxWaitCount = Integer.parseInt(maxWaitCountStr);
} catch (NumberFormatException e) {
throw new InvalidConfigurationException("maxWaitThreads is number " + maxWaitCountStr);
}
}
String forceFreeTimeoutStr = MetaData.getOptionalAttribute(element, FORCE_FREE_TIMEOUT_ATTRIBUTE);
if (forceFreeTimeoutStr != null) {
forceFreeTimeoutStr = factoryCallBack.replaceProperty(forceFreeTimeoutStr);
try {
forceFreeTimeout = Long.parseLong(forceFreeTimeoutStr);
} catch (NumberFormatException e) {
throw new InvalidConfigurationException("forceFreeTimeout is number " + forceFreeTimeoutStr);
}
}
final String transactionStr = MetaData.getOptionalAttribute(element, TRANSACTION_ATTRIBUTE);
if (transactionStr != null) {
if (REQUIRED.equals(transactionStr)) {
transactionType = REQUIRED_VALUE;
} else if (REQUIRESNEW.equals(transactionStr)) {
transactionType = REQUIRESNEW_VALUE;
} else if (SUPPORTS.equals(transactionStr)) {
transactionType = SUPPORTS_VALUE;
} else if (MANDATORY.equals(transactionStr)) {
transactionType = MANDATORY_VALUE;
} else if (NEVER.equals(transactionStr)) {
transactionType = NEVER_VALUE;
} else if (NOT_SUPPORTED.equals(transactionStr)) {
transactionType = NOT_SUPPORTED_VALUE;
} else {
throw new InvalidConfigurationException("Invalid transaction : " + transactionStr);
}
if (transactionType != SUPPORTS_VALUE) {
try {
TransactionManagerFactory tranMngFactory = factoryCallBack.getTransactionManagerFactory();
if (getTransactionManagerJndiName() != null && tranMngFactory instanceof JndiTransactionManagerFactoryService) {
((JndiTransactionManagerFactoryService) tranMngFactory).setTransactionManagerName(getTransactionManagerJndiName());
}
tranManager = tranMngFactory.getTransactionManager();
} catch (TransactionManagerFactoryException e) {
throw new DeploymentException(e);
}
}
}
final String transactionTimeoutStr = MetaData.getOptionalAttribute(element, TRANTIMEOUT_ATTRIBUTE);
if (transactionTimeoutStr != null) {
try {
transactionTimeout = Integer.parseInt(transactionTimeoutStr);
} catch (NumberFormatException e) {
throw new InvalidConfigurationException("trantimeout is number " + transactionTimeoutStr);
}
}
final String journalStr = MetaData.getOptionalAttribute(element, JOURNAL_ATTRIBUTE);
if (journalStr != null) {
isJournal = Boolean.valueOf(journalStr).booleanValue();
}
final String suspendStr = MetaData.getOptionalAttribute(element, SUSPEND_ATTRIBUTE);
if (suspendStr != null) {
isSuspend = Boolean.valueOf(suspendStr).booleanValue();
}
final String stopStr = MetaData.getOptionalAttribute(element, STOP_ATTRIBUTE);
if (stopStr != null) {
isStop = Boolean.valueOf(stopStr).booleanValue();
}
final Iterator aliasElements = MetaData.getChildrenByTagName(element, ALIAS_ELEMENT);
while (aliasElements.hasNext()) {
aliasNames.add(MetaData.getUniqueAttribute((Element) aliasElements.next(), NAME_ATTRIBUTE));
}
final Iterator owElements = getChildrenByTagName(element, OVERRIDE_ELEMENT);
List overrideNameList = null;
while (owElements.hasNext()) {
Element owElement = (Element) owElements.next();
String overrideName = getUniqueAttribute(owElement, NAME_ATTRIBUTE);
if (overrideNameList == null) {
overrideNameList = new ArrayList();
}
overrideNameList.add(overrideName);
}
if (overrideNameList != null) {
overrideNames = (String[]) overrideNameList.toArray(new String[overrideNameList.size()]);
}
final Iterator inputDefElements = MetaData.getChildrenByTagName(element, INPUT_DEF_ELEMENT);
while (inputDefElements.hasNext()) {
final Element inputDefElement = (Element) inputDefElements.next();
final String name = MetaData.getUniqueAttribute(inputDefElement, NAME_ATTRIBUTE);
final String nullCheckAttribute = MetaData.getOptionalAttribute(inputDefElement, NULLCHECK_ATTRIBUTE);
boolean nullCheck = false;
if (nullCheckAttribute != null) {
nullCheck = Boolean.valueOf(nullCheckAttribute).booleanValue();
}
String val = MetaData.getElementContent(inputDefElement);
Property property = null;
if (val != null && val.length() != 0) {
try {
property = PropertyFactory.createProperty(val);
if (!nullCheck) {
property.setIgnoreNullProperty(true);
}
} catch (Exception e) {
throw new DeploymentException(e);
}
}
if (inputDefs == null) {
inputDefs = new HashMap();
}
inputDefs.put(name, property);
}
final ServiceNameEditor editor = new ServiceNameEditor();
final Iterator resourceElements = MetaData.getChildrenByTagName(element, RESOURCE_ELEMENT);
while (resourceElements.hasNext()) {
final Element resourceElement = (Element) resourceElements.next();
final String name = MetaData.getUniqueAttribute(resourceElement, NAME_ATTRIBUTE);
final String key = MetaData.getOptionalAttribute(resourceElement, KEY_ATTRIBUTE);
final String serviceNameStr = MetaData.getUniqueAttribute(resourceElement, SERVICE_ATTRIBUTE);
editor.setAsText(factoryCallBack.replaceProperty(serviceNameStr));
final ServiceName serviceName = (ServiceName) editor.getValue();
final boolean isTranControl = MetaData.getOptionalBooleanAttribute(resourceElement, TRANCONTROL_ATTRIBUTE);
final boolean isTranClose = MetaData.getOptionalBooleanAttribute(resourceElement, TRANCLOSE_ATTRIBUTE, true);
ResourceInfo resourceInfo = new ResourceInfo();
resourceInfo.name = name;
resourceInfo.key = key;
resourceInfo.serviceName = serviceName;
resourceInfo.isTranControl = isTranControl;
resourceInfo.isTranClose = isTranClose;
if (resources == null) {
resources = new HashMap();
}
resources.put(name, resourceInfo);
}
Iterator children = MetaData.getChildrenWithoutTagName(element, new String[] { ALIAS_ELEMENT, OVERRIDE_ELEMENT, INPUT_DEF_ELEMENT, RESOURCE_ELEMENT, CATCH_ELEMENT, FINALLY_ELEMENT });
boolean isReturn = false;
while (children.hasNext()) {
final Element currentElement = (Element) children.next();
final String tagName = currentElement.getTagName();
if (isReturn) {
throw new DeploymentException("Unreachable element : " + tagName);
}
Step stepObj = null;
if (STEP_ELEMENT.equals(tagName)) {
StepMetaData step = new StepMetaData(this, coverage);
step.importXML(currentElement);
stepObj = step;
} else if (CALL_FLOW_ELEMENT.equals(tagName)) {
CallFlowMetaData callFlowData = new CallFlowMetaData(this, coverage);
callFlowData.importXML(currentElement);
stepObj = callFlowData;
} else if (REPLY_ELEMENT.equals(tagName)) {
GetAsynchReplyMetaData replyData = new GetAsynchReplyMetaData(this, coverage);
replyData.importXML(currentElement);
stepObj = replyData;
} else if (SWITCH_ELEMENT.equals(tagName)) {
SwitchMetaData sw = new SwitchMetaData(this, coverage);
sw.importXML(currentElement);
stepObj = sw;
} else if (IF_ELEMENT.equals(tagName)) {
IfMetaData ifData = new IfMetaData(this, coverage);
ifData.importXML(currentElement);
stepObj = ifData;
} else if (FOR_ELEMENT.equals(tagName)) {
ForMetaData forData = new ForMetaData(this, coverage);
forData.importXML(currentElement);
stepObj = forData;
} else if (WHILE_ELEMENT.equals(tagName)) {
WhileMetaData whileData = new WhileMetaData(this, coverage);
whileData.importXML(currentElement);
stepObj = whileData;
} else if (RETURN_ELEMENT.equals(tagName)) {
ReturnMetaData returnData = new ReturnMetaData(this, coverage);
returnData.importXML(currentElement);
stepObj = returnData;
isReturn = true;
} else {
throw new DeploymentException("Invalid child tag of flow tag : " + tagName);
}
if (stepObj != null) {
if (jobSteps == null) {
jobSteps = new ArrayList();
}
jobSteps.add(stepObj);
}
}
final Iterator catchElements = MetaData.getChildrenByTagName(element, CATCH_ELEMENT);
while (catchElements.hasNext()) {
final Element catchElement = (Element) catchElements.next();
CatchMetaData step = new CatchMetaData(this, coverage);
step.importXML(catchElement);
if (catchSteps == null) {
catchSteps = new ArrayList();
}
catchSteps.add(step);
}
final Element finallyElement = MetaData.getOptionalChild(element, FINALLY_ELEMENT);
if (finallyElement != null) {
FinallyMetaData step = new FinallyMetaData(this, coverage);
step.importXML(finallyElement);
finallyStep = step;
}
stepNames = new HashSet();
if (inputDefs != null) {
stepNames.addAll(inputDefs.keySet());
}
if (jobSteps != null) {
for (int i = 0, max = jobSteps.size(); i < max; i++) {
Step jobStep = (Step) jobSteps.get(i);
jobStep.setupStepNames(stepNames);
}
}
} catch (InvalidConfigurationException e) {
e.setResourceName("flowName=" + flowName);
throw e;
} catch (DeploymentException e) {
e.setResourceName("flowName=" + flowName);
throw new InvalidConfigurationException("Invalid flow." + flowName, e);
}
journal = factoryCallBack.getJournal(this);
}
use of jp.ossc.nimbus.core.DeploymentException in project nimbus by nimbus-org.
the class DataSetCodeGenerator method loadDefinition.
public void loadDefinition(String definitionPath, InputStream definitionIn) throws DeploymentException {
try {
final InputSource inputSource = new InputSource(definitionIn);
final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setValidating(isValidate);
final DocumentBuilder builder = domFactory.newDocumentBuilder();
final NimbusEntityResolver resolver = new NimbusEntityResolver();
builder.setEntityResolver(resolver);
final MyErrorHandler handler = new MyErrorHandler(definitionPath);
builder.setErrorHandler(handler);
final Document doc = builder.parse(inputSource);
if (handler.isError()) {
throw new DeploymentException(ServiceManagerFactory.getMessageRecordFactory().findEmbedMessage("DSCG_00004", new Object[] { definitionPath }));
}
dataSetsData = new DataSetsMetaData();
dataSetsData.importXML(doc.getDocumentElement());
} catch (DeploymentException e) {
throw e;
} catch (Exception e) {
throw new DeploymentException(ServiceManagerFactory.getMessageRecordFactory().findEmbedMessage("DSCG_00004", new Object[] { definitionPath }), e);
}
}
Aggregations