001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.theme.deployment.jboss;
023:
024: import org.jboss.portal.theme.metadata.PortalLayoutMetaData;
025: import org.jboss.portal.theme.metadata.StateURIMetaData;
026: import org.jboss.xb.binding.ObjectModelFactory;
027: import org.jboss.xb.binding.UnmarshallingContext;
028: import org.xml.sax.Attributes;
029:
030: import java.util.ArrayList;
031:
032: /**
033: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
034: * @version $Revision: 8784 $
035: */
036: public class PortalLayoutMetaDataFactory implements ObjectModelFactory {
037:
038: public Object newRoot(Object root, UnmarshallingContext nav,
039: String nsURI, String localName, Attributes attrs) {
040: return new ArrayList();
041: }
042:
043: public Object completeRoot(Object root, UnmarshallingContext nav,
044: String nsURI, String localName) {
045: return root;
046: }
047:
048: public Object newChild(ArrayList list, UnmarshallingContext nav,
049: String nsURI, String localName, Attributes attrs) {
050: if ("layout".equals(localName)) {
051: return new PortalLayoutMetaData();
052: }
053: return null;
054: }
055:
056: public void addChild(ArrayList list,
057: PortalLayoutMetaData portalLayout,
058: UnmarshallingContext nav, String nsURI, String localName) {
059: list.add(portalLayout);
060: }
061:
062: public void setValue(PortalLayoutMetaData portalLayout,
063: UnmarshallingContext nav, String nsURI, String localName,
064: String value) {
065: if ("name".equals(localName)) {
066: portalLayout.setName(value);
067: } else if ("layout-implementation".equals(localName)) {
068: portalLayout.setClassName(value);
069: } else if ("uri".equals(localName)) {
070: portalLayout.setURI(value);
071: } else if ("region".equals(localName)) {
072: portalLayout.getRegionNames().add(value);
073: }
074: }
075:
076: public Object newChild(PortalLayoutMetaData portalLayout,
077: UnmarshallingContext nav, String nsURI, String localName,
078: Attributes attrs) {
079: if ("uri".equals(localName)) {
080: String state = attrs.getValue("state");
081: if (state != null) {
082: StateURIMetaData stateURI = new StateURIMetaData();
083: stateURI.setState(state);
084: return stateURI;
085: }
086: } else if ("region".equals(localName)) {
087: return attrs.getValue("name");
088: }
089: return null;
090: }
091:
092: public void setValue(StateURIMetaData stateURI,
093: UnmarshallingContext nav, String nsURI, String localName,
094: String value) {
095: if ("uri".equals(localName)) {
096: stateURI.setURI(value);
097: }
098: }
099:
100: public void addChild(PortalLayoutMetaData portalLayout,
101: StateURIMetaData stateURI, UnmarshallingContext nav,
102: String nsURI, String localName) {
103: portalLayout.getLayoutURIStateMap().put(stateURI.getState(),
104: stateURI);
105: }
106:
107: public void addChild(PortalLayoutMetaData portalLayout,
108: String regionName, UnmarshallingContext nav, String nsURI,
109: String localName) {
110: portalLayout.getRegionNames().add(regionName);
111: }
112: }
|