All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fabric3.cache.introspection.CacheResourceLoader Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
/*
 * Fabric3
 * Copyright (c) 2009-2015 Metaform Systems
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.fabric3.cache.introspection;

import javax.xml.namespace.QName;
import javax.xml.stream.Location;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

import org.oasisopen.sca.Constants;
import org.oasisopen.sca.annotation.Destroy;
import org.oasisopen.sca.annotation.EagerInit;
import org.oasisopen.sca.annotation.Init;
import org.oasisopen.sca.annotation.Reference;

import org.fabric3.cache.model.CacheSetResourceDefinition;
import org.fabric3.cache.spi.CacheResourceDefinition;
import org.fabric3.spi.introspection.IntrospectionContext;
import org.fabric3.spi.introspection.xml.AbstractValidatingTypeLoader;
import org.fabric3.spi.introspection.xml.LoaderRegistry;
import org.fabric3.spi.introspection.xml.MissingAttribute;

/**
 * Loads cache configurations specified in a composite. The format of the caches element is:
 * 
 *      <caches>
 *          <cache name="MyCache">
 *              <!-- cache-specific configuration -->
 *           </cache>
 *      </caches>
 * 
*/ @EagerInit public class CacheResourceLoader extends AbstractValidatingTypeLoader { private static final QName SCA_TYPE = new QName(Constants.SCA_NS, "caches"); private static final QName F3_TYPE = new QName(org.fabric3.api.Namespaces.F3, "caches"); private LoaderRegistry registry; public CacheResourceLoader(@Reference LoaderRegistry registry) { this.registry = registry; addAttributes("name"); } @Init public void init() { // register under both namespaces registry.registerLoader(F3_TYPE, this); registry.registerLoader(SCA_TYPE, this); } @Destroy public void destroy() { registry.unregisterLoader(F3_TYPE); registry.unregisterLoader(SCA_TYPE); } public CacheSetResourceDefinition load(XMLStreamReader reader, IntrospectionContext context) throws XMLStreamException { CacheSetResourceDefinition definition = new CacheSetResourceDefinition(); validateAttributes(reader, context, definition); while (true) { switch (reader.next()) { case XMLStreamConstants.START_ELEMENT: if ("cache".equals(reader.getName().getLocalPart())) { Location location = reader.getLocation(); String name = reader.getAttributeValue(null, "name"); if (null == name) { MissingAttribute error = new MissingAttribute("Cache name not specified", location); context.addError(error); name = "default"; } reader.nextTag(); CacheResourceDefinition configuration = registry.load(reader, CacheResourceDefinition.class, context); if (configuration == null) { continue; } configuration.setCacheName(name); definition.addDefinition(configuration); } break; case XMLStreamConstants.END_ELEMENT: if ("caches".equals(reader.getName().getLocalPart())) { return definition; } } } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy