001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.config;
017:
018: import org.apache.openejb.OpenEJBException;
019: import org.apache.openejb.loader.SystemInstance;
020: import org.apache.openejb.jee.EjbJar;
021: import org.apache.openejb.jee.JaxbJavaee;
022: import org.apache.openejb.jee.oejb3.JaxbOpenejbJar3;
023: import org.apache.openejb.jee.oejb3.OpenejbJar;
024: import org.apache.openejb.util.LogCategory;
025: import org.apache.openejb.util.Logger;
026:
027: import javax.xml.bind.JAXBException;
028: import java.io.BufferedOutputStream;
029: import java.io.File;
030: import java.io.FileOutputStream;
031:
032: /**
033: * @version $Rev: 609116 $ $Date: 2008-01-05 02:04:19 -0800 $
034: */
035: public class OutputGeneratedDescriptors implements DynamicDeployer {
036: private static final Logger logger = Logger.getInstance(
037: LogCategory.OPENEJB_STARTUP_CONFIG,
038: "org.apache.openejb.util.resources");
039: private static final String OUTPUT_DESCRIPTORS = "openejb.descriptors.output";
040:
041: public AppModule deploy(AppModule appModule)
042: throws OpenEJBException {
043: boolean output = SystemInstance.get().getProperty(
044: OUTPUT_DESCRIPTORS, "false").equalsIgnoreCase("true");
045:
046: for (EjbModule ejbModule : appModule.getEjbModules()) {
047:
048: output = ejbModule.getOpenejbJar().getProperties()
049: .getProperty(OUTPUT_DESCRIPTORS, output + "")
050: .equalsIgnoreCase("true");
051:
052: if (output) {
053: if (ejbModule.getEjbJar() != null) {
054: writeEjbJar(ejbModule);
055: }
056:
057: if (ejbModule.getOpenejbJar() != null) {
058: writeOpenejbJar(ejbModule);
059: }
060: }
061: }
062:
063: return appModule;
064: }
065:
066: private void writeOpenejbJar(EjbModule ejbModule) {
067: try {
068: OpenejbJar openejbJar = ejbModule.getOpenejbJar();
069: File tempFile = File.createTempFile("openejb-jar-",
070: ejbModule.getModuleId() + ".xml");
071: FileOutputStream fout = new FileOutputStream(tempFile);
072: BufferedOutputStream out = new BufferedOutputStream(fout);
073: try {
074: JaxbOpenejbJar3.marshal(OpenejbJar.class, openejbJar,
075: out);
076: logger.info("Dumping Generated openejb-jar.xml to: "
077: + tempFile.getAbsolutePath());
078: } catch (JAXBException e) {
079: } finally {
080: out.close();
081: }
082: } catch (Exception e) {
083: }
084: }
085:
086: private void writeEjbJar(EjbModule ejbModule) {
087: try {
088: EjbJar ejbJar = ejbModule.getEjbJar();
089: File tempFile = File.createTempFile("ejb-jar-", ejbModule
090: .getModuleId()
091: + ".xml");
092: FileOutputStream fout = new FileOutputStream(tempFile);
093: BufferedOutputStream out = new BufferedOutputStream(fout);
094: try {
095: JaxbJavaee.marshal(EjbJar.class, ejbJar, out);
096: logger.info("Dumping Generated ejb-jar.xml to: "
097: + tempFile.getAbsolutePath());
098: } catch (JAXBException e) {
099: } finally {
100: out.close();
101: }
102: } catch (Exception e) {
103: }
104: }
105: }
|