Source Code Cross Referenced for Utils.java in  » Web-Services-AXIS2 » kernal » org » apache » axis2 » deployment » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Services AXIS2 » kernal » org.apache.axis2.deployment.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:        package org.apache.axis2.deployment.util;
020:
021:        import org.apache.axiom.om.OMAbstractFactory;
022:        import org.apache.axiom.om.OMElement;
023:        import org.apache.axiom.om.OMFactory;
024:        import org.apache.axis2.AxisFault;
025:        import org.apache.axis2.Constants;
026:        import org.apache.axis2.context.ConfigurationContext;
027:        import org.apache.axis2.deployment.DeploymentClassLoader;
028:        import org.apache.axis2.deployment.DeploymentException;
029:        import org.apache.axis2.deployment.repository.util.ArchiveReader;
030:        import org.apache.axis2.deployment.repository.util.DeploymentFileData;
031:        import org.apache.axis2.description.AxisModule;
032:        import org.apache.axis2.description.AxisOperation;
033:        import org.apache.axis2.description.AxisOperationFactory;
034:        import org.apache.axis2.description.AxisService;
035:        import org.apache.axis2.description.AxisServiceGroup;
036:        import org.apache.axis2.description.Flow;
037:        import org.apache.axis2.description.HandlerDescription;
038:        import org.apache.axis2.description.Parameter;
039:        import org.apache.axis2.description.java2wsdl.AnnotationConstants;
040:        import org.apache.axis2.description.java2wsdl.DefaultSchemaGenerator;
041:        import org.apache.axis2.description.java2wsdl.DocLitBareSchemaGenerator;
042:        import org.apache.axis2.description.java2wsdl.Java2WSDLConstants;
043:        import org.apache.axis2.description.java2wsdl.SchemaGenerator;
044:        import org.apache.axis2.engine.AxisConfiguration;
045:        import org.apache.axis2.engine.Handler;
046:        import org.apache.axis2.engine.MessageReceiver;
047:        import org.apache.axis2.util.Loader;
048:        import org.apache.axis2.wsdl.WSDLConstants;
049:        import org.apache.commons.logging.Log;
050:        import org.apache.commons.logging.LogFactory;
051:        import org.apache.ws.commons.schema.utils.NamespaceMap;
052:        import org.codehaus.jam.JAnnotation;
053:        import org.codehaus.jam.JMethod;
054:
055:        import javax.xml.namespace.QName;
056:        import java.io.BufferedReader;
057:        import java.io.File;
058:        import java.io.FileInputStream;
059:        import java.io.FileOutputStream;
060:        import java.io.IOException;
061:        import java.io.InputStream;
062:        import java.io.InputStreamReader;
063:        import java.io.OutputStreamWriter;
064:        import java.io.UnsupportedEncodingException;
065:        import java.lang.reflect.Method;
066:        import java.lang.reflect.Modifier;
067:        import java.net.MalformedURLException;
068:        import java.net.URL;
069:        import java.net.URLClassLoader;
070:        import java.net.URLDecoder;
071:        import java.util.ArrayList;
072:        import java.util.Collection;
073:        import java.util.HashMap;
074:        import java.util.Iterator;
075:        import java.util.LinkedList;
076:        import java.util.List;
077:        import java.util.Stack;
078:        import java.util.StringTokenizer;
079:        import java.util.zip.ZipEntry;
080:        import java.util.zip.ZipInputStream;
081:
082:        public class Utils {
083:
084:            public static String defaultEncoding = new OutputStreamWriter(
085:                    System.out).getEncoding();
086:
087:            private static Log log = LogFactory.getLog(Utils.class);
088:
089:            public static void addFlowHandlers(Flow flow, ClassLoader clsLoader)
090:                    throws AxisFault {
091:                int count = flow.getHandlerCount();
092:
093:                for (int j = 0; j < count; j++) {
094:                    HandlerDescription handlermd = flow.getHandler(j);
095:                    Class handlerClass;
096:                    Handler handler;
097:
098:                    handlerClass = getHandlerClass(handlermd.getClassName(),
099:                            clsLoader);
100:
101:                    try {
102:                        handler = (Handler) handlerClass.newInstance();
103:                        handler.init(handlermd);
104:                        handlermd.setHandler(handler);
105:                    } catch (InstantiationException e) {
106:                        throw AxisFault.makeFault(e);
107:                    } catch (IllegalAccessException e) {
108:                        throw AxisFault.makeFault(e);
109:                    }
110:                }
111:            }
112:
113:            public static void loadHandler(ClassLoader loader1,
114:                    HandlerDescription desc) throws DeploymentException {
115:                String handlername = desc.getClassName();
116:                Handler handler;
117:                Class handlerClass;
118:
119:                try {
120:                    handlerClass = Loader.loadClass(loader1, handlername);
121:                    if (handlerClass.getPackage().getName().equals(
122:                            "org.apache.axis2.engine")) {
123:                        String name = handlerClass.getName();
124:                        log.warn("Dispatcher " + name + " is now deprecated.");
125:                        if (name.indexOf("InstanceDispatcher") != -1) {
126:                            log
127:                                    .warn("Please remove the entry for "
128:                                            + handlerClass.getName()
129:                                            + "from axis2.xml");
130:                        } else {
131:                            log
132:                                    .warn("Please edit axis2.xml "
133:                                            + "and replace with the same class in org.apache.axis2.dispatchers package");
134:                        }
135:                    }
136:                    handler = (Handler) handlerClass.newInstance();
137:                    handler.init(desc);
138:                    desc.setHandler(handler);
139:                } catch (ClassNotFoundException e) {
140:                    throw new DeploymentException(e);
141:                } catch (Exception e) {
142:                    throw new DeploymentException(e);
143:                }
144:            }
145:
146:            public static URL[] getURLsForAllJars(URL url, File tmpDir) {
147:                try {
148:                    ArrayList array = new ArrayList();
149:                    InputStream in = url.openStream();
150:                    String fileName = url.getFile();
151:                    int index = fileName.lastIndexOf('/');
152:                    if (index != -1) {
153:                        fileName = fileName.substring(index + 1);
154:                    }
155:                    File f = createTempFile(fileName, in, tmpDir);
156:                    in.close();
157:                    ZipInputStream zin;
158:                    FileInputStream fin = new FileInputStream(f);
159:                    array.add(f.toURL());
160:                    zin = new ZipInputStream(fin);
161:
162:                    ZipEntry entry;
163:                    String entryName;
164:                    while ((entry = zin.getNextEntry()) != null) {
165:                        entryName = entry.getName();
166:                        /**
167:                         * id the entry name start with /lib and end with .jar
168:                         * then those entry name will be added to the arraylist
169:                         */
170:                        if ((entryName != null)
171:                                && entryName.toLowerCase().startsWith("lib/")
172:                                && entryName.toLowerCase().endsWith(".jar")) {
173:                            String suffix = entryName.substring(4);
174:                            f = createTempFile(suffix, zin, tmpDir);
175:                            array.add(f.toURL());
176:                        }
177:                    }
178:                    zin.close();
179:                    if (fin != null) {
180:                        fin.close();
181:                    }
182:                    return (URL[]) array.toArray(new URL[array.size()]);
183:                } catch (Exception e) {
184:                    throw new RuntimeException(e);
185:                }
186:            }
187:
188:            public static File createTempFile(String suffix, InputStream in,
189:                    File tmpDir) throws IOException {
190:                byte data[] = new byte[2048];
191:                int count;
192:                File f;
193:                if (tmpDir == null) {
194:                    new File(System.getProperty("java.io.tmpdir"), "_axis2")
195:                            .mkdirs();
196:                    File tempFile = new File(System
197:                            .getProperty("java.io.tmpdir"), "_axis2");
198:                    f = File.createTempFile("axis2", suffix, tempFile);
199:                } else {
200:                    f = File.createTempFile("axis2", suffix, tmpDir);
201:                }
202:                if (log.isDebugEnabled()) {
203:                    log.info("Created temporary file : " + f.getAbsolutePath());
204:                }
205:                f.deleteOnExit();
206:                FileOutputStream out = new FileOutputStream(f);
207:                while ((count = in.read(data, 0, 2048)) != -1) {
208:                    out.write(data, 0, count);
209:                }
210:                out.close();
211:                return f;
212:            }
213:
214:            public static ClassLoader getClassLoader(ClassLoader parent,
215:                    String path) throws DeploymentException {
216:                return getClassLoader(parent, new File(path));
217:            }
218:
219:            /**
220:             * Get a ClassLoader which contains a classpath of a) the passed directory and b) any jar
221:             * files inside the "lib/" or "Lib/" subdirectory of the passed directory.
222:             *
223:             * @param parent parent ClassLoader which will be the parent of the result of this method
224:             * @param file   a File which must be a directory for this to be useful
225:             * @return a new ClassLoader pointing to both the passed dir and jar files under lib/
226:             * @throws DeploymentException if problems occur
227:             */
228:            public static ClassLoader getClassLoader(ClassLoader parent,
229:                    File file) throws DeploymentException {
230:                URLClassLoader classLoader;
231:
232:                if (file == null)
233:                    return null; // Shouldn't this just return the parent?
234:
235:                try {
236:                    ArrayList urls = new ArrayList();
237:                    urls.add(file.toURL());
238:
239:                    // lower case directory name
240:                    File libfiles = new File(file, "lib");
241:                    if (libfiles.exists()) {
242:                        urls.add(libfiles.toURL());
243:                        File jarfiles[] = libfiles.listFiles();
244:                        for (int i = 0; i < jarfiles.length; i++) {
245:                            File jarfile = jarfiles[i];
246:                            if (jarfile.getName().endsWith(".jar")) {
247:                                urls.add(jarfile.toURL());
248:                            }
249:                        }
250:                    } else {
251:                        // upper case directory name
252:                        libfiles = new File(file, "Lib");
253:                        if (libfiles.exists()) {
254:                            urls.add(libfiles.toURL());
255:                            File jarfiles[] = libfiles.listFiles();
256:                            for (int i = 0; i < jarfiles.length; i++) {
257:                                File jarfile = jarfiles[i];
258:                                if (jarfile.getName().endsWith(".jar")) {
259:                                    urls.add(jarfile.toURL());
260:                                }
261:                            }
262:                        }
263:                    }
264:
265:                    URL urllist[] = new URL[urls.size()];
266:                    for (int i = 0; i < urls.size(); i++) {
267:                        urllist[i] = (URL) urls.get(i);
268:                    }
269:                    classLoader = new URLClassLoader(urllist, parent);
270:                    return classLoader;
271:                } catch (MalformedURLException e) {
272:                    throw new DeploymentException(e);
273:                }
274:            }
275:
276:            private static Class getHandlerClass(String className,
277:                    ClassLoader loader1) throws AxisFault {
278:                Class handlerClass;
279:
280:                try {
281:                    handlerClass = Loader.loadClass(loader1, className);
282:                } catch (ClassNotFoundException e) {
283:                    throw AxisFault.makeFault(e);
284:                }
285:
286:                return handlerClass;
287:            }
288:
289:            /**
290:             * This guy will create a AxisService using java reflection
291:             *
292:             * @param axisService       the target AxisService
293:             * @param axisConfig        the in-scope AxisConfiguration
294:             * @param excludeOperations a List of Strings (or null), each containing a method to exclude
295:             * @param nonRpcMethods     a List of Strings (or null), each containing a non-rpc method name
296:             * @throws Exception if a problem occurs
297:             */
298:            public static void fillAxisService(AxisService axisService,
299:                    AxisConfiguration axisConfig, ArrayList excludeOperations,
300:                    ArrayList nonRpcMethods) throws Exception {
301:                String serviceClass;
302:                Parameter implInfoParam = axisService
303:                        .getParameter(Constants.SERVICE_CLASS);
304:                ClassLoader serviceClassLoader = axisService.getClassLoader();
305:
306:                if (implInfoParam != null) {
307:                    serviceClass = (String) implInfoParam.getValue();
308:                } else {
309:                    // if Service_Class is null, every AbstractMR will look for
310:                    // ServiceObjectSupplier. This is user specific and may contain
311:                    // other looks.
312:                    implInfoParam = axisService
313:                            .getParameter(Constants.SERVICE_OBJECT_SUPPLIER);
314:                    if (implInfoParam != null) {
315:                        String className = ((String) implInfoParam.getValue())
316:                                .trim();
317:                        Class serviceObjectMaker = Loader.loadClass(
318:                                serviceClassLoader, className);
319:                        if (serviceObjectMaker.getModifiers() != Modifier.PUBLIC) {
320:                            throw new AxisFault("Service class " + className
321:                                    + " must have public as access Modifier");
322:                        }
323:
324:                        // Find static getServiceObject() method, call it if there
325:                        Method method = serviceObjectMaker.getMethod(
326:                                "getServiceObject",
327:                                new Class[] { AxisService.class });
328:                        Object obj = null;
329:                        if (method != null) {
330:                            obj = method.invoke(serviceObjectMaker
331:                                    .newInstance(),
332:                                    new Object[] { axisService });
333:                        }
334:                        if (obj == null) {
335:                            log
336:                                    .warn("ServiceObjectSupplier implmentation Object could not be found");
337:                            throw new DeploymentException(
338:                                    "ServiceClass or ServiceObjectSupplier implmentation Object could not be found");
339:                        }
340:                        serviceClass = obj.getClass().getName();
341:                    } else {
342:                        return;
343:                    }
344:                }
345:                // adding name spaces
346:                NamespaceMap map = new NamespaceMap();
347:                map.put(Java2WSDLConstants.AXIS2_NAMESPACE_PREFIX,
348:                        Java2WSDLConstants.AXIS2_XSD);
349:                map.put(Java2WSDLConstants.DEFAULT_SCHEMA_NAMESPACE_PREFIX,
350:                        Java2WSDLConstants.URI_2001_SCHEMA_XSD);
351:                axisService.setNameSpacesMap(map);
352:                SchemaGenerator schemaGenerator;
353:                Parameter generateBare = axisService
354:                        .getParameter(Java2WSDLConstants.DOC_LIT_BARE_PARAMETER);
355:                if (generateBare != null
356:                        && "true".equals(generateBare.getValue())) {
357:                    schemaGenerator = new DocLitBareSchemaGenerator(
358:                            serviceClassLoader, serviceClass.trim(),
359:                            axisService.getSchematargetNamespace(), axisService
360:                                    .getSchemaTargetNamespacePrefix(),
361:                            axisService);
362:                } else {
363:                    schemaGenerator = new DefaultSchemaGenerator(
364:                            serviceClassLoader, serviceClass.trim(),
365:                            axisService.getSchematargetNamespace(), axisService
366:                                    .getSchemaTargetNamespacePrefix(),
367:                            axisService);
368:                }
369:                schemaGenerator.setExcludeMethods(excludeOperations);
370:                schemaGenerator.setNonRpcMethods(nonRpcMethods);
371:                if (!axisService.isElementFormDefault()) {
372:                    schemaGenerator
373:                            .setElementFormDefault(Java2WSDLConstants.FORM_DEFAULT_UNQUALIFIED);
374:                }
375:                // package to namespace map
376:                schemaGenerator.setPkg2nsmap(axisService.getP2nMap());
377:                Collection schemas = schemaGenerator.generateSchema();
378:                axisService.addSchema(schemas);
379:                axisService.setSchemaTargetNamespace(schemaGenerator
380:                        .getSchemaTargetNameSpace());
381:                axisService.setTypeTable(schemaGenerator.getTypeTable());
382:                if (Java2WSDLConstants.DEFAULT_TARGET_NAMESPACE
383:                        .equals(axisService.getTargetNamespace())) {
384:                    axisService.setTargetNamespace(schemaGenerator
385:                            .getTargetNamespace());
386:                }
387:
388:                JMethod[] method = schemaGenerator.getMethods();
389:                PhasesInfo pinfo = axisConfig.getPhasesInfo();
390:
391:                for (int i = 0; i < method.length; i++) {
392:                    JMethod jmethod = method[i];
393:                    String opName = jmethod.getSimpleName();
394:                    AxisOperation operation = axisService
395:                            .getOperation(new QName(opName));
396:                    // if the operation there in services.xml then try to set it schema element name
397:                    if (operation == null) {
398:                        operation = axisService.getOperation(new QName(jmethod
399:                                .getSimpleName()));
400:                    }
401:                    MessageReceiver mr = axisService
402:                            .getMessageReceiver(operation
403:                                    .getMessageExchangePattern());
404:                    if (mr != null) {
405:                    } else {
406:                        mr = axisConfig.getMessageReceiver(operation
407:                                .getMessageExchangePattern());
408:                    }
409:                    if (operation.getMessageReceiver() == null) {
410:                        operation.setMessageReceiver(mr);
411:                    }
412:                    pinfo.setOperationPhases(operation);
413:                    axisService.addOperation(operation);
414:                    if (operation.getSoapAction() == null) {
415:                        operation.setSoapAction("urn:" + opName);
416:                    }
417:                }
418:            }
419:
420:            public static AxisOperation getAxisOperationForJmethod(
421:                    JMethod jmethod) throws AxisFault {
422:                AxisOperation operation;
423:                if (jmethod.getReturnType().isVoidType()) {
424:                    if (jmethod.getExceptionTypes().length > 0) {
425:                        operation = AxisOperationFactory
426:                                .getAxisOperation(WSDLConstants.MEP_CONSTANT_ROBUST_IN_ONLY);
427:                    } else {
428:                        operation = AxisOperationFactory
429:                                .getAxisOperation(WSDLConstants.MEP_CONSTANT_IN_ONLY);
430:                    }
431:                } else {
432:                    operation = AxisOperationFactory
433:                            .getAxisOperation(WSDLConstants.MEP_CONSTANT_IN_OUT);
434:                }
435:                String opName = jmethod.getSimpleName();
436:                operation.setName(new QName(opName));
437:                JAnnotation methodAnnon = jmethod
438:                        .getAnnotation(AnnotationConstants.WEB_METHOD);
439:                if (methodAnnon != null) {
440:                    String action = methodAnnon.getValue(
441:                            AnnotationConstants.ACTION).asString();
442:                    if (action != null && !"".equals(action)) {
443:                        operation.setSoapAction(action);
444:                    }
445:                }
446:                return operation;
447:            }
448:
449:            public static OMElement getParameter(String name, String value,
450:                    boolean locked) {
451:                OMFactory fac = OMAbstractFactory.getOMFactory();
452:                OMElement parameter = fac.createOMElement("parameter", null);
453:                parameter.addAttribute("name", name, null);
454:                parameter
455:                        .addAttribute("locked", Boolean.toString(locked), null);
456:                parameter.setText(value);
457:                return parameter;
458:            }
459:
460:            /**
461:             * This method is to get the list of services there in a module
462:             * if module want to add services then the way of doing that is
463:             * 1. Add a directory called services inside the module (both in mar case and expanded case)
464:             * 2. Then add a services.list file into that directory adding all the modules
465:             * you want to add
466:             * 3. Then put all the services into services directory in the module
467:             * 4. All the class is module can be access via a the module services.
468:             */
469:
470:            public static void deployModuleServices(AxisModule module,
471:                    ConfigurationContext configCtx) throws AxisFault {
472:                try {
473:                    AxisConfiguration axisConfig = configCtx
474:                            .getAxisConfiguration();
475:                    ArchiveReader archiveReader = new ArchiveReader();
476:                    PhasesInfo phasesInfo = axisConfig.getPhasesInfo();
477:                    ClassLoader moduleClassLoader = module
478:                            .getModuleClassLoader();
479:                    ArrayList services = new ArrayList();
480:                    InputStream in = moduleClassLoader
481:                            .getResourceAsStream("aars/aars.list");
482:                    if (in != null) {
483:                        BufferedReader input;
484:                        try {
485:                            input = new BufferedReader(
486:                                    new InputStreamReader(in));
487:                            String line;
488:                            while ((line = input.readLine()) != null) {
489:                                line = line.trim();
490:                                if (line.length() > 0 && line.charAt(0) != '#') {
491:                                    services.add(line);
492:                                }
493:                            }
494:                            input.close();
495:                        } catch (IOException ex) {
496:                            ex.printStackTrace();
497:                        }
498:                    }
499:                    if (services.size() > 0) {
500:                        for (int i = 0; i < services.size(); i++) {
501:                            String servicename = (String) services.get(i);
502:                            if (servicename == null || "".equals(servicename)) {
503:                                continue;
504:                            }
505:                            InputStream fin = moduleClassLoader
506:                                    .getResourceAsStream("aars/" + servicename);
507:                            if (fin == null) {
508:                                throw new AxisFault(
509:                                        "No service archive found : "
510:                                                + servicename);
511:                            }
512:                            File inputFile = Utils
513:                                    .createTempFile(
514:                                            servicename,
515:                                            fin,
516:                                            (File) axisConfig
517:                                                    .getParameterValue(Constants.Configuration.ARTIFACTS_TEMP_DIR));
518:                            DeploymentFileData filedata = new DeploymentFileData(
519:                                    inputFile);
520:
521:                            filedata
522:                                    .setClassLoader(
523:                                            false,
524:                                            moduleClassLoader,
525:                                            (File) axisConfig
526:                                                    .getParameterValue(Constants.Configuration.ARTIFACTS_TEMP_DIR));
527:                            HashMap wsdlservice = archiveReader
528:                                    .processWSDLs(filedata);
529:                            if (wsdlservice != null && wsdlservice.size() > 0) {
530:                                Iterator servicesitr = wsdlservice.values()
531:                                        .iterator();
532:                                while (servicesitr.hasNext()) {
533:                                    AxisService service = (AxisService) servicesitr
534:                                            .next();
535:                                    Iterator operations = service
536:                                            .getOperations();
537:                                    while (operations.hasNext()) {
538:                                        AxisOperation axisOperation = (AxisOperation) operations
539:                                                .next();
540:                                        phasesInfo
541:                                                .setOperationPhases(axisOperation);
542:                                    }
543:                                }
544:                            }
545:                            AxisServiceGroup serviceGroup = new AxisServiceGroup(
546:                                    axisConfig);
547:                            serviceGroup.setServiceGroupClassLoader(filedata
548:                                    .getClassLoader());
549:                            ArrayList serviceList = archiveReader
550:                                    .processServiceGroup(filedata
551:                                            .getAbsolutePath(), filedata,
552:                                            serviceGroup, false, wsdlservice,
553:                                            configCtx);
554:                            for (int j = 0; j < serviceList.size(); j++) {
555:                                AxisService axisService = (AxisService) serviceList
556:                                        .get(j);
557:                                Parameter moduleService = new Parameter();
558:                                moduleService.setValue("true");
559:                                moduleService
560:                                        .setName(AxisModule.MODULE_SERVICE);
561:                                axisService.addParameter(moduleService);
562:                                serviceGroup.addService(axisService);
563:                            }
564:                            axisConfig.addServiceGroup(serviceGroup);
565:                            fin.close();
566:                        }
567:                    }
568:                } catch (IOException e) {
569:                    throw AxisFault.makeFault(e);
570:                }
571:            }
572:
573:            /**
574:             * Normalize a uri containing ../ and ./ paths.
575:             *
576:             * @param uri The uri path to normalize
577:             * @return The normalized uri
578:             */
579:            public static String normalize(String uri) {
580:                if ("".equals(uri)) {
581:                    return uri;
582:                }
583:                int leadingSlashes = 0;
584:                for (leadingSlashes = 0; leadingSlashes < uri.length()
585:                        && uri.charAt(leadingSlashes) == '/'; ++leadingSlashes) {
586:                }
587:                boolean isDir = (uri.charAt(uri.length() - 1) == '/');
588:                StringTokenizer st = new StringTokenizer(uri, "/");
589:                LinkedList clean = new LinkedList();
590:                while (st.hasMoreTokens()) {
591:                    String token = st.nextToken();
592:                    if ("..".equals(token)) {
593:                        if (!clean.isEmpty() && !"..".equals(clean.getLast())) {
594:                            clean.removeLast();
595:                            if (!st.hasMoreTokens()) {
596:                                isDir = true;
597:                            }
598:                        } else {
599:                            clean.add("..");
600:                        }
601:                    } else if (!".".equals(token) && !"".equals(token)) {
602:                        clean.add(token);
603:                    }
604:                }
605:                StringBuffer sb = new StringBuffer();
606:                while (leadingSlashes-- > 0) {
607:                    sb.append('/');
608:                }
609:                for (Iterator it = clean.iterator(); it.hasNext();) {
610:                    sb.append(it.next());
611:                    if (it.hasNext()) {
612:                        sb.append('/');
613:                    }
614:                }
615:                if (isDir && sb.length() > 0
616:                        && sb.charAt(sb.length() - 1) != '/') {
617:                    sb.append('/');
618:                }
619:                return sb.toString();
620:            }
621:
622:            public static String getPath(String parent, String childPath) {
623:                Stack parentStack = new Stack();
624:                Stack childStack = new Stack();
625:                if (parent != null) {
626:                    String[] values = parent.split("/");
627:                    if (values.length > 0) {
628:                        for (int i = 0; i < values.length; i++) {
629:                            String value = values[i];
630:                            parentStack.push(value);
631:                        }
632:                    }
633:                }
634:                String[] values = childPath.split("/");
635:                if (values.length > 0) {
636:                    for (int i = 0; i < values.length; i++) {
637:                        String value = values[i];
638:                        childStack.push(value);
639:                    }
640:                }
641:                String filepath = "";
642:                while (!childStack.isEmpty()) {
643:                    String value = (String) childStack.pop();
644:                    if ("..".equals(value)) {
645:                        parentStack.pop();
646:                    } else if (!"".equals(value)) {
647:                        if ("".equals(filepath)) {
648:                            filepath = value;
649:                        } else {
650:                            filepath = value + "/" + filepath;
651:                        }
652:                    }
653:                }
654:                while (!parentStack.isEmpty()) {
655:                    String value = (String) parentStack.pop();
656:                    if (!"".equals(value)) {
657:                        filepath = value + "/" + filepath;
658:                    }
659:                }
660:                return filepath;
661:            }
662:
663:            /**
664:             * Searches for jar files inside /lib dirctory. If there are any, the
665:             * names of those jar files will be added to the array list
666:             */
667:            public static List findLibJars(URL url) {
668:                ArrayList embedded_jars = new ArrayList();
669:                try {
670:                    ZipInputStream zin = new ZipInputStream(url.openStream());
671:                    ZipEntry entry;
672:                    String entryName = "";
673:                    while ((entry = zin.getNextEntry()) != null) {
674:                        entryName = entry.getName();
675:                        /**
676:                         * if the entry name start with /lib and ends with .jar
677:                         * add it to the the arraylist
678:                         */
679:                        if (entryName != null
680:                                && (entryName.startsWith("lib/") || entryName
681:                                        .startsWith("Lib/"))
682:                                && entryName.endsWith(".jar")) {
683:                            embedded_jars.add(entryName);
684:                        }
685:                    }
686:                    zin.close();
687:                } catch (Exception e) {
688:                    throw new RuntimeException(e);
689:                }
690:                return embedded_jars;
691:            }
692:
693:            /**
694:             * To add the exclude method when generating scheams , here the exclude methods
695:             * will be session releated axis2 methods
696:             */
697:            public static void addExcludeMethods(ArrayList excludeList) {
698:                excludeList.add("init");
699:                excludeList.add("setOperationContext");
700:                excludeList.add("startUp");
701:                excludeList.add("destroy");
702:                excludeList.add("shutDown");
703:            }
704:
705:            public static ClassLoader createClassLoader(URL[] urls,
706:                    ClassLoader serviceClassLoader, boolean extractJars,
707:                    File tmpDir) {
708:                if (extractJars) {
709:                    try {
710:                        URL[] urls1 = Utils.getURLsForAllJars(urls[0], tmpDir);
711:                        return new DeploymentClassLoader(urls1, null,
712:                                serviceClassLoader);
713:                    } catch (Exception e) {
714:                        log
715:                                .warn("Exception extracting jars into temporary directory : "
716:                                        + e.getMessage()
717:                                        + " : switching to alternate class loading mechanism");
718:                        log.debug(e.getMessage(), e);
719:                    }
720:                }
721:                List embedded_jars = Utils.findLibJars(urls[0]);
722:                return new DeploymentClassLoader(urls, embedded_jars,
723:                        serviceClassLoader);
724:            }
725:
726:            public static File toFile(URL url)
727:                    throws UnsupportedEncodingException {
728:                String path = URLDecoder.decode(url.getPath(), defaultEncoding);
729:                File file = new File(path.replace('/', File.separatorChar)
730:                        .replace('|', ':'));
731:                return file;
732:            }
733:
734:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.