001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2003-2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: ClientModifier.java 8270 2006-04-21 16:42:49Z sauthieg $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_ws.wsgen.modifier;
025:
026: import java.io.File;
027: import java.util.Iterator;
028: import java.util.List;
029: import java.util.jar.Attributes;
030:
031: import org.w3c.dom.Document;
032: import org.w3c.dom.Element;
033:
034: import org.objectweb.jonas_lib.genbase.GenBaseException;
035: import org.objectweb.jonas_lib.genbase.archive.Archive;
036: import org.objectweb.jonas_lib.genbase.archive.Client;
037: import org.objectweb.jonas_lib.genbase.modifier.ArchiveModifier;
038: import org.objectweb.jonas_lib.version.Version;
039:
040: import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc;
041: import org.objectweb.jonas_ws.wsgen.ddmodifier.WsClientDDModifier;
042: import org.objectweb.jonas_ws.wsgen.generator.Generator;
043: import org.objectweb.jonas_ws.wsgen.generator.GeneratorFactory;
044:
045: import org.objectweb.util.monolog.api.BasicLevel;
046:
047: /**
048: * Modify a given Client.
049: *
050: * @author Guillaume Sauthier
051: */
052: public class ClientModifier extends ArchiveModifier {
053:
054: /** client */
055: private Client client;
056:
057: /**
058: * Creates a new ClientModifier object.
059: *
060: * @param client Client Archive
061: */
062: public ClientModifier(Client client) {
063: super (client);
064: this .client = client;
065: }
066:
067: /**
068: * Modify the current archive and return a modified archive.
069: *
070: * @return a modified archive.
071: *
072: * @throws GenBaseException When Client Generation or storing phase fails.
073: */
074: public Archive modify() throws GenBaseException {
075:
076: getLogger().log(BasicLevel.INFO,
077: "Processing Client " + client.getName());
078:
079: // Update MANIFEST with Version Number
080: // used to say if WsGen has already been applied to this Module
081: Attributes main = this .client.getManifest().getMainAttributes();
082: main.put(new Attributes.Name(
083: WsGenModifierConstants.WSGEN_JONAS_VERSION_ATTR),
084: Version.getNumber());
085:
086: GeneratorFactory gf = GeneratorFactory.getInstance();
087: Document jclient = client.getJonasClientDoc();
088:
089: List refs = client.getServiceRefDescs();
090: for (Iterator i = refs.iterator(); i.hasNext();) {
091: ServiceRefDesc ref = (ServiceRefDesc) i.next();
092:
093: // create dd modifier
094: Element base = null;
095: if (jclient != null) {
096: base = jclient.getDocumentElement();
097: }
098: WsClientDDModifier ddm = new WsClientDDModifier(ref
099: .getServiceRefName(), jclient, base);
100:
101: // launch generation
102: Generator g = gf.newGenerator(ref, ddm, client);
103: g.generate();
104: g.compile();
105: // add files in web archive
106: g.addFiles(client);
107:
108: // update the Document if it was created
109: // in the meantime
110: jclient = ddm.getDocument();
111: }
112:
113: return save(gf.getConfiguration(), "clients" + File.separator
114: + client.getRootFile().getName());
115: }
116: }
|