Source Code Cross Referenced for UpdaterImpl.java in  » ESB » open-esb » com » sun » jbi » management » registry » xml » 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 » ESB » open esb » com.sun.jbi.management.registry.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * BEGIN_HEADER - DO NOT EDIT
0003:         *
0004:         * The contents of this file are subject to the terms
0005:         * of the Common Development and Distribution License
0006:         * (the "License").  You may not use this file except
0007:         * in compliance with the License.
0008:         *
0009:         * You can obtain a copy of the license at
0010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
0011:         * See the License for the specific language governing
0012:         * permissions and limitations under the License.
0013:         *
0014:         * When distributing Covered Code, include this CDDL
0015:         * HEADER in each file and include the License file at
0016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
0017:         * If applicable add the following below this CDDL HEADER,
0018:         * with the fields enclosed by brackets "[]" replaced with
0019:         * your own identifying information: Portions Copyright
0020:         * [year] [name of copyright owner]
0021:         */
0022:
0023:        /*
0024:         * @(#)UpdaterImpl.java
0025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
0026:         *
0027:         * END_HEADER - DO NOT EDIT
0028:         */
0029:        /**
0030:         *  UpdaterImpl.java
0031:         *
0032:         *  SUN PROPRIETARY/CONFIDENTIAL.
0033:         *  This software is the proprietary information of Sun Microsystems, Inc.
0034:         *  Use is subject to license terms.
0035:         *
0036:         *  Created on August 23, 2006, 5:17 PM
0037:         */package com.sun.jbi.management.registry.xml;
0038:
0039:        import java.io.File;
0040:
0041:        import java.math.BigInteger;
0042:
0043:        import java.util.Calendar;
0044:        import java.util.List;
0045:        import java.util.ArrayList;
0046:        import java.util.Map;
0047:        import java.util.HashMap;
0048:        import java.util.Properties;
0049:        import java.util.Set;
0050:        import java.util.logging.Logger;
0051:
0052:        import com.sun.jbi.StringTranslator;
0053:        import com.sun.jbi.management.ConfigurationCategory;
0054:        import com.sun.jbi.management.registry.Registry;
0055:        import com.sun.jbi.management.registry.RegistryException;
0056:        import com.sun.jbi.management.repository.ArchiveType;
0057:        import com.sun.jbi.management.LocalStringKeys;
0058:        import com.sun.jbi.management.system.ManagementContext;
0059:        import com.sun.jbi.management.system.ManagementException;
0060:        import com.sun.jbi.management.util.LockManager;
0061:
0062:        import com.sun.jbi.ComponentInfo;
0063:        import com.sun.jbi.ComponentState;
0064:        import com.sun.jbi.ServiceUnitInfo;
0065:        import com.sun.jbi.ServiceAssemblyInfo;
0066:        import com.sun.jbi.ServiceAssemblyState;
0067:        import com.sun.jbi.ServiceUnitState;
0068:
0069:        import javax.xml.bind.JAXBException;
0070:
0071:        /**
0072:         * This class encapsulates queries which are common to 
0073:         * all targets ( domain / server / cluster ).
0074:         *
0075:         * @author Sun Microsystems, Inc.
0076:         */
0077:        public class UpdaterImpl implements 
0078:                com.sun.jbi.management.registry.Updater {
0079:
0080:            private Jbi mJbiRegistry;
0081:            private RegistryImpl mRegistry;
0082:            private boolean mValidate;
0083:            private ManagementContext mMgtCtx;
0084:            private Logger mLogger;
0085:            private StringTranslator mTranslator;
0086:            private GenericQueryImpl mGenQuery;
0087:            private ObjectFactory mObjectFactory;
0088:            private String mThisTarget;
0089:            private LockManager mRegObjLM;
0090:
0091:            public UpdaterImpl(Jbi jbi, ManagementContext mgtCtx,
0092:                    boolean validate, RegistryImpl registry)
0093:                    throws RegistryException {
0094:                mJbiRegistry = jbi;
0095:                mRegistry = registry;
0096:                mValidate = validate;
0097:                mMgtCtx = mgtCtx;
0098:                mLogger = mMgtCtx.getLogger();
0099:                mTranslator = mMgtCtx.getEnvironmentContext()
0100:                        .getStringTranslator("com.sun.jbi.management");
0101:
0102:                mGenQuery = (GenericQueryImpl) mRegistry.getGenericQuery();
0103:
0104:                mObjectFactory = new ObjectFactory();
0105:                mRegObjLM = registry.getRegistryObjectLockManager();
0106:                mThisTarget = mMgtCtx.getEnvironmentContext()
0107:                        .getPlatformContext().getTargetName();
0108:            }
0109:
0110:            /*--------------------------------------------------------------------------------*\
0111:             *                          Add / Remove Entities                                 *
0112:            \*--------------------------------------------------------------------------------*/
0113:
0114:            /**
0115:             * Add a component to the runtime target
0116:             *
0117:             * @param componentInfo - component instance
0118:             * @throws RegistryException on errors
0119:             */
0120:            public void addComponent(ComponentInfo componentInfo)
0121:                    throws RegistryException {
0122:                addComponent(mThisTarget, componentInfo);
0123:            }
0124:
0125:            /**
0126:             * Add a domain component
0127:             * 
0128:             * @param componentName - name of the component
0129:             * @param fileName      - component file name
0130:             */
0131:            public void addComponent(String componentName, String fileName,
0132:                    Calendar timestamp) throws RegistryException {
0133:                mRegObjLM.acquireWriteLock();
0134:                try {
0135:                    Components compType = mJbiRegistry.getComponents();
0136:
0137:                    if (compType == null) {
0138:                        compType = mObjectFactory.createComponents();
0139:                        mJbiRegistry.setComponents(compType);
0140:                    }
0141:
0142:                    DomainComponentType component = mObjectFactory
0143:                            .createDomainComponentType();
0144:                    component.setName(componentName);
0145:                    component.setFileName(fileName);
0146:                    component.setTimestamp(java.math.BigInteger
0147:                            .valueOf(timestamp.getTimeInMillis()));
0148:                    compType.getComponent().add(component);
0149:                } catch (Exception jex) {
0150:                    mRegObjLM.releaseWriteLock();
0151:                    throw new RegistryException(jex);
0152:                }
0153:                commit();
0154:            }
0155:
0156:            /**
0157:             * Add a component to a given target. If target = DOMAIN, then a simple component 
0158:             * entry is created with the component name. If the target = SERVER / CLUSTER
0159:             * a component-ref is added.
0160:             *
0161:             * @param targetName - {'domain', 'server', "instance-name", "cluster-name"}
0162:             * not considered when targetType = DOMAIN.
0163:             * @param componentInfo - component instance
0164:             * @throws RegistryException on errors
0165:             */
0166:            public void addComponent(String targetName,
0167:                    ComponentInfo componentInfo) throws RegistryException {
0168:                boolean updated = false;
0169:                mRegObjLM.acquireWriteLock();
0170:                try {
0171:                    if (mGenQuery.isTargetServer(targetName)) {
0172:                        List<InstalledComponentsListType> servers = mJbiRegistry
0173:                                .getServers().getServer();
0174:
0175:                        for (InstalledComponentsListType server : servers) {
0176:                            if (server.getNameRef().equals(targetName)) {
0177:                                addComponentRef(componentInfo, server);
0178:                                updated = true;
0179:                                break;
0180:                            }
0181:                        }
0182:
0183:                    } else if (mGenQuery.isTargetCluster(targetName)) {
0184:                        List<InstalledComponentsListType> clusters = mJbiRegistry
0185:                                .getClusters().getCluster();
0186:
0187:                        for (InstalledComponentsListType cluster : clusters) {
0188:                            if (cluster.getNameRef().equals(targetName)) {
0189:                                addComponentRef(componentInfo, cluster);
0190:                                updated = true;
0191:                                break;
0192:                            }
0193:                        }
0194:                    } else {
0195:                        throw new RegistryException(mTranslator.getString(
0196:                                LocalStringKeys.JBI_ADMIN_UNKNOWN_TARGET,
0197:                                targetName));
0198:                    }
0199:                } catch (RegistryException re) {
0200:                    mRegObjLM.releaseWriteLock();
0201:                    throw re;
0202:                } catch (RuntimeException rte) {
0203:                    mRegObjLM.releaseWriteLock();
0204:                    throw rte;
0205:                }
0206:                if (updated) {
0207:                    commit();
0208:                }
0209:            }
0210:
0211:            /**
0212:             * Remove a component from the runtime's target
0213:             *
0214:             * @param componentName - component name
0215:             * @throws RegistryException on errors
0216:             */
0217:            public void removeComponent(String componentName)
0218:                    throws RegistryException {
0219:                removeComponent(mThisTarget, componentName);
0220:            }
0221:
0222:            /**
0223:             * Remove a component from a given target. 
0224:             *
0225:             * @param targetName - {'domain', 'server', "instance-name", "cluster-name"}
0226:             * @param componentName - component name
0227:             * @throws RegistryException on errors
0228:             */
0229:            public void removeComponent(String targetName, String componentName)
0230:                    throws RegistryException {
0231:                mRegObjLM.acquireWriteLock();
0232:                try {
0233:                    if (mGenQuery.isTargetDomain(targetName)) {
0234:                        deleteComponent(componentName);
0235:                        mGenQuery.removeComponentFromCache(componentName);
0236:                    } else if (mGenQuery.isTargetServer(targetName)) {
0237:                        List<InstalledComponentsListType> servers = mJbiRegistry
0238:                                .getServers().getServer();
0239:
0240:                        for (InstalledComponentsListType server : servers) {
0241:                            if (server.getNameRef().equals(targetName)) {
0242:                                removeComponentRef(componentName, server);
0243:                            }
0244:                        }
0245:                    } else if (mGenQuery.isTargetCluster(targetName)) {
0246:                        List<InstalledComponentsListType> clusters = mJbiRegistry
0247:                                .getClusters().getCluster();
0248:
0249:                        for (InstalledComponentsListType cluster : clusters) {
0250:                            if (cluster.getNameRef().equals(targetName)) {
0251:                                removeComponentRef(componentName, cluster);
0252:                            }
0253:                        }
0254:                    } else {
0255:                        throw new RegistryException(mTranslator.getString(
0256:                                LocalStringKeys.JBI_ADMIN_UNKNOWN_TARGET,
0257:                                targetName));
0258:                    }
0259:                } catch (RegistryException re) {
0260:                    mRegObjLM.releaseWriteLock();
0261:                    throw re;
0262:                } catch (RuntimeException rte) {
0263:                    mRegObjLM.releaseWriteLock();
0264:                    throw rte;
0265:                }
0266:                commit();
0267:            }
0268:
0269:            /** 
0270:             * Add a shared library to he runtime's target
0271:             *
0272:             * @param ComponentInfo - shared library info
0273:             * @throws RegistryException on errors
0274:             */
0275:            public void addSharedLibrary(ComponentInfo sharedLibraryInfo)
0276:                    throws RegistryException {
0277:                addSharedLibrary(mThisTarget, sharedLibraryInfo);
0278:            }
0279:
0280:            /**
0281:             * Add a domain shared library
0282:             * 
0283:             * @param slName        - name of the shared library
0284:             * @param fileName      - component file name
0285:             */
0286:            public void addSharedLibrary(String slName, String fileName,
0287:                    Calendar timestamp) throws RegistryException {
0288:                mRegObjLM.acquireWriteLock();
0289:                try {
0290:                    SharedLibraries slType = mJbiRegistry.getSharedLibraries();
0291:
0292:                    if (slType == null) {
0293:                        slType = mObjectFactory.createSharedLibraries();
0294:                        mJbiRegistry.setSharedLibraries(slType);
0295:                    }
0296:
0297:                    DomainSharedLibraryType sharedLibrary = mObjectFactory
0298:                            .createDomainSharedLibraryType();
0299:                    sharedLibrary.setName(slName);
0300:                    sharedLibrary.setFileName(fileName);
0301:                    sharedLibrary.setTimestamp(java.math.BigInteger
0302:                            .valueOf(timestamp.getTimeInMillis()));
0303:                    slType.getSharedLibrary().add(sharedLibrary);
0304:                } catch (Exception jex) {
0305:                    mRegObjLM.releaseWriteLock();
0306:                    throw new RegistryException(jex);
0307:                }
0308:                commit();
0309:            }
0310:
0311:            /** 
0312:             * Add a shared library to a given target. If target = DOMAIN, then a simple  
0313:             * entry is created with the library name. If the target = SERVER / CLUSTER
0314:             * a shared-library-ref is added.
0315:             *
0316:             * @param targetName - {'domain', 'server', "instance-name", "cluster-name"}
0317:             * @param ComponentInfo - shared library info
0318:             * @throws RegistryException on errors
0319:             */
0320:            public void addSharedLibrary(String targetName,
0321:                    ComponentInfo sharedLibraryInfo) throws RegistryException {
0322:                mRegObjLM.acquireWriteLock();
0323:                try {
0324:                    if (mGenQuery.isTargetDomain(targetName)) {
0325:                        addSharedLibrary(sharedLibraryInfo.getName(),
0326:                                "unknown", null);
0327:                    } else if (mGenQuery.isTargetServer(targetName)) {
0328:                        List<InstalledComponentsListType> servers = mJbiRegistry
0329:                                .getServers().getServer();
0330:
0331:                        for (InstalledComponentsListType server : servers) {
0332:                            if (server.getNameRef().equals(targetName)) {
0333:                                addSharedLibraryRef(sharedLibraryInfo, server);
0334:                            }
0335:                        }
0336:                    } else if (mGenQuery.isTargetCluster(targetName)) {
0337:
0338:                        List<InstalledComponentsListType> clusters = mJbiRegistry
0339:                                .getClusters().getCluster();
0340:
0341:                        for (InstalledComponentsListType cluster : clusters) {
0342:                            if (cluster.getNameRef().equals(targetName)) {
0343:                                addSharedLibraryRef(sharedLibraryInfo, cluster);
0344:                            }
0345:                        }
0346:                    } else {
0347:                        throw new RegistryException(mTranslator.getString(
0348:                                LocalStringKeys.JBI_ADMIN_UNKNOWN_TARGET,
0349:                                targetName));
0350:                    }
0351:                } catch (RegistryException re) {
0352:                    mRegObjLM.releaseWriteLock();
0353:                    throw re;
0354:                } catch (RuntimeException rte) {
0355:                    mRegObjLM.releaseWriteLock();
0356:                    throw rte;
0357:                }
0358:                commit();
0359:            }
0360:
0361:            /** 
0362:             * Remove a shared library from the runtimes target
0363:             *
0364:             * @param sharedLibraryName - shared library name
0365:             * @throws RegistryException on errors
0366:             */
0367:            public void removeSharedLibrary(String sharedLibraryName)
0368:                    throws RegistryException {
0369:                removeSharedLibrary(mThisTarget, sharedLibraryName);
0370:            }
0371:
0372:            /** 
0373:             * Remove a shared library from a given target.
0374:             *
0375:             * @param targetName - {'domain', 'server', "instance-name", "cluster-name"}
0376:             * @param sharedLibraryName - shared library name
0377:             * @throws RegistryException on errors
0378:             */
0379:            public void removeSharedLibrary(String targetName,
0380:                    String sharedLibraryName) throws RegistryException {
0381:                mRegObjLM.acquireWriteLock();
0382:                try {
0383:                    if (mGenQuery.isTargetDomain(targetName)) {
0384:                        deleteSharedLibrary(sharedLibraryName);
0385:                        mGenQuery
0386:                                .removeSharedLibraryFromCache(sharedLibraryName);
0387:                    } else if (mGenQuery.isTargetServer(targetName)) {
0388:                        List<InstalledComponentsListType> servers = mJbiRegistry
0389:                                .getServers().getServer();
0390:
0391:                        for (InstalledComponentsListType server : servers) {
0392:                            if (server.getNameRef().equals(targetName)) {
0393:                                removeSharedLibraryRef(sharedLibraryName,
0394:                                        server);
0395:                            }
0396:                        }
0397:                    } else if (mGenQuery.isTargetCluster(targetName)) {
0398:                        List<InstalledComponentsListType> clusters = mJbiRegistry
0399:                                .getClusters().getCluster();
0400:
0401:                        for (InstalledComponentsListType cluster : clusters) {
0402:                            if (cluster.getNameRef().equals(targetName)) {
0403:                                removeSharedLibraryRef(sharedLibraryName,
0404:                                        cluster);
0405:                            }
0406:                        }
0407:                    } else {
0408:                        throw new RegistryException(mTranslator.getString(
0409:                                LocalStringKeys.JBI_ADMIN_UNKNOWN_TARGET,
0410:                                targetName));
0411:                    }
0412:                } catch (RegistryException re) {
0413:                    mRegObjLM.releaseWriteLock();
0414:                    throw re;
0415:                } catch (RuntimeException rte) {
0416:                    mRegObjLM.releaseWriteLock();
0417:                    throw rte;
0418:                }
0419:                commit();
0420:            }
0421:
0422:            /** 
0423:             * Add a service assembly to the runtime's target
0424:             *
0425:             * @param saName - service assembly name 
0426:             * @throws RegistryException on errors
0427:             */
0428:            public void addServiceAssembly(String saName)
0429:                    throws RegistryException {
0430:                addServiceAssembly(mThisTarget, saName);
0431:            }
0432:
0433:            /**
0434:             * Add a service assembly to the domain.
0435:             *
0436:             * @param saName - service assembly name
0437:             * @param fileName - service assembly archive name
0438:             * @throws RegistryException on errors
0439:             */
0440:            public void addServiceAssembly(String saName, String fileName,
0441:                    Calendar timestamp) throws RegistryException {
0442:                mRegObjLM.acquireWriteLock();
0443:                try {
0444:                    ServiceAssemblies saType = mJbiRegistry
0445:                            .getServiceAssemblies();
0446:
0447:                    if (saType == null) {
0448:                        saType = mObjectFactory.createServiceAssemblies();
0449:                        mJbiRegistry.setServiceAssemblies(saType);
0450:                    }
0451:
0452:                    DomainEntityType serviceAssembly = mObjectFactory
0453:                            .createDomainEntityType();
0454:                    serviceAssembly.setName(saName);
0455:                    serviceAssembly.setFileName(fileName);
0456:                    serviceAssembly.setTimestamp(java.math.BigInteger
0457:                            .valueOf(timestamp.getTimeInMillis()));
0458:                    saType.getServiceAssembly().add(serviceAssembly);
0459:                } catch (Exception jex) {
0460:                    mRegObjLM.releaseWriteLock();
0461:                    throw new RegistryException(jex);
0462:                }
0463:                commit();
0464:            }
0465:
0466:            /** 
0467:             * Add a service assembly to a given target. If target = DOMAIN, then a simple  
0468:             * entry is created with the assembly name. If the target = SERVER / CLUSTER
0469:             * a service-assembly--ref is added.
0470:             *
0471:             * @param targetName - {'domain', 'server', "instance-name", "cluster-name"}
0472:             * @param saName - service assembly name 
0473:             * @throws RegistryException on errors
0474:             */
0475:            public void addServiceAssembly(String targetName, String saName)
0476:                    throws RegistryException {
0477:                mRegObjLM.acquireWriteLock();
0478:                try {
0479:                    if (mGenQuery.isTargetDomain(targetName)) {
0480:                        addServiceAssembly(saName, "unknown", null);
0481:                    } else if (mGenQuery.isTargetServer(targetName)) {
0482:                        List<InstalledComponentsListType> servers = mJbiRegistry
0483:                                .getServers().getServer();
0484:
0485:                        for (InstalledComponentsListType server : servers) {
0486:                            if (server.getNameRef().equals(targetName)) {
0487:                                addServiceAssemblyRef(saName, server);
0488:                            }
0489:                        }
0490:                    } else if (mGenQuery.isTargetCluster(targetName)) {
0491:
0492:                        List<InstalledComponentsListType> clusters = mJbiRegistry
0493:                                .getClusters().getCluster();
0494:
0495:                        for (InstalledComponentsListType cluster : clusters) {
0496:                            if (cluster.getNameRef().equals(targetName)) {
0497:                                addServiceAssemblyRef(saName, cluster);
0498:                            }
0499:                        }
0500:                    } else {
0501:                        throw new RegistryException(mTranslator.getString(
0502:                                LocalStringKeys.JBI_ADMIN_UNKNOWN_TARGET,
0503:                                targetName));
0504:                    }
0505:                } catch (RegistryException re) {
0506:                    mRegObjLM.releaseWriteLock();
0507:                    throw re;
0508:                } catch (RuntimeException rte) {
0509:                    mRegObjLM.releaseWriteLock();
0510:                    throw rte;
0511:                }
0512:                commit();
0513:            }
0514:
0515:            /** 
0516:             * Remove a service assembly from the runtime target
0517:             *
0518:             * @param saName - service assembly name
0519:             * @throws RegistryException on errors
0520:             */
0521:            public void removeServiceAssembly(String saName)
0522:                    throws RegistryException {
0523:                removeServiceAssembly(mThisTarget, saName);
0524:            }
0525:
0526:            /** 
0527:             * Remove a service assembly from a given target.
0528:             *
0529:             * @param targetName - {'domain', 'server', "instance-name", "cluster-name"}
0530:             * @param saName - service assembly name
0531:             * @throws RegistryException on errors
0532:             */
0533:            public void removeServiceAssembly(String targetName, String saName)
0534:                    throws RegistryException {
0535:                mRegObjLM.acquireWriteLock();
0536:                try {
0537:                    if (mGenQuery.isTargetDomain(targetName)) {
0538:                        deleteServiceAssembly(saName);
0539:                        mGenQuery.removeServiceAssemblyFromCache(saName);
0540:                    } else if (mGenQuery.isTargetServer(targetName)) {
0541:                        List<InstalledComponentsListType> servers = mJbiRegistry
0542:                                .getServers().getServer();
0543:
0544:                        for (InstalledComponentsListType server : servers) {
0545:                            if (server.getNameRef().equals(targetName)) {
0546:                                removeServiceAssemblyRef(saName, server);
0547:                            }
0548:                        }
0549:                    } else if (mGenQuery.isTargetCluster(targetName)) {
0550:                        List<InstalledComponentsListType> clusters = mJbiRegistry
0551:                                .getClusters().getCluster();
0552:
0553:                        for (InstalledComponentsListType cluster : clusters) {
0554:                            if (cluster.getNameRef().equals(targetName)) {
0555:                                removeServiceAssemblyRef(saName, cluster);
0556:                            }
0557:                        }
0558:                    } else {
0559:                        throw new RegistryException(mTranslator.getString(
0560:                                LocalStringKeys.JBI_ADMIN_UNKNOWN_TARGET,
0561:                                targetName));
0562:                    }
0563:                } catch (RegistryException re) {
0564:                    mRegObjLM.releaseWriteLock();
0565:                    throw re;
0566:                } catch (RuntimeException rte) {
0567:                    mRegObjLM.releaseWriteLock();
0568:                    throw rte;
0569:                }
0570:                commit();
0571:            }
0572:
0573:            /**
0574:             * @param serverNameRef - server name to be added
0575:             */
0576:            public void addServer(String serverNameRef)
0577:                    throws RegistryException {
0578:                try {
0579:                    if (!mGenQuery.isTargetServer(serverNameRef)
0580:                            && !mGenQuery.isTargetCluster(serverNameRef)) {
0581:                        mRegObjLM.acquireWriteLock();
0582:                        try {
0583:                            ServerListType servers = mJbiRegistry.getServers();
0584:
0585:                            if (servers == null) {
0586:                                servers = mObjectFactory.createServerListType();
0587:                                mJbiRegistry.setServers(servers);
0588:                            }
0589:
0590:                            InstalledComponentsListType server = mObjectFactory
0591:                                    .createInstalledComponentsListType();
0592:                            server.setNameRef(serverNameRef);
0593:
0594:                            mJbiRegistry.getServers().getServer().add(server);
0595:                        } catch (RuntimeException rte) {
0596:                            mRegObjLM.releaseWriteLock();
0597:                            throw rte;
0598:                        }
0599:                        commit();
0600:                    } else {
0601:                        throw new RegistryException(mTranslator.getString(
0602:                                LocalStringKeys.JBI_ADMIN_DUPLICATE_TARGET,
0603:                                serverNameRef));
0604:                    }
0605:                } catch (Exception jex) {
0606:                    throw new RegistryException(jex);
0607:                }
0608:            }
0609:
0610:            /**
0611:             * @param serverNameRef - server name to be removed
0612:             */
0613:            public void removeServer(String serverNameRef)
0614:                    throws RegistryException {
0615:                mRegObjLM.acquireWriteLock();
0616:                try {
0617:                    InstalledComponentsListType serverToDel = null;
0618:
0619:                    List<InstalledComponentsListType> servers = mJbiRegistry
0620:                            .getServers().getServer();
0621:
0622:                    for (InstalledComponentsListType server : servers) {
0623:                        if (server.getNameRef().equals(serverNameRef)) {
0624:                            serverToDel = server;
0625:                        }
0626:                    }
0627:
0628:                    if (serverToDel != null) {
0629:                        servers.remove(serverToDel);
0630:                    }
0631:                } catch (RuntimeException rte) {
0632:                    mRegObjLM.releaseWriteLock();
0633:                    throw rte;
0634:                }
0635:
0636:                commit();
0637:            }
0638:
0639:            /**
0640:             * @param clusterNameRef - cluster name to be added
0641:             */
0642:            public void addCluster(String clusterNameRef)
0643:                    throws RegistryException {
0644:                try {
0645:                    if (!mGenQuery.isTargetServer(clusterNameRef)
0646:                            && !mGenQuery.isTargetCluster(clusterNameRef)) {
0647:                        mRegObjLM.acquireWriteLock();
0648:                        try {
0649:                            ClusterListType clusters = mJbiRegistry
0650:                                    .getClusters();
0651:
0652:                            if (clusters == null) {
0653:                                clusters = mObjectFactory
0654:                                        .createClusterListType();
0655:                                mJbiRegistry.setClusters(clusters);
0656:                            }
0657:
0658:                            InstalledComponentsListType cluster = mObjectFactory
0659:                                    .createInstalledComponentsListType();
0660:                            cluster.setNameRef(clusterNameRef);
0661:                            mJbiRegistry.getClusters().getCluster()
0662:                                    .add(cluster);
0663:                        } catch (RuntimeException rte) {
0664:                            mRegObjLM.releaseWriteLock();
0665:                            throw rte;
0666:                        }
0667:                        commit();
0668:                    } else {
0669:                        throw new RegistryException(mTranslator.getString(
0670:                                LocalStringKeys.JBI_ADMIN_DUPLICATE_TARGET,
0671:                                clusterNameRef));
0672:                    }
0673:                } catch (Exception jex) {
0674:                    throw new RegistryException(jex);
0675:                }
0676:            }
0677:
0678:            /**
0679:             * @param clusterNameRef - cluster name to be removed
0680:             */
0681:            public void removeCluster(String clusterNameRef)
0682:                    throws RegistryException {
0683:                mRegObjLM.acquireWriteLock();
0684:                try {
0685:                    InstalledComponentsListType clusterToDel = null;
0686:
0687:                    List<InstalledComponentsListType> clusters = mJbiRegistry
0688:                            .getClusters().getCluster();
0689:
0690:                    for (InstalledComponentsListType cluster : clusters) {
0691:                        if (cluster.getNameRef().equals(clusterNameRef)) {
0692:                            clusterToDel = cluster;
0693:                        }
0694:                    }
0695:
0696:                    if (clusterToDel != null) {
0697:                        clusters.remove(clusterToDel);
0698:                    }
0699:                } catch (RuntimeException rte) {
0700:                    mRegObjLM.releaseWriteLock();
0701:                    throw rte;
0702:                }
0703:
0704:                commit();
0705:            }
0706:
0707:            /*--------------------------------------------------------------------------------*\
0708:             *                   Operations to update entries                                 *
0709:            \*--------------------------------------------------------------------------------*/
0710:
0711:            /**
0712:             * Set the file name for the domain component.
0713:             */
0714:            public void setComponentFileName(String fileName,
0715:                    String componentName) throws RegistryException {
0716:
0717:                DomainEntityType comp = mGenQuery.getComponent(componentName);
0718:
0719:                if (comp != null) {
0720:                    mRegObjLM.acquireWriteLock();
0721:                    try {
0722:                        comp.setFileName(fileName);
0723:                    } catch (RuntimeException rte) {
0724:                        mRegObjLM.releaseWriteLock();
0725:                        throw rte;
0726:                    }
0727:                    commit();
0728:                }
0729:            }
0730:
0731:            /**
0732:             * Set the file name for the domain service assembly.         
0733:             */
0734:            public void setSharedLibraryFileName(String fileName, String slName)
0735:                    throws RegistryException {
0736:                DomainEntityType sl = mGenQuery.getSharedLibrary(slName);
0737:
0738:                if (sl != null) {
0739:                    mRegObjLM.acquireWriteLock();
0740:                    try {
0741:                        sl.setFileName(fileName);
0742:                    } catch (RuntimeException rte) {
0743:                        mRegObjLM.releaseWriteLock();
0744:                        throw rte;
0745:                    }
0746:                    commit();
0747:                }
0748:            }
0749:
0750:            /**
0751:             * Set the file name for the domain service assembly
0752:             */
0753:            public void setServiceAssemblyFileName(String fileName,
0754:                    String saName) throws RegistryException {
0755:                DomainEntityType sa = mGenQuery.getServiceAssembly(saName);
0756:
0757:                if (sa != null) {
0758:                    mRegObjLM.acquireWriteLock();
0759:                    try {
0760:                        sa.setFileName(fileName);
0761:                    } catch (RuntimeException rte) {
0762:                        mRegObjLM.releaseWriteLock();
0763:                        throw rte;
0764:                    }
0765:                    commit();
0766:                }
0767:            }
0768:
0769:            /**
0770:             * Set the state of a component for the target at runtime.
0771:             *
0772:             * @param componentName - component name
0773:             * @param state  - the state to set. 
0774:             * @throws RegistryException on errors
0775:             */
0776:            public void setComponentState(ComponentState state,
0777:                    String componentName) throws RegistryException {
0778:                setComponentState(mThisTarget, state, componentName);
0779:            }
0780:
0781:            /**
0782:             * Set the state of a component in a server/cluster.
0783:             *
0784:             * @param targetName - either the server-name or cluster-name
0785:             * @param componentName - component name
0786:             * @param state  - the state to set. 
0787:             * @throws RegistryException on errors
0788:             */
0789:            public void setComponentState(String targetName,
0790:                    ComponentState state, String componentName)
0791:                    throws RegistryException {
0792:                ComponentRefType comp = mGenQuery.getComponent(componentName,
0793:                        targetName);
0794:
0795:                if (comp != null) {
0796:                    mRegObjLM.acquireWriteLock();
0797:                    try {
0798:                        mLogger.finest("Setting component " + componentName
0799:                                + " to " + state.toString() + " for target "
0800:                                + targetName);
0801:                        comp.setState(LifeCycleStatusEnum.fromValue(state
0802:                                .toString()));
0803:                    } catch (RuntimeException rte) {
0804:                        mRegObjLM.releaseWriteLock();
0805:                        throw rte;
0806:                    }
0807:                    commit();
0808:                }
0809:            }
0810:
0811:            /**
0812:             * Set the properties of a component in a server/cluster.
0813:             *
0814:             * @param targetName - either the server-name or cluster-name, this operation is 
0815:             *        a no-op  when target = domain.
0816:             * @param componentName - component name
0817:             * @param props  - the properties to set. 
0818:             * @throws RegistryException on errors
0819:             */
0820:            public void setComponentProperties(String targetName,
0821:                    Map<String, String> props, String componentName)
0822:                    throws RegistryException {
0823:                try {
0824:                    ComponentRefType comp = mGenQuery.getComponent(
0825:                            componentName, targetName == null ? mThisTarget
0826:                                    : targetName);
0827:
0828:                    mRegObjLM.acquireWriteLock();
0829:                    try {
0830:                        List<PropertyType> properties = comp.getProperty();
0831:                        int numProps = props.size();
0832:
0833:                        java.util.Iterator itr = props.keySet().iterator();
0834:
0835:                        while (itr.hasNext()) {
0836:                            PropertyType prop = mObjectFactory
0837:                                    .createPropertyType();
0838:
0839:                            String key = (String) itr.next();
0840:                            prop.setName(key);
0841:                            prop.setValue(props.get(key));
0842:                        }
0843:                    } catch (RuntimeException rte) {
0844:                        mRegObjLM.releaseWriteLock();
0845:                        throw rte;
0846:                    }
0847:                    commit();
0848:                } catch (Exception jex) {
0849:                    throw new RegistryException(jex);
0850:                }
0851:            }
0852:
0853:            /**
0854:             * Set the state of a ServiceUnit for the runtime target.
0855:             *
0856:             * @param componentName - component name
0857:             * @param suName - service unit name
0858:             * @param state  - the state to set. 
0859:             * @throws RegistryException on errors
0860:             */
0861:            public void setServiceUnitState(ServiceUnitState state,
0862:                    String componentName, String suName)
0863:                    throws RegistryException {
0864:                setServiceUnitState(mThisTarget, state, componentName, suName);
0865:            }
0866:
0867:            /**
0868:             * Set the state of a ServiceUnit in a server / cluster.
0869:             *
0870:             * @param targetName - either the value 'domain', 'server' or the
0871:             * server-name or cluster-name.
0872:             * @param componentName - component name
0873:             * @param suName - service unit name
0874:             * @param state  - the state to set. 
0875:             * @throws RegistryException on errors
0876:             */
0877:            public void setServiceUnitState(String targetName,
0878:                    ServiceUnitState state, String componentName, String suName)
0879:                    throws RegistryException {
0880:                ComponentRefType compRef = mGenQuery.getComponent(
0881:                        componentName, targetName);
0882:                boolean updated = false;
0883:
0884:                mRegObjLM.acquireWriteLock();
0885:                try {
0886:                    ServiceUnitListType suListType = compRef.getServiceUnits();
0887:
0888:                    if (suListType != null) {
0889:                        List<ServiceUnitType> suList = suListType
0890:                                .getServiceUnit();
0891:
0892:                        for (ServiceUnitType su : suList) {
0893:                            if (su.getName().equals(suName)) {
0894:                                su.setState(LifeCycleStatusEnum.fromValue(state
0895:                                        .toString()));
0896:                            }
0897:                        }
0898:                        updated = true;
0899:                    }
0900:                } catch (RuntimeException rte) {
0901:                    mRegObjLM.releaseWriteLock();
0902:                    throw rte;
0903:                }
0904:
0905:                if (updated) {
0906:                    commit();
0907:                } else {
0908:                    mRegObjLM.releaseWriteLock();
0909:                }
0910:            }
0911:
0912:            /**
0913:             * Set the state of a ServiceAssembly for the runtime target.
0914:             *
0915:             * @param state  - the state to set.
0916:             * @param saName - the service assembly name
0917:             * @throws RegistryException on errors
0918:             */
0919:            public void setServiceAssemblyState(ServiceAssemblyState state,
0920:                    String saName) throws RegistryException {
0921:                setServiceAssemblyState(mThisTarget, state, saName);
0922:            }
0923:
0924:            /**
0925:             * Set the state of a ServiceAssembly in a server / cluster.
0926:             *
0927:             * @param targetName - either the value 'domain', 'server' or the
0928:             * server-name or cluster-name.
0929:             * @param saName - service assembly name
0930:             * @param state  - the state to set.
0931:             * @throws RegistryException on errors
0932:             */
0933:            public void setServiceAssemblyState(String targetName,
0934:                    ServiceAssemblyState state, String saName)
0935:                    throws RegistryException {
0936:                ServiceAssemblyRefType sa = mGenQuery.getServiceAssembly(
0937:                        saName, targetName);
0938:
0939:                if (sa != null) {
0940:                    mRegObjLM.acquireWriteLock();
0941:                    try {
0942:                        mLogger.finest("Setting service assembly " + saName
0943:                                + " state to " + state.toString()
0944:                                + " for target " + targetName);
0945:                        sa.setState(LifeCycleStatusEnum.fromValue(state
0946:                                .toString()));
0947:                    } catch (RuntimeException rte) {
0948:                        mRegObjLM.releaseWriteLock();
0949:                        throw rte;
0950:                    }
0951:                    commit();
0952:                }
0953:            }
0954:
0955:            /**
0956:             * Add a ServiceUnit to a Component for the runtime target
0957:             *
0958:             * @param suInfo - ServiceUnitInfo
0959:             * @param componentName - component name
0960:             * @throws RegistryException on errors
0961:             */
0962:            public void addServiceUnitToComponent(String componentName,
0963:                    ServiceUnitInfo suInfo) throws RegistryException {
0964:                addServiceUnitToComponent(mThisTarget, componentName, suInfo);
0965:            }
0966:
0967:            /**
0968:             * Add a ServiceUnit to a Component
0969:             *
0970:             * @param suInfo - ServiceUnitInfo
0971:             * @param targetName - either the value 'domain', 'server' or the
0972:             * server-name or cluster-name.
0973:             * @param componentName - component name
0974:             * @throws RegistryException on errors
0975:             */
0976:            public void addServiceUnitToComponent(String targetName,
0977:                    String componentName, ServiceUnitInfo suInfo)
0978:                    throws RegistryException {
0979:                try {
0980:                    ComponentRefType compRef = mGenQuery.getComponent(
0981:                            componentName, targetName);
0982:                    if (compRef == null) {
0983:                        String errMsg = mTranslator
0984:                                .getString(
0985:                                        LocalStringKeys.JBI_ADMIN_COMPONENT_MISSING_IN_REGISTRY,
0986:                                        componentName);
0987:                        mLogger.warning(errMsg);
0988:                        throw new RegistryException(errMsg);
0989:                    }
0990:
0991:                    mRegObjLM.acquireWriteLock();
0992:                    try {
0993:                        ServiceUnitListType suListType = compRef
0994:                                .getServiceUnits();
0995:
0996:                        if (suListType == null) {
0997:                            suListType = mObjectFactory
0998:                                    .createServiceUnitListType();
0999:                            compRef.setServiceUnits(suListType);
1000:                        }
1001:                        List<ServiceUnitType> suList = suListType
1002:                                .getServiceUnit();
1003:
1004:                        for (ServiceUnitType su : suList) {
1005:                            if (su.getName().equals(suInfo.getName())) {
1006:                                throw new RegistryException(
1007:                                        mTranslator
1008:                                                .getString(
1009:                                                        LocalStringKeys.JBI_ADMIN_CANNOT_ADD_DUPLICATE_SU,
1010:                                                        suInfo.getName(),
1011:                                                        componentName,
1012:                                                        targetName));
1013:                            }
1014:                        }
1015:                        suList.add(ObjectTranslator
1016:                                .getJaxbServiceUnitType(suInfo));
1017:                    } catch (RegistryException re) {
1018:                        mRegObjLM.releaseWriteLock();
1019:                        throw re;
1020:                    } catch (RuntimeException rte) {
1021:                        mRegObjLM.releaseWriteLock();
1022:                        throw rte;
1023:                    }
1024:                    commit();
1025:
1026:                } catch (JAXBException jex) {
1027:                    throw new RegistryException(jex);
1028:                }
1029:            }
1030:
1031:            /**
1032:             * Remove a ServiceUnit from a Component for the runtime target
1033:             *
1034:             * @param suName - ServiceUnitInfo name
1035:             * @param componentName - component name
1036:             * @throws RegistryException on errors
1037:             */
1038:            public void removeServiceUnitFromComponent(String componentName,
1039:                    String suName) throws RegistryException {
1040:                removeServiceUnitFromComponent(mThisTarget, componentName,
1041:                        suName);
1042:            }
1043:
1044:            /**
1045:             * Remove a ServiceUnit from a Component
1046:             *
1047:             * @param suName - ServiceUnitInfo name
1048:             * @param targetName - the server-name or cluster-name.
1049:             * @param componentName - component name
1050:             * @throws RegistryException on errors
1051:             */
1052:            public void removeServiceUnitFromComponent(String targetName,
1053:                    String componentName, String suName)
1054:                    throws RegistryException {
1055:                ComponentRefType compRef = mGenQuery.getComponent(
1056:                        componentName, targetName);
1057:                boolean updated = false;
1058:
1059:                mRegObjLM.acquireWriteLock();
1060:                try {
1061:                    ServiceUnitListType suListType = compRef.getServiceUnits();
1062:
1063:                    if (suListType != null) {
1064:                        ServiceUnitType suToDel = null;
1065:                        List<ServiceUnitType> suList = suListType
1066:                                .getServiceUnit();
1067:
1068:                        for (ServiceUnitType su : suList) {
1069:                            if (su.getName().equals(suName)) {
1070:                                suToDel = su;
1071:                            }
1072:                        }
1073:                        suList.remove(suToDel);
1074:                        updated = true;
1075:                    }
1076:                } catch (RuntimeException rte) {
1077:                    mRegObjLM.releaseWriteLock();
1078:                    throw rte;
1079:                }
1080:                if (updated) {
1081:                    commit();
1082:                } else {
1083:                    mRegObjLM.releaseWriteLock();
1084:                }
1085:            }
1086:
1087:            /*--------------------------------------------------------------------------------*\
1088:             *                   Set configuration attributes                                 *
1089:            \*--------------------------------------------------------------------------------*/
1090:
1091:            /**
1092:             * Set the value of a configuration attribute belonging to the
1093:             * specified category, for the runtime target. 
1094:             *
1095:             * @param type - configuration category 
1096:             * @param name - identification for the attribute
1097:             * @param value - string representation of the attribute value
1098:             * @exception RegistryException on errors in getting the attribute value
1099:             */
1100:            public void setAttribute(ConfigurationCategory type, String name,
1101:                    String value) throws RegistryException {
1102:                setAttribute(mThisTarget, type, name, value);
1103:            }
1104:
1105:            /**
1106:             * Get the value of a configuration attribute belonging to the
1107:             * specified category, for the runtime target. 
1108:             *
1109:             * @param targetName - target instance/cluster name.
1110:             * @param type - configuration category 
1111:             * @param name - identification for the attribute
1112:             * @param value - string representation of the attribute value
1113:             * @exception RegistryException on errors in getting the attribute value
1114:             */
1115:            public void setAttribute(String targetName,
1116:                    ConfigurationCategory type, String name, String value)
1117:                    throws RegistryException {
1118:                ObjectFactory factory = new ObjectFactory();
1119:                mRegObjLM.acquireWriteLock();
1120:
1121:                try {
1122:                    // If attribute is already overriden then just set it,
1123:                    // If not then might need to add a new target config/category/property
1124:                    if (mGenQuery.isAttributeOverriden(targetName, type, name)) {
1125:                        ConfigCategoryType category = mGenQuery
1126:                                .getConfigCategory(targetName, type);
1127:
1128:                        List<PropertyType> props = category.getProperty();
1129:
1130:                        for (PropertyType prop : props) {
1131:                            if (prop.getName().equals(name)) {
1132:                                prop.setValue(value);
1133:                            }
1134:                        }
1135:                    } else {
1136:                        // Add the attribute ( and config, config-type if need be )
1137:                        ConfigType configType = mGenQuery.getConfig(targetName);
1138:                        if (configType == null) {
1139:                            configType = factory.createConfigType();
1140:                            configType.setName(mGenQuery
1141:                                    .getConfigName(targetName));
1142:                            if (mJbiRegistry.getConfigs() == null) {
1143:                                mJbiRegistry
1144:                                        .setConfigs(factory.createConfigs());
1145:                            }
1146:                            mJbiRegistry.getConfigs().getConfig().add(
1147:                                    configType);
1148:                        }
1149:
1150:                        ConfigCategoryType category = mGenQuery
1151:                                .getConfigCategory(targetName, type);
1152:
1153:                        if (category == null) {
1154:                            // Add the category
1155:                            List<ConfigCategoryType> categoryList = configType
1156:                                    .getConfigType();
1157:                            category = factory.createConfigCategoryType();
1158:                            category.setCategory(ConfigTypeEnum.fromValue(type
1159:                                    .toString()));
1160:                            categoryList.add(category);
1161:                        }
1162:                        List<PropertyType> props = category.getProperty();
1163:                        PropertyType newProp = factory.createPropertyType();
1164:                        newProp.setName(name);
1165:                        newProp.setValue(value);
1166:                        props.add(newProp);
1167:                    }
1168:                } catch (RuntimeException rte) {
1169:                    mRegObjLM.releaseWriteLock();
1170:                    throw rte;
1171:                }
1172:                commit();
1173:            }
1174:
1175:            /**
1176:             * Delete the named attribute from the category if it exists, for the implicit target
1177:             * The attribute is deleted only if it is overriden for the target, if target is "domain"
1178:             * the attribute is not deleted.
1179:             *
1180:             * @param type - configuration category 
1181:             * @param name - identification for the attribute
1182:             * @exception RegistryException on errors in getting the attribute value
1183:             */
1184:            public void deleteAttribute(ConfigurationCategory type, String name)
1185:                    throws RegistryException {
1186:                deleteAttribute(mThisTarget, type, name);
1187:            }
1188:
1189:            /**
1190:             * Delete the named attribute from the category if it exists.
1191:             * The attribute is deleted only if it is overriden for the target, if target is "domain"
1192:             * the attribute is not deleted.
1193:             *
1194:             * @param targetName - target instance/cluster name.
1195:             * @param type - configuration category 
1196:             * @param name - identification for the attribute
1197:             * @exception RegistryException on errors in getting the attribute value
1198:             */
1199:            public void deleteAttribute(String targetName,
1200:                    ConfigurationCategory type, String name)
1201:                    throws RegistryException {
1202:                if (!(mGenQuery.isTargetServer(targetName) || mGenQuery
1203:                        .isTargetCluster(targetName))) {
1204:                    // nothing to do for target="domain".
1205:                    return;
1206:                }
1207:
1208:                ObjectFactory factory = new ObjectFactory();
1209:                mRegObjLM.acquireWriteLock();
1210:
1211:                try {
1212:                    // If attribute is overriden then only delete it,
1213:                    if (mGenQuery.isAttributeOverriden(targetName, type, name)) {
1214:                        ConfigCategoryType category = mGenQuery
1215:                                .getConfigCategory(targetName, type);
1216:
1217:                        List<PropertyType> props = category.getProperty();
1218:                        PropertyType propToDelete = null;
1219:                        for (PropertyType prop : props) {
1220:                            if (prop.getName().equals(name)) {
1221:                                propToDelete = prop;
1222:                                break;
1223:                            }
1224:                        }
1225:                        if (propToDelete != null) {
1226:                            props.remove(propToDelete);
1227:                        }
1228:                    }
1229:                } catch (RuntimeException rte) {
1230:                    mRegObjLM.releaseWriteLock();
1231:                    throw rte;
1232:                }
1233:                commit();
1234:            }
1235:
1236:            /**
1237:             * This method is used to set the upgrade-number attribute in the domain 
1238:             * level entry for a component
1239:             * @param componentName the component name
1240:             * @param upgradeNumber the update number
1241:             * @throws RegistryException if the update number could not be set
1242:             */
1243:            public void setComponentUpgradeNumber(String componentName,
1244:                    java.math.BigInteger upgradeNumber)
1245:                    throws RegistryException {
1246:                mRegObjLM.acquireWriteLock();
1247:                try {
1248:                    Components compType = mJbiRegistry.getComponents();
1249:
1250:                    if (compType != null) {
1251:                        List<DomainComponentType> components = compType
1252:                                .getComponent();
1253:                        for (DomainComponentType component : components) {
1254:                            if (component.getName().equals(componentName)) {
1255:                                component.setUpgradeNumber(upgradeNumber);
1256:                                break;
1257:                            }
1258:                        }
1259:                    }
1260:                } catch (RuntimeException rte) {
1261:                    mRegObjLM.releaseWriteLock();
1262:                    throw rte;
1263:                }
1264:                commit();
1265:            }
1266:
1267:            /**
1268:             * This method is used to correct timestamps on system components on the DAS if they
1269:             * are not already set. Typically this only happens the first time an installation
1270:             * starts after install or upgrade.
1271:             */
1272:            public void correctTimestamps() throws RegistryException {
1273:                mRegObjLM.acquireWriteLock();
1274:                try {
1275:                    //
1276:                    //  Check components first.
1277:                    //
1278:                    Components compType = mJbiRegistry.getComponents();
1279:
1280:                    if (compType != null) {
1281:                        List<DomainComponentType> components = compType
1282:                                .getComponent();
1283:                        for (DomainComponentType component : components) {
1284:                            if (component.getTimestamp().equals(
1285:                                    BigInteger.valueOf(0))) {
1286:                                long timestamp = 0;
1287:                                String filename;
1288:                                File file;
1289:
1290:                                filename = mRegistry.getRepository()
1291:                                        .findArchive(ArchiveType.COMPONENT,
1292:                                                component.getName());
1293:                                file = new File(filename);
1294:                                timestamp = file.lastModified();
1295:                                component.setTimestamp(BigInteger
1296:                                        .valueOf(timestamp));
1297:                            }
1298:                        }
1299:                    }
1300:
1301:                    //
1302:                    //  Next check shared libraries.
1303:                    //
1304:                    SharedLibraries slType = mJbiRegistry.getSharedLibraries();
1305:                    if (slType != null) {
1306:                        List<DomainSharedLibraryType> libraries = slType
1307:                                .getSharedLibrary();
1308:                        for (DomainSharedLibraryType library : libraries) {
1309:                            if (library.getTimestamp().equals(
1310:                                    BigInteger.valueOf(0))) {
1311:                                long timestamp = 0;
1312:                                String filename;
1313:                                File file;
1314:
1315:                                filename = mRegistry.getRepository()
1316:                                        .findArchive(
1317:                                                ArchiveType.SHARED_LIBRARY,
1318:                                                library.getName());
1319:                                file = new File(filename);
1320:                                timestamp = file.lastModified();
1321:                                library.setTimestamp(BigInteger
1322:                                        .valueOf(timestamp));
1323:                            }
1324:                        }
1325:                    }
1326:                } catch (RuntimeException rte) {
1327:                    mRegObjLM.releaseWriteLock();
1328:                    throw rte;
1329:                }
1330:                commit();
1331:
1332:            }
1333:
1334:            /*--------------------------------------------------------------------------------*\
1335:             *                   Component configuration ops                                  *
1336:            \*--------------------------------------------------------------------------------*/
1337:
1338:            /*--------------------------------------------------------------------------------*\
1339:             *                  Set static component configuration                            *
1340:            \*--------------------------------------------------------------------------------*/
1341:            /**
1342:             * Set the value of a configuration attribute for a component installed on a target
1343:             * for the runtime target. 
1344:             * @param name - identification for the attribute
1345:             * @param value - string representation of the attribute value
1346:             * @param componentName - identification for the component
1347:             * @exception RegistryException on errors in getting the attribute value
1348:             */
1349:            public void setComponentAttribute(String componentName,
1350:                    String name, String value) throws RegistryException {
1351:                setComponentAttribute(componentName, mThisTarget, name, value);
1352:            }
1353:
1354:            /**
1355:             * Set the value of a configuration attribute for a component installed on a target,
1356:             *
1357:             * @param targetName - target instance/cluster name.
1358:             * @param name - identification for the attribute
1359:             * @param value - string representation of the attribute value
1360:             * @param componentName - identification for the component
1361:             * @exception RegistryException on errors in getting the attribute value
1362:             */
1363:            public void setComponentAttribute(String componentName,
1364:                    String targetName, String name, String value)
1365:                    throws RegistryException {
1366:                try {
1367:                    ComponentRefType comp = mGenQuery.getComponent(
1368:                            componentName, targetName);
1369:
1370:                    mRegObjLM.acquireWriteLock();
1371:                    try {
1372:                        ComponentConfigType ccfg = comp.getComponentConfig();
1373:                        if (ccfg == null) {
1374:                            ObjectFactory factory = new ObjectFactory();
1375:                            ccfg = factory.createComponentConfigType();
1376:                            comp.setComponentConfig(ccfg);
1377:                        }
1378:                        List<PropertyType> properties = ccfg.getProperty();
1379:
1380:                        List<PropertyType> newProperties = new ArrayList<PropertyType>();
1381:
1382:                        PropertyType prop = mObjectFactory.createPropertyType();
1383:                        prop.setName(name);
1384:                        prop.setValue(value);
1385:
1386:                        newProperties.add(prop);
1387:
1388:                        merge(properties, newProperties);
1389:                    } catch (RuntimeException rte) {
1390:                        mRegObjLM.releaseWriteLock();
1391:                        throw rte;
1392:                    }
1393:                    commit();
1394:                } catch (Exception jex) {
1395:                    throw new RegistryException(jex);
1396:                }
1397:            }
1398:
1399:            /**
1400:             * Set the value of a configuration attribute for a component installed on a target
1401:             * for the runtime target. 
1402:             * @param name - identification for the attribute
1403:             * @param value - string representation of the attribute value
1404:             * @param componentName - identification for the component
1405:             * @exception RegistryException on errors in getting the attribute value
1406:             */
1407:            public void setComponentAttributes(String componentName,
1408:                    Properties props) throws RegistryException {
1409:                setComponentAttributes(componentName, mThisTarget, props);
1410:            }
1411:
1412:            /**
1413:             * Set the value of a configuration attribute for a component installed on a target,
1414:             *
1415:             * @param targetName - target instance/cluster name.
1416:             * @param properties - the properties to set
1417:             * @param componentName - identification for the component
1418:             * @exception RegistryException on errors in getting the attribute value
1419:             */
1420:            public void setComponentAttributes(String componentName,
1421:                    String targetName, Properties props)
1422:                    throws RegistryException {
1423:                try {
1424:                    ComponentRefType comp = mGenQuery.getComponent(
1425:                            componentName, targetName);
1426:
1427:                    mRegObjLM.acquireWriteLock();
1428:                    try {
1429:                        ComponentConfigType ccfg = comp.getComponentConfig();
1430:                        if (ccfg == null) {
1431:                            ObjectFactory factory = new ObjectFactory();
1432:                            ccfg = factory.createComponentConfigType();
1433:                            comp.setComponentConfig(ccfg);
1434:                        }
1435:
1436:                        List<PropertyType> properties = ccfg.getProperty();
1437:                        int numProps = props.size();
1438:
1439:                        List<PropertyType> newProperties = new ArrayList<PropertyType>();
1440:                        java.util.Iterator itr = props.keySet().iterator();
1441:
1442:                        while (itr.hasNext()) {
1443:                            PropertyType prop = mObjectFactory
1444:                                    .createPropertyType();
1445:
1446:                            String key = (String) itr.next();
1447:                            prop.setName(key);
1448:                            prop.setValue((String) props.get(key));
1449:                            newProperties.add(prop);
1450:                        }
1451:
1452:                        merge(properties, newProperties);
1453:                    } catch (RuntimeException rte) {
1454:                        mRegObjLM.releaseWriteLock();
1455:                        throw rte;
1456:                    }
1457:                    commit();
1458:                } catch (Exception jex) {
1459:                    throw new RegistryException(jex);
1460:                }
1461:            }
1462:
1463:            /*--------------------------------------------------------------------------------*\
1464:             *                  Set/Add/Delete application  variables                         *
1465:            \*--------------------------------------------------------------------------------*/
1466:            /**
1467:             * Add a set of application variables to the registry for the runtime target.
1468:             *
1469:             * @param appVars - list of application variables to be added to the registry
1470:             * @exception RegistryException on errors in adding the application variables.
1471:             */
1472:            public void addComponentApplicationVariables(String componentName,
1473:                    com.sun.jbi.management.ComponentInfo.Variable[] appVars)
1474:                    throws RegistryException {
1475:                addComponentApplicationVariables(componentName, mThisTarget,
1476:                        appVars);
1477:            }
1478:
1479:            /**
1480:             * Add a set of application variables to the registry for the specified target.
1481:             *
1482:             * @param appVars - list of application variables to be added to the registry
1483:             * @param targetName - target to be updated
1484:             * @exception RegistryException on errors in adding the application variables.
1485:             */
1486:            public void addComponentApplicationVariables(String componentName,
1487:                    String targetName,
1488:                    com.sun.jbi.management.ComponentInfo.Variable[] appVars)
1489:                    throws RegistryException {
1490:                try {
1491:                    ComponentRefType comp = mGenQuery.getComponent(
1492:                            componentName, targetName);
1493:
1494:                    mRegObjLM.acquireWriteLock();
1495:                    try {
1496:                        ComponentConfigType ccfg = comp.getComponentConfig();
1497:                        if (ccfg == null) {
1498:                            ObjectFactory factory = new ObjectFactory();
1499:                            ccfg = factory.createComponentConfigType();
1500:                            comp.setComponentConfig(ccfg);
1501:                        }
1502:
1503:                        List<AppVariableType> variables = ccfg
1504:                                .getApplicationVariable();
1505:
1506:                        for (com.sun.jbi.management.ComponentInfo.Variable appVar : appVars) {
1507:                            AppVariableType var = mObjectFactory
1508:                                    .createAppVariableType();
1509:
1510:                            var.setName(appVar.getName());
1511:                            var.setValue(appVar.getValue());
1512:                            var.setType(appVar.getType());
1513:                            variables.add(var);
1514:                        }
1515:                    } catch (RuntimeException rte) {
1516:                        mRegObjLM.releaseWriteLock();
1517:                        throw rte;
1518:                    }
1519:                    commit();
1520:                } catch (Exception jex) {
1521:                    throw new RegistryException(jex);
1522:                }
1523:            }
1524:
1525:            /**
1526:             * Update a set of application variables to the registry for the runtime target.
1527:             *
1528:             * @param appVars - list of application variables to be updated
1529:             * @exception RegistryException on errors in updating the application variables.
1530:             */
1531:            public void updateComponentApplicationVariables(
1532:                    String componentName,
1533:                    com.sun.jbi.management.ComponentInfo.Variable[] appVars)
1534:                    throws RegistryException {
1535:                updateComponentApplicationVariables(componentName, mThisTarget,
1536:                        appVars);
1537:            }
1538:
1539:            /**
1540:             * Updated a set of application variables to the registry for the specified target.
1541:             *
1542:             * @param appVars - list of application variables to be updated
1543:             * @param targetName - target to be updated
1544:             * @exception RegistryException on errors in updating the application variables.
1545:             */
1546:            public void updateComponentApplicationVariables(
1547:                    String componentName, String targetName,
1548:                    com.sun.jbi.management.ComponentInfo.Variable[] appVars)
1549:                    throws RegistryException {
1550:
1551:                try {
1552:                    ComponentRefType comp = mGenQuery.getComponent(
1553:                            componentName, targetName);
1554:
1555:                    mRegObjLM.acquireWriteLock();
1556:                    try {
1557:                        ComponentConfigType ccfg = comp.getComponentConfig();
1558:                        if (ccfg == null) {
1559:                            ObjectFactory factory = new ObjectFactory();
1560:                            ccfg = factory.createComponentConfigType();
1561:                            comp.setComponentConfig(ccfg);
1562:                        }
1563:
1564:                        List<AppVariableType> variables = ccfg
1565:                                .getApplicationVariable();
1566:
1567:                        for (com.sun.jbi.management.ComponentInfo.Variable appVar : appVars) {
1568:                            boolean updated = false;
1569:                            for (AppVariableType var : variables) {
1570:                                if (var.getName().equals(appVar.getName())) {
1571:                                    var.setName(appVar.getName());
1572:                                    var.setValue(appVar.getValue());
1573:                                    var.setType(appVar.getType());
1574:                                    updated = true;
1575:                                    break;
1576:                                }
1577:                            }
1578:                            if (!updated) {
1579:                                // -- mLog.warning(mTranslator.getString(, appVar.getName()));
1580:                            }
1581:                        }
1582:                    } catch (RuntimeException rte) {
1583:                        mRegObjLM.releaseWriteLock();
1584:                        throw rte;
1585:                    }
1586:                    commit();
1587:                } catch (Exception jex) {
1588:                    throw new RegistryException(jex);
1589:                }
1590:            }
1591:
1592:            /**
1593:             * Delete a set of application variables from the registry for the runtime target.
1594:             *
1595:             * @param appVars - list of application variables to be deleted from the registry
1596:             * @param names - the names of the variables to be deleted.
1597:             * @exception RegistryException on errors in deleting the application variables.
1598:             */
1599:            public void deleteComponentApplicationVariables(
1600:                    String componentName, String[] names)
1601:                    throws RegistryException {
1602:                deleteComponentApplicationVariables(componentName, mThisTarget,
1603:                        names);
1604:            }
1605:
1606:            /**
1607:             * Add a set of application variables to the registry for the specified target.
1608:             *
1609:             * @param appVars - list of application variables to be deleted from the registry
1610:             * @param targetName - target to be updated
1611:             * @param names - the names of the variables to be deleted.
1612:             * @exception RegistryException on errors in deleting the application variables.
1613:             */
1614:            public void deleteComponentApplicationVariables(
1615:                    String componentName, String targetName, String[] names)
1616:                    throws RegistryException {
1617:                try {
1618:                    ComponentRefType comp = mGenQuery.getComponent(
1619:                            componentName, targetName);
1620:
1621:                    mRegObjLM.acquireWriteLock();
1622:                    try {
1623:                        ComponentConfigType ccfg = comp.getComponentConfig();
1624:                        if (ccfg == null) {
1625:                            ObjectFactory factory = new ObjectFactory();
1626:                            ccfg = factory.createComponentConfigType();
1627:                            comp.setComponentConfig(ccfg);
1628:                        }
1629:
1630:                        List<AppVariableType> variables = ccfg
1631:                                .getApplicationVariable();
1632:
1633:                        for (String name : names) {
1634:                            AppVariableType tbd = null;
1635:                            for (AppVariableType var : variables) {
1636:                                if (var.getName().equals(name)) {
1637:                                    tbd = var;
1638:                                    break;
1639:                                }
1640:                            }
1641:                            if (tbd != null) {
1642:                                variables.remove(tbd);
1643:                            } else {
1644:                                // -- mLog.warning(mTranslator.getString(, appVar.getName()));
1645:                            }
1646:                        }
1647:                    } catch (RuntimeException rte) {
1648:                        mRegObjLM.releaseWriteLock();
1649:                        throw rte;
1650:                    }
1651:                    commit();
1652:                } catch (Exception jex) {
1653:                    throw new RegistryException(jex);
1654:                }
1655:            }
1656:
1657:            /*--------------------------------------------------------------------------------*\
1658:             *                  Set/Add/Delete Named Configurations                           *
1659:            \*--------------------------------------------------------------------------------*/
1660:
1661:            /**
1662:             * The name of the application configuration is the value of the "configurationName"
1663:             * property.
1664:             */
1665:
1666:            /**
1667:             * Add a named application configuration to the registry for the component for the
1668:             * implicit runtime target.
1669:             *
1670:             * @param componentName
1671:             *                 component identification
1672:             * @param appConfig 
1673:             *                 named application configuration represented as properties
1674:             * @exception RegistryException on errors in adding the application configuration.
1675:             */
1676:            public void addComponentApplicationConfiguration(
1677:                    String componentName, Properties appConfig)
1678:                    throws RegistryException {
1679:                addComponentApplicationConfiguration(componentName,
1680:                        mThisTarget, appConfig);
1681:            }
1682:
1683:            /**
1684:             * Add a named application configuration to the registry for the component for the
1685:             * specified runtime target.
1686:             *
1687:             * @param componentName
1688:             *                 component identification
1689:             * @param appConfig 
1690:             *                 named application configuration represented as properties
1691:             * @param targetName 
1692:             *                target name
1693:             * @exception RegistryException on errors in adding the application configuration.
1694:             */
1695:            public void addComponentApplicationConfiguration(
1696:                    String componentName, String targetName,
1697:                    Properties appConfig) throws RegistryException {
1698:                try {
1699:                    String configName = (String) appConfig
1700:                            .get(Registry.APP_CONFIG_NAME_KEY);
1701:
1702:                    if (configName == null) {
1703:                        String errMsg = mTranslator
1704:                                .getString(LocalStringKeys.JBI_ADMIN_APP_CONFIG_PROPS_MISSING_NAME);
1705:                        throw new RegistryException(errMsg);
1706:                    }
1707:
1708:                    ComponentRefType comp = mGenQuery.getComponent(
1709:                            componentName, targetName);
1710:
1711:                    mRegObjLM.acquireWriteLock();
1712:                    try {
1713:                        ComponentConfigType ccfg = comp.getComponentConfig();
1714:                        if (ccfg == null) {
1715:                            ObjectFactory factory = new ObjectFactory();
1716:                            ccfg = factory.createComponentConfigType();
1717:                            comp.setComponentConfig(ccfg);
1718:                        }
1719:
1720:                        List<AppConfigType> configs = ccfg
1721:                                .getApplicationConfiguration();
1722:                        AppConfigType cfg = mObjectFactory
1723:                                .createAppConfigType();
1724:                        List<PropertyType> cfgPropList = cfg.getProperty();
1725:
1726:                        Set keys = appConfig.keySet();
1727:
1728:                        for (Object key : keys) {
1729:                            PropertyType prop = mObjectFactory
1730:                                    .createPropertyType();
1731:
1732:                            String propKey = (String) key;
1733:                            prop.setName(propKey);
1734:                            prop.setValue((String) appConfig.get(propKey));
1735:                            cfgPropList.add(prop);
1736:                        }
1737:                        cfg.setName(configName);
1738:                        configs.add(cfg);
1739:                    } catch (RuntimeException rte) {
1740:                        mRegObjLM.releaseWriteLock();
1741:                        throw rte;
1742:                    }
1743:                    commit();
1744:                } catch (Exception jex) {
1745:                    throw new RegistryException(jex);
1746:                }
1747:            }
1748:
1749:            /**
1750:             * Update a named application configuration set on a component 
1751:             * for the implicit runtime target.
1752:             *
1753:             * @param componentName
1754:             *                 component identification
1755:             * @param appConfig 
1756:             *                 named application configuration represented as properties
1757:             * @exception RegistryException on errors in updating the application configuration.
1758:             */
1759:            public void updateComponentApplicationConfiguration(
1760:                    String componentName, Properties appConfig)
1761:                    throws RegistryException {
1762:                updateComponentApplicationConfiguration(componentName,
1763:                        mThisTarget, appConfig);
1764:            }
1765:
1766:            /**
1767:             * Update a named application configuration set on a component 
1768:             * for the specified runtime target.
1769:             *
1770:             * @param componentName
1771:             *                 component identification
1772:             * @param appConfig 
1773:             *                 named application configuration represented as properties
1774:             * @param targetName 
1775:             *                 target name
1776:             * @exception RegistryException on errors in updating the application configuration.
1777:             */
1778:            public void updateComponentApplicationConfiguration(
1779:                    String componentName, String targetName,
1780:                    Properties appConfig) throws RegistryException {
1781:                try {
1782:                    String configName = (String) appConfig
1783:                            .get(Registry.APP_CONFIG_NAME_KEY);
1784:
1785:                    if (configName == null) {
1786:                        String errMsg = mTranslator
1787:                                .getString(LocalStringKeys.JBI_ADMIN_APP_CONFIG_PROPS_MISSING_NAME);
1788:                        throw new RegistryException(errMsg);
1789:                    }
1790:
1791:                    ComponentRefType comp = mGenQuery.getComponent(
1792:                            componentName, targetName);
1793:
1794:                    mRegObjLM.acquireWriteLock();
1795:                    try {
1796:                        ComponentConfigType ccfg = comp.getComponentConfig();
1797:                        if (ccfg == null) {
1798:                            ObjectFactory factory = new ObjectFactory();
1799:                            ccfg = factory.createComponentConfigType();
1800:                            comp.setComponentConfig(ccfg);
1801:                        }
1802:
1803:                        List<AppConfigType> configs = ccfg
1804:                                .getApplicationConfiguration();
1805:
1806:                        AppConfigType oldCfg = null;
1807:                        for (AppConfigType config : configs) {
1808:                            List<PropertyType> cfgPropList = config
1809:                                    .getProperty();
1810:
1811:                            if (checkContainsProperty(cfgPropList,
1812:                                    Registry.APP_CONFIG_NAME_KEY, configName)) {
1813:                                oldCfg = config;
1814:                            }
1815:                        }
1816:
1817:                        if (oldCfg != null) {
1818:                            // remove the old config and add the updated one
1819:                            //configs.remove(tbdCfg);
1820:
1821:                            //AppConfigType cfg = mObjectFactory.createAppConfigType();
1822:                            List<PropertyType> cfgPropList = oldCfg
1823:                                    .getProperty();
1824:
1825:                            Set keys = appConfig.keySet();
1826:
1827:                            for (Object key : keys) {
1828:                                String propKey = (String) key;
1829:                                Object valueObj = appConfig.get(propKey);
1830:
1831:                                if (valueObj != null) {
1832:
1833:                                    for (PropertyType prop : cfgPropList) {
1834:                                        if (prop.getName().equals(propKey)) {
1835:                                            prop.setValue(valueObj.toString());
1836:                                            continue;
1837:                                        }
1838:
1839:                                    }
1840:
1841:                                    // -- This is a new property being added with the update
1842:                                    PropertyType prop = mObjectFactory
1843:                                            .createPropertyType();
1844:                                    prop.setName(propKey);
1845:                                    prop.setValue(valueObj.toString());
1846:                                    cfgPropList.add(prop);
1847:                                }
1848:                            }
1849:                            //cfg.setName(configName);
1850:                            //configs.add(cfg);
1851:                        }
1852:                    } catch (RuntimeException rte) {
1853:                        mRegObjLM.releaseWriteLock();
1854:                        throw rte;
1855:                    }
1856:                    commit();
1857:                } catch (Exception jex) {
1858:                    throw new RegistryException(jex);
1859:                }
1860:            }
1861:
1862:            /**
1863:             * Delete a named application configuration
1864:             *
1865:             * @param appConfigName 
1866:             *          name of the application configuration to delete.
1867:             * @param componentName
1868:             *          component identification
1869:             * @exception RegistryException on errors in deleting the application configuration.
1870:             */
1871:            public void deleteComponentApplicationConfiguration(
1872:                    String componentName, String appConfigName)
1873:                    throws RegistryException {
1874:                deleteComponentApplicationConfiguration(componentName,
1875:                        mThisTarget, appConfigName);
1876:            }
1877:
1878:            /**
1879:             * Delete a named application configuration
1880:             *
1881:             * @param componentName
1882:             *          component identification
1883:             * @param targetName
1884:             *          target name
1885:             * @param appConfigName 
1886:             *          the name of the configuration to be deleted.
1887:             * @exception RegistryException on errors in deleting the application configuration.
1888:             */
1889:            public void deleteComponentApplicationConfiguration(
1890:                    String componentName, String targetName,
1891:                    String appConfigName) throws RegistryException {
1892:                try {
1893:                    ComponentRefType comp = mGenQuery.getComponent(
1894:                            componentName, targetName);
1895:
1896:                    mRegObjLM.acquireWriteLock();
1897:                    try {
1898:                        ComponentConfigType ccfg = comp.getComponentConfig();
1899:                        if (ccfg == null) {
1900:                            ObjectFactory factory = new ObjectFactory();
1901:                            ccfg = factory.createComponentConfigType();
1902:                            comp.setComponentConfig(ccfg);
1903:                        }
1904:
1905:                        List<AppConfigType> configs = ccfg
1906:                                .getApplicationConfiguration();
1907:
1908:                        AppConfigType tbdCfg = null;
1909:                        for (AppConfigType config : configs) {
1910:                            List<PropertyType> cfgPropList = config
1911:                                    .getProperty();
1912:
1913:                            if (checkContainsProperty(cfgPropList,
1914:                                    Registry.APP_CONFIG_NAME_KEY, appConfigName)) {
1915:                                tbdCfg = config;
1916:                            }
1917:                        }
1918:
1919:                        if (tbdCfg != null) {
1920:                            // remove the config
1921:                            configs.remove(tbdCfg);
1922:                        }
1923:                    } catch (RuntimeException rte) {
1924:                        mRegObjLM.releaseWriteLock();
1925:                        throw rte;
1926:                    }
1927:                    commit();
1928:                } catch (Exception jex) {
1929:                    throw new RegistryException(jex);
1930:                }
1931:            }
1932:
1933:            /*----------------------------------------------------------------------------------*\
1934:             *                          Private Helpers                                         *
1935:            \*----------------------------------------------------------------------------------*/
1936:
1937:            /**
1938:             * @param componentName - name of component to be added to the domain
1939:             */
1940:            private void deleteComponent(String componentName) {
1941:                Components compType = mJbiRegistry.getComponents();
1942:
1943:                if (compType != null) {
1944:                    DomainEntityType compToDel = null;
1945:                    List<DomainComponentType> components = compType
1946:                            .getComponent();
1947:                    for (DomainComponentType component : components) {
1948:                        if (component.getName().equals(componentName)) {
1949:                            compToDel = component;
1950:                        }
1951:                    }
1952:                    if (compToDel != null) {
1953:                        components.remove(compToDel);
1954:                    }
1955:                }
1956:            }
1957:
1958:            /**
1959:             * @param sharedLibraryName - name of service assembly to be removed
1960:             */
1961:            private void deleteSharedLibrary(String sharedLibraryName) {
1962:                SharedLibraries slType = mJbiRegistry.getSharedLibraries();
1963:
1964:                if (slType != null) {
1965:                    DomainEntityType slToDel = null;
1966:                    List<DomainSharedLibraryType> sls = slType
1967:                            .getSharedLibrary();
1968:                    for (DomainSharedLibraryType sl : sls) {
1969:                        if (sl.getName().equals(sharedLibraryName)) {
1970:                            slToDel = sl;
1971:                        }
1972:                    }
1973:                    if (slToDel != null) {
1974:                        sls.remove(slToDel);
1975:                    }
1976:                }
1977:            }
1978:
1979:            /**
1980:             * Remove a service assembly from the domain. 
1981:             *
1982:             * @param serviceAssemblyName - service assembly name
1983:             * @throws RegistryException on errors
1984:             */
1985:            private void deleteServiceAssembly(String serviceAssemblyName)
1986:                    throws RegistryException {
1987:                ServiceAssemblies saType = mJbiRegistry.getServiceAssemblies();
1988:
1989:                if (saType != null) {
1990:                    DomainEntityType saToDel = null;
1991:                    List<DomainEntityType> sas = saType.getServiceAssembly();
1992:                    for (DomainEntityType sa : sas) {
1993:                        if (sa.getName().equals(serviceAssemblyName)) {
1994:                            saToDel = sa;
1995:                        }
1996:                    }
1997:                    if (saToDel != null) {
1998:                        sas.remove(saToDel);
1999:                    }
2000:                }
2001:            }
2002:
2003:            /**
2004:             * Add a ComponentRef to a cluster or a server
2005:             */
2006:            private void addComponentRef(ComponentInfo compInfo,
2007:                    InstalledComponentsListType iclt) throws RegistryException {
2008:                try {
2009:                    ComponentRefType compRef = ObjectTranslator
2010:                            .getJaxbComponentRef(compInfo);
2011:
2012:                    iclt.getComponentRef().add(compRef);
2013:                } catch (JAXBException jex) {
2014:                    throw new RegistryException(jex);
2015:                }
2016:            }
2017:
2018:            /**
2019:             * Remove a ComponentRef to a cluster or a server
2020:             */
2021:            private void removeComponentRef(String componentName,
2022:                    InstalledComponentsListType iclt) {
2023:                if (iclt != null) {
2024:                    ComponentRefType compToDel = null;
2025:
2026:                    List<ComponentRefType> components = iclt.getComponentRef();
2027:
2028:                    for (ComponentRefType component : components) {
2029:                        if (component.getNameRef().equals(componentName)) {
2030:                            compToDel = component;
2031:                        }
2032:                    }
2033:
2034:                    if (compToDel != null) {
2035:                        components.remove(compToDel);
2036:                    }
2037:                }
2038:            }
2039:
2040:            /**
2041:             * Add a SharedLibraryRef to a cluster or a server
2042:             */
2043:            private void addSharedLibraryRef(ComponentInfo slInfo,
2044:                    InstalledComponentsListType iclt) throws RegistryException {
2045:                try {
2046:                    SharedLibraryRefType slRef = ObjectTranslator
2047:                            .getJaxbSharedLibraryRef(slInfo);
2048:
2049:                    iclt.getSharedLibraryRef().add(slRef);
2050:
2051:                } catch (JAXBException jex) {
2052:                    throw new RegistryException(jex);
2053:                }
2054:            }
2055:
2056:            /**
2057:             * Remove a SharedLibraryRef to a cluster or a server
2058:             */
2059:            private void removeSharedLibraryRef(String sharedLibraryName,
2060:                    InstalledComponentsListType iclt) {
2061:                SharedLibraryRefType slToBeDeleted = null;
2062:                if (iclt != null) {
2063:                    List<SharedLibraryRefType> sls = iclt.getSharedLibraryRef();
2064:
2065:                    for (SharedLibraryRefType sl : sls) {
2066:                        if (sl.getNameRef().equals(sharedLibraryName)) {
2067:                            slToBeDeleted = sl;
2068:                        }
2069:                    }
2070:
2071:                    if (slToBeDeleted != null) {
2072:                        sls.remove(slToBeDeleted);
2073:                    }
2074:                }
2075:            }
2076:
2077:            /**
2078:             * Add a ServiceAssemblyRef to a cluster or a server
2079:             */
2080:            private void addServiceAssemblyRef(String saName,
2081:                    InstalledComponentsListType iclt) throws RegistryException {
2082:                try {
2083:                    ServiceAssemblyRefType saRef = ObjectTranslator
2084:                            .getJaxbServiceAssemblyRef(saName);
2085:
2086:                    iclt.getServiceAssemblyRef().add(saRef);
2087:
2088:                } catch (JAXBException jex) {
2089:                    throw new RegistryException(jex);
2090:                }
2091:            }
2092:
2093:            /**
2094:             * Remove a ServiceAssemblyRef from a cluster or a server
2095:             */
2096:            private void removeServiceAssemblyRef(String saName,
2097:                    InstalledComponentsListType iclt) {
2098:                ServiceAssemblyRefType saToBeDeleted = null;
2099:                if (iclt != null) {
2100:                    List<ServiceAssemblyRefType> sas = iclt
2101:                            .getServiceAssemblyRef();
2102:
2103:                    for (ServiceAssemblyRefType sa : sas) {
2104:                        if (sa.getNameRef().equals(saName)) {
2105:                            saToBeDeleted = sa;
2106:                        }
2107:                    }
2108:
2109:                    if (saToBeDeleted != null) {
2110:                        sas.remove(saToBeDeleted);
2111:                    }
2112:                }
2113:            }
2114:
2115:            /**
2116:             * Commit the registry object after down grading the write to a read lock, finally
2117:             * relinquish the read lock.
2118:             */
2119:            private void commit() throws RegistryException {
2120:                mRegObjLM.downgradeWriteLock();
2121:                try {
2122:                    mRegistry.commit();
2123:                } catch (com.sun.jbi.management.registry.RegistryException rex) {
2124:                    throw rex;
2125:                } finally {
2126:                    mRegObjLM.releaseReadLock();
2127:                }
2128:            }
2129:
2130:            /**
2131:             * Update the property list with the new entries
2132:             * 
2133:             * @param properties - list of component properties to be updated
2134:             * @param newProperties - new component properties
2135:             */
2136:            private void merge(List<PropertyType> properties,
2137:                    List<PropertyType> newEntries) {
2138:                for (PropertyType newProp : newEntries) {
2139:                    boolean replaced = false;
2140:
2141:                    // If an entry with same name exists replace it
2142:                    for (PropertyType oldProp : properties) {
2143:                        if (oldProp.getName().equals(newProp.getName())) {
2144:                            oldProp.setValue(newProp.getValue());
2145:                            replaced = true;
2146:                            break;
2147:                        }
2148:                    }
2149:
2150:                    if (!replaced) {
2151:                        properties.add(newProp);
2152:                    }
2153:                }
2154:            }
2155:
2156:            /**
2157:             * @return true if the PropertyList contains a given property name value pair.
2158:             */
2159:            boolean checkContainsProperty(List<PropertyType> propList,
2160:                    String name, String value) {
2161:                for (PropertyType prop : propList) {
2162:                    if (prop.getName().equals(name)
2163:                            && prop.getValue().equals(value)) {
2164:                        return true;
2165:                    }
2166:                }
2167:                return false;
2168:            }
2169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.