001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.naming.deployment;
017:
018: import java.util.Map;
019:
020: import javax.xml.namespace.QName;
021:
022: import org.apache.geronimo.j2ee.deployment.NamingBuilder;
023: import org.apache.geronimo.j2ee.deployment.Module;
024: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
025: import org.apache.geronimo.kernel.repository.Environment;
026: import org.apache.geronimo.common.DeploymentException;
027: import org.apache.geronimo.gbean.GBeanInfo;
028: import org.apache.geronimo.gbean.GBeanInfoBuilder;
029: import org.apache.xmlbeans.XmlObject;
030: import org.apache.xmlbeans.QNameSet;
031:
032: /**
033: * @version $Rev: 535381 $ $Date: 2007-05-04 14:04:18 -0700 (Fri, 04 May 2007) $
034: */
035: public class UnavailableRefBuilder implements NamingBuilder {
036: private final QNameSet unavailableQNameSet;
037: private QName unavailableQName;
038:
039: public UnavailableRefBuilder(String namespaceURI, String localPart) {
040: unavailableQName = new QName(namespaceURI, localPart);
041: unavailableQNameSet = QNameSet.singleton(unavailableQName);
042: }
043:
044: public void buildEnvironment(XmlObject specDD, XmlObject plan,
045: Environment environment) throws DeploymentException {
046: if (specDD != null) {
047: checkUnavailable(specDD);
048: }
049: }
050:
051: private void checkUnavailable(XmlObject specDD)
052: throws DeploymentException {
053: XmlObject[] specRefs = specDD
054: .selectChildren(unavailableQNameSet);
055: if (specRefs.length > 0) {
056: throw new DeploymentException(
057: "This server cannot deploy references of type "
058: + unavailableQName);
059: }
060: }
061:
062: public void initContext(XmlObject specDD, XmlObject plan,
063: Module module) throws DeploymentException {
064: checkUnavailable(specDD);
065: }
066:
067: public void buildNaming(XmlObject specDD, XmlObject plan,
068: Module module, Map componentContext)
069: throws DeploymentException {
070: checkUnavailable(specDD);
071: }
072:
073: public QNameSet getSpecQNameSet() {
074: return unavailableQNameSet;
075: }
076:
077: public QNameSet getPlanQNameSet() {
078: return QNameSet.EMPTY;
079: }
080:
081: public static final GBeanInfo GBEAN_INFO;
082:
083: static {
084: GBeanInfoBuilder infoBuilder = GBeanInfoBuilder
085: .createStatic(UnavailableRefBuilder.class,
086: NameFactory.MODULE_BUILDER);
087: infoBuilder.addAttribute("specNamespaceURI", String.class,
088: true, true);
089: infoBuilder.addAttribute("specLocalPart", String.class, true,
090: true);
091:
092: infoBuilder.setConstructor(new String[] { "specNamespaceURI",
093: "specLocalPart" });
094:
095: GBEAN_INFO = infoBuilder.getBeanInfo();
096: }
097:
098: public static GBeanInfo getGBeanInfo() {
099: return GBEAN_INFO;
100: }
101: }
|