001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)ServiceAssemblyValidator.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: /**
030: * ArchiveValidator.java
031: *
032: * SUN PROPRIETARY/CONFIDENTIAL.
033: * This software is the proprietary information of Sun Microsystems, Inc.
034: * Use is subject to license terms.
035: *
036: * Created on January 2, 2006, 4:49 PM
037: */package com.sun.jbi.management.util;
038:
039: import com.sun.jbi.EnvironmentContext;
040: import com.sun.jbi.StringTranslator;
041:
042: import com.sun.jbi.management.LocalStringKeys;
043: import com.sun.jbi.management.descriptor.ServiceAssemblyDescriptor;
044: import com.sun.jbi.management.message.MessageBuilder;
045: import com.sun.jbi.management.descriptor.Jbi;
046: import com.sun.jbi.management.descriptor.ServiceAssembly;
047:
048: import java.util.logging.Logger;
049: import javax.jbi.JBIException;
050:
051: /**
052: * Validator for a shared library archives.
053: *
054: * @author Sun Microsystems, Inc
055: */
056: public class ServiceAssemblyValidator implements Validator {
057: private Logger mLog;
058: private StringTranslator mTranslator;
059: private ArchiveHelper mArchHelper;
060: private boolean mValidate;
061: private MessageBuilder mMsgBuilder;
062: private static final String EMPTY_STR = "";
063:
064: /**
065: * @param ctx - the environment context
066: * @param validate - flag to indicate whether jbi.xml should be validated based
067: * on the schema
068: */
069: public ServiceAssemblyValidator(EnvironmentContext envCtx,
070: boolean validate) throws Exception {
071: mTranslator = envCtx
072: .getStringTranslator("com.sun.jbi.management");
073: mLog = Logger.getLogger("com.sun.jbi.management");
074: mArchHelper = new ArchiveHelper(envCtx);
075: mValidate = validate;
076: mMsgBuilder = new MessageBuilder(mTranslator);
077: }
078:
079: /**
080: * Perform archive validation based on the type of the archive.
081: *
082: * @param archivePath - absolute path to the archive.
083: * @throws Exception if the archive is not valid. The exception message
084: * has the details on what caused validation to fail.
085: *
086: */
087: public void validate(java.io.File archivePath) throws Exception {
088: validateDescriptor(archivePath);
089: }
090:
091: /*---------------------------------------------------------------------------------*\
092: * Private Helpers *
093: \*---------------------------------------------------------------------------------*/
094:
095: /**
096: * Validate the jbi.xml component installation descriptor in the archive
097: *
098: * @throws Exception if any inconsistencies are found.
099: */
100: private void validateDescriptor(java.io.File archivePath)
101: throws Exception {
102: Jbi jbiXml = mArchHelper.loadJbiXml(archivePath, mValidate);
103: ServiceAssemblyDescriptor descr = null;
104: String[] params = new String[] { archivePath.getAbsolutePath() };
105:
106: try {
107: descr = new ServiceAssemblyDescriptor(jbiXml);
108: } catch (IllegalArgumentException iex) {
109: String errMsg = mTranslator
110: .getString(
111: LocalStringKeys.JBI_ADMIN_INVALID_SERVICE_ASSEMBLY_ARCHIVE_TYPE,
112: archivePath);
113: String jbiMsg = mMsgBuilder.buildFrameworkMessage(
114: "validateDescriptor",
115: MessageBuilder.TaskResult.FAILED,
116: MessageBuilder.MessageType.ERROR, mMsgBuilder
117: .getMessageString(errMsg), params,
118: mMsgBuilder.getMessageToken(errMsg));
119: throw new JBIException(jbiMsg);
120: }
121: }
122: }
|